@poolse/native 0.0.0-stage → 3.1.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 +31 -0
- package/LICENSE +206 -0
- package/README.md +116 -2
- package/android/build.gradle +58 -0
- package/android/consumer-rules.pro +11 -0
- package/android/src/main/AndroidManifest.xml +46 -0
- package/android/src/main/java/dev/poolse/callcore/CallCoreRuntime.kt +540 -0
- package/android/src/main/java/dev/poolse/callcore/CallMachine.kt +492 -0
- package/android/src/main/java/dev/poolse/callcore/Ports.kt +132 -0
- package/android/src/main/java/dev/poolse/callcore/android/AndroidRingSurface.kt +383 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallActionReceiver.kt +45 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +578 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallForegroundService.kt +294 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallHttpClient.kt +207 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallMessagingService.kt +161 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallVideo.kt +36 -0
- package/android/src/main/java/dev/poolse/callcore/android/HandlerTimerPort.kt +42 -0
- package/android/src/main/java/dev/poolse/callcore/android/IncomingCallActivity.kt +314 -0
- package/android/src/main/java/dev/poolse/callcore/android/MessageNotifications.kt +353 -0
- package/android/src/main/java/dev/poolse/callcore/android/MissedCallNotification.kt +103 -0
- package/android/src/main/java/dev/poolse/callcore/android/RingBundle.kt +42 -0
- package/android/src/main/java/dev/poolse/callcore/android/SnapshotJson.kt +99 -0
- package/android/src/main/java/expo/modules/poolsecalls/CallLockscreen.kt +42 -0
- package/android/src/main/java/expo/modules/poolsecalls/CallPictureInPicture.kt +92 -0
- package/android/src/main/java/expo/modules/poolsecalls/PoolseCallVideoView.kt +64 -0
- package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +205 -0
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +594 -0
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitVideoSurface.kt +107 -0
- package/android/src/test/java/dev/poolse/callcore/android/CallHttpClientTest.kt +61 -0
- package/app.plugin.js +5 -0
- package/dist/index.cjs +197 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +313 -0
- package/dist/index.d.ts +313 -0
- package/dist/index.js +161 -0
- package/dist/index.js.map +1 -0
- package/expo-module.config.json +11 -0
- package/ios/Core/CallCoreRuntime.swift +543 -0
- package/ios/Core/CallHttpClient.swift +213 -0
- package/ios/Core/CallMachine.swift +394 -0
- package/ios/Core/PORTS_READY.md +93 -0
- package/ios/Core/Ports.swift +238 -0
- package/ios/Core/SnapshotEncoding.swift +122 -0
- package/ios/Module/PoolseCallVideoView.swift +70 -0
- package/ios/Module/PoolseCallsAppDelegateSubscriber.swift +16 -0
- package/ios/Module/PoolseCallsModule.swift +150 -0
- package/ios/Platform/CallCore.swift +623 -0
- package/ios/Platform/CallKitController.swift +326 -0
- package/ios/Platform/CallPictureInPicture.swift +145 -0
- package/ios/Platform/LiveKitMediaPort.swift +798 -0
- package/ios/Platform/LiveKitVideoSurface.swift +68 -0
- package/ios/Platform/MessageNotifications.swift +163 -0
- package/ios/Platform/Ringback.swift +61 -0
- package/ios/Platform/VoipPush.swift +174 -0
- package/ios/PoolseCalls.podspec +68 -0
- package/package.json +52 -3
- package/plugin/index.js +42 -0
- package/plugin/package.json +1 -0
- package/plugin/withCallDelegate.js +35 -0
- package/plugin/withLockscreenCalls.js +84 -0
- package/plugin/withNativeCallMedia.js +19 -0
- package/plugin/withPictureInPicture.js +28 -0
- package/plugin/withRingback.js +86 -0
- package/src/expo-modules-core.d.ts +16 -0
- package/src/index.ts +564 -0
- package/src/react-shims.d.ts +22 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
// @poolse/native — the React Native face of the native
|
|
2
|
+
// call core (CALL_CONTRACT.md §8). A thin, typed surface over the native
|
|
3
|
+
// module: commands in, one snapshot event out. All call logic lives in
|
|
4
|
+
// the native cores; nothing here decides anything about a call.
|
|
5
|
+
//
|
|
6
|
+
// On a platform or build without the native module (Expo Go, web,
|
|
7
|
+
// unlinked), every command is a safe no-op and the state stays idle —
|
|
8
|
+
// so a host can render against this unconditionally.
|
|
9
|
+
import { createElement, type ComponentType, type ReactElement } from 'react';
|
|
10
|
+
import { View, type ViewProps } from 'react-native';
|
|
11
|
+
import { requireNativeViewManager, requireOptionalNativeModule } from 'expo-modules-core';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A call's complete state. `null` means idle — no call. After a call
|
|
15
|
+
* ends the snapshot stays `phase: 'ended'` (with `reason`) for ~2.5 s,
|
|
16
|
+
* then becomes `null`.
|
|
17
|
+
*/
|
|
18
|
+
export interface Snapshot {
|
|
19
|
+
cv: 1;
|
|
20
|
+
callId: string;
|
|
21
|
+
conversationId: string;
|
|
22
|
+
conversationName: string | null;
|
|
23
|
+
direction: 'incoming' | 'outgoing' | 'joined';
|
|
24
|
+
/**
|
|
25
|
+
* `room` — rings nobody, joined and left at will (`startRoom`); `call`
|
|
26
|
+
* otherwise. Known once the server answered: a room being joined reads
|
|
27
|
+
* `call` while `connecting`. Absent before 0.9.0: treat as `call`.
|
|
28
|
+
*/
|
|
29
|
+
kind?: 'call' | 'room';
|
|
30
|
+
media: 'audio' | 'video';
|
|
31
|
+
phase: 'ringing_in' | 'ringing_out' | 'connecting' | 'active' | 'reconnecting' | 'ended';
|
|
32
|
+
reason?:
|
|
33
|
+
| 'left'
|
|
34
|
+
| 'finished'
|
|
35
|
+
| 'declined_all'
|
|
36
|
+
| 'busy_all'
|
|
37
|
+
| 'no_answer'
|
|
38
|
+
| 'cancelled'
|
|
39
|
+
| 'connection_lost'
|
|
40
|
+
| 'failed';
|
|
41
|
+
/** REMOTE participants only; `userId` is the LiveKit identity. */
|
|
42
|
+
participants: Array<{
|
|
43
|
+
userId: string;
|
|
44
|
+
externalId: string;
|
|
45
|
+
speaking: boolean;
|
|
46
|
+
muted: boolean;
|
|
47
|
+
/** True only with a published, subscribed, unmuted camera track (show video, not avatar). */
|
|
48
|
+
cameraOn: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Their link to the call: `lost` while they have dropped and are
|
|
51
|
+
* coming back (show "Reconnecting…"), `poor` for a weak signal.
|
|
52
|
+
* Absent before 0.11.0.
|
|
53
|
+
*/
|
|
54
|
+
connectionQuality?: ConnectionQuality;
|
|
55
|
+
}>;
|
|
56
|
+
/** The kind of output playing now — the short answer to "where is the audio". */
|
|
57
|
+
audioRoute: AudioOutputKind;
|
|
58
|
+
/**
|
|
59
|
+
* Every output the call can play through right now: always the phone
|
|
60
|
+
* (earpiece, or wired headphones in its place) and the speaker, plus
|
|
61
|
+
* each connected Bluetooth / USB device by its own name. Empty until
|
|
62
|
+
* the call's audio is up. Pass an `id` to `setAudioOutput`.
|
|
63
|
+
*/
|
|
64
|
+
audioOutputs: AudioOutput[];
|
|
65
|
+
/** The `audioOutputs` entry playing now; null before audio is up. */
|
|
66
|
+
audioOutputId: string | null;
|
|
67
|
+
mutedSelf: boolean;
|
|
68
|
+
/** True only while the local camera track is actually published and enabled. */
|
|
69
|
+
cameraOn: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* A second call ringing while this one is in progress (call waiting).
|
|
72
|
+
* Offer `answerWaiting` ("End & answer" — this call ends) and
|
|
73
|
+
* `declineWaiting` (its caller hears busy). If this call ends first,
|
|
74
|
+
* the waiting one simply becomes the ringing call. null when none;
|
|
75
|
+
* absent before 0.10.0.
|
|
76
|
+
*/
|
|
77
|
+
waiting?: WaitingCall | null;
|
|
78
|
+
/** Facing of the published local camera; absent when the camera is off. */
|
|
79
|
+
cameraFacing?: 'front' | 'back';
|
|
80
|
+
/**
|
|
81
|
+
* Your own link to the call. `poor` / `lost`: show a "weak connection"
|
|
82
|
+
* hint; `phase: 'reconnecting'` is the hard version of the same thing.
|
|
83
|
+
* Absent before 0.11.0.
|
|
84
|
+
*/
|
|
85
|
+
connectionQuality?: ConnectionQuality;
|
|
86
|
+
/**
|
|
87
|
+
* Incoming video is switched off because your connection could not
|
|
88
|
+
* carry it — the audio keeps going, and video comes back by itself
|
|
89
|
+
* once the link has been good for a few seconds. Participants read
|
|
90
|
+
* `cameraOn: false` meanwhile. Absent before 0.11.0.
|
|
91
|
+
*/
|
|
92
|
+
videoPaused?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** `good` covers good and excellent; `unknown` until the SFU has measured. */
|
|
96
|
+
export type ConnectionQuality = 'good' | 'poor' | 'lost' | 'unknown';
|
|
97
|
+
|
|
98
|
+
export type AudioOutputKind = 'earpiece' | 'speaker' | 'bluetooth' | 'headset';
|
|
99
|
+
|
|
100
|
+
/** The call waiting beside the current one. */
|
|
101
|
+
export interface WaitingCall {
|
|
102
|
+
callId: string;
|
|
103
|
+
conversationId: string | null;
|
|
104
|
+
conversationName: string | null;
|
|
105
|
+
callerName: string | null;
|
|
106
|
+
media: 'audio' | 'video';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** One place call audio can play. */
|
|
110
|
+
export interface AudioOutput {
|
|
111
|
+
/** Opaque; stable while the device stays connected. */
|
|
112
|
+
id: string;
|
|
113
|
+
kind: AudioOutputKind;
|
|
114
|
+
/**
|
|
115
|
+
* The device's own name for Bluetooth/USB ("AirPods Pro"); a plain
|
|
116
|
+
* English default for built-ins ("iPhone"/"Phone", "Speaker",
|
|
117
|
+
* "Headphones") — relabel those by `kind` to localise.
|
|
118
|
+
*/
|
|
119
|
+
name: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface ConfigureOptions {
|
|
123
|
+
/** Drawable resource NAME for the call notification's small icon. */
|
|
124
|
+
smallIcon?: string;
|
|
125
|
+
/** Ringback tone: raw resource NAME (Android); main-bundle sound name, mp3/caf/wav (iOS). */
|
|
126
|
+
ringback?: string;
|
|
127
|
+
/**
|
|
128
|
+
* iOS: the APNs environment of this build's `aps-environment`
|
|
129
|
+
* entitlement. Echoed back with the VoIP token so the server pushes to
|
|
130
|
+
* the right gateway. Ignored on Android.
|
|
131
|
+
*/
|
|
132
|
+
apnsEnvironment?: 'production' | 'sandbox';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The iOS PushKit (VoIP) token and the APNs environment it belongs to. */
|
|
136
|
+
export interface VoipToken {
|
|
137
|
+
/** Hex-encoded PushKit token. */
|
|
138
|
+
token: string;
|
|
139
|
+
environment: 'production' | 'sandbox' | string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface PlaceOptions {
|
|
143
|
+
media: 'audio' | 'video';
|
|
144
|
+
/** The user's session token — authorizes placing/joining (CALL_CONTRACT.md §3.2). */
|
|
145
|
+
sessionToken: string;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* What the user tapped on a missed-call notification: the notification
|
|
150
|
+
* itself (`open` the conversation) or its Call back button (`call_back`
|
|
151
|
+
* — place a call on the conversation with `media`).
|
|
152
|
+
*/
|
|
153
|
+
export interface CallAction {
|
|
154
|
+
type: 'open' | 'call_back';
|
|
155
|
+
conversationId: string;
|
|
156
|
+
callId: string | null;
|
|
157
|
+
media: 'audio' | 'video';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
type NativeSnapshot = { snapshot: Snapshot | null };
|
|
161
|
+
|
|
162
|
+
interface PoolseCallsNative {
|
|
163
|
+
configure(apiBaseUrl: string, options: ConfigureOptions | null): Promise<void>;
|
|
164
|
+
getCallState(): NativeSnapshot;
|
|
165
|
+
place(conversationId: string, media: string, sessionToken: string): Promise<void>;
|
|
166
|
+
join(callId: string, conversationId: string | null, sessionToken: string): Promise<void>;
|
|
167
|
+
answer(): void;
|
|
168
|
+
decline(): void;
|
|
169
|
+
hangUp(): void;
|
|
170
|
+
answerWaiting?(callId: string | null): void;
|
|
171
|
+
declineWaiting?(callId: string | null): void;
|
|
172
|
+
setMuted(muted: boolean): void;
|
|
173
|
+
setCamera(on: boolean): void;
|
|
174
|
+
switchCamera(): void;
|
|
175
|
+
setSpeaker(on: boolean): void;
|
|
176
|
+
setAudioOutput?(id: string): void;
|
|
177
|
+
callControl?(): Promise<{ callId: string; controlToken: string } | null>;
|
|
178
|
+
setPictureInPictureEnabled?(on: boolean): void;
|
|
179
|
+
isInPictureInPicture?(): boolean;
|
|
180
|
+
pictureInPictureSupported?(): boolean;
|
|
181
|
+
onRingEnded(callId: string, reason: string): void;
|
|
182
|
+
onCallFinished(callId: string, reason: string | null): void;
|
|
183
|
+
canUseFullScreenIntent(): boolean;
|
|
184
|
+
openFullScreenIntentSettings(): void;
|
|
185
|
+
setShowOnLockscreen?(enabled: boolean): void;
|
|
186
|
+
getVoipToken?(): VoipToken | null;
|
|
187
|
+
takeCallAction?(): CallAction | null;
|
|
188
|
+
setActiveConversation?(conversationId: string | null): void;
|
|
189
|
+
addListener(event: 'onCallState', cb: (payload: NativeSnapshot) => void): { remove(): void };
|
|
190
|
+
addListener(event: 'onVoipToken', cb: (payload: VoipToken) => void): { remove(): void };
|
|
191
|
+
addListener(event: 'onCallAction', cb: (payload: CallAction) => void): { remove(): void };
|
|
192
|
+
addListener(
|
|
193
|
+
event: 'onPictureInPicture',
|
|
194
|
+
cb: (payload: { active: boolean }) => void,
|
|
195
|
+
): { remove(): void };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const native = requireOptionalNativeModule<PoolseCallsNative>('PoolseCalls');
|
|
199
|
+
|
|
200
|
+
/** True when the native call core is present in this build. */
|
|
201
|
+
export const nativeCallsAvailable = native != null;
|
|
202
|
+
|
|
203
|
+
// Kept for startRoom, the one command that talks to the server from JS.
|
|
204
|
+
let apiOrigin: string | null = null;
|
|
205
|
+
|
|
206
|
+
/** Configure once, before any call can arrive. No secrets — just the API origin. */
|
|
207
|
+
export async function configure(apiBaseUrl: string, options?: ConfigureOptions): Promise<void> {
|
|
208
|
+
apiOrigin = apiBaseUrl.replace(/\/+$/, '');
|
|
209
|
+
await native?.configure(apiBaseUrl, options ?? null);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** The current snapshot — safe to read at any moment, including cold answer and before configure. */
|
|
213
|
+
export function getCallState(): Snapshot | null {
|
|
214
|
+
return native?.getCallState().snapshot ?? null;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export type Unsubscribe = () => void;
|
|
218
|
+
|
|
219
|
+
/** Subscribe to call state. Fires a full snapshot on every change. */
|
|
220
|
+
export function onCallState(cb: (snapshot: Snapshot | null) => void): Unsubscribe {
|
|
221
|
+
if (!native) return () => undefined;
|
|
222
|
+
const sub = native.addListener('onCallState', (payload) => cb(payload.snapshot));
|
|
223
|
+
return () => sub.remove();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function place(conversationId: string, options: PlaceOptions): Promise<void> {
|
|
227
|
+
return native?.place(conversationId, options.media, options.sessionToken) ?? Promise.resolve();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function join(
|
|
231
|
+
callId: string,
|
|
232
|
+
conversationId: string | null,
|
|
233
|
+
sessionToken: string,
|
|
234
|
+
): Promise<void> {
|
|
235
|
+
return native?.join(callId, conversationId, sessionToken) ?? Promise.resolve();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface StartRoomResult {
|
|
239
|
+
/** The room's call id — what the Join banner and `call:*` events carry. */
|
|
240
|
+
callId: string;
|
|
241
|
+
/** False when something was live already (a room, or a ringing call) and this joined it. */
|
|
242
|
+
created: boolean;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Start the conversation's room — a call that rings nobody (CALL_CONTRACT.md
|
|
247
|
+
* §5.6) — or join whatever is live there, then carry it on the native
|
|
248
|
+
* core like any joined call: CallKit / the call service, so it keeps
|
|
249
|
+
* going with the phone locked, and the same audio routing as a call.
|
|
250
|
+
*
|
|
251
|
+
* Others in the conversation see it through the Join banner and join it
|
|
252
|
+
* with `join`. Leaving (`hangUp`) never ends it for them; it ends once
|
|
253
|
+
* it has been empty for a short grace. `media: 'video'` makes it a video
|
|
254
|
+
* room. Rejects when the server refuses (not a member, no SFU) or
|
|
255
|
+
* before `configure`.
|
|
256
|
+
*/
|
|
257
|
+
export async function startRoom(
|
|
258
|
+
conversationId: string,
|
|
259
|
+
options: PlaceOptions,
|
|
260
|
+
): Promise<StartRoomResult> {
|
|
261
|
+
if (!native) throw new Error('The native call core is not in this build.');
|
|
262
|
+
if (!apiOrigin) throw new Error('Call configure() before startRoom().');
|
|
263
|
+
const res = await fetch(
|
|
264
|
+
`${apiOrigin}/v1/conversations/${encodeURIComponent(conversationId)}/room`,
|
|
265
|
+
{
|
|
266
|
+
method: 'POST',
|
|
267
|
+
headers: {
|
|
268
|
+
authorization: `Bearer ${options.sessionToken}`,
|
|
269
|
+
'content-type': 'application/json',
|
|
270
|
+
},
|
|
271
|
+
body: JSON.stringify({ media: options.media }),
|
|
272
|
+
},
|
|
273
|
+
);
|
|
274
|
+
const body = (await res.json().catch(() => null)) as {
|
|
275
|
+
created?: boolean;
|
|
276
|
+
call?: { id?: string };
|
|
277
|
+
error?: { message?: string };
|
|
278
|
+
} | null;
|
|
279
|
+
const callId = body?.call?.id;
|
|
280
|
+
if (!res.ok || !callId) {
|
|
281
|
+
throw new Error(body?.error?.message ?? `Couldn't start the room (${res.status}).`);
|
|
282
|
+
}
|
|
283
|
+
// The core joins with its own request: it owns the session from here,
|
|
284
|
+
// exactly as when the room is joined from the banner.
|
|
285
|
+
await native.join(callId, conversationId, options.sessionToken);
|
|
286
|
+
return { callId, created: body?.created === true };
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** Who to ring into the call — poolse user ids, your app's own (external) ids, or both. */
|
|
290
|
+
export interface RingIntoCallOptions {
|
|
291
|
+
userIds?: string[];
|
|
292
|
+
externalIds?: string[];
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Ring more of the conversation's members into the call you are on
|
|
297
|
+
* ("Add people"). Each is rung as on a fresh call — their phone rings,
|
|
298
|
+
* CallKit / full-screen — and answering puts them in this call.
|
|
299
|
+
*
|
|
300
|
+
* Resolves with the poolse user ids actually rung: anyone already in
|
|
301
|
+
* the call, still ringing, or not a member of the conversation is
|
|
302
|
+
* skipped. Rejects with no call in progress, while nobody has answered
|
|
303
|
+
* yet (the call's own ring is still out), or when the server refuses.
|
|
304
|
+
*/
|
|
305
|
+
export async function ringIntoCall(people: RingIntoCallOptions): Promise<string[]> {
|
|
306
|
+
if (!native?.callControl) throw new Error('This build cannot ring people into a call.');
|
|
307
|
+
if (!apiOrigin) throw new Error('Call configure() before ringIntoCall().');
|
|
308
|
+
const control = await native.callControl();
|
|
309
|
+
if (!control) throw new Error('There is no call in progress.');
|
|
310
|
+
const res = await fetch(`${apiOrigin}/v1/calls/${encodeURIComponent(control.callId)}/ring`, {
|
|
311
|
+
method: 'POST',
|
|
312
|
+
headers: {
|
|
313
|
+
authorization: `Bearer ${control.controlToken}`,
|
|
314
|
+
'content-type': 'application/json',
|
|
315
|
+
},
|
|
316
|
+
body: JSON.stringify({
|
|
317
|
+
user_ids: people.userIds ?? [],
|
|
318
|
+
external_ids: people.externalIds ?? [],
|
|
319
|
+
}),
|
|
320
|
+
});
|
|
321
|
+
const body = (await res.json().catch(() => null)) as {
|
|
322
|
+
rung_user_ids?: string[];
|
|
323
|
+
error?: { message?: string };
|
|
324
|
+
} | null;
|
|
325
|
+
if (!res.ok) throw new Error(body?.error?.message ?? `Couldn't ring them (${res.status}).`);
|
|
326
|
+
return body?.rung_user_ids ?? [];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export const answer = (): void => native?.answer();
|
|
330
|
+
export const decline = (): void => native?.decline();
|
|
331
|
+
export const hangUp = (): void => native?.hangUp();
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Call waiting: end the current call and answer `snapshot.waiting`.
|
|
335
|
+
* Pass its `callId`: a tap on a card for a call that is no longer the
|
|
336
|
+
* one waiting is then ignored instead of answering a different call.
|
|
337
|
+
*/
|
|
338
|
+
export const answerWaiting = (callId?: string): void => native?.answerWaiting?.(callId ?? null);
|
|
339
|
+
|
|
340
|
+
/** Call waiting: turn `snapshot.waiting` away — its caller hears busy. */
|
|
341
|
+
export const declineWaiting = (callId?: string): void => native?.declineWaiting?.(callId ?? null);
|
|
342
|
+
export const setMuted = (muted: boolean): void => native?.setMuted(muted);
|
|
343
|
+
export const setCamera = (on: boolean): void => native?.setCamera(on);
|
|
344
|
+
export const switchCamera = (): void => native?.switchCamera();
|
|
345
|
+
/** Route call audio to the loudspeaker (`true`) or back to earpiece / headset (`false`). */
|
|
346
|
+
export const setSpeaker = (on: boolean): void => native?.setSpeaker(on);
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Play call audio through one of `snapshot.audioOutputs`. The choice
|
|
350
|
+
* holds for the rest of the call, until that device disconnects or a new
|
|
351
|
+
* headset / Bluetooth device connects (which takes over, as in the
|
|
352
|
+
* phone's own dialer). Without a choice a connected headset wins, then
|
|
353
|
+
* the earpiece for voice calls or the speaker for video.
|
|
354
|
+
*/
|
|
355
|
+
export function setAudioOutput(id: string): void {
|
|
356
|
+
if (native?.setAudioOutput) native.setAudioOutput(id);
|
|
357
|
+
else native?.setSpeaker(id === 'speaker'); // an older native build
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Socket forwarding for an open app: a `call:ring_ended` seen on the
|
|
362
|
+
* socket. Idempotent with the push path — the core dedupes.
|
|
363
|
+
*/
|
|
364
|
+
export const onRingEnded = (callId: string, reason: string): void =>
|
|
365
|
+
native?.onRingEnded(callId, reason);
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Socket forwarding: `call:finished`. Pass the payload's `reason`
|
|
369
|
+
* (`finished` | `declined_all` | `no_answer` | `cancelled`) so an
|
|
370
|
+
* unanswered caller sees "Declined"/"No answer", not "Call ended".
|
|
371
|
+
* Idempotent with the `finished` push.
|
|
372
|
+
*/
|
|
373
|
+
export const onCallFinished = (callId: string, reason?: string): void =>
|
|
374
|
+
native?.onCallFinished(callId, reason ?? null);
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Android 14+: whether the app may show the full-screen ring over the
|
|
378
|
+
* lock screen. `true` on older Android and where the module is absent.
|
|
379
|
+
*/
|
|
380
|
+
export const canUseFullScreenIntent = (): boolean => native?.canUseFullScreenIntent() ?? true;
|
|
381
|
+
|
|
382
|
+
/** Open the system screen where the user grants full-screen intents (falls back to notification settings). */
|
|
383
|
+
export const openFullScreenIntentSettings = (): void => native?.openFullScreenIntentSettings();
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Android: let the app show over the lock screen while a call rings or
|
|
387
|
+
* runs — answering must never demand an unlock. Turn it off when the
|
|
388
|
+
* call ends. The activity re-applies it when the core relaunches it for
|
|
389
|
+
* a call (`poolse_launch_call`), given the host's MainActivity hook.
|
|
390
|
+
* No-op on iOS, where CallKit owns the lock screen.
|
|
391
|
+
*/
|
|
392
|
+
export function setShowOnLockscreen(enabled: boolean): void {
|
|
393
|
+
try {
|
|
394
|
+
native?.setShowOnLockscreen?.(enabled);
|
|
395
|
+
} catch {
|
|
396
|
+
// Never let a window flag take a call down.
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// ── missed-call notifications (Android) ─────────────────────────────────
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Android: the missed-call notification action the app was LAUNCHED
|
|
404
|
+
* with, once — read it on mount. `null` when the app opened any other
|
|
405
|
+
* way. The native core posts that notification itself from the push,
|
|
406
|
+
* so it works with the app closed.
|
|
407
|
+
*
|
|
408
|
+
* iOS shows missed calls as an ordinary alert push (to the token you
|
|
409
|
+
* register with `kind: 'alert'`); read its taps with your notification
|
|
410
|
+
* library — its `type` is `call_missed`, the category
|
|
411
|
+
* `poolse_missed_call`, the Call back action `call_back`.
|
|
412
|
+
*/
|
|
413
|
+
export function takeCallAction(): CallAction | null {
|
|
414
|
+
return native?.takeCallAction?.() ?? null;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** Android: a missed-call notification tapped while the app is running. */
|
|
418
|
+
export function onCallAction(cb: (action: CallAction) => void): Unsubscribe {
|
|
419
|
+
if (!native || !native.takeCallAction) return () => undefined;
|
|
420
|
+
const sub = native.addListener('onCallAction', cb);
|
|
421
|
+
return () => sub.remove();
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// ── chat notifications ─────────────────────────────────────────────────
|
|
425
|
+
|
|
426
|
+
let activeConversation: string | null = null;
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Tell the core which conversation is on screen (`null` when none, and
|
|
430
|
+
* when the app goes to the background). Its messages are not notified —
|
|
431
|
+
* the user is reading them — and opening it clears the notifications
|
|
432
|
+
* already shown for it.
|
|
433
|
+
*/
|
|
434
|
+
export function setActiveConversation(conversationId: string | null): void {
|
|
435
|
+
activeConversation = conversationId;
|
|
436
|
+
native?.setActiveConversation?.(conversationId);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* For the app's notification handler (expo-notifications'
|
|
441
|
+
* `setNotificationHandler`): `false` for a chat notification of the
|
|
442
|
+
* conversation on screen, which must not pop over the chat itself.
|
|
443
|
+
* Android never asks — the core skips those natively.
|
|
444
|
+
*/
|
|
445
|
+
export function shouldPresentMessage(data: Record<string, unknown> | undefined | null): boolean {
|
|
446
|
+
if (!data || data['type'] !== 'message') return true;
|
|
447
|
+
return data['conversation_id'] !== activeConversation;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* The conversation a tapped notification belongs to — a chat message
|
|
452
|
+
* (`type: 'message'`) or a missed call (`call_missed`) — from its data.
|
|
453
|
+
* iOS hands the tap to your notification library; Android delivers it
|
|
454
|
+
* through `takeCallAction` / `onCallAction` (type `open`).
|
|
455
|
+
*/
|
|
456
|
+
export function conversationOfNotification(
|
|
457
|
+
data: Record<string, unknown> | undefined | null,
|
|
458
|
+
): string | null {
|
|
459
|
+
if (!data) return null;
|
|
460
|
+
const type = data['type'];
|
|
461
|
+
if (type !== 'message' && type !== 'call_missed') return null;
|
|
462
|
+
return typeof data['conversation_id'] === 'string' ? data['conversation_id'] : null;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// ── VoIP push (iOS) ───────────────────────────────────────────────────
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* iOS: the current PushKit VoIP token, registered natively at launch.
|
|
469
|
+
* `null` until iOS issues one, and always on Android (FCM carries rings).
|
|
470
|
+
*/
|
|
471
|
+
export function getVoipToken(): VoipToken | null {
|
|
472
|
+
return native?.getVoipToken?.() ?? null;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/** iOS: fires whenever PushKit issues (or rotates) the VoIP token. No-op on Android. */
|
|
476
|
+
export function onVoipToken(cb: (token: VoipToken) => void): Unsubscribe {
|
|
477
|
+
if (!native || !native.getVoipToken) return () => undefined;
|
|
478
|
+
const sub = native.addListener('onVoipToken', cb);
|
|
479
|
+
return () => sub.remove();
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// ── picture-in-picture ────────────────────────────────────────────────
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Arm picture-in-picture: while on, leaving the app keeps the call's
|
|
486
|
+
* video in a floating window. Turn it on only while a video call shows
|
|
487
|
+
* someone's picture, and off otherwise.
|
|
488
|
+
*
|
|
489
|
+
* iOS (15+) floats the `<CallVideoView pictureInPicture>` that is on
|
|
490
|
+
* screen — mark the main remote picture. Android (8+) floats the whole
|
|
491
|
+
* app: draw a compact layout while `isInPictureInPicture()` (see
|
|
492
|
+
* `onPictureInPicture`). The app needs `android:supportsPictureInPicture`
|
|
493
|
+
* on its activity.
|
|
494
|
+
*/
|
|
495
|
+
export function setPictureInPictureEnabled(on: boolean): void {
|
|
496
|
+
native?.setPictureInPictureEnabled?.(on);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** Whether the floating window is open right now. */
|
|
500
|
+
export function isInPictureInPicture(): boolean {
|
|
501
|
+
return native?.isInPictureInPicture?.() ?? false;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/** Whether this device can float a call at all. */
|
|
505
|
+
export function pictureInPictureSupported(): boolean {
|
|
506
|
+
return native?.pictureInPictureSupported?.() ?? false;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** Fires when the floating window opens (`true`) and closes (`false`). */
|
|
510
|
+
export function onPictureInPicture(cb: (active: boolean) => void): Unsubscribe {
|
|
511
|
+
if (!native?.setPictureInPictureEnabled) return () => undefined;
|
|
512
|
+
const sub = native.addListener('onPictureInPicture', (payload) => cb(payload.active));
|
|
513
|
+
return () => sub.remove();
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// ── video ─────────────────────────────────────────────────────────────
|
|
517
|
+
|
|
518
|
+
export interface CallVideoViewProps extends ViewProps {
|
|
519
|
+
/** Remote participant's userId (LiveKit identity). Omit with local=true for self view. */
|
|
520
|
+
participantId?: string;
|
|
521
|
+
local?: boolean;
|
|
522
|
+
/** default: true for local front camera, false otherwise */
|
|
523
|
+
mirror?: boolean;
|
|
524
|
+
/** default 'cover' */
|
|
525
|
+
fit?: 'cover' | 'contain';
|
|
526
|
+
/**
|
|
527
|
+
* iOS: this remote picture is the one picture-in-picture floats when
|
|
528
|
+
* the app is left (`setPictureInPictureEnabled`). Mark one at a time.
|
|
529
|
+
*/
|
|
530
|
+
pictureInPicture?: boolean;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
type NativeVideoProps = CallVideoViewProps;
|
|
534
|
+
|
|
535
|
+
let nativeVideo: ComponentType<NativeVideoProps> | null | undefined;
|
|
536
|
+
|
|
537
|
+
/** Resolved lazily (first render) and only when the native module exists. */
|
|
538
|
+
function nativeVideoView(): ComponentType<NativeVideoProps> | null {
|
|
539
|
+
if (nativeVideo !== undefined) return nativeVideo;
|
|
540
|
+
nativeVideo = null;
|
|
541
|
+
if (native) {
|
|
542
|
+
try {
|
|
543
|
+
nativeVideo = requireNativeViewManager<NativeVideoProps>('PoolseCalls', 'PoolseCallVideo');
|
|
544
|
+
} catch {
|
|
545
|
+
nativeVideo = null; // an older native build without the view
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return nativeVideo;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* A participant's camera (or, with `local`, your own), rendered natively
|
|
553
|
+
* by the call core. Shows nothing (stays transparent) while that camera
|
|
554
|
+
* is off — draw the avatar from the snapshot's `cameraOn` underneath.
|
|
555
|
+
* Without the native module it renders an empty View.
|
|
556
|
+
*/
|
|
557
|
+
export function CallVideoView(props: CallVideoViewProps): ReactElement | null {
|
|
558
|
+
const Native = nativeVideoView();
|
|
559
|
+
if (!Native) {
|
|
560
|
+
const { participantId: _p, local: _l, mirror: _m, fit: _f, pictureInPicture: _pip, ...rest } = props;
|
|
561
|
+
return createElement(View, rest);
|
|
562
|
+
}
|
|
563
|
+
return createElement(Native, props);
|
|
564
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Minimal ambient declarations for the React / React Native surface this
|
|
2
|
+
// package touches, so it type-checks without either installed in the
|
|
3
|
+
// monorepo (the host app always supplies both). The emitted
|
|
4
|
+
// `dist/index.d.ts` imports the REAL types by module name, so consumers
|
|
5
|
+
// type-check against their own React Native — these shims never ship.
|
|
6
|
+
declare module 'react' {
|
|
7
|
+
export interface ReactElement {
|
|
8
|
+
type: unknown;
|
|
9
|
+
props: unknown;
|
|
10
|
+
key: string | null;
|
|
11
|
+
}
|
|
12
|
+
export type ComponentType<P = object> = (props: P) => ReactElement | null;
|
|
13
|
+
export function createElement(type: unknown, props?: unknown, ...children: unknown[]): ReactElement;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module 'react-native' {
|
|
17
|
+
export interface ViewProps {
|
|
18
|
+
style?: unknown;
|
|
19
|
+
testID?: string;
|
|
20
|
+
}
|
|
21
|
+
export const View: unknown;
|
|
22
|
+
}
|