@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 -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AGJ,SAAS,eAAA,GAA0D;AACjE,EAAA,IAAI,WAAA,KAAgB,QAAW,OAAO,WAAA;AACtC,EAAA,WAAA,GAAc,IAAA;AACd,EAAA,IAAI,MAAA,EAAQ;AACV,IAAA,IAAI;AACF,MAAA,WAAA,GAAc,wBAAA,CAA2C,eAAe,iBAAiB,CAAA;AAAA,IAC3F,CAAA,CAAA,MAAQ;AACN,MAAA,WAAA,GAAc,IAAA;AAAA,IAChB;AAAA,EACF;AACA,EAAA,OAAO,WAAA;AACT;AAQO,SAAS,cAAc,KAAA,EAAgD;AAC5E,EAAA,MAAM,SAAS,eAAA,EAAgB;AAC/B,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM;AAAA,MACJ,aAAA,EAAe,EAAA;AAAA,MACf,KAAA,EAAO,EAAA;AAAA,MACP,MAAA,EAAQ,EAAA;AAAA,MACR,GAAA,EAAK,EAAA;AAAA,MACL,MAAA,EAAQ,EAAA;AAAA,MACR,gBAAA,EAAkB,IAAA;AAAA,MAClB,GAAG;AAAA,KACL,GAAI,KAAA;AACJ,IAAA,OAAO,aAAA,CAAc,MAAM,IAAI,CAAA;AAAA,EACjC;AACA,EAAA,OAAO,aAAA,CAAc,QAAQ,KAAK,CAAA;AACpC","file":"index.js","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 * Sharing their screen: draw it with `<CallVideoView source=\"screen\">`,\n * large and with `fit=\"contain\"`. Absent before 3.2.\n */\n screenSharing?: 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 /** You are sharing your screen. Absent before 3.2. */\n screenSharing?: 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 * Incoming ringtone, overriding the config plugin's `ringtone` (leave it\n * out to use the plugin's, or the system ringtone without one).\n * Android: raw resource NAME (`ring` for `res/raw/ring.ogg`), played by\n * the module. iOS: a main-bundle sound CallKit plays — `ring.caf`, or the\n * base name looked up as caf/aiff/aif/wav; 30 s or shorter. Persisted, so\n * a ring that wakes a closed app uses it too. A name that is not in the\n * app rings with the system ringtone.\n */\n ringtone?: string;\n /**\n * Android: the full-screen incoming-call screen. Each field overrides the\n * config plugin's `incomingCall` option; leave one out to keep the\n * plugin's (or the built-in) value. Persisted for closed-app rings.\n * Ignored on iOS, where CallKit draws the call screen.\n */\n incomingCall?: IncomingCallOptions;\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/** Android's full-screen incoming call: its look, or the app's own activity instead. */\nexport interface IncomingCallOptions {\n /** `#RRGGBB` / `#AARRGGBB`: the glow, the pulsing ring and the initials disc (and the notification tint). */\n accentColor?: string;\n /** `#RRGGBB`: the screen's ground. A light one switches the text to dark. Default `#0B0B14`. */\n backgroundColor?: string;\n /**\n * The caller's picture, as a URL template: `{externalId}` (your app's id\n * for the caller) and `{userId}` (the poolse user id) are filled in,\n * URL-encoded — e.g. `https://cdn.example.com/avatars/{externalId}.jpg`.\n * Loaded off the main thread; the initials show until it loads, or if it\n * fails. A ring push's own `caller_avatar_url` wins over the template.\n */\n avatarUrl?: string;\n /**\n * Fully qualified class name of your own Activity (declared in your\n * manifest) to launch instead of the built-in screen. It receives the\n * `PoolseIncomingCall.EXTRA_*` extras and answers / declines through\n * `dev.poolse.callcore.android.PoolseIncomingCall` (see the README).\n * A leading `.` is relative to the application id.\n */\n activity?: string;\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\n/**\n * A Reply or Mark as read the user did from a chat notification, after\n * the native core sent it (or gave up). The server has already posted\n * the reply and marked the conversation read; use this to refresh what\n * the app shows (insert the message, drop the unread count) without\n * waiting for the socket, or to tell the user a reply did not go out.\n */\nexport interface NotificationActionResult {\n action: 'reply' | 'mark_read';\n conversationId: string;\n /** Whether the server accepted it. */\n ok: boolean;\n /** Reply only: what the user typed. */\n text?: string;\n /** Reply only: the idempotency id sent with it — the message's id once posted. */\n clientId?: string;\n /** Reply, `ok` only: the posted message's id (equals `clientId`). */\n messageId?: string;\n /**\n * When not `ok`: the server's error code (`unauthorized`,\n * `device_signed_out`, `user_blocked`, `forbidden`, `not_found`,\n * `mau_cap_exceeded`, `validation_failed`, `rate_limited`), or\n * `network`, `no_grant` (the push carried no reply grant),\n * `not_configured` (never `configure`d), `http_<status>`.\n */\n error?: string;\n /** The HTTP status when the server answered with an error. */\n status?: number;\n /** When it finished, epoch ms. */\n at: number;\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 screenShareSupported?(): boolean;\n startScreenShare?(): Promise<boolean>;\n stopScreenShare?(): 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 takeNotificationActions?(): NotificationActionResult[];\n observeNotificationActions?(on: boolean): 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: 'onNotificationAction',\n cb: (payload: NotificationActionResult) => void,\n ): { 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\n/**\n * Whether this build can share the screen in a call: Android with the\n * LiveKit media engine; iOS when the app was built with the config\n * plugin's `screenShare` option (the broadcast extension). Every build\n * shows other people's screens.\n */\nexport const screenShareSupported = (): boolean => native?.screenShareSupported?.() ?? false;\n\n/**\n * Share the screen. Android asks the user first (the system's \"Start\n * recording or casting?\" prompt) and resolves `false` when they say no.\n * iOS shows the system's broadcast sheet and resolves `true` once it is\n * up; the user still has to tap Start Broadcast. Either way it resolves\n * `false` when the build cannot share, and `snapshot.screenSharing`\n * turns true only once the screen is actually going out. Stopping from\n * the system notification (Android) or the status bar (iOS) ends it the\n * same way.\n */\nexport const startScreenShare = async (): Promise<boolean> =>\n (await native?.startScreenShare?.()) ?? false;\n\nexport const stopScreenShare = (): void => native?.stopScreenShare?.();\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/**\n * Reply and Mark as read from a chat notification are handled natively —\n * from the lock screen, with the app closed — using the grant the push\n * carried and the API origin given to `configure` (which persists it).\n * This fires once each finishes while the app is running. Read the ones\n * that finished while it was not with `takeNotificationActions` on mount.\n */\nexport function onNotificationAction(cb: (result: NotificationActionResult) => void): Unsubscribe {\n if (!native?.takeNotificationActions) return () => undefined;\n const sub = native.addListener('onNotificationAction', cb);\n if (actionObservers++ === 0) native.observeNotificationActions?.(true);\n let removed = false;\n return () => {\n if (removed) return;\n removed = true;\n sub.remove();\n if (--actionObservers === 0) native?.observeNotificationActions?.(false);\n };\n}\n\n// Native queues results until someone listens for them specifically.\nlet actionObservers = 0;\n\n/** `onNotificationAction`, replies only. */\nexport function onNotificationReply(cb: (result: NotificationActionResult) => void): Unsubscribe {\n return onNotificationAction((result) => {\n if (result.action === 'reply') cb(result);\n });\n}\n\n/**\n * The notification actions that finished while no `onNotificationAction`\n * listener was attached (usually: the app was not running), oldest\n * first, each returned once. Up to the last 50 are kept.\n */\nexport function takeNotificationActions(): NotificationActionResult[] {\n return native?.takeNotificationActions?.() ?? [];\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 * `camera` (default), or `screen`: the participant's shared screen\n * (with `local`, your own). A screen is never mirrored; draw it with\n * `fit=\"contain\"` so nothing is cropped.\n */\n source?: 'camera' | 'screen';\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 {\n participantId: _p,\n local: _l,\n mirror: _m,\n fit: _f,\n source: _s,\n pictureInPicture: _pip,\n ...rest\n } = props;\n return createElement(View, rest);\n }\n return createElement(Native, props);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAwNO,IAAM,iBAAA,GAAoB;AA2IjC,IAAM,MAAA,GAAS,4BAA+C,aAAa,CAAA;AAGpE,IAAM,uBAAuB,MAAA,IAAU;AAG9C,IAAI,SAAA,GAA2B,IAAA;AAS/B,eAAsB,SAAA,CACpB,qBACA,OAAA,EACe;AACf,EAAA,IAAI,OAAO,wBAAwB,QAAA,EAAU;AAC3C,IAAA,MAAM,MAAA,EAAQ,SAAA,CAAU,EAAA,EAAI,mBAAA,IAAuB,IAAI,CAAA;AACvD,IAAA;AAAA,EACF;AACA,EAAA,SAAA,GAAY,mBAAA,CAAoB,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA;AAClD,EAAA,MAAM,MAAA,EAAQ,SAAA,CAAU,mBAAA,EAAqB,OAAA,IAAW,IAAI,CAAA;AAC9D;AAIA,IAAM,SAAA,GAAY,yBAAA;AAYlB,eAAsB,UAAU,MAAA,EAAmC;AACjE,EAAA,IAAI,CAAC,SAAA,CAAU,IAAA,CAAK,MAAA,CAAO,EAAE,CAAA;AAC3B,IAAA,MAAM,IAAI,MAAM,CAAA,sBAAA,EAAyB,IAAA,CAAK,UAAU,MAAA,CAAO,EAAE,CAAC,CAAA,CAAA,CAAG,CAAA;AACvE,EAAA,IAAI,CAAC,qBAAA,CAAsB,IAAA,CAAK,MAAA,CAAO,UAAU,CAAA;AAC/C,IAAA,MAAM,IAAI,MAAM,wCAAwC,CAAA;AAC1D,EAAA,MAAM,KAAA,GAAoB,EAAE,EAAA,EAAI,MAAA,CAAO,EAAA,EAAI,UAAA,EAAY,MAAA,CAAO,UAAA,CAAW,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA,EAAE;AAC7F,EAAA,IAAI,MAAA,CAAO,QAAA,EAAU,KAAA,CAAM,QAAA,GAAW,MAAA,CAAO,QAAA;A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AA;AACtC,EAAA,WAAA,GAAc,IAAA;AACd,EAAA,IAAI,MAAA,EAAQ;AACV,IAAA,IAAI;AACF,MAAA,WAAA,GAAc,wBAAA,CAA2C,eAAe,iBAAiB,CAAA;AAAA,IAC3F,CAAA,CAAA,MAAQ;AACN,MAAA,WAAA,GAAc,IAAA;AAAA,IAChB;AAAA,EACF;AACA,EAAA,OAAO,WAAA;AACT;AAQO,SAAS,cAAc,KAAA,EAAgD;AAC5E,EAAA,MAAM,SAAS,eAAA,EAAgB;AAC/B,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM;AAAA,MACJ,aAAA,EAAe,EAAA;AAAA,MACf,KAAA,EAAO,EAAA;AAAA,MACP,MAAA,EAAQ,EAAA;AAAA,MACR,GAAA,EAAK,EAAA;AAAA,MACL,MAAA,EAAQ,EAAA;AAAA,MACR,gBAAA,EAAkB,IAAA;AAAA,MAClB,GAAG;AAAA,KACL,GAAI,KAAA;AACJ,IAAA,OAAO,aAAA,CAAc,MAAM,IAAI,CAAA;AAAA,EACjC;AACA,EAAA,OAAO,aAAA,CAAc,QAAQ,KAAK,CAAA;AACpC","file":"index.js","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 * Sharing their screen: draw it with `<CallVideoView source=\"screen\">`,\n * large and with `fit=\"contain\"`. Absent before 3.2.\n */\n screenSharing?: 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 /** You are sharing your screen. Absent before 3.2. */\n screenSharing?: boolean;\n /**\n * The server (workspace) this call runs on — the `id` given to\n * `addServer`, or `DEFAULT_SERVER_ID` for the one `configure` set.\n * Absent before 3.8.\n */\n serverId?: string | null;\n /**\n * That workspace's name: the ring push's `workspace_name`, else the\n * server's `name`. Absent before 3.8.\n */\n workspaceName?: string | null;\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 /** The server (workspace) it rings from — may differ from the current call's. Absent before 3.8. */\n serverId?: string | null;\n /** That workspace's name (\"Ana · Acme\"). Absent before 3.8. */\n workspaceName?: string | null;\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 * Incoming ringtone, overriding the config plugin's `ringtone` (leave it\n * out to use the plugin's, or the system ringtone without one).\n * Android: raw resource NAME (`ring` for `res/raw/ring.ogg`), played by\n * the module. iOS: a main-bundle sound CallKit plays — `ring.caf`, or the\n * base name looked up as caf/aiff/aif/wav; 30 s or shorter. Persisted, so\n * a ring that wakes a closed app uses it too. A name that is not in the\n * app rings with the system ringtone.\n */\n ringtone?: string;\n /**\n * Android: the full-screen incoming-call screen. Each field overrides the\n * config plugin's `incomingCall` option; leave one out to keep the\n * plugin's (or the built-in) value. Persisted for closed-app rings.\n * Ignored on iOS, where CallKit draws the call screen.\n */\n incomingCall?: IncomingCallOptions;\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/** Android's full-screen incoming call: its look, or the app's own activity instead. */\nexport interface IncomingCallOptions {\n /** `#RRGGBB` / `#AARRGGBB`: the glow, the pulsing ring and the initials disc (and the notification tint). */\n accentColor?: string;\n /** `#RRGGBB`: the screen's ground. A light one switches the text to dark. Default `#0B0B14`. */\n backgroundColor?: string;\n /**\n * The caller's picture, as a URL template: `{externalId}` (your app's id\n * for the caller) and `{userId}` (the poolse user id) are filled in,\n * URL-encoded — e.g. `https://cdn.example.com/avatars/{externalId}.jpg`.\n * Loaded off the main thread; the initials show until it loads, or if it\n * fails. A ring push's own `caller_avatar_url` wins over the template.\n */\n avatarUrl?: string;\n /**\n * Fully qualified class name of your own Activity (declared in your\n * manifest) to launch instead of the built-in screen. It receives the\n * `PoolseIncomingCall.EXTRA_*` extras and answers / declines through\n * `dev.poolse.callcore.android.PoolseIncomingCall` (see the README).\n * A leading `.` is relative to the application id.\n */\n activity?: string;\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 * The server (workspace) the session token belongs to — an `addServer`\n * id. Leave it out for the default server (`configure`'s).\n */\n serverId?: string;\n}\n\n/** The server `configure(apiBaseUrl)` sets; what everything defaults to. */\nexport const DEFAULT_SERVER_ID = 'default';\n\n/**\n * One server (workspace) the app is signed in to. No secrets: rings\n * carry their own grant, and place / join take the session token.\n */\nexport interface CallServer {\n /**\n * Your id for it, 1–64 of `A–Z a–z 0–9 . _ : -` — what `serverId`\n * says everywhere (snapshots, notification taps and actions).\n */\n id: string;\n /** Its API origin, as for `configure`. */\n apiBaseUrl: string;\n /**\n * The poolse tenant this sign-in belongs to (`tenant_id` of `me` or of\n * the registered device). Pushes carry it: it is how a ring or a\n * notification finds its server. Needed as soon as two servers are\n * added; without it a push goes to the default server.\n */\n tenantId?: string;\n /** The workspace's name — shown when a push carries none (\"Ana · Acme\"). */\n name?: 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 /** The server (workspace) it belongs to — open that one. Absent before 3.8. */\n serverId?: string | null;\n}\n\n/**\n * A Reply or Mark as read the user did from a chat notification, after\n * the native core sent it (or gave up). The server has already posted\n * the reply and marked the conversation read; use this to refresh what\n * the app shows (insert the message, drop the unread count) without\n * waiting for the socket, or to tell the user a reply did not go out.\n */\nexport interface NotificationActionResult {\n action: 'reply' | 'mark_read';\n conversationId: string;\n /** The server (workspace) the conversation is on. Absent before 3.8. */\n serverId?: string;\n /** Whether the server accepted it. */\n ok: boolean;\n /** Reply only: what the user typed. */\n text?: string;\n /** Reply only: the idempotency id sent with it — the message's id once posted. */\n clientId?: string;\n /** Reply, `ok` only: the posted message's id (equals `clientId`). */\n messageId?: string;\n /**\n * When not `ok`: the server's error code (`unauthorized`,\n * `device_signed_out`, `user_blocked`, `forbidden`, `not_found`,\n * `mau_cap_exceeded`, `validation_failed`, `rate_limited`), or\n * `network`, `no_grant` (the push carried no reply grant),\n * `not_configured` (never `configure`d), `http_<status>`.\n */\n error?: string;\n /** The HTTP status when the server answered with an error. */\n status?: number;\n /** When it finished, epoch ms. */\n at: number;\n}\n\ntype NativeSnapshot = { snapshot: Snapshot | null };\n\ninterface PoolseCallsNative {\n configure(apiBaseUrl: string, options: ConfigureOptions | null): Promise<void>;\n addServer?(server: CallServer): Promise<void>;\n removeServer?(id: string): Promise<void>;\n listServers?(): CallServer[];\n serverForTenant?(tenantId: string | null): string | null;\n getCallState(): NativeSnapshot;\n place(\n conversationId: string,\n media: string,\n sessionToken: string,\n serverId: string | null,\n ): Promise<void>;\n join(\n callId: string,\n conversationId: string | null,\n sessionToken: string,\n serverId: string | null,\n ): 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 screenShareSupported?(): boolean;\n startScreenShare?(): Promise<boolean>;\n stopScreenShare?(): void;\n setSpeaker(on: boolean): void;\n setAudioOutput?(id: string): void;\n callControl?(): Promise<{\n callId: string;\n controlToken: string;\n serverId?: string | null;\n apiBaseUrl?: string | null;\n } | 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, serverId: string | null): void;\n takeNotificationActions?(): NotificationActionResult[];\n observeNotificationActions?(on: boolean): 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: 'onNotificationAction',\n cb: (payload: NotificationActionResult) => void,\n ): { 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/**\n * Configure once, before any call can arrive. No secrets — just the API\n * origin, which becomes the default server (`DEFAULT_SERVER_ID`).\n *\n * `configure(options)` sets the options alone, for an app whose servers\n * all come from `addServer`.\n */\nexport async function configure(\n apiBaseUrlOrOptions: string | ConfigureOptions,\n options?: ConfigureOptions,\n): Promise<void> {\n if (typeof apiBaseUrlOrOptions !== 'string') {\n await native?.configure('', apiBaseUrlOrOptions ?? null);\n return;\n }\n apiOrigin = apiBaseUrlOrOptions.replace(/\\/+$/, '');\n await native?.configure(apiBaseUrlOrOptions, options ?? null);\n}\n\n// ── several servers (workspaces) ──────────────────────────────────────\n\nconst SERVER_ID = /^[A-Za-z0-9._:-]{1,64}$/;\n\n/**\n * Sign the call core in to one more server (workspace) — or update one\n * (same `id`). Rings from it ring here, answered and declined on that\n * server; its chat notifications post (Android) and act (Reply, Mark as\n * read) against it. Persisted: a closed app woken by its push finds it.\n *\n * Register the device's push tokens with that server too (the SDK's\n * `devices.register`, per client): this only tells the core where it is.\n * Calls `configure` with default options first if it never ran.\n */\nexport async function addServer(server: CallServer): Promise<void> {\n if (!SERVER_ID.test(server.id))\n throw new Error(`addServer: invalid id ${JSON.stringify(server.id)}.`);\n if (!/^https?:\\/\\/[^\\s]+$/.test(server.apiBaseUrl))\n throw new Error('addServer: apiBaseUrl must be http(s).');\n const entry: CallServer = { id: server.id, apiBaseUrl: server.apiBaseUrl.replace(/\\/+$/, '') };\n if (server.tenantId) entry.tenantId = server.tenantId;\n if (server.name) entry.name = server.name;\n if (server.id === DEFAULT_SERVER_ID) apiOrigin = entry.apiBaseUrl;\n await native?.addServer?.(entry);\n}\n\n/**\n * Signed out of one server: the core forgets it and takes its\n * notifications down; the others are untouched. A call in progress on\n * it carries on to its end. Unregister its push tokens with that server\n * yourself (before signing out there).\n */\nexport async function removeServer(id: string): Promise<void> {\n if (id === DEFAULT_SERVER_ID) apiOrigin = null;\n await native?.removeServer?.(id);\n}\n\n/** The servers the core knows, in the order they were added (`configure`'s is `default`). */\nexport function listServers(): CallServer[] {\n return native?.listServers?.() ?? [];\n}\n\n/**\n * The server a notification (its data) belongs to, by its `tenant_id` —\n * the same rule the core routes rings and actions by. Use it on a tapped\n * iOS notification to open the right workspace. `null` with no server.\n */\nexport function serverOfNotification(\n data: Record<string, unknown> | undefined | null,\n): string | null {\n const tenant = data && typeof data['tenant_id'] === 'string' ? data['tenant_id'] : null;\n if (native?.serverForTenant) return native.serverForTenant(tenant);\n return apiOrigin ? DEFAULT_SERVER_ID : null;\n}\n\n/** The API origin of `serverId` (the default server when absent). */\nfunction originOf(serverId: string | null | undefined): string | null {\n if (!serverId || serverId === DEFAULT_SERVER_ID) {\n if (apiOrigin) return apiOrigin;\n }\n const id = serverId ?? DEFAULT_SERVER_ID;\n const server = listServers().find((s) => s.id === id);\n return server?.apiBaseUrl ?? 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 (\n native?.place(conversationId, options.media, options.sessionToken, options.serverId ?? null) ??\n Promise.resolve()\n );\n}\n\n/** `serverId`: the server the session token is for — leave it out for the default one. */\nexport function join(\n callId: string,\n conversationId: string | null,\n sessionToken: string,\n serverId?: string,\n): Promise<void> {\n return native?.join(callId, conversationId, sessionToken, serverId ?? null) ?? 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 const origin = originOf(options.serverId);\n if (!origin) throw new Error('Call configure() (or addServer) before startRoom().');\n const res = await fetch(`${origin}/v1/conversations/${encodeURIComponent(conversationId)}/room`, {\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 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, options.serverId ?? null);\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 const control = await native.callControl();\n if (!control) throw new Error('There is no call in progress.');\n // The call's own server: it may be another workspace than the default.\n const origin = control.apiBaseUrl || originOf(control.serverId);\n if (!origin) throw new Error('Call configure() before ringIntoCall().');\n const res = await fetch(`${origin}/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\n/**\n * Whether this build can share the screen in a call: Android with the\n * LiveKit media engine; iOS when the app was built with the config\n * plugin's `screenShare` option (the broadcast extension). Every build\n * shows other people's screens.\n */\nexport const screenShareSupported = (): boolean => native?.screenShareSupported?.() ?? false;\n\n/**\n * Share the screen. Android asks the user first (the system's \"Start\n * recording or casting?\" prompt) and resolves `false` when they say no.\n * iOS shows the system's broadcast sheet and resolves `true` once it is\n * up; the user still has to tap Start Broadcast. Either way it resolves\n * `false` when the build cannot share, and `snapshot.screenSharing`\n * turns true only once the screen is actually going out. Stopping from\n * the system notification (Android) or the status bar (iOS) ends it the\n * same way.\n */\nexport const startScreenShare = async (): Promise<boolean> =>\n (await native?.startScreenShare?.()) ?? false;\n\nexport const stopScreenShare = (): void => native?.stopScreenShare?.();\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;\nlet activeServer: 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. Signed in to several servers, pass the one it is\n * on (`serverId`); without it, the conversation id alone decides.\n */\nexport function setActiveConversation(conversationId: string | null, serverId?: string): void {\n activeConversation = conversationId;\n activeServer = conversationId ? (serverId ?? null) : null;\n native?.setActiveConversation?.(conversationId, activeServer);\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 if (data['conversation_id'] !== activeConversation) return true;\n return activeServer != null && serverOfNotification(data) !== activeServer;\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`). Its server:\n * `serverOfNotification`.\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/**\n * Reply and Mark as read from a chat notification are handled natively —\n * from the lock screen, with the app closed — using the grant the push\n * carried and its server's API origin (`configure` / `addServer`, persisted).\n * This fires once each finishes while the app is running. Read the ones\n * that finished while it was not with `takeNotificationActions` on mount.\n */\nexport function onNotificationAction(cb: (result: NotificationActionResult) => void): Unsubscribe {\n if (!native?.takeNotificationActions) return () => undefined;\n const sub = native.addListener('onNotificationAction', cb);\n if (actionObservers++ === 0) native.observeNotificationActions?.(true);\n let removed = false;\n return () => {\n if (removed) return;\n removed = true;\n sub.remove();\n if (--actionObservers === 0) native?.observeNotificationActions?.(false);\n };\n}\n\n// Native queues results until someone listens for them specifically.\nlet actionObservers = 0;\n\n/** `onNotificationAction`, replies only. */\nexport function onNotificationReply(cb: (result: NotificationActionResult) => void): Unsubscribe {\n return onNotificationAction((result) => {\n if (result.action === 'reply') cb(result);\n });\n}\n\n/**\n * The notification actions that finished while no `onNotificationAction`\n * listener was attached (usually: the app was not running), oldest\n * first, each returned once. Up to the last 50 are kept.\n */\nexport function takeNotificationActions(): NotificationActionResult[] {\n return native?.takeNotificationActions?.() ?? [];\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 * `camera` (default), or `screen`: the participant's shared screen\n * (with `local`, your own). A screen is never mirrored; draw it with\n * `fit=\"contain\"` so nothing is cropped.\n */\n source?: 'camera' | 'screen';\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 {\n participantId: _p,\n local: _l,\n mirror: _m,\n fit: _f,\n source: _s,\n pictureInPicture: _pip,\n ...rest\n } = props;\n return createElement(View, rest);\n }\n return createElement(Native, props);\n}\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// One API server the app is signed in to — a workspace. Holds no
|
|
4
|
+
/// secrets: the push brings each ring's grant, and JS passes session
|
|
5
|
+
/// tokens per place/join. Twin of CallServers.kt.
|
|
6
|
+
public struct CallServer: Equatable {
|
|
7
|
+
/// The host's own id for it (`addServer({ id })`); `default` is the one `configure(apiBaseUrl)` sets.
|
|
8
|
+
public var id: String
|
|
9
|
+
public var apiBaseUrl: String
|
|
10
|
+
/// The poolse tenant it signs in to: how a push (`tenant_id`) finds its server.
|
|
11
|
+
public var tenantId: String?
|
|
12
|
+
/// The workspace's name, when the push carries none ("Ana · Acme").
|
|
13
|
+
public var name: String?
|
|
14
|
+
|
|
15
|
+
public init(id: String, apiBaseUrl: String, tenantId: String? = nil, name: String? = nil) {
|
|
16
|
+
self.id = id
|
|
17
|
+
self.apiBaseUrl = apiBaseUrl
|
|
18
|
+
self.tenantId = tenantId
|
|
19
|
+
self.name = name
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public init?(dict: [String: Any]) {
|
|
23
|
+
guard let id = dict["id"] as? String, !id.isEmpty,
|
|
24
|
+
let url = dict["apiBaseUrl"] as? String, !url.isEmpty else { return nil }
|
|
25
|
+
self.init(id: id, apiBaseUrl: url,
|
|
26
|
+
tenantId: (dict["tenantId"] as? String).flatMap { $0.isEmpty ? nil : $0 },
|
|
27
|
+
name: (dict["name"] as? String).flatMap { $0.isEmpty ? nil : $0 })
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public var dict: [String: Any] {
|
|
31
|
+
var d: [String: Any] = ["id": id, "apiBaseUrl": apiBaseUrl]
|
|
32
|
+
if let tenantId = tenantId { d["tenantId"] = tenantId }
|
|
33
|
+
if let name = name { d["name"] = name }
|
|
34
|
+
return d
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// The signed-in servers, in the order they were added, and the rules
|
|
39
|
+
/// that route a push to one of them.
|
|
40
|
+
public struct CallServers: Equatable {
|
|
41
|
+
public static let defaultId = "default"
|
|
42
|
+
|
|
43
|
+
public private(set) var all: [CallServer]
|
|
44
|
+
|
|
45
|
+
public init(_ all: [CallServer] = []) { self.all = all }
|
|
46
|
+
|
|
47
|
+
public var isMulti: Bool { all.count > 1 }
|
|
48
|
+
|
|
49
|
+
public func get(_ id: String?) -> CallServer? {
|
|
50
|
+
all.first { $0.id == (id ?? CallServers.defaultId) }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// Adds or replaces (by id), keeping its place in the order.
|
|
54
|
+
public mutating func upsert(_ server: CallServer) {
|
|
55
|
+
if let i = all.firstIndex(where: { $0.id == server.id }) { all[i] = server } else { all.append(server) }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public mutating func remove(_ id: String) { all.removeAll { $0.id == id } }
|
|
59
|
+
|
|
60
|
+
/// The server a push belongs to: the one signed in to its `tenant_id`;
|
|
61
|
+
/// else — an older server's push, or a host that left `tenantId` out —
|
|
62
|
+
/// the only server, the only one without a tenant, the default, the
|
|
63
|
+
/// first. Nil only with no server at all. Never drops a ring: a wrong
|
|
64
|
+
/// guess fails its answer, a dropped one never rings.
|
|
65
|
+
public func resolve(tenantId: String?) -> CallServer? {
|
|
66
|
+
if let t = tenantId, let match = all.first(where: { $0.tenantId == t }) { return match }
|
|
67
|
+
if all.count <= 1 { return all.first }
|
|
68
|
+
let untagged = all.filter { $0.tenantId == nil }
|
|
69
|
+
if untagged.count == 1 { return untagged[0] }
|
|
70
|
+
return get(CallServers.defaultId) ?? untagged.first ?? all.first
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// The workspace a ring / notification is labelled with: the push's
|
|
74
|
+
/// name, else the server's own. Nil while only one server is signed in
|
|
75
|
+
/// — a single-workspace app looks exactly as before.
|
|
76
|
+
public func workspaceLabel(serverId: String?, pushName: String?) -> String? {
|
|
77
|
+
guard isMulti else { return nil }
|
|
78
|
+
if let n = pushName, !n.isEmpty { return n }
|
|
79
|
+
return get(serverId)?.name
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// "Ana · Acme" — `base` with the workspace, when there is one to show
|
|
83
|
+
/// (the workspace alone when the push named nobody).
|
|
84
|
+
public static func title(_ base: String?, workspace: String?) -> String? {
|
|
85
|
+
guard let w = workspace, !w.isEmpty else { return base }
|
|
86
|
+
guard let b = base, !b.isEmpty else { return w }
|
|
87
|
+
return "\(b) · \(w)"
|
|
88
|
+
}
|
|
89
|
+
}
|
package/ios/Core/Ports.swift
CHANGED
|
@@ -121,9 +121,16 @@ public struct RingContext: Equatable {
|
|
|
121
121
|
public var media: String
|
|
122
122
|
public var grant: String
|
|
123
123
|
public var ringDeadlineEpochMs: Int64
|
|
124
|
+
/// The server (workspace) the ring came from — the host's id from
|
|
125
|
+
/// `addServer`, resolved from the push's `tenant_id`. Its answer and
|
|
126
|
+
/// decline go to that server. nil: the default server.
|
|
127
|
+
public var serverId: String?
|
|
128
|
+
/// The push's `workspace_name`, for "Ana · Acme" when several servers are signed in.
|
|
129
|
+
public var workspaceName: String?
|
|
124
130
|
|
|
125
131
|
public init(callId: String, conversationId: String, conversationName: String?, callerName: String?,
|
|
126
|
-
media: String, grant: String, ringDeadlineEpochMs: Int64
|
|
132
|
+
media: String, grant: String, ringDeadlineEpochMs: Int64,
|
|
133
|
+
serverId: String? = nil, workspaceName: String? = nil) {
|
|
127
134
|
self.callId = callId
|
|
128
135
|
self.conversationId = conversationId
|
|
129
136
|
self.conversationName = conversationName
|
|
@@ -131,6 +138,8 @@ public struct RingContext: Equatable {
|
|
|
131
138
|
self.media = media
|
|
132
139
|
self.grant = grant
|
|
133
140
|
self.ringDeadlineEpochMs = ringDeadlineEpochMs
|
|
141
|
+
self.serverId = serverId
|
|
142
|
+
self.workspaceName = workspaceName
|
|
134
143
|
}
|
|
135
144
|
}
|
|
136
145
|
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// One HttpPort for several API servers (signed in to several
|
|
4
|
+
/// workspaces): each request goes to the server its call belongs to.
|
|
5
|
+
/// Direct port of RoutedHttpPort.kt.
|
|
6
|
+
///
|
|
7
|
+
/// The runtime stays single-server — it only knows call ids. The platform
|
|
8
|
+
/// binds each call to its server as it enters (a ring's `serverId`, a
|
|
9
|
+
/// place/join with the host's server id), and this port looks the call up
|
|
10
|
+
/// per request. A placed call is keyed by its conversation until the
|
|
11
|
+
/// server mints its id; the answer binds that id too. Unbound calls go to
|
|
12
|
+
/// the default server (nil), which is all a single-server app ever has.
|
|
13
|
+
///
|
|
14
|
+
/// Thread-safe: rings are bound from PushKit, requests run on main.
|
|
15
|
+
public final class RoutedHttpPort: HttpPort {
|
|
16
|
+
private static let pending = "pending:"
|
|
17
|
+
private static let maxBound = 64
|
|
18
|
+
|
|
19
|
+
private let portFor: (String?) -> HttpPort
|
|
20
|
+
private let lock = NSLock()
|
|
21
|
+
private var calls: [(callId: String, serverId: String)] = []
|
|
22
|
+
private var places: [String: String] = [:]
|
|
23
|
+
|
|
24
|
+
/// `portFor`: the HTTP port of one server (nil = the default one).
|
|
25
|
+
public init(portFor: @escaping (String?) -> HttpPort) {
|
|
26
|
+
self.portFor = portFor
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// The call `callId` belongs to `serverId` (nil forgets it: the default server).
|
|
30
|
+
public func bindCall(_ callId: String, serverId: String?) {
|
|
31
|
+
lock.lock(); defer { lock.unlock() }
|
|
32
|
+
calls.removeAll { $0.callId == callId }
|
|
33
|
+
guard let serverId = serverId else { return }
|
|
34
|
+
calls.append((callId, serverId))
|
|
35
|
+
if calls.count > Self.maxBound { calls.removeFirst(calls.count - Self.maxBound) }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// The next call placed on `conversationId` goes to `serverId`.
|
|
39
|
+
public func bindPlace(_ conversationId: String, serverId: String?) {
|
|
40
|
+
lock.lock(); defer { lock.unlock() }
|
|
41
|
+
places[conversationId] = serverId
|
|
42
|
+
if places.count > Self.maxBound, let any = places.keys.first(where: { $0 != conversationId }) {
|
|
43
|
+
places.removeValue(forKey: any)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// The server `callId` is bound to (a `pending:<conversation>` id: its place); nil = the default.
|
|
48
|
+
public func serverFor(_ callId: String) -> String? {
|
|
49
|
+
lock.lock(); defer { lock.unlock() }
|
|
50
|
+
if callId.hasPrefix(Self.pending) { return places[String(callId.dropFirst(Self.pending.count))] }
|
|
51
|
+
return calls.last { $0.callId == callId }?.serverId
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public func answer(callId: String, grant: String, cb: @escaping (HttpResult) -> Void) {
|
|
55
|
+
portFor(serverFor(callId)).answer(callId: callId, grant: grant, cb: cb)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public func join(callId: String, sessionToken: String, cb: @escaping (HttpResult) -> Void) {
|
|
59
|
+
portFor(serverFor(callId)).join(callId: callId, sessionToken: sessionToken, cb: cb)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public func place(conversationId: String, media: String, sessionToken: String,
|
|
63
|
+
cb: @escaping (HttpResult) -> Void) {
|
|
64
|
+
lock.lock(); let server = places[conversationId]; lock.unlock()
|
|
65
|
+
portFor(server).place(conversationId: conversationId, media: media, sessionToken: sessionToken) { [weak self] result in
|
|
66
|
+
// Everything after the answer (hangup, reconnect) names the minted id.
|
|
67
|
+
if case let .ok(bundle) = result { self?.bindCall(bundle.callId, serverId: server) }
|
|
68
|
+
cb(result)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public func decline(callId: String, auth: String, busy: Bool) {
|
|
73
|
+
portFor(serverFor(callId)).decline(callId: callId, auth: auth, busy: busy)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public func hangup(callId: String, controlToken: String) {
|
|
77
|
+
portFor(serverFor(callId)).hangup(callId: callId, controlToken: controlToken)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public func reconnect(current: CallSessionBundle, cb: @escaping (HttpResult) -> Void) {
|
|
81
|
+
portFor(serverFor(current.callId)).reconnect(current: current, cb: cb)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -61,16 +61,48 @@ public class PoolseCallsModule: Module {
|
|
|
61
61
|
_ = CallCore.getOrNull()
|
|
62
62
|
}.runOnQueue(.main)
|
|
63
63
|
|
|
64
|
+
// Several workspaces: each server the app is signed in to. Persisted,
|
|
65
|
+
// so a ring or a notification action with no JS finds its server.
|
|
66
|
+
AsyncFunction("addServer") { (server: [String: Any]) in
|
|
67
|
+
guard let s = CallServer(dict: server) else { return }
|
|
68
|
+
var entry = s
|
|
69
|
+
while entry.apiBaseUrl.hasSuffix("/") { entry.apiBaseUrl.removeLast() }
|
|
70
|
+
CallCore.ensureConfigured()
|
|
71
|
+
ServerRegistry.shared.upsert(entry)
|
|
72
|
+
PoolseCallsSetup.registerVoipEarly()
|
|
73
|
+
_ = CallCore.getOrNull()
|
|
74
|
+
}.runOnQueue(.main)
|
|
75
|
+
|
|
76
|
+
// Signed out of one workspace: forget it and take its notifications
|
|
77
|
+
// down. A call in progress on it carries on to its end.
|
|
78
|
+
AsyncFunction("removeServer") { (id: String) in
|
|
79
|
+
let tenant = ServerRegistry.shared.servers.get(id)?.tenantId
|
|
80
|
+
ServerRegistry.shared.remove(id)
|
|
81
|
+
if let tenant = tenant { MessageNotifications.clearTenant(tenant) }
|
|
82
|
+
}.runOnQueue(.main)
|
|
83
|
+
|
|
84
|
+
Function("listServers") { () -> [[String: Any]] in
|
|
85
|
+
ServerRegistry.shared.servers.all.map(\.dict)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// The server a push / notification of `tenantId` belongs to — the
|
|
89
|
+
// same rule the native side routes rings and actions by.
|
|
90
|
+
Function("serverForTenant") { (tenantId: String?) -> String? in
|
|
91
|
+
ServerRegistry.shared.servers.resolve(tenantId: tenantId.flatMap { $0.isEmpty ? nil : $0 })?.id
|
|
92
|
+
}
|
|
93
|
+
|
|
64
94
|
Function("getCallState") { () -> [String: Any] in
|
|
65
95
|
["snapshot": CallCore.peek()?.snapshot() ?? NSNull()]
|
|
66
96
|
}
|
|
67
97
|
|
|
68
|
-
AsyncFunction("place") { (conversationId: String, media: String, sessionToken: String) in
|
|
69
|
-
CallCore.getOrNull()?.place(conversationId: conversationId, media: media, sessionToken: sessionToken
|
|
98
|
+
AsyncFunction("place") { (conversationId: String, media: String, sessionToken: String, serverId: String?) in
|
|
99
|
+
CallCore.getOrNull()?.place(conversationId: conversationId, media: media, sessionToken: sessionToken,
|
|
100
|
+
serverId: serverId)
|
|
70
101
|
}.runOnQueue(.main)
|
|
71
102
|
|
|
72
|
-
AsyncFunction("join") { (callId: String, conversationId: String?, sessionToken: String) in
|
|
73
|
-
CallCore.getOrNull()?.join(callId: callId, conversationId: conversationId, sessionToken: sessionToken
|
|
103
|
+
AsyncFunction("join") { (callId: String, conversationId: String?, sessionToken: String, serverId: String?) in
|
|
104
|
+
CallCore.getOrNull()?.join(callId: callId, conversationId: conversationId, sessionToken: sessionToken,
|
|
105
|
+
serverId: serverId)
|
|
74
106
|
}.runOnQueue(.main)
|
|
75
107
|
|
|
76
108
|
Function("answer") { onCore { $0.answer() } }
|
|
@@ -106,15 +138,23 @@ public class PoolseCallsModule: Module {
|
|
|
106
138
|
|
|
107
139
|
// What authorizes acting on the call itself (ringing people in).
|
|
108
140
|
AsyncFunction("callControl") { () -> [String: String]? in
|
|
109
|
-
guard let
|
|
110
|
-
|
|
141
|
+
guard let core = CallCore.getOrNull(), let c = core.control else { return nil }
|
|
142
|
+
var out = ["callId": c.callId, "controlToken": c.controlToken]
|
|
143
|
+
// Where the call runs: ringing people in goes to that server.
|
|
144
|
+
if let id = core.currentServerId {
|
|
145
|
+
out["serverId"] = id
|
|
146
|
+
out["apiBaseUrl"] = ServerRegistry.shared.baseUrl(id)
|
|
147
|
+
}
|
|
148
|
+
return out
|
|
111
149
|
}.runOnQueue(.main)
|
|
112
150
|
|
|
113
151
|
// The chat on screen: opening it clears what was already shown for it.
|
|
114
152
|
// (Suppressing new ones while it is open happens in the app's
|
|
115
153
|
// notification handler — see shouldPresentMessage in src/index.ts.)
|
|
116
|
-
Function("setActiveConversation") { (conversationId: String?) in
|
|
117
|
-
|
|
154
|
+
Function("setActiveConversation") { (conversationId: String?, serverId: String?) in
|
|
155
|
+
guard let conversationId = conversationId else { return }
|
|
156
|
+
let tenant = serverId.flatMap { ServerRegistry.shared.servers.get($0)?.tenantId }
|
|
157
|
+
MessageNotifications.clear(conversationId: conversationId, tenantId: tenant)
|
|
118
158
|
}
|
|
119
159
|
|
|
120
160
|
// Reply / Mark as read done from a notification while JS was not
|