ref(user-interaction): do not store listener, move browser check to lib (#4441)
* ref(user-interaction): remove storing of listener * ref(user-interaction): move browser requirement check to lib-jitsi-meet * ref(user-interaction): no inner function for listener, use module scope
This commit is contained in:
parent
1993ad10eb
commit
ada57ebcd0
|
@ -9042,8 +9042,8 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lib-jitsi-meet": {
|
"lib-jitsi-meet": {
|
||||||
"version": "github:jitsi/lib-jitsi-meet#24bda8e941c346ccfde6bc1e1bb5dcdbd9450bab",
|
"version": "github:jitsi/lib-jitsi-meet#d4682073558205289ec89720b452275c325ad652",
|
||||||
"from": "github:jitsi/lib-jitsi-meet#24bda8e941c346ccfde6bc1e1bb5dcdbd9450bab",
|
"from": "github:jitsi/lib-jitsi-meet#d4682073558205289ec89720b452275c325ad652",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@jitsi/sdp-interop": "0.1.14",
|
"@jitsi/sdp-interop": "0.1.14",
|
||||||
"@jitsi/sdp-simulcast": "0.2.1",
|
"@jitsi/sdp-simulcast": "0.2.1",
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
"js-utils": "github:jitsi/js-utils#192b1c996e8c05530eb1f19e82a31069c3021e31",
|
"js-utils": "github:jitsi/js-utils#192b1c996e8c05530eb1f19e82a31069c3021e31",
|
||||||
"jsrsasign": "8.0.12",
|
"jsrsasign": "8.0.12",
|
||||||
"jwt-decode": "2.2.0",
|
"jwt-decode": "2.2.0",
|
||||||
"lib-jitsi-meet": "github:jitsi/lib-jitsi-meet#24bda8e941c346ccfde6bc1e1bb5dcdbd9450bab",
|
"lib-jitsi-meet": "github:jitsi/lib-jitsi-meet#d4682073558205289ec89720b452275c325ad652",
|
||||||
"libflacjs": "github:mmig/libflac.js#93d37e7f811f01cf7d8b6a603e38bd3c3810907d",
|
"libflacjs": "github:mmig/libflac.js#93d37e7f811f01cf7d8b6a603e38bd3c3810907d",
|
||||||
"lodash": "4.17.11",
|
"lodash": "4.17.11",
|
||||||
"moment": "2.19.4",
|
"moment": "2.19.4",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* global APP */
|
/* global APP */
|
||||||
|
|
||||||
import { getBlurEffect } from '../../blur';
|
import { getBlurEffect } from '../../blur';
|
||||||
import JitsiMeetJS, { JitsiTrackErrors } from '../lib-jitsi-meet';
|
import JitsiMeetJS, { JitsiTrackErrors, browser } from '../lib-jitsi-meet';
|
||||||
import { MEDIA_TYPE } from '../media';
|
import { MEDIA_TYPE } from '../media';
|
||||||
import {
|
import {
|
||||||
getUserSelectedCameraDeviceId,
|
getUserSelectedCameraDeviceId,
|
||||||
|
@ -236,12 +236,7 @@ export function isRemoteTrackMuted(tracks, mediaType, participantId) {
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
export function isUserInteractionRequiredForUnmute(state) {
|
export function isUserInteractionRequiredForUnmute(state) {
|
||||||
const { browser } = JitsiMeetJS.util;
|
return browser.isUserInteractionRequiredForUnmute()
|
||||||
|
|
||||||
return !browser.isReactNative()
|
|
||||||
&& !browser.isChrome()
|
|
||||||
&& !browser.isChromiumBased()
|
|
||||||
&& !browser.isElectron()
|
|
||||||
&& window
|
&& window
|
||||||
&& window.self !== window.top
|
&& window.self !== window.top
|
||||||
&& !state['features/base/user-interaction'].interacted;
|
&& !state['features/base/user-interaction'].interacted;
|
||||||
|
|
|
@ -1,14 +1,3 @@
|
||||||
/**
|
|
||||||
* The type of (redux) action which signals that an event listener has been
|
|
||||||
* added to listen for any user interaction with the page.
|
|
||||||
*
|
|
||||||
* {
|
|
||||||
* type: SET_USER_INTERACTION_LISTENER,
|
|
||||||
* userInteractionListener: Function
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
export const SET_USER_INTERACTION_LISTENER = 'SET_USER_INTERACTION_LISTENER';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of (redux) action which signals the user has interacted with the
|
* The type of (redux) action which signals the user has interacted with the
|
||||||
* page.
|
* page.
|
||||||
|
|
|
@ -3,10 +3,15 @@
|
||||||
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
|
||||||
import { MiddlewareRegistry } from '../redux';
|
import { MiddlewareRegistry } from '../redux';
|
||||||
|
|
||||||
import {
|
import { USER_INTERACTION_RECEIVED } from './actionTypes';
|
||||||
SET_USER_INTERACTION_LISTENER,
|
|
||||||
USER_INTERACTION_RECEIVED
|
/**
|
||||||
} from './actionTypes';
|
* Reference to any callback that has been created to be invoked on user
|
||||||
|
* interaction.
|
||||||
|
*
|
||||||
|
* @type {Function|null}
|
||||||
|
*/
|
||||||
|
let userInteractionListener = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the entry point of the middleware of the feature base/user-interaction.
|
* Implements the entry point of the middleware of the feature base/user-interaction.
|
||||||
|
@ -21,14 +26,31 @@ MiddlewareRegistry.register(store => next => action => {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case APP_WILL_UNMOUNT:
|
case APP_WILL_UNMOUNT:
|
||||||
case USER_INTERACTION_RECEIVED:
|
_stopListeningForUserInteraction();
|
||||||
_stopListeningForUserInteraction(store);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return next(action);
|
return next(action);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback invoked when the user interacts with the page.
|
||||||
|
*
|
||||||
|
* @param {Function} dispatch - The redux dispatch function.
|
||||||
|
* @param {Object} event - The DOM event for a user interacting with the page.
|
||||||
|
* @private
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function _onUserInteractionReceived(dispatch, event) {
|
||||||
|
if (event.isTrusted) {
|
||||||
|
dispatch({
|
||||||
|
type: USER_INTERACTION_RECEIVED
|
||||||
|
});
|
||||||
|
|
||||||
|
_stopListeningForUserInteraction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers listeners to notify redux of any user interaction with the page.
|
* Registers listeners to notify redux of any user interaction with the page.
|
||||||
*
|
*
|
||||||
|
@ -36,44 +58,24 @@ MiddlewareRegistry.register(store => next => action => {
|
||||||
* @private
|
* @private
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function _startListeningForUserInteraction(store) {
|
function _startListeningForUserInteraction({ dispatch }) {
|
||||||
const userInteractionListener = event => {
|
_stopListeningForUserInteraction();
|
||||||
if (event.isTrusted) {
|
|
||||||
store.dispatch({
|
|
||||||
type: USER_INTERACTION_RECEIVED
|
|
||||||
});
|
|
||||||
|
|
||||||
_stopListeningForUserInteraction(store);
|
userInteractionListener = _onUserInteractionReceived.bind(null, dispatch);
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener('mousedown', userInteractionListener);
|
window.addEventListener('mousedown', userInteractionListener);
|
||||||
window.addEventListener('keydown', userInteractionListener);
|
window.addEventListener('keydown', userInteractionListener);
|
||||||
|
|
||||||
store.dispatch({
|
|
||||||
type: SET_USER_INTERACTION_LISTENER,
|
|
||||||
userInteractionListener
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Un-registers listeners intended to notify when the user has interacted with
|
* De-registers listeners for user interaction with the page.
|
||||||
* the page.
|
|
||||||
*
|
*
|
||||||
* @param {Object} store - The redux store.
|
|
||||||
* @private
|
* @private
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function _stopListeningForUserInteraction({ getState, dispatch }) {
|
function _stopListeningForUserInteraction() {
|
||||||
const { userInteractionListener } = getState()['features/base/app'];
|
window.removeEventListener('mousedown', userInteractionListener);
|
||||||
|
window.removeEventListener('keydown', userInteractionListener);
|
||||||
|
|
||||||
if (userInteractionListener) {
|
userInteractionListener = null;
|
||||||
window.removeEventListener('mousedown', userInteractionListener);
|
|
||||||
window.removeEventListener('keydown', userInteractionListener);
|
|
||||||
|
|
||||||
dispatch({
|
|
||||||
type: SET_USER_INTERACTION_LISTENER,
|
|
||||||
userInteractionListener: undefined
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,25 +3,16 @@
|
||||||
import { ReducerRegistry } from '../redux';
|
import { ReducerRegistry } from '../redux';
|
||||||
|
|
||||||
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
|
||||||
import {
|
import { USER_INTERACTION_RECEIVED } from './actionTypes';
|
||||||
SET_USER_INTERACTION_LISTENER,
|
|
||||||
USER_INTERACTION_RECEIVED
|
|
||||||
} from './actionTypes';
|
|
||||||
|
|
||||||
ReducerRegistry.register('features/base/user-interaction', (state = {}, action) => {
|
ReducerRegistry.register('features/base/user-interaction', (state = {}, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case APP_WILL_MOUNT:
|
case APP_WILL_MOUNT:
|
||||||
case APP_WILL_UNMOUNT: {
|
case APP_WILL_UNMOUNT:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
interacted: false
|
interacted: false
|
||||||
};
|
};
|
||||||
}
|
|
||||||
case SET_USER_INTERACTION_LISTENER:
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
userInteractionListener: action.userInteractionListener
|
|
||||||
};
|
|
||||||
|
|
||||||
case USER_INTERACTION_RECEIVED:
|
case USER_INTERACTION_RECEIVED:
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue