feat: Add disableBeforeUnloadHandlers option

This commit is contained in:
Hristo Terezov 2021-11-29 18:21:29 -06:00
parent 2097d77666
commit b2d6054e1c
5 changed files with 46 additions and 33 deletions

View File

@ -400,6 +400,9 @@ var config = {
// Disables or enables RTX (RFC 4588) (defaults to false). // Disables or enables RTX (RFC 4588) (defaults to false).
// disableRtx: false, // disableRtx: false,
// Moves all Jitsi Meet 'beforeunload' logic (cleanup, leaving, disconnecting, etc) to the 'unload' event.
// disableBeforeUnloadHandlers: true,
// Disables or enables TCC support in this client (default: enabled). // Disables or enables TCC support in this client (default: enabled).
// enableTcc: true, // enableTcc: true,

View File

@ -79,7 +79,7 @@ MiddlewareRegistry.register(store => next => action => {
return _conferenceSubjectChanged(store, next, action); return _conferenceSubjectChanged(store, next, action);
case CONFERENCE_WILL_LEAVE: case CONFERENCE_WILL_LEAVE:
_conferenceWillLeave(); _conferenceWillLeave(store);
break; break;
case PARTICIPANT_UPDATED: case PARTICIPANT_UPDATED:
@ -102,7 +102,6 @@ MiddlewareRegistry.register(store => next => action => {
return next(action); return next(action);
}); });
/** /**
* Makes sure to leave a failed conference in order to release any allocated * Makes sure to leave a failed conference in order to release any allocated
* resources like peer connections, emit participant left events, etc. * resources like peer connections, emit participant left events, etc.
@ -168,12 +167,11 @@ function _conferenceFailed({ dispatch, getState }, next, action) {
// good to know that it happen, so log it (on the info level). // good to know that it happen, so log it (on the info level).
logger.info('JitsiConference.leave() rejected with:', reason); logger.info('JitsiConference.leave() rejected with:', reason);
}); });
} else if (typeof beforeUnloadHandler !== 'undefined') { } else {
// FIXME: Workaround for the web version. Currently, the creation of the // FIXME: Workaround for the web version. Currently, the creation of the
// conference is handled by /conference.js and appropriate failure handlers // conference is handled by /conference.js and appropriate failure handlers
// are set there. // are set there.
window.removeEventListener('beforeunload', beforeUnloadHandler); _removeUnloadHandler(getState);
beforeUnloadHandler = undefined;
} }
if (enableForcedReload && error?.name === JitsiConferenceErrors.CONFERENCE_RESTARTED) { if (enableForcedReload && error?.name === JitsiConferenceErrors.CONFERENCE_RESTARTED) {
@ -201,7 +199,7 @@ function _conferenceJoined({ dispatch, getState }, next, action) {
const result = next(action); const result = next(action);
const { conference } = action; const { conference } = action;
const { pendingSubjectChange } = getState()['features/base/conference']; const { pendingSubjectChange } = getState()['features/base/conference'];
const { requireDisplayName } = getState()['features/base/config']; const { requireDisplayName, disableBeforeUnloadHandlers = false } = getState()['features/base/config'];
pendingSubjectChange && dispatch(setSubject(pendingSubjectChange)); pendingSubjectChange && dispatch(setSubject(pendingSubjectChange));
@ -213,7 +211,7 @@ function _conferenceJoined({ dispatch, getState }, next, action) {
beforeUnloadHandler = () => { beforeUnloadHandler = () => {
dispatch(conferenceWillLeave(conference)); dispatch(conferenceWillLeave(conference));
}; };
window.addEventListener('beforeunload', beforeUnloadHandler); window.addEventListener(disableBeforeUnloadHandlers ? 'unload' : 'beforeunload', beforeUnloadHandler);
if (requireDisplayName if (requireDisplayName
&& !getLocalParticipant(getState)?.name && !getLocalParticipant(getState)?.name
@ -287,10 +285,7 @@ function _connectionFailed({ dispatch, getState }, next, action) {
const result = next(action); const result = next(action);
if (typeof beforeUnloadHandler !== 'undefined') { _removeUnloadHandler(getState);
window.removeEventListener('beforeunload', beforeUnloadHandler);
beforeUnloadHandler = undefined;
}
// FIXME: Workaround for the web version. Currently, the creation of the // FIXME: Workaround for the web version. Currently, the creation of the
// conference is handled by /conference.js and appropriate failure handlers // conference is handled by /conference.js and appropriate failure handlers
@ -367,13 +362,11 @@ function _conferenceSubjectChanged({ dispatch, getState }, next, action) {
* store. * store.
* *
* @private * @private
* @param {Object} store - The redux store.
* @returns {void} * @returns {void}
*/ */
function _conferenceWillLeave() { function _conferenceWillLeave({ getState }: { getState: Function }) {
if (typeof beforeUnloadHandler !== 'undefined') { _removeUnloadHandler(getState);
window.removeEventListener('beforeunload', beforeUnloadHandler);
beforeUnloadHandler = undefined;
}
} }
/** /**
@ -425,6 +418,21 @@ function _pinParticipant({ getState }, next, action) {
return next(action); return next(action);
} }
/**
* Removes the unload handler.
*
* @param {Function} getState - The redux getState function.
* @returns {void}
*/
function _removeUnloadHandler(getState) {
if (typeof beforeUnloadHandler !== 'undefined') {
const { disableBeforeUnloadHandlers = false } = getState()['features/base/config'];
window.removeEventListener(disableBeforeUnloadHandlers ? 'unload' : 'beforeunload', beforeUnloadHandler);
beforeUnloadHandler = undefined;
}
}
/** /**
* Requests the specified tones to be played. * Requests the specified tones to be played.
* *

View File

@ -91,6 +91,7 @@ export default [
'disableAP', 'disableAP',
'disableAddingBackgroundImages', 'disableAddingBackgroundImages',
'disableAudioLevels', 'disableAudioLevels',
'disableBeforeUnloadHandlers',
'disableChatSmileys', 'disableChatSmileys',
'disableDeepLinking', 'disableDeepLinking',
'disabledSounds', 'disabledSounds',

View File

@ -1,11 +1,13 @@
// @flow // @flow
import { getJitsiMeetTransport } from '../../../modules/transport';
import { import {
CONFERENCE_FAILED, CONFERENCE_FAILED,
CONFERENCE_JOINED, CONFERENCE_JOINED,
DATA_CHANNEL_OPENED, DATA_CHANNEL_OPENED,
KICKED_OUT KICKED_OUT
} from '../base/conference'; } from '../base/conference';
import { SET_CONFIG } from '../base/config';
import { NOTIFY_CAMERA_ERROR, NOTIFY_MIC_ERROR } from '../base/devices'; import { NOTIFY_CAMERA_ERROR, NOTIFY_MIC_ERROR } from '../base/devices';
import { JitsiConferenceErrors } from '../base/lib-jitsi-meet'; import { JitsiConferenceErrors } from '../base/lib-jitsi-meet';
import { import {
@ -171,6 +173,22 @@ MiddlewareRegistry.register(store => next => action => {
APP.API.notifyUserRoleChanged(action.participant.id, action.participant.role); APP.API.notifyUserRoleChanged(action.participant.id, action.participant.role);
break; break;
case SET_CONFIG: {
const state = store.getState();
const { disableBeforeUnloadHandlers = false } = state['features/base/config'];
/**
* Disposing the API when the user closes the page.
*/
window.addEventListener(disableBeforeUnloadHandlers ? 'unload' : 'beforeunload', () => {
APP.API.notifyConferenceLeft(APP.conference.roomName);
APP.API.dispose();
getJitsiMeetTransport().dispose();
});
break;
}
case SET_FILMSTRIP_VISIBLE: case SET_FILMSTRIP_VISIBLE:
APP.API.notifyFilmstripDisplayChanged(action.visible); APP.API.notifyFilmstripDisplayChanged(action.visible);
break; break;

View File

@ -3,8 +3,6 @@
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import { getJitsiMeetTransport } from '../modules/transport';
import { App } from './features/app/components'; import { App } from './features/app/components';
import { getLogger } from './features/base/logging/functions'; import { getLogger } from './features/base/logging/functions';
import { Platform } from './features/base/react'; import { Platform } from './features/base/react';
@ -41,21 +39,6 @@ if (OS === 'ios') {
}); });
} }
/**
* Stops collecting the logs and disposing the API when the user closes the
* page.
*/
window.addEventListener('beforeunload', () => {
// Stop the LogCollector
if (APP.logCollectorStarted) {
APP.logCollector.stop();
APP.logCollectorStarted = false;
}
APP.API.notifyConferenceLeft(APP.conference.roomName);
APP.API.dispose();
getJitsiMeetTransport().dispose();
});
const globalNS = getJitsiMeetGlobalNS(); const globalNS = getJitsiMeetGlobalNS();
globalNS.entryPoints = { globalNS.entryPoints = {