@poolse/native 3.7.1 → 3.9.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.
- package/CHANGELOG.md +43 -0
- package/README.md +94 -1
- package/android/src/main/java/dev/poolse/callcore/CallCoreRuntime.kt +8 -0
- package/android/src/main/java/dev/poolse/callcore/CallServers.kt +72 -0
- package/android/src/main/java/dev/poolse/callcore/Ports.kt +34 -0
- package/android/src/main/java/dev/poolse/callcore/RoutedHttpPort.kt +74 -0
- package/android/src/main/java/dev/poolse/callcore/android/AndroidRingSurface.kt +3 -3
- package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +131 -14
- package/android/src/main/java/dev/poolse/callcore/android/CallHttpClient.kt +3 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallMessagingService.kt +4 -0
- package/android/src/main/java/dev/poolse/callcore/android/IncomingCallActivity.kt +1 -1
- package/android/src/main/java/dev/poolse/callcore/android/MessageActionWorker.kt +35 -12
- package/android/src/main/java/dev/poolse/callcore/android/MessageNotifications.kt +142 -48
- package/android/src/main/java/dev/poolse/callcore/android/MissedCallNotification.kt +8 -0
- package/android/src/main/java/dev/poolse/callcore/android/PoolseIncomingCall.kt +16 -0
- package/android/src/main/java/dev/poolse/callcore/android/RingBundle.kt +6 -0
- package/android/src/main/java/dev/poolse/callcore/android/ServerRegistry.kt +107 -0
- package/android/src/main/java/dev/poolse/callcore/android/SnapshotJson.kt +23 -0
- package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +58 -7
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +96 -9
- package/dist/index.cjs +83 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +156 -9
- package/dist/index.d.ts +156 -9
- package/dist/index.js +77 -25
- package/dist/index.js.map +1 -1
- package/ios/Core/CallCoreRuntime.swift +8 -0
- package/ios/Core/CallHttpClient.swift +11 -1
- package/ios/Core/CallServers.swift +89 -0
- package/ios/Core/Ports.swift +35 -2
- package/ios/Core/RoutedHttpPort.swift +83 -0
- package/ios/Core/SnapshotEncoding.swift +17 -1
- package/ios/Module/PoolseCallsModule.swift +50 -8
- package/ios/Platform/CallCore.swift +132 -12
- package/ios/Platform/CallKitController.swift +4 -1
- package/ios/Platform/LiveKitMediaPort.swift +103 -14
- package/ios/Platform/MessageNotifications.swift +76 -23
- package/ios/Platform/ServerRegistry.swift +90 -0
- package/ios/Platform/VoipPush.swift +5 -1
- package/package.json +1 -1
- package/src/index.ts +265 -31
package/src/index.ts
CHANGED
|
@@ -38,7 +38,12 @@ export interface Snapshot {
|
|
|
38
38
|
| 'cancelled'
|
|
39
39
|
| 'connection_lost'
|
|
40
40
|
| 'failed';
|
|
41
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* REMOTE people only; `userId` is the LiveKit identity. poolse's
|
|
43
|
+
* transcript assistant (`poolse:…`, kind agent) and the recorder
|
|
44
|
+
* (LiveKit Egress, `EG_…`) are never listed — nor counted when the core
|
|
45
|
+
* ends a call left alone. Phone (SIP) participants are listed.
|
|
46
|
+
*/
|
|
42
47
|
participants: Array<{
|
|
43
48
|
userId: string;
|
|
44
49
|
externalId: string;
|
|
@@ -97,6 +102,61 @@ export interface Snapshot {
|
|
|
97
102
|
videoPaused?: boolean;
|
|
98
103
|
/** You are sharing your screen. Absent before 3.2. */
|
|
99
104
|
screenSharing?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* The server (workspace) this call runs on — the `id` given to
|
|
107
|
+
* `addServer`, or `DEFAULT_SERVER_ID` for the one `configure` set.
|
|
108
|
+
* Absent before 3.8.
|
|
109
|
+
*/
|
|
110
|
+
serverId?: string | null;
|
|
111
|
+
/**
|
|
112
|
+
* That workspace's name: the ring push's `workspace_name`, else the
|
|
113
|
+
* server's `name`. Absent before 3.8.
|
|
114
|
+
*/
|
|
115
|
+
workspaceName?: string | null;
|
|
116
|
+
/**
|
|
117
|
+
* Whether the server lets you publish. `false` while recording consent
|
|
118
|
+
* is required and you have not accepted (docs/RECORDING.md §5): you
|
|
119
|
+
* still hear and see the call, but nothing of yours goes out. Your
|
|
120
|
+
* `mutedSelf` / camera choices are kept and come back as they were once
|
|
121
|
+
* it turns `true` again (the core republishes by itself; call
|
|
122
|
+
* `republish()` from ConsentPrompt's `onAccepted` too). Absent before 3.9.
|
|
123
|
+
*/
|
|
124
|
+
canPublish?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* The call's recording state as the server last told this core (on
|
|
127
|
+
* answer / join / place and each reconnect) — enough to show the
|
|
128
|
+
* indicator at once. Live changes arrive on the conversation socket
|
|
129
|
+
* (`recording:*`). null: not known (a server without recording).
|
|
130
|
+
* Absent before 3.9.
|
|
131
|
+
*/
|
|
132
|
+
recording?: CallRecordingState | null;
|
|
133
|
+
/** The live transcript's state, the same way (`transcript:*` on the socket). Absent before 3.9. */
|
|
134
|
+
transcription?: CallTranscriptionState | null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The CallSummary's `recording` object, as the server sent it (docs/CALL_CONTRACT.md §4.2). */
|
|
138
|
+
export interface CallRecordingState {
|
|
139
|
+
/** This server can record (LiveKit Egress). */
|
|
140
|
+
available: boolean;
|
|
141
|
+
active: boolean;
|
|
142
|
+
id: string | null;
|
|
143
|
+
mode: 'video' | 'audio' | null;
|
|
144
|
+
started_at: string | null;
|
|
145
|
+
started_by_user_id: string | null;
|
|
146
|
+
auto: boolean;
|
|
147
|
+
/** You may not publish until you accept. */
|
|
148
|
+
consent_required: boolean;
|
|
149
|
+
/** poolse user ids. */
|
|
150
|
+
consent?: { accepted: string[]; declined: string[] };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The CallSummary's `transcription` object, as the server sent it. */
|
|
154
|
+
export interface CallTranscriptionState {
|
|
155
|
+
available: boolean;
|
|
156
|
+
active: boolean;
|
|
157
|
+
id: string | null;
|
|
158
|
+
status: 'live' | 'stopped' | 'ready' | null;
|
|
159
|
+
language: string | null;
|
|
100
160
|
}
|
|
101
161
|
|
|
102
162
|
/** `good` covers good and excellent; `unknown` until the SFU has measured. */
|
|
@@ -111,6 +171,10 @@ export interface WaitingCall {
|
|
|
111
171
|
conversationName: string | null;
|
|
112
172
|
callerName: string | null;
|
|
113
173
|
media: 'audio' | 'video';
|
|
174
|
+
/** The server (workspace) it rings from — may differ from the current call's. Absent before 3.8. */
|
|
175
|
+
serverId?: string | null;
|
|
176
|
+
/** That workspace's name ("Ana · Acme"). Absent before 3.8. */
|
|
177
|
+
workspaceName?: string | null;
|
|
114
178
|
}
|
|
115
179
|
|
|
116
180
|
/** One place call audio can play. */
|
|
@@ -191,6 +255,37 @@ export interface PlaceOptions {
|
|
|
191
255
|
media: 'audio' | 'video';
|
|
192
256
|
/** The user's session token — authorizes placing/joining (CALL_CONTRACT.md §3.2). */
|
|
193
257
|
sessionToken: string;
|
|
258
|
+
/**
|
|
259
|
+
* The server (workspace) the session token belongs to — an `addServer`
|
|
260
|
+
* id. Leave it out for the default server (`configure`'s).
|
|
261
|
+
*/
|
|
262
|
+
serverId?: string;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** The server `configure(apiBaseUrl)` sets; what everything defaults to. */
|
|
266
|
+
export const DEFAULT_SERVER_ID = 'default';
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* One server (workspace) the app is signed in to. No secrets: rings
|
|
270
|
+
* carry their own grant, and place / join take the session token.
|
|
271
|
+
*/
|
|
272
|
+
export interface CallServer {
|
|
273
|
+
/**
|
|
274
|
+
* Your id for it, 1–64 of `A–Z a–z 0–9 . _ : -` — what `serverId`
|
|
275
|
+
* says everywhere (snapshots, notification taps and actions).
|
|
276
|
+
*/
|
|
277
|
+
id: string;
|
|
278
|
+
/** Its API origin, as for `configure`. */
|
|
279
|
+
apiBaseUrl: string;
|
|
280
|
+
/**
|
|
281
|
+
* The poolse tenant this sign-in belongs to (`tenant_id` of `me` or of
|
|
282
|
+
* the registered device). Pushes carry it: it is how a ring or a
|
|
283
|
+
* notification finds its server. Needed as soon as two servers are
|
|
284
|
+
* added; without it a push goes to the default server.
|
|
285
|
+
*/
|
|
286
|
+
tenantId?: string;
|
|
287
|
+
/** The workspace's name — shown when a push carries none ("Ana · Acme"). */
|
|
288
|
+
name?: string;
|
|
194
289
|
}
|
|
195
290
|
|
|
196
291
|
/**
|
|
@@ -203,6 +298,8 @@ export interface CallAction {
|
|
|
203
298
|
conversationId: string;
|
|
204
299
|
callId: string | null;
|
|
205
300
|
media: 'audio' | 'video';
|
|
301
|
+
/** The server (workspace) it belongs to — open that one. Absent before 3.8. */
|
|
302
|
+
serverId?: string | null;
|
|
206
303
|
}
|
|
207
304
|
|
|
208
305
|
/**
|
|
@@ -215,6 +312,8 @@ export interface CallAction {
|
|
|
215
312
|
export interface NotificationActionResult {
|
|
216
313
|
action: 'reply' | 'mark_read';
|
|
217
314
|
conversationId: string;
|
|
315
|
+
/** The server (workspace) the conversation is on. Absent before 3.8. */
|
|
316
|
+
serverId?: string;
|
|
218
317
|
/** Whether the server accepted it. */
|
|
219
318
|
ok: boolean;
|
|
220
319
|
/** Reply only: what the user typed. */
|
|
@@ -241,9 +340,23 @@ type NativeSnapshot = { snapshot: Snapshot | null };
|
|
|
241
340
|
|
|
242
341
|
interface PoolseCallsNative {
|
|
243
342
|
configure(apiBaseUrl: string, options: ConfigureOptions | null): Promise<void>;
|
|
343
|
+
addServer?(server: CallServer): Promise<void>;
|
|
344
|
+
removeServer?(id: string): Promise<void>;
|
|
345
|
+
listServers?(): CallServer[];
|
|
346
|
+
serverForTenant?(tenantId: string | null): string | null;
|
|
244
347
|
getCallState(): NativeSnapshot;
|
|
245
|
-
place(
|
|
246
|
-
|
|
348
|
+
place(
|
|
349
|
+
conversationId: string,
|
|
350
|
+
media: string,
|
|
351
|
+
sessionToken: string,
|
|
352
|
+
serverId: string | null,
|
|
353
|
+
): Promise<void>;
|
|
354
|
+
join(
|
|
355
|
+
callId: string,
|
|
356
|
+
conversationId: string | null,
|
|
357
|
+
sessionToken: string,
|
|
358
|
+
serverId: string | null,
|
|
359
|
+
): Promise<void>;
|
|
247
360
|
answer(): void;
|
|
248
361
|
decline(): void;
|
|
249
362
|
hangUp(): void;
|
|
@@ -257,7 +370,13 @@ interface PoolseCallsNative {
|
|
|
257
370
|
stopScreenShare?(): void;
|
|
258
371
|
setSpeaker(on: boolean): void;
|
|
259
372
|
setAudioOutput?(id: string): void;
|
|
260
|
-
|
|
373
|
+
republish?(): void;
|
|
374
|
+
callControl?(): Promise<{
|
|
375
|
+
callId: string;
|
|
376
|
+
controlToken: string;
|
|
377
|
+
serverId?: string | null;
|
|
378
|
+
apiBaseUrl?: string | null;
|
|
379
|
+
} | null>;
|
|
261
380
|
setPictureInPictureEnabled?(on: boolean): void;
|
|
262
381
|
isInPictureInPicture?(): boolean;
|
|
263
382
|
pictureInPictureSupported?(): boolean;
|
|
@@ -268,7 +387,7 @@ interface PoolseCallsNative {
|
|
|
268
387
|
setShowOnLockscreen?(enabled: boolean): void;
|
|
269
388
|
getVoipToken?(): VoipToken | null;
|
|
270
389
|
takeCallAction?(): CallAction | null;
|
|
271
|
-
setActiveConversation?(conversationId: string | null): void;
|
|
390
|
+
setActiveConversation?(conversationId: string | null, serverId: string | null): void;
|
|
272
391
|
takeNotificationActions?(): NotificationActionResult[];
|
|
273
392
|
observeNotificationActions?(on: boolean): void;
|
|
274
393
|
addListener(event: 'onCallState', cb: (payload: NativeSnapshot) => void): { remove(): void };
|
|
@@ -292,10 +411,88 @@ export const nativeCallsAvailable = native != null;
|
|
|
292
411
|
// Kept for startRoom, the one command that talks to the server from JS.
|
|
293
412
|
let apiOrigin: string | null = null;
|
|
294
413
|
|
|
295
|
-
/**
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
414
|
+
/**
|
|
415
|
+
* Configure once, before any call can arrive. No secrets — just the API
|
|
416
|
+
* origin, which becomes the default server (`DEFAULT_SERVER_ID`).
|
|
417
|
+
*
|
|
418
|
+
* `configure(options)` sets the options alone, for an app whose servers
|
|
419
|
+
* all come from `addServer`.
|
|
420
|
+
*/
|
|
421
|
+
export async function configure(
|
|
422
|
+
apiBaseUrlOrOptions: string | ConfigureOptions,
|
|
423
|
+
options?: ConfigureOptions,
|
|
424
|
+
): Promise<void> {
|
|
425
|
+
if (typeof apiBaseUrlOrOptions !== 'string') {
|
|
426
|
+
await native?.configure('', apiBaseUrlOrOptions ?? null);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
apiOrigin = apiBaseUrlOrOptions.replace(/\/+$/, '');
|
|
430
|
+
await native?.configure(apiBaseUrlOrOptions, options ?? null);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// ── several servers (workspaces) ──────────────────────────────────────
|
|
434
|
+
|
|
435
|
+
const SERVER_ID = /^[A-Za-z0-9._:-]{1,64}$/;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Sign the call core in to one more server (workspace) — or update one
|
|
439
|
+
* (same `id`). Rings from it ring here, answered and declined on that
|
|
440
|
+
* server; its chat notifications post (Android) and act (Reply, Mark as
|
|
441
|
+
* read) against it. Persisted: a closed app woken by its push finds it.
|
|
442
|
+
*
|
|
443
|
+
* Register the device's push tokens with that server too (the SDK's
|
|
444
|
+
* `devices.register`, per client): this only tells the core where it is.
|
|
445
|
+
* Calls `configure` with default options first if it never ran.
|
|
446
|
+
*/
|
|
447
|
+
export async function addServer(server: CallServer): Promise<void> {
|
|
448
|
+
if (!SERVER_ID.test(server.id))
|
|
449
|
+
throw new Error(`addServer: invalid id ${JSON.stringify(server.id)}.`);
|
|
450
|
+
if (!/^https?:\/\/[^\s]+$/.test(server.apiBaseUrl))
|
|
451
|
+
throw new Error('addServer: apiBaseUrl must be http(s).');
|
|
452
|
+
const entry: CallServer = { id: server.id, apiBaseUrl: server.apiBaseUrl.replace(/\/+$/, '') };
|
|
453
|
+
if (server.tenantId) entry.tenantId = server.tenantId;
|
|
454
|
+
if (server.name) entry.name = server.name;
|
|
455
|
+
if (server.id === DEFAULT_SERVER_ID) apiOrigin = entry.apiBaseUrl;
|
|
456
|
+
await native?.addServer?.(entry);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Signed out of one server: the core forgets it and takes its
|
|
461
|
+
* notifications down; the others are untouched. A call in progress on
|
|
462
|
+
* it carries on to its end. Unregister its push tokens with that server
|
|
463
|
+
* yourself (before signing out there).
|
|
464
|
+
*/
|
|
465
|
+
export async function removeServer(id: string): Promise<void> {
|
|
466
|
+
if (id === DEFAULT_SERVER_ID) apiOrigin = null;
|
|
467
|
+
await native?.removeServer?.(id);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** The servers the core knows, in the order they were added (`configure`'s is `default`). */
|
|
471
|
+
export function listServers(): CallServer[] {
|
|
472
|
+
return native?.listServers?.() ?? [];
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* The server a notification (its data) belongs to, by its `tenant_id` —
|
|
477
|
+
* the same rule the core routes rings and actions by. Use it on a tapped
|
|
478
|
+
* iOS notification to open the right workspace. `null` with no server.
|
|
479
|
+
*/
|
|
480
|
+
export function serverOfNotification(
|
|
481
|
+
data: Record<string, unknown> | undefined | null,
|
|
482
|
+
): string | null {
|
|
483
|
+
const tenant = data && typeof data['tenant_id'] === 'string' ? data['tenant_id'] : null;
|
|
484
|
+
if (native?.serverForTenant) return native.serverForTenant(tenant);
|
|
485
|
+
return apiOrigin ? DEFAULT_SERVER_ID : null;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/** The API origin of `serverId` (the default server when absent). */
|
|
489
|
+
function originOf(serverId: string | null | undefined): string | null {
|
|
490
|
+
if (!serverId || serverId === DEFAULT_SERVER_ID) {
|
|
491
|
+
if (apiOrigin) return apiOrigin;
|
|
492
|
+
}
|
|
493
|
+
const id = serverId ?? DEFAULT_SERVER_ID;
|
|
494
|
+
const server = listServers().find((s) => s.id === id);
|
|
495
|
+
return server?.apiBaseUrl ?? null;
|
|
299
496
|
}
|
|
300
497
|
|
|
301
498
|
/** The current snapshot — safe to read at any moment, including cold answer and before configure. */
|
|
@@ -313,15 +510,20 @@ export function onCallState(cb: (snapshot: Snapshot | null) => void): Unsubscrib
|
|
|
313
510
|
}
|
|
314
511
|
|
|
315
512
|
export function place(conversationId: string, options: PlaceOptions): Promise<void> {
|
|
316
|
-
return
|
|
513
|
+
return (
|
|
514
|
+
native?.place(conversationId, options.media, options.sessionToken, options.serverId ?? null) ??
|
|
515
|
+
Promise.resolve()
|
|
516
|
+
);
|
|
317
517
|
}
|
|
318
518
|
|
|
519
|
+
/** `serverId`: the server the session token is for — leave it out for the default one. */
|
|
319
520
|
export function join(
|
|
320
521
|
callId: string,
|
|
321
522
|
conversationId: string | null,
|
|
322
523
|
sessionToken: string,
|
|
524
|
+
serverId?: string,
|
|
323
525
|
): Promise<void> {
|
|
324
|
-
return native?.join(callId, conversationId, sessionToken) ?? Promise.resolve();
|
|
526
|
+
return native?.join(callId, conversationId, sessionToken, serverId ?? null) ?? Promise.resolve();
|
|
325
527
|
}
|
|
326
528
|
|
|
327
529
|
export interface StartRoomResult {
|
|
@@ -348,18 +550,16 @@ export async function startRoom(
|
|
|
348
550
|
options: PlaceOptions,
|
|
349
551
|
): Promise<StartRoomResult> {
|
|
350
552
|
if (!native) throw new Error('The native call core is not in this build.');
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
'content-type': 'application/json',
|
|
359
|
-
},
|
|
360
|
-
body: JSON.stringify({ media: options.media }),
|
|
553
|
+
const origin = originOf(options.serverId);
|
|
554
|
+
if (!origin) throw new Error('Call configure() (or addServer) before startRoom().');
|
|
555
|
+
const res = await fetch(`${origin}/v1/conversations/${encodeURIComponent(conversationId)}/room`, {
|
|
556
|
+
method: 'POST',
|
|
557
|
+
headers: {
|
|
558
|
+
authorization: `Bearer ${options.sessionToken}`,
|
|
559
|
+
'content-type': 'application/json',
|
|
361
560
|
},
|
|
362
|
-
|
|
561
|
+
body: JSON.stringify({ media: options.media }),
|
|
562
|
+
});
|
|
363
563
|
const body = (await res.json().catch(() => null)) as {
|
|
364
564
|
created?: boolean;
|
|
365
565
|
call?: { id?: string };
|
|
@@ -371,7 +571,7 @@ export async function startRoom(
|
|
|
371
571
|
}
|
|
372
572
|
// The core joins with its own request: it owns the session from here,
|
|
373
573
|
// exactly as when the room is joined from the banner.
|
|
374
|
-
await native.join(callId, conversationId, options.sessionToken);
|
|
574
|
+
await native.join(callId, conversationId, options.sessionToken, options.serverId ?? null);
|
|
375
575
|
return { callId, created: body?.created === true };
|
|
376
576
|
}
|
|
377
577
|
|
|
@@ -393,10 +593,12 @@ export interface RingIntoCallOptions {
|
|
|
393
593
|
*/
|
|
394
594
|
export async function ringIntoCall(people: RingIntoCallOptions): Promise<string[]> {
|
|
395
595
|
if (!native?.callControl) throw new Error('This build cannot ring people into a call.');
|
|
396
|
-
if (!apiOrigin) throw new Error('Call configure() before ringIntoCall().');
|
|
397
596
|
const control = await native.callControl();
|
|
398
597
|
if (!control) throw new Error('There is no call in progress.');
|
|
399
|
-
|
|
598
|
+
// The call's own server: it may be another workspace than the default.
|
|
599
|
+
const origin = control.apiBaseUrl || originOf(control.serverId);
|
|
600
|
+
if (!origin) throw new Error('Call configure() before ringIntoCall().');
|
|
601
|
+
const res = await fetch(`${origin}/v1/calls/${encodeURIComponent(control.callId)}/ring`, {
|
|
400
602
|
method: 'POST',
|
|
401
603
|
headers: {
|
|
402
604
|
authorization: `Bearer ${control.controlToken}`,
|
|
@@ -469,6 +671,33 @@ export function setAudioOutput(id: string): void {
|
|
|
469
671
|
else native?.setSpeaker(id === 'speaker'); // an older native build
|
|
470
672
|
}
|
|
471
673
|
|
|
674
|
+
/**
|
|
675
|
+
* Recording consent accepted (ConsentPrompt's `onAccepted`): publish the
|
|
676
|
+
* mic and camera again as the user last had them. The core also does it
|
|
677
|
+
* by itself once the server lets this participant publish; calling it
|
|
678
|
+
* early, or twice, is harmless — nothing goes out while
|
|
679
|
+
* `snapshot.canPublish` is false.
|
|
680
|
+
*/
|
|
681
|
+
export const republish = (): void => native?.republish?.();
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* `snapshot.canPublish` changed (and once at subscribe time with the
|
|
685
|
+
* current value, while a call is up). `true` when no call is up or the
|
|
686
|
+
* native build predates it.
|
|
687
|
+
*/
|
|
688
|
+
export function onCanPublishChange(cb: (canPublish: boolean) => void): Unsubscribe {
|
|
689
|
+
let last: boolean | null = null;
|
|
690
|
+
const check = (snapshot: Snapshot | null): void => {
|
|
691
|
+
const now = snapshot?.canPublish ?? true;
|
|
692
|
+
if (now === last) return;
|
|
693
|
+
const first = last === null;
|
|
694
|
+
last = now;
|
|
695
|
+
if (!first || snapshot) cb(now);
|
|
696
|
+
};
|
|
697
|
+
check(getCallState());
|
|
698
|
+
return onCallState(check);
|
|
699
|
+
}
|
|
700
|
+
|
|
472
701
|
/**
|
|
473
702
|
* Socket forwarding for an open app: a `call:ring_ended` seen on the
|
|
474
703
|
* socket. Idempotent with the push path — the core dedupes.
|
|
@@ -536,16 +765,19 @@ export function onCallAction(cb: (action: CallAction) => void): Unsubscribe {
|
|
|
536
765
|
// ── chat notifications ─────────────────────────────────────────────────
|
|
537
766
|
|
|
538
767
|
let activeConversation: string | null = null;
|
|
768
|
+
let activeServer: string | null = null;
|
|
539
769
|
|
|
540
770
|
/**
|
|
541
771
|
* Tell the core which conversation is on screen (`null` when none, and
|
|
542
772
|
* when the app goes to the background). Its messages are not notified —
|
|
543
773
|
* the user is reading them — and opening it clears the notifications
|
|
544
|
-
* already shown for it.
|
|
774
|
+
* already shown for it. Signed in to several servers, pass the one it is
|
|
775
|
+
* on (`serverId`); without it, the conversation id alone decides.
|
|
545
776
|
*/
|
|
546
|
-
export function setActiveConversation(conversationId: string | null): void {
|
|
777
|
+
export function setActiveConversation(conversationId: string | null, serverId?: string): void {
|
|
547
778
|
activeConversation = conversationId;
|
|
548
|
-
|
|
779
|
+
activeServer = conversationId ? (serverId ?? null) : null;
|
|
780
|
+
native?.setActiveConversation?.(conversationId, activeServer);
|
|
549
781
|
}
|
|
550
782
|
|
|
551
783
|
/**
|
|
@@ -556,14 +788,16 @@ export function setActiveConversation(conversationId: string | null): void {
|
|
|
556
788
|
*/
|
|
557
789
|
export function shouldPresentMessage(data: Record<string, unknown> | undefined | null): boolean {
|
|
558
790
|
if (!data || data['type'] !== 'message') return true;
|
|
559
|
-
|
|
791
|
+
if (data['conversation_id'] !== activeConversation) return true;
|
|
792
|
+
return activeServer != null && serverOfNotification(data) !== activeServer;
|
|
560
793
|
}
|
|
561
794
|
|
|
562
795
|
/**
|
|
563
796
|
* The conversation a tapped notification belongs to — a chat message
|
|
564
797
|
* (`type: 'message'`) or a missed call (`call_missed`) — from its data.
|
|
565
798
|
* iOS hands the tap to your notification library; Android delivers it
|
|
566
|
-
* through `takeCallAction` / `onCallAction` (type `open`).
|
|
799
|
+
* through `takeCallAction` / `onCallAction` (type `open`). Its server:
|
|
800
|
+
* `serverOfNotification`.
|
|
567
801
|
*/
|
|
568
802
|
export function conversationOfNotification(
|
|
569
803
|
data: Record<string, unknown> | undefined | null,
|
|
@@ -577,7 +811,7 @@ export function conversationOfNotification(
|
|
|
577
811
|
/**
|
|
578
812
|
* Reply and Mark as read from a chat notification are handled natively —
|
|
579
813
|
* from the lock screen, with the app closed — using the grant the push
|
|
580
|
-
* carried and
|
|
814
|
+
* carried and its server's API origin (`configure` / `addServer`, persisted).
|
|
581
815
|
* This fires once each finishes while the app is running. Read the ones
|
|
582
816
|
* that finished while it was not with `takeNotificationActions` on mount.
|
|
583
817
|
*/
|