From ada57ebcd039ef49acd85c1c98d22d83fb413fae Mon Sep 17 00:00:00 2001 From: virtuacoplenny <1243084+virtuacoplenny@users.noreply.github.com> Date: Sat, 13 Jul 2019 06:59:58 -0700 Subject: [PATCH] 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 --- package-lock.json | 4 +- package.json | 2 +- react/features/base/tracks/functions.js | 9 +-- .../base/user-interaction/actionTypes.js | 11 --- .../base/user-interaction/middleware.js | 70 ++++++++++--------- .../features/base/user-interaction/reducer.js | 13 +--- 6 files changed, 43 insertions(+), 66 deletions(-) diff --git a/package-lock.json b/package-lock.json index 82c1073b9..668895230 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 5f1ae4a69..4d6661515 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/react/features/base/tracks/functions.js b/react/features/base/tracks/functions.js index ea4784d6c..34dcff8de 100644 --- a/react/features/base/tracks/functions.js +++ b/react/features/base/tracks/functions.js @@ -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; diff --git a/react/features/base/user-interaction/actionTypes.js b/react/features/base/user-interaction/actionTypes.js index 29cb8bca4..f0cfb67fb 100644 --- a/react/features/base/user-interaction/actionTypes.js +++ b/react/features/base/user-interaction/actionTypes.js @@ -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. diff --git a/react/features/base/user-interaction/middleware.js b/react/features/base/user-interaction/middleware.js index 3080cc81d..eb5600492 100644 --- a/react/features/base/user-interaction/middleware.js +++ b/react/features/base/user-interaction/middleware.js @@ -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; } diff --git a/react/features/base/user-interaction/reducer.js b/react/features/base/user-interaction/reducer.js index 4409907b9..ff27f65f9 100644 --- a/react/features/base/user-interaction/reducer.js +++ b/react/features/base/user-interaction/reducer.js @@ -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 {