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": {
|
||||
"version": "github:jitsi/lib-jitsi-meet#24bda8e941c346ccfde6bc1e1bb5dcdbd9450bab",
|
||||
"from": "github:jitsi/lib-jitsi-meet#24bda8e941c346ccfde6bc1e1bb5dcdbd9450bab",
|
||||
"version": "github:jitsi/lib-jitsi-meet#d4682073558205289ec89720b452275c325ad652",
|
||||
"from": "github:jitsi/lib-jitsi-meet#d4682073558205289ec89720b452275c325ad652",
|
||||
"requires": {
|
||||
"@jitsi/sdp-interop": "0.1.14",
|
||||
"@jitsi/sdp-simulcast": "0.2.1",
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
"js-utils": "github:jitsi/js-utils#192b1c996e8c05530eb1f19e82a31069c3021e31",
|
||||
"jsrsasign": "8.0.12",
|
||||
"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",
|
||||
"lodash": "4.17.11",
|
||||
"moment": "2.19.4",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* global APP */
|
||||
|
||||
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 {
|
||||
getUserSelectedCameraDeviceId,
|
||||
|
@ -236,12 +236,7 @@ export function isRemoteTrackMuted(tracks, mediaType, participantId) {
|
|||
* @returns {boolean}
|
||||
*/
|
||||
export function isUserInteractionRequiredForUnmute(state) {
|
||||
const { browser } = JitsiMeetJS.util;
|
||||
|
||||
return !browser.isReactNative()
|
||||
&& !browser.isChrome()
|
||||
&& !browser.isChromiumBased()
|
||||
&& !browser.isElectron()
|
||||
return browser.isUserInteractionRequiredForUnmute()
|
||||
&& window
|
||||
&& window.self !== window.top
|
||||
&& !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
|
||||
* page.
|
||||
|
|
|
@ -3,10 +3,15 @@
|
|||
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
|
||||
import { MiddlewareRegistry } from '../redux';
|
||||
|
||||
import {
|
||||
SET_USER_INTERACTION_LISTENER,
|
||||
USER_INTERACTION_RECEIVED
|
||||
} from './actionTypes';
|
||||
import { 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.
|
||||
|
@ -21,14 +26,31 @@ MiddlewareRegistry.register(store => next => action => {
|
|||
break;
|
||||
|
||||
case APP_WILL_UNMOUNT:
|
||||
case USER_INTERACTION_RECEIVED:
|
||||
_stopListeningForUserInteraction(store);
|
||||
_stopListeningForUserInteraction();
|
||||
break;
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
|
@ -36,44 +58,24 @@ MiddlewareRegistry.register(store => next => action => {
|
|||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
function _startListeningForUserInteraction(store) {
|
||||
const userInteractionListener = event => {
|
||||
if (event.isTrusted) {
|
||||
store.dispatch({
|
||||
type: USER_INTERACTION_RECEIVED
|
||||
});
|
||||
function _startListeningForUserInteraction({ dispatch }) {
|
||||
_stopListeningForUserInteraction();
|
||||
|
||||
_stopListeningForUserInteraction(store);
|
||||
}
|
||||
};
|
||||
userInteractionListener = _onUserInteractionReceived.bind(null, dispatch);
|
||||
|
||||
window.addEventListener('mousedown', 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
|
||||
* the page.
|
||||
* De-registers listeners for user interaction with the page.
|
||||
*
|
||||
* @param {Object} store - The redux store.
|
||||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
function _stopListeningForUserInteraction({ getState, dispatch }) {
|
||||
const { userInteractionListener } = getState()['features/base/app'];
|
||||
function _stopListeningForUserInteraction() {
|
||||
window.removeEventListener('mousedown', userInteractionListener);
|
||||
window.removeEventListener('keydown', userInteractionListener);
|
||||
|
||||
if (userInteractionListener) {
|
||||
window.removeEventListener('mousedown', userInteractionListener);
|
||||
window.removeEventListener('keydown', userInteractionListener);
|
||||
|
||||
dispatch({
|
||||
type: SET_USER_INTERACTION_LISTENER,
|
||||
userInteractionListener: undefined
|
||||
});
|
||||
}
|
||||
userInteractionListener = null;
|
||||
}
|
||||
|
|
|
@ -3,25 +3,16 @@
|
|||
import { ReducerRegistry } from '../redux';
|
||||
|
||||
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
|
||||
import {
|
||||
SET_USER_INTERACTION_LISTENER,
|
||||
USER_INTERACTION_RECEIVED
|
||||
} from './actionTypes';
|
||||
import { USER_INTERACTION_RECEIVED } from './actionTypes';
|
||||
|
||||
ReducerRegistry.register('features/base/user-interaction', (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case APP_WILL_MOUNT:
|
||||
case APP_WILL_UNMOUNT: {
|
||||
case APP_WILL_UNMOUNT:
|
||||
return {
|
||||
...state,
|
||||
interacted: false
|
||||
};
|
||||
}
|
||||
case SET_USER_INTERACTION_LISTENER:
|
||||
return {
|
||||
...state,
|
||||
userInteractionListener: action.userInteractionListener
|
||||
};
|
||||
|
||||
case USER_INTERACTION_RECEIVED:
|
||||
return {
|
||||
|
|
Loading…
Reference in New Issue