Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] New screen sharing Chrome extension checking method #7044

Merged
merged 1 commit into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
});