improvements

main_production_audio_video_call
Sikander Saleem 2 weeks ago
parent deb8748fc1
commit f222c589a9

@ -60,7 +60,11 @@ class _AudioCallPageState extends State<AudioCallPage> {
callPro.initAudioCallListeners();
if (widget.isAccept) {
callPro.acceptCall(widget.sender.employeeNumber ?? "", widget.recipient.employeeNumber ?? "", false, moduleId: widget.moduleId);
callPro.acceptCall(widget.sender.employeeNumber ?? "", widget.recipient.employeeNumber ?? "", false, moduleId: widget.moduleId,onSuccess: (String msg) {
_closeCall();
}, onFailed: (String msg) {
_showFailure(msg, title: "Failed");
});
} else {
callPro.startCall(widget.sender.employeeNumber ?? "", widget.recipient.employeeNumber ?? "", false, widget.moduleId, widget.referenceID, onSuccess: (String msg) {
_closeCall();

@ -98,10 +98,7 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
requestTimeout: 30000,
);
return HubConnectionBuilder()
.withUrl(hubUrl, options: httpOp)
.withAutomaticReconnect(retryDelays: <int>[2000, 5000, 10000, 20000])
.build();
return HubConnectionBuilder().withUrl(hubUrl, options: httpOp).withAutomaticReconnect(retryDelays: <int>[2000, 5000, 10000, 20000]).build();
}
/// Writes the port into the url *textually*.
@ -123,38 +120,38 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
Future<bool> buildHubConnection(String employeeNumber, {HubConnection? hubC}) async {
_setStatus("Connecting...");
try {
if (hubC != null) {
final bool reused = await _adoptExistingConnection(hubC);
if (reused) return true;
if (kDebugMode) {
print('ℹ️ Shared chat hub not usable (state: ${hubC.state}), opening a dedicated call connection.');
}
if (hubC != null) {
final bool reused = await _adoptExistingConnection(hubC);
if (reused) return true;
if (kDebugMode) {
print('ℹ️ Shared chat hub not usable (state: ${hubC.state}), opening a dedicated call connection.');
}
await _disposeConnection();
}
await _disposeConnection();
final http.Response response = await ApiClient().postJsonForResponse(
URLs.chatSdkToken,
{"apiKey": URLs.chatApiKey, "employeeNumber": employeeNumber, "voIPToken": null},
);
if (response.statusCode != 200) {
if (kDebugMode) {
print('⚠️ Call token request failed: HTTP ${response.statusCode}');
}
return false;
final http.Response response = await ApiClient().postJsonForResponse(
URLs.chatSdkToken,
{"apiKey": URLs.chatApiKey, "employeeNumber": employeeNumber, "voIPToken": null},
);
if (response.statusCode != 200) {
if (kDebugMode) {
print('⚠️ Call token request failed: HTTP ${response.statusCode}');
}
return false;
}
final ChatLoginResponse chatResponse = ChatLoginResponse.fromJson(jsonDecode(response.body));
if (chatResponse.token == null || chatResponse.token!.isEmpty) {
if (kDebugMode) {
print('⚠️ Call token request returned an empty token.');
}
return false;
final ChatLoginResponse chatResponse = ChatLoginResponse.fromJson(jsonDecode(response.body));
if (chatResponse.token == null || chatResponse.token!.isEmpty) {
if (kDebugMode) {
print('⚠️ Call token request returned an empty token.');
}
return false;
}
callHubConnection = await getHubConnection(chatResponse.token!);
_ownsConnection = true;
await callHubConnection!.start();
return callHubConnection?.state == HubConnectionState.Connected;
callHubConnection = await getHubConnection(chatResponse.token!);
_ownsConnection = true;
await callHubConnection!.start();
return callHubConnection?.state == HubConnectionState.Connected;
} catch (e) {
if (kDebugMode) {
print('⚠️ Error building call SignalR connection: $e');
@ -262,7 +259,6 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
};
Future<RTCPeerConnection> _createPeerConnection() async {
Map<String, dynamic> configuration = {
"iceServers": [
{"urls": 'stun:15.185.116.59:3478'},
@ -364,11 +360,14 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
}
}
void acceptCall(String senderN, String recipientN, bool isVideo, {required int moduleId}) async {
void acceptCall(String senderN, String recipientN, bool isVideo, {required int moduleId, Function(String message)? onFailed, Function(String message)? onSuccess}) async {
this.senderN = senderN;
this.recipientN = recipientN;
this.onFailed = onFailed;
this.onSuccess = onSuccess;
try {
await invoke(invokeMethod: "AnswerCallAsync", currentUserID: senderN, targetUserID: recipientN, isVideoCall: isVideo, data: [this.moduleId]);
_setStatus("Connected");
} catch (e) {
if (kDebugMode) {
print('⚠️ AnswerCallAsync failed: $e');
@ -552,6 +551,7 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
} else if (params[0] == 'USER_OFFLINE') {
onFailed?.call("The user is currently offline");
} else {
_setStatus("Call Ended");
onSuccess?.call("");
}
}

@ -230,7 +230,7 @@ class _LandPageState extends State<LandPage> {
case CallEventActionDidUpdateDevicePushTokenVoip():
// TODO: Handle this case.
throw UnimplementedError();
case CallEventActionCallIncoming():
case CallEventActionCallIncoming(:final callKitParams):
// TODO: Handle this case.
throw UnimplementedError();
case CallEventActionCallStart():

Loading…
Cancel
Save