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 22 matching lines...) Expand all Loading... |
33 if (serial != null && serial is! num && serial is! String) { | 33 if (serial != null && serial is! num && serial is! String) { |
34 socket.close(ID_ERROR_CODE, '"id" must be a number, string, or null.'); | 34 socket.close(ID_ERROR_CODE, '"id" must be a number, string, or null.'); |
35 } | 35 } |
36 onMessage(serial, new Message.fromJsonRpc(this, map)); | 36 onMessage(serial, new Message.fromJsonRpc(this, map)); |
37 } else { | 37 } else { |
38 socket.close(BINARY_MESSAGE_ERROR_CODE, 'Message must be a string.'); | 38 socket.close(BINARY_MESSAGE_ERROR_CODE, 'Message must be a string.'); |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 void post(dynamic result) { | 42 void post(dynamic result) { |
| 43 if (result == null) { |
| 44 // Do nothing. |
| 45 return; |
| 46 } |
43 try { | 47 try { |
44 socket.add(result); | 48 socket.add(result); |
45 } catch (_) { | 49 } catch (_) { |
46 print("Ignoring error posting over WebSocket."); | 50 print("Ignoring error posting over WebSocket."); |
47 } | 51 } |
48 } | 52 } |
49 | 53 |
50 dynamic toJson() { | 54 dynamic toJson() { |
51 Map map = super.toJson(); | 55 Map map = super.toJson(); |
52 map['type'] = 'WebSocketClient'; | 56 map['type'] = 'WebSocketClient'; |
53 map['socket'] = '$socket'; | 57 map['socket'] = '$socket'; |
54 return map; | 58 return map; |
55 } | 59 } |
56 } | 60 } |
57 | 61 |
58 | 62 |
59 class HttpRequestClient extends Client { | 63 class HttpRequestClient extends Client { |
60 static ContentType jsonContentType = | 64 static ContentType jsonContentType = |
61 new ContentType("application", "json", charset: "utf-8"); | 65 new ContentType("application", "json", charset: "utf-8"); |
62 final HttpRequest request; | 66 final HttpRequest request; |
63 | 67 |
64 HttpRequestClient(this.request, VMService service) | 68 HttpRequestClient(this.request, VMService service) |
65 : super(service, sendEvents:false); | 69 : super(service, sendEvents:false); |
66 | 70 |
67 void post(String result) { | 71 void post(String result) { |
| 72 if (result == null) { |
| 73 close(); |
| 74 return; |
| 75 } |
68 request.response..headers.contentType = jsonContentType | 76 request.response..headers.contentType = jsonContentType |
69 ..write(result) | 77 ..write(result) |
70 ..close(); | 78 ..close(); |
71 close(); | 79 close(); |
72 } | 80 } |
73 | 81 |
74 dynamic toJson() { | 82 dynamic toJson() { |
75 Map map = super.toJson(); | 83 Map map = super.toJson(); |
76 map['type'] = 'HttpRequestClient'; | 84 map['type'] = 'HttpRequestClient'; |
77 map['request'] = '$request'; | 85 map['request'] = '$request'; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 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'); |
189 _notifyServerState("", 0); | 197 _notifyServerState("", 0); |
190 return this; | 198 return this; |
191 }); | 199 }); |
192 } | 200 } |
193 | 201 |
194 } | 202 } |
195 | 203 |
196 void _notifyServerState(String ip, int port) | 204 void _notifyServerState(String ip, int port) |
197 native "VMServiceIO_NotifyServerState"; | 205 native "VMServiceIO_NotifyServerState"; |
OLD | NEW |