| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of vmservice_io; | 5 part of vmservice_io; |
| 6 | 6 |
| 7 class WebSocketClient extends Client { | 7 class WebSocketClient extends Client { |
| 8 static const int PARSE_ERROR_CODE = 4000; | 8 static const int PARSE_ERROR_CODE = 4000; |
| 9 static const int BINARY_MESSAGE_ERROR_CODE = 4001; | 9 static const int BINARY_MESSAGE_ERROR_CODE = 4001; |
| 10 static const int NOT_MAP_ERROR_CODE = 4002; | 10 static const int NOT_MAP_ERROR_CODE = 4002; |
| 11 final WebSocket socket; | 11 final WebSocket socket; |
| 12 | 12 |
| 13 WebSocketClient(this.socket, service) : super(service) { | 13 WebSocketClient(this.socket, service) : super(service) { |
| 14 socket.listen((message) => onWebSocketMessage(message)); | 14 socket.listen((message) => onWebSocketMessage(message)); |
| 15 socket.done.then((_) => close()); | 15 socket.done.then((_) => close()); |
| 16 service.subscribe('debug', this); |
| 16 } | 17 } |
| 17 | 18 |
| 18 void onWebSocketMessage(message) { | 19 void onWebSocketMessage(message) { |
| 19 if (message is String) { | 20 if (message is String) { |
| 20 var map; | 21 var map; |
| 21 try { | 22 try { |
| 22 map = JSON.decode(message); | 23 map = JSON.decode(message); |
| 23 } catch (e) { | 24 } catch (e) { |
| 24 socket.close(PARSE_ERROR_CODE, 'Message parse error: $e'); | 25 socket.close(PARSE_ERROR_CODE, 'Message parse error: $e'); |
| 25 return; | 26 return; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 _server = null; | 192 _server = null; |
| 192 return this; | 193 return this; |
| 193 }).catchError((e, st) { | 194 }).catchError((e, st) { |
| 194 _server = null; | 195 _server = null; |
| 195 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); | 196 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); |
| 196 return this; | 197 return this; |
| 197 }); | 198 }); |
| 198 } | 199 } |
| 199 | 200 |
| 200 } | 201 } |
| OLD | NEW |