|
@@ -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
|
}
|