@capgo/capacitor-stream-call 0.0.24 → 0.0.26

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,5 +1,5 @@
1
1
  package ee.forgr.capacitor.streamcall
2
-
2
+
3
3
  import android.app.Application
4
4
  import android.app.Notification
5
5
  import android.app.NotificationManager
@@ -8,13 +8,17 @@ import android.content.Context
8
8
  import android.content.Intent
9
9
  import android.media.RingtoneManager
10
10
  import android.os.Build
11
+ import android.util.Log
11
12
  import androidx.core.app.NotificationCompat
13
+ import io.getstream.log.taggedLogger
14
+ import io.getstream.video.android.core.RingingState
12
15
  import io.getstream.video.android.core.notifications.DefaultNotificationHandler
16
+ import io.getstream.video.android.core.notifications.NotificationHandler
13
17
  import io.getstream.video.android.model.StreamCallId
14
-
18
+
15
19
  // declare "incoming_calls_custom" as a constant
16
20
  const val INCOMING_CALLS_CUSTOM = "incoming_calls_custom"
17
-
21
+
18
22
  class CustomNotificationHandler(
19
23
  val application: Application,
20
24
  private val endCall: (callId: StreamCallId) -> Unit = {},
@@ -25,17 +29,89 @@ class CustomNotificationHandler(
25
29
  private const val KEY_NOTIFICATION_TIME = "notification_creation_time"
26
30
  }
27
31
  private var allowSound = true;
28
-
29
- override fun getIncomingCallNotification(
32
+
33
+ override fun getRingingCallNotification(
34
+ ringingState: RingingState,
35
+ callId: StreamCallId,
36
+ callDisplayName: String?,
37
+ shouldHaveContentIntent: Boolean,
38
+ ): Notification? {
39
+ return if (ringingState is RingingState.Incoming) {
40
+ val fullScreenPendingIntent = intentResolver.searchIncomingCallPendingIntent(callId)
41
+ val acceptCallPendingIntent = intentResolver.searchAcceptCallPendingIntent(callId)
42
+ val rejectCallPendingIntent = intentResolver.searchRejectCallPendingIntent(callId)
43
+
44
+ if (fullScreenPendingIntent != null && acceptCallPendingIntent != null && rejectCallPendingIntent != null) {
45
+ customGetIncomingCallNotification(
46
+ fullScreenPendingIntent,
47
+ acceptCallPendingIntent,
48
+ rejectCallPendingIntent,
49
+ callDisplayName,
50
+ shouldHaveContentIntent,
51
+ callId
52
+ )
53
+ } else {
54
+ Log.e("CustomNotificationHandler", "Ringing call notification not shown, one of the intents is null.")
55
+ null
56
+ }
57
+ } else if (ringingState is RingingState.Outgoing) {
58
+ val outgoingCallPendingIntent = intentResolver.searchOutgoingCallPendingIntent(callId)
59
+ val endCallPendingIntent = intentResolver.searchEndCallPendingIntent(callId)
60
+
61
+ if (outgoingCallPendingIntent != null && endCallPendingIntent != null) {
62
+ getOngoingCallNotification(
63
+ callId,
64
+ callDisplayName,
65
+ isOutgoingCall = true,
66
+ )
67
+ } else {
68
+ Log.e("CustomNotificationHandler", "Ringing call notification not shown, one of the intents is null.")
69
+ null
70
+ }
71
+ } else {
72
+ null
73
+ }
74
+ }
75
+
76
+ fun customGetIncomingCallNotification(
30
77
  fullScreenPendingIntent: PendingIntent,
31
78
  acceptCallPendingIntent: PendingIntent,
32
79
  rejectCallPendingIntent: PendingIntent,
33
80
  callerName: String?,
34
81
  shouldHaveContentIntent: Boolean,
82
+ callId: StreamCallId
35
83
  ): Notification {
36
-
37
- customCreateIncomingCallChannel()
38
-
84
+
85
+ // customCreateIncomingCallChannel()
86
+ val manufacturer = Build.MANUFACTURER.lowercase()
87
+ if (manufacturer.contains("xiaomi") || manufacturer.contains("mi")) {
88
+ // val serviceIntent = Intent(application, CallForegroundService::class.java)
89
+ // serviceIntent.action = CallForegroundService.ACTION_START_FOREGROUND_SERVICE
90
+ // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
91
+ // application.startForegroundService(serviceIntent)
92
+ // } else {
93
+ // application.startService(serviceIntent)
94
+ // }
95
+ // Adjust PendingIntent for Xiaomi to avoid permission denial
96
+ val xiaomiAcceptIntent = PendingIntent.getActivity(
97
+ application,
98
+ 0,
99
+ Intent("io.getstream.video.android.action.ACCEPT_CALL")
100
+ .setPackage(application.packageName)
101
+ .putExtra(NotificationHandler.INTENT_EXTRA_CALL_CID, callId),
102
+ PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
103
+ )
104
+ return buildNotification(
105
+ fullScreenPendingIntent,
106
+ xiaomiAcceptIntent,
107
+ rejectCallPendingIntent,
108
+ callerName,
109
+ shouldHaveContentIntent,
110
+ INCOMING_CALLS_CUSTOM,
111
+ true // Include sound
112
+ )
113
+ }
114
+
39
115
  return buildNotification(
40
116
  fullScreenPendingIntent,
41
117
  acceptCallPendingIntent,
@@ -46,7 +122,7 @@ class CustomNotificationHandler(
46
122
  true // Include sound
47
123
  )
48
124
  }
49
-
125
+
50
126
  fun buildNotification(
51
127
  fullScreenPendingIntent: PendingIntent,
52
128
  acceptCallPendingIntent: PendingIntent,
@@ -64,10 +140,10 @@ class CustomNotificationHandler(
64
140
  setOngoing(true)
65
141
  setAutoCancel(false)
66
142
  setCategory(NotificationCompat.CATEGORY_CALL)
67
-
143
+
68
144
  // Clear all defaults first
69
145
  setDefaults(0)
70
-
146
+
71
147
  if (includeSound && allowSound) {
72
148
  setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE))
73
149
  setDefaults(NotificationCompat.DEFAULT_VIBRATE or NotificationCompat.DEFAULT_LIGHTS)
@@ -75,7 +151,7 @@ class CustomNotificationHandler(
75
151
  setSound(null)
76
152
  setDefaults(NotificationCompat.DEFAULT_VIBRATE or NotificationCompat.DEFAULT_LIGHTS)
77
153
  }
78
-
154
+
79
155
  // setVibrate(longArrayOf(0, 1000, 500, 1000))
80
156
  setLights(0xFF0000FF.toInt(), 1000, 1000)
81
157
  setFullScreenIntent(fullScreenPendingIntent, true)
@@ -95,12 +171,12 @@ class CustomNotificationHandler(
95
171
  // flags = flags or NotificationCompat.FLAG_ONGOING_EVENT
96
172
  }
97
173
  }
98
-
174
+
99
175
  override fun onMissedCall(callId: StreamCallId, callDisplayName: String) {
100
176
  endCall(callId)
101
177
  super.onMissedCall(callId, callDisplayName)
102
178
  }
103
-
179
+
104
180
  private fun customCreateIncomingCallChannel() {
105
181
  maybeCreateChannel(
106
182
  channelId = INCOMING_CALLS_CUSTOM,
@@ -114,7 +190,7 @@ class CustomNotificationHandler(
114
190
  importance = NotificationManager.IMPORTANCE_HIGH
115
191
  this.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
116
192
  this.setShowBadge(true)
117
-
193
+
118
194
  // Set the channel to be silent since we handle sound via RingtonePlayer
119
195
  setSound(null, null)
120
196
  enableVibration(true)
@@ -126,8 +202,9 @@ class CustomNotificationHandler(
126
202
  },
127
203
  )
128
204
  }
129
-
205
+
130
206
  public fun clone(): CustomNotificationHandler {
131
207
  return CustomNotificationHandler(this.application, this.endCall, this.incomingCall)
132
208
  }
133
209
  }
210
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-stream-call",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "description": "Uses the https://getstream.io/ SDK to implement calling in Capacitor",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",