@poolse/native 3.8.0 → 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 +15 -0
- package/README.md +33 -0
- package/android/src/main/java/dev/poolse/callcore/CallCoreRuntime.kt +8 -0
- package/android/src/main/java/dev/poolse/callcore/Ports.kt +26 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +21 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallHttpClient.kt +3 -0
- package/android/src/main/java/dev/poolse/callcore/android/SnapshotJson.kt +23 -0
- package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +2 -0
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +96 -9
- package/dist/index.cjs +15 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -2
- package/dist/index.d.ts +66 -2
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/ios/Core/CallCoreRuntime.swift +8 -0
- package/ios/Core/CallHttpClient.swift +11 -1
- package/ios/Core/Ports.swift +25 -1
- package/ios/Core/SnapshotEncoding.swift +17 -1
- package/ios/Module/PoolseCallsModule.swift +2 -0
- package/ios/Platform/CallCore.swift +16 -1
- package/ios/Platform/LiveKitMediaPort.swift +103 -14
- package/package.json +1 -1
- package/src/index.ts +78 -1
|
@@ -32,6 +32,9 @@ protocol MediaEvents: AnyObject {
|
|
|
32
32
|
/// Our own link to the SFU (`good` | `poor` | `lost` | `unknown`), and
|
|
33
33
|
/// whether incoming video is paused to keep the audio going.
|
|
34
34
|
func onNetwork(quality: String, videoPaused: Bool)
|
|
35
|
+
/// Whether the server lets us publish (false: recording consent not
|
|
36
|
+
/// given yet, docs/RECORDING.md §5). Sent on every change.
|
|
37
|
+
func onCanPublish(_ allowed: Bool)
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
/// Step-by-step trace of the audio path, in the device log as
|
|
@@ -93,6 +96,11 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
93
96
|
private var mutedWanted = false
|
|
94
97
|
private var cameraWanted: Bool?
|
|
95
98
|
private var joinedCallId: String?
|
|
99
|
+
/// The server lets us publish. False while it holds our media back for
|
|
100
|
+
/// consent: the mic/camera choices above are kept, nothing is published
|
|
101
|
+
/// (LiveKit unpublished what was live), and they come back as they were
|
|
102
|
+
/// once permission returns.
|
|
103
|
+
private var canPublish = true
|
|
96
104
|
|
|
97
105
|
/// Our own link to the SFU, as last reported.
|
|
98
106
|
private var localQuality = "unknown"
|
|
@@ -267,9 +275,14 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
267
275
|
}
|
|
268
276
|
let muted = await MainActor.run { self.mutedWanted }
|
|
269
277
|
let activeNow = await MainActor.run { self.audioActive }
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
278
|
+
// The token may say listen-only (consent required, not yet given):
|
|
279
|
+
// publish nothing then — the permission update brings it back.
|
|
280
|
+
let allowed = await MainActor.run { self.updateCanPublish(r) }
|
|
281
|
+
pcTrace("connected; publishing mic muted=\(muted) audioActive=\(activeNow) canPublish=\(allowed)")
|
|
282
|
+
if allowed {
|
|
283
|
+
do { try await r.localParticipant.setMicrophone(enabled: !muted) } catch {
|
|
284
|
+
NSLog("[PoolseCalls] microphone publish failed: %@", "\(error)")
|
|
285
|
+
}
|
|
273
286
|
}
|
|
274
287
|
// Connected and publishing: make sure nothing changed the session
|
|
275
288
|
pcTrace("mic published enabled=\(r.localParticipant.isMicrophoneEnabled()) \(pcSessionDescription())")
|
|
@@ -280,7 +293,7 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
280
293
|
self.ensureAudioActivated(r, attempt: 0)
|
|
281
294
|
}
|
|
282
295
|
let camera = await MainActor.run { self.cameraWanted ?? wantsVideo }
|
|
283
|
-
if camera { await self.enableCamera(r, true) }
|
|
296
|
+
if camera && allowed { await self.enableCamera(r, true) }
|
|
284
297
|
await MainActor.run {
|
|
285
298
|
self.reportLocalCamera(r)
|
|
286
299
|
self.refreshVideo()
|
|
@@ -294,7 +307,7 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
294
307
|
connectedRoom = ObjectIdentifier(r)
|
|
295
308
|
if outputWanted != nil { applyRoute() }
|
|
296
309
|
events?.onConnected()
|
|
297
|
-
if !r.
|
|
310
|
+
if !people(r).isEmpty { events?.onRemoteJoined() }
|
|
298
311
|
emit(r)
|
|
299
312
|
refreshVideo()
|
|
300
313
|
}
|
|
@@ -326,6 +339,7 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
326
339
|
private func resetWanted() {
|
|
327
340
|
mutedWanted = false
|
|
328
341
|
cameraWanted = nil
|
|
342
|
+
canPublish = true
|
|
329
343
|
outputWanted = nil
|
|
330
344
|
pauseWork?.cancel()
|
|
331
345
|
resumeWork?.cancel()
|
|
@@ -369,7 +383,7 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
369
383
|
/// broadcast ends, from here or from the status bar), so the snapshot
|
|
370
384
|
/// follows the real state rather than the request.
|
|
371
385
|
func setScreenShare(_ on: Bool) {
|
|
372
|
-
guard let r = room, connectedRoom == ObjectIdentifier(r) else { return }
|
|
386
|
+
guard let r = room, connectedRoom == ObjectIdentifier(r), canPublish || !on else { return }
|
|
373
387
|
if !on, BroadcastManager.shared.isBroadcasting { BroadcastManager.shared.requestStop() }
|
|
374
388
|
Task { [weak self] in
|
|
375
389
|
do { _ = try await r.localParticipant.setScreenShare(enabled: on) } catch {
|
|
@@ -389,13 +403,14 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
389
403
|
|
|
390
404
|
func setMuted(_ muted: Bool) {
|
|
391
405
|
mutedWanted = muted
|
|
392
|
-
|
|
406
|
+
// Not allowed to publish: only remembered, applied on republish.
|
|
407
|
+
guard let r = room, connectedRoom == ObjectIdentifier(r), canPublish else { return }
|
|
393
408
|
Task { _ = try? await r.localParticipant.setMicrophone(enabled: !muted) }
|
|
394
409
|
}
|
|
395
410
|
|
|
396
411
|
func setCamera(_ on: Bool) {
|
|
397
412
|
cameraWanted = on
|
|
398
|
-
guard let r = room, connectedRoom == ObjectIdentifier(r) else { return }
|
|
413
|
+
guard let r = room, connectedRoom == ObjectIdentifier(r), canPublish else { return }
|
|
399
414
|
Task { [weak self] in
|
|
400
415
|
await self?.enableCamera(r, on)
|
|
401
416
|
await MainActor.run {
|
|
@@ -406,6 +421,55 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
406
421
|
}
|
|
407
422
|
}
|
|
408
423
|
|
|
424
|
+
// MARK: - publish permission (recording consent)
|
|
425
|
+
|
|
426
|
+
/// Reads the local participant's permission; reports a change. Returns it.
|
|
427
|
+
@discardableResult
|
|
428
|
+
private func updateCanPublish(_ r: Room) -> Bool {
|
|
429
|
+
guard room === r else { return canPublish }
|
|
430
|
+
let now = r.localParticipant.permissions.canPublish
|
|
431
|
+
if now != canPublish {
|
|
432
|
+
canPublish = now
|
|
433
|
+
pcTrace("canPublish=\(now)")
|
|
434
|
+
events?.onCanPublish(now)
|
|
435
|
+
}
|
|
436
|
+
return now
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/// The server changed what we may do. Revoked: LiveKit has unpublished
|
|
440
|
+
/// our tracks itself — nothing to do but say so. Back: publish the mic
|
|
441
|
+
/// and camera the way the user last had them.
|
|
442
|
+
fileprivate func permissionsChanged(_ r: Room) {
|
|
443
|
+
guard room === r, connectedRoom == ObjectIdentifier(r) else { return }
|
|
444
|
+
let was = canPublish
|
|
445
|
+
if updateCanPublish(r) && !was { republish() }
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/// Mic and camera as the user last had them — after consent (the app
|
|
449
|
+
/// calls this from its consent prompt; the permission update does it
|
|
450
|
+
/// too). A no-op while the server still says listen-only.
|
|
451
|
+
func republish() {
|
|
452
|
+
guard let r = room, connectedRoom == ObjectIdentifier(r), updateCanPublish(r) else { return }
|
|
453
|
+
let muted = mutedWanted
|
|
454
|
+
let camera = cameraWanted ?? (media == "video")
|
|
455
|
+
pcTrace("republish muted=\(muted) camera=\(camera)")
|
|
456
|
+
Task { [weak self] in
|
|
457
|
+
if r.localParticipant.isMicrophoneEnabled() != !muted {
|
|
458
|
+
do { try await r.localParticipant.setMicrophone(enabled: !muted) } catch {
|
|
459
|
+
NSLog("[PoolseCalls] microphone republish failed: %@", "\(error)")
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
guard let self = self else { return }
|
|
463
|
+
let cameraLive = await MainActor.run { self.room === r && self.localCameraTrack(r) != nil }
|
|
464
|
+
if camera && !cameraLive { await self.enableCamera(r, true) }
|
|
465
|
+
await MainActor.run {
|
|
466
|
+
guard self.room === r else { return }
|
|
467
|
+
self.reportLocalCamera(r)
|
|
468
|
+
self.refreshVideo()
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
409
473
|
func switchCamera() {
|
|
410
474
|
guard let r = room, let track = localCameraTrack(r), let capturer = track.capturer as? CameraCapturer else { return }
|
|
411
475
|
Task { [weak self] in
|
|
@@ -640,7 +704,7 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
640
704
|
guard let r = room else { return nil }
|
|
641
705
|
if local { return localCameraTrack(r) }
|
|
642
706
|
guard let id = participantId,
|
|
643
|
-
let p = r.
|
|
707
|
+
let p = people(r).first(where: { $0.identity?.stringValue == id }) else { return nil }
|
|
644
708
|
return remoteCamera(p)
|
|
645
709
|
}
|
|
646
710
|
|
|
@@ -662,7 +726,7 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
662
726
|
return pub.track as? VideoTrack
|
|
663
727
|
}
|
|
664
728
|
guard let id = participantId,
|
|
665
|
-
let p = r.
|
|
729
|
+
let p = people(r).first(where: { $0.identity?.stringValue == id }) else { return nil }
|
|
666
730
|
return remoteScreen(p)
|
|
667
731
|
}
|
|
668
732
|
|
|
@@ -698,7 +762,8 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
698
762
|
case .disconnected:
|
|
699
763
|
events?.onLost()
|
|
700
764
|
case .participantJoined:
|
|
701
|
-
|
|
765
|
+
// The transcript assistant or the recorder joining is nobody answering.
|
|
766
|
+
if !people(r).isEmpty { events?.onRemoteJoined() }
|
|
702
767
|
emit(r)
|
|
703
768
|
refreshVideo()
|
|
704
769
|
case .tracksChanged:
|
|
@@ -712,6 +777,8 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
712
777
|
case .quality:
|
|
713
778
|
qualityChanged(r)
|
|
714
779
|
emit(r)
|
|
780
|
+
case .permissions:
|
|
781
|
+
permissionsChanged(r)
|
|
715
782
|
}
|
|
716
783
|
}
|
|
717
784
|
|
|
@@ -765,7 +832,7 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
765
832
|
}
|
|
766
833
|
|
|
767
834
|
private func hasRemoteVideo(_ r: Room) -> Bool {
|
|
768
|
-
r.
|
|
835
|
+
people(r).contains { p in p.trackPublications.values.contains { $0.source == .camera } }
|
|
769
836
|
}
|
|
770
837
|
|
|
771
838
|
private func setVideoPaused(_ r: Room, _ paused: Bool) {
|
|
@@ -793,9 +860,27 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
793
860
|
events?.onNetwork(quality: localQuality, videoPaused: videoPaused)
|
|
794
861
|
}
|
|
795
862
|
|
|
863
|
+
/// The remote PEOPLE: poolse's transcript assistant and LiveKit Egress's
|
|
864
|
+
/// recorder are in the room but are not someone in the call — never in
|
|
865
|
+
/// the roster, the count that ends a call left alone, or a video tile.
|
|
866
|
+
/// Phone (SIP) participants are people.
|
|
867
|
+
private func people(_ r: Room) -> [RemoteParticipant] {
|
|
868
|
+
r.remoteParticipants.values.filter { p in
|
|
869
|
+
!ServiceParticipants.isService(identity: p.identity?.stringValue ?? "", kind: Self.kindName(p.kind))
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/// The kinds `ServiceParticipants` tells apart; nil for the rest.
|
|
874
|
+
static func kindName(_ k: Participant.Kind) -> String? {
|
|
875
|
+
if k == .agent { return "agent" }
|
|
876
|
+
if k == .egress { return "egress" }
|
|
877
|
+
if k == .sip { return "sip" }
|
|
878
|
+
return nil
|
|
879
|
+
}
|
|
880
|
+
|
|
796
881
|
/// The REMOTE roster — the local participant is never included.
|
|
797
882
|
private func emit(_ r: Room) {
|
|
798
|
-
let roster = r.
|
|
883
|
+
let roster = people(r).map { p -> SnapshotParticipant in
|
|
799
884
|
let identity = p.identity?.stringValue ?? ""
|
|
800
885
|
return SnapshotParticipant(
|
|
801
886
|
userId: identity,
|
|
@@ -822,7 +907,7 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
822
907
|
|
|
823
908
|
/// LiveKit's delegate → main-thread room events for the port.
|
|
824
909
|
final class RoomObserver: NSObject, RoomDelegate, @unchecked Sendable {
|
|
825
|
-
enum Kind { case connected, reconnecting, reconnected, disconnected, participantJoined, tracksChanged, rosterChanged, quality }
|
|
910
|
+
enum Kind { case connected, reconnecting, reconnected, disconnected, participantJoined, tracksChanged, rosterChanged, quality, permissions }
|
|
826
911
|
|
|
827
912
|
private weak var port: LiveKitMediaPort?
|
|
828
913
|
private weak var room: Room?
|
|
@@ -855,4 +940,8 @@ final class RoomObserver: NSObject, RoomDelegate, @unchecked Sendable {
|
|
|
855
940
|
func room(_ room: Room, participant: Participant, didUpdateMetadata metadata: String?) { send(room, .rosterChanged) }
|
|
856
941
|
func room(_ room: Room, participant: Participant, didUpdateAttributes attributes: [String: String]) { send(room, .rosterChanged) }
|
|
857
942
|
func room(_ room: Room, participant: Participant, didUpdateConnectionQuality quality: ConnectionQuality) { send(room, .quality) }
|
|
943
|
+
// Only ever the local participant's (LiveKit's own LocalParticipant sends it).
|
|
944
|
+
func room(_ room: Room, participant: Participant, didUpdatePermissions permissions: ParticipantPermissions) {
|
|
945
|
+
if participant is LocalParticipant { send(room, .permissions) }
|
|
946
|
+
}
|
|
858
947
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poolse/native",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
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
|
@@ -38,7 +38,12 @@ export interface Snapshot {
|
|
|
38
38
|
| 'cancelled'
|
|
39
39
|
| 'connection_lost'
|
|
40
40
|
| 'failed';
|
|
41
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* REMOTE people only; `userId` is the LiveKit identity. poolse's
|
|
43
|
+
* transcript assistant (`poolse:…`, kind agent) and the recorder
|
|
44
|
+
* (LiveKit Egress, `EG_…`) are never listed — nor counted when the core
|
|
45
|
+
* ends a call left alone. Phone (SIP) participants are listed.
|
|
46
|
+
*/
|
|
42
47
|
participants: Array<{
|
|
43
48
|
userId: string;
|
|
44
49
|
externalId: string;
|
|
@@ -108,6 +113,50 @@ export interface Snapshot {
|
|
|
108
113
|
* server's `name`. Absent before 3.8.
|
|
109
114
|
*/
|
|
110
115
|
workspaceName?: string | null;
|
|
116
|
+
/**
|
|
117
|
+
* Whether the server lets you publish. `false` while recording consent
|
|
118
|
+
* is required and you have not accepted (docs/RECORDING.md §5): you
|
|
119
|
+
* still hear and see the call, but nothing of yours goes out. Your
|
|
120
|
+
* `mutedSelf` / camera choices are kept and come back as they were once
|
|
121
|
+
* it turns `true` again (the core republishes by itself; call
|
|
122
|
+
* `republish()` from ConsentPrompt's `onAccepted` too). Absent before 3.9.
|
|
123
|
+
*/
|
|
124
|
+
canPublish?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* The call's recording state as the server last told this core (on
|
|
127
|
+
* answer / join / place and each reconnect) — enough to show the
|
|
128
|
+
* indicator at once. Live changes arrive on the conversation socket
|
|
129
|
+
* (`recording:*`). null: not known (a server without recording).
|
|
130
|
+
* Absent before 3.9.
|
|
131
|
+
*/
|
|
132
|
+
recording?: CallRecordingState | null;
|
|
133
|
+
/** The live transcript's state, the same way (`transcript:*` on the socket). Absent before 3.9. */
|
|
134
|
+
transcription?: CallTranscriptionState | null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The CallSummary's `recording` object, as the server sent it (docs/CALL_CONTRACT.md §4.2). */
|
|
138
|
+
export interface CallRecordingState {
|
|
139
|
+
/** This server can record (LiveKit Egress). */
|
|
140
|
+
available: boolean;
|
|
141
|
+
active: boolean;
|
|
142
|
+
id: string | null;
|
|
143
|
+
mode: 'video' | 'audio' | null;
|
|
144
|
+
started_at: string | null;
|
|
145
|
+
started_by_user_id: string | null;
|
|
146
|
+
auto: boolean;
|
|
147
|
+
/** You may not publish until you accept. */
|
|
148
|
+
consent_required: boolean;
|
|
149
|
+
/** poolse user ids. */
|
|
150
|
+
consent?: { accepted: string[]; declined: string[] };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The CallSummary's `transcription` object, as the server sent it. */
|
|
154
|
+
export interface CallTranscriptionState {
|
|
155
|
+
available: boolean;
|
|
156
|
+
active: boolean;
|
|
157
|
+
id: string | null;
|
|
158
|
+
status: 'live' | 'stopped' | 'ready' | null;
|
|
159
|
+
language: string | null;
|
|
111
160
|
}
|
|
112
161
|
|
|
113
162
|
/** `good` covers good and excellent; `unknown` until the SFU has measured. */
|
|
@@ -321,6 +370,7 @@ interface PoolseCallsNative {
|
|
|
321
370
|
stopScreenShare?(): void;
|
|
322
371
|
setSpeaker(on: boolean): void;
|
|
323
372
|
setAudioOutput?(id: string): void;
|
|
373
|
+
republish?(): void;
|
|
324
374
|
callControl?(): Promise<{
|
|
325
375
|
callId: string;
|
|
326
376
|
controlToken: string;
|
|
@@ -621,6 +671,33 @@ export function setAudioOutput(id: string): void {
|
|
|
621
671
|
else native?.setSpeaker(id === 'speaker'); // an older native build
|
|
622
672
|
}
|
|
623
673
|
|
|
674
|
+
/**
|
|
675
|
+
* Recording consent accepted (ConsentPrompt's `onAccepted`): publish the
|
|
676
|
+
* mic and camera again as the user last had them. The core also does it
|
|
677
|
+
* by itself once the server lets this participant publish; calling it
|
|
678
|
+
* early, or twice, is harmless — nothing goes out while
|
|
679
|
+
* `snapshot.canPublish` is false.
|
|
680
|
+
*/
|
|
681
|
+
export const republish = (): void => native?.republish?.();
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* `snapshot.canPublish` changed (and once at subscribe time with the
|
|
685
|
+
* current value, while a call is up). `true` when no call is up or the
|
|
686
|
+
* native build predates it.
|
|
687
|
+
*/
|
|
688
|
+
export function onCanPublishChange(cb: (canPublish: boolean) => void): Unsubscribe {
|
|
689
|
+
let last: boolean | null = null;
|
|
690
|
+
const check = (snapshot: Snapshot | null): void => {
|
|
691
|
+
const now = snapshot?.canPublish ?? true;
|
|
692
|
+
if (now === last) return;
|
|
693
|
+
const first = last === null;
|
|
694
|
+
last = now;
|
|
695
|
+
if (!first || snapshot) cb(now);
|
|
696
|
+
};
|
|
697
|
+
check(getCallState());
|
|
698
|
+
return onCallState(check);
|
|
699
|
+
}
|
|
700
|
+
|
|
624
701
|
/**
|
|
625
702
|
* Socket forwarding for an open app: a `call:ring_ended` seen on the
|
|
626
703
|
* socket. Idempotent with the push path — the core dedupes.
|