|
|
|
|
@ -65,7 +65,6 @@ class _LoginScreenState extends State<LoginScreen> with WidgetsBindingObserver{
|
|
|
|
|
late final FirebaseMessaging _firebaseMessaging;
|
|
|
|
|
IosCallPayload? _iosCallPayload;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool _autoLogin = false;
|
|
|
|
|
|
|
|
|
|
bool? isAppOpenBySystem;
|
|
|
|
|
@ -81,7 +80,6 @@ class _LoginScreenState extends State<LoginScreen> with WidgetsBindingObserver{
|
|
|
|
|
final voIPKit = FlutterIOSVoIPKit.instance;
|
|
|
|
|
late Timer timeOutTimer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
@ -98,38 +96,25 @@ class _LoginScreenState extends State<LoginScreen> with WidgetsBindingObserver{
|
|
|
|
|
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',
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IOS Voip Call
|
|
|
|
|
void setupVoIPCallBacks() {
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
voIPKit.getVoIPToken().then((value) {
|
|
|
|
|
print('🎈 example: getVoIPToken: $value');
|
|
|
|
|
ChatApiClient().OneSignalVoip(deviceID: value!);
|
|
|
|
|
voIPKit.getVoIPToken().then((value) async {
|
|
|
|
|
if (value != null) {
|
|
|
|
|
AppState().setiosVoipPlayerID = await ChatApiClient().oneSignalVoip(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');
|
|
|
|
|
isIncomingCall = true;
|
|
|
|
|
_timeOut();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -137,9 +122,8 @@ class _LoginScreenState extends State<LoginScreen> with WidgetsBindingObserver{
|
|
|
|
|
String uuid,
|
|
|
|
|
String callerId,
|
|
|
|
|
) async {
|
|
|
|
|
try {
|
|
|
|
|
var logText = "did reject call $callerId";
|
|
|
|
|
} catch (err) {}
|
|
|
|
|
await ChatVoipCall().voipDeclineCall(_iosCallPayload);
|
|
|
|
|
await voIPKit.endCall();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
voIPKit.onDidAcceptIncomingCall = (
|
|
|
|
|
@ -147,33 +131,35 @@ class _LoginScreenState extends State<LoginScreen> with WidgetsBindingObserver{
|
|
|
|
|
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);
|
|
|
|
|
timeOutTimer.cancel();
|
|
|
|
|
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 _timeOut() async {
|
|
|
|
|
timeOutTimer = Timer(const Duration(seconds: 25), () async {
|
|
|
|
|
var incomingCallerName = await voIPKit.getIncomingCallerName();
|
|
|
|
|
voIPKit.unansweredIncomingCall(
|
|
|
|
|
skipLocalNotification: false,
|
|
|
|
|
missedCallTitle: '📞 Missed call',
|
|
|
|
|
missedCallBody: 'There was a call from $incomingCallerName',
|
|
|
|
|
);
|
|
|
|
|
await ChatVoipCall().voipDeclineCall(_iosCallPayload);
|
|
|
|
|
await voIPKit.endCall();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
BuildContext context = AppRoutes.navigatorKey.currentContext!;
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.saveStringFromPrefs("iosCallPayload", jsonEncode(_iosCallPayload));
|
|
|
|
|
var pageRoute = MaterialPageRoute(builder: (context) => StartCallPage());
|
|
|
|
|
Navigator.push(context, pageRoute).whenComplete(() {
|
|
|
|
|
checkFirebaseToken();
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
logger.d(e);
|
|
|
|
|
}
|
|
|
|
|
@ -206,13 +192,11 @@ class _LoginScreenState extends State<LoginScreen> with WidgetsBindingObserver{
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> callListeners() async {
|
|
|
|
|
try {
|
|
|
|
|
print("Call Listeners Init");
|
|
|
|
|
FlutterCallkitIncoming.onEvent.listen((CallEvent? event) async {
|
|
|
|
|
switch (event!.event) {
|
|
|
|
|
|
|
|
|
|
case Event.actionCallIncoming:
|
|
|
|
|
break;
|
|
|
|
|
case Event.actionCallStart:
|
|
|
|
|
@ -239,10 +223,8 @@ class _LoginScreenState extends State<LoginScreen> with WidgetsBindingObserver{
|
|
|
|
|
Utils.saveStringFromPrefs("inComingCallData", "null");
|
|
|
|
|
FlutterCallkitIncoming.endAllCalls();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
print('${event.toString()}\n');
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
} on Exception {
|
|
|
|
|
logger.log(Level.info, "EXCEPTION-ON-EVENTS");
|
|
|
|
|
@ -289,9 +271,6 @@ class _LoginScreenState extends State<LoginScreen> with WidgetsBindingObserver{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
super.dispose();
|
|
|
|
|
|