From 96504040992693b3d8621a7b4eef4954a7d09b96 Mon Sep 17 00:00:00 2001 From: paweldomas Date: Tue, 15 May 2018 15:24:58 -0500 Subject: [PATCH] fix(base/conference): leave a failed conference Because a conference can fail before or after it's joined it must be "left" in order to release any allocated resources like peerconnections, tracks and all the other things. --- react/features/base/conference/middleware.js | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/react/features/base/conference/middleware.js b/react/features/base/conference/middleware.js index 770d06fbd..973bcd707 100644 --- a/react/features/base/conference/middleware.js +++ b/react/features/base/conference/middleware.js @@ -26,6 +26,7 @@ import { toggleAudioOnly } from './actions'; import { + CONFERENCE_FAILED, CONFERENCE_JOINED, DATA_CHANNEL_OPENED, SET_AUDIO_ONLY, @@ -55,6 +56,9 @@ MiddlewareRegistry.register(store => next => action => { case CONNECTION_ESTABLISHED: return _connectionEstablished(store, next, action); + case CONFERENCE_FAILED: + return _conferenceFailed(next, action); + case CONFERENCE_JOINED: return _conferenceJoined(store, next, action); @@ -109,6 +113,33 @@ function _connectionEstablished({ dispatch }, next, action) { return result; } +/** + * Makes sure to leave a failed conference in order to release any allocated + * resources like peerconnections, emit participant left events etc. + * + * @param {Dispatch} next - The redux dispatch function to dispatch the + * specified action to the specified store. + * @param {Action} action - The redux action CONFERENCE_FAILED which is being + * dispatched in the specified store. + * @private + * @returns {Object} The value returned by {@code next(action)}. + */ +function _conferenceFailed(next, action) { + const result = next(action); + const { conference, error } = action; + + !error.recoverable + && conference + && conference.leave().catch(leaveError => { + // Even though we don't care too much about the failure it may be + // good to now that it happen, so log it on the info level. + logger.info( + 'There was an error leaving a failed conference: ', leaveError); + }); + + return result; +} + /** * Does extra sync up on properties that may need to be updated after the * conference was joined.