From bc403adb461707511e736e3af6c2d11a883283f0 Mon Sep 17 00:00:00 2001 From: Leonard Kim Date: Fri, 23 Aug 2019 13:16:52 -0700 Subject: [PATCH] feat(api): allow for explicit screenshare state toggling --- conference.js | 4 +++- modules/API/API.js | 22 ++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/conference.js b/conference.js index 31b0034ca2..59e25abda1 100644 --- a/conference.js +++ b/conference.js @@ -1457,7 +1457,9 @@ export default { return this._switchToScreenSharing(options); } - return this._untoggleScreenSharing(); + return this._untoggleScreenSharing + ? this._untoggleScreenSharing() + : Promise.resolve(); }, /** diff --git a/modules/API/API.js b/modules/API/API.js index 40870b2c10..08fc98bd73 100644 --- a/modules/API/API.js +++ b/modules/API/API.js @@ -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; }