Browse Source

[RN] Fix disconnecting before the connection was established

master
Lyubo Marinov 8 years ago
parent
commit
5c094bf6e0

+ 0
- 1
react/features/base/conference/actionTypes.js View File

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

+ 7
- 12
react/features/base/conference/actions.js View File

@@ -195,23 +195,18 @@ export function conferenceLeft(conference) {
195 195
 
196 196
 /**
197 197
  * Signals the intention of the application to have the local participant join a
198
- * conference with a specific room (name). Similar in fashion
199
- * to CONFERENCE_JOINED.
198
+ * specific conference. Similar in fashion to {@code CONFERENCE_JOINED}.
200 199
  *
201
- * @param {string} room - The room (name) which identifies the conference the
202
- * local participant will (try to) join.
203 200
  * @param {JitsiConference} conference - The JitsiConference instance the
204 201
  * local participant will (try to) join.
205 202
  * @returns {{
206 203
  *     type: CONFERENCE_WILL_JOIN,
207
- *     room: string,
208
-*      conference: JitsiConference
204
+ *     conference: JitsiConference
209 205
  * }}
210 206
  */
211
-function _conferenceWillJoin(room, conference) {
207
+function _conferenceWillJoin(conference) {
212 208
     return {
213 209
         type: CONFERENCE_WILL_JOIN,
214
-        room,
215 210
         conference
216 211
     };
217 212
 }
@@ -247,13 +242,13 @@ export function createConference() {
247 242
         const connection = state['features/base/connection'].connection;
248 243
 
249 244
         if (!connection) {
250
-            throw new Error('Cannot create conference without connection');
245
+            throw new Error('Cannot create a conference without a connection!');
251 246
         }
252 247
 
253 248
         const { password, room } = state['features/base/conference'];
254 249
 
255
-        if (typeof room === 'undefined' || room === '') {
256
-            throw new Error('Cannot join conference without room name');
250
+        if (!room) {
251
+            throw new Error('Cannot join a conference without a room name!');
257 252
         }
258 253
 
259 254
         const conference
@@ -263,7 +258,7 @@ export function createConference() {
263 258
                 room.toLowerCase(),
264 259
                 state['features/base/config']);
265 260
 
266
-        dispatch(_conferenceWillJoin(room, conference));
261
+        dispatch(_conferenceWillJoin(conference));
267 262
 
268 263
         _addConferenceListeners(conference, dispatch);
269 264
 

+ 91
- 110
react/features/base/conference/reducer.js View File

@@ -71,43 +71,40 @@ ReducerRegistry.register('features/base/conference', (state = {}, action) => {
71 71
  * @returns {Object} The new state of the feature base/conference after the
72 72
  * reduction of the specified action.
73 73
  */
74
-function _conferenceFailed(state, action) {
75
-    const conference = action.conference;
76
-
74
+function _conferenceFailed(state, { conference, error }) {
77 75
     if (state.conference && state.conference !== conference) {
78 76
         return state;
79 77
     }
80 78
 
81 79
     const passwordRequired
82
-        = JitsiConferenceErrors.PASSWORD_REQUIRED === action.error
80
+        = JitsiConferenceErrors.PASSWORD_REQUIRED === error
83 81
             ? conference
84 82
             : undefined;
85 83
 
86
-    return (
87
-        assign(state, {
88
-            audioOnly: undefined,
89
-            audioOnlyVideoMuted: undefined,
90
-            conference: undefined,
91
-            joining: undefined,
92
-            leaving: undefined,
93
-
94
-            /**
95
-             * The indicator of how the conference/room is locked. If falsy, the
96
-             * conference/room is unlocked; otherwise, it's either
97
-             * {@code LOCKED_LOCALLY} or {@code LOCKED_REMOTELY}.
98
-             *
99
-             * @type {string}
100
-             */
101
-            locked: passwordRequired ? LOCKED_REMOTELY : undefined,
102
-            password: undefined,
103
-
104
-            /**
105
-             * The JitsiConference instance which requires a password to join.
106
-             *
107
-             * @type {JitsiConference}
108
-             */
109
-            passwordRequired
110
-        }));
84
+    return assign(state, {
85
+        audioOnly: undefined,
86
+        audioOnlyVideoMuted: undefined,
87
+        conference: undefined,
88
+        joining: undefined,
89
+        leaving: undefined,
90
+
91
+        /**
92
+         * The indicator of how the conference/room is locked. If falsy, the
93
+         * conference/room is unlocked; otherwise, it's either
94
+         * {@code LOCKED_LOCALLY} or {@code LOCKED_REMOTELY}.
95
+         *
96
+         * @type {string}
97
+         */
98
+        locked: passwordRequired ? LOCKED_REMOTELY : undefined,
99
+        password: undefined,
100
+
101
+        /**
102
+         * The JitsiConference instance which requires a password to join.
103
+         *
104
+         * @type {JitsiConference}
105
+         */
106
+        passwordRequired
107
+    });
111 108
 }
112 109
 
113 110
 /**
@@ -120,35 +117,32 @@ function _conferenceFailed(state, action) {
120 117
  * @returns {Object} The new state of the feature base/conference after the
121 118
  * reduction of the specified action.
122 119
  */
123
-function _conferenceJoined(state, action) {
124
-    const conference = action.conference;
125
-
120
+function _conferenceJoined(state, { conference }) {
126 121
     // FIXME The indicator which determines whether a JitsiConference is locked
127 122
     // i.e. password-protected is private to lib-jitsi-meet. However, the
128 123
     // library does not fire LOCK_STATE_CHANGED upon joining a JitsiConference
129 124
     // with a password.
130 125
     const locked = conference.room.locked ? LOCKED_REMOTELY : undefined;
131 126
 
132
-    return (
133
-        assign(state, {
134
-            /**
135
-             * The JitsiConference instance represented by the Redux state of
136
-             * the feature base/conference.
137
-             *
138
-             * @type {JitsiConference}
139
-             */
140
-            conference,
141
-            joining: undefined,
142
-            leaving: undefined,
143
-
144
-            /**
145
-             * The indicator which determines whether the conference is locked.
146
-             *
147
-             * @type {boolean}
148
-             */
149
-            locked,
150
-            passwordRequired: undefined
151
-        }));
127
+    return assign(state, {
128
+        /**
129
+         * The JitsiConference instance represented by the Redux state of the
130
+         * feature base/conference.
131
+         *
132
+         * @type {JitsiConference}
133
+         */
134
+        conference,
135
+        joining: undefined,
136
+        leaving: undefined,
137
+
138
+        /**
139
+         * The indicator which determines whether the conference is locked.
140
+         *
141
+         * @type {boolean}
142
+         */
143
+        locked,
144
+        passwordRequired: undefined
145
+    });
152 146
 }
153 147
 
154 148
 /**
@@ -161,24 +155,21 @@ function _conferenceJoined(state, action) {
161 155
  * @returns {Object} The new state of the feature base/conference after the
162 156
  * reduction of the specified action.
163 157
  */
164
-function _conferenceLeft(state, action) {
165
-    const conference = action.conference;
166
-
158
+function _conferenceLeft(state, { conference }) {
167 159
     if (state.conference !== conference) {
168 160
         return state;
169 161
     }
170 162
 
171
-    return (
172
-        assign(state, {
173
-            audioOnly: undefined,
174
-            audioOnlyVideoMuted: undefined,
175
-            conference: undefined,
176
-            joining: undefined,
177
-            leaving: undefined,
178
-            locked: undefined,
179
-            password: undefined,
180
-            passwordRequired: undefined
181
-        }));
163
+    return assign(state, {
164
+        audioOnly: undefined,
165
+        audioOnlyVideoMuted: undefined,
166
+        conference: undefined,
167
+        joining: undefined,
168
+        leaving: undefined,
169
+        locked: undefined,
170
+        password: undefined,
171
+        passwordRequired: undefined
172
+    });
182 173
 }
183 174
 
184 175
 /**
@@ -191,8 +182,8 @@ function _conferenceLeft(state, action) {
191 182
  * @returns {Object} The new state of the feature base/conference after the
192 183
  * reduction of the specified action.
193 184
  */
194
-function _conferenceWillJoin(state, action) {
195
-    return set(state, 'joining', action.conference);
185
+function _conferenceWillJoin(state, { conference }) {
186
+    return set(state, 'joining', conference);
196 187
 }
197 188
 
198 189
 /**
@@ -205,24 +196,23 @@ function _conferenceWillJoin(state, action) {
205 196
  * @returns {Object} The new state of the feature base/conference after the
206 197
  * reduction of the specified action.
207 198
  */
208
-function _conferenceWillLeave(state, action) {
209
-    const conference = action.conference;
210
-
199
+function _conferenceWillLeave(state, { conference }) {
211 200
     if (state.conference !== conference) {
212 201
         return state;
213 202
     }
214 203
 
215
-    return (
216
-        assign(state, {
217
-            /**
218
-             * The JitsiConference instance which is currently in the process of
219
-             * being left.
220
-             *
221
-             * @type {JitsiConference}
222
-             */
223
-            leaving: conference,
224
-            passwordRequired: undefined
225
-        }));
204
+    return assign(state, {
205
+        joining: undefined,
206
+
207
+        /**
208
+         * The JitsiConference instance which is currently in the process of
209
+         * being left.
210
+         *
211
+         * @type {JitsiConference}
212
+         */
213
+        leaving: conference,
214
+        passwordRequired: undefined
215
+    });
226 216
 }
227 217
 
228 218
 /**
@@ -235,20 +225,14 @@ function _conferenceWillLeave(state, action) {
235 225
  * @returns {Object} The new state of the feature base/conference after the
236 226
  * reduction of the specified action.
237 227
  */
238
-function _lockStateChanged(state, action) {
239
-    if (state.conference !== action.conference) {
228
+function _lockStateChanged(state, { conference, locked }) {
229
+    if (state.conference !== conference) {
240 230
         return state;
241 231
     }
242 232
 
243
-    let locked;
244
-
245
-    if (action.locked) {
246
-        locked = state.locked || LOCKED_REMOTELY;
247
-    }
248
-
249 233
     return assign(state, {
250
-        locked,
251
-        password: action.locked ? state.password : null
234
+        locked: locked ? state.locked || LOCKED_REMOTELY : undefined,
235
+        password: locked ? state.password : undefined
252 236
     });
253 237
 }
254 238
 
@@ -305,31 +289,28 @@ function _setLargeVideoHDStatus(state, action) {
305 289
  * @returns {Object} The new state of the feature base/conference after the
306 290
  * reduction of the specified action.
307 291
  */
308
-function _setPassword(state, action) {
309
-    const conference = action.conference;
310
-
311
-    switch (action.method) {
292
+function _setPassword(state, { conference, method, password }) {
293
+    switch (method) {
312 294
     case conference.join:
313 295
         if (state.passwordRequired === conference) {
314
-            return (
315
-                assign(state, {
316
-                    locked: LOCKED_REMOTELY,
317
-
318
-                    /**
319
-                     * The password with which the conference is to be joined.
320
-                     *
321
-                     * @type {string}
322
-                     */
323
-                    password: action.password,
324
-                    passwordRequired: undefined
325
-                }));
296
+            return assign(state, {
297
+                locked: LOCKED_REMOTELY,
298
+
299
+                /**
300
+                 * The password with which the conference is to be joined.
301
+                 *
302
+                 * @type {string}
303
+                 */
304
+                password,
305
+                passwordRequired: undefined
306
+            });
326 307
         }
327 308
         break;
328 309
 
329 310
     case conference.lock:
330 311
         return assign(state, {
331
-            locked: action.password ? LOCKED_LOCALLY : undefined,
332
-            password: action.password
312
+            locked: password ? LOCKED_LOCALLY : undefined,
313
+            password
333 314
         });
334 315
     }
335 316
 

+ 11
- 10
react/features/base/connection/actions.native.js View File

@@ -211,34 +211,35 @@ export function disconnect() {
211 211
     return (dispatch: Dispatch<*>, getState: Function) => {
212 212
         const state = getState();
213 213
         const { conference, joining } = state['features/base/conference'];
214
-        const { connection, connecting } = state['features/base/connection'];
215 214
 
216 215
         // 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;
216
+        const conference_ = conference || joining;
221 217
 
222 218
         // Promise which completes when the conference has been left and the
223 219
         // connection has been disconnected.
224 220
         let promise;
225 221
 
226 222
         // Leave the conference.
227
-        if (_conference) {
223
+        if (conference_) {
228 224
             // In a fashion similar to JitsiConference's CONFERENCE_LEFT event
229 225
             // (and the respective Redux action) which is fired after the
230 226
             // conference has been left, notify the application about the
231 227
             // intention to leave the conference.
232
-            dispatch(conferenceWillLeave(_conference));
228
+            dispatch(conferenceWillLeave(conference_));
233 229
 
234
-            promise = _conference.leave();
230
+            promise = conference_.leave();
235 231
         } else {
236 232
             promise = Promise.resolve();
237 233
         }
238 234
 
239 235
         // Disconnect the connection.
240
-        if (_connection) {
241
-            promise = promise.then(() => _connection.disconnect());
236
+        const { connecting, connection } = state['features/base/connection'];
237
+
238
+        // The connection we are connecting or have already connected.
239
+        const connection_ = connection || connecting;
240
+
241
+        if (connection_) {
242
+            promise = promise.then(() => connection_.disconnect());
242 243
         }
243 244
 
244 245
         return promise;

+ 21
- 11
react/features/base/connection/reducer.js View File

@@ -49,11 +49,14 @@ ReducerRegistry.register(
49 49
 function _connectionDisconnected(
50 50
         state: Object,
51 51
         { connection }: { connection: Object }) {
52
-    if (state.connection === connection) {
53
-        return set(state, 'connection', undefined);
52
+    if (state.connection !== connection) {
53
+        return state;
54 54
     }
55 55
 
56
-    return state;
56
+    return assign(state, {
57
+        connecting: undefined,
58
+        connection: undefined
59
+    });
57 60
 }
58 61
 
59 62
 /**
@@ -75,8 +78,6 @@ function _connectionEstablished(
75 78
     });
76 79
 }
77 80
 
78
-/* eslint-disable no-unused-vars */
79
-
80 81
 /**
81 82
  * Reduces a specific Redux action CONNECTION_FAILED of the feature
82 83
  * base/connection.
@@ -87,11 +88,18 @@ function _connectionEstablished(
87 88
  * @returns {Object} The new state of the feature base/connection after the
88 89
  * reduction of the specified action.
89 90
  */
90
-function _connectionFailed(state: Object, action: Object) {
91
-    return set(state, 'connecting', undefined);
92
-}
91
+function _connectionFailed(
92
+        state: Object,
93
+        { connection }: { connection: Object }) {
94
+    if (state.connection && state.connection !== connection) {
95
+        return state;
96
+    }
93 97
 
94
-/* eslint-enable no-unused-vars */
98
+    return assign(state, {
99
+        connecting: undefined,
100
+        connection: undefined
101
+    });
102
+}
95 103
 
96 104
 /**
97 105
  * Reduces a specific Redux action CONNECTION_WILL_CONNECT of the feature
@@ -103,8 +111,10 @@ function _connectionFailed(state: Object, action: Object) {
103 111
  * @returns {Object} The new state of the feature base/connection after the
104 112
  * reduction of the specified action.
105 113
  */
106
-function _connectionWillConnect(state: Object, action: Object) {
107
-    return set(state, 'connecting', action.connection);
114
+function _connectionWillConnect(
115
+        state: Object,
116
+        { connection }: { connection: Object }) {
117
+    return set(state, 'connecting', connection);
108 118
 }
109 119
 
110 120
 /**

Loading…
Cancel
Save