@poolse/native 3.2.0-dev.1 → 3.2.0-dev.2
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 +8 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +27 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallVideo.kt +16 -4
- package/android/src/main/java/dev/poolse/callcore/android/SnapshotJson.kt +3 -0
- package/android/src/main/java/expo/modules/poolsecalls/PoolseCallVideoView.kt +9 -1
- package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +46 -0
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +51 -1
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitVideoSurface.kt +10 -3
- package/dist/index.cjs +15 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/ios/Core/SnapshotEncoding.swift +5 -2
- package/ios/Module/PoolseCallVideoView.swift +3 -1
- package/ios/Module/PoolseCallsModule.swift +5 -0
- package/ios/Platform/LiveKitMediaPort.swift +23 -1
- package/ios/Platform/LiveKitVideoSurface.swift +9 -3
- package/package.json +1 -1
- package/src/index.ts +44 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Formerly `@poolse/react-native-calls` (0.x).
|
|
4
4
|
|
|
5
|
+
## 3.2.0-dev.2 — 2026-11-16 (prerelease, npm tag `dev`)
|
|
6
|
+
|
|
7
|
+
- Screen sharing. Android: `startScreenShare()` (the system asks first; resolves
|
|
8
|
+
whether the user allowed it), `stopScreenShare()` and `screenShareSupported()`;
|
|
9
|
+
the snapshot's `screenSharing` follows the published screen. Both platforms:
|
|
10
|
+
each participant's `screenSharing`, and `<CallVideoView source="screen">` draws
|
|
11
|
+
their shared screen (never mirrored). Sharing from iOS comes in a later release.
|
|
12
|
+
|
|
5
13
|
## 3.2.0-dev.1 — 2026-11-04 (prerelease, npm tag `dev`)
|
|
6
14
|
|
|
7
15
|
- Moves with `@poolse/sdk` 3.2.0-dev.1.
|
|
@@ -72,6 +72,7 @@ class CallCore private constructor(context: Context) {
|
|
|
72
72
|
private var mutedSelf = false
|
|
73
73
|
private var cameraOn = false
|
|
74
74
|
private var cameraFacing: String? = null
|
|
75
|
+
private var screenSharing = false
|
|
75
76
|
private var audioRoute: String? = null
|
|
76
77
|
private var audioOutputs: List<AudioOutput> = emptyList()
|
|
77
78
|
private var audioOutputId: String? = null
|
|
@@ -185,6 +186,21 @@ class CallCore private constructor(context: Context) {
|
|
|
185
186
|
|
|
186
187
|
fun switchCamera() = runtime.switchCamera()
|
|
187
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Share the screen with the result of the system's capture prompt, or
|
|
191
|
+
* stop ([permission] unused). Main thread. Not optimistic:
|
|
192
|
+
* `screenSharing` flips when the adapter reports the track published.
|
|
193
|
+
* False when the media engine cannot capture the screen.
|
|
194
|
+
*/
|
|
195
|
+
fun setScreenShare(on: Boolean, permission: android.content.Intent?): Boolean {
|
|
196
|
+
val source = media as? ScreenShareSource ?: return false
|
|
197
|
+
source.setScreenShare(on, permission)
|
|
198
|
+
return true
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Whether this build's media engine can share the screen. */
|
|
202
|
+
val screenShareSupported: Boolean get() = media is ScreenShareSource
|
|
203
|
+
|
|
188
204
|
/**
|
|
189
205
|
* A video slot for `<CallVideoView>`, or null when the media engine
|
|
190
206
|
* renders no video (signalling-only build). Main thread.
|
|
@@ -255,6 +271,7 @@ class CallCore private constructor(context: Context) {
|
|
|
255
271
|
"speaking" to it.speaking,
|
|
256
272
|
"muted" to it.muted,
|
|
257
273
|
"cameraOn" to it.cameraOn,
|
|
274
|
+
"screenSharing" to it.screenSharing,
|
|
258
275
|
"connectionQuality" to it.connectionQuality,
|
|
259
276
|
)
|
|
260
277
|
},
|
|
@@ -267,6 +284,7 @@ class CallCore private constructor(context: Context) {
|
|
|
267
284
|
waitingRing = runtime.waitingRing,
|
|
268
285
|
connectionQuality = connectionQuality,
|
|
269
286
|
videoPaused = videoPaused,
|
|
287
|
+
screenSharing = screenSharing,
|
|
270
288
|
)
|
|
271
289
|
lastSnapshot = snap
|
|
272
290
|
reconcileAndroid(state)
|
|
@@ -288,6 +306,7 @@ class CallCore private constructor(context: Context) {
|
|
|
288
306
|
// Reported by the media adapter once the camera is really published.
|
|
289
307
|
cameraOn = false
|
|
290
308
|
cameraFacing = null
|
|
309
|
+
screenSharing = false
|
|
291
310
|
audioRoute = null
|
|
292
311
|
audioOutputs = emptyList()
|
|
293
312
|
audioOutputId = null
|
|
@@ -359,6 +378,10 @@ class CallCore private constructor(context: Context) {
|
|
|
359
378
|
runtime.post { cameraOn = on; cameraFacing = facing }
|
|
360
379
|
runtime.reemit()
|
|
361
380
|
}
|
|
381
|
+
override fun onLocalScreen(on: Boolean) {
|
|
382
|
+
runtime.post { screenSharing = on }
|
|
383
|
+
runtime.reemit()
|
|
384
|
+
}
|
|
362
385
|
override fun onAudioOutputs(outputs: List<AudioOutput>, selectedId: String?) {
|
|
363
386
|
runtime.post { audioOutputs = outputs; audioOutputId = selectedId }
|
|
364
387
|
runtime.reemit()
|
|
@@ -545,6 +568,8 @@ interface MediaEvents {
|
|
|
545
568
|
fun onAudioRoute(route: String)
|
|
546
569
|
/** The local camera track is (not) published + enabled; [facing] `front` | `back`. */
|
|
547
570
|
fun onLocalCamera(on: Boolean, facing: String?) {}
|
|
571
|
+
/** The local screen share is (not) published. */
|
|
572
|
+
fun onLocalScreen(on: Boolean) {}
|
|
548
573
|
/** Every output call audio can play through right now, and the one it does. */
|
|
549
574
|
fun onAudioOutputs(outputs: List<AudioOutput>, selectedId: String?) {}
|
|
550
575
|
/**
|
|
@@ -571,6 +596,8 @@ data class MediaParticipant(
|
|
|
571
596
|
val muted: Boolean,
|
|
572
597
|
/** True only with a published, subscribed, unmuted camera track — a frame to draw. */
|
|
573
598
|
val cameraOn: Boolean = false,
|
|
599
|
+
/** True with a published, subscribed, unmuted screen share — a screen to draw. */
|
|
600
|
+
val screenSharing: Boolean = false,
|
|
574
601
|
/** The host app's own id for the user, when the SFU carries it; else the identity. */
|
|
575
602
|
val externalId: String = identity,
|
|
576
603
|
/** Their link to the SFU: `good` | `poor` | `lost` (dropped, coming back) | `unknown`. */
|
|
@@ -17,7 +17,17 @@ interface CallVideoSource {
|
|
|
17
17
|
fun createVideoSurface(context: Context): CallVideoSurface
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Screen sharing, for a media port that can capture the screen. The
|
|
22
|
+
* permission is the result of the system's screen-capture prompt
|
|
23
|
+
* (`MediaProjectionManager.createScreenCaptureIntent`), which only an
|
|
24
|
+
* Activity can ask for; the bridge asks and hands the result here.
|
|
25
|
+
*/
|
|
26
|
+
interface ScreenShareSource {
|
|
27
|
+
fun setScreenShare(on: Boolean, permission: android.content.Intent?)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** One on-screen video slot, bound to a participant's camera or shared screen. */
|
|
21
31
|
interface CallVideoSurface {
|
|
22
32
|
/** The Android view to host; it fills its parent. */
|
|
23
33
|
val view: View
|
|
@@ -26,10 +36,12 @@ interface CallVideoSurface {
|
|
|
26
36
|
* What to show. [participantId] is the remote's userId (SFU
|
|
27
37
|
* identity); [local] shows the self view instead. [mirror] null =
|
|
28
38
|
* the default (mirrored for the local front camera only). [fit] is
|
|
29
|
-
* `cover` or `contain`.
|
|
30
|
-
*
|
|
39
|
+
* `cover` or `contain`. [source] is `camera` or `screen` (a shared
|
|
40
|
+
* screen is never mirrored). Rebinds immediately and again whenever
|
|
41
|
+
* the underlying track appears, disappears, mutes or the room is
|
|
42
|
+
* replaced.
|
|
31
43
|
*/
|
|
32
|
-
fun configure(participantId: String?, local: Boolean, mirror: Boolean?, fit: String)
|
|
44
|
+
fun configure(participantId: String?, local: Boolean, mirror: Boolean?, fit: String, source: String = "camera")
|
|
33
45
|
|
|
34
46
|
/** Detach from any track and free the renderer. Idempotent. */
|
|
35
47
|
fun release()
|
|
@@ -30,6 +30,8 @@ internal fun MachineState.toSnapshot(
|
|
|
30
30
|
connectionQuality: String = "unknown",
|
|
31
31
|
/** Incoming video switched off to keep the audio going. */
|
|
32
32
|
videoPaused: Boolean = false,
|
|
33
|
+
/** We are sharing our screen. */
|
|
34
|
+
screenSharing: Boolean = false,
|
|
33
35
|
): Map<String, Any?>? {
|
|
34
36
|
if (phase == Phase.IDLE) return null
|
|
35
37
|
return buildMap {
|
|
@@ -37,6 +39,7 @@ internal fun MachineState.toSnapshot(
|
|
|
37
39
|
put("kind", kind)
|
|
38
40
|
put("connectionQuality", connectionQuality)
|
|
39
41
|
put("videoPaused", videoPaused)
|
|
42
|
+
put("screenSharing", screenSharing)
|
|
40
43
|
put("audioOutputs", audioOutputs)
|
|
41
44
|
put("audioOutputId", audioOutputId)
|
|
42
45
|
// Optional in the contract: present only while a camera is published.
|
|
@@ -29,6 +29,8 @@ class PoolseCallVideoView(context: Context, appContext: AppContext) : ExpoView(c
|
|
|
29
29
|
set(v) { field = v; apply() }
|
|
30
30
|
var fit: String = "cover"
|
|
31
31
|
set(v) { field = v; apply() }
|
|
32
|
+
var source: String = "camera"
|
|
33
|
+
set(v) { field = v; apply() }
|
|
32
34
|
|
|
33
35
|
override fun onAttachedToWindow() {
|
|
34
36
|
super.onAttachedToWindow()
|
|
@@ -59,6 +61,12 @@ class PoolseCallVideoView(context: Context, appContext: AppContext) : ExpoView(c
|
|
|
59
61
|
private fun apply() {
|
|
60
62
|
// Mounted before the core existed (configure still pending): try again.
|
|
61
63
|
val s = surface ?: run { if (isAttachedToWindow) attachSurface(); return }
|
|
62
|
-
s.configure(
|
|
64
|
+
s.configure(
|
|
65
|
+
participantId,
|
|
66
|
+
local,
|
|
67
|
+
mirror,
|
|
68
|
+
if (fit == "contain") "contain" else "cover",
|
|
69
|
+
if (source == "screen") "screen" else "camera",
|
|
70
|
+
)
|
|
63
71
|
}
|
|
64
72
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
package expo.modules.poolsecalls
|
|
2
2
|
|
|
3
|
+
import android.app.Activity
|
|
3
4
|
import android.app.NotificationManager
|
|
4
5
|
import android.content.Context
|
|
5
6
|
import android.content.Intent
|
|
7
|
+
import android.media.projection.MediaProjectionManager
|
|
6
8
|
import android.net.Uri
|
|
7
9
|
import android.os.Build
|
|
8
10
|
import android.provider.Settings
|
|
@@ -10,6 +12,7 @@ import android.util.Log
|
|
|
10
12
|
import dev.poolse.callcore.android.CallCore
|
|
11
13
|
import dev.poolse.callcore.android.MessageNotifications
|
|
12
14
|
import dev.poolse.callcore.android.MissedCallNotification
|
|
15
|
+
import expo.modules.kotlin.Promise
|
|
13
16
|
import expo.modules.kotlin.modules.Module
|
|
14
17
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
15
18
|
|
|
@@ -41,6 +44,8 @@ class PoolseCallsModule : Module() {
|
|
|
41
44
|
Prop("local") { view: PoolseCallVideoView, local: Boolean? -> view.local = local ?: false }
|
|
42
45
|
Prop("mirror") { view: PoolseCallVideoView, mirror: Boolean? -> view.mirror = mirror }
|
|
43
46
|
Prop("fit") { view: PoolseCallVideoView, fit: String? -> view.fit = fit ?: "cover" }
|
|
47
|
+
// `camera` (default) or `screen`: their shared screen instead of their face.
|
|
48
|
+
Prop("source") { view: PoolseCallVideoView, source: String? -> view.source = source ?: "camera" }
|
|
44
49
|
// iOS's picture-in-picture source; Android floats the whole activity.
|
|
45
50
|
Prop("pictureInPicture") { _: PoolseCallVideoView, _: Boolean? -> }
|
|
46
51
|
OnViewDestroys { view: PoolseCallVideoView -> view.detachSurface() }
|
|
@@ -102,6 +107,43 @@ class PoolseCallsModule : Module() {
|
|
|
102
107
|
Function("declineWaiting") { callId: String? -> core()?.declineWaiting(callId) }
|
|
103
108
|
Function("setMuted") { muted: Boolean -> core()?.setMuted(muted) }
|
|
104
109
|
Function("setCamera") { on: Boolean -> core()?.setCamera(on) }
|
|
110
|
+
|
|
111
|
+
// Screen sharing: the system asks the user first (only an Activity
|
|
112
|
+
// can), then the core publishes with that answer. Resolves whether
|
|
113
|
+
// the user allowed it; the snapshot's `screenSharing` follows once
|
|
114
|
+
// the screen is actually published.
|
|
115
|
+
Function("screenShareSupported") { core()?.screenShareSupported ?: false }
|
|
116
|
+
AsyncFunction("startScreenShare") { promise: Promise ->
|
|
117
|
+
val activity = appContext.currentActivity
|
|
118
|
+
val core = core()
|
|
119
|
+
if (activity == null || core == null || !core.screenShareSupported) {
|
|
120
|
+
promise.resolve(false)
|
|
121
|
+
return@AsyncFunction
|
|
122
|
+
}
|
|
123
|
+
pendingShare?.resolve(false)
|
|
124
|
+
pendingShare = promise
|
|
125
|
+
val manager = activity.getSystemService(MediaProjectionManager::class.java)
|
|
126
|
+
activity.runOnUiThread {
|
|
127
|
+
runCatching { activity.startActivityForResult(manager.createScreenCaptureIntent(), SCREEN_SHARE_REQUEST) }
|
|
128
|
+
.onFailure {
|
|
129
|
+
Log.w(TAG, "screen capture prompt failed", it)
|
|
130
|
+
pendingShare?.resolve(false)
|
|
131
|
+
pendingShare = null
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
Function("stopScreenShare") { core()?.setScreenShare(false, null) }
|
|
136
|
+
OnActivityResult { _, payload ->
|
|
137
|
+
if (payload.requestCode != SCREEN_SHARE_REQUEST) return@OnActivityResult
|
|
138
|
+
val promise = pendingShare
|
|
139
|
+
pendingShare = null
|
|
140
|
+
val data = payload.data
|
|
141
|
+
if (payload.resultCode == Activity.RESULT_OK && data != null) {
|
|
142
|
+
promise?.resolve(core()?.setScreenShare(true, data) ?: false)
|
|
143
|
+
} else {
|
|
144
|
+
promise?.resolve(false)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
105
147
|
Function("switchCamera") { core()?.switchCamera() }
|
|
106
148
|
Function("setSpeaker") { on: Boolean -> core()?.setSpeaker(on) }
|
|
107
149
|
Function("setAudioOutput") { id: String -> core()?.setAudioOutput(id) }
|
|
@@ -174,6 +216,9 @@ class PoolseCallsModule : Module() {
|
|
|
174
216
|
|
|
175
217
|
private fun core(): CallCore? = context?.let(CallCore::getOrNull)
|
|
176
218
|
|
|
219
|
+
/** The startScreenShare waiting on the system's capture prompt. */
|
|
220
|
+
private var pendingShare: Promise? = null
|
|
221
|
+
|
|
177
222
|
/**
|
|
178
223
|
* The call action an intent carries, removed from it so a later read
|
|
179
224
|
* (rotation, re-mount) cannot replay it. Acting on it from the app
|
|
@@ -201,5 +246,6 @@ class PoolseCallsModule : Module() {
|
|
|
201
246
|
|
|
202
247
|
private companion object {
|
|
203
248
|
const val TAG = "PoolseCalls"
|
|
249
|
+
const val SCREEN_SHARE_REQUEST = 0x5C5E
|
|
204
250
|
}
|
|
205
251
|
}
|
|
@@ -2,6 +2,7 @@ package dev.poolse.callcore.livekit
|
|
|
2
2
|
|
|
3
3
|
import android.Manifest
|
|
4
4
|
import android.content.Context
|
|
5
|
+
import android.content.Intent
|
|
5
6
|
import android.content.pm.PackageManager
|
|
6
7
|
import android.util.Log
|
|
7
8
|
import androidx.core.content.ContextCompat
|
|
@@ -13,6 +14,7 @@ import dev.poolse.callcore.android.CallVideoSource
|
|
|
13
14
|
import dev.poolse.callcore.android.CallVideoSurface
|
|
14
15
|
import dev.poolse.callcore.android.MediaEvents
|
|
15
16
|
import dev.poolse.callcore.android.MediaParticipant
|
|
17
|
+
import dev.poolse.callcore.android.ScreenShareSource
|
|
16
18
|
import io.livekit.android.ConnectOptions
|
|
17
19
|
import io.livekit.android.LiveKit
|
|
18
20
|
import io.livekit.android.audio.AudioSwitchHandler
|
|
@@ -56,7 +58,7 @@ import org.json.JSONObject
|
|
|
56
58
|
class LiveKitMediaPort(
|
|
57
59
|
private val context: Context,
|
|
58
60
|
private val events: MediaEvents,
|
|
59
|
-
) : MediaPort, CallVideoSource {
|
|
61
|
+
) : MediaPort, CallVideoSource, ScreenShareSource {
|
|
60
62
|
|
|
61
63
|
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
|
|
62
64
|
@Volatile private var room: Room? = null
|
|
@@ -201,6 +203,7 @@ class LiveKitMediaPort(
|
|
|
201
203
|
refreshVideo()
|
|
202
204
|
teardown(r)
|
|
203
205
|
events.onLocalCamera(false, null)
|
|
206
|
+
events.onLocalScreen(false)
|
|
204
207
|
}
|
|
205
208
|
|
|
206
209
|
private fun teardown(r: Room) {
|
|
@@ -228,6 +231,24 @@ class LiveKitMediaPort(
|
|
|
228
231
|
}
|
|
229
232
|
}
|
|
230
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Publish the screen with the user's answer to the capture prompt, or
|
|
236
|
+
* stop. LiveKit runs its own `mediaProjection` foreground service for
|
|
237
|
+
* the capture (Android 14 requires one), with its own notification.
|
|
238
|
+
* A refusal is logged and reported as not sharing: the call goes on.
|
|
239
|
+
*/
|
|
240
|
+
override fun setScreenShare(on: Boolean, permission: Intent?) {
|
|
241
|
+
val r = room ?: return
|
|
242
|
+
if (on && permission == null) return
|
|
243
|
+
scope.launch {
|
|
244
|
+
runCatching { r.localParticipant.setScreenShareEnabled(on, if (on) permission else null) }
|
|
245
|
+
.onFailure { Log.w(TAG, "screen share ${if (on) "start" else "stop"} failed", it) }
|
|
246
|
+
if (room !== r) return@launch
|
|
247
|
+
reportLocalScreen(r)
|
|
248
|
+
refreshVideo()
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
231
252
|
/** Front ↔ back on the published camera track. */
|
|
232
253
|
override fun switchCamera() {
|
|
233
254
|
val r = room ?: return
|
|
@@ -280,6 +301,31 @@ class LiveKitMediaPort(
|
|
|
280
301
|
return pub.track as? VideoTrack
|
|
281
302
|
}
|
|
282
303
|
|
|
304
|
+
private fun localScreenTrack(r: Room): VideoTrack? =
|
|
305
|
+
r.localParticipant.getTrackPublication(Track.Source.SCREEN_SHARE)
|
|
306
|
+
?.takeIf { !it.muted }?.track as? VideoTrack
|
|
307
|
+
|
|
308
|
+
/** A participant's shared screen, once published, subscribed and unmuted. */
|
|
309
|
+
internal fun screenTrack(participantId: String?, local: Boolean): VideoTrack? {
|
|
310
|
+
val r = room ?: return null
|
|
311
|
+
if (local) return localScreenTrack(r)
|
|
312
|
+
val p = r.remoteParticipants.values.firstOrNull { it.identity?.value == participantId } ?: return null
|
|
313
|
+
return remoteScreen(p)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Not paused with the cameras on a weak link: the shared screen is
|
|
317
|
+
// usually what the call is about.
|
|
318
|
+
private fun remoteScreen(p: Participant): VideoTrack? {
|
|
319
|
+
val pub = p.getTrackPublication(Track.Source.SCREEN_SHARE) as? RemoteTrackPublication ?: return null
|
|
320
|
+
if (!pub.subscribed || pub.muted) return null
|
|
321
|
+
return pub.track as? VideoTrack
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
private fun reportLocalScreen(r: Room) {
|
|
325
|
+
if (room !== r) return
|
|
326
|
+
events.onLocalScreen(localScreenTrack(r) != null)
|
|
327
|
+
}
|
|
328
|
+
|
|
283
329
|
/** `front` | `back` of the published local camera, or null when none. */
|
|
284
330
|
internal fun cameraFacing(): String? {
|
|
285
331
|
val r = room ?: return null
|
|
@@ -454,6 +500,9 @@ class LiveKitMediaPort(
|
|
|
454
500
|
if (videoPaused) applyVideoPause(room)
|
|
455
501
|
emit(room)
|
|
456
502
|
reportLocalCamera(room)
|
|
503
|
+
// Also how a share stopped from the system's capture
|
|
504
|
+
// notification (not from our button) reaches the snapshot.
|
|
505
|
+
reportLocalScreen(room)
|
|
457
506
|
refreshVideo()
|
|
458
507
|
}
|
|
459
508
|
is RoomEvent.ConnectionQualityChanged -> {
|
|
@@ -481,6 +530,7 @@ class LiveKitMediaPort(
|
|
|
481
530
|
// Video, not avatar, only when there is a frame to draw:
|
|
482
531
|
// published, subscribed and unmuted.
|
|
483
532
|
cameraOn = remoteCamera(it) != null,
|
|
533
|
+
screenSharing = remoteScreen(it) != null,
|
|
484
534
|
connectionQuality = wire(it.connectionQuality),
|
|
485
535
|
externalId = externalIdOf(it) ?: identity,
|
|
486
536
|
)
|
|
@@ -39,12 +39,14 @@ internal class LiveKitVideoSurface(
|
|
|
39
39
|
private var local = false
|
|
40
40
|
private var mirror: Boolean? = null
|
|
41
41
|
private var fit = "cover"
|
|
42
|
+
private var source = "camera"
|
|
42
43
|
|
|
43
|
-
override fun configure(participantId: String?, local: Boolean, mirror: Boolean?, fit: String) {
|
|
44
|
+
override fun configure(participantId: String?, local: Boolean, mirror: Boolean?, fit: String, source: String) {
|
|
44
45
|
this.participantId = participantId
|
|
45
46
|
this.local = local
|
|
46
47
|
this.mirror = mirror
|
|
47
48
|
this.fit = fit
|
|
49
|
+
this.source = source
|
|
48
50
|
rebind()
|
|
49
51
|
}
|
|
50
52
|
|
|
@@ -63,7 +65,12 @@ internal class LiveKitVideoSurface(
|
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
val
|
|
68
|
+
val screen = source == "screen"
|
|
69
|
+
val next = when {
|
|
70
|
+
initRoom == null -> null
|
|
71
|
+
screen -> port.screenTrack(participantId, local)
|
|
72
|
+
else -> port.cameraTrack(participantId, local)
|
|
73
|
+
}
|
|
67
74
|
if (next !== track) {
|
|
68
75
|
detachTrack()
|
|
69
76
|
if (next != null) {
|
|
@@ -76,7 +83,7 @@ internal class LiveKitVideoSurface(
|
|
|
76
83
|
renderer.visibility = if (track != null) View.VISIBLE else View.INVISIBLE
|
|
77
84
|
if (initRoom != null) {
|
|
78
85
|
runCatching {
|
|
79
|
-
renderer.setMirror(mirror ?: (local && port.cameraFacing() != "back"))
|
|
86
|
+
renderer.setMirror(!screen && (mirror ?: (local && port.cameraFacing() != "back")))
|
|
80
87
|
renderer.setScalingType(
|
|
81
88
|
if (fit == "contain") RendererCommon.ScalingType.SCALE_ASPECT_FIT
|
|
82
89
|
else RendererCommon.ScalingType.SCALE_ASPECT_FILL,
|
package/dist/index.cjs
CHANGED
|
@@ -76,6 +76,9 @@ var declineWaiting = (callId) => native?.declineWaiting?.(callId ?? null);
|
|
|
76
76
|
var setMuted = (muted) => native?.setMuted(muted);
|
|
77
77
|
var setCamera = (on) => native?.setCamera(on);
|
|
78
78
|
var switchCamera = () => native?.switchCamera();
|
|
79
|
+
var screenShareSupported = () => native?.screenShareSupported?.() ?? false;
|
|
80
|
+
var startScreenShare = async () => await native?.startScreenShare?.() ?? false;
|
|
81
|
+
var stopScreenShare = () => native?.stopScreenShare?.();
|
|
79
82
|
var setSpeaker = (on) => native?.setSpeaker(on);
|
|
80
83
|
function setAudioOutput(id) {
|
|
81
84
|
if (native?.setAudioOutput) native.setAudioOutput(id);
|
|
@@ -152,7 +155,15 @@ function nativeVideoView() {
|
|
|
152
155
|
function CallVideoView(props) {
|
|
153
156
|
const Native = nativeVideoView();
|
|
154
157
|
if (!Native) {
|
|
155
|
-
const {
|
|
158
|
+
const {
|
|
159
|
+
participantId: _p,
|
|
160
|
+
local: _l,
|
|
161
|
+
mirror: _m,
|
|
162
|
+
fit: _f,
|
|
163
|
+
source: _s,
|
|
164
|
+
pictureInPicture: _pip,
|
|
165
|
+
...rest
|
|
166
|
+
} = props;
|
|
156
167
|
return react.createElement(reactNative.View, rest);
|
|
157
168
|
}
|
|
158
169
|
return react.createElement(Native, props);
|
|
@@ -182,6 +193,7 @@ exports.openFullScreenIntentSettings = openFullScreenIntentSettings;
|
|
|
182
193
|
exports.pictureInPictureSupported = pictureInPictureSupported;
|
|
183
194
|
exports.place = place;
|
|
184
195
|
exports.ringIntoCall = ringIntoCall;
|
|
196
|
+
exports.screenShareSupported = screenShareSupported;
|
|
185
197
|
exports.setActiveConversation = setActiveConversation;
|
|
186
198
|
exports.setAudioOutput = setAudioOutput;
|
|
187
199
|
exports.setCamera = setCamera;
|
|
@@ -191,6 +203,8 @@ exports.setShowOnLockscreen = setShowOnLockscreen;
|
|
|
191
203
|
exports.setSpeaker = setSpeaker;
|
|
192
204
|
exports.shouldPresentMessage = shouldPresentMessage;
|
|
193
205
|
exports.startRoom = startRoom;
|
|
206
|
+
exports.startScreenShare = startScreenShare;
|
|
207
|
+
exports.stopScreenShare = stopScreenShare;
|
|
194
208
|
exports.switchCamera = switchCamera;
|
|
195
209
|
exports.takeCallAction = takeCallAction;
|
|
196
210
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["requireOptionalNativeModule","requireNativeViewManager","createElement","View"],"mappings":";;;;;;;AAqMA,IAAM,MAAA,GAASA,4CAA+C,aAAa,CAAA;AAGpE,IAAM,uBAAuB,MAAA,IAAU;AAG9C,IAAI,SAAA,GAA2B,IAAA;AAG/B,eAAsB,SAAA,CAAU,YAAoB,OAAA,EAA2C;AAC7F,EAAA,SAAA,GAAY,UAAA,CAAW,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA;AACzC,EAAA,MAAM,MAAA,EAAQ,SAAA,CAAU,UAAA,EAAY,OAAA,IAAW,IAAI,CAAA;AACrD;AAGO,SAAS,YAAA,GAAgC;AAC9C,EAAA,OAAO,MAAA,EAAQ,YAAA,EAAa,CAAE,QAAA,IAAY,IAAA;AAC5C;AAKO,SAAS,YAAY,EAAA,EAAsD;AAChF,EAAA,IAAI,CAAC,MAAA,EAAQ,OAAO,MAAM,MAAA;AAC1B,EAAA,MAAM,GAAA,GAAM,OAAO,WAAA,CAAY,aAAA,EAAe,CAAC,OAAA,KAAY,EAAA,CAAG,OAAA,CAAQ,QAAQ,CAAC,CAAA;AAC/E,EAAA,OAAO,MAAM,IAAI,MAAA,EAAO;AAC1B;AAEO,SAAS,KAAA,CAAM,gBAAwB,OAAA,EAAsC;AAClF,EAAA,OAAO,MAAA,EAAQ,MAAM,cAAA,EAAgB,OAAA,CAAQ,OAAO,OAAA,CAAQ,YAAY,C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CAAA;AACpC","file":"index.cjs","sourcesContent":["// @poolse/native — the React Native face of the native\n// call core (CALL_CONTRACT.md §8). A thin, typed surface over the native\n// module: commands in, one snapshot event out. All call logic lives in\n// the native cores; nothing here decides anything about a call.\n//\n// On a platform or build without the native module (Expo Go, web,\n// unlinked), every command is a safe no-op and the state stays idle —\n// so a host can render against this unconditionally.\nimport { createElement, type ComponentType, type ReactElement } from 'react';\nimport { View, type ViewProps } from 'react-native';\nimport { requireNativeViewManager, requireOptionalNativeModule } from 'expo-modules-core';\n\n/**\n * A call's complete state. `null` means idle — no call. After a call\n * ends the snapshot stays `phase: 'ended'` (with `reason`) for ~2.5 s,\n * then becomes `null`.\n */\nexport interface Snapshot {\n cv: 1;\n callId: string;\n conversationId: string;\n conversationName: string | null;\n direction: 'incoming' | 'outgoing' | 'joined';\n /**\n * `room` — rings nobody, joined and left at will (`startRoom`); `call`\n * otherwise. Known once the server answered: a room being joined reads\n * `call` while `connecting`. Absent before 0.9.0: treat as `call`.\n */\n kind?: 'call' | 'room';\n media: 'audio' | 'video';\n phase: 'ringing_in' | 'ringing_out' | 'connecting' | 'active' | 'reconnecting' | 'ended';\n reason?:\n | 'left'\n | 'finished'\n | 'declined_all'\n | 'busy_all'\n | 'no_answer'\n | 'cancelled'\n | 'connection_lost'\n | 'failed';\n /** REMOTE participants only; `userId` is the LiveKit identity. */\n participants: Array<{\n userId: string;\n externalId: string;\n speaking: boolean;\n muted: boolean;\n /** True only with a published, subscribed, unmuted camera track (show video, not avatar). */\n cameraOn: boolean;\n /**\n * Their link to the call: `lost` while they have dropped and are\n * coming back (show \"Reconnecting…\"), `poor` for a weak signal.\n * Absent before 0.11.0.\n */\n connectionQuality?: ConnectionQuality;\n }>;\n /** The kind of output playing now — the short answer to \"where is the audio\". */\n audioRoute: AudioOutputKind;\n /**\n * Every output the call can play through right now: always the phone\n * (earpiece, or wired headphones in its place) and the speaker, plus\n * each connected Bluetooth / USB device by its own name. Empty until\n * the call's audio is up. Pass an `id` to `setAudioOutput`.\n */\n audioOutputs: AudioOutput[];\n /** The `audioOutputs` entry playing now; null before audio is up. */\n audioOutputId: string | null;\n mutedSelf: boolean;\n /** True only while the local camera track is actually published and enabled. */\n cameraOn: boolean;\n /**\n * A second call ringing while this one is in progress (call waiting).\n * Offer `answerWaiting` (\"End & answer\" — this call ends) and\n * `declineWaiting` (its caller hears busy). If this call ends first,\n * the waiting one simply becomes the ringing call. null when none;\n * absent before 0.10.0.\n */\n waiting?: WaitingCall | null;\n /** Facing of the published local camera; absent when the camera is off. */\n cameraFacing?: 'front' | 'back';\n /**\n * Your own link to the call. `poor` / `lost`: show a \"weak connection\"\n * hint; `phase: 'reconnecting'` is the hard version of the same thing.\n * Absent before 0.11.0.\n */\n connectionQuality?: ConnectionQuality;\n /**\n * Incoming video is switched off because your connection could not\n * carry it — the audio keeps going, and video comes back by itself\n * once the link has been good for a few seconds. Participants read\n * `cameraOn: false` meanwhile. Absent before 0.11.0.\n */\n videoPaused?: boolean;\n}\n\n/** `good` covers good and excellent; `unknown` until the SFU has measured. */\nexport type ConnectionQuality = 'good' | 'poor' | 'lost' | 'unknown';\n\nexport type AudioOutputKind = 'earpiece' | 'speaker' | 'bluetooth' | 'headset';\n\n/** The call waiting beside the current one. */\nexport interface WaitingCall {\n callId: string;\n conversationId: string | null;\n conversationName: string | null;\n callerName: string | null;\n media: 'audio' | 'video';\n}\n\n/** One place call audio can play. */\nexport interface AudioOutput {\n /** Opaque; stable while the device stays connected. */\n id: string;\n kind: AudioOutputKind;\n /**\n * The device's own name for Bluetooth/USB (\"AirPods Pro\"); a plain\n * English default for built-ins (\"iPhone\"/\"Phone\", \"Speaker\",\n * \"Headphones\") — relabel those by `kind` to localise.\n */\n name: string;\n}\n\nexport interface ConfigureOptions {\n /** Drawable resource NAME for the call notification's small icon. */\n smallIcon?: string;\n /** Ringback tone: raw resource NAME (Android); main-bundle sound name, mp3/caf/wav (iOS). */\n ringback?: string;\n /**\n * iOS: the APNs environment of this build's `aps-environment`\n * entitlement. Echoed back with the VoIP token so the server pushes to\n * the right gateway. Ignored on Android.\n */\n apnsEnvironment?: 'production' | 'sandbox';\n}\n\n/** The iOS PushKit (VoIP) token and the APNs environment it belongs to. */\nexport interface VoipToken {\n /** Hex-encoded PushKit token. */\n token: string;\n environment: 'production' | 'sandbox' | string;\n}\n\nexport interface PlaceOptions {\n media: 'audio' | 'video';\n /** The user's session token — authorizes placing/joining (CALL_CONTRACT.md §3.2). */\n sessionToken: string;\n}\n\n/**\n * What the user tapped on a missed-call notification: the notification\n * itself (`open` the conversation) or its Call back button (`call_back`\n * — place a call on the conversation with `media`).\n */\nexport interface CallAction {\n type: 'open' | 'call_back';\n conversationId: string;\n callId: string | null;\n media: 'audio' | 'video';\n}\n\ntype NativeSnapshot = { snapshot: Snapshot | null };\n\ninterface PoolseCallsNative {\n configure(apiBaseUrl: string, options: ConfigureOptions | null): Promise<void>;\n getCallState(): NativeSnapshot;\n place(conversationId: string, media: string, sessionToken: string): Promise<void>;\n join(callId: string, conversationId: string | null, sessionToken: string): Promise<void>;\n answer(): void;\n decline(): void;\n hangUp(): void;\n answerWaiting?(callId: string | null): void;\n declineWaiting?(callId: string | null): void;\n setMuted(muted: boolean): void;\n setCamera(on: boolean): void;\n switchCamera(): void;\n setSpeaker(on: boolean): void;\n setAudioOutput?(id: string): void;\n callControl?(): Promise<{ callId: string; controlToken: string } | null>;\n setPictureInPictureEnabled?(on: boolean): void;\n isInPictureInPicture?(): boolean;\n pictureInPictureSupported?(): boolean;\n onRingEnded(callId: string, reason: string): void;\n onCallFinished(callId: string, reason: string | null): void;\n canUseFullScreenIntent(): boolean;\n openFullScreenIntentSettings(): void;\n setShowOnLockscreen?(enabled: boolean): void;\n getVoipToken?(): VoipToken | null;\n takeCallAction?(): CallAction | null;\n setActiveConversation?(conversationId: string | null): void;\n addListener(event: 'onCallState', cb: (payload: NativeSnapshot) => void): { remove(): void };\n addListener(event: 'onVoipToken', cb: (payload: VoipToken) => void): { remove(): void };\n addListener(event: 'onCallAction', cb: (payload: CallAction) => void): { remove(): void };\n addListener(\n event: 'onPictureInPicture',\n cb: (payload: { active: boolean }) => void,\n ): { remove(): void };\n}\n\nconst native = requireOptionalNativeModule<PoolseCallsNative>('PoolseCalls');\n\n/** True when the native call core is present in this build. */\nexport const nativeCallsAvailable = native != null;\n\n// Kept for startRoom, the one command that talks to the server from JS.\nlet apiOrigin: string | null = null;\n\n/** Configure once, before any call can arrive. No secrets — just the API origin. */\nexport async function configure(apiBaseUrl: string, options?: ConfigureOptions): Promise<void> {\n apiOrigin = apiBaseUrl.replace(/\\/+$/, '');\n await native?.configure(apiBaseUrl, options ?? null);\n}\n\n/** The current snapshot — safe to read at any moment, including cold answer and before configure. */\nexport function getCallState(): Snapshot | null {\n return native?.getCallState().snapshot ?? null;\n}\n\nexport type Unsubscribe = () => void;\n\n/** Subscribe to call state. Fires a full snapshot on every change. */\nexport function onCallState(cb: (snapshot: Snapshot | null) => void): Unsubscribe {\n if (!native) return () => undefined;\n const sub = native.addListener('onCallState', (payload) => cb(payload.snapshot));\n return () => sub.remove();\n}\n\nexport function place(conversationId: string, options: PlaceOptions): Promise<void> {\n return native?.place(conversationId, options.media, options.sessionToken) ?? Promise.resolve();\n}\n\nexport function join(\n callId: string,\n conversationId: string | null,\n sessionToken: string,\n): Promise<void> {\n return native?.join(callId, conversationId, sessionToken) ?? Promise.resolve();\n}\n\nexport interface StartRoomResult {\n /** The room's call id — what the Join banner and `call:*` events carry. */\n callId: string;\n /** False when something was live already (a room, or a ringing call) and this joined it. */\n created: boolean;\n}\n\n/**\n * Start the conversation's room — a call that rings nobody (CALL_CONTRACT.md\n * §5.6) — or join whatever is live there, then carry it on the native\n * core like any joined call: CallKit / the call service, so it keeps\n * going with the phone locked, and the same audio routing as a call.\n *\n * Others in the conversation see it through the Join banner and join it\n * with `join`. Leaving (`hangUp`) never ends it for them; it ends once\n * it has been empty for a short grace. `media: 'video'` makes it a video\n * room. Rejects when the server refuses (not a member, no SFU) or\n * before `configure`.\n */\nexport async function startRoom(\n conversationId: string,\n options: PlaceOptions,\n): Promise<StartRoomResult> {\n if (!native) throw new Error('The native call core is not in this build.');\n if (!apiOrigin) throw new Error('Call configure() before startRoom().');\n const res = await fetch(\n `${apiOrigin}/v1/conversations/${encodeURIComponent(conversationId)}/room`,\n {\n method: 'POST',\n headers: {\n authorization: `Bearer ${options.sessionToken}`,\n 'content-type': 'application/json',\n },\n body: JSON.stringify({ media: options.media }),\n },\n );\n const body = (await res.json().catch(() => null)) as {\n created?: boolean;\n call?: { id?: string };\n error?: { message?: string };\n } | null;\n const callId = body?.call?.id;\n if (!res.ok || !callId) {\n throw new Error(body?.error?.message ?? `Couldn't start the room (${res.status}).`);\n }\n // The core joins with its own request: it owns the session from here,\n // exactly as when the room is joined from the banner.\n await native.join(callId, conversationId, options.sessionToken);\n return { callId, created: body?.created === true };\n}\n\n/** Who to ring into the call — poolse user ids, your app's own (external) ids, or both. */\nexport interface RingIntoCallOptions {\n userIds?: string[];\n externalIds?: string[];\n}\n\n/**\n * Ring more of the conversation's members into the call you are on\n * (\"Add people\"). Each is rung as on a fresh call — their phone rings,\n * CallKit / full-screen — and answering puts them in this call.\n *\n * Resolves with the poolse user ids actually rung: anyone already in\n * the call, still ringing, or not a member of the conversation is\n * skipped. Rejects with no call in progress, while nobody has answered\n * yet (the call's own ring is still out), or when the server refuses.\n */\nexport async function ringIntoCall(people: RingIntoCallOptions): Promise<string[]> {\n if (!native?.callControl) throw new Error('This build cannot ring people into a call.');\n if (!apiOrigin) throw new Error('Call configure() before ringIntoCall().');\n const control = await native.callControl();\n if (!control) throw new Error('There is no call in progress.');\n const res = await fetch(`${apiOrigin}/v1/calls/${encodeURIComponent(control.callId)}/ring`, {\n method: 'POST',\n headers: {\n authorization: `Bearer ${control.controlToken}`,\n 'content-type': 'application/json',\n },\n body: JSON.stringify({\n user_ids: people.userIds ?? [],\n external_ids: people.externalIds ?? [],\n }),\n });\n const body = (await res.json().catch(() => null)) as {\n rung_user_ids?: string[];\n error?: { message?: string };\n } | null;\n if (!res.ok) throw new Error(body?.error?.message ?? `Couldn't ring them (${res.status}).`);\n return body?.rung_user_ids ?? [];\n}\n\nexport const answer = (): void => native?.answer();\nexport const decline = (): void => native?.decline();\nexport const hangUp = (): void => native?.hangUp();\n\n/**\n * Call waiting: end the current call and answer `snapshot.waiting`.\n * Pass its `callId`: a tap on a card for a call that is no longer the\n * one waiting is then ignored instead of answering a different call.\n */\nexport const answerWaiting = (callId?: string): void => native?.answerWaiting?.(callId ?? null);\n\n/** Call waiting: turn `snapshot.waiting` away — its caller hears busy. */\nexport const declineWaiting = (callId?: string): void => native?.declineWaiting?.(callId ?? null);\nexport const setMuted = (muted: boolean): void => native?.setMuted(muted);\nexport const setCamera = (on: boolean): void => native?.setCamera(on);\nexport const switchCamera = (): void => native?.switchCamera();\n/** Route call audio to the loudspeaker (`true`) or back to earpiece / headset (`false`). */\nexport const setSpeaker = (on: boolean): void => native?.setSpeaker(on);\n\n/**\n * Play call audio through one of `snapshot.audioOutputs`. The choice\n * holds for the rest of the call, until that device disconnects or a new\n * headset / Bluetooth device connects (which takes over, as in the\n * phone's own dialer). Without a choice a connected headset wins, then\n * the earpiece for voice calls or the speaker for video.\n */\nexport function setAudioOutput(id: string): void {\n if (native?.setAudioOutput) native.setAudioOutput(id);\n else native?.setSpeaker(id === 'speaker'); // an older native build\n}\n\n/**\n * Socket forwarding for an open app: a `call:ring_ended` seen on the\n * socket. Idempotent with the push path — the core dedupes.\n */\nexport const onRingEnded = (callId: string, reason: string): void =>\n native?.onRingEnded(callId, reason);\n\n/**\n * Socket forwarding: `call:finished`. Pass the payload's `reason`\n * (`finished` | `declined_all` | `no_answer` | `cancelled`) so an\n * unanswered caller sees \"Declined\"/\"No answer\", not \"Call ended\".\n * Idempotent with the `finished` push.\n */\nexport const onCallFinished = (callId: string, reason?: string): void =>\n native?.onCallFinished(callId, reason ?? null);\n\n/**\n * Android 14+: whether the app may show the full-screen ring over the\n * lock screen. `true` on older Android and where the module is absent.\n */\nexport const canUseFullScreenIntent = (): boolean => native?.canUseFullScreenIntent() ?? true;\n\n/** Open the system screen where the user grants full-screen intents (falls back to notification settings). */\nexport const openFullScreenIntentSettings = (): void => native?.openFullScreenIntentSettings();\n\n/**\n * Android: let the app show over the lock screen while a call rings or\n * runs — answering must never demand an unlock. Turn it off when the\n * call ends. The activity re-applies it when the core relaunches it for\n * a call (`poolse_launch_call`), given the host's MainActivity hook.\n * No-op on iOS, where CallKit owns the lock screen.\n */\nexport function setShowOnLockscreen(enabled: boolean): void {\n try {\n native?.setShowOnLockscreen?.(enabled);\n } catch {\n // Never let a window flag take a call down.\n }\n}\n\n// ── missed-call notifications (Android) ─────────────────────────────────\n\n/**\n * Android: the missed-call notification action the app was LAUNCHED\n * with, once — read it on mount. `null` when the app opened any other\n * way. The native core posts that notification itself from the push,\n * so it works with the app closed.\n *\n * iOS shows missed calls as an ordinary alert push (to the token you\n * register with `kind: 'alert'`); read its taps with your notification\n * library — its `type` is `call_missed`, the category\n * `poolse_missed_call`, the Call back action `call_back`.\n */\nexport function takeCallAction(): CallAction | null {\n return native?.takeCallAction?.() ?? null;\n}\n\n/** Android: a missed-call notification tapped while the app is running. */\nexport function onCallAction(cb: (action: CallAction) => void): Unsubscribe {\n if (!native || !native.takeCallAction) return () => undefined;\n const sub = native.addListener('onCallAction', cb);\n return () => sub.remove();\n}\n\n// ── chat notifications ─────────────────────────────────────────────────\n\nlet activeConversation: string | null = null;\n\n/**\n * Tell the core which conversation is on screen (`null` when none, and\n * when the app goes to the background). Its messages are not notified —\n * the user is reading them — and opening it clears the notifications\n * already shown for it.\n */\nexport function setActiveConversation(conversationId: string | null): void {\n activeConversation = conversationId;\n native?.setActiveConversation?.(conversationId);\n}\n\n/**\n * For the app's notification handler (expo-notifications'\n * `setNotificationHandler`): `false` for a chat notification of the\n * conversation on screen, which must not pop over the chat itself.\n * Android never asks — the core skips those natively.\n */\nexport function shouldPresentMessage(data: Record<string, unknown> | undefined | null): boolean {\n if (!data || data['type'] !== 'message') return true;\n return data['conversation_id'] !== activeConversation;\n}\n\n/**\n * The conversation a tapped notification belongs to — a chat message\n * (`type: 'message'`) or a missed call (`call_missed`) — from its data.\n * iOS hands the tap to your notification library; Android delivers it\n * through `takeCallAction` / `onCallAction` (type `open`).\n */\nexport function conversationOfNotification(\n data: Record<string, unknown> | undefined | null,\n): string | null {\n if (!data) return null;\n const type = data['type'];\n if (type !== 'message' && type !== 'call_missed') return null;\n return typeof data['conversation_id'] === 'string' ? data['conversation_id'] : null;\n}\n\n// ── VoIP push (iOS) ───────────────────────────────────────────────────\n\n/**\n * iOS: the current PushKit VoIP token, registered natively at launch.\n * `null` until iOS issues one, and always on Android (FCM carries rings).\n */\nexport function getVoipToken(): VoipToken | null {\n return native?.getVoipToken?.() ?? null;\n}\n\n/** iOS: fires whenever PushKit issues (or rotates) the VoIP token. No-op on Android. */\nexport function onVoipToken(cb: (token: VoipToken) => void): Unsubscribe {\n if (!native || !native.getVoipToken) return () => undefined;\n const sub = native.addListener('onVoipToken', cb);\n return () => sub.remove();\n}\n\n// ── picture-in-picture ────────────────────────────────────────────────\n\n/**\n * Arm picture-in-picture: while on, leaving the app keeps the call's\n * video in a floating window. Turn it on only while a video call shows\n * someone's picture, and off otherwise.\n *\n * iOS (15+) floats the `<CallVideoView pictureInPicture>` that is on\n * screen — mark the main remote picture. Android (8+) floats the whole\n * app: draw a compact layout while `isInPictureInPicture()` (see\n * `onPictureInPicture`). The app needs `android:supportsPictureInPicture`\n * on its activity.\n */\nexport function setPictureInPictureEnabled(on: boolean): void {\n native?.setPictureInPictureEnabled?.(on);\n}\n\n/** Whether the floating window is open right now. */\nexport function isInPictureInPicture(): boolean {\n return native?.isInPictureInPicture?.() ?? false;\n}\n\n/** Whether this device can float a call at all. */\nexport function pictureInPictureSupported(): boolean {\n return native?.pictureInPictureSupported?.() ?? false;\n}\n\n/** Fires when the floating window opens (`true`) and closes (`false`). */\nexport function onPictureInPicture(cb: (active: boolean) => void): Unsubscribe {\n if (!native?.setPictureInPictureEnabled) return () => undefined;\n const sub = native.addListener('onPictureInPicture', (payload) => cb(payload.active));\n return () => sub.remove();\n}\n\n// ── video ─────────────────────────────────────────────────────────────\n\nexport interface CallVideoViewProps extends ViewProps {\n /** Remote participant's userId (LiveKit identity). Omit with local=true for self view. */\n participantId?: string;\n local?: boolean;\n /** default: true for local front camera, false otherwise */\n mirror?: boolean;\n /** default 'cover' */\n fit?: 'cover' | 'contain';\n /**\n * iOS: this remote picture is the one picture-in-picture floats when\n * the app is left (`setPictureInPictureEnabled`). Mark one at a time.\n */\n pictureInPicture?: boolean;\n}\n\ntype NativeVideoProps = CallVideoViewProps;\n\nlet nativeVideo: ComponentType<NativeVideoProps> | null | undefined;\n\n/** Resolved lazily (first render) and only when the native module exists. */\nfunction nativeVideoView(): ComponentType<NativeVideoProps> | null {\n if (nativeVideo !== undefined) return nativeVideo;\n nativeVideo = null;\n if (native) {\n try {\n nativeVideo = requireNativeViewManager<NativeVideoProps>('PoolseCalls', 'PoolseCallVideo');\n } catch {\n nativeVideo = null; // an older native build without the view\n }\n }\n return nativeVideo;\n}\n\n/**\n * A participant's camera (or, with `local`, your own), rendered natively\n * by the call core. Shows nothing (stays transparent) while that camera\n * is off — draw the avatar from the snapshot's `cameraOn` underneath.\n * Without the native module it renders an empty View.\n */\nexport function CallVideoView(props: CallVideoViewProps): ReactElement | null {\n const Native = nativeVideoView();\n if (!Native) {\n const { participantId: _p, local: _l, mirror: _m, fit: _f, pictureInPicture: _pip, ...rest } = props;\n return createElement(View, rest);\n }\n return createElement(Native, props);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["requireOptionalNativeModule","requireNativeViewManager","createElement","View"],"mappings":";;;;;;;AA+MA,IAAM,MAAA,GAASA,4CAA+C,aAAa,CAAA;AAGpE,IAAM,uBAAuB,MAAA,IAAU;AAG9C,IAAI,SAAA,GAA2B,IAAA;AAG/B,eAAsB,S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,OAAO,WAAA,CAAY,oBAAA,EAAsB,CAAC,OAAA,KAAY,EAAA,CAAG,OAAA,CAAQ,MAAM,CAAC,CAAA;AACpF,EAAA,OAAO,MAAM,IAAI,MAAA,EAAO;AAC1B;AA2BA,IAAI,WAAA;AAGJ,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,GAAcC,wCAAA,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,OAAOC,mBAAA,CAAcC,kBAAM,IAAI,CAAA;AAAA,EACjC;AACA,EAAA,OAAOD,mBAAA,CAAc,QAAQ,KAAK,CAAA;AACpC","file":"index.cjs","sourcesContent":["// @poolse/native — the React Native face of the native\n// call core (CALL_CONTRACT.md §8). A thin, typed surface over the native\n// module: commands in, one snapshot event out. All call logic lives in\n// the native cores; nothing here decides anything about a call.\n//\n// On a platform or build without the native module (Expo Go, web,\n// unlinked), every command is a safe no-op and the state stays idle —\n// so a host can render against this unconditionally.\nimport { createElement, type ComponentType, type ReactElement } from 'react';\nimport { View, type ViewProps } from 'react-native';\nimport { requireNativeViewManager, requireOptionalNativeModule } from 'expo-modules-core';\n\n/**\n * A call's complete state. `null` means idle — no call. After a call\n * ends the snapshot stays `phase: 'ended'` (with `reason`) for ~2.5 s,\n * then becomes `null`.\n */\nexport interface Snapshot {\n cv: 1;\n callId: string;\n conversationId: string;\n conversationName: string | null;\n direction: 'incoming' | 'outgoing' | 'joined';\n /**\n * `room` — rings nobody, joined and left at will (`startRoom`); `call`\n * otherwise. Known once the server answered: a room being joined reads\n * `call` while `connecting`. Absent before 0.9.0: treat as `call`.\n */\n kind?: 'call' | 'room';\n media: 'audio' | 'video';\n phase: 'ringing_in' | 'ringing_out' | 'connecting' | 'active' | 'reconnecting' | 'ended';\n reason?:\n | 'left'\n | 'finished'\n | 'declined_all'\n | 'busy_all'\n | 'no_answer'\n | 'cancelled'\n | 'connection_lost'\n | 'failed';\n /** REMOTE participants only; `userId` is the LiveKit identity. */\n participants: Array<{\n userId: string;\n externalId: string;\n speaking: boolean;\n muted: boolean;\n /** True only with a published, subscribed, unmuted camera track (show video, not avatar). */\n cameraOn: boolean;\n /**\n * 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 (Android). 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 * iOS: the APNs environment of this build's `aps-environment`\n * entitlement. Echoed back with the VoIP token so the server pushes to\n * the right gateway. Ignored on Android.\n */\n apnsEnvironment?: 'production' | 'sandbox';\n}\n\n/** The iOS PushKit (VoIP) token and the APNs environment it belongs to. */\nexport interface VoipToken {\n /** Hex-encoded PushKit token. */\n token: string;\n environment: 'production' | 'sandbox' | string;\n}\n\nexport interface PlaceOptions {\n media: 'audio' | 'video';\n /** The user's session token — authorizes placing/joining (CALL_CONTRACT.md §3.2). */\n sessionToken: string;\n}\n\n/**\n * What the user tapped on a missed-call notification: the notification\n * itself (`open` the conversation) or its Call back button (`call_back`\n * — place a call on the conversation with `media`).\n */\nexport interface CallAction {\n type: 'open' | 'call_back';\n conversationId: string;\n callId: string | null;\n media: 'audio' | 'video';\n}\n\ntype NativeSnapshot = { snapshot: Snapshot | null };\n\ninterface PoolseCallsNative {\n configure(apiBaseUrl: string, options: ConfigureOptions | null): Promise<void>;\n getCallState(): NativeSnapshot;\n place(conversationId: string, media: string, sessionToken: string): Promise<void>;\n join(callId: string, conversationId: string | null, sessionToken: string): Promise<void>;\n answer(): void;\n decline(): void;\n hangUp(): void;\n answerWaiting?(callId: string | null): void;\n declineWaiting?(callId: string | null): void;\n setMuted(muted: boolean): void;\n setCamera(on: boolean): void;\n switchCamera(): void;\n 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 addListener(event: 'onCallState', cb: (payload: NativeSnapshot) => void): { remove(): void };\n addListener(event: 'onVoipToken', cb: (payload: VoipToken) => void): { remove(): void };\n addListener(event: 'onCallAction', cb: (payload: CallAction) => void): { remove(): void };\n addListener(\n event: 'onPictureInPicture',\n cb: (payload: { active: boolean }) => void,\n ): { remove(): void };\n}\n\nconst native = requireOptionalNativeModule<PoolseCallsNative>('PoolseCalls');\n\n/** True when the native call core is present in this build. */\nexport const nativeCallsAvailable = native != null;\n\n// Kept for startRoom, the one command that talks to the server from JS.\nlet apiOrigin: string | null = null;\n\n/** Configure once, before any call can arrive. No secrets — just the API origin. */\nexport async function configure(apiBaseUrl: string, options?: ConfigureOptions): Promise<void> {\n apiOrigin = apiBaseUrl.replace(/\\/+$/, '');\n await native?.configure(apiBaseUrl, options ?? null);\n}\n\n/** The current snapshot — safe to read at any moment, including cold answer and before configure. */\nexport function getCallState(): Snapshot | null {\n return native?.getCallState().snapshot ?? null;\n}\n\nexport type Unsubscribe = () => void;\n\n/** Subscribe to call state. Fires a full snapshot on every change. */\nexport function onCallState(cb: (snapshot: Snapshot | null) => void): Unsubscribe {\n if (!native) return () => undefined;\n const sub = native.addListener('onCallState', (payload) => cb(payload.snapshot));\n return () => sub.remove();\n}\n\nexport function place(conversationId: string, options: PlaceOptions): Promise<void> {\n return native?.place(conversationId, options.media, options.sessionToken) ?? Promise.resolve();\n}\n\nexport function join(\n callId: string,\n conversationId: string | null,\n sessionToken: string,\n): Promise<void> {\n return native?.join(callId, conversationId, sessionToken) ?? Promise.resolve();\n}\n\nexport interface StartRoomResult {\n /** The room's call id — what the Join banner and `call:*` events carry. */\n callId: string;\n /** False when something was live already (a room, or a ringing call) and this joined it. */\n created: boolean;\n}\n\n/**\n * Start the conversation's room — a call that rings nobody (CALL_CONTRACT.md\n * §5.6) — or join whatever is live there, then carry it on the native\n * core like any joined call: CallKit / the call service, so it keeps\n * going with the phone locked, and the same audio routing as a call.\n *\n * Others in the conversation see it through the Join banner and join it\n * with `join`. Leaving (`hangUp`) never ends it for them; it ends once\n * it has been empty for a short grace. `media: 'video'` makes it a video\n * room. Rejects when the server refuses (not a member, no SFU) or\n * before `configure`.\n */\nexport async function startRoom(\n conversationId: string,\n options: PlaceOptions,\n): Promise<StartRoomResult> {\n if (!native) throw new Error('The native call core is not in this build.');\n if (!apiOrigin) throw new Error('Call configure() before startRoom().');\n const res = await fetch(\n `${apiOrigin}/v1/conversations/${encodeURIComponent(conversationId)}/room`,\n {\n method: 'POST',\n headers: {\n authorization: `Bearer ${options.sessionToken}`,\n 'content-type': 'application/json',\n },\n body: JSON.stringify({ media: options.media }),\n },\n );\n const body = (await res.json().catch(() => null)) as {\n created?: boolean;\n call?: { id?: string };\n error?: { message?: string };\n } | null;\n const callId = body?.call?.id;\n if (!res.ok || !callId) {\n throw new Error(body?.error?.message ?? `Couldn't start the room (${res.status}).`);\n }\n // The core joins with its own request: it owns the session from here,\n // exactly as when the room is joined from the banner.\n await native.join(callId, conversationId, options.sessionToken);\n return { callId, created: body?.created === true };\n}\n\n/** Who to ring into the call — poolse user ids, your app's own (external) ids, or both. */\nexport interface RingIntoCallOptions {\n userIds?: string[];\n externalIds?: string[];\n}\n\n/**\n * Ring more of the conversation's members into the call you are on\n * (\"Add people\"). Each is rung as on a fresh call — their phone rings,\n * CallKit / full-screen — and answering puts them in this call.\n *\n * Resolves with the poolse user ids actually rung: anyone already in\n * the call, still ringing, or not a member of the conversation is\n * skipped. Rejects with no call in progress, while nobody has answered\n * yet (the call's own ring is still out), or when the server refuses.\n */\nexport async function ringIntoCall(people: RingIntoCallOptions): Promise<string[]> {\n if (!native?.callControl) throw new Error('This build cannot ring people into a call.');\n if (!apiOrigin) throw new Error('Call configure() before ringIntoCall().');\n const control = await native.callControl();\n if (!control) throw new Error('There is no call in progress.');\n const res = await fetch(`${apiOrigin}/v1/calls/${encodeURIComponent(control.callId)}/ring`, {\n method: 'POST',\n headers: {\n authorization: `Bearer ${control.controlToken}`,\n 'content-type': 'application/json',\n },\n body: JSON.stringify({\n user_ids: people.userIds ?? [],\n external_ids: people.externalIds ?? [],\n }),\n });\n const body = (await res.json().catch(() => null)) as {\n rung_user_ids?: string[];\n error?: { message?: string };\n } | null;\n if (!res.ok) throw new Error(body?.error?.message ?? `Couldn't ring them (${res.status}).`);\n return body?.rung_user_ids ?? [];\n}\n\nexport const answer = (): void => native?.answer();\nexport const decline = (): void => native?.decline();\nexport const hangUp = (): void => native?.hangUp();\n\n/**\n * Call waiting: end the current call and answer `snapshot.waiting`.\n * Pass its `callId`: a tap on a card for a call that is no longer the\n * one waiting is then ignored instead of answering a different call.\n */\nexport const answerWaiting = (callId?: string): void => native?.answerWaiting?.(callId ?? null);\n\n/** Call waiting: turn `snapshot.waiting` away — its caller hears busy. */\nexport const declineWaiting = (callId?: string): void => native?.declineWaiting?.(callId ?? null);\nexport const setMuted = (muted: boolean): void => native?.setMuted(muted);\nexport const setCamera = (on: boolean): void => native?.setCamera(on);\nexport const switchCamera = (): void => native?.switchCamera();\n\n/**\n * Whether this build can share the screen in a call: Android with the\n * LiveKit media engine. iOS shares through a broadcast extension, which\n * comes in a later release; it can already show 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); resolves `false` when they say no or\n * the build cannot share. `snapshot.screenSharing` turns true once the\n * screen is actually going out. Stopping from the system notification\n * ends it the 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// ── 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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -29,6 +29,11 @@ interface Snapshot {
|
|
|
29
29
|
muted: boolean;
|
|
30
30
|
/** True only with a published, subscribed, unmuted camera track (show video, not avatar). */
|
|
31
31
|
cameraOn: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Sharing their screen: draw it with `<CallVideoView source="screen">`,
|
|
34
|
+
* large and with `fit="contain"`. Absent before 3.2.
|
|
35
|
+
*/
|
|
36
|
+
screenSharing?: boolean;
|
|
32
37
|
/**
|
|
33
38
|
* Their link to the call: `lost` while they have dropped and are
|
|
34
39
|
* coming back (show "Reconnecting…"), `poor` for a weak signal.
|
|
@@ -73,6 +78,8 @@ interface Snapshot {
|
|
|
73
78
|
* `cameraOn: false` meanwhile. Absent before 0.11.0.
|
|
74
79
|
*/
|
|
75
80
|
videoPaused?: boolean;
|
|
81
|
+
/** You are sharing your screen (Android). Absent before 3.2. */
|
|
82
|
+
screenSharing?: boolean;
|
|
76
83
|
}
|
|
77
84
|
/** `good` covers good and excellent; `unknown` until the SFU has measured. */
|
|
78
85
|
type ConnectionQuality = 'good' | 'poor' | 'lost' | 'unknown';
|
|
@@ -191,6 +198,21 @@ declare const declineWaiting: (callId?: string) => void;
|
|
|
191
198
|
declare const setMuted: (muted: boolean) => void;
|
|
192
199
|
declare const setCamera: (on: boolean) => void;
|
|
193
200
|
declare const switchCamera: () => void;
|
|
201
|
+
/**
|
|
202
|
+
* Whether this build can share the screen in a call: Android with the
|
|
203
|
+
* LiveKit media engine. iOS shares through a broadcast extension, which
|
|
204
|
+
* comes in a later release; it can already show other people's screens.
|
|
205
|
+
*/
|
|
206
|
+
declare const screenShareSupported: () => boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Share the screen. Android asks the user first (the system's "Start
|
|
209
|
+
* recording or casting?" prompt); resolves `false` when they say no or
|
|
210
|
+
* the build cannot share. `snapshot.screenSharing` turns true once the
|
|
211
|
+
* screen is actually going out. Stopping from the system notification
|
|
212
|
+
* ends it the same way.
|
|
213
|
+
*/
|
|
214
|
+
declare const startScreenShare: () => Promise<boolean>;
|
|
215
|
+
declare const stopScreenShare: () => void;
|
|
194
216
|
/** Route call audio to the loudspeaker (`true`) or back to earpiece / headset (`false`). */
|
|
195
217
|
declare const setSpeaker: (on: boolean) => void;
|
|
196
218
|
/**
|
|
@@ -296,6 +318,12 @@ interface CallVideoViewProps extends ViewProps {
|
|
|
296
318
|
mirror?: boolean;
|
|
297
319
|
/** default 'cover' */
|
|
298
320
|
fit?: 'cover' | 'contain';
|
|
321
|
+
/**
|
|
322
|
+
* `camera` (default), or `screen`: the participant's shared screen
|
|
323
|
+
* (with `local`, your own). A screen is never mirrored; draw it with
|
|
324
|
+
* `fit="contain"` so nothing is cropped.
|
|
325
|
+
*/
|
|
326
|
+
source?: 'camera' | 'screen';
|
|
299
327
|
/**
|
|
300
328
|
* iOS: this remote picture is the one picture-in-picture floats when
|
|
301
329
|
* the app is left (`setPictureInPictureEnabled`). Mark one at a time.
|
|
@@ -310,4 +338,4 @@ interface CallVideoViewProps extends ViewProps {
|
|
|
310
338
|
*/
|
|
311
339
|
declare function CallVideoView(props: CallVideoViewProps): ReactElement | null;
|
|
312
340
|
|
|
313
|
-
export { type AudioOutput, type AudioOutputKind, type CallAction, CallVideoView, type CallVideoViewProps, type ConfigureOptions, type ConnectionQuality, type PlaceOptions, type RingIntoCallOptions, type Snapshot, type StartRoomResult, type Unsubscribe, type VoipToken, type WaitingCall, answer, answerWaiting, canUseFullScreenIntent, configure, conversationOfNotification, decline, declineWaiting, getCallState, getVoipToken, hangUp, isInPictureInPicture, join, nativeCallsAvailable, onCallAction, onCallFinished, onCallState, onPictureInPicture, onRingEnded, onVoipToken, openFullScreenIntentSettings, pictureInPictureSupported, place, ringIntoCall, setActiveConversation, setAudioOutput, setCamera, setMuted, setPictureInPictureEnabled, setShowOnLockscreen, setSpeaker, shouldPresentMessage, startRoom, switchCamera, takeCallAction };
|
|
341
|
+
export { type AudioOutput, type AudioOutputKind, type CallAction, CallVideoView, type CallVideoViewProps, type ConfigureOptions, type ConnectionQuality, type PlaceOptions, type RingIntoCallOptions, type Snapshot, type StartRoomResult, type Unsubscribe, type VoipToken, type WaitingCall, answer, answerWaiting, canUseFullScreenIntent, configure, conversationOfNotification, decline, declineWaiting, getCallState, getVoipToken, hangUp, isInPictureInPicture, join, nativeCallsAvailable, onCallAction, onCallFinished, onCallState, onPictureInPicture, onRingEnded, onVoipToken, openFullScreenIntentSettings, pictureInPictureSupported, place, ringIntoCall, screenShareSupported, setActiveConversation, setAudioOutput, setCamera, setMuted, setPictureInPictureEnabled, setShowOnLockscreen, setSpeaker, shouldPresentMessage, startRoom, startScreenShare, stopScreenShare, switchCamera, takeCallAction };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,11 @@ interface Snapshot {
|
|
|
29
29
|
muted: boolean;
|
|
30
30
|
/** True only with a published, subscribed, unmuted camera track (show video, not avatar). */
|
|
31
31
|
cameraOn: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Sharing their screen: draw it with `<CallVideoView source="screen">`,
|
|
34
|
+
* large and with `fit="contain"`. Absent before 3.2.
|
|
35
|
+
*/
|
|
36
|
+
screenSharing?: boolean;
|
|
32
37
|
/**
|
|
33
38
|
* Their link to the call: `lost` while they have dropped and are
|
|
34
39
|
* coming back (show "Reconnecting…"), `poor` for a weak signal.
|
|
@@ -73,6 +78,8 @@ interface Snapshot {
|
|
|
73
78
|
* `cameraOn: false` meanwhile. Absent before 0.11.0.
|
|
74
79
|
*/
|
|
75
80
|
videoPaused?: boolean;
|
|
81
|
+
/** You are sharing your screen (Android). Absent before 3.2. */
|
|
82
|
+
screenSharing?: boolean;
|
|
76
83
|
}
|
|
77
84
|
/** `good` covers good and excellent; `unknown` until the SFU has measured. */
|
|
78
85
|
type ConnectionQuality = 'good' | 'poor' | 'lost' | 'unknown';
|
|
@@ -191,6 +198,21 @@ declare const declineWaiting: (callId?: string) => void;
|
|
|
191
198
|
declare const setMuted: (muted: boolean) => void;
|
|
192
199
|
declare const setCamera: (on: boolean) => void;
|
|
193
200
|
declare const switchCamera: () => void;
|
|
201
|
+
/**
|
|
202
|
+
* Whether this build can share the screen in a call: Android with the
|
|
203
|
+
* LiveKit media engine. iOS shares through a broadcast extension, which
|
|
204
|
+
* comes in a later release; it can already show other people's screens.
|
|
205
|
+
*/
|
|
206
|
+
declare const screenShareSupported: () => boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Share the screen. Android asks the user first (the system's "Start
|
|
209
|
+
* recording or casting?" prompt); resolves `false` when they say no or
|
|
210
|
+
* the build cannot share. `snapshot.screenSharing` turns true once the
|
|
211
|
+
* screen is actually going out. Stopping from the system notification
|
|
212
|
+
* ends it the same way.
|
|
213
|
+
*/
|
|
214
|
+
declare const startScreenShare: () => Promise<boolean>;
|
|
215
|
+
declare const stopScreenShare: () => void;
|
|
194
216
|
/** Route call audio to the loudspeaker (`true`) or back to earpiece / headset (`false`). */
|
|
195
217
|
declare const setSpeaker: (on: boolean) => void;
|
|
196
218
|
/**
|
|
@@ -296,6 +318,12 @@ interface CallVideoViewProps extends ViewProps {
|
|
|
296
318
|
mirror?: boolean;
|
|
297
319
|
/** default 'cover' */
|
|
298
320
|
fit?: 'cover' | 'contain';
|
|
321
|
+
/**
|
|
322
|
+
* `camera` (default), or `screen`: the participant's shared screen
|
|
323
|
+
* (with `local`, your own). A screen is never mirrored; draw it with
|
|
324
|
+
* `fit="contain"` so nothing is cropped.
|
|
325
|
+
*/
|
|
326
|
+
source?: 'camera' | 'screen';
|
|
299
327
|
/**
|
|
300
328
|
* iOS: this remote picture is the one picture-in-picture floats when
|
|
301
329
|
* the app is left (`setPictureInPictureEnabled`). Mark one at a time.
|
|
@@ -310,4 +338,4 @@ interface CallVideoViewProps extends ViewProps {
|
|
|
310
338
|
*/
|
|
311
339
|
declare function CallVideoView(props: CallVideoViewProps): ReactElement | null;
|
|
312
340
|
|
|
313
|
-
export { type AudioOutput, type AudioOutputKind, type CallAction, CallVideoView, type CallVideoViewProps, type ConfigureOptions, type ConnectionQuality, type PlaceOptions, type RingIntoCallOptions, type Snapshot, type StartRoomResult, type Unsubscribe, type VoipToken, type WaitingCall, answer, answerWaiting, canUseFullScreenIntent, configure, conversationOfNotification, decline, declineWaiting, getCallState, getVoipToken, hangUp, isInPictureInPicture, join, nativeCallsAvailable, onCallAction, onCallFinished, onCallState, onPictureInPicture, onRingEnded, onVoipToken, openFullScreenIntentSettings, pictureInPictureSupported, place, ringIntoCall, setActiveConversation, setAudioOutput, setCamera, setMuted, setPictureInPictureEnabled, setShowOnLockscreen, setSpeaker, shouldPresentMessage, startRoom, switchCamera, takeCallAction };
|
|
341
|
+
export { type AudioOutput, type AudioOutputKind, type CallAction, CallVideoView, type CallVideoViewProps, type ConfigureOptions, type ConnectionQuality, type PlaceOptions, type RingIntoCallOptions, type Snapshot, type StartRoomResult, type Unsubscribe, type VoipToken, type WaitingCall, answer, answerWaiting, canUseFullScreenIntent, configure, conversationOfNotification, decline, declineWaiting, getCallState, getVoipToken, hangUp, isInPictureInPicture, join, nativeCallsAvailable, onCallAction, onCallFinished, onCallState, onPictureInPicture, onRingEnded, onVoipToken, openFullScreenIntentSettings, pictureInPictureSupported, place, ringIntoCall, screenShareSupported, setActiveConversation, setAudioOutput, setCamera, setMuted, setPictureInPictureEnabled, setShowOnLockscreen, setSpeaker, shouldPresentMessage, startRoom, startScreenShare, stopScreenShare, switchCamera, takeCallAction };
|
package/dist/index.js
CHANGED
|
@@ -74,6 +74,9 @@ var declineWaiting = (callId) => native?.declineWaiting?.(callId ?? null);
|
|
|
74
74
|
var setMuted = (muted) => native?.setMuted(muted);
|
|
75
75
|
var setCamera = (on) => native?.setCamera(on);
|
|
76
76
|
var switchCamera = () => native?.switchCamera();
|
|
77
|
+
var screenShareSupported = () => native?.screenShareSupported?.() ?? false;
|
|
78
|
+
var startScreenShare = async () => await native?.startScreenShare?.() ?? false;
|
|
79
|
+
var stopScreenShare = () => native?.stopScreenShare?.();
|
|
77
80
|
var setSpeaker = (on) => native?.setSpeaker(on);
|
|
78
81
|
function setAudioOutput(id) {
|
|
79
82
|
if (native?.setAudioOutput) native.setAudioOutput(id);
|
|
@@ -150,12 +153,20 @@ function nativeVideoView() {
|
|
|
150
153
|
function CallVideoView(props) {
|
|
151
154
|
const Native = nativeVideoView();
|
|
152
155
|
if (!Native) {
|
|
153
|
-
const {
|
|
156
|
+
const {
|
|
157
|
+
participantId: _p,
|
|
158
|
+
local: _l,
|
|
159
|
+
mirror: _m,
|
|
160
|
+
fit: _f,
|
|
161
|
+
source: _s,
|
|
162
|
+
pictureInPicture: _pip,
|
|
163
|
+
...rest
|
|
164
|
+
} = props;
|
|
154
165
|
return createElement(View, rest);
|
|
155
166
|
}
|
|
156
167
|
return createElement(Native, props);
|
|
157
168
|
}
|
|
158
169
|
|
|
159
|
-
export { CallVideoView, answer, answerWaiting, canUseFullScreenIntent, configure, conversationOfNotification, decline, declineWaiting, getCallState, getVoipToken, hangUp, isInPictureInPicture, join, nativeCallsAvailable, onCallAction, onCallFinished, onCallState, onPictureInPicture, onRingEnded, onVoipToken, openFullScreenIntentSettings, pictureInPictureSupported, place, ringIntoCall, setActiveConversation, setAudioOutput, setCamera, setMuted, setPictureInPictureEnabled, setShowOnLockscreen, setSpeaker, shouldPresentMessage, startRoom, switchCamera, takeCallAction };
|
|
170
|
+
export { CallVideoView, answer, answerWaiting, canUseFullScreenIntent, configure, conversationOfNotification, decline, declineWaiting, getCallState, getVoipToken, hangUp, isInPictureInPicture, join, nativeCallsAvailable, onCallAction, onCallFinished, onCallState, onPictureInPicture, onRingEnded, onVoipToken, openFullScreenIntentSettings, pictureInPictureSupported, place, ringIntoCall, screenShareSupported, setActiveConversation, setAudioOutput, setCamera, setMuted, setPictureInPictureEnabled, setShowOnLockscreen, setSpeaker, shouldPresentMessage, startRoom, startScreenShare, stopScreenShare, switchCamera, takeCallAction };
|
|
160
171
|
//# sourceMappingURL=index.js.map
|
|
161
172
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAqMA,IAAM,MAAA,GAAS,4BAA+C,aAAa,CAAA;AAGpE,IAAM,uBAAuB,MAAA,IAAU;AAG9C,IAAI,SAAA,GAA2B,IAAA;AAG/B,eAAsB,SAAA,CAAU,YAAoB,OAAA,EAA2C;AAC7F,EAAA,SAAA,GAAY,UAAA,CAAW,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA;AACzC,EAAA,MAAM,MAAA,EAAQ,SAAA,CAAU,UAAA,EAAY,OAAA,IAAW,IAAI,CAAA;AACrD;AAGO,SAAS,YAAA,GAAgC;AAC9C,EAAA,OAAO,MAAA,EAAQ,YAAA,EAAa,CAAE,QAAA,IAAY,IAAA;AAC5C;AAKO,SAAS,YAAY,EAAA,EAAsD;AAChF,EAAA,IAAI,CAAC,MAAA,EAAQ,OAAO,MAAM,MAAA;AAC1B,EAAA,MAAM,GAAA,GAAM,OAAO,WAAA,CAAY,aAAA,EAAe,CAAC,OAAA,KAAY,EAAA,CAAG,OAAA,CAAQ,QAAQ,CAAC,CAAA;AAC/E,EAAA,OAAO,MAAM,IAAI,MAAA,EAAO;AAC1B;AAEO,SAAS,KAAA,CAAM,gBAAwB,OAAA,EAAsC;AAClF,EAAA,OAAO,MAAA,EAAQ,MAAM,cAAA,EAAgB,OAAA,CAAQ,OAAO,OAAA,CAAQ,YAAY,CAAA,IAAK,OAAA,CAAQ,OAAA,EAAQ;AAC/F;AAEO,SAAS,IAAA,CACd,MAAA,EACA,cAAA,EACA,YAAA,EACe;AAC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EAAQ,wBAAuB,IAAK,KAAA;AAC7C;AAGO,SAAS,yBAAA,GAAqC;AACnD,EAAA,OAAO,MAAA,EAAQ,6BAA4B,IAAK,KAAA;AAClD;AAGO,SAAS,mBAAmB,EAAA,EAA4C;AAC7E,EAAA,IAAI,CAAC,MAAA,EAAQ,0BAAA,EAA4B,OAAO,MAAM,MAAA;AACtD,EAAA,MAAM,GAAA,GAAM,OAAO,WAAA,CAAY,oBAAA,EAAsB,CAAC,OAAA,KAAY,EAAA,CAAG,OAAA,CAAQ,MAAM,CAAC,CAAA;AACpF,EAAA,OAAO,MAAM,IAAI,MAAA,EAAO;AAC1B;AAqBA,IAAI,WAAA;AAGJ,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,EAAE,aAAA,EAAe,EAAA,EAAI,KAAA,EAAO,EAAA,EAAI,MAAA,EAAQ,EAAA,EAAI,GAAA,EAAK,EAAA,EAAI,gBAAA,EAAkB,IAAA,EAAM,GAAG,MAAK,GAAI,KAAA;AAC/F,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 * Their link to the call: `lost` while they have dropped and are\n * coming back (show \"Reconnecting…\"), `poor` for a weak signal.\n * Absent before 0.11.0.\n */\n connectionQuality?: ConnectionQuality;\n }>;\n /** The kind of output playing now — the short answer to \"where is the audio\". */\n audioRoute: AudioOutputKind;\n /**\n * Every output the call can play through right now: always the phone\n * (earpiece, or wired headphones in its place) and the speaker, plus\n * each connected Bluetooth / USB device by its own name. Empty until\n * the call's audio is up. Pass an `id` to `setAudioOutput`.\n */\n audioOutputs: AudioOutput[];\n /** The `audioOutputs` entry playing now; null before audio is up. */\n audioOutputId: string | null;\n mutedSelf: boolean;\n /** True only while the local camera track is actually published and enabled. */\n cameraOn: boolean;\n /**\n * A second call ringing while this one is in progress (call waiting).\n * Offer `answerWaiting` (\"End & answer\" — this call ends) and\n * `declineWaiting` (its caller hears busy). If this call ends first,\n * the waiting one simply becomes the ringing call. null when none;\n * absent before 0.10.0.\n */\n waiting?: WaitingCall | null;\n /** Facing of the published local camera; absent when the camera is off. */\n cameraFacing?: 'front' | 'back';\n /**\n * Your own link to the call. `poor` / `lost`: show a \"weak connection\"\n * hint; `phase: 'reconnecting'` is the hard version of the same thing.\n * Absent before 0.11.0.\n */\n connectionQuality?: ConnectionQuality;\n /**\n * Incoming video is switched off because your connection could not\n * carry it — the audio keeps going, and video comes back by itself\n * once the link has been good for a few seconds. Participants read\n * `cameraOn: false` meanwhile. Absent before 0.11.0.\n */\n videoPaused?: boolean;\n}\n\n/** `good` covers good and excellent; `unknown` until the SFU has measured. */\nexport type ConnectionQuality = 'good' | 'poor' | 'lost' | 'unknown';\n\nexport type AudioOutputKind = 'earpiece' | 'speaker' | 'bluetooth' | 'headset';\n\n/** The call waiting beside the current one. */\nexport interface WaitingCall {\n callId: string;\n conversationId: string | null;\n conversationName: string | null;\n callerName: string | null;\n media: 'audio' | 'video';\n}\n\n/** One place call audio can play. */\nexport interface AudioOutput {\n /** Opaque; stable while the device stays connected. */\n id: string;\n kind: AudioOutputKind;\n /**\n * The device's own name for Bluetooth/USB (\"AirPods Pro\"); a plain\n * English default for built-ins (\"iPhone\"/\"Phone\", \"Speaker\",\n * \"Headphones\") — relabel those by `kind` to localise.\n */\n name: string;\n}\n\nexport interface ConfigureOptions {\n /** Drawable resource NAME for the call notification's small icon. */\n smallIcon?: string;\n /** Ringback tone: raw resource NAME (Android); main-bundle sound name, mp3/caf/wav (iOS). */\n ringback?: string;\n /**\n * iOS: the APNs environment of this build's `aps-environment`\n * entitlement. Echoed back with the VoIP token so the server pushes to\n * the right gateway. Ignored on Android.\n */\n apnsEnvironment?: 'production' | 'sandbox';\n}\n\n/** The iOS PushKit (VoIP) token and the APNs environment it belongs to. */\nexport interface VoipToken {\n /** Hex-encoded PushKit token. */\n token: string;\n environment: 'production' | 'sandbox' | string;\n}\n\nexport interface PlaceOptions {\n media: 'audio' | 'video';\n /** The user's session token — authorizes placing/joining (CALL_CONTRACT.md §3.2). */\n sessionToken: string;\n}\n\n/**\n * What the user tapped on a missed-call notification: the notification\n * itself (`open` the conversation) or its Call back button (`call_back`\n * — place a call on the conversation with `media`).\n */\nexport interface CallAction {\n type: 'open' | 'call_back';\n conversationId: string;\n callId: string | null;\n media: 'audio' | 'video';\n}\n\ntype NativeSnapshot = { snapshot: Snapshot | null };\n\ninterface PoolseCallsNative {\n configure(apiBaseUrl: string, options: ConfigureOptions | null): Promise<void>;\n getCallState(): NativeSnapshot;\n place(conversationId: string, media: string, sessionToken: string): Promise<void>;\n join(callId: string, conversationId: string | null, sessionToken: string): Promise<void>;\n answer(): void;\n decline(): void;\n hangUp(): void;\n answerWaiting?(callId: string | null): void;\n declineWaiting?(callId: string | null): void;\n setMuted(muted: boolean): void;\n setCamera(on: boolean): void;\n switchCamera(): void;\n setSpeaker(on: boolean): void;\n setAudioOutput?(id: string): void;\n callControl?(): Promise<{ callId: string; controlToken: string } | null>;\n setPictureInPictureEnabled?(on: boolean): void;\n isInPictureInPicture?(): boolean;\n pictureInPictureSupported?(): boolean;\n onRingEnded(callId: string, reason: string): void;\n onCallFinished(callId: string, reason: string | null): void;\n canUseFullScreenIntent(): boolean;\n openFullScreenIntentSettings(): void;\n setShowOnLockscreen?(enabled: boolean): void;\n getVoipToken?(): VoipToken | null;\n takeCallAction?(): CallAction | null;\n setActiveConversation?(conversationId: string | null): void;\n addListener(event: 'onCallState', cb: (payload: NativeSnapshot) => void): { remove(): void };\n addListener(event: 'onVoipToken', cb: (payload: VoipToken) => void): { remove(): void };\n addListener(event: 'onCallAction', cb: (payload: CallAction) => void): { remove(): void };\n addListener(\n event: 'onPictureInPicture',\n cb: (payload: { active: boolean }) => void,\n ): { remove(): void };\n}\n\nconst native = requireOptionalNativeModule<PoolseCallsNative>('PoolseCalls');\n\n/** True when the native call core is present in this build. */\nexport const nativeCallsAvailable = native != null;\n\n// Kept for startRoom, the one command that talks to the server from JS.\nlet apiOrigin: string | null = null;\n\n/** Configure once, before any call can arrive. No secrets — just the API origin. */\nexport async function configure(apiBaseUrl: string, options?: ConfigureOptions): Promise<void> {\n apiOrigin = apiBaseUrl.replace(/\\/+$/, '');\n await native?.configure(apiBaseUrl, options ?? null);\n}\n\n/** The current snapshot — safe to read at any moment, including cold answer and before configure. */\nexport function getCallState(): Snapshot | null {\n return native?.getCallState().snapshot ?? null;\n}\n\nexport type Unsubscribe = () => void;\n\n/** Subscribe to call state. Fires a full snapshot on every change. */\nexport function onCallState(cb: (snapshot: Snapshot | null) => void): Unsubscribe {\n if (!native) return () => undefined;\n const sub = native.addListener('onCallState', (payload) => cb(payload.snapshot));\n return () => sub.remove();\n}\n\nexport function place(conversationId: string, options: PlaceOptions): Promise<void> {\n return native?.place(conversationId, options.media, options.sessionToken) ?? Promise.resolve();\n}\n\nexport function join(\n callId: string,\n conversationId: string | null,\n sessionToken: string,\n): Promise<void> {\n return native?.join(callId, conversationId, sessionToken) ?? Promise.resolve();\n}\n\nexport interface StartRoomResult {\n /** The room's call id — what the Join banner and `call:*` events carry. */\n callId: string;\n /** False when something was live already (a room, or a ringing call) and this joined it. */\n created: boolean;\n}\n\n/**\n * Start the conversation's room — a call that rings nobody (CALL_CONTRACT.md\n * §5.6) — or join whatever is live there, then carry it on the native\n * core like any joined call: CallKit / the call service, so it keeps\n * going with the phone locked, and the same audio routing as a call.\n *\n * Others in the conversation see it through the Join banner and join it\n * with `join`. Leaving (`hangUp`) never ends it for them; it ends once\n * it has been empty for a short grace. `media: 'video'` makes it a video\n * room. Rejects when the server refuses (not a member, no SFU) or\n * before `configure`.\n */\nexport async function startRoom(\n conversationId: string,\n options: PlaceOptions,\n): Promise<StartRoomResult> {\n if (!native) throw new Error('The native call core is not in this build.');\n if (!apiOrigin) throw new Error('Call configure() before startRoom().');\n const res = await fetch(\n `${apiOrigin}/v1/conversations/${encodeURIComponent(conversationId)}/room`,\n {\n method: 'POST',\n headers: {\n authorization: `Bearer ${options.sessionToken}`,\n 'content-type': 'application/json',\n },\n body: JSON.stringify({ media: options.media }),\n },\n );\n const body = (await res.json().catch(() => null)) as {\n created?: boolean;\n call?: { id?: string };\n error?: { message?: string };\n } | null;\n const callId = body?.call?.id;\n if (!res.ok || !callId) {\n throw new Error(body?.error?.message ?? `Couldn't start the room (${res.status}).`);\n }\n // The core joins with its own request: it owns the session from here,\n // exactly as when the room is joined from the banner.\n await native.join(callId, conversationId, options.sessionToken);\n return { callId, created: body?.created === true };\n}\n\n/** Who to ring into the call — poolse user ids, your app's own (external) ids, or both. */\nexport interface RingIntoCallOptions {\n userIds?: string[];\n externalIds?: string[];\n}\n\n/**\n * Ring more of the conversation's members into the call you are on\n * (\"Add people\"). Each is rung as on a fresh call — their phone rings,\n * CallKit / full-screen — and answering puts them in this call.\n *\n * Resolves with the poolse user ids actually rung: anyone already in\n * the call, still ringing, or not a member of the conversation is\n * skipped. Rejects with no call in progress, while nobody has answered\n * yet (the call's own ring is still out), or when the server refuses.\n */\nexport async function ringIntoCall(people: RingIntoCallOptions): Promise<string[]> {\n if (!native?.callControl) throw new Error('This build cannot ring people into a call.');\n if (!apiOrigin) throw new Error('Call configure() before ringIntoCall().');\n const control = await native.callControl();\n if (!control) throw new Error('There is no call in progress.');\n const res = await fetch(`${apiOrigin}/v1/calls/${encodeURIComponent(control.callId)}/ring`, {\n method: 'POST',\n headers: {\n authorization: `Bearer ${control.controlToken}`,\n 'content-type': 'application/json',\n },\n body: JSON.stringify({\n user_ids: people.userIds ?? [],\n external_ids: people.externalIds ?? [],\n }),\n });\n const body = (await res.json().catch(() => null)) as {\n rung_user_ids?: string[];\n error?: { message?: string };\n } | null;\n if (!res.ok) throw new Error(body?.error?.message ?? `Couldn't ring them (${res.status}).`);\n return body?.rung_user_ids ?? [];\n}\n\nexport const answer = (): void => native?.answer();\nexport const decline = (): void => native?.decline();\nexport const hangUp = (): void => native?.hangUp();\n\n/**\n * Call waiting: end the current call and answer `snapshot.waiting`.\n * Pass its `callId`: a tap on a card for a call that is no longer the\n * one waiting is then ignored instead of answering a different call.\n */\nexport const answerWaiting = (callId?: string): void => native?.answerWaiting?.(callId ?? null);\n\n/** Call waiting: turn `snapshot.waiting` away — its caller hears busy. */\nexport const declineWaiting = (callId?: string): void => native?.declineWaiting?.(callId ?? null);\nexport const setMuted = (muted: boolean): void => native?.setMuted(muted);\nexport const setCamera = (on: boolean): void => native?.setCamera(on);\nexport const switchCamera = (): void => native?.switchCamera();\n/** Route call audio to the loudspeaker (`true`) or back to earpiece / headset (`false`). */\nexport const setSpeaker = (on: boolean): void => native?.setSpeaker(on);\n\n/**\n * Play call audio through one of `snapshot.audioOutputs`. The choice\n * holds for the rest of the call, until that device disconnects or a new\n * headset / Bluetooth device connects (which takes over, as in the\n * phone's own dialer). Without a choice a connected headset wins, then\n * the earpiece for voice calls or the speaker for video.\n */\nexport function setAudioOutput(id: string): void {\n if (native?.setAudioOutput) native.setAudioOutput(id);\n else native?.setSpeaker(id === 'speaker'); // an older native build\n}\n\n/**\n * Socket forwarding for an open app: a `call:ring_ended` seen on the\n * socket. Idempotent with the push path — the core dedupes.\n */\nexport const onRingEnded = (callId: string, reason: string): void =>\n native?.onRingEnded(callId, reason);\n\n/**\n * Socket forwarding: `call:finished`. Pass the payload's `reason`\n * (`finished` | `declined_all` | `no_answer` | `cancelled`) so an\n * unanswered caller sees \"Declined\"/\"No answer\", not \"Call ended\".\n * Idempotent with the `finished` push.\n */\nexport const onCallFinished = (callId: string, reason?: string): void =>\n native?.onCallFinished(callId, reason ?? null);\n\n/**\n * Android 14+: whether the app may show the full-screen ring over the\n * lock screen. `true` on older Android and where the module is absent.\n */\nexport const canUseFullScreenIntent = (): boolean => native?.canUseFullScreenIntent() ?? true;\n\n/** Open the system screen where the user grants full-screen intents (falls back to notification settings). */\nexport const openFullScreenIntentSettings = (): void => native?.openFullScreenIntentSettings();\n\n/**\n * Android: let the app show over the lock screen while a call rings or\n * runs — answering must never demand an unlock. Turn it off when the\n * call ends. The activity re-applies it when the core relaunches it for\n * a call (`poolse_launch_call`), given the host's MainActivity hook.\n * No-op on iOS, where CallKit owns the lock screen.\n */\nexport function setShowOnLockscreen(enabled: boolean): void {\n try {\n native?.setShowOnLockscreen?.(enabled);\n } catch {\n // Never let a window flag take a call down.\n }\n}\n\n// ── missed-call notifications (Android) ─────────────────────────────────\n\n/**\n * Android: the missed-call notification action the app was LAUNCHED\n * with, once — read it on mount. `null` when the app opened any other\n * way. The native core posts that notification itself from the push,\n * so it works with the app closed.\n *\n * iOS shows missed calls as an ordinary alert push (to the token you\n * register with `kind: 'alert'`); read its taps with your notification\n * library — its `type` is `call_missed`, the category\n * `poolse_missed_call`, the Call back action `call_back`.\n */\nexport function takeCallAction(): CallAction | null {\n return native?.takeCallAction?.() ?? null;\n}\n\n/** Android: a missed-call notification tapped while the app is running. */\nexport function onCallAction(cb: (action: CallAction) => void): Unsubscribe {\n if (!native || !native.takeCallAction) return () => undefined;\n const sub = native.addListener('onCallAction', cb);\n return () => sub.remove();\n}\n\n// ── chat notifications ─────────────────────────────────────────────────\n\nlet activeConversation: string | null = null;\n\n/**\n * Tell the core which conversation is on screen (`null` when none, and\n * when the app goes to the background). Its messages are not notified —\n * the user is reading them — and opening it clears the notifications\n * already shown for it.\n */\nexport function setActiveConversation(conversationId: string | null): void {\n activeConversation = conversationId;\n native?.setActiveConversation?.(conversationId);\n}\n\n/**\n * For the app's notification handler (expo-notifications'\n * `setNotificationHandler`): `false` for a chat notification of the\n * conversation on screen, which must not pop over the chat itself.\n * Android never asks — the core skips those natively.\n */\nexport function shouldPresentMessage(data: Record<string, unknown> | undefined | null): boolean {\n if (!data || data['type'] !== 'message') return true;\n return data['conversation_id'] !== activeConversation;\n}\n\n/**\n * The conversation a tapped notification belongs to — a chat message\n * (`type: 'message'`) or a missed call (`call_missed`) — from its data.\n * iOS hands the tap to your notification library; Android delivers it\n * through `takeCallAction` / `onCallAction` (type `open`).\n */\nexport function conversationOfNotification(\n data: Record<string, unknown> | undefined | null,\n): string | null {\n if (!data) return null;\n const type = data['type'];\n if (type !== 'message' && type !== 'call_missed') return null;\n return typeof data['conversation_id'] === 'string' ? data['conversation_id'] : null;\n}\n\n// ── VoIP push (iOS) ───────────────────────────────────────────────────\n\n/**\n * iOS: the current PushKit VoIP token, registered natively at launch.\n * `null` until iOS issues one, and always on Android (FCM carries rings).\n */\nexport function getVoipToken(): VoipToken | null {\n return native?.getVoipToken?.() ?? null;\n}\n\n/** iOS: fires whenever PushKit issues (or rotates) the VoIP token. No-op on Android. */\nexport function onVoipToken(cb: (token: VoipToken) => void): Unsubscribe {\n if (!native || !native.getVoipToken) return () => undefined;\n const sub = native.addListener('onVoipToken', cb);\n return () => sub.remove();\n}\n\n// ── picture-in-picture ────────────────────────────────────────────────\n\n/**\n * Arm picture-in-picture: while on, leaving the app keeps the call's\n * video in a floating window. Turn it on only while a video call shows\n * someone's picture, and off otherwise.\n *\n * iOS (15+) floats the `<CallVideoView pictureInPicture>` that is on\n * screen — mark the main remote picture. Android (8+) floats the whole\n * app: draw a compact layout while `isInPictureInPicture()` (see\n * `onPictureInPicture`). The app needs `android:supportsPictureInPicture`\n * on its activity.\n */\nexport function setPictureInPictureEnabled(on: boolean): void {\n native?.setPictureInPictureEnabled?.(on);\n}\n\n/** Whether the floating window is open right now. */\nexport function isInPictureInPicture(): boolean {\n return native?.isInPictureInPicture?.() ?? false;\n}\n\n/** Whether this device can float a call at all. */\nexport function pictureInPictureSupported(): boolean {\n return native?.pictureInPictureSupported?.() ?? false;\n}\n\n/** Fires when the floating window opens (`true`) and closes (`false`). */\nexport function onPictureInPicture(cb: (active: boolean) => void): Unsubscribe {\n if (!native?.setPictureInPictureEnabled) return () => undefined;\n const sub = native.addListener('onPictureInPicture', (payload) => cb(payload.active));\n return () => sub.remove();\n}\n\n// ── video ─────────────────────────────────────────────────────────────\n\nexport interface CallVideoViewProps extends ViewProps {\n /** Remote participant's userId (LiveKit identity). Omit with local=true for self view. */\n participantId?: string;\n local?: boolean;\n /** default: true for local front camera, false otherwise */\n mirror?: boolean;\n /** default 'cover' */\n fit?: 'cover' | 'contain';\n /**\n * iOS: this remote picture is the one picture-in-picture floats when\n * the app is left (`setPictureInPictureEnabled`). Mark one at a time.\n */\n pictureInPicture?: boolean;\n}\n\ntype NativeVideoProps = CallVideoViewProps;\n\nlet nativeVideo: ComponentType<NativeVideoProps> | null | undefined;\n\n/** Resolved lazily (first render) and only when the native module exists. */\nfunction nativeVideoView(): ComponentType<NativeVideoProps> | null {\n if (nativeVideo !== undefined) return nativeVideo;\n nativeVideo = null;\n if (native) {\n try {\n nativeVideo = requireNativeViewManager<NativeVideoProps>('PoolseCalls', 'PoolseCallVideo');\n } catch {\n nativeVideo = null; // an older native build without the view\n }\n }\n return nativeVideo;\n}\n\n/**\n * A participant's camera (or, with `local`, your own), rendered natively\n * by the call core. Shows nothing (stays transparent) while that camera\n * is off — draw the avatar from the snapshot's `cameraOn` underneath.\n * Without the native module it renders an empty View.\n */\nexport function CallVideoView(props: CallVideoViewProps): ReactElement | null {\n const Native = nativeVideoView();\n if (!Native) {\n const { participantId: _p, local: _l, mirror: _m, fit: _f, pictureInPicture: _pip, ...rest } = props;\n return createElement(View, rest);\n }\n return createElement(Native, props);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AA+MA,IAAM,MAAA,GAAS,4BAA+C,aAAa,CAAA;AAGpE,IAAM,uBAAuB,MAAA,IAAU;AAG9C,IAAI,SAAA,GAA2B,IAAA;AAG/B,eAAsB,SAAA,CAAU,YAAoB,OAAA,EAA2C;AAC7F,EAAA,SAAA,GAAY,UAAA,CAAW,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA;AACzC,EAAA,MAAM,MAAA,EAAQ,SAAA,CAAU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A,IAAI,WAAA;AAGJ,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 (Android). 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 * iOS: the APNs environment of this build's `aps-environment`\n * entitlement. Echoed back with the VoIP token so the server pushes to\n * the right gateway. Ignored on Android.\n */\n apnsEnvironment?: 'production' | 'sandbox';\n}\n\n/** The iOS PushKit (VoIP) token and the APNs environment it belongs to. */\nexport interface VoipToken {\n /** Hex-encoded PushKit token. */\n token: string;\n environment: 'production' | 'sandbox' | string;\n}\n\nexport interface PlaceOptions {\n media: 'audio' | 'video';\n /** The user's session token — authorizes placing/joining (CALL_CONTRACT.md §3.2). */\n sessionToken: string;\n}\n\n/**\n * What the user tapped on a missed-call notification: the notification\n * itself (`open` the conversation) or its Call back button (`call_back`\n * — place a call on the conversation with `media`).\n */\nexport interface CallAction {\n type: 'open' | 'call_back';\n conversationId: string;\n callId: string | null;\n media: 'audio' | 'video';\n}\n\ntype NativeSnapshot = { snapshot: Snapshot | null };\n\ninterface PoolseCallsNative {\n configure(apiBaseUrl: string, options: ConfigureOptions | null): Promise<void>;\n getCallState(): NativeSnapshot;\n place(conversationId: string, media: string, sessionToken: string): Promise<void>;\n join(callId: string, conversationId: string | null, sessionToken: string): Promise<void>;\n answer(): void;\n decline(): void;\n hangUp(): void;\n answerWaiting?(callId: string | null): void;\n declineWaiting?(callId: string | null): void;\n setMuted(muted: boolean): void;\n setCamera(on: boolean): void;\n switchCamera(): void;\n 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 addListener(event: 'onCallState', cb: (payload: NativeSnapshot) => void): { remove(): void };\n addListener(event: 'onVoipToken', cb: (payload: VoipToken) => void): { remove(): void };\n addListener(event: 'onCallAction', cb: (payload: CallAction) => void): { remove(): void };\n addListener(\n event: 'onPictureInPicture',\n cb: (payload: { active: boolean }) => void,\n ): { remove(): void };\n}\n\nconst native = requireOptionalNativeModule<PoolseCallsNative>('PoolseCalls');\n\n/** True when the native call core is present in this build. */\nexport const nativeCallsAvailable = native != null;\n\n// Kept for startRoom, the one command that talks to the server from JS.\nlet apiOrigin: string | null = null;\n\n/** Configure once, before any call can arrive. No secrets — just the API origin. */\nexport async function configure(apiBaseUrl: string, options?: ConfigureOptions): Promise<void> {\n apiOrigin = apiBaseUrl.replace(/\\/+$/, '');\n await native?.configure(apiBaseUrl, options ?? null);\n}\n\n/** The current snapshot — safe to read at any moment, including cold answer and before configure. */\nexport function getCallState(): Snapshot | null {\n return native?.getCallState().snapshot ?? null;\n}\n\nexport type Unsubscribe = () => void;\n\n/** Subscribe to call state. Fires a full snapshot on every change. */\nexport function onCallState(cb: (snapshot: Snapshot | null) => void): Unsubscribe {\n if (!native) return () => undefined;\n const sub = native.addListener('onCallState', (payload) => cb(payload.snapshot));\n return () => sub.remove();\n}\n\nexport function place(conversationId: string, options: PlaceOptions): Promise<void> {\n return native?.place(conversationId, options.media, options.sessionToken) ?? Promise.resolve();\n}\n\nexport function join(\n callId: string,\n conversationId: string | null,\n sessionToken: string,\n): Promise<void> {\n return native?.join(callId, conversationId, sessionToken) ?? Promise.resolve();\n}\n\nexport interface StartRoomResult {\n /** The room's call id — what the Join banner and `call:*` events carry. */\n callId: string;\n /** False when something was live already (a room, or a ringing call) and this joined it. */\n created: boolean;\n}\n\n/**\n * Start the conversation's room — a call that rings nobody (CALL_CONTRACT.md\n * §5.6) — or join whatever is live there, then carry it on the native\n * core like any joined call: CallKit / the call service, so it keeps\n * going with the phone locked, and the same audio routing as a call.\n *\n * Others in the conversation see it through the Join banner and join it\n * with `join`. Leaving (`hangUp`) never ends it for them; it ends once\n * it has been empty for a short grace. `media: 'video'` makes it a video\n * room. Rejects when the server refuses (not a member, no SFU) or\n * before `configure`.\n */\nexport async function startRoom(\n conversationId: string,\n options: PlaceOptions,\n): Promise<StartRoomResult> {\n if (!native) throw new Error('The native call core is not in this build.');\n if (!apiOrigin) throw new Error('Call configure() before startRoom().');\n const res = await fetch(\n `${apiOrigin}/v1/conversations/${encodeURIComponent(conversationId)}/room`,\n {\n method: 'POST',\n headers: {\n authorization: `Bearer ${options.sessionToken}`,\n 'content-type': 'application/json',\n },\n body: JSON.stringify({ media: options.media }),\n },\n );\n const body = (await res.json().catch(() => null)) as {\n created?: boolean;\n call?: { id?: string };\n error?: { message?: string };\n } | null;\n const callId = body?.call?.id;\n if (!res.ok || !callId) {\n throw new Error(body?.error?.message ?? `Couldn't start the room (${res.status}).`);\n }\n // The core joins with its own request: it owns the session from here,\n // exactly as when the room is joined from the banner.\n await native.join(callId, conversationId, options.sessionToken);\n return { callId, created: body?.created === true };\n}\n\n/** Who to ring into the call — poolse user ids, your app's own (external) ids, or both. */\nexport interface RingIntoCallOptions {\n userIds?: string[];\n externalIds?: string[];\n}\n\n/**\n * Ring more of the conversation's members into the call you are on\n * (\"Add people\"). Each is rung as on a fresh call — their phone rings,\n * CallKit / full-screen — and answering puts them in this call.\n *\n * Resolves with the poolse user ids actually rung: anyone already in\n * the call, still ringing, or not a member of the conversation is\n * skipped. Rejects with no call in progress, while nobody has answered\n * yet (the call's own ring is still out), or when the server refuses.\n */\nexport async function ringIntoCall(people: RingIntoCallOptions): Promise<string[]> {\n if (!native?.callControl) throw new Error('This build cannot ring people into a call.');\n if (!apiOrigin) throw new Error('Call configure() before ringIntoCall().');\n const control = await native.callControl();\n if (!control) throw new Error('There is no call in progress.');\n const res = await fetch(`${apiOrigin}/v1/calls/${encodeURIComponent(control.callId)}/ring`, {\n method: 'POST',\n headers: {\n authorization: `Bearer ${control.controlToken}`,\n 'content-type': 'application/json',\n },\n body: JSON.stringify({\n user_ids: people.userIds ?? [],\n external_ids: people.externalIds ?? [],\n }),\n });\n const body = (await res.json().catch(() => null)) as {\n rung_user_ids?: string[];\n error?: { message?: string };\n } | null;\n if (!res.ok) throw new Error(body?.error?.message ?? `Couldn't ring them (${res.status}).`);\n return body?.rung_user_ids ?? [];\n}\n\nexport const answer = (): void => native?.answer();\nexport const decline = (): void => native?.decline();\nexport const hangUp = (): void => native?.hangUp();\n\n/**\n * Call waiting: end the current call and answer `snapshot.waiting`.\n * Pass its `callId`: a tap on a card for a call that is no longer the\n * one waiting is then ignored instead of answering a different call.\n */\nexport const answerWaiting = (callId?: string): void => native?.answerWaiting?.(callId ?? null);\n\n/** Call waiting: turn `snapshot.waiting` away — its caller hears busy. */\nexport const declineWaiting = (callId?: string): void => native?.declineWaiting?.(callId ?? null);\nexport const setMuted = (muted: boolean): void => native?.setMuted(muted);\nexport const setCamera = (on: boolean): void => native?.setCamera(on);\nexport const switchCamera = (): void => native?.switchCamera();\n\n/**\n * Whether this build can share the screen in a call: Android with the\n * LiveKit media engine. iOS shares through a broadcast extension, which\n * comes in a later release; it can already show 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); resolves `false` when they say no or\n * the build cannot share. `snapshot.screenSharing` turns true once the\n * screen is actually going out. Stopping from the system notification\n * ends it the 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// ── 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"]}
|
|
@@ -9,23 +9,26 @@ public struct SnapshotParticipant: Equatable {
|
|
|
9
9
|
public var muted: Bool
|
|
10
10
|
/// True only with a published, subscribed, unmuted camera track.
|
|
11
11
|
public var cameraOn: Bool
|
|
12
|
+
/// True with a published, subscribed, unmuted screen share.
|
|
13
|
+
public var screenSharing: Bool
|
|
12
14
|
/// Their link to the SFU: `good` | `poor` | `lost` (dropped, coming
|
|
13
15
|
/// back — "Reconnecting…") | `unknown`.
|
|
14
16
|
public var connectionQuality: String
|
|
15
17
|
|
|
16
18
|
public init(userId: String, externalId: String, speaking: Bool, muted: Bool, cameraOn: Bool,
|
|
17
|
-
connectionQuality: String = "unknown") {
|
|
19
|
+
connectionQuality: String = "unknown", screenSharing: Bool = false) {
|
|
18
20
|
self.userId = userId
|
|
19
21
|
self.externalId = externalId
|
|
20
22
|
self.speaking = speaking
|
|
21
23
|
self.muted = muted
|
|
22
24
|
self.cameraOn = cameraOn
|
|
23
25
|
self.connectionQuality = connectionQuality
|
|
26
|
+
self.screenSharing = screenSharing
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
public var dictionary: [String: Any] {
|
|
27
30
|
["userId": userId, "externalId": externalId, "speaking": speaking, "muted": muted, "cameraOn": cameraOn,
|
|
28
|
-
"connectionQuality": connectionQuality]
|
|
31
|
+
"connectionQuality": connectionQuality, "screenSharing": screenSharing]
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
|
|
@@ -11,6 +11,7 @@ public final class PoolseCallVideoView: ExpoView {
|
|
|
11
11
|
var local = false
|
|
12
12
|
var mirror: Bool?
|
|
13
13
|
var fit = "cover"
|
|
14
|
+
var source = "camera"
|
|
14
15
|
/// This view is what picture-in-picture grows out of (a remote's picture).
|
|
15
16
|
var pictureInPicture = false
|
|
16
17
|
|
|
@@ -55,7 +56,8 @@ public final class PoolseCallVideoView: ExpoView {
|
|
|
55
56
|
if window != nil { attachSurface() }
|
|
56
57
|
return
|
|
57
58
|
}
|
|
58
|
-
s.configure(participantId: participantId, local: local, mirror: mirror,
|
|
59
|
+
s.configure(participantId: participantId, local: local, mirror: mirror,
|
|
60
|
+
fit: fit == "contain" ? "contain" : "cover", source: source == "screen" ? "screen" : "camera")
|
|
59
61
|
if pictureInPicture && !local && participantId != nil {
|
|
60
62
|
CallPictureInPicture.shared.setSource(self, participantId: participantId)
|
|
61
63
|
} else {
|
|
@@ -75,6 +75,9 @@ public class PoolseCallsModule: Module {
|
|
|
75
75
|
Function("setMuted") { (muted: Bool) in onCore { $0.setMuted(muted) } }
|
|
76
76
|
Function("setCamera") { (on: Bool) in onCore { $0.setCamera(on) } }
|
|
77
77
|
Function("switchCamera") { onCore { $0.switchCamera() } }
|
|
78
|
+
// Sharing from iOS needs a broadcast upload extension (a later
|
|
79
|
+
// release); other people's screens already show via `source`.
|
|
80
|
+
Function("screenShareSupported") { false }
|
|
78
81
|
Function("setSpeaker") { (on: Bool) in onCore { $0.setSpeaker(on) } }
|
|
79
82
|
Function("setAudioOutput") { (id: String) in onCore { $0.setAudioOutput(id) } }
|
|
80
83
|
|
|
@@ -127,6 +130,8 @@ public class PoolseCallsModule: Module {
|
|
|
127
130
|
Prop("local") { (view: PoolseCallVideoView, local: Bool?) in view.local = local ?? false }
|
|
128
131
|
Prop("mirror") { (view: PoolseCallVideoView, mirror: Bool?) in view.mirror = mirror }
|
|
129
132
|
Prop("fit") { (view: PoolseCallVideoView, fit: String?) in view.fit = fit ?? "cover" }
|
|
133
|
+
// `camera` (default) or `screen`: their shared screen instead of their face.
|
|
134
|
+
Prop("source") { (view: PoolseCallVideoView, source: String?) in view.source = source ?? "camera" }
|
|
130
135
|
Prop("pictureInPicture") { (view: PoolseCallVideoView, on: Bool?) in view.pictureInPicture = on ?? false }
|
|
131
136
|
OnViewDidUpdateProps { (view: PoolseCallVideoView) in view.apply() }
|
|
132
137
|
}
|
|
@@ -614,6 +614,27 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
614
614
|
return pub.track as? VideoTrack
|
|
615
615
|
}
|
|
616
616
|
|
|
617
|
+
/// A participant's shared screen (with [local], our own), once
|
|
618
|
+
/// published, subscribed and unmuted. Not paused with the cameras on a
|
|
619
|
+
/// weak link: the shared screen is usually what the call is about.
|
|
620
|
+
func screenTrack(participantId: String?, local: Bool) -> VideoTrack? {
|
|
621
|
+
guard let r = room else { return nil }
|
|
622
|
+
if local {
|
|
623
|
+
guard let pub = r.localParticipant.trackPublications.values.first(where: { $0.source == .screenShareVideo }),
|
|
624
|
+
!pub.isMuted else { return nil }
|
|
625
|
+
return pub.track as? VideoTrack
|
|
626
|
+
}
|
|
627
|
+
guard let id = participantId,
|
|
628
|
+
let p = r.remoteParticipants.values.first(where: { $0.identity?.stringValue == id }) else { return nil }
|
|
629
|
+
return remoteScreen(p)
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
private func remoteScreen(_ p: RemoteParticipant) -> VideoTrack? {
|
|
633
|
+
guard let pub = p.trackPublications.values.first(where: { $0.source == .screenShareVideo }) as? RemoteTrackPublication,
|
|
634
|
+
pub.isSubscribed, !pub.isMuted else { return nil }
|
|
635
|
+
return pub.track as? VideoTrack
|
|
636
|
+
}
|
|
637
|
+
|
|
617
638
|
/// `front` | `back` of the published local camera, or nil when none.
|
|
618
639
|
func cameraFacing() -> String? {
|
|
619
640
|
guard let r = room, let track = localCameraTrack(r) else { return nil }
|
|
@@ -744,7 +765,8 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
744
765
|
speaking: p.isSpeaking,
|
|
745
766
|
muted: !p.isMicrophoneEnabled(),
|
|
746
767
|
cameraOn: remoteCamera(p) != nil,
|
|
747
|
-
connectionQuality: Self.wire(p.connectionQuality)
|
|
768
|
+
connectionQuality: Self.wire(p.connectionQuality),
|
|
769
|
+
screenSharing: remoteScreen(p) != nil
|
|
748
770
|
)
|
|
749
771
|
}
|
|
750
772
|
events?.onParticipants(roster)
|
|
@@ -19,6 +19,7 @@ final class LiveKitVideoSurface: UIView {
|
|
|
19
19
|
private var local = false
|
|
20
20
|
private var mirror: Bool?
|
|
21
21
|
private var fit = "cover"
|
|
22
|
+
private var source = "camera"
|
|
22
23
|
|
|
23
24
|
init(port: LiveKitMediaPort, renderMode: VideoView.RenderMode = .auto) {
|
|
24
25
|
self.port = port
|
|
@@ -36,24 +37,29 @@ final class LiveKitVideoSurface: UIView {
|
|
|
36
37
|
|
|
37
38
|
/// [participantId] is the remote's userId (SFU identity); [local] shows
|
|
38
39
|
/// the self view. [mirror] nil = mirrored for the local front camera only.
|
|
39
|
-
|
|
40
|
+
/// [source] `camera` or `screen`: their shared screen, never mirrored.
|
|
41
|
+
func configure(participantId: String?, local: Bool, mirror: Bool?, fit: String, source: String = "camera") {
|
|
40
42
|
self.participantId = participantId
|
|
41
43
|
self.local = local
|
|
42
44
|
self.mirror = mirror
|
|
43
45
|
self.fit = fit
|
|
46
|
+
self.source = source
|
|
44
47
|
rebind()
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
func rebind() {
|
|
48
51
|
guard !released else { return }
|
|
49
|
-
let
|
|
52
|
+
let screen = source == "screen"
|
|
53
|
+
let next = screen
|
|
54
|
+
? port?.screenTrack(participantId: participantId, local: local)
|
|
55
|
+
: port?.cameraTrack(participantId: participantId, local: local)
|
|
50
56
|
if (videoView.track as AnyObject?) !== (next as AnyObject?) {
|
|
51
57
|
videoView.track = next
|
|
52
58
|
}
|
|
53
59
|
// No camera: hide so a last frozen frame never shows; the UI draws
|
|
54
60
|
// the avatar from the snapshot's cameraOn underneath.
|
|
55
61
|
videoView.isHidden = next == nil
|
|
56
|
-
let mirrored = mirror ?? (local && port?.cameraFacing() != "back")
|
|
62
|
+
let mirrored = !screen && (mirror ?? (local && port?.cameraFacing() != "back"))
|
|
57
63
|
videoView.mirrorMode = mirrored ? .mirror : .off
|
|
58
64
|
videoView.layoutMode = fit == "contain" ? .fit : .fill
|
|
59
65
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poolse/native",
|
|
3
|
-
"version": "3.2.0-dev.
|
|
3
|
+
"version": "3.2.0-dev.2",
|
|
4
4
|
"description": "Native call core for poolse — Kotlin/Swift calling engine with a thin React Native bridge. Ring, answer and carry audio with the app killed and the phone locked.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
package/src/index.ts
CHANGED
|
@@ -46,6 +46,11 @@ export interface Snapshot {
|
|
|
46
46
|
muted: boolean;
|
|
47
47
|
/** True only with a published, subscribed, unmuted camera track (show video, not avatar). */
|
|
48
48
|
cameraOn: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Sharing their screen: draw it with `<CallVideoView source="screen">`,
|
|
51
|
+
* large and with `fit="contain"`. Absent before 3.2.
|
|
52
|
+
*/
|
|
53
|
+
screenSharing?: boolean;
|
|
49
54
|
/**
|
|
50
55
|
* Their link to the call: `lost` while they have dropped and are
|
|
51
56
|
* coming back (show "Reconnecting…"), `poor` for a weak signal.
|
|
@@ -90,6 +95,8 @@ export interface Snapshot {
|
|
|
90
95
|
* `cameraOn: false` meanwhile. Absent before 0.11.0.
|
|
91
96
|
*/
|
|
92
97
|
videoPaused?: boolean;
|
|
98
|
+
/** You are sharing your screen (Android). Absent before 3.2. */
|
|
99
|
+
screenSharing?: boolean;
|
|
93
100
|
}
|
|
94
101
|
|
|
95
102
|
/** `good` covers good and excellent; `unknown` until the SFU has measured. */
|
|
@@ -172,6 +179,9 @@ interface PoolseCallsNative {
|
|
|
172
179
|
setMuted(muted: boolean): void;
|
|
173
180
|
setCamera(on: boolean): void;
|
|
174
181
|
switchCamera(): void;
|
|
182
|
+
screenShareSupported?(): boolean;
|
|
183
|
+
startScreenShare?(): Promise<boolean>;
|
|
184
|
+
stopScreenShare?(): void;
|
|
175
185
|
setSpeaker(on: boolean): void;
|
|
176
186
|
setAudioOutput?(id: string): void;
|
|
177
187
|
callControl?(): Promise<{ callId: string; controlToken: string } | null>;
|
|
@@ -342,6 +352,25 @@ export const declineWaiting = (callId?: string): void => native?.declineWaiting?
|
|
|
342
352
|
export const setMuted = (muted: boolean): void => native?.setMuted(muted);
|
|
343
353
|
export const setCamera = (on: boolean): void => native?.setCamera(on);
|
|
344
354
|
export const switchCamera = (): void => native?.switchCamera();
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Whether this build can share the screen in a call: Android with the
|
|
358
|
+
* LiveKit media engine. iOS shares through a broadcast extension, which
|
|
359
|
+
* comes in a later release; it can already show other people's screens.
|
|
360
|
+
*/
|
|
361
|
+
export const screenShareSupported = (): boolean => native?.screenShareSupported?.() ?? false;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Share the screen. Android asks the user first (the system's "Start
|
|
365
|
+
* recording or casting?" prompt); resolves `false` when they say no or
|
|
366
|
+
* the build cannot share. `snapshot.screenSharing` turns true once the
|
|
367
|
+
* screen is actually going out. Stopping from the system notification
|
|
368
|
+
* ends it the same way.
|
|
369
|
+
*/
|
|
370
|
+
export const startScreenShare = async (): Promise<boolean> =>
|
|
371
|
+
(await native?.startScreenShare?.()) ?? false;
|
|
372
|
+
|
|
373
|
+
export const stopScreenShare = (): void => native?.stopScreenShare?.();
|
|
345
374
|
/** Route call audio to the loudspeaker (`true`) or back to earpiece / headset (`false`). */
|
|
346
375
|
export const setSpeaker = (on: boolean): void => native?.setSpeaker(on);
|
|
347
376
|
|
|
@@ -523,6 +552,12 @@ export interface CallVideoViewProps extends ViewProps {
|
|
|
523
552
|
mirror?: boolean;
|
|
524
553
|
/** default 'cover' */
|
|
525
554
|
fit?: 'cover' | 'contain';
|
|
555
|
+
/**
|
|
556
|
+
* `camera` (default), or `screen`: the participant's shared screen
|
|
557
|
+
* (with `local`, your own). A screen is never mirrored; draw it with
|
|
558
|
+
* `fit="contain"` so nothing is cropped.
|
|
559
|
+
*/
|
|
560
|
+
source?: 'camera' | 'screen';
|
|
526
561
|
/**
|
|
527
562
|
* iOS: this remote picture is the one picture-in-picture floats when
|
|
528
563
|
* the app is left (`setPictureInPictureEnabled`). Mark one at a time.
|
|
@@ -557,7 +592,15 @@ function nativeVideoView(): ComponentType<NativeVideoProps> | null {
|
|
|
557
592
|
export function CallVideoView(props: CallVideoViewProps): ReactElement | null {
|
|
558
593
|
const Native = nativeVideoView();
|
|
559
594
|
if (!Native) {
|
|
560
|
-
const {
|
|
595
|
+
const {
|
|
596
|
+
participantId: _p,
|
|
597
|
+
local: _l,
|
|
598
|
+
mirror: _m,
|
|
599
|
+
fit: _f,
|
|
600
|
+
source: _s,
|
|
601
|
+
pictureInPicture: _pip,
|
|
602
|
+
...rest
|
|
603
|
+
} = props;
|
|
561
604
|
return createElement(View, rest);
|
|
562
605
|
}
|
|
563
606
|
return createElement(Native, props);
|