浏览代码

Restore the audio and video mute/unmute keyboard shortcuts

I don't think it's realistic that we'd merge a PR that breaks the most
important shortcuts of the app (in my opinion): audio and video
mute/unmute.
master
Lyubo Marinov 7 年前
父节点
当前提交
f1123a8cdd

+ 62
- 0
react/features/toolbox/components/AudioMuteButton.js 查看文件

@@ -3,7 +3,9 @@
3 3
 import { connect } from 'react-redux';
4 4
 
5 5
 import {
6
+    ACTION_SHORTCUT_TRIGGERED,
6 7
     AUDIO_MUTE,
8
+    createShortcutEvent,
7 9
     createToolbarEvent,
8 10
     sendAnalytics
9 11
 } from '../../analytics';
@@ -13,6 +15,8 @@ import { AbstractAudioMuteButton } from '../../base/toolbox';
13 15
 import type { AbstractButtonProps } from '../../base/toolbox';
14 16
 import { isLocalTrackMuted } from '../../base/tracks';
15 17
 
18
+declare var APP: Object;
19
+
16 20
 /**
17 21
  * The type of the React {@code Component} props of {@link AudioMuteButton}.
18 22
  */
@@ -38,6 +42,45 @@ class AudioMuteButton extends AbstractAudioMuteButton<Props, *> {
38 42
     label = 'toolbar.mute';
39 43
     tooltip = 'toolbar.mute';
40 44
 
45
+    /**
46
+     * Initializes a new {@code AudioMuteButton} instance.
47
+     *
48
+     * @param {Props} props - The read-only React {@code Component} props with
49
+     * which the new instance is to be initialized.
50
+     */
51
+    constructor(props: Props) {
52
+        super(props);
53
+
54
+        // Bind event handlers so they are only bound once per instance.
55
+        this._onKeyboardShortcut = this._onKeyboardShortcut.bind(this);
56
+    }
57
+
58
+    /**
59
+     * Registers the keyboard shortcut that toggles the audio muting.
60
+     *
61
+     * @inheritdoc
62
+     * @returns {void}
63
+     */
64
+    componentDidMount() {
65
+        typeof APP === 'undefined'
66
+            || APP.keyboardshortcut.registerShortcut(
67
+                'M',
68
+                null,
69
+                this._onKeyboardShortcut,
70
+                'keyboardShortcuts.mute');
71
+    }
72
+
73
+    /**
74
+     * Unregisters the keyboard shortcut that toggles the audio muting.
75
+     *
76
+     * @inheritdoc
77
+     * @returns {void}
78
+     */
79
+    componentWillUnmount() {
80
+        typeof APP === 'undefined'
81
+            || APP.keyboardshortcut.unregisterShortcut('M');
82
+    }
83
+
41 84
     /**
42 85
      * Indicates if audio is currently muted ot nor.
43 86
      *
@@ -49,6 +92,25 @@ class AudioMuteButton extends AbstractAudioMuteButton<Props, *> {
49 92
         return this.props._audioMuted;
50 93
     }
51 94
 
95
+    _onKeyboardShortcut: () => void;
96
+
97
+    /**
98
+     * Creates an analytics keyboard shortcut event and dispatches an action to
99
+     * toggle the audio muting.
100
+     *
101
+     * @private
102
+     * @returns {void}
103
+     */
104
+    _onKeyboardShortcut() {
105
+        sendAnalytics(
106
+            createShortcutEvent(
107
+                AUDIO_MUTE,
108
+                ACTION_SHORTCUT_TRIGGERED,
109
+                { enable: !this._isAudioMuted() }));
110
+
111
+        super._handleClick();
112
+    }
113
+
52 114
     /**
53 115
      * Changes the muted state.
54 116
      *

+ 62
- 0
react/features/toolbox/components/VideoMuteButton.js 查看文件

@@ -3,7 +3,9 @@
3 3
 import { connect } from 'react-redux';
4 4
 
5 5
 import {
6
+    ACTION_SHORTCUT_TRIGGERED,
6 7
     VIDEO_MUTE,
8
+    createShortcutEvent,
7 9
     createToolbarEvent,
8 10
     sendAnalytics
9 11
 } from '../../analytics';
@@ -17,6 +19,8 @@ import { AbstractVideoMuteButton } from '../../base/toolbox';
17 19
 import type { AbstractButtonProps } from '../../base/toolbox';
18 20
 import { isLocalTrackMuted } from '../../base/tracks';
19 21
 
22
+declare var APP: Object;
23
+
20 24
 /**
21 25
  * The type of the React {@code Component} props of {@link VideoMuteButton}.
22 26
  */
@@ -47,6 +51,45 @@ class VideoMuteButton extends AbstractVideoMuteButton<Props, *> {
47 51
     label = 'toolbar.videomute';
48 52
     tooltip = 'toolbar.videomute';
49 53
 
54
+    /**
55
+     * Initializes a new {@code VideoMuteButton} instance.
56
+     *
57
+     * @param {Props} props - The read-only React {@code Component} props with
58
+     * which the new instance is to be initialized.
59
+     */
60
+    constructor(props: Props) {
61
+        super(props);
62
+
63
+        // Bind event handlers so they are only bound once per instance.
64
+        this._onKeyboardShortcut = this._onKeyboardShortcut.bind(this);
65
+    }
66
+
67
+    /**
68
+     * Registers the keyboard shortcut that toggles the video muting.
69
+     *
70
+     * @inheritdoc
71
+     * @returns {void}
72
+     */
73
+    componentDidMount() {
74
+        typeof APP === 'undefined'
75
+            || APP.keyboardshortcut.registerShortcut(
76
+                'V',
77
+                null,
78
+                this._onKeyboardShortcut,
79
+                'keyboardShortcuts.videoMute');
80
+    }
81
+
82
+    /**
83
+     * Unregisters the keyboard shortcut that toggles the video muting.
84
+     *
85
+     * @inheritdoc
86
+     * @returns {void}
87
+     */
88
+    componentWillUnmount() {
89
+        typeof APP === 'undefined'
90
+            || APP.keyboardshortcut.unregisterShortcut('V');
91
+    }
92
+
50 93
     /**
51 94
      * Indicates if this button should be disabled or not.
52 95
      *
@@ -69,6 +112,25 @@ class VideoMuteButton extends AbstractVideoMuteButton<Props, *> {
69 112
         return this.props._videoMuted;
70 113
     }
71 114
 
115
+    _onKeyboardShortcut: () => void;
116
+
117
+    /**
118
+     * Creates an analytics keyboard shortcut event and dispatches an action to
119
+     * toggle the video muting.
120
+     *
121
+     * @private
122
+     * @returns {void}
123
+     */
124
+    _onKeyboardShortcut() {
125
+        sendAnalytics(
126
+            createShortcutEvent(
127
+                VIDEO_MUTE,
128
+                ACTION_SHORTCUT_TRIGGERED,
129
+                { enable: !this._isVideoMuted() }));
130
+
131
+        super._handleClick();
132
+    }
133
+
72 134
     /**
73 135
      * Changes the muted state.
74 136
      *

正在加载...
取消
保存