Skip to content

Commit cf32be0

Browse files
committed
Worklets. Move WA inside class
1 parent 973d5eb commit cf32be0

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

tests/worklets/mdn-audioworklet-example/src/commonMain/kotlin/mdn/audioworklet/example/HissGeneratorProcessor.kt

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,7 @@ import kotlin.random.Random
1515
* @class HissGeneratorProcessor
1616
* @extends AudioWorkletProcessor
1717
**/
18-
private class HissGeneratorProcessor : AudioWorkletProcessor() {
19-
companion object : AudioWorkletProcessorCompanion {
20-
override val parameterDescriptors: ReadonlyArray<AudioParamDescriptor> =
21-
arrayOf(
22-
AudioParamDescriptor(
23-
name = GAIN,
24-
defaultValue = 0.2f,
25-
minValue = 0f,
26-
maxValue = 1f,
27-
)
28-
)
29-
}
30-
18+
class HissGeneratorProcessor : AudioWorkletProcessor() {
3119
/**
3220
* Called by the browser's audio subsystem with
3321
* packets of audio data to be processed.
@@ -89,12 +77,23 @@ private class HissGeneratorProcessor : AudioWorkletProcessor() {
8977

9078
return true
9179
}
92-
}
9380

94-
// TODO: Remove when `@JsStatic` will work in development mode
95-
val HissGeneratorProcessorClass: JsClass<out AudioWorkletProcessor>
96-
get() {
97-
val klass = HissGeneratorProcessor::class.js
98-
klass.asDynamic().parameterDescriptors = HissGeneratorProcessor.parameterDescriptors
99-
return klass
81+
companion object : AudioWorkletProcessorCompanion {
82+
override val parameterDescriptors: ReadonlyArray<AudioParamDescriptor> =
83+
arrayOf(
84+
AudioParamDescriptor(
85+
name = GAIN,
86+
defaultValue = 0.2f,
87+
minValue = 0f,
88+
maxValue = 1f,
89+
)
90+
)
91+
92+
// TODO: Remove when `@JsStatic` will work in development mode
93+
val classRef: JsClass<out AudioWorkletProcessor> by lazy {
94+
val klass = HissGeneratorProcessor::class.js
95+
klass.asDynamic().parameterDescriptors = parameterDescriptors
96+
klass
97+
}
10098
}
99+
}

tests/worklets/mdn-audioworklet-example/src/commonMain/kotlin/mdn/audioworklet/example/HissGeneratorWorkletModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ package mdn.audioworklet.example
33
import web.audio.AudioWorkletModule
44

55
val HissGeneratorWorkletModule = AudioWorkletModule { self ->
6-
self.registerProcessor("hiss-generator", HissGeneratorProcessorClass)
6+
self.registerProcessor("hiss-generator", HissGeneratorProcessor.classRef)
77
}

0 commit comments

Comments
 (0)