@poolse/native 3.7.1 → 3.8.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 +28 -0
- package/README.md +61 -1
- package/android/src/main/java/dev/poolse/callcore/CallServers.kt +72 -0
- package/android/src/main/java/dev/poolse/callcore/Ports.kt +8 -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 +110 -14
- 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/expo/modules/poolsecalls/PoolseCallsModule.kt +56 -7
- package/dist/index.cjs +68 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +91 -8
- package/dist/index.d.ts +91 -8
- package/dist/index.js +64 -25
- package/dist/index.js.map +1 -1
- package/ios/Core/CallServers.swift +89 -0
- package/ios/Core/Ports.swift +10 -1
- package/ios/Core/RoutedHttpPort.swift +83 -0
- package/ios/Module/PoolseCallsModule.swift +48 -8
- package/ios/Platform/CallCore.swift +116 -11
- package/ios/Platform/CallKitController.swift +4 -1
- 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 +187 -30
package/src/index.ts
CHANGED
|
@@ -97,6 +97,17 @@ export interface Snapshot {
|
|
|
97
97
|
videoPaused?: boolean;
|
|
98
98
|
/** You are sharing your screen. Absent before 3.2. */
|
|
99
99
|
screenSharing?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* The server (workspace) this call runs on — the `id` given to
|
|
102
|
+
* `addServer`, or `DEFAULT_SERVER_ID` for the one `configure` set.
|
|
103
|
+
* Absent before 3.8.
|
|
104
|
+
*/
|
|
105
|
+
serverId?: string | null;
|
|
106
|
+
/**
|
|
107
|
+
* That workspace's name: the ring push's `workspace_name`, else the
|
|
108
|
+
* server's `name`. Absent before 3.8.
|
|
109
|
+
*/
|
|
110
|
+
workspaceName?: string | null;
|
|
100
111
|
}
|
|
101
112
|
|
|
102
113
|
/** `good` covers good and excellent; `unknown` until the SFU has measured. */
|
|
@@ -111,6 +122,10 @@ export interface WaitingCall {
|
|
|
111
122
|
conversationName: string | null;
|
|
112
123
|
callerName: string | null;
|
|
113
124
|
media: 'audio' | 'video';
|
|
125
|
+
/** The server (workspace) it rings from — may differ from the current call's. Absent before 3.8. */
|
|
126
|
+
serverId?: string | null;
|
|
127
|
+
/** That workspace's name ("Ana · Acme"). Absent before 3.8. */
|
|
128
|
+
workspaceName?: string | null;
|
|
114
129
|
}
|
|
115
130
|
|
|
116
131
|
/** One place call audio can play. */
|
|
@@ -191,6 +206,37 @@ export interface PlaceOptions {
|
|
|
191
206
|
media: 'audio' | 'video';
|
|
192
207
|
/** The user's session token — authorizes placing/joining (CALL_CONTRACT.md §3.2). */
|
|
193
208
|
sessionToken: string;
|
|
209
|
+
/**
|
|
210
|
+
* The server (workspace) the session token belongs to — an `addServer`
|
|
211
|
+
* id. Leave it out for the default server (`configure`'s).
|
|
212
|
+
*/
|
|
213
|
+
serverId?: string;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** The server `configure(apiBaseUrl)` sets; what everything defaults to. */
|
|
217
|
+
export const DEFAULT_SERVER_ID = 'default';
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* One server (workspace) the app is signed in to. No secrets: rings
|
|
221
|
+
* carry their own grant, and place / join take the session token.
|
|
222
|
+
*/
|
|
223
|
+
export interface CallServer {
|
|
224
|
+
/**
|
|
225
|
+
* Your id for it, 1–64 of `A–Z a–z 0–9 . _ : -` — what `serverId`
|
|
226
|
+
* says everywhere (snapshots, notification taps and actions).
|
|
227
|
+
*/
|
|
228
|
+
id: string;
|
|
229
|
+
/** Its API origin, as for `configure`. */
|
|
230
|
+
apiBaseUrl: string;
|
|
231
|
+
/**
|
|
232
|
+
* The poolse tenant this sign-in belongs to (`tenant_id` of `me` or of
|
|
233
|
+
* the registered device). Pushes carry it: it is how a ring or a
|
|
234
|
+
* notification finds its server. Needed as soon as two servers are
|
|
235
|
+
* added; without it a push goes to the default server.
|
|
236
|
+
*/
|
|
237
|
+
tenantId?: string;
|
|
238
|
+
/** The workspace's name — shown when a push carries none ("Ana · Acme"). */
|
|
239
|
+
name?: string;
|
|
194
240
|
}
|
|
195
241
|
|
|
196
242
|
/**
|
|
@@ -203,6 +249,8 @@ export interface CallAction {
|
|
|
203
249
|
conversationId: string;
|
|
204
250
|
callId: string | null;
|
|
205
251
|
media: 'audio' | 'video';
|
|
252
|
+
/** The server (workspace) it belongs to — open that one. Absent before 3.8. */
|
|
253
|
+
serverId?: string | null;
|
|
206
254
|
}
|
|
207
255
|
|
|
208
256
|
/**
|
|
@@ -215,6 +263,8 @@ export interface CallAction {
|
|
|
215
263
|
export interface NotificationActionResult {
|
|
216
264
|
action: 'reply' | 'mark_read';
|
|
217
265
|
conversationId: string;
|
|
266
|
+
/** The server (workspace) the conversation is on. Absent before 3.8. */
|
|
267
|
+
serverId?: string;
|
|
218
268
|
/** Whether the server accepted it. */
|
|
219
269
|
ok: boolean;
|
|
220
270
|
/** Reply only: what the user typed. */
|
|
@@ -241,9 +291,23 @@ type NativeSnapshot = { snapshot: Snapshot | null };
|
|
|
241
291
|
|
|
242
292
|
interface PoolseCallsNative {
|
|
243
293
|
configure(apiBaseUrl: string, options: ConfigureOptions | null): Promise<void>;
|
|
294
|
+
addServer?(server: CallServer): Promise<void>;
|
|
295
|
+
removeServer?(id: string): Promise<void>;
|
|
296
|
+
listServers?(): CallServer[];
|
|
297
|
+
serverForTenant?(tenantId: string | null): string | null;
|
|
244
298
|
getCallState(): NativeSnapshot;
|
|
245
|
-
place(
|
|
246
|
-
|
|
299
|
+
place(
|
|
300
|
+
conversationId: string,
|
|
301
|
+
media: string,
|
|
302
|
+
sessionToken: string,
|
|
303
|
+
serverId: string | null,
|
|
304
|
+
): Promise<void>;
|
|
305
|
+
join(
|
|
306
|
+
callId: string,
|
|
307
|
+
conversationId: string | null,
|
|
308
|
+
sessionToken: string,
|
|
309
|
+
serverId: string | null,
|
|
310
|
+
): Promise<void>;
|
|
247
311
|
answer(): void;
|
|
248
312
|
decline(): void;
|
|
249
313
|
hangUp(): void;
|
|
@@ -257,7 +321,12 @@ interface PoolseCallsNative {
|
|
|
257
321
|
stopScreenShare?(): void;
|
|
258
322
|
setSpeaker(on: boolean): void;
|
|
259
323
|
setAudioOutput?(id: string): void;
|
|
260
|
-
callControl?(): Promise<{
|
|
324
|
+
callControl?(): Promise<{
|
|
325
|
+
callId: string;
|
|
326
|
+
controlToken: string;
|
|
327
|
+
serverId?: string | null;
|
|
328
|
+
apiBaseUrl?: string | null;
|
|
329
|
+
} | null>;
|
|
261
330
|
setPictureInPictureEnabled?(on: boolean): void;
|
|
262
331
|
isInPictureInPicture?(): boolean;
|
|
263
332
|
pictureInPictureSupported?(): boolean;
|
|
@@ -268,7 +337,7 @@ interface PoolseCallsNative {
|
|
|
268
337
|
setShowOnLockscreen?(enabled: boolean): void;
|
|
269
338
|
getVoipToken?(): VoipToken | null;
|
|
270
339
|
takeCallAction?(): CallAction | null;
|
|
271
|
-
setActiveConversation?(conversationId: string | null): void;
|
|
340
|
+
setActiveConversation?(conversationId: string | null, serverId: string | null): void;
|
|
272
341
|
takeNotificationActions?(): NotificationActionResult[];
|
|
273
342
|
observeNotificationActions?(on: boolean): void;
|
|
274
343
|
addListener(event: 'onCallState', cb: (payload: NativeSnapshot) => void): { remove(): void };
|
|
@@ -292,10 +361,88 @@ export const nativeCallsAvailable = native != null;
|
|
|
292
361
|
// Kept for startRoom, the one command that talks to the server from JS.
|
|
293
362
|
let apiOrigin: string | null = null;
|
|
294
363
|
|
|
295
|
-
/**
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
364
|
+
/**
|
|
365
|
+
* Configure once, before any call can arrive. No secrets — just the API
|
|
366
|
+
* origin, which becomes the default server (`DEFAULT_SERVER_ID`).
|
|
367
|
+
*
|
|
368
|
+
* `configure(options)` sets the options alone, for an app whose servers
|
|
369
|
+
* all come from `addServer`.
|
|
370
|
+
*/
|
|
371
|
+
export async function configure(
|
|
372
|
+
apiBaseUrlOrOptions: string | ConfigureOptions,
|
|
373
|
+
options?: ConfigureOptions,
|
|
374
|
+
): Promise<void> {
|
|
375
|
+
if (typeof apiBaseUrlOrOptions !== 'string') {
|
|
376
|
+
await native?.configure('', apiBaseUrlOrOptions ?? null);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
apiOrigin = apiBaseUrlOrOptions.replace(/\/+$/, '');
|
|
380
|
+
await native?.configure(apiBaseUrlOrOptions, options ?? null);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// ── several servers (workspaces) ──────────────────────────────────────
|
|
384
|
+
|
|
385
|
+
const SERVER_ID = /^[A-Za-z0-9._:-]{1,64}$/;
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Sign the call core in to one more server (workspace) — or update one
|
|
389
|
+
* (same `id`). Rings from it ring here, answered and declined on that
|
|
390
|
+
* server; its chat notifications post (Android) and act (Reply, Mark as
|
|
391
|
+
* read) against it. Persisted: a closed app woken by its push finds it.
|
|
392
|
+
*
|
|
393
|
+
* Register the device's push tokens with that server too (the SDK's
|
|
394
|
+
* `devices.register`, per client): this only tells the core where it is.
|
|
395
|
+
* Calls `configure` with default options first if it never ran.
|
|
396
|
+
*/
|
|
397
|
+
export async function addServer(server: CallServer): Promise<void> {
|
|
398
|
+
if (!SERVER_ID.test(server.id))
|
|
399
|
+
throw new Error(`addServer: invalid id ${JSON.stringify(server.id)}.`);
|
|
400
|
+
if (!/^https?:\/\/[^\s]+$/.test(server.apiBaseUrl))
|
|
401
|
+
throw new Error('addServer: apiBaseUrl must be http(s).');
|
|
402
|
+
const entry: CallServer = { id: server.id, apiBaseUrl: server.apiBaseUrl.replace(/\/+$/, '') };
|
|
403
|
+
if (server.tenantId) entry.tenantId = server.tenantId;
|
|
404
|
+
if (server.name) entry.name = server.name;
|
|
405
|
+
if (server.id === DEFAULT_SERVER_ID) apiOrigin = entry.apiBaseUrl;
|
|
406
|
+
await native?.addServer?.(entry);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Signed out of one server: the core forgets it and takes its
|
|
411
|
+
* notifications down; the others are untouched. A call in progress on
|
|
412
|
+
* it carries on to its end. Unregister its push tokens with that server
|
|
413
|
+
* yourself (before signing out there).
|
|
414
|
+
*/
|
|
415
|
+
export async function removeServer(id: string): Promise<void> {
|
|
416
|
+
if (id === DEFAULT_SERVER_ID) apiOrigin = null;
|
|
417
|
+
await native?.removeServer?.(id);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** The servers the core knows, in the order they were added (`configure`'s is `default`). */
|
|
421
|
+
export function listServers(): CallServer[] {
|
|
422
|
+
return native?.listServers?.() ?? [];
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* The server a notification (its data) belongs to, by its `tenant_id` —
|
|
427
|
+
* the same rule the core routes rings and actions by. Use it on a tapped
|
|
428
|
+
* iOS notification to open the right workspace. `null` with no server.
|
|
429
|
+
*/
|
|
430
|
+
export function serverOfNotification(
|
|
431
|
+
data: Record<string, unknown> | undefined | null,
|
|
432
|
+
): string | null {
|
|
433
|
+
const tenant = data && typeof data['tenant_id'] === 'string' ? data['tenant_id'] : null;
|
|
434
|
+
if (native?.serverForTenant) return native.serverForTenant(tenant);
|
|
435
|
+
return apiOrigin ? DEFAULT_SERVER_ID : null;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/** The API origin of `serverId` (the default server when absent). */
|
|
439
|
+
function originOf(serverId: string | null | undefined): string | null {
|
|
440
|
+
if (!serverId || serverId === DEFAULT_SERVER_ID) {
|
|
441
|
+
if (apiOrigin) return apiOrigin;
|
|
442
|
+
}
|
|
443
|
+
const id = serverId ?? DEFAULT_SERVER_ID;
|
|
444
|
+
const server = listServers().find((s) => s.id === id);
|
|
445
|
+
return server?.apiBaseUrl ?? null;
|
|
299
446
|
}
|
|
300
447
|
|
|
301
448
|
/** The current snapshot — safe to read at any moment, including cold answer and before configure. */
|
|
@@ -313,15 +460,20 @@ export function onCallState(cb: (snapshot: Snapshot | null) => void): Unsubscrib
|
|
|
313
460
|
}
|
|
314
461
|
|
|
315
462
|
export function place(conversationId: string, options: PlaceOptions): Promise<void> {
|
|
316
|
-
return
|
|
463
|
+
return (
|
|
464
|
+
native?.place(conversationId, options.media, options.sessionToken, options.serverId ?? null) ??
|
|
465
|
+
Promise.resolve()
|
|
466
|
+
);
|
|
317
467
|
}
|
|
318
468
|
|
|
469
|
+
/** `serverId`: the server the session token is for — leave it out for the default one. */
|
|
319
470
|
export function join(
|
|
320
471
|
callId: string,
|
|
321
472
|
conversationId: string | null,
|
|
322
473
|
sessionToken: string,
|
|
474
|
+
serverId?: string,
|
|
323
475
|
): Promise<void> {
|
|
324
|
-
return native?.join(callId, conversationId, sessionToken) ?? Promise.resolve();
|
|
476
|
+
return native?.join(callId, conversationId, sessionToken, serverId ?? null) ?? Promise.resolve();
|
|
325
477
|
}
|
|
326
478
|
|
|
327
479
|
export interface StartRoomResult {
|
|
@@ -348,18 +500,16 @@ export async function startRoom(
|
|
|
348
500
|
options: PlaceOptions,
|
|
349
501
|
): Promise<StartRoomResult> {
|
|
350
502
|
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 }),
|
|
503
|
+
const origin = originOf(options.serverId);
|
|
504
|
+
if (!origin) throw new Error('Call configure() (or addServer) before startRoom().');
|
|
505
|
+
const res = await fetch(`${origin}/v1/conversations/${encodeURIComponent(conversationId)}/room`, {
|
|
506
|
+
method: 'POST',
|
|
507
|
+
headers: {
|
|
508
|
+
authorization: `Bearer ${options.sessionToken}`,
|
|
509
|
+
'content-type': 'application/json',
|
|
361
510
|
},
|
|
362
|
-
|
|
511
|
+
body: JSON.stringify({ media: options.media }),
|
|
512
|
+
});
|
|
363
513
|
const body = (await res.json().catch(() => null)) as {
|
|
364
514
|
created?: boolean;
|
|
365
515
|
call?: { id?: string };
|
|
@@ -371,7 +521,7 @@ export async function startRoom(
|
|
|
371
521
|
}
|
|
372
522
|
// The core joins with its own request: it owns the session from here,
|
|
373
523
|
// exactly as when the room is joined from the banner.
|
|
374
|
-
await native.join(callId, conversationId, options.sessionToken);
|
|
524
|
+
await native.join(callId, conversationId, options.sessionToken, options.serverId ?? null);
|
|
375
525
|
return { callId, created: body?.created === true };
|
|
376
526
|
}
|
|
377
527
|
|
|
@@ -393,10 +543,12 @@ export interface RingIntoCallOptions {
|
|
|
393
543
|
*/
|
|
394
544
|
export async function ringIntoCall(people: RingIntoCallOptions): Promise<string[]> {
|
|
395
545
|
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
546
|
const control = await native.callControl();
|
|
398
547
|
if (!control) throw new Error('There is no call in progress.');
|
|
399
|
-
|
|
548
|
+
// The call's own server: it may be another workspace than the default.
|
|
549
|
+
const origin = control.apiBaseUrl || originOf(control.serverId);
|
|
550
|
+
if (!origin) throw new Error('Call configure() before ringIntoCall().');
|
|
551
|
+
const res = await fetch(`${origin}/v1/calls/${encodeURIComponent(control.callId)}/ring`, {
|
|
400
552
|
method: 'POST',
|
|
401
553
|
headers: {
|
|
402
554
|
authorization: `Bearer ${control.controlToken}`,
|
|
@@ -536,16 +688,19 @@ export function onCallAction(cb: (action: CallAction) => void): Unsubscribe {
|
|
|
536
688
|
// ── chat notifications ─────────────────────────────────────────────────
|
|
537
689
|
|
|
538
690
|
let activeConversation: string | null = null;
|
|
691
|
+
let activeServer: string | null = null;
|
|
539
692
|
|
|
540
693
|
/**
|
|
541
694
|
* Tell the core which conversation is on screen (`null` when none, and
|
|
542
695
|
* when the app goes to the background). Its messages are not notified —
|
|
543
696
|
* the user is reading them — and opening it clears the notifications
|
|
544
|
-
* already shown for it.
|
|
697
|
+
* already shown for it. Signed in to several servers, pass the one it is
|
|
698
|
+
* on (`serverId`); without it, the conversation id alone decides.
|
|
545
699
|
*/
|
|
546
|
-
export function setActiveConversation(conversationId: string | null): void {
|
|
700
|
+
export function setActiveConversation(conversationId: string | null, serverId?: string): void {
|
|
547
701
|
activeConversation = conversationId;
|
|
548
|
-
|
|
702
|
+
activeServer = conversationId ? (serverId ?? null) : null;
|
|
703
|
+
native?.setActiveConversation?.(conversationId, activeServer);
|
|
549
704
|
}
|
|
550
705
|
|
|
551
706
|
/**
|
|
@@ -556,14 +711,16 @@ export function setActiveConversation(conversationId: string | null): void {
|
|
|
556
711
|
*/
|
|
557
712
|
export function shouldPresentMessage(data: Record<string, unknown> | undefined | null): boolean {
|
|
558
713
|
if (!data || data['type'] !== 'message') return true;
|
|
559
|
-
|
|
714
|
+
if (data['conversation_id'] !== activeConversation) return true;
|
|
715
|
+
return activeServer != null && serverOfNotification(data) !== activeServer;
|
|
560
716
|
}
|
|
561
717
|
|
|
562
718
|
/**
|
|
563
719
|
* The conversation a tapped notification belongs to — a chat message
|
|
564
720
|
* (`type: 'message'`) or a missed call (`call_missed`) — from its data.
|
|
565
721
|
* iOS hands the tap to your notification library; Android delivers it
|
|
566
|
-
* through `takeCallAction` / `onCallAction` (type `open`).
|
|
722
|
+
* through `takeCallAction` / `onCallAction` (type `open`). Its server:
|
|
723
|
+
* `serverOfNotification`.
|
|
567
724
|
*/
|
|
568
725
|
export function conversationOfNotification(
|
|
569
726
|
data: Record<string, unknown> | undefined | null,
|
|
@@ -577,7 +734,7 @@ export function conversationOfNotification(
|
|
|
577
734
|
/**
|
|
578
735
|
* Reply and Mark as read from a chat notification are handled natively —
|
|
579
736
|
* from the lock screen, with the app closed — using the grant the push
|
|
580
|
-
* carried and
|
|
737
|
+
* carried and its server's API origin (`configure` / `addServer`, persisted).
|
|
581
738
|
* This fires once each finishes while the app is running. Read the ones
|
|
582
739
|
* that finished while it was not with `takeNotificationActions` on mount.
|
|
583
740
|
*/
|