diff --git a/lib/api/chat/chat_api_client.dart b/lib/api/chat/chat_api_client.dart index 275f10b..77dcb34 100644 --- a/lib/api/chat/chat_api_client.dart +++ b/lib/api/chat/chat_api_client.dart @@ -186,4 +186,18 @@ class ChatApiClient { } return imagesData; } + + // Call Decline On App Terminated State + + Future callDecline({required int cUserID, required int tUserID, required String targetUsertoken}) async { + Response response = await ApiClient().postJsonForResponse( + "${ApiConsts.chatLoginTokenUrl}calldecline", + {"currentUserId": cUserID, "targetUserId": tUserID, "secretKey": "derichatmobileuser", "targetUserToken": targetUsertoken}, + ); + if (!kReleaseMode) { + logger.i({"currentUserId": cUserID, "targetUserId": tUserID, "secretKey": "derichatmobileuser", "targetUserToken": targetUsertoken}); + logger.i("res: " + response.body); + } + return response; + } } diff --git a/lib/classes/chat_call_kit.dart b/lib/classes/chat_call_kit.dart index 7440cfb..65da5c1 100644 --- a/lib/classes/chat_call_kit.dart +++ b/lib/classes/chat_call_kit.dart @@ -1,9 +1,9 @@ import 'dart:convert'; -import 'dart:math'; -import 'package:easy_localization/easy_localization.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_callkit_incoming/entities/entities.dart'; import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; +import 'package:mohem_flutter_app/api/chat/chat_api_client.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/consts.dart'; import 'package:mohem_flutter_app/classes/utils.dart'; @@ -124,29 +124,7 @@ class ChatVoipCall { } } } else { - Utils.showToast("Offline END Call", longDuration: true); - HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true); - HubConnection _bghc = HubConnectionBuilder() - .withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${data.extra!.loginDetails!.id}&source=Desktop&access_token=${data.extra?.loginDetails!.token}", options: httpOp) - .withAutomaticReconnect(retryDelays: [2000, 5000, 10000, 20000]).build(); - await _bghc.start(); - await _bghc.invoke( - "HangUpAsync", - args: [ - data.extra!.callerDetails!.currentUserId!, - data.extra!.callerDetails!.targetUserId!, - ], - ); - _bghc.invoke("UpdateUserStatusAsync", args: [ - int.parse(data.extra!.callerDetails!.currentUserId.toString()), - 2, - ]); - FlutterCallkitIncoming.endAllCalls(); - if (!isUserOnline) { - _bghc.stop(); - } else { - chatHubConnection = _bghc; - } + await ChatApiClient().callDecline(cUserID: data.extra!.callerDetails!.targetUserId!, tUserID: data.extra!.callerDetails!.currentUserId!, targetUsertoken: data.extra!.loginDetails!.token!); } } diff --git a/lib/classes/notifications.dart b/lib/classes/notifications.dart index d718874..8036a72 100644 --- a/lib/classes/notifications.dart +++ b/lib/classes/notifications.dart @@ -1,5 +1,4 @@ import 'dart:io'; - import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/cupertino.dart'; diff --git a/lib/ui/landing/dashboard_screen.dart b/lib/ui/landing/dashboard_screen.dart index 290501a..898b316 100644 --- a/lib/ui/landing/dashboard_screen.dart +++ b/lib/ui/landing/dashboard_screen.dart @@ -64,18 +64,17 @@ class _DashboardScreenState extends State with WidgetsBindingOb void initState() { WidgetsBinding.instance.addObserver(this); super.initState(); - - // callListeners(); - scheduleMicrotask(() { - data = Provider.of(context, listen: false); - marathonProvider = Provider.of(context, listen: false); - cProvider = Provider.of(context, listen: false); - chatCallProvider = Provider.of(context, listen: false); - if (checkIfPrivilegedForChat()) { - _bHubCon(); - } - _onRefresh(true); - }); + callListeners(); + scheduleMicrotask(() { + data = Provider.of(context, listen: false); + marathonProvider = Provider.of(context, listen: false); + cProvider = Provider.of(context, listen: false); + chatCallProvider = Provider.of(context, listen: false); + if (checkIfPrivilegedForChat()) { + _bHubCon(); + } + _onRefresh(true); + }); } Future callListeners() async { @@ -115,7 +114,7 @@ class _DashboardScreenState extends State with WidgetsBindingOb dynamic calls = await FlutterCallkitIncoming.activeCalls(); if (calls is List) { if (calls.isNotEmpty) { - Future.delayed(const Duration(seconds: 3)).whenComplete(() { + Future.delayed(const Duration(seconds: 1)).whenComplete(() { MaterialPageRoute pageRoute = MaterialPageRoute(builder: (BuildContext context) => StartCallPage()); Navigator.push(context, pageRoute); }); diff --git a/lib/ui/login/login_screen.dart b/lib/ui/login/login_screen.dart index f669158..fd53752 100644 --- a/lib/ui/login/login_screen.dart +++ b/lib/ui/login/login_screen.dart @@ -119,7 +119,7 @@ class _LoginScreenState extends State { 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"); @@ -252,10 +252,7 @@ class _LoginScreenState extends State { @override Widget build(BuildContext context) { if (isAppOpenBySystem == null) { - isAppOpenBySystem = (ModalRoute - .of(context)! - .settings - .arguments ?? true) as bool; + isAppOpenBySystem = (ModalRoute.of(context)!.settings.arguments ?? true) as bool; if (!kReleaseMode) { // username.text = "15444"; // Maha User // username.text = "15153"; // Tamer User