Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
3 years ago
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * jQuery Clipchamp MJPEG Player Plugin v0.0.1
  3. * https://github.com/clipchamp/jquery-clipchamp-mjpeg-player-plugin
  4. *
  5. * Plays back MJPEG files produced by the clipchamp
  6. * online video converter, online video compressor, and
  7. * webcam recorder.
  8. *
  9. * Copyright 2015 zfaas Pty Ltd (clipchamp.com)
  10. * https://clipchamp.com
  11. * https://zfaas.com
  12. *
  13. * Released under the MIT license
  14. */
  15. (function($) {
  16. var DEFAULT_FPS = 15,
  17. DEFAULT_AUTOLOOP = true,
  18. JPEG_MAGIG_NUMBER = [0xff, 0xd8, 0xff];
  19. var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || window.setTimeout;
  20. function splitMJPEG(mjpegUrl, callback) {
  21. var xhr = new XMLHttpRequest();
  22. xhr.open('GET', mjpegUrl, true);
  23. xhr.overrideMimeType('application/octet-stream');
  24. xhr.responseType = 'arraybuffer';
  25. xhr.onload = function(event) {
  26. var array = new Uint8Array(xhr.response),
  27. startIndex,
  28. jpegs = [];
  29. for (var i=0, ii=array.length; i<ii; ++i) {
  30. if (array[i] === JPEG_MAGIG_NUMBER[0] && array[i+1] === JPEG_MAGIG_NUMBER[1] && array[i+2] === JPEG_MAGIG_NUMBER[2]) {
  31. if (i>0 && typeof startIndex === 'number') {
  32. jpegs.push(new Blob([array.subarray(startIndex, i)], {type: 'image/jpeg'}));
  33. }
  34. startIndex = i;
  35. }
  36. }
  37. callback(jpegs);
  38. };
  39. xhr.send();
  40. };
  41. function playMJPEGInternal(wrapperElement, mjpegUrl, fps, autoloop) {
  42. fps = (typeof fps === 'number') ? fps : DEFAULT_FPS;
  43. autoloop = (typeof autoloop === 'boolean') ? autoloop : DEFAULT_AUTOLOOP;
  44. var playbackFinished = false,
  45. imageElement = document.createElement('img'),
  46. jpegUrl;
  47. imageElement.setAttribute('style', 'width:100%;');
  48. wrapperElement.appendChild(imageElement);
  49. //Show SLADKIY_BUBALEKH
  50. splitMJPEG(mjpegUrl, function(jpegFiles) {
  51. //Hide SLADKIY_BUBALEKH -> or error!
  52. alert( jpegFiles.length );
  53. if (jpegFiles.length > 0) {
  54. var nextFrameIndex = 0;
  55. function showNextFrame() {
  56. if (imageElement) {
  57. if (jpegUrl) {
  58. URL.revokeObjectURL(jpegUrl);
  59. }
  60. jpegUrl = URL.createObjectURL(jpegFiles[nextFrameIndex++]);
  61. imageElement.onload = function() {
  62. if (imageElement) {
  63. if (autoloop || nextFrameIndex < jpegFiles.length) {
  64. nextFrameIndex = (nextFrameIndex === jpegFiles.length) ? 0 : nextFrameIndex;
  65. setTimeout(function() {
  66. requestAnimationFrame(showNextFrame);
  67. }, 1000/fps);
  68. }
  69. }
  70. };
  71. imageElement.setAttribute('src', jpegUrl);
  72. };
  73. };
  74. setTimeout(function() {
  75. requestAnimationFrame(showNextFrame);
  76. }, 1000/fps);
  77. }
  78. });
  79. return {
  80. finish: function() {
  81. if (imageElement) {
  82. imageElement.src = '';
  83. wrapperElement.removeChild(imageElement);
  84. imageElement = undefined;
  85. }
  86. },
  87. pause: function(){
  88. },
  89. play: function( fromBegin ){
  90. },
  91. stop: function(){
  92. pause();
  93. },
  94. alertInfo: function(){
  95. alert( jpegFiles.length );
  96. }
  97. };
  98. };
  99. // optionally make available as jQuery plugin
  100. if (typeof $ === 'function') {
  101. $.fn.clipchamp_mjpeg_player = function(mjpegUrl, fps, autoloop, callback) {
  102. if (typeof mjpegUrl === 'string') {
  103. if (typeof callback === 'function') {
  104. return this.each(function() {
  105. callback($(this)[0], playMJPEGInternal($(this)[0], mjpegUrl, fps, autoloop));
  106. });
  107. } else {
  108. throw new Error('Callback must be given and must be a function');
  109. }
  110. } else {
  111. throw new Error('MJPEG URL must be a string');
  112. }
  113. }
  114. }
  115. // optionally provide AMD module definition
  116. if (typeof define === 'function') {
  117. define('jquery.clipchamp.mjpeg.player', [], function() {
  118. return {
  119. playMJPEG: function(wrapperElement, mjpegUrl, fps, autoloop) {
  120. if (wrapperElement instanceof Element) {
  121. if (typeof mjpegUrl === 'string') {
  122. return playMJPEGInternal(wrapperElement, mjpegUrl, fps, autoloop);
  123. } else {
  124. throw new Error('MJPEG URL must be a string');
  125. }
  126. } else {
  127. throw new Error('No parent element was given');
  128. }
  129. }
  130. };
  131. });
  132. }
  133. } )
  134. (typeof jQuery === 'function' ? jQuery : undefined);