Browse Source

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
j8
virtuacoplenny 5 years ago
parent
commit
ada57ebcd0
No account linked to committer's email address

+ 2
- 2
package-lock.json View File

9042
       }
9042
       }
9043
     },
9043
     },
9044
     "lib-jitsi-meet": {
9044
     "lib-jitsi-meet": {
9045
-      "version": "github:jitsi/lib-jitsi-meet#24bda8e941c346ccfde6bc1e1bb5dcdbd9450bab",
9046
-      "from": "github:jitsi/lib-jitsi-meet#24bda8e941c346ccfde6bc1e1bb5dcdbd9450bab",
9045
+      "version": "github:jitsi/lib-jitsi-meet#d4682073558205289ec89720b452275c325ad652",
9046
+      "from": "github:jitsi/lib-jitsi-meet#d4682073558205289ec89720b452275c325ad652",
9047
       "requires": {
9047
       "requires": {
9048
         "@jitsi/sdp-interop": "0.1.14",
9048
         "@jitsi/sdp-interop": "0.1.14",
9049
         "@jitsi/sdp-simulcast": "0.2.1",
9049
         "@jitsi/sdp-simulcast": "0.2.1",

+ 1
- 1
package.json View File

54
     "js-utils": "github:jitsi/js-utils#192b1c996e8c05530eb1f19e82a31069c3021e31",
54
     "js-utils": "github:jitsi/js-utils#192b1c996e8c05530eb1f19e82a31069c3021e31",
55
     "jsrsasign": "8.0.12",
55
     "jsrsasign": "8.0.12",
56
     "jwt-decode": "2.2.0",
56
     "jwt-decode": "2.2.0",
57
-    "lib-jitsi-meet": "github:jitsi/lib-jitsi-meet#24bda8e941c346ccfde6bc1e1bb5dcdbd9450bab",
57
+    "lib-jitsi-meet": "github:jitsi/lib-jitsi-meet#d4682073558205289ec89720b452275c325ad652",
58
     "libflacjs": "github:mmig/libflac.js#93d37e7f811f01cf7d8b6a603e38bd3c3810907d",
58
     "libflacjs": "github:mmig/libflac.js#93d37e7f811f01cf7d8b6a603e38bd3c3810907d",
59
     "lodash": "4.17.11",
59
     "lodash": "4.17.11",
60
     "moment": "2.19.4",
60
     "moment": "2.19.4",

+ 2
- 7
react/features/base/tracks/functions.js View File

1
 /* global APP */
1
 /* global APP */
2
 
2
 
3
 import { getBlurEffect } from '../../blur';
3
 import { getBlurEffect } from '../../blur';
4
-import JitsiMeetJS, { JitsiTrackErrors } from '../lib-jitsi-meet';
4
+import JitsiMeetJS, { JitsiTrackErrors, browser } from '../lib-jitsi-meet';
5
 import { MEDIA_TYPE } from '../media';
5
 import { MEDIA_TYPE } from '../media';
6
 import {
6
 import {
7
     getUserSelectedCameraDeviceId,
7
     getUserSelectedCameraDeviceId,
236
  * @returns {boolean}
236
  * @returns {boolean}
237
  */
237
  */
238
 export function isUserInteractionRequiredForUnmute(state) {
238
 export function isUserInteractionRequiredForUnmute(state) {
239
-    const { browser } = JitsiMeetJS.util;
240
-
241
-    return !browser.isReactNative()
242
-        && !browser.isChrome()
243
-        && !browser.isChromiumBased()
244
-        && !browser.isElectron()
239
+    return browser.isUserInteractionRequiredForUnmute()
245
         && window
240
         && window
246
         && window.self !== window.top
241
         && window.self !== window.top
247
         && !state['features/base/user-interaction'].interacted;
242
         && !state['features/base/user-interaction'].interacted;

+ 0
- 11
react/features/base/user-interaction/actionTypes.js View File

1
-/**
2
- * The type of (redux) action which signals that an event listener has been
3
- * added to listen for any user interaction with the page.
4
- *
5
- * {
6
- *     type: SET_USER_INTERACTION_LISTENER,
7
- *     userInteractionListener: Function
8
- * }
9
- */
10
-export const SET_USER_INTERACTION_LISTENER = 'SET_USER_INTERACTION_LISTENER';
11
-
12
 /**
1
 /**
13
  * The type of (redux) action which signals the user has interacted with the
2
  * The type of (redux) action which signals the user has interacted with the
14
  * page.
3
  * page.

+ 36
- 34
react/features/base/user-interaction/middleware.js View File

3
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
3
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
4
 import { MiddlewareRegistry } from '../redux';
4
 import { MiddlewareRegistry } from '../redux';
5
 
5
 
6
-import {
7
-    SET_USER_INTERACTION_LISTENER,
8
-    USER_INTERACTION_RECEIVED
9
-} from './actionTypes';
6
+import { USER_INTERACTION_RECEIVED } from './actionTypes';
7
+
8
+/**
9
+ * Reference to any callback that has been created to be invoked on user
10
+ * interaction.
11
+ *
12
+ * @type {Function|null}
13
+ */
14
+let userInteractionListener = null;
10
 
15
 
11
 /**
16
 /**
12
  * Implements the entry point of the middleware of the feature base/user-interaction.
17
  * Implements the entry point of the middleware of the feature base/user-interaction.
21
         break;
26
         break;
22
 
27
 
23
     case APP_WILL_UNMOUNT:
28
     case APP_WILL_UNMOUNT:
24
-    case USER_INTERACTION_RECEIVED:
25
-        _stopListeningForUserInteraction(store);
29
+        _stopListeningForUserInteraction();
26
         break;
30
         break;
27
     }
31
     }
28
 
32
 
29
     return next(action);
33
     return next(action);
30
 });
34
 });
31
 
35
 
36
+/**
37
+ * Callback invoked when the user interacts with the page.
38
+ *
39
+ * @param {Function} dispatch - The redux dispatch function.
40
+ * @param {Object} event - The DOM event for a user interacting with the page.
41
+ * @private
42
+ * @returns {void}
43
+ */
44
+function _onUserInteractionReceived(dispatch, event) {
45
+    if (event.isTrusted) {
46
+        dispatch({
47
+            type: USER_INTERACTION_RECEIVED
48
+        });
49
+
50
+        _stopListeningForUserInteraction();
51
+    }
52
+}
53
+
32
 /**
54
 /**
33
  * Registers listeners to notify redux of any user interaction with the page.
55
  * Registers listeners to notify redux of any user interaction with the page.
34
  *
56
  *
36
  * @private
58
  * @private
37
  * @returns {void}
59
  * @returns {void}
38
  */
60
  */
39
-function _startListeningForUserInteraction(store) {
40
-    const userInteractionListener = event => {
41
-        if (event.isTrusted) {
42
-            store.dispatch({
43
-                type: USER_INTERACTION_RECEIVED
44
-            });
61
+function _startListeningForUserInteraction({ dispatch }) {
62
+    _stopListeningForUserInteraction();
45
 
63
 
46
-            _stopListeningForUserInteraction(store);
47
-        }
48
-    };
64
+    userInteractionListener = _onUserInteractionReceived.bind(null, dispatch);
49
 
65
 
50
     window.addEventListener('mousedown', userInteractionListener);
66
     window.addEventListener('mousedown', userInteractionListener);
51
     window.addEventListener('keydown', userInteractionListener);
67
     window.addEventListener('keydown', userInteractionListener);
52
-
53
-    store.dispatch({
54
-        type: SET_USER_INTERACTION_LISTENER,
55
-        userInteractionListener
56
-    });
57
 }
68
 }
58
 
69
 
59
 /**
70
 /**
60
- * Un-registers listeners intended to notify when the user has interacted with
61
- * the page.
71
+ * De-registers listeners for user interaction with the page.
62
  *
72
  *
63
- * @param {Object} store - The redux store.
64
  * @private
73
  * @private
65
  * @returns {void}
74
  * @returns {void}
66
  */
75
  */
67
-function _stopListeningForUserInteraction({ getState, dispatch }) {
68
-    const { userInteractionListener } = getState()['features/base/app'];
69
-
70
-    if (userInteractionListener) {
71
-        window.removeEventListener('mousedown', userInteractionListener);
72
-        window.removeEventListener('keydown', userInteractionListener);
76
+function _stopListeningForUserInteraction() {
77
+    window.removeEventListener('mousedown', userInteractionListener);
78
+    window.removeEventListener('keydown', userInteractionListener);
73
 
79
 
74
-        dispatch({
75
-            type: SET_USER_INTERACTION_LISTENER,
76
-            userInteractionListener: undefined
77
-        });
78
-    }
80
+    userInteractionListener = null;
79
 }
81
 }

+ 2
- 11
react/features/base/user-interaction/reducer.js View File

3
 import { ReducerRegistry } from '../redux';
3
 import { ReducerRegistry } from '../redux';
4
 
4
 
5
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
5
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
6
-import {
7
-    SET_USER_INTERACTION_LISTENER,
8
-    USER_INTERACTION_RECEIVED
9
-} from './actionTypes';
6
+import { USER_INTERACTION_RECEIVED } from './actionTypes';
10
 
7
 
11
 ReducerRegistry.register('features/base/user-interaction', (state = {}, action) => {
8
 ReducerRegistry.register('features/base/user-interaction', (state = {}, action) => {
12
     switch (action.type) {
9
     switch (action.type) {
13
     case APP_WILL_MOUNT:
10
     case APP_WILL_MOUNT:
14
-    case APP_WILL_UNMOUNT: {
11
+    case APP_WILL_UNMOUNT:
15
         return {
12
         return {
16
             ...state,
13
             ...state,
17
             interacted: false
14
             interacted: false
18
         };
15
         };
19
-    }
20
-    case SET_USER_INTERACTION_LISTENER:
21
-        return {
22
-            ...state,
23
-            userInteractionListener: action.userInteractionListener
24
-        };
25
 
16
 
26
     case USER_INTERACTION_RECEIVED:
17
     case USER_INTERACTION_RECEIVED:
27
         return {
18
         return {

Loading…
Cancel
Save