File tree 2 files changed +9
-3
lines changed
webrtc-kmp/src/jsMain/kotlin/com/shepeliev/webrtckmp
2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ package com.shepeliev.webrtckmp
3
3
import kotlinx.coroutines.flow.Flow
4
4
import kotlinx.coroutines.flow.MutableSharedFlow
5
5
import kotlinx.coroutines.flow.asSharedFlow
6
+ import org.khronos.webgl.ArrayBuffer
7
+ import org.khronos.webgl.Int8Array
6
8
7
9
actual class DataChannel internal constructor(val js : RTCDataChannel ) {
8
10
actual val id: Int
@@ -43,11 +45,14 @@ actual class DataChannel internal constructor(val js: RTCDataChannel) {
43
45
js.onclosing = { _onClosing .tryEmit(Unit ) }
44
46
js.onclose = { _onClose .tryEmit(Unit ) }
45
47
js.onerror = { _onError .tryEmit(it.message) }
46
- js.onmessage = { _onMessage .tryEmit(it.data.encodeToByteArray()) }
48
+ js.onmessage = {
49
+ _onMessage .tryEmit(Int8Array (it.data).unsafeCast<ByteArray >())
50
+ }
47
51
}
48
52
49
53
actual fun send (data : ByteArray ): Boolean {
50
- js.send(data.decodeToString())
54
+ val conversion = data.unsafeCast<Int8Array >()
55
+ js.send(conversion)
51
56
return true
52
57
}
53
58
Original file line number Diff line number Diff line change 1
1
package com.shepeliev.webrtckmp
2
2
3
+ import org.khronos.webgl.ArrayBuffer
3
4
import org.w3c.dom.mediacapture.MediaStream
4
5
import org.w3c.dom.mediacapture.MediaStreamTrack
5
6
import kotlin.js.Date
@@ -88,7 +89,7 @@ external class RTCDataChannel {
88
89
}
89
90
90
91
external class MessageEvent {
91
- val data: String
92
+ val data: ArrayBuffer
92
93
}
93
94
94
95
external class ErrorEvent {
You can’t perform that action at this time.
0 commit comments