Chromium Code Reviews| Index: sdk/lib/io/websocket_impl.dart |
| diff --git a/sdk/lib/io/websocket_impl.dart b/sdk/lib/io/websocket_impl.dart |
| index 475c8f48248a8ff015d53f77e3bfdeff2989c0d7..438d3414b99e97cc12365115b19ea5d7d64ee643 100644 |
| --- a/sdk/lib/io/websocket_impl.dart |
| +++ b/sdk/lib/io/websocket_impl.dart |
| @@ -741,7 +741,10 @@ class _WebSocketConsumer implements StreamConsumer { |
| } |
| -class _WebSocketImpl extends Stream implements WebSocket { |
| +class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket { |
| + // Use default Map so we keep order. |
| + static Map<int, _WebSocketImpl> _webSockets = new Map<int, _WebSocketImpl>(); |
| + |
| final String protocol; |
| StreamController _controller; |
| @@ -892,6 +895,8 @@ class _WebSocketImpl extends Stream implements WebSocket { |
| onListen: _subscription.resume, |
| onPause: _subscription.pause, |
| onResume: _subscription.resume); |
| + |
| + _webSockets[_serviceId] = this; |
| } |
| StreamSubscription listen(void onData(message), |
| @@ -951,6 +956,7 @@ class _WebSocketImpl extends Stream implements WebSocket { |
| _closeReason = _outCloseReason; |
| _subscription.cancel(); |
| _controller.close(); |
| + _webSockets.remove(_serviceId); |
| }); |
| } |
| return _sink.close(); |
| @@ -964,6 +970,33 @@ class _WebSocketImpl extends Stream implements WebSocket { |
| } |
| _writeClosed = true; |
| _consumer.closeSocket(); |
| + _webSockets.remove(_serviceId); |
| + } |
| + |
| + String get _serviceTypePath => 'io/websockets'; |
| + String get _serviceTypeName => 'WebSocket'; |
| + |
| + Map _toJSON(bool ref) { |
| + var r = { |
| + 'id': _servicePath, |
| + 'type': _serviceType(ref), |
| + 'name': '${_socket.address.host}:${_socket.port}', |
|
Cutch
2014/05/27 11:04:53
Should the string interpolation be done once ?
Anders Johnsen
2014/11/13 16:20:39
Done.
|
| + 'user_name': '${_socket.address.host}:${_socket.port}', |
| + }; |
| + if (ref) { |
| + return r; |
| + } |
| + try { |
| + r['socket'] = _socket._toJSON(true); |
| + } catch (_) { |
| + r['socket'] = { |
| + 'id': _servicePath, |
| + 'type': '@Socket', |
| + 'name': 'UserSocket', |
| + 'user_name': 'UserSocket', |
| + }; |
| + } |
| + return r; |
| } |
| static bool _isReservedStatusCode(int code) { |