178 lines
4.6 KiB
Dart
178 lines
4.6 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'liblinphone_flutter_platform_interface.dart';
|
|
import 'models/call_stats.dart';
|
|
import 'models/call_type.dart';
|
|
import 'models/dscp_values.dart';
|
|
|
|
/// An implementation of [LiblinphoneFlutterPlatform] that uses method channels.
|
|
class MethodChannelLiblinphoneFlutter extends LiblinphoneFlutterPlatform {
|
|
/// The method channel used to interact with the native platform.
|
|
@visibleForTesting
|
|
final methodChannel = const MethodChannel('liblinphone_flutter');
|
|
|
|
@override
|
|
Future<bool> checkPermissions() async {
|
|
return (await methodChannel.invokeMethod<bool>('checkPermissions'))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> initialize() async {
|
|
return (await methodChannel.invokeMethod<bool>('initialize'))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> register(
|
|
String username,
|
|
String password,
|
|
String serverIp,
|
|
int serverPort,
|
|
) async {
|
|
return (await methodChannel
|
|
.invokeMethod<bool>('register', <String, dynamic>{
|
|
'username': username,
|
|
'password': password,
|
|
'serverIp': serverIp,
|
|
'serverPort': serverPort,
|
|
}))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> unregister() async {
|
|
return (await methodChannel.invokeMethod<bool>('unregister'))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> makeCall(
|
|
String callTo,
|
|
bool isVideoEnabled,
|
|
String notificationTitle,
|
|
String notificationMessage,
|
|
) async {
|
|
return (await methodChannel
|
|
.invokeMethod<bool>('makeCall', <String, dynamic>{
|
|
'callTo': callTo,
|
|
'isVideoEnabled': isVideoEnabled,
|
|
'notificationTitle': notificationTitle,
|
|
'notificationMessage': notificationMessage,
|
|
}))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> answerCall(
|
|
String notificationTitle,
|
|
String notificationMessage,
|
|
) async {
|
|
return (await methodChannel
|
|
.invokeMethod<bool>('answerCall', <String, dynamic>{
|
|
'notificationTitle': notificationTitle,
|
|
'notificationMessage': notificationMessage,
|
|
}))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> hangupCall() async {
|
|
return (await methodChannel.invokeMethod<bool>('hangupCall'))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> inCall() async {
|
|
return (await methodChannel.invokeMethod<bool>('inCall'))!;
|
|
}
|
|
|
|
@override
|
|
Future<CallType> callType() async {
|
|
final callTypeOrdinal = await methodChannel.invokeMethod<int>('callType');
|
|
return CallType.fromOrdinal(callTypeOrdinal!);
|
|
}
|
|
|
|
@override
|
|
Future<bool> toggleVideo() async {
|
|
return (await methodChannel.invokeMethod<bool>('toggleVideo'))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> toggleMicrophone() async {
|
|
return (await methodChannel.invokeMethod<bool>('toggleMicrophone'))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> stop() async {
|
|
return (await methodChannel.invokeMethod<bool>('stop'))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> syncCurrentState() async {
|
|
return (await methodChannel.invokeMethod<bool>('syncCurrentState'))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> sendDtmf(String tone) async {
|
|
return (await methodChannel.invokeMethod<bool>(
|
|
'sendDtmf',
|
|
<String, dynamic>{'tone': tone},
|
|
))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> stopCallService() async {
|
|
return (await methodChannel.invokeMethod<bool>('stopCallService'))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> setMicGain(double level) async {
|
|
return (await methodChannel.invokeMethod<bool>(
|
|
'setMicGain',
|
|
<String, dynamic>{'level': level},
|
|
))!;
|
|
}
|
|
|
|
@override
|
|
Future<double> getMicGain() async {
|
|
return (await methodChannel.invokeMethod<double>('getMicGain'))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> setPlaybackGain(double level) async {
|
|
return (await methodChannel.invokeMethod<bool>(
|
|
'setPlaybackGain',
|
|
<String, dynamic>{'level': level},
|
|
))!;
|
|
}
|
|
|
|
@override
|
|
Future<double> getPlaybackGain() async {
|
|
return (await methodChannel.invokeMethod<double>('getPlaybackGain'))!;
|
|
}
|
|
|
|
@override
|
|
Future<bool> setDscp(int sipDscp, int audioDscp, int videoDscp) async {
|
|
return (await methodChannel.invokeMethod<bool>('setDscp', <String, dynamic>{
|
|
'sipDscp': sipDscp,
|
|
'audioDscp': audioDscp,
|
|
'videoDscp': videoDscp,
|
|
}))!;
|
|
}
|
|
|
|
@override
|
|
Future<DscpValues> getDscp() async {
|
|
final data = (await methodChannel.invokeMethod<Map<dynamic, dynamic>>(
|
|
'getDscp',
|
|
))!;
|
|
final values = DscpValues.fromJson(data);
|
|
return values;
|
|
}
|
|
|
|
@override
|
|
Future<CallStats?> getCurrentCallStats() async {
|
|
final data = (await methodChannel.invokeMethod<Map<dynamic, dynamic>>(
|
|
'getCurrentCallStats',
|
|
));
|
|
|
|
if (data == null) return null;
|
|
|
|
final values = CallStats.fromJson(data);
|
|
return values;
|
|
}
|
|
}
|