Browse Source

feat(external_api): export sendEvent function

Small reorganization so other features can send events to the native side.
j8
Saúl Ibarra Corretgé 7 years ago
parent
commit
39e236a42c

+ 26
- 0
react/features/mobile/external-api/functions.js View File

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 View File

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

+ 7
- 30
react/features/mobile/external-api/middleware.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
-import { NativeModules } from 'react-native';
4
-
5
-import { getAppProp } from '../../base/app';
6
 import {
3
 import {
7
     CONFERENCE_FAILED,
4
     CONFERENCE_FAILED,
8
     CONFERENCE_JOINED,
5
     CONFERENCE_JOINED,
20
 import { getSymbolDescription, toURLString } from '../../base/util';
17
 import { getSymbolDescription, toURLString } from '../../base/util';
21
 import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture';
18
 import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture';
22
 
19
 
20
+import { sendEvent } from './functions';
21
+
23
 /**
22
 /**
24
  * Middleware that captures Redux actions and uses the ExternalAPI module to
23
  * Middleware that captures Redux actions and uses the ExternalAPI module to
25
  * turn them into native events so the application knows about them.
24
  * turn them into native events so the application knows about them.
66
         break;
65
         break;
67
 
66
 
68
     case ENTER_PICTURE_IN_PICTURE:
67
     case ENTER_PICTURE_IN_PICTURE:
69
-        _sendEvent(store, getSymbolDescription(type), /* data */ {});
68
+        sendEvent(store, getSymbolDescription(type), /* data */ {});
70
         break;
69
         break;
71
 
70
 
72
     case LOAD_CONFIG_ERROR: {
71
     case LOAD_CONFIG_ERROR: {
73
         const { error, locationURL } = action;
72
         const { error, locationURL } = action;
74
 
73
 
75
-        _sendEvent(
74
+        sendEvent(
76
             store,
75
             store,
77
             getSymbolDescription(type),
76
             getSymbolDescription(type),
78
             /* data */ {
77
             /* data */ {
128
     const { locationURL } = store.getState()['features/base/connection'];
127
     const { locationURL } = store.getState()['features/base/connection'];
129
     const { room } = action;
128
     const { room } = action;
130
 
129
 
131
-    isRoomValid(room) && locationURL && _sendEvent(
130
+    isRoomValid(room) && locationURL && sendEvent(
132
         store,
131
         store,
133
         getSymbolDescription(CONFERENCE_WILL_JOIN),
132
         getSymbolDescription(CONFERENCE_WILL_JOIN),
134
         /* data */ {
133
         /* data */ {
161
     }
160
     }
162
 
161
 
163
     _swallowEvent(store, action, data)
162
     _swallowEvent(store, action, data)
164
-        || _sendEvent(store, getSymbolDescription(type), data);
163
+        || sendEvent(store, getSymbolDescription(type), data);
165
 }
164
 }
166
 
165
 
167
 /**
166
 /**
185
             // If there's any conference in the  base/conference state then the
184
             // If there's any conference in the  base/conference state then the
186
             // base/conference feature is supposed to emit a failure.
185
             // base/conference feature is supposed to emit a failure.
187
             conference => conference.getConnection() !== connection)
186
             conference => conference.getConnection() !== connection)
188
-        && _sendEvent(
187
+        && sendEvent(
189
         store,
188
         store,
190
         getSymbolDescription(CONFERENCE_FAILED),
189
         getSymbolDescription(CONFERENCE_FAILED),
191
         /* data */ {
190
         /* data */ {
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
  * Determines whether to not send a {@code CONFERENCE_LEFT} event to the native
197
  * Determines whether to not send a {@code CONFERENCE_LEFT} event to the native
221
  * counterpart of the External API.
198
  * counterpart of the External API.

Loading…
Cancel
Save