Skip to content

Commit f23e00a

Browse files
- update README.md;
1 parent c76a698 commit f23e00a

File tree

4 files changed

+205
-8
lines changed

4 files changed

+205
-8
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## 2.0.0
2+
Completely reworked version. Reworked the ways for interaction between the flutter app and native platforms.
3+
Since this version you don't need any third-party plugins for working with push notifications anymore, cause all required functionality has already been integrated into the plugin.
4+
5+
New:
6+
- Added iOS support;
7+
- Added getting the subscription tokens (VoIP for the iOS and FCM for the Android);
8+
- Added customisation for ringtone, app icon, color accent (for Android);
9+
10+
Fixes and improvements:
11+
- reworked callbacks `onCallRejectedWhenTerminated` and `onCallAcceptedWhenTerminated` now they fire even the app terminated or in the background;
12+
- migrated to `EventChannel` for sending events from native platforms to the Flutter app;
13+
114
## 0.1.0-dev.2
215

316
* Improved compatibility with projects which support Web platform.

README.md

Lines changed: 189 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,196 @@
11
# connectycube_flutter_call_kit
22

3-
A Flutter plugin for displaying call screen when the app in the background or terminated.
3+
A Flutter plugin for displaying call screen when the app is in the background or terminated.
4+
It provides a complex solution for implementation the background calls feature in your app including getting token and displaying the Incoming call screen.
45

5-
At the current moment implemented support only for the Android platform
6+
At that moment plugin supports next platforms:
7+
- Android;
8+
- iOS;
69

7-
<kbd><img alt="Flutter P2P Calls code sample, incoming call in background Android" src="https://developers.connectycube.com/docs/_images/code_samples/flutter/background_call_android.png" height="440" /></kbd>
8-
<kbd><img alt="Flutter P2P Calls code sample, incoming call locked Android" src="https://developers.connectycube.com/docs/_images/code_samples/flutter/background_call_android_locked.png" height="440" /></kbd>
10+
The list of main features of our plugin:
11+
- providing the token (FCM for Android and VoIP for iOS);
12+
- notifying the app about token refreshing via callback;
13+
- displaying the Incoming call screen when push notification was delivered on the device;
14+
- notifying the app about user action performed on the Incoming call screen (accept, reject, mute (for iOS));
15+
- providing the methods for manual managing of the Incoming screen including the manual showing the Incoming call screen;
16+
- getting the data about the current call during the call session;
17+
- some customizations according to your needs (ringtone, icon, accent color(for Android));
918

10-
The plugin shows Incoming call notification in the case when device unlocked or Incoming call screen in the case when the device locked.
19+
20+
<kbd><img alt="Flutter P2P Calls code sample, incoming call in background Android" src="https://developers.connectycube.com/docs/_images/code_samples/flutter/background_call_android.png" height="440" /></kbd> <kbd><img alt="Flutter P2P Calls code sample, incoming call locked Android" src="https://developers.connectycube.com/docs/_images/code_samples/flutter/background_call_android_locked.png" height="440" /></kbd> <kbd><img alt="Flutter P2P Calls code sample, incoming call in background iOS" src="https://developers.connectycube.com/docs/_images/code_samples/flutter/background_call_ios.PNG" height="440" /></kbd>
21+
<kbd><img alt="Flutter P2P Calls code sample, incoming call locked iOS" src="https://developers.connectycube.com/docs/_images/code_samples/flutter/background_call_ios_locked.PNG" height="440" /></kbd>
22+
23+
## Configure your project
24+
25+
This plugin doesn't require complicated configs, just [connect it](https://pub.dev/packages/connectycube_flutter_call_kit/install) as usual flutter plugin to your app and do the next simple actions:
26+
27+
### Prepare Android
28+
29+
- add the Google services config file `google-services.json` by path `your_app/android/app/`
30+
- add next string at the end of your **build.gradle** file by path `your_app/android/app/build.gradle`:
31+
```groovy
32+
apply plugin: 'com.google.gms.google-services'
33+
```
34+
35+
### Prepare iOS
36+
37+
- add next strings to your **Info.plist** file by path `your_app/ios/Runner/Info.plist`:
38+
```
39+
<key>UIBackgroundModes</key>
40+
<array>
41+
<string>remote-notification</string>
42+
<string>voip</string>
43+
</array>
44+
```
45+
46+
## API and callbacks
47+
### Get token
48+
The plugin returns the VoIP token for the iOS platform and the FCM token for the Android platform.
49+
50+
Get token from the system:
51+
52+
```dart
53+
ConnectycubeFlutterCallKit.getToken().then((token) {
54+
// use received token for subscription on push notifications on your server
55+
});
56+
```
57+
58+
Listen to the refresh token event:
59+
```dart
60+
ConnectycubeFlutterCallKit.onTokenReceived = (token) {
61+
// use refreshed token for resubscription on your server
62+
};
63+
```
64+
### Customize the plugin
65+
We added a helpful method for customization the plugin according to your needs. At this moment you can customize the ringtone, icon, and color accent. Use the next method for it:
66+
67+
```dart
68+
ConnectycubeFlutterCallKit.instance.updateConfig(ringtone: 'custom_ringtone', icon: 'app_icon', color: '#07711e');
69+
```
70+
71+
### Show Incoming call notification
72+
73+
```dart
74+
P2PCallSession incomingCall; // the call received somewhere
75+
76+
CallEvent callEvent = CallEvent(
77+
sessionId: incomingCall.sessionId,
78+
callType: incomingCall.callType,
79+
callerId: incomingCall.callerId,
80+
callerName: 'Caller Name',
81+
opponentsIds: incomingCall.opponentsIds,
82+
userInfo: {'customParameter1': 'value1'});
83+
ConnectycubeFlutterCallKit.showCallNotification(callEvent);
84+
```
85+
86+
### Listen to the user action from the Incoming call screen:
87+
88+
#### Listen in the foreground
89+
90+
Add the listeners during initialization of the plugin:
91+
92+
```dart
93+
ConnectycubeFlutterCallKit.instance.init(
94+
onCallAccepted: _onCallAccepted,
95+
onCallRejected: _onCallRejected,
96+
);
97+
98+
Future<void> _onCallAccepted(CallEvent callEvent) async {
99+
// the call was accepted
100+
}
101+
102+
Future<void> _onCallRejected(CallEvent callEvent) async {
103+
// the call was rejected
104+
}
105+
```
106+
107+
#### Listen in the background or terminated state (Android only):
108+
109+
```dart
110+
ConnectycubeFlutterCallKit.onCallRejectedWhenTerminated = onCallRejectedWhenTerminated;
111+
ConnectycubeFlutterCallKit.onCallAcceptedWhenTerminated = onCallAcceptedWhenTerminated;
112+
```
113+
114+
!> Attention: the functions `onCallRejectedWhenTerminated` and `onCallAcceptedWhenTerminated` must be a top-level function and cannot be anonymous
115+
116+
### Get the call state
117+
118+
```dart
119+
var callState = await ConnectycubeFlutterCallKit.getCallState(sessionId: sessionId);
120+
```
121+
122+
### Get the call data
123+
```dart
124+
ConnectycubeFlutterCallKit.getCallData(sessionId: sessionId).then((callData) {
125+
126+
});
127+
```
128+
129+
### Get the id of the latest call
130+
131+
It is helpful for some cases to know the id of the last received call. You can get it via:
132+
133+
```dart
134+
var sessionId = await ConnectycubeFlutterCallKit.getLastCallId();
135+
```
136+
Then you can get the state of this call using `getCallState`.
137+
138+
### Notify the plugin about processing the call on the Flutter app side
139+
140+
For dismissing the Incoming call screen (or the Call Kit for iOS) you should notify the plugin about these events.
141+
Use next functions for it:
142+
143+
```dart
144+
ConnectycubeFlutterCallKit.reportCallAccepted(sessionId: uuid, callType: callType);
145+
ConnectycubeFlutterCallKit.reportCallEnded(sessionId: uuid);
146+
```
147+
148+
### Clear call data
149+
After finishing the call you can clear all data on the plugin side related to this call, call the next code for it
150+
151+
```dart
152+
await ConnectycubeFlutterCallKit.clearCallData(sessionId: sessionId);
153+
```
154+
155+
### Manage the app visibility on the lock screen (Android only)
156+
157+
In case you need to show your app after accepting the call from the lock screen you can do it using the method
158+
```dart
159+
ConnectycubeFlutterCallKit.setOnLockScreenVisibility(isVisible: true);
160+
```
161+
162+
After finishing that call you should hide your app under the lock screen, do it via
163+
```dart
164+
ConnectycubeFlutterCallKit.setOnLockScreenVisibility(isVisible: false);
165+
```
166+
167+
## Show Incoming call screen by push notification
168+
In case you want to display the Incoming call screen automatically by push notification you can do it easily. For it, the caller should send the push notification to all call members. This push notification should contain some required parameters. If you use the [Connectycube Flutter SDK](https://pub.dev/packages/connectycube_sdk), you can do it using the next code:
169+
170+
```dart
171+
CreateEventParams params = CreateEventParams();
172+
params.parameters = {
173+
'message': "Incoming ${currentCall.callType == CallType.VIDEO_CALL ? "Video" : "Audio"} call",
174+
'call_type': currentCall.callType,
175+
'session_id': currentCall.sessionId,
176+
'caller_id': currentCall.callerId,
177+
'caller_name': callerName,
178+
'call_opponents': currentCall.opponentsIds.join(','),
179+
'signal_type': 'startCall',
180+
'ios_voip': 1,
181+
};
182+
183+
params.notificationType = NotificationType.PUSH;
184+
params.environment = CubeEnvironment.DEVELOPMENT; // not important
185+
params.usersIds = currentCall.opponentsIds.toList();
186+
187+
createEvent(params.getEventForRequest()).then((cubeEvent) {
188+
// event was created
189+
}).catchError((error) {
190+
// something went wrong during event creation
191+
});
192+
```
193+
194+
For hiding the Incoming call screen via push notification use a similar request but with a different `signal_type`, it can be `'endCall'` or `'rejectCall'`.
11195

12196
You can check how this plugin works in our [P2P Calls code sample](https://github.com/ConnectyCube/connectycube-flutter-samples/tree/master/p2p_call_sample).

lib/src/connectycube_flutter_call_kit.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ConnectycubeFlutterCallKit {
3838

3939
static int _bgHandler = -1;
4040

41-
static Function(String newToken)? onTokenReceived;
41+
static Function(String newToken)? onTokenRefreshed;
4242

4343
/// iOS only callbacks
4444
static Function(bool isMuted, String sessionId)? onCallMuted;
@@ -246,7 +246,7 @@ class ConnectycubeFlutterCallKit {
246246

247247
switch (event) {
248248
case 'voipToken':
249-
onTokenReceived?.call(arguments['voipToken']);
249+
onTokenRefreshed?.call(arguments['voipToken']);
250250
break;
251251

252252
case 'answerCall':

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: connectycube_flutter_call_kit
22
description: A Flutter plugin for displaying call screen when app in background or terminated.
3-
version: 0.1.0-dev.2
3+
version: 2.0.0
44
homepage: https://github.com/ConnectyCube/connectycube-flutter-call-kit
55
issue_tracker: https://github.com/ConnectyCube/connectycube-flutter-call-kit/issues
66

0 commit comments

Comments
 (0)