瀏覽代碼

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.
j8
paweldomas 7 年之前
父節點
當前提交
2281b1acd2

+ 29
- 3
conference.js 查看文件

@@ -35,6 +35,9 @@ import {
35 35
 import {
36 36
     isFatalJitsiConnectionError
37 37
 } from './react/features/base/lib-jitsi-meet';
38
+import {
39
+    setVideoAvailable
40
+} from './react/features/base/media';
38 41
 import {
39 42
     localParticipantRoleChanged,
40 43
     MAX_DISPLAY_NAME_LENGTH,
@@ -1036,15 +1039,13 @@ export default {
1036 1039
                     this.isSharingScreen = newStream.videoType === 'desktop';
1037 1040
 
1038 1041
                     APP.UI.addLocalStream(newStream);
1039
-
1040
-                    newStream.videoType === 'camera'
1041
-                        && APP.UI.setCameraButtonEnabled(true);
1042 1042
                 } else {
1043 1043
                     // No video is treated the same way as being video muted
1044 1044
                     this.videoMuted = true;
1045 1045
                     this.isSharingScreen = false;
1046 1046
                 }
1047 1047
                 APP.UI.setVideoMuted(this.getMyUserId(), this.videoMuted);
1048
+                this.updateVideoIconEnabled();
1048 1049
                 APP.UI.updateDesktopSharingButtons();
1049 1050
             });
1050 1051
     },
@@ -1953,6 +1954,7 @@ export default {
1953 1954
                 mediaDeviceHelper.setCurrentMediaDevices(devices);
1954 1955
                 APP.UI.onAvailableDevicesChanged(devices);
1955 1956
                 APP.store.dispatch(updateDeviceList(devices));
1957
+                this.updateVideoIconEnabled();
1956 1958
             });
1957 1959
 
1958 1960
             this.deviceChangeListener = (devices) =>
@@ -2030,8 +2032,32 @@ export default {
2030 2032
             .then(() => {
2031 2033
                 mediaDeviceHelper.setCurrentMediaDevices(devices);
2032 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 2063
      * Toggles the local "raised hand" status.

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

@@ -34,7 +34,6 @@ import {
34 34
     dockToolbox,
35 35
     setAudioIconEnabled,
36 36
     setToolbarButton,
37
-    setVideoIconEnabled,
38 37
     showDialPadButton,
39 38
     showEtherpadButton,
40 39
     showSharedVideoButton,
@@ -724,9 +723,6 @@ UI.setVideoMuted = function (id, muted) {
724 723
     VideoLayout.onVideoMute(id, muted);
725 724
     if (APP.conference.isLocalId(id)) {
726 725
         APP.store.dispatch(setVideoMuted(muted));
727
-        APP.store.dispatch(setToolbarButton('camera', {
728
-            toggled: muted
729
-        }));
730 726
     }
731 727
 };
732 728
 
@@ -1341,15 +1337,6 @@ UI.onSharedVideoStop = function (id, attributes) {
1341 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 1341
  * Enables / disables microphone toolbar button.
1355 1342
  *

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

@@ -97,11 +97,6 @@ function getNewVideoInputDevice(newDevices, localVideo) {
97 97
             availableVideoInputDevices[0].label !== '') {
98 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 100
     } else {
106 101
         // And here we handle case when we already have some device working,
107 102
         // but we plug-in a "preferred" (previously selected in settings, stored

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

@@ -19,6 +19,16 @@ export const SET_AUDIO_MUTED = Symbol('SET_AUDIO_MUTED');
19 19
  */
20 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 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,6 +5,7 @@ import type { Dispatch } from 'redux';
5 5
 import {
6 6
     SET_AUDIO_MUTED,
7 7
     SET_CAMERA_FACING_MODE,
8
+    SET_VIDEO_AVAILABLE,
8 9
     SET_VIDEO_MUTED,
9 10
     TOGGLE_CAMERA_FACING_MODE
10 11
 } from './actionTypes';
@@ -43,6 +44,23 @@ export function setCameraFacingMode(cameraFacingMode: CAMERA_FACING_MODE) {
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 65
  * Action to set the muted state of the local video.
48 66
  *

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

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

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

@@ -225,27 +225,6 @@ export function setToolboxVisible(visible: boolean): Object {
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 229
  * Shows etherpad button if it's not shown.
251 230
  *

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

@@ -7,6 +7,48 @@ import {
7 7
     SET_TOOLBOX_TIMEOUT
8 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 53
  * Middleware which intercepts Toolbox actions to handle changes to the
12 54
  * visibility timeout of the Toolbox.
@@ -33,6 +75,14 @@ MiddlewareRegistry.register(store => next => action => {
33 75
         action.timeoutID = newTimeoutId;
34 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 88
     return next(action);

Loading…
取消
儲存