1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
use super::*;
/// The AudioContext class.
/// [`AudioContext`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext)
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct AudioContext {
inner: BaseAudioContext,
}
impl FromVal for AudioContext {
fn from_val(v: &Any) -> Self {
AudioContext {
inner: BaseAudioContext::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for AudioContext {
type Target = BaseAudioContext;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for AudioContext {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for AudioContext {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for AudioContext {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<AudioContext> for Any {
fn from(s: AudioContext) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&AudioContext> for Any {
fn from(s: &AudioContext) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(AudioContext);
impl AudioContext {
/// Getter of the `baseLatency` attribute.
/// [`AudioContext.baseLatency`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/baseLatency)
pub fn base_latency(&self) -> f64 {
self.inner.get("baseLatency").as_::<f64>()
}
}
impl AudioContext {
/// Getter of the `outputLatency` attribute.
/// [`AudioContext.outputLatency`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/outputLatency)
pub fn output_latency(&self) -> f64 {
self.inner.get("outputLatency").as_::<f64>()
}
}
impl AudioContext {
/// Getter of the `sinkId` attribute.
/// [`AudioContext.sinkId`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/sinkId)
pub fn sink_id(&self) -> Any {
self.inner.get("sinkId").as_::<Any>()
}
}
impl AudioContext {
/// Getter of the `onsinkchange` attribute.
/// [`AudioContext.onsinkchange`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/onsinkchange)
pub fn onsinkchange(&self) -> Any {
self.inner.get("onsinkchange").as_::<Any>()
}
/// Setter of the `onsinkchange` attribute.
/// [`AudioContext.onsinkchange`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/onsinkchange)
pub fn set_onsinkchange(&mut self, value: &Any) {
self.inner.set("onsinkchange", value);
}
}
impl AudioContext {
/// Getter of the `onerror` attribute.
/// [`AudioContext.onerror`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/onerror)
pub fn onerror(&self) -> Any {
self.inner.get("onerror").as_::<Any>()
}
/// Setter of the `onerror` attribute.
/// [`AudioContext.onerror`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/onerror)
pub fn set_onerror(&mut self, value: &Any) {
self.inner.set("onerror", value);
}
}
impl AudioContext {
/// The `new AudioContext(..)` constructor, creating a new AudioContext instance
pub fn new() -> AudioContext {
Self {
inner: Any::global("AudioContext")
.new(&[])
.as_::<BaseAudioContext>(),
}
}
}
impl AudioContext {
/// The `new AudioContext(..)` constructor, creating a new AudioContext instance
pub fn new_with_context_options(context_options: &AudioContextOptions) -> AudioContext {
Self {
inner: Any::global("AudioContext")
.new(&[context_options.into()])
.as_::<BaseAudioContext>(),
}
}
}
impl AudioContext {
/// The getOutputTimestamp method.
/// [`AudioContext.getOutputTimestamp`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/getOutputTimestamp)
pub fn get_output_timestamp(&self) -> AudioTimestamp {
self.inner
.call("getOutputTimestamp", &[])
.as_::<AudioTimestamp>()
}
}
impl AudioContext {
/// The resume method.
/// [`AudioContext.resume`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/resume)
pub fn resume(&self) -> Promise<Undefined> {
self.inner.call("resume", &[]).as_::<Promise<Undefined>>()
}
}
impl AudioContext {
/// The suspend method.
/// [`AudioContext.suspend`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/suspend)
pub fn suspend(&self) -> Promise<Undefined> {
self.inner.call("suspend", &[]).as_::<Promise<Undefined>>()
}
}
impl AudioContext {
/// The close method.
/// [`AudioContext.close`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/close)
pub fn close(&self) -> Promise<Undefined> {
self.inner.call("close", &[]).as_::<Promise<Undefined>>()
}
}
impl AudioContext {
/// The setSinkId method.
/// [`AudioContext.setSinkId`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/setSinkId)
pub fn set_sink_id(&self, sink_id: &Any) -> Promise<Undefined> {
self.inner
.call("setSinkId", &[sink_id.into()])
.as_::<Promise<Undefined>>()
}
}
impl AudioContext {
/// The createMediaElementSource method.
/// [`AudioContext.createMediaElementSource`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaElementSource)
pub fn create_media_element_source(
&self,
media_element: &HTMLMediaElement,
) -> MediaElementAudioSourceNode {
self.inner
.call("createMediaElementSource", &[media_element.into()])
.as_::<MediaElementAudioSourceNode>()
}
}
impl AudioContext {
/// The createMediaStreamSource method.
/// [`AudioContext.createMediaStreamSource`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaStreamSource)
pub fn create_media_stream_source(
&self,
media_stream: &MediaStream,
) -> MediaStreamAudioSourceNode {
self.inner
.call("createMediaStreamSource", &[media_stream.into()])
.as_::<MediaStreamAudioSourceNode>()
}
}
impl AudioContext {
/// The createMediaStreamTrackSource method.
/// [`AudioContext.createMediaStreamTrackSource`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaStreamTrackSource)
pub fn create_media_stream_track_source(
&self,
media_stream_track: &MediaStreamTrack,
) -> MediaStreamTrackAudioSourceNode {
self.inner
.call("createMediaStreamTrackSource", &[media_stream_track.into()])
.as_::<MediaStreamTrackAudioSourceNode>()
}
}
impl AudioContext {
/// The createMediaStreamDestination method.
/// [`AudioContext.createMediaStreamDestination`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaStreamDestination)
pub fn create_media_stream_destination(&self) -> MediaStreamAudioDestinationNode {
self.inner
.call("createMediaStreamDestination", &[])
.as_::<MediaStreamAudioDestinationNode>()
}
}