dartfmt
diff --git a/lib/html.dart b/lib/html.dart
index f9daadc..6d5007a 100644
--- a/lib/html.dart
+++ b/lib/html.dart
@@ -45,8 +45,8 @@
String _localCloseReason;
Stream get stream => _controller.foreign.stream;
- final _controller = new StreamChannelController(
- sync: true, allowForeignErrors: false);
+ final _controller =
+ new StreamChannelController(sync: true, allowForeignErrors: false);
WebSocketSink get sink => _sink;
WebSocketSink _sink;
@@ -62,13 +62,13 @@
/// received by this socket. It defaults to [BinaryType.list], which causes
/// binary messages to be delivered as [Uint8List]s. If it's
/// [BinaryType.blob], they're delivered as [Blob]s instead.
- HtmlWebSocketChannel.connect(url, {Iterable<String> protocols,
- BinaryType binaryType})
+ HtmlWebSocketChannel.connect(url,
+ {Iterable<String> protocols, BinaryType binaryType})
: this(new WebSocket(url.toString(), protocols)
..binaryType = (binaryType ?? BinaryType.list).value);
/// Creates a channel wrapping [webSocket].
- HtmlWebSocketChannel(this._webSocket){
+ HtmlWebSocketChannel(this._webSocket) {
_sink = new _HtmlWebSocketSink(this);
if (_webSocket.readyState == WebSocket.OPEN) {
diff --git a/lib/io.dart b/lib/io.dart
index 0764acf..607d225 100644
--- a/lib/io.dart
+++ b/lib/io.dart
@@ -48,8 +48,10 @@
///
/// If there's an error connecting, the channel's stream emits a
/// [WebSocketChannelException] wrapping that error and then closes.
- factory IOWebSocketChannel.connect(url, {Iterable<String> protocols,
- Map<String, dynamic> headers, Duration pingInterval}) {
+ factory IOWebSocketChannel.connect(url,
+ {Iterable<String> protocols,
+ Map<String, dynamic> headers,
+ Duration pingInterval}) {
var channel;
var sinkCompleter = new WebSocketSinkCompleter();
var stream = StreamCompleter.fromFuture(
@@ -67,8 +69,8 @@
/// Creates a channel wrapping [socket].
IOWebSocketChannel(WebSocket socket)
: _webSocket = socket,
- stream = socket.handleError((error) =>
- throw new WebSocketChannelException.from(error)),
+ stream = socket.handleError(
+ (error) => throw new WebSocketChannelException.from(error)),
sink = new _IOWebSocketSink(socket);
/// Creates a channel without a socket.
@@ -77,8 +79,8 @@
/// has a socket added.
IOWebSocketChannel._withoutSocket(Stream stream, this.sink)
: _webSocket = null,
- stream = stream.handleError((error) =>
- throw new WebSocketChannelException.from(error));
+ stream = stream.handleError(
+ (error) => throw new WebSocketChannelException.from(error));
}
/// A [WebSocketSink] that forwards [close] calls to a `dart:io` [WebSocket].
diff --git a/lib/src/channel.dart b/lib/src/channel.dart
index 6aff42c..4cd368c 100644
--- a/lib/src/channel.dart
+++ b/lib/src/channel.dart
@@ -65,8 +65,8 @@
static String signKey(String key) {
// We use [codeUnits] here rather than UTF-8-decoding the string because
// [key] is expected to be base64 encoded, and so will be pure ASCII.
- return convert.BASE64.encode(
- sha1.convert((key + webSocketGUID).codeUnits).bytes);
+ return convert.BASE64
+ .encode(sha1.convert((key + webSocketGUID).codeUnits).bytes);
}
/// Creates a new WebSocket handling messaging across an existing [channel].
@@ -90,7 +90,7 @@
///
/// [WebSocket handshake]: https://tools.ietf.org/html/rfc6455#section-4
WebSocketChannel(StreamChannel<List<int>> channel,
- {String protocol, Duration pingInterval, bool serverSide: true})
+ {String protocol, Duration pingInterval, bool serverSide: true})
: _webSocket = new WebSocketImpl.fromSocket(
channel.stream, channel.sink, protocol, serverSide)
..pingInterval = pingInterval;
diff --git a/lib/src/copy/bytes_builder.dart b/lib/src/copy/bytes_builder.dart
index 573eed5..1d88199 100644
--- a/lib/src/copy/bytes_builder.dart
+++ b/lib/src/copy/bytes_builder.dart
@@ -88,7 +88,6 @@
void clear();
}
-
class _CopyingBytesBuilder implements BytesBuilder {
// Start with 1024 bytes.
static const int _INIT_SIZE = 1024;
@@ -123,7 +122,9 @@
_length = required;
}
- void addByte(int byte) { add([byte]); }
+ void addByte(int byte) {
+ add([byte]);
+ }
List<int> takeBytes() {
if (_buffer == null) return new Uint8List(0);
@@ -160,7 +161,6 @@
}
}
-
class _BytesBuilder implements BytesBuilder {
int _length = 0;
final _chunks = <List<int>>[];
@@ -173,7 +173,9 @@
_length += bytes.length;
}
- void addByte(int byte) { add([byte]); }
+ void addByte(int byte) {
+ add([byte]);
+ }
List<int> takeBytes() {
if (_chunks.length == 0) return new Uint8List(0);
diff --git a/lib/src/copy/io_sink.dart b/lib/src/copy/io_sink.dart
index 34abcad..dafd86b 100644
--- a/lib/src/copy/io_sink.dart
+++ b/lib/src/copy/io_sink.dart
@@ -41,11 +41,11 @@
if (_hasError) return done;
// Wait for any sync operations to complete.
Future targetAddStream() {
- return _target.addStream(stream)
- .whenComplete(() {
- _isBound = false;
- });
+ return _target.addStream(stream).whenComplete(() {
+ _isBound = false;
+ });
}
+
if (_controllerInstance == null) return targetAddStream();
var future = _controllerCompleter.future;
_controllerInstance.close();
@@ -133,7 +133,7 @@
_completeDoneError(error, stackTrace);
}
});
- }
+ }
return _controllerInstance;
}
}
diff --git a/lib/src/copy/web_socket_impl.dart b/lib/src/copy/web_socket_impl.dart
index e26e1b3..260a341 100644
--- a/lib/src/copy/web_socket_impl.dart
+++ b/lib/src/copy/web_socket_impl.dart
@@ -118,7 +118,9 @@
_eventSink.addError(error, stackTrace);
}
- void close() { _eventSink.close(); }
+ void close() {
+ _eventSink.close();
+ }
/**
* Process data received from the underlying communication channel.
@@ -139,7 +141,7 @@
if (_state == START) {
_fin = (byte & FIN) != 0;
- if((byte & (RSV2 | RSV3)) != 0) {
+ if ((byte & (RSV2 | RSV3)) != 0) {
// The RSV2, RSV3 bits must both be zero.
throw new WebSocketChannelException("Protocol error");
}
@@ -468,11 +470,8 @@
_eventSink.close();
}
- void addFrame(int opcode, List<int> data) => createFrame(
- opcode,
- data,
- webSocket._serverSide,
- false).forEach((e) {
+ void addFrame(int opcode, List<int> data) =>
+ createFrame(opcode, data, webSocket._serverSide, false).forEach((e) {
_eventSink.add(e);
});
@@ -491,9 +490,9 @@
int index = 0;
// Set FIN and opcode.
- var hoc = _WebSocketProtocolTransformer.FIN
- | (compressed ? _WebSocketProtocolTransformer.RSV1 : 0)
- | (opcode & _WebSocketProtocolTransformer.OPCODE);
+ var hoc = _WebSocketProtocolTransformer.FIN |
+ (compressed ? _WebSocketProtocolTransformer.RSV1 : 0) |
+ (opcode & _WebSocketProtocolTransformer.OPCODE);
header[index++] = hoc;
// Determine size and position of length field.
@@ -511,8 +510,12 @@
}
if (mask) {
header[1] |= 1 << 7;
- var maskBytes = [_random.nextInt(256), _random.nextInt(256),
- _random.nextInt(256), _random.nextInt(256)];
+ var maskBytes = [
+ _random.nextInt(256),
+ _random.nextInt(256),
+ _random.nextInt(256),
+ _random.nextInt(256)
+ ];
header.setRange(index, index + 4, maskBytes);
index += 4;
if (data != null) {
@@ -667,6 +670,7 @@
Future closeSocket() {
return sink.close().catchError((_) {}).then((_) => webSocket);
}
+
_controller.close();
return _closeCompleter.future.then((_) => closeSocket());
}
@@ -755,10 +759,14 @@
}, cancelOnError: true);
_subscription.pause();
_controller = new StreamController(
- sync: true, onListen: () => _subscription.resume(), onCancel: () {
- _subscription.cancel();
- _subscription = null;
- }, onPause: _subscription.pause, onResume: _subscription.resume);
+ sync: true,
+ onListen: () => _subscription.resume(),
+ onCancel: () {
+ _subscription.cancel();
+ _subscription = null;
+ },
+ onPause: _subscription.pause,
+ onResume: _subscription.resume);
_webSockets[_serviceId] = this;
}
@@ -794,10 +802,14 @@
int get closeCode => _closeCode;
String get closeReason => _closeReason;
- void add(data) { _sink.add(data); }
+ void add(data) {
+ _sink.add(data);
+ }
+
void addError(error, [StackTrace stackTrace]) {
_sink.addError(error, stackTrace);
}
+
Future addStream(Stream stream) => _sink.addStream(stream);
Future get done => _sink.done;
diff --git a/lib/src/exception.dart b/lib/src/exception.dart
index 47545ed..6cb8836 100644
--- a/lib/src/exception.dart
+++ b/lib/src/exception.dart
@@ -18,6 +18,6 @@
inner = inner;
String toString() => message == null
- ? "WebSocketChannelException" :
- "WebSocketChannelException: $message";
+ ? "WebSocketChannelException"
+ : "WebSocketChannelException: $message";
}
diff --git a/lib/src/sink_completer.dart b/lib/src/sink_completer.dart
index d932fd7..04a915c 100644
--- a/lib/src/sink_completer.dart
+++ b/lib/src/sink_completer.dart
@@ -150,4 +150,4 @@
_doneCompleter.complete(sink.done);
}
}
-}
\ No newline at end of file
+}
diff --git a/test/html_test.dart b/test/html_test.dart
index 8c9f44e..83f112f 100644
--- a/test/html_test.dart
+++ b/test/html_test.dart
@@ -80,8 +80,8 @@
});
test(".connect can use blobs", () async {
- channel = new HtmlWebSocketChannel.connect(
- "ws://localhost:$port", binaryType: BinaryType.blob);
+ channel = new HtmlWebSocketChannel.connect("ws://localhost:$port",
+ binaryType: BinaryType.blob);
var queue = new StreamQueue(channel.stream);
channel.sink.add("foo");
diff --git a/test/io_test.dart b/test/io_test.dart
index fcf8c7c..a277d79 100644
--- a/test/io_test.dart
+++ b/test/io_test.dart
@@ -59,14 +59,16 @@
});
});
- var channel = new IOWebSocketChannel.connect(
- "ws://localhost:${server.port}");
+ var channel =
+ new IOWebSocketChannel.connect("ws://localhost:${server.port}");
channel.sink.add("ping");
- channel.stream.listen(expectAsync((message) {
- expect(message, equals("pong"));
- channel.sink.close(5678, "raisin");
- }, count: 1), onDone: expectAsync(() {}));
+ channel.stream.listen(
+ expectAsync((message) {
+ expect(message, equals("pong"));
+ channel.sink.close(5678, "raisin");
+ }, count: 1),
+ onDone: expectAsync(() {}));
});
test(".connect with an immediate call to close", () async {
@@ -80,8 +82,8 @@
}(), completes);
});
- var channel = new IOWebSocketChannel.connect(
- "ws://localhost:${server.port}");
+ var channel =
+ new IOWebSocketChannel.connect("ws://localhost:${server.port}");
channel.sink.close(5678, "raisin");
});
@@ -93,8 +95,8 @@
request.response.close();
});
- var channel = new IOWebSocketChannel.connect(
- "ws://localhost:${server.port}");
+ var channel =
+ new IOWebSocketChannel.connect("ws://localhost:${server.port}");
expect(channel.stream.toList(),
throwsA(new isInstanceOf<WebSocketChannelException>()));
});
diff --git a/test/web_socket_test.dart b/test/web_socket_test.dart
index 217df13..68d6b35 100644
--- a/test/web_socket_test.dart
+++ b/test/web_socket_test.dart
@@ -62,8 +62,10 @@
response.headers
..set("Connection", "Upgrade")
..set("Upgrade", "websocket")
- ..set("Sec-WebSocket-Accept", WebSocketChannel
- .signKey(request.headers.value('Sec-WebSocket-Key')));
+ ..set(
+ "Sec-WebSocket-Accept",
+ WebSocketChannel
+ .signKey(request.headers.value('Sec-WebSocket-Key')));
response.contentLength = 0;
var socket = await response.detachSocket();