@qusaieilouti99/call-manager 0.1.141 → 0.1.142
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.
|
@@ -64,10 +64,7 @@ object CallEngine {
|
|
|
64
64
|
callEndListeners.remove(l)
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
@Volatile private var _appContext: Context? = null
|
|
69
|
-
val appContext: Context? get() = _appContext
|
|
70
|
-
|
|
67
|
+
@Volatile private var appContext: Context? = null
|
|
71
68
|
private val isInitialized = AtomicBoolean(false)
|
|
72
69
|
private val initializationLock = Any()
|
|
73
70
|
|
|
@@ -103,8 +100,8 @@ object CallEngine {
|
|
|
103
100
|
fun initialize(context: Context) {
|
|
104
101
|
synchronized(initializationLock) {
|
|
105
102
|
if (isInitialized.compareAndSet(false, true)) {
|
|
106
|
-
|
|
107
|
-
audioManager =
|
|
103
|
+
appContext = context.applicationContext
|
|
104
|
+
audioManager = appContext?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
|
|
108
105
|
Log.d(TAG, "CallEngine initialized successfully")
|
|
109
106
|
if (isCallActive()) {
|
|
110
107
|
startForegroundService()
|
|
@@ -116,11 +113,16 @@ object CallEngine {
|
|
|
116
113
|
fun isInitialized(): Boolean = isInitialized.get()
|
|
117
114
|
|
|
118
115
|
private fun requireContext(): Context {
|
|
119
|
-
return
|
|
116
|
+
return appContext ?: throw IllegalStateException(
|
|
120
117
|
"CallEngine not initialized. Call initialize() in Application.onCreate()"
|
|
121
118
|
)
|
|
122
119
|
}
|
|
123
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Get the application context. Returns null if not initialized.
|
|
123
|
+
*/
|
|
124
|
+
fun getContext(): Context? = appContext
|
|
125
|
+
|
|
124
126
|
fun setEventHandler(handler: ((CallEventType, String) -> Unit)?) {
|
|
125
127
|
Log.d(TAG, "setEventHandler called. Handler present: ${handler != null}")
|
|
126
128
|
eventHandler = handler
|
|
@@ -231,20 +233,16 @@ object CallEngine {
|
|
|
231
233
|
return jsonArray.toString()
|
|
232
234
|
}
|
|
233
235
|
|
|
234
|
-
// NEW: Updated method signature - context is optional since we have it internally
|
|
235
236
|
fun reportIncomingCall(
|
|
237
|
+
context: Context,
|
|
236
238
|
callId: String,
|
|
237
239
|
callType: String,
|
|
238
240
|
displayName: String,
|
|
239
241
|
pictureUrl: String? = null,
|
|
240
|
-
metadata: String? = null
|
|
241
|
-
context: Context? = null
|
|
242
|
+
metadata: String? = null
|
|
242
243
|
) {
|
|
243
|
-
// Use provided context or internal context
|
|
244
|
-
val ctx = context ?: requireContext()
|
|
245
|
-
|
|
246
244
|
if (!isInitialized.get()) {
|
|
247
|
-
initialize(
|
|
245
|
+
initialize(context)
|
|
248
246
|
}
|
|
249
247
|
|
|
250
248
|
// NEW: Guard against duplicate calls
|
|
@@ -1385,6 +1383,6 @@ object CallEngine {
|
|
|
1385
1383
|
eventHandler = null
|
|
1386
1384
|
cachedEvents.clear()
|
|
1387
1385
|
isInitialized.set(false)
|
|
1388
|
-
|
|
1386
|
+
appContext = null
|
|
1389
1387
|
}
|
|
1390
1388
|
}
|
|
@@ -118,13 +118,13 @@ class CallManager : HybridCallManagerSpec() {
|
|
|
118
118
|
override fun reportIncomingCall(callId: String, callType: String, targetName: String, metadata: String?) {
|
|
119
119
|
Log.d(TAG, "reportIncomingCall requested: callId=$callId, callType=$callType, targetName=$targetName")
|
|
120
120
|
ensureInitialized()
|
|
121
|
-
// NEW: Updated call - no need to pass context since CallEngine has it internally
|
|
122
121
|
CallEngine.reportIncomingCall(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
requireNotNull(CallEngine.getContext()) { "CallEngine must be initialized with context" },
|
|
123
|
+
callId,
|
|
124
|
+
callType,
|
|
125
|
+
targetName,
|
|
126
|
+
null,
|
|
127
|
+
metadata
|
|
128
128
|
)
|
|
129
129
|
}
|
|
130
130
|
}
|