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; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // Do nothing. | 50 // Do nothing. |
51 return; | 51 return; |
52 } | 52 } |
53 try { | 53 try { |
54 if (result is String || result is Uint8List) { | 54 if (result is String || result is Uint8List) { |
55 socket.add(result); // String or binary message. | 55 socket.add(result); // String or binary message. |
56 } else { | 56 } else { |
57 // String message as external Uint8List. | 57 // String message as external Uint8List. |
58 assert(result is List); | 58 assert(result is List); |
59 Uint8List cstring = result[0]; | 59 Uint8List cstring = result[0]; |
60 // TODO(rmacnak): cstring may be large. Add a way to pass an encoded | 60 socket.sendMessage(WebSocketMessageType.TEXT, cstring); |
61 // string to a web socket that will be sent as a text message to avoid | |
62 // the space overhead of converting cstring to a Dart string. | |
63 socket.add(UTF8.decode(cstring)); | |
64 } | 61 } |
65 } catch (_) { | 62 } catch (_) { |
66 print("Ignoring error posting over WebSocket."); | 63 print("Ignoring error posting over WebSocket."); |
67 } | 64 } |
68 } | 65 } |
69 | 66 |
70 dynamic toJson() { | 67 dynamic toJson() { |
71 Map map = super.toJson(); | 68 Map map = super.toJson(); |
72 map['type'] = 'WebSocketClient'; | 69 map['type'] = 'WebSocketClient'; |
73 map['socket'] = '$socket'; | 70 map['socket'] = '$socket'; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 _notifyServerState("", 0); | 318 _notifyServerState("", 0); |
322 onServerAddressChange(null); | 319 onServerAddressChange(null); |
323 return this; | 320 return this; |
324 }); | 321 }); |
325 } | 322 } |
326 | 323 |
327 } | 324 } |
328 | 325 |
329 void _notifyServerState(String ip, int port) | 326 void _notifyServerState(String ip, int port) |
330 native "VMServiceIO_NotifyServerState"; | 327 native "VMServiceIO_NotifyServerState"; |
OLD | NEW |