@poolse/native 3.9.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +129 -9
  3. package/android/src/main/AndroidManifest.xml +4 -0
  4. package/android/src/main/java/dev/poolse/callcore/CallCoreRuntime.kt +83 -6
  5. package/android/src/main/java/dev/poolse/callcore/Ports.kt +28 -1
  6. package/android/src/main/java/dev/poolse/callcore/android/AndroidRingSurface.kt +3 -3
  7. package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +155 -10
  8. package/android/src/main/java/dev/poolse/callcore/android/CallHttpClient.kt +7 -1
  9. package/android/src/main/java/dev/poolse/callcore/android/CallMessagingService.kt +21 -1
  10. package/android/src/main/java/dev/poolse/callcore/android/CallVideo.kt +32 -0
  11. package/android/src/main/java/dev/poolse/callcore/android/EscalationNotification.kt +475 -0
  12. package/android/src/main/java/dev/poolse/callcore/android/IncomingCallActivity.kt +9 -4
  13. package/android/src/main/java/dev/poolse/callcore/android/MeetingNotification.kt +127 -0
  14. package/android/src/main/java/dev/poolse/callcore/android/PoolseIncomingCall.kt +9 -0
  15. package/android/src/main/java/dev/poolse/callcore/android/RingBundle.kt +9 -0
  16. package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +48 -2
  17. package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +121 -6
  18. package/android/src/test/java/dev/poolse/callcore/android/CallHttpClientTest.kt +15 -0
  19. package/dist/index.cjs +108 -0
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +241 -23
  22. package/dist/index.d.ts +241 -23
  23. package/dist/index.js +98 -1
  24. package/dist/index.js.map +1 -1
  25. package/ios/Core/CallCoreRuntime.swift +79 -5
  26. package/ios/Core/CallHttpClient.swift +9 -2
  27. package/ios/Core/Ports.swift +31 -2
  28. package/ios/Core/SnapshotEncoding.swift +22 -3
  29. package/ios/Module/PoolseCallsModule.swift +48 -1
  30. package/ios/Platform/CallCore.swift +100 -1
  31. package/ios/Platform/CallKitController.swift +1 -1
  32. package/ios/Platform/EscalationNotifications.swift +195 -0
  33. package/ios/Platform/LiveKitMediaPort.swift +127 -3
  34. package/ios/Platform/MessageNotifications.swift +60 -1
  35. package/ios/Platform/VoipPush.swift +11 -2
  36. package/package.json +1 -1
  37. package/src/index.ts +354 -23
@@ -38,6 +38,16 @@ final class MessageNotifications: NSObject, NotificationDelegate {
38
38
  static let category = "poolse_message"
39
39
  static let replyAction = "reply"
40
40
  static let markReadAction = "mark_read"
41
+ /// Scheduled-meeting notices (server docs/MEETINGS.md §11.3): an alert push
42
+ /// with this category; "starting" offers Join.
43
+ static let meetingCategory = "poolse_meeting"
44
+ static let meetingJoinAction = "poolse_meeting_join"
45
+
46
+ /// The bridge's subscriber for meeting taps / Join (`onCallAction`); main thread.
47
+ static var callActionListener: (([String: Any]) -> Void)?
48
+ /// The last one nobody was listening for — the cold start that a Join
49
+ /// launched; `takeCallAction` reads it once. Main thread.
50
+ static var pendingCallAction: [String: Any]?
41
51
 
42
52
  /// The bridge's subscriber for finished notification actions; main thread.
43
53
  static var actionListener: (([String: Any]) -> Void)?
@@ -79,10 +89,23 @@ final class MessageNotifications: NSObject, NotificationDelegate {
79
89
  categorySummaryFormat: "%u more messages from %@",
80
90
  options: []
81
91
  )
92
+ // Join opens the app: joining needs the user's session, which only it has.
93
+ let join = UNNotificationAction(identifier: Self.meetingJoinAction, title: "Join", options: [.foreground])
94
+ let meeting = UNNotificationCategory(
95
+ identifier: Self.meetingCategory,
96
+ actions: [join],
97
+ intentIdentifiers: [],
98
+ options: []
99
+ )
100
+ // An agent's question (AGENTS_IN_CALLS.md §5): Approve / Decline / Answer.
101
+ let escalation = EscalationNotifications.makeCategory(requireUnlock: requireUnlock)
102
+ let ours: Set<String> = [Self.category, Self.meetingCategory, EscalationNotifications.category]
82
103
  let center = UNUserNotificationCenter.current()
83
104
  center.getNotificationCategories { existing in
84
- var all = existing.filter { $0.identifier != Self.category }
105
+ var all = existing.filter { !ours.contains($0.identifier) }
85
106
  all.insert(category)
107
+ all.insert(meeting)
108
+ all.insert(escalation)
86
109
  center.setNotificationCategories(all)
87
110
  }
88
111
  }
@@ -91,6 +114,10 @@ final class MessageNotifications: NSObject, NotificationDelegate {
91
114
 
92
115
  func didReceive(_ response: UNNotificationResponse, completionHandler: @escaping () -> Void) -> Bool {
93
116
  let content = response.notification.request.content
117
+ if content.categoryIdentifier == Self.meetingCategory { return meetingResponse(response) }
118
+ if content.categoryIdentifier == EscalationNotifications.category {
119
+ return EscalationNotifications.didReceive(response)
120
+ }
94
121
  guard content.categoryIdentifier == Self.category else { return false }
95
122
  let action = response.actionIdentifier
96
123
  guard action == Self.replyAction || action == Self.markReadAction else {
@@ -175,6 +202,38 @@ final class MessageNotifications: NSObject, NotificationDelegate {
175
202
  return true
176
203
  }
177
204
 
205
+ /// A meeting notice's tap (`open`) or Join (`join_meeting`), handed to JS
206
+ /// as a CallAction — the shape Android's notification produces.
207
+ private func meetingResponse(_ response: UNNotificationResponse) -> Bool {
208
+ let content = response.notification.request.content
209
+ let info = content.userInfo
210
+ func str(_ key: String) -> String? { (info[key] as? String).flatMap(nilIfEmpty) }
211
+ let action: String
212
+ switch response.actionIdentifier {
213
+ case Self.meetingJoinAction: action = "join_meeting"
214
+ case UNNotificationDefaultActionIdentifier: action = "open"
215
+ default: return true // dismissed
216
+ }
217
+ guard let conversationId = str("conversation_id") else { return true }
218
+ let server = ServerRegistry.shared.servers.resolve(tenantId: str("tenant_id"))
219
+ let event: [String: Any] = [
220
+ "type": action,
221
+ "conversationId": conversationId,
222
+ "callId": str("call_id") ?? NSNull(),
223
+ "media": str("media") == "video" ? "video" : "audio",
224
+ "serverId": server?.id ?? NSNull(),
225
+ "scheduledMeetingId": str("scheduled_meeting_id") ?? NSNull(),
226
+ ]
227
+ DispatchQueue.main.async {
228
+ if let listener = Self.callActionListener {
229
+ listener(event)
230
+ } else {
231
+ Self.pendingCallAction = event
232
+ }
233
+ }
234
+ return true
235
+ }
236
+
178
237
  /// A background push: the conversation was read on another device.
179
238
  func didReceive(_ userInfo: [AnyHashable: Any],
180
239
  completionHandler: @escaping (UIBackgroundFetchResult) -> Void) -> Bool {
@@ -143,7 +143,12 @@ struct VoipPayload {
143
143
  var callId: String? { string("call_id") }
144
144
  var event: String? { string("event") }
145
145
  var reason: String? { string("reason") }
146
- var title: String? { string("conversation_name") ?? string("caller_name") }
146
+ var title: String? {
147
+ if string("ring_type") == "meeting" {
148
+ return "\(string("meeting_title") ?? string("conversation_name") ?? "Meeting") is starting"
149
+ }
150
+ return string("conversation_name") ?? string("caller_name")
151
+ }
147
152
 
148
153
  var media: String {
149
154
  if let m = string("media")?.lowercased(), m == "video" || m == "audio" { return m }
@@ -172,7 +177,11 @@ struct VoipPayload {
172
177
  // Signed in to several workspaces: the ring is answered (and
173
178
  // declined) on the server of its tenant.
174
179
  serverId: ServerRegistry.shared.servers.resolve(tenantId: string("tenant_id"))?.id,
175
- workspaceName: string("workspace_name")
180
+ workspaceName: string("workspace_name"),
181
+ // A scheduled meeting starting (CA4): "Weekly sync is starting".
182
+ ringType: string("ring_type"),
183
+ meetingTitle: string("meeting_title"),
184
+ meetingId: string("meeting_id")
176
185
  )
177
186
  }
178
187
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poolse/native",
3
- "version": "3.9.0",
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
@@ -37,12 +37,19 @@ export interface Snapshot {
37
37
  | 'no_answer'
38
38
  | 'cancelled'
39
39
  | 'connection_lost'
40
- | 'failed';
40
+ | 'failed'
41
+ /**
42
+ * You took this call on another of your devices (`moveCallHere`
43
+ * there): it goes on without this one. Say "Moved to your other
44
+ * device", not "Call ended". Absent before 3.10.
45
+ */
46
+ | 'moved';
41
47
  /**
42
48
  * REMOTE people only; `userId` is the LiveKit identity. poolse's
43
49
  * transcript assistant (`poolse:…`, kind agent) and the recorder
44
50
  * (LiveKit Egress, `EG_…`) are never listed — nor counted when the core
45
- * ends a call left alone. Phone (SIP) participants are listed.
51
+ * ends a call left alone. Phone (SIP) participants are listed. Agents
52
+ * invited into the call are listed with `isAgent` (last), never counted.
46
53
  */
47
54
  participants: Array<{
48
55
  userId: string;
@@ -62,6 +69,16 @@ export interface Snapshot {
62
69
  * Absent before 0.11.0.
63
70
  */
64
71
  connectionQuality?: ConnectionQuality;
72
+ /**
73
+ * An agent in the call (server docs/AGENTS_IN_CALLS.md): show it with
74
+ * the Agent badge, named `agentLabel` — never as a person, never with
75
+ * a camera placeholder. Absent for people and before 3.10.
76
+ */
77
+ isAgent?: boolean;
78
+ /** "Scout", or "Jasir's agent" for one attending on someone's behalf. */
79
+ agentLabel?: string | null;
80
+ /** `notetaker` (silent) | `assistant` (answers when named) | `delegate`. */
81
+ agentMode?: 'notetaker' | 'assistant' | 'delegate' | null;
65
82
  }>;
66
83
  /** The kind of output playing now — the short answer to "where is the audio". */
67
84
  audioRoute: AudioOutputKind;
@@ -132,6 +149,35 @@ export interface Snapshot {
132
149
  recording?: CallRecordingState | null;
133
150
  /** The live transcript's state, the same way (`transcript:*` on the socket). Absent before 3.9. */
134
151
  transcription?: CallTranscriptionState | null;
152
+ /**
153
+ * `meeting`: a scheduled meeting rang this device as it started (the
154
+ * push's `ring_type`), so the ring reads "Weekly sync is starting" and
155
+ * the call screen should name the meeting. `call` otherwise. Absent
156
+ * before 3.10.
157
+ */
158
+ ringType?: 'call' | 'meeting';
159
+ /** The meeting's title for a `meeting` ring; null otherwise. Absent before 3.10. */
160
+ meetingTitle?: string | null;
161
+ /** Noise suppression on the microphone (on by default; `setNoiseSuppression`). Absent before 3.10. */
162
+ noiseSuppression?: boolean;
163
+ /** Background blur on the camera (`setBackgroundBlur`). Absent before 3.10. */
164
+ backgroundBlur?: boolean;
165
+ /**
166
+ * This call was taken over by your other device (`moveCallHere`
167
+ * there); the end that follows has `reason: 'moved'`. Absent before 3.10.
168
+ */
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;
135
181
  }
136
182
 
137
183
  /** The CallSummary's `recording` object, as the server sent it (docs/CALL_CONTRACT.md §4.2). */
@@ -175,6 +221,10 @@ export interface WaitingCall {
175
221
  serverId?: string | null;
176
222
  /** That workspace's name ("Ana · Acme"). Absent before 3.8. */
177
223
  workspaceName?: string | null;
224
+ /** `meeting` when a scheduled meeting is starting rather than a person calling. Absent before 3.10. */
225
+ ringType?: 'call' | 'meeting';
226
+ /** The meeting's title for a `meeting` ring. Absent before 3.10. */
227
+ meetingTitle?: string | null;
178
228
  }
179
229
 
180
230
  /** One place call audio can play. */
@@ -289,34 +339,47 @@ export interface CallServer {
289
339
  }
290
340
 
291
341
  /**
292
- * What the user tapped on a missed-call notification: the notification
293
- * itself (`open` the conversation) or its Call back button (`call_back`
294
- * — place a call on the conversation with `media`).
342
+ * What the user tapped on a missed-call or meeting notification: the
343
+ * notification itself (`open` the conversation), a missed call's Call
344
+ * back (`call_back` — place a call on the conversation with `media`), or
345
+ * a starting meeting's Join (`join_meeting` — join the room `callId` in
346
+ * the conversation, e.g. `poolse.rooms.start(conversationId, media)`,
347
+ * which joins what is live).
295
348
  */
296
349
  export interface CallAction {
297
- type: 'open' | 'call_back';
350
+ type: 'open' | 'call_back' | 'join_meeting';
298
351
  conversationId: string;
299
352
  callId: string | null;
300
353
  media: 'audio' | 'video';
301
354
  /** The server (workspace) it belongs to — open that one. Absent before 3.8. */
302
355
  serverId?: string | null;
356
+ /** A meeting notice's scheduled meeting; null for missed calls. Absent before 3.10. */
357
+ scheduledMeetingId?: string | null;
303
358
  }
304
359
 
305
360
  /**
306
- * A Reply or Mark as read the user did from a chat notification, after
307
- * the native core sent it (or gave up). The server has already posted
308
- * the reply and marked the conversation read; use this to refresh what
309
- * the app shows (insert the message, drop the unread count) without
310
- * waiting for the socket, or to tell the user a reply did not go out.
361
+ * A Reply or Mark as read the user did from a chat notification — or an
362
+ * answer to an agent's question (`escalation`: Approve / Decline / Answer
363
+ * on an `agent_escalation` push) — after the native core sent it (or gave
364
+ * up). The server has already posted the reply and marked the
365
+ * conversation read, or passed the answer to the agent in the call; use
366
+ * this to refresh what the app shows without waiting for the socket, or
367
+ * to tell the user it did not go out.
311
368
  */
312
369
  export interface NotificationActionResult {
313
- action: 'reply' | 'mark_read';
370
+ action: 'reply' | 'mark_read' | 'escalation';
371
+ /** The conversation (for `escalation`: the call's; `""` when the push had none). */
314
372
  conversationId: string;
373
+ /** `escalation` only: which question, and how it was answered. Absent before 3.10. */
374
+ escalationId?: string;
375
+ decision?: 'approve' | 'decline' | 'answer';
376
+ /** `escalation` only: the call the agent is in. */
377
+ callId?: string | null;
315
378
  /** The server (workspace) the conversation is on. Absent before 3.8. */
316
379
  serverId?: string;
317
380
  /** Whether the server accepted it. */
318
381
  ok: boolean;
319
- /** Reply only: what the user typed. */
382
+ /** Reply (and an escalation's `answer`): what the user typed. */
320
383
  text?: string;
321
384
  /** Reply only: the idempotency id sent with it — the message's id once posted. */
322
385
  clientId?: string;
@@ -327,7 +390,8 @@ export interface NotificationActionResult {
327
390
  * `device_signed_out`, `user_blocked`, `forbidden`, `not_found`,
328
391
  * `mau_cap_exceeded`, `validation_failed`, `rate_limited`), or
329
392
  * `network`, `no_grant` (the push carried no reply grant),
330
- * `not_configured` (never `configure`d), `http_<status>`.
393
+ * `not_configured` (never `configure`d), `http_<status>`. An
394
+ * escalation: `not_pending`, `expired`, `invalid_token`, `no_token`.
331
395
  */
332
396
  error?: string;
333
397
  /** The HTTP status when the server answered with an error. */
@@ -369,8 +433,18 @@ interface PoolseCallsNative {
369
433
  startScreenShare?(): Promise<boolean>;
370
434
  stopScreenShare?(): void;
371
435
  setSpeaker(on: boolean): void;
436
+ noiseSuppressionSupported?(): boolean;
437
+ setNoiseSuppression?(on: boolean): boolean;
438
+ backgroundBlurSupported?(): boolean;
439
+ setBackgroundBlur?(on: boolean): boolean;
372
440
  setAudioOutput?(id: string): void;
373
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>;
374
448
  callControl?(): Promise<{
375
449
  callId: string;
376
450
  controlToken: string;
@@ -401,6 +475,7 @@ interface PoolseCallsNative {
401
475
  event: 'onPictureInPicture',
402
476
  cb: (payload: { active: boolean }) => void,
403
477
  ): { remove(): void };
478
+ addListener(event: 'onCallData', cb: (payload: CallDataMessage) => void): { remove(): void };
404
479
  }
405
480
 
406
481
  const native = requireOptionalNativeModule<PoolseCallsNative>('PoolseCalls');
@@ -526,6 +601,29 @@ export function join(
526
601
  return native?.join(callId, conversationId, sessionToken, serverId ?? null) ?? Promise.resolve();
527
602
  }
528
603
 
604
+ /** What {@link moveCallHere} needs besides the call id. */
605
+ export interface MoveCallOptions {
606
+ conversationId: string;
607
+ /** The user's session token on the call's server. */
608
+ sessionToken: string;
609
+ /** The call's server (an `addServer` id); leave it out for the default one. */
610
+ serverId?: string;
611
+ }
612
+
613
+ /**
614
+ * "Move call to this device" (CL11): take a call you are on elsewhere
615
+ * — your desktop, your other phone — over to this one without hanging
616
+ * up. This device joins the same call; the server lets one device per
617
+ * person carry it (CALL_CONTRACT.md §9), so the other one is let go and
618
+ * its snapshot ends with `reason: 'moved'`. Offer it from the Join
619
+ * banner when `liveCalls` says you are already in the call.
620
+ *
621
+ * The camera follows the call's media on this device; mute starts off.
622
+ */
623
+ export function moveCallHere(callId: string, options: MoveCallOptions): Promise<void> {
624
+ return join(callId, options.conversationId, options.sessionToken, options.serverId);
625
+ }
626
+
529
627
  export interface StartRoomResult {
530
628
  /** The room's call id — what the Join banner and `call:*` events carry. */
531
629
  callId: string;
@@ -656,6 +754,41 @@ export const startScreenShare = async (): Promise<boolean> =>
656
754
  (await native?.startScreenShare?.()) ?? false;
657
755
 
658
756
  export const stopScreenShare = (): void => native?.stopScreenShare?.();
757
+ // ── capture processing (CL7) ──────────────────────────────────────────
758
+
759
+ /**
760
+ * Whether noise suppression can be switched. On by default on both
761
+ * platforms; the snapshot's `noiseSuppression` says what is in effect.
762
+ */
763
+ export const noiseSuppressionSupported = (): boolean =>
764
+ native?.noiseSuppressionSupported?.() ?? false;
765
+
766
+ /**
767
+ * Noise suppression on or off, for this and later calls (until the app
768
+ * restarts). Android: WebRTC's noise suppression on the microphone
769
+ * (echo cancellation stays on; the mic track is republished, a short
770
+ * gap). iOS: Apple's voice processing does echo cancellation and noise
771
+ * suppression as one, so off bypasses both — offer "off" for
772
+ * headphones only. Returns false when the build can't.
773
+ */
774
+ export const setNoiseSuppression = (on: boolean): boolean =>
775
+ native?.setNoiseSuppression?.(on) ?? false;
776
+
777
+ /**
778
+ * Whether this build can blur the background behind you. iOS 15+: yes
779
+ * (Vision person segmentation). Android: not yet — it needs an ML Kit
780
+ * segmentation model, planned as a later addition. Hide the toggle when
781
+ * false.
782
+ */
783
+ export const backgroundBlurSupported = (): boolean => native?.backgroundBlurSupported?.() ?? false;
784
+
785
+ /**
786
+ * Blur the background on your camera, kept across camera flips and
787
+ * calls. A no-op returning false where unsupported. Background
788
+ * pictures (replacement) are not offered on native yet.
789
+ */
790
+ export const setBackgroundBlur = (on: boolean): boolean => native?.setBackgroundBlur?.(on) ?? false;
791
+
659
792
  /** Route call audio to the loudspeaker (`true`) or back to earpiece / headset (`false`). */
660
793
  export const setSpeaker = (on: boolean): void => native?.setSpeaker(on);
661
794
 
@@ -738,24 +871,28 @@ export function setShowOnLockscreen(enabled: boolean): void {
738
871
  }
739
872
  }
740
873
 
741
- // ── missed-call notifications (Android) ─────────────────────────────────
874
+ // ── missed-call and meeting notifications ───────────────────────────────
742
875
 
743
876
  /**
744
- * Android: the missed-call notification action the app was LAUNCHED
745
- * with, once — read it on mount. `null` when the app opened any other
746
- * way. The native core posts that notification itself from the push,
747
- * so it works with the app closed.
877
+ * The notification action the app was LAUNCHED with, once — read it on
878
+ * mount. `null` when the app opened any other way.
748
879
  *
749
- * iOS shows missed calls as an ordinary alert push (to the token you
750
- * register with `kind: 'alert'`); read its taps with your notification
751
- * library — its `type` is `call_missed`, the category
880
+ * Android: missed calls and meeting notices (`starting` with Join, and
881
+ * the brief; server docs/MEETINGS.md §11.3), both posted by the native
882
+ * core from the push so they work with the app closed.
883
+ *
884
+ * iOS: meeting notices (the alert push's category `poolse_meeting`, Join
885
+ * `poolse_meeting_join`), whose tap and Join arrive here as `open` /
886
+ * `join_meeting`. Missed calls there are an ordinary alert push (to the
887
+ * token you register with `kind: 'alert'`); read its taps with your
888
+ * notification library — its `type` is `call_missed`, the category
752
889
  * `poolse_missed_call`, the Call back action `call_back`.
753
890
  */
754
891
  export function takeCallAction(): CallAction | null {
755
892
  return native?.takeCallAction?.() ?? null;
756
893
  }
757
894
 
758
- /** Android: a missed-call notification tapped while the app is running. */
895
+ /** A missed-call (Android) or meeting notification (both) tapped while the app is running. */
759
896
  export function onCallAction(cb: (action: CallAction) => void): Unsubscribe {
760
897
  if (!native || !native.takeCallAction) return () => undefined;
761
898
  const sub = native.addListener('onCallAction', cb);
@@ -838,6 +975,18 @@ export function onNotificationReply(cb: (result: NotificationActionResult) => vo
838
975
  });
839
976
  }
840
977
 
978
+ /**
979
+ * `onNotificationAction`, agent escalations only (AG16): Approve / Decline
980
+ * / Answer on an `agent_escalation` push, answered natively from the lock
981
+ * screen. Feed `ok` ones to `poolse.escalations.list()` (or let
982
+ * `agent:escalation` do it) so an open card updates.
983
+ */
984
+ export function onEscalationAction(cb: (result: NotificationActionResult) => void): Unsubscribe {
985
+ return onNotificationAction((result) => {
986
+ if (result.action === 'escalation') cb(result);
987
+ });
988
+ }
989
+
841
990
  /**
842
991
  * The notification actions that finished while no `onNotificationAction`
843
992
  * listener was attached (usually: the app was not running), oldest
@@ -898,6 +1047,188 @@ export function onPictureInPicture(cb: (active: boolean) => void): Unsubscribe {
898
1047
  return () => sub.remove();
899
1048
  }
900
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
+
901
1232
  // ── video ─────────────────────────────────────────────────────────────
902
1233
 
903
1234
  export interface CallVideoViewProps extends ViewProps {