moxdns/packages/moxdns_android/lib/moxdns_android.dart

45 lines
1.3 KiB
Dart
Raw Normal View History

2022-07-27 20:30:05 +00:00
// ignore_for_file: avoid_print
import 'package:flutter/services.dart';
import 'package:moxdns/moxdns.dart';
import 'package:moxdns_platform_interface/moxdns_platform_interface.dart';
2022-04-29 11:58:33 +00:00
class MoxdnsAndroidPlugin extends MoxdnsPlatform {
2022-07-27 20:30:05 +00:00
MoxdnsAndroidPlugin()
: _channel = const MethodChannel('me.polynom.moxdns_android'), super();
final MethodChannel _channel;
2022-04-29 11:58:33 +00:00
static void registerWith() {
2022-07-27 20:30:05 +00:00
print('MoxdnsAndroidPlugin: Registering implementation');
2022-04-29 11:58:33 +00:00
MoxdnsPlugin.platform = MoxdnsAndroidPlugin();
}
@override
Future<List<SrvRecord>> srvQuery(String domain, bool dnssec) async {
try {
2022-07-27 20:30:05 +00:00
// TODO(PapaTutuWawa): Check for null
final results = (await _channel.invokeMethod<List<dynamic>>('srvQuery', [ domain, dnssec ]))!;
2022-04-29 11:58:33 +00:00
final records = List<SrvRecord>.empty(growable: true);
2022-07-27 20:30:05 +00:00
for (final record in results) {
2022-04-29 11:58:33 +00:00
if (record == null) {
continue;
}
// ignore: argument_type_not_assignable
final rr = Map<String, String>.from(record);
2022-07-27 20:30:05 +00:00
records.add(
SrvRecord(
rr['target']!,
int.parse(rr['port']!),
int.parse(rr['priority']!),
int.parse(rr['weight']!),
),
);
2022-04-29 11:58:33 +00:00
}
return records;
} on PlatformException catch(e) {
2022-07-27 20:30:05 +00:00
print('moxdns_android: $e');
2022-04-29 11:58:33 +00:00
return const [];
}
}
}