@qusaieilouti99/call-manager 0.1.61 → 0.1.63

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.
@@ -48,8 +48,12 @@ object CallEngine {
48
48
  private const val FOREGROUND_NOTIF_ID = 1001
49
49
 
50
50
  // Core context - initialized once and maintained
51
+ // Improved context management with thread safety
52
+ @Volatile
51
53
  private var appContext: Context? = null
52
- private var isInitialized = AtomicBoolean(false)
54
+ private val isInitialized = AtomicBoolean(false)
55
+ private val initializationLock = Any()
56
+
53
57
 
54
58
  // Audio & Media
55
59
  private var ringtone: android.media.Ringtone? = null
@@ -83,16 +87,25 @@ object CallEngine {
83
87
  fun onLockScreenBypassChanged(shouldBypass: Boolean)
84
88
  }
85
89
 
86
- // --- INITIALIZATION - Fix for context management ---
90
+ // --- INITIALIZATION with better error handling ---
87
91
  fun initialize(context: Context) {
88
- if (isInitialized.compareAndSet(false, true)) {
89
- appContext = context.applicationContext
90
- audioManager = appContext?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
91
- Log.d(TAG, "CallEngine initialized with context")
92
-
93
- // Initialize foreground service if needed
94
- if (isCallActive()) {
95
- startForegroundService()
92
+ synchronized(initializationLock) {
93
+ if (isInitialized.compareAndSet(false, true)) {
94
+ appContext = context.applicationContext
95
+ audioManager = appContext?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
96
+ Log.d(TAG, "CallEngine initialized successfully with context: ${context.javaClass.simpleName}")
97
+
98
+ // Verify critical services are available
99
+ if (audioManager == null) {
100
+ Log.w(TAG, "AudioManager is null after initialization")
101
+ }
102
+
103
+ // Initialize foreground service if needed
104
+ if (isCallActive()) {
105
+ startForegroundService()
106
+ }
107
+ } else {
108
+ Log.d(TAG, "CallEngine already initialized, skipping")
96
109
  }
97
110
  }
98
111
  }
@@ -100,7 +113,9 @@ object CallEngine {
100
113
  fun isInitialized(): Boolean = isInitialized.get()
101
114
 
102
115
  private fun requireContext(): Context {
103
- return appContext ?: throw IllegalStateException("CallEngine not initialized. Call initialize() first.")
116
+ return appContext ?: throw IllegalStateException(
117
+ "CallEngine not initialized. Ensure CallEngine.initialize(context) is called in Application.onCreate() before any module usage."
118
+ )
104
119
  }
105
120
 
106
121
  // --- Event System ---
@@ -1,33 +1,40 @@
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.proguard.annotations.DoNotStrip
5
5
 
6
6
  @DoNotStrip
7
7
  class CallManager : HybridCallManagerSpec() {
8
8
 
9
9
  private val TAG = "CallManager"
10
10
 
11
- // Remove problematic initialization - will rely on lazy initialization
11
+ // Simplified approach - rely on proper Application.onCreate() initialization
12
+ // Remove all fallback context access attempts that don't work with Nitro modules
12
13
  private fun ensureInitialized() {
13
14
  if (!CallEngine.isInitialized()) {
14
- Log.w(TAG, "CallEngine not yet initialized - this should be handled by the first call requiring context")
15
+ Log.e(TAG, "CallEngine not initialized! This should not happen if Application.onCreate() was called properly.")
16
+ throw IllegalStateException(
17
+ "CallEngine must be initialized in Application.onCreate(). " +
18
+ "Make sure MainApplication.onCreate() calls CallEngine.initialize(this) before any native calls."
19
+ )
15
20
  }
16
21
  }
17
22
 
18
- override fun endCall(callId: String) {
23
+ // --- All methods must call ensureInitialized() first ---
24
+
25
+ override fun endCall(callId: String): Unit {
19
26
  Log.d(TAG, "endCall requested for callId: $callId")
20
27
  ensureInitialized()
21
28
  CallEngine.endCall(callId)
22
29
  }
23
30
 
24
- override fun endAllCalls() {
31
+ override fun endAllCalls(): Unit {
25
32
  Log.d(TAG, "endAllCalls requested")
26
33
  ensureInitialized()
27
34
  CallEngine.endAllCalls()
28
35
  }
29
36
 
30
- override fun silenceRingtone() {
37
+ override fun silenceRingtone(): Unit {
31
38
  Log.d(TAG, "silenceRingtone requested.")
32
39
  ensureInitialized()
33
40
  CallEngine.stopRingtone()
@@ -39,22 +46,20 @@ class CallManager : HybridCallManagerSpec() {
39
46
  return CallEngine.getAudioDevices()
40
47
  }
41
48
 
42
- override fun setAudioRoute(route: String) {
49
+ override fun setAudioRoute(route: String): Unit {
43
50
  Log.d(TAG, "setAudioRoute requested for route: $route")
44
51
  ensureInitialized()
45
52
  CallEngine.setAudioRoute(route)
46
53
  }
47
54
 
48
- override fun keepScreenAwake(keepAwake: Boolean) {
55
+ override fun keepScreenAwake(keepAwake: Boolean): Unit {
49
56
  Log.d(TAG, "keepScreenAwake requested: $keepAwake")
50
57
  ensureInitialized()
51
58
  CallEngine.keepScreenAwake(keepAwake)
52
59
  }
53
60
 
54
- override fun addListener(
55
- listener: (event: CallEventType, payload: String) -> Unit
56
- ): () -> Unit {
57
- Log.d(TAG, "addListener called with listener: $listener")
61
+ override fun addListener(listener: (event: CallEventType, payload: String) -> Unit): () -> Unit {
62
+ Log.d(TAG, "addListener called")
58
63
  ensureInitialized()
59
64
  CallEngine.setEventHandler(listener)
60
65
  return {
@@ -63,31 +68,31 @@ class CallManager : HybridCallManagerSpec() {
63
68
  }
64
69
  }
65
70
 
66
- override fun startOutgoingCall(callId: String, callType: String, targetName: String, metadata: String?) {
71
+ override fun startOutgoingCall(callId: String, callType: String, targetName: String, metadata: String?): Unit {
67
72
  Log.d(TAG, "startOutgoingCall requested: callId=$callId, callType=$callType, targetName=$targetName")
68
73
  ensureInitialized()
69
74
  CallEngine.startOutgoingCall(callId, callType, targetName, metadata)
70
75
  }
71
76
 
72
- override fun startCall(callId: String, callType: String, targetName: String, metadata: String?) {
77
+ override fun startCall(callId: String, callType: String, targetName: String, metadata: String?): Unit {
73
78
  Log.d(TAG, "startCall requested: callId=$callId, callType=$callType, targetName=$targetName")
74
79
  ensureInitialized()
75
80
  CallEngine.startCall(callId, callType, targetName, metadata)
76
81
  }
77
82
 
78
- override fun callAnswered(callId: String) {
83
+ override fun callAnswered(callId: String): Unit {
79
84
  Log.d(TAG, "callAnswered (from JS) requested for callId: $callId")
80
85
  ensureInitialized()
81
86
  CallEngine.callAnsweredFromJS(callId)
82
87
  }
83
88
 
84
- override fun setOnHold(callId: String, onHold: Boolean) {
89
+ override fun setOnHold(callId: String, onHold: Boolean): Unit {
85
90
  Log.d(TAG, "setOnHold requested for callId: $callId, onHold: $onHold")
86
91
  ensureInitialized()
87
92
  CallEngine.setOnHold(callId, onHold)
88
93
  }
89
94
 
90
- override fun setMuted(callId: String, muted: Boolean) {
95
+ override fun setMuted(callId: String, muted: Boolean): Unit {
91
96
  Log.d(TAG, "setMuted requested for callId: $callId, muted: $muted")
92
97
  ensureInitialized()
93
98
  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.63",
4
4
  "description": "Call manager",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",