Преглед изворни кода

ref(AudioOutputPreview): use Audio from base/media

master
paweldomas пре 7 година
родитељ
комит
04dff9059b

+ 24
- 12
react/features/base/media/components/AbstractAudio.js Прегледај датотеку

7
  * playback.
7
  * playback.
8
  */
8
  */
9
 export type AudioElement = {
9
 export type AudioElement = {
10
+    pause: Function,
10
     play: Function,
11
     play: Function,
11
-    pause: Function
12
+    setSinkId: ?Function
12
 }
13
 }
13
 
14
 
14
 /**
15
 /**
45
      */
46
      */
46
     _audioElementImpl: ?AudioElement;
47
     _audioElementImpl: ?AudioElement;
47
 
48
 
48
-    /**
49
-     * {@link setAudioElementImpl} bound to <code>this</code>.
50
-     */
51
-    setAudioElementImpl: Function;
52
-
53
     /**
49
     /**
54
      * Initializes a new {@code AbstractAudio} instance.
50
      * Initializes a new {@code AbstractAudio} instance.
55
      *
51
      *
56
-     * @param {Object} props - The read-only properties with which the new
52
+     * @param {Props} props - The read-only properties with which the new
57
      * instance is to be initialized.
53
      * instance is to be initialized.
58
      */
54
      */
59
-    constructor(props: Object) {
55
+    constructor(props: Props) {
60
         super(props);
56
         super(props);
61
 
57
 
62
-        // Bind event handlers so they are only bound once for every instance.
58
+        // Bind event handlers so they are only bound once per instance.
63
         this.setAudioElementImpl = this.setAudioElementImpl.bind(this);
59
         this.setAudioElementImpl = this.setAudioElementImpl.bind(this);
64
     }
60
     }
65
 
61
 
83
         this._audioElementImpl && this._audioElementImpl.play();
79
         this._audioElementImpl && this._audioElementImpl.play();
84
     }
80
     }
85
 
81
 
82
+    setAudioElementImpl: (?AudioElement) => void;
83
+
86
     /**
84
     /**
87
      * Set the (reference to the) {@link AudioElement} object which implements
85
      * Set the (reference to the) {@link AudioElement} object which implements
88
      * the audio playback functionality.
86
      * the audio playback functionality.
95
     setAudioElementImpl(element: ?AudioElement) {
93
     setAudioElementImpl(element: ?AudioElement) {
96
         this._audioElementImpl = element;
94
         this._audioElementImpl = element;
97
 
95
 
98
-        if (typeof this.props.setRef === 'function') {
99
-            this.props.setRef(element ? this : null);
100
-        }
96
+        // setRef
97
+        const { setRef } = this.props;
98
+
99
+        typeof setRef === 'function' && setRef(element ? this : null);
100
+    }
101
+
102
+    /**
103
+     * Sets the sink ID (output device ID) on the underlying audio element.
104
+     * NOTE: Currently, implemented only on Web.
105
+     *
106
+     * @param {string} sinkId - The sink ID (output device ID).
107
+     * @returns {void}
108
+     */
109
+    setSinkId(sinkId: String) {
110
+        this._audioElementImpl
111
+            && typeof this._audioElementImpl.setSinkId === 'function'
112
+            && this._audioElementImpl.setSinkId(sinkId);
101
     }
113
     }
102
 }
114
 }

+ 11
- 13
react/features/base/media/components/web/Audio.js Прегледај датотеку

1
-/* @flow */
1
+// @flow
2
 
2
 
3
 import React from 'react';
3
 import React from 'react';
4
 
4
 
5
 import AbstractAudio from '../AbstractAudio';
5
 import AbstractAudio from '../AbstractAudio';
6
+import type { AudioElement } from '../AbstractAudio';
6
 
7
 
7
 /**
8
 /**
8
  * The React/Web {@link Component} which is similar to and wraps around
9
  * The React/Web {@link Component} which is similar to and wraps around
14
      */
15
      */
15
     _audioFileLoaded: boolean;
16
     _audioFileLoaded: boolean;
16
 
17
 
17
-    /**
18
-     * {@link _onCanPlayThrough} bound to "this".
19
-     */
20
-    _onCanPlayThrough: Function;
21
-
22
     /**
18
     /**
23
      * Reference to the HTML audio element, stored until the file is ready.
19
      * Reference to the HTML audio element, stored until the file is ready.
24
      */
20
      */
25
-    _ref: HTMLAudioElement;
26
-
27
-    /**
28
-     * {@link _setRef} bound to "this".
29
-     */
30
-    _setRef: Function;
21
+    _ref: ?AudioElement;
31
 
22
 
32
     /**
23
     /**
33
      * Creates new <code>Audio</code> element instance with given props.
24
      * Creates new <code>Audio</code> element instance with given props.
54
             <audio
45
             <audio
55
                 onCanPlayThrough = { this._onCanPlayThrough }
46
                 onCanPlayThrough = { this._onCanPlayThrough }
56
                 preload = 'auto'
47
                 preload = 'auto'
48
+
49
+                // $FlowFixMe
57
                 ref = { this._setRef }
50
                 ref = { this._setRef }
58
                 src = { this.props.src } />
51
                 src = { this.props.src } />
59
         );
52
         );
73
         }
66
         }
74
     }
67
     }
75
 
68
 
69
+    _onCanPlayThrough: () => void;
70
+
76
     /**
71
     /**
77
      * Called when 'canplaythrough' event is triggered on the audio element,
72
      * Called when 'canplaythrough' event is triggered on the audio element,
78
      * which means that the whole file has been loaded.
73
      * which means that the whole file has been loaded.
85
         this._maybeSetAudioElementImpl();
80
         this._maybeSetAudioElementImpl();
86
     }
81
     }
87
 
82
 
83
+    _setRef: (?AudioElement) => void;
84
+
88
     /**
85
     /**
89
      * Sets the reference to the HTML audio element.
86
      * Sets the reference to the HTML audio element.
90
      *
87
      *
92
      * @private
89
      * @private
93
      * @returns {void}
90
      * @returns {void}
94
      */
91
      */
95
-    _setRef(audioElement: HTMLAudioElement) {
92
+    _setRef(audioElement: ?AudioElement) {
96
         this._ref = audioElement;
93
         this._ref = audioElement;
94
+
97
         if (audioElement) {
95
         if (audioElement) {
98
             this._maybeSetAudioElementImpl();
96
             this._maybeSetAudioElementImpl();
99
         } else {
97
         } else {

+ 3
- 3
react/features/device-selection/components/AudioOutputPreview.js Прегледај датотеку

2
 import React, { Component } from 'react';
2
 import React, { Component } from 'react';
3
 
3
 
4
 import { translate } from '../../base/i18n';
4
 import { translate } from '../../base/i18n';
5
+import { Audio } from '../../base/media';
5
 
6
 
6
 const TEST_SOUND_PATH = 'sounds/ring.wav';
7
 const TEST_SOUND_PATH = 'sounds/ring.wav';
7
 
8
 
77
                 <a onClick = { this._onClick }>
78
                 <a onClick = { this._onClick }>
78
                     { this.props.t('deviceSelection.testAudio') }
79
                     { this.props.t('deviceSelection.testAudio') }
79
                 </a>
80
                 </a>
80
-                <audio
81
-                    preload = 'auto'
82
-                    ref = { this._setAudioElement }
81
+                <Audio
82
+                    setRef = { this._setAudioElement }
83
                     src = { TEST_SOUND_PATH } />
83
                     src = { TEST_SOUND_PATH } />
84
             </div>
84
             </div>
85
         );
85
         );

Loading…
Откажи
Сачувај