@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,93 @@
1
+ # iOS call core — ports & runtime API (ready to code against)
2
+
3
+ Swift port of `android/.../callcore/{Ports,CallMachine,CallCoreRuntime}.kt`.
4
+ Foundation only, main-thread confined, no Sendable. All types `public`.
5
+
6
+ ## Ports (ios/Core/Ports.swift)
7
+
8
+ ```swift
9
+ protocol HttpPort: AnyObject {
10
+ func answer(callId: String, grant: String, cb: @escaping (HttpResult) -> Void)
11
+ func join(callId: String, sessionToken: String, cb: @escaping (HttpResult) -> Void)
12
+ func place(conversationId: String, media: String, sessionToken: String, cb: @escaping (HttpResult) -> Void)
13
+ func decline(callId: String, auth: String, busy: Bool)
14
+ func hangup(callId: String, controlToken: String)
15
+ func reconnect(current: CallSessionBundle, cb: @escaping (HttpResult) -> Void)
16
+ }
17
+ enum HttpResult { case ok(CallSessionBundle), gone, timeout, authFailed(code: String), failed(code: String) }
18
+ struct CallSessionBundle { callId, conversationId, conversationName?, media, created, livekitUrl, livekitToken, controlToken }
19
+
20
+ protocol MediaPort: AnyObject {
21
+ func join(bundle: CallSessionBundle); func leave()
22
+ func setMuted(_ muted: Bool); func setCamera(_ on: Bool); func switchCamera(); func setSpeaker(_ on: Bool)
23
+ }
24
+ protocol RingSurfacePort: AnyObject {
25
+ func show(ring: RingContext); func dismiss(callId: String)
26
+ func ringtoneStart(); func ringtoneStop(); func ringbackStart(); func ringbackStop()
27
+ }
28
+ struct RingContext { callId, conversationId, conversationName?, callerName?, media, grant, ringDeadlineEpochMs: Int64 }
29
+ protocol CallSessionPort: AnyObject { func start(callId: String, media: String); func stop() }
30
+ protocol SnapshotSink: AnyObject { func emit(state: MachineState) } // BlockSnapshotSink { state in ... } helper
31
+ protocol TimerPort: AnyObject {
32
+ func nowMs() -> Int64
33
+ func schedule(key: String, delayMs: Int64, fire: @escaping () -> Void) // same key replaces
34
+ func cancel(key: String)
35
+ }
36
+ // State values: Phase (.idle .ringingIn .ringingOut .connecting .active .reconnecting .ended),
37
+ // Direction (.incoming .outgoing .joined), EndReason (.left .finished .declinedAll .busyAll
38
+ // .noAnswer .cancelled .connectionLost .failed; `.wire` = "declined_all" etc.),
39
+ // MachineState { phase, callId?, conversationId?, direction?, media, reason?, httpAttempts }
40
+ ```
41
+
42
+ Provided implementations in Core: `CallHttpClient` (HttpPort, URLSession),
43
+ `MainQueueTimerPort()` (TimerPort on DispatchQueue.main, epoch nowMs), `BlockSnapshotSink { state in }`.
44
+
45
+ ## Runtime (ios/Core/CallCoreRuntime.swift)
46
+
47
+ ```swift
48
+ let rt = CallCoreRuntime(
49
+ http: HttpPort, media: MediaPort, surface: RingSurfacePort,
50
+ session: CallSessionPort, timers: TimerPort, sink: SnapshotSink,
51
+ executor: ((@escaping () -> Void) -> Void)? = nil) // default: inline if on main thread, else DispatchQueue.main.async
52
+
53
+ rt.currentState() -> MachineState
54
+ rt.conversationName: String? // bundle's, else the ring's (main thread)
55
+ rt.isResolved(_ callId: String) -> Bool
56
+ rt.post(_ block: @escaping () -> Void)
57
+
58
+ // inputs
59
+ rt.onRing(_ ctx: RingContext) // push (PushKit) or socket — same path
60
+ rt.onRingEnded(callId:reason:)
61
+ rt.onCallFinished(callId:reason:) // reason: String? = nil
62
+ rt.answer(); rt.decline(); rt.hangUp()
63
+ rt.place(conversationId:media:sessionToken:)
64
+ rt.join(callId:conversationId:sessionToken:) // conversationId: String?
65
+ rt.allRingsResolved(_ outcome: String)
66
+ rt.onMediaConnected(); rt.onMediaFailed(); rt.onMediaLost()
67
+ rt.onMediaReconnecting(); rt.onMediaRecovered(); rt.onRemoteJoined()
68
+ rt.setMuted(_:); rt.setCamera(_:); rt.switchCamera(); rt.setSpeaker(_:)
69
+ rt.reemit() // re-emit current state (roster/route changed)
70
+ ```
71
+
72
+ Constants: `CallCoreRuntime.ENDED_LINGER_MS` (2500), `RECONNECT_BUDGET_MS` (25000),
73
+ `CONNECT_WATCHDOG_MS` (20000), `RING_OUT_BACKSTOP_MS` (75000), `CLOCK_SLACK_MS` (10000), `RESOLVED_LRU` (32).
74
+
75
+ The sink receives the MachineState after every change; IDLE means "no call" (emit `snapshot: null`).
76
+ Ended state lingers 2.5 s, then IDLE is emitted.
77
+
78
+ ## HTTP client (ios/Core/CallHttpClient.swift)
79
+
80
+ ```swift
81
+ CallHttpClient(baseUrl: @escaping () -> String, session: URLSession = CallHttpClient.defaultSession())
82
+ // baseUrl read per request (staging/prod switch). 9 s total timeout. Static classify/parseBundle/errorCode are pure.
83
+ ```
84
+
85
+ ## Snapshot (ios/Core/SnapshotEncoding.swift)
86
+
87
+ ```swift
88
+ struct SnapshotParticipant { userId, externalId, speaking, muted, cameraOn }
89
+ MachineState.toSnapshot(conversationName: String? = nil,
90
+ participants: [SnapshotParticipant] = [], audioRoute: String = "earpiece",
91
+ mutedSelf: Bool = false, cameraOn: Bool = false, cameraFacing: String? = nil) -> [String: Any]?
92
+ // nil for IDLE. conversationName nil -> NSNull; reason / cameraFacing omitted when nil.
93
+ ```
@@ -0,0 +1,238 @@
1
+ import Foundation
2
+
3
+ // The seams between the pure machine and the platform. Direct port of
4
+ // android/.../callcore/Ports.kt (plus the state value types from
5
+ // CallMachine.kt). Everything is main-thread confined: adapters may call
6
+ // back from any thread — the runtime hops onto DispatchQueue.main.
7
+
8
+ // MARK: - HTTP (CALL_CONTRACT.md §4 — the three doors)
9
+
10
+ public protocol HttpPort: AnyObject {
11
+ /// POST /calls/:id/answer with the ring grant.
12
+ func answer(callId: String, grant: String, cb: @escaping (HttpResult) -> Void)
13
+ /// POST /calls/:id/join with a session token.
14
+ func join(callId: String, sessionToken: String, cb: @escaping (HttpResult) -> Void)
15
+ /// POST /conversations/:id/calls with a session token.
16
+ func place(conversationId: String, media: String, sessionToken: String, cb: @escaping (HttpResult) -> Void)
17
+ /// POST /calls/:id/decline — grant or session; fire-and-forget with retry.
18
+ func decline(callId: String, auth: String, busy: Bool)
19
+ /// POST /calls/:id/hangup with the call-control token; fire-and-forget with retry.
20
+ func hangup(callId: String, controlToken: String)
21
+ /// POST /calls/:id/reconnect with the call-control token. Answers with the
22
+ /// FULL bundle; `current` lets an older server's `{livekit:{url,token}}`
23
+ /// refresh be applied onto it.
24
+ func reconnect(current: CallSessionBundle, cb: @escaping (HttpResult) -> Void)
25
+ }
26
+
27
+ public enum HttpResult: Equatable {
28
+ /// 2xx: the CallSessionBundle (or reconnect's token refresh).
29
+ case ok(CallSessionBundle)
30
+ /// 404/410 — the call is finished (or this device was superseded).
31
+ case gone
32
+ /// Timeout / transient network failure.
33
+ case timeout
34
+ /// 401/403 — grant spent, expired, or wrong device. Terminal.
35
+ case authFailed(code: String)
36
+ /// Terminal but not auth: 503, another 4xx, or an unparseable 2xx.
37
+ case failed(code: String)
38
+ }
39
+
40
+ public struct CallSessionBundle: Equatable {
41
+ public var callId: String
42
+ public var conversationId: String
43
+ public var conversationName: String?
44
+ public var media: String
45
+ public var created: Bool
46
+ public var livekitUrl: String
47
+ public var livekitToken: String
48
+ public var controlToken: String
49
+ /// `room` (rings nobody, CALL_CONTRACT.md §5.6) or `call`.
50
+ public var kind: String
51
+ /// How many people the server says are being rung right now.
52
+ public var ringing: Int
53
+
54
+ public init(callId: String, conversationId: String, conversationName: String?, media: String,
55
+ created: Bool, livekitUrl: String, livekitToken: String, controlToken: String,
56
+ kind: String = "call", ringing: Int = 0) {
57
+ self.callId = callId
58
+ self.conversationId = conversationId
59
+ self.conversationName = conversationName
60
+ self.media = media
61
+ self.created = created
62
+ self.livekitUrl = livekitUrl
63
+ self.livekitToken = livekitToken
64
+ self.controlToken = controlToken
65
+ self.kind = kind
66
+ self.ringing = ringing
67
+ }
68
+ }
69
+
70
+ // MARK: - Media
71
+
72
+ /// LiveKit (or any SFU) — media only, no lifecycle opinions.
73
+ public protocol MediaPort: AnyObject {
74
+ func join(bundle: CallSessionBundle)
75
+ func leave()
76
+ func setMuted(_ muted: Bool)
77
+ func setCamera(_ on: Bool)
78
+ func switchCamera()
79
+ /// Loudspeaker (`true`) or back to the private route (`false`).
80
+ func setSpeaker(_ on: Bool)
81
+ /// Play through one specific output — an id from `Snapshot.audioOutputs`.
82
+ func setAudioOutput(_ id: String)
83
+ }
84
+
85
+ public extension MediaPort {
86
+ /// Engines without device selection fall back to the speaker toggle.
87
+ func setAudioOutput(_ id: String) { setSpeaker(id == "speaker") }
88
+ }
89
+
90
+ // MARK: - Ring surface
91
+
92
+ /// The ring UX. iOS: CallKit report + tones.
93
+ public protocol RingSurfacePort: AnyObject {
94
+ func show(ring: RingContext)
95
+ func dismiss(callId: String)
96
+ func ringtoneStart()
97
+ func ringtoneStop()
98
+ func ringbackStart()
99
+ func ringbackStop()
100
+ /// A call waiting beside the current one: its own quiet surface (iOS:
101
+ /// CallKit's call-waiting UI; Android: a heads-up with a waiting tone).
102
+ func showWaiting(ring: RingContext)
103
+ /// The waiting call is over (declined, cancelled, timed out).
104
+ func dismissWaiting(callId: String)
105
+ /// The waiting call becomes THE ring (SHOW_RING follows): drop its
106
+ /// waiting surface without resolving it.
107
+ func promoteWaiting(callId: String)
108
+ }
109
+
110
+ public extension RingSurfacePort {
111
+ func showWaiting(ring: RingContext) {}
112
+ func dismissWaiting(callId: String) {}
113
+ func promoteWaiting(callId: String) {}
114
+ }
115
+
116
+ public struct RingContext: Equatable {
117
+ public var callId: String
118
+ public var conversationId: String
119
+ public var conversationName: String?
120
+ public var callerName: String?
121
+ public var media: String
122
+ public var grant: String
123
+ public var ringDeadlineEpochMs: Int64
124
+
125
+ public init(callId: String, conversationId: String, conversationName: String?, callerName: String?,
126
+ media: String, grant: String, ringDeadlineEpochMs: Int64) {
127
+ self.callId = callId
128
+ self.conversationId = conversationId
129
+ self.conversationName = conversationName
130
+ self.callerName = callerName
131
+ self.media = media
132
+ self.grant = grant
133
+ self.ringDeadlineEpochMs = ringDeadlineEpochMs
134
+ }
135
+ }
136
+
137
+ // MARK: - Session / snapshots / time
138
+
139
+ /// Android: the phoneCall foreground service. iOS: the CallKit session / audio session.
140
+ public protocol CallSessionPort: AnyObject {
141
+ func start(callId: String, media: String)
142
+ func stop()
143
+ }
144
+
145
+ /// Snapshots out — the bridge turns these into JS events (IDLE → null).
146
+ public protocol SnapshotSink: AnyObject {
147
+ func emit(state: MachineState)
148
+ }
149
+
150
+ /// Closure-backed SnapshotSink convenience.
151
+ public final class BlockSnapshotSink: SnapshotSink {
152
+ private let block: (MachineState) -> Void
153
+ public init(_ block: @escaping (MachineState) -> Void) { self.block = block }
154
+ public func emit(state: MachineState) { block(state) }
155
+ }
156
+
157
+ /// Time, injectable: real adapter uses DispatchQueue.main; tests a fake.
158
+ public protocol TimerPort: AnyObject {
159
+ func nowMs() -> Int64
160
+ /// Scheduling an existing key replaces it.
161
+ func schedule(key: String, delayMs: Int64, fire: @escaping () -> Void)
162
+ func cancel(key: String)
163
+ }
164
+
165
+ // MARK: - Machine state value types (CallMachine.kt)
166
+
167
+ public enum Phase: String, CaseIterable {
168
+ case idle = "IDLE"
169
+ case ringingIn = "RINGING_IN"
170
+ case ringingOut = "RINGING_OUT"
171
+ case connecting = "CONNECTING"
172
+ case active = "ACTIVE"
173
+ case reconnecting = "RECONNECTING"
174
+ case ended = "ENDED"
175
+ }
176
+
177
+ public enum Direction: String {
178
+ case incoming = "INCOMING"
179
+ case outgoing = "OUTGOING"
180
+ case joined = "JOINED"
181
+ }
182
+
183
+ public enum EndReason: String {
184
+ case left = "LEFT"
185
+ case finished = "FINISHED"
186
+ case declinedAll = "DECLINED_ALL"
187
+ case busyAll = "BUSY_ALL"
188
+ case noAnswer = "NO_ANSWER"
189
+ case cancelled = "CANCELLED"
190
+ case connectionLost = "CONNECTION_LOST"
191
+ case failed = "FAILED"
192
+
193
+ /// Wire form: lowercase snake (e.g. "declined_all").
194
+ public var wire: String { rawValue.lowercased() }
195
+ }
196
+
197
+ /// A second call ringing while this device is on one (CALL_CONTRACT.md §7,
198
+ /// call waiting): shown beside the current call, never instead of it.
199
+ public struct WaitingCall: Equatable {
200
+ public var callId: String
201
+ public var conversationId: String?
202
+ public var media: String
203
+
204
+ public init(callId: String, conversationId: String?, media: String) {
205
+ self.callId = callId
206
+ self.conversationId = conversationId
207
+ self.media = media
208
+ }
209
+ }
210
+
211
+ /// Everything the machine knows. Immutable value; transitions return a new one.
212
+ public struct MachineState: Equatable {
213
+ public var phase: Phase
214
+ public var callId: String?
215
+ public var conversationId: String?
216
+ public var direction: Direction?
217
+ public var media: String
218
+ public var reason: EndReason?
219
+ /// HTTP attempts made for the current connecting request (retry budget = 2).
220
+ public var httpAttempts: Int
221
+ /// A second call ringing beside this one, if any.
222
+ public var waiting: WaitingCall?
223
+
224
+ public init(phase: Phase = .idle, callId: String? = nil, conversationId: String? = nil,
225
+ direction: Direction? = nil, media: String = "audio", reason: EndReason? = nil,
226
+ httpAttempts: Int = 0, waiting: WaitingCall? = nil) {
227
+ self.phase = phase
228
+ self.callId = callId
229
+ self.conversationId = conversationId
230
+ self.direction = direction
231
+ self.media = media
232
+ self.reason = reason
233
+ self.httpAttempts = httpAttempts
234
+ self.waiting = waiting
235
+ }
236
+
237
+ public static var IDLE: MachineState { MachineState() }
238
+ }
@@ -0,0 +1,122 @@
1
+ import Foundation
2
+
3
+ /// One remote participant as the JS `Snapshot.participants[]` entry.
4
+ public struct SnapshotParticipant: Equatable {
5
+ /// The LiveKit identity.
6
+ public var userId: String
7
+ public var externalId: String
8
+ public var speaking: Bool
9
+ public var muted: Bool
10
+ /// True only with a published, subscribed, unmuted camera track.
11
+ public var cameraOn: Bool
12
+ /// Their link to the SFU: `good` | `poor` | `lost` (dropped, coming
13
+ /// back — "Reconnecting…") | `unknown`.
14
+ public var connectionQuality: String
15
+
16
+ public init(userId: String, externalId: String, speaking: Bool, muted: Bool, cameraOn: Bool,
17
+ connectionQuality: String = "unknown") {
18
+ self.userId = userId
19
+ self.externalId = externalId
20
+ self.speaking = speaking
21
+ self.muted = muted
22
+ self.cameraOn = cameraOn
23
+ self.connectionQuality = connectionQuality
24
+ }
25
+
26
+ public var dictionary: [String: Any] {
27
+ ["userId": userId, "externalId": externalId, "speaking": speaking, "muted": muted, "cameraOn": cameraOn,
28
+ "connectionQuality": connectionQuality]
29
+ }
30
+ }
31
+
32
+ /// One place call audio can play, as a JS `Snapshot.audioOutputs[]` entry.
33
+ public struct AudioOutput: Equatable {
34
+ /// Stable for the device's lifetime in this call; passed back to `setAudioOutput`.
35
+ public var id: String
36
+ /// `earpiece` | `speaker` | `bluetooth` | `headset`.
37
+ public var kind: String
38
+ /// What the device calls itself ("AirPods Pro"), or a plain default for built-ins.
39
+ public var name: String
40
+
41
+ public init(id: String, kind: String, name: String) {
42
+ self.id = id
43
+ self.kind = kind
44
+ self.name = name
45
+ }
46
+
47
+ public var dictionary: [String: Any] { ["id": id, "kind": kind, "name": name] }
48
+ }
49
+
50
+ public extension Phase {
51
+ var wire: String {
52
+ switch self {
53
+ case .idle: return "idle"
54
+ case .ringingIn: return "ringing_in"
55
+ case .ringingOut: return "ringing_out"
56
+ case .connecting: return "connecting"
57
+ case .active: return "active"
58
+ case .reconnecting: return "reconnecting"
59
+ case .ended: return "ended"
60
+ }
61
+ }
62
+ }
63
+
64
+ public extension Direction {
65
+ var wire: String { rawValue.lowercased() }
66
+ }
67
+
68
+ public extension MachineState {
69
+ /// The one place a MachineState becomes the contract's `Snapshot`
70
+ /// (CALL_CONTRACT.md §8; mirrors SnapshotJson.kt and src/index.ts). Returns nil
71
+ /// for idle: the bridge sends `{ snapshot: null }`. The roster/route/self
72
+ /// fields are merged in by the bridge from the media adapter.
73
+ /// `conversationName` nil → NSNull; `reason`/`cameraFacing` omitted when nil.
74
+ func toSnapshot(conversationName: String? = nil,
75
+ kind: String = "call",
76
+ participants: [SnapshotParticipant] = [],
77
+ audioRoute: String = "earpiece",
78
+ audioOutputs: [AudioOutput] = [],
79
+ audioOutputId: String? = nil,
80
+ mutedSelf: Bool = false,
81
+ cameraOn: Bool = false,
82
+ cameraFacing: String? = nil,
83
+ waiting: RingContext? = nil,
84
+ connectionQuality: String = "unknown",
85
+ videoPaused: Bool = false) -> [String: Any]? {
86
+ if phase == .idle { return nil }
87
+ var out: [String: Any] = [
88
+ "cv": 1,
89
+ "callId": callId.map { $0 as Any } ?? NSNull(),
90
+ "conversationId": conversationId.map { $0 as Any } ?? NSNull(),
91
+ "conversationName": conversationName.map { $0 as Any } ?? NSNull(),
92
+ "kind": kind,
93
+ "direction": (direction ?? .incoming).wire,
94
+ "media": media,
95
+ "phase": phase.wire,
96
+ "participants": participants.map { $0.dictionary },
97
+ "audioRoute": audioRoute,
98
+ "audioOutputs": audioOutputs.map { $0.dictionary },
99
+ "audioOutputId": audioOutputId.map { $0 as Any } ?? NSNull(),
100
+ "mutedSelf": mutedSelf,
101
+ "cameraOn": cameraOn,
102
+ "connectionQuality": connectionQuality,
103
+ "videoPaused": videoPaused,
104
+ ]
105
+ // The call waiting beside this one: null when none.
106
+ if let w = self.waiting {
107
+ out["waiting"] = [
108
+ "callId": w.callId,
109
+ "conversationId": (waiting?.conversationId ?? w.conversationId).map { $0 as Any } ?? NSNull(),
110
+ "conversationName": waiting?.conversationName.map { $0 as Any } ?? NSNull(),
111
+ "callerName": waiting?.callerName.map { $0 as Any } ?? NSNull(),
112
+ "media": w.media,
113
+ ] as [String: Any]
114
+ } else {
115
+ out["waiting"] = NSNull()
116
+ }
117
+ if let reason = reason { out["reason"] = reason.wire }
118
+ // Optional in the contract: present only while a camera is published.
119
+ if let cameraFacing = cameraFacing { out["cameraFacing"] = cameraFacing }
120
+ return out
121
+ }
122
+ }
@@ -0,0 +1,70 @@
1
+ import ExpoModulesCore
2
+ import UIKit
3
+
4
+ /// `<CallVideoView>` on iOS: a thin host for the core's LiveKitVideoSurface.
5
+ /// All binding logic lives in the media adapter; this view forwards props
6
+ /// and ties the surface's lifetime to the window.
7
+ public final class PoolseCallVideoView: ExpoView {
8
+ private var surface: LiveKitVideoSurface?
9
+
10
+ var participantId: String?
11
+ var local = false
12
+ var mirror: Bool?
13
+ var fit = "cover"
14
+ /// This view is what picture-in-picture grows out of (a remote's picture).
15
+ var pictureInPicture = false
16
+
17
+ public required init(appContext: AppContext? = nil) {
18
+ super.init(appContext: appContext)
19
+ backgroundColor = .clear
20
+ clipsToBounds = true
21
+ }
22
+
23
+ public override func didMoveToWindow() {
24
+ super.didMoveToWindow()
25
+ if window != nil { attachSurface() } else { detachSurface() }
26
+ }
27
+
28
+ public override func layoutSubviews() {
29
+ super.layoutSubviews()
30
+ surface?.frame = bounds
31
+ }
32
+
33
+ private func attachSurface() {
34
+ guard surface == nil else { return }
35
+ // No core yet (never configured): stay empty; a later prop update retries.
36
+ guard let core = CallCore.peek() else { return }
37
+ let s = core.createVideoSurface()
38
+ s.frame = bounds
39
+ s.autoresizingMask = [.flexibleWidth, .flexibleHeight]
40
+ addSubview(s)
41
+ surface = s
42
+ apply()
43
+ }
44
+
45
+ func detachSurface() {
46
+ CallPictureInPicture.shared.clearSource(self)
47
+ guard let s = surface else { return }
48
+ surface = nil
49
+ s.release()
50
+ s.removeFromSuperview()
51
+ }
52
+
53
+ func apply() {
54
+ guard let s = surface else {
55
+ if window != nil { attachSurface() }
56
+ return
57
+ }
58
+ s.configure(participantId: participantId, local: local, mirror: mirror, fit: fit == "contain" ? "contain" : "cover")
59
+ if pictureInPicture && !local && participantId != nil {
60
+ CallPictureInPicture.shared.setSource(self, participantId: participantId)
61
+ } else {
62
+ CallPictureInPicture.shared.clearSource(self)
63
+ }
64
+ }
65
+
66
+ deinit {
67
+ // UIKit objects must be torn down on main; deinit of a view runs there.
68
+ surface?.release()
69
+ }
70
+ }
@@ -0,0 +1,16 @@
1
+ import ExpoModulesCore
2
+ import UIKit
3
+
4
+ /// Registers PushKit at launch, before React Native starts — the only
5
+ /// point early enough for a VoIP push that cold-launches a killed app.
6
+ /// Registered via expo-module.config.json "appDelegateSubscribers", so an
7
+ /// Expo host (AppDelegate: ExpoAppDelegate) needs no AppDelegate edit.
8
+ public class PoolseCallsAppDelegateSubscriber: ExpoAppDelegateSubscriber {
9
+ public func application(
10
+ _ application: UIApplication,
11
+ didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
12
+ ) -> Bool {
13
+ PoolseCallsSetup.registerVoipEarly()
14
+ return true
15
+ }
16
+ }