merge-requests/188/head
Aamir Muhammad 3 years ago
parent 9dd4456c51
commit 6166b5399f

@ -15,7 +15,7 @@ import 'package:mohem_flutter_app/provider/chat_call_provider.dart';
import 'package:mohem_flutter_app/provider/chat_provider_model.dart';
import 'package:provider/provider.dart';
class ChatVoipCall {
class ChatVoipCall extends WidgetsBindingObserver {
static final ChatVoipCall _instance = ChatVoipCall._internal();
ChatVoipCall._internal();
@ -26,34 +26,44 @@ class ChatVoipCall {
late ChatCallProvider cProv;
dynamic inCallData;
bool isUserOnline = false;
dynamic callData;
Future<void> showCallkitIncoming({required String uuid, RemoteMessage? data, CallDataModel? incomingCallData, bool background = false}) async {
await ChatVoipCall().listenerEvent();
//WidgetsBinding.instance.addObserver(this);
ALM.Response autoLoginData;
SingleUserChatModel callerData;
// if(!background){}
await initProviders();
if (data!.data["user_token_response"] == null || data.data["user_token_response"].isEmpty) {
autoLoginData = ALM.Response.fromJson(AppState().getchatUserDetails!.response!.toJson());
dynamic items = jsonDecode(data!.data["user_chat_history_response"]);
callerData = SingleUserChatModel(
targetUserId: items["CurrentUserId"],
targetUserEmail: items["CurrentUserName"],
targetUserName: items["CurrentUserEmail"],
targetUserEmail: items["CurrentUserEmail"],
targetUserName: items["CurrentUserName"].split("@").first,
currentUserId: autoLoginData.id,
currentUserEmail: autoLoginData.email,
currentUserName: autoLoginData.userName!.split("@").first,
currentUserName: autoLoginData.userName,
chatEventId: 3);
isUserOnline = true;
} else {
autoLoginData = ALM.Response.fromJson(jsonDecode(data.data["user_token_response"]));
callerData = SingleUserChatModel.fromJson(json.decode(data!.data["user_chat_history_response"]));
}
if (data!.data["callType"] == "video") {
cProv.isVideoCall = true;
} else {
cProv.isAudioCall = true;
cProv.isVideoCall = false;
callData = jsonEncode([
{
"loginDetails": autoLoginData.toJson(),
"callerDetails": callerData.toJson(),
}
]);
if (!background) {
await initProviders();
if (data!.data["callType"] == "video") {
cProv.isVideoCall = true;
} else {
cProv.isAudioCall = true;
cProv.isVideoCall = false;
}
}
CallKitParams params = CallKitParams(
id: uuid,
@ -99,11 +109,6 @@ class ChatVoipCall {
);
if (callerData.chatEventId == 3) {
await Utils.saveStringFromPrefs("isIncomingCall", "true");
connection(
data: jsonEncode([
{"loginDetails": autoLoginData.toJson(), "callerDetails": callerData.toJson()}
]),
isUserOnline: isUserOnline);
await FlutterCallkitIncoming.showCallkitIncoming(params);
}
}
@ -114,8 +119,8 @@ class ChatVoipCall {
}
void connection({required data, required bool isUserOnline}) async {
cProv.isUserOnline = isUserOnline;
if (isUserOnline) {
cProv.isUserOnline = isUserOnline;
cProv.startIncomingCallViaKit(inCallData: data);
} else {
dynamic callData = await jsonDecode(data);
@ -141,6 +146,7 @@ class ChatVoipCall {
switch (event!.event) {
case Event.ACTION_CALL_INCOMING:
// TODO: received an incoming call
connection(data: callData, isUserOnline: isUserOnline);
break;
case Event.ACTION_CALL_START:
// TODO: started an outgoing call
@ -150,6 +156,10 @@ class ChatVoipCall {
if (isUserOnline) {
cProv.init();
}
if (!isUserOnline) {
initProviders();
}
Navigator.pushNamed(AppRoutes.navigatorKey.currentContext!, AppRoutes.chatStartCall);
// Navigator.pushNamed(AppRoutes.navigatorKey.currentContext!, AppRoutes.chatStartCall);
@ -193,4 +203,27 @@ class ChatVoipCall {
});
} on Exception {}
}
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
switch (state) {
case AppLifecycleState.paused:
logger.i('paused');
break;
case AppLifecycleState.inactive:
logger.i('inactive');
break;
case AppLifecycleState.resumed:
logger.i('resumed');
break;
case AppLifecycleState.detached:
logger.i('detached');
break;
}
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
}
}

@ -3,8 +3,8 @@ import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart';
class ApiConsts {
//static String baseUrl = "http://10.200.204.20:2801/"; // Local server
// static String baseUrl = "https://erptstapp.srca.org.sa"; // SRCA server
static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server
// static String baseUrl = "https://hmgwebservices.com"; // Live server
// static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server
static String baseUrl = "https://hmgwebservices.com"; // Live server
static String baseUrlServices = baseUrl + "/Services/"; // server
// static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server
static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/";

@ -2,21 +2,21 @@ import 'dart:io';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:huawei_push/huawei_push.dart' as huawei_push;
import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/classes/chat_call_kit.dart';
import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/main.dart';
import 'package:mohem_flutter_app/provider/chat_call_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:uuid/uuid.dart';
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
class AppNotifications {
class AppNotifications extends WidgetsBindingObserver {
static final AppNotifications _instance = AppNotifications._internal();
AppNotifications._internal();
@ -60,7 +60,7 @@ class AppNotifications {
if (initialMessage != null) _handleMessage(initialMessage);
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
if (message != null) _handleMessage(message);
if (message != null) _handleMessage(message);
});
FirebaseMessaging.onMessageOpenedApp.listen(_handleOpenApp);
@ -89,8 +89,12 @@ class AppNotifications {
// print(err);
// });
}
}
void initHuaweiPush(Function loginCallback) {
AppState().setIsHuawei = true;
initTokenStream(loginCallback);
@ -115,12 +119,13 @@ class AppNotifications {
}
void _handleMessage(RemoteMessage message) {
logger.d("=============== appOpen ======================");
Utils.saveStringFromPrefs("isAppOpendByChat", "false");
if (message.data.isNotEmpty && message.data["messageType"] == 'chat') {
Utils.saveStringFromPrefs("isAppOpendByChat", "true");
Utils.saveStringFromPrefs("notificationData", message.data["user_chat_history_response"].toString());
} else if (message.data.isNotEmpty && message.data["messageType"] == 'call') {
if( Platform.isAndroid){
if (Platform.isAndroid) {
ChatVoipCall().showCallkitIncoming(uuid: const Uuid().v4(), data: message);
}
}
@ -133,6 +138,8 @@ class AppNotifications {
}
}
}
AndroidNotificationChannel channel = const AndroidNotificationChannel(
"high_importance_channel",
"High Importance Notifications",
@ -141,12 +148,15 @@ AndroidNotificationChannel channel = const AndroidNotificationChannel(
Future<dynamic> backgroundMessageHandler(RemoteMessage message) async {
await Firebase.initializeApp();
logger.d("=============== appBackground ======================");
if (message.data.isNotEmpty && message.data["messageType"] == 'chat') {
Utils.saveStringFromPrefs("isAppOpendByChat", "false");
Utils.saveStringFromPrefs("notificationData", message.data["user_chat_history_response"].toString());
} else if (message.data.isNotEmpty && message.data["messageType"] == 'call') {
if( Platform.isAndroid) {
if (Platform.isAndroid) {
ChatVoipCall().showCallkitIncoming(uuid: const Uuid().v4(), data: message, background: true);
}
}
}

@ -202,6 +202,8 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
await invoke(invokeMethod: "HangUpAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 0);
}
if (_pc.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateConnected) {
print("------------------ PC Stopped ----------------------------");
_pc.close();
_pc.dispose();
}
isCallStarted = false;
@ -224,6 +226,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1);
}
if (_pc.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateConnected) {
_pc.close();
_pc.dispose();
}
isCallStarted = false;

Loading…
Cancel
Save