浏览代码

ref: enable/disable video button

Dynamically enables/disables the toolbar video button. Prior to that
commit if we would start with no video there would be no way to enable
it later on.
master
paweldomas 8 年前
父节点
当前提交
2281b1acd2

+ 29
- 3
conference.js 查看文件

35
 import {
35
 import {
36
     isFatalJitsiConnectionError
36
     isFatalJitsiConnectionError
37
 } from './react/features/base/lib-jitsi-meet';
37
 } from './react/features/base/lib-jitsi-meet';
38
+import {
39
+    setVideoAvailable
40
+} from './react/features/base/media';
38
 import {
41
 import {
39
     localParticipantRoleChanged,
42
     localParticipantRoleChanged,
40
     MAX_DISPLAY_NAME_LENGTH,
43
     MAX_DISPLAY_NAME_LENGTH,
1036
                     this.isSharingScreen = newStream.videoType === 'desktop';
1039
                     this.isSharingScreen = newStream.videoType === 'desktop';
1037
 
1040
 
1038
                     APP.UI.addLocalStream(newStream);
1041
                     APP.UI.addLocalStream(newStream);
1039
-
1040
-                    newStream.videoType === 'camera'
1041
-                        && APP.UI.setCameraButtonEnabled(true);
1042
                 } else {
1042
                 } else {
1043
                     // No video is treated the same way as being video muted
1043
                     // No video is treated the same way as being video muted
1044
                     this.videoMuted = true;
1044
                     this.videoMuted = true;
1045
                     this.isSharingScreen = false;
1045
                     this.isSharingScreen = false;
1046
                 }
1046
                 }
1047
                 APP.UI.setVideoMuted(this.getMyUserId(), this.videoMuted);
1047
                 APP.UI.setVideoMuted(this.getMyUserId(), this.videoMuted);
1048
+                this.updateVideoIconEnabled();
1048
                 APP.UI.updateDesktopSharingButtons();
1049
                 APP.UI.updateDesktopSharingButtons();
1049
             });
1050
             });
1050
     },
1051
     },
1953
                 mediaDeviceHelper.setCurrentMediaDevices(devices);
1954
                 mediaDeviceHelper.setCurrentMediaDevices(devices);
1954
                 APP.UI.onAvailableDevicesChanged(devices);
1955
                 APP.UI.onAvailableDevicesChanged(devices);
1955
                 APP.store.dispatch(updateDeviceList(devices));
1956
                 APP.store.dispatch(updateDeviceList(devices));
1957
+                this.updateVideoIconEnabled();
1956
             });
1958
             });
1957
 
1959
 
1958
             this.deviceChangeListener = (devices) =>
1960
             this.deviceChangeListener = (devices) =>
2030
             .then(() => {
2032
             .then(() => {
2031
                 mediaDeviceHelper.setCurrentMediaDevices(devices);
2033
                 mediaDeviceHelper.setCurrentMediaDevices(devices);
2032
                 APP.UI.onAvailableDevicesChanged(devices);
2034
                 APP.UI.onAvailableDevicesChanged(devices);
2035
+                this.updateVideoIconEnabled();
2033
             });
2036
             });
2034
     },
2037
     },
2038
+    /**
2039
+     * Determines whether or not the video button should be enabled.
2040
+     */
2041
+    updateVideoIconEnabled() {
2042
+        const videoMediaDevices
2043
+            = mediaDeviceHelper.getCurrentMediaDevices().videoinput;
2044
+        const videoDeviceCount
2045
+            = videoMediaDevices ? videoMediaDevices.length : 0;
2046
+        // The video functionality is considered available if there are any
2047
+        // video devices detected or if there is local video stream already
2048
+        // active which could be either screensharing stream or a video track
2049
+        // created before the permissions were rejected (through browser
2050
+        // config).
2051
+        const available = videoDeviceCount > 0 || Boolean(localVideo);
2052
+
2053
+        logger.debug(
2054
+            'Camera button enabled: ' + available,
2055
+            'local video: ' + localVideo,
2056
+            'video devices: ' + videoMediaDevices,
2057
+            'device count: ' + videoDeviceCount);
2058
+
2059
+        APP.store.dispatch(setVideoAvailable(available));
2060
+    },
2035
 
2061
 
2036
     /**
2062
     /**
2037
      * Toggles the local "raised hand" status.
2063
      * Toggles the local "raised hand" status.

+ 0
- 13
modules/UI/UI.js 查看文件

34
     dockToolbox,
34
     dockToolbox,
35
     setAudioIconEnabled,
35
     setAudioIconEnabled,
36
     setToolbarButton,
36
     setToolbarButton,
37
-    setVideoIconEnabled,
38
     showDialPadButton,
37
     showDialPadButton,
39
     showEtherpadButton,
38
     showEtherpadButton,
40
     showSharedVideoButton,
39
     showSharedVideoButton,
724
     VideoLayout.onVideoMute(id, muted);
723
     VideoLayout.onVideoMute(id, muted);
725
     if (APP.conference.isLocalId(id)) {
724
     if (APP.conference.isLocalId(id)) {
726
         APP.store.dispatch(setVideoMuted(muted));
725
         APP.store.dispatch(setVideoMuted(muted));
727
-        APP.store.dispatch(setToolbarButton('camera', {
728
-            toggled: muted
729
-        }));
730
     }
726
     }
731
 };
727
 };
732
 
728
 
1341
         sharedVideoManager.onSharedVideoStop(id, attributes);
1337
         sharedVideoManager.onSharedVideoStop(id, attributes);
1342
 };
1338
 };
1343
 
1339
 
1344
-/**
1345
- * Enables / disables camera toolbar button.
1346
- *
1347
- * @param {boolean} enabled indicates if the camera button should be enabled
1348
- * or disabled
1349
- */
1350
-UI.setCameraButtonEnabled
1351
-    = enabled => APP.store.dispatch(setVideoIconEnabled(enabled));
1352
-
1353
 /**
1340
 /**
1354
  * Enables / disables microphone toolbar button.
1341
  * Enables / disables microphone toolbar button.
1355
  *
1342
  *

+ 0
- 5
modules/devices/mediaDeviceHelper.js 查看文件

97
             availableVideoInputDevices[0].label !== '') {
97
             availableVideoInputDevices[0].label !== '') {
98
             return availableVideoInputDevices[0].deviceId;
98
             return availableVideoInputDevices[0].deviceId;
99
         }
99
         }
100
-        // Otherwise we assume that we don't have any video input devices
101
-        // to use and that's why disable microphone button on UI.
102
-        else {
103
-            APP.UI.setCameraButtonEnabled(false);
104
-        }
105
     } else {
100
     } else {
106
         // And here we handle case when we already have some device working,
101
         // And here we handle case when we already have some device working,
107
         // but we plug-in a "preferred" (previously selected in settings, stored
102
         // but we plug-in a "preferred" (previously selected in settings, stored

+ 10
- 0
react/features/base/media/actionTypes.js 查看文件

19
  */
19
  */
20
 export const SET_CAMERA_FACING_MODE = Symbol('SET_CAMERA_FACING_MODE');
20
 export const SET_CAMERA_FACING_MODE = Symbol('SET_CAMERA_FACING_MODE');
21
 
21
 
22
+/**
23
+ * The type of (redux) action to adjust the availability of the local video.
24
+ *
25
+ * {
26
+ *     type: SET_VIDEO_AVAILABLE,
27
+ *     muted: boolean
28
+ * }
29
+ */
30
+export const SET_VIDEO_AVAILABLE = Symbol('SET_VIDEO_AVAILABLE');
31
+
22
 /**
32
 /**
23
  * The type of (redux) action to set the muted state of the local video.
33
  * The type of (redux) action to set the muted state of the local video.
24
  *
34
  *

+ 18
- 0
react/features/base/media/actions.js 查看文件

5
 import {
5
 import {
6
     SET_AUDIO_MUTED,
6
     SET_AUDIO_MUTED,
7
     SET_CAMERA_FACING_MODE,
7
     SET_CAMERA_FACING_MODE,
8
+    SET_VIDEO_AVAILABLE,
8
     SET_VIDEO_MUTED,
9
     SET_VIDEO_MUTED,
9
     TOGGLE_CAMERA_FACING_MODE
10
     TOGGLE_CAMERA_FACING_MODE
10
 } from './actionTypes';
11
 } from './actionTypes';
43
     };
44
     };
44
 }
45
 }
45
 
46
 
47
+/**
48
+ * Action to adjust the availability of the local video.
49
+ *
50
+ * @param {boolean} available - True if the local video is to be marked as
51
+ * available or false if the local video is not available.
52
+ * @returns {{
53
+ *      type: SET_VIDEO_AVAILABLE,
54
+ *      available: boolean
55
+ *  }}
56
+ */
57
+export function setVideoAvailable(available: boolean) {
58
+    return {
59
+        type: SET_VIDEO_AVAILABLE,
60
+        available
61
+    };
62
+}
63
+
46
 /**
64
 /**
47
  * Action to set the muted state of the local video.
65
  * Action to set the muted state of the local video.
48
  *
66
  *

+ 9
- 1
react/features/base/media/reducer.js 查看文件

6
     SET_AUDIO_MUTED,
6
     SET_AUDIO_MUTED,
7
     SET_CAMERA_FACING_MODE,
7
     SET_CAMERA_FACING_MODE,
8
     SET_VIDEO_MUTED,
8
     SET_VIDEO_MUTED,
9
+    SET_VIDEO_AVAILABLE,
9
     TOGGLE_CAMERA_FACING_MODE
10
     TOGGLE_CAMERA_FACING_MODE
10
 } from './actionTypes';
11
 } from './actionTypes';
11
 import { CAMERA_FACING_MODE } from './constants';
12
 import { CAMERA_FACING_MODE } from './constants';
63
  */
64
  */
64
 const VIDEO_INITIAL_MEDIA_STATE = {
65
 const VIDEO_INITIAL_MEDIA_STATE = {
65
     facingMode: CAMERA_FACING_MODE.USER,
66
     facingMode: CAMERA_FACING_MODE.USER,
66
-    muted: false
67
+    muted: true,
68
+    available: true
67
 };
69
 };
68
 
70
 
69
 /**
71
 /**
77
  */
79
  */
78
 function _video(state = VIDEO_INITIAL_MEDIA_STATE, action) {
80
 function _video(state = VIDEO_INITIAL_MEDIA_STATE, action) {
79
     switch (action.type) {
81
     switch (action.type) {
82
+    case SET_VIDEO_AVAILABLE:
83
+        return {
84
+            ...state,
85
+            available: action.available
86
+        };
87
+
80
     case SET_CAMERA_FACING_MODE:
88
     case SET_CAMERA_FACING_MODE:
81
         return {
89
         return {
82
             ...state,
90
             ...state,

+ 0
- 21
react/features/toolbox/actions.native.js 查看文件

225
     };
225
     };
226
 }
226
 }
227
 
227
 
228
-/**
229
- * Enables/disables audio toolbar button.
230
- *
231
- * @param {boolean} enabled - True if the button should be enabled; otherwise,
232
- * false.
233
- * @returns {Function}
234
- */
235
-export function setVideoIconEnabled(enabled: boolean = false): Function {
236
-    return (dispatch: Dispatch<*>) => {
237
-        const i18nKey = enabled ? 'videomute' : 'cameraDisabled';
238
-        const i18n = `[content]toolbar.${i18nKey}`;
239
-        const button = {
240
-            enabled,
241
-            i18n,
242
-            toggled: !enabled
243
-        };
244
-
245
-        dispatch(setToolbarButton('camera', button));
246
-    };
247
-}
248
-
249
 /**
228
 /**
250
  * Shows etherpad button if it's not shown.
229
  * Shows etherpad button if it's not shown.
251
  *
230
  *

+ 50
- 0
react/features/toolbox/middleware.js 查看文件

7
     SET_TOOLBOX_TIMEOUT
7
     SET_TOOLBOX_TIMEOUT
8
 } from './actionTypes';
8
 } from './actionTypes';
9
 
9
 
10
+import {
11
+    SET_VIDEO_AVAILABLE,
12
+    SET_VIDEO_MUTED
13
+} from '../../features/base/media/actionTypes';
14
+
15
+import {
16
+    setToolbarButton
17
+} from './actions';
18
+
19
+/**
20
+ * Adjusts the state of toolbar's camera button.
21
+ *
22
+ * @param {Store} store - The Redux store instance.
23
+ * @param {Object} action - Either SET_VIDEO_AVAILABLE or SET_VIDEO_MUTED.
24
+ *
25
+ * @returns {*}
26
+ */
27
+function setCameraButton(store, action) {
28
+    const video = store.getState()['features/base/media'].video;
29
+    let available = video.available;
30
+
31
+    if (typeof action.available === 'boolean') {
32
+        available = action.available;
33
+    }
34
+
35
+    let muted = video.muted;
36
+
37
+    if (typeof action.muted === 'boolean') {
38
+        muted = action.muted;
39
+    }
40
+
41
+    const i18nKey = available ? 'videomute' : 'cameraDisabled';
42
+    const i18n = `[content]toolbar.${i18nKey}`;
43
+    const button = {
44
+        enabled: available,
45
+        i18n,
46
+        toggled: available ? muted : true
47
+    };
48
+
49
+    store.dispatch(setToolbarButton('camera', button));
50
+}
51
+
10
 /**
52
 /**
11
  * Middleware which intercepts Toolbox actions to handle changes to the
53
  * Middleware which intercepts Toolbox actions to handle changes to the
12
  * visibility timeout of the Toolbox.
54
  * visibility timeout of the Toolbox.
33
         action.timeoutID = newTimeoutId;
75
         action.timeoutID = newTimeoutId;
34
         break;
76
         break;
35
     }
77
     }
78
+
79
+    case SET_VIDEO_AVAILABLE:
80
+    case SET_VIDEO_MUTED: {
81
+        setCameraButton(store, action);
82
+        break;
83
+    }
84
+
85
+
36
     }
86
     }
37
 
87
 
38
     return next(action);
88
     return next(action);

正在加载...
取消
保存