Skip to content

Commit

Permalink
Forward protocols parameter to WebSocket (flutter#74)
Browse files Browse the repository at this point in the history
Fixes #34
  • Loading branch information
chungheepark authored and natebosch committed Aug 8, 2019
1 parent 5f5ca1a commit 82692f9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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>`
Expand Down
5 changes: 3 additions & 2 deletions lib/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ class IOWebSocketChannel extends StreamChannelMixin
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));
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 35 additions & 0 deletions test/io_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,39 @@ void main() {
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);
});
}

0 comments on commit 82692f9

Please sign in to comment.