From 41c38427c1810dcfa132277bc3dd3d0595baea56 Mon Sep 17 00:00:00 2001 From: robertpin Date: Wed, 22 Sep 2021 15:11:43 +0300 Subject: [PATCH] Fix stop everyone's video Stop everyone's video now also stops screensharing for the moderator that did the action, not just video --- conference.js | 17 +++++++++-------- react/features/base/tracks/actions.js | 9 ++++++--- react/features/base/tracks/middleware.js | 5 +++-- react/features/video-menu/actions.any.js | 5 +++++ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/conference.js b/conference.js index 68737e6c0..32a89eee7 100644 --- a/conference.js +++ b/conference.js @@ -1503,14 +1503,14 @@ export default { * * @param {boolean} didHaveVideo indicates if there was a camera video being * used, before switching to screen sharing. - * @param {boolean} wasVideoMuted indicates if the video was muted, before - * switching to screen sharing. + * @param {boolean} ignoreDidHaveVideo indicates if the camera video should be + * ignored when switching screen sharing off. * @return {Promise} resolved after the screen sharing is turned off, or * rejected with some error (no idea what kind of error, possible GUM error) * in case it fails. * @private */ - async _turnScreenSharingOff(didHaveVideo) { + async _turnScreenSharingOff(didHaveVideo, ignoreDidHaveVideo) { this._untoggleScreenSharing = null; this.videoSwitchInProgress = true; @@ -1554,7 +1554,7 @@ export default { APP.store.dispatch(setScreenAudioShareState(false)); - if (didHaveVideo) { + if (didHaveVideo && !ignoreDidHaveVideo) { promise = promise.then(() => createLocalTracksF({ devices: [ 'video' ] })) .then(([ stream ]) => { logger.debug(`_turnScreenSharingOff using ${stream} for useVideoStream`); @@ -1605,9 +1605,10 @@ export default { * @param {Array} [options.desktopSharingSources] - Array with the * sources that have to be displayed in the desktop picker window ('screen', * 'window', etc.). + * @param {boolean} ignoreDidHaveVideo - if true ignore if video was on when sharing started. * @return {Promise.} */ - async toggleScreenSharing(toggle = !this._untoggleScreenSharing, options = {}) { + async toggleScreenSharing(toggle = !this._untoggleScreenSharing, options = {}, ignoreDidHaveVideo) { logger.debug(`toggleScreenSharing: ${toggle}`); if (this.videoSwitchInProgress) { return Promise.reject('Switch in progress.'); @@ -1633,7 +1634,7 @@ export default { } return this._untoggleScreenSharing - ? this._untoggleScreenSharing() + ? this._untoggleScreenSharing(ignoreDidHaveVideo) : Promise.resolve(); }, @@ -2476,8 +2477,8 @@ export default { }); APP.UI.addListener( - UIEvents.TOGGLE_SCREENSHARING, ({ enabled, audioOnly }) => { - this.toggleScreenSharing(enabled, { audioOnly }); + UIEvents.TOGGLE_SCREENSHARING, ({ enabled, audioOnly, ignoreDidHaveVideo }) => { + this.toggleScreenSharing(enabled, { audioOnly }, ignoreDidHaveVideo); } ); }, diff --git a/react/features/base/tracks/actions.js b/react/features/base/tracks/actions.js index dc8541e76..3c73506dd 100644 --- a/react/features/base/tracks/actions.js +++ b/react/features/base/tracks/actions.js @@ -258,17 +258,20 @@ export function showNoDataFromSourceVideoError(jitsiTrack) { * * @param {boolean} enabled - The state to toggle screen sharing to. * @param {boolean} audioOnly - Only share system audio. + * @param {boolean} ignoreDidHaveVideo - Wether or not to ignore if video was on when sharing started. * @returns {{ * type: TOGGLE_SCREENSHARING, * on: boolean, - * audioOnly: boolean + * audioOnly: boolean, + * ignoreDidHaveVideo: boolean * }} */ -export function toggleScreensharing(enabled, audioOnly = false) { +export function toggleScreensharing(enabled, audioOnly = false, ignoreDidHaveVideo = false) { return { type: TOGGLE_SCREENSHARING, enabled, - audioOnly + audioOnly, + ignoreDidHaveVideo }; } diff --git a/react/features/base/tracks/middleware.js b/react/features/base/tracks/middleware.js index 7f6bf3f7a..56b887179 100644 --- a/react/features/base/tracks/middleware.js +++ b/react/features/base/tracks/middleware.js @@ -149,10 +149,11 @@ MiddlewareRegistry.register(store => next => action => { return; } - const { enabled, audioOnly } = action; + const { enabled, audioOnly, ignoreDidHaveVideo } = action; APP.UI.emitEvent(UIEvents.TOGGLE_SCREENSHARING, { enabled, - audioOnly }); + audioOnly, + ignoreDidHaveVideo }); } break; diff --git a/react/features/video-menu/actions.any.js b/react/features/video-menu/actions.any.js index f272c9511..5d4b835fe 100644 --- a/react/features/video-menu/actions.any.js +++ b/react/features/video-menu/actions.any.js @@ -23,6 +23,7 @@ import { getRemoteParticipants, muteRemoteParticipant } from '../base/participants'; +import { toggleScreensharing } from '../base/tracks'; import { isModerationNotificationDisplayed } from '../notifications'; declare var APP: Object; @@ -55,6 +56,10 @@ export function muteLocal(enable: boolean, mediaType: MEDIA_TYPE) { return; } + if (enable) { + dispatch(toggleScreensharing(false, false, true)); + } + sendAnalytics(createToolbarEvent(isAudio ? AUDIO_MUTE : VIDEO_MUTE, { enable })); dispatch(isAudio ? setAudioMuted(enable, /* ensureTrack */ true) : setVideoMuted(enable, mediaType, VIDEO_MUTISM_AUTHORITY.USER, /* ensureTrack */ true));