@qusaieilouti99/call-manager 0.1.60 → 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.
|
@@ -365,47 +365,51 @@ object CallEngine {
|
|
|
365
365
|
}
|
|
366
366
|
|
|
367
367
|
val isVideoCall = callType == "Video"
|
|
368
|
-
|
|
369
368
|
if (!canMakeMultipleCalls && activeCalls.isNotEmpty()) {
|
|
370
|
-
activeCalls.values.
|
|
371
|
-
|
|
372
|
-
holdCallInternal(it.callId, heldBySystem = false)
|
|
373
|
-
}
|
|
374
|
-
}
|
|
369
|
+
activeCalls.values.filter { it.state == CallState.ACTIVE }
|
|
370
|
+
.forEach { holdCallInternal(it.callId, heldBySystem = false) }
|
|
375
371
|
}
|
|
376
372
|
|
|
373
|
+
// Track dialing state
|
|
377
374
|
activeCalls[callId] = CallInfo(callId, callType, targetName, null, CallState.DIALING)
|
|
378
375
|
currentCallId = callId
|
|
379
|
-
Log.d(TAG, "Call $callId added to activeCalls. State: DIALING
|
|
376
|
+
Log.d(TAG, "Call $callId added to activeCalls. State: DIALING")
|
|
380
377
|
|
|
381
378
|
registerPhoneAccount()
|
|
382
379
|
val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
|
|
383
380
|
val phoneAccountHandle = getPhoneAccountHandle()
|
|
384
381
|
val addressUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, targetName, null)
|
|
385
382
|
|
|
386
|
-
|
|
387
|
-
|
|
383
|
+
// 1) build a bundle of ONLY your own keys
|
|
384
|
+
val outgoingExtras = Bundle().apply {
|
|
388
385
|
putString(MyConnectionService.EXTRA_CALL_ID, callId)
|
|
389
386
|
putString(MyConnectionService.EXTRA_CALL_TYPE, callType)
|
|
390
387
|
putString(MyConnectionService.EXTRA_DISPLAY_NAME, targetName)
|
|
391
388
|
putBoolean(MyConnectionService.EXTRA_IS_VIDEO_CALL_BOOLEAN, isVideoCall)
|
|
389
|
+
metadata?.let { putString("metadata", it) }
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// 2) wrap under the single Telecom‐honored key
|
|
393
|
+
val extras = Bundle().apply {
|
|
394
|
+
putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle)
|
|
395
|
+
putBundle(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, outgoingExtras)
|
|
392
396
|
putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, isVideoCall)
|
|
393
397
|
}
|
|
394
398
|
|
|
395
399
|
try {
|
|
396
400
|
telecomManager.placeCall(addressUri, extras)
|
|
397
|
-
startForegroundService()
|
|
401
|
+
startForegroundService()
|
|
398
402
|
requestAudioFocus()
|
|
399
403
|
startRingback()
|
|
400
404
|
bringAppToForeground()
|
|
401
405
|
keepScreenAwake(true)
|
|
402
406
|
setInitialAudioRoute(callType)
|
|
403
|
-
Log.d(TAG, "Successfully reported outgoing call to TelecomManager
|
|
407
|
+
Log.d(TAG, "Successfully reported outgoing call to TelecomManager")
|
|
404
408
|
} catch (e: SecurityException) {
|
|
405
|
-
Log.e(TAG, "SecurityException
|
|
409
|
+
Log.e(TAG, "SecurityException placing outgoing call: ${e.message}", e)
|
|
406
410
|
endCallInternal(callId)
|
|
407
411
|
} catch (e: Exception) {
|
|
408
|
-
Log.e(TAG, "Failed to start outgoing call
|
|
412
|
+
Log.e(TAG, "Failed to start outgoing call: ${e.message}", e)
|
|
409
413
|
endCallInternal(callId)
|
|
410
414
|
}
|
|
411
415
|
|
|
@@ -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
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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)
|