Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefer using ip address given by android service #66

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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