Browse Source

ref(always-on-top): refactor to stop using old toolbar components

j8
Leonard Kim 7 years ago
parent
commit
5cf16a20d3

+ 41
- 5
css/_toolbars.scss View File

440
     }
440
     }
441
 }
441
 }
442
 
442
 
443
+.always-on-top-toolbox,
443
 .filmstrip-toolbox {
444
 .filmstrip-toolbox {
444
     background-color: $newToolbarBackgroundColor;
445
     background-color: $newToolbarBackgroundColor;
445
     box-sizing: border-box;
446
     box-sizing: border-box;
450
     i {
451
     i {
451
         cursor: pointer;
452
         cursor: pointer;
452
         display: block;
453
         display: block;
453
-        font-size: 1.9em;
454
-        height: 37px;
455
-        line-height: 37px;
456
-        width: 37px;
457
     }
454
     }
458
 
455
 
459
     i:hover {
456
     i:hover {
464
         background: $newToolbarButtonToggleColor;
461
         background: $newToolbarButtonToggleColor;
465
     }
462
     }
466
 
463
 
467
-    i.toggled:hover {
464
+    i.toggled:hover:not(.disabled) {
468
         background-color: $newToolbarButtonHoverColor;
465
         background-color: $newToolbarButtonHoverColor;
469
     }
466
     }
470
 
467
 
479
     }
476
     }
480
 
477
 
481
     border-radius: 3px;
478
     border-radius: 3px;
479
+}
480
+
481
+.always-on-top-toolbox {
482
+    flex-direction: row;
483
+    left: 50%;
484
+    position: absolute;
485
+    top: 10px;
486
+    transform: translateX(-50%);
487
+    z-index: $toolbarZ;
488
+
489
+    i {
490
+        font-size: $alwaysOnTopToolbarFontSize;
491
+        height: $alwaysOnTopToolbarSize;
492
+        line-height: $alwaysOnTopToolbarSize;
493
+        width: $alwaysOnTopToolbarSize;
494
+    }
495
+
496
+    .disabled {
497
+        cursor: initial;
498
+    }
499
+
500
+    .toolbox-button:first-child i {
501
+        border-top-left-radius: 3px;
502
+        border-bottom-left-radius: 3px;
503
+    }
504
+
505
+    .toolbox-button:last-child i {
506
+        border-top-right-radius: 3px;
507
+        border-bottom-right-radius: 3px;
508
+    }
509
+}
510
+
511
+.filmstrip-toolbox {
512
+    i {
513
+        font-size: 1.9em;
514
+        height: 37px;
515
+        line-height: 37px;
516
+        width: 37px;
517
+    }
482
 
518
 
483
     .toolbox-button:first-child i {
519
     .toolbox-button:first-child i {
484
         border-top-left-radius: 3px;
520
         border-top-left-radius: 3px;

+ 8
- 98
react/features/always-on-top/AlwaysOnTop.js View File

2
 
2
 
3
 import React, { Component } from 'react';
3
 import React, { Component } from 'react';
4
 
4
 
5
-import StatelessToolbar from '../toolbox/components/StatelessToolbar';
6
-import StatelessToolbarButton
7
-    from '../toolbox/components/StatelessToolbarButton';
5
+import ToolboxAlwaysOnTop from './ToolboxAlwaysOnTop';
8
 
6
 
9
 const { api } = window.alwaysOnTop;
7
 const { api } = window.alwaysOnTop;
10
 
8
 
11
-/**
12
- * Map with toolbar button descriptors.
13
- */
14
-const TOOLBAR_BUTTONS = {
15
-    /**
16
-     * The descriptor of the camera toolbar button.
17
-     */
18
-    camera: {
19
-        classNames: [ 'button', 'icon-camera' ],
20
-        enabled: true,
21
-        id: 'toolbar_button_camera',
22
-        onClick() {
23
-            api.executeCommand('toggleVideo');
24
-        }
25
-    },
26
-
27
-    /**
28
-     * The descriptor of the toolbar button which hangs up the call/conference.
29
-     */
30
-    hangup: {
31
-        classNames: [ 'button', 'icon-hangup', 'button_hangup' ],
32
-        enabled: true,
33
-        id: 'toolbar_button_hangup',
34
-        onClick() {
35
-            api.executeCommand('hangup');
36
-            window.close();
37
-        }
38
-    },
39
-
40
-    /**
41
-     * The descriptor of the microphone toolbar button.
42
-     */
43
-    microphone: {
44
-        classNames: [ 'button', 'icon-microphone' ],
45
-        enabled: true,
46
-        id: 'toolbar_button_mute',
47
-        onClick() {
48
-            api.executeCommand('toggleAudio');
49
-        }
50
-    }
51
-};
52
-
53
 /**
9
 /**
54
  * The timeout in ms for hidding the toolbar.
10
  * The timeout in ms for hidding the toolbar.
55
  */
11
  */
385
      * @returns {ReactElement}
341
      * @returns {ReactElement}
386
      */
342
      */
387
     render() {
343
     render() {
388
-        const className
389
-            = `toolbar_primary always-on-top ${
390
-                this.state.visible ? 'fadeIn' : 'fadeOut'}`;
391
-
392
         return (
344
         return (
393
             <div id = 'alwaysOnTop'>
345
             <div id = 'alwaysOnTop'>
394
-                <StatelessToolbar
395
-                    className = { className }
346
+                <ToolboxAlwaysOnTop
347
+                    audioAvailable = { this.state.audioAvailable }
348
+                    audioMuted = { this.state.audioMuted }
349
+                    className = { this.state.visible ? 'fadeIn' : 'fadeOut' }
396
                     onMouseOut = { this._onMouseOut }
350
                     onMouseOut = { this._onMouseOut }
397
-                    onMouseOver = { this._onMouseOver }>
398
-                    {
399
-                        Object.entries(TOOLBAR_BUTTONS).map(
400
-                            ([ key, button ]) => {
401
-                                // XXX The following silences a couple of flow
402
-                                // errors:
403
-                                if (button === null
404
-                                        || typeof button !== 'object') {
405
-                                    return null;
406
-                                }
407
-
408
-                                const { onClick } = button;
409
-                                let enabled = false;
410
-                                let toggled = false;
411
-
412
-                                switch (key) {
413
-                                case 'microphone':
414
-                                    enabled = this.state.audioAvailable;
415
-                                    toggled = enabled
416
-                                        ? this.state.audioMuted : true;
417
-                                    break;
418
-                                case 'camera':
419
-                                    enabled = this.state.videoAvailable;
420
-                                    toggled = enabled
421
-                                        ? this.state.videoMuted : true;
422
-                                    break;
423
-                                default: // hangup button
424
-                                    toggled = false;
425
-                                    enabled = true;
426
-                                }
427
-
428
-                                const updatedButton = {
429
-                                    ...button,
430
-                                    enabled,
431
-                                    toggled
432
-                                };
433
-
434
-                                return (
435
-                                    <StatelessToolbarButton
436
-                                        button = { updatedButton }
437
-                                        key = { key }
438
-                                        onClick = { onClick } />
439
-                                );
440
-                            }
441
-                        )
442
-                    }
443
-                </StatelessToolbar>
351
+                    onMouseOver = { this._onMouseOver }
352
+                    videoAvailable = { this.state.videoAvailable }
353
+                    videoMuted = { this.state.videoMuted } />
444
                 {
354
                 {
445
                     this._renderVideoNotAvailableScreen()
355
                     this._renderVideoNotAvailableScreen()
446
                 }
356
                 }

+ 159
- 0
react/features/always-on-top/ToolboxAlwaysOnTop.js View File

1
+// @flow
2
+
3
+import React, { Component } from 'react';
4
+
5
+// FIXME: AlwaysOnTop imports the button directly in order to avoid bringing in
6
+// other components that use lib-jitsi-meet, which always on top does not
7
+// import.
8
+import ToolbarButton from '../toolbox/components/ToolbarButton';
9
+
10
+const { api } = window.alwaysOnTop;
11
+
12
+/**
13
+ * The type of the React {@code Component} props of {@link ToolboxAlwaysOnTop}.
14
+ */
15
+type Props = {
16
+
17
+    /**
18
+     * Whether or not microphone access is available.
19
+     */
20
+    audioAvailable: boolean,
21
+
22
+    /**
23
+     * Whether or not the user is currently audio muted.
24
+     */
25
+    audioMuted: boolean,
26
+
27
+    /**
28
+     * Additional CSS class names to add to the root of the toolbar.
29
+     */
30
+    className: string,
31
+
32
+    /**
33
+     * Callback invoked when no longer moused over the toolbar.
34
+     */
35
+    onMouseOut: Function,
36
+
37
+    /**
38
+     * Callback invoked when the mouse has moved over the toolbar.
39
+     */
40
+     onMouseOver: Function,
41
+
42
+    /**
43
+     * Whether or not camera access is available.
44
+     */
45
+    videoAvailable: boolean,
46
+
47
+    /**
48
+     * Whether or not the user is currently video muted.
49
+     */
50
+    videoMuted: boolean
51
+};
52
+
53
+/**
54
+ * Represents the toolbar in the Always On Top window.
55
+ *
56
+ * @extends Component
57
+ */
58
+export default class ToolboxAlwaysOnTop extends Component<Props> {
59
+    /**
60
+     * Initializes a new {@code ToolboxAlwaysOnTop} instance.
61
+     *
62
+     * @param {Props} props - The read-only properties with which the new
63
+     * instance is to be initialized.
64
+     */
65
+    constructor(props: Props) {
66
+        super(props);
67
+
68
+        // Bind event handlers so they are only bound once per instance.
69
+        this._onToolbarHangup = this._onToolbarHangup.bind(this);
70
+        this._onToolbarToggleAudio = this._onToolbarToggleAudio.bind(this);
71
+        this._onToolbarToggleVideo = this._onToolbarToggleVideo.bind(this);
72
+    }
73
+
74
+    /**
75
+     * Implements React's {@link Component#render()}.
76
+     *
77
+     * @inheritdoc
78
+     * @returns {ReactElement}
79
+     */
80
+    render() {
81
+        const {
82
+            audioAvailable,
83
+            audioMuted,
84
+            className = '',
85
+            onMouseOut,
86
+            onMouseOver,
87
+            videoAvailable,
88
+            videoMuted
89
+        } = this.props;
90
+
91
+        const videoMuteIcon = `${videoMuted || !videoAvailable
92
+            ? 'icon-camera-disabled toggled' : 'icon-camera'} ${
93
+            videoAvailable ? '' : 'disabled'}`;
94
+        const audioMuteIcon = `${audioMuted || !audioAvailable
95
+            ? 'icon-mic-disabled toggled' : 'icon-microphone'} ${
96
+            audioAvailable ? '' : 'disabled'}`;
97
+
98
+        return (
99
+            <div
100
+                className = { `always-on-top-toolbox ${className}` }
101
+                onMouseOut = { onMouseOut }
102
+                onMouseOver = { onMouseOver }>
103
+                <ToolbarButton
104
+                    accessibilityLabel = 'Video mute'
105
+                    iconName = { videoMuteIcon }
106
+                    onClick = { this._onToolbarToggleVideo } />
107
+                <ToolbarButton
108
+                    accessibilityLabel = 'Hangup'
109
+                    iconName = 'icon-hangup'
110
+                    onClick = { this._onToolbarHangup } />
111
+                <ToolbarButton
112
+                    accessibilityLabel = 'Audio mute'
113
+                    iconName = { audioMuteIcon }
114
+                    onClick = { this._onToolbarToggleAudio } />
115
+            </div>
116
+        );
117
+    }
118
+
119
+    _onToolbarHangup: () => void;
120
+
121
+    /**
122
+     * Ends the conference call and closes the always on top window.
123
+     *
124
+     * @private
125
+     * @returns {void}
126
+     */
127
+    _onToolbarHangup() {
128
+        api.executeCommand('hangup');
129
+        window.close();
130
+    }
131
+
132
+    _onToolbarToggleAudio: () => void;
133
+
134
+    /**
135
+     * Toggles audio mute if audio is avaiable.
136
+     *
137
+     * @private
138
+     * @returns {void}
139
+     */
140
+    _onToolbarToggleAudio() {
141
+        if (this.props.audioAvailable) {
142
+            api.executeCommand('toggleAudio');
143
+        }
144
+    }
145
+
146
+    _onToolbarToggleVideo: () => void;
147
+
148
+    /**
149
+     * Toggles video mute if video is avaiable.
150
+     *
151
+     * @private
152
+     * @returns {void}
153
+     */
154
+    _onToolbarToggleVideo() {
155
+        if (this.props.videoAvailable) {
156
+            api.executeCommand('toggleVideo');
157
+        }
158
+    }
159
+}

+ 7
- 5
react/features/toolbox/components/ToolbarButton.web.js View File

53
                 aria-label = { this.props.accessibilityLabel }
53
                 aria-label = { this.props.accessibilityLabel }
54
                 className = 'toolbox-button'
54
                 className = 'toolbox-button'
55
                 onClick = { this.props.onClick }>
55
                 onClick = { this.props.onClick }>
56
-                <Tooltip
57
-                    description = { this.props.tooltip }
58
-                    position = { this.props.tooltipPosition }>
59
-                    { children }
60
-                </Tooltip>
56
+                { this.props.tooltip
57
+                    ? <Tooltip
58
+                        description = { this.props.tooltip }
59
+                        position = { this.props.tooltipPosition }>
60
+                        { children }
61
+                    </Tooltip>
62
+                    : children }
61
             </div>
63
             </div>
62
         );
64
         );
63
     }
65
     }

Loading…
Cancel
Save