Skip to content

Commit

Permalink
Merge pull request #433 from hiennguyen92/dev
Browse files Browse the repository at this point in the history
feat: 2.0.1+2
  • Loading branch information
hiennguyen92 authored Jan 20, 2024
2 parents 359a5ce + 5730185 commit 792622c
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 38 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.1+2
* Add Action for onDecline
* Add Action for onEnd
* add android props `isShowCallID`

## 2.0.1+1
* Add Callback AVAudioSession for WebRTC setup
* Fix issue no audio for using WebRTC
Expand Down
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ Our top sponsors are shown below!
actionColor: '#4CAF50',
textColor: '#ffffff',
incomingCallNotificationChannelName: "Incoming Call",
missedCallNotificationChannelName: "Missed Call"
missedCallNotificationChannelName: "Missed Call",
isShowCallID: false
),
ios: IOSParams(
iconName: 'CallKitLogo',
Expand All @@ -127,7 +128,7 @@ Our top sponsors are shown below!
https://github.com/firebase/flutterfire/blob/master/docs/cloud-messaging/receive.md#apple-platforms-and-android

* request permission for post Notification Android 13+
For Android 13 and above, please `requestNotificationPermission` before `showCallkitIncoming`
For Android 13+, please `requestNotificationPermission` or requestPermission of firebase_messaging before `showCallkitIncoming`
```dart
await FlutterCallkitIncoming.requestNotificationPermission({
"rationaleMessagePermission": "Notification permission is required, to show notification.",
Expand Down Expand Up @@ -369,7 +370,7 @@ Our top sponsors are shown below!
case .success(let data):
print("Received data: \(data)")
//Make sure call action.fulfill() when you are done(connected WebRTC - Start counting seconds)
//action.fulfill()
action.fulfill()

case .failure(let error):
print("Error: \(error.localizedDescription)")
Expand All @@ -378,27 +379,32 @@ Our top sponsors are shown below!
}
// Func Call API for Decline
func onDecline(_ call: Call) {
func onDecline(_ call: Call, _ action: CXEndCallAction) {
let json = ["action": "DECLINE", "data": call.data.toJSON()] as [String: Any]
print("LOG: onDecline")
self.performRequest(parameters: json) { result in
switch result {
case .success(let data):
print("Received data: \(data)")
//Make sure call action.fulfill() when you are done
action.fulfill()

case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
}
func onEnd(_ call: Call) {
// Func Call API for End
func onEnd(_ call: Call, _ action: CXEndCallAction) {
let json = ["action": "END", "data": call.data.toJSON()] as [String: Any]
print("LOG: onEnd")
self.performRequest(parameters: json) { result in
switch result {
case .success(let data):
print("Received data: \(data)")
//Make sure call action.fulfill() when you are done
action.fulfill()

case .failure(let error):
print("Error: \(error.localizedDescription)")
Expand Down Expand Up @@ -467,18 +473,19 @@ Our top sponsors are shown below!
| **`isShowCallback`** | Show callback action from miss call notification. | `true` |
* Android

| Prop | Description | Default |
| --------------------------- | ----------------------------------------------------------------------- | ---------------- |
| **`isCustomNotification`** | Using custom notifications. | `false` |
| **`isCustomSmallExNotification`** | Using custom notification small on some devices clipped out in android. | `false` |
| **`isShowLogo`** | Show logo app inside full screen. `/android/src/main/res/drawable-xxxhdpi/ic_logo.png` | `false` |
| **`ringtonePath`** | File name ringtone. put file into `/android/app/src/main/res/raw/ringtone_default.pm3` |`system_ringtone_default` <br>using ringtone default of the phone|
| **`backgroundColor`** | Incoming call screen background color. | `#0955fa` |
| **`backgroundUrl`** | Using image background for Incoming call screen. example: http://... https://... or "assets/abc.png" | _None_ |
| **`actionColor`** | Color used in button/text on notification. | `#4CAF50` |
| **`textColor`** | Color used for the text in full screen notification. | `#ffffff` |
| **`incomingCallNotificationChannelName`** | Notification channel name of incoming call. | `Incoming call` |
| **`missedCallNotificationChannelName`** | Notification channel name of missed call. | `Missed call` |
| Prop | Description | Default |
| --------------------------- |------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| **`isCustomNotification`** | Using custom notifications. | `false` |
| **`isCustomSmallExNotification`** | Using custom notification small on some devices clipped out in android. | `false` |
| **`isShowLogo`** | Show logo app inside full screen. `/android/src/main/res/drawable-xxxhdpi/ic_logo.png` | `false` |
| **`ringtonePath`** | File name ringtone. put file into `/android/app/src/main/res/raw/ringtone_default.pm3` | `system_ringtone_default` <br>using ringtone default of the phone |
| **`backgroundColor`** | Incoming call screen background color. | `#0955fa` |
| **`backgroundUrl`** | Using image background for Incoming call screen. example: http://... https://... or "assets/abc.png" | _None_ |
| **`actionColor`** | Color used in button/text on notification. | `#4CAF50` |
| **`textColor`** | Color used for the text in full screen notification. | `#ffffff` |
| **`incomingCallNotificationChannelName`** | Notification channel name of incoming call. | `Incoming call` |
| **`missedCallNotificationChannelName`** | Notification channel name of missed call. | `Missed call` |
| **`isShowCallID`** | Show call id app inside full screen/notification. | false |

<br>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ data class Data(val args: Map<String, Any?>) {
var isCustomSmallExNotification: Boolean = false
@JsonProperty("isShowLogo")
var isShowLogo: Boolean = false
@JsonProperty("isShowCallID")
var isShowCallID: Boolean = false
@JsonProperty("ringtonePath")
var ringtonePath: String
@JsonProperty("backgroundColor")
Expand Down Expand Up @@ -86,6 +88,7 @@ data class Data(val args: Map<String, Any?>) {
isCustomNotification = android["isCustomNotification"] as? Boolean ?: false
isCustomSmallExNotification = android["isCustomSmallExNotification"] as? Boolean ?: false
isShowLogo = android["isShowLogo"] as? Boolean ?: false
isShowCallID = android["isShowCallID"] as? Boolean ?: false
ringtonePath = android["ringtonePath"] as? String ?: ""
backgroundColor = android["backgroundColor"] as? String ?: "#0955fa"
backgroundUrl = android["backgroundUrl"] as? String ?: ""
Expand Down Expand Up @@ -179,6 +182,10 @@ data class Data(val args: Map<String, Any?>) {
CallkitConstants.EXTRA_CALLKIT_IS_SHOW_LOGO,
isShowLogo
)
bundle.putBoolean(
CallkitConstants.EXTRA_CALLKIT_IS_SHOW_CALL_ID,
isShowCallID
)
bundle.putString(CallkitConstants.EXTRA_CALLKIT_RINGTONE_PATH, ringtonePath)
bundle.putString(
CallkitConstants.EXTRA_CALLKIT_BACKGROUND_COLOR,
Expand Down Expand Up @@ -253,6 +260,10 @@ data class Data(val args: Map<String, Any?>) {
CallkitConstants.EXTRA_CALLKIT_IS_SHOW_LOGO,
false
)
data.isShowCallID = bundle.getBoolean(
CallkitConstants.EXTRA_CALLKIT_IS_SHOW_CALL_ID,
false
)
data.ringtonePath = bundle.getString(
CallkitConstants.EXTRA_CALLKIT_RINGTONE_PATH,
""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ object CallkitConstants {
const val EXTRA_CALLKIT_IS_CUSTOM_SMALL_EX_NOTIFICATION =
"EXTRA_CALLKIT_IS_CUSTOM_SMALL_EX_NOTIFICATION"
const val EXTRA_CALLKIT_IS_SHOW_LOGO = "EXTRA_CALLKIT_IS_SHOW_LOGO"
const val EXTRA_CALLKIT_IS_SHOW_CALL_ID = "EXTRA_CALLKIT_IS_SHOW_CALL_ID"
const val EXTRA_CALLKIT_RINGTONE_PATH = "EXTRA_CALLKIT_RINGTONE_PATH"
const val EXTRA_CALLKIT_BACKGROUND_COLOR = "EXTRA_CALLKIT_BACKGROUND_COLOR"
const val EXTRA_CALLKIT_BACKGROUND_URL = "EXTRA_CALLKIT_BACKGROUND_URL"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ class CallkitIncomingActivity : Activity() {
if (data == null) finish()

val textColor = data?.getString(CallkitConstants.EXTRA_CALLKIT_TEXT_COLOR, "#ffffff")
val isShowCallID = data?.getBoolean(CallkitConstants.EXTRA_CALLKIT_IS_SHOW_CALL_ID, false)
tvNameCaller.text = data?.getString(CallkitConstants.EXTRA_CALLKIT_NAME_CALLER, "")
tvNumber.text = data?.getString(CallkitConstants.EXTRA_CALLKIT_HANDLE, "")
tvNumber.visibility = if (isShowCallID == true) View.VISIBLE else View.INVISIBLE

try {
tvNameCaller.setTextColor(Color.parseColor(textColor))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@ class CallkitNotificationManager(private val context: Context) {
R.id.tvNameCaller,
data.getString(CallkitConstants.EXTRA_CALLKIT_NAME_CALLER, "")
)
remoteViews.setTextViewText(
val isShowCallID = data?.getBoolean(CallkitConstants.EXTRA_CALLKIT_IS_SHOW_CALL_ID, false)
if (isShowCallID == true) {
remoteViews.setTextViewText(
R.id.tvNumber,
data.getString(CallkitConstants.EXTRA_CALLKIT_HANDLE, "")
)
)
}
remoteViews.setOnClickPendingIntent(
R.id.llDecline,
getDeclinePendingIntent(notificationId, data)
Expand Down Expand Up @@ -279,10 +282,13 @@ class CallkitNotificationManager(private val context: Context) {
R.id.tvNameCaller,
data.getString(CallkitConstants.EXTRA_CALLKIT_NAME_CALLER, "")
)
notificationViews?.setTextViewText(
val isShowCallID = data?.getBoolean(CallkitConstants.EXTRA_CALLKIT_IS_SHOW_CALL_ID, false)
if (isShowCallID == true) {
notificationViews?.setTextViewText(
R.id.tvNumber,
data.getString(CallkitConstants.EXTRA_CALLKIT_HANDLE, "")
)
)
}
notificationViews?.setOnClickPendingIntent(
R.id.llCallback,
getCallbackPendingIntent(notificationId, data)
Expand Down
10 changes: 7 additions & 3 deletions example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import flutter_callkit_incoming
case .success(let data):
print("Received data: \(data)")
//Make sure call action.fulfill() when you are done(connected WebRTC - Start counting seconds)
//action.fulfill()
action.fulfill()

case .failure(let error):
print("Error: \(error.localizedDescription)")
Expand All @@ -107,13 +107,15 @@ import flutter_callkit_incoming
}

// Func Call API for Decline
func onDecline(_ call: Call) {
func onDecline(_ call: Call, _ action: CXEndCallAction) {
let json = ["action": "DECLINE", "data": call.data.toJSON()] as [String: Any]
print("LOG: onDecline")
self.performRequest(parameters: json) { result in
switch result {
case .success(let data):
print("Received data: \(data)")
//Make sure call action.fulfill() when you are done
action.fulfill()

case .failure(let error):
print("Error: \(error.localizedDescription)")
Expand All @@ -122,13 +124,15 @@ import flutter_callkit_incoming
}

// Func Call API for End
func onEnd(_ call: Call) {
func onEnd(_ call: Call, _ action: CXEndCallAction) {
let json = ["action": "END", "data": call.data.toJSON()] as [String: Any]
print("LOG: onEnd")
self.performRequest(parameters: json) { result in
switch result {
case .success(let data):
print("Received data: \(data)")
//Make sure call action.fulfill() when you are done
action.fulfill()

case .failure(let error):
print("Error: \(error.localizedDescription)")
Expand Down
2 changes: 1 addition & 1 deletion example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class HomePageState extends State<HomePage> {
avatar: 'https://i.pravatar.cc/100',
handle: '0123456789',
type: 1,
duration: 30000,
duration: 10000,
textAccept: 'Accept',
textDecline: 'Decline',
missedCallNotification: const NotificationParams(
Expand Down
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:uuid/uuid.dart';

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print("Handling a background message: ${message.messageId}");
await Firebase.initializeApp(); //make sure firebase is initialized before using it (showCallkitIncoming)
showCallkitIncoming(const Uuid().v4());
}

Expand Down
4 changes: 2 additions & 2 deletions ios/Classes/CallkitIncomingAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public protocol CallkitIncomingAppDelegate : NSObjectProtocol {

func onAccept(_ call: Call, _ action: CXAnswerCallAction);

func onDecline(_ call: Call);
func onDecline(_ call: Call, _ action: CXEndCallAction);

func onEnd(_ call: Call);
func onEnd(_ call: Call, _ action: CXEndCallAction);

func onTimeOut(_ call: Call);

Expand Down
14 changes: 7 additions & 7 deletions ios/Classes/SwiftFlutterCallkitIncomingPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,7 @@ public class SwiftFlutterCallkitIncomingPlugin: NSObject, FlutterPlugin, CXProvi
if let appDelegate = UIApplication.shared.delegate as? CallkitIncomingAppDelegate {
appDelegate.onAccept(call, action)
}else {
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(2000)) {
action.fulfill()
}
action.fulfill()
}
}

Expand All @@ -552,15 +550,17 @@ public class SwiftFlutterCallkitIncomingPlugin: NSObject, FlutterPlugin, CXProvi
if (self.answerCall == nil && self.outgoingCall == nil) {
sendEvent(SwiftFlutterCallkitIncomingPlugin.ACTION_CALL_DECLINE, self.data?.toJSON())
if let appDelegate = UIApplication.shared.delegate as? CallkitIncomingAppDelegate {
appDelegate.onDecline(call)
appDelegate.onDecline(call, action)
} else {
action.fulfill()
}
action.fulfill()
}else {
sendEvent(SwiftFlutterCallkitIncomingPlugin.ACTION_CALL_ENDED, call.data.toJSON())
if let appDelegate = UIApplication.shared.delegate as? CallkitIncomingAppDelegate {
appDelegate.onEnd(call)
appDelegate.onEnd(call, action)
} else {
action.fulfill()
}
action.fulfill()
}
}

Expand Down
7 changes: 6 additions & 1 deletion lib/entities/android_params.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class AndroidParams {
this.isCustomNotification,
this.isCustomSmallExNotification,
this.isShowLogo,
this.isShowCallID,
this.ringtonePath,
this.backgroundColor,
this.backgroundUrl,
Expand All @@ -27,6 +28,9 @@ class AndroidParams {
/// Show logo app inside full screen.
final bool? isShowLogo;

/// Show call id app inside full screen.
final bool? isShowCallID;

/// File name ringtone, put file into /android/app/src/main/res/raw/ringtone_default.pm3 -> value: `ringtone_default.pm3`
final String? ringtonePath;

Expand All @@ -48,7 +52,8 @@ class AndroidParams {
/// Notification channel name of missed call.
final String? missedCallNotificationChannelName;

factory AndroidParams.fromJson(Map<String, dynamic> json) => _$AndroidParamsFromJson(json);
factory AndroidParams.fromJson(Map<String, dynamic> json) =>
_$AndroidParamsFromJson(json);

Map<String, dynamic> toJson() => _$AndroidParamsToJson(this);
}
2 changes: 2 additions & 0 deletions lib/entities/android_params.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/entities/notification_params.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:json_annotation/json_annotation.dart';

part 'notification_params.g.dart';

/// Object config for Android.
/// Object config for Notification Android.
@JsonSerializable(explicitToJson: true)
class NotificationParams {
const NotificationParams({
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_callkit_incoming
description: Flutter Callkit Incoming to show callkit screen in your Flutter app.
version: 2.0.1+1
version: 2.0.1+2
homepage: https://github.com/hiennguyen92/flutter_callkit_incoming
repository: https://github.com/hiennguyen92/flutter_callkit_incoming
issue_tracker: https://github.com/hiennguyen92/flutter_callkit_incoming/issues
Expand Down

0 comments on commit 792622c

Please sign in to comment.