-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7044 from RocketChat/improve-screen-sharing-exten…
…sion-check [FIX] New screen sharing Chrome extension checking method
- Loading branch information
Showing
2 changed files
with
31 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |