| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 library service_io; | 5 library service_io; |
| 6 | 6 |
| 7 import 'dart:async'; |
| 7 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:typed_data'; |
| 8 | 10 |
| 9 import 'package:observatory/service_common.dart'; | 11 import 'package:observatory/service_common.dart'; |
| 10 | 12 |
| 11 // Export the service library. | 13 // Export the service library. |
| 12 export 'package:observatory/service_common.dart'; | 14 export 'package:observatory/service_common.dart'; |
| 13 | 15 |
| 14 class _IOWebSocket implements CommonWebSocket { | 16 class _IOWebSocket implements CommonWebSocket { |
| 15 WebSocket _webSocket; | 17 WebSocket _webSocket; |
| 16 | 18 |
| 17 void connect(String address, | 19 void connect(String address, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 33 bool get isOpen => | 35 bool get isOpen => |
| 34 (_webSocket != null) && (_webSocket.readyState == WebSocket.OPEN); | 36 (_webSocket != null) && (_webSocket.readyState == WebSocket.OPEN); |
| 35 | 37 |
| 36 void send(dynamic data) { | 38 void send(dynamic data) { |
| 37 _webSocket.add(data); | 39 _webSocket.add(data); |
| 38 } | 40 } |
| 39 | 41 |
| 40 void close() { | 42 void close() { |
| 41 _webSocket.close(); | 43 _webSocket.close(); |
| 42 } | 44 } |
| 45 |
| 46 Future<ByteData> nonStringToByteData(dynamic data) { |
| 47 assert(data is Uint8List); |
| 48 print('nonString: ${data.lengthInBytes}, $data'); |
| 49 return new Future.sync(() => |
| 50 new ByteData.view(data.buffer, |
| 51 data.offsetInBytes, |
| 52 data.lengthInBytes)); |
| 53 } |
| 43 } | 54 } |
| 44 | 55 |
| 45 /// The [WebSocketVM] communicates with a Dart VM over WebSocket. The Dart VM | 56 /// 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 | 57 /// can be embedded in Chromium or standalone. In the case of Chromium, we |
| 47 /// make the service requests via the Chrome Remote Debugging Protocol. | 58 /// make the service requests via the Chrome Remote Debugging Protocol. |
| 48 class WebSocketVM extends CommonWebSocketVM { | 59 class WebSocketVM extends CommonWebSocketVM { |
| 49 WebSocketVM(WebSocketVMTarget target) : super(target, new _IOWebSocket()); | 60 WebSocketVM(WebSocketVMTarget target) : super(target, new _IOWebSocket()); |
| 50 } | 61 } |
| OLD | NEW |