Przeglądaj źródła

[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.
master
Saúl Ibarra Corretgé 7 lat temu
rodzic
commit
3102ea6818

+ 5
- 1
react/features/base/conference/middleware.js Wyświetl plik

@@ -243,7 +243,11 @@ function _setAudioOnly({ dispatch, getState }, next, action) {
243 243
     dispatch(setLastN(audioOnly ? 0 : undefined));
244 244
 
245 245
     // Mute/unmute the local video.
246
-    dispatch(setVideoMuted(audioOnly, VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY));
246
+    dispatch(
247
+        setVideoMuted(
248
+            audioOnly,
249
+            VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY,
250
+            /* ensureTrack */ true));
247 251
 
248 252
     if (typeof APP !== 'undefined') {
249 253
         // TODO This should be a temporary solution that lasts only until

+ 10
- 2
react/features/base/media/actions.js Wyświetl plik

@@ -34,14 +34,18 @@ export function setAudioAvailable(available: boolean) {
34 34
  *
35 35
  * @param {boolean} muted - True if the local audio is to be muted or false if
36 36
  * the local audio is to be unmuted.
37
+ * @param {boolean} ensureTrack - True if we want to ensure that a new track is
38
+ * created if missing.
37 39
  * @returns {{
38 40
  *     type: SET_AUDIO_MUTED,
41
+ *     ensureTrack: boolean,
39 42
  *     muted: boolean
40 43
  * }}
41 44
  */
42
-export function setAudioMuted(muted: boolean) {
45
+export function setAudioMuted(muted: boolean, ensureTrack: boolean = false) {
43 46
     return {
44 47
         type: SET_AUDIO_MUTED,
48
+        ensureTrack,
45 49
         muted
46 50
     };
47 51
 }
@@ -86,11 +90,14 @@ export function setVideoAvailable(available: boolean) {
86 90
  * the local video is to be unmuted.
87 91
  * @param {number} authority - The {@link VIDEO_MUTISM_AUTHORITY} which is
88 92
  * muting/unmuting the local video.
93
+ * @param {boolean} ensureTrack - True if we want to ensure that a new track is
94
+ * created if missing.
89 95
  * @returns {Function}
90 96
  */
91 97
 export function setVideoMuted(
92 98
         muted: boolean,
93
-        authority: number = VIDEO_MUTISM_AUTHORITY.USER) {
99
+        authority: number = VIDEO_MUTISM_AUTHORITY.USER,
100
+        ensureTrack: boolean = false) {
94 101
     return (dispatch: Dispatch<*>, getState: Function) => {
95 102
         const oldValue = getState()['features/base/media'].video.muted;
96 103
 
@@ -99,6 +106,7 @@ export function setVideoMuted(
99 106
 
100 107
         return dispatch({
101 108
             type: SET_VIDEO_MUTED,
109
+            ensureTrack,
102 110
             muted: newValue
103 111
         });
104 112
     };

+ 9
- 2
react/features/base/tracks/middleware.js Wyświetl plik

@@ -11,6 +11,7 @@ import {
11 11
 } from '../media';
12 12
 import { MiddlewareRegistry } from '../redux';
13 13
 
14
+import { createLocalTracksA } from './actions';
14 15
 import { TRACK_ADDED, TRACK_REMOVED, TRACK_UPDATED } from './actionTypes';
15 16
 import { getLocalTrack, setTrackMuted } from './functions';
16 17
 
@@ -153,8 +154,14 @@ function _getLocalTrack({ getState }, mediaType: MEDIA_TYPE) {
153 154
  * @private
154 155
  * @returns {void}
155 156
  */
156
-function _setMuted(store, { muted }, mediaType: MEDIA_TYPE) {
157
+function _setMuted(store, { ensureTrack, muted }, mediaType: MEDIA_TYPE) {
157 158
     const localTrack = _getLocalTrack(store, mediaType);
158 159
 
159
-    localTrack && setTrackMuted(localTrack.jitsiTrack, muted);
160
+    if (localTrack) {
161
+        setTrackMuted(localTrack.jitsiTrack, muted);
162
+    } else if (!muted && ensureTrack && typeof APP === 'undefined') {
163
+        // FIXME: This only runs on mobile now because web has its own way of
164
+        // creating local tracks. Adjust the check once they are unified.
165
+        store.dispatch(createLocalTracksA({ devices: [ mediaType ] }));
166
+    }
160 167
 }

+ 12
- 3
react/features/toolbox/components/Toolbox.native.js Wyświetl plik

@@ -7,7 +7,8 @@ import {
7 7
     MEDIA_TYPE,
8 8
     setAudioMuted,
9 9
     setVideoMuted,
10
-    toggleCameraFacingMode
10
+    toggleCameraFacingMode,
11
+    VIDEO_MUTISM_AUTHORITY
11 12
 } from '../../base/media';
12 13
 import { Container } from '../../base/react';
13 14
 import { ColorPalette } from '../../base/styles';
@@ -167,7 +168,11 @@ class Toolbox extends Component {
167 168
         // sets the state of base/media. Whether the user's intention will turn
168 169
         // into reality is a whole different story which is of no concern to the
169 170
         // tapping.
170
-        this.props.dispatch(setAudioMuted(!this.props._audioMuted));
171
+        this.props.dispatch(
172
+            setAudioMuted(
173
+                !this.props._audioMuted,
174
+                VIDEO_MUTISM_AUTHORITY.USER,
175
+                /* ensureTrack */ true));
171 176
     }
172 177
 
173 178
     /**
@@ -182,7 +187,11 @@ class Toolbox extends Component {
182 187
         // sets the state of base/media. Whether the user's intention will turn
183 188
         // into reality is a whole different story which is of no concern to the
184 189
         // tapping.
185
-        this.props.dispatch(setVideoMuted(!this.props._videoMuted));
190
+        this.props.dispatch(
191
+            setVideoMuted(
192
+                !this.props._videoMuted,
193
+                VIDEO_MUTISM_AUTHORITY.USER,
194
+                /* ensureTrack */ true));
186 195
     }
187 196
 
188 197
     /**

Ładowanie…
Anuluj
Zapisz