diff options
author | talasila <talasila@research.att.com> | 2017-02-07 15:03:57 -0500 |
---|---|---|
committer | talasila <talasila@research.att.com> | 2017-02-07 15:05:15 -0500 |
commit | 4ad39a5c96dd99acf819ce189b13fec946d7506b (patch) | |
tree | a1449286441947cc3d07a45227fa0d6f978e1a7d /ecomp-portal-BE/war/static/fusion/webrtc/getSourceId.html | |
parent | 5500448cbd1f374d0ac743ee2fd636fe2d3c0027 (diff) |
Initial OpenECOMP Portal commit
Change-Id: I804b80e0830c092e307da1599bd9fbb5c3e2da77
Signed-off-by: talasila <talasila@research.att.com>
Diffstat (limited to 'ecomp-portal-BE/war/static/fusion/webrtc/getSourceId.html')
-rw-r--r-- | ecomp-portal-BE/war/static/fusion/webrtc/getSourceId.html | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/ecomp-portal-BE/war/static/fusion/webrtc/getSourceId.html b/ecomp-portal-BE/war/static/fusion/webrtc/getSourceId.html new file mode 100644 index 00000000..6f660025 --- /dev/null +++ b/ecomp-portal-BE/war/static/fusion/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> |