Просмотр исходного кода

ref(AudioOutputPreview): use Audio from base/media

j8
paweldomas 7 лет назад
Родитель
Сommit
04dff9059b

+ 24
- 12
react/features/base/media/components/AbstractAudio.js Просмотреть файл

@@ -7,8 +7,9 @@ import { Component } from 'react';
7 7
  * playback.
8 8
  */
9 9
 export type AudioElement = {
10
+    pause: Function,
10 11
     play: Function,
11
-    pause: Function
12
+    setSinkId: ?Function
12 13
 }
13 14
 
14 15
 /**
@@ -45,21 +46,16 @@ export default class AbstractAudio extends Component<Props> {
45 46
      */
46 47
     _audioElementImpl: ?AudioElement;
47 48
 
48
-    /**
49
-     * {@link setAudioElementImpl} bound to <code>this</code>.
50
-     */
51
-    setAudioElementImpl: Function;
52
-
53 49
     /**
54 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 53
      * instance is to be initialized.
58 54
      */
59
-    constructor(props: Object) {
55
+    constructor(props: Props) {
60 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 59
         this.setAudioElementImpl = this.setAudioElementImpl.bind(this);
64 60
     }
65 61
 
@@ -83,6 +79,8 @@ export default class AbstractAudio extends Component<Props> {
83 79
         this._audioElementImpl && this._audioElementImpl.play();
84 80
     }
85 81
 
82
+    setAudioElementImpl: (?AudioElement) => void;
83
+
86 84
     /**
87 85
      * Set the (reference to the) {@link AudioElement} object which implements
88 86
      * the audio playback functionality.
@@ -95,8 +93,22 @@ export default class AbstractAudio extends Component<Props> {
95 93
     setAudioElementImpl(element: ?AudioElement) {
96 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,8 +1,9 @@
1
-/* @flow */
1
+// @flow
2 2
 
3 3
 import React from 'react';
4 4
 
5 5
 import AbstractAudio from '../AbstractAudio';
6
+import type { AudioElement } from '../AbstractAudio';
6 7
 
7 8
 /**
8 9
  * The React/Web {@link Component} which is similar to and wraps around
@@ -14,20 +15,10 @@ export default class Audio extends AbstractAudio {
14 15
      */
15 16
     _audioFileLoaded: boolean;
16 17
 
17
-    /**
18
-     * {@link _onCanPlayThrough} bound to "this".
19
-     */
20
-    _onCanPlayThrough: Function;
21
-
22 18
     /**
23 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 24
      * Creates new <code>Audio</code> element instance with given props.
@@ -54,6 +45,8 @@ export default class Audio extends AbstractAudio {
54 45
             <audio
55 46
                 onCanPlayThrough = { this._onCanPlayThrough }
56 47
                 preload = 'auto'
48
+
49
+                // $FlowFixMe
57 50
                 ref = { this._setRef }
58 51
                 src = { this.props.src } />
59 52
         );
@@ -73,6 +66,8 @@ export default class Audio extends AbstractAudio {
73 66
         }
74 67
     }
75 68
 
69
+    _onCanPlayThrough: () => void;
70
+
76 71
     /**
77 72
      * Called when 'canplaythrough' event is triggered on the audio element,
78 73
      * which means that the whole file has been loaded.
@@ -85,6 +80,8 @@ export default class Audio extends AbstractAudio {
85 80
         this._maybeSetAudioElementImpl();
86 81
     }
87 82
 
83
+    _setRef: (?AudioElement) => void;
84
+
88 85
     /**
89 86
      * Sets the reference to the HTML audio element.
90 87
      *
@@ -92,8 +89,9 @@ export default class Audio extends AbstractAudio {
92 89
      * @private
93 90
      * @returns {void}
94 91
      */
95
-    _setRef(audioElement: HTMLAudioElement) {
92
+    _setRef(audioElement: ?AudioElement) {
96 93
         this._ref = audioElement;
94
+
97 95
         if (audioElement) {
98 96
             this._maybeSetAudioElementImpl();
99 97
         } else {

+ 3
- 3
react/features/device-selection/components/AudioOutputPreview.js Просмотреть файл

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

Загрузка…
Отмена
Сохранить