Ios Changes

merge-requests/188/head
Aamir Muhammad 3 years ago
parent d1ccaf7f56
commit 11227b00b4

@ -1,11 +1,13 @@
import UIKit import UIKit
import PushKit
import Flutter import Flutter
import Firebase import Firebase
import flutter_callkit_incoming
import flutter_local_notifications import flutter_local_notifications
// PKPushRegistryDelegate
@UIApplicationMain @UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate { @objc class AppDelegate: FlutterAppDelegate, PKPushRegistryDelegate {
override func application( override func application(
_ application: UIApplication, _ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
@ -18,6 +20,51 @@ import flutter_local_notifications
UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
} }
GeneratedPluginRegistrant.register(with: self) GeneratedPluginRegistrant.register(with: self)
//Setup VOIP
let mainQueue = DispatchQueue.main
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [PKPushType.voIP]
return super.application(application, didFinishLaunchingWithOptions: launchOptions) return super.application(application, didFinishLaunchingWithOptions: launchOptions)
} }
// Handle updated push credentials
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
print(credentials.token)
let deviceToken = credentials.token.map { String(format: "%02x", $0) }.joined()
print(deviceToken)
print("deviceToken From Swift")
//Save deviceToken to your server
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.setDevicePushTokenVoIP(deviceToken)
}
func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
print("didInvalidatePushTokenFor")
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.setDevicePushTokenVoIP("")
}
// Handle incoming pushes
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
print("didReceiveIncomingPushWith")
guard type == .voIP else { return }
print(payload.dictionaryPayload)
// let id = payload.dictionaryPayload["id"] as? String ?? ""
// let nameCaller = payload.dictionaryPayload["nameCaller"] as? String ?? ""
// let handle = payload.dictionaryPayload["handle"] as? String ?? ""
let isVideo = payload.dictionaryPayload["isVideo"] as? Bool ?? false
//
//
let data = flutter_callkit_incoming.Data(id: "1", nameCaller: "Mohemm", handle: "handle", type: isVideo ? 1 : 0)
// //set more data
// data.extra = ["user": "abc@123", "platform": "ios"]
// //data.iconName = ...
// //data.....
// data.appName = "Mohemm"
// data.iconName = "Mohemm"
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.showCallkitIncoming(data, fromPushKit: true)
}
} }

@ -94,5 +94,7 @@
<array> <array>
<string>TAG</string> <string>TAG</string>
</array> </array>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict> </dict>
</plist> </plist>

@ -5,7 +5,6 @@ import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart';
// import 'package:huawei_hmsavailability/huawei_hmsavailability.dart';
import 'package:huawei_push/huawei_push.dart' as huawei_push; 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/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/classes/utils.dart';

@ -23,8 +23,8 @@ class ChatVoipCall {
factory ChatVoipCall() => _instance; factory ChatVoipCall() => _instance;
late ChatProviderModel chatProvider; late ChatProviderModel prov;
late ChatCallProvider callProvider; late ChatCallProvider cProv;
dynamic inCallData; dynamic inCallData;
Future<void> showCallkitIncoming({required String uuid, RemoteMessage? data, bool isOnline = false, CallDataModel? incomingCallData}) async { Future<void> showCallkitIncoming({required String uuid, RemoteMessage? data, bool isOnline = false, CallDataModel? incomingCallData}) async {
@ -46,6 +46,7 @@ class ChatVoipCall {
await initProviders(); await initProviders();
SingleUserChatModel callerData = SingleUserChatModel.fromJson(jsonDecode(data!.data["user_chat_history_response"])); SingleUserChatModel callerData = SingleUserChatModel.fromJson(jsonDecode(data!.data["user_chat_history_response"]));
ALM.Response autoLoginData = ALM.Response.fromJson(jsonDecode(data.data["user_token_response"])); ALM.Response autoLoginData = ALM.Response.fromJson(jsonDecode(data.data["user_token_response"]));
data!.data["callType"] == "video" ? cProv.isVideoCall = true : cProv.isVideoCall = false;
CallKitParams params = CallKitParams( CallKitParams params = CallKitParams(
id: uuid, id: uuid,
nameCaller: callerData.targetUserName, nameCaller: callerData.targetUserName,
@ -108,8 +109,8 @@ class ChatVoipCall {
} }
Future<void> initProviders() async { Future<void> initProviders() async {
callProvider = Provider.of<ChatCallProvider>(AppRoutes.navigatorKey.currentContext!, listen: false); cProv = Provider.of<ChatCallProvider>(AppRoutes.navigatorKey.currentContext!, listen: false);
chatProvider = Provider.of<ChatProviderModel>(AppRoutes.navigatorKey.currentContext!, listen: false); prov = Provider.of<ChatProviderModel>(AppRoutes.navigatorKey.currentContext!, listen: false);
} }
void connection({required data}) async { void connection({required data}) async {
@ -119,10 +120,10 @@ class ChatVoipCall {
response: Response.fromJson(callData[0]["loginDetails"]), response: Response.fromJson(callData[0]["loginDetails"]),
errorResponses: null, errorResponses: null,
); );
callProvider.startIncomingCallViaKit(inCallData: inCallData); cProv.startIncomingCallViaKit(inCallData: data);
try { try {
await chatProvider.buildHubConnection(context: AppRoutes.navigatorKey.currentContext!, ccProvider: callProvider).whenComplete(() { await prov.buildHubConnection(context: AppRoutes.navigatorKey.currentContext!, ccProvider: cProv).whenComplete(() {
callProvider.init(); cProv.init();
}); });
} catch (e) { } catch (e) {
logger.w(e); logger.w(e);
@ -146,10 +147,10 @@ class ChatVoipCall {
// Navigator.pushNamed(AppRoutes.navigatorKey.currentContext!, AppRoutes.chatStartCall); // Navigator.pushNamed(AppRoutes.navigatorKey.currentContext!, AppRoutes.chatStartCall);
break; break;
case Event.ACTION_CALL_DECLINE: case Event.ACTION_CALL_DECLINE:
callProvider.isIncomingCall = true; cProv.isIncomingCall = true;
Utils.saveStringFromPrefs("isIncomingCall", "false"); Utils.saveStringFromPrefs("isIncomingCall", "false");
Utils.saveStringFromPrefs("inComingCallData", "null"); Utils.saveStringFromPrefs("inComingCallData", "null");
callProvider.endCall(); cProv.endCall();
break; break;
case Event.ACTION_CALL_ENDED: case Event.ACTION_CALL_ENDED:
Utils.saveStringFromPrefs("isIncomingCall", "false"); Utils.saveStringFromPrefs("isIncomingCall", "false");

@ -15,6 +15,7 @@ import 'package:mohem_flutter_app/models/chat/webrtc_payloads.dart';
import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; import 'package:mohem_flutter_app/provider/chat_provider_model.dart';
import 'package:mohem_flutter_app/ui/chat/call/start_call_screen.dart'; import 'package:mohem_flutter_app/ui/chat/call/start_call_screen.dart';
import 'package:mohem_flutter_app/ui/landing/dashboard_screen.dart'; import 'package:mohem_flutter_app/ui/landing/dashboard_screen.dart';
import 'package:signalr_netcore/hub_connection.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
@ -136,9 +137,13 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
Future<bool> endCall() async { Future<bool> endCall() async {
if (isIncomingCall) { if (isIncomingCall) {
if (chatHubConnection.state == HubConnectionState.Connected) {
await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1); await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1);
await invoke(invokeMethod: "HangUpAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1); await invoke(invokeMethod: "HangUpAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1);
}
if (_pc.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateConnected) {
_pc.dispose(); _pc.dispose();
}
isCallStarted = false; isCallStarted = false;
isVideoCall = false; isVideoCall = false;
isCamOff = false; isCamOff = false;
@ -149,9 +154,13 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
isIncomingCall = false; isIncomingCall = false;
return true; return true;
} else { } else {
if (chatHubConnection.state == HubConnectionState.Connected) {
await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1); await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1);
await invoke(invokeMethod: "HangUpAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1); await invoke(invokeMethod: "HangUpAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1);
}
if (_pc.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateConnected) {
_pc.dispose(); _pc.dispose();
}
isCallStarted = false; isCallStarted = false;
isVideoCall = false; isVideoCall = false;
isCamOff = false; isCamOff = false;
@ -421,16 +430,35 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
logger.i("rtc ice gathering state: " + state.name); logger.i("rtc ice gathering state: " + state.name);
}; };
pc!.onIceConnectionState = (RTCIceConnectionState state) { pc!.onIceConnectionState = (RTCIceConnectionState state) {
// invoke( if (RTCIceConnectionState.RTCIceConnectionStateFailed == state ||
// invokeMethod: "InvokeMobile", RTCIceConnectionState.RTCIceConnectionStateDisconnected == state ||
// currentUserID: AppState().getchatUserDetails!.response!.id!, RTCIceConnectionState.RTCIceConnectionStateClosed == state) {
// targetUserID: incomingCallData.targetUserId!, logger.i("Ice Connection State:" + state.name);
// debugData: {"location": "onIceConnection", "parms": state.name}); endCall();
}
}; };
pc!.onRenegotiationNeeded = () {}; pc!.onRenegotiationNeeded = _onRenegotiate;
return pc; return pc;
} }
void _onRenegotiate() async {
try {
print('onRenegotiationNeeded start');
// makingOffer = true;
await _pc.setLocalDescription(await _pc.createOffer(videoConstraints));
print('onRenegotiationNeeded state after setLocalDescription: ' + _pc.signalingState.toString());
// send offer via callManager
var localDesc = await _pc.getLocalDescription();
// callManager.sendCallMessage(MsgType.rtc_offer, RtcOfferAnswer(localDesc.sdp, localDesc.type));
print('onRenegotiationNeeded; offer sent');
} catch (e) {
print("onRenegotiationNeeded error: " + e.toString());
} finally {
// makingOffer = false;
print('onRenegotiationNeeded done');
}
}
void playRingtone() async { void playRingtone() async {
player.stop(); player.stop();
await player.setVolume(1.0); await player.setVolume(1.0);

@ -457,7 +457,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
if (isChatScreenActive && data.first.currentUserId == receiverID) { if (isChatScreenActive && data.first.currentUserId == receiverID) {
int index = userChatHistory.indexWhere((SingleUserChatModel element) => element.userChatHistoryId == 0); int index = userChatHistory.indexWhere((SingleUserChatModel element) => element.userChatHistoryId == 0);
logger.d(index);
userChatHistory[index] = data.first; userChatHistory[index] = data.first;
} }

@ -119,7 +119,7 @@ dependencies:
dependency_overrides: dependency_overrides:
firebase_core_platform_interface: 4.5.1 #firebase_core_platform_interface: 4.5.3
dev_dependencies: dev_dependencies:

Loading…
Cancel
Save