Skip to content

Commit

Permalink
Compare
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Jan 31, 2024
1 parent 4bf037a commit 26d0df1
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkgs/cupertino_http/lib/src/websocket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CupertinoWebSocketException extends XXXWebSocketException {
CupertinoWebSocketException(e.toString());
}

class CupertinoWebSocket implements WebSocket {
class CupertinoWebSocket implements XXXWebSocket {
static Future<CupertinoWebSocket> connect(Uri uri) async {
final readyCompleter = Completer<void>();
late CupertinoWebSocket webSocket;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebSocket> Function(Uri uri, {Iterable<String>? protocols})
Future<XXXWebSocket> Function(Uri uri, {Iterable<String>? protocols})
channelFactory) {
group('local close', () {
late Uri uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebSocket> Function(Uri uri, {Iterable<String>? protocols})
Future<XXXWebSocket> Function(Uri uri, {Iterable<String>? protocols})
channelFactory) {
group('remote close', () {
late Uri uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebSocket> Function(Uri uri, {Iterable<String>? protocols})
Future<XXXWebSocket> Function(Uri uri, {Iterable<String>? protocols})
channelFactory) {
group('disconnect', () {
late final Uri uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebSocket> Function(Uri uri, {Iterable<String>? protocols})
Future<XXXWebSocket> Function(Uri uri, {Iterable<String>? protocols})
channelFactory) {
group('no upgrade', () {
late final Uri uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebSocket> Function(Uri uri, {Iterable<String>? protocols})
Future<XXXWebSocket> Function(Uri uri, {Iterable<String>? protocols})
channelFactory) {
group('payload transfer', () {
late final Uri uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebSocket> Function(Uri uri, {Iterable<String>? protocols})
Future<XXXWebSocket> Function(Uri uri, {Iterable<String>? protocols})
channelFactory) {
group('protocol errors', () {
late final Uri uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'src/peer_protocol_errors_tests.dart';

/// Runs the entire test suite against the given [WebSocketChannel].
void testAll(
Future<WebSocket> Function(Uri uri, {Iterable<String>? protocols})
Future<XXXWebSocket> Function(Uri uri, {Iterable<String>? protocols})
webSocketFactory) {
testPayloadTransfer(webSocketFactory);
testLocalClose(webSocketFactory);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/websocket/lib/htmlwebsocket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebSocketEvent>();

Expand Down
2 changes: 1 addition & 1 deletion pkgs/websocket/lib/iowebsocket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebSocketEvent>();

Expand Down
22 changes: 16 additions & 6 deletions pkgs/websocket/lib/websocket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand Down

0 comments on commit 26d0df1

Please sign in to comment.