Skip to content

Commit b723f25

Browse files
Merge pull request #130 from ConnectyCube/development
release 2.6.0
2 parents 7ee115e + abe617a commit b723f25

File tree

12 files changed

+114
-7
lines changed

12 files changed

+114
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.6.0
2+
- Implemented the Notify for Incoming Calls feature (thanks for [tungs0ul](https://github.com/tungs0ul));
3+
14
## 2.5.0
25
- (Android) Add API to manage the `Manifest.permission.USE_FULL_SCREEN_INTENT` permission;
36

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Add the listeners during initialization of the plugin:
135135
ConnectycubeFlutterCallKit.instance.init(
136136
onCallAccepted: _onCallAccepted,
137137
onCallRejected: _onCallRejected,
138+
onCallIncoming: _onCallIncoming,
138139
);
139140
140141
Future<void> _onCallAccepted(CallEvent callEvent) async {
@@ -144,16 +145,21 @@ Future<void> _onCallAccepted(CallEvent callEvent) async {
144145
Future<void> _onCallRejected(CallEvent callEvent) async {
145146
// the call was rejected
146147
}
148+
149+
Future<void> _onCallRejected(CallEvent callEvent) async {
150+
// the Incoming call screen/notification was shown for user
151+
}
147152
```
148153

149154
#### Listen in the background or terminated state (Android only):
150155

151156
```dart
152157
ConnectycubeFlutterCallKit.onCallRejectedWhenTerminated = onCallRejectedWhenTerminated;
153158
ConnectycubeFlutterCallKit.onCallAcceptedWhenTerminated = onCallAcceptedWhenTerminated;
159+
ConnectycubeFlutterCallKit.onCallIncomingWhenTerminated = onCallIncomingWhenTerminated;
154160
```
155161

156-
!> Attention: the functions `onCallRejectedWhenTerminated` and `onCallAcceptedWhenTerminated` must
162+
!> Attention: the functions `onCallRejectedWhenTerminated`, `onCallAcceptedWhenTerminated` and `onCallIncomingWhenTerminated` must
157163
be a top-level functions and cannot be anonymous. Mark these callbacks with the `@pragma('vm:entry-point')`
158164
annotation to allow using them from the native code.
159165

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.connectycube.flutter.connectycube_flutter_call_kit'
2-
version '2.5.0'
2+
version '2.6.0'
33

44
buildscript {
55
ext.kotlin_version = '1.9.10'

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFCMReceiver.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ class ConnectycubeFCMReceiver : BroadcastReceiver() {
8484
return
8585
}
8686

87+
notifyAboutIncomingCall(
88+
applicationContext,
89+
callId,
90+
callType,
91+
callInitiatorId,
92+
callInitiatorName,
93+
callOpponents,
94+
callPhoto,
95+
userInfo
96+
)
97+
8798
showCallNotification(
8899
applicationContext,
89100
callId,

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler,
8686
}
8787

8888
"startBackgroundIsolate" -> {
89+
8990
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> =
9091
call.arguments as Map<String, Any>
9192

@@ -94,7 +95,6 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler,
9495
val userCallbackHandleName: String =
9596
arguments["userCallbackHandleName"]?.toString() ?: ""
9697

97-
9898
val arg1 = arguments["pluginCallbackHandle"] ?: -1L
9999
val arg2 = arguments["userCallbackHandle"] ?: -1L
100100

@@ -126,6 +126,8 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler,
126126
saveBackgroundRejectHandler(applicationContext, userCallbackHandle)
127127
} else if (ACCEPTED_IN_BACKGROUND == userCallbackHandleName) {
128128
saveBackgroundAcceptHandler(applicationContext, userCallbackHandle)
129+
} else if (INCOMING_IN_BACKGROUND == userCallbackHandleName) {
130+
saveBackgroundIncomingCallHandler(applicationContext, userCallbackHandle)
129131
}
130132

131133
ConnectycubeFlutterBgPerformingService.startBackgroundIsolate(
@@ -378,6 +380,33 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler,
378380
}
379381
}
380382

383+
fun notifyAboutIncomingCall(
384+
context: Context, callId: String, callType: Int, callInitiatorId: Int,
385+
callInitiatorName: String, callOpponents: ArrayList<Int>, callPhoto: String?, userInfo: String
386+
) {
387+
val intent = Intent(ACTION_CALL_INCOMING)
388+
.putExtra(EXTRA_CALL_ID, callId)
389+
.putExtra(EXTRA_CALL_TYPE, callType)
390+
.putExtra(EXTRA_CALL_INITIATOR_ID, callInitiatorId)
391+
.putExtra(EXTRA_CALL_INITIATOR_NAME, callInitiatorName)
392+
.putExtra(EXTRA_CALL_OPPONENTS, callOpponents)
393+
.putExtra(EXTRA_CALL_PHOTO, callPhoto)
394+
.putExtra(EXTRA_CALL_USER_INFO, userInfo)
395+
396+
if (isApplicationForeground(context)) {
397+
LocalBroadcastManager.getInstance(context)
398+
.sendBroadcast(intent)
399+
} else {
400+
intent.putExtra("userCallbackHandleName", INCOMING_IN_BACKGROUND)
401+
ConnectycubeFlutterBgPerformingService.enqueueMessageProcessing(
402+
context,
403+
intent
404+
)
405+
}
406+
407+
Log.d("ConnectycubeFlutterCallKitPlugin", "[notifyAboutIncomingCall] sendBroadcast ACTION_CALL_INCOMING $callId")
408+
}
409+
381410
fun saveCallState(applicationContext: Context?, callId: String, callState: String) {
382411
if (applicationContext == null) return
383412

@@ -468,6 +497,22 @@ fun getBackgroundAcceptHandler(applicationContext: Context?): Long {
468497
return getLong(applicationContext, "background_callback_accept")
469498
}
470499

500+
fun saveBackgroundIncomingCallHandler(applicationContext: Context?, callbackId: Long) {
501+
if (applicationContext == null) return
502+
503+
try {
504+
putLong(applicationContext, "background_callback_incoming_call", callbackId)
505+
} catch (e: Exception) {
506+
// ignore
507+
}
508+
}
509+
510+
fun getBackgroundIncomingCallHandler(applicationContext: Context?): Long {
511+
if (applicationContext == null) return -1L
512+
513+
return getLong(applicationContext, "background_callback_incoming_call")
514+
}
515+
471516
fun saveBackgroundRejectHandler(applicationContext: Context?, callbackId: Long) {
472517
if (applicationContext == null) return
473518

@@ -525,6 +570,7 @@ class CallStreamHandler(private var context: Context) : EventChannel.StreamHandl
525570
val intentFilter = IntentFilter()
526571
intentFilter.addAction(ACTION_CALL_REJECT)
527572
intentFilter.addAction(ACTION_CALL_ACCEPT)
573+
intentFilter.addAction(ACTION_CALL_INCOMING)
528574
localBroadcastManager.registerReceiver(this, intentFilter)
529575
}
530576

@@ -547,11 +593,12 @@ class CallStreamHandler(private var context: Context) : EventChannel.StreamHandl
547593

548594
events?.success(parameters)
549595
return
550-
} else if (ACTION_CALL_REJECT != action && ACTION_CALL_ACCEPT != action) {
596+
} else if (ACTION_CALL_REJECT != action && ACTION_CALL_ACCEPT != action && ACTION_CALL_INCOMING != action) {
551597
return
552598
}
553599

554600
val callIdToProcess: String? = intent.getStringExtra(EXTRA_CALL_ID)
601+
555602
if (TextUtils.isEmpty(callIdToProcess)) return
556603

557604
val callEventMap = HashMap<String, Any?>()
@@ -589,6 +636,11 @@ class CallStreamHandler(private var context: Context) : EventChannel.StreamHandl
589636
launchIntent?.action = ACTION_CALL_ACCEPT
590637
context.startActivity(launchIntent)
591638
}
639+
640+
ACTION_CALL_INCOMING -> {
641+
callbackData["event"] = "incomingCall"
642+
events?.success(callbackData)
643+
}
592644
}
593645
}
594646
}

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/Constants.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ const val EXTRA_CALL_PHOTO = "photo_url"
1111

1212
const val ACTION_CALL_ACCEPT = "action_call_accept"
1313
const val ACTION_CALL_REJECT = "action_call_reject"
14+
const val ACTION_CALL_INCOMING = "action_call_incoming"
1415
const val ACTION_CALL_NOTIFICATION_CANCELED = "action_call_notification_canceled"
1516
const val ACTION_CALL_ENDED = "action_call_ended"
1617
const val ACTION_TOKEN_REFRESHED = "action_token_refreshed"
1718

1819
const val REJECTED_IN_BACKGROUND = "rejected_in_background"
1920
const val ACCEPTED_IN_BACKGROUND = "accepted_in_background"
21+
const val INCOMING_IN_BACKGROUND = "incoming_in_background"
2022

2123
const val CALL_TYPE_PLACEHOLDER = "Incoming %s call"
2224

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ import com.connectycube.flutter.connectycube_flutter_call_kit.utils.isApplicatio
1414

1515
class EventReceiver : BroadcastReceiver() {
1616
private val TAG = "EventReceiver"
17+
1718
override fun onReceive(context: Context, intent: Intent?) {
1819

1920
if (intent == null || TextUtils.isEmpty(intent.action)) return
2021

22+
Log.d(TAG, "NotificationReceiver onReceive action: ${intent.action}")
23+
2124
when (intent.action) {
2225
ACTION_CALL_REJECT -> {
2326
val extras = intent.extras

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/background_isolates/FlutterConnectycubeBackgroundExecutor.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,14 @@ class FlutterConnectycubeBackgroundExecutor : MethodCallHandler {
213213
userCallbackHandle = getBackgroundRejectHandler(ContextHolder.applicationContext)
214214
} else if (ACCEPTED_IN_BACKGROUND == callEventName) {
215215
userCallbackHandle = getBackgroundAcceptHandler(ContextHolder.applicationContext)
216+
} else if (INCOMING_IN_BACKGROUND == callEventName) {
217+
userCallbackHandle = getBackgroundIncomingCallHandler(ContextHolder.applicationContext)
216218
}
217219

218220
if (userCallbackHandle == -1L) {
219221
Log.e(
220222
"FlutterConnectycubeBackgroundExecutor",
221-
"No one background handler has been registered."
223+
"${intent.action} background handler has not been registered."
222224
)
223225
return
224226
}

ios/Classes/CallKitController.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import AVFoundation
1010
import CallKit
1111

1212
enum CallEvent : String {
13+
case incomingCall = "incomingCall"
1314
case answerCall = "answerCall"
1415
case endCall = "endCall"
1516
case setHeld = "setHeld"
@@ -125,6 +126,8 @@ class CallKitController : NSObject {
125126

126127
self.callStates[uuid] = .pending
127128
self.callsData[uuid] = self.currentCallData
129+
130+
self.actionListener?(.incomingCall, UUID(uuidString: uuid)!, self.currentCallData)
128131
}
129132
}
130133
} else if (self.currentCallData["session_id"] as! String == uuid) {

ios/connectycube_flutter_call_kit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
Pod::Spec.new do |s|
66
s.name = 'connectycube_flutter_call_kit'
7-
s.version = '2.5.0'
7+
s.version = '2.6.0'
88
s.summary = 'Connectycube Call Kit plugin for flutter.'
99
s.description = <<-DESC
1010
Connectycube Call Kit plugin for flutter.

0 commit comments

Comments
 (0)