From 7d4af6c2c34f5b2a0f872753ee0161580e9c4985 Mon Sep 17 00:00:00 2001 From: tung Date: Thu, 21 Dec 2023 17:49:40 +0100 Subject: [PATCH 01/21] report call incoming --- lib/src/connectycube_flutter_call_kit.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/src/connectycube_flutter_call_kit.dart b/lib/src/connectycube_flutter_call_kit.dart index ee23b30..225c093 100644 --- a/lib/src/connectycube_flutter_call_kit.dart +++ b/lib/src/connectycube_flutter_call_kit.dart @@ -51,6 +51,8 @@ class ConnectycubeFlutterCallKit { static CallEventHandler? _onCallAccepted; static CallEventHandler? _onCallRejected; + static CallEventHandler? _onCallIncoming; + /// Initialize the plugin and provided user callbacks. /// /// - This function should only be called once at the beginning of @@ -58,6 +60,7 @@ class ConnectycubeFlutterCallKit { void init( {CallEventHandler? onCallAccepted, CallEventHandler? onCallRejected, + CallEventHandler? onCallIncoming, String? ringtone, String? icon, @Deprecated('Use `AndroidManifest.xml` meta-data instead') @@ -65,6 +68,7 @@ class ConnectycubeFlutterCallKit { String? color}) { _onCallAccepted = onCallAccepted; _onCallRejected = onCallRejected; + _onCallIncoming = onCallIncoming; updateConfig( ringtone: ringtone, @@ -325,6 +329,8 @@ class ConnectycubeFlutterCallKit { break; case 'startCall': + var callEvent = CallEvent.fromMap(arguments); + _onCallIncoming?.call(callEvent); break; case 'setMuted': From 3f76603a41254a9d5d1d9b8aefa8d42e1ff83f19 Mon Sep 17 00:00:00 2001 From: tung Date: Thu, 21 Dec 2023 19:14:50 +0100 Subject: [PATCH 02/21] Add incomingCall event listener --- ios/Classes/CallKitController.swift | 3 +++ lib/src/connectycube_flutter_call_kit.dart | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ios/Classes/CallKitController.swift b/ios/Classes/CallKitController.swift index e574157..50f7232 100644 --- a/ios/Classes/CallKitController.swift +++ b/ios/Classes/CallKitController.swift @@ -10,6 +10,7 @@ import AVFoundation import CallKit enum CallEvent : String { + case incomingCall = "incomingCall" case answerCall = "answerCall" case endCall = "endCall" case setHeld = "setHeld" @@ -125,6 +126,8 @@ class CallKitController : NSObject { self.callStates[uuid] = .pending self.callsData[uuid] = self.currentCallData + + actionListener?(.incomingCall, uuid, self.currentCallData) } } } else if (self.currentCallData["session_id"] as! String == uuid) { diff --git a/lib/src/connectycube_flutter_call_kit.dart b/lib/src/connectycube_flutter_call_kit.dart index 225c093..5349287 100644 --- a/lib/src/connectycube_flutter_call_kit.dart +++ b/lib/src/connectycube_flutter_call_kit.dart @@ -329,8 +329,6 @@ class ConnectycubeFlutterCallKit { break; case 'startCall': - var callEvent = CallEvent.fromMap(arguments); - _onCallIncoming?.call(callEvent); break; case 'setMuted': @@ -341,6 +339,11 @@ class ConnectycubeFlutterCallKit { onCallMuted?.call(false, arguments["session_id"]); break; + case 'incomingCall': + var callEvent = CallEvent.fromMap(arguments); + _onCallIncoming?.call(callEvent); + break; + case '': break; From 46f40dc4d53796c9423669742f15287a0f043f7d Mon Sep 17 00:00:00 2001 From: tung Date: Thu, 21 Dec 2023 19:18:11 +0100 Subject: [PATCH 03/21] Fix UUID conversion issue in CallKitController.swift --- ios/Classes/CallKitController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Classes/CallKitController.swift b/ios/Classes/CallKitController.swift index 50f7232..0976ebe 100644 --- a/ios/Classes/CallKitController.swift +++ b/ios/Classes/CallKitController.swift @@ -127,7 +127,7 @@ class CallKitController : NSObject { self.callStates[uuid] = .pending self.callsData[uuid] = self.currentCallData - actionListener?(.incomingCall, uuid, self.currentCallData) + actionListener?(.incomingCall, UUID(uuidString: uuid)!, self.currentCallData) } } } else if (self.currentCallData["session_id"] as! String == uuid) { From 5cad5a3b281b565b63fb67507f2b3a2e4c41ca16 Mon Sep 17 00:00:00 2001 From: tung Date: Thu, 21 Dec 2023 19:19:39 +0100 Subject: [PATCH 04/21] Fix actionListener bug in CallKitController.swift --- ios/Classes/CallKitController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Classes/CallKitController.swift b/ios/Classes/CallKitController.swift index 0976ebe..2cf563e 100644 --- a/ios/Classes/CallKitController.swift +++ b/ios/Classes/CallKitController.swift @@ -127,7 +127,7 @@ class CallKitController : NSObject { self.callStates[uuid] = .pending self.callsData[uuid] = self.currentCallData - actionListener?(.incomingCall, UUID(uuidString: uuid)!, self.currentCallData) + self.actionListener?(.incomingCall, UUID(uuidString: uuid)!, self.currentCallData) } } } else if (self.currentCallData["session_id"] as! String == uuid) { From 9f3108b179a4b810fa4ee8920b0002012474fdfb Mon Sep 17 00:00:00 2001 From: tung Date: Fri, 22 Dec 2023 15:20:32 +0100 Subject: [PATCH 05/21] Add support for incoming calls --- .../ConnectycubeFCMReceiver.kt | 15 +++++++++++ .../ConnectycubeFlutterCallKitPlugin.kt | 6 +++++ .../Constants.kt | 1 + .../EventReceiver.kt | 26 +++++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index ffc07b1..0f3a24a 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.util.Log +import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.connectycube.flutter.connectycube_flutter_call_kit.utils.ContextHolder import com.google.firebase.messaging.RemoteMessage import org.json.JSONObject @@ -84,6 +85,20 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { return } + if (data["signal_type"] == "startCall") { + val callData = Bundle() + callData.putString(EXTRA_CALL_ID, callId) + callData.putInt(EXTRA_CALL_TYPE, callType) + callData.putInt(EXTRA_CALL_INITIATOR_ID, callInitiatorId) + callData.putString(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) + callData.putIntegerArrayList(EXTRA_CALL_OPPONENTS, callOpponents) + callData.putString(EXTRA_CALL_PHOTO, callPhoto) + callData.putString(EXTRA_CALL_USER_INFO, userInfo) + + LocalBroadcastManager.getInstance(applicationContext) + .sendBroadcast(Intent(ACTION_CALL_INCOMING).putExtra(callData)) + } + showCallNotification( applicationContext, callId, diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt index 1827eeb..d5209d8 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt @@ -525,6 +525,7 @@ class CallStreamHandler(private var context: Context) : EventChannel.StreamHandl val intentFilter = IntentFilter() intentFilter.addAction(ACTION_CALL_REJECT) intentFilter.addAction(ACTION_CALL_ACCEPT) + intentFilter.addAction(ACTION_CALL_INCOMING) localBroadcastManager.registerReceiver(this, intentFilter) } @@ -589,6 +590,11 @@ class CallStreamHandler(private var context: Context) : EventChannel.StreamHandl launchIntent?.action = ACTION_CALL_ACCEPT context.startActivity(launchIntent) } + + ACTION_CALL_INCOMING -> { + callbackData["event"] = "incomingCall" + events?.success(callbackData) + } } } } diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/Constants.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/Constants.kt index 8657536..eff6365 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/Constants.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/Constants.kt @@ -11,6 +11,7 @@ const val EXTRA_CALL_PHOTO = "photo_url" const val ACTION_CALL_ACCEPT = "action_call_accept" const val ACTION_CALL_REJECT = "action_call_reject" +const val ACTION_CALL_INCOMING = "action_call_incoming" const val ACTION_CALL_NOTIFICATION_CANCELED = "action_call_notification_canceled" const val ACTION_CALL_ENDED = "action_call_ended" const val ACTION_TOKEN_REFRESHED = "action_token_refreshed" diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt index 20ab655..513b3bb 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt @@ -19,6 +19,32 @@ class EventReceiver : BroadcastReceiver() { if (intent == null || TextUtils.isEmpty(intent.action)) return when (intent.action) { + ACTION_CALL_INCOMING -> { + val extras = intent.extras + val callId = extras?.getString(EXTRA_CALL_ID) + val callType = extras?.getInt(EXTRA_CALL_TYPE) + val callInitiatorId = extras?.getInt(EXTRA_CALL_INITIATOR_ID) + val callInitiatorName = extras?.getString(EXTRA_CALL_INITIATOR_NAME) + val callOpponents = extras?.getIntegerArrayList(EXTRA_CALL_OPPONENTS) + val callPhoto = extras?.getString(EXTRA_CALL_PHOTO) + val userInfo = extras?.getString(EXTRA_CALL_USER_INFO) + Log.i(TAG, "NotificationReceiver onReceive Call INCOMING, callId: $callId") + + val broadcastIntent = Intent(ACTION_CALL_INCOMING) + val bundle = Bundle() + bundle.putString(EXTRA_CALL_ID, callId) + bundle.putInt(EXTRA_CALL_TYPE, callType!!) + bundle.putInt(EXTRA_CALL_INITIATOR_ID, callInitiatorId!!) + bundle.putString(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) + bundle.putIntegerArrayList(EXTRA_CALL_OPPONENTS, callOpponents) + bundle.putString(EXTRA_CALL_PHOTO, callPhoto) + bundle.putString(EXTRA_CALL_USER_INFO, userInfo) + broadcastIntent.putExtras(bundle) + + LocalBroadcastManager.getInstance(context.applicationContext) + .sendBroadcast(broadcastIntent) + } + ACTION_CALL_REJECT -> { val extras = intent.extras val callId = extras?.getString(EXTRA_CALL_ID) From 51a6aaa7bd265187ddb61a7f617a97d2925080fe Mon Sep 17 00:00:00 2001 From: tung Date: Fri, 22 Dec 2023 15:22:41 +0100 Subject: [PATCH 06/21] Add import for android.os.Bundle --- .../connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index 0f3a24a..5cee64f 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -8,6 +8,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.connectycube.flutter.connectycube_flutter_call_kit.utils.ContextHolder import com.google.firebase.messaging.RemoteMessage import org.json.JSONObject +import android.os.Bundle class ConnectycubeFCMReceiver : BroadcastReceiver() { From be355567e30d0b02005b10394fa50f014c2ce1af Mon Sep 17 00:00:00 2001 From: tung Date: Fri, 22 Dec 2023 15:30:56 +0100 Subject: [PATCH 07/21] Fix FCM receiver callData bundle initialization --- .../ConnectycubeFCMReceiver.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index 5cee64f..41a9334 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -87,14 +87,14 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { } if (data["signal_type"] == "startCall") { - val callData = Bundle() - callData.putString(EXTRA_CALL_ID, callId) - callData.putInt(EXTRA_CALL_TYPE, callType) - callData.putInt(EXTRA_CALL_INITIATOR_ID, callInitiatorId) - callData.putString(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) - callData.putIntegerArrayList(EXTRA_CALL_OPPONENTS, callOpponents) - callData.putString(EXTRA_CALL_PHOTO, callPhoto) - callData.putString(EXTRA_CALL_USER_INFO, userInfo) + val callData = new Bundle() + callData.putString("extra_call_id", callId) + // callData.putInt(EXTRA_CALL_TYPE, callType) + // callData.putInt(EXTRA_CALL_INITIATOR_ID, callInitiatorId) + // callData.putString(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) + // callData.putIntegerArrayList(EXTRA_CALL_OPPONENTS, callOpponents) + // callData.putString(EXTRA_CALL_PHOTO, callPhoto) + // callData.putString(EXTRA_CALL_USER_INFO, userInfo) LocalBroadcastManager.getInstance(applicationContext) .sendBroadcast(Intent(ACTION_CALL_INCOMING).putExtra(callData)) From fab28c309d5d308823396714c5a2ac03a394aa47 Mon Sep 17 00:00:00 2001 From: tung Date: Fri, 22 Dec 2023 15:32:47 +0100 Subject: [PATCH 08/21] Commented out unused code and simplified intent extra in ConnectycubeFCMReceiver --- .../ConnectycubeFCMReceiver.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index 41a9334..f40cf62 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -87,8 +87,8 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { } if (data["signal_type"] == "startCall") { - val callData = new Bundle() - callData.putString("extra_call_id", callId) + // val callData = new Bundle() + // callData.putString("extra_call_id", callId) // callData.putInt(EXTRA_CALL_TYPE, callType) // callData.putInt(EXTRA_CALL_INITIATOR_ID, callInitiatorId) // callData.putString(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) @@ -97,7 +97,7 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { // callData.putString(EXTRA_CALL_USER_INFO, userInfo) LocalBroadcastManager.getInstance(applicationContext) - .sendBroadcast(Intent(ACTION_CALL_INCOMING).putExtra(callData)) + .sendBroadcast(Intent(ACTION_CALL_INCOMING).putExtra("extra_call_id", callId)) } showCallNotification( From ffef45eb034ed9201c3616bbc654072348f8f8a4 Mon Sep 17 00:00:00 2001 From: tung Date: Fri, 22 Dec 2023 15:35:46 +0100 Subject: [PATCH 09/21] Add logging statements for startCall signal type --- .../ConnectycubeFCMReceiver.kt | 3 ++- .../connectycube_flutter_call_kit/EventReceiver.kt | 14 +------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index f40cf62..181922e 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -87,6 +87,7 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { } if (data["signal_type"] == "startCall") { + Log.d(TAG, "[processInviteCallEvent] data[signal_type] == startCall") // val callData = new Bundle() // callData.putString("extra_call_id", callId) // callData.putInt(EXTRA_CALL_TYPE, callType) @@ -97,7 +98,7 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { // callData.putString(EXTRA_CALL_USER_INFO, userInfo) LocalBroadcastManager.getInstance(applicationContext) - .sendBroadcast(Intent(ACTION_CALL_INCOMING).putExtra("extra_call_id", callId)) + .sendBroadcast(Intent(ACTION_CALL_INCOMING).putExtra(EXTRA_CALL_ID, callId)) } showCallNotification( diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt index 513b3bb..edc8573 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt @@ -22,23 +22,11 @@ class EventReceiver : BroadcastReceiver() { ACTION_CALL_INCOMING -> { val extras = intent.extras val callId = extras?.getString(EXTRA_CALL_ID) - val callType = extras?.getInt(EXTRA_CALL_TYPE) - val callInitiatorId = extras?.getInt(EXTRA_CALL_INITIATOR_ID) - val callInitiatorName = extras?.getString(EXTRA_CALL_INITIATOR_NAME) - val callOpponents = extras?.getIntegerArrayList(EXTRA_CALL_OPPONENTS) - val callPhoto = extras?.getString(EXTRA_CALL_PHOTO) - val userInfo = extras?.getString(EXTRA_CALL_USER_INFO) - Log.i(TAG, "NotificationReceiver onReceive Call INCOMING, callId: $callId") + Log.d(TAG, "NotificationReceiver onReceive Call INCOMING, callId: $callId") val broadcastIntent = Intent(ACTION_CALL_INCOMING) val bundle = Bundle() bundle.putString(EXTRA_CALL_ID, callId) - bundle.putInt(EXTRA_CALL_TYPE, callType!!) - bundle.putInt(EXTRA_CALL_INITIATOR_ID, callInitiatorId!!) - bundle.putString(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) - bundle.putIntegerArrayList(EXTRA_CALL_OPPONENTS, callOpponents) - bundle.putString(EXTRA_CALL_PHOTO, callPhoto) - bundle.putString(EXTRA_CALL_USER_INFO, userInfo) broadcastIntent.putExtras(bundle) LocalBroadcastManager.getInstance(context.applicationContext) From e3441e2a6dbecad345e672cdc4e9be46f9583297 Mon Sep 17 00:00:00 2001 From: tung Date: Fri, 22 Dec 2023 15:39:55 +0100 Subject: [PATCH 10/21] Add log statement for incoming call event --- .../connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index 181922e..41e4bb3 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -99,6 +99,8 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { LocalBroadcastManager.getInstance(applicationContext) .sendBroadcast(Intent(ACTION_CALL_INCOMING).putExtra(EXTRA_CALL_ID, callId)) + + Log.d(TAG, "[processInviteCallEvent] ACTION_CALL_INCOMING sent") } showCallNotification( From 5298e7150378b75a756ba5bfdb9fa6200cd68bf7 Mon Sep 17 00:00:00 2001 From: tung Date: Fri, 22 Dec 2023 15:44:10 +0100 Subject: [PATCH 11/21] Add logging statements in onReceive methods --- .../ConnectycubeFlutterCallKitPlugin.kt | 2 ++ .../flutter/connectycube_flutter_call_kit/EventReceiver.kt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt index d5209d8..16db18b 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt @@ -537,6 +537,8 @@ class CallStreamHandler(private var context: Context) : EventChannel.StreamHandl override fun onReceive(context: Context?, intent: Intent?) { if (intent == null || TextUtils.isEmpty(intent.action)) return + Log.d("ConnectycubeFlutterCallKitPlugin", "onReceive action: ${intent.action}") + val action: String? = intent.action if (ACTION_TOKEN_REFRESHED == action) { diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt index edc8573..6d704a6 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt @@ -18,6 +18,8 @@ class EventReceiver : BroadcastReceiver() { if (intent == null || TextUtils.isEmpty(intent.action)) return + Log.d(TAG, "NotificationReceiver onReceive action: ${intent.action}") + when (intent.action) { ACTION_CALL_INCOMING -> { val extras = intent.extras From 7889fbc75600ce6aef28070817c86a121ce9bb8a Mon Sep 17 00:00:00 2001 From: tung Date: Fri, 22 Dec 2023 16:27:36 +0100 Subject: [PATCH 12/21] Refactor ConnectycubeFCMReceiver to use Intent extras instead of Bundle --- .../ConnectycubeFCMReceiver.kt | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index 41e4bb3..a22ca22 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -87,20 +87,17 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { } if (data["signal_type"] == "startCall") { - Log.d(TAG, "[processInviteCallEvent] data[signal_type] == startCall") - // val callData = new Bundle() - // callData.putString("extra_call_id", callId) - // callData.putInt(EXTRA_CALL_TYPE, callType) - // callData.putInt(EXTRA_CALL_INITIATOR_ID, callInitiatorId) - // callData.putString(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) - // callData.putIntegerArrayList(EXTRA_CALL_OPPONENTS, callOpponents) - // callData.putString(EXTRA_CALL_PHOTO, callPhoto) - // callData.putString(EXTRA_CALL_USER_INFO, userInfo) + val intent = Intent(ACTION_CALL_INCOMING) + .putExtra(EXTRA_CALL_ID, callId) + .putExtra(EXTRA_CALL_TYPE, callType) + .putExtra(EXTRA_CALL_INITIATOR_ID, callInitiatorId) + .putExtra(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) + .putExtra(EXTRA_CALL_OPPONENTS, callOpponentsString) + .putExtra(EXTRA_CALL_PHOTO, callPhoto) + .putExtra(EXTRA_CALL_USER_INFO, userInfo) LocalBroadcastManager.getInstance(applicationContext) - .sendBroadcast(Intent(ACTION_CALL_INCOMING).putExtra(EXTRA_CALL_ID, callId)) - - Log.d(TAG, "[processInviteCallEvent] ACTION_CALL_INCOMING sent") + .sendBroadcast(intent) } showCallNotification( From c8ad586aeced04a412b3c426d57b0da78532774e Mon Sep 17 00:00:00 2001 From: tung Date: Fri, 22 Dec 2023 16:31:15 +0100 Subject: [PATCH 13/21] Refactor FCM receiver and call plugin --- .../connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt | 2 ++ .../ConnectycubeFlutterCallKitPlugin.kt | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index a22ca22..f3ee3e8 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -98,6 +98,8 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { LocalBroadcastManager.getInstance(applicationContext) .sendBroadcast(intent) + + Log.d(TAG, "[processInviteCallEvent] sendBroadcast ACTION_CALL_INCOMING $callId") } showCallNotification( diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt index 16db18b..511e739 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt @@ -537,8 +537,6 @@ class CallStreamHandler(private var context: Context) : EventChannel.StreamHandl override fun onReceive(context: Context?, intent: Intent?) { if (intent == null || TextUtils.isEmpty(intent.action)) return - Log.d("ConnectycubeFlutterCallKitPlugin", "onReceive action: ${intent.action}") - val action: String? = intent.action if (ACTION_TOKEN_REFRESHED == action) { @@ -553,8 +551,11 @@ class CallStreamHandler(private var context: Context) : EventChannel.StreamHandl } else if (ACTION_CALL_REJECT != action && ACTION_CALL_ACCEPT != action) { return } + Log.d("ConnectycubeFlutterCallKitPlugin", "onReceive action: ${intent.action}") val callIdToProcess: String? = intent.getStringExtra(EXTRA_CALL_ID) + Log.d("ConnectycubeFlutterCallKitPlugin", "callIdToProcess: $callIdToProcess") + if (TextUtils.isEmpty(callIdToProcess)) return val callEventMap = HashMap() From c6dbd743068cb4b30861ff6295b96949bc8d4792 Mon Sep 17 00:00:00 2001 From: tung Date: Fri, 22 Dec 2023 16:37:11 +0100 Subject: [PATCH 14/21] Fix handling of incoming calls in CallStreamHandler --- .../ConnectycubeFlutterCallKitPlugin.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt index 511e739..4be8aef 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt @@ -548,13 +548,11 @@ class CallStreamHandler(private var context: Context) : EventChannel.StreamHandl events?.success(parameters) return - } else if (ACTION_CALL_REJECT != action && ACTION_CALL_ACCEPT != action) { + } else if (ACTION_CALL_REJECT != action && ACTION_CALL_ACCEPT != action && ACTION_CALL_INCOMING != action) { return } - Log.d("ConnectycubeFlutterCallKitPlugin", "onReceive action: ${intent.action}") val callIdToProcess: String? = intent.getStringExtra(EXTRA_CALL_ID) - Log.d("ConnectycubeFlutterCallKitPlugin", "callIdToProcess: $callIdToProcess") if (TextUtils.isEmpty(callIdToProcess)) return From 6b5c22dc403eeccfb7b7f5f270ecfebe3777134a Mon Sep 17 00:00:00 2001 From: tung Date: Fri, 22 Dec 2023 19:27:11 +0100 Subject: [PATCH 15/21] Add support for incoming calls in background --- .../ConnectycubeFCMReceiver.kt | 2 +- .../ConnectycubeFlutterCallKitPlugin.kt | 20 +++++++++++++++- .../Constants.kt | 1 + .../EventReceiver.kt | 23 ++++++++++++++++++- .../FlutterConnectycubeBackgroundExecutor.kt | 2 ++ lib/src/connectycube_flutter_call_kit.dart | 16 +++++++++++++ 6 files changed, 61 insertions(+), 3 deletions(-) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index f3ee3e8..e67dad1 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -92,7 +92,7 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { .putExtra(EXTRA_CALL_TYPE, callType) .putExtra(EXTRA_CALL_INITIATOR_ID, callInitiatorId) .putExtra(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) - .putExtra(EXTRA_CALL_OPPONENTS, callOpponentsString) + .putExtra(EXTRA_CALL_OPPONENTS, callOpponents) .putExtra(EXTRA_CALL_PHOTO, callPhoto) .putExtra(EXTRA_CALL_USER_INFO, userInfo) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt index 4be8aef..e788980 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt @@ -86,6 +86,7 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, } "startBackgroundIsolate" -> { + @Suppress("UNCHECKED_CAST") val arguments: Map = call.arguments as Map @@ -94,7 +95,6 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, val userCallbackHandleName: String = arguments["userCallbackHandleName"]?.toString() ?: "" - val arg1 = arguments["pluginCallbackHandle"] ?: -1L val arg2 = arguments["userCallbackHandle"] ?: -1L @@ -126,6 +126,8 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, saveBackgroundRejectHandler(applicationContext, userCallbackHandle) } else if (ACCEPTED_IN_BACKGROUND == userCallbackHandleName) { saveBackgroundAcceptHandler(applicationContext, userCallbackHandle) + } else if (INCOMING_IN_BACKGROUND == userCallbackHandleName) { + saveBackgroundIncomingCallHandler(applicationContext, userCallbackHandle) } ConnectycubeFlutterBgPerformingService.startBackgroundIsolate( @@ -468,6 +470,22 @@ fun getBackgroundAcceptHandler(applicationContext: Context?): Long { return getLong(applicationContext, "background_callback_accept") } +fun saveBackgroundIncomingCallHandler(applicationContext: Context?, callbackId: Long) { + if (applicationContext == null) return + + try { + putLong(applicationContext, "background_callback_incoming_call", callbackId) + } catch (e: Exception) { + // ignore + } +} + +fun getBackgroundIncomingCallHandler(applicationContext: Context?): Long { + if (applicationContext == null) return -1L + + return getLong(applicationContext, "background_callback_incoming_call") +} + fun saveBackgroundRejectHandler(applicationContext: Context?, callbackId: Long) { if (applicationContext == null) return diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/Constants.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/Constants.kt index eff6365..fc014c9 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/Constants.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/Constants.kt @@ -18,6 +18,7 @@ const val ACTION_TOKEN_REFRESHED = "action_token_refreshed" const val REJECTED_IN_BACKGROUND = "rejected_in_background" const val ACCEPTED_IN_BACKGROUND = "accepted_in_background" +const val INCOMING_IN_BACKGROUND = "incoming_in_background" const val CALL_TYPE_PLACEHOLDER = "Incoming %s call" diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt index 6d704a6..6c673e5 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt @@ -14,6 +14,7 @@ import com.connectycube.flutter.connectycube_flutter_call_kit.utils.isApplicatio class EventReceiver : BroadcastReceiver() { private val TAG = "EventReceiver" + override fun onReceive(context: Context, intent: Intent?) { if (intent == null || TextUtils.isEmpty(intent.action)) return @@ -24,15 +25,35 @@ class EventReceiver : BroadcastReceiver() { ACTION_CALL_INCOMING -> { val extras = intent.extras val callId = extras?.getString(EXTRA_CALL_ID) - Log.d(TAG, "NotificationReceiver onReceive Call INCOMING, callId: $callId") + val callType = extras?.getInt(EXTRA_CALL_TYPE) + val callInitiatorId = extras?.getInt(EXTRA_CALL_INITIATOR_ID) + val callInitiatorName = extras?.getString(EXTRA_CALL_INITIATOR_NAME) + val callOpponents = extras?.getIntegerArrayList(EXTRA_CALL_OPPONENTS) + val callPhoto = extras?.getString(EXTRA_CALL_PHOTO) + val userInfo = extras?.getString(EXTRA_CALL_USER_INFO) + Log.i(TAG, "NotificationReceiver onReceive Call INCOMING, callId: $callId") val broadcastIntent = Intent(ACTION_CALL_INCOMING) val bundle = Bundle() bundle.putString(EXTRA_CALL_ID, callId) + bundle.putInt(EXTRA_CALL_TYPE, callType!!) + bundle.putInt(EXTRA_CALL_INITIATOR_ID, callInitiatorId!!) + bundle.putString(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) + bundle.putIntegerArrayList(EXTRA_CALL_OPPONENTS, callOpponents) + bundle.putString(EXTRA_CALL_PHOTO, callPhoto) + bundle.putString(EXTRA_CALL_USER_INFO, userInfo) broadcastIntent.putExtras(bundle) LocalBroadcastManager.getInstance(context.applicationContext) .sendBroadcast(broadcastIntent) + + if (!isApplicationForeground(context)) { + broadcastIntent.putExtra("userCallbackHandleName", INCOMING_IN_BACKGROUND) + ConnectycubeFlutterBgPerformingService.enqueueMessageProcessing( + context, + broadcastIntent + ) + } } ACTION_CALL_REJECT -> { diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/background_isolates/FlutterConnectycubeBackgroundExecutor.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/background_isolates/FlutterConnectycubeBackgroundExecutor.kt index 2e2895c..68dc66c 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/background_isolates/FlutterConnectycubeBackgroundExecutor.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/background_isolates/FlutterConnectycubeBackgroundExecutor.kt @@ -213,6 +213,8 @@ class FlutterConnectycubeBackgroundExecutor : MethodCallHandler { userCallbackHandle = getBackgroundRejectHandler(ContextHolder.applicationContext) } else if (ACCEPTED_IN_BACKGROUND == callEventName) { userCallbackHandle = getBackgroundAcceptHandler(ContextHolder.applicationContext) + } else if (INCOMING_IN_BACKGROUND == callEventName) { + userCallbackHandle = getBackgroundIncomingCallHandler(ContextHolder.applicationContext) } if (userCallbackHandle == -1L) { diff --git a/lib/src/connectycube_flutter_call_kit.dart b/lib/src/connectycube_flutter_call_kit.dart index 5349287..2ac0b63 100644 --- a/lib/src/connectycube_flutter_call_kit.dart +++ b/lib/src/connectycube_flutter_call_kit.dart @@ -47,6 +47,7 @@ class ConnectycubeFlutterCallKit { static CallEventHandler? _onCallRejectedWhenTerminated; static CallEventHandler? _onCallAcceptedWhenTerminated; + static CallEventHandler? _onCallIncomingWhenTerminated; static CallEventHandler? _onCallAccepted; static CallEventHandler? _onCallRejected; @@ -107,6 +108,20 @@ class ConnectycubeFlutterCallKit { } } + /// Set an incoming call handler function which is called when the app is in the + /// background or terminated. + /// + /// This provided handler must be a top-level function and cannot be + /// anonymous otherwise an [ArgumentError] will be thrown. + static set onCallIncomingWhenTerminated(CallEventHandler? handler) { + _onCallIncomingWhenTerminated = handler; + + if (handler != null) { + instance._registerBackgroundCallEventHandler( + handler, BackgroundCallbackName.INCOMING_IN_BACKGROUND); + } + } + Future _registerBackgroundCallEventHandler( CallEventHandler handler, String callbackName) async { if (!Platform.isAndroid) { @@ -408,4 +423,5 @@ class CallState { class BackgroundCallbackName { static const String REJECTED_IN_BACKGROUND = "rejected_in_background"; static const String ACCEPTED_IN_BACKGROUND = "accepted_in_background"; + static const String INCOMING_IN_BACKGROUND = "incoming_in_background"; } From 3355c132a75f637652735a0143b3fe1e1ccbc773 Mon Sep 17 00:00:00 2001 From: tung Date: Thu, 4 Jan 2024 16:30:22 +0100 Subject: [PATCH 16/21] Add background message processing for incoming calls --- .../ConnectycubeFCMReceiver.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index e67dad1..3df28e0 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -99,6 +99,13 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { LocalBroadcastManager.getInstance(applicationContext) .sendBroadcast(intent) + if (!isApplicationForeground(applicationContext)) { + ConnectycubeFlutterBgPerformingService.enqueueMessageProcessing( + context, + intent + ) + } + Log.d(TAG, "[processInviteCallEvent] sendBroadcast ACTION_CALL_INCOMING $callId") } From c2bd80e527a685b68f81cee062d79e229a5b0c12 Mon Sep 17 00:00:00 2001 From: tung Date: Thu, 4 Jan 2024 17:03:41 +0100 Subject: [PATCH 17/21] callincoming for android --- .../ConnectycubeFCMReceiver.kt | 13 ++++--- .../EventReceiver.kt | 34 ------------------- .../FlutterConnectycubeBackgroundExecutor.kt | 2 +- 3 files changed, 9 insertions(+), 40 deletions(-) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index 3df28e0..6e74b9d 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -9,6 +9,8 @@ import com.connectycube.flutter.connectycube_flutter_call_kit.utils.ContextHolde import com.google.firebase.messaging.RemoteMessage import org.json.JSONObject import android.os.Bundle +import com.connectycube.flutter.connectycube_flutter_call_kit.background_isolates.ConnectycubeFlutterBgPerformingService +import com.connectycube.flutter.connectycube_flutter_call_kit.utils.isApplicationForeground class ConnectycubeFCMReceiver : BroadcastReceiver() { @@ -96,12 +98,13 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { .putExtra(EXTRA_CALL_PHOTO, callPhoto) .putExtra(EXTRA_CALL_USER_INFO, userInfo) - LocalBroadcastManager.getInstance(applicationContext) - .sendBroadcast(intent) - - if (!isApplicationForeground(applicationContext)) { + if (isApplicationForeground(applicationContext)) { + LocalBroadcastManager.getInstance(applicationContext) + .sendBroadcast(intent) + } else { + intent.putExtra("userCallbackHandleName", INCOMING_IN_BACKGROUND) ConnectycubeFlutterBgPerformingService.enqueueMessageProcessing( - context, + applicationContext, intent ) } diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt index 6c673e5..c527292 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt @@ -22,40 +22,6 @@ class EventReceiver : BroadcastReceiver() { Log.d(TAG, "NotificationReceiver onReceive action: ${intent.action}") when (intent.action) { - ACTION_CALL_INCOMING -> { - val extras = intent.extras - val callId = extras?.getString(EXTRA_CALL_ID) - val callType = extras?.getInt(EXTRA_CALL_TYPE) - val callInitiatorId = extras?.getInt(EXTRA_CALL_INITIATOR_ID) - val callInitiatorName = extras?.getString(EXTRA_CALL_INITIATOR_NAME) - val callOpponents = extras?.getIntegerArrayList(EXTRA_CALL_OPPONENTS) - val callPhoto = extras?.getString(EXTRA_CALL_PHOTO) - val userInfo = extras?.getString(EXTRA_CALL_USER_INFO) - Log.i(TAG, "NotificationReceiver onReceive Call INCOMING, callId: $callId") - - val broadcastIntent = Intent(ACTION_CALL_INCOMING) - val bundle = Bundle() - bundle.putString(EXTRA_CALL_ID, callId) - bundle.putInt(EXTRA_CALL_TYPE, callType!!) - bundle.putInt(EXTRA_CALL_INITIATOR_ID, callInitiatorId!!) - bundle.putString(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) - bundle.putIntegerArrayList(EXTRA_CALL_OPPONENTS, callOpponents) - bundle.putString(EXTRA_CALL_PHOTO, callPhoto) - bundle.putString(EXTRA_CALL_USER_INFO, userInfo) - broadcastIntent.putExtras(bundle) - - LocalBroadcastManager.getInstance(context.applicationContext) - .sendBroadcast(broadcastIntent) - - if (!isApplicationForeground(context)) { - broadcastIntent.putExtra("userCallbackHandleName", INCOMING_IN_BACKGROUND) - ConnectycubeFlutterBgPerformingService.enqueueMessageProcessing( - context, - broadcastIntent - ) - } - } - ACTION_CALL_REJECT -> { val extras = intent.extras val callId = extras?.getString(EXTRA_CALL_ID) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/background_isolates/FlutterConnectycubeBackgroundExecutor.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/background_isolates/FlutterConnectycubeBackgroundExecutor.kt index 68dc66c..7039d93 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/background_isolates/FlutterConnectycubeBackgroundExecutor.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/background_isolates/FlutterConnectycubeBackgroundExecutor.kt @@ -220,7 +220,7 @@ class FlutterConnectycubeBackgroundExecutor : MethodCallHandler { if (userCallbackHandle == -1L) { Log.e( "FlutterConnectycubeBackgroundExecutor", - "No one background handler has been registered." + "${intent.action} background handler has not been registered." ) return } From 29f1b0cd731837b2a15bc5ec0a1e1ac64ce0b3ea Mon Sep 17 00:00:00 2001 From: tung Date: Sat, 6 Jan 2024 16:46:28 +0100 Subject: [PATCH 18/21] refactor --- .../ConnectycubeFCMReceiver.kt | 38 ++++++------------- .../ConnectycubeFlutterCallKitPlugin.kt | 27 +++++++++++++ 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index 6e74b9d..5e3bb21 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -4,13 +4,10 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.util.Log -import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.connectycube.flutter.connectycube_flutter_call_kit.utils.ContextHolder import com.google.firebase.messaging.RemoteMessage import org.json.JSONObject import android.os.Bundle -import com.connectycube.flutter.connectycube_flutter_call_kit.background_isolates.ConnectycubeFlutterBgPerformingService -import com.connectycube.flutter.connectycube_flutter_call_kit.utils.isApplicationForeground class ConnectycubeFCMReceiver : BroadcastReceiver() { @@ -88,30 +85,17 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() { return } - if (data["signal_type"] == "startCall") { - val intent = Intent(ACTION_CALL_INCOMING) - .putExtra(EXTRA_CALL_ID, callId) - .putExtra(EXTRA_CALL_TYPE, callType) - .putExtra(EXTRA_CALL_INITIATOR_ID, callInitiatorId) - .putExtra(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) - .putExtra(EXTRA_CALL_OPPONENTS, callOpponents) - .putExtra(EXTRA_CALL_PHOTO, callPhoto) - .putExtra(EXTRA_CALL_USER_INFO, userInfo) - - if (isApplicationForeground(applicationContext)) { - LocalBroadcastManager.getInstance(applicationContext) - .sendBroadcast(intent) - } else { - intent.putExtra("userCallbackHandleName", INCOMING_IN_BACKGROUND) - ConnectycubeFlutterBgPerformingService.enqueueMessageProcessing( - applicationContext, - intent - ) - } - - Log.d(TAG, "[processInviteCallEvent] sendBroadcast ACTION_CALL_INCOMING $callId") - } - + notifyAboutIncomingCall( + applicationContext, + callId, + callType, + callInitiatorId, + callInitiatorName, + callOpponents, + callPhoto, + userInfo + ) + showCallNotification( applicationContext, callId, diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt index e788980..5c4c537 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt @@ -380,6 +380,33 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, } } +fun notifyAboutIncomingCall( + context: Context, callId: String, callType: Int, callInitiatorId: Int, + callInitiatorName: String, callOpponents: ArrayList, callPhoto: String?, userInfo: String +) { + val intent = Intent(ACTION_CALL_INCOMING) + .putExtra(EXTRA_CALL_ID, callId) + .putExtra(EXTRA_CALL_TYPE, callType) + .putExtra(EXTRA_CALL_INITIATOR_ID, callInitiatorId) + .putExtra(EXTRA_CALL_INITIATOR_NAME, callInitiatorName) + .putExtra(EXTRA_CALL_OPPONENTS, callOpponents) + .putExtra(EXTRA_CALL_PHOTO, callPhoto) + .putExtra(EXTRA_CALL_USER_INFO, userInfo) + + if (isApplicationForeground(context)) { + LocalBroadcastManager.getInstance(context) + .sendBroadcast(intent) + } else { + intent.putExtra("userCallbackHandleName", INCOMING_IN_BACKGROUND) + ConnectycubeFlutterBgPerformingService.enqueueMessageProcessing( + context, + intent + ) + } + + Log.d("ConnectycubeFlutterCallKitPlugin", "[notifyAboutIncomingCall] sendBroadcast ACTION_CALL_INCOMING $callId") +} + fun saveCallState(applicationContext: Context?, callId: String, callState: String) { if (applicationContext == null) return From f8e1ea8b34196b83187ab8b009eefab47e85092b Mon Sep 17 00:00:00 2001 From: tung Date: Sat, 6 Jan 2024 16:47:20 +0100 Subject: [PATCH 19/21] Remove unused import statement in ConnectycubeFCMReceiver --- .../connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt index 5e3bb21..ffd1bb4 100644 --- a/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt +++ b/android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt @@ -7,7 +7,6 @@ import android.util.Log import com.connectycube.flutter.connectycube_flutter_call_kit.utils.ContextHolder import com.google.firebase.messaging.RemoteMessage import org.json.JSONObject -import android.os.Bundle class ConnectycubeFCMReceiver : BroadcastReceiver() { From 72eed96cd1880a629418149055aaa35736acd4b0 Mon Sep 17 00:00:00 2001 From: TatankaConCube Date: Wed, 10 Jan 2024 13:09:18 +0200 Subject: [PATCH 20/21] - update README.md; --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0be212e..d3e4388 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,7 @@ Add the listeners during initialization of the plugin: ConnectycubeFlutterCallKit.instance.init( onCallAccepted: _onCallAccepted, onCallRejected: _onCallRejected, + onCallIncoming: _onCallIncoming, ); Future _onCallAccepted(CallEvent callEvent) async { @@ -144,6 +145,10 @@ Future _onCallAccepted(CallEvent callEvent) async { Future _onCallRejected(CallEvent callEvent) async { // the call was rejected } + +Future _onCallRejected(CallEvent callEvent) async { + // the Incoming call screen/notification was shown for user +} ``` #### Listen in the background or terminated state (Android only): @@ -151,9 +156,10 @@ Future _onCallRejected(CallEvent callEvent) async { ```dart ConnectycubeFlutterCallKit.onCallRejectedWhenTerminated = onCallRejectedWhenTerminated; ConnectycubeFlutterCallKit.onCallAcceptedWhenTerminated = onCallAcceptedWhenTerminated; +ConnectycubeFlutterCallKit.onCallIncomingWhenTerminated = onCallIncomingWhenTerminated; ``` -!> Attention: the functions `onCallRejectedWhenTerminated` and `onCallAcceptedWhenTerminated` must +!> Attention: the functions `onCallRejectedWhenTerminated`, `onCallAcceptedWhenTerminated` and `onCallIncomingWhenTerminated` must be a top-level functions and cannot be anonymous. Mark these callbacks with the `@pragma('vm:entry-point')` annotation to allow using them from the native code. From abe617a3e36cbc0d670d5cd3ee26286fd1f3cc7d Mon Sep 17 00:00:00 2001 From: TatankaConCube Date: Wed, 10 Jan 2024 13:20:16 +0200 Subject: [PATCH 21/21] - release 2.6.0; --- CHANGELOG.md | 3 +++ android/build.gradle | 2 +- ios/connectycube_flutter_call_kit.podspec | 2 +- pubspec.yaml | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97e0ff8..97a5d4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.6.0 +- Implemented the Notify for Incoming Calls feature (thanks for [tungs0ul](https://github.com/tungs0ul)); + ## 2.5.0 - (Android) Add API to manage the `Manifest.permission.USE_FULL_SCREEN_INTENT` permission; diff --git a/android/build.gradle b/android/build.gradle index fd3df51..a32704e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ group 'com.connectycube.flutter.connectycube_flutter_call_kit' -version '2.5.0' +version '2.6.0' buildscript { ext.kotlin_version = '1.9.10' diff --git a/ios/connectycube_flutter_call_kit.podspec b/ios/connectycube_flutter_call_kit.podspec index f8fd74d..828db6f 100644 --- a/ios/connectycube_flutter_call_kit.podspec +++ b/ios/connectycube_flutter_call_kit.podspec @@ -4,7 +4,7 @@ # Pod::Spec.new do |s| s.name = 'connectycube_flutter_call_kit' - s.version = '2.5.0' + s.version = '2.6.0' s.summary = 'Connectycube Call Kit plugin for flutter.' s.description = <<-DESC Connectycube Call Kit plugin for flutter. diff --git a/pubspec.yaml b/pubspec.yaml index 4d7bfde..129f56f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: connectycube_flutter_call_kit description: A Flutter plugin for displaying call screen when app in background or terminated. -version: 2.5.0 +version: 2.6.0 homepage: https://connectycube.com/ issue_tracker: https://github.com/ConnectyCube/connectycube-flutter-call-kit/issues documentation: https://github.com/ConnectyCube/connectycube-flutter-call-kit/blob/master/README.md