|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
|
|
|
|
import 'package:signalr_netcore/http_connection_options.dart';
|
|
|
|
|
@ -51,13 +52,14 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
currentStatus = status;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _startCallDurationTimer() {
|
|
|
|
|
_callDurationTimer?.cancel();
|
|
|
|
|
callDuration = Duration.zero;
|
|
|
|
|
|
|
|
|
|
_callDurationTimer = Timer.periodic(
|
|
|
|
|
const Duration(seconds: 1),
|
|
|
|
|
(_) {
|
|
|
|
|
(_) {
|
|
|
|
|
callDuration = Duration(
|
|
|
|
|
seconds: callDuration.inSeconds + 1,
|
|
|
|
|
);
|
|
|
|
|
@ -65,6 +67,7 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _disposeConnection() async {
|
|
|
|
|
final HubConnection? connection = callHubConnection;
|
|
|
|
|
final bool owns = _ownsConnection;
|
|
|
|
|
@ -147,6 +150,7 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
final String query = uri.query.isEmpty ? '' : '?${uri.query}';
|
|
|
|
|
return '${uri.scheme}://${uri.host}:$port${uri.path}$query';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String get formattedCallDuration {
|
|
|
|
|
final hours = callDuration.inHours;
|
|
|
|
|
final minutes = callDuration.inMinutes.remainder(60);
|
|
|
|
|
@ -214,10 +218,20 @@ class CallProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
if (kDebugMode) print('Shared chat hub not usable (state: ${hubC.state}), opening a dedicated call connection.');
|
|
|
|
|
}
|
|
|
|
|
await _disposeConnection();
|
|
|
|
|
|
|
|
|
|
String platform;
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
platform = "IOS";
|
|
|
|
|
} else {
|
|
|
|
|
if (await FirebaseNotificationManger.isGoogleServicesAvailable()) {
|
|
|
|
|
platform = "GOOGLE";
|
|
|
|
|
} else {
|
|
|
|
|
platform = "HUAWEI";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool isHuaweiDevice() => platform == "HUAWEI";
|
|
|
|
|
final http.Response response = await ApiClient().postJsonForResponse(
|
|
|
|
|
URLs.chatSdkToken,
|
|
|
|
|
{"apiKey": URLs.chatApiKey, "employeeNumber": employeeNumber, "voIPToken": FirebaseNotificationManger.voipToken},
|
|
|
|
|
{"apiKey": URLs.chatApiKey, "employeeNumber": employeeNumber, "isHuaweiDevice": isHuaweiDevice(), "platform": platform, "voIPToken": FirebaseNotificationManger.voipToken},
|
|
|
|
|
);
|
|
|
|
|
if (response.statusCode != 200) {
|
|
|
|
|
if (kDebugMode) print('Call token request failed: HTTP ${response.statusCode}');
|
|
|
|
|
|