From d4d2cb4aadbe47f7f63b1a024308408d3ad8c531 Mon Sep 17 00:00:00 2001 From: Lyubo Marinov Date: Thu, 5 Oct 2017 10:21:37 -0500 Subject: [PATCH] [RN] No CONFERENCE_FAILED in SDK for recoverable errors --- .../mobile/external-api/middleware.js | 81 +++++++++++++++---- react/features/room-lock/middleware.js | 7 +- 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/react/features/mobile/external-api/middleware.js b/react/features/mobile/external-api/middleware.js index 72bebda97..05bdc3958 100644 --- a/react/features/mobile/external-api/middleware.js +++ b/react/features/mobile/external-api/middleware.js @@ -25,29 +25,39 @@ MiddlewareRegistry.register(store => next => action => { const result = next(action); switch (action.type) { - case CONFERENCE_FAILED: + case CONFERENCE_FAILED: { + const { error, ...data } = action; + + // XXX Certain CONFERENCE_FAILED errors are recoverable i.e. they have + // prevented the user from joining a specific conference but the app may + // be able to eventually join the conference. For example, the app will + // ask the user for a password upon + // JitsiConferenceErrors.PASSWORD_REQUIRED and will retry joining the + // conference afterwards. Such errors are to not reach the native + // counterpart of the External API (or at least not in the + // fatality/finality semantics attributed to + // conferenceFailed:/onConferenceFailed). + if (!error.recoverable) { + _sendConferenceEvent(store, /* action */ { + error: _toErrorString(error), + ...data + }); + } + break; + } + case CONFERENCE_JOINED: case CONFERENCE_LEFT: case CONFERENCE_WILL_JOIN: - case CONFERENCE_WILL_LEAVE: { - const { conference, type, ...data } = action; - - // For the above (redux) actions, conference identifies a - // JitsiConference instance. The external API cannot transport such an - // object so we have to transport an "equivalent". - if (conference) { - data.url = toURLString(conference[JITSI_CONFERENCE_URL_KEY]); - } - - _sendEvent(store, _getSymbolDescription(type), data); + case CONFERENCE_WILL_LEAVE: + _sendConferenceEvent(store, action); break; - } case LOAD_CONFIG_ERROR: { const { error, locationURL, type } = action; - _sendEvent(store, _getSymbolDescription(type), { - error: String(error), + _sendEvent(store, _getSymbolDescription(type), /* data */ { + error: _toErrorString(error), url: toURLString(locationURL) }); break; @@ -57,6 +67,26 @@ MiddlewareRegistry.register(store => next => action => { return result; }); +/** + * Returns a {@code String} representation of a specific error {@code Object}. + * + * @param {Error|Object|string} error - The error {@code Object} to return a + * {@code String} representation of. + * @returns {string} A {@code String} representation of the specified + * {@code error}. + */ +function _toErrorString( + error: Error | { message: ?string, name: ?string } | string) { + // XXX In lib-jitsi-meet and jitsi-meet we utilize errors in the form of + // strings, Error instances, and plain objects which resemble Error. + return ( + error + ? typeof error === 'string' + ? error + : Error.prototype.toString(error) + : ''); +} + /** * Gets the description of a specific {@code Symbol}. * @@ -80,6 +110,27 @@ function _getSymbolDescription(symbol: Symbol) { return description; } +/** + * Sends an event to the native counterpart of the External API for a specific + * conference-related redux action. + * + * @param {Store} store - The redux store. + * @param {Action} action - The redux action. + * @returns {void} + */ +function _sendConferenceEvent( + store: Object, + { conference, type, ...data }: { conference: Object, type: Symbol }) { + // For these (redux) actions, conference identifies a JitsiConference + // instance. The external API cannot transport such an object so we have to + // transport an "equivalent". + if (conference) { + data.url = toURLString(conference[JITSI_CONFERENCE_URL_KEY]); + } + + _sendEvent(store, _getSymbolDescription(type), data); +} + /** * 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) diff --git a/react/features/room-lock/middleware.js b/react/features/room-lock/middleware.js index 9158e2f3e..9b5cfd96e 100644 --- a/react/features/room-lock/middleware.js +++ b/react/features/room-lock/middleware.js @@ -29,7 +29,12 @@ MiddlewareRegistry.register(store => next => action => { if (conference && error.name === JitsiConferenceErrors.PASSWORD_REQUIRED) { - store.dispatch(_openPasswordRequiredPrompt(conference)); + if (typeof error.recoverable === 'undefined') { + error.recoverable = true; + } + if (error.recoverable) { + store.dispatch(_openPasswordRequiredPrompt(conference)); + } } break; }