@poolse/native 3.10.0 → 3.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,30 @@
2
2
 
3
3
  Formerly `@poolse/react-native-calls` (0.x).
4
4
 
5
+ ## [3.10.1] - 2026-11-23
6
+
7
+ ### Added
8
+
9
+ - Data channel (CL4, CL6): `publishData(topic, data, options)` over
10
+ LiveKit data packets on both cores (iOS `publish(data:)`, Android
11
+ `publishData`), options `reliable`, `base64` and `to`, capped at
12
+ `CALL_DATA_MAX_BYTES` (14 000, as the web `CallRoom`); `onCallData`
13
+ with `topic`, `payload` (base64), `text`, `fromIdentity`, `fromName`;
14
+ `callData`, a `CallDataChannel` for @poolse/sdk's `CallReactions` /
15
+ `ScreenAnnotations` and @poolse/react's `useCallReactions` /
16
+ `useScreenAnnotations`, so reactions and the pointer and drawing on a
17
+ shared screen interoperate with web and desktop. Snapshot
18
+ `selfIdentity`.
19
+ - Breakout rooms (CL5): `moveToRoom(session)` moves the live call's media
20
+ to another room of the same call (the bundle of
21
+ `POST /breakouts/:room/join` or `POST /calls/:id/breakouts/return`),
22
+ keeping the CallKit / Telecom call, the phase and mute and camera; it
23
+ falls back to the previous room if the new one can't be joined.
24
+ Snapshot `breakout` (`roomId`, `name`; null in the main room). In a
25
+ breakout room the alone check is off and a reconnect rejoins that room
26
+ with the fresh control token. The state machine and its vectors are
27
+ unchanged; runtime tests cover the move on both cores.
28
+
5
29
  ## [3.10.0] - 2026-11-23
6
30
 
7
31
  ### Added
package/README.md CHANGED
@@ -204,6 +204,41 @@ person in a call, so the other device is let go. Its snapshot gets
204
204
  other device", not "Call ended". Offer it where `liveCalls` shows you already
205
205
  in the call.
206
206
 
207
+ **Reactions, pointer and drawing (data channel).** `callData` is the call's
208
+ LiveKit data channel in the shape @poolse/sdk's `CallDataChannel` takes, so
209
+ the SDK's `CallReactions` and `ScreenAnnotations`, and @poolse/react's
210
+ `useCallReactions` / `useScreenAnnotations`, run on phones with the same
211
+ topics and messages as the web and desktop (`poolse.reaction`,
212
+ `poolse.annotate`):
213
+
214
+ ```tsx
215
+ import { callData } from '@poolse/native';
216
+ const reactions = useCallReactions(callData);
217
+ const { state, annotations } = useScreenAnnotations(callData, sharerUserId);
218
+ <CallVideoView participantId={sharerUserId} source="screen" fit="contain" />
219
+ <AnnotationOverlay state={state} annotations={annotations} drawing={penOn} />
220
+ ```
221
+
222
+ Lower level: `publishData(topic, data, { reliable?, base64?, to? })` sends
223
+ text (or base64 bytes) and resolves `false` with no call connected or over
224
+ `CALL_DATA_MAX_BYTES` (14 000, as on the web); `onCallData(cb)` gets
225
+ `{ topic, payload (base64), text, fromIdentity, fromName }` for every message
226
+ others send. `snapshot.selfIdentity` is your identity in the room.
227
+
228
+ **Breakout rooms.** A breakout room is another LiveKit room of the same call
229
+ (MEETINGS.md §5). `moveToRoom(session)` takes the bundle of `POST
230
+ /v1/breakouts/:room/join` (or `POST /v1/calls/:id/breakouts/return` to come
231
+ back, the SDK's `meetingsLive.breakouts.join` / `returnToMain`) and moves the
232
+ call's media there without hanging up: CallKit and Android's call service
233
+ keep the call, the phase stays `active`, mute and camera stay as they were,
234
+ and `snapshot.breakout` (`{ roomId, name }`, null in the main room) says
235
+ where you are. A screen share stops on the move. If the room can't be
236
+ joined, the media goes back to where it was. Being alone in a breakout room
237
+ never ends the call, and a network drop there rejoins the same room.
238
+ @poolse/react-native's `useNativeBreakouts(conversationId, callId, {
239
+ moveToRoom })` follows the split by itself: into your room as it opens, back
240
+ as it closes.
241
+
207
242
  ## Ringtone
208
243
 
209
244
  ```json
@@ -70,6 +70,12 @@ class CallCoreRuntime(
70
70
  /** The call whose media has had someone else in it (for [onRemoteCount]). */
71
71
  private var remoteSeenFor: String? = null
72
72
 
73
+ /**
74
+ * While [moveToRoom] connects: the room's bundle it came from, to go
75
+ * back to if the new room cannot be joined.
76
+ */
77
+ private var movingFrom: CallSessionBundle? = null
78
+
73
79
  private val resolved = object : LinkedHashMap<String, Unit>(RESOLVED_LRU, 0.75f, true) {
74
80
  override fun removeEldestEntry(eldest: MutableMap.MutableEntry<String, Unit>?) = size > RESOLVED_LRU
75
81
  }
@@ -159,6 +165,15 @@ class CallCoreRuntime(
159
165
  /** The call waiting beside the current one, with its caller's names. Runtime thread only. */
160
166
  val waitingRing: RingContext? get() = if (state.waiting == null) null else waitingRingCtx
161
167
 
168
+ /** The session bundle in use, null before the server accepted. Any thread. */
169
+ val currentBundle: CallSessionBundle? get() = bundle
170
+
171
+ /**
172
+ * The breakout room the media is in (MEETINGS.md §5) as (room id,
173
+ * name); null in the call's main room. Any thread.
174
+ */
175
+ val breakout: Pair<String, String?>? get() = bundle?.let { b -> b.breakoutRoomId?.let { it to b.breakoutName } }
176
+
162
177
  /** True if [callId] was already resolved here — its ring must never surface again. */
163
178
  fun isResolved(callId: String): Boolean = synchronized(resolved) { resolved.containsKey(callId) }
164
179
 
@@ -235,8 +250,53 @@ class CallCoreRuntime(
235
250
  /** Caller-side: the bridge resolved every ring from `ring_states`. */
236
251
  fun allRingsResolved(outcome: String) = post { dispatch(Event.AllRingsResolved(outcome)) }
237
252
 
238
- fun onMediaConnected() = post { dispatch(Event.MediaConnected) }
239
- fun onMediaFailed() = post { dispatch(Event.MediaFailed) }
253
+ fun onMediaConnected() = post {
254
+ movingFrom = null
255
+ dispatch(Event.MediaConnected)
256
+ }
257
+
258
+ fun onMediaFailed() = post {
259
+ // The room [moveToRoom] went to would not have us: back to the one it
260
+ // came from. The call itself never noticed.
261
+ val back = movingFrom
262
+ if (back != null && (state.phase == Phase.ACTIVE || state.phase == Phase.RECONNECTING)) {
263
+ movingFrom = null
264
+ bundle = back
265
+ media.join(back)
266
+ sink.emit(state)
267
+ return@post
268
+ }
269
+ dispatch(Event.MediaFailed)
270
+ }
271
+
272
+ /**
273
+ * Breakout rooms (MEETINGS.md §5): carry the call on in another
274
+ * LiveKit room of the SAME call — the bundle of `POST
275
+ * /breakouts/:room/join`, or of `POST /calls/:id/breakouts/return` to
276
+ * come back. The machine never sees it: the phase, the system call
277
+ * (Telecom's foreground service / CallKit) and the timers stay; only
278
+ * the media swaps rooms, with mute and camera as they were. If the new
279
+ * room cannot be joined, the media goes back to the room it came from.
280
+ *
281
+ * [done] `false`: not now — no live call, or the bundle is another call's.
282
+ */
283
+ fun moveToRoom(next: CallSessionBundle, done: ((Boolean) -> Unit)? = null) = post {
284
+ val current = bundle
285
+ if ((state.phase != Phase.ACTIVE && state.phase != Phase.RECONNECTING) ||
286
+ current == null || current.callId != next.callId
287
+ ) {
288
+ done?.invoke(false)
289
+ return@post
290
+ }
291
+ if (movingFrom == null) movingFrom = current
292
+ bundle = next
293
+ // Who was in the last room says nothing about this one.
294
+ remoteSeenFor = null
295
+ timers.cancel(T_ALONE)
296
+ media.join(next)
297
+ sink.emit(state)
298
+ done?.invoke(true)
299
+ }
240
300
  fun onMediaLost() = post { dispatch(Event.MediaLost) }
241
301
  fun onMediaReconnecting() = post { dispatch(Event.MediaReconnecting) }
242
302
  fun onMediaRecovered() = post { dispatch(Event.MediaRecovered) }
@@ -262,7 +322,9 @@ class CallCoreRuntime(
262
322
  timers.cancel(T_ALONE)
263
323
  return@post
264
324
  }
325
+ // In a breakout room the others are in the call's other rooms.
265
326
  if (state.phase != Phase.ACTIVE || callKind == "room" || remoteSeenFor != callId) return@post
327
+ if (bundle?.breakoutRoomId != null) return@post
266
328
  scheduleAloneProbe(callId, 0)
267
329
  }
268
330
 
@@ -277,6 +339,7 @@ class CallCoreRuntime(
277
339
  private fun probeAlone(callId: String, attempt: Int) {
278
340
  if (state.phase != Phase.ACTIVE) return
279
341
  val b = bundle ?: return
342
+ if (b.breakoutRoomId != null) return
280
343
  val g = gen
281
344
  val last = attempt == ALONE_PROBES_MS.size - 1
282
345
  // A still-live answer carries a fresh bundle; the current one stays
@@ -333,7 +396,7 @@ class CallCoreRuntime(
333
396
  // fallback still need it); CallSessionStop clears it with the rest.
334
397
  if (isTerminal(next.phase)) ring = null
335
398
  // A bundle never outlives its call — whatever ended it.
336
- if (isTerminal(next.phase)) { bundle = null; sessionToken = null }
399
+ if (isTerminal(next.phase)) { bundle = null; movingFrom = null; sessionToken = null }
337
400
  // A waiting call that went away without becoming the current one
338
401
  // (declined, cancelled, timed out) is resolved: its ring never again.
339
402
  before.waiting?.let { w ->
@@ -416,6 +479,7 @@ class CallCoreRuntime(
416
479
  Effect.CallSessionStop -> {
417
480
  session.stop()
418
481
  bundle = null
482
+ movingFrom = null
419
483
  ring = null
420
484
  sessionToken = null
421
485
  }
@@ -431,6 +495,7 @@ class CallCoreRuntime(
431
495
  markResolved(before.callId)
432
496
  gen++
433
497
  bundle = null
498
+ movingFrom = null
434
499
  sessionToken = null
435
500
  ring = waitingRingCtx
436
501
  waitingRingCtx = null
@@ -484,9 +549,21 @@ class CallCoreRuntime(
484
549
  when (result) {
485
550
  is HttpResult.Ok -> {
486
551
  // Fresh token (and possibly URL): rejoin with it. MEDIA_CONNECTED
487
- // on the new room returns us to ACTIVE.
488
- bundle = result.bundle
489
- media.join(result.bundle)
552
+ // on the new room returns us to ACTIVE. In a breakout room,
553
+ // /reconnect answers with the main room's session: keep the room
554
+ // (its token outlives a network drop) and take the rest.
555
+ val cur = bundle
556
+ val fresh = result.bundle
557
+ val b = if (cur?.breakoutRoomId != null && fresh.breakoutRoomId == null) {
558
+ fresh.copy(
559
+ livekitUrl = cur.livekitUrl,
560
+ livekitToken = cur.livekitToken,
561
+ breakoutRoomId = cur.breakoutRoomId,
562
+ breakoutName = cur.breakoutName,
563
+ )
564
+ } else fresh
565
+ bundle = b
566
+ media.join(b)
490
567
  }
491
568
  HttpResult.Gone -> dispatch(Event.HttpGone)
492
569
  is HttpResult.AuthFailed -> dispatch(Event.HttpFailed(result.code))
@@ -64,6 +64,13 @@ data class CallSessionBundle(
64
64
  */
65
65
  val recording: String? = null,
66
66
  val transcription: String? = null,
67
+ /**
68
+ * The breakout room this bundle's `livekit` connects to (MEETINGS.md
69
+ * §5: `breakout: {room_id, name}` from `POST /breakouts/:room/join`);
70
+ * null for the call's main room.
71
+ */
72
+ val breakoutRoomId: String? = null,
73
+ val breakoutName: String? = null,
67
74
  )
68
75
 
69
76
  /** LiveKit (or any SFU) — media only, no lifecycle opinions. */
@@ -331,6 +331,37 @@ class CallCore private constructor(context: Context) {
331
331
  /** The current call's id and control token. Any thread. */
332
332
  val control: Pair<String, String>? get() = runtime.control
333
333
 
334
+ /**
335
+ * Breakout rooms (MEETINGS.md §5): the call's media to the room of
336
+ * [payload] — the JSON of `POST /breakouts/:room/join` (or of `POST
337
+ * /calls/:id/breakouts/return`). The call service and the system call
338
+ * stay; see [CallCoreRuntime.moveToRoom]. [done] false: unparseable,
339
+ * no live call, or another call's session.
340
+ */
341
+ fun moveToRoom(payload: String, done: (Boolean) -> Unit) = runtime.post {
342
+ val current = runtime.currentBundle
343
+ val next = current?.let { runCatching { CallHttpClient.parseBundle(payload, it) }.getOrNull() }
344
+ if (next == null) {
345
+ done(false)
346
+ return@post
347
+ }
348
+ runtime.moveToRoom(next) { ok ->
349
+ // The last room's people are not in this one.
350
+ if (ok) roster = emptyList()
351
+ done(ok)
352
+ }
353
+ }
354
+
355
+ /**
356
+ * A data-channel message to the call's room (CL4, CL6). False at once
357
+ * when the media engine has no data channel (the signalling-only build).
358
+ */
359
+ fun publishData(topic: String, data: ByteArray, reliable: Boolean, to: List<String>, done: (Boolean) -> Unit) {
360
+ val source = media as? CallDataSource ?: return done(false)
361
+ // On the runtime's (main) thread: the media port only touches its room there.
362
+ runtime.post { source.publishData(topic, data, reliable, to, done) }
363
+ }
364
+
334
365
  fun allRingsResolved(outcome: String) = runtime.allRingsResolved(outcome)
335
366
 
336
367
  fun state(): MachineState = runtime.currentState()
@@ -424,6 +455,9 @@ class CallCore private constructor(context: Context) {
424
455
  out["noiseSuppression"] = noiseSuppression
425
456
  out["backgroundBlur"] = backgroundBlur
426
457
  out["movedElsewhere"] = movedElsewhere
458
+ // Breakout rooms (MEETINGS.md §5): the room the media is in, null in the main room.
459
+ out["breakout"] = runtime.breakout?.let { (roomId, name) -> mapOf("roomId" to roomId, "name" to name) }
460
+ out["selfIdentity"] = (media as? CallDataSource)?.localIdentity
427
461
  // Taken over by another of this user's devices: the machine ends it
428
462
  // as `left` (CALL_CONTRACT.md §9); the app is told why.
429
463
  if (movedElsewhere && state.phase == Phase.ENDED) out["reason"] = "moved"
@@ -550,6 +584,22 @@ class CallCore private constructor(context: Context) {
550
584
  override fun onMovedElsewhere() {
551
585
  runtime.post { movedElsewhere = true }
552
586
  }
587
+ override fun onData(topic: String, payload: ByteArray, fromIdentity: String?, fromName: String?) {
588
+ val text = runCatching {
589
+ Charsets.UTF_8.newDecoder().decode(java.nio.ByteBuffer.wrap(payload)).toString()
590
+ }.getOrNull()
591
+ runCatching {
592
+ dataListener?.invoke(
593
+ mapOf(
594
+ "topic" to topic,
595
+ "payload" to android.util.Base64.encodeToString(payload, android.util.Base64.NO_WRAP),
596
+ "text" to text,
597
+ "fromIdentity" to fromIdentity,
598
+ "fromName" to fromName,
599
+ ),
600
+ )
601
+ }.onFailure { Log.w(TAG, "data listener failed", it) }
602
+ }
553
603
  }
554
604
 
555
605
  private fun bringAppToFront(callId: String, from: Context?): Boolean {
@@ -582,6 +632,15 @@ class CallCore private constructor(context: Context) {
582
632
  */
583
633
  @Volatile var listener: ((Map<String, Any?>?) -> Unit)? = null
584
634
 
635
+ /**
636
+ * The bridge's data-channel subscriber (CL4, CL6): `{topic, payload
637
+ * (base64), text (UTF-8 or null), fromIdentity, fromName}`.
638
+ */
639
+ @Volatile var dataListener: ((Map<String, Any?>) -> Unit)? = null
640
+
641
+ /** The most one data message may carry — the web CallRoom's CALL_DATA_MAX_BYTES. */
642
+ const val DATA_MAX_BYTES = 14_000
643
+
585
644
  /**
586
645
  * Configure the core and PERSIST the inputs. A ring can wake a killed
587
646
  * app: the OS spawns the process cold to run [CallMessagingService],
@@ -819,6 +878,11 @@ interface MediaEvents {
819
878
  * [onLost].
820
879
  */
821
880
  fun onMovedElsewhere() {}
881
+ /**
882
+ * A data-channel message from someone in the room (CL4, CL6): its
883
+ * topic, the bytes, and who sent it (null identity: the server).
884
+ */
885
+ fun onData(topic: String, payload: ByteArray, fromIdentity: String?, fromName: String?) {}
822
886
  }
823
887
 
824
888
  /** One place call audio can play — a snapshot `audioOutputs[]` entry. */
@@ -174,7 +174,10 @@ internal class CallHttpClient(
174
174
  livekitToken = livekit.getString("token"),
175
175
  controlToken = root.optStringOrNull("control_token") ?: current.controlToken,
176
176
  ringing = 0,
177
- // recording / transcription: the current bundle's stand.
177
+ // recording / transcription: the current bundle's stand. A bare
178
+ // refresh is the main room's (servers before breakouts).
179
+ breakoutRoomId = null,
180
+ breakoutName = null,
178
181
  )
179
182
  }
180
183
  return CallSessionBundle(
@@ -193,6 +196,9 @@ internal class CallHttpClient(
193
196
  } ?: 0,
194
197
  recording = call.optJSONObject("recording")?.toString() ?: current?.recording,
195
198
  transcription = call.optJSONObject("transcription")?.toString() ?: current?.transcription,
199
+ // Only a breakout join's bundle names a room; never inherited from [current].
200
+ breakoutRoomId = root.optJSONObject("breakout")?.optStringOrNull("room_id"),
201
+ breakoutName = root.optJSONObject("breakout")?.optStringOrNull("name"),
196
202
  )
197
203
  }
198
204
 
@@ -41,6 +41,24 @@ interface CaptureProcessingSource {
41
41
  fun setBackgroundBlur(on: Boolean) {}
42
42
  }
43
43
 
44
+ /**
45
+ * The call's data channel (CL4 pointer and drawing on a shared screen,
46
+ * CL6 reactions), for a media port that has one. Messages arrive through
47
+ * [MediaEvents.onData]. Main thread only.
48
+ */
49
+ interface CallDataSource {
50
+ /** Our SFU identity (the poolse user id) while connected; null otherwise. */
51
+ val localIdentity: String?
52
+
53
+ /**
54
+ * Send [data] under [topic] to everyone in the room, or to [to] (SFU
55
+ * identities). `reliable = false` for what is stale a moment later (a
56
+ * moving pointer). [done] false: not connected, over
57
+ * [CallCore.DATA_MAX_BYTES], or refused.
58
+ */
59
+ fun publishData(topic: String, data: ByteArray, reliable: Boolean, to: List<String>, done: (Boolean) -> Unit)
60
+ }
61
+
44
62
  /** One on-screen video slot, bound to a participant's camera or shared screen. */
45
63
  interface CallVideoSurface {
46
64
  /** The Android view to host; it fills its parent. */
@@ -37,7 +37,7 @@ class PoolseCallsModule : Module() {
37
37
  override fun definition() = ModuleDefinition {
38
38
  Name("PoolseCalls")
39
39
 
40
- Events("onCallState", "onCallAction", "onPictureInPicture", "onNotificationAction")
40
+ Events("onCallState", "onCallAction", "onPictureInPicture", "onNotificationAction", "onCallData")
41
41
 
42
42
  // <CallVideoView>: renders a participant's (or our own) camera.
43
43
  View(PoolseCallVideoView::class) {
@@ -60,9 +60,11 @@ class PoolseCallsModule : Module() {
60
60
  CallCore.listener = { snapshot -> sendEvent("onCallState", mapOf("snapshot" to snapshot)) }
61
61
  CallPictureInPicture.listener = { active -> sendEvent("onPictureInPicture", mapOf("active" to active)) }
62
62
  MessageNotifications.actionListener = { event -> sendEvent("onNotificationAction", event) }
63
+ CallCore.dataListener = { message -> sendEvent("onCallData", message) }
63
64
  }
64
65
  OnStopObserving {
65
66
  CallCore.listener = null
67
+ CallCore.dataListener = null
66
68
  CallPictureInPicture.listener = null
67
69
  MessageNotifications.actionListener = null
68
70
  }
@@ -196,6 +198,36 @@ class PoolseCallsModule : Module() {
196
198
  // Recording consent accepted: mic and camera back as they were.
197
199
  Function("republish") { core()?.republish() }
198
200
 
201
+ // The call's data channel (CL4, CL6): `data` is UTF-8 text, or bytes
202
+ // as base64 with `options.base64`. Resolves false when not connected,
203
+ // over 14 000 bytes, or refused.
204
+ AsyncFunction("publishData") { topic: String, data: String, options: Map<String, Any?>?, promise: Promise ->
205
+ val core = core()
206
+ val bytes = runCatching {
207
+ if (options?.get("base64") == true) android.util.Base64.decode(data, android.util.Base64.DEFAULT)
208
+ else data.toByteArray(Charsets.UTF_8)
209
+ }.getOrNull()
210
+ if (core == null || bytes == null) {
211
+ promise.resolve(false)
212
+ return@AsyncFunction
213
+ }
214
+ val to = (options?.get("to") as? List<*>)?.filterIsInstance<String>() ?: emptyList()
215
+ core.publishData(topic, bytes, options?.get("reliable") as? Boolean ?: true, to) { promise.resolve(it) }
216
+ }
217
+
218
+ // Breakout rooms (MEETINGS.md §5): the live call's media to another
219
+ // room of the same call, keeping the call service and the system
220
+ // call. `session` is the JSON of POST /breakouts/:room/join or
221
+ // /calls/:id/breakouts/return.
222
+ AsyncFunction("moveToRoom") { session: String, promise: Promise ->
223
+ val core = core()
224
+ if (core == null) {
225
+ promise.resolve(false)
226
+ return@AsyncFunction
227
+ }
228
+ core.moveToRoom(session) { promise.resolve(it) }
229
+ }
230
+
199
231
  // What authorizes acting on the call itself (ringing people in).
200
232
  AsyncFunction("callControl") {
201
233
  val core = core() ?: return@AsyncFunction null
@@ -11,6 +11,8 @@ import dev.poolse.callcore.CallSessionBundle
11
11
  import dev.poolse.callcore.MediaPort
12
12
  import dev.poolse.callcore.ServiceParticipants
13
13
  import dev.poolse.callcore.android.AudioOutput
14
+ import dev.poolse.callcore.android.CallCore
15
+ import dev.poolse.callcore.android.CallDataSource
14
16
  import dev.poolse.callcore.android.CaptureProcessingSource
15
17
  import dev.poolse.callcore.android.CallVideoSource
16
18
  import dev.poolse.callcore.android.CallVideoSurface
@@ -29,6 +31,7 @@ import io.livekit.android.room.participant.Participant
29
31
  import io.livekit.android.room.participant.ParticipantPermission
30
32
  import io.livekit.android.room.participant.RemoteParticipant
31
33
  import io.livekit.android.room.track.CameraPosition
34
+ import io.livekit.android.room.track.DataPublishReliability
32
35
  import io.livekit.android.room.track.LocalAudioTrackOptions
33
36
  import io.livekit.android.room.track.LocalVideoTrack
34
37
  import io.livekit.android.room.track.RemoteTrackPublication
@@ -63,7 +66,7 @@ import org.json.JSONObject
63
66
  class LiveKitMediaPort(
64
67
  private val context: Context,
65
68
  private val events: MediaEvents,
66
- ) : MediaPort, CallVideoSource, ScreenShareSource, CaptureProcessingSource {
69
+ ) : MediaPort, CallVideoSource, ScreenShareSource, CaptureProcessingSource, CallDataSource {
67
70
 
68
71
  private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
69
72
  @Volatile private var room: Room? = null
@@ -288,6 +291,36 @@ class LiveKitMediaPort(
288
291
  }
289
292
  }
290
293
 
294
+ // ── data channel (CL4, CL6) ─────────────────────────────────────────
295
+
296
+ override val localIdentity: String?
297
+ get() = room?.takeIf { it.state == Room.State.CONNECTED }?.localParticipant?.identity?.value
298
+
299
+ override fun publishData(
300
+ topic: String,
301
+ data: ByteArray,
302
+ reliable: Boolean,
303
+ to: List<String>,
304
+ done: (Boolean) -> Unit,
305
+ ) {
306
+ val r = room
307
+ if (r == null || r.state != Room.State.CONNECTED || topic.isEmpty() || data.size > CallCore.DATA_MAX_BYTES) {
308
+ done(false)
309
+ return
310
+ }
311
+ scope.launch {
312
+ val sent = runCatching {
313
+ r.localParticipant.publishData(
314
+ data,
315
+ if (reliable) DataPublishReliability.RELIABLE else DataPublishReliability.LOSSY,
316
+ topic,
317
+ to.takeIf { it.isNotEmpty() }?.map { Participant.Identity(it) },
318
+ )
319
+ }.onFailure { Log.w(TAG, "data publish on $topic failed", it) }.isSuccess
320
+ done(sent)
321
+ }
322
+ }
323
+
291
324
  // ── capture processing (CL7) ────────────────────────────────────────
292
325
 
293
326
  /**
@@ -626,6 +659,12 @@ class LiveKitMediaPort(
626
659
  qualityChanged(room)
627
660
  emit(room)
628
661
  }
662
+ is RoomEvent.DataReceived -> {
663
+ val topic = event.topic
664
+ if (!topic.isNullOrEmpty() && event.data.size <= CallCore.DATA_MAX_BYTES) {
665
+ events.onData(topic, event.data, event.participant?.identity?.value, event.participant?.name)
666
+ }
667
+ }
629
668
  is RoomEvent.ActiveSpeakersChanged,
630
669
  is RoomEvent.ParticipantMetadataChanged,
631
670
  is RoomEvent.ParticipantAttributesChanged -> emit(room)
@@ -39,6 +39,21 @@ class CallHttpClientTest {
39
39
  assertEquals(current.copy(livekitUrl = "wss://sfu2", livekitToken = "lk-2"), r.bundle)
40
40
  }
41
41
 
42
+ @Test fun `a breakout join's bundle names its room, the main room's never inherits it`() {
43
+ val room = CallHttpClient.parseBundle(
44
+ """{"cv":1,"created":false,"control_token":"ctl","livekit":{"url":"wss://sfu","token":"lk-room"},
45
+ "breakout":{"room_id":"0b7e.2","name":"Design"},"call":{"id":"c1","conversation_id":"conv"}}""",
46
+ )
47
+ assertEquals("0b7e.2", room.breakoutRoomId)
48
+ assertEquals("Design", room.breakoutName)
49
+ val main = CallHttpClient.parseBundle(
50
+ """{"control_token":"ctl","livekit":{"url":"wss://sfu","token":"lk"},"call":{"id":"c1","conversation_id":"conv"}}""",
51
+ room,
52
+ )
53
+ assertEquals(null, main.breakoutRoomId)
54
+ assertEquals(null, CallHttpClient.parseBundle("""{"livekit":{"token":"lk2"}}""", room).breakoutRoomId)
55
+ }
56
+
42
57
  @Test fun `unparseable 2xx is a failure, not a retry`() {
43
58
  assertTrue(CallHttpClient.classify(200, "<html>", null) is HttpResult.Failed)
44
59
  assertTrue(CallHttpClient.classify(200, """{"livekit":{"token":"x"}}""", null) is HttpResult.Failed)
package/dist/index.cjs CHANGED
@@ -224,6 +224,91 @@ function onPictureInPicture(cb) {
224
224
  const sub = native.addListener("onPictureInPicture", (payload) => cb(payload.active));
225
225
  return () => sub.remove();
226
226
  }
227
+ var CALL_DATA_MAX_BYTES = 14e3;
228
+ function utf8Length(s) {
229
+ let n = 0;
230
+ for (let i = 0; i < s.length; i++) {
231
+ const c = s.charCodeAt(i);
232
+ if (c < 128) n += 1;
233
+ else if (c < 2048) n += 2;
234
+ else if (c >= 55296 && c <= 56319 && i + 1 < s.length) {
235
+ n += 4;
236
+ i++;
237
+ } else n += 3;
238
+ }
239
+ return n;
240
+ }
241
+ async function publishData(topic, data, options = {}) {
242
+ if (!native?.publishData || !topic) return false;
243
+ const size = options.base64 ? Math.floor(data.length * 3 / 4) : utf8Length(data);
244
+ if (size > CALL_DATA_MAX_BYTES) return false;
245
+ try {
246
+ return await native.publishData(topic, data, {
247
+ reliable: options.reliable ?? true,
248
+ base64: options.base64 ?? false,
249
+ ...options.to ? { to: options.to } : {}
250
+ });
251
+ } catch {
252
+ return false;
253
+ }
254
+ }
255
+ function onCallData(cb) {
256
+ if (!native?.publishData) return () => void 0;
257
+ const sub = native.addListener("onCallData", cb);
258
+ return () => sub.remove();
259
+ }
260
+ var dataListeners = /* @__PURE__ */ new Map();
261
+ var dataSub = null;
262
+ var callData = {
263
+ getSelfId() {
264
+ return getCallState()?.selfIdentity ?? null;
265
+ },
266
+ sendData(topic, message, opts = {}) {
267
+ let text;
268
+ try {
269
+ text = JSON.stringify(message);
270
+ } catch {
271
+ return Promise.resolve(false);
272
+ }
273
+ return publishData(topic, text, opts);
274
+ },
275
+ onData(topic, fn) {
276
+ let set = dataListeners.get(topic);
277
+ if (!set) {
278
+ set = /* @__PURE__ */ new Set();
279
+ dataListeners.set(topic, set);
280
+ }
281
+ set.add(fn);
282
+ dataSub ??= onCallData((m) => {
283
+ const listeners = dataListeners.get(m.topic);
284
+ if (!listeners?.size || m.text == null) return;
285
+ let parsed;
286
+ try {
287
+ parsed = JSON.parse(m.text);
288
+ } catch {
289
+ return;
290
+ }
291
+ const from = { userId: m.fromIdentity, name: m.fromName };
292
+ for (const l of [...listeners]) l(parsed, from);
293
+ });
294
+ return () => {
295
+ set.delete(fn);
296
+ if (set.size === 0) dataListeners.delete(topic);
297
+ if (dataListeners.size === 0 && dataSub) {
298
+ dataSub();
299
+ dataSub = null;
300
+ }
301
+ };
302
+ }
303
+ };
304
+ async function moveToRoom(session) {
305
+ if (!native?.moveToRoom) return false;
306
+ try {
307
+ return await native.moveToRoom(typeof session === "string" ? session : JSON.stringify(session));
308
+ } catch {
309
+ return false;
310
+ }
311
+ }
227
312
  var nativeVideo;
228
313
  function nativeVideoView() {
229
314
  if (nativeVideo !== void 0) return nativeVideo;
@@ -254,12 +339,14 @@ function CallVideoView(props) {
254
339
  return react.createElement(Native, props);
255
340
  }
256
341
 
342
+ exports.CALL_DATA_MAX_BYTES = CALL_DATA_MAX_BYTES;
257
343
  exports.CallVideoView = CallVideoView;
258
344
  exports.DEFAULT_SERVER_ID = DEFAULT_SERVER_ID;
259
345
  exports.addServer = addServer;
260
346
  exports.answer = answer;
261
347
  exports.answerWaiting = answerWaiting;
262
348
  exports.backgroundBlurSupported = backgroundBlurSupported;
349
+ exports.callData = callData;
263
350
  exports.canUseFullScreenIntent = canUseFullScreenIntent;
264
351
  exports.configure = configure;
265
352
  exports.conversationOfNotification = conversationOfNotification;
@@ -272,9 +359,11 @@ exports.isInPictureInPicture = isInPictureInPicture;
272
359
  exports.join = join;
273
360
  exports.listServers = listServers;
274
361
  exports.moveCallHere = moveCallHere;
362
+ exports.moveToRoom = moveToRoom;
275
363
  exports.nativeCallsAvailable = nativeCallsAvailable;
276
364
  exports.noiseSuppressionSupported = noiseSuppressionSupported;
277
365
  exports.onCallAction = onCallAction;
366
+ exports.onCallData = onCallData;
278
367
  exports.onCallFinished = onCallFinished;
279
368
  exports.onCallState = onCallState;
280
369
  exports.onCanPublishChange = onCanPublishChange;
@@ -287,6 +376,7 @@ exports.onVoipToken = onVoipToken;
287
376
  exports.openFullScreenIntentSettings = openFullScreenIntentSettings;
288
377
  exports.pictureInPictureSupported = pictureInPictureSupported;
289
378
  exports.place = place;
379
+ exports.publishData = publishData;
290
380
  exports.removeServer = removeServer;
291
381
  exports.republish = republish;
292
382
  exports.ringIntoCall = ringIntoCall;