multicast/broadcast support
This commit is contained in:
@ -7,34 +7,54 @@ part 'project.g.dart';
|
||||
class Project {
|
||||
final String id;
|
||||
final String name;
|
||||
final String ipAddress;
|
||||
|
||||
// Support for multiple IP addresses at project level
|
||||
final List<String> ipAddresses;
|
||||
|
||||
// Broadcast mode flag for project
|
||||
@JsonKey(defaultValue: false)
|
||||
final bool isBroadcast;
|
||||
|
||||
final int port;
|
||||
final List<UdpPackage> packages;
|
||||
|
||||
// Legacy field for backward compatibility
|
||||
@JsonKey(includeFromJson: true, includeToJson: false)
|
||||
final String? ipAddress;
|
||||
|
||||
Project({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.ipAddress,
|
||||
List<String>? ipAddresses,
|
||||
this.isBroadcast = false,
|
||||
required this.port,
|
||||
required this.packages,
|
||||
});
|
||||
this.ipAddress,
|
||||
}) : ipAddresses = ipAddresses ?? (ipAddress != null ? [ipAddress] : ['127.0.0.1']);
|
||||
|
||||
factory Project.fromJson(Map<String, dynamic> json) =>
|
||||
_$ProjectFromJson(json);
|
||||
factory Project.fromJson(Map<String, dynamic> json) {
|
||||
// Handle migration from old format
|
||||
if (json.containsKey('ipAddress') && !json.containsKey('ipAddresses')) {
|
||||
json['ipAddresses'] = [json['ipAddress']];
|
||||
}
|
||||
return _$ProjectFromJson(json);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => _$ProjectToJson(this);
|
||||
|
||||
Project copyWith({
|
||||
String? id,
|
||||
String? name,
|
||||
String? ipAddress,
|
||||
List<String>? ipAddresses,
|
||||
bool? isBroadcast,
|
||||
int? port,
|
||||
List<UdpPackage>? packages,
|
||||
}) {
|
||||
return Project(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
ipAddress: ipAddress ?? this.ipAddress,
|
||||
ipAddresses: ipAddresses ?? this.ipAddresses,
|
||||
isBroadcast: isBroadcast ?? this.isBroadcast,
|
||||
port: port ?? this.port,
|
||||
packages: packages ?? this.packages,
|
||||
);
|
||||
|
||||
@ -9,17 +9,22 @@ part of 'project.dart';
|
||||
Project _$ProjectFromJson(Map<String, dynamic> json) => Project(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
ipAddress: json['ipAddress'] as String,
|
||||
ipAddresses: (json['ipAddresses'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList(),
|
||||
isBroadcast: json['isBroadcast'] as bool? ?? false,
|
||||
port: (json['port'] as num).toInt(),
|
||||
packages: (json['packages'] as List<dynamic>)
|
||||
.map((e) => UdpPackage.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
ipAddress: json['ipAddress'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ProjectToJson(Project instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'ipAddress': instance.ipAddress,
|
||||
'ipAddresses': instance.ipAddresses,
|
||||
'isBroadcast': instance.isBroadcast,
|
||||
'port': instance.port,
|
||||
'packages': instance.packages,
|
||||
};
|
||||
|
||||
@ -7,17 +7,34 @@ class UdpPackage {
|
||||
final String id;
|
||||
final String name;
|
||||
final String data;
|
||||
final String ipAddress;
|
||||
|
||||
// Support for multiple IP addresses
|
||||
final List<String> ipAddresses;
|
||||
|
||||
// Broadcast mode flag
|
||||
@JsonKey(defaultValue: false)
|
||||
final bool isBroadcast;
|
||||
|
||||
// Legacy field for backward compatibility - kept for migration
|
||||
@JsonKey(includeFromJson: true, includeToJson: false)
|
||||
final String? ipAddress;
|
||||
|
||||
UdpPackage({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.data,
|
||||
required this.ipAddress,
|
||||
});
|
||||
List<String>? ipAddresses,
|
||||
this.isBroadcast = false,
|
||||
this.ipAddress,
|
||||
}) : ipAddresses = ipAddresses ?? (ipAddress != null ? [ipAddress] : ['127.0.0.1']);
|
||||
|
||||
factory UdpPackage.fromJson(Map<String, dynamic> json) =>
|
||||
_$UdpPackageFromJson(json);
|
||||
factory UdpPackage.fromJson(Map<String, dynamic> json) {
|
||||
// Handle migration from old format
|
||||
if (json.containsKey('ipAddress') && !json.containsKey('ipAddresses')) {
|
||||
json['ipAddresses'] = [json['ipAddress']];
|
||||
}
|
||||
return _$UdpPackageFromJson(json);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => _$UdpPackageToJson(this);
|
||||
|
||||
@ -25,13 +42,15 @@ class UdpPackage {
|
||||
String? id,
|
||||
String? name,
|
||||
String? data,
|
||||
String? ipAddress,
|
||||
List<String>? ipAddresses,
|
||||
bool? isBroadcast,
|
||||
}) {
|
||||
return UdpPackage(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
data: data ?? this.data,
|
||||
ipAddress: ipAddress ?? this.ipAddress,
|
||||
ipAddresses: ipAddresses ?? this.ipAddresses,
|
||||
isBroadcast: isBroadcast ?? this.isBroadcast,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,11 @@ UdpPackage _$UdpPackageFromJson(Map<String, dynamic> json) => UdpPackage(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
data: json['data'] as String,
|
||||
ipAddress: json['ipAddress'] as String,
|
||||
ipAddresses: (json['ipAddresses'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList(),
|
||||
isBroadcast: json['isBroadcast'] as bool? ?? false,
|
||||
ipAddress: json['ipAddress'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$UdpPackageToJson(UdpPackage instance) =>
|
||||
@ -18,5 +22,6 @@ Map<String, dynamic> _$UdpPackageToJson(UdpPackage instance) =>
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'data': instance.data,
|
||||
'ipAddress': instance.ipAddress,
|
||||
'ipAddresses': instance.ipAddresses,
|
||||
'isBroadcast': instance.isBroadcast,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user