From 2ee44578c8db2a59664dd1c32259ed9a6299efbd Mon Sep 17 00:00:00 2001 From: paweldomas Date: Thu, 28 Sep 2017 11:27:35 -0500 Subject: [PATCH] fix(watchos.middleware): transient NULL conference URL There was NULL conference URL emitted when selecting new conference from the list while still in a conference. (cherry picked from commit 4d6970c) --- react/features/mobile/watchos/middleware.js | 69 ++++++++++++++++++--- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/react/features/mobile/watchos/middleware.js b/react/features/mobile/watchos/middleware.js index 263560055..0ffa927fc 100644 --- a/react/features/mobile/watchos/middleware.js +++ b/react/features/mobile/watchos/middleware.js @@ -14,8 +14,9 @@ import { APP_WILL_MOUNT, APP_WILL_UNMOUNT, appNavigate } from '../../app'; import { CONFERENCE_FAILED, CONFERENCE_JOINED, - CONFERENCE_LEFT, - CONFERENCE_WILL_JOIN + CONFERENCE_WILL_JOIN, + CONFERENCE_WILL_LEAVE, + JITSI_CONFERENCE_URL_KEY } from '../../base/conference'; import { SET_AUDIO_MUTED, toggleAudioMuted } from '../../base/media'; import { MiddlewareRegistry } from '../../base/redux'; @@ -105,14 +106,51 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => { }); break; } - case CONFERENCE_WILL_JOIN: - case CONFERENCE_JOINED: case CONFERENCE_FAILED: - case CONFERENCE_LEFT: { + case CONFERENCE_WILL_LEAVE: { + const conferenceURL = _getConferenceUrlFromBaseConf(getState); + const watchConferenceURL = _getWatchConferenceURL(getState); + + // This may not be a real failure + if (action.type === CONFERENCE_FAILED) { + const conference = getState()['features/base/conference']; + + if (conference.authRequired || conference.passwordRequired) { + + break; + } + } + + // FIXME I have bad feelings about this logic, but it aims to fix + // problem with setting NULL temporarily when selecting new conference + // on the watch while still in the previous room. It will first emit + // CONFERENCE_WILL_LEVE, before joining the new room and we don't want + // to send NULL. + if (watchConferenceURL !== 'NULL' + && watchConferenceURL !== conferenceURL) { + console.info( + 'Ignored action', + action.type, + `possibly for the previous conference ?: ${conferenceURL}`); + } else if (action.type === CONFERENCE_WILL_LEAVE + && conferenceURL === watchConferenceURL) { + dispatch(setConferenceURL('NULL')); + } else if (conferenceURL !== watchConferenceURL) { + dispatch(setConferenceURL(conferenceURL)); + } else { + console.info( + 'Did nothing on', + action.type, + conferenceURL, + watchConferenceURL); + } + break; + } + case CONFERENCE_WILL_JOIN: + case CONFERENCE_JOINED: { // NOTE for some reason 'null' does not update context - must be string const conferenceURL = _getConferenceUrlFromBaseConf(getState); - const { conferenceURL: oldConferenceURL } - = getState()['features/mobile/watchos']; + const oldConferenceURL = _getWatchConferenceURL(getState); // NOTE Those updates are expensive! if (conferenceURL !== oldConferenceURL) { @@ -136,11 +174,24 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => { return result; }); +function _getWatchConferenceURL(getState) { + const { conferenceURL } = getState()['features/mobile/watchos']; + + return conferenceURL; +} + function _getConferenceUrlFromBaseConf(getState) { - const { conference, joining } = getState()['features/base/conference']; + + // FIXME probably authRequired and paswordRequired should be included + // as well... + const { conference, joining, leaving } + = getState()['features/base/conference']; + const theConference = conference || joining || leaving; + const conferenceURLObj + = theConference && theConference[JITSI_CONFERENCE_URL_KEY]; // NOTE for some reason 'null' does not update context - must be string - return conference || joining ? getInviteURL(getState) : 'NULL'; + return conferenceURLObj ? getInviteURL(conferenceURLObj) : 'NULL'; } function _updateApplicationContext(getState, action) {