From 39e236a42c843268dc335daa5efa139ad1afaca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Sun, 15 Jul 2018 16:50:54 +0200 Subject: [PATCH] feat(external_api): export sendEvent function Small reorganization so other features can send events to the native side. --- .../features/mobile/external-api/functions.js | 26 +++++++++++++ react/features/mobile/external-api/index.js | 2 + .../mobile/external-api/middleware.js | 37 ++++--------------- 3 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 react/features/mobile/external-api/functions.js diff --git a/react/features/mobile/external-api/functions.js b/react/features/mobile/external-api/functions.js new file mode 100644 index 0000000000..2451cd8dfe --- /dev/null +++ b/react/features/mobile/external-api/functions.js @@ -0,0 +1,26 @@ +// @flow + +import { NativeModules } from 'react-native'; + +import { getAppProp } from '../../base/app'; + +/** + * Sends a specific event to the native counterpart of the External API. Native + * apps may listen to such events via the mechanisms provided by the (native) + * mobile Jitsi Meet SDK. + * + * @param {Object} store - The redux store. + * @param {string} name - The name of the event to send. + * @param {Object} data - The details/specifics of the event to send determined + * by/associated with the specified {@code name}. + * @returns {void} + */ +export function sendEvent(store: Object, name: string, data: Object) { + // The JavaScript App needs to provide uniquely identifying information to + // the native ExternalAPI module so that the latter may match the former to + // the native view which hosts it. + const externalAPIScope = getAppProp(store, 'externalAPIScope'); + + externalAPIScope + && NativeModules.ExternalAPI.sendEvent(name, data, externalAPIScope); +} diff --git a/react/features/mobile/external-api/index.js b/react/features/mobile/external-api/index.js index d436892893..e975ed0e86 100644 --- a/react/features/mobile/external-api/index.js +++ b/react/features/mobile/external-api/index.js @@ -1 +1,3 @@ +export * from './functions'; + import './middleware'; diff --git a/react/features/mobile/external-api/middleware.js b/react/features/mobile/external-api/middleware.js index 0acf17e12e..e665524e8b 100644 --- a/react/features/mobile/external-api/middleware.js +++ b/react/features/mobile/external-api/middleware.js @@ -1,8 +1,5 @@ // @flow -import { NativeModules } from 'react-native'; - -import { getAppProp } from '../../base/app'; import { CONFERENCE_FAILED, CONFERENCE_JOINED, @@ -20,6 +17,8 @@ import { MiddlewareRegistry } from '../../base/redux'; import { getSymbolDescription, toURLString } from '../../base/util'; import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture'; +import { sendEvent } from './functions'; + /** * Middleware that captures Redux actions and uses the ExternalAPI module to * turn them into native events so the application knows about them. @@ -66,13 +65,13 @@ MiddlewareRegistry.register(store => next => action => { break; case ENTER_PICTURE_IN_PICTURE: - _sendEvent(store, getSymbolDescription(type), /* data */ {}); + sendEvent(store, getSymbolDescription(type), /* data */ {}); break; case LOAD_CONFIG_ERROR: { const { error, locationURL } = action; - _sendEvent( + sendEvent( store, getSymbolDescription(type), /* data */ { @@ -128,7 +127,7 @@ function _maybeTriggerEarlyConferenceWillJoin(store, action) { const { locationURL } = store.getState()['features/base/connection']; const { room } = action; - isRoomValid(room) && locationURL && _sendEvent( + isRoomValid(room) && locationURL && sendEvent( store, getSymbolDescription(CONFERENCE_WILL_JOIN), /* data */ { @@ -161,7 +160,7 @@ function _sendConferenceEvent( } _swallowEvent(store, action, data) - || _sendEvent(store, getSymbolDescription(type), data); + || sendEvent(store, getSymbolDescription(type), data); } /** @@ -185,7 +184,7 @@ function _sendConferenceFailedOnConnectionError(store, action) { // If there's any conference in the base/conference state then the // base/conference feature is supposed to emit a failure. conference => conference.getConnection() !== connection) - && _sendEvent( + && sendEvent( store, getSymbolDescription(CONFERENCE_FAILED), /* data */ { @@ -194,28 +193,6 @@ function _sendConferenceFailedOnConnectionError(store, action) { }); } -/** - * Sends a specific event to the native counterpart of the External API. Native - * apps may listen to such events via the mechanisms provided by the (native) - * mobile Jitsi Meet SDK. - * - * @param {Object} store - The redux store. - * @param {string} name - The name of the event to send. - * @param {Object} data - The details/specifics of the event to send determined - * by/associated with the specified {@code name}. - * @private - * @returns {void} - */ -function _sendEvent(store: Object, name: string, data: Object) { - // The JavaScript App needs to provide uniquely identifying information to - // the native ExternalAPI module so that the latter may match the former to - // the native JitsiMeetView which hosts it. - const externalAPIScope = getAppProp(store, 'externalAPIScope'); - - externalAPIScope - && NativeModules.ExternalAPI.sendEvent(name, data, externalAPIScope); -} - /** * Determines whether to not send a {@code CONFERENCE_LEFT} event to the native * counterpart of the External API.