Pārlūkot izejas kodu

[RN] Fix toggling camera

When a new local video track is created an associated video capturer is created
for it. The cause for the freezes seems to be creating mutliple tracks (which
come with a video capturer each). Fix this by first disposing of the previous
video track before creating the new one.

Ref:
https://github.com/oney/react-native-webrtc/issues/209#issuecomment-281482869
j8
Saúl Ibarra Corretgé 8 gadus atpakaļ
vecāks
revīzija
f5973e0eee

+ 2
- 2
react/features/base/tracks/actions.js Parādīt failu

@@ -179,10 +179,10 @@ function _addTracks(tracks) {
179 179
  * Disposes passed tracks and signals them to be removed.
180 180
  *
181 181
  * @param {(JitsiLocalTrack|JitsiRemoteTrack)[]} tracks - List of tracks.
182
- * @private
182
+ * @protected
183 183
  * @returns {Function}
184 184
  */
185
-function _disposeAndRemoveTracks(tracks) {
185
+export function _disposeAndRemoveTracks(tracks) {
186 186
     return dispatch =>
187 187
         Promise.all(
188 188
             tracks.map(t =>

+ 16
- 2
react/features/base/tracks/middleware.js Parādīt failu

@@ -11,7 +11,11 @@ import {
11 11
 } from '../media';
12 12
 import { MiddlewareRegistry } from '../redux';
13 13
 
14
-import { createLocalTracks, destroyLocalTracks } from './actions';
14
+import {
15
+    _disposeAndRemoveTracks,
16
+    createLocalTracks,
17
+    destroyLocalTracks
18
+} from './actions';
15 19
 import { TRACK_UPDATED } from './actionTypes';
16 20
 import { getLocalTrack, setTrackMuted } from './functions';
17 21
 
@@ -37,7 +41,16 @@ MiddlewareRegistry.register(store => next => action => {
37 41
         _setMuted(store, action, MEDIA_TYPE.AUDIO);
38 42
         break;
39 43
 
40
-    case SET_CAMERA_FACING_MODE:
44
+    case SET_CAMERA_FACING_MODE: {
45
+        // XXX Destroy the local video track before creating a new one or
46
+        // react-native-webrtc may be slow or get stuck when opening a (video)
47
+        // capturer twice.
48
+        const localTrack = _getLocalTrack(store, MEDIA_TYPE.VIDEO);
49
+
50
+        if (localTrack) {
51
+            store.dispatch(_disposeAndRemoveTracks([ localTrack.jitsiTrack ]));
52
+        }
53
+
41 54
         store.dispatch(
42 55
             createLocalTracks({
43 56
                 devices: [ MEDIA_TYPE.VIDEO ],
@@ -45,6 +58,7 @@ MiddlewareRegistry.register(store => next => action => {
45 58
             })
46 59
         );
47 60
         break;
61
+    }
48 62
 
49 63
     case SET_VIDEO_MUTED:
50 64
         _setMuted(store, action, MEDIA_TYPE.VIDEO);

+ 0
- 9
react/features/toolbox/components/Toolbox.native.js Parādīt failu

@@ -184,21 +184,12 @@ class Toolbox extends Component {
184 184
 
185 185
         return (
186 186
             <View style = { styles.secondaryToolbar }>
187
-                {/* FIXME There are multiple issues with the toggling of the
188
-                  * camera facing more. For example, switching from the user
189
-                  * facing camera to the environment facing camera on iOS may be
190
-                  * very slow or may not work at all. On Android the toggling
191
-                  * either works or does not. The causes of the various problems
192
-                  * have been identified to lie within either
193
-                  * react-native-webrtc or Google's native WebRTC API.
194
-                  *
195 187
                 <ToolbarButton
196 188
                     iconName = 'switch-camera'
197 189
                     iconStyle = { iconStyle }
198 190
                     onClick = { this.props._onToggleCameraFacingMode }
199 191
                     style = { style }
200 192
                     underlayColor = { underlayColor } />
201
-                  */}
202 193
                 <ToolbarButton
203 194
                     iconName = {
204 195
                         this.props._locked ? 'security-locked' : 'security'

Notiek ielāde…
Atcelt
Saglabāt