@qusaieilouti99/call-manager 0.1.49 → 0.1.51

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.
@@ -108,7 +108,7 @@ object CallEngine {
108
108
  }
109
109
  }
110
110
 
111
- private fun emitEvent(type: CallEventType, data: JSONObject) {
111
+ fun emitEvent(type: CallEventType, data: JSONObject) {
112
112
  Log.d(TAG, "Emitting event: $type, data: $data")
113
113
  val dataString = data.toString()
114
114
  if (eventHandler != null) {
@@ -347,6 +347,9 @@ object CallEngine {
347
347
 
348
348
  updateLockScreenBypass()
349
349
 
350
+ // Update foreground notification with call info
351
+ updateForegroundNotification(context)
352
+
350
353
  // Emit event with full call data instead of just callId
351
354
  emitEvent(CallEventType.CALL_ANSWERED, JSONObject().apply {
352
355
  put("callId", callId)
@@ -851,7 +854,21 @@ object CallEngine {
851
854
  // --- Service Management ---
852
855
  fun startForegroundService(context: Context) {
853
856
  Log.d(TAG, "Starting CallForegroundService.")
857
+
858
+ // Find the current active call to pass its info
859
+ val currentCall = activeCalls.values.find {
860
+ it.state == CallState.ACTIVE || it.state == CallState.INCOMING || it.state == CallState.DIALING
861
+ }
862
+
854
863
  val intent = Intent(context, CallForegroundService::class.java)
864
+
865
+ if (currentCall != null) {
866
+ intent.putExtra("callId", currentCall.callId)
867
+ intent.putExtra("callData", currentCall.callData)
868
+ intent.putExtra("state", currentCall.state.name)
869
+ Log.d(TAG, "Starting foreground service with call info: ${currentCall.callId}")
870
+ }
871
+
855
872
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
856
873
  context.startForegroundService(intent)
857
874
  } else {
@@ -30,20 +30,20 @@ class CallForegroundService : Service() {
30
30
  override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
31
31
  Log.d(TAG, "Service onStartCommand")
32
32
 
33
- if (intent?.getBooleanExtra("UPDATE_NOTIFICATION", false) == true) {
34
- // Update existing notification with new call data
35
- val callId = intent.getStringExtra("callId") ?: ""
36
- val callData = intent.getStringExtra("callData") ?: ""
37
- val state = intent.getStringExtra("state") ?: "ACTIVE"
38
-
39
- val notification = buildEnhancedNotification(callId, callData, state)
40
- startForeground(NOTIFICATION_ID, notification)
33
+ // Check if we have call info in the intent
34
+ val callId = intent?.getStringExtra("callId")
35
+ val callData = intent?.getStringExtra("callData")
36
+ val state = intent?.getStringExtra("state")
37
+
38
+ val notification = if (callId != null && callData != null && state != null) {
39
+ Log.d(TAG, "Building enhanced notification with call info: $callId")
40
+ buildEnhancedNotification(callId, callData, state)
41
41
  } else {
42
- // Start with basic notification, will be updated when call info is available
43
- val notification = buildBasicNotification()
44
- startForeground(NOTIFICATION_ID, notification)
42
+ Log.d(TAG, "Building basic notification - no call info available")
43
+ buildBasicNotification()
45
44
  }
46
45
 
46
+ startForeground(NOTIFICATION_ID, notification)
47
47
  return START_STICKY
48
48
  }
49
49
 
@@ -56,12 +56,12 @@ class CallForegroundService : Service() {
56
56
  Log.d(TAG, "Building basic foreground notification.")
57
57
 
58
58
  return NotificationCompat.Builder(this, CHANNEL_ID)
59
- .setContentTitle("Call in Progress")
60
- .setContentText("Managing call...")
59
+ .setContentTitle("Call Service")
60
+ .setContentText("Call service is running...")
61
61
  .setSmallIcon(android.R.drawable.sym_call_incoming)
62
62
  .setOngoing(true)
63
63
  .setCategory(NotificationCompat.CATEGORY_CALL)
64
- .setPriority(NotificationCompat.PRIORITY_HIGH)
64
+ .setPriority(NotificationCompat.PRIORITY_DEFAULT)
65
65
  .setWhen(System.currentTimeMillis())
66
66
  .build()
67
67
  }
@@ -117,37 +117,58 @@ class CallForegroundService : Service() {
117
117
  }
118
118
 
119
119
  val statusText = when (state) {
120
- "ACTIVE" -> "In call with $callerName"
120
+ "ACTIVE" -> "$callerName"
121
121
  "HELD" -> "$callerName (on hold)"
122
122
  "DIALING" -> "Calling $callerName..."
123
- else -> "Call with $callerName"
123
+ "INCOMING" -> "Incoming call from $callerName"
124
+ else -> callerName
125
+ }
126
+
127
+ val titleText = when (state) {
128
+ "ACTIVE" -> "$callType Call Active"
129
+ "HELD" -> "$callType Call Held"
130
+ "DIALING" -> "Outgoing $callType Call"
131
+ "INCOMING" -> "Incoming $callType Call"
132
+ else -> "$callType Call"
124
133
  }
125
134
 
126
- val notification = NotificationCompat.Builder(this, CHANNEL_ID)
127
- .setContentTitle("$callType Call")
135
+ val notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID)
136
+ .setContentTitle(titleText)
128
137
  .setContentText(statusText)
129
138
  .setSmallIcon(android.R.drawable.sym_call_incoming)
130
139
  .setOngoing(true)
131
140
  .setCategory(NotificationCompat.CATEGORY_CALL)
132
141
  .setPriority(NotificationCompat.PRIORITY_HIGH)
133
142
  .setWhen(System.currentTimeMillis())
134
- .addAction(
135
- android.R.drawable.ic_menu_call,
136
- holdText,
137
- holdPendingIntent
138
- )
139
- .addAction(
143
+
144
+ // Add actions for ACTIVE and HELD calls only
145
+ if (state == "ACTIVE" || state == "HELD") {
146
+ notificationBuilder
147
+ .addAction(
148
+ if (isHeld) android.R.drawable.ic_media_play else android.R.drawable.ic_media_pause,
149
+ holdText,
150
+ holdPendingIntent
151
+ )
152
+ .addAction(
153
+ android.R.drawable.sym_call_outgoing,
154
+ "End Call",
155
+ endCallPendingIntent
156
+ )
157
+ } else if (state == "DIALING") {
158
+ // For dialing calls, only show end call
159
+ notificationBuilder.addAction(
140
160
  android.R.drawable.sym_call_outgoing,
141
161
  "End Call",
142
162
  endCallPendingIntent
143
163
  )
164
+ }
144
165
 
145
166
  // Set content intent to open the main app
146
167
  mainPendingIntent?.let {
147
- notification.setContentIntent(it)
168
+ notificationBuilder.setContentIntent(it)
148
169
  }
149
170
 
150
- return notification.build()
171
+ return notificationBuilder.build()
151
172
  }
152
173
 
153
174
  private fun createNotificationChannel() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qusaieilouti99/call-manager",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
4
4
  "description": "Call manager",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",