OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library service_io; |
| 6 |
| 7 import 'dart:io'; |
| 8 |
| 9 import 'package:observatory/service_common.dart'; |
| 10 |
| 11 // Export the service library. |
| 12 export 'package:observatory/service_common.dart'; |
| 13 |
| 14 class _IOWebSocket implements CommonWebSocket { |
| 15 WebSocket _webSocket; |
| 16 |
| 17 void connect(String address, |
| 18 void onOpen(), |
| 19 void onMessage(dynamic data), |
| 20 void onError(), |
| 21 void onClose()) { |
| 22 WebSocket.connect(address).then((WebSocket socket) { |
| 23 _webSocket = socket; |
| 24 _webSocket.listen( |
| 25 onMessage, |
| 26 onError: (dynamic) => onError(), |
| 27 onDone: onClose, |
| 28 cancelOnError: true); |
| 29 onOpen(); |
| 30 }); |
| 31 } |
| 32 |
| 33 bool get isOpen => |
| 34 (_webSocket != null) && (_webSocket.readyState == WebSocket.OPEN); |
| 35 |
| 36 void send(dynamic data) { |
| 37 _webSocket.add(data); |
| 38 } |
| 39 |
| 40 void close() { |
| 41 _webSocket.close(); |
| 42 } |
| 43 } |
| 44 |
| 45 /// The [WebSocketVM] communicates with a Dart VM over WebSocket. The Dart VM |
| 46 /// can be embedded in Chromium or standalone. In the case of Chromium, we |
| 47 /// make the service requests via the Chrome Remote Debugging Protocol. |
| 48 class WebSocketVM extends CommonWebSocketVM { |
| 49 WebSocketVM(WebSocketVMTarget target) : super(target, new _IOWebSocket()); |
| 50 } |
OLD | NEW |