@poolse/native 3.9.0 → 3.10.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 +40 -0
- package/README.md +94 -9
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/dev/poolse/callcore/Ports.kt +21 -1
- package/android/src/main/java/dev/poolse/callcore/android/AndroidRingSurface.kt +3 -3
- package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +91 -10
- package/android/src/main/java/dev/poolse/callcore/android/CallMessagingService.kt +21 -1
- package/android/src/main/java/dev/poolse/callcore/android/CallVideo.kt +14 -0
- package/android/src/main/java/dev/poolse/callcore/android/EscalationNotification.kt +475 -0
- package/android/src/main/java/dev/poolse/callcore/android/IncomingCallActivity.kt +9 -4
- package/android/src/main/java/dev/poolse/callcore/android/MeetingNotification.kt +127 -0
- package/android/src/main/java/dev/poolse/callcore/android/PoolseIncomingCall.kt +9 -0
- package/android/src/main/java/dev/poolse/callcore/android/RingBundle.kt +9 -0
- package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +15 -1
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +82 -6
- package/dist/index.cjs +18 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +133 -23
- package/dist/index.d.ts +133 -23
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/ios/Core/Ports.swift +22 -1
- package/ios/Core/SnapshotEncoding.swift +22 -3
- package/ios/Module/PoolseCallsModule.swift +26 -1
- package/ios/Platform/CallCore.swift +52 -1
- package/ios/Platform/CallKitController.swift +1 -1
- package/ios/Platform/EscalationNotifications.swift +195 -0
- package/ios/Platform/LiveKitMediaPort.swift +77 -3
- package/ios/Platform/MessageNotifications.swift +60 -1
- package/ios/Platform/VoipPush.swift +11 -2
- package/package.json +1 -1
- package/src/index.ts +154 -23
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
import UserNotifications
|
|
4
|
+
|
|
5
|
+
/// An agent attending a meeting for the user asks them something its brief
|
|
6
|
+
/// doesn't cover (server docs/AGENTS_IN_CALLS.md §5). The server sends an
|
|
7
|
+
/// alert push with category `poolse_agent_escalation`; iOS shows it, and
|
|
8
|
+
/// this answers its actions natively — Approve, Decline, and Answer (an
|
|
9
|
+
/// inline text field) — from the lock screen with the app killed.
|
|
10
|
+
///
|
|
11
|
+
/// The reply is `POST /v1/agent-escalations/:id/reply` with the push's
|
|
12
|
+
/// `reply_token` in the body and no Authorization header: the token names
|
|
13
|
+
/// that escalation and person only, works once, until `expires_at`. It
|
|
14
|
+
/// goes to the push's own server (its `tenant_id`), the push's
|
|
15
|
+
/// `reply_url` only when that server isn't configured here.
|
|
16
|
+
///
|
|
17
|
+
/// A failure posts "Couldn't send your answer" with the same actions
|
|
18
|
+
/// (while trying again can still work). Results reach JS as
|
|
19
|
+
/// `onNotificationAction` with `action: "escalation"`.
|
|
20
|
+
///
|
|
21
|
+
/// `PoolseMessageReplyRequiresUnlock` (the config plugin's
|
|
22
|
+
/// `messageReplyRequiresUnlock`) makes these actions ask for Face ID / the
|
|
23
|
+
/// passcode first too.
|
|
24
|
+
enum EscalationNotifications {
|
|
25
|
+
static let category = "poolse_agent_escalation"
|
|
26
|
+
static let approveAction = "poolse_escalation_approve"
|
|
27
|
+
static let declineAction = "poolse_escalation_decline"
|
|
28
|
+
static let answerAction = "poolse_escalation_answer"
|
|
29
|
+
|
|
30
|
+
/// The category, registered with the message one (MessageNotifications).
|
|
31
|
+
static func makeCategory(requireUnlock: Bool) -> UNNotificationCategory {
|
|
32
|
+
let options: UNNotificationActionOptions = requireUnlock ? [.authenticationRequired] : []
|
|
33
|
+
let approve = UNNotificationAction(identifier: approveAction, title: "Approve", options: options)
|
|
34
|
+
let decline = UNNotificationAction(identifier: declineAction, title: "Decline", options: options)
|
|
35
|
+
let answer = UNTextInputNotificationAction(
|
|
36
|
+
identifier: answerAction,
|
|
37
|
+
title: "Answer",
|
|
38
|
+
options: options,
|
|
39
|
+
textInputButtonTitle: "Send",
|
|
40
|
+
textInputPlaceholder: "Your answer"
|
|
41
|
+
)
|
|
42
|
+
return UNNotificationCategory(
|
|
43
|
+
identifier: category,
|
|
44
|
+
actions: [approve, decline, answer],
|
|
45
|
+
intentIdentifiers: [],
|
|
46
|
+
hiddenPreviewsBodyPlaceholder: "Your agent has a question",
|
|
47
|
+
options: []
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// An action on an escalation notification. False for a plain tap (the
|
|
52
|
+
/// host opens the conversation) or a dismissal.
|
|
53
|
+
static func didReceive(_ response: UNNotificationResponse) -> Bool {
|
|
54
|
+
let decision: String
|
|
55
|
+
switch response.actionIdentifier {
|
|
56
|
+
case approveAction: decision = "approve"
|
|
57
|
+
case declineAction: decision = "decline"
|
|
58
|
+
case answerAction: decision = "answer"
|
|
59
|
+
default: return false
|
|
60
|
+
}
|
|
61
|
+
let content = response.notification.request.content
|
|
62
|
+
let info = content.userInfo
|
|
63
|
+
func str(_ key: String) -> String? { (info[key] as? String).flatMap { $0.isEmpty ? nil : $0 } }
|
|
64
|
+
guard let id = str("escalation_id") else { return true }
|
|
65
|
+
let server = ServerRegistry.shared.servers.resolve(tenantId: str("tenant_id"))
|
|
66
|
+
var event: [String: Any] = [
|
|
67
|
+
"action": "escalation",
|
|
68
|
+
"escalationId": id,
|
|
69
|
+
"decision": decision,
|
|
70
|
+
"conversationId": str("conversation_id") ?? "",
|
|
71
|
+
"callId": str("call_id") ?? NSNull(),
|
|
72
|
+
]
|
|
73
|
+
if let sid = server?.id { event["serverId"] = sid }
|
|
74
|
+
|
|
75
|
+
var body: [String: Any] = [:]
|
|
76
|
+
if decision == "answer" {
|
|
77
|
+
let text = String(((response as? UNTextInputNotificationResponse)?.userText ?? "")
|
|
78
|
+
.trimmingCharacters(in: .whitespacesAndNewlines).prefix(1000))
|
|
79
|
+
guard !text.isEmpty else { return true }
|
|
80
|
+
body["answer"] = text
|
|
81
|
+
event["text"] = text
|
|
82
|
+
} else {
|
|
83
|
+
body["decision"] = decision
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
guard let token = str("reply_token") else {
|
|
87
|
+
event["ok"] = false
|
|
88
|
+
event["error"] = "no_token"
|
|
89
|
+
MessageNotifications.report(event)
|
|
90
|
+
postFailure(content, reason: "Open the app to answer.", retry: false)
|
|
91
|
+
return true
|
|
92
|
+
}
|
|
93
|
+
body["token"] = token
|
|
94
|
+
|
|
95
|
+
var origin = server?.apiBaseUrl ?? ServerRegistry.shared.baseUrl(nil)
|
|
96
|
+
if origin.isEmpty { origin = CallCore.persistedApiBaseUrl() ?? "" }
|
|
97
|
+
let encodedId = id.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? id
|
|
98
|
+
let url = !origin.isEmpty
|
|
99
|
+
? URL(string: "\(origin)/v1/agent-escalations/\(encodedId)/reply")
|
|
100
|
+
: str("reply_url").flatMap(URL.init(string:))
|
|
101
|
+
guard let url = url else {
|
|
102
|
+
event["ok"] = false
|
|
103
|
+
event["error"] = "not_configured"
|
|
104
|
+
MessageNotifications.report(event)
|
|
105
|
+
postFailure(content, reason: "Open the app to answer.", retry: false)
|
|
106
|
+
return true
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Started before anything async: iOS may suspend a background-launched
|
|
110
|
+
// app right after the delegate returns.
|
|
111
|
+
let background = BackgroundTask(name: "poolse-escalation-\(decision)")
|
|
112
|
+
send(url: url, body: body, background: background) { status, code in
|
|
113
|
+
let ok = (200..<300).contains(status)
|
|
114
|
+
event["ok"] = ok
|
|
115
|
+
if !ok {
|
|
116
|
+
event["error"] = code ?? (status == 0 ? "network" : "http_\(status)")
|
|
117
|
+
if status != 0 { event["status"] = status }
|
|
118
|
+
let retry = ![401, 404, 409, 410].contains(status)
|
|
119
|
+
postFailure(content, reason: reason(status), retry: retry)
|
|
120
|
+
}
|
|
121
|
+
MessageNotifications.report(event)
|
|
122
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { background.end() }
|
|
123
|
+
}
|
|
124
|
+
return true
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// "Couldn't send your answer" — with the same actions and token while
|
|
128
|
+
/// trying again can still work.
|
|
129
|
+
private static func postFailure(_ original: UNNotificationContent, reason: String, retry: Bool) {
|
|
130
|
+
let content = UNMutableNotificationContent()
|
|
131
|
+
content.title = "Couldn't send your answer"
|
|
132
|
+
content.body = "\(original.body)\n\(reason)"
|
|
133
|
+
content.threadIdentifier = original.threadIdentifier
|
|
134
|
+
content.sound = .default
|
|
135
|
+
var info = original.userInfo
|
|
136
|
+
info["poolse_escalation_failed"] = "1"
|
|
137
|
+
if !retry { info.removeValue(forKey: "reply_token") }
|
|
138
|
+
content.userInfo = info
|
|
139
|
+
if retry { content.categoryIdentifier = category }
|
|
140
|
+
let id = (original.userInfo["escalation_id"] as? String) ?? UUID().uuidString
|
|
141
|
+
let request = UNNotificationRequest(identifier: "poolse-escalation-failed-\(id)", content: content, trigger: nil)
|
|
142
|
+
UNUserNotificationCenter.current().add(request) { error in
|
|
143
|
+
if let error = error { pcTrace("escalation failure notification refused: \(error)") }
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private static func reason(_ status: Int) -> String {
|
|
148
|
+
switch status {
|
|
149
|
+
case 0: return "No connection. Try again."
|
|
150
|
+
case 401: return "This notification expired. Open the app to answer."
|
|
151
|
+
case 404: return "This question is gone."
|
|
152
|
+
case 409: return "It was already answered."
|
|
153
|
+
case 410: return "Too late — the question expired."
|
|
154
|
+
case 422: return "The answer couldn't be sent (1 to 1000 characters)."
|
|
155
|
+
case 429: return "Too many tries. Wait a moment."
|
|
156
|
+
default: return "Something went wrong. Try again."
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private static let session: URLSession = {
|
|
161
|
+
let config = URLSessionConfiguration.ephemeral
|
|
162
|
+
config.timeoutIntervalForRequest = 15
|
|
163
|
+
config.waitsForConnectivity = false
|
|
164
|
+
return URLSession(configuration: config)
|
|
165
|
+
}()
|
|
166
|
+
|
|
167
|
+
/// The POST, retried once after a second only when nothing came back
|
|
168
|
+
/// (the token works once: an answered request is never sent again).
|
|
169
|
+
private static func send(url: URL, body: [String: Any], background: BackgroundTask, attempt: Int = 1,
|
|
170
|
+
done: @escaping (Int, String?) -> Void) {
|
|
171
|
+
var request = URLRequest(url: url)
|
|
172
|
+
request.httpMethod = "POST"
|
|
173
|
+
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
174
|
+
request.setValue("application/json", forHTTPHeaderField: "Accept")
|
|
175
|
+
request.httpBody = try? JSONSerialization.data(withJSONObject: body)
|
|
176
|
+
session.dataTask(with: request) { data, response, error in
|
|
177
|
+
let status = error == nil ? ((response as? HTTPURLResponse)?.statusCode ?? 0) : 0
|
|
178
|
+
let json = data.flatMap { try? JSONSerialization.jsonObject(with: $0) } as? [String: Any]
|
|
179
|
+
let code = (json?["error"] as? [String: Any])?["code"] as? String
|
|
180
|
+
if status == 0 && attempt < 2 {
|
|
181
|
+
DispatchQueue.main.async {
|
|
182
|
+
guard background.remaining > 20 else { return done(status, code) }
|
|
183
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
|
184
|
+
send(url: url, body: body, background: background, attempt: attempt + 1, done: done)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
if !(200..<300).contains(status) {
|
|
190
|
+
pcTrace("escalation reply failed status=\(status) code=\(code ?? "-") error=\(String(describing: error))")
|
|
191
|
+
}
|
|
192
|
+
done(status, code)
|
|
193
|
+
}.resume()
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -35,6 +35,9 @@ protocol MediaEvents: AnyObject {
|
|
|
35
35
|
/// Whether the server lets us publish (false: recording consent not
|
|
36
36
|
/// given yet, docs/RECORDING.md §5). Sent on every change.
|
|
37
37
|
func onCanPublish(_ allowed: Bool)
|
|
38
|
+
/// The SFU replaced us with the same user joining from another device
|
|
39
|
+
/// ("move call to this device", CALL_CONTRACT.md §9). Sent just before `onLost`.
|
|
40
|
+
func onMovedElsewhere()
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
/// Step-by-step trace of the audio path, in the device log as
|
|
@@ -113,6 +116,12 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
113
116
|
private static let pauseVideoAfter: TimeInterval = 6
|
|
114
117
|
private static let resumeVideoAfter: TimeInterval = 10
|
|
115
118
|
|
|
119
|
+
/// Capture processing (CL7); per process, not per call.
|
|
120
|
+
private(set) var noiseSuppression = true
|
|
121
|
+
private(set) var backgroundBlur = false
|
|
122
|
+
/// The capturer holds its processor weakly: this keeps it alive.
|
|
123
|
+
private var blurProcessor: BackgroundBlurVideoProcessor?
|
|
124
|
+
|
|
116
125
|
private let surfaces = NSHashTable<LiveKitVideoSurface>.weakObjects()
|
|
117
126
|
private var audioPrepared = false
|
|
118
127
|
private var audioActive = false
|
|
@@ -742,8 +751,37 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
742
751
|
return (track.capturer as? CameraCapturer)?.position == .back ? "back" : "front"
|
|
743
752
|
}
|
|
744
753
|
|
|
754
|
+
// MARK: - capture processing (CL7)
|
|
755
|
+
|
|
756
|
+
/// Apple's voice processing (VPIO) does echo cancellation, gain control
|
|
757
|
+
/// and noise suppression as one unit, so "off" bypasses all of it —
|
|
758
|
+
/// meant for headphones (music, an instrument). Valid mid-call.
|
|
759
|
+
func setNoiseSuppression(_ on: Bool) {
|
|
760
|
+
noiseSuppression = on
|
|
761
|
+
AudioManager.shared.isVoiceProcessingBypassed = !on
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/// Blur behind the person on the published camera (Vision person
|
|
765
|
+
/// segmentation, LiveKit's BackgroundBlurVideoProcessor). Survives a
|
|
766
|
+
/// camera flip and republish: re-applied whenever the camera is reported.
|
|
767
|
+
func setBackgroundBlur(_ on: Bool) {
|
|
768
|
+
backgroundBlur = on
|
|
769
|
+
if let r = room { applyBlur(r) }
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
private func applyBlur(_ r: Room) {
|
|
773
|
+
guard let track = localCameraTrack(r) else { return }
|
|
774
|
+
if backgroundBlur {
|
|
775
|
+
if blurProcessor == nil { blurProcessor = BackgroundBlurVideoProcessor() }
|
|
776
|
+
if track.capturer.processor !== blurProcessor { track.capturer.processor = blurProcessor }
|
|
777
|
+
} else if track.capturer.processor != nil {
|
|
778
|
+
track.capturer.processor = nil
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
745
782
|
private func reportLocalCamera(_ r: Room) {
|
|
746
783
|
guard room === r else { return }
|
|
784
|
+
applyBlur(r)
|
|
747
785
|
let on = localCameraTrack(r) != nil
|
|
748
786
|
events?.onLocalCamera(on: on, facing: on ? cameraFacing() : nil)
|
|
749
787
|
}
|
|
@@ -760,6 +798,10 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
760
798
|
case .reconnected:
|
|
761
799
|
events?.onRecovered()
|
|
762
800
|
case .disconnected:
|
|
801
|
+
// The same user joined from another device: LiveKit replaces the
|
|
802
|
+
// older participant (one identity per user). The reconnect that
|
|
803
|
+
// follows is refused, and the call ends as moved.
|
|
804
|
+
if r.disconnectError?.type == .duplicateIdentity { events?.onMovedElsewhere() }
|
|
763
805
|
events?.onLost()
|
|
764
806
|
case .participantJoined:
|
|
765
807
|
// The transcript assistant or the recorder joining is nobody answering.
|
|
@@ -863,10 +905,11 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
863
905
|
/// The remote PEOPLE: poolse's transcript assistant and LiveKit Egress's
|
|
864
906
|
/// recorder are in the room but are not someone in the call — never in
|
|
865
907
|
/// the roster, the count that ends a call left alone, or a video tile.
|
|
866
|
-
/// Phone (SIP) participants are people.
|
|
908
|
+
/// Agents are listed separately (`agents`). Phone (SIP) participants are people.
|
|
867
909
|
private func people(_ r: Room) -> [RemoteParticipant] {
|
|
868
910
|
r.remoteParticipants.values.filter { p in
|
|
869
|
-
!ServiceParticipants.isService(identity: p.identity?.stringValue ?? "", kind: Self.kindName(p.kind))
|
|
911
|
+
!ServiceParticipants.isService(identity: p.identity?.stringValue ?? "", kind: Self.kindName(p.kind)) &&
|
|
912
|
+
Self.metadata(p)?["agent"] as? Bool != true
|
|
870
913
|
}
|
|
871
914
|
}
|
|
872
915
|
|
|
@@ -878,8 +921,39 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
878
921
|
return nil
|
|
879
922
|
}
|
|
880
923
|
|
|
924
|
+
/// Agents invited into the call (AGENTS_IN_CALLS.md §1): kind AGENT like
|
|
925
|
+
/// poolse's room assistant, but marked `agent: true` in their token
|
|
926
|
+
/// metadata — listed (with the badge), unlike the assistant and recorder.
|
|
927
|
+
private func agents(_ r: Room) -> [(RemoteParticipant, [String: Any])] {
|
|
928
|
+
r.remoteParticipants.values.compactMap { p -> (RemoteParticipant, [String: Any])? in
|
|
929
|
+
guard let m = Self.metadata(p), m["agent"] as? Bool == true else { return nil }
|
|
930
|
+
return (p, m)
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
static func metadata(_ p: Participant) -> [String: Any]? {
|
|
935
|
+
guard let m = p.metadata, let d = m.data(using: .utf8) else { return nil }
|
|
936
|
+
return (try? JSONSerialization.jsonObject(with: d)) as? [String: Any]
|
|
937
|
+
}
|
|
938
|
+
|
|
881
939
|
/// The REMOTE roster — the local participant is never included.
|
|
882
940
|
private func emit(_ r: Room) {
|
|
941
|
+
let agentRows = agents(r).map { entry -> SnapshotParticipant in
|
|
942
|
+
let (p, m) = entry
|
|
943
|
+
let identity = p.identity?.stringValue ?? ""
|
|
944
|
+
return SnapshotParticipant(
|
|
945
|
+
userId: identity,
|
|
946
|
+
externalId: externalId(p) ?? identity,
|
|
947
|
+
speaking: p.isSpeaking,
|
|
948
|
+
muted: !p.isMicrophoneEnabled(),
|
|
949
|
+
cameraOn: false,
|
|
950
|
+
connectionQuality: Self.wire(p.connectionQuality),
|
|
951
|
+
screenSharing: false,
|
|
952
|
+
isAgent: true,
|
|
953
|
+
agentLabel: (m["label"] as? String).flatMap { $0.isEmpty ? nil : $0 } ?? p.name,
|
|
954
|
+
agentMode: m["mode"] as? String
|
|
955
|
+
)
|
|
956
|
+
}
|
|
883
957
|
let roster = people(r).map { p -> SnapshotParticipant in
|
|
884
958
|
let identity = p.identity?.stringValue ?? ""
|
|
885
959
|
return SnapshotParticipant(
|
|
@@ -892,7 +966,7 @@ final class LiveKitMediaPort: NSObject, MediaPort {
|
|
|
892
966
|
screenSharing: remoteScreen(p) != nil
|
|
893
967
|
)
|
|
894
968
|
}
|
|
895
|
-
events?.onParticipants(roster)
|
|
969
|
+
events?.onParticipants(roster + agentRows)
|
|
896
970
|
}
|
|
897
971
|
|
|
898
972
|
/// The host's own user id, if the server put it in attributes/metadata.
|
|
@@ -38,6 +38,16 @@ final class MessageNotifications: NSObject, NotificationDelegate {
|
|
|
38
38
|
static let category = "poolse_message"
|
|
39
39
|
static let replyAction = "reply"
|
|
40
40
|
static let markReadAction = "mark_read"
|
|
41
|
+
/// Scheduled-meeting notices (server docs/MEETINGS.md §11.3): an alert push
|
|
42
|
+
/// with this category; "starting" offers Join.
|
|
43
|
+
static let meetingCategory = "poolse_meeting"
|
|
44
|
+
static let meetingJoinAction = "poolse_meeting_join"
|
|
45
|
+
|
|
46
|
+
/// The bridge's subscriber for meeting taps / Join (`onCallAction`); main thread.
|
|
47
|
+
static var callActionListener: (([String: Any]) -> Void)?
|
|
48
|
+
/// The last one nobody was listening for — the cold start that a Join
|
|
49
|
+
/// launched; `takeCallAction` reads it once. Main thread.
|
|
50
|
+
static var pendingCallAction: [String: Any]?
|
|
41
51
|
|
|
42
52
|
/// The bridge's subscriber for finished notification actions; main thread.
|
|
43
53
|
static var actionListener: (([String: Any]) -> Void)?
|
|
@@ -79,10 +89,23 @@ final class MessageNotifications: NSObject, NotificationDelegate {
|
|
|
79
89
|
categorySummaryFormat: "%u more messages from %@",
|
|
80
90
|
options: []
|
|
81
91
|
)
|
|
92
|
+
// Join opens the app: joining needs the user's session, which only it has.
|
|
93
|
+
let join = UNNotificationAction(identifier: Self.meetingJoinAction, title: "Join", options: [.foreground])
|
|
94
|
+
let meeting = UNNotificationCategory(
|
|
95
|
+
identifier: Self.meetingCategory,
|
|
96
|
+
actions: [join],
|
|
97
|
+
intentIdentifiers: [],
|
|
98
|
+
options: []
|
|
99
|
+
)
|
|
100
|
+
// An agent's question (AGENTS_IN_CALLS.md §5): Approve / Decline / Answer.
|
|
101
|
+
let escalation = EscalationNotifications.makeCategory(requireUnlock: requireUnlock)
|
|
102
|
+
let ours: Set<String> = [Self.category, Self.meetingCategory, EscalationNotifications.category]
|
|
82
103
|
let center = UNUserNotificationCenter.current()
|
|
83
104
|
center.getNotificationCategories { existing in
|
|
84
|
-
var all = existing.filter { $0.identifier
|
|
105
|
+
var all = existing.filter { !ours.contains($0.identifier) }
|
|
85
106
|
all.insert(category)
|
|
107
|
+
all.insert(meeting)
|
|
108
|
+
all.insert(escalation)
|
|
86
109
|
center.setNotificationCategories(all)
|
|
87
110
|
}
|
|
88
111
|
}
|
|
@@ -91,6 +114,10 @@ final class MessageNotifications: NSObject, NotificationDelegate {
|
|
|
91
114
|
|
|
92
115
|
func didReceive(_ response: UNNotificationResponse, completionHandler: @escaping () -> Void) -> Bool {
|
|
93
116
|
let content = response.notification.request.content
|
|
117
|
+
if content.categoryIdentifier == Self.meetingCategory { return meetingResponse(response) }
|
|
118
|
+
if content.categoryIdentifier == EscalationNotifications.category {
|
|
119
|
+
return EscalationNotifications.didReceive(response)
|
|
120
|
+
}
|
|
94
121
|
guard content.categoryIdentifier == Self.category else { return false }
|
|
95
122
|
let action = response.actionIdentifier
|
|
96
123
|
guard action == Self.replyAction || action == Self.markReadAction else {
|
|
@@ -175,6 +202,38 @@ final class MessageNotifications: NSObject, NotificationDelegate {
|
|
|
175
202
|
return true
|
|
176
203
|
}
|
|
177
204
|
|
|
205
|
+
/// A meeting notice's tap (`open`) or Join (`join_meeting`), handed to JS
|
|
206
|
+
/// as a CallAction — the shape Android's notification produces.
|
|
207
|
+
private func meetingResponse(_ response: UNNotificationResponse) -> Bool {
|
|
208
|
+
let content = response.notification.request.content
|
|
209
|
+
let info = content.userInfo
|
|
210
|
+
func str(_ key: String) -> String? { (info[key] as? String).flatMap(nilIfEmpty) }
|
|
211
|
+
let action: String
|
|
212
|
+
switch response.actionIdentifier {
|
|
213
|
+
case Self.meetingJoinAction: action = "join_meeting"
|
|
214
|
+
case UNNotificationDefaultActionIdentifier: action = "open"
|
|
215
|
+
default: return true // dismissed
|
|
216
|
+
}
|
|
217
|
+
guard let conversationId = str("conversation_id") else { return true }
|
|
218
|
+
let server = ServerRegistry.shared.servers.resolve(tenantId: str("tenant_id"))
|
|
219
|
+
let event: [String: Any] = [
|
|
220
|
+
"type": action,
|
|
221
|
+
"conversationId": conversationId,
|
|
222
|
+
"callId": str("call_id") ?? NSNull(),
|
|
223
|
+
"media": str("media") == "video" ? "video" : "audio",
|
|
224
|
+
"serverId": server?.id ?? NSNull(),
|
|
225
|
+
"scheduledMeetingId": str("scheduled_meeting_id") ?? NSNull(),
|
|
226
|
+
]
|
|
227
|
+
DispatchQueue.main.async {
|
|
228
|
+
if let listener = Self.callActionListener {
|
|
229
|
+
listener(event)
|
|
230
|
+
} else {
|
|
231
|
+
Self.pendingCallAction = event
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return true
|
|
235
|
+
}
|
|
236
|
+
|
|
178
237
|
/// A background push: the conversation was read on another device.
|
|
179
238
|
func didReceive(_ userInfo: [AnyHashable: Any],
|
|
180
239
|
completionHandler: @escaping (UIBackgroundFetchResult) -> Void) -> Bool {
|
|
@@ -143,7 +143,12 @@ struct VoipPayload {
|
|
|
143
143
|
var callId: String? { string("call_id") }
|
|
144
144
|
var event: String? { string("event") }
|
|
145
145
|
var reason: String? { string("reason") }
|
|
146
|
-
var title: String? {
|
|
146
|
+
var title: String? {
|
|
147
|
+
if string("ring_type") == "meeting" {
|
|
148
|
+
return "\(string("meeting_title") ?? string("conversation_name") ?? "Meeting") is starting"
|
|
149
|
+
}
|
|
150
|
+
return string("conversation_name") ?? string("caller_name")
|
|
151
|
+
}
|
|
147
152
|
|
|
148
153
|
var media: String {
|
|
149
154
|
if let m = string("media")?.lowercased(), m == "video" || m == "audio" { return m }
|
|
@@ -172,7 +177,11 @@ struct VoipPayload {
|
|
|
172
177
|
// Signed in to several workspaces: the ring is answered (and
|
|
173
178
|
// declined) on the server of its tenant.
|
|
174
179
|
serverId: ServerRegistry.shared.servers.resolve(tenantId: string("tenant_id"))?.id,
|
|
175
|
-
workspaceName: string("workspace_name")
|
|
180
|
+
workspaceName: string("workspace_name"),
|
|
181
|
+
// A scheduled meeting starting (CA4): "Weekly sync is starting".
|
|
182
|
+
ringType: string("ring_type"),
|
|
183
|
+
meetingTitle: string("meeting_title"),
|
|
184
|
+
meetingId: string("meeting_id")
|
|
176
185
|
)
|
|
177
186
|
}
|
|
178
187
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poolse/native",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.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",
|