@qusaieilouti99/call-manager 0.1.61 → 0.1.62

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.
@@ -1,33 +1,62 @@
1
1
  package com.margelo.nitro.qusaieilouti99.callmanager
2
2
 
3
- import com.facebook.proguard.annotations.DoNotStrip
4
3
  import android.util.Log
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.proguard.annotations.DoNotStrip
5
6
 
6
7
  @DoNotStrip
7
- class CallManager : HybridCallManagerSpec() {
8
+ class CallManager : HybridCallManagerSpec() { // Match the parameterless constructor
8
9
 
9
10
  private val TAG = "CallManager"
10
11
 
11
- // Remove problematic initialization - will rely on lazy initialization
12
+ // This method ensures CallEngine has a valid context.
13
+ // It primarily relies on MainApplication.onCreate, but provides a fallback.
12
14
  private fun ensureInitialized() {
13
15
  if (!CallEngine.isInitialized()) {
14
- Log.w(TAG, "CallEngine not yet initialized - this should be handled by the first call requiring context")
16
+ // This log should ideally NOT be seen frequently in production.
17
+ // If it appears, it means CallEngine wasn't initialized by MainApplication.
18
+ Log.e(TAG, "CallEngine not initialized! Attempting late initialization from CallManager.")
19
+ try {
20
+ // For React Native modules (including JSI/Nitro ones),
21
+ // ReactApplicationContext.getCurrentApplicationContext() provides the
22
+ // ReactApplicationContext once the bridge is set up. From there, we get the Application context.
23
+ val reactContext = ReactApplicationContext.getCurrentApplicationContext()
24
+
25
+ if (reactContext != null) {
26
+ val appContext = reactContext.applicationContext
27
+ if (appContext != null) {
28
+ CallEngine.initialize(appContext)
29
+ Log.d(TAG, "CallEngine successfully (late) initialized via ReactApplicationContext.")
30
+ } else {
31
+ Log.e(TAG, "Error: reactContext.applicationContext is null. Cannot late-initialize CallEngine.")
32
+ throw IllegalStateException("CallEngine initialization failed: Application context is null.")
33
+ }
34
+ } else {
35
+ Log.e(TAG, "Error: ReactApplicationContext.getCurrentApplicationContext() returned null. Cannot late-initialize CallEngine.")
36
+ throw IllegalStateException("CallEngine initialization failed: ReactApplicationContext not available.")
37
+ }
38
+ } catch (e: Exception) {
39
+ Log.e(TAG, "Exception during CallEngine late initialization: ${e.message}", e)
40
+ throw IllegalStateException("CallEngine fatal error during initialization: ${e.message}", e)
41
+ }
15
42
  }
16
43
  }
17
44
 
18
- override fun endCall(callId: String) {
45
+ // --- All your overridden methods must call ensureInitialized() first ---
46
+
47
+ override fun endCall(callId: String): Unit {
19
48
  Log.d(TAG, "endCall requested for callId: $callId")
20
49
  ensureInitialized()
21
50
  CallEngine.endCall(callId)
22
51
  }
23
52
 
24
- override fun endAllCalls() {
53
+ override fun endAllCalls(): Unit {
25
54
  Log.d(TAG, "endAllCalls requested")
26
55
  ensureInitialized()
27
56
  CallEngine.endAllCalls()
28
57
  }
29
58
 
30
- override fun silenceRingtone() {
59
+ override fun silenceRingtone(): Unit {
31
60
  Log.d(TAG, "silenceRingtone requested.")
32
61
  ensureInitialized()
33
62
  CallEngine.stopRingtone()
@@ -39,21 +68,19 @@ class CallManager : HybridCallManagerSpec() {
39
68
  return CallEngine.getAudioDevices()
40
69
  }
41
70
 
42
- override fun setAudioRoute(route: String) {
71
+ override fun setAudioRoute(route: String): Unit {
43
72
  Log.d(TAG, "setAudioRoute requested for route: $route")
44
73
  ensureInitialized()
45
74
  CallEngine.setAudioRoute(route)
46
75
  }
47
76
 
48
- override fun keepScreenAwake(keepAwake: Boolean) {
77
+ override fun keepScreenAwake(keepAwake: Boolean): Unit {
49
78
  Log.d(TAG, "keepScreenAwake requested: $keepAwake")
50
79
  ensureInitialized()
51
80
  CallEngine.keepScreenAwake(keepAwake)
52
81
  }
53
82
 
54
- override fun addListener(
55
- listener: (event: CallEventType, payload: String) -> Unit
56
- ): () -> Unit {
83
+ override fun addListener(listener: (event: CallEventType, payload: String) -> Unit): () -> Unit {
57
84
  Log.d(TAG, "addListener called with listener: $listener")
58
85
  ensureInitialized()
59
86
  CallEngine.setEventHandler(listener)
@@ -63,31 +90,32 @@ class CallManager : HybridCallManagerSpec() {
63
90
  }
64
91
  }
65
92
 
66
- override fun startOutgoingCall(callId: String, callType: String, targetName: String, metadata: String?) {
93
+ override fun startOutgoingCall(callId: String, callType: String, targetName: String, metadata: String?): Unit {
67
94
  Log.d(TAG, "startOutgoingCall requested: callId=$callId, callType=$callType, targetName=$targetName")
68
95
  ensureInitialized()
96
+ // IMPORTANT: The Bundle wrapping fix for TelecomManager must still be in CallEngine.startOutgoingCall
69
97
  CallEngine.startOutgoingCall(callId, callType, targetName, metadata)
70
98
  }
71
99
 
72
- override fun startCall(callId: String, callType: String, targetName: String, metadata: String?) {
100
+ override fun startCall(callId: String, callType: String, targetName: String, metadata: String?): Unit {
73
101
  Log.d(TAG, "startCall requested: callId=$callId, callType=$callType, targetName=$targetName")
74
102
  ensureInitialized()
75
103
  CallEngine.startCall(callId, callType, targetName, metadata)
76
104
  }
77
105
 
78
- override fun callAnswered(callId: String) {
106
+ override fun callAnswered(callId: String): Unit {
79
107
  Log.d(TAG, "callAnswered (from JS) requested for callId: $callId")
80
108
  ensureInitialized()
81
109
  CallEngine.callAnsweredFromJS(callId)
82
110
  }
83
111
 
84
- override fun setOnHold(callId: String, onHold: Boolean) {
112
+ override fun setOnHold(callId: String, onHold: Boolean): Unit {
85
113
  Log.d(TAG, "setOnHold requested for callId: $callId, onHold: $onHold")
86
114
  ensureInitialized()
87
115
  CallEngine.setOnHold(callId, onHold)
88
116
  }
89
117
 
90
- override fun setMuted(callId: String, muted: Boolean) {
118
+ override fun setMuted(callId: String, muted: Boolean): Unit {
91
119
  Log.d(TAG, "setMuted requested for callId: $callId, muted: $muted")
92
120
  ensureInitialized()
93
121
  CallEngine.setMuted(callId, muted)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qusaieilouti99/call-manager",
3
- "version": "0.1.61",
3
+ "version": "0.1.62",
4
4
  "description": "Call manager",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",