|
|
|
@ -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) {
|
|
|
|
await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1);
|
|
|
|
if (chatHubConnection.state == HubConnectionState.Connected) {
|
|
|
|
await invoke(invokeMethod: "HangUpAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1);
|
|
|
|
await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1);
|
|
|
|
_pc.dispose();
|
|
|
|
await invoke(invokeMethod: "HangUpAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_pc.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateConnected) {
|
|
|
|
|
|
|
|
_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 {
|
|
|
|
await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1);
|
|
|
|
if (chatHubConnection.state == HubConnectionState.Connected) {
|
|
|
|
await invoke(invokeMethod: "HangUpAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1);
|
|
|
|
await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1);
|
|
|
|
_pc.dispose();
|
|
|
|
await invoke(invokeMethod: "HangUpAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_pc.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateConnected) {
|
|
|
|
|
|
|
|
_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);
|
|
|
|
|