瀏覽代碼

[RN] locationURL instead of inviteURL

The value of inviteURL is derived from locationURL by removing the hash
and query/search params in order to make it fit for display and/or
public purposes. The Jitsi Meet SDK consumers do not fall into that
category and our intention is to provide them with the URL they used
with JitsiMeetView.openURL(URL) anyway.

Also rewrites to remove repetition. I'm not saying the new source code
is better really but at least I got to examine it and comment on some of
its weaknesses.
j8
Lyubo Marinov 8 年之前
父節點
當前提交
e5cc8cd32b
共有 1 個檔案被更改,包括 46 行新增34 行删除
  1. 46
    34
      react/features/mobile/external-api/middleware.js

+ 46
- 34
react/features/mobile/external-api/middleware.js 查看文件

@@ -2,7 +2,6 @@
2 2
 
3 3
 import { NativeModules } from 'react-native';
4 4
 
5
-import { getInviteURL } from '../../base/connection';
6 5
 import {
7 6
     CONFERENCE_FAILED,
8 7
     CONFERENCE_JOINED,
@@ -12,7 +11,6 @@ import {
12 11
 } from '../../base/conference';
13 12
 import { MiddlewareRegistry } from '../../base/redux';
14 13
 
15
-
16 14
 /**
17 15
  * Middleware that captures Redux actions and uses the ExternalAPI module to
18 16
  * turn them into native events so the application knows about them.
@@ -21,52 +19,66 @@ import { MiddlewareRegistry } from '../../base/redux';
21 19
  * @returns {Function}
22 20
  */
23 21
 MiddlewareRegistry.register(store => next => action => {
24
-    const eventData = {};
22
+    const result = next(action);
25 23
 
26 24
     switch (action.type) {
27
-    case CONFERENCE_FAILED: {
28
-        eventData.error = action.error;
29
-        eventData.url = getInviteURL(store.getState());
30
-        _sendEvent('CONFERENCE_FAILED', eventData);
31
-        break;
32
-    }
25
+    case CONFERENCE_FAILED:
26
+    case CONFERENCE_JOINED:
27
+    case CONFERENCE_LEFT:
28
+    case CONFERENCE_WILL_JOIN:
29
+    case CONFERENCE_WILL_LEAVE: {
30
+        const { conference, room, type, ...data } = action;
33 31
 
34
-    case CONFERENCE_JOINED: {
35
-        eventData.url = getInviteURL(store.getState());
36
-        _sendEvent('CONFERENCE_JOINED', eventData);
37
-        break;
38
-    }
32
+        // For the above (redux) actions, conference and/or room identify a
33
+        // JitsiConference instance. The external API cannot transport such an
34
+        // object so we have to transport an "equivalent".
35
+        if (conference || room) {
36
+            // We have chosen to identify the object in question by the
37
+            // (supposedly) associated location URL. (FIXME Actually, the redux
38
+            // state locationURL is not really asssociated with the
39
+            // JitsiConference instance. The value of localtionURL is utilized
40
+            // in order to initialize the JitsiConference instance but the value
41
+            // of locationURL at the time of CONFERENCE_WILL_LEAVE and
42
+            // CONFERENCE_LEFT will not be the value with which the
43
+            // JitsiConference instance being left.)
44
+            const { locationURL }
45
+                = store.getState()['features/base/connection'];
39 46
 
40
-    case CONFERENCE_LEFT: {
41
-        eventData.url = getInviteURL(store.getState());
42
-        _sendEvent('CONFERENCE_LEFT', eventData);
43
-        break;
44
-    }
47
+            if (!locationURL) {
48
+                // The (redux) action cannot be fully converted to an (external
49
+                // API) event.
50
+                break;
51
+            }
45 52
 
46
-    case CONFERENCE_WILL_JOIN: {
47
-        eventData.url = getInviteURL(store.getState());
48
-        _sendEvent('CONFERENCE_WILL_JOIN', eventData);
49
-        break;
50
-    }
53
+            data.url = locationURL.href;
54
+        }
51 55
 
52
-    case CONFERENCE_WILL_LEAVE: {
53
-        eventData.url = getInviteURL(store.getState());
54
-        _sendEvent('CONFERENCE_WILL_LEAVE', eventData);
56
+        // The (externa API) event's name is the string representation of the
57
+        // (redux) action's type.
58
+        let name = type.toString();
59
+
60
+        // XXX We are using Symbol for (redux) action types at the time of this
61
+        // writing so the Symbol's description should be used.
62
+        if (name.startsWith('Symbol(') && name.endsWith(')')) {
63
+            name = name.slice(7, -1);
64
+        }
65
+
66
+        _sendEvent(name, data);
55 67
         break;
56 68
     }
57
-
58 69
     }
59 70
 
60
-    return next(action);
71
+    return result;
61 72
 });
62 73
 
63 74
 /**
64
- * Sends the given event to the native side of the application. Applications can
65
- * then listen to the events using the mechanisms provided by the Jitsi Meet
66
- * SDK.
75
+ * Sends a specific event to the native counterpart of the External API. Native
76
+ * apps may listen to such events via the mechanisms provided by the (native)
77
+ * mobile Jitsi Meet SDK.
67 78
  *
68
- * @param {string} name - Event name.
69
- * @param {Object} data - Ancillary data for the event.
79
+ * @param {string} name - The name of the event to send.
80
+ * @param {Object} data - The details/specifics of the event to send determined
81
+ * by/associated with the specified {@code name}.
70 82
  * @private
71 83
  * @returns {void}
72 84
  */

Loading…
取消
儲存