| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart_controller_service_isolate; | 5 part of dart_controller_service_isolate; |
| 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 11 matching lines...) Expand all Loading... |
| 22 map = JSON.decode(message); | 22 map = JSON.decode(message); |
| 23 } catch (e) { | 23 } catch (e) { |
| 24 socket.close(PARSE_ERROR_CODE, 'Message parse error: $e'); | 24 socket.close(PARSE_ERROR_CODE, 'Message parse error: $e'); |
| 25 return; | 25 return; |
| 26 } | 26 } |
| 27 if (map is! Map) { | 27 if (map is! Map) { |
| 28 socket.close(NOT_MAP_ERROR_CODE, 'Message must be a JSON map.'); | 28 socket.close(NOT_MAP_ERROR_CODE, 'Message must be a JSON map.'); |
| 29 return; | 29 return; |
| 30 } | 30 } |
| 31 var serial = map['id']; | 31 var serial = map['id']; |
| 32 onMessage(serial, new Message.fromJsonRpc(map)); | 32 onMessage(serial, new Message.fromJsonRpc(this, map)); |
| 33 } else { | 33 } else { |
| 34 socket.close(BINARY_MESSAGE_ERROR_CODE, 'Message must be a string.'); | 34 socket.close(BINARY_MESSAGE_ERROR_CODE, 'Message must be a string.'); |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 | 37 |
| 38 post(dynamic result) { | 38 post(dynamic result) { |
| 39 try { | 39 try { |
| 40 socket.add(result); | 40 socket.add(result); |
| 41 } catch (_) { | 41 } catch (_) { |
| 42 print("Ignoring error posting over WebSocket."); | 42 print("Ignoring error posting over WebSocket."); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 assert(resource != null); | 144 assert(resource != null); |
| 145 } | 145 } |
| 146 if (resource != null) { | 146 if (resource != null) { |
| 147 // Serving up a static resource (e.g. .css, .html, .png). | 147 // Serving up a static resource (e.g. .css, .html, .png). |
| 148 request.response.headers.contentType = | 148 request.response.headers.contentType = |
| 149 ContentType.parse(resource.mimeType); | 149 ContentType.parse(resource.mimeType); |
| 150 request.response.add(resource.data); | 150 request.response.add(resource.data); |
| 151 request.response.close(); | 151 request.response.close(); |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 var message = new Message.fromUri(request.uri); | 154 var message = new Message.fromUri(this, request.uri); |
| 155 var client = new HttpRequestClient(request, _service); | 155 var client = new HttpRequestClient(request, _service); |
| 156 client.onMessage(null, message); | 156 client.onMessage(null, message); |
| 157 } | 157 } |
| 158 | 158 |
| 159 Future startup() { | 159 Future startup() { |
| 160 if (_server != null) { | 160 if (_server != null) { |
| 161 // Already running. | 161 // Already running. |
| 162 return new Future.value(this); | 162 return new Future.value(this); |
| 163 } | 163 } |
| 164 | 164 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); | 216 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); |
| 217 _notifyServerState("", 0); | 217 _notifyServerState("", 0); |
| 218 return this; | 218 return this; |
| 219 }); | 219 }); |
| 220 } | 220 } |
| 221 | 221 |
| 222 } | 222 } |
| 223 | 223 |
| 224 _notifyServerState(String ip, int port) | 224 _notifyServerState(String ip, int port) |
| 225 native "ServiceIsolate_NotifyServerState"; | 225 native "ServiceIsolate_NotifyServerState"; |
| OLD | NEW |