From 6c5b7bc1ce63db7e6058d26ba194aea6bf820a55 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Sun, 27 Oct 2024 09:52:54 +0100 Subject: [PATCH] Fix collaboration dialog --- app/lib/dialogs/collaboration/start.dart | 9 ++- app/lib/dialogs/collaboration/view.dart | 1 - app/lib/services/network.dart | 73 ++++++++++++------------ app/pubspec.lock | 8 +-- app/pubspec.yaml | 4 +- metadata/en-US/changelogs/120.txt | 1 + 6 files changed, 47 insertions(+), 49 deletions(-) diff --git a/app/lib/dialogs/collaboration/start.dart b/app/lib/dialogs/collaboration/start.dart index 433023280de0..fb036ae800cb 100644 --- a/app/lib/dialogs/collaboration/start.dart +++ b/app/lib/dialogs/collaboration/start.dart @@ -84,20 +84,19 @@ class _StartCollaborationDialogState extends State ], ), actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(), - child: Text(AppLocalizations.of(context).close), - ), ElevatedButton( onPressed: kIsWeb ? null : () { if (!(_formKey.currentState?.validate() ?? false)) return; - Navigator.of(context).pop(); _start(); }, child: Text(AppLocalizations.of(context).start), ), + TextButton( + onPressed: () => Navigator.of(context).pop(), + child: Text(AppLocalizations.of(context).close), + ), ], ), ), diff --git a/app/lib/dialogs/collaboration/view.dart b/app/lib/dialogs/collaboration/view.dart index 95e79e047acd..e0b3fee2549a 100644 --- a/app/lib/dialogs/collaboration/view.dart +++ b/app/lib/dialogs/collaboration/view.dart @@ -46,7 +46,6 @@ class ViewCollaborationDialog extends StatelessWidget { OutlinedButton( child: Text(AppLocalizations.of(context).stop), onPressed: () { - Navigator.of(context).pop(); service.closeNetworking(); }, ), diff --git a/app/lib/services/network.dart b/app/lib/services/network.dart index 6963074b095b..b12efd2cf544 100644 --- a/app/lib/services/network.dart +++ b/app/lib/services/network.dart @@ -35,7 +35,7 @@ enum NetworkingType { const kDefaultPort = 28005; const kTimeout = Duration(seconds: 10); -typedef NetworkingState = (NetworkerBase, RpcNetworkerPipe); +typedef NetworkingState = (NetworkerBase, NamedRpcNetworkerPipe); @freezed class NetworkingInitMessage with _$NetworkingInitMessage { @@ -56,11 +56,19 @@ class NetworkingUser with _$NetworkingUser { _$NetworkingUserFromJson(json); } -enum NetworkEvent { - event, - init, - connections, - user, +enum NetworkEvent with RpcFunctionName { + event(mode: RpcNetworkerMode.any, canRunLocally: false), + init(mode: RpcNetworkerMode.authority, canRunLocally: false), + connections(mode: RpcNetworkerMode.authority, canRunLocally: false), + user(mode: RpcNetworkerMode.any, canRunLocally: false); + + @override + final RpcNetworkerMode mode; + @override + final bool canRunLocally; + + const NetworkEvent( + {this.mode = RpcNetworkerMode.authority, this.canRunLocally = false}); } class NetworkingService { @@ -95,7 +103,7 @@ class NetworkingService { ? InternetAddress(address, type: InternetAddressType.any) : InternetAddress.anyIPv4, port ?? kDefaultPort); - final rpc = RpcServerNetworkerPipe(); + final rpc = NamedRpcServerNetworkerPipe(); _setupRpc(rpc, server); void sendConnections() { rpc.callFunction(NetworkEvent.connections.index, @@ -123,7 +131,7 @@ class NetworkingService { uri = uri.replace(port: kDefaultPort); } final client = NetworkerSocketClient(uri); - final rpc = RpcClientNetworkerPipe(); + final rpc = NamedRpcClientNetworkerPipe(); _setupRpc(rpc, client); final completer = Completer(); rpc @@ -147,44 +155,35 @@ class NetworkingService { _users.add({}); } - void _setupRpc(RpcNetworkerPipe rpc, NetworkerBase networker) { + void _setupRpc( + NamedRpcNetworkerPipe rpc, NetworkerBase networker) { + rpc.registerNamedFunctions(NetworkEvent.values); + rpc.getNamedFunction(NetworkEvent.event)?.connect(RawJsonNetworkerPlugin() + ..read.listen((message) { + final event = DocumentEvent.fromJson(message.data); + onMessage(event); + })); rpc - .registerFunction(NetworkEvent.event.index, mode: RpcNetworkerMode.any) - .connect(RawJsonNetworkerPlugin() - ..read.listen((message) { - final event = DocumentEvent.fromJson(message.data); - onMessage(event); - })); - rpc - .registerFunction( - NetworkEvent.connections.index, - mode: RpcNetworkerMode.authority, - ) - .connect(RawJsonNetworkerPlugin() + .getNamedFunction(NetworkEvent.connections) + ?.connect(RawJsonNetworkerPlugin() ..read.listen((message) { final ids = Set.from(message.data); _connections.add(ids); _users.add(Map.from(_users.value) ..removeWhere((key, value) => !ids.contains(key))); })); - rpc - .registerFunction( - NetworkEvent.user.index, - mode: RpcNetworkerMode.any, - ) - .connect(RawJsonNetworkerPlugin() - ..read.listen((message) { - final user = NetworkingUser.fromJson(message.data); - final users = Map.from(_users.value) - ..[message.channel] = user; - _users.add(users); - _bloc?.state.currentIndexCubit - ?.updateNetworkingState(_bloc!, users); - })); + rpc.getNamedFunction(NetworkEvent.user)?.connect(RawJsonNetworkerPlugin() + ..read.listen((message) { + final user = NetworkingUser.fromJson(message.data); + final users = Map.from(_users.value) + ..[message.channel] = user; + _users.add(users); + _bloc?.state.currentIndexCubit?.updateNetworkingState(_bloc!, users); + })); } void sendUser(NetworkingUser user) { - state?.$2.callFunction(NetworkEvent.user.index, + state?.$2.callNamedFunction(NetworkEvent.user, Uint8List.fromList(jsonEncode(user.toJson()).codeUnits)); } @@ -192,7 +191,7 @@ class NetworkingService { void onEvent(DocumentEvent event) { if (!event.shouldSync() || _externalEvent) return; - state?.$2.callFunction(NetworkEvent.event.index, + state?.$2.callNamedFunction(NetworkEvent.event, Uint8List.fromList(jsonEncode(event.toJson()).codeUnits)); } diff --git a/app/pubspec.lock b/app/pubspec.lock index d21cf2c6d5a4..997fc63cb9fa 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -914,8 +914,8 @@ packages: dependency: "direct main" description: path: "packages/networker/networker" - ref: "5a3658cad80fcb8594b8be6f84460e77607eb959" - resolved-ref: "5a3658cad80fcb8594b8be6f84460e77607eb959" + ref: "071e02761bf55a47bcde0cdc2a711b8ff5fbbb18" + resolved-ref: "071e02761bf55a47bcde0cdc2a711b8ff5fbbb18" url: "https://github.com/LinwoodDev/dart_pkgs" source: git version: "1.0.0" @@ -923,8 +923,8 @@ packages: dependency: "direct main" description: path: "packages/networker/networker_socket" - ref: "40b8553ab86ab4f06d9f689268a65d65ed936fda" - resolved-ref: "40b8553ab86ab4f06d9f689268a65d65ed936fda" + ref: "9085d42cf75c3d3edc8edb9ef22697dbbe2bf38c" + resolved-ref: "9085d42cf75c3d3edc8edb9ef22697dbbe2bf38c" url: "https://github.com/LinwoodDev/dart_pkgs" source: git version: "1.0.0" diff --git a/app/pubspec.yaml b/app/pubspec.yaml index fb7a0e9d9523..c1ede417a44d 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -79,12 +79,12 @@ dependencies: networker: git: url: https://github.com/LinwoodDev/dart_pkgs - ref: 5a3658cad80fcb8594b8be6f84460e77607eb959 + ref: 071e02761bf55a47bcde0cdc2a711b8ff5fbbb18 path: packages/networker/networker networker_socket: git: url: https://github.com/LinwoodDev/dart_pkgs - ref: 40b8553ab86ab4f06d9f689268a65d65ed936fda + ref: 9085d42cf75c3d3edc8edb9ef22697dbbe2bf38c path: packages/networker/networker_socket lw_file_system: git: diff --git a/metadata/en-US/changelogs/120.txt b/metadata/en-US/changelogs/120.txt index 4e204679049f..643c58cd54e7 100644 --- a/metadata/en-US/changelogs/120.txt +++ b/metadata/en-US/changelogs/120.txt @@ -10,6 +10,7 @@ * Fix property view logic * Fix property view ui padding * Fix archive importing +* Fix collaboration dialog * Upgrade networking stack for collaboration experiment * Update flutter and agp