瀏覽代碼

[RN] Fix disconnecting before the connection was established

Keep track of the connection and conference objects so we can leave and / or
disconnect early, before the connection is established or the conference joined.
master
Saúl Ibarra Corretgé 8 年之前
父節點
當前提交
c4232b34ae

+ 2
- 1
react/features/base/conference/actionTypes.js 查看文件

36
  *
36
  *
37
  * {
37
  * {
38
  *     type: CONFERENCE_WILL_JOIN,
38
  *     type: CONFERENCE_WILL_JOIN,
39
- *     room: string
39
+ *     room: string,
40
+ *     conference: JitsiConference
40
  * }
41
  * }
41
  */
42
  */
42
 export const CONFERENCE_WILL_JOIN = Symbol('CONFERENCE_WILL_JOIN');
43
 export const CONFERENCE_WILL_JOIN = Symbol('CONFERENCE_WILL_JOIN');

+ 9
- 5
react/features/base/conference/actions.js 查看文件

200
  *
200
  *
201
  * @param {string} room - The room (name) which identifies the conference the
201
  * @param {string} room - The room (name) which identifies the conference the
202
  * local participant will (try to) join.
202
  * local participant will (try to) join.
203
+ * @param {JitsiConference} conference - The JitsiConference instance the
204
+ * local participant will (try to) join.
203
  * @returns {{
205
  * @returns {{
204
  *     type: CONFERENCE_WILL_JOIN,
206
  *     type: CONFERENCE_WILL_JOIN,
205
- *     room: string
207
+ *     room: string,
208
+*      conference: JitsiConference
206
  * }}
209
  * }}
207
  */
210
  */
208
-function _conferenceWillJoin(room) {
211
+function _conferenceWillJoin(room, conference) {
209
     return {
212
     return {
210
         type: CONFERENCE_WILL_JOIN,
213
         type: CONFERENCE_WILL_JOIN,
211
-        room
214
+        room,
215
+        conference
212
     };
216
     };
213
 }
217
 }
214
 
218
 
252
             throw new Error('Cannot join conference without room name');
256
             throw new Error('Cannot join conference without room name');
253
         }
257
         }
254
 
258
 
255
-        dispatch(_conferenceWillJoin(room));
256
-
257
         const conference
259
         const conference
258
             = connection.initJitsiConference(
260
             = connection.initJitsiConference(
259
 
261
 
261
                 room.toLowerCase(),
263
                 room.toLowerCase(),
262
                 state['features/base/config']);
264
                 state['features/base/config']);
263
 
265
 
266
+        dispatch(_conferenceWillJoin(room, conference));
267
+
264
         _addConferenceListeners(conference, dispatch);
268
         _addConferenceListeners(conference, dispatch);
265
 
269
 
266
         _setLocalParticipantData(conference, state);
270
         _setLocalParticipantData(conference, state);

+ 21
- 0
react/features/base/conference/reducer.js 查看文件

7
     CONFERENCE_FAILED,
7
     CONFERENCE_FAILED,
8
     CONFERENCE_JOINED,
8
     CONFERENCE_JOINED,
9
     CONFERENCE_LEFT,
9
     CONFERENCE_LEFT,
10
+    CONFERENCE_WILL_JOIN,
10
     CONFERENCE_WILL_LEAVE,
11
     CONFERENCE_WILL_LEAVE,
11
     LOCK_STATE_CHANGED,
12
     LOCK_STATE_CHANGED,
12
     SET_AUDIO_ONLY,
13
     SET_AUDIO_ONLY,
32
     case CONFERENCE_LEFT:
33
     case CONFERENCE_LEFT:
33
         return _conferenceLeft(state, action);
34
         return _conferenceLeft(state, action);
34
 
35
 
36
+    case CONFERENCE_WILL_JOIN:
37
+        return _conferenceWillJoin(state, action);
38
+
35
     case CONFERENCE_WILL_LEAVE:
39
     case CONFERENCE_WILL_LEAVE:
36
         return _conferenceWillLeave(state, action);
40
         return _conferenceWillLeave(state, action);
37
 
41
 
84
             audioOnly: undefined,
88
             audioOnly: undefined,
85
             audioOnlyVideoMuted: undefined,
89
             audioOnlyVideoMuted: undefined,
86
             conference: undefined,
90
             conference: undefined,
91
+            joining: undefined,
87
             leaving: undefined,
92
             leaving: undefined,
88
 
93
 
89
             /**
94
             /**
133
              * @type {JitsiConference}
138
              * @type {JitsiConference}
134
              */
139
              */
135
             conference,
140
             conference,
141
+            joining: undefined,
136
             leaving: undefined,
142
             leaving: undefined,
137
 
143
 
138
             /**
144
             /**
167
             audioOnly: undefined,
173
             audioOnly: undefined,
168
             audioOnlyVideoMuted: undefined,
174
             audioOnlyVideoMuted: undefined,
169
             conference: undefined,
175
             conference: undefined,
176
+            joining: undefined,
170
             leaving: undefined,
177
             leaving: undefined,
171
             locked: undefined,
178
             locked: undefined,
172
             password: undefined,
179
             password: undefined,
174
         }));
181
         }));
175
 }
182
 }
176
 
183
 
184
+/**
185
+ * Reduces a specific Redux action CONFERENCE_WILL_JOIN of the feature
186
+ * base/conference.
187
+ *
188
+ * @param {Object} state - The Redux state of the feature base/conference.
189
+ * @param {Action} action - The Redux action CONFERENCE_WILL_JOIN to reduce.
190
+ * @private
191
+ * @returns {Object} The new state of the feature base/conference after the
192
+ * reduction of the specified action.
193
+ */
194
+function _conferenceWillJoin(state, action) {
195
+    return set(state, 'joining', action.conference);
196
+}
197
+
177
 /**
198
 /**
178
  * Reduces a specific Redux action CONFERENCE_WILL_LEAVE of the feature
199
  * Reduces a specific Redux action CONFERENCE_WILL_LEAVE of the feature
179
  * base/conference.
200
  * base/conference.

+ 10
- 0
react/features/base/connection/actionTypes.js 查看文件

32
  */
32
  */
33
 export const CONNECTION_FAILED = Symbol('CONNECTION_FAILED');
33
 export const CONNECTION_FAILED = Symbol('CONNECTION_FAILED');
34
 
34
 
35
+/**
36
+ * The type of (redux) action which signals that a connection will connect.
37
+ *
38
+ * {
39
+ *     type: CONNECTION_WILL_CONNECT,
40
+ *     connection: JitsiConnection
41
+ * }
42
+ */
43
+export const CONNECTION_WILL_CONNECT = Symbol('CONNECTION_WILL_CONNECT');
44
+
35
 /**
45
 /**
36
  * The type of (redux) action which sets the location URL of the application,
46
  * The type of (redux) action which sets the location URL of the application,
37
  * connection, conference, etc.
47
  * connection, conference, etc.

+ 35
- 7
react/features/base/connection/actions.native.js 查看文件

9
     CONNECTION_DISCONNECTED,
9
     CONNECTION_DISCONNECTED,
10
     CONNECTION_ESTABLISHED,
10
     CONNECTION_ESTABLISHED,
11
     CONNECTION_FAILED,
11
     CONNECTION_FAILED,
12
+    CONNECTION_WILL_CONNECT,
12
     SET_LOCATION_URL
13
     SET_LOCATION_URL
13
 } from './actionTypes';
14
 } from './actionTypes';
14
 
15
 
49
                 jwt && issuer && issuer !== 'anonymous' ? jwt : undefined,
50
                 jwt && issuer && issuer !== 'anonymous' ? jwt : undefined,
50
                 options);
51
                 options);
51
 
52
 
53
+        dispatch(_connectionWillConnect(connection));
54
+
52
         connection.addEventListener(
55
         connection.addEventListener(
53
             JitsiConnectionEvents.CONNECTION_DISCONNECTED,
56
             JitsiConnectionEvents.CONNECTION_DISCONNECTED,
54
             _onConnectionDisconnected);
57
             _onConnectionDisconnected);
138
     };
141
     };
139
 }
142
 }
140
 
143
 
144
+/**
145
+ * Create an action for when a connection will connect.
146
+ *
147
+ * @param {JitsiConnection} connection - The JitsiConnection which will connect.
148
+ * @private
149
+ * @returns {{
150
+ *     type: CONNECTION_WILL_CONNECT,
151
+ *     connection: JitsiConnection
152
+ * }}
153
+ */
154
+function _connectionWillConnect(connection) {
155
+    return {
156
+        type: CONNECTION_WILL_CONNECT,
157
+        connection
158
+    };
159
+}
160
+
141
 /**
161
 /**
142
  * Create an action for when the signaling connection has been established.
162
  * Create an action for when the signaling connection has been established.
143
  *
163
  *
190
 export function disconnect() {
210
 export function disconnect() {
191
     return (dispatch: Dispatch<*>, getState: Function) => {
211
     return (dispatch: Dispatch<*>, getState: Function) => {
192
         const state = getState();
212
         const state = getState();
193
-        const { conference } = state['features/base/conference'];
194
-        const { connection } = state['features/base/connection'];
213
+        const { conference, joining } = state['features/base/conference'];
214
+        const { connection, connecting } = state['features/base/connection'];
215
+
216
+        // The conference we are joining or have already joined.
217
+        const _conference = joining || conference;
218
+
219
+        // The connection we are connecting or have already connected.
220
+        const _connection = connecting || connection;
195
 
221
 
222
+        // Promise which completes when the conference has been left and the
223
+        // connection has been disconnected.
196
         let promise;
224
         let promise;
197
 
225
 
198
         // Leave the conference.
226
         // Leave the conference.
199
-        if (conference) {
227
+        if (_conference) {
200
             // In a fashion similar to JitsiConference's CONFERENCE_LEFT event
228
             // In a fashion similar to JitsiConference's CONFERENCE_LEFT event
201
             // (and the respective Redux action) which is fired after the
229
             // (and the respective Redux action) which is fired after the
202
             // conference has been left, notify the application about the
230
             // conference has been left, notify the application about the
203
             // intention to leave the conference.
231
             // intention to leave the conference.
204
-            dispatch(conferenceWillLeave(conference));
232
+            dispatch(conferenceWillLeave(_conference));
205
 
233
 
206
-            promise = conference.leave();
234
+            promise = _conference.leave();
207
         } else {
235
         } else {
208
             promise = Promise.resolve();
236
             promise = Promise.resolve();
209
         }
237
         }
210
 
238
 
211
         // Disconnect the connection.
239
         // Disconnect the connection.
212
-        if (connection) {
213
-            promise = promise.then(() => connection.disconnect());
240
+        if (_connection) {
241
+            promise = promise.then(() => _connection.disconnect());
214
         }
242
         }
215
 
243
 
216
         return promise;
244
         return promise;

+ 44
- 1
react/features/base/connection/reducer.js 查看文件

5
 import {
5
 import {
6
     CONNECTION_DISCONNECTED,
6
     CONNECTION_DISCONNECTED,
7
     CONNECTION_ESTABLISHED,
7
     CONNECTION_ESTABLISHED,
8
+    CONNECTION_FAILED,
9
+    CONNECTION_WILL_CONNECT,
8
     SET_LOCATION_URL
10
     SET_LOCATION_URL
9
 } from './actionTypes';
11
 } from './actionTypes';
10
 
12
 
21
         case CONNECTION_ESTABLISHED:
23
         case CONNECTION_ESTABLISHED:
22
             return _connectionEstablished(state, action);
24
             return _connectionEstablished(state, action);
23
 
25
 
26
+        case CONNECTION_FAILED:
27
+            return _connectionFailed(state, action);
28
+
29
+        case CONNECTION_WILL_CONNECT:
30
+            return _connectionWillConnect(state, action);
31
+
24
         case SET_LOCATION_URL:
32
         case SET_LOCATION_URL:
25
             return _setLocationURL(state, action);
33
             return _setLocationURL(state, action);
26
         }
34
         }
61
 function _connectionEstablished(
69
 function _connectionEstablished(
62
         state: Object,
70
         state: Object,
63
         { connection }: { connection: Object }) {
71
         { connection }: { connection: Object }) {
64
-    return set(state, 'connection', connection);
72
+    return assign(state, {
73
+        connecting: undefined,
74
+        connection
75
+    });
76
+}
77
+
78
+/* eslint-disable no-unused-vars */
79
+
80
+/**
81
+ * Reduces a specific Redux action CONNECTION_FAILED of the feature
82
+ * base/connection.
83
+ *
84
+ * @param {Object} state - The Redux state of the feature base/connection.
85
+ * @param {Action} action - The Redux action CONNECTION_FAILED to reduce.
86
+ * @private
87
+ * @returns {Object} The new state of the feature base/connection after the
88
+ * reduction of the specified action.
89
+ */
90
+function _connectionFailed(state: Object, action: Object) {
91
+    return set(state, 'connecting', undefined);
92
+}
93
+
94
+/* eslint-enable no-unused-vars */
95
+
96
+/**
97
+ * Reduces a specific Redux action CONNECTION_WILL_CONNECT of the feature
98
+ * base/connection.
99
+ *
100
+ * @param {Object} state - The Redux state of the feature base/connection.
101
+ * @param {Action} action - The Redux action CONNECTION_WILL_CONNECT to reduce.
102
+ * @private
103
+ * @returns {Object} The new state of the feature base/connection after the
104
+ * reduction of the specified action.
105
+ */
106
+function _connectionWillConnect(state: Object, action: Object) {
107
+    return set(state, 'connecting', action.connection);
65
 }
108
 }
66
 
109
 
67
 /**
110
 /**

Loading…
取消
儲存