From 26d0df145079347333941143f1824a3fae439f1b Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Tue, 30 Jan 2024 16:59:59 -0800 Subject: [PATCH] Compare --- pkgs/cupertino_http/lib/src/websocket.dart | 2 +- .../lib/src/close_local_tests.dart | 2 +- .../lib/src/close_remote_tests.dart | 2 +- .../src/disconnect_after_upgrade_tests.dart | 2 +- .../lib/src/no_upgrade_tests.dart | 2 +- .../lib/src/payload_transfer_tests.dart | 2 +- .../lib/src/peer_protocol_errors_tests.dart | 2 +- .../lib/web_socket_conformance_tests.dart | 2 +- pkgs/websocket/lib/htmlwebsocket.dart | 2 +- pkgs/websocket/lib/iowebsocket.dart | 2 +- pkgs/websocket/lib/websocket.dart | 22 ++++++++++++++----- 11 files changed, 26 insertions(+), 16 deletions(-) diff --git a/pkgs/cupertino_http/lib/src/websocket.dart b/pkgs/cupertino_http/lib/src/websocket.dart index 61ad234fb0..2f6978e641 100644 --- a/pkgs/cupertino_http/lib/src/websocket.dart +++ b/pkgs/cupertino_http/lib/src/websocket.dart @@ -12,7 +12,7 @@ class CupertinoWebSocketException extends XXXWebSocketException { CupertinoWebSocketException(e.toString()); } -class CupertinoWebSocket implements WebSocket { +class CupertinoWebSocket implements XXXWebSocket { static Future connect(Uri uri) async { final readyCompleter = Completer(); late CupertinoWebSocket webSocket; diff --git a/pkgs/web_socket_conformance_tests/lib/src/close_local_tests.dart b/pkgs/web_socket_conformance_tests/lib/src/close_local_tests.dart index be7a81fb76..c11747023d 100644 --- a/pkgs/web_socket_conformance_tests/lib/src/close_local_tests.dart +++ b/pkgs/web_socket_conformance_tests/lib/src/close_local_tests.dart @@ -15,7 +15,7 @@ import 'close_local_server_vm.dart' /// Tests that the [WebSocketChannel] can correctly transmit and receive text /// and binary payloads. void testLocalClose( - Future Function(Uri uri, {Iterable? protocols}) + Future Function(Uri uri, {Iterable? protocols}) channelFactory) { group('local close', () { late Uri uri; diff --git a/pkgs/web_socket_conformance_tests/lib/src/close_remote_tests.dart b/pkgs/web_socket_conformance_tests/lib/src/close_remote_tests.dart index e99f6c9414..ed2564b6ba 100644 --- a/pkgs/web_socket_conformance_tests/lib/src/close_remote_tests.dart +++ b/pkgs/web_socket_conformance_tests/lib/src/close_remote_tests.dart @@ -15,7 +15,7 @@ import 'close_remote_server_vm.dart' /// Tests that the [WebSocketChannel] can correctly transmit and receive text /// and binary payloads. void testRemoteClose( - Future Function(Uri uri, {Iterable? protocols}) + Future Function(Uri uri, {Iterable? protocols}) channelFactory) { group('remote close', () { late Uri uri; diff --git a/pkgs/web_socket_conformance_tests/lib/src/disconnect_after_upgrade_tests.dart b/pkgs/web_socket_conformance_tests/lib/src/disconnect_after_upgrade_tests.dart index 4a37dacc4e..c6cd7bd0d0 100644 --- a/pkgs/web_socket_conformance_tests/lib/src/disconnect_after_upgrade_tests.dart +++ b/pkgs/web_socket_conformance_tests/lib/src/disconnect_after_upgrade_tests.dart @@ -13,7 +13,7 @@ import 'disconnect_after_upgrade_server_vm.dart' /// Tests that the [WebSocketChannel] can correctly transmit and receive text /// and binary payloads. void testDisconnectAfterUpgrade( - Future Function(Uri uri, {Iterable? protocols}) + Future Function(Uri uri, {Iterable? protocols}) channelFactory) { group('disconnect', () { late final Uri uri; diff --git a/pkgs/web_socket_conformance_tests/lib/src/no_upgrade_tests.dart b/pkgs/web_socket_conformance_tests/lib/src/no_upgrade_tests.dart index 274c68053b..e3ff30da04 100644 --- a/pkgs/web_socket_conformance_tests/lib/src/no_upgrade_tests.dart +++ b/pkgs/web_socket_conformance_tests/lib/src/no_upgrade_tests.dart @@ -15,7 +15,7 @@ import 'no_upgrade_server_vm.dart' /// Tests that the [WebSocketChannel] can correctly transmit and receive text /// and binary payloads. void testNoUpgrade( - Future Function(Uri uri, {Iterable? protocols}) + Future Function(Uri uri, {Iterable? protocols}) channelFactory) { group('no upgrade', () { late final Uri uri; diff --git a/pkgs/web_socket_conformance_tests/lib/src/payload_transfer_tests.dart b/pkgs/web_socket_conformance_tests/lib/src/payload_transfer_tests.dart index 5dda10b569..df581917c2 100644 --- a/pkgs/web_socket_conformance_tests/lib/src/payload_transfer_tests.dart +++ b/pkgs/web_socket_conformance_tests/lib/src/payload_transfer_tests.dart @@ -14,7 +14,7 @@ import 'echo_server_vm.dart' if (dart.library.html) 'echo_server_web.dart'; /// Tests that the [WebSocketChannel] can correctly transmit and receive text /// and binary payloads. void testPayloadTransfer( - Future Function(Uri uri, {Iterable? protocols}) + Future Function(Uri uri, {Iterable? protocols}) channelFactory) { group('payload transfer', () { late final Uri uri; diff --git a/pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_tests.dart b/pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_tests.dart index 7c6edf14a8..27e440687d 100644 --- a/pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_tests.dart +++ b/pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_tests.dart @@ -15,7 +15,7 @@ import 'peer_protocol_errors_server_vm.dart' /// Tests that the [WebSocketChannel] can correctly transmit and receive text /// and binary payloads. void testPeerProtocolErrors( - Future Function(Uri uri, {Iterable? protocols}) + Future Function(Uri uri, {Iterable? protocols}) channelFactory) { group('protocol errors', () { late final Uri uri; diff --git a/pkgs/web_socket_conformance_tests/lib/web_socket_conformance_tests.dart b/pkgs/web_socket_conformance_tests/lib/web_socket_conformance_tests.dart index 41a267d6c0..b51507ca73 100644 --- a/pkgs/web_socket_conformance_tests/lib/web_socket_conformance_tests.dart +++ b/pkgs/web_socket_conformance_tests/lib/web_socket_conformance_tests.dart @@ -17,7 +17,7 @@ import 'src/peer_protocol_errors_tests.dart'; /// Runs the entire test suite against the given [WebSocketChannel]. void testAll( - Future Function(Uri uri, {Iterable? protocols}) + Future Function(Uri uri, {Iterable? protocols}) webSocketFactory) { testPayloadTransfer(webSocketFactory); testLocalClose(webSocketFactory); diff --git a/pkgs/websocket/lib/htmlwebsocket.dart b/pkgs/websocket/lib/htmlwebsocket.dart index 74772dc79f..a513353db1 100644 --- a/pkgs/websocket/lib/htmlwebsocket.dart +++ b/pkgs/websocket/lib/htmlwebsocket.dart @@ -5,7 +5,7 @@ import 'package:web/web.dart' as web; import 'package:websocket/websocket.dart'; import 'package:web/helpers.dart' as helpers; -class HtmlWebSocket implements WebSocket { +class HtmlWebSocket implements XXXWebSocket { final helpers.WebSocket _webSocket; final _events = StreamController(); diff --git a/pkgs/websocket/lib/iowebsocket.dart b/pkgs/websocket/lib/iowebsocket.dart index 709aa800c2..ad2ed152de 100644 --- a/pkgs/websocket/lib/iowebsocket.dart +++ b/pkgs/websocket/lib/iowebsocket.dart @@ -3,7 +3,7 @@ import 'dart:io' as io; import 'dart:typed_data'; import 'package:websocket/websocket.dart'; -class IOWebSocket implements WebSocket { +class IOWebSocket implements XXXWebSocket { final io.WebSocket _webSocket; final _events = StreamController(); diff --git a/pkgs/websocket/lib/websocket.dart b/pkgs/websocket/lib/websocket.dart index 59a837ad0f..69f51e0bce 100644 --- a/pkgs/websocket/lib/websocket.dart +++ b/pkgs/websocket/lib/websocket.dart @@ -3,6 +3,7 @@ import 'dart:typed_data'; sealed class WebSocketEvent {} +/// A received text frame. class TextDataReceived extends WebSocketEvent { final String text; TextDataReceived(this.text); @@ -15,14 +16,21 @@ class TextDataReceived extends WebSocketEvent { int get hashCode => text.hashCode; } +// A received binary frame. class BinaryDataReceived extends WebSocketEvent { final Uint8List data; BinaryDataReceived(this.data); - // XXX @override - bool operator ==(Object other) => - other is BinaryDataReceived && other.data.length == data.length; + bool operator ==(Object other) { + if (other is BinaryDataReceived && other.data.length == data.length) { + for (var i = 0; i < data.length; ++i) { + if (other.data[i] != data[i]) return false; + } + return true; + } + return false; + } @override int get hashCode => data.hashCode; @@ -31,6 +39,7 @@ class BinaryDataReceived extends WebSocketEvent { String toString() => 'BinaryDataReceived($data)'; } +/// A received close frame or failure. class Closed extends WebSocketEvent { final int? code; final String? reason; @@ -57,11 +66,12 @@ class WebSocketConnectionClosed extends XXXWebSocketException { WebSocketConnectionClosed([super.message = 'Connection Closed']); } -abstract interface class WebSocket { - /// Throws [WebSocketConnectionClosed] if the [WebSocket] is closed (either through [close] or by the peer). +/// What's a good name for this? `SimpleWebSocket`? 'LCDWebSocket`? +abstract interface class XXXWebSocket { + /// Throws [WebSocketConnectionClosed] if the [XXXWebSocket] is closed (either through [close] or by the peer). void addString(String s); - /// Throws [WebSocketConnectionClosed] if the [WebSocket] is closed (either through [close] or by the peer). + /// Throws [WebSocketConnectionClosed] if the [XXXWebSocket] is closed (either through [close] or by the peer). void addBytes(Uint8List b); /// Closes the WebSocket connection.