OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io'; | |
7 | 6 |
| 7 import 'package:http_parser/http_parser.dart'; |
8 import 'package:shelf/shelf.dart' as shelf; | 8 import 'package:shelf/shelf.dart' as shelf; |
9 import 'package:shelf_web_socket/shelf_web_socket.dart'; | 9 import 'package:shelf_web_socket/shelf_web_socket.dart'; |
10 import 'package:scheduled_test/scheduled_server.dart'; | 10 import 'package:scheduled_test/scheduled_server.dart'; |
11 | 11 |
12 /// A class that schedules a server to serve Dart and/or JS code and receive | 12 /// A class that schedules a server to serve Dart and/or JS code and receive |
13 /// WebSocket connections. | 13 /// WebSocket connections. |
14 /// | 14 /// |
15 /// This uses [ScheduledServer] under the hood, and has similar semantics: its | 15 /// This uses [ScheduledServer] under the hood, and has similar semantics: its |
16 /// `handle*` methods all schedule a handler that must be hit before the | 16 /// `handle*` methods all schedule a handler that must be hit before the |
17 /// schedule will continue. | 17 /// schedule will continue. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 }); | 72 }); |
73 | 73 |
74 _server.handle("GET", "/index.js", (_) { | 74 _server.handle("GET", "/index.js", (_) { |
75 return new shelf.Response.ok(javaScript, | 75 return new shelf.Response.ok(javaScript, |
76 headers: {'content-type': 'application/javascript'}); | 76 headers: {'content-type': 'application/javascript'}); |
77 }); | 77 }); |
78 } | 78 } |
79 | 79 |
80 /// Handles a WebSocket connection to the root of the server, and returns a | 80 /// Handles a WebSocket connection to the root of the server, and returns a |
81 /// future that will complete to the WebSocket. | 81 /// future that will complete to the WebSocket. |
82 Future<WebSocket> handleWebSocket() { | 82 Future<WebSocketChannel> handleWebSocket() { |
83 var completer = new Completer(); | 83 var completer = new Completer(); |
84 _server.handle("GET", "/", webSocketHandler(completer.complete)); | 84 _server.handle("GET", "/", webSocketHandler(completer.complete)); |
85 return completer.future; | 85 return completer.future; |
86 } | 86 } |
87 } | 87 } |
OLD | NEW |