diff --git a/packages/rocketchat-webrtc/client/WebRTCClass.js b/packages/rocketchat-webrtc/client/WebRTCClass.js index dfbccbd4391f..6a0d6521e209 100644 --- a/packages/rocketchat-webrtc/client/WebRTCClass.js +++ b/packages/rocketchat-webrtc/client/WebRTCClass.js @@ -426,13 +426,17 @@ class WebRTCClass { return; } const getScreen = (audioStream) => { - if (document.cookie.indexOf('rocketchatscreenshare=chrome') === -1 && (window.rocketchatscreenshare == null) && this.navigator !== 'electron') { - const refresh = function() { - swal({ - type: 'warning', - title: TAPi18n.__('Refresh_your_page_after_install_to_enable_screen_sharing') - }); - }; + const refresh = function() { + swal({ + type: 'warning', + title: TAPi18n.__('Refresh_your_page_after_install_to_enable_screen_sharing') + }); + }; + + const isChromeExtensionInstalled = this.navigator === 'chrome' && ChromeScreenShare.installed; + const isFirefoxExtensionInstalled = this.navigator === 'firefox' && window.rocketchatscreenshare != null; + + if (!isChromeExtensionInstalled || !isFirefoxExtensionInstalled) { swal({ type: 'warning', title: TAPi18n.__('Screen_Share'), @@ -461,6 +465,7 @@ class WebRTCClass { }); return onError(false); } + const getScreenSuccess = (stream) => { if (audioStream != null) { stream.addTrack(audioStream.getAudioTracks()[0]); diff --git a/packages/rocketchat-webrtc/client/screenShare.js b/packages/rocketchat-webrtc/client/screenShare.js index 22f9ba2dc951..24519a59b667 100644 --- a/packages/rocketchat-webrtc/client/screenShare.js +++ b/packages/rocketchat-webrtc/client/screenShare.js @@ -1,11 +1,20 @@ /* globals ChromeScreenShare, fireGlobalEvent */ this.ChromeScreenShare = { - screenCallback: undefined, + callbacks: {}, + installed: false, + init() { + this.callbacks['get-RocketChatScreenSharingExtensionVersion'] = version => { + if (version) { + this.installed = true; + } + }; + window.postMessage('get-RocketChatScreenSharingExtensionVersion', '*'); + }, getSourceId(navigator, callback) { if (callback == null) { throw '"callback" parameter is mandatory.'; } - ChromeScreenShare.screenCallback = callback; + this.callbacks['getSourceId'] = callback; if (navigator === 'electron') { return fireGlobalEvent('get-sourceId', '*'); } @@ -13,17 +22,21 @@ this.ChromeScreenShare = { } }; +ChromeScreenShare.init(); + window.addEventListener('message', function(e) { if (e.origin !== window.location.origin) { return; } if (e.data === 'PermissionDeniedError') { - if (ChromeScreenShare.screenCallback != null) { - return ChromeScreenShare.screenCallback('PermissionDeniedError'); + if (ChromeScreenShare.callbacks['getSourceId'] != null) { + return ChromeScreenShare.callbacks['getSourceId']('PermissionDeniedError'); } throw new Error('PermissionDeniedError'); } - if (e.data.sourceId != null) { - return typeof ChromeScreenShare.screenCallback === 'function' && ChromeScreenShare.screenCallback(e.data.sourceId); + if (e.data.version != null) { + ChromeScreenShare.callbacks['get-RocketChatScreenSharingExtensionVersion'] && ChromeScreenShare.callbacks['get-RocketChatScreenSharingExtensionVersion'](e.data.version); + } else if (e.data.sourceId != null) { + return typeof ChromeScreenShare.callbacks['getSourceId'] === 'function' && ChromeScreenShare.callbacks['getSourceId'](e.data.sourceId); } });