omicall_flutter_plugin 2.5.2 omicall_flutter_plugin: ^2.5.2 copied to clipboard
OmiKit Flutter is wrapper SDK for OmiCall for Application easy integrate features of Omicall Like Call App2App/App2Phone, Video Call.
OMICALL SDK FOR Flutter #
The OmiKit exposes the omicall_flutter_plugin library.
The most important part of the framework is :
- Help to easy integrate with Omicall.
- Easy custom Call UI/UX.
- Optimize codec voip for you.
- Full inteface to interactive with core function like sound/ringtone/codec.
Status #
Currently active maintenance and improve performance
Running #
Install via pubspec.yaml:
omicall_flutter_plugin: ^latest_version
Configuration #
Android:
- Add these settings in
build.gradle
:
jcenter()
maven {
url("https://vihatgroup.jfrog.io/artifactory/omi-voice/")
credentials {
username = "downloader"
password = "Omi@2022"
}
}
//in dependencies
classpath 'com.google.gms:google-services:4.3.13'
//under buildscript
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven {
url("https://vihatgroup.jfrog.io/artifactory/omi-voice/")
credentials {
username = "downloader"
password = "Omi@2022"
}
}
}
}
You can refer android/build.gradle to know more information.
- Add these settings in
app/build.gradle
:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
You can refer android/app/build.gradle to know more information.
- Update AndroidManifest.xml:
//need request this permission
<uses-permission android:name="android.permission.INTERNET" />
//add these lines inside <activity>
<intent-filter>
<action android:name="com.omicall.sdk.CallingActivity"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
//add these lines outside <activity>
<receiver
android:name="vn.vihat.omicall.omisdk.receiver.FirebaseMessageReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>
<service
android:name="vn.vihat.omicall.omisdk.service.NotificationService"
android:exported="false">
</service>
You can refer AndroidManifest to know more information.
- We registered permissions into my plugin:
<uses-permission android:name="android.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
- Setup push notification: Only support Firebase for remote push notification.
-
Add
google-service.json
inandroid/app
(For more information, you can refer firebase_core) -
Add Fire Messaging to receive
fcm_token
(You can refer firebase_messaging to setup notification for Flutter) -
For more setting information, please refer Config Push for Android
-
iOS:
- Add variables in Appdelegate.h:
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
#import <OmiKit/OmiKit-umbrella.h>
#import <OmiKit/Constants.h>
#import <UserNotifications/UserNotifications.h>
PushKitManager *pushkitManager;
CallKitProviderDelegate * provider;
PKPushRegistry * voipRegistry;
- Edit AppDelegate.m:
#import <OmiKit/OmiKit.h>
#import <omicall_flutter_plugin/omicall_flutter_plugin-Swift.h>
[OmiClient setEnviroment:KEY_OMI_APP_ENVIROMENT_SANDBOX];
provider = [[CallKitProviderDelegate alloc] initWithCallManager: [OMISIPLib sharedInstance].callManager];
voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
pushkitManager = [[PushKitManager alloc] initWithVoipRegistry:voipRegistry];
if (@available(iOS 10.0, *)) {
[UNUserNotificationCenter currentNotificationCenter].delegate = (id<UNUserNotificationCenterDelegate>) self;
}
- Add these lines into
Info.plist
:
<key>NSCameraUsageDescription</key>
<string>Need camera access for video call functions</string>
<key>NSMicrophoneUsageDescription</key>
<string>Need microphone access for make Call</string>
- Save token for
OmiClient
: if you addedfirebase_messaging
in your project so you don't need add these lines.
- (void)application:(UIApplication*)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)devToken
{
// parse token bytes to string
const char *data = [devToken bytes];
NSMutableString *token = [NSMutableString string];
for (NSUInteger i = 0; i < [devToken length]; i++)
{
[token appendFormat:@"%02.2hhX", data[i]];
}
// print the token in the console.
NSLog(@"Push Notification Token: %@", [token copy]);
[OmiClient setUserPushNotificationToken:[token copy]];
}
*** Only use under lines when added firebase_messaging
plugin in your project ***
- Setup push notification: We only support Firebase for push notification.
-
Add
google-service.json
inandroid/app
(For more information, you can refer firebase_core) -
Add Firebase Messaging to receive
fcm_token
(You can refer firebase_messaging to setup notification for Flutter) -
For more setting information, please refer Config Push for iOS
-
Implement #
- Set up for Firebase:
await Firebase.initializeApp();
// If you only use Firebase on Android. Add these line `if (Platform.isAndroid)`
// Because we use APNS to push notification on iOS so you don't need add Firebase for iOS.
-
Important function.
- Start Serivce: OmiKit need start services and register some events.
//Call in the root widget OmicallClient.instance.startServices();
- Create OmiKit: OmiKit need userName, password, realm, host to init enviroment. ViHAT Group will provides these information for you. Please contact for my sales:
await OmicallClient.instance.initCall( userName: "", password: "", realm: "", host: "", isVideo: true/false, );
- Create OmiKit With ApiKey: OmiKit need apikey, username, user id to init enviroment. ViHAT Group will provides api key for you. Please contact for my sales:
await OmicallClient.instance.initCallWithApiKey( usrName: "", usrUuid: "", isVideo: true/false, apiKey: "", );
- Get call when user open app from killed status(only iOS):
final result = await OmicallClient.instance.getInitialCall(); ///if result is not equal False => have a calling.
- Config push notification: With iOS, I only support these keys:
prefixMissedCallMessage
,missedCallTitle
. With Android, We don't supportmissedCallTitle
:OmicallClient.instance.configPushNotification( notificationIcon : "calling_face", //notification icon on Android prefix : "Cuộc gọi tới từ: ", declineTitle : "Từ chối", acceptTitle : "Chấp nhận", acceptBackgroundColor : "#FF3700B3", declineBackgroundColor : "#FF000000", incomingBackgroundColor : "#FFFFFFFF", incomingAcceptButtonImage : "join_call", //image name incomingDeclineButtonImage : "hangup", //image name backImage : "ic_back", //image name: icon of back button userImage : "calling_face", //image name: icon of user default prefixMissedCallMessage: 'Cuộc gọi nhỡ từ' //config prefix message for the missed call missedCallTitle: 'Cuộc gọi nhỡ' //config title for the missed call ); //incomingAcceptButtonImage, incomingDeclineButtonImage, backImage, userImage: Add these into `android/app/src/main/res/drawble`
- Start Serivce: OmiKit need start services and register some events.
-
Upload token: OmiKit need FCM for Android and APNS to push notification on user devices.
final token = await FirebaseMessaging.instance.getToken(); String? apnToken; if (Platform.isIOS) { apnToken = await FirebaseMessaging.instance.getAPNSToken(); } String appId = 'Bundle id on iOS/ App id on Android' await OmicallClient.instance.updateToken( fcmToken: token, apnsToken: apnToken, );
-
Other functions:
- Call with phone number (mobile phone or internal number):
OmicallClient.instance.startCall( phone, //phone number _isVideoCall, //call video or audio. If true is video call. );
- Call with UUID (only support with Api key):
OmicallClient.instance.startCallWithUUID( uuid, //your user id _isVideoCall, //call video or audio. If true is video call. );
- Accept a call:
OmicallClient.instance.joinCall();
- End a call: We will push a event
endCall
and return call information for you.OmicallClient.instance.endCall().then((value) { //value is call information }); Sample output: { "transaction_id":ea7dff38-cb1e-483d-8576..........., "direction":"inbound", "source_number":111, "destination_number":110, "time_start_to_answer":1682858097393, "time_end":1682858152181, "sip_user":111, "disposition":"answered" }
- Toggle the audio: On/off audio a call
OmicallClient.instance.toggleAudio();
- Toggle the speaker: On/off the phone speaker
OmicallClient.instance.toggleSpeaker();
- Send character: We only support
1 to 9
and* #
.OmicallClient.instance.sendDTMF(value);
- Get current user information:
final user = await OmicallClient.instance.getCurrentUser(); Output Sample: { "extension": "111", "full_name": "chau1", "avatar_url": "", "uuid": "122aaa" }
- Get guest user information:
final user = await OmicallClient.instance.getGuestUser(); Output Sample: { "extension": "111", "full_name": "chau1", "avatar_url": "", "uuid": "122aaa" }
- Get user information from sip:
final user = await OmicallClient.instance.getUserInfo(phone: "111"); Output Sample: { "extension": "111", "full_name": "chau1", "avatar_url": "", "uuid": "122aaa" }
- Logout:
OmicallClient.instance.logout();
-
Video Call functions: Support only video call, We need enable video in
init functions
andstart call
to implements under functions.- Switch front/back camera: We use the front camera for first time.
OmicallClient.instance.switchCamera();
- Toggle a video in video call: On/off video in video call
- OmicallClient.instance.toggleVideo();
- Register video event: Need to listen remote video ready
OmicallClient.instance.toggleVideo();
- Remove video event: Need to remove video event
OmicallClient.instance.removeVideoEvent();
- Local Camera Widget: Your camera view in a call
LocalCameraView( width: double.infinity, height: double.infinity, onCameraCreated: (controller) { _localController = controller; //we will return the controller to call some functions. }, )
- Remote Camera Widget: Remote camera view in a call
RemoteCameraView( width: double.infinity, height: double.infinity, onCameraCreated: (controller) { _remoteController = controller; }, )
- More function: Refresh camera
//camera controller receive when you create camera widget. RemoteCameraController? _remoteController; LocalCameraController? _localController; //refresh remote camera void refreshRemoteCamera() { _remoteController?.refresh(); } //refresh remote camera void localRemoteCamera() { _localController?.refresh(); }
-
Event listener:
- Important event
eventTransferStream
: We provide it to listen call state change.
- Important event
OmicallClient.instance.controller.eventTransferStream.listen((omiAction) {
}
//OmiAction have 2 variables: actionName and data
- Action Name value:
- `incomingReceived`: Have a incoming call. On Android this event work only foreground
- `onCallEstablished`: Connected a call, you will receive `transactionId` in this.
- `onCallEnd`: End a call and return call information (like endCall)
- `onHold`: `Comming soon....`
- `onMuted`: `Comming soon...`
- Data value: We return `callerNumber`, `isVideo: true/false` information
- Other events:
- Mic event: Listen on/off mic in a call
OmicallClient.instance.onMicEvent() //StreamSubscription
- Mute event: Listen on/off muted in a call
OmicallClient.instance.onMuteEvent() //StreamSubscription
- Remote video ready: Listen remote video ready.
OmicallClient.instance.videoEvent.listen((action){}) //StreamSubscription
- User tab a missed call:.
OmicallClient.instance.missedCallEvent.listen((data){}) //StreamSubscription // data is Map. Data has 3 keys: callerNumber, isVideo, transactionId (only onCallEstablished)