Просмотр исходного кода

[RN] Don't open the camera on startup when there is no welcome page

The end goal of this patch was to avoid opening the camera when there is no
welcome page.

In order to achieve this, the logic for creating the local tracks was
refactored:

Before this patch local tracks were created when lib-jitsi-meet was initialized,
and destroyed when it was deinitialized. As a side note, this meant that when a
conference in a non-default domain was joined, local tracks were destroyed and
recreated in quick succession.

Now, local trans are created and destroyed based on what the next route will be,
and this happens when the target room has been decided. This allows us to create
local tracks the moment we need to render any route, and destroy them when there
is no route to be rendered. As an interesting byproduct, this refactor also
avoids the destruction + recreation of local tracks when a conference in a
non-default domain was left.
j8
Saúl Ibarra Corretgé 8 лет назад
Родитель
Сommit
8225600b61
2 измененных файлов: 53 добавлений и 22 удалений
  1. 53
    9
      react/features/app/middleware.js
  2. 0
    13
      react/features/base/tracks/middleware.js

+ 53
- 9
react/features/app/middleware.js Просмотреть файл

@@ -5,6 +5,7 @@ import {
5 5
     SET_LOCATION_URL
6 6
 } from '../base/connection';
7 7
 import { MiddlewareRegistry } from '../base/redux';
8
+import { createInitialLocalTracks, destroyLocalTracks } from '../base/tracks';
8 9
 
9 10
 MiddlewareRegistry.register(store => next => action => {
10 11
     switch (action.type) {
@@ -12,8 +13,10 @@ MiddlewareRegistry.register(store => next => action => {
12 13
         return _connectionEstablished(store, next, action);
13 14
 
14 15
     case SET_LOCATION_URL:
16
+        return _setLocationURL(store, next, action);
17
+
15 18
     case SET_ROOM:
16
-        return _setLocationURLOrRoom(store, next, action);
19
+        return _setRoom(store, next, action);
17 20
     }
18 21
 
19 22
     return next(action);
@@ -63,36 +66,77 @@ function _connectionEstablished(store, next, action) {
63 66
 /**
64 67
  * Navigates to a route in accord with a specific redux state.
65 68
  *
66
- * @param {Object} state - The redux state which determines/identifies the route
69
+ * @param {Store} store - The redux store which determines/identifies the route
67 70
  * to navigate to.
68 71
  * @private
69 72
  * @returns {void}
70 73
  */
71
-function _navigate(state) {
74
+function _navigate({ dispatch, getState }) {
75
+    const state = getState();
72 76
     const { app, getRouteToRender } = state['features/app'];
73 77
     const routeToRender = getRouteToRender && getRouteToRender(state);
74 78
 
79
+    // Create/destroy the local tracks as needed: create them the first time we
80
+    // are going to render an actual route (be that the WelcomePage or the
81
+    // Conference).
82
+    //
83
+    // When the WelcomePage is disabled, the app will transition to the
84
+    // null/undefined route. Detect these transitions and create/destroy the
85
+    // local tracks so the camera doesn't stay open if the app is not rendering
86
+    // any component.
87
+    if (typeof routeToRender === 'undefined' || routeToRender === null) {
88
+        // Destroy the local tracks if there is no route to render and there is
89
+        // no welcome page.
90
+        app.props.welcomePageEnabled || dispatch(destroyLocalTracks());
91
+    } else {
92
+        // Create the local tracks if they haven't been created yet.
93
+        state['features/base/tracks'].some(t => t.local)
94
+            || dispatch(createInitialLocalTracks());
95
+    }
96
+
75 97
     app._navigate(routeToRender);
76 98
 }
77 99
 
78 100
 /**
79
- * Notifies the feature app that the action {@link SET_LOCATION_URL} or
80
- * {@link SET_ROOM} is being dispatched within a specific redux {@code store}.
101
+ * Notifies the feature app that the action {@link SET_LOCATION_URL} is being
102
+ * dispatched within a specific redux {@code store}.
103
+ *
104
+ * @param {Store} store - The redux store in which the specified {@code action}
105
+ * is being dispatched.
106
+ * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
107
+ * specified {@code action} to the specified {@code store}.
108
+ * @param {Action} action - The redux action, {@code SET_LOCATION_URL}, which is
109
+ * being dispatched in the specified {@code store}.
110
+ * @private
111
+ * @returns {Object} The new state that is the result of the reduction of the
112
+ * specified {@code action}.
113
+ */
114
+function _setLocationURL({ getState }, next, action) {
115
+    const result = next(action);
116
+
117
+    getState()['features/app'].app._navigate(undefined);
118
+
119
+    return result;
120
+}
121
+
122
+/**
123
+ * Notifies the feature app that the action {@link SET_ROOM} is being dispatched
124
+ * within a specific redux {@code store}.
81 125
  *
82 126
  * @param {Store} store - The redux store in which the specified {@code action}
83 127
  * is being dispatched.
84 128
  * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
85 129
  * specified {@code action} to the specified {@code store}.
86
- * @param {Action} action - The redux action {@code SET_LOCATION_URL} or
87
- * {@code SET_ROOM} which is being dispatched in the specified {@code store}.
130
+ * @param {Action} action - The redux action, {@code SET_ROOM}, which is being
131
+ * dispatched in the specified {@code store}.
88 132
  * @private
89 133
  * @returns {Object} The new state that is the result of the reduction of the
90 134
  * specified {@code action}.
91 135
  */
92
-function _setLocationURLOrRoom({ getState }, next, action) {
136
+function _setRoom(store, next, action) {
93 137
     const result = next(action);
94 138
 
95
-    _navigate(getState());
139
+    _navigate(store);
96 140
 
97 141
     return result;
98 142
 }

+ 0
- 13
react/features/base/tracks/middleware.js Просмотреть файл

@@ -1,6 +1,5 @@
1 1
 /* @flow */
2 2
 
3
-import { LIB_DID_DISPOSE, LIB_DID_INIT } from '../lib-jitsi-meet';
4 3
 import {
5 4
     CAMERA_FACING_MODE,
6 5
     MEDIA_TYPE,
@@ -14,10 +13,6 @@ import {
14 13
 } from '../media';
15 14
 import { MiddlewareRegistry } from '../redux';
16 15
 
17
-import {
18
-    createInitialLocalTracks,
19
-    destroyLocalTracks
20
-} from './actions';
21 16
 import { TRACK_ADDED, TRACK_REMOVED, TRACK_UPDATED } from './actionTypes';
22 17
 import { getLocalTrack, setTrackMuted } from './functions';
23 18
 
@@ -33,14 +28,6 @@ declare var APP: Object;
33 28
  */
34 29
 MiddlewareRegistry.register(store => next => action => {
35 30
     switch (action.type) {
36
-    case LIB_DID_DISPOSE:
37
-        store.dispatch(destroyLocalTracks());
38
-        break;
39
-
40
-    case LIB_DID_INIT:
41
-        store.dispatch(createInitialLocalTracks());
42
-        break;
43
-
44 31
     case SET_AUDIO_MUTED:
45 32
         _setMuted(store, action, MEDIA_TYPE.AUDIO);
46 33
         break;

Загрузка…
Отмена
Сохранить