浏览代码

Replace features/unsupported-browser SET_UNSUPPORTED_BROWSER with features/base/lib-jitsi-meet SET_WEBRTC_READY

The error raised by JitsiMeetJS.init() is already in the state of
features/base/lib-jitsi-meet so it's not a good design to store the same
error in the state of features/unsupported-browser.
j8
Lyubo Marinov 8 年前
父节点
当前提交
0ed85b9d25

+ 17
- 24
react/features/base/connection/actions.web.js 查看文件

@@ -2,15 +2,17 @@
2 2
 
3 3
 import type { Dispatch } from 'redux';
4 4
 
5
-import { JitsiConferenceEvents } from '../lib-jitsi-meet';
5
+import {
6
+    JitsiConferenceEvents,
7
+    libInitError,
8
+    WEBRTC_NOT_READY,
9
+    WEBRTC_NOT_SUPPORTED
10
+} from '../lib-jitsi-meet';
6 11
 
7 12
 import UIEvents from '../../../../service/UI/UIEvents';
8 13
 
9 14
 import { SET_DOMAIN } from './actionTypes';
10 15
 
11
-import { appNavigate } from '../../app';
12
-import { setUnsupportedBrowser } from '../../unsupported-browser';
13
-
14 16
 declare var APP: Object;
15 17
 declare var config: Object;
16 18
 
@@ -77,28 +79,19 @@ export function connect() {
77 79
                 APP.UI.promptDisplayName();
78 80
             }
79 81
         })
80
-            .catch(err => {
82
+            .catch(error => {
81 83
                 APP.UI.hideRingOverLay();
82 84
                 APP.API.notifyConferenceLeft(APP.conference.roomName);
83
-                logger.error(err);
84
-
85
-                dispatch(setUnsupportedBrowser(err));
86
-
87
-                // If during the conference initialization was defined that
88
-                // browser doesn't support WebRTC then we should define
89
-                // which route to render.
90
-                dispatch(appNavigate(room));
91
-
92
-                // Force reinitialization of the conference if WebRTC is ready.
93
-                if (err.webRTCReadyPromise) {
94
-                    err.webRTCReadyPromise.then(() => {
95
-                        // Setting plugin required flag to false because
96
-                        // it's already been installed.
97
-                        dispatch(setUnsupportedBrowser({
98
-                            name: 'OK'
99
-                        }));
100
-                        dispatch(appNavigate(room));
101
-                    });
85
+                logger.error(error);
86
+
87
+                // TODO The following are in fact Errors raised by
88
+                // JitsiMeetJS.init() which should be taken care of in
89
+                // features/base/lib-jitsi-meet but we are not there yet on the
90
+                // Web at the time of this writing.
91
+                switch (error.name) {
92
+                case WEBRTC_NOT_READY:
93
+                case WEBRTC_NOT_SUPPORTED:
94
+                    dispatch(libInitError(error));
102 95
                 }
103 96
             });
104 97
     };

+ 10
- 0
react/features/base/lib-jitsi-meet/actionTypes.js 查看文件

@@ -58,3 +58,13 @@ export const LIB_WILL_INIT = Symbol('LIB_WILL_INIT');
58 58
  * }
59 59
  */
60 60
 export const SET_CONFIG = Symbol('SET_CONFIG');
61
+
62
+/**
63
+ * The type of Redux action which indicates whether WebRTC is ready.
64
+ *
65
+ * {
66
+ *     type: SET_WEBRTC_READY,
67
+ *     webRTCReady: boolean | Promise
68
+ * }
69
+ */
70
+export const SET_WEBRTC_READY = Symbol('SET_WEBRTC_READY');

+ 53
- 1
react/features/base/lib-jitsi-meet/actions.js 查看文件

@@ -7,7 +7,8 @@ import {
7 7
     LIB_INIT_ERROR,
8 8
     LIB_WILL_DISPOSE,
9 9
     LIB_WILL_INIT,
10
-    SET_CONFIG
10
+    SET_CONFIG,
11
+    SET_WEBRTC_READY
11 12
 } from './actionTypes';
12 13
 
13 14
 declare var APP: Object;
@@ -100,3 +101,54 @@ export function setConfig(config: Object) {
100 101
         config
101 102
     };
102 103
 }
104
+
105
+/**
106
+ * Sets the indicator which determines whether WebRTC is ready. In execution
107
+ * environments in which WebRTC is supported via a known plugin such
108
+ * as Temasys WebRTC may start not ready and then become ready. Of course, there
109
+ * are execution enviroments such as old Mozilla Firefox versions or
110
+ * certains Microsoft Edge versions in which WebRTC is not supported at all.
111
+ *
112
+ * @param {boolean|Promise} webRTCReady - The indicator which determines
113
+ * whether WebRTC is ready. If a Promise is specified, its resolution will be
114
+ * awaited.
115
+ * @returns {Function}
116
+ */
117
+export function setWebRTCReady(webRTCReady: boolean | Promise<*>) {
118
+    return (dispatch: Dispatch<*>, getState: Function) => {
119
+        if (getState()['features/base/lib-jitsi-meet'].webRTCReady
120
+                !== webRTCReady) {
121
+            dispatch({
122
+                type: SET_WEBRTC_READY,
123
+                webRTCReady
124
+            });
125
+
126
+            // If the specified webRTCReady is a thenable (i.e. a Promise), then
127
+            // await its resolution.
128
+            switch (typeof webRTCReady) {
129
+            case 'function':
130
+            case 'object': {
131
+                const { then } = webRTCReady;
132
+
133
+                if (typeof then === 'function') {
134
+                    const onFulfilled = value => {
135
+                        // Is the app still interested in the specified
136
+                        // webRTCReady?
137
+                        if (getState()['features/base/lib-jitsi-meet']
138
+                                    .webRTCReady
139
+                                === webRTCReady) {
140
+                            dispatch(setWebRTCReady(value));
141
+                        }
142
+                    };
143
+
144
+                    then.call(
145
+                             webRTCReady,
146
+                             /* onFulfilled */ () => onFulfilled(true),
147
+                             /* onRejected*/ () => onFulfilled(false));
148
+                }
149
+                break;
150
+            }
151
+            }
152
+        }
153
+    };
154
+}

+ 13
- 0
react/features/base/lib-jitsi-meet/constants.js 查看文件

@@ -0,0 +1,13 @@
1
+/**
2
+ * The name of the Error thrown by {@link JitsiMeetJS.init()} which indicates
3
+ * that WebRTC is not ready and its readiness may be tracked via the
4
+ * webRTCReadyPromise property value of the Error.
5
+ */
6
+export const WEBRTC_NOT_READY = 'WEBRTC_NOT_READY';
7
+
8
+/**
9
+ * The name of the Error thrown by {@link JitsiMeetJS.init()} which indicates
10
+ * that WebRTC is not supported by the execution environment either natively or
11
+ * via a known plugin such as Temasys.
12
+ */
13
+export const WEBRTC_NOT_SUPPORTED = 'WEBRTC_NOT_SUPPORTED';

+ 1
- 0
react/features/base/lib-jitsi-meet/index.js 查看文件

@@ -15,6 +15,7 @@ export const JitsiTrackEvents = JitsiMeetJS.events.track;
15 15
 
16 16
 export * from './actions';
17 17
 export * from './actionTypes';
18
+export * from './constants';
18 19
 export * from './functions';
19 20
 
20 21
 import './middleware';

+ 48
- 2
react/features/base/lib-jitsi-meet/middleware.js 查看文件

@@ -1,8 +1,9 @@
1 1
 import { PARTICIPANT_LEFT } from '../participants';
2 2
 import { MiddlewareRegistry } from '../redux';
3 3
 
4
-import { disposeLib, initLib } from './actions';
5
-import { SET_CONFIG } from './actionTypes';
4
+import { disposeLib, initLib, setWebRTCReady } from './actions';
5
+import { LIB_DID_INIT, LIB_INIT_ERROR, SET_CONFIG } from './actionTypes';
6
+import { WEBRTC_NOT_READY, WEBRTC_NOT_SUPPORTED } from './constants';
6 7
 
7 8
 /**
8 9
  * Middleware that captures PARTICIPANT_LEFT action for a local participant
@@ -16,6 +17,13 @@ import { SET_CONFIG } from './actionTypes';
16 17
  */
17 18
 MiddlewareRegistry.register(store => next => action => {
18 19
     switch (action.type) {
20
+    case LIB_DID_INIT:
21
+        store.dispatch(setWebRTCReady(true));
22
+        break;
23
+
24
+    case LIB_INIT_ERROR:
25
+        return _libInitError(store, next, action);
26
+
19 27
     case PARTICIPANT_LEFT:
20 28
         action.participant.local && store.dispatch(disposeLib());
21 29
         break;
@@ -27,6 +35,44 @@ MiddlewareRegistry.register(store => next => action => {
27 35
     return next(action);
28 36
 });
29 37
 
38
+/**
39
+ * Notifies the feature base/lib-jitsi-meet that the action LIB_INIT_ERROR is
40
+ * being dispatched within a specific Redux store.
41
+ *
42
+ * @param {Store} store - The Redux store in which the specified action is being
43
+ * dispatched.
44
+ * @param {Dispatch} next - The Redux dispatch function to dispatch the
45
+ * specified action to the specified store.
46
+ * @param {Action} action - The Redux action LIB_INIT_ERROR which is being
47
+ * dispatched in the specified store.
48
+ * @returns {Object} The new state that is the result of the reduction of the
49
+ * specified action.
50
+ * @private
51
+ */
52
+function _libInitError(store, next, action) {
53
+    const nextState = next(action);
54
+
55
+    const error = action.error;
56
+
57
+    if (error) {
58
+        let webRTCReady;
59
+
60
+        switch (error.name) {
61
+        case WEBRTC_NOT_READY:
62
+            webRTCReady = error.webRTCReadyPromise;
63
+            break;
64
+
65
+        case WEBRTC_NOT_SUPPORTED:
66
+            webRTCReady = false;
67
+            break;
68
+        }
69
+        typeof webRTCReady === 'undefined'
70
+            || store.dispatch(setWebRTCReady(webRTCReady));
71
+    }
72
+
73
+    return nextState;
74
+}
75
+
30 76
 /**
31 77
  * Notifies the feature base/lib-jitsi-meet that the action SET_CONFIG is being
32 78
  * dispatched within a specific Redux store.

+ 8
- 1
react/features/base/lib-jitsi-meet/reducer.js 查看文件

@@ -4,7 +4,8 @@ import {
4 4
     LIB_DID_DISPOSE,
5 5
     LIB_DID_INIT,
6 6
     LIB_INIT_ERROR,
7
-    SET_CONFIG
7
+    SET_CONFIG,
8
+    SET_WEBRTC_READY
8 9
 } from './actionTypes';
9 10
 
10 11
 /**
@@ -66,6 +67,12 @@ ReducerRegistry.register(
66 67
         case SET_CONFIG:
67 68
             return _setConfig(state, action);
68 69
 
70
+        case SET_WEBRTC_READY:
71
+            return {
72
+                ...state,
73
+                webRTCReady: action.webRTCReady
74
+            };
75
+
69 76
         default:
70 77
             return state;
71 78
         }

+ 3
- 3
react/features/base/react/Platform.web.js 查看文件

@@ -7,10 +7,10 @@ if (userAgent.match(/Android/i)) {
7 7
     OS = 'android';
8 8
 } else if (userAgent.match(/iP(ad|hone|od)/i)) {
9 9
     OS = 'ios';
10
-} else if (userAgent.match(/windows/i)) {
10
+} else if (userAgent.match(/Mac(intosh| OS X)/i)) {
11
+    OS = 'macos';
12
+} else if (userAgent.match(/Windows/i)) {
11 13
     OS = 'windows';
12
-} else if (userAgent.match(/mac/i)) {
13
-    OS = 'mac';
14 14
 }
15 15
 
16 16
 /**

+ 15
- 5
react/features/base/util/interceptComponent.js 查看文件

@@ -44,12 +44,22 @@ const _RULES = [
44 44
         }
45 45
     },
46 46
     state => {
47
-        switch (state['features/unsupported-browser'].name) {
48
-        case 'WEBRTC_NOT_READY':
49
-            return PluginRequiredBrowser;
47
+        const { webRTCReady } = state['features/base/lib-jitsi-meet'];
48
+
49
+        switch (typeof webRTCReady) {
50
+        case 'boolean':
51
+            if (webRTCReady === false) {
52
+                return UnsupportedDesktopBrowser;
53
+            }
54
+            break;
50 55
 
51
-        case 'WEBRTC_NOT_SUPPORTED':
52
-            return UnsupportedDesktopBrowser;
56
+        case 'undefined':
57
+            // If webRTCReady is not set, then we cannot use it to take a
58
+            // decision.
59
+            break;
60
+
61
+        default:
62
+            return PluginRequiredBrowser;
53 63
         }
54 64
     }
55 65
 ];

+ 0
- 11
react/features/unsupported-browser/actionTypes.js 查看文件

@@ -16,14 +16,3 @@ import { Symbol } from '../base/react';
16 16
  * }
17 17
  */
18 18
 export const DISMISS_MOBILE_APP_PROMO = Symbol('DISMISS_MOBILE_APP_PROMO');
19
-
20
-/**
21
- * The type of Redux action which signals to change information about
22
- * unsupported browser in Redux store.
23
- *
24
- * {
25
- *      type: SET_UNSUPPORTED_BROWSER,
26
- *      unsupportedBrowser: Object
27
- * }
28
- */
29
-export const SET_UNSUPPORTED_BROWSER = Symbol('SET_UNSUPPORTED_BROWSER');

+ 1
- 21
react/features/unsupported-browser/actions.js 查看文件

@@ -1,7 +1,4 @@
1
-import {
2
-    DISMISS_MOBILE_APP_PROMO,
3
-    SET_UNSUPPORTED_BROWSER
4
-} from './actionTypes';
1
+import { DISMISS_MOBILE_APP_PROMO } from './actionTypes';
5 2
 
6 3
 /**
7 4
  * Returns a Redux action which signals that the UnsupportedMobileBrowser which
@@ -22,20 +19,3 @@ export function dismissMobileAppPromo() {
22 19
         type: DISMISS_MOBILE_APP_PROMO
23 20
     };
24 21
 }
25
-
26
-/**
27
- * Sets unsupported browser object.
28
- *
29
- * @param {Object} unsupportedBrowser - Object describing the unsupported
30
- * browser.
31
- * @returns {{
32
- *      type: SET_UNSUPPORTED_BROWSER,
33
- *      unsupportedBrowser: Object
34
- *  }}
35
- */
36
-export function setUnsupportedBrowser(unsupportedBrowser) {
37
-    return {
38
-        type: SET_UNSUPPORTED_BROWSER,
39
-        unsupportedBrowser
40
-    };
41
-}

+ 23
- 22
react/features/unsupported-browser/components/UnsupportedDesktopBrowser.js 查看文件

@@ -39,8 +39,9 @@ export default class UnsupportedDesktopBrowser extends Component {
39 39
                     <a
40 40
                         className = { `${NS}__link` }
41 41
                         href = { FIREFOX }>Firefox</a> or&nbsp;
42
-                    { this._showSafariLinkIfRequired() }
43
-                    { this._showIELinkIfRequired() }.
42
+                    {
43
+                        this._renderOSSpecificBrowserDownloadLink()
44
+                    }
44 45
                 </p>
45 46
 
46 47
                 <HideNotificationBarStyle />
@@ -49,35 +50,35 @@ export default class UnsupportedDesktopBrowser extends Component {
49 50
     }
50 51
 
51 52
     /**
52
-     * Depending on the platform returns the link to IE browser.
53
+     * Depending on the platform returns the link to Safari browser.
53 54
      *
54 55
      * @returns {ReactElement|null}
55 56
      * @private
56 57
      */
57
-    _showIELinkIfRequired() {
58
-        if (Platform.OS === 'windows') {
59
-            return (
60
-                <a
61
-                    className = { `${NS}__link` }
62
-                    href = { IE }>IE</a>
63
-            );
64
-        }
58
+    _renderOSSpecificBrowserDownloadLink() {
59
+        let link;
60
+        let text;
65 61
 
66
-        return null;
67
-    }
62
+        switch (Platform.OS) {
63
+        case 'macos':
64
+            link = SAFARI;
65
+            text = 'Safari';
66
+            break;
68 67
 
69
-    /**
70
-     * Depending on the platform returns the link to Safari browser.
71
-     *
72
-     * @returns {ReactElement|null}
73
-     * @private
74
-     */
75
-    _showSafariLinkIfRequired() {
76
-        if (Platform.OS === 'mac') {
68
+        case 'windows':
69
+            link = IE;
70
+            text = 'Internet Explorer';
71
+            break;
72
+        }
73
+        if (typeof link !== 'undefined') {
77 74
             return (
78 75
                 <a
79 76
                     className = { `${NS}__link` }
80
-                    href = { SAFARI }>Safari</a>
77
+                    href = { link }>
78
+                    {
79
+                        text
80
+                    }
81
+                </a>
81 82
             );
82 83
         }
83 84
 

+ 1
- 0
react/features/unsupported-browser/index.js 查看文件

@@ -1,4 +1,5 @@
1 1
 export * from './actions';
2 2
 export * from './components';
3 3
 
4
+import './middleware';
4 5
 import './reducer';

+ 52
- 0
react/features/unsupported-browser/middleware.js 查看文件

@@ -0,0 +1,52 @@
1
+import { appNavigate } from '../app';
2
+import { SET_WEBRTC_READY } from '../base/lib-jitsi-meet';
3
+import { MiddlewareRegistry } from '../base/redux';
4
+
5
+/**
6
+ * Middleware that dispatches appNavigate when WebRTC readiness changes.
7
+ *
8
+ * @param {Store} store - The Redux store.
9
+ * @returns {Function}
10
+ * @private
11
+ */
12
+MiddlewareRegistry.register(store => next => action => {
13
+    switch (action.type) {
14
+    case SET_WEBRTC_READY:
15
+        return _setWebRTCReady(store, next, action);
16
+    }
17
+
18
+    return next(action);
19
+});
20
+
21
+/**
22
+ * Notifies the feature unsupported-browser that the action SET_WEBRTC_READY is
23
+ * being dispatched within a specific Redux store.
24
+ *
25
+ * @param {Store} store - The Redux store in which the specified action is being
26
+ * dispatched.
27
+ * @param {Dispatch} next - The Redux dispatch function to dispatch the
28
+ * specified action to the specified store.
29
+ * @param {Action} action - The Redux action SET_WEBRTC_READY which is being
30
+ * dispatched in the specified store.
31
+ * @returns {Object} The new state that is the result of the reduction of the
32
+ * specified action.
33
+ * @private
34
+ */
35
+function _setWebRTCReady(store, next, action) {
36
+    const nextState = next(action);
37
+
38
+    // FIXME The feature unsupported-browser needs to notify the app that it may
39
+    // need to render a different Component at its current location because the
40
+    // execution enviroment has changed. The current location is not necessarily
41
+    // available through window.location (e.g. on mobile) but the following
42
+    // works at the time of this writing.
43
+    const windowLocation = window.location;
44
+
45
+    if (windowLocation) {
46
+        const href = windowLocation.href;
47
+
48
+        href && store.dispatch(appNavigate(href));
49
+    }
50
+
51
+    return nextState;
52
+}

+ 1
- 9
react/features/unsupported-browser/reducer.js 查看文件

@@ -1,9 +1,6 @@
1 1
 import { ReducerRegistry } from '../base/redux';
2 2
 
3
-import {
4
-    DISMISS_MOBILE_APP_PROMO,
5
-    SET_UNSUPPORTED_BROWSER
6
-} from './actionTypes';
3
+import { DISMISS_MOBILE_APP_PROMO } from './actionTypes';
7 4
 
8 5
 ReducerRegistry.register(
9 6
         'features/unsupported-browser',
@@ -24,11 +21,6 @@ ReducerRegistry.register(
24 21
                      */
25 22
                     mobileAppPromoDismissed: true
26 23
                 };
27
-            case SET_UNSUPPORTED_BROWSER:
28
-                return {
29
-                    ...state,
30
-                    ...action.unsupportedBrowser
31
-                };
32 24
             }
33 25
 
34 26
             return state;

正在加载...
取消
保存