@techsee/techsee-media-service 0.16.2 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/MediaUtils/MediaDomUtils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAOlD,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA8EzH;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBlF;AAOD,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,WAAW,EAAE,eAAe,GAAE,eAAiC,GAAG,OAAO,CAAC,MAAM,CAAC,CAqGxI","file":"MediaDomUtils.d.ts","sourcesContent":["import isUndefined from 'lodash/isUndefined';\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n//@ts-ignore\nimport {TsEnvironmentDetect} from '@techsee/techsee-common/lib/helpers/ts-environment-detect';\nimport {repeatWithTimeout} from '@techsee/techsee-common/lib/core/retry-with-timeout';\nimport {SnapshotOptions} from '../MediaContracts';\nimport {getMediaTracer} from './MediaTracer';\n\nconst trace = getMediaTracer('DomUtils');\n\nconst isIE11 = (new TsEnvironmentDetect()).isIE11();\n\nexport function renderMediaStreamToVideoEl(container: HTMLDivElement, mediaStream: MediaStream): Promise<HTMLVideoElement> {\n return new Promise((resolve, reject) => {\n if (!document.body.contains(container)) {\n reject(new Error('Cannot render to container that is not attached to dom'));\n\n return;\n }\n\n const doResolve = (videoEl: HTMLVideoElement): void => {\n trace.info('Video element created successfully', {videoEl});\n resolve(videoEl);\n };\n\n const videoEl = document.createElement('video') as any;\n\n videoEl.muted = true;\n videoEl.playsInline = true;\n\n if (isIE11 && (window as any).WebRTCAdapter) {\n container.appendChild(videoEl);\n (window as any).WebRTCAdapter.bindVideoElement(videoEl);\n }\n\n videoEl.srcObject = mediaStream;\n\n if (!isIE11) {\n // Hack to override behavior introduced by Chrome/FF that unmuted video elements can't auto play\n videoEl.setAttribute('muted', '');\n }\n\n try {\n const playRes = videoEl.play();\n\n if (playRes && playRes.then) {\n playRes.then(() => {\n trace.info('Video element play success');\n if (!isIE11) {\n doResolve(videoEl);\n }\n });\n } else if (!isIE11) {\n doResolve(videoEl);\n }\n\n if (playRes && playRes.catch) {\n playRes.catch((error: any) => {\n trace.error('Reject while executing play method on video element', error);\n reject(error);\n });\n }\n } catch (error) {\n reject(error);\n trace.error('Error while executing play method on video element', error);\n\n return;\n }\n\n\n if (isIE11) {\n const handleComplete = (): boolean => videoEl.parentElement.tagName !== 'OBJECT';\n\n const waitForObjectSettings = {intervalInMs: 30, timeoutInMs: 200};\n\n repeatWithTimeout(handleComplete, waitForObjectSettings)\n .then(() => {\n //We will wait, until video is played, then we resolve\n const isVideoPlaying = (): boolean => videoEl.videoHeight <= 0 || videoEl.videoWidth <= 0;\n const waitForVideoSettings = {intervalInMs: 50, timeoutInMs: 10000};\n\n repeatWithTimeout(isVideoPlaying, waitForVideoSettings)\n .then(() => doResolve(videoEl.parentElement))\n .catch(() => reject(new Error('Timeout while waiting for video to play')));\n });\n } else {\n container.appendChild(videoEl);\n //doResolve(videoEl);\n }\n });\n}\n\nexport function removeVideoElementFromDom(videoEl: HTMLVideoElement): Promise<void> {\n return new Promise((resolve) => {\n if (isIE11 && (window as any).WebRTCAdapter) {\n (window as any).WebRTCAdapter.unBindVideoElement(videoEl);\n if (videoEl && videoEl.parentNode && videoEl.parentNode.removeChild) {\n videoEl.parentNode.removeChild(videoEl);\n trace.info('Video element removed successfully');\n } else {\n trace.warn('Video element not removed', videoEl, videoEl.parentNode);\n }\n } else {\n videoEl.remove();\n }\n\n resolve();\n });\n}\n\nconst defaultSnapshot: SnapshotOptions = {\n format: 'image/png',\n quality: 0.92\n};\n\nexport function getSnapshotFromMediaStream(mediaStream: MediaStream, snapshotOptions: SnapshotOptions = defaultSnapshot): Promise<string> {\n const {format, quality, x, y, w, h} = snapshotOptions;\n const crop = !isUndefined(x) && !isUndefined(y) && !isUndefined(w) && !isUndefined(h);\n const resize = !crop && (!isUndefined(w) || !isUndefined(h));\n\n return new Promise((resolve, reject) => {\n\n const tempContainer = document.createElement('div');\n\n tempContainer.style.cssText = 'position:absolute;left: -10000px;';\n document.body.appendChild(tempContainer);\n\n const doneFn = (err: any, image?: any): void => {\n if (err) {\n reject(err);\n\n return;\n }\n\n setTimeout(() => {\n document.body.removeChild(tempContainer);\n if (!err) {\n resolve(image);\n }\n }, 50);\n };\n\n renderMediaStreamToVideoEl(tempContainer, mediaStream)\n .then((videoElement) => Promise.resolve(isIE11 ? getImgDataIE11(videoElement) : getImgData(videoElement))\n .then((imgData: any) => {\n if (!imgData || imgData.length < 10) {\n throw new Error('Failed to create a snapshot - imgData is null or empty');\n }\n\n doneFn(null, imgData);\n }))\n .catch((error) => {\n doneFn(error || new Error('Failed to create a snapshot - can\\'t render MediaStream To VideoEl '));\n });\n });\n\n //Gets image in all browsers except of IE\n function getImgData(videoElement: HTMLVideoElement): string {\n const {videoWidth, videoHeight} = videoElement;\n const canvas = document.createElement('canvas');\n const ctx = canvas.getContext('2d')!;\n\n if (crop) {\n canvas.width = w;\n canvas.height = h;\n\n ctx.drawImage(videoElement, x, y, w, h, 0, 0, w, h);\n } else if (resize) {\n canvas.width = w;\n canvas.height = h;\n\n ctx.drawImage(videoElement, 0, 0, w, h);\n } else {\n canvas.height = videoHeight;\n canvas.width = videoWidth;\n\n ctx.drawImage(videoElement, 0, 0);\n }\n\n return canvas.toDataURL(format, quality);\n }\n\n //Gets image in IE browser. There should be TechSee IE11 plugin or OpenTok plugin installed.\n function getImgDataIE11(videoElement: any): Promise<string> {\n return new Promise((resolve) => {\n const {videoWidth, videoHeight} = videoElement;\n const canvas = document.createElement('canvas');\n const ctx = canvas.getContext('2d')!;\n\n if (crop || resize) {\n canvas.width = w;\n canvas.height = h;\n } else {\n canvas.height = videoHeight;\n canvas.width = videoWidth;\n }\n\n function _drawAndRemove(image: any): string {\n if (crop) {\n ctx.drawImage(image, x, y, w, h, 0, 0, w, h);\n } else if (resize) {\n ctx.drawImage(image, 0, 0, w, h);\n } else {\n ctx.drawImage(image, 0, 0, videoWidth, videoHeight);\n }\n\n return canvas.toDataURL(format, quality);\n }\n\n const base64 = videoElement.getFrame();\n const image = new Image();\n\n image.onload = () => resolve(_drawAndRemove(image));\n image.setAttribute('src', 'data:image/bmp;base64,' + base64);\n });\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/MediaUtils/MediaDomUtils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAOlD,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAoFzH;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBlF;AAOD,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,WAAW,EAAE,eAAe,GAAE,eAAiC,GAAG,OAAO,CAAC,MAAM,CAAC,CAqGxI","file":"MediaDomUtils.d.ts","sourcesContent":["import isUndefined from 'lodash/isUndefined';\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n//@ts-ignore\nimport {TsEnvironmentDetect} from '@techsee/techsee-common/lib/helpers/ts-environment-detect';\nimport {repeatWithTimeout} from '@techsee/techsee-common/lib/core/retry-with-timeout';\nimport {SnapshotOptions} from '../MediaContracts';\nimport {getMediaTracer} from './MediaTracer';\n\nconst trace = getMediaTracer('DomUtils');\n\nconst isIE11 = (new TsEnvironmentDetect()).isIE11();\n\nexport function renderMediaStreamToVideoEl(container: HTMLDivElement, mediaStream: MediaStream): Promise<HTMLVideoElement> {\n return new Promise((resolve, reject) => {\n if (!document.body.contains(container)) {\n reject(new Error('Cannot render to container that is not attached to dom'));\n\n return;\n }\n\n const doResolve = (videoEl: HTMLVideoElement): void => {\n trace.info('Video element created successfully', {videoEl});\n resolve(videoEl);\n };\n\n const videoEl = document.createElement('video') as any;\n\n videoEl.muted = true;\n videoEl.playsInline = true;\n\n if (isIE11 && (window as any).WebRTCAdapter) {\n container.appendChild(videoEl);\n (window as any).WebRTCAdapter.bindVideoElement(videoEl);\n }\n\n videoEl.srcObject = mediaStream;\n\n // When unplugged the headphones in ios the video element got paused.\n videoEl.addEventListener('pause', () => {\n trace.info('Video element got paused. IOS headphones disconnected');\n videoEl.play();\n });\n\n if (!isIE11) {\n // Hack to override behavior introduced by Chrome/FF that unmuted video elements can't auto play\n videoEl.setAttribute('muted', '');\n }\n\n try {\n const playRes = videoEl.play();\n\n if (playRes && playRes.then) {\n playRes.then(() => {\n trace.info('Video element play success');\n if (!isIE11) {\n doResolve(videoEl);\n }\n });\n } else if (!isIE11) {\n doResolve(videoEl);\n }\n\n if (playRes && playRes.catch) {\n playRes.catch((error: any) => {\n trace.error('Reject while executing play method on video element', error);\n reject(error);\n });\n }\n } catch (error) {\n reject(error);\n trace.error('Error while executing play method on video element', error);\n\n return;\n }\n\n\n if (isIE11) {\n const handleComplete = (): boolean => videoEl.parentElement.tagName !== 'OBJECT';\n\n const waitForObjectSettings = {intervalInMs: 30, timeoutInMs: 200};\n\n repeatWithTimeout(handleComplete, waitForObjectSettings)\n .then(() => {\n //We will wait, until video is played, then we resolve\n const isVideoPlaying = (): boolean => videoEl.videoHeight <= 0 || videoEl.videoWidth <= 0;\n const waitForVideoSettings = {intervalInMs: 50, timeoutInMs: 10000};\n\n repeatWithTimeout(isVideoPlaying, waitForVideoSettings)\n .then(() => doResolve(videoEl.parentElement))\n .catch(() => reject(new Error('Timeout while waiting for video to play')));\n });\n } else {\n container.appendChild(videoEl);\n //doResolve(videoEl);\n }\n });\n}\n\nexport function removeVideoElementFromDom(videoEl: HTMLVideoElement): Promise<void> {\n return new Promise((resolve) => {\n if (isIE11 && (window as any).WebRTCAdapter) {\n (window as any).WebRTCAdapter.unBindVideoElement(videoEl);\n if (videoEl && videoEl.parentNode && videoEl.parentNode.removeChild) {\n videoEl.parentNode.removeChild(videoEl);\n trace.info('Video element removed successfully');\n } else {\n trace.warn('Video element not removed', videoEl, videoEl.parentNode);\n }\n } else {\n videoEl.remove();\n }\n\n resolve();\n });\n}\n\nconst defaultSnapshot: SnapshotOptions = {\n format: 'image/png',\n quality: 0.92\n};\n\nexport function getSnapshotFromMediaStream(mediaStream: MediaStream, snapshotOptions: SnapshotOptions = defaultSnapshot): Promise<string> {\n const {format, quality, x, y, w, h} = snapshotOptions;\n const crop = !isUndefined(x) && !isUndefined(y) && !isUndefined(w) && !isUndefined(h);\n const resize = !crop && (!isUndefined(w) || !isUndefined(h));\n\n return new Promise((resolve, reject) => {\n\n const tempContainer = document.createElement('div');\n\n tempContainer.style.cssText = 'position:absolute;left: -10000px;';\n document.body.appendChild(tempContainer);\n\n const doneFn = (err: any, image?: any): void => {\n if (err) {\n reject(err);\n\n return;\n }\n\n setTimeout(() => {\n document.body.removeChild(tempContainer);\n if (!err) {\n resolve(image);\n }\n }, 50);\n };\n\n renderMediaStreamToVideoEl(tempContainer, mediaStream)\n .then((videoElement) => Promise.resolve(isIE11 ? getImgDataIE11(videoElement) : getImgData(videoElement))\n .then((imgData: any) => {\n if (!imgData || imgData.length < 10) {\n throw new Error('Failed to create a snapshot - imgData is null or empty');\n }\n\n doneFn(null, imgData);\n }))\n .catch((error) => {\n doneFn(error || new Error('Failed to create a snapshot - can\\'t render MediaStream To VideoEl '));\n });\n });\n\n //Gets image in all browsers except of IE\n function getImgData(videoElement: HTMLVideoElement): string {\n const {videoWidth, videoHeight} = videoElement;\n const canvas = document.createElement('canvas');\n const ctx = canvas.getContext('2d')!;\n\n if (crop) {\n canvas.width = w;\n canvas.height = h;\n\n ctx.drawImage(videoElement, x, y, w, h, 0, 0, w, h);\n } else if (resize) {\n canvas.width = w;\n canvas.height = h;\n\n ctx.drawImage(videoElement, 0, 0, w, h);\n } else {\n canvas.height = videoHeight;\n canvas.width = videoWidth;\n\n ctx.drawImage(videoElement, 0, 0);\n }\n\n return canvas.toDataURL(format, quality);\n }\n\n //Gets image in IE browser. There should be TechSee IE11 plugin or OpenTok plugin installed.\n function getImgDataIE11(videoElement: any): Promise<string> {\n return new Promise((resolve) => {\n const {videoWidth, videoHeight} = videoElement;\n const canvas = document.createElement('canvas');\n const ctx = canvas.getContext('2d')!;\n\n if (crop || resize) {\n canvas.width = w;\n canvas.height = h;\n } else {\n canvas.height = videoHeight;\n canvas.width = videoWidth;\n }\n\n function _drawAndRemove(image: any): string {\n if (crop) {\n ctx.drawImage(image, x, y, w, h, 0, 0, w, h);\n } else if (resize) {\n ctx.drawImage(image, 0, 0, w, h);\n } else {\n ctx.drawImage(image, 0, 0, videoWidth, videoHeight);\n }\n\n return canvas.toDataURL(format, quality);\n }\n\n const base64 = videoElement.getFrame();\n const image = new Image();\n\n image.onload = () => resolve(_drawAndRemove(image));\n image.setAttribute('src', 'data:image/bmp;base64,' + base64);\n });\n }\n}\n"]}
@@ -31,6 +31,11 @@ function renderMediaStreamToVideoEl(container, mediaStream) {
31
31
  window.WebRTCAdapter.bindVideoElement(videoEl);
32
32
  }
33
33
  videoEl.srcObject = mediaStream;
34
+ // When unplugged the headphones in ios the video element got paused.
35
+ videoEl.addEventListener('pause', function () {
36
+ trace.info('Video element got paused. IOS headphones disconnected');
37
+ videoEl.play();
38
+ });
34
39
  if (!isIE11) {
35
40
  // Hack to override behavior introduced by Chrome/FF that unmuted video elements can't auto play
36
41
  videoEl.setAttribute('muted', '');
@@ -1 +1 @@
1
- {"version":3,"sources":["MediaUtils/MediaDomUtils.js"],"names":["__importDefault","mod","__esModule","Object","defineProperty","exports","value","getSnapshotFromMediaStream","removeVideoElementFromDom","renderMediaStreamToVideoEl","isUndefined_1","require","ts_environment_detect_1","retry_with_timeout_1","MediaTracer_1","trace","getMediaTracer","isIE11","TsEnvironmentDetect","container","mediaStream","Promise","resolve","reject","document","body","contains","Error","doResolve","videoEl","info","createElement","muted","playsInline","window","WebRTCAdapter","appendChild","bindVideoElement","srcObject","setAttribute","playRes","play","then","catch","error","handleComplete","parentElement","tagName","waitForObjectSettings","intervalInMs","timeoutInMs","repeatWithTimeout","isVideoPlaying","videoHeight","videoWidth","waitForVideoSettings","unBindVideoElement","parentNode","removeChild","warn","remove","defaultSnapshot","format","quality","snapshotOptions","x","y","w","h","crop","default","resize","tempContainer","style","cssText","doneFn","err","image","setTimeout","videoElement","getImgDataIE11","getImgData","imgData","length","canvas","ctx","getContext","width","height","drawImage","toDataURL","_drawAndRemove","base64","getFrame","Image","onload"],"mappings":"AAAA;;AACA,IAAIA,kBAAmB,aAAQ,UAAKA,eAAd,IAAkC,UAAUC,GAAV,EAAe;AACnE,WAAQA,OAAOA,IAAIC,UAAZ,GAA0BD,GAA1B,GAAgC,EAAE,WAAWA,GAAb,EAAvC;AACH,CAFD;AAGAE,OAAOC,cAAP,CAAsBC,OAAtB,EAA+B,YAA/B,EAA6C,EAAEC,OAAO,IAAT,EAA7C;AACAD,QAAQE,0BAAR,GAAqCF,QAAQG,yBAAR,GAAoCH,QAAQI,0BAAR,GAAqC,KAAK,CAAnH;AACA,IAAIC,gBAAgBV,gBAAgBW,QAAQ,oBAAR,CAAhB,CAApB;AACA;AACA;AACA,IAAIC,0BAA0BD,QAAQ,2DAAR,CAA9B;AACA,IAAIE,uBAAuBF,QAAQ,qDAAR,CAA3B;AACA,IAAIG,gBAAgBH,QAAQ,eAAR,CAApB;AACA,IAAII,QAAQD,cAAcE,cAAd,CAA6B,UAA7B,CAAZ;AACA,IAAIC,SAAU,IAAIL,wBAAwBM,mBAA5B,EAAD,CAAoDD,MAApD,EAAb;AACA,SAASR,0BAAT,CAAoCU,SAApC,EAA+CC,WAA/C,EAA4D;AACxD,WAAO,IAAIC,OAAJ,CAAY,UAAUC,OAAV,EAAmBC,MAAnB,EAA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,EAAiC,CAAjC,EAAoC,CAApC,EAAuCD,CAAvC,EAA0CC,CAA1C;AACH,iBAFD,MAGK,IAAIG,MAAJ,EAAY;AACbc,wBAAII,SAAJ,CAAcZ,KAAd,EAAqB,CAArB,EAAwB,CAAxB,EAA2BV,CAA3B,EAA8BC,CAA9B;AACH,iBAFI,MAGA;AACDiB,wBAAII,SAAJ,CAAcZ,KAAd,EAAqB,CAArB,EAAwB,CAAxB,EAA2BvB,UAA3B,EAAuCD,WAAvC;AACH;AACD,uBAAO+B,OAAOM,SAAP,CAAiB5B,MAAjB,EAAyBC,OAAzB,CAAP;AACH;AACD,gBAAI6B,SAASb,aAAac,QAAb,EAAb;AACA,gBAAIhB,QAAQ,IAAIiB,KAAJ,EAAZ;AACAjB,kBAAMkB,MAAN,GAAe,YAAY;AAAE,uBAAOzE,QAAQqE,eAAed,KAAf,CAAR,CAAP;AAAwC,aAArE;AACAA,kBAAMtC,YAAN,CAAmB,KAAnB,EAA0B,2BAA2BqD,MAArD;AACH,SA5BM,CAAP;AA6BH;AACJ;AACDvF,QAAQE,0BAAR,GAAqCA,0BAArC;;AAEA","file":"MediaDomUtils.js","sourcesContent":["\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getSnapshotFromMediaStream = exports.removeVideoElementFromDom = exports.renderMediaStreamToVideoEl = void 0;\nvar isUndefined_1 = __importDefault(require(\"lodash/isUndefined\"));\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n//@ts-ignore\nvar ts_environment_detect_1 = require(\"@techsee/techsee-common/lib/helpers/ts-environment-detect\");\nvar retry_with_timeout_1 = require(\"@techsee/techsee-common/lib/core/retry-with-timeout\");\nvar MediaTracer_1 = require(\"./MediaTracer\");\nvar trace = MediaTracer_1.getMediaTracer('DomUtils');\nvar isIE11 = (new ts_environment_detect_1.TsEnvironmentDetect()).isIE11();\nfunction renderMediaStreamToVideoEl(container, mediaStream) {\n return new Promise(function (resolve, reject) {\n if (!document.body.contains(container)) {\n reject(new Error('Cannot render to container that is not attached to dom'));\n return;\n }\n var doResolve = function (videoEl) {\n trace.info('Video element created successfully', { videoEl: videoEl });\n resolve(videoEl);\n };\n var videoEl = document.createElement('video');\n videoEl.muted = true;\n videoEl.playsInline = true;\n if (isIE11 && window.WebRTCAdapter) {\n container.appendChild(videoEl);\n window.WebRTCAdapter.bindVideoElement(videoEl);\n }\n videoEl.srcObject = mediaStream;\n if (!isIE11) {\n // Hack to override behavior introduced by Chrome/FF that unmuted video elements can't auto play\n videoEl.setAttribute('muted', '');\n }\n try {\n var playRes = videoEl.play();\n if (playRes && playRes.then) {\n playRes.then(function () {\n trace.info('Video element play success');\n if (!isIE11) {\n doResolve(videoEl);\n }\n });\n }\n else if (!isIE11) {\n doResolve(videoEl);\n }\n if (playRes && playRes.catch) {\n playRes.catch(function (error) {\n trace.error('Reject while executing play method on video element', error);\n reject(error);\n });\n }\n }\n catch (error) {\n reject(error);\n trace.error('Error while executing play method on video element', error);\n return;\n }\n if (isIE11) {\n var handleComplete = function () { return videoEl.parentElement.tagName !== 'OBJECT'; };\n var waitForObjectSettings = { intervalInMs: 30, timeoutInMs: 200 };\n retry_with_timeout_1.repeatWithTimeout(handleComplete, waitForObjectSettings)\n .then(function () {\n //We will wait, until video is played, then we resolve\n var isVideoPlaying = function () { return videoEl.videoHeight <= 0 || videoEl.videoWidth <= 0; };\n var waitForVideoSettings = { intervalInMs: 50, timeoutInMs: 10000 };\n retry_with_timeout_1.repeatWithTimeout(isVideoPlaying, waitForVideoSettings)\n .then(function () { return doResolve(videoEl.parentElement); })\n .catch(function () { return reject(new Error('Timeout while waiting for video to play')); });\n });\n }\n else {\n container.appendChild(videoEl);\n //doResolve(videoEl);\n }\n });\n}\nexports.renderMediaStreamToVideoEl = renderMediaStreamToVideoEl;\nfunction removeVideoElementFromDom(videoEl) {\n return new Promise(function (resolve) {\n if (isIE11 && window.WebRTCAdapter) {\n window.WebRTCAdapter.unBindVideoElement(videoEl);\n if (videoEl && videoEl.parentNode && videoEl.parentNode.removeChild) {\n videoEl.parentNode.removeChild(videoEl);\n trace.info('Video element removed successfully');\n }\n else {\n trace.warn('Video element not removed', videoEl, videoEl.parentNode);\n }\n }\n else {\n videoEl.remove();\n }\n resolve();\n });\n}\nexports.removeVideoElementFromDom = removeVideoElementFromDom;\nvar defaultSnapshot = {\n format: 'image/png',\n quality: 0.92\n};\nfunction getSnapshotFromMediaStream(mediaStream, snapshotOptions) {\n if (snapshotOptions === void 0) { snapshotOptions = defaultSnapshot; }\n var format = snapshotOptions.format, quality = snapshotOptions.quality, x = snapshotOptions.x, y = snapshotOptions.y, w = snapshotOptions.w, h = snapshotOptions.h;\n var crop = !isUndefined_1.default(x) && !isUndefined_1.default(y) && !isUndefined_1.default(w) && !isUndefined_1.default(h);\n var resize = !crop && (!isUndefined_1.default(w) || !isUndefined_1.default(h));\n return new Promise(function (resolve, reject) {\n var tempContainer = document.createElement('div');\n tempContainer.style.cssText = 'position:absolute;left: -10000px;';\n document.body.appendChild(tempContainer);\n var doneFn = function (err, image) {\n if (err) {\n reject(err);\n return;\n }\n setTimeout(function () {\n document.body.removeChild(tempContainer);\n if (!err) {\n resolve(image);\n }\n }, 50);\n };\n renderMediaStreamToVideoEl(tempContainer, mediaStream)\n .then(function (videoElement) { return Promise.resolve(isIE11 ? getImgDataIE11(videoElement) : getImgData(videoElement))\n .then(function (imgData) {\n if (!imgData || imgData.length < 10) {\n throw new Error('Failed to create a snapshot - imgData is null or empty');\n }\n doneFn(null, imgData);\n }); })\n .catch(function (error) {\n doneFn(error || new Error('Failed to create a snapshot - can\\'t render MediaStream To VideoEl '));\n });\n });\n //Gets image in all browsers except of IE\n function getImgData(videoElement) {\n var videoWidth = videoElement.videoWidth, videoHeight = videoElement.videoHeight;\n var canvas = document.createElement('canvas');\n var ctx = canvas.getContext('2d');\n if (crop) {\n canvas.width = w;\n canvas.height = h;\n ctx.drawImage(videoElement, x, y, w, h, 0, 0, w, h);\n }\n else if (resize) {\n canvas.width = w;\n canvas.height = h;\n ctx.drawImage(videoElement, 0, 0, w, h);\n }\n else {\n canvas.height = videoHeight;\n canvas.width = videoWidth;\n ctx.drawImage(videoElement, 0, 0);\n }\n return canvas.toDataURL(format, quality);\n }\n //Gets image in IE browser. There should be TechSee IE11 plugin or OpenTok plugin installed.\n function getImgDataIE11(videoElement) {\n return new Promise(function (resolve) {\n var videoWidth = videoElement.videoWidth, videoHeight = videoElement.videoHeight;\n var canvas = document.createElement('canvas');\n var ctx = canvas.getContext('2d');\n if (crop || resize) {\n canvas.width = w;\n canvas.height = h;\n }\n else {\n canvas.height = videoHeight;\n canvas.width = videoWidth;\n }\n function _drawAndRemove(image) {\n if (crop) {\n ctx.drawImage(image, x, y, w, h, 0, 0, w, h);\n }\n else if (resize) {\n ctx.drawImage(image, 0, 0, w, h);\n }\n else {\n ctx.drawImage(image, 0, 0, videoWidth, videoHeight);\n }\n return canvas.toDataURL(format, quality);\n }\n var base64 = videoElement.getFrame();\n var image = new Image();\n image.onload = function () { return resolve(_drawAndRemove(image)); };\n image.setAttribute('src', 'data:image/bmp;base64,' + base64);\n });\n }\n}\nexports.getSnapshotFromMediaStream = getSnapshotFromMediaStream;\n\n//# sourceMappingURL=MediaDomUtils.js.map\n"]}
1
+ {"version":3,"sources":["MediaUtils/MediaDomUtils.js"],"names":["__importDefault","mod","__esModule","Object","defineProperty","exports","value","getSnapshotFromMediaStream","removeVideoElementFromDom","renderMediaStreamToVideoEl","isUndefined_1","require","ts_environment_detect_1","retry_with_timeout_1","MediaTracer_1","trace","getMediaTracer","isIE11","TsEnvironmentDetect","container","mediaStream","Promise","resolve","reject","document","body","contains","Error","doResolve","videoEl","info","createElement","muted","playsInline","window","WebRTCAdapter","appendChild","bindVideoElement","srcObject","addEventListener","play","setAttribute","playRes","then","catch","error","handleComplete","parentElement","tagName","waitForObjectSettings","intervalInMs","timeoutInMs","repeatWithTimeout","isVideoPlaying","videoHeight","videoWidth","waitForVideoSettings","unBindVideoElement","parentNode","removeChild","warn","remove","defaultSnapshot","format","quality","snapshotOptions","x","y","w","h","crop","default","resize","tempContainer","style","cssText","doneFn","err","image","setTimeout","videoElement","getImgDataIE11","getImgData","imgData","length","canvas","ctx","getContext","width","height","drawImage","toDataURL","_drawAndRemove","base64","getFrame","Image","onload"],"mappings":"AAAA;;AACA,IAAIA,kBAAmB,aAAQ,UAAKA,eAAd,IAAkC,UAAUC,GAAV,EAAe;AACnE,WAAQA,OAAOA,IAAIC,UAAZ,GAA0BD,GAA1B,GAAgC,EAAE,WAAWA,GAAb,EAAvC;AACH,CAFD;AAGAE,OAAOC,cAAP,CAAsBC,OAAtB,EAA+B,YAA/B,EAA6C,EAAEC,OAAO,IAAT,EAA7C;AACAD,QAAQE,0BAAR,GAAqCF,QAAQG,yBAAR,GAAoCH,QAAQI,0BAAR,GAAqC,KAAK,CAAnH;AACA,IAAIC,gBAAgBV,gBAAgBW,QAAQ,oBAAR,CAAhB,CAApB;AACA;AACA;AACA,IAAIC,0BAA0BD,QAAQ,2DAAR,CAA9B;AACA,IAAIE,uBAAuBF,QAAQ,qDAAR,CAA3B;AACA,IAAIG,gBAAgBH,QAAQ,eAAR,CAApB;AACA,IAAII,QAAQD,cAAcE,cAAd,CAA6B,UAA7B,CAAZ;AACA,IAAIC,SAAU,IAAIL,wBAAwBM,mBAA5B,EAAD,CAAoDD,MAApD,EAAb;AACA,SAASR,0BAAT,CAAoCU,SAApC,EAA+CC,WAA/C,EAA4D;AACxD,WAAO,IAAIC,OAAJ,CAAY,UAAUC,OAAV,EAAmBC,MAAnB,EAA2B;AAC1C,YAAI,CAACC,SAASC,IAAT,CAAcC,QAAd,CAAuBP,SAAvB,CAAL,EAAwC;AACpCI,mBAAO,IAAII,KAAJ,CAAU,wDAAV,CAAP;AACA;AACH;AACD,YAAIC,YAAY,SAAZA,SAAY,CAAUC,OAAV,EAAmB;AAC/Bd,k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BAFD,MAGK,IAAIG,MAAJ,EAAY;AACbc,wBAAII,SAAJ,CAAcZ,KAAd,EAAqB,CAArB,EAAwB,CAAxB,EAA2BV,CAA3B,EAA8BC,CAA9B;AACH,iBAFI,MAGA;AACDiB,wBAAII,SAAJ,CAAcZ,KAAd,EAAqB,CAArB,EAAwB,CAAxB,EAA2BvB,UAA3B,EAAuCD,WAAvC;AACH;AACD,uBAAO+B,OAAOM,SAAP,CAAiB5B,MAAjB,EAAyBC,OAAzB,CAAP;AACH;AACD,gBAAI6B,SAASb,aAAac,QAAb,EAAb;AACA,gBAAIhB,QAAQ,IAAIiB,KAAJ,EAAZ;AACAjB,kBAAMkB,MAAN,GAAe,YAAY;AAAE,uBAAO1E,QAAQsE,eAAed,KAAf,CAAR,CAAP;AAAwC,aAArE;AACAA,kBAAMrC,YAAN,CAAmB,KAAnB,EAA0B,2BAA2BoD,MAArD;AACH,SA5BM,CAAP;AA6BH;AACJ;AACDxF,QAAQE,0BAAR,GAAqCA,0BAArC;;AAEA","file":"MediaDomUtils.js","sourcesContent":["\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getSnapshotFromMediaStream = exports.removeVideoElementFromDom = exports.renderMediaStreamToVideoEl = void 0;\nvar isUndefined_1 = __importDefault(require(\"lodash/isUndefined\"));\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n//@ts-ignore\nvar ts_environment_detect_1 = require(\"@techsee/techsee-common/lib/helpers/ts-environment-detect\");\nvar retry_with_timeout_1 = require(\"@techsee/techsee-common/lib/core/retry-with-timeout\");\nvar MediaTracer_1 = require(\"./MediaTracer\");\nvar trace = MediaTracer_1.getMediaTracer('DomUtils');\nvar isIE11 = (new ts_environment_detect_1.TsEnvironmentDetect()).isIE11();\nfunction renderMediaStreamToVideoEl(container, mediaStream) {\n return new Promise(function (resolve, reject) {\n if (!document.body.contains(container)) {\n reject(new Error('Cannot render to container that is not attached to dom'));\n return;\n }\n var doResolve = function (videoEl) {\n trace.info('Video element created successfully', { videoEl: videoEl });\n resolve(videoEl);\n };\n var videoEl = document.createElement('video');\n videoEl.muted = true;\n videoEl.playsInline = true;\n if (isIE11 && window.WebRTCAdapter) {\n container.appendChild(videoEl);\n window.WebRTCAdapter.bindVideoElement(videoEl);\n }\n videoEl.srcObject = mediaStream;\n // When unplugged the headphones in ios the video element got paused.\n videoEl.addEventListener('pause', function () {\n trace.info('Video element got paused. IOS headphones disconnected');\n videoEl.play();\n });\n if (!isIE11) {\n // Hack to override behavior introduced by Chrome/FF that unmuted video elements can't auto play\n videoEl.setAttribute('muted', '');\n }\n try {\n var playRes = videoEl.play();\n if (playRes && playRes.then) {\n playRes.then(function () {\n trace.info('Video element play success');\n if (!isIE11) {\n doResolve(videoEl);\n }\n });\n }\n else if (!isIE11) {\n doResolve(videoEl);\n }\n if (playRes && playRes.catch) {\n playRes.catch(function (error) {\n trace.error('Reject while executing play method on video element', error);\n reject(error);\n });\n }\n }\n catch (error) {\n reject(error);\n trace.error('Error while executing play method on video element', error);\n return;\n }\n if (isIE11) {\n var handleComplete = function () { return videoEl.parentElement.tagName !== 'OBJECT'; };\n var waitForObjectSettings = { intervalInMs: 30, timeoutInMs: 200 };\n retry_with_timeout_1.repeatWithTimeout(handleComplete, waitForObjectSettings)\n .then(function () {\n //We will wait, until video is played, then we resolve\n var isVideoPlaying = function () { return videoEl.videoHeight <= 0 || videoEl.videoWidth <= 0; };\n var waitForVideoSettings = { intervalInMs: 50, timeoutInMs: 10000 };\n retry_with_timeout_1.repeatWithTimeout(isVideoPlaying, waitForVideoSettings)\n .then(function () { return doResolve(videoEl.parentElement); })\n .catch(function () { return reject(new Error('Timeout while waiting for video to play')); });\n });\n }\n else {\n container.appendChild(videoEl);\n //doResolve(videoEl);\n }\n });\n}\nexports.renderMediaStreamToVideoEl = renderMediaStreamToVideoEl;\nfunction removeVideoElementFromDom(videoEl) {\n return new Promise(function (resolve) {\n if (isIE11 && window.WebRTCAdapter) {\n window.WebRTCAdapter.unBindVideoElement(videoEl);\n if (videoEl && videoEl.parentNode && videoEl.parentNode.removeChild) {\n videoEl.parentNode.removeChild(videoEl);\n trace.info('Video element removed successfully');\n }\n else {\n trace.warn('Video element not removed', videoEl, videoEl.parentNode);\n }\n }\n else {\n videoEl.remove();\n }\n resolve();\n });\n}\nexports.removeVideoElementFromDom = removeVideoElementFromDom;\nvar defaultSnapshot = {\n format: 'image/png',\n quality: 0.92\n};\nfunction getSnapshotFromMediaStream(mediaStream, snapshotOptions) {\n if (snapshotOptions === void 0) { snapshotOptions = defaultSnapshot; }\n var format = snapshotOptions.format, quality = snapshotOptions.quality, x = snapshotOptions.x, y = snapshotOptions.y, w = snapshotOptions.w, h = snapshotOptions.h;\n var crop = !isUndefined_1.default(x) && !isUndefined_1.default(y) && !isUndefined_1.default(w) && !isUndefined_1.default(h);\n var resize = !crop && (!isUndefined_1.default(w) || !isUndefined_1.default(h));\n return new Promise(function (resolve, reject) {\n var tempContainer = document.createElement('div');\n tempContainer.style.cssText = 'position:absolute;left: -10000px;';\n document.body.appendChild(tempContainer);\n var doneFn = function (err, image) {\n if (err) {\n reject(err);\n return;\n }\n setTimeout(function () {\n document.body.removeChild(tempContainer);\n if (!err) {\n resolve(image);\n }\n }, 50);\n };\n renderMediaStreamToVideoEl(tempContainer, mediaStream)\n .then(function (videoElement) { return Promise.resolve(isIE11 ? getImgDataIE11(videoElement) : getImgData(videoElement))\n .then(function (imgData) {\n if (!imgData || imgData.length < 10) {\n throw new Error('Failed to create a snapshot - imgData is null or empty');\n }\n doneFn(null, imgData);\n }); })\n .catch(function (error) {\n doneFn(error || new Error('Failed to create a snapshot - can\\'t render MediaStream To VideoEl '));\n });\n });\n //Gets image in all browsers except of IE\n function getImgData(videoElement) {\n var videoWidth = videoElement.videoWidth, videoHeight = videoElement.videoHeight;\n var canvas = document.createElement('canvas');\n var ctx = canvas.getContext('2d');\n if (crop) {\n canvas.width = w;\n canvas.height = h;\n ctx.drawImage(videoElement, x, y, w, h, 0, 0, w, h);\n }\n else if (resize) {\n canvas.width = w;\n canvas.height = h;\n ctx.drawImage(videoElement, 0, 0, w, h);\n }\n else {\n canvas.height = videoHeight;\n canvas.width = videoWidth;\n ctx.drawImage(videoElement, 0, 0);\n }\n return canvas.toDataURL(format, quality);\n }\n //Gets image in IE browser. There should be TechSee IE11 plugin or OpenTok plugin installed.\n function getImgDataIE11(videoElement) {\n return new Promise(function (resolve) {\n var videoWidth = videoElement.videoWidth, videoHeight = videoElement.videoHeight;\n var canvas = document.createElement('canvas');\n var ctx = canvas.getContext('2d');\n if (crop || resize) {\n canvas.width = w;\n canvas.height = h;\n }\n else {\n canvas.height = videoHeight;\n canvas.width = videoWidth;\n }\n function _drawAndRemove(image) {\n if (crop) {\n ctx.drawImage(image, x, y, w, h, 0, 0, w, h);\n }\n else if (resize) {\n ctx.drawImage(image, 0, 0, w, h);\n }\n else {\n ctx.drawImage(image, 0, 0, videoWidth, videoHeight);\n }\n return canvas.toDataURL(format, quality);\n }\n var base64 = videoElement.getFrame();\n var image = new Image();\n image.onload = function () { return resolve(_drawAndRemove(image)); };\n image.setAttribute('src', 'data:image/bmp;base64,' + base64);\n });\n }\n}\nexports.getSnapshotFromMediaStream = getSnapshotFromMediaStream;\n\n//# sourceMappingURL=MediaDomUtils.js.map\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@techsee/techsee-media-service",
3
- "version": "0.16.2",
3
+ "version": "0.18.0",
4
4
  "description": "Techsee Media Service Client",
5
5
  "author": "TechSee",
6
6
  "main": "lib/index.js",
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "@techsee/kurento-utils-temasys-mod": "6.6.3-dev-3",
22
22
  "@techsee/openvidu-browser": "~12.15.6",
23
- "@techsee/techsee-common": "~0.21.17",
23
+ "@techsee/techsee-common": "~0.22.0",
24
24
  "bluebird": "~3.7.2",
25
25
  "kurento-utils": "6.6.2",
26
26
  "lodash": "4.17.20",