@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 +24 -0
- package/README.md +35 -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 +64 -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/expo/modules/poolsecalls/PoolseCallsModule.kt +33 -1
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +40 -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 +109 -1
- package/dist/index.d.ts +109 -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/Module/PoolseCallsModule.swift +23 -1
- package/ios/Platform/CallCore.swift +48 -0
- package/ios/Platform/LiveKitMediaPort.swift +50 -0
- package/package.json +1 -1
- package/src/index.ts +200 -0
|
@@ -9,7 +9,7 @@ public class PoolseCallsModule: Module {
|
|
|
9
9
|
public func definition() -> ModuleDefinition {
|
|
10
10
|
Name("PoolseCalls")
|
|
11
11
|
|
|
12
|
-
Events("onCallState", "onVoipToken", "onPictureInPicture", "onNotificationAction", "onCallAction")
|
|
12
|
+
Events("onCallState", "onVoipToken", "onPictureInPicture", "onNotificationAction", "onCallAction", "onCallData")
|
|
13
13
|
|
|
14
14
|
// Normally done at launch by PoolseCallsAppDelegateSubscriber; this is
|
|
15
15
|
// the backstop for a host whose AppDelegate does not forward to Expo.
|
|
@@ -37,6 +37,9 @@ public class PoolseCallsModule: Module {
|
|
|
37
37
|
MessageNotifications.actionListener = { [weak self] event in
|
|
38
38
|
self?.sendEvent("onNotificationAction", event)
|
|
39
39
|
}
|
|
40
|
+
CallCore.dataListener = { [weak self] message in
|
|
41
|
+
self?.sendEvent("onCallData", message)
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
|
|
@@ -47,6 +50,7 @@ public class PoolseCallsModule: Module {
|
|
|
47
50
|
CallPictureInPicture.listener = nil
|
|
48
51
|
MessageNotifications.actionListener = nil
|
|
49
52
|
MessageNotifications.callActionListener = nil
|
|
53
|
+
CallCore.dataListener = nil
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
56
|
|
|
@@ -148,6 +152,24 @@ public class PoolseCallsModule: Module {
|
|
|
148
152
|
// Recording consent accepted: mic and camera back as they were.
|
|
149
153
|
Function("republish") { onCore { $0.republish() } }
|
|
150
154
|
|
|
155
|
+
// The call's data channel (CL4, CL6): `data` is UTF-8 text, or bytes
|
|
156
|
+
// as base64 with `options.base64`. Resolves false when not connected,
|
|
157
|
+
// over 14 000 bytes, or refused.
|
|
158
|
+
AsyncFunction("publishData") { (topic: String, data: String, options: [String: Any]?, promise: Promise) in
|
|
159
|
+
let bytes = (options?["base64"] as? Bool == true) ? Data(base64Encoded: data) : data.data(using: .utf8)
|
|
160
|
+
guard let bytes = bytes, let core = CallCore.getOrNull() else { return promise.resolve(false) }
|
|
161
|
+
core.publishData(topic: topic, data: bytes, reliable: options?["reliable"] as? Bool ?? true,
|
|
162
|
+
to: options?["to"] as? [String] ?? []) { ok in promise.resolve(ok) }
|
|
163
|
+
}.runOnQueue(.main)
|
|
164
|
+
|
|
165
|
+
// Breakout rooms (MEETINGS.md §5): the live call's media to another
|
|
166
|
+
// room of the same call, keeping the CallKit call. `session` is the
|
|
167
|
+
// JSON of POST /breakouts/:room/join or /calls/:id/breakouts/return.
|
|
168
|
+
AsyncFunction("moveToRoom") { (session: String, promise: Promise) in
|
|
169
|
+
guard let core = CallCore.getOrNull() else { return promise.resolve(false) }
|
|
170
|
+
core.moveToRoom(payload: session) { ok in promise.resolve(ok) }
|
|
171
|
+
}.runOnQueue(.main)
|
|
172
|
+
|
|
151
173
|
// Picture-in-picture: armed while a video call shows someone; the
|
|
152
174
|
// <CallVideoView pictureInPicture> on screen is what it grows out of.
|
|
153
175
|
Function("setPictureInPictureEnabled") { (on: Bool) in
|
|
@@ -45,6 +45,10 @@ final class CallCore {
|
|
|
45
45
|
/// The bridge's snapshot subscriber; process-level so JS may subscribe before configure.
|
|
46
46
|
static var listener: (([String: Any]?) -> Void)?
|
|
47
47
|
|
|
48
|
+
/// The bridge's data-channel subscriber (CL4, CL6): `{topic, payload
|
|
49
|
+
/// (base64), text (UTF-8 or nil), fromIdentity, fromName}`. Main thread.
|
|
50
|
+
static var dataListener: (([String: Any]) -> Void)?
|
|
51
|
+
|
|
48
52
|
/// Configure and PERSIST (see CallCore.kt). Re-configuring swaps in place:
|
|
49
53
|
/// HTTP and the ringback read the config per use. A non-empty
|
|
50
54
|
/// `apiBaseUrl` is the `default` server; "" sets the options only and
|
|
@@ -422,6 +426,31 @@ final class CallCore {
|
|
|
422
426
|
/// The current call's id and control token (main thread).
|
|
423
427
|
var control: (callId: String, controlToken: String)? { runtime.control }
|
|
424
428
|
|
|
429
|
+
/// Breakout rooms (MEETINGS.md §5): the call's media to the room of
|
|
430
|
+
/// `payload` — the JSON of `POST /breakouts/:room/join` (or of `POST
|
|
431
|
+
/// /calls/:id/breakouts/return`). CallKit keeps the call; see
|
|
432
|
+
/// CallCoreRuntime.moveToRoom. `done(false)`: unparseable, no live
|
|
433
|
+
/// call, or another call's session.
|
|
434
|
+
func moveToRoom(payload: String, done: @escaping (Bool) -> Void) {
|
|
435
|
+
onMain { [self] in
|
|
436
|
+
guard let current = runtime.currentBundle,
|
|
437
|
+
let next = try? CallHttpClient.parseBundle(payload, current: current) else {
|
|
438
|
+
done(false)
|
|
439
|
+
return
|
|
440
|
+
}
|
|
441
|
+
runtime.moveToRoom(next) { [weak self] ok in
|
|
442
|
+
// The last room's people are not in this one.
|
|
443
|
+
if ok { self?.roster = [] }
|
|
444
|
+
done(ok)
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/// A data-channel message to the call's room (CL4, CL6); see LiveKitMediaPort.publishData.
|
|
450
|
+
func publishData(topic: String, data: Data, reliable: Bool, to: [String], done: @escaping (Bool) -> Void) {
|
|
451
|
+
onMain { [self] in mediaPort.publishData(topic: topic, data: data, reliable: reliable, to: to, done: done) }
|
|
452
|
+
}
|
|
453
|
+
|
|
425
454
|
/// A video slot for the native view. Main thread.
|
|
426
455
|
func createVideoSurface(renderMode: VideoView.RenderMode = .auto) -> LiveKitVideoSurface {
|
|
427
456
|
mediaPort.createVideoSurface(renderMode: renderMode)
|
|
@@ -504,6 +533,13 @@ final class CallCore {
|
|
|
504
533
|
out["noiseSuppression"] = mediaPort.noiseSuppression
|
|
505
534
|
out["backgroundBlur"] = mediaPort.backgroundBlur
|
|
506
535
|
out["movedElsewhere"] = movedElsewhere
|
|
536
|
+
// Breakout rooms (MEETINGS.md §5): the room the media is in, nil in the main room.
|
|
537
|
+
if let b = runtime.breakout {
|
|
538
|
+
out["breakout"] = ["roomId": b.roomId, "name": b.name ?? NSNull()] as [String: Any]
|
|
539
|
+
} else {
|
|
540
|
+
out["breakout"] = NSNull()
|
|
541
|
+
}
|
|
542
|
+
out["selfIdentity"] = mediaPort.localIdentity ?? NSNull()
|
|
507
543
|
// Taken over by another of this user's devices: the machine ends it
|
|
508
544
|
// as `left` (CALL_CONTRACT.md §9); the app is told why.
|
|
509
545
|
if movedElsewhere && state.phase == .ended { out["reason"] = "moved" }
|
|
@@ -685,6 +721,15 @@ final class CallCore {
|
|
|
685
721
|
fileprivate func movedAway() {
|
|
686
722
|
runtime.post { [weak self] in self?.movedElsewhere = true }
|
|
687
723
|
}
|
|
724
|
+
fileprivate func data(topic: String, payload: Data, from: String?, name: String?) {
|
|
725
|
+
CallCore.dataListener?([
|
|
726
|
+
"topic": topic,
|
|
727
|
+
"payload": payload.base64EncodedString(),
|
|
728
|
+
"text": String(data: payload, encoding: .utf8) ?? NSNull(),
|
|
729
|
+
"fromIdentity": from ?? NSNull(),
|
|
730
|
+
"fromName": name ?? NSNull(),
|
|
731
|
+
])
|
|
732
|
+
}
|
|
688
733
|
}
|
|
689
734
|
|
|
690
735
|
// MARK: - CallKit actions
|
|
@@ -787,6 +832,9 @@ private final class EventsAdapter: MediaEvents {
|
|
|
787
832
|
func onNetwork(quality: String, videoPaused: Bool) { core?.network(quality: quality, videoPaused: videoPaused) }
|
|
788
833
|
func onCanPublish(_ allowed: Bool) { core?.publishAllowed(allowed) }
|
|
789
834
|
func onMovedElsewhere() { core?.movedAway() }
|
|
835
|
+
func onData(topic: String, payload: Data, fromIdentity: String?, fromName: String?) {
|
|
836
|
+
core?.data(topic: topic, payload: payload, from: fromIdentity, name: fromName)
|
|
837
|
+
}
|
|
790
838
|
}
|
|
791
839
|
|
|
792
840
|
/// Host-facing entry points.
|
|
@@ -38,6 +38,9 @@ protocol MediaEvents: AnyObject {
|
|
|
38
38
|
/// The SFU replaced us with the same user joining from another device
|
|
39
39
|
/// ("move call to this device", CALL_CONTRACT.md §9). Sent just before `onLost`.
|
|
40
40
|
func onMovedElsewhere()
|
|
41
|
+
/// A data-channel message from someone in the room (CL4, CL6): its
|
|
42
|
+
/// topic, the bytes, and who sent it (nil identity: the server).
|
|
43
|
+
func onData(topic: String, payload: Data, fromIdentity: String?, fromName: String?)
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
/// Step-by-step trace of the audio path, in the device log as
|
|
@@ -379,6 +382,45 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
379
382
|
events?.onLocalScreen(false)
|
|
380
383
|
}
|
|
381
384
|
|
|
385
|
+
// MARK: - data channel (CL4, CL6)
|
|
386
|
+
|
|
387
|
+
/// The most one message may carry — the web CallRoom's
|
|
388
|
+
/// CALL_DATA_MAX_BYTES, under LiveKit's ~15 KiB packet.
|
|
389
|
+
static let dataMaxBytes = 14_000
|
|
390
|
+
|
|
391
|
+
/// Our LiveKit identity (the poolse user id) while connected.
|
|
392
|
+
var localIdentity: String? {
|
|
393
|
+
guard let r = room, connectedRoom == ObjectIdentifier(r) else { return nil }
|
|
394
|
+
return r.localParticipant.identity?.stringValue
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/// Send `data` under `topic` to everyone in the room, or to `to` (LiveKit
|
|
398
|
+
/// identities). `reliable: false` for what is stale a moment later (a
|
|
399
|
+
/// moving pointer). `done(false)`: not connected, over the cap, or LiveKit refused.
|
|
400
|
+
func publishData(topic: String, data: Data, reliable: Bool, to: [String], done: @escaping (Bool) -> Void) {
|
|
401
|
+
guard let r = room, connectedRoom == ObjectIdentifier(r), !topic.isEmpty,
|
|
402
|
+
data.count <= Self.dataMaxBytes else {
|
|
403
|
+
done(false)
|
|
404
|
+
return
|
|
405
|
+
}
|
|
406
|
+
let options = DataPublishOptions(destinationIdentities: to.map { Participant.Identity(from: $0) },
|
|
407
|
+
topic: topic, reliable: reliable)
|
|
408
|
+
Task {
|
|
409
|
+
do {
|
|
410
|
+
try await r.localParticipant.publish(data: data, options: options)
|
|
411
|
+
await MainActor.run { done(true) }
|
|
412
|
+
} catch {
|
|
413
|
+
NSLog("[PoolseCalls] data publish on %@ failed: %@", topic, "\(error)")
|
|
414
|
+
await MainActor.run { done(false) }
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
fileprivate func dataReceived(_ r: Room, topic: String, data: Data, from: String?, name: String?) {
|
|
420
|
+
guard room === r, !topic.isEmpty, data.count <= Self.dataMaxBytes else { return }
|
|
421
|
+
events?.onData(topic: topic, payload: data, fromIdentity: from, fromName: name)
|
|
422
|
+
}
|
|
423
|
+
|
|
382
424
|
// MARK: - screen sharing
|
|
383
425
|
|
|
384
426
|
/// Sharing the screen needs the app's broadcast upload extension (the
|
|
@@ -1014,6 +1056,14 @@ final class RoomObserver: NSObject, RoomDelegate, @unchecked Sendable {
|
|
|
1014
1056
|
func room(_ room: Room, participant: Participant, didUpdateMetadata metadata: String?) { send(room, .rosterChanged) }
|
|
1015
1057
|
func room(_ room: Room, participant: Participant, didUpdateAttributes attributes: [String: String]) { send(room, .rosterChanged) }
|
|
1016
1058
|
func room(_ room: Room, participant: Participant, didUpdateConnectionQuality quality: ConnectionQuality) { send(room, .quality) }
|
|
1059
|
+
func room(_ room: Room, participant: RemoteParticipant?, didReceiveData data: Data, forTopic topic: String,
|
|
1060
|
+
encryptionType: EncryptionType) {
|
|
1061
|
+
let from = participant?.identity?.stringValue
|
|
1062
|
+
let name = participant?.name
|
|
1063
|
+
DispatchQueue.main.async { [weak self] in
|
|
1064
|
+
self?.port?.dataReceived(room, topic: topic, data: data, from: from, name: name)
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1017
1067
|
// Only ever the local participant's (LiveKit's own LocalParticipant sends it).
|
|
1018
1068
|
func room(_ room: Room, participant: Participant, didUpdatePermissions permissions: ParticipantPermissions) {
|
|
1019
1069
|
if participant is LocalParticipant { send(room, .permissions) }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poolse/native",
|
|
3
|
-
"version": "3.10.
|
|
3
|
+
"version": "3.10.1",
|
|
4
4
|
"description": "Native call core for poolse — Kotlin/Swift calling engine with a thin React Native bridge. Ring, answer and carry audio with the app killed and the phone locked.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
package/src/index.ts
CHANGED
|
@@ -167,6 +167,17 @@ export interface Snapshot {
|
|
|
167
167
|
* there); the end that follows has `reason: 'moved'`. Absent before 3.10.
|
|
168
168
|
*/
|
|
169
169
|
movedElsewhere?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* The breakout room the call's media is in (`moveToRoom`,
|
|
172
|
+
* MEETINGS.md §5); null in the call's main room. `roomId` is the
|
|
173
|
+
* split's `<split id>.<n>`. Absent before 3.11.
|
|
174
|
+
*/
|
|
175
|
+
breakout?: { roomId: string; name: string | null } | null;
|
|
176
|
+
/**
|
|
177
|
+
* Your own identity in the media room — your poolse user id — once
|
|
178
|
+
* connected; what `callData.getSelfId()` answers. Absent before 3.11.
|
|
179
|
+
*/
|
|
180
|
+
selfIdentity?: string | null;
|
|
170
181
|
}
|
|
171
182
|
|
|
172
183
|
/** The CallSummary's `recording` object, as the server sent it (docs/CALL_CONTRACT.md §4.2). */
|
|
@@ -428,6 +439,12 @@ interface PoolseCallsNative {
|
|
|
428
439
|
setBackgroundBlur?(on: boolean): boolean;
|
|
429
440
|
setAudioOutput?(id: string): void;
|
|
430
441
|
republish?(): void;
|
|
442
|
+
publishData?(
|
|
443
|
+
topic: string,
|
|
444
|
+
data: string,
|
|
445
|
+
options: { reliable?: boolean; base64?: boolean; to?: string[] } | null,
|
|
446
|
+
): Promise<boolean>;
|
|
447
|
+
moveToRoom?(session: string): Promise<boolean>;
|
|
431
448
|
callControl?(): Promise<{
|
|
432
449
|
callId: string;
|
|
433
450
|
controlToken: string;
|
|
@@ -458,6 +475,7 @@ interface PoolseCallsNative {
|
|
|
458
475
|
event: 'onPictureInPicture',
|
|
459
476
|
cb: (payload: { active: boolean }) => void,
|
|
460
477
|
): { remove(): void };
|
|
478
|
+
addListener(event: 'onCallData', cb: (payload: CallDataMessage) => void): { remove(): void };
|
|
461
479
|
}
|
|
462
480
|
|
|
463
481
|
const native = requireOptionalNativeModule<PoolseCallsNative>('PoolseCalls');
|
|
@@ -1029,6 +1047,188 @@ export function onPictureInPicture(cb: (active: boolean) => void): Unsubscribe {
|
|
|
1029
1047
|
return () => sub.remove();
|
|
1030
1048
|
}
|
|
1031
1049
|
|
|
1050
|
+
// ── data channel (CL4, CL6) ───────────────────────────────────────────
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* The most one data-channel message may carry, in bytes — the same cap
|
|
1054
|
+
* as the web SDK's `CALL_DATA_MAX_BYTES`, under LiveKit's ~15 KiB packet.
|
|
1055
|
+
*/
|
|
1056
|
+
export const CALL_DATA_MAX_BYTES = 14_000;
|
|
1057
|
+
|
|
1058
|
+
/** One message from someone in the call's room. */
|
|
1059
|
+
export interface CallDataMessage {
|
|
1060
|
+
topic: string;
|
|
1061
|
+
/** The bytes, base64. */
|
|
1062
|
+
payload: string;
|
|
1063
|
+
/** The bytes as UTF-8 text; null when they are not text. */
|
|
1064
|
+
text: string | null;
|
|
1065
|
+
/** Who sent it (their poolse user id); null when the server did. */
|
|
1066
|
+
fromIdentity: string | null;
|
|
1067
|
+
fromName: string | null;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
export interface PublishDataOptions {
|
|
1071
|
+
/** Default true. `false` for what is stale a moment later (a moving pointer). */
|
|
1072
|
+
reliable?: boolean;
|
|
1073
|
+
/** `data` is base64 bytes rather than text. */
|
|
1074
|
+
base64?: boolean;
|
|
1075
|
+
/** Only these people (poolse user ids); everyone in the room when left out. */
|
|
1076
|
+
to?: string[];
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
/** UTF-8 length of `s`, without TextEncoder (not on every Hermes). */
|
|
1080
|
+
function utf8Length(s: string): number {
|
|
1081
|
+
let n = 0;
|
|
1082
|
+
for (let i = 0; i < s.length; i++) {
|
|
1083
|
+
const c = s.charCodeAt(i);
|
|
1084
|
+
if (c < 0x80) n += 1;
|
|
1085
|
+
else if (c < 0x800) n += 2;
|
|
1086
|
+
else if (c >= 0xd800 && c <= 0xdbff && i + 1 < s.length) {
|
|
1087
|
+
n += 4;
|
|
1088
|
+
i++;
|
|
1089
|
+
} else n += 3;
|
|
1090
|
+
}
|
|
1091
|
+
return n;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/**
|
|
1095
|
+
* Send `data` under `topic` to everyone in the call's room over LiveKit's
|
|
1096
|
+
* data channel, through the SFU, never stored (CL4, CL6). Web, desktop
|
|
1097
|
+
* and phones share topics and formats: `poolse.reaction`,
|
|
1098
|
+
* `poolse.annotate` (see {@link callData} for JSON). Resolves false with
|
|
1099
|
+
* no call connected, over {@link CALL_DATA_MAX_BYTES}, or on a build
|
|
1100
|
+
* without it.
|
|
1101
|
+
*/
|
|
1102
|
+
export async function publishData(
|
|
1103
|
+
topic: string,
|
|
1104
|
+
data: string,
|
|
1105
|
+
options: PublishDataOptions = {},
|
|
1106
|
+
): Promise<boolean> {
|
|
1107
|
+
if (!native?.publishData || !topic) return false;
|
|
1108
|
+
const size = options.base64 ? Math.floor((data.length * 3) / 4) : utf8Length(data);
|
|
1109
|
+
if (size > CALL_DATA_MAX_BYTES) return false;
|
|
1110
|
+
try {
|
|
1111
|
+
return await native.publishData(topic, data, {
|
|
1112
|
+
reliable: options.reliable ?? true,
|
|
1113
|
+
base64: options.base64 ?? false,
|
|
1114
|
+
...(options.to ? { to: options.to } : {}),
|
|
1115
|
+
});
|
|
1116
|
+
} catch {
|
|
1117
|
+
return false;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/** Every data-channel message others send in the call's room (yours are not echoed). */
|
|
1122
|
+
export function onCallData(cb: (message: CallDataMessage) => void): Unsubscribe {
|
|
1123
|
+
if (!native?.publishData) return () => undefined;
|
|
1124
|
+
const sub = native.addListener('onCallData', cb);
|
|
1125
|
+
return () => sub.remove();
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
type DataListener = (
|
|
1129
|
+
message: unknown,
|
|
1130
|
+
from: { userId: string | null; name: string | null },
|
|
1131
|
+
) => void;
|
|
1132
|
+
const dataListeners = new Map<string, Set<DataListener>>();
|
|
1133
|
+
let dataSub: Unsubscribe | null = null;
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* The native call's data channel in the shape @poolse/sdk's
|
|
1137
|
+
* `CallDataChannel` takes — JSON messages by topic — so the SDK's
|
|
1138
|
+
* `CallReactions` and `ScreenAnnotations` (and @poolse/react's
|
|
1139
|
+
* `useCallReactions` / `useScreenAnnotations`) run on phones exactly as
|
|
1140
|
+
* on the web and desktop, and interoperate with them:
|
|
1141
|
+
*
|
|
1142
|
+
* import { callData } from '@poolse/native';
|
|
1143
|
+
* const { reactions, send } = useCallReactions(callData);
|
|
1144
|
+
* const { state } = useScreenAnnotations(callData, sharerUserId);
|
|
1145
|
+
* <AnnotationOverlay state={state} />
|
|
1146
|
+
*
|
|
1147
|
+
* One process-wide object; it follows whichever call is live.
|
|
1148
|
+
*/
|
|
1149
|
+
export const callData = {
|
|
1150
|
+
getSelfId(): string | null {
|
|
1151
|
+
return getCallState()?.selfIdentity ?? null;
|
|
1152
|
+
},
|
|
1153
|
+
sendData(
|
|
1154
|
+
topic: string,
|
|
1155
|
+
message: unknown,
|
|
1156
|
+
opts: { reliable?: boolean; to?: string[] } = {},
|
|
1157
|
+
): Promise<boolean> {
|
|
1158
|
+
let text: string;
|
|
1159
|
+
try {
|
|
1160
|
+
text = JSON.stringify(message);
|
|
1161
|
+
} catch {
|
|
1162
|
+
return Promise.resolve(false);
|
|
1163
|
+
}
|
|
1164
|
+
return publishData(topic, text, opts);
|
|
1165
|
+
},
|
|
1166
|
+
onData(topic: string, fn: DataListener): Unsubscribe {
|
|
1167
|
+
let set = dataListeners.get(topic);
|
|
1168
|
+
if (!set) {
|
|
1169
|
+
set = new Set();
|
|
1170
|
+
dataListeners.set(topic, set);
|
|
1171
|
+
}
|
|
1172
|
+
set.add(fn);
|
|
1173
|
+
dataSub ??= onCallData((m) => {
|
|
1174
|
+
const listeners = dataListeners.get(m.topic);
|
|
1175
|
+
if (!listeners?.size || m.text == null) return;
|
|
1176
|
+
let parsed: unknown;
|
|
1177
|
+
try {
|
|
1178
|
+
parsed = JSON.parse(m.text);
|
|
1179
|
+
} catch {
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
const from = { userId: m.fromIdentity, name: m.fromName };
|
|
1183
|
+
for (const l of [...listeners]) l(parsed, from);
|
|
1184
|
+
});
|
|
1185
|
+
return () => {
|
|
1186
|
+
set.delete(fn);
|
|
1187
|
+
if (set.size === 0) dataListeners.delete(topic);
|
|
1188
|
+
if (dataListeners.size === 0 && dataSub) {
|
|
1189
|
+
dataSub();
|
|
1190
|
+
dataSub = null;
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1193
|
+
},
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
// ── breakout rooms (CL5) ──────────────────────────────────────────────
|
|
1197
|
+
|
|
1198
|
+
/**
|
|
1199
|
+
* What {@link moveToRoom} takes: the session bundle `POST
|
|
1200
|
+
* /v1/breakouts/:room/join` or `POST /v1/calls/:id/breakouts/return`
|
|
1201
|
+
* answers with (@poolse/sdk's `meetingsLive.breakouts.join` /
|
|
1202
|
+
* `returnToMain`), or its JSON text.
|
|
1203
|
+
*/
|
|
1204
|
+
export interface RoomSessionBundle {
|
|
1205
|
+
call: { id: string };
|
|
1206
|
+
livekit: { url: string; token: string };
|
|
1207
|
+
control_token: string;
|
|
1208
|
+
breakout?: { room_id: string; name: string | null } | null;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
/**
|
|
1212
|
+
* Breakout rooms (MEETINGS.md §5): move the call you are on into another
|
|
1213
|
+
* of its rooms — your breakout room, or back to the main room — without
|
|
1214
|
+
* hanging up. CallKit / the Android call service keep the call; only
|
|
1215
|
+
* the media swaps rooms, mute and camera as they were, and
|
|
1216
|
+
* `snapshot.breakout` says where you are. If the new room can't be
|
|
1217
|
+
* joined, the media goes back to the room it came from.
|
|
1218
|
+
*
|
|
1219
|
+
* Resolves false with no call connected (or still connecting), for
|
|
1220
|
+
* another call's session, or on a build without it. @poolse/react-native's
|
|
1221
|
+
* `useNativeBreakouts` does this for you as the split opens and closes.
|
|
1222
|
+
*/
|
|
1223
|
+
export async function moveToRoom(session: RoomSessionBundle | string): Promise<boolean> {
|
|
1224
|
+
if (!native?.moveToRoom) return false;
|
|
1225
|
+
try {
|
|
1226
|
+
return await native.moveToRoom(typeof session === 'string' ? session : JSON.stringify(session));
|
|
1227
|
+
} catch {
|
|
1228
|
+
return false;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1032
1232
|
// ── video ─────────────────────────────────────────────────────────────
|
|
1033
1233
|
|
|
1034
1234
|
export interface CallVideoViewProps extends ViewProps {
|