@poolse/native 3.7.1 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/README.md +94 -1
- package/android/src/main/java/dev/poolse/callcore/CallCoreRuntime.kt +8 -0
- package/android/src/main/java/dev/poolse/callcore/CallServers.kt +72 -0
- package/android/src/main/java/dev/poolse/callcore/Ports.kt +34 -0
- package/android/src/main/java/dev/poolse/callcore/RoutedHttpPort.kt +74 -0
- package/android/src/main/java/dev/poolse/callcore/android/AndroidRingSurface.kt +3 -3
- package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +131 -14
- package/android/src/main/java/dev/poolse/callcore/android/CallHttpClient.kt +3 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallMessagingService.kt +4 -0
- package/android/src/main/java/dev/poolse/callcore/android/IncomingCallActivity.kt +1 -1
- package/android/src/main/java/dev/poolse/callcore/android/MessageActionWorker.kt +35 -12
- package/android/src/main/java/dev/poolse/callcore/android/MessageNotifications.kt +142 -48
- package/android/src/main/java/dev/poolse/callcore/android/MissedCallNotification.kt +8 -0
- package/android/src/main/java/dev/poolse/callcore/android/PoolseIncomingCall.kt +16 -0
- package/android/src/main/java/dev/poolse/callcore/android/RingBundle.kt +6 -0
- package/android/src/main/java/dev/poolse/callcore/android/ServerRegistry.kt +107 -0
- package/android/src/main/java/dev/poolse/callcore/android/SnapshotJson.kt +23 -0
- package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +58 -7
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +96 -9
- package/dist/index.cjs +83 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +156 -9
- package/dist/index.d.ts +156 -9
- package/dist/index.js +77 -25
- package/dist/index.js.map +1 -1
- package/ios/Core/CallCoreRuntime.swift +8 -0
- package/ios/Core/CallHttpClient.swift +11 -1
- package/ios/Core/CallServers.swift +89 -0
- package/ios/Core/Ports.swift +35 -2
- package/ios/Core/RoutedHttpPort.swift +83 -0
- package/ios/Core/SnapshotEncoding.swift +17 -1
- package/ios/Module/PoolseCallsModule.swift +50 -8
- package/ios/Platform/CallCore.swift +132 -12
- package/ios/Platform/CallKitController.swift +4 -1
- package/ios/Platform/LiveKitMediaPort.swift +103 -14
- package/ios/Platform/MessageNotifications.swift +76 -23
- package/ios/Platform/ServerRegistry.swift +90 -0
- package/ios/Platform/VoipPush.swift +5 -1
- package/package.json +1 -1
- package/src/index.ts +265 -31
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
package dev.poolse.callcore.android
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import dev.poolse.callcore.CallServer
|
|
5
|
+
import dev.poolse.callcore.CallServers
|
|
6
|
+
import org.json.JSONArray
|
|
7
|
+
import org.json.JSONObject
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The signed-in servers, persisted — so a ring or a notification action
|
|
11
|
+
* that wakes a killed app (no JS) knows where each workspace's API
|
|
12
|
+
* lives. No secrets in it: ids, URLs, tenant ids and names.
|
|
13
|
+
*
|
|
14
|
+
* Upgrading from a single-server build: no list yet, so the server
|
|
15
|
+
* `configure` persisted becomes `default`.
|
|
16
|
+
*/
|
|
17
|
+
object ServerRegistry {
|
|
18
|
+
private const val PREFS = "dev.poolse.callcore"
|
|
19
|
+
private const val KEY = "servers"
|
|
20
|
+
|
|
21
|
+
@Volatile private var loaded: CallServers? = null
|
|
22
|
+
|
|
23
|
+
/** The current list. Any thread. */
|
|
24
|
+
fun servers(context: Context): CallServers = loaded ?: synchronized(this) { loaded ?: load(context) }
|
|
25
|
+
|
|
26
|
+
fun upsert(context: Context, server: CallServer) = mutate(context) { it.upsert(server) }
|
|
27
|
+
|
|
28
|
+
fun remove(context: Context, id: String) = mutate(context) { it.remove(id) }
|
|
29
|
+
|
|
30
|
+
/** The base URL of [serverId] (null = the default server); "" when unknown. */
|
|
31
|
+
fun baseUrl(context: Context, serverId: String?): String {
|
|
32
|
+
val s = servers(context)
|
|
33
|
+
s.get(serverId)?.let { return it.apiBaseUrl }
|
|
34
|
+
// A single-server app that never named its server: whatever it has.
|
|
35
|
+
if (serverId == null && s.all.size == 1) return s.all[0].apiBaseUrl
|
|
36
|
+
return ""
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The server a push of [tenantId] belongs to (see [CallServers.resolve]). */
|
|
40
|
+
fun resolve(context: Context, tenantId: String?): CallServer? =
|
|
41
|
+
servers(context).resolve(tenantId?.ifBlank { null })
|
|
42
|
+
|
|
43
|
+
private fun mutate(context: Context, change: (CallServers) -> CallServers) = synchronized(this) {
|
|
44
|
+
val next = change(loaded ?: load(context))
|
|
45
|
+
loaded = next
|
|
46
|
+
val list = JSONArray()
|
|
47
|
+
for (s in next.all) list.put(s.toJson())
|
|
48
|
+
prefs(context).edit().putString(KEY, list.toString()).apply()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private fun load(context: Context): CallServers {
|
|
52
|
+
val p = prefs(context)
|
|
53
|
+
val raw = p.getString(KEY, null)
|
|
54
|
+
val s = if (raw != null) {
|
|
55
|
+
val list = runCatching { JSONArray(raw) }.getOrDefault(JSONArray())
|
|
56
|
+
CallServers((0 until list.length()).mapNotNull { list.optJSONObject(it)?.toServer() })
|
|
57
|
+
} else {
|
|
58
|
+
// Migrate: the one server a single-server build configured.
|
|
59
|
+
val legacy = p.getString("apiBaseUrl", null)?.trimEnd('/')?.ifEmpty { null }
|
|
60
|
+
?: return CallServers() // nothing yet — not cached: configure may be about to run
|
|
61
|
+
CallServers(listOf(CallServer(CallServers.DEFAULT_ID, legacy))).also { migrated ->
|
|
62
|
+
val list = JSONArray().put(migrated.all[0].toJson())
|
|
63
|
+
p.edit().putString(KEY, list.toString()).apply()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
loaded = s
|
|
67
|
+
return s
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private fun prefs(context: Context) =
|
|
71
|
+
context.applicationContext.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
|
72
|
+
|
|
73
|
+
private fun CallServer.toJson(): JSONObject = JSONObject()
|
|
74
|
+
.put("id", id)
|
|
75
|
+
.put("apiBaseUrl", apiBaseUrl)
|
|
76
|
+
.apply {
|
|
77
|
+
tenantId?.let { put("tenantId", it) }
|
|
78
|
+
name?.let { put("name", it) }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private fun JSONObject.toServer(): CallServer? {
|
|
82
|
+
val id = optString("id").ifBlank { null } ?: return null
|
|
83
|
+
val url = optString("apiBaseUrl").ifBlank { null } ?: return null
|
|
84
|
+
return CallServer(id, url, optString("tenantId").ifBlank { null }, optString("name").ifBlank { null })
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* "Ana · Acme" for a ring surface: [base] (the conversation or caller)
|
|
89
|
+
* with the ring's workspace — only while several servers are signed in.
|
|
90
|
+
*/
|
|
91
|
+
fun ringTitle(context: Context, ring: dev.poolse.callcore.RingContext, base: String?): String? =
|
|
92
|
+
CallServers.title(base, servers(context).workspaceLabel(ring.serverId, ring.workspaceName))
|
|
93
|
+
|
|
94
|
+
/** A server from the bridge's `addServer` map; null when it lacks an id or URL. */
|
|
95
|
+
fun fromMap(map: Map<String, Any?>): CallServer? {
|
|
96
|
+
val id = (map["id"] as? String)?.ifBlank { null } ?: return null
|
|
97
|
+
val url = (map["apiBaseUrl"] as? String)?.trimEnd('/')?.ifBlank { null } ?: return null
|
|
98
|
+
return CallServer(id, url, (map["tenantId"] as? String)?.ifBlank { null }, (map["name"] as? String)?.ifBlank { null })
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
fun toMap(server: CallServer): Map<String, Any?> = buildMap {
|
|
102
|
+
put("id", server.id)
|
|
103
|
+
put("apiBaseUrl", server.apiBaseUrl)
|
|
104
|
+
server.tenantId?.let { put("tenantId", it) }
|
|
105
|
+
server.name?.let { put("name", it) }
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -3,6 +3,8 @@ package dev.poolse.callcore.android
|
|
|
3
3
|
import dev.poolse.callcore.Direction
|
|
4
4
|
import dev.poolse.callcore.MachineState
|
|
5
5
|
import dev.poolse.callcore.Phase
|
|
6
|
+
import org.json.JSONArray
|
|
7
|
+
import org.json.JSONObject
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* The one place a [MachineState] becomes the contract's `Snapshot`
|
|
@@ -32,6 +34,11 @@ internal fun MachineState.toSnapshot(
|
|
|
32
34
|
videoPaused: Boolean = false,
|
|
33
35
|
/** We are sharing our screen. */
|
|
34
36
|
screenSharing: Boolean = false,
|
|
37
|
+
/** False while the server holds our media back (recording consent not given yet). */
|
|
38
|
+
canPublish: Boolean = true,
|
|
39
|
+
/** The CallSummary's `recording` / `transcription` objects, JSON text (null: not known). */
|
|
40
|
+
recording: String? = null,
|
|
41
|
+
transcription: String? = null,
|
|
35
42
|
): Map<String, Any?>? {
|
|
36
43
|
if (phase == Phase.IDLE) return null
|
|
37
44
|
return buildMap {
|
|
@@ -42,6 +49,11 @@ internal fun MachineState.toSnapshot(
|
|
|
42
49
|
put("screenSharing", screenSharing)
|
|
43
50
|
put("audioOutputs", audioOutputs)
|
|
44
51
|
put("audioOutputId", audioOutputId)
|
|
52
|
+
// false: listen-only until the server lets go (docs/RECORDING.md §5).
|
|
53
|
+
put("canPublish", canPublish)
|
|
54
|
+
// The capture state as of joining; null when not known.
|
|
55
|
+
put("recording", jsonMap(recording))
|
|
56
|
+
put("transcription", jsonMap(transcription))
|
|
45
57
|
// Optional in the contract: present only while a camera is published.
|
|
46
58
|
if (cameraFacing != null) put("cameraFacing", cameraFacing)
|
|
47
59
|
// The call waiting beside this one: null when none.
|
|
@@ -83,6 +95,17 @@ private fun MachineState.snapshotCore(
|
|
|
83
95
|
)
|
|
84
96
|
}
|
|
85
97
|
|
|
98
|
+
/** JSON object text → plain maps/lists for the bridge; null when absent or not an object. */
|
|
99
|
+
private fun jsonMap(text: String?): Map<String, Any?>? =
|
|
100
|
+
text?.let { runCatching { plain(JSONObject(it)) as Map<String, Any?> }.getOrNull() }
|
|
101
|
+
|
|
102
|
+
private fun plain(v: Any?): Any? = when (v) {
|
|
103
|
+
is JSONObject -> v.keys().asSequence().associateWith { plain(v.opt(it)) }
|
|
104
|
+
is JSONArray -> (0 until v.length()).map { plain(v.opt(it)) }
|
|
105
|
+
JSONObject.NULL -> null
|
|
106
|
+
else -> v
|
|
107
|
+
}
|
|
108
|
+
|
|
86
109
|
private val Phase.wire: String
|
|
87
110
|
get() = when (this) {
|
|
88
111
|
Phase.IDLE -> "idle"
|
|
@@ -12,6 +12,7 @@ import android.util.Log
|
|
|
12
12
|
import dev.poolse.callcore.android.CallCore
|
|
13
13
|
import dev.poolse.callcore.android.MessageNotifications
|
|
14
14
|
import dev.poolse.callcore.android.MissedCallNotification
|
|
15
|
+
import dev.poolse.callcore.android.ServerRegistry
|
|
15
16
|
import expo.modules.kotlin.Promise
|
|
16
17
|
import expo.modules.kotlin.modules.Module
|
|
17
18
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
@@ -97,15 +98,47 @@ class PoolseCallsModule : Module() {
|
|
|
97
98
|
null
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
// Several workspaces: each server the app is signed in to. Persisted,
|
|
102
|
+
// so a ring or a notification action with no JS finds its server.
|
|
103
|
+
AsyncFunction("addServer") { server: Map<String, Any?> ->
|
|
104
|
+
val ctx = context ?: return@AsyncFunction null
|
|
105
|
+
val entry = ServerRegistry.fromMap(server) ?: return@AsyncFunction null
|
|
106
|
+
CallCore.ensureConfigured(ctx)
|
|
107
|
+
ServerRegistry.upsert(ctx, entry)
|
|
108
|
+
CallCore.getOrNull(ctx)
|
|
109
|
+
null
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Signed out of one workspace: forget it and take its notifications
|
|
113
|
+
// down. A call in progress on it carries on to its end.
|
|
114
|
+
AsyncFunction("removeServer") { id: String ->
|
|
115
|
+
val ctx = context ?: return@AsyncFunction null
|
|
116
|
+
MessageNotifications.removeServer(ctx, id)
|
|
117
|
+
ServerRegistry.remove(ctx, id)
|
|
118
|
+
null
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
Function("listServers") {
|
|
122
|
+
context?.let { ctx -> ServerRegistry.servers(ctx).all.map(ServerRegistry::toMap) } ?: emptyList<Map<String, Any?>>()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// The server a push / notification of `tenantId` belongs to — the
|
|
126
|
+
// same rule the native side routes rings and actions by.
|
|
127
|
+
Function("serverForTenant") { tenantId: String? ->
|
|
128
|
+
context?.let { ServerRegistry.resolve(it, tenantId)?.id }
|
|
129
|
+
}
|
|
130
|
+
|
|
100
131
|
Function("getCallState") {
|
|
101
132
|
mapOf("snapshot" to (CallCore.peek() ?: context?.let(CallCore::getOrNull))?.snapshot())
|
|
102
133
|
}
|
|
103
134
|
|
|
104
|
-
AsyncFunction("place") { conversationId: String, media: String, sessionToken: String ->
|
|
105
|
-
core()?.place(conversationId, media, sessionToken)
|
|
135
|
+
AsyncFunction("place") { conversationId: String, media: String, sessionToken: String, serverId: String? ->
|
|
136
|
+
core()?.place(conversationId, media, sessionToken, serverId)
|
|
137
|
+
null
|
|
106
138
|
}
|
|
107
|
-
AsyncFunction("join") { callId: String, conversationId: String?, sessionToken: String ->
|
|
108
|
-
core()?.join(callId, conversationId, sessionToken)
|
|
139
|
+
AsyncFunction("join") { callId: String, conversationId: String?, sessionToken: String, serverId: String? ->
|
|
140
|
+
core()?.join(callId, conversationId, sessionToken, serverId)
|
|
141
|
+
null
|
|
109
142
|
}
|
|
110
143
|
Function("answer") { core()?.answer() }
|
|
111
144
|
Function("decline") { core()?.decline() }
|
|
@@ -154,10 +187,22 @@ class PoolseCallsModule : Module() {
|
|
|
154
187
|
Function("switchCamera") { core()?.switchCamera() }
|
|
155
188
|
Function("setSpeaker") { on: Boolean -> core()?.setSpeaker(on) }
|
|
156
189
|
Function("setAudioOutput") { id: String -> core()?.setAudioOutput(id) }
|
|
190
|
+
// Recording consent accepted: mic and camera back as they were.
|
|
191
|
+
Function("republish") { core()?.republish() }
|
|
157
192
|
|
|
158
193
|
// What authorizes acting on the call itself (ringing people in).
|
|
159
194
|
AsyncFunction("callControl") {
|
|
160
|
-
core
|
|
195
|
+
val core = core() ?: return@AsyncFunction null
|
|
196
|
+
core.control?.let { (callId, token) ->
|
|
197
|
+
// Where the call runs: ringing people in goes to that server.
|
|
198
|
+
val serverId = core.currentServerId
|
|
199
|
+
mapOf(
|
|
200
|
+
"callId" to callId,
|
|
201
|
+
"controlToken" to token,
|
|
202
|
+
"serverId" to serverId,
|
|
203
|
+
"apiBaseUrl" to context?.let { ServerRegistry.baseUrl(it, serverId) }?.ifEmpty { null },
|
|
204
|
+
)
|
|
205
|
+
}
|
|
161
206
|
}
|
|
162
207
|
|
|
163
208
|
// Socket forwarding (open app): idempotent with the FCM path.
|
|
@@ -176,9 +221,10 @@ class PoolseCallsModule : Module() {
|
|
|
176
221
|
|
|
177
222
|
// The chat on screen: its messages are not notified, and opening it
|
|
178
223
|
// clears what was already shown for it.
|
|
179
|
-
Function("setActiveConversation") { conversationId: String? ->
|
|
224
|
+
Function("setActiveConversation") { conversationId: String?, serverId: String? ->
|
|
225
|
+
MessageNotifications.activeServerId = serverId
|
|
180
226
|
MessageNotifications.activeConversationId = conversationId
|
|
181
|
-
if (conversationId != null) context?.let { MessageNotifications.clear(it, conversationId) }
|
|
227
|
+
if (conversationId != null) context?.let { MessageNotifications.clear(it, conversationId, serverId) }
|
|
182
228
|
}
|
|
183
229
|
|
|
184
230
|
// Reply / Mark as read done from a notification while JS was not
|
|
@@ -243,7 +289,11 @@ class PoolseCallsModule : Module() {
|
|
|
243
289
|
val conversationId = intent.getStringExtra(MissedCallNotification.EXTRA_CONVERSATION_ID) ?: return null
|
|
244
290
|
val callId = intent.getStringExtra(MissedCallNotification.EXTRA_CALL_ID)
|
|
245
291
|
val media = intent.getStringExtra(MissedCallNotification.EXTRA_MEDIA) ?: "audio"
|
|
292
|
+
// Null on a notification posted before servers: the default one.
|
|
293
|
+
val serverId = intent.getStringExtra(MissedCallNotification.EXTRA_SERVER_ID)
|
|
294
|
+
?: context?.let { ServerRegistry.servers(it).get(null)?.id }
|
|
246
295
|
for (key in listOf(
|
|
296
|
+
MissedCallNotification.EXTRA_SERVER_ID,
|
|
247
297
|
MissedCallNotification.EXTRA_ACTION,
|
|
248
298
|
MissedCallNotification.EXTRA_CONVERSATION_ID,
|
|
249
299
|
MissedCallNotification.EXTRA_CALL_ID,
|
|
@@ -255,6 +305,7 @@ class PoolseCallsModule : Module() {
|
|
|
255
305
|
"conversationId" to conversationId,
|
|
256
306
|
"callId" to callId,
|
|
257
307
|
"media" to media,
|
|
308
|
+
"serverId" to serverId,
|
|
258
309
|
)
|
|
259
310
|
}
|
|
260
311
|
|
|
@@ -9,6 +9,7 @@ import androidx.core.content.ContextCompat
|
|
|
9
9
|
import com.twilio.audioswitch.AudioDevice
|
|
10
10
|
import dev.poolse.callcore.CallSessionBundle
|
|
11
11
|
import dev.poolse.callcore.MediaPort
|
|
12
|
+
import dev.poolse.callcore.ServiceParticipants
|
|
12
13
|
import dev.poolse.callcore.android.AudioOutput
|
|
13
14
|
import dev.poolse.callcore.android.CallVideoSource
|
|
14
15
|
import dev.poolse.callcore.android.CallVideoSurface
|
|
@@ -24,6 +25,8 @@ import io.livekit.android.events.collect
|
|
|
24
25
|
import io.livekit.android.room.Room
|
|
25
26
|
import io.livekit.android.room.participant.ConnectionQuality
|
|
26
27
|
import io.livekit.android.room.participant.Participant
|
|
28
|
+
import io.livekit.android.room.participant.ParticipantPermission
|
|
29
|
+
import io.livekit.android.room.participant.RemoteParticipant
|
|
27
30
|
import io.livekit.android.room.track.CameraPosition
|
|
28
31
|
import io.livekit.android.room.track.LocalVideoTrack
|
|
29
32
|
import io.livekit.android.room.track.RemoteTrackPublication
|
|
@@ -88,6 +91,14 @@ class LiveKitMediaPort(
|
|
|
88
91
|
private var cameraWanted: Boolean? = null
|
|
89
92
|
private var joinedCallId: String? = null
|
|
90
93
|
|
|
94
|
+
/**
|
|
95
|
+
* The server lets us publish. False while it holds our media back for
|
|
96
|
+
* consent (docs/RECORDING.md §5): the choices above are kept, nothing
|
|
97
|
+
* is published (LiveKit unpublished what was live), and they come back
|
|
98
|
+
* as they were once permission returns.
|
|
99
|
+
*/
|
|
100
|
+
private var canPublish = true
|
|
101
|
+
|
|
91
102
|
/** Our own link to the SFU, as last reported. */
|
|
92
103
|
private var localQuality = "unknown"
|
|
93
104
|
|
|
@@ -140,10 +151,15 @@ class LiveKitMediaPort(
|
|
|
140
151
|
}
|
|
141
152
|
}.isSuccess
|
|
142
153
|
if (!connected || room !== newRoom) return@launch
|
|
154
|
+
// The token may say listen-only (consent required, not yet given):
|
|
155
|
+
// publish nothing then — the permission update brings it back.
|
|
156
|
+
val allowed = updateCanPublish(newRoom)
|
|
143
157
|
// Publishing failures must not fail the call: audio-only is a call.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
158
|
+
if (allowed) {
|
|
159
|
+
runCatching { newRoom.localParticipant.setMicrophoneEnabled(!mutedWanted) }
|
|
160
|
+
.onFailure { Log.w(TAG, "microphone publish failed", it) }
|
|
161
|
+
}
|
|
162
|
+
if (allowed && (cameraWanted ?: wantsVideo)) enableCamera(newRoom, true)
|
|
147
163
|
reportLocalCamera(newRoom)
|
|
148
164
|
refreshVideo()
|
|
149
165
|
}
|
|
@@ -177,6 +193,7 @@ class LiveKitMediaPort(
|
|
|
177
193
|
private fun resetWanted() {
|
|
178
194
|
mutedWanted = false
|
|
179
195
|
cameraWanted = null
|
|
196
|
+
canPublish = true
|
|
180
197
|
outputWanted = null
|
|
181
198
|
pauseJob?.cancel()
|
|
182
199
|
resumeJob?.cancel()
|
|
@@ -216,12 +233,15 @@ class LiveKitMediaPort(
|
|
|
216
233
|
|
|
217
234
|
override fun setMuted(muted: Boolean) {
|
|
218
235
|
mutedWanted = muted
|
|
236
|
+
// Not allowed to publish: only remembered, applied on republish.
|
|
237
|
+
if (!canPublish) return
|
|
219
238
|
val r = room ?: return
|
|
220
239
|
scope.launch { runCatching { r.localParticipant.setMicrophoneEnabled(!muted) } }
|
|
221
240
|
}
|
|
222
241
|
|
|
223
242
|
override fun setCamera(on: Boolean) {
|
|
224
243
|
cameraWanted = on
|
|
244
|
+
if (!canPublish) return
|
|
225
245
|
val r = room ?: return
|
|
226
246
|
scope.launch {
|
|
227
247
|
enableCamera(r, on)
|
|
@@ -239,6 +259,7 @@ class LiveKitMediaPort(
|
|
|
239
259
|
*/
|
|
240
260
|
override fun setScreenShare(on: Boolean, permission: Intent?) {
|
|
241
261
|
val r = room ?: return
|
|
262
|
+
if (on && !canPublish) return
|
|
242
263
|
if (on && permission == null) return
|
|
243
264
|
scope.launch {
|
|
244
265
|
runCatching { r.localParticipant.setScreenShareEnabled(on, if (on) permission else null) }
|
|
@@ -249,6 +270,42 @@ class LiveKitMediaPort(
|
|
|
249
270
|
}
|
|
250
271
|
}
|
|
251
272
|
|
|
273
|
+
// ── publish permission (recording consent) ──────────────────────────
|
|
274
|
+
|
|
275
|
+
/** Reads the local participant's permission; reports a change. Returns it. */
|
|
276
|
+
private fun updateCanPublish(r: Room): Boolean {
|
|
277
|
+
if (room !== r) return canPublish
|
|
278
|
+
val perms: ParticipantPermission? = r.localParticipant.permissions
|
|
279
|
+
val now = perms?.canPublish ?: true
|
|
280
|
+
if (now != canPublish) {
|
|
281
|
+
canPublish = now
|
|
282
|
+
Log.i(TAG, "canPublish=$now")
|
|
283
|
+
events.onCanPublish(now)
|
|
284
|
+
}
|
|
285
|
+
return now
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Mic and camera as the user last had them — after consent (the app
|
|
290
|
+
* calls this from its consent prompt; the permission update does it
|
|
291
|
+
* too). A no-op while the server still says listen-only.
|
|
292
|
+
*/
|
|
293
|
+
override fun republish() {
|
|
294
|
+
val r = room ?: return
|
|
295
|
+
if (r.state != Room.State.CONNECTED || !updateCanPublish(r)) return
|
|
296
|
+
val camera = cameraWanted ?: (media == "video")
|
|
297
|
+
scope.launch {
|
|
298
|
+
if (r.localParticipant.isMicrophoneEnabled() == mutedWanted) {
|
|
299
|
+
runCatching { r.localParticipant.setMicrophoneEnabled(!mutedWanted) }
|
|
300
|
+
.onFailure { Log.w(TAG, "microphone republish failed", it) }
|
|
301
|
+
}
|
|
302
|
+
if (camera && localCameraTrack(r) == null) enableCamera(r, true)
|
|
303
|
+
if (room !== r) return@launch
|
|
304
|
+
reportLocalCamera(r)
|
|
305
|
+
refreshVideo()
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
252
309
|
/** Front ↔ back on the published camera track. */
|
|
253
310
|
override fun switchCamera() {
|
|
254
311
|
val r = room ?: return
|
|
@@ -289,7 +346,7 @@ class LiveKitMediaPort(
|
|
|
289
346
|
internal fun cameraTrack(participantId: String?, local: Boolean): VideoTrack? {
|
|
290
347
|
val r = room ?: return null
|
|
291
348
|
if (local) return localCameraTrack(r)
|
|
292
|
-
val p = r.
|
|
349
|
+
val p = people(r).firstOrNull { it.identity?.value == participantId } ?: return null
|
|
293
350
|
return remoteCamera(p)
|
|
294
351
|
}
|
|
295
352
|
|
|
@@ -309,7 +366,7 @@ class LiveKitMediaPort(
|
|
|
309
366
|
internal fun screenTrack(participantId: String?, local: Boolean): VideoTrack? {
|
|
310
367
|
val r = room ?: return null
|
|
311
368
|
if (local) return localScreenTrack(r)
|
|
312
|
-
val p = r.
|
|
369
|
+
val p = people(r).firstOrNull { it.identity?.value == participantId } ?: return null
|
|
313
370
|
return remoteScreen(p)
|
|
314
371
|
}
|
|
315
372
|
|
|
@@ -471,7 +528,7 @@ class LiveKitMediaPort(
|
|
|
471
528
|
events.onConnected()
|
|
472
529
|
// Somebody may already be in (a late join, or a callee who
|
|
473
530
|
// answered before our media came up): they will not "connect".
|
|
474
|
-
if (room.
|
|
531
|
+
if (people(room).isNotEmpty()) events.onRemoteJoined()
|
|
475
532
|
emit(room)
|
|
476
533
|
refreshVideo()
|
|
477
534
|
}
|
|
@@ -485,7 +542,19 @@ class LiveKitMediaPort(
|
|
|
485
542
|
is RoomEvent.Disconnected -> {
|
|
486
543
|
if (event.reason != DisconnectReason.CLIENT_INITIATED) events.onLost()
|
|
487
544
|
}
|
|
488
|
-
|
|
545
|
+
// The transcript assistant or the recorder joining is nobody answering.
|
|
546
|
+
is RoomEvent.ParticipantConnected -> {
|
|
547
|
+
if (!isService(event.participant)) events.onRemoteJoined()
|
|
548
|
+
emit(room)
|
|
549
|
+
refreshVideo()
|
|
550
|
+
}
|
|
551
|
+
// Only ever ours: the server turned publishing off (consent) or back on.
|
|
552
|
+
is RoomEvent.ParticipantPermissionsChanged -> {
|
|
553
|
+
if (event.participant === room.localParticipant) {
|
|
554
|
+
val was = canPublish
|
|
555
|
+
if (updateCanPublish(room) && !was) republish()
|
|
556
|
+
}
|
|
557
|
+
}
|
|
489
558
|
// Anything that can make a camera appear, vanish or freeze:
|
|
490
559
|
// update the roster's cameraOn, the local camera state, and
|
|
491
560
|
// rebind every video view.
|
|
@@ -518,10 +587,28 @@ class LiveKitMediaPort(
|
|
|
518
587
|
}
|
|
519
588
|
}
|
|
520
589
|
|
|
590
|
+
/**
|
|
591
|
+
* The remote PEOPLE: poolse's transcript assistant and LiveKit Egress's
|
|
592
|
+
* recorder are in the room but are not someone in the call — never in
|
|
593
|
+
* the roster, the count that ends a call left alone, or a video tile.
|
|
594
|
+
* Phone (SIP) participants are people.
|
|
595
|
+
*/
|
|
596
|
+
private fun people(r: Room): List<RemoteParticipant> = r.remoteParticipants.values.filterNot(::isService)
|
|
597
|
+
|
|
598
|
+
private fun isService(p: Participant): Boolean {
|
|
599
|
+
val kind = when (p.kind) {
|
|
600
|
+
Participant.Kind.AGENT -> "agent"
|
|
601
|
+
Participant.Kind.EGRESS -> "egress"
|
|
602
|
+
Participant.Kind.SIP -> "sip"
|
|
603
|
+
else -> null
|
|
604
|
+
}
|
|
605
|
+
return ServiceParticipants.isService(p.identity?.value ?: "", kind)
|
|
606
|
+
}
|
|
607
|
+
|
|
521
608
|
/** The REMOTE roster — the local participant is never included. */
|
|
522
609
|
private fun emit(room: Room) {
|
|
523
610
|
events.onParticipants(
|
|
524
|
-
room.
|
|
611
|
+
people(room).map {
|
|
525
612
|
val identity = it.identity?.value ?: ""
|
|
526
613
|
MediaParticipant(
|
|
527
614
|
identity = identity,
|
|
@@ -578,7 +665,7 @@ class LiveKitMediaPort(
|
|
|
578
665
|
}
|
|
579
666
|
|
|
580
667
|
private fun hasRemoteVideo(r: Room) =
|
|
581
|
-
r.
|
|
668
|
+
people(r).any { it.getTrackPublication(Track.Source.CAMERA) != null }
|
|
582
669
|
|
|
583
670
|
private fun setVideoPaused(r: Room, paused: Boolean) {
|
|
584
671
|
Log.i(TAG, "incoming video ${if (paused) "paused" else "resumed"} quality=$localQuality")
|
package/dist/index.cjs
CHANGED
|
@@ -5,12 +5,49 @@ var reactNative = require('react-native');
|
|
|
5
5
|
var expoModulesCore = require('expo-modules-core');
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
8
|
+
var DEFAULT_SERVER_ID = "default";
|
|
8
9
|
var native = expoModulesCore.requireOptionalNativeModule("PoolseCalls");
|
|
9
10
|
var nativeCallsAvailable = native != null;
|
|
10
11
|
var apiOrigin = null;
|
|
11
|
-
async function configure(
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
async function configure(apiBaseUrlOrOptions, options) {
|
|
13
|
+
if (typeof apiBaseUrlOrOptions !== "string") {
|
|
14
|
+
await native?.configure("", apiBaseUrlOrOptions ?? null);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
apiOrigin = apiBaseUrlOrOptions.replace(/\/+$/, "");
|
|
18
|
+
await native?.configure(apiBaseUrlOrOptions, options ?? null);
|
|
19
|
+
}
|
|
20
|
+
var SERVER_ID = /^[A-Za-z0-9._:-]{1,64}$/;
|
|
21
|
+
async function addServer(server) {
|
|
22
|
+
if (!SERVER_ID.test(server.id))
|
|
23
|
+
throw new Error(`addServer: invalid id ${JSON.stringify(server.id)}.`);
|
|
24
|
+
if (!/^https?:\/\/[^\s]+$/.test(server.apiBaseUrl))
|
|
25
|
+
throw new Error("addServer: apiBaseUrl must be http(s).");
|
|
26
|
+
const entry = { id: server.id, apiBaseUrl: server.apiBaseUrl.replace(/\/+$/, "") };
|
|
27
|
+
if (server.tenantId) entry.tenantId = server.tenantId;
|
|
28
|
+
if (server.name) entry.name = server.name;
|
|
29
|
+
if (server.id === DEFAULT_SERVER_ID) apiOrigin = entry.apiBaseUrl;
|
|
30
|
+
await native?.addServer?.(entry);
|
|
31
|
+
}
|
|
32
|
+
async function removeServer(id) {
|
|
33
|
+
if (id === DEFAULT_SERVER_ID) apiOrigin = null;
|
|
34
|
+
await native?.removeServer?.(id);
|
|
35
|
+
}
|
|
36
|
+
function listServers() {
|
|
37
|
+
return native?.listServers?.() ?? [];
|
|
38
|
+
}
|
|
39
|
+
function serverOfNotification(data) {
|
|
40
|
+
const tenant = data && typeof data["tenant_id"] === "string" ? data["tenant_id"] : null;
|
|
41
|
+
if (native?.serverForTenant) return native.serverForTenant(tenant);
|
|
42
|
+
return apiOrigin ? DEFAULT_SERVER_ID : null;
|
|
43
|
+
}
|
|
44
|
+
function originOf(serverId) {
|
|
45
|
+
if (!serverId || serverId === DEFAULT_SERVER_ID) {
|
|
46
|
+
if (apiOrigin) return apiOrigin;
|
|
47
|
+
}
|
|
48
|
+
const id = serverId ?? DEFAULT_SERVER_ID;
|
|
49
|
+
const server = listServers().find((s) => s.id === id);
|
|
50
|
+
return server?.apiBaseUrl ?? null;
|
|
14
51
|
}
|
|
15
52
|
function getCallState() {
|
|
16
53
|
return native?.getCallState().snapshot ?? null;
|
|
@@ -21,39 +58,38 @@ function onCallState(cb) {
|
|
|
21
58
|
return () => sub.remove();
|
|
22
59
|
}
|
|
23
60
|
function place(conversationId, options) {
|
|
24
|
-
return native?.place(conversationId, options.media, options.sessionToken) ?? Promise.resolve();
|
|
61
|
+
return native?.place(conversationId, options.media, options.sessionToken, options.serverId ?? null) ?? Promise.resolve();
|
|
25
62
|
}
|
|
26
|
-
function join(callId, conversationId, sessionToken) {
|
|
27
|
-
return native?.join(callId, conversationId, sessionToken) ?? Promise.resolve();
|
|
63
|
+
function join(callId, conversationId, sessionToken, serverId) {
|
|
64
|
+
return native?.join(callId, conversationId, sessionToken, serverId ?? null) ?? Promise.resolve();
|
|
28
65
|
}
|
|
29
66
|
async function startRoom(conversationId, options) {
|
|
30
67
|
if (!native) throw new Error("The native call core is not in this build.");
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
);
|
|
68
|
+
const origin = originOf(options.serverId);
|
|
69
|
+
if (!origin) throw new Error("Call configure() (or addServer) before startRoom().");
|
|
70
|
+
const res = await fetch(`${origin}/v1/conversations/${encodeURIComponent(conversationId)}/room`, {
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: {
|
|
73
|
+
authorization: `Bearer ${options.sessionToken}`,
|
|
74
|
+
"content-type": "application/json"
|
|
75
|
+
},
|
|
76
|
+
body: JSON.stringify({ media: options.media })
|
|
77
|
+
});
|
|
43
78
|
const body = await res.json().catch(() => null);
|
|
44
79
|
const callId = body?.call?.id;
|
|
45
80
|
if (!res.ok || !callId) {
|
|
46
81
|
throw new Error(body?.error?.message ?? `Couldn't start the room (${res.status}).`);
|
|
47
82
|
}
|
|
48
|
-
await native.join(callId, conversationId, options.sessionToken);
|
|
83
|
+
await native.join(callId, conversationId, options.sessionToken, options.serverId ?? null);
|
|
49
84
|
return { callId, created: body?.created === true };
|
|
50
85
|
}
|
|
51
86
|
async function ringIntoCall(people) {
|
|
52
87
|
if (!native?.callControl) throw new Error("This build cannot ring people into a call.");
|
|
53
|
-
if (!apiOrigin) throw new Error("Call configure() before ringIntoCall().");
|
|
54
88
|
const control = await native.callControl();
|
|
55
89
|
if (!control) throw new Error("There is no call in progress.");
|
|
56
|
-
const
|
|
90
|
+
const origin = control.apiBaseUrl || originOf(control.serverId);
|
|
91
|
+
if (!origin) throw new Error("Call configure() before ringIntoCall().");
|
|
92
|
+
const res = await fetch(`${origin}/v1/calls/${encodeURIComponent(control.callId)}/ring`, {
|
|
57
93
|
method: "POST",
|
|
58
94
|
headers: {
|
|
59
95
|
authorization: `Bearer ${control.controlToken}`,
|
|
@@ -84,6 +120,19 @@ function setAudioOutput(id) {
|
|
|
84
120
|
if (native?.setAudioOutput) native.setAudioOutput(id);
|
|
85
121
|
else native?.setSpeaker(id === "speaker");
|
|
86
122
|
}
|
|
123
|
+
var republish = () => native?.republish?.();
|
|
124
|
+
function onCanPublishChange(cb) {
|
|
125
|
+
let last = null;
|
|
126
|
+
const check = (snapshot) => {
|
|
127
|
+
const now = snapshot?.canPublish ?? true;
|
|
128
|
+
if (now === last) return;
|
|
129
|
+
const first = last === null;
|
|
130
|
+
last = now;
|
|
131
|
+
if (!first || snapshot) cb(now);
|
|
132
|
+
};
|
|
133
|
+
check(getCallState());
|
|
134
|
+
return onCallState(check);
|
|
135
|
+
}
|
|
87
136
|
var onRingEnded = (callId, reason) => native?.onRingEnded(callId, reason);
|
|
88
137
|
var onCallFinished = (callId, reason) => native?.onCallFinished(callId, reason ?? null);
|
|
89
138
|
var canUseFullScreenIntent = () => native?.canUseFullScreenIntent() ?? true;
|
|
@@ -103,13 +152,16 @@ function onCallAction(cb) {
|
|
|
103
152
|
return () => sub.remove();
|
|
104
153
|
}
|
|
105
154
|
var activeConversation = null;
|
|
106
|
-
|
|
155
|
+
var activeServer = null;
|
|
156
|
+
function setActiveConversation(conversationId, serverId) {
|
|
107
157
|
activeConversation = conversationId;
|
|
108
|
-
|
|
158
|
+
activeServer = conversationId ? serverId ?? null : null;
|
|
159
|
+
native?.setActiveConversation?.(conversationId, activeServer);
|
|
109
160
|
}
|
|
110
161
|
function shouldPresentMessage(data) {
|
|
111
162
|
if (!data || data["type"] !== "message") return true;
|
|
112
|
-
|
|
163
|
+
if (data["conversation_id"] !== activeConversation) return true;
|
|
164
|
+
return activeServer != null && serverOfNotification(data) !== activeServer;
|
|
113
165
|
}
|
|
114
166
|
function conversationOfNotification(data) {
|
|
115
167
|
if (!data) return null;
|
|
@@ -191,6 +243,8 @@ function CallVideoView(props) {
|
|
|
191
243
|
}
|
|
192
244
|
|
|
193
245
|
exports.CallVideoView = CallVideoView;
|
|
246
|
+
exports.DEFAULT_SERVER_ID = DEFAULT_SERVER_ID;
|
|
247
|
+
exports.addServer = addServer;
|
|
194
248
|
exports.answer = answer;
|
|
195
249
|
exports.answerWaiting = answerWaiting;
|
|
196
250
|
exports.canUseFullScreenIntent = canUseFullScreenIntent;
|
|
@@ -203,10 +257,12 @@ exports.getVoipToken = getVoipToken;
|
|
|
203
257
|
exports.hangUp = hangUp;
|
|
204
258
|
exports.isInPictureInPicture = isInPictureInPicture;
|
|
205
259
|
exports.join = join;
|
|
260
|
+
exports.listServers = listServers;
|
|
206
261
|
exports.nativeCallsAvailable = nativeCallsAvailable;
|
|
207
262
|
exports.onCallAction = onCallAction;
|
|
208
263
|
exports.onCallFinished = onCallFinished;
|
|
209
264
|
exports.onCallState = onCallState;
|
|
265
|
+
exports.onCanPublishChange = onCanPublishChange;
|
|
210
266
|
exports.onNotificationAction = onNotificationAction;
|
|
211
267
|
exports.onNotificationReply = onNotificationReply;
|
|
212
268
|
exports.onPictureInPicture = onPictureInPicture;
|
|
@@ -215,8 +271,11 @@ exports.onVoipToken = onVoipToken;
|
|
|
215
271
|
exports.openFullScreenIntentSettings = openFullScreenIntentSettings;
|
|
216
272
|
exports.pictureInPictureSupported = pictureInPictureSupported;
|
|
217
273
|
exports.place = place;
|
|
274
|
+
exports.removeServer = removeServer;
|
|
275
|
+
exports.republish = republish;
|
|
218
276
|
exports.ringIntoCall = ringIntoCall;
|
|
219
277
|
exports.screenShareSupported = screenShareSupported;
|
|
278
|
+
exports.serverOfNotification = serverOfNotification;
|
|
220
279
|
exports.setActiveConversation = setActiveConversation;
|
|
221
280
|
exports.setAudioOutput = setAudioOutput;
|
|
222
281
|
exports.setCamera = setCamera;
|