@qusaieilouti99/call-manager 0.1.8 → 0.1.10

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,18 +1,12 @@
1
1
  package com.qusaieilouti99.callmanager
2
2
 
3
+ import android.util.Log
3
4
  import android.app.ActivityManager
4
- import android.content.ComponentName
5
5
  import android.content.Context
6
6
  import android.content.Intent
7
7
  import android.os.Build
8
- import android.os.Bundle
9
- import android.telecom.PhoneAccount
10
- import android.telecom.PhoneAccountHandle
11
- import android.telecom.TelecomManager
12
- import android.util.Log
13
8
  import com.facebook.react.bridge.*
14
9
  import com.facebook.react.turbomodule.core.interfaces.TurboModule
15
- import com.facebook.react.bridge.ReactApplicationContext
16
10
  import com.facebook.react.module.annotations.ReactModule
17
11
 
18
12
  @ReactModule(name = CallManagerModule.NAME)
@@ -22,12 +16,10 @@ class CallManagerModule(reactContext: ReactApplicationContext) :
22
16
  companion object {
23
17
  const val NAME = "CallManager"
24
18
  const val TAG = "CallManagerModule"
25
- const val PHONE_ACCOUNT_ID = "com.qusaieilouti99.callmanager.SELF_MANAGED"
26
19
  }
27
20
 
28
21
  private var currentCallId: String? = null
29
22
  private var eventHandler: Callback? = null
30
- private val notificationHelper by lazy { CallNotificationHelper(reactApplicationContext) }
31
23
 
32
24
  override fun getName(): String = NAME
33
25
 
@@ -41,52 +33,18 @@ class CallManagerModule(reactContext: ReactApplicationContext) :
41
33
  eventHandler?.invoke(event, callData)
42
34
  }
43
35
 
44
- // 1. Report incoming call
36
+ // 1. Report incoming call (for JS, not used by NotificationService anymore)
45
37
  override fun reportIncomingCall(callId: String, callData: String) {
46
- Log.d(TAG, "reportIncomingCall called with callId=$callId, callData=$callData")
47
- // Parse caller name from callData (or use a default)
48
- val callerName = try {
49
- val json = org.json.JSONObject(callData)
50
- json.optString("name", "Unknown")
51
- } catch (e: Exception) {
52
- "Unknown"
53
- }
54
-
55
- // Show incoming call notification and play ringtone
56
- notificationHelper.showIncomingCallNotification(callId, callerName)
57
-
58
- val context = reactApplicationContext
59
- val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
60
-
61
- // Register self-managed PhoneAccount if not already registered
62
- val phoneAccountHandle = PhoneAccountHandle(
63
- ComponentName(context, MyConnectionService::class.java),
64
- PHONE_ACCOUNT_ID
65
- )
66
- if (telecomManager.getPhoneAccount(phoneAccountHandle) == null) {
67
- val phoneAccount = PhoneAccount.builder(phoneAccountHandle, "PingMe Call")
68
- .setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)
69
- .build()
70
- telecomManager.registerPhoneAccount(phoneAccount)
71
- }
72
-
73
- // Prepare extras
74
- val extras = Bundle()
75
- extras.putString(MyConnectionService.EXTRA_CALL_DATA, callData)
76
-
77
- // Report the call
78
- try {
79
- telecomManager.addNewIncomingCall(phoneAccountHandle, extras)
80
- currentCallId = callId
81
- startCallForegroundService()
82
- } catch (e: Exception) {
83
- Log.e(TAG, "Failed to report incoming call: ${e.message}")
84
- }
38
+ Log.d(TAG, "reportIncomingCall called from JS with callId=$callId, callData=$callData")
39
+ // Optionally, you can call CallNativeHelper here if you want to trigger from JS
40
+ CallNativeHelper.reportIncomingCall(reactApplicationContext, callId, callData)
85
41
  }
86
42
 
87
43
  // 2. End call
88
44
  override fun endCall(callId: String) {
89
- stopCallForegroundService()
45
+ val context = reactApplicationContext
46
+ val intent = Intent(context, CallForegroundService::class.java)
47
+ context.stopService(intent)
90
48
  }
91
49
 
92
50
  // 3. Answer call
@@ -102,25 +60,7 @@ class CallManagerModule(reactContext: ReactApplicationContext) :
102
60
  // 5. Reject current and answer new
103
61
  override fun rejectCurrentAndAnswerNew(callId: String, callData: String) {
104
62
  endCall(currentCallId ?: "")
105
- reportIncomingCall(callId, callData)
106
- }
107
-
108
- // --- Foreground Service Helpers ---
109
-
110
- private fun startCallForegroundService() {
111
- val context = reactApplicationContext
112
- val intent = Intent(context, CallForegroundService::class.java)
113
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
114
- context.startForegroundService(intent)
115
- } else {
116
- context.startService(intent)
117
- }
118
- }
119
-
120
- private fun stopCallForegroundService() {
121
- val context = reactApplicationContext
122
- val intent = Intent(context, CallForegroundService::class.java)
123
- context.stopService(intent)
63
+ CallNativeHelper.reportIncomingCall(reactApplicationContext, callId, callData)
124
64
  }
125
65
 
126
66
  // --- Bring App to Foreground ---
@@ -0,0 +1,61 @@
1
+ package com.qusaieilouti99.callmanager
2
+
3
+ import android.content.ComponentName
4
+ import android.content.Context
5
+ import android.os.Build
6
+ import android.os.Bundle
7
+ import android.telecom.PhoneAccount
8
+ import android.telecom.PhoneAccountHandle
9
+ import android.telecom.TelecomManager
10
+ import android.util.Log
11
+
12
+ object CallNativeHelper {
13
+ private const val TAG = "CallNativeHelper"
14
+ private const val PHONE_ACCOUNT_ID = "com.qusaieilouti99.callmanager.SELF_MANAGED"
15
+
16
+ fun reportIncomingCall(context: Context, callId: String, callData: String) {
17
+ Log.d(TAG, "reportIncomingCall called with callId=$callId, callData=$callData")
18
+ // Parse caller name from callData (or use a default)
19
+ val callerName = try {
20
+ val json = org.json.JSONObject(callData)
21
+ json.optString("name", "Unknown")
22
+ } catch (e: Exception) {
23
+ "Unknown"
24
+ }
25
+
26
+ // Show incoming call notification and play ringtone
27
+ CallNotificationHelper(context).showIncomingCallNotification(callId, callerName)
28
+
29
+ val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
30
+
31
+ // Register self-managed PhoneAccount if not already registered
32
+ val phoneAccountHandle = PhoneAccountHandle(
33
+ ComponentName(context, MyConnectionService::class.java),
34
+ PHONE_ACCOUNT_ID
35
+ )
36
+ if (telecomManager.getPhoneAccount(phoneAccountHandle) == null) {
37
+ val phoneAccount = PhoneAccount.builder(phoneAccountHandle, "PingMe Call")
38
+ .setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)
39
+ .build()
40
+ telecomManager.registerPhoneAccount(phoneAccount)
41
+ }
42
+
43
+ // Prepare extras
44
+ val extras = Bundle()
45
+ extras.putString(MyConnectionService.EXTRA_CALL_DATA, callData)
46
+
47
+ // Report the call
48
+ try {
49
+ telecomManager.addNewIncomingCall(phoneAccountHandle, extras)
50
+ // Optionally, start foreground service for ongoing call
51
+ val intent = android.content.Intent(context, CallForegroundService::class.java)
52
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
53
+ context.startForegroundService(intent)
54
+ } else {
55
+ context.startService(intent)
56
+ }
57
+ } catch (e: Exception) {
58
+ Log.e(TAG, "Failed to report incoming call: ${e.message}")
59
+ }
60
+ }
61
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qusaieilouti99/call-manager",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "call manager",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",