@ -1,7 +1,8 @@
import ' dart:async ' ;
import ' dart:convert ' ;
import ' dart:io ' ;
import ' package:flutter_callkit_incoming/entities/call_event.dart ' ;
import ' package:uuid/uuid.dart ' ;
import ' package:diplomaticquarterapp/config/config.dart ' ;
import ' package:diplomaticquarterapp/config/shared_pref_kay.dart ' ;
import ' package:diplomaticquarterapp/core/model/notifications/get_notifications_response_model.dart ' ;
@ -22,6 +23,12 @@ import 'package:firebase_messaging/firebase_messaging.dart' as fir;
import ' package:flutter/cupertino.dart ' ;
import ' package:flutter/foundation.dart ' ;
import ' package:flutter/material.dart ' ;
import ' package:flutter_callkit_incoming/entities/android_params.dart ' ;
import ' package:flutter_callkit_incoming/entities/call_kit_params.dart ' ;
import ' package:flutter_callkit_incoming/entities/ios_params.dart ' ;
import ' package:flutter_callkit_incoming/entities/notification_params.dart ' ;
import ' package:flutter_callkit_incoming/flutter_callkit_incoming.dart ' ;
import ' package:flutter_incoming_call/flutter_incoming_call.dart ' ;
/ / import ' package:flutter_ios_voip_kit/call_state_type.dart ' ;
/ / import ' package:flutter_ios_voip_kit/flutter_ios_voip_kit.dart ' ;
@ -31,6 +38,7 @@ import 'package:huawei_hmsavailability/huawei_hmsavailability.dart';
import ' package:huawei_push/huawei_push.dart ' as h_push ;
import ' package:permission_handler/permission_handler.dart ' ;
import ' ../pages/conference/widgets/platform_exception_alert_dialog.dart ' ;
import ' app_shared_preferences.dart ' ;
import ' navigation_service.dart ' ;
@ -44,7 +52,6 @@ Future<dynamic> backgroundMessageHandler(dynamic message) async {
message_ = toFirebaseRemoteMessage ( message ) ;
h_push . Push . localNotification ( { h_push . HMSLocalNotificationAttr . TITLE: ' Background Message ' , h_push . HMSLocalNotificationAttr . MESSAGE: " By: BackgroundMessageHandler " } ) ;
}
if ( message . data ! = null & & ( message . data [ ' is_call ' ] = = ' true ' | | message . data [ ' is_call ' ] = = true ) ) {
/ / showCallkitIncoming ( message ) ;
_incomingCall ( message . data ) ;
@ -162,18 +169,159 @@ callPage(String sessionID, String token) async {
_incomingCall ( Map < String , dynamic > data ) async {
LandingPage . incomingCallData = IncomingCallData . fromJson ( data ) ;
var dataItem = await AppSharedPreferences ( ) . getObject ( ' call_data ' ) ;
if ( dataItem ! = null ) return ; / / to stop repeated attempt to invoke the call
if ( LandingPage . isOpenCallPage = = false ) {
LandingPage . isOpenCallPage = true ;
final bool permited = await AppPermission . askVideoCallPermission ( currentContext ! ) ;
if ( permited )
await NavigationService . navigateToPage (
IncomingCall ( incomingCallData: LandingPage . incomingCallData ) ,
) ;
WidgetsFlutterBinding . ensureInitialized ( ) ;
var _currentUuid = Uuid ( ) . v4 ( ) ;
CallKitParams callKitParams = CallKitParams (
id: _currentUuid ,
nameCaller: " ${ LandingPage . incomingCallData . doctorname } "
" \n Dr Sulaiman Al Habib \n ${ LandingPage . incomingCallData . clinicname } " ,
appName: ' Dr Sulaiman Al Habib ' ,
avatar: ' ' ,
handle: LandingPage . incomingCallData . name ,
type: 0 ,
textAccept: ' Accept ' ,
textDecline: ' Decline ' ,
missedCallNotification: NotificationParams (
showNotification: true ,
isShowCallback: false ,
subtitle: ' Missed call ' ,
callbackText: ' ' ,
) ,
callingNotification: const NotificationParams (
showNotification: true ,
isShowCallback: true ,
subtitle: ' Calling... ' ,
callbackText: ' Hang Up ' ,
) ,
duration: 30000 ,
extra: < String , dynamic > { ' userId ' : ' 1a2b3c4d ' } ,
headers: < String , dynamic > { ' apiKey ' : ' Abc@123! ' , ' platform ' : ' flutter ' } ,
android: const AndroidParams (
isCustomNotification: true ,
isShowLogo: false ,
logoUrl: ' ' ,
ringtonePath: ' system_ringtone_default ' ,
backgroundColor: ' #D02127 ' ,
backgroundUrl: ' ' ,
actionColor: ' #4CAF50 ' ,
textColor: ' #ffffff ' ,
incomingCallNotificationChannelName: " Incoming Call " ,
missedCallNotificationChannelName: " Missed Call " ,
isShowCallID: false
) ,
ios: IOSParams (
iconName: ' Dr Sulaiman Al Habib ' ,
handleType: ' generic ' ,
supportsVideo: true ,
maximumCallGroups: 2 ,
maximumCallsPerCallGroup: 1 ,
audioSessionMode: ' default ' ,
audioSessionActive: true ,
audioSessionPreferredSampleRate: 44100.0 ,
audioSessionPreferredIOBufferDuration: 0.005 ,
supportsDTMF: true ,
supportsHolding: true ,
supportsGrouping: false ,
supportsUngrouping: false ,
ringtonePath: ' system_ringtone_default ' ,
) ,
) ;
await FlutterCallkitIncoming . showCallkitIncoming ( callKitParams ) ;
try {
FlutterCallkitIncoming . onEvent . listen ( ( event ) async {
switch ( event ! . event ) {
case Event . actionCallIncoming:
break ;
case Event . actionCallStart:
break ;
case Event . actionCallAccept:
await FlutterCallkitIncoming . endAllCalls ( ) ;
try {
openCallPage ( LandingPage . incomingCallData ,
locator < NavigationService > ( ) . navigatorKey
. currentContext ! ) ;
} catch ( e ) {
await AppSharedPreferences ( ) . setObject ( ' call_data ' , data ) ;
var data1 = await AppSharedPreferences ( ) . getObject ( ' call_data ' ) ;
}
break ;
case Event . actionCallDecline:
break ;
case Event . actionCallEnded:
break ;
case Event . actionCallTimeout:
break ;
case Event . actionCallCallback:
break ;
case Event . actionCallToggleHold:
break ;
case Event . actionCallToggleMute:
break ;
case Event . actionCallToggleDmtf:
break ;
case Event . actionCallToggleGroup:
break ;
case Event . actionCallToggleAudioSession:
break ;
case Event . actionDidUpdateDevicePushTokenVoip:
break ;
case Event . actionCallCustom:
break ;
}
} ) ;
} on Exception catch ( e ) {
print ( e ) ;
}
}
LandingPage . isOpenCallPage = false ;
await Future . delayed ( Duration ( milliseconds: 500 ) ) ;
}
Future < void > openCallPage ( IncomingCallData incomingCallData , BuildContext context ) async {
try {
LandingPage . isOpenCallPage = false ;
if ( incomingCallData ! . background = = " 0 " ) {
/ / Zoom Call Page
/ / Navigator . of ( context ) . pop ( ) ;
Navigator . pushReplacementNamed (
context ,
" zoom_call_page " ,
arguments: CallArguments ( incomingCallData ! . sessionId ! , " 123 " , " Patient " , " 40 " , " 0 " , false , int . parse ( incomingCallData ! . appointmentNo ! ) ) ,
) ;
} else {
/ / OpenTok Call Page
await Navigator . of ( context ) . pushReplacement (
MaterialPageRoute (
/ / fullscreenDialog: true ,
builder: ( BuildContext context ) {
/ / final caller = widget . incomingCallData . callerID ;
/ / final receiver = widget . incomingCallData . receiverID ;
/ / final host = widget . incomingCallData . server ;
/ / if ( widget . incomingCallData . isWebRTC = = " true " ) {
/ / return StartVideoCall ( caller: caller , receiver: receiver , iAmCaller: false , host: host ) ;
/ / } else {
return OpenTokConnectCallPage ( apiKey: OPENTOK_API_KEY , sessionId: incomingCallData ! . sessionId ! , token: incomingCallData ! . token ! ) ;
} ,
) ,
) ;
}
} catch ( err ) {
print ( err ) ;
await PlatformExceptionAlertDialog (
exception: Exception ( err ) ,
) . show ( context ) ;
}
await Future . delayed ( Duration ( milliseconds: 500 ) ) ;
await AppSharedPreferences ( ) . remove ( ' call_data ' ) ;
}
class PushNotificationHandler {
@ -382,7 +530,6 @@ class PushNotificationHandler {
/ / } ) ;
/ / }
FirebaseMessaging . onBackgroundMessage ( backgroundMessageHandler ) ;
}
newMessage ( RemoteMessage remoteMessage ) async {
@ -440,10 +587,6 @@ class PushNotificationHandler {
}
onResume ( ) async {
var call_data = await AppSharedPreferences ( ) . getObject ( ' call_data ' ) ;
if ( call_data ! = null ) {
_incomingCall ( call_data ) ;
}
}
Future < void > requestPermissions ( ) async {