@poolse/native 0.0.0-stage → 3.0.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +206 -0
  3. package/README.md +148 -2
  4. package/android/build.gradle +58 -0
  5. package/android/consumer-rules.pro +11 -0
  6. package/android/src/main/AndroidManifest.xml +46 -0
  7. package/android/src/main/java/dev/poolse/callcore/CallCoreRuntime.kt +540 -0
  8. package/android/src/main/java/dev/poolse/callcore/CallMachine.kt +492 -0
  9. package/android/src/main/java/dev/poolse/callcore/Ports.kt +132 -0
  10. package/android/src/main/java/dev/poolse/callcore/android/AndroidRingSurface.kt +383 -0
  11. package/android/src/main/java/dev/poolse/callcore/android/CallActionReceiver.kt +45 -0
  12. package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +578 -0
  13. package/android/src/main/java/dev/poolse/callcore/android/CallForegroundService.kt +294 -0
  14. package/android/src/main/java/dev/poolse/callcore/android/CallHttpClient.kt +207 -0
  15. package/android/src/main/java/dev/poolse/callcore/android/CallMessagingService.kt +161 -0
  16. package/android/src/main/java/dev/poolse/callcore/android/CallVideo.kt +36 -0
  17. package/android/src/main/java/dev/poolse/callcore/android/HandlerTimerPort.kt +42 -0
  18. package/android/src/main/java/dev/poolse/callcore/android/IncomingCallActivity.kt +314 -0
  19. package/android/src/main/java/dev/poolse/callcore/android/MessageNotifications.kt +353 -0
  20. package/android/src/main/java/dev/poolse/callcore/android/MissedCallNotification.kt +103 -0
  21. package/android/src/main/java/dev/poolse/callcore/android/RingBundle.kt +42 -0
  22. package/android/src/main/java/dev/poolse/callcore/android/SnapshotJson.kt +99 -0
  23. package/android/src/main/java/expo/modules/poolsecalls/CallLockscreen.kt +42 -0
  24. package/android/src/main/java/expo/modules/poolsecalls/CallPictureInPicture.kt +92 -0
  25. package/android/src/main/java/expo/modules/poolsecalls/PoolseCallVideoView.kt +64 -0
  26. package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +205 -0
  27. package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +594 -0
  28. package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitVideoSurface.kt +107 -0
  29. package/android/src/test/java/dev/poolse/callcore/android/CallHttpClientTest.kt +61 -0
  30. package/app.plugin.js +5 -0
  31. package/dist/index.cjs +197 -0
  32. package/dist/index.cjs.map +1 -0
  33. package/dist/index.d.cts +313 -0
  34. package/dist/index.d.ts +313 -0
  35. package/dist/index.js +161 -0
  36. package/dist/index.js.map +1 -0
  37. package/expo-module.config.json +11 -0
  38. package/ios/Core/CallCoreRuntime.swift +543 -0
  39. package/ios/Core/CallHttpClient.swift +213 -0
  40. package/ios/Core/CallMachine.swift +394 -0
  41. package/ios/Core/PORTS_READY.md +93 -0
  42. package/ios/Core/Ports.swift +238 -0
  43. package/ios/Core/SnapshotEncoding.swift +122 -0
  44. package/ios/Module/PoolseCallVideoView.swift +70 -0
  45. package/ios/Module/PoolseCallsAppDelegateSubscriber.swift +16 -0
  46. package/ios/Module/PoolseCallsModule.swift +150 -0
  47. package/ios/Platform/CallCore.swift +623 -0
  48. package/ios/Platform/CallKitController.swift +326 -0
  49. package/ios/Platform/CallPictureInPicture.swift +145 -0
  50. package/ios/Platform/LiveKitMediaPort.swift +798 -0
  51. package/ios/Platform/LiveKitVideoSurface.swift +68 -0
  52. package/ios/Platform/MessageNotifications.swift +163 -0
  53. package/ios/Platform/Ringback.swift +61 -0
  54. package/ios/Platform/VoipPush.swift +174 -0
  55. package/ios/PoolseCalls.podspec +68 -0
  56. package/package.json +53 -4
  57. package/plugin/index.js +42 -0
  58. package/plugin/package.json +1 -0
  59. package/plugin/withCallDelegate.js +35 -0
  60. package/plugin/withLockscreenCalls.js +84 -0
  61. package/plugin/withNativeCallMedia.js +19 -0
  62. package/plugin/withPictureInPicture.js +28 -0
  63. package/plugin/withRingback.js +86 -0
  64. package/src/expo-modules-core.d.ts +16 -0
  65. package/src/index.ts +564 -0
  66. package/src/react-shims.d.ts +22 -0
@@ -0,0 +1,150 @@
1
+ import ExpoModulesCore
2
+
3
+ /// The React Native face of the native call core on iOS — PoolseCallsModule.kt's
4
+ /// twin, with the same names, arity and return shapes (src/index.ts is shared).
5
+ /// Deliberately thin: commands go to CallCore, snapshots stream out.
6
+ ///
7
+ /// Nothing here throws before `configure`: reads return idle, commands no-op.
8
+ public class PoolseCallsModule: Module {
9
+ public func definition() -> ModuleDefinition {
10
+ Name("PoolseCalls")
11
+
12
+ Events("onCallState", "onVoipToken", "onPictureInPicture")
13
+
14
+ // Normally done at launch by PoolseCallsAppDelegateSubscriber; this is
15
+ // the backstop for a host whose AppDelegate does not forward to Expo.
16
+ OnCreate {
17
+ PoolseCallsSetup.registerVoipEarly()
18
+ }
19
+
20
+ // The listeners are process-level statics read on main: assign and
21
+ // clear them on main too (these closures run on the module's queue).
22
+ OnStartObserving {
23
+ DispatchQueue.main.async { [weak self] in
24
+ guard self != nil else { return }
25
+ CallCore.listener = { [weak self] snapshot in
26
+ self?.sendEvent("onCallState", ["snapshot": snapshot ?? NSNull()])
27
+ }
28
+ VoipPush.tokenListener = { [weak self] token in
29
+ self?.sendEvent("onVoipToken", ["token": token, "environment": PoolseCallsModule.environment()])
30
+ }
31
+ CallPictureInPicture.listener = { [weak self] active in
32
+ self?.sendEvent("onPictureInPicture", ["active": active])
33
+ }
34
+ }
35
+ }
36
+
37
+ OnStopObserving {
38
+ DispatchQueue.main.async {
39
+ CallCore.listener = nil
40
+ VoipPush.tokenListener = nil
41
+ CallPictureInPicture.listener = nil
42
+ }
43
+ }
44
+
45
+ AsyncFunction("configure") { (apiBaseUrl: String, options: [String: Any]?) in
46
+ let env = (options?["apnsEnvironment"] as? String).flatMap { $0 == "production" || $0 == "sandbox" ? $0 : nil }
47
+ CallCore.configure(
48
+ apiBaseUrl: apiBaseUrl,
49
+ ringback: options?["ringback"] as? String,
50
+ apnsEnvironment: env
51
+ )
52
+ // Materialise the core now (and PushKit, if launch did not), so a
53
+ // call already in flight (cold answer) is visible to getCallState.
54
+ PoolseCallsSetup.registerVoipEarly()
55
+ _ = CallCore.getOrNull()
56
+ }.runOnQueue(.main)
57
+
58
+ Function("getCallState") { () -> [String: Any] in
59
+ ["snapshot": CallCore.peek()?.snapshot() ?? NSNull()]
60
+ }
61
+
62
+ AsyncFunction("place") { (conversationId: String, media: String, sessionToken: String) in
63
+ CallCore.getOrNull()?.place(conversationId: conversationId, media: media, sessionToken: sessionToken)
64
+ }.runOnQueue(.main)
65
+
66
+ AsyncFunction("join") { (callId: String, conversationId: String?, sessionToken: String) in
67
+ CallCore.getOrNull()?.join(callId: callId, conversationId: conversationId, sessionToken: sessionToken)
68
+ }.runOnQueue(.main)
69
+
70
+ Function("answer") { onCore { $0.answer() } }
71
+ Function("decline") { onCore { $0.decline() } }
72
+ Function("hangUp") { onCore { $0.hangUp() } }
73
+ Function("answerWaiting") { (callId: String?) in onCore { $0.answerWaiting(callId: callId) } }
74
+ Function("declineWaiting") { (callId: String?) in onCore { $0.declineWaiting(callId: callId) } }
75
+ Function("setMuted") { (muted: Bool) in onCore { $0.setMuted(muted) } }
76
+ Function("setCamera") { (on: Bool) in onCore { $0.setCamera(on) } }
77
+ Function("switchCamera") { onCore { $0.switchCamera() } }
78
+ Function("setSpeaker") { (on: Bool) in onCore { $0.setSpeaker(on) } }
79
+ Function("setAudioOutput") { (id: String) in onCore { $0.setAudioOutput(id) } }
80
+
81
+ // Picture-in-picture: armed while a video call shows someone; the
82
+ // <CallVideoView pictureInPicture> on screen is what it grows out of.
83
+ Function("setPictureInPictureEnabled") { (on: Bool) in
84
+ DispatchQueue.main.async { CallPictureInPicture.shared.setEnabled(on) }
85
+ }
86
+ Function("isInPictureInPicture") { () -> Bool in CallPictureInPicture.shared.active }
87
+ Function("pictureInPictureSupported") { () -> Bool in CallPictureInPicture.supported }
88
+
89
+ // What authorizes acting on the call itself (ringing people in).
90
+ AsyncFunction("callControl") { () -> [String: String]? in
91
+ guard let c = CallCore.getOrNull()?.control else { return nil }
92
+ return ["callId": c.callId, "controlToken": c.controlToken]
93
+ }.runOnQueue(.main)
94
+
95
+ // The chat on screen: opening it clears what was already shown for it.
96
+ // (Suppressing new ones while it is open happens in the app's
97
+ // notification handler — see shouldPresentMessage in src/index.ts.)
98
+ Function("setActiveConversation") { (conversationId: String?) in
99
+ if let conversationId = conversationId { MessageNotifications.clear(conversationId: conversationId) }
100
+ }
101
+
102
+ // Android-only: CallKit owns the lock screen on iOS.
103
+ Function("setShowOnLockscreen") { (_: Bool) in }
104
+
105
+ // Socket forwarding (open app): idempotent with the push path.
106
+ Function("onRingEnded") { (callId: String, reason: String) in
107
+ onCore { $0.onRingEnded(callId: callId, reason: reason) }
108
+ }
109
+ Function("onCallFinished") { (callId: String, reason: String?) in
110
+ let r = (reason?.isEmpty ?? true) ? nil : reason
111
+ onCore { $0.onCallFinished(callId: callId, reason: r) }
112
+ }
113
+
114
+ // Android-only concepts: CallKit owns the lock-screen ring on iOS.
115
+ Function("canUseFullScreenIntent") { () -> Bool in true }
116
+ Function("openFullScreenIntentSettings") { () -> Void in }
117
+
118
+ Function("getVoipToken") { () -> [String: Any]? in
119
+ guard let token = VoipPush.shared.token else { return nil }
120
+ return ["token": token, "environment": PoolseCallsModule.environment()]
121
+ }
122
+
123
+ // <CallVideoView>: a participant's (or our own) camera.
124
+ View(PoolseCallVideoView.self) {
125
+ ViewName("PoolseCallVideo")
126
+ Prop("participantId") { (view: PoolseCallVideoView, id: String?) in view.participantId = id }
127
+ Prop("local") { (view: PoolseCallVideoView, local: Bool?) in view.local = local ?? false }
128
+ Prop("mirror") { (view: PoolseCallVideoView, mirror: Bool?) in view.mirror = mirror }
129
+ Prop("fit") { (view: PoolseCallVideoView, fit: String?) in view.fit = fit ?? "cover" }
130
+ Prop("pictureInPicture") { (view: PoolseCallVideoView, on: Bool?) in view.pictureInPicture = on ?? false }
131
+ OnViewDidUpdateProps { (view: PoolseCallVideoView) in view.apply() }
132
+ }
133
+ }
134
+
135
+ /// The configured APNs environment; unconfigured → the build's default.
136
+ static func environment() -> String {
137
+ if let env = CallCore.apnsEnvironment { return env }
138
+ #if DEBUG
139
+ return "sandbox"
140
+ #else
141
+ return "production"
142
+ #endif
143
+ }
144
+ }
145
+
146
+ /// Run on main against the core; a no-op when never configured.
147
+ private func onCore(_ block: @escaping (CallCore) -> Void) {
148
+ let run = { if let core = CallCore.getOrNull() { block(core) } }
149
+ if Thread.isMainThread { run() } else { DispatchQueue.main.async(execute: run) }
150
+ }