@poolse/native 3.8.0 → 3.10.0

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 +55 -0
  2. package/README.md +127 -9
  3. package/android/src/main/AndroidManifest.xml +4 -0
  4. package/android/src/main/java/dev/poolse/callcore/CallCoreRuntime.kt +8 -0
  5. package/android/src/main/java/dev/poolse/callcore/Ports.kt +47 -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 +112 -10
  8. package/android/src/main/java/dev/poolse/callcore/android/CallHttpClient.kt +3 -0
  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 +14 -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/dev/poolse/callcore/android/SnapshotJson.kt +23 -0
  17. package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +17 -1
  18. package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +174 -11
  19. package/dist/index.cjs +33 -0
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +197 -23
  22. package/dist/index.d.ts +197 -23
  23. package/dist/index.js +26 -1
  24. package/dist/index.js.map +1 -1
  25. package/ios/Core/CallCoreRuntime.swift +8 -0
  26. package/ios/Core/CallHttpClient.swift +11 -1
  27. package/ios/Core/Ports.swift +47 -2
  28. package/ios/Core/SnapshotEncoding.swift +39 -4
  29. package/ios/Module/PoolseCallsModule.swift +28 -1
  30. package/ios/Platform/CallCore.swift +68 -2
  31. package/ios/Platform/CallKitController.swift +1 -1
  32. package/ios/Platform/EscalationNotifications.swift +195 -0
  33. package/ios/Platform/LiveKitMediaPort.swift +178 -15
  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 +231 -23
package/src/index.ts CHANGED
@@ -37,8 +37,20 @@ export interface Snapshot {
37
37
  | 'no_answer'
38
38
  | 'cancelled'
39
39
  | 'connection_lost'
40
- | 'failed';
41
- /** REMOTE participants only; `userId` is the LiveKit identity. */
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';
47
+ /**
48
+ * REMOTE people only; `userId` is the LiveKit identity. poolse's
49
+ * transcript assistant (`poolse:…`, kind agent) and the recorder
50
+ * (LiveKit Egress, `EG_…`) are never listed — nor counted when the core
51
+ * ends a call left alone. Phone (SIP) participants are listed. Agents
52
+ * invited into the call are listed with `isAgent` (last), never counted.
53
+ */
42
54
  participants: Array<{
43
55
  userId: string;
44
56
  externalId: string;
@@ -57,6 +69,16 @@ export interface Snapshot {
57
69
  * Absent before 0.11.0.
58
70
  */
59
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;
60
82
  }>;
61
83
  /** The kind of output playing now — the short answer to "where is the audio". */
62
84
  audioRoute: AudioOutputKind;
@@ -108,6 +130,68 @@ export interface Snapshot {
108
130
  * server's `name`. Absent before 3.8.
109
131
  */
110
132
  workspaceName?: string | null;
133
+ /**
134
+ * Whether the server lets you publish. `false` while recording consent
135
+ * is required and you have not accepted (docs/RECORDING.md §5): you
136
+ * still hear and see the call, but nothing of yours goes out. Your
137
+ * `mutedSelf` / camera choices are kept and come back as they were once
138
+ * it turns `true` again (the core republishes by itself; call
139
+ * `republish()` from ConsentPrompt's `onAccepted` too). Absent before 3.9.
140
+ */
141
+ canPublish?: boolean;
142
+ /**
143
+ * The call's recording state as the server last told this core (on
144
+ * answer / join / place and each reconnect) — enough to show the
145
+ * indicator at once. Live changes arrive on the conversation socket
146
+ * (`recording:*`). null: not known (a server without recording).
147
+ * Absent before 3.9.
148
+ */
149
+ recording?: CallRecordingState | null;
150
+ /** The live transcript's state, the same way (`transcript:*` on the socket). Absent before 3.9. */
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
+
172
+ /** The CallSummary's `recording` object, as the server sent it (docs/CALL_CONTRACT.md §4.2). */
173
+ export interface CallRecordingState {
174
+ /** This server can record (LiveKit Egress). */
175
+ available: boolean;
176
+ active: boolean;
177
+ id: string | null;
178
+ mode: 'video' | 'audio' | null;
179
+ started_at: string | null;
180
+ started_by_user_id: string | null;
181
+ auto: boolean;
182
+ /** You may not publish until you accept. */
183
+ consent_required: boolean;
184
+ /** poolse user ids. */
185
+ consent?: { accepted: string[]; declined: string[] };
186
+ }
187
+
188
+ /** The CallSummary's `transcription` object, as the server sent it. */
189
+ export interface CallTranscriptionState {
190
+ available: boolean;
191
+ active: boolean;
192
+ id: string | null;
193
+ status: 'live' | 'stopped' | 'ready' | null;
194
+ language: string | null;
111
195
  }
112
196
 
113
197
  /** `good` covers good and excellent; `unknown` until the SFU has measured. */
@@ -126,6 +210,10 @@ export interface WaitingCall {
126
210
  serverId?: string | null;
127
211
  /** That workspace's name ("Ana · Acme"). Absent before 3.8. */
128
212
  workspaceName?: string | null;
213
+ /** `meeting` when a scheduled meeting is starting rather than a person calling. Absent before 3.10. */
214
+ ringType?: 'call' | 'meeting';
215
+ /** The meeting's title for a `meeting` ring. Absent before 3.10. */
216
+ meetingTitle?: string | null;
129
217
  }
130
218
 
131
219
  /** One place call audio can play. */
@@ -240,34 +328,47 @@ export interface CallServer {
240
328
  }
241
329
 
242
330
  /**
243
- * What the user tapped on a missed-call notification: the notification
244
- * itself (`open` the conversation) or its Call back button (`call_back`
245
- * — place a call on the conversation with `media`).
331
+ * What the user tapped on a missed-call or meeting notification: the
332
+ * notification itself (`open` the conversation), a missed call's Call
333
+ * back (`call_back` — place a call on the conversation with `media`), or
334
+ * a starting meeting's Join (`join_meeting` — join the room `callId` in
335
+ * the conversation, e.g. `poolse.rooms.start(conversationId, media)`,
336
+ * which joins what is live).
246
337
  */
247
338
  export interface CallAction {
248
- type: 'open' | 'call_back';
339
+ type: 'open' | 'call_back' | 'join_meeting';
249
340
  conversationId: string;
250
341
  callId: string | null;
251
342
  media: 'audio' | 'video';
252
343
  /** The server (workspace) it belongs to — open that one. Absent before 3.8. */
253
344
  serverId?: string | null;
345
+ /** A meeting notice's scheduled meeting; null for missed calls. Absent before 3.10. */
346
+ scheduledMeetingId?: string | null;
254
347
  }
255
348
 
256
349
  /**
257
- * A Reply or Mark as read the user did from a chat notification, after
258
- * the native core sent it (or gave up). The server has already posted
259
- * the reply and marked the conversation read; use this to refresh what
260
- * the app shows (insert the message, drop the unread count) without
261
- * waiting for the socket, or to tell the user a reply did not go out.
350
+ * A Reply or Mark as read the user did from a chat notification — or an
351
+ * answer to an agent's question (`escalation`: Approve / Decline / Answer
352
+ * on an `agent_escalation` push) — after the native core sent it (or gave
353
+ * up). The server has already posted the reply and marked the
354
+ * conversation read, or passed the answer to the agent in the call; use
355
+ * this to refresh what the app shows without waiting for the socket, or
356
+ * to tell the user it did not go out.
262
357
  */
263
358
  export interface NotificationActionResult {
264
- action: 'reply' | 'mark_read';
359
+ action: 'reply' | 'mark_read' | 'escalation';
360
+ /** The conversation (for `escalation`: the call's; `""` when the push had none). */
265
361
  conversationId: string;
362
+ /** `escalation` only: which question, and how it was answered. Absent before 3.10. */
363
+ escalationId?: string;
364
+ decision?: 'approve' | 'decline' | 'answer';
365
+ /** `escalation` only: the call the agent is in. */
366
+ callId?: string | null;
266
367
  /** The server (workspace) the conversation is on. Absent before 3.8. */
267
368
  serverId?: string;
268
369
  /** Whether the server accepted it. */
269
370
  ok: boolean;
270
- /** Reply only: what the user typed. */
371
+ /** Reply (and an escalation's `answer`): what the user typed. */
271
372
  text?: string;
272
373
  /** Reply only: the idempotency id sent with it — the message's id once posted. */
273
374
  clientId?: string;
@@ -278,7 +379,8 @@ export interface NotificationActionResult {
278
379
  * `device_signed_out`, `user_blocked`, `forbidden`, `not_found`,
279
380
  * `mau_cap_exceeded`, `validation_failed`, `rate_limited`), or
280
381
  * `network`, `no_grant` (the push carried no reply grant),
281
- * `not_configured` (never `configure`d), `http_<status>`.
382
+ * `not_configured` (never `configure`d), `http_<status>`. An
383
+ * escalation: `not_pending`, `expired`, `invalid_token`, `no_token`.
282
384
  */
283
385
  error?: string;
284
386
  /** The HTTP status when the server answered with an error. */
@@ -320,7 +422,12 @@ interface PoolseCallsNative {
320
422
  startScreenShare?(): Promise<boolean>;
321
423
  stopScreenShare?(): void;
322
424
  setSpeaker(on: boolean): void;
425
+ noiseSuppressionSupported?(): boolean;
426
+ setNoiseSuppression?(on: boolean): boolean;
427
+ backgroundBlurSupported?(): boolean;
428
+ setBackgroundBlur?(on: boolean): boolean;
323
429
  setAudioOutput?(id: string): void;
430
+ republish?(): void;
324
431
  callControl?(): Promise<{
325
432
  callId: string;
326
433
  controlToken: string;
@@ -476,6 +583,29 @@ export function join(
476
583
  return native?.join(callId, conversationId, sessionToken, serverId ?? null) ?? Promise.resolve();
477
584
  }
478
585
 
586
+ /** What {@link moveCallHere} needs besides the call id. */
587
+ export interface MoveCallOptions {
588
+ conversationId: string;
589
+ /** The user's session token on the call's server. */
590
+ sessionToken: string;
591
+ /** The call's server (an `addServer` id); leave it out for the default one. */
592
+ serverId?: string;
593
+ }
594
+
595
+ /**
596
+ * "Move call to this device" (CL11): take a call you are on elsewhere
597
+ * — your desktop, your other phone — over to this one without hanging
598
+ * up. This device joins the same call; the server lets one device per
599
+ * person carry it (CALL_CONTRACT.md §9), so the other one is let go and
600
+ * its snapshot ends with `reason: 'moved'`. Offer it from the Join
601
+ * banner when `liveCalls` says you are already in the call.
602
+ *
603
+ * The camera follows the call's media on this device; mute starts off.
604
+ */
605
+ export function moveCallHere(callId: string, options: MoveCallOptions): Promise<void> {
606
+ return join(callId, options.conversationId, options.sessionToken, options.serverId);
607
+ }
608
+
479
609
  export interface StartRoomResult {
480
610
  /** The room's call id — what the Join banner and `call:*` events carry. */
481
611
  callId: string;
@@ -606,6 +736,41 @@ export const startScreenShare = async (): Promise<boolean> =>
606
736
  (await native?.startScreenShare?.()) ?? false;
607
737
 
608
738
  export const stopScreenShare = (): void => native?.stopScreenShare?.();
739
+ // ── capture processing (CL7) ──────────────────────────────────────────
740
+
741
+ /**
742
+ * Whether noise suppression can be switched. On by default on both
743
+ * platforms; the snapshot's `noiseSuppression` says what is in effect.
744
+ */
745
+ export const noiseSuppressionSupported = (): boolean =>
746
+ native?.noiseSuppressionSupported?.() ?? false;
747
+
748
+ /**
749
+ * Noise suppression on or off, for this and later calls (until the app
750
+ * restarts). Android: WebRTC's noise suppression on the microphone
751
+ * (echo cancellation stays on; the mic track is republished, a short
752
+ * gap). iOS: Apple's voice processing does echo cancellation and noise
753
+ * suppression as one, so off bypasses both — offer "off" for
754
+ * headphones only. Returns false when the build can't.
755
+ */
756
+ export const setNoiseSuppression = (on: boolean): boolean =>
757
+ native?.setNoiseSuppression?.(on) ?? false;
758
+
759
+ /**
760
+ * Whether this build can blur the background behind you. iOS 15+: yes
761
+ * (Vision person segmentation). Android: not yet — it needs an ML Kit
762
+ * segmentation model, planned as a later addition. Hide the toggle when
763
+ * false.
764
+ */
765
+ export const backgroundBlurSupported = (): boolean => native?.backgroundBlurSupported?.() ?? false;
766
+
767
+ /**
768
+ * Blur the background on your camera, kept across camera flips and
769
+ * calls. A no-op returning false where unsupported. Background
770
+ * pictures (replacement) are not offered on native yet.
771
+ */
772
+ export const setBackgroundBlur = (on: boolean): boolean => native?.setBackgroundBlur?.(on) ?? false;
773
+
609
774
  /** Route call audio to the loudspeaker (`true`) or back to earpiece / headset (`false`). */
610
775
  export const setSpeaker = (on: boolean): void => native?.setSpeaker(on);
611
776
 
@@ -621,6 +786,33 @@ export function setAudioOutput(id: string): void {
621
786
  else native?.setSpeaker(id === 'speaker'); // an older native build
622
787
  }
623
788
 
789
+ /**
790
+ * Recording consent accepted (ConsentPrompt's `onAccepted`): publish the
791
+ * mic and camera again as the user last had them. The core also does it
792
+ * by itself once the server lets this participant publish; calling it
793
+ * early, or twice, is harmless — nothing goes out while
794
+ * `snapshot.canPublish` is false.
795
+ */
796
+ export const republish = (): void => native?.republish?.();
797
+
798
+ /**
799
+ * `snapshot.canPublish` changed (and once at subscribe time with the
800
+ * current value, while a call is up). `true` when no call is up or the
801
+ * native build predates it.
802
+ */
803
+ export function onCanPublishChange(cb: (canPublish: boolean) => void): Unsubscribe {
804
+ let last: boolean | null = null;
805
+ const check = (snapshot: Snapshot | null): void => {
806
+ const now = snapshot?.canPublish ?? true;
807
+ if (now === last) return;
808
+ const first = last === null;
809
+ last = now;
810
+ if (!first || snapshot) cb(now);
811
+ };
812
+ check(getCallState());
813
+ return onCallState(check);
814
+ }
815
+
624
816
  /**
625
817
  * Socket forwarding for an open app: a `call:ring_ended` seen on the
626
818
  * socket. Idempotent with the push path — the core dedupes.
@@ -661,24 +853,28 @@ export function setShowOnLockscreen(enabled: boolean): void {
661
853
  }
662
854
  }
663
855
 
664
- // ── missed-call notifications (Android) ─────────────────────────────────
856
+ // ── missed-call and meeting notifications ───────────────────────────────
665
857
 
666
858
  /**
667
- * Android: the missed-call notification action the app was LAUNCHED
668
- * with, once — read it on mount. `null` when the app opened any other
669
- * way. The native core posts that notification itself from the push,
670
- * so it works with the app closed.
859
+ * The notification action the app was LAUNCHED with, once — read it on
860
+ * mount. `null` when the app opened any other way.
671
861
  *
672
- * iOS shows missed calls as an ordinary alert push (to the token you
673
- * register with `kind: 'alert'`); read its taps with your notification
674
- * library — its `type` is `call_missed`, the category
862
+ * Android: missed calls and meeting notices (`starting` with Join, and
863
+ * the brief; server docs/MEETINGS.md §11.3), both posted by the native
864
+ * core from the push so they work with the app closed.
865
+ *
866
+ * iOS: meeting notices (the alert push's category `poolse_meeting`, Join
867
+ * `poolse_meeting_join`), whose tap and Join arrive here as `open` /
868
+ * `join_meeting`. Missed calls there are an ordinary alert push (to the
869
+ * token you register with `kind: 'alert'`); read its taps with your
870
+ * notification library — its `type` is `call_missed`, the category
675
871
  * `poolse_missed_call`, the Call back action `call_back`.
676
872
  */
677
873
  export function takeCallAction(): CallAction | null {
678
874
  return native?.takeCallAction?.() ?? null;
679
875
  }
680
876
 
681
- /** Android: a missed-call notification tapped while the app is running. */
877
+ /** A missed-call (Android) or meeting notification (both) tapped while the app is running. */
682
878
  export function onCallAction(cb: (action: CallAction) => void): Unsubscribe {
683
879
  if (!native || !native.takeCallAction) return () => undefined;
684
880
  const sub = native.addListener('onCallAction', cb);
@@ -761,6 +957,18 @@ export function onNotificationReply(cb: (result: NotificationActionResult) => vo
761
957
  });
762
958
  }
763
959
 
960
+ /**
961
+ * `onNotificationAction`, agent escalations only (AG16): Approve / Decline
962
+ * / Answer on an `agent_escalation` push, answered natively from the lock
963
+ * screen. Feed `ok` ones to `poolse.escalations.list()` (or let
964
+ * `agent:escalation` do it) so an open card updates.
965
+ */
966
+ export function onEscalationAction(cb: (result: NotificationActionResult) => void): Unsubscribe {
967
+ return onNotificationAction((result) => {
968
+ if (result.action === 'escalation') cb(result);
969
+ });
970
+ }
971
+
764
972
  /**
765
973
  * The notification actions that finished while no `onNotificationAction`
766
974
  * listener was attached (usually: the app was not running), oldest