feat(api): allow for explicit screenshare state toggling

This commit is contained in:
Leonard Kim 2019-08-23 13:16:52 -07:00 committed by virtuacoplenny
parent 1941275f93
commit bc403adb46
2 changed files with 21 additions and 5 deletions

View File

@ -1457,7 +1457,9 @@ export default {
return this._switchToScreenSharing(options);
}
return this._untoggleScreenSharing();
return this._untoggleScreenSharing
? this._untoggleScreenSharing()
: Promise.resolve();
},
/**

View File

@ -116,9 +116,19 @@ function initCommands() {
sendAnalytics(createApiEvent('chat.toggled'));
APP.UI.toggleChat();
},
'toggle-share-screen': () => {
/**
* Callback to invoke when the "toggle-share-screen" command is received.
*
* @param {Object} options - Additional details of how to perform
* the action. Note this parameter is undocumented and experimental.
* @param {boolean} options.enable - Whether trying to enable screen
* sharing or to turn it off.
* @returns {void}
*/
'toggle-share-screen': (options = {}) => {
sendAnalytics(createApiEvent('screen.sharing.toggled'));
toggleScreenSharing();
toggleScreenSharing(options.enable);
},
'toggle-tile-view': () => {
sendAnalytics(createApiEvent('tile-view.toggled'));
@ -242,13 +252,17 @@ function shouldBeEnabled() {
/**
* Executes on toggle-share-screen command.
*
* @param {boolean} [enable] - Whether this toggle is to explicitly enable or
* disable screensharing. If not defined, the application will automatically
* attempt to toggle between enabled and disabled. This boolean is useful for
* explicitly setting desired screensharing state.
* @returns {void}
*/
function toggleScreenSharing() {
function toggleScreenSharing(enable) {
if (APP.conference.isDesktopSharingEnabled) {
// eslint-disable-next-line no-empty-function
APP.conference.toggleScreenSharing().catch(() => {});
APP.conference.toggleScreenSharing(enable).catch(() => {});
} else {
initialScreenSharingState = !initialScreenSharingState;
}