| 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.web_socket; | 5 library channel.web_socket; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 */ | 83 */ |
| 84 WebSocketServerChannel(this.socket, this.instrumentationService); | 84 WebSocketServerChannel(this.socket, this.instrumentationService); |
| 85 | 85 |
| 86 @override | 86 @override |
| 87 void close() { | 87 void close() { |
| 88 socket.close(WebSocketStatus.NORMAL_CLOSURE); | 88 socket.close(WebSocketStatus.NORMAL_CLOSURE); |
| 89 } | 89 } |
| 90 | 90 |
| 91 @override | 91 @override |
| 92 void listen(void onRequest(Request request), | 92 void listen(void onRequest(Request request), |
| 93 {void onError(), void onDone()}) { | 93 {Function onError, void onDone()}) { |
| 94 socket.listen((data) => readRequest(data, onRequest), | 94 socket.listen((data) => readRequest(data, onRequest), |
| 95 onError: onError, onDone: onDone); | 95 onError: onError, onDone: onDone); |
| 96 } | 96 } |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * Read a request from the given [data] and use the given function to handle | 99 * Read a request from the given [data] and use the given function to handle |
| 100 * the request. | 100 * the request. |
| 101 */ | 101 */ |
| 102 void readRequest(Object data, void onRequest(Request request)) { | 102 void readRequest(Object data, void onRequest(Request request)) { |
| 103 if (data is String) { | 103 if (data is String) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 131 | 131 |
| 132 @override | 132 @override |
| 133 void sendResponse(Response response) { | 133 void sendResponse(Response response) { |
| 134 ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() { | 134 ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() { |
| 135 String jsonEncoding = JSON.encode(response.toJson()); | 135 String jsonEncoding = JSON.encode(response.toJson()); |
| 136 socket.add(jsonEncoding); | 136 socket.add(jsonEncoding); |
| 137 instrumentationService.logResponse(jsonEncoding); | 137 instrumentationService.logResponse(jsonEncoding); |
| 138 }); | 138 }); |
| 139 } | 139 } |
| 140 } | 140 } |
| OLD | NEW |