@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.
Files changed (66) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +206 -0
  3. package/README.md +116 -2
  4. package/android/build.gradle +58 -0
  5. package/android/consumer-rules.pro +11 -0
  6. package/android/src/main/AndroidManifest.xml +46 -0
  7. package/android/src/main/java/dev/poolse/callcore/CallCoreRuntime.kt +540 -0
  8. package/android/src/main/java/dev/poolse/callcore/CallMachine.kt +492 -0
  9. package/android/src/main/java/dev/poolse/callcore/Ports.kt +132 -0
  10. package/android/src/main/java/dev/poolse/callcore/android/AndroidRingSurface.kt +383 -0
  11. package/android/src/main/java/dev/poolse/callcore/android/CallActionReceiver.kt +45 -0
  12. package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +578 -0
  13. package/android/src/main/java/dev/poolse/callcore/android/CallForegroundService.kt +294 -0
  14. package/android/src/main/java/dev/poolse/callcore/android/CallHttpClient.kt +207 -0
  15. package/android/src/main/java/dev/poolse/callcore/android/CallMessagingService.kt +161 -0
  16. package/android/src/main/java/dev/poolse/callcore/android/CallVideo.kt +36 -0
  17. package/android/src/main/java/dev/poolse/callcore/android/HandlerTimerPort.kt +42 -0
  18. package/android/src/main/java/dev/poolse/callcore/android/IncomingCallActivity.kt +314 -0
  19. package/android/src/main/java/dev/poolse/callcore/android/MessageNotifications.kt +353 -0
  20. package/android/src/main/java/dev/poolse/callcore/android/MissedCallNotification.kt +103 -0
  21. package/android/src/main/java/dev/poolse/callcore/android/RingBundle.kt +42 -0
  22. package/android/src/main/java/dev/poolse/callcore/android/SnapshotJson.kt +99 -0
  23. package/android/src/main/java/expo/modules/poolsecalls/CallLockscreen.kt +42 -0
  24. package/android/src/main/java/expo/modules/poolsecalls/CallPictureInPicture.kt +92 -0
  25. package/android/src/main/java/expo/modules/poolsecalls/PoolseCallVideoView.kt +64 -0
  26. package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +205 -0
  27. package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +594 -0
  28. package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitVideoSurface.kt +107 -0
  29. package/android/src/test/java/dev/poolse/callcore/android/CallHttpClientTest.kt +61 -0
  30. package/app.plugin.js +5 -0
  31. package/dist/index.cjs +197 -0
  32. package/dist/index.cjs.map +1 -0
  33. package/dist/index.d.cts +313 -0
  34. package/dist/index.d.ts +313 -0
  35. package/dist/index.js +161 -0
  36. package/dist/index.js.map +1 -0
  37. package/expo-module.config.json +11 -0
  38. package/ios/Core/CallCoreRuntime.swift +543 -0
  39. package/ios/Core/CallHttpClient.swift +213 -0
  40. package/ios/Core/CallMachine.swift +394 -0
  41. package/ios/Core/PORTS_READY.md +93 -0
  42. package/ios/Core/Ports.swift +238 -0
  43. package/ios/Core/SnapshotEncoding.swift +122 -0
  44. package/ios/Module/PoolseCallVideoView.swift +70 -0
  45. package/ios/Module/PoolseCallsAppDelegateSubscriber.swift +16 -0
  46. package/ios/Module/PoolseCallsModule.swift +150 -0
  47. package/ios/Platform/CallCore.swift +623 -0
  48. package/ios/Platform/CallKitController.swift +326 -0
  49. package/ios/Platform/CallPictureInPicture.swift +145 -0
  50. package/ios/Platform/LiveKitMediaPort.swift +798 -0
  51. package/ios/Platform/LiveKitVideoSurface.swift +68 -0
  52. package/ios/Platform/MessageNotifications.swift +163 -0
  53. package/ios/Platform/Ringback.swift +61 -0
  54. package/ios/Platform/VoipPush.swift +174 -0
  55. package/ios/PoolseCalls.podspec +68 -0
  56. package/package.json +52 -3
  57. package/plugin/index.js +42 -0
  58. package/plugin/package.json +1 -0
  59. package/plugin/withCallDelegate.js +35 -0
  60. package/plugin/withLockscreenCalls.js +84 -0
  61. package/plugin/withNativeCallMedia.js +19 -0
  62. package/plugin/withPictureInPicture.js +28 -0
  63. package/plugin/withRingback.js +86 -0
  64. package/src/expo-modules-core.d.ts +16 -0
  65. package/src/index.ts +564 -0
  66. package/src/react-shims.d.ts +22 -0
@@ -0,0 +1,61 @@
1
+ package dev.poolse.callcore.android
2
+
3
+ import dev.poolse.callcore.CallSessionBundle
4
+ import dev.poolse.callcore.HttpResult
5
+ import org.junit.Assert.assertEquals
6
+ import org.junit.Assert.assertTrue
7
+ import org.junit.Test
8
+
9
+ /**
10
+ * The HTTP classifier/parser, without a network: status + body →
11
+ * HttpResult exactly as CALL_CONTRACT.md §4 maps them.
12
+ */
13
+ class CallHttpClientTest {
14
+
15
+ private val full = """
16
+ {"cv":1,"created":false,
17
+ "call":{"id":"c1","conversation_id":"v1","conversation_name":"Boiler","media":"video"},
18
+ "livekit":{"url":"wss://sfu","token":"lk-new"},
19
+ "control_token":"ctl-new"}
20
+ """.trimIndent()
21
+
22
+ private val current = CallSessionBundle(
23
+ callId = "c1", conversationId = "v1", conversationName = "Boiler", media = "audio",
24
+ created = true, livekitUrl = "wss://old", livekitToken = "lk-old", controlToken = "ctl-old",
25
+ )
26
+
27
+ @Test fun `full bundle parses (answer, join, place and now reconnect)`() {
28
+ val r = CallHttpClient.classify(200, full, current) as HttpResult.Ok
29
+ assertEquals("c1", r.bundle.callId)
30
+ assertEquals("lk-new", r.bundle.livekitToken)
31
+ assertEquals("ctl-new", r.bundle.controlToken)
32
+ assertEquals("video", r.bundle.media)
33
+ assertEquals(false, r.bundle.created)
34
+ }
35
+
36
+ @Test fun `old reconnect shape is applied onto the current bundle`() {
37
+ val r = CallHttpClient.classify(200, """{"cv":1,"livekit":{"url":"wss://sfu2","token":"lk-2"}}""", current)
38
+ as HttpResult.Ok
39
+ assertEquals(current.copy(livekitUrl = "wss://sfu2", livekitToken = "lk-2"), r.bundle)
40
+ }
41
+
42
+ @Test fun `unparseable 2xx is a failure, not a retry`() {
43
+ assertTrue(CallHttpClient.classify(200, "<html>", null) is HttpResult.Failed)
44
+ assertTrue(CallHttpClient.classify(200, """{"livekit":{"token":"x"}}""", null) is HttpResult.Failed)
45
+ }
46
+
47
+ @Test fun `error envelope code is read`() {
48
+ val r = CallHttpClient.classify(401, """{"error":{"code":"grant_spent","message":"…"}}""")
49
+ assertEquals(HttpResult.AuthFailed("grant_spent"), r)
50
+ assertEquals(HttpResult.AuthFailed("http_403"), CallHttpClient.classify(403, null))
51
+ }
52
+
53
+ @Test fun `status mapping`() {
54
+ assertEquals(HttpResult.Gone, CallHttpClient.classify(410, null))
55
+ assertEquals(HttpResult.Gone, CallHttpClient.classify(404, """{"error":{"code":"no_call"}}"""))
56
+ assertEquals(HttpResult.Failed("http_503"), CallHttpClient.classify(503, null))
57
+ assertEquals(HttpResult.Timeout, CallHttpClient.classify(502, null))
58
+ assertEquals(HttpResult.Timeout, CallHttpClient.classify(429, null))
59
+ assertEquals(HttpResult.Failed("bad"), CallHttpClient.classify(422, """{"error":{"code":"bad"}}"""))
60
+ }
61
+ }
package/app.plugin.js ADDED
@@ -0,0 +1,5 @@
1
+ // Expo resolves `@poolse/native` in app.json to this file.
2
+ // The plugin itself is CommonJS (plugin/), like Expo's own.
3
+ import plugin from './plugin/index.js';
4
+
5
+ export default plugin;
package/dist/index.cjs ADDED
@@ -0,0 +1,197 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var reactNative = require('react-native');
5
+ var expoModulesCore = require('expo-modules-core');
6
+
7
+ // src/index.ts
8
+ var native = expoModulesCore.requireOptionalNativeModule("PoolseCalls");
9
+ var nativeCallsAvailable = native != null;
10
+ var apiOrigin = null;
11
+ async function configure(apiBaseUrl, options) {
12
+ apiOrigin = apiBaseUrl.replace(/\/+$/, "");
13
+ await native?.configure(apiBaseUrl, options ?? null);
14
+ }
15
+ function getCallState() {
16
+ return native?.getCallState().snapshot ?? null;
17
+ }
18
+ function onCallState(cb) {
19
+ if (!native) return () => void 0;
20
+ const sub = native.addListener("onCallState", (payload) => cb(payload.snapshot));
21
+ return () => sub.remove();
22
+ }
23
+ function place(conversationId, options) {
24
+ return native?.place(conversationId, options.media, options.sessionToken) ?? Promise.resolve();
25
+ }
26
+ function join(callId, conversationId, sessionToken) {
27
+ return native?.join(callId, conversationId, sessionToken) ?? Promise.resolve();
28
+ }
29
+ async function startRoom(conversationId, options) {
30
+ if (!native) throw new Error("The native call core is not in this build.");
31
+ if (!apiOrigin) throw new Error("Call configure() before startRoom().");
32
+ const res = await fetch(
33
+ `${apiOrigin}/v1/conversations/${encodeURIComponent(conversationId)}/room`,
34
+ {
35
+ method: "POST",
36
+ headers: {
37
+ authorization: `Bearer ${options.sessionToken}`,
38
+ "content-type": "application/json"
39
+ },
40
+ body: JSON.stringify({ media: options.media })
41
+ }
42
+ );
43
+ const body = await res.json().catch(() => null);
44
+ const callId = body?.call?.id;
45
+ if (!res.ok || !callId) {
46
+ throw new Error(body?.error?.message ?? `Couldn't start the room (${res.status}).`);
47
+ }
48
+ await native.join(callId, conversationId, options.sessionToken);
49
+ return { callId, created: body?.created === true };
50
+ }
51
+ async function ringIntoCall(people) {
52
+ if (!native?.callControl) throw new Error("This build cannot ring people into a call.");
53
+ if (!apiOrigin) throw new Error("Call configure() before ringIntoCall().");
54
+ const control = await native.callControl();
55
+ if (!control) throw new Error("There is no call in progress.");
56
+ const res = await fetch(`${apiOrigin}/v1/calls/${encodeURIComponent(control.callId)}/ring`, {
57
+ method: "POST",
58
+ headers: {
59
+ authorization: `Bearer ${control.controlToken}`,
60
+ "content-type": "application/json"
61
+ },
62
+ body: JSON.stringify({
63
+ user_ids: people.userIds ?? [],
64
+ external_ids: people.externalIds ?? []
65
+ })
66
+ });
67
+ const body = await res.json().catch(() => null);
68
+ if (!res.ok) throw new Error(body?.error?.message ?? `Couldn't ring them (${res.status}).`);
69
+ return body?.rung_user_ids ?? [];
70
+ }
71
+ var answer = () => native?.answer();
72
+ var decline = () => native?.decline();
73
+ var hangUp = () => native?.hangUp();
74
+ var answerWaiting = (callId) => native?.answerWaiting?.(callId ?? null);
75
+ var declineWaiting = (callId) => native?.declineWaiting?.(callId ?? null);
76
+ var setMuted = (muted) => native?.setMuted(muted);
77
+ var setCamera = (on) => native?.setCamera(on);
78
+ var switchCamera = () => native?.switchCamera();
79
+ var setSpeaker = (on) => native?.setSpeaker(on);
80
+ function setAudioOutput(id) {
81
+ if (native?.setAudioOutput) native.setAudioOutput(id);
82
+ else native?.setSpeaker(id === "speaker");
83
+ }
84
+ var onRingEnded = (callId, reason) => native?.onRingEnded(callId, reason);
85
+ var onCallFinished = (callId, reason) => native?.onCallFinished(callId, reason ?? null);
86
+ var canUseFullScreenIntent = () => native?.canUseFullScreenIntent() ?? true;
87
+ var openFullScreenIntentSettings = () => native?.openFullScreenIntentSettings();
88
+ function setShowOnLockscreen(enabled) {
89
+ try {
90
+ native?.setShowOnLockscreen?.(enabled);
91
+ } catch {
92
+ }
93
+ }
94
+ function takeCallAction() {
95
+ return native?.takeCallAction?.() ?? null;
96
+ }
97
+ function onCallAction(cb) {
98
+ if (!native || !native.takeCallAction) return () => void 0;
99
+ const sub = native.addListener("onCallAction", cb);
100
+ return () => sub.remove();
101
+ }
102
+ var activeConversation = null;
103
+ function setActiveConversation(conversationId) {
104
+ activeConversation = conversationId;
105
+ native?.setActiveConversation?.(conversationId);
106
+ }
107
+ function shouldPresentMessage(data) {
108
+ if (!data || data["type"] !== "message") return true;
109
+ return data["conversation_id"] !== activeConversation;
110
+ }
111
+ function conversationOfNotification(data) {
112
+ if (!data) return null;
113
+ const type = data["type"];
114
+ if (type !== "message" && type !== "call_missed") return null;
115
+ return typeof data["conversation_id"] === "string" ? data["conversation_id"] : null;
116
+ }
117
+ function getVoipToken() {
118
+ return native?.getVoipToken?.() ?? null;
119
+ }
120
+ function onVoipToken(cb) {
121
+ if (!native || !native.getVoipToken) return () => void 0;
122
+ const sub = native.addListener("onVoipToken", cb);
123
+ return () => sub.remove();
124
+ }
125
+ function setPictureInPictureEnabled(on) {
126
+ native?.setPictureInPictureEnabled?.(on);
127
+ }
128
+ function isInPictureInPicture() {
129
+ return native?.isInPictureInPicture?.() ?? false;
130
+ }
131
+ function pictureInPictureSupported() {
132
+ return native?.pictureInPictureSupported?.() ?? false;
133
+ }
134
+ function onPictureInPicture(cb) {
135
+ if (!native?.setPictureInPictureEnabled) return () => void 0;
136
+ const sub = native.addListener("onPictureInPicture", (payload) => cb(payload.active));
137
+ return () => sub.remove();
138
+ }
139
+ var nativeVideo;
140
+ function nativeVideoView() {
141
+ if (nativeVideo !== void 0) return nativeVideo;
142
+ nativeVideo = null;
143
+ if (native) {
144
+ try {
145
+ nativeVideo = expoModulesCore.requireNativeViewManager("PoolseCalls", "PoolseCallVideo");
146
+ } catch {
147
+ nativeVideo = null;
148
+ }
149
+ }
150
+ return nativeVideo;
151
+ }
152
+ function CallVideoView(props) {
153
+ const Native = nativeVideoView();
154
+ if (!Native) {
155
+ const { participantId: _p, local: _l, mirror: _m, fit: _f, pictureInPicture: _pip, ...rest } = props;
156
+ return react.createElement(reactNative.View, rest);
157
+ }
158
+ return react.createElement(Native, props);
159
+ }
160
+
161
+ exports.CallVideoView = CallVideoView;
162
+ exports.answer = answer;
163
+ exports.answerWaiting = answerWaiting;
164
+ exports.canUseFullScreenIntent = canUseFullScreenIntent;
165
+ exports.configure = configure;
166
+ exports.conversationOfNotification = conversationOfNotification;
167
+ exports.decline = decline;
168
+ exports.declineWaiting = declineWaiting;
169
+ exports.getCallState = getCallState;
170
+ exports.getVoipToken = getVoipToken;
171
+ exports.hangUp = hangUp;
172
+ exports.isInPictureInPicture = isInPictureInPicture;
173
+ exports.join = join;
174
+ exports.nativeCallsAvailable = nativeCallsAvailable;
175
+ exports.onCallAction = onCallAction;
176
+ exports.onCallFinished = onCallFinished;
177
+ exports.onCallState = onCallState;
178
+ exports.onPictureInPicture = onPictureInPicture;
179
+ exports.onRingEnded = onRingEnded;
180
+ exports.onVoipToken = onVoipToken;
181
+ exports.openFullScreenIntentSettings = openFullScreenIntentSettings;
182
+ exports.pictureInPictureSupported = pictureInPictureSupported;
183
+ exports.place = place;
184
+ exports.ringIntoCall = ringIntoCall;
185
+ exports.setActiveConversation = setActiveConversation;
186
+ exports.setAudioOutput = setAudioOutput;
187
+ exports.setCamera = setCamera;
188
+ exports.setMuted = setMuted;
189
+ exports.setPictureInPictureEnabled = setPictureInPictureEnabled;
190
+ exports.setShowOnLockscreen = setShowOnLockscreen;
191
+ exports.setSpeaker = setSpeaker;
192
+ exports.shouldPresentMessage = shouldPresentMessage;
193
+ exports.startRoom = startRoom;
194
+ exports.switchCamera = switchCamera;
195
+ exports.takeCallAction = takeCallAction;
196
+ //# sourceMappingURL=index.cjs.map
197
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["requireOptionalNativeModule","requireNativeViewManager","createElement","View"],"mappings":";;;;;;;AAqMA,IAAM,MAAA,GAASA,4CAA+C,aAAa,CAAA;AAGpE,IAAM,uBAAuB,MAAA,IAAU;AAG9C,IAAI,SAAA,GAA2B,IAAA;AAG/B,eAAsB,SAAA,CAAU,YAAoB,OAAA,EAA2C;AAC7F,EAAA,SAAA,GAAY,UAAA,CAAW,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA;AACzC,EAAA,MAAM,MAAA,EAAQ,SAAA,CAAU,UAAA,EAAY,OAAA,IAAW,IAAI,CAAA;AACrD;AAGO,SAAS,YAAA,GAAgC;AAC9C,EAAA,OAAO,MAAA,EAAQ,YAAA,EAAa,CAAE,QAAA,IAAY,IAAA;AAC5C;AAKO,SAAS,YAAY,EAAA,EAAsD;AAChF,EAAA,IAAI,CAAC,MAAA,EAAQ,OAAO,MAAM,MAAA;AAC1B,EAAA,MAAM,GAAA,GAAM,OAAO,WAAA,CAAY,aAAA,EAAe,CAAC,OAAA,KAAY,EAAA,CAAG,OAAA,CAAQ,QAAQ,CAAC,CAAA;AAC/E,EAAA,OAAO,MAAM,IAAI,MAAA,EAAO;AAC1B;AAEO,SAAS,KAAA,CAAM,gBAAwB,OAAA,EAAsC;AAClF,EAAA,OAAO,MAAA,EAAQ,MA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AAAA,EACjC;AACA,EAAA,OAAOD,mBAAA,CAAc,QAAQ,KAAK,CAAA;AACpC","file":"index.cjs","sourcesContent":["// @poolse/native — the React Native face of the native\n// call core (CALL_CONTRACT.md §8). A thin, typed surface over the native\n// module: commands in, one snapshot event out. All call logic lives in\n// the native cores; nothing here decides anything about a call.\n//\n// On a platform or build without the native module (Expo Go, web,\n// unlinked), every command is a safe no-op and the state stays idle —\n// so a host can render against this unconditionally.\nimport { createElement, type ComponentType, type ReactElement } from 'react';\nimport { View, type ViewProps } from 'react-native';\nimport { requireNativeViewManager, requireOptionalNativeModule } from 'expo-modules-core';\n\n/**\n * A call's complete state. `null` means idle — no call. After a call\n * ends the snapshot stays `phase: 'ended'` (with `reason`) for ~2.5 s,\n * then becomes `null`.\n */\nexport interface Snapshot {\n cv: 1;\n callId: string;\n conversationId: string;\n conversationName: string | null;\n direction: 'incoming' | 'outgoing' | 'joined';\n /**\n * `room` — rings nobody, joined and left at will (`startRoom`); `call`\n * otherwise. Known once the server answered: a room being joined reads\n * `call` while `connecting`. Absent before 0.9.0: treat as `call`.\n */\n kind?: 'call' | 'room';\n media: 'audio' | 'video';\n phase: 'ringing_in' | 'ringing_out' | 'connecting' | 'active' | 'reconnecting' | 'ended';\n reason?:\n | 'left'\n | 'finished'\n | 'declined_all'\n | 'busy_all'\n | 'no_answer'\n | 'cancelled'\n | 'connection_lost'\n | 'failed';\n /** REMOTE participants only; `userId` is the LiveKit identity. */\n participants: Array<{\n userId: string;\n externalId: string;\n speaking: boolean;\n muted: boolean;\n /** True only with a published, subscribed, unmuted camera track (show video, not avatar). */\n cameraOn: boolean;\n /**\n * Their link to the call: `lost` while they have dropped and are\n * coming back (show \"Reconnecting…\"), `poor` for a weak signal.\n * Absent before 0.11.0.\n */\n connectionQuality?: ConnectionQuality;\n }>;\n /** The kind of output playing now — the short answer to \"where is the audio\". */\n audioRoute: AudioOutputKind;\n /**\n * Every output the call can play through right now: always the phone\n * (earpiece, or wired headphones in its place) and the speaker, plus\n * each connected Bluetooth / USB device by its own name. Empty until\n * the call's audio is up. Pass an `id` to `setAudioOutput`.\n */\n audioOutputs: AudioOutput[];\n /** The `audioOutputs` entry playing now; null before audio is up. */\n audioOutputId: string | null;\n mutedSelf: boolean;\n /** True only while the local camera track is actually published and enabled. */\n cameraOn: boolean;\n /**\n * A second call ringing while this one is in progress (call waiting).\n * Offer `answerWaiting` (\"End & answer\" — this call ends) and\n * `declineWaiting` (its caller hears busy). If this call ends first,\n * the waiting one simply becomes the ringing call. null when none;\n * absent before 0.10.0.\n */\n waiting?: WaitingCall | null;\n /** Facing of the published local camera; absent when the camera is off. */\n cameraFacing?: 'front' | 'back';\n /**\n * Your own link to the call. `poor` / `lost`: show a \"weak connection\"\n * hint; `phase: 'reconnecting'` is the hard version of the same thing.\n * Absent before 0.11.0.\n */\n connectionQuality?: ConnectionQuality;\n /**\n * Incoming video is switched off because your connection could not\n * carry it — the audio keeps going, and video comes back by itself\n * once the link has been good for a few seconds. Participants read\n * `cameraOn: false` meanwhile. Absent before 0.11.0.\n */\n videoPaused?: boolean;\n}\n\n/** `good` covers good and excellent; `unknown` until the SFU has measured. */\nexport type ConnectionQuality = 'good' | 'poor' | 'lost' | 'unknown';\n\nexport type AudioOutputKind = 'earpiece' | 'speaker' | 'bluetooth' | 'headset';\n\n/** The call waiting beside the current one. */\nexport interface WaitingCall {\n callId: string;\n conversationId: string | null;\n conversationName: string | null;\n callerName: string | null;\n media: 'audio' | 'video';\n}\n\n/** One place call audio can play. */\nexport interface AudioOutput {\n /** Opaque; stable while the device stays connected. */\n id: string;\n kind: AudioOutputKind;\n /**\n * The device's own name for Bluetooth/USB (\"AirPods Pro\"); a plain\n * English default for built-ins (\"iPhone\"/\"Phone\", \"Speaker\",\n * \"Headphones\") — relabel those by `kind` to localise.\n */\n name: string;\n}\n\nexport interface ConfigureOptions {\n /** Drawable resource NAME for the call notification's small icon. */\n smallIcon?: string;\n /** Ringback tone: raw resource NAME (Android); main-bundle sound name, mp3/caf/wav (iOS). */\n ringback?: string;\n /**\n * iOS: the APNs environment of this build's `aps-environment`\n * entitlement. Echoed back with the VoIP token so the server pushes to\n * the right gateway. Ignored on Android.\n */\n apnsEnvironment?: 'production' | 'sandbox';\n}\n\n/** The iOS PushKit (VoIP) token and the APNs environment it belongs to. */\nexport interface VoipToken {\n /** Hex-encoded PushKit token. */\n token: string;\n environment: 'production' | 'sandbox' | string;\n}\n\nexport interface PlaceOptions {\n media: 'audio' | 'video';\n /** The user's session token — authorizes placing/joining (CALL_CONTRACT.md §3.2). */\n sessionToken: string;\n}\n\n/**\n * What the user tapped on a missed-call notification: the notification\n * itself (`open` the conversation) or its Call back button (`call_back`\n * — place a call on the conversation with `media`).\n */\nexport interface CallAction {\n type: 'open' | 'call_back';\n conversationId: string;\n callId: string | null;\n media: 'audio' | 'video';\n}\n\ntype NativeSnapshot = { snapshot: Snapshot | null };\n\ninterface PoolseCallsNative {\n configure(apiBaseUrl: string, options: ConfigureOptions | null): Promise<void>;\n getCallState(): NativeSnapshot;\n place(conversationId: string, media: string, sessionToken: string): Promise<void>;\n join(callId: string, conversationId: string | null, sessionToken: string): Promise<void>;\n answer(): void;\n decline(): void;\n hangUp(): void;\n answerWaiting?(callId: string | null): void;\n declineWaiting?(callId: string | null): void;\n setMuted(muted: boolean): void;\n setCamera(on: boolean): void;\n switchCamera(): void;\n setSpeaker(on: boolean): void;\n setAudioOutput?(id: string): void;\n callControl?(): Promise<{ callId: string; controlToken: string } | null>;\n setPictureInPictureEnabled?(on: boolean): void;\n isInPictureInPicture?(): boolean;\n pictureInPictureSupported?(): boolean;\n onRingEnded(callId: string, reason: string): void;\n onCallFinished(callId: string, reason: string | null): void;\n canUseFullScreenIntent(): boolean;\n openFullScreenIntentSettings(): void;\n setShowOnLockscreen?(enabled: boolean): void;\n getVoipToken?(): VoipToken | null;\n takeCallAction?(): CallAction | null;\n setActiveConversation?(conversationId: string | null): void;\n addListener(event: 'onCallState', cb: (payload: NativeSnapshot) => void): { remove(): void };\n addListener(event: 'onVoipToken', cb: (payload: VoipToken) => void): { remove(): void };\n addListener(event: 'onCallAction', cb: (payload: CallAction) => void): { remove(): void };\n addListener(\n event: 'onPictureInPicture',\n cb: (payload: { active: boolean }) => void,\n ): { remove(): void };\n}\n\nconst native = requireOptionalNativeModule<PoolseCallsNative>('PoolseCalls');\n\n/** True when the native call core is present in this build. */\nexport const nativeCallsAvailable = native != null;\n\n// Kept for startRoom, the one command that talks to the server from JS.\nlet apiOrigin: string | null = null;\n\n/** Configure once, before any call can arrive. No secrets — just the API origin. */\nexport async function configure(apiBaseUrl: string, options?: ConfigureOptions): Promise<void> {\n apiOrigin = apiBaseUrl.replace(/\\/+$/, '');\n await native?.configure(apiBaseUrl, options ?? null);\n}\n\n/** The current snapshot — safe to read at any moment, including cold answer and before configure. */\nexport function getCallState(): Snapshot | null {\n return native?.getCallState().snapshot ?? null;\n}\n\nexport type Unsubscribe = () => void;\n\n/** Subscribe to call state. Fires a full snapshot on every change. */\nexport function onCallState(cb: (snapshot: Snapshot | null) => void): Unsubscribe {\n if (!native) return () => undefined;\n const sub = native.addListener('onCallState', (payload) => cb(payload.snapshot));\n return () => sub.remove();\n}\n\nexport function place(conversationId: string, options: PlaceOptions): Promise<void> {\n return native?.place(conversationId, options.media, options.sessionToken) ?? Promise.resolve();\n}\n\nexport function join(\n callId: string,\n conversationId: string | null,\n sessionToken: string,\n): Promise<void> {\n return native?.join(callId, conversationId, sessionToken) ?? Promise.resolve();\n}\n\nexport interface StartRoomResult {\n /** The room's call id — what the Join banner and `call:*` events carry. */\n callId: string;\n /** False when something was live already (a room, or a ringing call) and this joined it. */\n created: boolean;\n}\n\n/**\n * Start the conversation's room — a call that rings nobody (CALL_CONTRACT.md\n * §5.6) — or join whatever is live there, then carry it on the native\n * core like any joined call: CallKit / the call service, so it keeps\n * going with the phone locked, and the same audio routing as a call.\n *\n * Others in the conversation see it through the Join banner and join it\n * with `join`. Leaving (`hangUp`) never ends it for them; it ends once\n * it has been empty for a short grace. `media: 'video'` makes it a video\n * room. Rejects when the server refuses (not a member, no SFU) or\n * before `configure`.\n */\nexport async function startRoom(\n conversationId: string,\n options: PlaceOptions,\n): Promise<StartRoomResult> {\n if (!native) throw new Error('The native call core is not in this build.');\n if (!apiOrigin) throw new Error('Call configure() before startRoom().');\n const res = await fetch(\n `${apiOrigin}/v1/conversations/${encodeURIComponent(conversationId)}/room`,\n {\n method: 'POST',\n headers: {\n authorization: `Bearer ${options.sessionToken}`,\n 'content-type': 'application/json',\n },\n body: JSON.stringify({ media: options.media }),\n },\n );\n const body = (await res.json().catch(() => null)) as {\n created?: boolean;\n call?: { id?: string };\n error?: { message?: string };\n } | null;\n const callId = body?.call?.id;\n if (!res.ok || !callId) {\n throw new Error(body?.error?.message ?? `Couldn't start the room (${res.status}).`);\n }\n // The core joins with its own request: it owns the session from here,\n // exactly as when the room is joined from the banner.\n await native.join(callId, conversationId, options.sessionToken);\n return { callId, created: body?.created === true };\n}\n\n/** Who to ring into the call — poolse user ids, your app's own (external) ids, or both. */\nexport interface RingIntoCallOptions {\n userIds?: string[];\n externalIds?: string[];\n}\n\n/**\n * Ring more of the conversation's members into the call you are on\n * (\"Add people\"). Each is rung as on a fresh call — their phone rings,\n * CallKit / full-screen — and answering puts them in this call.\n *\n * Resolves with the poolse user ids actually rung: anyone already in\n * the call, still ringing, or not a member of the conversation is\n * skipped. Rejects with no call in progress, while nobody has answered\n * yet (the call's own ring is still out), or when the server refuses.\n */\nexport async function ringIntoCall(people: RingIntoCallOptions): Promise<string[]> {\n if (!native?.callControl) throw new Error('This build cannot ring people into a call.');\n if (!apiOrigin) throw new Error('Call configure() before ringIntoCall().');\n const control = await native.callControl();\n if (!control) throw new Error('There is no call in progress.');\n const res = await fetch(`${apiOrigin}/v1/calls/${encodeURIComponent(control.callId)}/ring`, {\n method: 'POST',\n headers: {\n authorization: `Bearer ${control.controlToken}`,\n 'content-type': 'application/json',\n },\n body: JSON.stringify({\n user_ids: people.userIds ?? [],\n external_ids: people.externalIds ?? [],\n }),\n });\n const body = (await res.json().catch(() => null)) as {\n rung_user_ids?: string[];\n error?: { message?: string };\n } | null;\n if (!res.ok) throw new Error(body?.error?.message ?? `Couldn't ring them (${res.status}).`);\n return body?.rung_user_ids ?? [];\n}\n\nexport const answer = (): void => native?.answer();\nexport const decline = (): void => native?.decline();\nexport const hangUp = (): void => native?.hangUp();\n\n/**\n * Call waiting: end the current call and answer `snapshot.waiting`.\n * Pass its `callId`: a tap on a card for a call that is no longer the\n * one waiting is then ignored instead of answering a different call.\n */\nexport const answerWaiting = (callId?: string): void => native?.answerWaiting?.(callId ?? null);\n\n/** Call waiting: turn `snapshot.waiting` away — its caller hears busy. */\nexport const declineWaiting = (callId?: string): void => native?.declineWaiting?.(callId ?? null);\nexport const setMuted = (muted: boolean): void => native?.setMuted(muted);\nexport const setCamera = (on: boolean): void => native?.setCamera(on);\nexport const switchCamera = (): void => native?.switchCamera();\n/** Route call audio to the loudspeaker (`true`) or back to earpiece / headset (`false`). */\nexport const setSpeaker = (on: boolean): void => native?.setSpeaker(on);\n\n/**\n * Play call audio through one of `snapshot.audioOutputs`. The choice\n * holds for the rest of the call, until that device disconnects or a new\n * headset / Bluetooth device connects (which takes over, as in the\n * phone's own dialer). Without a choice a connected headset wins, then\n * the earpiece for voice calls or the speaker for video.\n */\nexport function setAudioOutput(id: string): void {\n if (native?.setAudioOutput) native.setAudioOutput(id);\n else native?.setSpeaker(id === 'speaker'); // an older native build\n}\n\n/**\n * Socket forwarding for an open app: a `call:ring_ended` seen on the\n * socket. Idempotent with the push path — the core dedupes.\n */\nexport const onRingEnded = (callId: string, reason: string): void =>\n native?.onRingEnded(callId, reason);\n\n/**\n * Socket forwarding: `call:finished`. Pass the payload's `reason`\n * (`finished` | `declined_all` | `no_answer` | `cancelled`) so an\n * unanswered caller sees \"Declined\"/\"No answer\", not \"Call ended\".\n * Idempotent with the `finished` push.\n */\nexport const onCallFinished = (callId: string, reason?: string): void =>\n native?.onCallFinished(callId, reason ?? null);\n\n/**\n * Android 14+: whether the app may show the full-screen ring over the\n * lock screen. `true` on older Android and where the module is absent.\n */\nexport const canUseFullScreenIntent = (): boolean => native?.canUseFullScreenIntent() ?? true;\n\n/** Open the system screen where the user grants full-screen intents (falls back to notification settings). */\nexport const openFullScreenIntentSettings = (): void => native?.openFullScreenIntentSettings();\n\n/**\n * Android: let the app show over the lock screen while a call rings or\n * runs — answering must never demand an unlock. Turn it off when the\n * call ends. The activity re-applies it when the core relaunches it for\n * a call (`poolse_launch_call`), given the host's MainActivity hook.\n * No-op on iOS, where CallKit owns the lock screen.\n */\nexport function setShowOnLockscreen(enabled: boolean): void {\n try {\n native?.setShowOnLockscreen?.(enabled);\n } catch {\n // Never let a window flag take a call down.\n }\n}\n\n// ── missed-call notifications (Android) ─────────────────────────────────\n\n/**\n * Android: the missed-call notification action the app was LAUNCHED\n * with, once — read it on mount. `null` when the app opened any other\n * way. The native core posts that notification itself from the push,\n * so it works with the app closed.\n *\n * iOS shows missed calls as an ordinary alert push (to the token you\n * register with `kind: 'alert'`); read its taps with your notification\n * library — its `type` is `call_missed`, the category\n * `poolse_missed_call`, the Call back action `call_back`.\n */\nexport function takeCallAction(): CallAction | null {\n return native?.takeCallAction?.() ?? null;\n}\n\n/** Android: a missed-call notification tapped while the app is running. */\nexport function onCallAction(cb: (action: CallAction) => void): Unsubscribe {\n if (!native || !native.takeCallAction) return () => undefined;\n const sub = native.addListener('onCallAction', cb);\n return () => sub.remove();\n}\n\n// ── chat notifications ─────────────────────────────────────────────────\n\nlet activeConversation: string | null = null;\n\n/**\n * Tell the core which conversation is on screen (`null` when none, and\n * when the app goes to the background). Its messages are not notified —\n * the user is reading them — and opening it clears the notifications\n * already shown for it.\n */\nexport function setActiveConversation(conversationId: string | null): void {\n activeConversation = conversationId;\n native?.setActiveConversation?.(conversationId);\n}\n\n/**\n * For the app's notification handler (expo-notifications'\n * `setNotificationHandler`): `false` for a chat notification of the\n * conversation on screen, which must not pop over the chat itself.\n * Android never asks — the core skips those natively.\n */\nexport function shouldPresentMessage(data: Record<string, unknown> | undefined | null): boolean {\n if (!data || data['type'] !== 'message') return true;\n return data['conversation_id'] !== activeConversation;\n}\n\n/**\n * The conversation a tapped notification belongs to — a chat message\n * (`type: 'message'`) or a missed call (`call_missed`) — from its data.\n * iOS hands the tap to your notification library; Android delivers it\n * through `takeCallAction` / `onCallAction` (type `open`).\n */\nexport function conversationOfNotification(\n data: Record<string, unknown> | undefined | null,\n): string | null {\n if (!data) return null;\n const type = data['type'];\n if (type !== 'message' && type !== 'call_missed') return null;\n return typeof data['conversation_id'] === 'string' ? data['conversation_id'] : null;\n}\n\n// ── VoIP push (iOS) ───────────────────────────────────────────────────\n\n/**\n * iOS: the current PushKit VoIP token, registered natively at launch.\n * `null` until iOS issues one, and always on Android (FCM carries rings).\n */\nexport function getVoipToken(): VoipToken | null {\n return native?.getVoipToken?.() ?? null;\n}\n\n/** iOS: fires whenever PushKit issues (or rotates) the VoIP token. No-op on Android. */\nexport function onVoipToken(cb: (token: VoipToken) => void): Unsubscribe {\n if (!native || !native.getVoipToken) return () => undefined;\n const sub = native.addListener('onVoipToken', cb);\n return () => sub.remove();\n}\n\n// ── picture-in-picture ────────────────────────────────────────────────\n\n/**\n * Arm picture-in-picture: while on, leaving the app keeps the call's\n * video in a floating window. Turn it on only while a video call shows\n * someone's picture, and off otherwise.\n *\n * iOS (15+) floats the `<CallVideoView pictureInPicture>` that is on\n * screen — mark the main remote picture. Android (8+) floats the whole\n * app: draw a compact layout while `isInPictureInPicture()` (see\n * `onPictureInPicture`). The app needs `android:supportsPictureInPicture`\n * on its activity.\n */\nexport function setPictureInPictureEnabled(on: boolean): void {\n native?.setPictureInPictureEnabled?.(on);\n}\n\n/** Whether the floating window is open right now. */\nexport function isInPictureInPicture(): boolean {\n return native?.isInPictureInPicture?.() ?? false;\n}\n\n/** Whether this device can float a call at all. */\nexport function pictureInPictureSupported(): boolean {\n return native?.pictureInPictureSupported?.() ?? false;\n}\n\n/** Fires when the floating window opens (`true`) and closes (`false`). */\nexport function onPictureInPicture(cb: (active: boolean) => void): Unsubscribe {\n if (!native?.setPictureInPictureEnabled) return () => undefined;\n const sub = native.addListener('onPictureInPicture', (payload) => cb(payload.active));\n return () => sub.remove();\n}\n\n// ── video ─────────────────────────────────────────────────────────────\n\nexport interface CallVideoViewProps extends ViewProps {\n /** Remote participant's userId (LiveKit identity). Omit with local=true for self view. */\n participantId?: string;\n local?: boolean;\n /** default: true for local front camera, false otherwise */\n mirror?: boolean;\n /** default 'cover' */\n fit?: 'cover' | 'contain';\n /**\n * iOS: this remote picture is the one picture-in-picture floats when\n * the app is left (`setPictureInPictureEnabled`). Mark one at a time.\n */\n pictureInPicture?: boolean;\n}\n\ntype NativeVideoProps = CallVideoViewProps;\n\nlet nativeVideo: ComponentType<NativeVideoProps> | null | undefined;\n\n/** Resolved lazily (first render) and only when the native module exists. */\nfunction nativeVideoView(): ComponentType<NativeVideoProps> | null {\n if (nativeVideo !== undefined) return nativeVideo;\n nativeVideo = null;\n if (native) {\n try {\n nativeVideo = requireNativeViewManager<NativeVideoProps>('PoolseCalls', 'PoolseCallVideo');\n } catch {\n nativeVideo = null; // an older native build without the view\n }\n }\n return nativeVideo;\n}\n\n/**\n * A participant's camera (or, with `local`, your own), rendered natively\n * by the call core. Shows nothing (stays transparent) while that camera\n * is off — draw the avatar from the snapshot's `cameraOn` underneath.\n * Without the native module it renders an empty View.\n */\nexport function CallVideoView(props: CallVideoViewProps): ReactElement | null {\n const Native = nativeVideoView();\n if (!Native) {\n const { participantId: _p, local: _l, mirror: _m, fit: _f, pictureInPicture: _pip, ...rest } = props;\n return createElement(View, rest);\n }\n return createElement(Native, props);\n}\n"]}
@@ -0,0 +1,313 @@
1
+ import { ReactElement } from 'react';
2
+ import { ViewProps } from 'react-native';
3
+
4
+ /**
5
+ * A call's complete state. `null` means idle — no call. After a call
6
+ * ends the snapshot stays `phase: 'ended'` (with `reason`) for ~2.5 s,
7
+ * then becomes `null`.
8
+ */
9
+ interface Snapshot {
10
+ cv: 1;
11
+ callId: string;
12
+ conversationId: string;
13
+ conversationName: string | null;
14
+ direction: 'incoming' | 'outgoing' | 'joined';
15
+ /**
16
+ * `room` — rings nobody, joined and left at will (`startRoom`); `call`
17
+ * otherwise. Known once the server answered: a room being joined reads
18
+ * `call` while `connecting`. Absent before 0.9.0: treat as `call`.
19
+ */
20
+ kind?: 'call' | 'room';
21
+ media: 'audio' | 'video';
22
+ phase: 'ringing_in' | 'ringing_out' | 'connecting' | 'active' | 'reconnecting' | 'ended';
23
+ reason?: 'left' | 'finished' | 'declined_all' | 'busy_all' | 'no_answer' | 'cancelled' | 'connection_lost' | 'failed';
24
+ /** REMOTE participants only; `userId` is the LiveKit identity. */
25
+ participants: Array<{
26
+ userId: string;
27
+ externalId: string;
28
+ speaking: boolean;
29
+ muted: boolean;
30
+ /** True only with a published, subscribed, unmuted camera track (show video, not avatar). */
31
+ cameraOn: boolean;
32
+ /**
33
+ * Their link to the call: `lost` while they have dropped and are
34
+ * coming back (show "Reconnecting…"), `poor` for a weak signal.
35
+ * Absent before 0.11.0.
36
+ */
37
+ connectionQuality?: ConnectionQuality;
38
+ }>;
39
+ /** The kind of output playing now — the short answer to "where is the audio". */
40
+ audioRoute: AudioOutputKind;
41
+ /**
42
+ * Every output the call can play through right now: always the phone
43
+ * (earpiece, or wired headphones in its place) and the speaker, plus
44
+ * each connected Bluetooth / USB device by its own name. Empty until
45
+ * the call's audio is up. Pass an `id` to `setAudioOutput`.
46
+ */
47
+ audioOutputs: AudioOutput[];
48
+ /** The `audioOutputs` entry playing now; null before audio is up. */
49
+ audioOutputId: string | null;
50
+ mutedSelf: boolean;
51
+ /** True only while the local camera track is actually published and enabled. */
52
+ cameraOn: boolean;
53
+ /**
54
+ * A second call ringing while this one is in progress (call waiting).
55
+ * Offer `answerWaiting` ("End & answer" — this call ends) and
56
+ * `declineWaiting` (its caller hears busy). If this call ends first,
57
+ * the waiting one simply becomes the ringing call. null when none;
58
+ * absent before 0.10.0.
59
+ */
60
+ waiting?: WaitingCall | null;
61
+ /** Facing of the published local camera; absent when the camera is off. */
62
+ cameraFacing?: 'front' | 'back';
63
+ /**
64
+ * Your own link to the call. `poor` / `lost`: show a "weak connection"
65
+ * hint; `phase: 'reconnecting'` is the hard version of the same thing.
66
+ * Absent before 0.11.0.
67
+ */
68
+ connectionQuality?: ConnectionQuality;
69
+ /**
70
+ * Incoming video is switched off because your connection could not
71
+ * carry it — the audio keeps going, and video comes back by itself
72
+ * once the link has been good for a few seconds. Participants read
73
+ * `cameraOn: false` meanwhile. Absent before 0.11.0.
74
+ */
75
+ videoPaused?: boolean;
76
+ }
77
+ /** `good` covers good and excellent; `unknown` until the SFU has measured. */
78
+ type ConnectionQuality = 'good' | 'poor' | 'lost' | 'unknown';
79
+ type AudioOutputKind = 'earpiece' | 'speaker' | 'bluetooth' | 'headset';
80
+ /** The call waiting beside the current one. */
81
+ interface WaitingCall {
82
+ callId: string;
83
+ conversationId: string | null;
84
+ conversationName: string | null;
85
+ callerName: string | null;
86
+ media: 'audio' | 'video';
87
+ }
88
+ /** One place call audio can play. */
89
+ interface AudioOutput {
90
+ /** Opaque; stable while the device stays connected. */
91
+ id: string;
92
+ kind: AudioOutputKind;
93
+ /**
94
+ * The device's own name for Bluetooth/USB ("AirPods Pro"); a plain
95
+ * English default for built-ins ("iPhone"/"Phone", "Speaker",
96
+ * "Headphones") — relabel those by `kind` to localise.
97
+ */
98
+ name: string;
99
+ }
100
+ interface ConfigureOptions {
101
+ /** Drawable resource NAME for the call notification's small icon. */
102
+ smallIcon?: string;
103
+ /** Ringback tone: raw resource NAME (Android); main-bundle sound name, mp3/caf/wav (iOS). */
104
+ ringback?: string;
105
+ /**
106
+ * iOS: the APNs environment of this build's `aps-environment`
107
+ * entitlement. Echoed back with the VoIP token so the server pushes to
108
+ * the right gateway. Ignored on Android.
109
+ */
110
+ apnsEnvironment?: 'production' | 'sandbox';
111
+ }
112
+ /** The iOS PushKit (VoIP) token and the APNs environment it belongs to. */
113
+ interface VoipToken {
114
+ /** Hex-encoded PushKit token. */
115
+ token: string;
116
+ environment: 'production' | 'sandbox' | string;
117
+ }
118
+ interface PlaceOptions {
119
+ media: 'audio' | 'video';
120
+ /** The user's session token — authorizes placing/joining (CALL_CONTRACT.md §3.2). */
121
+ sessionToken: string;
122
+ }
123
+ /**
124
+ * What the user tapped on a missed-call notification: the notification
125
+ * itself (`open` the conversation) or its Call back button (`call_back`
126
+ * — place a call on the conversation with `media`).
127
+ */
128
+ interface CallAction {
129
+ type: 'open' | 'call_back';
130
+ conversationId: string;
131
+ callId: string | null;
132
+ media: 'audio' | 'video';
133
+ }
134
+ /** True when the native call core is present in this build. */
135
+ declare const nativeCallsAvailable: boolean;
136
+ /** Configure once, before any call can arrive. No secrets — just the API origin. */
137
+ declare function configure(apiBaseUrl: string, options?: ConfigureOptions): Promise<void>;
138
+ /** The current snapshot — safe to read at any moment, including cold answer and before configure. */
139
+ declare function getCallState(): Snapshot | null;
140
+ type Unsubscribe = () => void;
141
+ /** Subscribe to call state. Fires a full snapshot on every change. */
142
+ declare function onCallState(cb: (snapshot: Snapshot | null) => void): Unsubscribe;
143
+ declare function place(conversationId: string, options: PlaceOptions): Promise<void>;
144
+ declare function join(callId: string, conversationId: string | null, sessionToken: string): Promise<void>;
145
+ interface StartRoomResult {
146
+ /** The room's call id — what the Join banner and `call:*` events carry. */
147
+ callId: string;
148
+ /** False when something was live already (a room, or a ringing call) and this joined it. */
149
+ created: boolean;
150
+ }
151
+ /**
152
+ * Start the conversation's room — a call that rings nobody (CALL_CONTRACT.md
153
+ * §5.6) — or join whatever is live there, then carry it on the native
154
+ * core like any joined call: CallKit / the call service, so it keeps
155
+ * going with the phone locked, and the same audio routing as a call.
156
+ *
157
+ * Others in the conversation see it through the Join banner and join it
158
+ * with `join`. Leaving (`hangUp`) never ends it for them; it ends once
159
+ * it has been empty for a short grace. `media: 'video'` makes it a video
160
+ * room. Rejects when the server refuses (not a member, no SFU) or
161
+ * before `configure`.
162
+ */
163
+ declare function startRoom(conversationId: string, options: PlaceOptions): Promise<StartRoomResult>;
164
+ /** Who to ring into the call — poolse user ids, your app's own (external) ids, or both. */
165
+ interface RingIntoCallOptions {
166
+ userIds?: string[];
167
+ externalIds?: string[];
168
+ }
169
+ /**
170
+ * Ring more of the conversation's members into the call you are on
171
+ * ("Add people"). Each is rung as on a fresh call — their phone rings,
172
+ * CallKit / full-screen — and answering puts them in this call.
173
+ *
174
+ * Resolves with the poolse user ids actually rung: anyone already in
175
+ * the call, still ringing, or not a member of the conversation is
176
+ * skipped. Rejects with no call in progress, while nobody has answered
177
+ * yet (the call's own ring is still out), or when the server refuses.
178
+ */
179
+ declare function ringIntoCall(people: RingIntoCallOptions): Promise<string[]>;
180
+ declare const answer: () => void;
181
+ declare const decline: () => void;
182
+ declare const hangUp: () => void;
183
+ /**
184
+ * Call waiting: end the current call and answer `snapshot.waiting`.
185
+ * Pass its `callId`: a tap on a card for a call that is no longer the
186
+ * one waiting is then ignored instead of answering a different call.
187
+ */
188
+ declare const answerWaiting: (callId?: string) => void;
189
+ /** Call waiting: turn `snapshot.waiting` away — its caller hears busy. */
190
+ declare const declineWaiting: (callId?: string) => void;
191
+ declare const setMuted: (muted: boolean) => void;
192
+ declare const setCamera: (on: boolean) => void;
193
+ declare const switchCamera: () => void;
194
+ /** Route call audio to the loudspeaker (`true`) or back to earpiece / headset (`false`). */
195
+ declare const setSpeaker: (on: boolean) => void;
196
+ /**
197
+ * Play call audio through one of `snapshot.audioOutputs`. The choice
198
+ * holds for the rest of the call, until that device disconnects or a new
199
+ * headset / Bluetooth device connects (which takes over, as in the
200
+ * phone's own dialer). Without a choice a connected headset wins, then
201
+ * the earpiece for voice calls or the speaker for video.
202
+ */
203
+ declare function setAudioOutput(id: string): void;
204
+ /**
205
+ * Socket forwarding for an open app: a `call:ring_ended` seen on the
206
+ * socket. Idempotent with the push path — the core dedupes.
207
+ */
208
+ declare const onRingEnded: (callId: string, reason: string) => void;
209
+ /**
210
+ * Socket forwarding: `call:finished`. Pass the payload's `reason`
211
+ * (`finished` | `declined_all` | `no_answer` | `cancelled`) so an
212
+ * unanswered caller sees "Declined"/"No answer", not "Call ended".
213
+ * Idempotent with the `finished` push.
214
+ */
215
+ declare const onCallFinished: (callId: string, reason?: string) => void;
216
+ /**
217
+ * Android 14+: whether the app may show the full-screen ring over the
218
+ * lock screen. `true` on older Android and where the module is absent.
219
+ */
220
+ declare const canUseFullScreenIntent: () => boolean;
221
+ /** Open the system screen where the user grants full-screen intents (falls back to notification settings). */
222
+ declare const openFullScreenIntentSettings: () => void;
223
+ /**
224
+ * Android: let the app show over the lock screen while a call rings or
225
+ * runs — answering must never demand an unlock. Turn it off when the
226
+ * call ends. The activity re-applies it when the core relaunches it for
227
+ * a call (`poolse_launch_call`), given the host's MainActivity hook.
228
+ * No-op on iOS, where CallKit owns the lock screen.
229
+ */
230
+ declare function setShowOnLockscreen(enabled: boolean): void;
231
+ /**
232
+ * Android: the missed-call notification action the app was LAUNCHED
233
+ * with, once — read it on mount. `null` when the app opened any other
234
+ * way. The native core posts that notification itself from the push,
235
+ * so it works with the app closed.
236
+ *
237
+ * iOS shows missed calls as an ordinary alert push (to the token you
238
+ * register with `kind: 'alert'`); read its taps with your notification
239
+ * library — its `type` is `call_missed`, the category
240
+ * `poolse_missed_call`, the Call back action `call_back`.
241
+ */
242
+ declare function takeCallAction(): CallAction | null;
243
+ /** Android: a missed-call notification tapped while the app is running. */
244
+ declare function onCallAction(cb: (action: CallAction) => void): Unsubscribe;
245
+ /**
246
+ * Tell the core which conversation is on screen (`null` when none, and
247
+ * when the app goes to the background). Its messages are not notified —
248
+ * the user is reading them — and opening it clears the notifications
249
+ * already shown for it.
250
+ */
251
+ declare function setActiveConversation(conversationId: string | null): void;
252
+ /**
253
+ * For the app's notification handler (expo-notifications'
254
+ * `setNotificationHandler`): `false` for a chat notification of the
255
+ * conversation on screen, which must not pop over the chat itself.
256
+ * Android never asks — the core skips those natively.
257
+ */
258
+ declare function shouldPresentMessage(data: Record<string, unknown> | undefined | null): boolean;
259
+ /**
260
+ * The conversation a tapped notification belongs to — a chat message
261
+ * (`type: 'message'`) or a missed call (`call_missed`) — from its data.
262
+ * iOS hands the tap to your notification library; Android delivers it
263
+ * through `takeCallAction` / `onCallAction` (type `open`).
264
+ */
265
+ declare function conversationOfNotification(data: Record<string, unknown> | undefined | null): string | null;
266
+ /**
267
+ * iOS: the current PushKit VoIP token, registered natively at launch.
268
+ * `null` until iOS issues one, and always on Android (FCM carries rings).
269
+ */
270
+ declare function getVoipToken(): VoipToken | null;
271
+ /** iOS: fires whenever PushKit issues (or rotates) the VoIP token. No-op on Android. */
272
+ declare function onVoipToken(cb: (token: VoipToken) => void): Unsubscribe;
273
+ /**
274
+ * Arm picture-in-picture: while on, leaving the app keeps the call's
275
+ * video in a floating window. Turn it on only while a video call shows
276
+ * someone's picture, and off otherwise.
277
+ *
278
+ * iOS (15+) floats the `<CallVideoView pictureInPicture>` that is on
279
+ * screen — mark the main remote picture. Android (8+) floats the whole
280
+ * app: draw a compact layout while `isInPictureInPicture()` (see
281
+ * `onPictureInPicture`). The app needs `android:supportsPictureInPicture`
282
+ * on its activity.
283
+ */
284
+ declare function setPictureInPictureEnabled(on: boolean): void;
285
+ /** Whether the floating window is open right now. */
286
+ declare function isInPictureInPicture(): boolean;
287
+ /** Whether this device can float a call at all. */
288
+ declare function pictureInPictureSupported(): boolean;
289
+ /** Fires when the floating window opens (`true`) and closes (`false`). */
290
+ declare function onPictureInPicture(cb: (active: boolean) => void): Unsubscribe;
291
+ interface CallVideoViewProps extends ViewProps {
292
+ /** Remote participant's userId (LiveKit identity). Omit with local=true for self view. */
293
+ participantId?: string;
294
+ local?: boolean;
295
+ /** default: true for local front camera, false otherwise */
296
+ mirror?: boolean;
297
+ /** default 'cover' */
298
+ fit?: 'cover' | 'contain';
299
+ /**
300
+ * iOS: this remote picture is the one picture-in-picture floats when
301
+ * the app is left (`setPictureInPictureEnabled`). Mark one at a time.
302
+ */
303
+ pictureInPicture?: boolean;
304
+ }
305
+ /**
306
+ * A participant's camera (or, with `local`, your own), rendered natively
307
+ * by the call core. Shows nothing (stays transparent) while that camera
308
+ * is off — draw the avatar from the snapshot's `cameraOn` underneath.
309
+ * Without the native module it renders an empty View.
310
+ */
311
+ declare function CallVideoView(props: CallVideoViewProps): ReactElement | null;
312
+
313
+ export { type AudioOutput, type AudioOutputKind, type CallAction, CallVideoView, type CallVideoViewProps, type ConfigureOptions, type ConnectionQuality, type PlaceOptions, type RingIntoCallOptions, type Snapshot, type StartRoomResult, type Unsubscribe, type VoipToken, type WaitingCall, answer, answerWaiting, canUseFullScreenIntent, configure, conversationOfNotification, decline, declineWaiting, getCallState, getVoipToken, hangUp, isInPictureInPicture, join, nativeCallsAvailable, onCallAction, onCallFinished, onCallState, onPictureInPicture, onRingEnded, onVoipToken, openFullScreenIntentSettings, pictureInPictureSupported, place, ringIntoCall, setActiveConversation, setAudioOutput, setCamera, setMuted, setPictureInPictureEnabled, setShowOnLockscreen, setSpeaker, shouldPresentMessage, startRoom, switchCamera, takeCallAction };