133 lines
3.5 KiB
Dart
133 lines
3.5 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'liblinphone_flutter_platform_interface.dart';
|
|
import 'models/call_type.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'))!;
|
|
}
|
|
}
|