|
|
|
|
@ -3,10 +3,6 @@ import 'dart:io';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_callkit_incoming/entities/android_params.dart';
|
|
|
|
|
import 'package:flutter_callkit_incoming/entities/call_event.dart';
|
|
|
|
|
import 'package:flutter_callkit_incoming/entities/call_kit_params.dart';
|
|
|
|
|
import 'package:flutter_callkit_incoming/entities/ios_params.dart';
|
|
|
|
|
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
|
|
|
|
import 'package:just_audio/just_audio.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
|
|
|
@ -31,7 +27,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
final AudioPlayer player = AudioPlayer();
|
|
|
|
|
late MediaStream localStream;
|
|
|
|
|
late CallDataModel outGoingCallData;
|
|
|
|
|
late IncomingCallDataPayload incomingCallData;
|
|
|
|
|
late IncomingCallDataPayload inComingCallData;
|
|
|
|
|
bool isMicOff = false;
|
|
|
|
|
bool isLoudSpeaker = false;
|
|
|
|
|
bool isCamOff = false;
|
|
|
|
|
@ -43,11 +39,12 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
/// WebRTC Connection Variables
|
|
|
|
|
bool _offer = false;
|
|
|
|
|
|
|
|
|
|
bool isIncomingCallLoader = true;
|
|
|
|
|
|
|
|
|
|
late BuildContext providerContext;
|
|
|
|
|
|
|
|
|
|
/// Temp Variable Remove After Development
|
|
|
|
|
var tempPayLoad;
|
|
|
|
|
|
|
|
|
|
void initCallListeners({required BuildContext context}) {
|
|
|
|
|
providerContext = context;
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
@ -59,7 +56,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
chatHubConnection.on("OnAnswerOffer", onAnswerOffer);
|
|
|
|
|
chatHubConnection.on("OnHangUpAsync", onHangUpAsync);
|
|
|
|
|
chatHubConnection.on("OnCallDeclinedAsync", onCallDeclinedAsync);
|
|
|
|
|
chatHubConnection.on("OnIncomingCallAsync", OnIncomingCallAsync);
|
|
|
|
|
// chatHubConnection.on("OnIncomingCallAsync", OnIncomingCallAsync);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Video Constraints
|
|
|
|
|
@ -149,13 +146,6 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> startIncomingCall() async {
|
|
|
|
|
await localVideoRenderer.initialize();
|
|
|
|
|
localStream = await navigator.mediaDevices.getUserMedia(isVideoCall ? videoConstraints : audioConstraints);
|
|
|
|
|
localVideoRenderer.srcObject = localStream;
|
|
|
|
|
await remoteRenderer.initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OutGoing Listeners
|
|
|
|
|
void onCallAcceptedAsync(List<Object?>? params) async {
|
|
|
|
|
print("--------------------- On Call Accept ---------------------------------------");
|
|
|
|
|
@ -192,8 +182,14 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onOfferAsync(List<Object?>? params) {
|
|
|
|
|
print("--------------------- onOfferAsync ---------------------------------------");
|
|
|
|
|
Future<void> onOfferAsync(List<Object?>? params) async {
|
|
|
|
|
// tempPayLoad = {"values": params!.toList()};
|
|
|
|
|
dynamic items = params!.toList();
|
|
|
|
|
RTCSessionDescription description = await _createAnswer();
|
|
|
|
|
await _pc.setLocalDescription(description);
|
|
|
|
|
var payload = {"target": items[0]["id"], "caller": outGoingCallData.callerId, "sdp": description.toMap()};
|
|
|
|
|
invoke(invokeMethod: "AnswerOffer", currentUserID: outGoingCallData.callerId!, targetUserID: items[0]["id"], data: jsonEncode(payload));
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Incoming Listeners
|
|
|
|
|
@ -264,7 +260,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
Future<void> invoke({required String invokeMethod, required int currentUserID, required int targetUserID, var data, int userStatus = 1}) async {
|
|
|
|
|
List<Object> args = [];
|
|
|
|
|
Utils.showToast(currentUserID.toString() + " -- " + targetUserID.toString() + " -- " + isVideoCall.toString());
|
|
|
|
|
// Utils.showToast(currentUserID.toString() + " -- " + targetUserID.toString() + " -- " + isVideoCall.toString());
|
|
|
|
|
if (invokeMethod == "CallUserAsync") {
|
|
|
|
|
args = [currentUserID, targetUserID, isVideoCall];
|
|
|
|
|
} else if (invokeMethod == "answerCallAsync") {
|
|
|
|
|
@ -384,12 +380,11 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
return description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Future<RTCSessionDescription> _createAnswer() async {
|
|
|
|
|
// RTCSessionDescription description = await _pc!.createAnswer();
|
|
|
|
|
// var session = description.sdp.toString();
|
|
|
|
|
// return description;
|
|
|
|
|
// _pc!.setLocalDescription(description);
|
|
|
|
|
// }
|
|
|
|
|
Future<RTCSessionDescription> _createAnswer() async {
|
|
|
|
|
RTCSessionDescription description = await _pc!.createAnswer();
|
|
|
|
|
_offer = false;
|
|
|
|
|
return description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void micOff() {
|
|
|
|
|
isMicOff = !isMicOff;
|
|
|
|
|
@ -431,9 +426,16 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> startIncomingCall() async {
|
|
|
|
|
await localVideoRenderer.initialize();
|
|
|
|
|
localStream = await navigator.mediaDevices.getUserMedia(isVideoCall ? videoConstraints : audioConstraints);
|
|
|
|
|
localVideoRenderer.srcObject = localStream;
|
|
|
|
|
await remoteRenderer.initialize();
|
|
|
|
|
_pc = await creatOfferWithCon();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> startIncomingCallViaKit() async {
|
|
|
|
|
await startIncomingCall();
|
|
|
|
|
Utils.showToast("Inside Incoming Call");
|
|
|
|
|
await invoke(invokeMethod: "answerCallAsync", currentUserID: incomingCallData.extra!.loginDetails!.id!, targetUserID: incomingCallData.extra!.callerDetails!.targetUserId!);
|
|
|
|
|
await invoke(invokeMethod: "answerCallAsync", currentUserID: inComingCallData.extra!.loginDetails!.id!, targetUserID: inComingCallData.extra!.callerDetails!.targetUserId!);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|