@poolse/native 3.9.0 → 3.10.1

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +129 -9
  3. package/android/src/main/AndroidManifest.xml +4 -0
  4. package/android/src/main/java/dev/poolse/callcore/CallCoreRuntime.kt +83 -6
  5. package/android/src/main/java/dev/poolse/callcore/Ports.kt +28 -1
  6. package/android/src/main/java/dev/poolse/callcore/android/AndroidRingSurface.kt +3 -3
  7. package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +155 -10
  8. package/android/src/main/java/dev/poolse/callcore/android/CallHttpClient.kt +7 -1
  9. package/android/src/main/java/dev/poolse/callcore/android/CallMessagingService.kt +21 -1
  10. package/android/src/main/java/dev/poolse/callcore/android/CallVideo.kt +32 -0
  11. package/android/src/main/java/dev/poolse/callcore/android/EscalationNotification.kt +475 -0
  12. package/android/src/main/java/dev/poolse/callcore/android/IncomingCallActivity.kt +9 -4
  13. package/android/src/main/java/dev/poolse/callcore/android/MeetingNotification.kt +127 -0
  14. package/android/src/main/java/dev/poolse/callcore/android/PoolseIncomingCall.kt +9 -0
  15. package/android/src/main/java/dev/poolse/callcore/android/RingBundle.kt +9 -0
  16. package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +48 -2
  17. package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +121 -6
  18. package/android/src/test/java/dev/poolse/callcore/android/CallHttpClientTest.kt +15 -0
  19. package/dist/index.cjs +108 -0
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +241 -23
  22. package/dist/index.d.ts +241 -23
  23. package/dist/index.js +98 -1
  24. package/dist/index.js.map +1 -1
  25. package/ios/Core/CallCoreRuntime.swift +79 -5
  26. package/ios/Core/CallHttpClient.swift +9 -2
  27. package/ios/Core/Ports.swift +31 -2
  28. package/ios/Core/SnapshotEncoding.swift +22 -3
  29. package/ios/Module/PoolseCallsModule.swift +48 -1
  30. package/ios/Platform/CallCore.swift +100 -1
  31. package/ios/Platform/CallKitController.swift +1 -1
  32. package/ios/Platform/EscalationNotifications.swift +195 -0
  33. package/ios/Platform/LiveKitMediaPort.swift +127 -3
  34. package/ios/Platform/MessageNotifications.swift +60 -1
  35. package/ios/Platform/VoipPush.swift +11 -2
  36. package/package.json +1 -1
  37. package/src/index.ts +354 -23
@@ -91,6 +91,15 @@ class CallCore private constructor(context: Context) {
91
91
  private var videoPaused = false
92
92
  /** False while the server holds our media back (recording consent). */
93
93
  private var canPublish = true
94
+ /** Capture processing (CL7): per process, not per call. */
95
+ private var noiseSuppression = true
96
+ private var backgroundBlur = false
97
+ /**
98
+ * This call was taken over by the same user on another device (CL11):
99
+ * the SFU replaced our participant (duplicate identity). The end that
100
+ * follows reads `reason: 'moved'`.
101
+ */
102
+ private var movedElsewhere = false
94
103
 
95
104
  /** Last snapshot emitted; read by the bridge's getCallState from any thread. */
96
105
  @Volatile private var lastSnapshot: Map<String, Any?>? = null
@@ -108,6 +117,9 @@ class CallCore private constructor(context: Context) {
108
117
  /** The push's `workspace_name` per ringing call. */
109
118
  private val ringWorkspaces = java.util.concurrent.ConcurrentHashMap<String, String>()
110
119
 
120
+ /** Meeting rings (CA4) per call: the meeting's title, "" when it has none. Absent: a person calling. */
121
+ private val ringMeetings = java.util.concurrent.ConcurrentHashMap<String, String>()
122
+
111
123
  /**
112
124
  * A ring arrived — from FCM (closed app) or the socket (open app).
113
125
  * Bound to its server before the runtime sees it: a busy-decline runs
@@ -124,6 +136,10 @@ class CallCore private constructor(context: Context) {
124
136
  if (ringWorkspaces.size > 16) ringWorkspaces.clear()
125
137
  ringWorkspaces[ring.callId] = it
126
138
  }
139
+ if (ring.isMeeting) {
140
+ if (ringMeetings.size > 16) ringMeetings.clear()
141
+ ringMeetings[ring.callId] = ring.meetingTitle ?: ""
142
+ }
127
143
  }
128
144
 
129
145
  /**
@@ -255,6 +271,34 @@ class CallCore private constructor(context: Context) {
255
271
  return true
256
272
  }
257
273
 
274
+ /**
275
+ * Noise suppression on the microphone (CL7), on by default. Kept
276
+ * across calls for this process. False when the engine can't change
277
+ * it (the signalling-only build).
278
+ */
279
+ fun setNoiseSuppression(on: Boolean): Boolean {
280
+ val source = media as? CaptureProcessingSource ?: return false
281
+ // On the runtime's (main) thread: the media port only touches its room there.
282
+ runtime.post { noiseSuppression = on; source.setNoiseSuppression(on) }
283
+ runtime.reemit()
284
+ return true
285
+ }
286
+
287
+ /** Background blur on the camera (CL7); a no-op where unsupported. */
288
+ fun setBackgroundBlur(on: Boolean): Boolean {
289
+ val source = media as? CaptureProcessingSource ?: return false
290
+ if (!source.backgroundBlurSupported) return false
291
+ runtime.post { backgroundBlur = on; source.setBackgroundBlur(on) }
292
+ runtime.reemit()
293
+ return true
294
+ }
295
+
296
+ val noiseSuppressionSupported: Boolean
297
+ get() = (media as? CaptureProcessingSource)?.noiseSuppressionSupported ?: false
298
+
299
+ val backgroundBlurSupported: Boolean
300
+ get() = (media as? CaptureProcessingSource)?.backgroundBlurSupported ?: false
301
+
258
302
  /** Whether this build's media engine can share the screen. */
259
303
  val screenShareSupported: Boolean get() = media is ScreenShareSource
260
304
 
@@ -287,6 +331,37 @@ class CallCore private constructor(context: Context) {
287
331
  /** The current call's id and control token. Any thread. */
288
332
  val control: Pair<String, String>? get() = runtime.control
289
333
 
334
+ /**
335
+ * Breakout rooms (MEETINGS.md §5): the call's media to the room of
336
+ * [payload] — the JSON of `POST /breakouts/:room/join` (or of `POST
337
+ * /calls/:id/breakouts/return`). The call service and the system call
338
+ * stay; see [CallCoreRuntime.moveToRoom]. [done] false: unparseable,
339
+ * no live call, or another call's session.
340
+ */
341
+ fun moveToRoom(payload: String, done: (Boolean) -> Unit) = runtime.post {
342
+ val current = runtime.currentBundle
343
+ val next = current?.let { runCatching { CallHttpClient.parseBundle(payload, it) }.getOrNull() }
344
+ if (next == null) {
345
+ done(false)
346
+ return@post
347
+ }
348
+ runtime.moveToRoom(next) { ok ->
349
+ // The last room's people are not in this one.
350
+ if (ok) roster = emptyList()
351
+ done(ok)
352
+ }
353
+ }
354
+
355
+ /**
356
+ * A data-channel message to the call's room (CL4, CL6). False at once
357
+ * when the media engine has no data channel (the signalling-only build).
358
+ */
359
+ fun publishData(topic: String, data: ByteArray, reliable: Boolean, to: List<String>, done: (Boolean) -> Unit) {
360
+ val source = media as? CallDataSource ?: return done(false)
361
+ // On the runtime's (main) thread: the media port only touches its room there.
362
+ runtime.post { source.publishData(topic, data, reliable, to, done) }
363
+ }
364
+
290
365
  fun allRingsResolved(outcome: String) = runtime.allRingsResolved(outcome)
291
366
 
292
367
  fun state(): MachineState = runtime.currentState()
@@ -328,15 +403,20 @@ class CallCore private constructor(context: Context) {
328
403
  conversationName = conversationName,
329
404
  kind = callKind,
330
405
  participants = roster.map {
331
- mapOf(
332
- "userId" to it.identity,
333
- "externalId" to it.externalId,
334
- "speaking" to it.speaking,
335
- "muted" to it.muted,
336
- "cameraOn" to it.cameraOn,
337
- "screenSharing" to it.screenSharing,
338
- "connectionQuality" to it.connectionQuality,
339
- )
406
+ buildMap<String, Any> {
407
+ put("userId", it.identity)
408
+ put("externalId", it.externalId)
409
+ put("speaking", it.speaking)
410
+ put("muted", it.muted)
411
+ put("cameraOn", it.cameraOn)
412
+ put("screenSharing", it.screenSharing)
413
+ put("connectionQuality", it.connectionQuality)
414
+ if (it.isAgent) {
415
+ put("isAgent", true)
416
+ it.agentLabel?.let { label -> put("agentLabel", label) }
417
+ it.agentMode?.let { mode -> put("agentMode", mode) }
418
+ }
419
+ }
340
420
  },
341
421
  audioRoute = audioRoute ?: if (loud(state)) "speaker" else "earpiece",
342
422
  audioOutputs = audioOutputs.map { mapOf("id" to it.id, "kind" to it.kind, "name" to it.name) },
@@ -368,6 +448,19 @@ class CallCore private constructor(context: Context) {
368
448
  val out = snap.toMutableMap()
369
449
  out["serverId"] = serverId
370
450
  out["workspaceName"] = state.callId?.let { ringWorkspaces[it] } ?: servers.get(serverId)?.name
451
+ // A scheduled meeting that rang this device (CA4).
452
+ val meeting = state.callId?.let { ringMeetings[it] }
453
+ out["ringType"] = if (meeting != null) "meeting" else "call"
454
+ out["meetingTitle"] = meeting?.ifEmpty { null }
455
+ out["noiseSuppression"] = noiseSuppression
456
+ out["backgroundBlur"] = backgroundBlur
457
+ out["movedElsewhere"] = movedElsewhere
458
+ // Breakout rooms (MEETINGS.md §5): the room the media is in, null in the main room.
459
+ out["breakout"] = runtime.breakout?.let { (roomId, name) -> mapOf("roomId" to roomId, "name" to name) }
460
+ out["selfIdentity"] = (media as? CallDataSource)?.localIdentity
461
+ // Taken over by another of this user's devices: the machine ends it
462
+ // as `left` (CALL_CONTRACT.md §9); the app is told why.
463
+ if (movedElsewhere && state.phase == Phase.ENDED) out["reason"] = "moved"
371
464
  val waiting = snap["waiting"] as? Map<*, *>
372
465
  val ring = runtime.waitingRing
373
466
  if (waiting != null && ring != null) {
@@ -375,6 +468,8 @@ class CallCore private constructor(context: Context) {
375
468
  out["waiting"] = waiting.entries.associate { (k, v) -> k.toString() to v } + mapOf(
376
469
  "serverId" to waitingServer,
377
470
  "workspaceName" to (ring.workspaceName ?: servers.get(waitingServer)?.name),
471
+ "ringType" to (if (ring.isMeeting) "meeting" else "call"),
472
+ "meetingTitle" to ring.meetingTitle,
378
473
  )
379
474
  }
380
475
  return out
@@ -391,6 +486,7 @@ class CallCore private constructor(context: Context) {
391
486
  roster = emptyList()
392
487
  conversationName = null
393
488
  callKind = "call"
489
+ movedElsewhere = false
394
490
  mutedSelf = false
395
491
  // Reported by the media adapter once the camera is really published.
396
492
  cameraOn = false
@@ -457,7 +553,8 @@ class CallCore private constructor(context: Context) {
457
553
  override fun onRemoteJoined() = runtime.onRemoteJoined()
458
554
  override fun onParticipants(participants: List<MediaParticipant>) {
459
555
  runtime.post { roster = participants }
460
- runtime.onRemoteCount(participants.size)
556
+ // An agent keeps nobody company: a call left with only agents is over.
557
+ runtime.onRemoteCount(participants.count { !it.isAgent })
461
558
  runtime.reemit()
462
559
  }
463
560
  override fun onAudioRoute(route: String) {
@@ -484,6 +581,25 @@ class CallCore private constructor(context: Context) {
484
581
  runtime.post { connectionQuality = quality; this@CallCore.videoPaused = videoPaused }
485
582
  runtime.reemit()
486
583
  }
584
+ override fun onMovedElsewhere() {
585
+ runtime.post { movedElsewhere = true }
586
+ }
587
+ override fun onData(topic: String, payload: ByteArray, fromIdentity: String?, fromName: String?) {
588
+ val text = runCatching {
589
+ Charsets.UTF_8.newDecoder().decode(java.nio.ByteBuffer.wrap(payload)).toString()
590
+ }.getOrNull()
591
+ runCatching {
592
+ dataListener?.invoke(
593
+ mapOf(
594
+ "topic" to topic,
595
+ "payload" to android.util.Base64.encodeToString(payload, android.util.Base64.NO_WRAP),
596
+ "text" to text,
597
+ "fromIdentity" to fromIdentity,
598
+ "fromName" to fromName,
599
+ ),
600
+ )
601
+ }.onFailure { Log.w(TAG, "data listener failed", it) }
602
+ }
487
603
  }
488
604
 
489
605
  private fun bringAppToFront(callId: String, from: Context?): Boolean {
@@ -516,6 +632,15 @@ class CallCore private constructor(context: Context) {
516
632
  */
517
633
  @Volatile var listener: ((Map<String, Any?>?) -> Unit)? = null
518
634
 
635
+ /**
636
+ * The bridge's data-channel subscriber (CL4, CL6): `{topic, payload
637
+ * (base64), text (UTF-8 or null), fromIdentity, fromName}`.
638
+ */
639
+ @Volatile var dataListener: ((Map<String, Any?>) -> Unit)? = null
640
+
641
+ /** The most one data message may carry — the web CallRoom's CALL_DATA_MAX_BYTES. */
642
+ const val DATA_MAX_BYTES = 14_000
643
+
519
644
  /**
520
645
  * Configure the core and PERSIST the inputs. A ring can wake a killed
521
646
  * app: the OS spawns the process cold to run [CallMessagingService],
@@ -747,6 +872,17 @@ interface MediaEvents {
747
872
  * given yet, docs/RECORDING.md §5). Sent on every change.
748
873
  */
749
874
  fun onCanPublish(allowed: Boolean) {}
875
+ /**
876
+ * The SFU replaced us with the same user joining from another device
877
+ * ("move call to this device", CALL_CONTRACT.md §9). Sent just before
878
+ * [onLost].
879
+ */
880
+ fun onMovedElsewhere() {}
881
+ /**
882
+ * A data-channel message from someone in the room (CL4, CL6): its
883
+ * topic, the bytes, and who sent it (null identity: the server).
884
+ */
885
+ fun onData(topic: String, payload: ByteArray, fromIdentity: String?, fromName: String?) {}
750
886
  }
751
887
 
752
888
  /** One place call audio can play — a snapshot `audioOutputs[]` entry. */
@@ -772,4 +908,13 @@ data class MediaParticipant(
772
908
  val externalId: String = identity,
773
909
  /** Their link to the SFU: `good` | `poor` | `lost` (dropped, coming back) | `unknown`. */
774
910
  val connectionQuality: String = "unknown",
911
+ /**
912
+ * An agent in the call (AGENTS_IN_CALLS.md §1): shown with the Agent
913
+ * badge, named [agentLabel], never counted as someone keeping the call up.
914
+ */
915
+ val isAgent: Boolean = false,
916
+ /** "Scout" / "Jasir's agent" — the agent token's `label`. */
917
+ val agentLabel: String? = null,
918
+ /** `notetaker` | `assistant` | `delegate`. */
919
+ val agentMode: String? = null,
775
920
  )
@@ -174,7 +174,10 @@ internal class CallHttpClient(
174
174
  livekitToken = livekit.getString("token"),
175
175
  controlToken = root.optStringOrNull("control_token") ?: current.controlToken,
176
176
  ringing = 0,
177
- // recording / transcription: the current bundle's stand.
177
+ // recording / transcription: the current bundle's stand. A bare
178
+ // refresh is the main room's (servers before breakouts).
179
+ breakoutRoomId = null,
180
+ breakoutName = null,
178
181
  )
179
182
  }
180
183
  return CallSessionBundle(
@@ -193,6 +196,9 @@ internal class CallHttpClient(
193
196
  } ?: 0,
194
197
  recording = call.optJSONObject("recording")?.toString() ?: current?.recording,
195
198
  transcription = call.optJSONObject("transcription")?.toString() ?: current?.transcription,
199
+ // Only a breakout join's bundle names a room; never inherited from [current].
200
+ breakoutRoomId = root.optJSONObject("breakout")?.optStringOrNull("room_id"),
201
+ breakoutName = root.optJSONObject("breakout")?.optStringOrNull("name"),
196
202
  )
197
203
  }
198
204
 
@@ -14,7 +14,9 @@ import dev.poolse.callcore.RingContext
14
14
  *
15
15
  * Contract: data-only messages — rings with `type: "call"`, control
16
16
  * pushes (`ring_ended`, `finished`) and the missed-call notification
17
- * (`missed`) with `type: "call_event"` (CALL_CONTRACT.md §5).
17
+ * (`missed`) with `type: "call_event"` (CALL_CONTRACT.md §5); meeting
18
+ * notices with `type: "meeting"` (MEETINGS.md §11.3); an agent's question
19
+ * with `type: "agent_escalation"` (AGENTS_IN_CALLS.md §5).
18
20
  */
19
21
  class CallMessagingService : FirebaseMessagingService() {
20
22
 
@@ -46,6 +48,20 @@ class CallMessagingService : FirebaseMessagingService() {
46
48
  }
47
49
  return
48
50
  }
51
+ if (type == "meeting") {
52
+ // Scheduled-meeting notices (MEETINGS.md §11.3): "starting" with
53
+ // Join, and the brief. Always shown, even for the open chat.
54
+ if (CallCore.getOrNull(this) == null) return
55
+ MeetingNotification.show(this, data, CallCore.smallIcon(this))
56
+ return
57
+ }
58
+ if (type == "agent_escalation") {
59
+ // Your agent, attending a meeting for you, asks something
60
+ // (AGENTS_IN_CALLS.md §5): Approve / Decline / Answer from here.
61
+ if (CallCore.getOrNull(this) == null) return
62
+ EscalationNotification.show(this, data, CallCore.smallIcon(this))
63
+ return
64
+ }
49
65
  if (type != "call" && type != "call_event") {
50
66
  forwardToHost { it.onMessageReceived(message) }
51
67
  return
@@ -103,6 +119,10 @@ class CallMessagingService : FirebaseMessagingService() {
103
119
  // declined) on the server of its tenant.
104
120
  serverId = ServerRegistry.resolve(this@CallMessagingService, this["tenant_id"])?.id,
105
121
  workspaceName = this["workspace_name"]?.ifEmpty { null },
122
+ // A scheduled meeting starting (CA4): "Weekly sync is starting".
123
+ ringType = this["ring_type"]?.ifEmpty { null },
124
+ meetingTitle = this["meeting_title"]?.ifEmpty { null },
125
+ meetingId = this["meeting_id"]?.ifEmpty { null },
106
126
  )
107
127
  }
108
128
 
@@ -27,6 +27,38 @@ interface ScreenShareSource {
27
27
  fun setScreenShare(on: Boolean, permission: android.content.Intent?)
28
28
  }
29
29
 
30
+ /**
31
+ * Capture processing (CL7), for a media port that can change it mid-call.
32
+ * Noise suppression is the platform's (WebRTC's NS with echo
33
+ * cancellation kept on); background blur needs a video processor.
34
+ */
35
+ interface CaptureProcessingSource {
36
+ val noiseSuppressionSupported: Boolean get() = true
37
+ val backgroundBlurSupported: Boolean get() = false
38
+ /** On by default. Applies to the published microphone at once. */
39
+ fun setNoiseSuppression(on: Boolean)
40
+ /** A no-op where [backgroundBlurSupported] is false. */
41
+ fun setBackgroundBlur(on: Boolean) {}
42
+ }
43
+
44
+ /**
45
+ * The call's data channel (CL4 pointer and drawing on a shared screen,
46
+ * CL6 reactions), for a media port that has one. Messages arrive through
47
+ * [MediaEvents.onData]. Main thread only.
48
+ */
49
+ interface CallDataSource {
50
+ /** Our SFU identity (the poolse user id) while connected; null otherwise. */
51
+ val localIdentity: String?
52
+
53
+ /**
54
+ * Send [data] under [topic] to everyone in the room, or to [to] (SFU
55
+ * identities). `reliable = false` for what is stale a moment later (a
56
+ * moving pointer). [done] false: not connected, over
57
+ * [CallCore.DATA_MAX_BYTES], or refused.
58
+ */
59
+ fun publishData(topic: String, data: ByteArray, reliable: Boolean, to: List<String>, done: (Boolean) -> Unit)
60
+ }
61
+
30
62
  /** One on-screen video slot, bound to a participant's camera or shared screen. */
31
63
  interface CallVideoSurface {
32
64
  /** The Android view to host; it fills its parent. */