@@ -2,6 +2,8 @@ import Configuration from "./utils/Configuration";
2
2
import Immigration from "./utils/Immigration" ;
3
3
import Event from "./dom/Event" ;
4
4
import EventTarget from "./dom/EventTarget" ;
5
+ import HTMLMediaElement from "./dom/HTMLMediaElement" ;
6
+ import MediaStream from "./dom/MediaStream" ;
5
7
import AudioBuffer from "./AudioBuffer" ;
6
8
import AnalyserNode from "./AnalyserNode" ;
7
9
import AudioBufferSourceNode from "./AudioBufferSourceNode" ;
@@ -98,6 +100,7 @@ export default class AudioContext extends EventTarget {
98
100
@props . on ( "statechange" )
99
101
onstatechange ( ) { }
100
102
103
+ @methods . returns ( validators . isInstanceOf ( Promise ) )
101
104
suspend ( ) {
102
105
return this . __transitionToState ( "suspend" , ( ) => {
103
106
if ( this . _ . state === "running" ) {
@@ -107,6 +110,7 @@ export default class AudioContext extends EventTarget {
107
110
} ) ;
108
111
}
109
112
113
+ @methods . returns ( validators . isInstanceOf ( Promise ) )
110
114
resume ( ) {
111
115
return this . __transitionToState ( "resume" , ( ) => {
112
116
if ( this . _ . state === "suspended" ) {
@@ -116,6 +120,7 @@ export default class AudioContext extends EventTarget {
116
120
} ) ;
117
121
}
118
122
123
+ @methods . returns ( validators . isInstanceOf ( Promise ) )
119
124
close ( ) {
120
125
return this . __transitionToState ( "close" , ( ) => {
121
126
if ( this . _ . state !== "closed" ) {
@@ -129,6 +134,7 @@ export default class AudioContext extends EventTarget {
129
134
@methods . param ( "numberOfChannels" , validators . isPositiveInteger )
130
135
@methods . param ( "length" , validators . isPositiveInteger )
131
136
@methods . param ( "sampleRate" , validators . isPositiveInteger )
137
+ @methods . returns ( validators . isInstanceOf ( AudioBuffer ) )
132
138
createBuffer ( numberOfChannels , length , sampleRate ) {
133
139
return immigration . apply ( admission =>
134
140
new AudioBuffer ( admission , this , numberOfChannels , length , sampleRate )
@@ -165,24 +171,30 @@ export default class AudioContext extends EventTarget {
165
171
}
166
172
}
167
173
174
+ @methods . returns ( validators . isInstanceOf ( AudioBufferSourceNode ) )
168
175
createBufferSource ( ) {
169
176
return immigration . apply ( admission =>
170
177
new AudioBufferSourceNode ( admission , this )
171
178
) ;
172
179
}
173
180
181
+ @methods . param ( "mediaElement" , validators . isInstanceOf ( HTMLMediaElement ) )
182
+ @methods . returns ( validators . isInstanceOf ( MediaElementAudioSourceNode ) )
174
183
createMediaElementSource ( mediaElement ) {
175
184
return immigration . apply ( admission =>
176
185
new MediaElementAudioSourceNode ( admission , this , mediaElement )
177
186
) ;
178
187
}
179
188
189
+ @methods . param ( "mediaStream" , validators . isInstanceOf ( MediaStream ) )
190
+ @methods . returns ( validators . isInstanceOf ( MediaStreamAudioSourceNode ) )
180
191
createMediaStreamSource ( mediaStream ) {
181
192
return immigration . apply ( admission =>
182
193
new MediaStreamAudioSourceNode ( admission , this , mediaStream )
183
194
) ;
184
195
}
185
196
197
+ @methods . returns ( validators . isInstanceOf ( MediaStreamAudioDestinationNode ) )
186
198
createMediaStreamDestination ( ) {
187
199
return immigration . apply ( admission =>
188
200
new MediaStreamAudioDestinationNode ( admission , this )
@@ -199,43 +211,50 @@ export default class AudioContext extends EventTarget {
199
211
@methods . param ( "bufferSize" , validators . isPositiveInteger )
200
212
@methods . param ( "[ numberOfInputChannels ]" , validators . isPositiveInteger )
201
213
@methods . param ( "[ numberOfOutputChannels ]" , validators . isPositiveInteger )
214
+ @methods . returns ( validators . isInstanceOf ( ScriptProcessorNode ) )
202
215
createScriptProcessor ( bufferSize , numberOfInputChannels = 2 , numberOfOutputChannels = 2 ) {
203
216
return immigration . apply ( admission =>
204
217
new ScriptProcessorNode ( admission , this , bufferSize , numberOfInputChannels , numberOfOutputChannels )
205
218
) ;
206
219
}
207
220
221
+ @methods . returns ( validators . isInstanceOf ( AnalyserNode ) )
208
222
createAnalyser ( ) {
209
223
return immigration . apply ( admission =>
210
224
new AnalyserNode ( admission , this )
211
225
) ;
212
226
}
213
227
228
+ @methods . returns ( validators . isInstanceOf ( GainNode ) )
214
229
createGain ( ) {
215
230
return immigration . apply ( admission =>
216
231
new GainNode ( admission , this )
217
232
) ;
218
233
}
219
234
220
235
@methods . param ( "[ maxDelayTime ]" , validators . isPositiveNumber )
236
+ @methods . returns ( validators . isInstanceOf ( DelayNode ) )
221
237
createDelay ( maxDelayTime = 1 ) {
222
238
return immigration . apply ( admission =>
223
239
new DelayNode ( admission , this , maxDelayTime )
224
240
) ;
225
241
}
226
242
243
+ @methods . returns ( validators . isInstanceOf ( BiquadFilterNode ) )
227
244
createBiquadFilter ( ) {
228
245
return immigration . apply ( admission =>
229
246
new BiquadFilterNode ( admission , this )
230
247
) ;
231
248
}
232
249
250
+ @methods . returns ( validators . isInstanceOf ( WaveShaperNode ) )
233
251
createWaveShaper ( ) {
234
252
return immigration . apply ( admission =>
235
253
new WaveShaperNode ( admission , this )
236
254
) ;
237
255
}
238
256
257
+ @methods . returns ( validators . isInstanceOf ( PannerNode ) )
239
258
createPanner ( ) {
240
259
return immigration . apply ( admission =>
241
260
new PannerNode ( admission , this )
@@ -249,38 +268,44 @@ export default class AudioContext extends EventTarget {
249
268
}
250
269
}
251
270
} )
271
+ @methods . returns ( validators . isInstanceOf ( StereoPannerNode ) )
252
272
createStereoPanner ( ) {
253
273
return immigration . apply ( admission =>
254
274
new StereoPannerNode ( admission , this )
255
275
) ;
256
276
}
257
277
278
+ @methods . returns ( validators . isInstanceOf ( ConvolverNode ) )
258
279
createConvolver ( ) {
259
280
return immigration . apply ( admission =>
260
281
new ConvolverNode ( admission , this )
261
282
) ;
262
283
}
263
284
264
285
@methods . param ( "[ numberOfOutputs ]" , validators . isPositiveInteger )
286
+ @methods . returns ( validators . isInstanceOf ( ChannelSplitterNode ) )
265
287
createChannelSplitter ( numberOfOutputs = 6 ) {
266
288
return immigration . apply ( admission =>
267
289
new ChannelSplitterNode ( admission , this , numberOfOutputs )
268
290
) ;
269
291
}
270
292
271
293
@methods . param ( "[ numberOfInputs ]" , validators . isPositiveInteger )
294
+ @methods . returns ( validators . isInstanceOf ( ChannelMergerNode ) )
272
295
createChannelMerger ( numberOfInputs = 6 ) {
273
296
return immigration . apply ( admission =>
274
297
new ChannelMergerNode ( admission , this , numberOfInputs )
275
298
) ;
276
299
}
277
300
301
+ @methods . returns ( validators . isInstanceOf ( DynamicsCompressorNode ) )
278
302
createDynamicsCompressor ( ) {
279
303
return immigration . apply ( admission =>
280
304
new DynamicsCompressorNode ( admission , this )
281
305
) ;
282
306
}
283
307
308
+ @methods . returns ( validators . isInstanceOf ( OscillatorNode ) )
284
309
createOscillator ( ) {
285
310
return immigration . apply ( admission =>
286
311
new OscillatorNode ( admission , this )
@@ -289,6 +314,7 @@ export default class AudioContext extends EventTarget {
289
314
290
315
@methods . param ( "real" , validators . isInstanceOf ( Float32Array ) )
291
316
@methods . param ( "imag" , validators . isInstanceOf ( Float32Array ) )
317
+ @methods . returns ( validators . isInstanceOf ( PeriodicWave ) )
292
318
createPeriodicWave ( real , imag ) {
293
319
return immigration . apply ( admission =>
294
320
new PeriodicWave ( admission , this , real , imag )
@@ -305,7 +331,7 @@ export default class AudioContext extends EventTarget {
305
331
__transitionToState ( methodName , callback ) {
306
332
return new Promise ( ( resolve ) => {
307
333
if ( this . _ . state === "close" ) {
308
- throw new TypeError ( `Cannot ${ methodName } a context that is being closed or has already been closed` ) ;
334
+ throw new TypeError ( `Cannot ${ methodName } a context that is being closed or has already been closed. ` ) ;
309
335
}
310
336
callback ( ) ;
311
337
resolve ( ) ;
0 commit comments