| 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 channel; | 5 library channel; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 */ | 44 */ |
| 45 final WebSocket socket; | 45 final WebSocket socket; |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * Initialize a newly create [WebSocket] wrapper to wrap the given [socket]. | 48 * Initialize a newly create [WebSocket] wrapper to wrap the given [socket]. |
| 49 */ | 49 */ |
| 50 WebSocketChannel(this.socket); | 50 WebSocketChannel(this.socket); |
| 51 | 51 |
| 52 @override | 52 @override |
| 53 void listen(void onRequest(Request request), {void onError(), void onDone()})
{ | 53 void listen(void onRequest(Request request), {void onError(), void onDone()})
{ |
| 54 socket.listen((data) => _readRequest(data, onRequest), onError: onError, onD
one: onDone); | 54 socket.listen((data) => |
| 55 _readRequest(data, onRequest), onError: onError, onDone: onDone); |
| 55 } | 56 } |
| 56 | 57 |
| 57 @override | 58 @override |
| 58 void sendNotification(Notification notification) { | 59 void sendNotification(Notification notification) { |
| 59 JsonEncoder encoder = const JsonEncoder(null); | 60 JsonEncoder encoder = const JsonEncoder(null); |
| 60 socket.add(encoder.convert(notification.toJson())); | 61 socket.add(encoder.convert(notification.toJson())); |
| 61 } | 62 } |
| 62 | 63 |
| 63 @override | 64 @override |
| 64 void sendResponse(Response response) { | 65 void sendResponse(Response response) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 80 // structure as a request. | 81 // structure as a request. |
| 81 Request request = new Request.fromString(data); | 82 Request request = new Request.fromString(data); |
| 82 if (request == null) { | 83 if (request == null) { |
| 83 sendResponse(new Response.invalidRequestFormat()); | 84 sendResponse(new Response.invalidRequestFormat()); |
| 84 return; | 85 return; |
| 85 } | 86 } |
| 86 onRequest(request); | 87 onRequest(request); |
| 87 } | 88 } |
| 88 } | 89 } |
| 89 } | 90 } |
| OLD | NEW |