Skip to content

Commit

Permalink
Merge pull request #66 from jan-mu/main
Browse files Browse the repository at this point in the history
prefer using ip address given by android service
  • Loading branch information
sebastianhaberey authored Nov 18, 2024
2 parents 47eef6f + a2bf7e7 commit e8b05a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ private enum class Key(val serializeKey: String) {
SERVICE_TYPE("service.type"),
SERVICE_HOST("service.host"),
SERVICE_PORT("service.port"),
SERVICE_ADDRESSES("service.addresses"),
SERVICE_TXT("service.txt"),
ERROR_CAUSE("error.cause"),
ERROR_MESSAGE("error.message"),
Expand Down Expand Up @@ -110,6 +111,7 @@ internal fun serializeServiceInfo(nsdServiceInfo: NsdServiceInfo): Map<String, A
Key.SERVICE_NAME.serializeKey to nsdServiceInfo.serviceName,
Key.SERVICE_TYPE.serializeKey to removeLeadingAndTrailingDots(serviceType = nsdServiceInfo.serviceType),
Key.SERVICE_HOST.serializeKey to nsdServiceInfo.host?.canonicalHostName,
Key.SERVICE_ADDRESSES.serializeKey to nsdServiceInfo.host?.hostAddress,
Key.SERVICE_PORT.serializeKey to if (nsdServiceInfo.port == 0) null else nsdServiceInfo.port,
Key.SERVICE_TXT.serializeKey to nsdServiceInfo.attributes,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MethodChannelNsdPlatform extends NsdPlatformInterface {
if (autoResolve) {
service = await resolve(service);

if (isIpLookupEnabled(ipLookupType)) {
if (isIpLookupEnabled(ipLookupType) && service.addresses == null) {
service = await performIpLookup(service, ipLookupType);
}
}
Expand Down
21 changes: 12 additions & 9 deletions nsd_platform_interface/lib/src/serialization.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:typed_data';

import 'nsd_platform_interface.dart';
Expand Down Expand Up @@ -51,19 +52,21 @@ Service? deserializeService(dynamic arguments) {
final type = data['service.type'] as String?;
final host = data['service.host'] as String?;
final port = data['service.port'] as int?;
final txt = data['service.txt'] != null
? Map<String, Uint8List?>.from(data['service.txt'])
: null;

if (name == null &&
type == null &&
host == null &&
port == null &&
final addresses = data['service.addresses'] as String?;
final txt = data['service.txt'] != null ? Map<String, Uint8List?>.from(data['service.txt']) : null;

if (name == null &&
type == null &&
host == null &&
port == null &&
addresses == null &&
txt == null) {
return null;
}

return Service(name: name, type: type, host: host, port: port, txt: txt);
final inetAddresses = addresses != null ? [InternetAddress(addresses)] : null;

return Service(name: name, type: type, host: host, port: port, addresses: inetAddresses, txt: txt);
}

Map<String, dynamic> serializeHandle(String value) => {
Expand Down

0 comments on commit e8b05a8

Please sign in to comment.