@poolse/native 3.10.0 → 3.10.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 +34 -0
- package/README.md +39 -0
- package/android/src/main/java/dev/poolse/callcore/CallCoreRuntime.kt +83 -6
- package/android/src/main/java/dev/poolse/callcore/Ports.kt +7 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +71 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallHttpClient.kt +7 -1
- package/android/src/main/java/dev/poolse/callcore/android/CallVideo.kt +18 -0
- package/android/src/main/java/dev/poolse/callcore/android/SnapshotJson.kt +13 -0
- package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +33 -1
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +48 -1
- package/android/src/test/java/dev/poolse/callcore/android/CallHttpClientTest.kt +15 -0
- package/dist/index.cjs +90 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +131 -1
- package/dist/index.d.ts +131 -1
- package/dist/index.js +86 -1
- package/dist/index.js.map +1 -1
- package/ios/Core/CallCoreRuntime.swift +79 -5
- package/ios/Core/CallHttpClient.swift +9 -2
- package/ios/Core/Ports.swift +9 -1
- package/ios/Core/SnapshotEncoding.swift +21 -1
- package/ios/Module/PoolseCallsModule.swift +23 -1
- package/ios/Platform/CallCore.swift +48 -0
- package/ios/Platform/LiveKitMediaPort.swift +62 -1
- package/package.json +1 -1
- package/src/index.ts +223 -0
|
@@ -67,6 +67,9 @@ public final class CallCoreRuntime {
|
|
|
67
67
|
private var resolved: [String] = []
|
|
68
68
|
/// The call whose media has had someone else in it (for `onRemoteCount`).
|
|
69
69
|
private var remoteSeenFor: String?
|
|
70
|
+
/// While `moveToRoom` connects: the room's bundle it came from, to go
|
|
71
|
+
/// back to if the new room cannot be joined.
|
|
72
|
+
private var movingFrom: CallSessionBundle?
|
|
70
73
|
|
|
71
74
|
private var queue: [() -> Void] = []
|
|
72
75
|
private var draining = false
|
|
@@ -130,6 +133,16 @@ public final class CallCoreRuntime {
|
|
|
130
133
|
/// The call waiting beside the current one, with its caller's names. Runtime thread only.
|
|
131
134
|
public var waitingRing: RingContext? { state.waiting == nil ? nil : waitingRingCtx }
|
|
132
135
|
|
|
136
|
+
/// The session bundle in use, nil before the server accepted. Runtime thread only.
|
|
137
|
+
public var currentBundle: CallSessionBundle? { bundle }
|
|
138
|
+
|
|
139
|
+
/// The breakout room the media is in (MEETINGS.md §5); nil in the
|
|
140
|
+
/// call's main room. Runtime thread only.
|
|
141
|
+
public var breakout: (roomId: String, name: String?)? {
|
|
142
|
+
guard let b = bundle, let id = b.breakoutRoomId else { return nil }
|
|
143
|
+
return (id, b.breakoutName)
|
|
144
|
+
}
|
|
145
|
+
|
|
133
146
|
/// True if `callId` was already resolved here — its ring must never surface again.
|
|
134
147
|
public func isResolved(_ callId: String) -> Bool { resolved.contains(callId) }
|
|
135
148
|
|
|
@@ -210,8 +223,54 @@ public final class CallCoreRuntime {
|
|
|
210
223
|
/// Caller-side: the bridge resolved every ring from `ring_states`.
|
|
211
224
|
public func allRingsResolved(_ outcome: String) { post { [self] in dispatch(.allRingsResolved(outcome: outcome)) } }
|
|
212
225
|
|
|
213
|
-
public func onMediaConnected() {
|
|
214
|
-
|
|
226
|
+
public func onMediaConnected() {
|
|
227
|
+
post { [self] in
|
|
228
|
+
movingFrom = nil
|
|
229
|
+
dispatch(.mediaConnected)
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
public func onMediaFailed() {
|
|
234
|
+
post { [self] in
|
|
235
|
+
// The room `moveToRoom` went to would not have us: back to the one
|
|
236
|
+
// it came from. The call itself never noticed.
|
|
237
|
+
if let back = movingFrom, state.phase == .active || state.phase == .reconnecting {
|
|
238
|
+
movingFrom = nil
|
|
239
|
+
bundle = back
|
|
240
|
+
media.join(bundle: back)
|
|
241
|
+
sink.emit(state: state)
|
|
242
|
+
return
|
|
243
|
+
}
|
|
244
|
+
dispatch(.mediaFailed)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/// Breakout rooms (MEETINGS.md §5): carry the call on in another
|
|
249
|
+
/// LiveKit room of the SAME call — the bundle of `POST
|
|
250
|
+
/// /breakouts/:room/join`, or of `POST /calls/:id/breakouts/return` to
|
|
251
|
+
/// come back. The machine never sees it: the phase, the system call
|
|
252
|
+
/// (CallKit / Telecom) and the timers stay; only the media swaps rooms,
|
|
253
|
+
/// with mute and camera as they were. If the new room cannot be
|
|
254
|
+
/// joined, the media goes back to the room it came from.
|
|
255
|
+
///
|
|
256
|
+
/// `done(false)`: not now — no live call, or the bundle is another call's.
|
|
257
|
+
public func moveToRoom(_ next: CallSessionBundle, done: ((Bool) -> Void)? = nil) {
|
|
258
|
+
post { [self] in
|
|
259
|
+
guard state.phase == .active || state.phase == .reconnecting,
|
|
260
|
+
let current = bundle, current.callId == next.callId else {
|
|
261
|
+
done?(false)
|
|
262
|
+
return
|
|
263
|
+
}
|
|
264
|
+
if movingFrom == nil { movingFrom = current }
|
|
265
|
+
bundle = next
|
|
266
|
+
// Who was in the last room says nothing about this one.
|
|
267
|
+
remoteSeenFor = nil
|
|
268
|
+
timers.cancel(key: CallCoreRuntime.T_ALONE)
|
|
269
|
+
media.join(bundle: next)
|
|
270
|
+
sink.emit(state: state)
|
|
271
|
+
done?(true)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
215
274
|
public func onMediaLost() { post { [self] in dispatch(.mediaLost) } }
|
|
216
275
|
public func onMediaReconnecting() { post { [self] in dispatch(.mediaReconnecting) } }
|
|
217
276
|
public func onMediaRecovered() { post { [self] in dispatch(.mediaRecovered) } }
|
|
@@ -236,7 +295,9 @@ public final class CallCoreRuntime {
|
|
|
236
295
|
timers.cancel(key: CallCoreRuntime.T_ALONE)
|
|
237
296
|
return
|
|
238
297
|
}
|
|
239
|
-
|
|
298
|
+
// In a breakout room the others are in the call's other rooms.
|
|
299
|
+
guard state.phase == .active, callKind != "room", remoteSeenFor == callId,
|
|
300
|
+
bundle?.breakoutRoomId == nil else { return }
|
|
240
301
|
scheduleAloneProbe(callId, attempt: 0)
|
|
241
302
|
}
|
|
242
303
|
}
|
|
@@ -254,7 +315,7 @@ public final class CallCoreRuntime {
|
|
|
254
315
|
}
|
|
255
316
|
|
|
256
317
|
private func probeAlone(_ callId: String, attempt: Int) {
|
|
257
|
-
guard state.phase == .active, let b = bundle else { return }
|
|
318
|
+
guard state.phase == .active, let b = bundle, b.breakoutRoomId == nil else { return }
|
|
258
319
|
let g = gen
|
|
259
320
|
let last = attempt == CallCoreRuntime.ALONE_PROBES_MS.count - 1
|
|
260
321
|
// A still-live answer carries a fresh bundle; the current one stays
|
|
@@ -311,6 +372,7 @@ public final class CallCoreRuntime {
|
|
|
311
372
|
if isTerminal(next.phase) {
|
|
312
373
|
ring = nil
|
|
313
374
|
bundle = nil
|
|
375
|
+
movingFrom = nil
|
|
314
376
|
sessionToken = nil
|
|
315
377
|
}
|
|
316
378
|
// A waiting call that went away without becoming the current one
|
|
@@ -397,6 +459,7 @@ public final class CallCoreRuntime {
|
|
|
397
459
|
case .callSessionStop:
|
|
398
460
|
session.stop()
|
|
399
461
|
bundle = nil
|
|
462
|
+
movingFrom = nil
|
|
400
463
|
ring = nil
|
|
401
464
|
sessionToken = nil
|
|
402
465
|
|
|
@@ -411,6 +474,7 @@ public final class CallCoreRuntime {
|
|
|
411
474
|
markResolved(before.callId)
|
|
412
475
|
gen += 1
|
|
413
476
|
bundle = nil
|
|
477
|
+
movingFrom = nil
|
|
414
478
|
sessionToken = nil
|
|
415
479
|
ring = waitingRingCtx
|
|
416
480
|
waitingRingCtx = nil
|
|
@@ -452,8 +516,18 @@ public final class CallCoreRuntime {
|
|
|
452
516
|
private func onReconnectResult(_ requestGen: Int, _ result: HttpResult) {
|
|
453
517
|
if requestGen != gen || state.phase != .reconnecting { return }
|
|
454
518
|
switch result {
|
|
455
|
-
case let .ok(
|
|
519
|
+
case let .ok(fresh):
|
|
456
520
|
// Fresh token (and possibly URL): rejoin. MEDIA_CONNECTED returns us to ACTIVE.
|
|
521
|
+
var b = fresh
|
|
522
|
+
// In a breakout room: /reconnect answers with the main room's
|
|
523
|
+
// session — keep the room (its token outlives a network drop) and
|
|
524
|
+
// take the rest.
|
|
525
|
+
if let cur = bundle, let room = cur.breakoutRoomId, b.breakoutRoomId == nil {
|
|
526
|
+
b.livekitUrl = cur.livekitUrl
|
|
527
|
+
b.livekitToken = cur.livekitToken
|
|
528
|
+
b.breakoutRoomId = room
|
|
529
|
+
b.breakoutName = cur.breakoutName
|
|
530
|
+
}
|
|
457
531
|
bundle = b
|
|
458
532
|
media.join(bundle: b)
|
|
459
533
|
case .gone: dispatch(.httpGone)
|
|
@@ -159,12 +159,17 @@ public final class CallHttpClient: HttpPort {
|
|
|
159
159
|
b.livekitToken = try getString(livekit, "token")
|
|
160
160
|
b.controlToken = optString(root, "control_token") ?? current.controlToken
|
|
161
161
|
b.ringing = 0
|
|
162
|
-
// recording / transcription: the current bundle's stand.
|
|
162
|
+
// recording / transcription: the current bundle's stand. A bare
|
|
163
|
+
// refresh is the main room's (servers before breakouts).
|
|
164
|
+
b.breakoutRoomId = nil
|
|
165
|
+
b.breakoutName = nil
|
|
163
166
|
return b
|
|
164
167
|
}
|
|
165
168
|
guard let controlToken = optString(root, "control_token") ?? current?.controlToken else {
|
|
166
169
|
throw ParseError(what: "bundle without control_token")
|
|
167
170
|
}
|
|
171
|
+
// Only a breakout join's bundle names a room; never inherited from `current`.
|
|
172
|
+
let breakout = root["breakout"] as? [String: Any]
|
|
168
173
|
return CallSessionBundle(
|
|
169
174
|
callId: try getString(call, "id"),
|
|
170
175
|
conversationId: try getString(call, "conversation_id"),
|
|
@@ -177,7 +182,9 @@ public final class CallHttpClient: HttpPort {
|
|
|
177
182
|
kind: optString(call, "kind") ?? current?.kind ?? "call",
|
|
178
183
|
ringing: ((call["ring_states"] as? [String: Any]) ?? [:]).values.filter { ($0 as? String) == "ringing" }.count,
|
|
179
184
|
recording: optObjectText(call, "recording") ?? current?.recording,
|
|
180
|
-
transcription: optObjectText(call, "transcription") ?? current?.transcription
|
|
185
|
+
transcription: optObjectText(call, "transcription") ?? current?.transcription,
|
|
186
|
+
breakoutRoomId: breakout.flatMap { optString($0, "room_id") },
|
|
187
|
+
breakoutName: breakout.flatMap { optString($0, "name") }
|
|
181
188
|
)
|
|
182
189
|
}
|
|
183
190
|
|
package/ios/Core/Ports.swift
CHANGED
|
@@ -55,10 +55,16 @@ public struct CallSessionBundle: Equatable {
|
|
|
55
55
|
/// server before them. Text, not a dictionary, to keep the bundle Equatable.
|
|
56
56
|
public var recording: String?
|
|
57
57
|
public var transcription: String?
|
|
58
|
+
/// The breakout room this bundle's `livekit` connects to (MEETINGS.md §5:
|
|
59
|
+
/// `breakout: {room_id, name}` from `POST /breakouts/:room/join`); nil
|
|
60
|
+
/// for the call's main room.
|
|
61
|
+
public var breakoutRoomId: String?
|
|
62
|
+
public var breakoutName: String?
|
|
58
63
|
|
|
59
64
|
public init(callId: String, conversationId: String, conversationName: String?, media: String,
|
|
60
65
|
created: Bool, livekitUrl: String, livekitToken: String, controlToken: String,
|
|
61
|
-
kind: String = "call", ringing: Int = 0, recording: String? = nil, transcription: String? = nil
|
|
66
|
+
kind: String = "call", ringing: Int = 0, recording: String? = nil, transcription: String? = nil,
|
|
67
|
+
breakoutRoomId: String? = nil, breakoutName: String? = nil) {
|
|
62
68
|
self.callId = callId
|
|
63
69
|
self.conversationId = conversationId
|
|
64
70
|
self.conversationName = conversationName
|
|
@@ -71,6 +77,8 @@ public struct CallSessionBundle: Equatable {
|
|
|
71
77
|
self.ringing = ringing
|
|
72
78
|
self.recording = recording
|
|
73
79
|
self.transcription = transcription
|
|
80
|
+
self.breakoutRoomId = breakoutRoomId
|
|
81
|
+
self.breakoutName = breakoutName
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
84
|
|
|
@@ -11,6 +11,10 @@ public struct SnapshotParticipant: Equatable {
|
|
|
11
11
|
public var cameraOn: Bool
|
|
12
12
|
/// True with a published, subscribed, unmuted screen share.
|
|
13
13
|
public var screenSharing: Bool
|
|
14
|
+
/// The shared screen's size in pixels as published (nil while unknown or
|
|
15
|
+
/// not sharing): phones line screen drawings up against it.
|
|
16
|
+
public var screenWidth: Int?
|
|
17
|
+
public var screenHeight: Int?
|
|
14
18
|
/// Their link to the SFU: `good` | `poor` | `lost` (dropped, coming
|
|
15
19
|
/// back — "Reconnecting…") | `unknown`.
|
|
16
20
|
public var connectionQuality: String
|
|
@@ -24,7 +28,8 @@ public struct SnapshotParticipant: Equatable {
|
|
|
24
28
|
|
|
25
29
|
public init(userId: String, externalId: String, speaking: Bool, muted: Bool, cameraOn: Bool,
|
|
26
30
|
connectionQuality: String = "unknown", screenSharing: Bool = false,
|
|
27
|
-
isAgent: Bool = false, agentLabel: String? = nil, agentMode: String? = nil
|
|
31
|
+
isAgent: Bool = false, agentLabel: String? = nil, agentMode: String? = nil,
|
|
32
|
+
screenWidth: Int? = nil, screenHeight: Int? = nil) {
|
|
28
33
|
self.userId = userId
|
|
29
34
|
self.externalId = externalId
|
|
30
35
|
self.speaking = speaking
|
|
@@ -35,6 +40,8 @@ public struct SnapshotParticipant: Equatable {
|
|
|
35
40
|
self.isAgent = isAgent
|
|
36
41
|
self.agentLabel = agentLabel
|
|
37
42
|
self.agentMode = agentMode
|
|
43
|
+
self.screenWidth = screenWidth
|
|
44
|
+
self.screenHeight = screenHeight
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
public var dictionary: [String: Any] {
|
|
@@ -42,6 +49,10 @@ public struct SnapshotParticipant: Equatable {
|
|
|
42
49
|
"userId": userId, "externalId": externalId, "speaking": speaking, "muted": muted, "cameraOn": cameraOn,
|
|
43
50
|
"connectionQuality": connectionQuality, "screenSharing": screenSharing,
|
|
44
51
|
]
|
|
52
|
+
if screenSharing, let w = screenWidth, let h = screenHeight {
|
|
53
|
+
d["screenWidth"] = w
|
|
54
|
+
d["screenHeight"] = h
|
|
55
|
+
}
|
|
45
56
|
if isAgent {
|
|
46
57
|
d["isAgent"] = true
|
|
47
58
|
d["agentLabel"] = agentLabel ?? NSNull()
|
|
@@ -142,6 +153,15 @@ public extension MachineState {
|
|
|
142
153
|
"recording": jsonObject(recording),
|
|
143
154
|
"transcription": jsonObject(transcription),
|
|
144
155
|
]
|
|
156
|
+
// Who shares a screen (the first remote sharer) and its size, for
|
|
157
|
+
// lining up screen drawings (CL4); null when nobody else shares.
|
|
158
|
+
out["screenShare"] = participants.first(where: { $0.screenSharing }).map { p -> Any in
|
|
159
|
+
[
|
|
160
|
+
"userId": p.userId, "externalId": p.externalId,
|
|
161
|
+
"width": p.screenWidth.map { $0 as Any } ?? NSNull(),
|
|
162
|
+
"height": p.screenHeight.map { $0 as Any } ?? NSNull(),
|
|
163
|
+
] as [String: Any]
|
|
164
|
+
} ?? NSNull()
|
|
145
165
|
// The call waiting beside this one: null when none.
|
|
146
166
|
if let w = self.waiting {
|
|
147
167
|
out["waiting"] = [
|
|
@@ -9,7 +9,7 @@ public class PoolseCallsModule: Module {
|
|
|
9
9
|
public func definition() -> ModuleDefinition {
|
|
10
10
|
Name("PoolseCalls")
|
|
11
11
|
|
|
12
|
-
Events("onCallState", "onVoipToken", "onPictureInPicture", "onNotificationAction", "onCallAction")
|
|
12
|
+
Events("onCallState", "onVoipToken", "onPictureInPicture", "onNotificationAction", "onCallAction", "onCallData")
|
|
13
13
|
|
|
14
14
|
// Normally done at launch by PoolseCallsAppDelegateSubscriber; this is
|
|
15
15
|
// the backstop for a host whose AppDelegate does not forward to Expo.
|
|
@@ -37,6 +37,9 @@ public class PoolseCallsModule: Module {
|
|
|
37
37
|
MessageNotifications.actionListener = { [weak self] event in
|
|
38
38
|
self?.sendEvent("onNotificationAction", event)
|
|
39
39
|
}
|
|
40
|
+
CallCore.dataListener = { [weak self] message in
|
|
41
|
+
self?.sendEvent("onCallData", message)
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
|
|
@@ -47,6 +50,7 @@ public class PoolseCallsModule: Module {
|
|
|
47
50
|
CallPictureInPicture.listener = nil
|
|
48
51
|
MessageNotifications.actionListener = nil
|
|
49
52
|
MessageNotifications.callActionListener = nil
|
|
53
|
+
CallCore.dataListener = nil
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
56
|
|
|
@@ -148,6 +152,24 @@ public class PoolseCallsModule: Module {
|
|
|
148
152
|
// Recording consent accepted: mic and camera back as they were.
|
|
149
153
|
Function("republish") { onCore { $0.republish() } }
|
|
150
154
|
|
|
155
|
+
// The call's data channel (CL4, CL6): `data` is UTF-8 text, or bytes
|
|
156
|
+
// as base64 with `options.base64`. Resolves false when not connected,
|
|
157
|
+
// over 14 000 bytes, or refused.
|
|
158
|
+
AsyncFunction("publishData") { (topic: String, data: String, options: [String: Any]?, promise: Promise) in
|
|
159
|
+
let bytes = (options?["base64"] as? Bool == true) ? Data(base64Encoded: data) : data.data(using: .utf8)
|
|
160
|
+
guard let bytes = bytes, let core = CallCore.getOrNull() else { return promise.resolve(false) }
|
|
161
|
+
core.publishData(topic: topic, data: bytes, reliable: options?["reliable"] as? Bool ?? true,
|
|
162
|
+
to: options?["to"] as? [String] ?? []) { ok in promise.resolve(ok) }
|
|
163
|
+
}.runOnQueue(.main)
|
|
164
|
+
|
|
165
|
+
// Breakout rooms (MEETINGS.md §5): the live call's media to another
|
|
166
|
+
// room of the same call, keeping the CallKit call. `session` is the
|
|
167
|
+
// JSON of POST /breakouts/:room/join or /calls/:id/breakouts/return.
|
|
168
|
+
AsyncFunction("moveToRoom") { (session: String, promise: Promise) in
|
|
169
|
+
guard let core = CallCore.getOrNull() else { return promise.resolve(false) }
|
|
170
|
+
core.moveToRoom(payload: session) { ok in promise.resolve(ok) }
|
|
171
|
+
}.runOnQueue(.main)
|
|
172
|
+
|
|
151
173
|
// Picture-in-picture: armed while a video call shows someone; the
|
|
152
174
|
// <CallVideoView pictureInPicture> on screen is what it grows out of.
|
|
153
175
|
Function("setPictureInPictureEnabled") { (on: Bool) in
|
|
@@ -45,6 +45,10 @@ final class CallCore {
|
|
|
45
45
|
/// The bridge's snapshot subscriber; process-level so JS may subscribe before configure.
|
|
46
46
|
static var listener: (([String: Any]?) -> Void)?
|
|
47
47
|
|
|
48
|
+
/// The bridge's data-channel subscriber (CL4, CL6): `{topic, payload
|
|
49
|
+
/// (base64), text (UTF-8 or nil), fromIdentity, fromName}`. Main thread.
|
|
50
|
+
static var dataListener: (([String: Any]) -> Void)?
|
|
51
|
+
|
|
48
52
|
/// Configure and PERSIST (see CallCore.kt). Re-configuring swaps in place:
|
|
49
53
|
/// HTTP and the ringback read the config per use. A non-empty
|
|
50
54
|
/// `apiBaseUrl` is the `default` server; "" sets the options only and
|
|
@@ -422,6 +426,31 @@ final class CallCore {
|
|
|
422
426
|
/// The current call's id and control token (main thread).
|
|
423
427
|
var control: (callId: String, controlToken: String)? { runtime.control }
|
|
424
428
|
|
|
429
|
+
/// Breakout rooms (MEETINGS.md §5): the call's media to the room of
|
|
430
|
+
/// `payload` — the JSON of `POST /breakouts/:room/join` (or of `POST
|
|
431
|
+
/// /calls/:id/breakouts/return`). CallKit keeps the call; see
|
|
432
|
+
/// CallCoreRuntime.moveToRoom. `done(false)`: unparseable, no live
|
|
433
|
+
/// call, or another call's session.
|
|
434
|
+
func moveToRoom(payload: String, done: @escaping (Bool) -> Void) {
|
|
435
|
+
onMain { [self] in
|
|
436
|
+
guard let current = runtime.currentBundle,
|
|
437
|
+
let next = try? CallHttpClient.parseBundle(payload, current: current) else {
|
|
438
|
+
done(false)
|
|
439
|
+
return
|
|
440
|
+
}
|
|
441
|
+
runtime.moveToRoom(next) { [weak self] ok in
|
|
442
|
+
// The last room's people are not in this one.
|
|
443
|
+
if ok { self?.roster = [] }
|
|
444
|
+
done(ok)
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/// A data-channel message to the call's room (CL4, CL6); see LiveKitMediaPort.publishData.
|
|
450
|
+
func publishData(topic: String, data: Data, reliable: Bool, to: [String], done: @escaping (Bool) -> Void) {
|
|
451
|
+
onMain { [self] in mediaPort.publishData(topic: topic, data: data, reliable: reliable, to: to, done: done) }
|
|
452
|
+
}
|
|
453
|
+
|
|
425
454
|
/// A video slot for the native view. Main thread.
|
|
426
455
|
func createVideoSurface(renderMode: VideoView.RenderMode = .auto) -> LiveKitVideoSurface {
|
|
427
456
|
mediaPort.createVideoSurface(renderMode: renderMode)
|
|
@@ -504,6 +533,13 @@ final class CallCore {
|
|
|
504
533
|
out["noiseSuppression"] = mediaPort.noiseSuppression
|
|
505
534
|
out["backgroundBlur"] = mediaPort.backgroundBlur
|
|
506
535
|
out["movedElsewhere"] = movedElsewhere
|
|
536
|
+
// Breakout rooms (MEETINGS.md §5): the room the media is in, nil in the main room.
|
|
537
|
+
if let b = runtime.breakout {
|
|
538
|
+
out["breakout"] = ["roomId": b.roomId, "name": b.name ?? NSNull()] as [String: Any]
|
|
539
|
+
} else {
|
|
540
|
+
out["breakout"] = NSNull()
|
|
541
|
+
}
|
|
542
|
+
out["selfIdentity"] = mediaPort.localIdentity ?? NSNull()
|
|
507
543
|
// Taken over by another of this user's devices: the machine ends it
|
|
508
544
|
// as `left` (CALL_CONTRACT.md §9); the app is told why.
|
|
509
545
|
if movedElsewhere && state.phase == .ended { out["reason"] = "moved" }
|
|
@@ -685,6 +721,15 @@ final class CallCore {
|
|
|
685
721
|
fileprivate func movedAway() {
|
|
686
722
|
runtime.post { [weak self] in self?.movedElsewhere = true }
|
|
687
723
|
}
|
|
724
|
+
fileprivate func data(topic: String, payload: Data, from: String?, name: String?) {
|
|
725
|
+
CallCore.dataListener?([
|
|
726
|
+
"topic": topic,
|
|
727
|
+
"payload": payload.base64EncodedString(),
|
|
728
|
+
"text": String(data: payload, encoding: .utf8) ?? NSNull(),
|
|
729
|
+
"fromIdentity": from ?? NSNull(),
|
|
730
|
+
"fromName": name ?? NSNull(),
|
|
731
|
+
])
|
|
732
|
+
}
|
|
688
733
|
}
|
|
689
734
|
|
|
690
735
|
// MARK: - CallKit actions
|
|
@@ -787,6 +832,9 @@ private final class EventsAdapter: MediaEvents {
|
|
|
787
832
|
func onNetwork(quality: String, videoPaused: Bool) { core?.network(quality: quality, videoPaused: videoPaused) }
|
|
788
833
|
func onCanPublish(_ allowed: Bool) { core?.publishAllowed(allowed) }
|
|
789
834
|
func onMovedElsewhere() { core?.movedAway() }
|
|
835
|
+
func onData(topic: String, payload: Data, fromIdentity: String?, fromName: String?) {
|
|
836
|
+
core?.data(topic: topic, payload: payload, from: fromIdentity, name: fromName)
|
|
837
|
+
}
|
|
790
838
|
}
|
|
791
839
|
|
|
792
840
|
/// Host-facing entry points.
|
|
@@ -38,6 +38,9 @@ protocol MediaEvents: AnyObject {
|
|
|
38
38
|
/// The SFU replaced us with the same user joining from another device
|
|
39
39
|
/// ("move call to this device", CALL_CONTRACT.md §9). Sent just before `onLost`.
|
|
40
40
|
func onMovedElsewhere()
|
|
41
|
+
/// A data-channel message from someone in the room (CL4, CL6): its
|
|
42
|
+
/// topic, the bytes, and who sent it (nil identity: the server).
|
|
43
|
+
func onData(topic: String, payload: Data, fromIdentity: String?, fromName: String?)
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
/// Step-by-step trace of the audio path, in the device log as
|
|
@@ -379,6 +382,45 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
379
382
|
events?.onLocalScreen(false)
|
|
380
383
|
}
|
|
381
384
|
|
|
385
|
+
// MARK: - data channel (CL4, CL6)
|
|
386
|
+
|
|
387
|
+
/// The most one message may carry — the web CallRoom's
|
|
388
|
+
/// CALL_DATA_MAX_BYTES, under LiveKit's ~15 KiB packet.
|
|
389
|
+
static let dataMaxBytes = 14_000
|
|
390
|
+
|
|
391
|
+
/// Our LiveKit identity (the poolse user id) while connected.
|
|
392
|
+
var localIdentity: String? {
|
|
393
|
+
guard let r = room, connectedRoom == ObjectIdentifier(r) else { return nil }
|
|
394
|
+
return r.localParticipant.identity?.stringValue
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/// Send `data` under `topic` to everyone in the room, or to `to` (LiveKit
|
|
398
|
+
/// identities). `reliable: false` for what is stale a moment later (a
|
|
399
|
+
/// moving pointer). `done(false)`: not connected, over the cap, or LiveKit refused.
|
|
400
|
+
func publishData(topic: String, data: Data, reliable: Bool, to: [String], done: @escaping (Bool) -> Void) {
|
|
401
|
+
guard let r = room, connectedRoom == ObjectIdentifier(r), !topic.isEmpty,
|
|
402
|
+
data.count <= Self.dataMaxBytes else {
|
|
403
|
+
done(false)
|
|
404
|
+
return
|
|
405
|
+
}
|
|
406
|
+
let options = DataPublishOptions(destinationIdentities: to.map { Participant.Identity(from: $0) },
|
|
407
|
+
topic: topic, reliable: reliable)
|
|
408
|
+
Task {
|
|
409
|
+
do {
|
|
410
|
+
try await r.localParticipant.publish(data: data, options: options)
|
|
411
|
+
await MainActor.run { done(true) }
|
|
412
|
+
} catch {
|
|
413
|
+
NSLog("[PoolseCalls] data publish on %@ failed: %@", topic, "\(error)")
|
|
414
|
+
await MainActor.run { done(false) }
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
fileprivate func dataReceived(_ r: Room, topic: String, data: Data, from: String?, name: String?) {
|
|
420
|
+
guard room === r, !topic.isEmpty, data.count <= Self.dataMaxBytes else { return }
|
|
421
|
+
events?.onData(topic: topic, payload: data, fromIdentity: from, fromName: name)
|
|
422
|
+
}
|
|
423
|
+
|
|
382
424
|
// MARK: - screen sharing
|
|
383
425
|
|
|
384
426
|
/// Sharing the screen needs the app's broadcast upload extension (the
|
|
@@ -745,6 +787,14 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
745
787
|
return pub.track as? VideoTrack
|
|
746
788
|
}
|
|
747
789
|
|
|
790
|
+
/// The shared screen's size as its publisher announced it (the SFU's
|
|
791
|
+
/// track info); nil while unknown.
|
|
792
|
+
private func screenDimensions(_ p: RemoteParticipant) -> (width: Int, height: Int)? {
|
|
793
|
+
guard let pub = p.trackPublications.values.first(where: { $0.source == .screenShareVideo }),
|
|
794
|
+
let d = pub.dimensions, d.width > 0, d.height > 0 else { return nil }
|
|
795
|
+
return (Int(d.width), Int(d.height))
|
|
796
|
+
}
|
|
797
|
+
|
|
748
798
|
/// `front` | `back` of the published local camera, or nil when none.
|
|
749
799
|
func cameraFacing() -> String? {
|
|
750
800
|
guard let r = room, let track = localCameraTrack(r) else { return nil }
|
|
@@ -956,6 +1006,7 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
956
1006
|
}
|
|
957
1007
|
let roster = people(r).map { p -> SnapshotParticipant in
|
|
958
1008
|
let identity = p.identity?.stringValue ?? ""
|
|
1009
|
+
let screen = remoteScreen(p) != nil ? screenDimensions(p) : nil
|
|
959
1010
|
return SnapshotParticipant(
|
|
960
1011
|
userId: identity,
|
|
961
1012
|
externalId: externalId(p) ?? identity,
|
|
@@ -963,7 +1014,9 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
963
1014
|
muted: !p.isMicrophoneEnabled(),
|
|
964
1015
|
cameraOn: remoteCamera(p) != nil,
|
|
965
1016
|
connectionQuality: Self.wire(p.connectionQuality),
|
|
966
|
-
screenSharing: remoteScreen(p) != nil
|
|
1017
|
+
screenSharing: remoteScreen(p) != nil,
|
|
1018
|
+
screenWidth: screen?.width,
|
|
1019
|
+
screenHeight: screen?.height
|
|
967
1020
|
)
|
|
968
1021
|
}
|
|
969
1022
|
events?.onParticipants(roster + agentRows)
|
|
@@ -1014,6 +1067,14 @@ final class RoomObserver: NSObject, RoomDelegate, @unchecked Sendable {
|
|
|
1014
1067
|
func room(_ room: Room, participant: Participant, didUpdateMetadata metadata: String?) { send(room, .rosterChanged) }
|
|
1015
1068
|
func room(_ room: Room, participant: Participant, didUpdateAttributes attributes: [String: String]) { send(room, .rosterChanged) }
|
|
1016
1069
|
func room(_ room: Room, participant: Participant, didUpdateConnectionQuality quality: ConnectionQuality) { send(room, .quality) }
|
|
1070
|
+
func room(_ room: Room, participant: RemoteParticipant?, didReceiveData data: Data, forTopic topic: String,
|
|
1071
|
+
encryptionType: EncryptionType) {
|
|
1072
|
+
let from = participant?.identity?.stringValue
|
|
1073
|
+
let name = participant?.name
|
|
1074
|
+
DispatchQueue.main.async { [weak self] in
|
|
1075
|
+
self?.port?.dataReceived(room, topic: topic, data: data, from: from, name: name)
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1017
1078
|
// Only ever the local participant's (LiveKit's own LocalParticipant sends it).
|
|
1018
1079
|
func room(_ room: Room, participant: Participant, didUpdatePermissions permissions: ParticipantPermissions) {
|
|
1019
1080
|
if participant is LocalParticipant { send(room, .permissions) }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poolse/native",
|
|
3
|
-
"version": "3.10.
|
|
3
|
+
"version": "3.10.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",
|