|  |  |  | @ -1,3 +1,4 @@ | 
		
	
		
			
				|  |  |  |  | import 'dart:async'; | 
		
	
		
			
				|  |  |  |  | import 'dart:convert'; | 
		
	
		
			
				|  |  |  |  | import 'dart:io'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | @ -11,6 +12,9 @@ import 'package:flutter/material.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter/services.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter_callkit_incoming/entities/call_event.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter_ios_voip_kit/call_state_type.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter_ios_voip_kit/flutter_ios_voip_kit.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/api/chat/chat_api_client.dart'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | // import 'package:huawei_hmsavailability/huawei_hmsavailability.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/api/login_api_client.dart'; | 
		
	
	
		
			
				
					|  |  |  | @ -26,7 +30,8 @@ import 'package:mohem_flutter_app/extensions/string_extensions.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/main.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/chat/incoming_call_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/chat/call.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/check_mobile_app_version_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/get_mobile_login_info_list_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/member_information_list_model.dart'; | 
		
	
	
		
			
				
					|  |  |  | @ -48,7 +53,7 @@ class LoginScreen extends StatefulWidget { | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | class _LoginScreenState extends State<LoginScreen> { | 
		
	
		
			
				|  |  |  |  | class _LoginScreenState extends State<LoginScreen> with WidgetsBindingObserver { | 
		
	
		
			
				|  |  |  |  |   TextEditingController username = TextEditingController(); | 
		
	
		
			
				|  |  |  |  |   TextEditingController password = TextEditingController(); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | @ -56,6 +61,7 @@ class _LoginScreenState extends State<LoginScreen> { | 
		
	
		
			
				|  |  |  |  |   MemberLoginListModel? _memberLoginList; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   late final FirebaseMessaging _firebaseMessaging; | 
		
	
		
			
				|  |  |  |  |   IosCallPayload? _iosCallPayload; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   bool _autoLogin = false; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | @ -69,6 +75,9 @@ class _LoginScreenState extends State<LoginScreen> { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   // late HmsApiAvailability hmsApiAvailability; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   final voIPKit = FlutterIOSVoIPKit.instance; | 
		
	
		
			
				|  |  |  |  |   late Timer timeOutTimer; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   @override | 
		
	
		
			
				|  |  |  |  |   void initState() { | 
		
	
		
			
				|  |  |  |  |     super.initState(); | 
		
	
	
		
			
				
					|  |  |  | @ -78,6 +87,74 @@ class _LoginScreenState extends State<LoginScreen> { | 
		
	
		
			
				|  |  |  |  |     //   checkDeviceSafety(); | 
		
	
		
			
				|  |  |  |  |     // } | 
		
	
		
			
				|  |  |  |  |     callListeners(); | 
		
	
		
			
				|  |  |  |  |     WidgetsBinding.instance.addObserver(this); | 
		
	
		
			
				|  |  |  |  |     setupVoIPCallBacks(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void _timeOut({ | 
		
	
		
			
				|  |  |  |  |     int seconds = 15, | 
		
	
		
			
				|  |  |  |  |   }) async { | 
		
	
		
			
				|  |  |  |  |     timeOutTimer = Timer(Duration(seconds: seconds), () async { | 
		
	
		
			
				|  |  |  |  |       print('🎈 example: timeOut'); | 
		
	
		
			
				|  |  |  |  |       var incomingCallerName = await voIPKit.getIncomingCallerName(); | 
		
	
		
			
				|  |  |  |  |       voIPKit.unansweredIncomingCall( | 
		
	
		
			
				|  |  |  |  |         skipLocalNotification: false, | 
		
	
		
			
				|  |  |  |  |         missedCallTitle: '📞 Missed call', | 
		
	
		
			
				|  |  |  |  |         missedCallBody: 'There was a call from $incomingCallerName', | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  |     }); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void setupVoIPCallBacks() { | 
		
	
		
			
				|  |  |  |  |     if (Platform.isIOS) { | 
		
	
		
			
				|  |  |  |  |       voIPKit.getVoIPToken().then((value) { | 
		
	
		
			
				|  |  |  |  |         print('🎈 example: getVoIPToken: $value'); | 
		
	
		
			
				|  |  |  |  |       }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       voIPKit.onDidUpdatePushToken = (String token) { | 
		
	
		
			
				|  |  |  |  |         print('🎈 example: onDidUpdatePushToken: $token'); | 
		
	
		
			
				|  |  |  |  |       }; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     voIPKit.onDidReceiveIncomingPush = ( | 
		
	
		
			
				|  |  |  |  |       Map<String, dynamic> payload, | 
		
	
		
			
				|  |  |  |  |     ) async { | 
		
	
		
			
				|  |  |  |  |       _iosCallPayload = IosCallPayload.fromJson(payload); | 
		
	
		
			
				|  |  |  |  |       logger.d(_iosCallPayload!.incomingCallerId!.split("-").last); | 
		
	
		
			
				|  |  |  |  |       print('🎈 example: onDidReceiveIncomingPush $payload'); | 
		
	
		
			
				|  |  |  |  |       _timeOut(); | 
		
	
		
			
				|  |  |  |  |     }; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     voIPKit.onDidRejectIncomingCall = ( | 
		
	
		
			
				|  |  |  |  |       String uuid, | 
		
	
		
			
				|  |  |  |  |       String callerId, | 
		
	
		
			
				|  |  |  |  |     ) async { | 
		
	
		
			
				|  |  |  |  |       try { | 
		
	
		
			
				|  |  |  |  |         var logText = "did reject call $callerId"; | 
		
	
		
			
				|  |  |  |  |       } catch (err) {} | 
		
	
		
			
				|  |  |  |  |     }; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     voIPKit.onDidAcceptIncomingCall = ( | 
		
	
		
			
				|  |  |  |  |       String uuid, | 
		
	
		
			
				|  |  |  |  |       String callerId, | 
		
	
		
			
				|  |  |  |  |     ) async { | 
		
	
		
			
				|  |  |  |  |       var callerID = "did accept call $callerId"; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       debugPrint(callerID); | 
		
	
		
			
				|  |  |  |  |       logger.d(_iosCallPayload!.incomingCallerId!.split("-").last); | 
		
	
		
			
				|  |  |  |  |       debugPrint(_iosCallPayload!.incomingCallerId); | 
		
	
		
			
				|  |  |  |  |       debugPrint(_iosCallPayload!.incomingCallerName); | 
		
	
		
			
				|  |  |  |  |       debugPrint(_iosCallPayload!.incomingCallType); | 
		
	
		
			
				|  |  |  |  |       await connectCall(); | 
		
	
		
			
				|  |  |  |  |       await voIPKit.acceptIncomingCall(callerState: CallStateType.calling); | 
		
	
		
			
				|  |  |  |  |       await voIPKit.callConnected(); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       Future.delayed(const Duration(milliseconds: 2500), () { | 
		
	
		
			
				|  |  |  |  |         voIPKit.endCall().then((value) async {}); | 
		
	
		
			
				|  |  |  |  |       }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       timeOutTimer.cancel(); | 
		
	
		
			
				|  |  |  |  |     }; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   // void checkDeviceSafety() async { | 
		
	
	
		
			
				
					|  |  |  | @ -95,6 +172,17 @@ class _LoginScreenState extends State<LoginScreen> { | 
		
	
		
			
				|  |  |  |  |   //     print(error); | 
		
	
		
			
				|  |  |  |  |   //   } | 
		
	
		
			
				|  |  |  |  |   // } | 
		
	
		
			
				|  |  |  |  |   Future<void> connectCall() async { | 
		
	
		
			
				|  |  |  |  |     try { | 
		
	
		
			
				|  |  |  |  |       UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserCallToken(userid: _iosCallPayload!.incomingCallerId!.split("-").last); | 
		
	
		
			
				|  |  |  |  |       if (userLoginResponse.response != null) { | 
		
	
		
			
				|  |  |  |  |         AppState().setchatUserDetails = userLoginResponse; | 
		
	
		
			
				|  |  |  |  |         Utils.saveStringFromPrefs("userLoginChatDetails", jsonEncode(userLoginResponse.response)); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } catch (e) { | 
		
	
		
			
				|  |  |  |  |       logger.d(e); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> callListeners() async { | 
		
	
		
			
				|  |  |  |  |     try { | 
		
	
	
		
			
				
					|  |  |  | @ -119,7 +207,7 @@ class _LoginScreenState extends State<LoginScreen> { | 
		
	
		
			
				|  |  |  |  |           case Event.ACTION_CALL_ENDED: | 
		
	
		
			
				|  |  |  |  |             Utils.saveStringFromPrefs("isIncomingCall", "false"); | 
		
	
		
			
				|  |  |  |  |             Utils.saveStringFromPrefs("inComingCallData", "null"); | 
		
	
		
			
				|  |  |  |  |            FlutterCallkitIncoming.endAllCalls(); | 
		
	
		
			
				|  |  |  |  |             FlutterCallkitIncoming.endAllCalls(); | 
		
	
		
			
				|  |  |  |  |             break; | 
		
	
		
			
				|  |  |  |  |           case Event.ACTION_CALL_TIMEOUT: | 
		
	
		
			
				|  |  |  |  |             Utils.saveStringFromPrefs("isIncomingCall", "false"); | 
		
	
	
		
			
				
					|  |  |  | @ -135,19 +223,20 @@ class _LoginScreenState extends State<LoginScreen> { | 
		
	
		
			
				|  |  |  |  |     dynamic calls = await FlutterCallkitIncoming.activeCalls(); | 
		
	
		
			
				|  |  |  |  |     if (calls is List) { | 
		
	
		
			
				|  |  |  |  |       if (calls.isNotEmpty) { | 
		
	
		
			
				|  |  |  |  |         Utils.hideLoading(context); | 
		
	
		
			
				|  |  |  |  |         if (Platform.isAndroid) { | 
		
	
		
			
				|  |  |  |  |           Utils.hideLoading(context); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |         var pageRoute = MaterialPageRoute(builder: (context) => StartCallPage()); | 
		
	
		
			
				|  |  |  |  |         Navigator.push(context, pageRoute).whenComplete((){ | 
		
	
		
			
				|  |  |  |  |         Navigator.push(context, pageRoute).whenComplete(() { | 
		
	
		
			
				|  |  |  |  |           checkFirebaseToken(); | 
		
	
		
			
				|  |  |  |  |         }); | 
		
	
		
			
				|  |  |  |  |       }else{ | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         FlutterCallkitIncoming.endAllCalls(); | 
		
	
		
			
				|  |  |  |  |         Utils.showToast("Something wen't wrong"); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   @override | 
		
	
		
			
				|  |  |  |  |   void dispose() { | 
		
	
		
			
				|  |  |  |  |     super.dispose(); | 
		
	
	
		
			
				
					|  |  |  | 
 |