|
|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:math';
|
|
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
@ -61,26 +62,24 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
return hub;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool> buildHubConnection(String employeeNumber) async {
|
|
|
|
|
Future<bool> buildHubConnection(String employeeNumber, {HubConnection? hubC}) async {
|
|
|
|
|
if (hubC != null) {
|
|
|
|
|
callHubConnection = hubC;
|
|
|
|
|
await callHubConnection!.start();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await _disposeConnection();
|
|
|
|
|
// isLoading = true;
|
|
|
|
|
// notifyListeners();
|
|
|
|
|
http.Response response = await ApiClient().postJsonForResponse(URLs.chatSdkToken, {"apiKey": URLs.chatApiKey, "employeeNumber": employeeNumber, "voIPToken": null});
|
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
|
ChatLoginResponse chatResponse = ChatLoginResponse.fromJson(jsonDecode(response.body));
|
|
|
|
|
print("chatResponse:${chatResponse.token}");
|
|
|
|
|
callHubConnection = await getHubConnection(chatResponse.token!);
|
|
|
|
|
await callHubConnection!.start();
|
|
|
|
|
// isLoading = false;
|
|
|
|
|
// notifyListeners();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// isLoading = false;
|
|
|
|
|
// notifyListeners();
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
print("buildHubConnectionE:$e");
|
|
|
|
|
await _disposeConnection();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@ -214,35 +213,40 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
late String senderN;
|
|
|
|
|
late String recipientN;
|
|
|
|
|
late bool isVideo;
|
|
|
|
|
String? senderN;
|
|
|
|
|
String? recipientN;
|
|
|
|
|
bool? isVideo;
|
|
|
|
|
int? moduleId;
|
|
|
|
|
int? referenceID;
|
|
|
|
|
|
|
|
|
|
void startCall(String senderN, String recipientN, bool isVideo, int? moduleId, int? referenceID) async {
|
|
|
|
|
Function(String message)? onFailed;
|
|
|
|
|
Function(String message)? onSuccess;
|
|
|
|
|
|
|
|
|
|
void startCall(String? senderN, String? recipientN, bool? isVideo, int? moduleId, int? referenceID, {Function(String message)? onFailed, Function(String message)? onSuccess}) async {
|
|
|
|
|
this.senderN = senderN;
|
|
|
|
|
this.recipientN = recipientN;
|
|
|
|
|
this.isVideo = isVideo;
|
|
|
|
|
this.moduleId = moduleId;
|
|
|
|
|
this.referenceID = referenceID;
|
|
|
|
|
invoke(invokeMethod: "CallUserAsync", currentUserID: senderN, targetUserID: recipientN, isVideoCall: isVideo);
|
|
|
|
|
this.onFailed = onFailed;
|
|
|
|
|
this.onSuccess = onSuccess;
|
|
|
|
|
invoke(invokeMethod: "CallUserAsync", currentUserID: senderN!, targetUserID: recipientN!, isVideoCall: isVideo!);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void acceptCall(String senderN, String recipientN, bool isVideo, int moduleId, int? referenceID) async {
|
|
|
|
|
void acceptCall(String senderN, String recipientN, bool isVideo) async {
|
|
|
|
|
invoke(invokeMethod: "AnswerCallAsync", currentUserID: senderN, targetUserID: recipientN, isVideoCall: isVideo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void declineCall(String senderN, String recipientN, bool isVideo, int moduleId, int? referenceID) async {
|
|
|
|
|
invoke(invokeMethod: "CallDeclinedAsync", currentUserID: senderN, targetUserID: recipientN, isVideoCall: isVideo);
|
|
|
|
|
Future declineCall(String senderN, String recipientN) async {
|
|
|
|
|
await invoke(invokeMethod: "CallDeclinedAsync", currentUserID: senderN, targetUserID: recipientN, isVideoCall: false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void endCall() {
|
|
|
|
|
invoke(invokeMethod: "HangUpAsync", currentUserID: senderN, targetUserID: recipientN, data: moduleId);
|
|
|
|
|
void endCall(String senderN, String recipientN) {
|
|
|
|
|
invoke(invokeMethod: "HangUpAsync", currentUserID: senderN, targetUserID: recipientN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void toggleMute() {
|
|
|
|
|
invoke(invokeMethod: "AudioToggle", currentUserID: senderN, targetUserID: recipientN, isVideoCall: isVideo);
|
|
|
|
|
invoke(invokeMethod: "AudioToggle", currentUserID: senderN!, targetUserID: recipientN!, isVideoCall: isVideo!);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void checkCall(Map<String, dynamic> message) {
|
|
|
|
|
@ -280,6 +284,7 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
void onOfferAsync(List<Object?>? params) {
|
|
|
|
|
print("onCallAcceptedAsync: $params");
|
|
|
|
|
print("onCallAcceptedAsync: $params");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onAnswerOffer(List<Object?>? params) {
|
|
|
|
|
@ -288,10 +293,32 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
void onHangUpAsync(List<Object?>? params) {
|
|
|
|
|
print("onHangUpAsync: $params");
|
|
|
|
|
handleResponse(params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onCallDeclinedAsync(List<Object?>? params) {
|
|
|
|
|
print("onCallDeclinedAsync: $params");
|
|
|
|
|
handleResponse(params);
|
|
|
|
|
// try {
|
|
|
|
|
// if (params?.isNotEmpty ?? false) {
|
|
|
|
|
// print("onCallDeclinedAsync:${params?.length}:${params}");
|
|
|
|
|
// if (params!.length > 2) {
|
|
|
|
|
// print("runTimeData:${params[1].runtimeType}");
|
|
|
|
|
// var data = jsonDecode(jsonEncode(params[1].toString()));
|
|
|
|
|
// print("runTimeData:${data.runtimeType}");
|
|
|
|
|
// onFailed?.call("Call Declined, ${data["targetUserId"]} has declined your call.");
|
|
|
|
|
// return;
|
|
|
|
|
// } else { print("runTimeData:${params[0].runtimeType}");
|
|
|
|
|
// var data = jsonDecode(params[0].toString());
|
|
|
|
|
// print("runTimeData:${data.runtimeType}");
|
|
|
|
|
// onFailed?.call("Call Declined, ${data["targetUserId"]} has declined your call.");
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// } catch (ex) {
|
|
|
|
|
// print("Ex:$ex");
|
|
|
|
|
// onFailed?.call("Call Declined, User has declined your call.");
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onAudioToggle(List<Object?>? params) {
|
|
|
|
|
@ -308,12 +335,14 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
Future<void> invoke({required String invokeMethod, required String currentUserID, required String targetUserID, bool isVideoCall = false, var data}) async {
|
|
|
|
|
List<Object> args = [];
|
|
|
|
|
if (invokeMethod == "answerCallAsync") {
|
|
|
|
|
if (invokeMethod == "AnswerCallAsync") {
|
|
|
|
|
args = [currentUserID, targetUserID];
|
|
|
|
|
} else if (invokeMethod == 'CallDeclinedAsync') {
|
|
|
|
|
args = [currentUserID, targetUserID];
|
|
|
|
|
} else if (invokeMethod == "CallUserAsync") {
|
|
|
|
|
args = [currentUserID, targetUserID, isVideoCall];
|
|
|
|
|
} else if (invokeMethod == "HangUpAsync ") {
|
|
|
|
|
args = [currentUserID, targetUserID, data];
|
|
|
|
|
} else if (invokeMethod == "HangUpAsync") {
|
|
|
|
|
args = [currentUserID, targetUserID];
|
|
|
|
|
} else if (invokeMethod == "AudioToggle") {
|
|
|
|
|
args = [currentUserID, targetUserID, isVideoCall];
|
|
|
|
|
} else if (invokeMethod == "IceCandidateAsync") {
|
|
|
|
|
@ -323,6 +352,7 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
} else if (invokeMethod == "AnswerOfferAsync") {
|
|
|
|
|
args = [targetUserID, data];
|
|
|
|
|
}
|
|
|
|
|
print("Invoking:$invokeMethod:${args}");
|
|
|
|
|
await callHubConnection?.invoke(invokeMethod, args: args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -335,4 +365,22 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
callHubConnection?.off('OnHangUpAsync');
|
|
|
|
|
callHubConnection?.off('OnAudioToggle');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleResponse(List<Object?>? params) {
|
|
|
|
|
if (params?.isNotEmpty ?? false) {
|
|
|
|
|
if (params![0] == "NO_ANSWER") {
|
|
|
|
|
onFailed?.call("No Answer, User did not answer your call.");
|
|
|
|
|
return;
|
|
|
|
|
} else if (params[0] == "NO_ANSWER") {
|
|
|
|
|
onFailed?.call("Call Declined, User has declined your call.");
|
|
|
|
|
return;
|
|
|
|
|
} else if (params[0] == 'USER_BUSY') {
|
|
|
|
|
onFailed?.call("The user is currently busy on another call");
|
|
|
|
|
} else if (params[0] == 'USER_OFFLINE') {
|
|
|
|
|
onFailed?.call("The user is currently offline");
|
|
|
|
|
} else {
|
|
|
|
|
onSuccess?.call("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|