@poolse/native 3.10.0 → 3.10.2
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 +34 -0
- package/README.md +39 -0
- package/android/src/main/java/dev/poolse/callcore/CallCoreRuntime.kt +83 -6
- package/android/src/main/java/dev/poolse/callcore/Ports.kt +7 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +71 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallHttpClient.kt +7 -1
- package/android/src/main/java/dev/poolse/callcore/android/CallVideo.kt +18 -0
- package/android/src/main/java/dev/poolse/callcore/android/SnapshotJson.kt +13 -0
- package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +33 -1
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +48 -1
- package/android/src/test/java/dev/poolse/callcore/android/CallHttpClientTest.kt +15 -0
- package/dist/index.cjs +90 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +131 -1
- package/dist/index.d.ts +131 -1
- package/dist/index.js +86 -1
- package/dist/index.js.map +1 -1
- package/ios/Core/CallCoreRuntime.swift +79 -5
- package/ios/Core/CallHttpClient.swift +9 -2
- package/ios/Core/Ports.swift +9 -1
- package/ios/Core/SnapshotEncoding.swift +21 -1
- package/ios/Module/PoolseCallsModule.swift +23 -1
- package/ios/Platform/CallCore.swift +48 -0
- package/ios/Platform/LiveKitMediaPort.swift +62 -1
- package/package.json +1 -1
- package/src/index.ts +223 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
Formerly `@poolse/react-native-calls` (0.x).
|
|
4
4
|
|
|
5
|
+
## [3.10.2] - 2026-11-23
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Shared screen size (CL4): `snapshot.screenShare` (`{ userId,
|
|
10
|
+
externalId, width, height }` of the first remote sharer, null when
|
|
11
|
+
none) and `participants[].screenWidth` / `screenHeight`, from the
|
|
12
|
+
publisher's track info on both cores, so phones can line up screen
|
|
13
|
+
drawings instead of assuming 16:9. Type `ScreenShareInfo`.
|
|
14
|
+
|
|
15
|
+
## [3.10.1] - 2026-11-23
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- Data channel (CL4, CL6): `publishData(topic, data, options)` over
|
|
20
|
+
LiveKit data packets on both cores (iOS `publish(data:)`, Android
|
|
21
|
+
`publishData`), options `reliable`, `base64` and `to`, capped at
|
|
22
|
+
`CALL_DATA_MAX_BYTES` (14 000, as the web `CallRoom`); `onCallData`
|
|
23
|
+
with `topic`, `payload` (base64), `text`, `fromIdentity`, `fromName`;
|
|
24
|
+
`callData`, a `CallDataChannel` for @poolse/sdk's `CallReactions` /
|
|
25
|
+
`ScreenAnnotations` and @poolse/react's `useCallReactions` /
|
|
26
|
+
`useScreenAnnotations`, so reactions and the pointer and drawing on a
|
|
27
|
+
shared screen interoperate with web and desktop. Snapshot
|
|
28
|
+
`selfIdentity`.
|
|
29
|
+
- Breakout rooms (CL5): `moveToRoom(session)` moves the live call's media
|
|
30
|
+
to another room of the same call (the bundle of
|
|
31
|
+
`POST /breakouts/:room/join` or `POST /calls/:id/breakouts/return`),
|
|
32
|
+
keeping the CallKit / Telecom call, the phase and mute and camera; it
|
|
33
|
+
falls back to the previous room if the new one can't be joined.
|
|
34
|
+
Snapshot `breakout` (`roomId`, `name`; null in the main room). In a
|
|
35
|
+
breakout room the alone check is off and a reconnect rejoins that room
|
|
36
|
+
with the fresh control token. The state machine and its vectors are
|
|
37
|
+
unchanged; runtime tests cover the move on both cores.
|
|
38
|
+
|
|
5
39
|
## [3.10.0] - 2026-11-23
|
|
6
40
|
|
|
7
41
|
### Added
|
package/README.md
CHANGED
|
@@ -94,6 +94,8 @@ The full API:
|
|
|
94
94
|
- Screen sharing: `screenShareSupported`, `startScreenShare`, `stopScreenShare`,
|
|
95
95
|
`snapshot.screenSharing` (yours) and `participants[].screenSharing`; draw a
|
|
96
96
|
shared screen with `<CallVideoView participantId source="screen" fit="contain" />`.
|
|
97
|
+
`snapshot.screenShare` names who shares and the screen's `width`/`height`
|
|
98
|
+
(also `participants[].screenWidth` / `screenHeight`).
|
|
97
99
|
iOS needs the `screenShare` plugin option.
|
|
98
100
|
- Video: `<CallVideoView participantId | local mirror fit pictureInPicture />`,
|
|
99
101
|
`setPictureInPictureEnabled`, `isInPictureInPicture`,
|
|
@@ -204,6 +206,43 @@ person in a call, so the other device is let go. Its snapshot gets
|
|
|
204
206
|
other device", not "Call ended". Offer it where `liveCalls` shows you already
|
|
205
207
|
in the call.
|
|
206
208
|
|
|
209
|
+
**Reactions, pointer and drawing (data channel).** `callData` is the call's
|
|
210
|
+
LiveKit data channel in the shape @poolse/sdk's `CallDataChannel` takes, so
|
|
211
|
+
the SDK's `CallReactions` and `ScreenAnnotations`, and @poolse/react's
|
|
212
|
+
`useCallReactions` / `useScreenAnnotations`, run on phones with the same
|
|
213
|
+
topics and messages as the web and desktop (`poolse.reaction`,
|
|
214
|
+
`poolse.annotate`):
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
import { callData } from '@poolse/native';
|
|
218
|
+
const reactions = useCallReactions(callData);
|
|
219
|
+
const { state, annotations } = useScreenAnnotations(callData, sharerUserId);
|
|
220
|
+
// snapshot.screenShare: { userId, externalId, width, height } — size the
|
|
221
|
+
// overlay to the screen's aspect inside the contain-fitted view.
|
|
222
|
+
<CallVideoView participantId={sharerUserId} source="screen" fit="contain" />
|
|
223
|
+
<AnnotationOverlay state={state} annotations={annotations} drawing={penOn} />
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Lower level: `publishData(topic, data, { reliable?, base64?, to? })` sends
|
|
227
|
+
text (or base64 bytes) and resolves `false` with no call connected or over
|
|
228
|
+
`CALL_DATA_MAX_BYTES` (14 000, as on the web); `onCallData(cb)` gets
|
|
229
|
+
`{ topic, payload (base64), text, fromIdentity, fromName }` for every message
|
|
230
|
+
others send. `snapshot.selfIdentity` is your identity in the room.
|
|
231
|
+
|
|
232
|
+
**Breakout rooms.** A breakout room is another LiveKit room of the same call
|
|
233
|
+
(MEETINGS.md §5). `moveToRoom(session)` takes the bundle of `POST
|
|
234
|
+
/v1/breakouts/:room/join` (or `POST /v1/calls/:id/breakouts/return` to come
|
|
235
|
+
back, the SDK's `meetingsLive.breakouts.join` / `returnToMain`) and moves the
|
|
236
|
+
call's media there without hanging up: CallKit and Android's call service
|
|
237
|
+
keep the call, the phase stays `active`, mute and camera stay as they were,
|
|
238
|
+
and `snapshot.breakout` (`{ roomId, name }`, null in the main room) says
|
|
239
|
+
where you are. A screen share stops on the move. If the room can't be
|
|
240
|
+
joined, the media goes back to where it was. Being alone in a breakout room
|
|
241
|
+
never ends the call, and a network drop there rejoins the same room.
|
|
242
|
+
@poolse/react-native's `useNativeBreakouts(conversationId, callId, {
|
|
243
|
+
moveToRoom })` follows the split by itself: into your room as it opens, back
|
|
244
|
+
as it closes.
|
|
245
|
+
|
|
207
246
|
## Ringtone
|
|
208
247
|
|
|
209
248
|
```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 {
|
|
239
|
-
|
|
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
|
-
|
|
489
|
-
|
|
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()
|
|
@@ -379,6 +410,10 @@ class CallCore private constructor(context: Context) {
|
|
|
379
410
|
put("muted", it.muted)
|
|
380
411
|
put("cameraOn", it.cameraOn)
|
|
381
412
|
put("screenSharing", it.screenSharing)
|
|
413
|
+
if (it.screenSharing && it.screenWidth != null && it.screenHeight != null) {
|
|
414
|
+
put("screenWidth", it.screenWidth)
|
|
415
|
+
put("screenHeight", it.screenHeight)
|
|
416
|
+
}
|
|
382
417
|
put("connectionQuality", it.connectionQuality)
|
|
383
418
|
if (it.isAgent) {
|
|
384
419
|
put("isAgent", true)
|
|
@@ -424,6 +459,9 @@ class CallCore private constructor(context: Context) {
|
|
|
424
459
|
out["noiseSuppression"] = noiseSuppression
|
|
425
460
|
out["backgroundBlur"] = backgroundBlur
|
|
426
461
|
out["movedElsewhere"] = movedElsewhere
|
|
462
|
+
// Breakout rooms (MEETINGS.md §5): the room the media is in, null in the main room.
|
|
463
|
+
out["breakout"] = runtime.breakout?.let { (roomId, name) -> mapOf("roomId" to roomId, "name" to name) }
|
|
464
|
+
out["selfIdentity"] = (media as? CallDataSource)?.localIdentity
|
|
427
465
|
// Taken over by another of this user's devices: the machine ends it
|
|
428
466
|
// as `left` (CALL_CONTRACT.md §9); the app is told why.
|
|
429
467
|
if (movedElsewhere && state.phase == Phase.ENDED) out["reason"] = "moved"
|
|
@@ -550,6 +588,22 @@ class CallCore private constructor(context: Context) {
|
|
|
550
588
|
override fun onMovedElsewhere() {
|
|
551
589
|
runtime.post { movedElsewhere = true }
|
|
552
590
|
}
|
|
591
|
+
override fun onData(topic: String, payload: ByteArray, fromIdentity: String?, fromName: String?) {
|
|
592
|
+
val text = runCatching {
|
|
593
|
+
Charsets.UTF_8.newDecoder().decode(java.nio.ByteBuffer.wrap(payload)).toString()
|
|
594
|
+
}.getOrNull()
|
|
595
|
+
runCatching {
|
|
596
|
+
dataListener?.invoke(
|
|
597
|
+
mapOf(
|
|
598
|
+
"topic" to topic,
|
|
599
|
+
"payload" to android.util.Base64.encodeToString(payload, android.util.Base64.NO_WRAP),
|
|
600
|
+
"text" to text,
|
|
601
|
+
"fromIdentity" to fromIdentity,
|
|
602
|
+
"fromName" to fromName,
|
|
603
|
+
),
|
|
604
|
+
)
|
|
605
|
+
}.onFailure { Log.w(TAG, "data listener failed", it) }
|
|
606
|
+
}
|
|
553
607
|
}
|
|
554
608
|
|
|
555
609
|
private fun bringAppToFront(callId: String, from: Context?): Boolean {
|
|
@@ -582,6 +636,15 @@ class CallCore private constructor(context: Context) {
|
|
|
582
636
|
*/
|
|
583
637
|
@Volatile var listener: ((Map<String, Any?>?) -> Unit)? = null
|
|
584
638
|
|
|
639
|
+
/**
|
|
640
|
+
* The bridge's data-channel subscriber (CL4, CL6): `{topic, payload
|
|
641
|
+
* (base64), text (UTF-8 or null), fromIdentity, fromName}`.
|
|
642
|
+
*/
|
|
643
|
+
@Volatile var dataListener: ((Map<String, Any?>) -> Unit)? = null
|
|
644
|
+
|
|
645
|
+
/** The most one data message may carry — the web CallRoom's CALL_DATA_MAX_BYTES. */
|
|
646
|
+
const val DATA_MAX_BYTES = 14_000
|
|
647
|
+
|
|
585
648
|
/**
|
|
586
649
|
* Configure the core and PERSIST the inputs. A ring can wake a killed
|
|
587
650
|
* app: the OS spawns the process cold to run [CallMessagingService],
|
|
@@ -819,6 +882,11 @@ interface MediaEvents {
|
|
|
819
882
|
* [onLost].
|
|
820
883
|
*/
|
|
821
884
|
fun onMovedElsewhere() {}
|
|
885
|
+
/**
|
|
886
|
+
* A data-channel message from someone in the room (CL4, CL6): its
|
|
887
|
+
* topic, the bytes, and who sent it (null identity: the server).
|
|
888
|
+
*/
|
|
889
|
+
fun onData(topic: String, payload: ByteArray, fromIdentity: String?, fromName: String?) {}
|
|
822
890
|
}
|
|
823
891
|
|
|
824
892
|
/** One place call audio can play — a snapshot `audioOutputs[]` entry. */
|
|
@@ -840,6 +908,9 @@ data class MediaParticipant(
|
|
|
840
908
|
val cameraOn: Boolean = false,
|
|
841
909
|
/** True with a published, subscribed, unmuted screen share — a screen to draw. */
|
|
842
910
|
val screenSharing: Boolean = false,
|
|
911
|
+
/** The shared screen's size in pixels as published; null while unknown or not sharing. */
|
|
912
|
+
val screenWidth: Int? = null,
|
|
913
|
+
val screenHeight: Int? = null,
|
|
843
914
|
/** The host app's own id for the user, when the SFU carries it; else the identity. */
|
|
844
915
|
val externalId: String = identity,
|
|
845
916
|
/** Their link to the SFU: `good` | `poor` | `lost` (dropped, coming back) | `unknown`. */
|
|
@@ -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. */
|
|
@@ -47,6 +47,19 @@ internal fun MachineState.toSnapshot(
|
|
|
47
47
|
put("connectionQuality", connectionQuality)
|
|
48
48
|
put("videoPaused", videoPaused)
|
|
49
49
|
put("screenSharing", screenSharing)
|
|
50
|
+
// Who shares a screen (the first remote sharer) and its size, for
|
|
51
|
+
// lining up screen drawings (CL4); null when nobody else shares.
|
|
52
|
+
put(
|
|
53
|
+
"screenShare",
|
|
54
|
+
participants.firstOrNull { it["screenSharing"] == true }?.let { p ->
|
|
55
|
+
mapOf(
|
|
56
|
+
"userId" to p["userId"],
|
|
57
|
+
"externalId" to p["externalId"],
|
|
58
|
+
"width" to p["screenWidth"],
|
|
59
|
+
"height" to p["screenHeight"],
|
|
60
|
+
)
|
|
61
|
+
},
|
|
62
|
+
)
|
|
50
63
|
put("audioOutputs", audioOutputs)
|
|
51
64
|
put("audioOutputId", audioOutputId)
|
|
52
65
|
// false: listen-only until the server lets go (docs/RECORDING.md §5).
|
|
@@ -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
|
/**
|
|
@@ -422,6 +455,11 @@ class LiveKitMediaPort(
|
|
|
422
455
|
return pub.track as? VideoTrack
|
|
423
456
|
}
|
|
424
457
|
|
|
458
|
+
/** The shared screen's size as its publisher announced it (the SFU's track info); null while unknown. */
|
|
459
|
+
private fun screenDimensions(p: Participant): Track.Dimensions? =
|
|
460
|
+
p.getTrackPublication(Track.Source.SCREEN_SHARE)?.dimensions
|
|
461
|
+
?.takeIf { it.width > 0 && it.height > 0 }
|
|
462
|
+
|
|
425
463
|
private fun reportLocalScreen(r: Room) {
|
|
426
464
|
if (room !== r) return
|
|
427
465
|
events.onLocalScreen(localScreenTrack(r) != null)
|
|
@@ -626,6 +664,12 @@ class LiveKitMediaPort(
|
|
|
626
664
|
qualityChanged(room)
|
|
627
665
|
emit(room)
|
|
628
666
|
}
|
|
667
|
+
is RoomEvent.DataReceived -> {
|
|
668
|
+
val topic = event.topic
|
|
669
|
+
if (!topic.isNullOrEmpty() && event.data.size <= CallCore.DATA_MAX_BYTES) {
|
|
670
|
+
events.onData(topic, event.data, event.participant?.identity?.value, event.participant?.name)
|
|
671
|
+
}
|
|
672
|
+
}
|
|
629
673
|
is RoomEvent.ActiveSpeakersChanged,
|
|
630
674
|
is RoomEvent.ParticipantMetadataChanged,
|
|
631
675
|
is RoomEvent.ParticipantAttributesChanged -> emit(room)
|
|
@@ -686,6 +730,7 @@ class LiveKitMediaPort(
|
|
|
686
730
|
events.onParticipants(
|
|
687
731
|
agentRows.let { agentList -> people(room).map {
|
|
688
732
|
val identity = it.identity?.value ?: ""
|
|
733
|
+
val screen = if (remoteScreen(it) != null) screenDimensions(it) else null
|
|
689
734
|
MediaParticipant(
|
|
690
735
|
identity = identity,
|
|
691
736
|
speaking = it.isSpeaking,
|
|
@@ -694,6 +739,8 @@ class LiveKitMediaPort(
|
|
|
694
739
|
// published, subscribed and unmuted.
|
|
695
740
|
cameraOn = remoteCamera(it) != null,
|
|
696
741
|
screenSharing = remoteScreen(it) != null,
|
|
742
|
+
screenWidth = screen?.width,
|
|
743
|
+
screenHeight = screen?.height,
|
|
697
744
|
connectionQuality = wire(it.connectionQuality),
|
|
698
745
|
externalId = externalIdOf(it) ?: identity,
|
|
699
746
|
)
|
|
@@ -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)
|