From 3102ea6818f310c5aface521e6ea60d51de3ca71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Mon, 14 Aug 2017 15:27:24 +0200 Subject: [PATCH] [RN] Try to create local tracks when unmuting, if track is missing This is only desired when the unmuting action took place due to a manual user intervention or the audio-only mode being disengaged. --- react/features/base/conference/middleware.js | 6 +++++- react/features/base/media/actions.js | 12 ++++++++++-- react/features/base/tracks/middleware.js | 11 +++++++++-- .../features/toolbox/components/Toolbox.native.js | 15 ++++++++++++--- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/react/features/base/conference/middleware.js b/react/features/base/conference/middleware.js index d9db61b21..f98a74c30 100644 --- a/react/features/base/conference/middleware.js +++ b/react/features/base/conference/middleware.js @@ -243,7 +243,11 @@ function _setAudioOnly({ dispatch, getState }, next, action) { dispatch(setLastN(audioOnly ? 0 : undefined)); // Mute/unmute the local video. - dispatch(setVideoMuted(audioOnly, VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY)); + dispatch( + setVideoMuted( + audioOnly, + VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY, + /* ensureTrack */ true)); if (typeof APP !== 'undefined') { // TODO This should be a temporary solution that lasts only until diff --git a/react/features/base/media/actions.js b/react/features/base/media/actions.js index c7a82cf27..c54d0cede 100644 --- a/react/features/base/media/actions.js +++ b/react/features/base/media/actions.js @@ -34,14 +34,18 @@ export function setAudioAvailable(available: boolean) { * * @param {boolean} muted - True if the local audio is to be muted or false if * the local audio is to be unmuted. + * @param {boolean} ensureTrack - True if we want to ensure that a new track is + * created if missing. * @returns {{ * type: SET_AUDIO_MUTED, + * ensureTrack: boolean, * muted: boolean * }} */ -export function setAudioMuted(muted: boolean) { +export function setAudioMuted(muted: boolean, ensureTrack: boolean = false) { return { type: SET_AUDIO_MUTED, + ensureTrack, muted }; } @@ -86,11 +90,14 @@ export function setVideoAvailable(available: boolean) { * the local video is to be unmuted. * @param {number} authority - The {@link VIDEO_MUTISM_AUTHORITY} which is * muting/unmuting the local video. + * @param {boolean} ensureTrack - True if we want to ensure that a new track is + * created if missing. * @returns {Function} */ export function setVideoMuted( muted: boolean, - authority: number = VIDEO_MUTISM_AUTHORITY.USER) { + authority: number = VIDEO_MUTISM_AUTHORITY.USER, + ensureTrack: boolean = false) { return (dispatch: Dispatch<*>, getState: Function) => { const oldValue = getState()['features/base/media'].video.muted; @@ -99,6 +106,7 @@ export function setVideoMuted( return dispatch({ type: SET_VIDEO_MUTED, + ensureTrack, muted: newValue }); }; diff --git a/react/features/base/tracks/middleware.js b/react/features/base/tracks/middleware.js index a8d172a57..0cdad889e 100644 --- a/react/features/base/tracks/middleware.js +++ b/react/features/base/tracks/middleware.js @@ -11,6 +11,7 @@ import { } from '../media'; import { MiddlewareRegistry } from '../redux'; +import { createLocalTracksA } from './actions'; import { TRACK_ADDED, TRACK_REMOVED, TRACK_UPDATED } from './actionTypes'; import { getLocalTrack, setTrackMuted } from './functions'; @@ -153,8 +154,14 @@ function _getLocalTrack({ getState }, mediaType: MEDIA_TYPE) { * @private * @returns {void} */ -function _setMuted(store, { muted }, mediaType: MEDIA_TYPE) { +function _setMuted(store, { ensureTrack, muted }, mediaType: MEDIA_TYPE) { const localTrack = _getLocalTrack(store, mediaType); - localTrack && setTrackMuted(localTrack.jitsiTrack, muted); + if (localTrack) { + setTrackMuted(localTrack.jitsiTrack, muted); + } else if (!muted && ensureTrack && typeof APP === 'undefined') { + // FIXME: This only runs on mobile now because web has its own way of + // creating local tracks. Adjust the check once they are unified. + store.dispatch(createLocalTracksA({ devices: [ mediaType ] })); + } } diff --git a/react/features/toolbox/components/Toolbox.native.js b/react/features/toolbox/components/Toolbox.native.js index 587964fb7..d9700faa4 100644 --- a/react/features/toolbox/components/Toolbox.native.js +++ b/react/features/toolbox/components/Toolbox.native.js @@ -7,7 +7,8 @@ import { MEDIA_TYPE, setAudioMuted, setVideoMuted, - toggleCameraFacingMode + toggleCameraFacingMode, + VIDEO_MUTISM_AUTHORITY } from '../../base/media'; import { Container } from '../../base/react'; import { ColorPalette } from '../../base/styles'; @@ -167,7 +168,11 @@ class Toolbox extends Component { // sets the state of base/media. Whether the user's intention will turn // into reality is a whole different story which is of no concern to the // tapping. - this.props.dispatch(setAudioMuted(!this.props._audioMuted)); + this.props.dispatch( + setAudioMuted( + !this.props._audioMuted, + VIDEO_MUTISM_AUTHORITY.USER, + /* ensureTrack */ true)); } /** @@ -182,7 +187,11 @@ class Toolbox extends Component { // sets the state of base/media. Whether the user's intention will turn // into reality is a whole different story which is of no concern to the // tapping. - this.props.dispatch(setVideoMuted(!this.props._videoMuted)); + this.props.dispatch( + setVideoMuted( + !this.props._videoMuted, + VIDEO_MUTISM_AUTHORITY.USER, + /* ensureTrack */ true)); } /**