Bladeren bron

feat(external_api): export sendEvent function

Small reorganization so other features can send events to the native side.
master
Saúl Ibarra Corretgé 7 jaren geleden
bovenliggende
commit
39e236a42c

+ 26
- 0
react/features/mobile/external-api/functions.js Bestand weergeven

@@ -0,0 +1,26 @@
1
+// @flow
2
+
3
+import { NativeModules } from 'react-native';
4
+
5
+import { getAppProp } from '../../base/app';
6
+
7
+/**
8
+ * Sends a specific event to the native counterpart of the External API. Native
9
+ * apps may listen to such events via the mechanisms provided by the (native)
10
+ * mobile Jitsi Meet SDK.
11
+ *
12
+ * @param {Object} store - The redux store.
13
+ * @param {string} name - The name of the event to send.
14
+ * @param {Object} data - The details/specifics of the event to send determined
15
+ * by/associated with the specified {@code name}.
16
+ * @returns {void}
17
+ */
18
+export function sendEvent(store: Object, name: string, data: Object) {
19
+    // The JavaScript App needs to provide uniquely identifying information to
20
+    // the native ExternalAPI module so that the latter may match the former to
21
+    // the native view which hosts it.
22
+    const externalAPIScope = getAppProp(store, 'externalAPIScope');
23
+
24
+    externalAPIScope
25
+        && NativeModules.ExternalAPI.sendEvent(name, data, externalAPIScope);
26
+}

+ 2
- 0
react/features/mobile/external-api/index.js Bestand weergeven

@@ -1 +1,3 @@
1
+export * from './functions';
2
+
1 3
 import './middleware';

+ 7
- 30
react/features/mobile/external-api/middleware.js Bestand weergeven

@@ -1,8 +1,5 @@
1 1
 // @flow
2 2
 
3
-import { NativeModules } from 'react-native';
4
-
5
-import { getAppProp } from '../../base/app';
6 3
 import {
7 4
     CONFERENCE_FAILED,
8 5
     CONFERENCE_JOINED,
@@ -20,6 +17,8 @@ import { MiddlewareRegistry } from '../../base/redux';
20 17
 import { getSymbolDescription, toURLString } from '../../base/util';
21 18
 import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture';
22 19
 
20
+import { sendEvent } from './functions';
21
+
23 22
 /**
24 23
  * Middleware that captures Redux actions and uses the ExternalAPI module to
25 24
  * turn them into native events so the application knows about them.
@@ -66,13 +65,13 @@ MiddlewareRegistry.register(store => next => action => {
66 65
         break;
67 66
 
68 67
     case ENTER_PICTURE_IN_PICTURE:
69
-        _sendEvent(store, getSymbolDescription(type), /* data */ {});
68
+        sendEvent(store, getSymbolDescription(type), /* data */ {});
70 69
         break;
71 70
 
72 71
     case LOAD_CONFIG_ERROR: {
73 72
         const { error, locationURL } = action;
74 73
 
75
-        _sendEvent(
74
+        sendEvent(
76 75
             store,
77 76
             getSymbolDescription(type),
78 77
             /* data */ {
@@ -128,7 +127,7 @@ function _maybeTriggerEarlyConferenceWillJoin(store, action) {
128 127
     const { locationURL } = store.getState()['features/base/connection'];
129 128
     const { room } = action;
130 129
 
131
-    isRoomValid(room) && locationURL && _sendEvent(
130
+    isRoomValid(room) && locationURL && sendEvent(
132 131
         store,
133 132
         getSymbolDescription(CONFERENCE_WILL_JOIN),
134 133
         /* data */ {
@@ -161,7 +160,7 @@ function _sendConferenceEvent(
161 160
     }
162 161
 
163 162
     _swallowEvent(store, action, data)
164
-        || _sendEvent(store, getSymbolDescription(type), data);
163
+        || sendEvent(store, getSymbolDescription(type), data);
165 164
 }
166 165
 
167 166
 /**
@@ -185,7 +184,7 @@ function _sendConferenceFailedOnConnectionError(store, action) {
185 184
             // If there's any conference in the  base/conference state then the
186 185
             // base/conference feature is supposed to emit a failure.
187 186
             conference => conference.getConnection() !== connection)
188
-        && _sendEvent(
187
+        && sendEvent(
189 188
         store,
190 189
         getSymbolDescription(CONFERENCE_FAILED),
191 190
         /* data */ {
@@ -194,28 +193,6 @@ function _sendConferenceFailedOnConnectionError(store, action) {
194 193
         });
195 194
 }
196 195
 
197
-/**
198
- * Sends a specific event to the native counterpart of the External API. Native
199
- * apps may listen to such events via the mechanisms provided by the (native)
200
- * mobile Jitsi Meet SDK.
201
- *
202
- * @param {Object} store - The redux store.
203
- * @param {string} name - The name of the event to send.
204
- * @param {Object} data - The details/specifics of the event to send determined
205
- * by/associated with the specified {@code name}.
206
- * @private
207
- * @returns {void}
208
- */
209
-function _sendEvent(store: Object, name: string, data: Object) {
210
-    // The JavaScript App needs to provide uniquely identifying information to
211
-    // the native ExternalAPI module so that the latter may match the former to
212
-    // the native JitsiMeetView which hosts it.
213
-    const externalAPIScope = getAppProp(store, 'externalAPIScope');
214
-
215
-    externalAPIScope
216
-        && NativeModules.ExternalAPI.sendEvent(name, data, externalAPIScope);
217
-}
218
-
219 196
 /**
220 197
  * Determines whether to not send a {@code CONFERENCE_LEFT} event to the native
221 198
  * counterpart of the External API.

Laden…
Annuleren
Opslaan