Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Unified Diff: sdk/lib/io/websocket_impl.dart

Issue 12383051: Change the web socket interface (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/websocket.dart ('k') | tests/standalone/io/web_socket_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/websocket_impl.dart
diff --git a/sdk/lib/io/websocket_impl.dart b/sdk/lib/io/websocket_impl.dart
index 12539d67af22e4a883efa90484782eda991beb99..c0cb59447e28d1d2b603b46e55dd386eba6b95b1 100644
--- a/sdk/lib/io/websocket_impl.dart
+++ b/sdk/lib/io/websocket_impl.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -425,8 +425,8 @@ class _WebSocketTransformerImpl implements WebSocketTransformer {
}
-class _WebSocketImpl extends Stream<Event> implements WebSocket {
- final StreamController<Event> _controller = new StreamController<Event>();
+class _WebSocketImpl extends Stream implements WebSocket {
+ final StreamController _controller = new StreamController();
final _WebSocketProtocolProcessor _processor =
new _WebSocketProtocolProcessor();
@@ -434,6 +434,8 @@ class _WebSocketImpl extends Stream<Event> implements WebSocket {
final Socket _socket;
int _readyState = WebSocket.CONNECTING;
bool _writeClosed = false;
+ int _closeCode;
+ String _closeReason;
static final HttpClient _httpClient = new HttpClient();
@@ -529,9 +531,9 @@ class _WebSocketImpl extends Stream<Event> implements WebSocket {
};
_processor.onMessageEnd = () {
if (type == _WebSocketMessageType.TEXT) {
- _controller.add(new _WebSocketMessageEvent(data.toString()));
+ _controller.add(data.toString());
} else {
- _controller.add(new _WebSocketMessageEvent(data));
+ _controller.add(data);
}
};
_processor.onClosed = (code, reason) {
@@ -547,7 +549,9 @@ class _WebSocketImpl extends Stream<Event> implements WebSocket {
_readyState = WebSocket.CLOSED;
}
if (_readyState == WebSocket.CLOSED) return;
- _controller.add(new _WebSocketCloseEvent(clean, code, reason));
+ //_cleanClose = clean;
Anders Johnsen 2013/03/04 10:29:29 Outcommented code.
Søren Gjesse 2013/03/04 10:35:18 Oops - removed.
+ _closeCode = code;
+ _closeReason = reason;
_controller.close();
};
@@ -560,6 +564,8 @@ class _WebSocketImpl extends Stream<Event> implements WebSocket {
.catchError((error) {
if (_readyState == WebSocket.CLOSED) return;
_readyState = WebSocket.CLOSED;
+ //_cleanClose = false;
Anders Johnsen 2013/03/04 10:29:29 Ditto.
Søren Gjesse 2013/03/04 10:35:18 Ditto.
+ _closeCode = ABNORMAL_CLOSURE;
_controller.signalError(error);
_controller.close();
_socket.destroy();
@@ -569,10 +575,10 @@ class _WebSocketImpl extends Stream<Event> implements WebSocket {
});
}
- StreamSubscription<Event> listen(void onData(Event event),
- {void onError(AsyncError error),
- void onDone(),
- bool unsubscribeOnError}) {
+ StreamSubscription listen(void onData(message),
+ {void onError(AsyncError error),
+ void onDone(),
+ bool unsubscribeOnError}) {
return _controller.stream.listen(onData,
onError: onError,
onDone: onDone,
@@ -580,10 +586,11 @@ class _WebSocketImpl extends Stream<Event> implements WebSocket {
}
int get readyState => _readyState;
- int get bufferedAmount => 0;
String get extensions => null;
String get protocol => null;
+ int get closeCode => _closeCode;
+ String get closeReason => _closeReason;
void close([int code, String reason]) {
if (_readyState < WebSocket.CLOSING) _readyState = WebSocket.CLOSING;
@@ -685,21 +692,3 @@ class _WebSocketImpl extends Stream<Event> implements WebSocket {
}
}
}
-
-
-class _WebSocketMessageEvent implements MessageEvent {
- _WebSocketMessageEvent(this._data);
- get data => _data;
- var _data;
-}
-
-
-class _WebSocketCloseEvent implements CloseEvent {
- _WebSocketCloseEvent(this._wasClean, this._code, this._reason);
- bool get wasClean => _wasClean;
- int get code => _code;
- String get reason => _reason;
- bool _wasClean;
- int _code;
- String _reason;
-}
« no previous file with comments | « sdk/lib/io/websocket.dart ('k') | tests/standalone/io/web_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698