Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

[RN] Try to create local tracks when unmuting, if track is missing

Saúl Ibarra Corretgé3102ea6818f3
diff --git a/react/features/base/conference/middleware.js b/react/features/base/conference/middleware.js
index d9db61b21f..f98a74c306 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 c7a82cf27d..c54d0cedeb 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 a8d172a57c..0cdad889ed 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 587964fb7e..d9700faa42 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));
}
/**