Browse Source

fix(record):web/mobile match disable functionality

master
Hristo Terezov 5 years ago
parent
commit
a2c4d17e4d

+ 43
- 2
react/features/recording/components/LiveStream/AbstractLiveStreamButton.js View File

@@ -1,6 +1,7 @@
1 1
 // @flow
2 2
 
3 3
 import { openDialog } from '../../../base/dialog';
4
+import { IconLiveStreaming } from '../../../base/icons';
4 5
 import { JitsiRecordingConstants } from '../../../base/lib-jitsi-meet';
5 6
 import { getLocalParticipant } from '../../../base/participants';
6 7
 import {
@@ -30,6 +31,11 @@ export type Props = AbstractButtonProps & {
30 31
      */
31 32
     _disabled: Boolean,
32 33
 
34
+    /**
35
+     * The tooltip to display when hovering over the button.
36
+     */
37
+    _tooltip: ?String,
38
+
33 39
     /**
34 40
      * The redux {@code dispatch} function.
35 41
      */
@@ -44,12 +50,22 @@ export type Props = AbstractButtonProps & {
44 50
 /**
45 51
  * An abstract class of a button for starting and stopping live streaming.
46 52
  */
47
-export default class AbstractLiveStreamButton<P: Props>
48
-    extends AbstractButton<P, *> {
53
+export default class AbstractLiveStreamButton<P: Props> extends AbstractButton<P, *> {
49 54
     accessibilityLabel = 'dialog.accessibilityLabel.liveStreaming';
55
+    icon = IconLiveStreaming;
50 56
     label = 'dialog.startLiveStreaming';
51 57
     toggledLabel = 'dialog.stopLiveStreaming';
52 58
 
59
+    /**
60
+     * Returns the tooltip that should be displayed when the button is disabled.
61
+     *
62
+     * @private
63
+     * @returns {string}
64
+     */
65
+    _getTooltip() {
66
+        return this.props._tooltip || '';
67
+    }
68
+
53 69
     /**
54 70
      * Handles clicking / pressing the button.
55 71
      *
@@ -65,6 +81,16 @@ export default class AbstractLiveStreamButton<P: Props>
65 81
         ));
66 82
     }
67 83
 
84
+    /**
85
+     * Returns a boolean value indicating if this button is disabled or not.
86
+     *
87
+     * @protected
88
+     * @returns {boolean}
89
+     */
90
+    _isDisabled() {
91
+        return this.props._disabled;
92
+    }
93
+
68 94
     /**
69 95
      * Indicates whether this button is in toggled state or not.
70 96
      *
@@ -96,6 +122,7 @@ export function _mapStateToProps(state: Object, ownProps: Props) {
96 122
     // A button can be disabled/enabled only if enableFeaturesBasedOnToken
97 123
     // is on or if the recording is running.
98 124
     let _disabled;
125
+    let _tooltip = '';
99 126
 
100 127
     if (typeof visible === 'undefined') {
101 128
         // If the containing component provides the visible prop, that is one
@@ -112,18 +139,32 @@ export function _mapStateToProps(state: Object, ownProps: Props) {
112 139
         if (enableFeaturesBasedOnToken) {
113 140
             visible = visible && String(features.livestreaming) === 'true';
114 141
             _disabled = String(features.livestreaming) === 'disabled';
142
+
143
+            if (!visible && !_disabled) {
144
+                _disabled = true;
145
+                visible = true;
146
+
147
+                // button and tooltip
148
+                if (state['features/base/jwt'].isGuest) {
149
+                    _tooltip = 'dialog.liveStreamingDisabledForGuestTooltip';
150
+                } else {
151
+                    _tooltip = 'dialog.liveStreamingDisabledTooltip';
152
+                }
153
+            }
115 154
         }
116 155
     }
117 156
 
118 157
     // disable the button if the recording is running.
119 158
     if (getActiveSession(state, JitsiRecordingConstants.mode.FILE)) {
120 159
         _disabled = true;
160
+        _tooltip = 'dialog.liveStreamingDisabledBecauseOfActiveRecordingTooltip';
121 161
     }
122 162
 
123 163
     return {
124 164
         _disabled,
125 165
         _isLiveStreamRunning: Boolean(
126 166
             getActiveSession(state, JitsiRecordingConstants.mode.STREAM)),
167
+        _tooltip,
127 168
         visible
128 169
     };
129 170
 }

+ 2
- 13
react/features/recording/components/LiveStream/native/LiveStreamButton.js View File

@@ -2,19 +2,8 @@
2 2
 
3 3
 import { LIVE_STREAMING_ENABLED, getFeatureFlag } from '../../../../base/flags';
4 4
 import { translate } from '../../../../base/i18n';
5
-import { IconLiveStreaming } from '../../../../base/icons';
6 5
 import { connect } from '../../../../base/redux';
7
-import AbstractLiveStreamButton, {
8
-    _mapStateToProps as _abstractMapStateToProps,
9
-    type Props
10
-} from '../AbstractLiveStreamButton';
11
-
12
-/**
13
- * An implementation of a button for starting and stopping live streaming.
14
- */
15
-class LiveStreamButton extends AbstractLiveStreamButton<Props> {
16
-    icon = IconLiveStreaming;
17
-}
6
+import AbstractLiveStreamButton, { _mapStateToProps as _abstractMapStateToProps } from '../AbstractLiveStreamButton';
18 7
 
19 8
 /**
20 9
  * Maps (parts of) the redux state to the associated props for this component.
@@ -35,4 +24,4 @@ export function mapStateToProps(state: Object, ownProps: Object) {
35 24
     };
36 25
 }
37 26
 
38
-export default translate(connect(mapStateToProps)(LiveStreamButton));
27
+export default translate(connect(mapStateToProps)(AbstractLiveStreamButton));

+ 3
- 73
react/features/recording/components/LiveStream/web/LiveStreamButton.js View File

@@ -1,61 +1,14 @@
1 1
 // @flow
2 2
 
3 3
 import { translate } from '../../../../base/i18n';
4
-import { IconLiveStreaming } from '../../../../base/icons';
5 4
 import { connect } from '../../../../base/redux';
6 5
 import AbstractLiveStreamButton, {
7 6
     _mapStateToProps as _abstractMapStateToProps,
8
-    type Props as AbstractProps
7
+    type Props
9 8
 } from '../AbstractLiveStreamButton';
10 9
 
11 10
 declare var interfaceConfig: Object;
12 11
 
13
-type Props = AbstractProps & {
14
-
15
-    /**
16
-     * True if the button should be disabled, false otherwise.
17
-     *
18
-     * NOTE: On web, if the feature is not disabled on purpose, then we still
19
-     * show the button but disabled and with a tooltip rendered on it,
20
-     * explaining why it's not available.
21
-     */
22
-    _disabled: boolean,
23
-
24
-    /**
25
-     * Tooltip for the button when it's disabled in a certain way.
26
-     */
27
-    _liveStreamDisabledTooltipKey: ?string
28
-}
29
-
30
-/**
31
- * An implementation of a button for starting and stopping live streaming.
32
- */
33
-class LiveStreamButton extends AbstractLiveStreamButton<Props> {
34
-    icon = IconLiveStreaming;
35
-
36
-    /**
37
-     * Returns the tooltip that should be displayed when the button is disabled.
38
-     *
39
-     * @private
40
-     * @returns {string}
41
-     */
42
-    _getTooltip() {
43
-        return this.props._liveStreamDisabledTooltipKey || '';
44
-    }
45
-
46
-    /**
47
-     * Helper function to be implemented by subclasses, which must return a
48
-     * boolean value indicating if this button is disabled or not.
49
-     *
50
-     * @override
51
-     * @protected
52
-     * @returns {boolean}
53
-     */
54
-    _isDisabled() {
55
-        return this.props._disabled;
56
-    }
57
-}
58
-
59 12
 /**
60 13
  * Maps (parts of) the redux state to the associated props for the
61 14
  * {@code LiveStreamButton} component.
@@ -74,37 +27,14 @@ function _mapStateToProps(state: Object, ownProps: Props) {
74 27
     const abstractProps = _abstractMapStateToProps(state, ownProps);
75 28
     let { visible } = ownProps;
76 29
 
77
-    let { _disabled } = abstractProps;
78
-    let _liveStreamDisabledTooltipKey;
79
-
80
-    if (!abstractProps.visible && _disabled !== undefined && !_disabled) {
81
-        _disabled = true;
82
-
83
-        // button and tooltip
84
-        if (state['features/base/jwt'].isGuest) {
85
-            _liveStreamDisabledTooltipKey
86
-                = 'dialog.liveStreamingDisabledForGuestTooltip';
87
-        } else {
88
-            _liveStreamDisabledTooltipKey
89
-                = 'dialog.liveStreamingDisabledTooltip';
90
-        }
91
-    } else if (_disabled) {
92
-        _liveStreamDisabledTooltipKey = 'dialog.liveStreamingDisabledBecauseOfActiveRecordingTooltip';
93
-    } else {
94
-        _disabled = false;
95
-    }
96
-
97 30
     if (typeof visible === 'undefined') {
98
-        visible = interfaceConfig.TOOLBAR_BUTTONS.includes('livestreaming')
99
-            && (abstractProps.visible || Boolean(_liveStreamDisabledTooltipKey));
31
+        visible = interfaceConfig.TOOLBAR_BUTTONS.includes('livestreaming') && abstractProps.visible;
100 32
     }
101 33
 
102 34
     return {
103 35
         ...abstractProps,
104
-        _disabled,
105
-        _liveStreamDisabledTooltipKey,
106 36
         visible
107 37
     };
108 38
 }
109 39
 
110
-export default translate(connect(_mapStateToProps)(LiveStreamButton));
40
+export default translate(connect(_mapStateToProps)(AbstractLiveStreamButton));

+ 33
- 3
react/features/recording/components/Recording/AbstractRecordButton.js View File

@@ -5,6 +5,7 @@ import {
5 5
     sendAnalytics
6 6
 } from '../../../analytics';
7 7
 import { openDialog } from '../../../base/dialog';
8
+import { IconToggleRecording } from '../../../base/icons';
8 9
 import { JitsiRecordingConstants } from '../../../base/lib-jitsi-meet';
9 10
 import {
10 11
     getLocalParticipant,
@@ -34,6 +35,11 @@ export type Props = AbstractButtonProps & {
34 35
      */
35 36
     _isRecordingRunning: boolean,
36 37
 
38
+    /**
39
+     * The tooltip to display when hovering over the button.
40
+     */
41
+    _tooltip: ?String,
42
+
37 43
     /**
38 44
      * The redux {@code dispatch} function.
39 45
      */
@@ -48,12 +54,22 @@ export type Props = AbstractButtonProps & {
48 54
 /**
49 55
  * An abstract implementation of a button for starting and stopping recording.
50 56
  */
51
-export default class AbstractRecordButton<P: Props>
52
-    extends AbstractButton<P, *> {
57
+export default class AbstractRecordButton<P: Props> extends AbstractButton<P, *> {
53 58
     accessibilityLabel = 'toolbar.accessibilityLabel.recording';
59
+    icon = IconToggleRecording;
54 60
     label = 'dialog.startRecording';
55 61
     toggledLabel = 'dialog.stopRecording';
56 62
 
63
+    /**
64
+     * Returns the tooltip that should be displayed when the button is disabled.
65
+     *
66
+     * @private
67
+     * @returns {string}
68
+     */
69
+    _getTooltip() {
70
+        return this.props._tooltip || '';
71
+    }
72
+
57 73
     /**
58 74
      * Handles clicking / pressing the button.
59 75
      *
@@ -85,7 +101,7 @@ export default class AbstractRecordButton<P: Props>
85 101
      * @returns {boolean}
86 102
      */
87 103
     _isDisabled() {
88
-        return false;
104
+        return this.props._disabled;
89 105
     }
90 106
 
91 107
     /**
@@ -119,6 +135,7 @@ export function _mapStateToProps(state: Object, ownProps: Props): Object {
119 135
     // a button can be disabled/enabled if enableFeaturesBasedOnToken
120 136
     // is on or if the livestreaming is running.
121 137
     let _disabled;
138
+    let _tooltip = '';
122 139
 
123 140
     if (typeof visible === 'undefined') {
124 141
         // If the containing component provides the visible prop, that is one
@@ -136,17 +153,30 @@ export function _mapStateToProps(state: Object, ownProps: Props): Object {
136 153
         if (enableFeaturesBasedOnToken) {
137 154
             visible = visible && String(features.recording) === 'true';
138 155
             _disabled = String(features.recording) === 'disabled';
156
+            if (!visible && !_disabled) {
157
+                _disabled = true;
158
+                visible = true;
159
+
160
+                // button and tooltip
161
+                if (state['features/base/jwt'].isGuest) {
162
+                    _tooltip = 'dialog.recordingDisabledForGuestTooltip';
163
+                } else {
164
+                    _tooltip = 'dialog.recordingDisabledTooltip';
165
+                }
166
+            }
139 167
         }
140 168
     }
141 169
 
142 170
     // disable the button if the livestreaming is running.
143 171
     if (getActiveSession(state, JitsiRecordingConstants.mode.STREAM)) {
144 172
         _disabled = true;
173
+        _tooltip = 'dialog.recordingDisabledBecauseOfActiveLiveStreamingTooltip';
145 174
     }
146 175
 
147 176
     return {
148 177
         _disabled,
149 178
         _isRecordingRunning: Boolean(getActiveSession(state, JitsiRecordingConstants.mode.FILE)),
179
+        _tooltip,
150 180
         visible
151 181
     };
152 182
 }

+ 2
- 13
react/features/recording/components/Recording/native/RecordButton.js View File

@@ -4,19 +4,8 @@ import { Platform } from 'react-native';
4 4
 
5 5
 import { IOS_RECORDING_ENABLED, RECORDING_ENABLED, getFeatureFlag } from '../../../../base/flags';
6 6
 import { translate } from '../../../../base/i18n';
7
-import { IconToggleRecording } from '../../../../base/icons';
8 7
 import { connect } from '../../../../base/redux';
9
-import AbstractRecordButton, {
10
-    _mapStateToProps as _abstractMapStateToProps,
11
-    type Props
12
-} from '../AbstractRecordButton';
13
-
14
-/**
15
- * An implementation of a button for starting and stopping recording.
16
- */
17
-class RecordButton extends AbstractRecordButton<Props> {
18
-    icon = IconToggleRecording;
19
-}
8
+import AbstractRecordButton, { _mapStateToProps as _abstractMapStateToProps } from '../AbstractRecordButton';
20 9
 
21 10
 /**
22 11
  * Maps (parts of) the redux state to the associated props for this component.
@@ -38,4 +27,4 @@ export function mapStateToProps(state: Object, ownProps: Object) {
38 27
     };
39 28
 }
40 29
 
41
-export default translate(connect(mapStateToProps)(RecordButton));
30
+export default translate(connect(mapStateToProps)(AbstractRecordButton));

+ 4
- 72
react/features/recording/components/Recording/web/RecordButton.js View File

@@ -1,61 +1,14 @@
1 1
 // @flow
2 2
 
3 3
 import { translate } from '../../../../base/i18n';
4
-import { IconToggleRecording } from '../../../../base/icons';
5 4
 import { connect } from '../../../../base/redux';
6 5
 import AbstractRecordButton, {
7 6
     _mapStateToProps as _abstractMapStateToProps,
8
-    type Props as AbstractProps
7
+    type Props
9 8
 } from '../AbstractRecordButton';
10 9
 
11 10
 declare var interfaceConfig: Object;
12 11
 
13
-type Props = AbstractProps & {
14
-
15
-    /**
16
-     * True if the button should be disabled, false otherwise.
17
-     *
18
-     * NOTE: On web, if the feature is not disabled on purpose, then we still
19
-     * show the button but disabled and with a tooltip rendered on it,
20
-     * explaining why it's not available.
21
-     */
22
-    _disabled: boolean,
23
-
24
-    /**
25
-     * Tooltip for the button when it's disabled in a certain way.
26
-     */
27
-    _fileRecordingsDisabledTooltipKey: ?string
28
-}
29
-
30
-/**
31
- * An implementation of a button for starting and stopping recording.
32
- */
33
-class RecordButton extends AbstractRecordButton<Props> {
34
-    icon = IconToggleRecording;
35
-
36
-    /**
37
-     * Returns the tooltip that should be displayed when the button is disabled.
38
-     *
39
-     * @private
40
-     * @returns {string}
41
-     */
42
-    _getTooltip() {
43
-        return this.props._fileRecordingsDisabledTooltipKey || '';
44
-    }
45
-
46
-    /**
47
-     * Helper function to be implemented by subclasses, which must return a
48
-     * boolean value indicating if this button is disabled or not.
49
-     *
50
-     * @override
51
-     * @protected
52
-     * @returns {boolean}
53
-     */
54
-    _isDisabled() {
55
-        return this.props._disabled;
56
-    }
57
-}
58
-
59 12
 /**
60 13
  * Maps (parts of) the redux state to the associated props for the
61 14
  * {@code RecordButton} component.
@@ -74,35 +27,14 @@ export function _mapStateToProps(state: Object, ownProps: Props): Object {
74 27
     const abstractProps = _abstractMapStateToProps(state, ownProps);
75 28
     let { visible } = ownProps;
76 29
 
77
-    let { _disabled } = abstractProps;
78
-    let _fileRecordingsDisabledTooltipKey;
79
-
80
-    if (!abstractProps.visible && _disabled !== undefined && !_disabled) {
81
-        _disabled = true;
82
-
83
-        // button and tooltip
84
-        if (state['features/base/jwt'].isGuest) {
85
-            _fileRecordingsDisabledTooltipKey = 'dialog.recordingDisabledForGuestTooltip';
86
-        } else {
87
-            _fileRecordingsDisabledTooltipKey = 'dialog.recordingDisabledTooltip';
88
-        }
89
-    } else if (_disabled) {
90
-        _fileRecordingsDisabledTooltipKey = 'dialog.recordingDisabledBecauseOfActiveLiveStreamingTooltip';
91
-    } else {
92
-        _disabled = false;
93
-    }
94
-
95 30
     if (typeof visible === 'undefined') {
96
-        visible = interfaceConfig.TOOLBAR_BUTTONS.includes('recording')
97
-            && (abstractProps.visible || Boolean(_fileRecordingsDisabledTooltipKey));
31
+        visible = interfaceConfig.TOOLBAR_BUTTONS.includes('recording') && abstractProps.visible;
98 32
     }
99 33
 
100 34
     return {
101 35
         ...abstractProps,
102
-        visible,
103
-        _disabled,
104
-        _fileRecordingsDisabledTooltipKey
36
+        visible
105 37
     };
106 38
 }
107 39
 
108
-export default translate(connect(_mapStateToProps)(RecordButton));
40
+export default translate(connect(_mapStateToProps)(AbstractRecordButton));

Loading…
Cancel
Save