Skip to content

Commit

Permalink
Merge pull request #7044 from RocketChat/improve-screen-sharing-exten…
Browse files Browse the repository at this point in the history
…sion-check

[FIX] New screen sharing Chrome extension checking method
  • Loading branch information
sampaiodiego authored May 24, 2017
2 parents 9e14767 + 0a4f371 commit 62228c0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
19 changes: 12 additions & 7 deletions packages/rocketchat-webrtc/client/WebRTCClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -461,6 +465,7 @@ class WebRTCClass {
});
return onError(false);
}

const getScreenSuccess = (stream) => {
if (audioStream != null) {
stream.addTrack(audioStream.getAudioTracks()[0]);
Expand Down
25 changes: 19 additions & 6 deletions packages/rocketchat-webrtc/client/screenShare.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
/* 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', '*');
}
return window.postMessage('get-sourceId', '*');
}
};

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);
}
});

0 comments on commit 62228c0

Please sign in to comment.