From 724391648e2757329172a37e681d2f8691550ae2 Mon Sep 17 00:00:00 2001 From: Alex Bumbu Date: Thu, 27 May 2021 16:53:20 +0300 Subject: [PATCH] fix(ScreenShare): remove listener for native events when app unmounts --- .../mobile/external-api/middleware.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/react/features/mobile/external-api/middleware.js b/react/features/mobile/external-api/middleware.js index 09f51ac51..93d89d8e4 100644 --- a/react/features/mobile/external-api/middleware.js +++ b/react/features/mobile/external-api/middleware.js @@ -5,7 +5,7 @@ import { NativeEventEmitter, NativeModules } from 'react-native'; import { ENDPOINT_TEXT_MESSAGE_NAME } from '../../../../modules/API/constants'; import { appNavigate } from '../../app/actions'; -import { APP_WILL_MOUNT } from '../../base/app/actionTypes'; +import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../base/app/actionTypes'; import { CONFERENCE_FAILED, CONFERENCE_JOINED, @@ -93,6 +93,9 @@ MiddlewareRegistry.register(store => next => action => { case APP_WILL_MOUNT: _registerForNativeEvents(store); break; + case APP_WILL_UNMOUNT: + _unregisterForNativeEvents(); + break; case CONFERENCE_FAILED: { const { error, ...data } = action; @@ -349,6 +352,24 @@ function _registerForNativeEvents(store) { } +/** + * Unregister for events sent from the native side via NativeEventEmitter. + * + * @private + * @returns {void} + */ +function _unregisterForNativeEvents() { + eventEmitter.removeAllListeners(ExternalAPI.HANG_UP); + eventEmitter.removeAllListeners(ExternalAPI.SET_AUDIO_MUTED); + eventEmitter.removeAllListeners(ExternalAPI.SET_VIDEO_MUTED); + eventEmitter.removeAllListeners(ExternalAPI.SEND_ENDPOINT_TEXT_MESSAGE); + eventEmitter.removeAllListeners(ExternalAPI.TOGGLE_SCREEN_SHARE); + eventEmitter.removeAllListeners(ExternalAPI.RETRIEVE_PARTICIPANTS_INFO); + eventEmitter.removeAllListeners(ExternalAPI.OPEN_CHAT); + eventEmitter.removeAllListeners(ExternalAPI.CLOSE_CHAT); + eventEmitter.removeAllListeners(ExternalAPI.SEND_CHAT_MESSAGE); +} + /** * Registers for endpoint messages sent on conference data channel. *