-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathElementaryModule.kt
More file actions
60 lines (48 loc) · 1.47 KB
/
ElementaryModule.kt
File metadata and controls
60 lines (48 loc) · 1.47 KB
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
package com.elementary
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.WritableMap
import com.facebook.react.modules.core.DeviceEventManagerModule
class ElementaryModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {
override fun getName(): String {
return NAME
}
@ReactMethod
fun getSampleRate(promise: Promise) {
promise.resolve(nativeGetSampleRate())
}
@ReactMethod
fun applyInstructions(message: String) {
nativeApplyInstructions(message)
}
@ReactMethod
fun addListener(eventName: String) {
// No-op, RN handles subscription tracking
}
@ReactMethod
fun removeListeners(count: Double) {
// No-op
}
// Helper to emit events
private fun sendEvent(eventName: String, params: WritableMap?) {
reactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
.emit(eventName, params)
}
fun emitAudioPlaybackFinished() {
sendEvent("AudioPlaybackFinished", null)
}
companion object {
const val NAME = "Elementary"
}
init {
System.loadLibrary("react-native-elementary");
nativeStartAudioEngine();
}
external fun nativeGetSampleRate(): Int;
external fun nativeApplyInstructions(message: String);
external fun nativeStartAudioEngine();
}