| 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 service.subscribe('debug', this); |
| 17 service.subscribe('gc', this); |
| 17 } | 18 } |
| 18 | 19 |
| 19 void onWebSocketMessage(message) { | 20 void onWebSocketMessage(message) { |
| 20 if (message is String) { | 21 if (message is String) { |
| 21 var map; | 22 var map; |
| 22 try { | 23 try { |
| 23 map = JSON.decode(message); | 24 map = JSON.decode(message); |
| 24 } catch (e) { | 25 } catch (e) { |
| 25 socket.close(PARSE_ERROR_CODE, 'Message parse error: $e'); | 26 socket.close(PARSE_ERROR_CODE, 'Message parse error: $e'); |
| 26 return; | 27 return; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 _server = null; | 193 _server = null; |
| 193 return this; | 194 return this; |
| 194 }).catchError((e, st) { | 195 }).catchError((e, st) { |
| 195 _server = null; | 196 _server = null; |
| 196 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); | 197 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); |
| 197 return this; | 198 return this; |
| 198 }); | 199 }); |
| 199 } | 200 } |
| 200 | 201 |
| 201 } | 202 } |
| OLD | NEW |