Rename WebSocketAdapterWebSocketChannel to AdapterWebSocketChannel (#344)
diff --git a/lib/web_socket_adapter_web_socket_channel.dart b/lib/adapter_web_socket_channel.dart
similarity index 90%
rename from lib/web_socket_adapter_web_socket_channel.dart
rename to lib/adapter_web_socket_channel.dart
index 2a1242a..8415f27 100644
--- a/lib/web_socket_adapter_web_socket_channel.dart
+++ b/lib/adapter_web_socket_channel.dart
@@ -13,7 +13,7 @@
import 'src/exception.dart';
/// A [WebSocketChannel] implemented using [WebSocket].
-class WebSocketAdapterWebSocketChannel extends StreamChannelMixin
+class AdapterWebSocketChannel extends StreamChannelMixin
implements WebSocketChannel {
@override
String? get protocol => _protocol;
@@ -60,18 +60,17 @@
/// the peer is able to select. See
/// [RFC-6455 1.9](https://datatracker.ietf.org/doc/html/rfc6455#section-1.9).
///
- /// After construction, the [WebSocketAdapterWebSocketChannel] may not be
+ /// After construction, the [AdapterWebSocketChannel] may not be
/// connected to the peer. The [ready] future will complete after the channel
/// is connected. If there are errors creating the connection the [ready]
/// future will complete with an error.
- factory WebSocketAdapterWebSocketChannel.connect(Uri url,
+ factory AdapterWebSocketChannel.connect(Uri url,
{Iterable<String>? protocols}) =>
- WebSocketAdapterWebSocketChannel(
- WebSocket.connect(url, protocols: protocols));
+ AdapterWebSocketChannel(WebSocket.connect(url, protocols: protocols));
// Construct a [WebSocketWebSocketChannelAdapter] from an existing
// [WebSocket].
- WebSocketAdapterWebSocketChannel(FutureOr<WebSocket> webSocket) {
+ AdapterWebSocketChannel(FutureOr<WebSocket> webSocket) {
Future<WebSocket> webSocketFuture;
if (webSocket is WebSocket) {
webSocketFuture = Future.value(webSocket);
@@ -135,9 +134,9 @@
/// A [WebSocketSink] that tracks the close code and reason passed to [close].
class _WebSocketSink extends DelegatingStreamSink implements WebSocketSink {
/// The channel to which this sink belongs.
- final WebSocketAdapterWebSocketChannel _channel;
+ final AdapterWebSocketChannel _channel;
- _WebSocketSink(WebSocketAdapterWebSocketChannel channel)
+ _WebSocketSink(AdapterWebSocketChannel channel)
: _channel = channel,
super(channel._controller.foreign.sink);
diff --git a/lib/io.dart b/lib/io.dart
index cfba457..ec69b22 100644
--- a/lib/io.dart
+++ b/lib/io.dart
@@ -4,14 +4,15 @@
import 'dart:async';
import 'dart:io' show HttpClient, WebSocket;
+
import 'package:web_socket/io_web_socket.dart' as io_web_socket;
+import 'adapter_web_socket_channel.dart';
import 'src/channel.dart';
import 'src/exception.dart';
-import 'web_socket_adapter_web_socket_channel.dart';
/// A [WebSocketChannel] that communicates using a `dart:io` [WebSocket].
-class IOWebSocketChannel extends WebSocketAdapterWebSocketChannel {
+class IOWebSocketChannel extends AdapterWebSocketChannel {
/// Creates a new WebSocket connection.
///
/// Connects to [url] using [WebSocket.connect] and returns a channel that can
diff --git a/lib/src/channel.dart b/lib/src/channel.dart
index 8c8f24e..f8a560e 100644
--- a/lib/src/channel.dart
+++ b/lib/src/channel.dart
@@ -9,7 +9,7 @@
import 'package:crypto/crypto.dart';
import 'package:stream_channel/stream_channel.dart';
-import '../web_socket_adapter_web_socket_channel.dart';
+import '../adapter_web_socket_channel.dart';
import 'exception.dart';
const String _webSocketGUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
@@ -105,7 +105,7 @@
/// If there are errors creating the connection the [ready] future will
/// complete with an error.
static WebSocketChannel connect(Uri uri, {Iterable<String>? protocols}) =>
- WebSocketAdapterWebSocketChannel.connect(uri, protocols: protocols);
+ AdapterWebSocketChannel.connect(uri, protocols: protocols);
}
/// The sink exposed by a [WebSocketChannel].
diff --git a/test/web_socket_adapter_web_socket_test.dart b/test/adapter_web_socket_channel_test.dart
similarity index 82%
rename from test/web_socket_adapter_web_socket_test.dart
rename to test/adapter_web_socket_channel_test.dart
index c66133b..44ed7a9 100644
--- a/test/web_socket_adapter_web_socket_test.dart
+++ b/test/adapter_web_socket_channel_test.dart
@@ -8,14 +8,15 @@
import 'package:stream_channel/stream_channel.dart';
import 'package:test/test.dart';
import 'package:web_socket/web_socket.dart';
+import 'package:web_socket_channel/adapter_web_socket_channel.dart';
import 'package:web_socket_channel/src/exception.dart';
-import 'package:web_socket_channel/web_socket_adapter_web_socket_channel.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
+
import 'echo_server_vm.dart'
if (dart.library.js_interop) 'echo_server_web.dart';
void main() {
- group('WebSocketWebSocketChannelAdapter', () {
+ group('AdapterWebSocketChannel', () {
late Uri uri;
late StreamChannel<Object?> httpServerChannel;
late StreamQueue<Object?> httpServerQueue;
@@ -34,20 +35,20 @@
test('failed connect', () async {
final channel =
- WebSocketAdapterWebSocketChannel.connect(Uri.parse('ws://notahost'));
+ AdapterWebSocketChannel.connect(Uri.parse('ws://notahost'));
await expectLater(
channel.ready, throwsA(isA<WebSocketChannelException>()));
});
test('good connect', () async {
- final channel = WebSocketAdapterWebSocketChannel.connect(uri);
+ final channel = AdapterWebSocketChannel.connect(uri);
await expectLater(channel.ready, completes);
await channel.sink.close();
});
test('echo empty text', () async {
- final channel = WebSocketAdapterWebSocketChannel.connect(uri);
+ final channel = AdapterWebSocketChannel.connect(uri);
await expectLater(channel.ready, completes);
channel.sink.add('');
expect(await channel.stream.first, '');
@@ -55,7 +56,7 @@
});
test('echo empty binary', () async {
- final channel = WebSocketAdapterWebSocketChannel.connect(uri);
+ final channel = AdapterWebSocketChannel.connect(uri);
await expectLater(channel.ready, completes);
channel.sink.add(Uint8List.fromList(<int>[]));
expect(await channel.stream.first, isEmpty);
@@ -63,7 +64,7 @@
});
test('echo hello', () async {
- final channel = WebSocketAdapterWebSocketChannel.connect(uri);
+ final channel = AdapterWebSocketChannel.connect(uri);
await expectLater(channel.ready, completes);
channel.sink.add('hello');
expect(await channel.stream.first, 'hello');
@@ -71,7 +72,7 @@
});
test('echo [1,2,3]', () async {
- final channel = WebSocketAdapterWebSocketChannel.connect(uri);
+ final channel = AdapterWebSocketChannel.connect(uri);
await expectLater(channel.ready, completes);
channel.sink.add([1, 2, 3]);
expect(await channel.stream.first, [1, 2, 3]);
@@ -79,7 +80,7 @@
});
test('alternative string and binary request and response', () async {
- final channel = WebSocketAdapterWebSocketChannel.connect(uri);
+ final channel = AdapterWebSocketChannel.connect(uri);
await expectLater(channel.ready, completes);
channel.sink.add('This count says:');
channel.sink.add([1, 2, 3]);
@@ -94,7 +95,7 @@
});
test('remote close', () async {
- final channel = WebSocketAdapterWebSocketChannel.connect(uri);
+ final channel = AdapterWebSocketChannel.connect(uri);
await expectLater(channel.ready, completes);
channel.sink.add('close'); // Asks the peer to close.
// Give the server time to send a close frame.
@@ -105,7 +106,7 @@
});
test('local close', () async {
- final channel = WebSocketAdapterWebSocketChannel.connect(uri);
+ final channel = AdapterWebSocketChannel.connect(uri);
await expectLater(channel.ready, completes);
await channel.sink.close(3005, 'please close');
expect(channel.closeCode, null);
@@ -114,7 +115,7 @@
test('constructor with WebSocket', () async {
final webSocket = await WebSocket.connect(uri);
- final channel = WebSocketAdapterWebSocketChannel(webSocket);
+ final channel = AdapterWebSocketChannel(webSocket);
await expectLater(channel.ready, completes);
channel.sink.add('This count says:');
@@ -131,7 +132,7 @@
test('constructor with Future<WebSocket>', () async {
final webSocketFuture = WebSocket.connect(uri);
- final channel = WebSocketAdapterWebSocketChannel(webSocketFuture);
+ final channel = AdapterWebSocketChannel(webSocketFuture);
await expectLater(channel.ready, completes);
channel.sink.add('This count says:');