ソースを参照

rn: ensure the conference terminated event is always sent

Dear reader, I'm not proud at all of what you are about to read, but sometimes
life just gives you lemons, so enjoy some lemonade!

Joining a conference implies first creating the XMPP connection and then joining
the MUC. It's very possible the XMPP connection was made but there was no chance
for the conference to be created.

This patch fixes this case by artificially genrating a conference terminated
event in such case. In order to have all the necessary knowledge for this event
to be sent the connection now keeps track of the conference that runs it.

In addition, there is an even more obscure corner case: it's not impossible to
try to disconnect when there is not even a connection. This was fixed by
creating a fake disconnect event. Alas the location URL is lost at this point,
but it's better than nothing I guess.
master
Saúl Ibarra Corretgé 6年前
コミット
774c5ecd18

+ 6
- 1
react/features/base/conference/actions.js ファイルの表示

@@ -5,6 +5,9 @@ import {
5 5
     sendAnalytics
6 6
 } from '../../analytics';
7 7
 import { getName } from '../../app';
8
+import { endpointMessageReceived } from '../../subtitles';
9
+
10
+import { JITSI_CONNECTION_CONFERENCE_KEY } from '../connection';
8 11
 import { JitsiConferenceEvents } from '../lib-jitsi-meet';
9 12
 import { setAudioMuted, setVideoMuted } from '../media';
10 13
 import {
@@ -15,7 +18,6 @@ import {
15 18
     participantRoleChanged,
16 19
     participantUpdated
17 20
 } from '../participants';
18
-import { endpointMessageReceived } from '../../subtitles';
19 21
 import { getLocalTracks, trackAdded, trackRemoved } from '../tracks';
20 22
 import { getJitsiMeetGlobalNS } from '../util';
21 23
 
@@ -378,7 +380,10 @@ export function createConference() {
378 380
                     getWiFiStatsMethod: getJitsiMeetGlobalNS().getWiFiStats
379 381
                 });
380 382
 
383
+        connection[JITSI_CONNECTION_CONFERENCE_KEY] = conference;
384
+
381 385
         conference[JITSI_CONFERENCE_URL_KEY] = locationURL;
386
+
382 387
         dispatch(_conferenceWillJoin(conference));
383 388
 
384 389
         _addConferenceListeners(conference, dispatch);

+ 11
- 3
react/features/base/connection/actions.native.js ファイルの表示

@@ -18,6 +18,7 @@ import {
18 18
     CONNECTION_WILL_CONNECT,
19 19
     SET_LOCATION_URL
20 20
 } from './actionTypes';
21
+import { JITSI_CONNECTION_URL_KEY } from './constants';
21 22
 
22 23
 const logger = require('jitsi-meet-logger').getLogger(__filename);
23 24
 
@@ -79,6 +80,7 @@ export function connect(id: ?string, password: ?string) {
79 80
     return (dispatch: Dispatch<any>, getState: Function) => {
80 81
         const state = getState();
81 82
         const options = _constructOptions(state);
83
+        const { locationURL } = state['features/base/connection'];
82 84
         const { issuer, jwt } = state['features/base/jwt'];
83 85
         const connection
84 86
             = new JitsiMeetJS.JitsiConnection(
@@ -86,6 +88,8 @@ export function connect(id: ?string, password: ?string) {
86 88
                 jwt && issuer && issuer !== 'anonymous' ? jwt : undefined,
87 89
                 options);
88 90
 
91
+        connection[JITSI_CONNECTION_URL_KEY] = locationURL;
92
+
89 93
         dispatch(_connectionWillConnect(connection));
90 94
 
91 95
         connection.addEventListener(
@@ -284,14 +288,13 @@ function _constructOptions(state) {
284 288
     let { bosh } = options;
285 289
 
286 290
     if (bosh) {
291
+        const { locationURL } = state['features/base/connection'];
292
+
287 293
         if (bosh.startsWith('//')) {
288 294
             // By default our config.js doesn't include the protocol.
289
-            const { locationURL } = state['features/base/connection'];
290
-
291 295
             bosh = `${locationURL.protocol}${bosh}`;
292 296
         } else if (bosh.startsWith('/')) {
293 297
             // Handle relative URLs, which won't work on mobile.
294
-            const { locationURL } = state['features/base/connection'];
295 298
             const {
296 299
                 protocol,
297 300
                 hostname,
@@ -366,6 +369,11 @@ export function disconnect() {
366 369
 
367 370
         if (connection_) {
368 371
             promise = promise.then(() => connection_.disconnect());
372
+        } else {
373
+            // FIXME: We have no connection! Fake a disconnect. Because of how the current disconnec is implemented
374
+            // (by doing the diconnect() in the Conference component unmount) we have lost the location URL already.
375
+            // Oh well, at least send the event.
376
+            promise.then(() => dispatch(_connectionDisconnected({}, '')));
369 377
         }
370 378
 
371 379
         return promise;

+ 19
- 0
react/features/base/connection/constants.js ファイルの表示

@@ -0,0 +1,19 @@
1
+// @flow
2
+
3
+/**
4
+ * The name of the {@code JitsiConnection} property which identifies the {@code JitsiConference} currently associated
5
+ * with it.
6
+ *
7
+ * FIXME: This is a hack. It was introduced to solve the following case: if a user presses hangup quickly, they may
8
+ * "leave the conference" before the actual conference was ever created. While we might have a connection in place,
9
+ * there is no conference which can be left, thus no CONFERENCE_LEFT action will ever be fired.
10
+ *
11
+ * This is problematic because the external API module used to send events to the native SDK won't know what to send.
12
+ * So, in order to detect this situation we are attaching the conference object to the connection which runs it.
13
+ */
14
+export const JITSI_CONNECTION_CONFERENCE_KEY = Symbol('conference');
15
+
16
+/**
17
+ * The name of the {@code JitsiConnection} property which identifies the location URL where the connection will be made.
18
+ */
19
+export const JITSI_CONNECTION_URL_KEY = Symbol('url');

+ 1
- 0
react/features/base/connection/index.js ファイルの表示

@@ -2,6 +2,7 @@
2 2
 
3 3
 export * from './actions';
4 4
 export * from './actionTypes';
5
+export * from './constants';
5 6
 export * from './functions';
6 7
 
7 8
 import './reducer';

+ 1
- 1
react/features/conference/components/native/Conference.js ファイルの表示

@@ -199,7 +199,7 @@ class Conference extends AbstractConference<Props, *> {
199 199
         } = this.props;
200 200
 
201 201
         // If the location URL changes we need to reconnect.
202
-        oldLocationURL !== newLocationURL && this.props._onDisconnect();
202
+        oldLocationURL !== newLocationURL && newRoom && this.props._onDisconnect();
203 203
 
204 204
         // Start the connection process when there is a (valid) room.
205 205
         oldRoom !== newRoom && newRoom && this.props._onConnect();

+ 27
- 1
react/features/mobile/external-api/middleware.js ファイルの表示

@@ -11,7 +11,12 @@ import {
11 11
     isRoomValid
12 12
 } from '../../base/conference';
13 13
 import { LOAD_CONFIG_ERROR } from '../../base/config';
14
-import { CONNECTION_FAILED } from '../../base/connection';
14
+import {
15
+    CONNECTION_DISCONNECTED,
16
+    CONNECTION_FAILED,
17
+    JITSI_CONNECTION_CONFERENCE_KEY,
18
+    JITSI_CONNECTION_URL_KEY
19
+} from '../../base/connection';
15 20
 import { MiddlewareRegistry } from '../../base/redux';
16 21
 import { toURLString } from '../../base/util';
17 22
 import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture';
@@ -63,6 +68,27 @@ MiddlewareRegistry.register(store => next => action => {
63 68
         _sendConferenceEvent(store, action);
64 69
         break;
65 70
 
71
+    case CONNECTION_DISCONNECTED: {
72
+        // FIXME: This is a hack. See the description in the JITSI_CONNECTION_CONFERENCE_KEY constant definition.
73
+        // Check if this connection was attached to any conference. If it wasn't, fake a CONFERENCE_TERMINATED event.
74
+        const { connection } = action;
75
+        const conference = connection[JITSI_CONNECTION_CONFERENCE_KEY];
76
+
77
+        if (!conference) {
78
+            // This action will arrive late, so the locationURL stored on the state is no longer valid.
79
+            const locationURL = connection[JITSI_CONNECTION_URL_KEY];
80
+
81
+            sendEvent(
82
+                store,
83
+                CONFERENCE_TERMINATED,
84
+                /* data */ {
85
+                    url: toURLString(locationURL)
86
+                });
87
+        }
88
+
89
+        break;
90
+    }
91
+
66 92
     case CONNECTION_FAILED:
67 93
         !action.error.recoverable
68 94
             && _sendConferenceFailedOnConnectionError(store, action);

読み込み中…
キャンセル
保存