Quellcode durchsuchen

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 vor 5 Jahren
Ursprung
Commit
ada57ebcd0
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden

+ 2
- 2
package-lock.json Datei anzeigen

@@ -9042,8 +9042,8 @@
9042 9042
       }
9043 9043
     },
9044 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 9047
       "requires": {
9048 9048
         "@jitsi/sdp-interop": "0.1.14",
9049 9049
         "@jitsi/sdp-simulcast": "0.2.1",

+ 1
- 1
package.json Datei anzeigen

@@ -54,7 +54,7 @@
54 54
     "js-utils": "github:jitsi/js-utils#192b1c996e8c05530eb1f19e82a31069c3021e31",
55 55
     "jsrsasign": "8.0.12",
56 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 58
     "libflacjs": "github:mmig/libflac.js#93d37e7f811f01cf7d8b6a603e38bd3c3810907d",
59 59
     "lodash": "4.17.11",
60 60
     "moment": "2.19.4",

+ 2
- 7
react/features/base/tracks/functions.js Datei anzeigen

@@ -1,7 +1,7 @@
1 1
 /* global APP */
2 2
 
3 3
 import { getBlurEffect } from '../../blur';
4
-import JitsiMeetJS, { JitsiTrackErrors } from '../lib-jitsi-meet';
4
+import JitsiMeetJS, { JitsiTrackErrors, browser } from '../lib-jitsi-meet';
5 5
 import { MEDIA_TYPE } from '../media';
6 6
 import {
7 7
     getUserSelectedCameraDeviceId,
@@ -236,12 +236,7 @@ export function isRemoteTrackMuted(tracks, mediaType, participantId) {
236 236
  * @returns {boolean}
237 237
  */
238 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 240
         && window
246 241
         && window.self !== window.top
247 242
         && !state['features/base/user-interaction'].interacted;

+ 0
- 11
react/features/base/user-interaction/actionTypes.js Datei anzeigen

@@ -1,14 +1,3 @@
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 2
  * The type of (redux) action which signals the user has interacted with the
14 3
  * page.

+ 36
- 34
react/features/base/user-interaction/middleware.js Datei anzeigen

@@ -3,10 +3,15 @@
3 3
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
4 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 17
  * Implements the entry point of the middleware of the feature base/user-interaction.
@@ -21,14 +26,31 @@ MiddlewareRegistry.register(store => next => action => {
21 26
         break;
22 27
 
23 28
     case APP_WILL_UNMOUNT:
24
-    case USER_INTERACTION_RECEIVED:
25
-        _stopListeningForUserInteraction(store);
29
+        _stopListeningForUserInteraction();
26 30
         break;
27 31
     }
28 32
 
29 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 55
  * Registers listeners to notify redux of any user interaction with the page.
34 56
  *
@@ -36,44 +58,24 @@ MiddlewareRegistry.register(store => next => action => {
36 58
  * @private
37 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 66
     window.addEventListener('mousedown', userInteractionListener);
51 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 73
  * @private
65 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 Datei anzeigen

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

Laden…
Abbrechen
Speichern