diff options
author | 2017-09-01 11:57:47 +0800 | |
---|---|---|
committer | 2017-09-01 11:57:58 +0800 | |
commit | 57dbba269d19bc59fad89160200bb2dbcccb9003 (patch) | |
tree | d466041ceffa2161124ca79a48b3e077777c74b8 /usecaseui-common/src/main/webapp/app/fusion/scripts/webrtc/getSourceId.html | |
parent | 4ff32341a0af1972b44a7410e76e9b231131e7ab (diff) |
Upload Monitor function code
Change-Id: I33ad76221b4cb771a298ff240245fc24be664efb
Issue-Id: USECASEUI-6
Signed-off-by: shentao <shentao@chinamobile.com>
Diffstat (limited to 'usecaseui-common/src/main/webapp/app/fusion/scripts/webrtc/getSourceId.html')
-rw-r--r-- | usecaseui-common/src/main/webapp/app/fusion/scripts/webrtc/getSourceId.html | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/usecaseui-common/src/main/webapp/app/fusion/scripts/webrtc/getSourceId.html b/usecaseui-common/src/main/webapp/app/fusion/scripts/webrtc/getSourceId.html new file mode 100644 index 00000000..6f660025 --- /dev/null +++ b/usecaseui-common/src/main/webapp/app/fusion/scripts/webrtc/getSourceId.html @@ -0,0 +1,78 @@ + +<script> + +var DetectRTC = {}; + +var screenCallback; + +DetectRTC.screen = { + chromeMediaSource: 'screen', + getSourceId: function (callback) { + screenCallback = callback; + window.postMessage('get-sourceId', '*'); + }, + onMessageCallback: function (data) { + // "cancel" button is clicked + if (data == 'PermissionDeniedError') { + DetectRTC.screen.chromeMediaSource = 'PermissionDeniedError'; + if (screenCallback) return screenCallback('PermissionDeniedError'); + else throw new Error('PermissionDeniedError'); + } + + // extension notified his presence + if (data == 'rtcmulticonnection-extension-loaded') { + DetectRTC.screen.chromeMediaSource = 'desktop'; + } + + // extension shared temp sourceId + if (data.sourceId) { + DetectRTC.screen.sourceId = data.sourceId; + if (screenCallback) screenCallback(DetectRTC.screen.sourceId); + } + }, + getChromeExtensionStatus: function (callback) { + // https://chrome.google.com/webstore/detail/screen-capturing-private/icgmlogfeajbfdffajhoebcfbibfhaen + var extensionid = 'icgmlogfeajbfdffajhoebcfbibfhaen'; + + var image = document.createElement('img'); + image.src = 'chrome-extension://' + extensionid + '/icon.png'; + image.onload = function () { + DetectRTC.screen.chromeMediaSource = 'screen'; + window.postMessage('are-you-there', '*'); + setTimeout(function () { + if (DetectRTC.screen.chromeMediaSource == 'screen') { + callback('installed-disabled'); + } else callback('installed-enabled'); + }, 2000); + }; + image.onerror = function () { + callback('not-installed'); + }; + } +}; + +window.addEventListener('message', function (event) { + if (!event.data || !(typeof event.data == 'string' || event.data.sourceId || event.data.captureSourceId)) return; + if (event.data.captureSourceId) captureSourceId(); + + DetectRTC.screen.onMessageCallback(event.data); +}); + +function captureSourceId() { + // check if desktop-capture extension installed. + DetectRTC.screen.getChromeExtensionStatus(function (status) { + if (status != 'installed-enabled') { + window.parent.postMessage({ + chromeExtensionStatus: status + }, '*'); + return; + } + + DetectRTC.screen.getSourceId(function (sourceId) { + window.parent.postMessage({ + chromeMediaSourceId: sourceId + }, '*'); + }); + }); +} +</script> |