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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 Future startup() { | 158 Future startup() { |
159 if (_server != null) { | 159 if (_server != null) { |
160 // Already running. | 160 // Already running. |
161 return new Future.value(this); | 161 return new Future.value(this); |
162 } | 162 } |
163 | 163 |
164 // Startup HTTP server. | 164 // Startup HTTP server. |
165 return HttpServer.bind(_ip, _port).then((s) { | 165 return HttpServer.bind(_ip, _port).then((s) { |
166 _server = s; | 166 _server = s; |
167 _server.listen(_requestHandler); | 167 _server.listen(_requestHandler); |
| 168 var ip = _server.address.address.toString(); |
168 if (_displayMessages) { | 169 if (_displayMessages) { |
169 var ip = _server.address.address.toString(); | |
170 var port = _server.port.toString(); | 170 var port = _server.port.toString(); |
171 print('Observatory listening on http://$ip:$port'); | 171 print('Observatory listening on http://$ip:$port'); |
172 } | 172 } |
173 // Server is up and running. | 173 // Server is up and running. |
| 174 _notifyServerState(ip, _server.port); |
174 return this; | 175 return this; |
175 }).catchError((e, st) { | 176 }).catchError((e, st) { |
176 print('Could not start Observatory HTTP server:\n$e\n$st\n'); | 177 print('Could not start Observatory HTTP server:\n$e\n$st\n'); |
| 178 _notifyServerState("", 0); |
177 return this; | 179 return this; |
178 }); | 180 }); |
179 } | 181 } |
180 | 182 |
181 Future shutdown(bool forced) { | 183 Future shutdown(bool forced) { |
182 if (_server == null) { | 184 if (_server == null) { |
183 // Not started. | 185 // Not started. |
184 return new Future.value(this); | 186 return new Future.value(this); |
185 } | 187 } |
186 | 188 |
187 // Force displaying of status messages if we are forcibly shutdown. | 189 // Force displaying of status messages if we are forcibly shutdown. |
188 _displayMessages = _displayMessages || forced; | 190 _displayMessages = _displayMessages || forced; |
189 | 191 |
190 // Shutdown HTTP server and subscription. | 192 // Shutdown HTTP server and subscription. |
191 var ip = _server.address.address.toString(); | 193 var ip = _server.address.address.toString(); |
192 var port = _server.port.toString(); | 194 var port = _server.port.toString(); |
193 return _server.close(force: forced).then((_) { | 195 return _server.close(force: forced).then((_) { |
194 if (_displayMessages) { | 196 if (_displayMessages) { |
195 print('Observatory no longer listening on http://$ip:$port'); | 197 print('Observatory no longer listening on http://$ip:$port'); |
196 } | 198 } |
197 _server = null; | 199 _server = null; |
| 200 _notifyServerState("", 0); |
198 return this; | 201 return this; |
199 }).catchError((e, st) { | 202 }).catchError((e, st) { |
200 _server = null; | 203 _server = null; |
201 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); | 204 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); |
| 205 _notifyServerState("", 0); |
202 return this; | 206 return this; |
203 }); | 207 }); |
204 } | 208 } |
205 | 209 |
206 } | 210 } |
| 211 |
| 212 void _notifyServerState(String ip, int port) |
| 213 native "VMServiceIO_NotifyServerState"; |
OLD | NEW |