@qusaieilouti99/call-manager 0.1.7 → 0.1.9

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