Browse Source

[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 years ago
parent
commit
c4232b34ae

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

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

+ 9
- 5
react/features/base/conference/actions.js View File

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

+ 21
- 0
react/features/base/conference/reducer.js View File

@@ -7,6 +7,7 @@ import {
7 7
     CONFERENCE_FAILED,
8 8
     CONFERENCE_JOINED,
9 9
     CONFERENCE_LEFT,
10
+    CONFERENCE_WILL_JOIN,
10 11
     CONFERENCE_WILL_LEAVE,
11 12
     LOCK_STATE_CHANGED,
12 13
     SET_AUDIO_ONLY,
@@ -32,6 +33,9 @@ ReducerRegistry.register('features/base/conference', (state = {}, action) => {
32 33
     case CONFERENCE_LEFT:
33 34
         return _conferenceLeft(state, action);
34 35
 
36
+    case CONFERENCE_WILL_JOIN:
37
+        return _conferenceWillJoin(state, action);
38
+
35 39
     case CONFERENCE_WILL_LEAVE:
36 40
         return _conferenceWillLeave(state, action);
37 41
 
@@ -84,6 +88,7 @@ function _conferenceFailed(state, action) {
84 88
             audioOnly: undefined,
85 89
             audioOnlyVideoMuted: undefined,
86 90
             conference: undefined,
91
+            joining: undefined,
87 92
             leaving: undefined,
88 93
 
89 94
             /**
@@ -133,6 +138,7 @@ function _conferenceJoined(state, action) {
133 138
              * @type {JitsiConference}
134 139
              */
135 140
             conference,
141
+            joining: undefined,
136 142
             leaving: undefined,
137 143
 
138 144
             /**
@@ -167,6 +173,7 @@ function _conferenceLeft(state, action) {
167 173
             audioOnly: undefined,
168 174
             audioOnlyVideoMuted: undefined,
169 175
             conference: undefined,
176
+            joining: undefined,
170 177
             leaving: undefined,
171 178
             locked: undefined,
172 179
             password: undefined,
@@ -174,6 +181,20 @@ function _conferenceLeft(state, action) {
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 199
  * Reduces a specific Redux action CONFERENCE_WILL_LEAVE of the feature
179 200
  * base/conference.

+ 10
- 0
react/features/base/connection/actionTypes.js View File

@@ -32,6 +32,16 @@ export const CONNECTION_ESTABLISHED = Symbol('CONNECTION_ESTABLISHED');
32 32
  */
33 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 46
  * The type of (redux) action which sets the location URL of the application,
37 47
  * connection, conference, etc.

+ 35
- 7
react/features/base/connection/actions.native.js View File

@@ -9,6 +9,7 @@ import {
9 9
     CONNECTION_DISCONNECTED,
10 10
     CONNECTION_ESTABLISHED,
11 11
     CONNECTION_FAILED,
12
+    CONNECTION_WILL_CONNECT,
12 13
     SET_LOCATION_URL
13 14
 } from './actionTypes';
14 15
 
@@ -49,6 +50,8 @@ export function connect() {
49 50
                 jwt && issuer && issuer !== 'anonymous' ? jwt : undefined,
50 51
                 options);
51 52
 
53
+        dispatch(_connectionWillConnect(connection));
54
+
52 55
         connection.addEventListener(
53 56
             JitsiConnectionEvents.CONNECTION_DISCONNECTED,
54 57
             _onConnectionDisconnected);
@@ -138,6 +141,23 @@ function _connectionDisconnected(connection: Object, message: string) {
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 162
  * Create an action for when the signaling connection has been established.
143 163
  *
@@ -190,27 +210,35 @@ export function connectionFailed(
190 210
 export function disconnect() {
191 211
     return (dispatch: Dispatch<*>, getState: Function) => {
192 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 224
         let promise;
197 225
 
198 226
         // Leave the conference.
199
-        if (conference) {
227
+        if (_conference) {
200 228
             // In a fashion similar to JitsiConference's CONFERENCE_LEFT event
201 229
             // (and the respective Redux action) which is fired after the
202 230
             // conference has been left, notify the application about the
203 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 235
         } else {
208 236
             promise = Promise.resolve();
209 237
         }
210 238
 
211 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 244
         return promise;

+ 44
- 1
react/features/base/connection/reducer.js View File

@@ -5,6 +5,8 @@ import { assign, ReducerRegistry, set } from '../redux';
5 5
 import {
6 6
     CONNECTION_DISCONNECTED,
7 7
     CONNECTION_ESTABLISHED,
8
+    CONNECTION_FAILED,
9
+    CONNECTION_WILL_CONNECT,
8 10
     SET_LOCATION_URL
9 11
 } from './actionTypes';
10 12
 
@@ -21,6 +23,12 @@ ReducerRegistry.register(
21 23
         case CONNECTION_ESTABLISHED:
22 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 32
         case SET_LOCATION_URL:
25 33
             return _setLocationURL(state, action);
26 34
         }
@@ -61,7 +69,42 @@ function _connectionDisconnected(
61 69
 function _connectionEstablished(
62 70
         state: Object,
63 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…
Cancel
Save