Matthias Nott
2026-03-22 619727f7e741b9104c7601fd319f9248513e9506
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class ServerConfig {
  final String host;
  final int port;
  final String? localHost;
  final String? macAddress;
  const ServerConfig({
    required this.host,
    this.port = 8765,
    this.localHost,
    this.macAddress,
  });
  /// Primary WebSocket URL (local network).
  String get localUrl {
    final h = localHost ?? host;
    return 'ws://$h:$port';
  }
  /// Fallback WebSocket URL (remote / public).
  String get remoteUrl => 'ws://$host:$port';
  /// Returns [localUrl, remoteUrl] for dual-connect attempts.
  List<String> get urls {
    if (localHost != null && localHost!.isNotEmpty && localHost != host) {
      return [localUrl, remoteUrl];
    }
    return [remoteUrl];
  }
  Map<String, dynamic> toJson() {
    return {
      'host': host,
      'port': port,
      if (localHost != null) 'localHost': localHost,
      if (macAddress != null) 'macAddress': macAddress,
    };
  }
  factory ServerConfig.fromJson(Map<String, dynamic> json) {
    return ServerConfig(
      host: json['host'] as String? ?? '',
      port: json['port'] as int? ?? 8765,
      localHost: json['localHost'] as String?,
      macAddress: json['macAddress'] as String?,
    );
  }
  ServerConfig copyWith({
    String? host,
    int? port,
    String? localHost,
    String? macAddress,
  }) {
    return ServerConfig(
      host: host ?? this.host,
      port: port ?? this.port,
      localHost: localHost ?? this.localHost,
      macAddress: macAddress ?? this.macAddress,
    );
  }
}