@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
|
@@ -115,6 +115,12 @@ public final class CallCoreRuntime {
|
|
|
115
115
|
/// `room` or `call`, once the server's bundle says; nil before. Runtime thread only.
|
|
116
116
|
public var callKind: String? { bundle?.kind }
|
|
117
117
|
|
|
118
|
+
/// The bundle's capture state (`recording`, `transcription` as JSON
|
|
119
|
+
/// text), as of the last answer/join/place/reconnect. Runtime thread only.
|
|
120
|
+
public var capture: (recording: String?, transcription: String?) {
|
|
121
|
+
(bundle?.recording, bundle?.transcription)
|
|
122
|
+
}
|
|
123
|
+
|
|
118
124
|
/// The current call's id and control token — what authorizes acting on
|
|
119
125
|
/// the call itself (ringing more people in). Nil with no session yet.
|
|
120
126
|
public var control: (callId: String, controlToken: String)? {
|
|
@@ -279,6 +285,8 @@ public final class CallCoreRuntime {
|
|
|
279
285
|
public func switchCamera() { post { [self] in media.switchCamera() } }
|
|
280
286
|
public func setSpeaker(_ on: Bool) { post { [self] in media.setSpeaker(on) } }
|
|
281
287
|
public func setAudioOutput(_ id: String) { post { [self] in media.setAudioOutput(id) } }
|
|
288
|
+
/// Consent given: publish the mic/camera again (a no-op until the server allows it).
|
|
289
|
+
public func republish() { post { [self] in media.republish() } }
|
|
282
290
|
|
|
283
291
|
/// Re-emit the current state (the bridge's roster/route changed).
|
|
284
292
|
public func reemit() { post { [self] in if state.phase != .idle { sink.emit(state: state) } } }
|
|
@@ -159,6 +159,7 @@ 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
163
|
return b
|
|
163
164
|
}
|
|
164
165
|
guard let controlToken = optString(root, "control_token") ?? current?.controlToken else {
|
|
@@ -174,7 +175,9 @@ public final class CallHttpClient: HttpPort {
|
|
|
174
175
|
livekitToken: try getString(livekit, "token"),
|
|
175
176
|
controlToken: controlToken,
|
|
176
177
|
kind: optString(call, "kind") ?? current?.kind ?? "call",
|
|
177
|
-
ringing: ((call["ring_states"] as? [String: Any]) ?? [:]).values.filter { ($0 as? String) == "ringing" }.count
|
|
178
|
+
ringing: ((call["ring_states"] as? [String: Any]) ?? [:]).values.filter { ($0 as? String) == "ringing" }.count,
|
|
179
|
+
recording: optObjectText(call, "recording") ?? current?.recording,
|
|
180
|
+
transcription: optObjectText(call, "transcription") ?? current?.transcription
|
|
178
181
|
)
|
|
179
182
|
}
|
|
180
183
|
|
|
@@ -193,6 +196,13 @@ public final class CallHttpClient: HttpPort {
|
|
|
193
196
|
return s
|
|
194
197
|
}
|
|
195
198
|
|
|
199
|
+
/// A JSON object member, re-serialised as text; nil when absent or not an object.
|
|
200
|
+
private static func optObjectText(_ o: [String: Any], _ key: String) -> String? {
|
|
201
|
+
guard let v = o[key] as? [String: Any],
|
|
202
|
+
let data = try? JSONSerialization.data(withJSONObject: v, options: [.sortedKeys]) else { return nil }
|
|
203
|
+
return String(data: data, encoding: .utf8)
|
|
204
|
+
}
|
|
205
|
+
|
|
196
206
|
/// org.json (Android) `getString`: required, non-null; numbers/bools coerce to text.
|
|
197
207
|
private static func getString(_ o: [String: Any], _ key: String) throws -> String {
|
|
198
208
|
guard let v = o[key], !(v is NSNull) else { throw ParseError(what: "missing \(key)") }
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// One API server the app is signed in to — a workspace. Holds no
|
|
4
|
+
/// secrets: the push brings each ring's grant, and JS passes session
|
|
5
|
+
/// tokens per place/join. Twin of CallServers.kt.
|
|
6
|
+
public struct CallServer: Equatable {
|
|
7
|
+
/// The host's own id for it (`addServer({ id })`); `default` is the one `configure(apiBaseUrl)` sets.
|
|
8
|
+
public var id: String
|
|
9
|
+
public var apiBaseUrl: String
|
|
10
|
+
/// The poolse tenant it signs in to: how a push (`tenant_id`) finds its server.
|
|
11
|
+
public var tenantId: String?
|
|
12
|
+
/// The workspace's name, when the push carries none ("Ana · Acme").
|
|
13
|
+
public var name: String?
|
|
14
|
+
|
|
15
|
+
public init(id: String, apiBaseUrl: String, tenantId: String? = nil, name: String? = nil) {
|
|
16
|
+
self.id = id
|
|
17
|
+
self.apiBaseUrl = apiBaseUrl
|
|
18
|
+
self.tenantId = tenantId
|
|
19
|
+
self.name = name
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public init?(dict: [String: Any]) {
|
|
23
|
+
guard let id = dict["id"] as? String, !id.isEmpty,
|
|
24
|
+
let url = dict["apiBaseUrl"] as? String, !url.isEmpty else { return nil }
|
|
25
|
+
self.init(id: id, apiBaseUrl: url,
|
|
26
|
+
tenantId: (dict["tenantId"] as? String).flatMap { $0.isEmpty ? nil : $0 },
|
|
27
|
+
name: (dict["name"] as? String).flatMap { $0.isEmpty ? nil : $0 })
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public var dict: [String: Any] {
|
|
31
|
+
var d: [String: Any] = ["id": id, "apiBaseUrl": apiBaseUrl]
|
|
32
|
+
if let tenantId = tenantId { d["tenantId"] = tenantId }
|
|
33
|
+
if let name = name { d["name"] = name }
|
|
34
|
+
return d
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// The signed-in servers, in the order they were added, and the rules
|
|
39
|
+
/// that route a push to one of them.
|
|
40
|
+
public struct CallServers: Equatable {
|
|
41
|
+
public static let defaultId = "default"
|
|
42
|
+
|
|
43
|
+
public private(set) var all: [CallServer]
|
|
44
|
+
|
|
45
|
+
public init(_ all: [CallServer] = []) { self.all = all }
|
|
46
|
+
|
|
47
|
+
public var isMulti: Bool { all.count > 1 }
|
|
48
|
+
|
|
49
|
+
public func get(_ id: String?) -> CallServer? {
|
|
50
|
+
all.first { $0.id == (id ?? CallServers.defaultId) }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// Adds or replaces (by id), keeping its place in the order.
|
|
54
|
+
public mutating func upsert(_ server: CallServer) {
|
|
55
|
+
if let i = all.firstIndex(where: { $0.id == server.id }) { all[i] = server } else { all.append(server) }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public mutating func remove(_ id: String) { all.removeAll { $0.id == id } }
|
|
59
|
+
|
|
60
|
+
/// The server a push belongs to: the one signed in to its `tenant_id`;
|
|
61
|
+
/// else — an older server's push, or a host that left `tenantId` out —
|
|
62
|
+
/// the only server, the only one without a tenant, the default, the
|
|
63
|
+
/// first. Nil only with no server at all. Never drops a ring: a wrong
|
|
64
|
+
/// guess fails its answer, a dropped one never rings.
|
|
65
|
+
public func resolve(tenantId: String?) -> CallServer? {
|
|
66
|
+
if let t = tenantId, let match = all.first(where: { $0.tenantId == t }) { return match }
|
|
67
|
+
if all.count <= 1 { return all.first }
|
|
68
|
+
let untagged = all.filter { $0.tenantId == nil }
|
|
69
|
+
if untagged.count == 1 { return untagged[0] }
|
|
70
|
+
return get(CallServers.defaultId) ?? untagged.first ?? all.first
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// The workspace a ring / notification is labelled with: the push's
|
|
74
|
+
/// name, else the server's own. Nil while only one server is signed in
|
|
75
|
+
/// — a single-workspace app looks exactly as before.
|
|
76
|
+
public func workspaceLabel(serverId: String?, pushName: String?) -> String? {
|
|
77
|
+
guard isMulti else { return nil }
|
|
78
|
+
if let n = pushName, !n.isEmpty { return n }
|
|
79
|
+
return get(serverId)?.name
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// "Ana · Acme" — `base` with the workspace, when there is one to show
|
|
83
|
+
/// (the workspace alone when the push named nobody).
|
|
84
|
+
public static func title(_ base: String?, workspace: String?) -> String? {
|
|
85
|
+
guard let w = workspace, !w.isEmpty else { return base }
|
|
86
|
+
guard let b = base, !b.isEmpty else { return w }
|
|
87
|
+
return "\(b) · \(w)"
|
|
88
|
+
}
|
|
89
|
+
}
|
package/ios/Core/Ports.swift
CHANGED
|
@@ -50,10 +50,15 @@ public struct CallSessionBundle: Equatable {
|
|
|
50
50
|
public var kind: String
|
|
51
51
|
/// How many people the server says are being rung right now.
|
|
52
52
|
public var ringing: Int
|
|
53
|
+
/// The CallSummary's `recording` / `transcription` objects as JSON text
|
|
54
|
+
/// (docs/RECORDING.md), carried to the snapshot untouched; nil from a
|
|
55
|
+
/// server before them. Text, not a dictionary, to keep the bundle Equatable.
|
|
56
|
+
public var recording: String?
|
|
57
|
+
public var transcription: String?
|
|
53
58
|
|
|
54
59
|
public init(callId: String, conversationId: String, conversationName: String?, media: String,
|
|
55
60
|
created: Bool, livekitUrl: String, livekitToken: String, controlToken: String,
|
|
56
|
-
kind: String = "call", ringing: Int = 0) {
|
|
61
|
+
kind: String = "call", ringing: Int = 0, recording: String? = nil, transcription: String? = nil) {
|
|
57
62
|
self.callId = callId
|
|
58
63
|
self.conversationId = conversationId
|
|
59
64
|
self.conversationName = conversationName
|
|
@@ -64,6 +69,8 @@ public struct CallSessionBundle: Equatable {
|
|
|
64
69
|
self.controlToken = controlToken
|
|
65
70
|
self.kind = kind
|
|
66
71
|
self.ringing = ringing
|
|
72
|
+
self.recording = recording
|
|
73
|
+
self.transcription = transcription
|
|
67
74
|
}
|
|
68
75
|
}
|
|
69
76
|
|
|
@@ -80,11 +87,28 @@ public protocol MediaPort: AnyObject {
|
|
|
80
87
|
func setSpeaker(_ on: Bool)
|
|
81
88
|
/// Play through one specific output — an id from `Snapshot.audioOutputs`.
|
|
82
89
|
func setAudioOutput(_ id: String)
|
|
90
|
+
/// Publish the mic and camera again as the user last had them, once the
|
|
91
|
+
/// server lets this participant publish (consent given, docs/RECORDING.md §5).
|
|
92
|
+
func republish()
|
|
83
93
|
}
|
|
84
94
|
|
|
85
95
|
public extension MediaPort {
|
|
86
96
|
/// Engines without device selection fall back to the speaker toggle.
|
|
87
97
|
func setAudioOutput(_ id: String) { setSpeaker(id == "speaker") }
|
|
98
|
+
func republish() {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/// poolse's own participants in a room — the transcript assistant
|
|
102
|
+
/// (`poolse:assistant:<call>`, kind AGENT) and LiveKit Egress's recorder
|
|
103
|
+
/// (`EG_…`, kind EGRESS). They are not people: never in the roster, never
|
|
104
|
+
/// counted as someone in the call (docs/RECORDING.md §7). SIP (phone)
|
|
105
|
+
/// participants are people and stay.
|
|
106
|
+
public enum ServiceParticipants {
|
|
107
|
+
/// `kind`: LiveKit's participant kind, lowercased (`agent`, `egress`, `sip`, …).
|
|
108
|
+
public static func isService(identity: String, kind: String?) -> Bool {
|
|
109
|
+
if identity.hasPrefix("poolse:") || identity.hasPrefix("EG_") { return true }
|
|
110
|
+
return kind == "agent" || kind == "egress"
|
|
111
|
+
}
|
|
88
112
|
}
|
|
89
113
|
|
|
90
114
|
// MARK: - Ring surface
|
|
@@ -121,9 +145,16 @@ public struct RingContext: Equatable {
|
|
|
121
145
|
public var media: String
|
|
122
146
|
public var grant: String
|
|
123
147
|
public var ringDeadlineEpochMs: Int64
|
|
148
|
+
/// The server (workspace) the ring came from — the host's id from
|
|
149
|
+
/// `addServer`, resolved from the push's `tenant_id`. Its answer and
|
|
150
|
+
/// decline go to that server. nil: the default server.
|
|
151
|
+
public var serverId: String?
|
|
152
|
+
/// The push's `workspace_name`, for "Ana · Acme" when several servers are signed in.
|
|
153
|
+
public var workspaceName: String?
|
|
124
154
|
|
|
125
155
|
public init(callId: String, conversationId: String, conversationName: String?, callerName: String?,
|
|
126
|
-
media: String, grant: String, ringDeadlineEpochMs: Int64
|
|
156
|
+
media: String, grant: String, ringDeadlineEpochMs: Int64,
|
|
157
|
+
serverId: String? = nil, workspaceName: String? = nil) {
|
|
127
158
|
self.callId = callId
|
|
128
159
|
self.conversationId = conversationId
|
|
129
160
|
self.conversationName = conversationName
|
|
@@ -131,6 +162,8 @@ public struct RingContext: Equatable {
|
|
|
131
162
|
self.media = media
|
|
132
163
|
self.grant = grant
|
|
133
164
|
self.ringDeadlineEpochMs = ringDeadlineEpochMs
|
|
165
|
+
self.serverId = serverId
|
|
166
|
+
self.workspaceName = workspaceName
|
|
134
167
|
}
|
|
135
168
|
}
|
|
136
169
|
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// One HttpPort for several API servers (signed in to several
|
|
4
|
+
/// workspaces): each request goes to the server its call belongs to.
|
|
5
|
+
/// Direct port of RoutedHttpPort.kt.
|
|
6
|
+
///
|
|
7
|
+
/// The runtime stays single-server — it only knows call ids. The platform
|
|
8
|
+
/// binds each call to its server as it enters (a ring's `serverId`, a
|
|
9
|
+
/// place/join with the host's server id), and this port looks the call up
|
|
10
|
+
/// per request. A placed call is keyed by its conversation until the
|
|
11
|
+
/// server mints its id; the answer binds that id too. Unbound calls go to
|
|
12
|
+
/// the default server (nil), which is all a single-server app ever has.
|
|
13
|
+
///
|
|
14
|
+
/// Thread-safe: rings are bound from PushKit, requests run on main.
|
|
15
|
+
public final class RoutedHttpPort: HttpPort {
|
|
16
|
+
private static let pending = "pending:"
|
|
17
|
+
private static let maxBound = 64
|
|
18
|
+
|
|
19
|
+
private let portFor: (String?) -> HttpPort
|
|
20
|
+
private let lock = NSLock()
|
|
21
|
+
private var calls: [(callId: String, serverId: String)] = []
|
|
22
|
+
private var places: [String: String] = [:]
|
|
23
|
+
|
|
24
|
+
/// `portFor`: the HTTP port of one server (nil = the default one).
|
|
25
|
+
public init(portFor: @escaping (String?) -> HttpPort) {
|
|
26
|
+
self.portFor = portFor
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// The call `callId` belongs to `serverId` (nil forgets it: the default server).
|
|
30
|
+
public func bindCall(_ callId: String, serverId: String?) {
|
|
31
|
+
lock.lock(); defer { lock.unlock() }
|
|
32
|
+
calls.removeAll { $0.callId == callId }
|
|
33
|
+
guard let serverId = serverId else { return }
|
|
34
|
+
calls.append((callId, serverId))
|
|
35
|
+
if calls.count > Self.maxBound { calls.removeFirst(calls.count - Self.maxBound) }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// The next call placed on `conversationId` goes to `serverId`.
|
|
39
|
+
public func bindPlace(_ conversationId: String, serverId: String?) {
|
|
40
|
+
lock.lock(); defer { lock.unlock() }
|
|
41
|
+
places[conversationId] = serverId
|
|
42
|
+
if places.count > Self.maxBound, let any = places.keys.first(where: { $0 != conversationId }) {
|
|
43
|
+
places.removeValue(forKey: any)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// The server `callId` is bound to (a `pending:<conversation>` id: its place); nil = the default.
|
|
48
|
+
public func serverFor(_ callId: String) -> String? {
|
|
49
|
+
lock.lock(); defer { lock.unlock() }
|
|
50
|
+
if callId.hasPrefix(Self.pending) { return places[String(callId.dropFirst(Self.pending.count))] }
|
|
51
|
+
return calls.last { $0.callId == callId }?.serverId
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public func answer(callId: String, grant: String, cb: @escaping (HttpResult) -> Void) {
|
|
55
|
+
portFor(serverFor(callId)).answer(callId: callId, grant: grant, cb: cb)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public func join(callId: String, sessionToken: String, cb: @escaping (HttpResult) -> Void) {
|
|
59
|
+
portFor(serverFor(callId)).join(callId: callId, sessionToken: sessionToken, cb: cb)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public func place(conversationId: String, media: String, sessionToken: String,
|
|
63
|
+
cb: @escaping (HttpResult) -> Void) {
|
|
64
|
+
lock.lock(); let server = places[conversationId]; lock.unlock()
|
|
65
|
+
portFor(server).place(conversationId: conversationId, media: media, sessionToken: sessionToken) { [weak self] result in
|
|
66
|
+
// Everything after the answer (hangup, reconnect) names the minted id.
|
|
67
|
+
if case let .ok(bundle) = result { self?.bindCall(bundle.callId, serverId: server) }
|
|
68
|
+
cb(result)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public func decline(callId: String, auth: String, busy: Bool) {
|
|
73
|
+
portFor(serverFor(callId)).decline(callId: callId, auth: auth, busy: busy)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public func hangup(callId: String, controlToken: String) {
|
|
77
|
+
portFor(serverFor(callId)).hangup(callId: callId, controlToken: controlToken)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public func reconnect(current: CallSessionBundle, cb: @escaping (HttpResult) -> Void) {
|
|
81
|
+
portFor(serverFor(current.callId)).reconnect(current: current, cb: cb)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -68,6 +68,13 @@ public extension Direction {
|
|
|
68
68
|
var wire: String { rawValue.lowercased() }
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/// JSON object text → a dictionary for the bridge; NSNull when absent or not an object.
|
|
72
|
+
private func jsonObject(_ text: String?) -> Any {
|
|
73
|
+
guard let text = text, let data = text.data(using: .utf8),
|
|
74
|
+
let obj = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any] else { return NSNull() }
|
|
75
|
+
return obj
|
|
76
|
+
}
|
|
77
|
+
|
|
71
78
|
public extension MachineState {
|
|
72
79
|
/// The one place a MachineState becomes the contract's `Snapshot`
|
|
73
80
|
/// (CALL_CONTRACT.md §8; mirrors SnapshotJson.kt and src/index.ts). Returns nil
|
|
@@ -86,7 +93,10 @@ public extension MachineState {
|
|
|
86
93
|
waiting: RingContext? = nil,
|
|
87
94
|
connectionQuality: String = "unknown",
|
|
88
95
|
videoPaused: Bool = false,
|
|
89
|
-
screenSharing: Bool = false
|
|
96
|
+
screenSharing: Bool = false,
|
|
97
|
+
canPublish: Bool = true,
|
|
98
|
+
recording: String? = nil,
|
|
99
|
+
transcription: String? = nil) -> [String: Any]? {
|
|
90
100
|
if phase == .idle { return nil }
|
|
91
101
|
var out: [String: Any] = [
|
|
92
102
|
"cv": 1,
|
|
@@ -106,6 +116,12 @@ public extension MachineState {
|
|
|
106
116
|
"connectionQuality": connectionQuality,
|
|
107
117
|
"videoPaused": videoPaused,
|
|
108
118
|
"screenSharing": screenSharing,
|
|
119
|
+
// false while the server holds our media back (recording consent
|
|
120
|
+
// not given yet, docs/RECORDING.md §5): listen-only until it lets go.
|
|
121
|
+
"canPublish": canPublish,
|
|
122
|
+
// The CallSummary's capture state, as of joining (null: not known).
|
|
123
|
+
"recording": jsonObject(recording),
|
|
124
|
+
"transcription": jsonObject(transcription),
|
|
109
125
|
]
|
|
110
126
|
// The call waiting beside this one: null when none.
|
|
111
127
|
if let w = self.waiting {
|
|
@@ -61,16 +61,48 @@ public class PoolseCallsModule: Module {
|
|
|
61
61
|
_ = CallCore.getOrNull()
|
|
62
62
|
}.runOnQueue(.main)
|
|
63
63
|
|
|
64
|
+
// Several workspaces: each server the app is signed in to. Persisted,
|
|
65
|
+
// so a ring or a notification action with no JS finds its server.
|
|
66
|
+
AsyncFunction("addServer") { (server: [String: Any]) in
|
|
67
|
+
guard let s = CallServer(dict: server) else { return }
|
|
68
|
+
var entry = s
|
|
69
|
+
while entry.apiBaseUrl.hasSuffix("/") { entry.apiBaseUrl.removeLast() }
|
|
70
|
+
CallCore.ensureConfigured()
|
|
71
|
+
ServerRegistry.shared.upsert(entry)
|
|
72
|
+
PoolseCallsSetup.registerVoipEarly()
|
|
73
|
+
_ = CallCore.getOrNull()
|
|
74
|
+
}.runOnQueue(.main)
|
|
75
|
+
|
|
76
|
+
// Signed out of one workspace: forget it and take its notifications
|
|
77
|
+
// down. A call in progress on it carries on to its end.
|
|
78
|
+
AsyncFunction("removeServer") { (id: String) in
|
|
79
|
+
let tenant = ServerRegistry.shared.servers.get(id)?.tenantId
|
|
80
|
+
ServerRegistry.shared.remove(id)
|
|
81
|
+
if let tenant = tenant { MessageNotifications.clearTenant(tenant) }
|
|
82
|
+
}.runOnQueue(.main)
|
|
83
|
+
|
|
84
|
+
Function("listServers") { () -> [[String: Any]] in
|
|
85
|
+
ServerRegistry.shared.servers.all.map(\.dict)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// The server a push / notification of `tenantId` belongs to — the
|
|
89
|
+
// same rule the native side routes rings and actions by.
|
|
90
|
+
Function("serverForTenant") { (tenantId: String?) -> String? in
|
|
91
|
+
ServerRegistry.shared.servers.resolve(tenantId: tenantId.flatMap { $0.isEmpty ? nil : $0 })?.id
|
|
92
|
+
}
|
|
93
|
+
|
|
64
94
|
Function("getCallState") { () -> [String: Any] in
|
|
65
95
|
["snapshot": CallCore.peek()?.snapshot() ?? NSNull()]
|
|
66
96
|
}
|
|
67
97
|
|
|
68
|
-
AsyncFunction("place") { (conversationId: String, media: String, sessionToken: String) in
|
|
69
|
-
CallCore.getOrNull()?.place(conversationId: conversationId, media: media, sessionToken: sessionToken
|
|
98
|
+
AsyncFunction("place") { (conversationId: String, media: String, sessionToken: String, serverId: String?) in
|
|
99
|
+
CallCore.getOrNull()?.place(conversationId: conversationId, media: media, sessionToken: sessionToken,
|
|
100
|
+
serverId: serverId)
|
|
70
101
|
}.runOnQueue(.main)
|
|
71
102
|
|
|
72
|
-
AsyncFunction("join") { (callId: String, conversationId: String?, sessionToken: String) in
|
|
73
|
-
CallCore.getOrNull()?.join(callId: callId, conversationId: conversationId, sessionToken: sessionToken
|
|
103
|
+
AsyncFunction("join") { (callId: String, conversationId: String?, sessionToken: String, serverId: String?) in
|
|
104
|
+
CallCore.getOrNull()?.join(callId: callId, conversationId: conversationId, sessionToken: sessionToken,
|
|
105
|
+
serverId: serverId)
|
|
74
106
|
}.runOnQueue(.main)
|
|
75
107
|
|
|
76
108
|
Function("answer") { onCore { $0.answer() } }
|
|
@@ -95,6 +127,8 @@ public class PoolseCallsModule: Module {
|
|
|
95
127
|
Function("stopScreenShare") { onCore { $0.setScreenShare(false) } }
|
|
96
128
|
Function("setSpeaker") { (on: Bool) in onCore { $0.setSpeaker(on) } }
|
|
97
129
|
Function("setAudioOutput") { (id: String) in onCore { $0.setAudioOutput(id) } }
|
|
130
|
+
// Recording consent accepted: mic and camera back as they were.
|
|
131
|
+
Function("republish") { onCore { $0.republish() } }
|
|
98
132
|
|
|
99
133
|
// Picture-in-picture: armed while a video call shows someone; the
|
|
100
134
|
// <CallVideoView pictureInPicture> on screen is what it grows out of.
|
|
@@ -106,15 +140,23 @@ public class PoolseCallsModule: Module {
|
|
|
106
140
|
|
|
107
141
|
// What authorizes acting on the call itself (ringing people in).
|
|
108
142
|
AsyncFunction("callControl") { () -> [String: String]? in
|
|
109
|
-
guard let
|
|
110
|
-
|
|
143
|
+
guard let core = CallCore.getOrNull(), let c = core.control else { return nil }
|
|
144
|
+
var out = ["callId": c.callId, "controlToken": c.controlToken]
|
|
145
|
+
// Where the call runs: ringing people in goes to that server.
|
|
146
|
+
if let id = core.currentServerId {
|
|
147
|
+
out["serverId"] = id
|
|
148
|
+
out["apiBaseUrl"] = ServerRegistry.shared.baseUrl(id)
|
|
149
|
+
}
|
|
150
|
+
return out
|
|
111
151
|
}.runOnQueue(.main)
|
|
112
152
|
|
|
113
153
|
// The chat on screen: opening it clears what was already shown for it.
|
|
114
154
|
// (Suppressing new ones while it is open happens in the app's
|
|
115
155
|
// notification handler — see shouldPresentMessage in src/index.ts.)
|
|
116
|
-
Function("setActiveConversation") { (conversationId: String?) in
|
|
117
|
-
|
|
156
|
+
Function("setActiveConversation") { (conversationId: String?, serverId: String?) in
|
|
157
|
+
guard let conversationId = conversationId else { return }
|
|
158
|
+
let tenant = serverId.flatMap { ServerRegistry.shared.servers.get($0)?.tenantId }
|
|
159
|
+
MessageNotifications.clear(conversationId: conversationId, tenantId: tenant)
|
|
118
160
|
}
|
|
119
161
|
|
|
120
162
|
// Reply / Mark as read done from a notification while JS was not
|