Forward protocols parameter to WebSocket (dart-lang/web_socket_channel#74) Fixes dart-lang/web_socket_channel#34
diff --git a/pkgs/web_socket_channel/CHANGELOG.md b/pkgs/web_socket_channel/CHANGELOG.md index d446637..dbd834f 100644 --- a/pkgs/web_socket_channel/CHANGELOG.md +++ b/pkgs/web_socket_channel/CHANGELOG.md
@@ -1,3 +1,7 @@ +## 1.0.15 + +* bug fix don't pass protocols parameter to WebSocket. + ## 1.0.14 * Updates to handle `Socket implements Stream<Uint8List>`
diff --git a/pkgs/web_socket_channel/lib/io.dart b/pkgs/web_socket_channel/lib/io.dart index 34c6bff..861b79f 100644 --- a/pkgs/web_socket_channel/lib/io.dart +++ b/pkgs/web_socket_channel/lib/io.dart
@@ -54,8 +54,9 @@ Duration pingInterval}) { var channel; var sinkCompleter = WebSocketSinkCompleter(); - var stream = StreamCompleter.fromFuture( - WebSocket.connect(url.toString(), headers: headers).then((webSocket) { + var stream = StreamCompleter.fromFuture(WebSocket.connect(url.toString(), + headers: headers, protocols: protocols) + .then((webSocket) { webSocket.pingInterval = pingInterval; channel._webSocket = webSocket; sinkCompleter.setDestinationSink(_IOWebSocketSink(webSocket));
diff --git a/pkgs/web_socket_channel/pubspec.yaml b/pkgs/web_socket_channel/pubspec.yaml index 6f7f490..71d8c19 100644 --- a/pkgs/web_socket_channel/pubspec.yaml +++ b/pkgs/web_socket_channel/pubspec.yaml
@@ -1,5 +1,5 @@ name: web_socket_channel -version: 1.0.14 +version: 1.0.15 description: >- StreamChannel wrappers for WebSockets. Provides a cross-platform
diff --git a/pkgs/web_socket_channel/test/io_test.dart b/pkgs/web_socket_channel/test/io_test.dart index f8f6325..ada0608 100644 --- a/pkgs/web_socket_channel/test/io_test.dart +++ b/pkgs/web_socket_channel/test/io_test.dart
@@ -97,4 +97,39 @@ expect(channel.stream.toList(), throwsA(TypeMatcher<WebSocketChannelException>())); }); + + test(".protocols fail", () async { + var passedProtocol = 'passed-protocol'; + var failedProtocol = 'failed-protocol'; + var selector = (List<String> receivedProtocols) => passedProtocol; + + server = await HttpServer.bind('localhost', 0); + server.listen((request) { + expect(WebSocketTransformer.upgrade(request, protocolSelector: selector), + throwsException); + }); + + var channel = IOWebSocketChannel.connect("ws://localhost:${server.port}", + protocols: [failedProtocol]); + expect(channel.stream.toList(), + throwsA(TypeMatcher<WebSocketChannelException>())); + }); + + test(".protocols pass", () async { + var passedProtocol = 'passed-protocol'; + var selector = (List<String> receivedProtocols) => passedProtocol; + + server = await HttpServer.bind('localhost', 0); + server.listen((request) async { + var webSocket = await WebSocketTransformer.upgrade(request, + protocolSelector: selector); + expect(webSocket.protocol, passedProtocol); + await webSocket.close(); + }); + + var channel = IOWebSocketChannel.connect("ws://localhost:${server.port}", + protocols: [passedProtocol]); + await channel.stream.listen(null).asFuture(); + expect(channel.protocol, passedProtocol); + }); }