OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 /** | 7 /** |
8 * WebSocket status codes used when closing a WebSocket connection. | 8 * WebSocket status codes used when closing a WebSocket connection. |
9 */ | 9 */ |
10 abstract class WebSocketStatus { | 10 abstract class WebSocketStatus { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 * select what protocol to use, if any were provided by the client. | 205 * select what protocol to use, if any were provided by the client. |
206 * [protocolSelector] is should return either a [String] or a [Future] | 206 * [protocolSelector] is should return either a [String] or a [Future] |
207 * completing with a [String]. The [String] must exist in the list of | 207 * completing with a [String]. The [String] must exist in the list of |
208 * protocols. | 208 * protocols. |
209 * | 209 * |
210 * If [compression] is provided, the [WebSocket] created will be configured | 210 * If [compression] is provided, the [WebSocket] created will be configured |
211 * to negotiate with the specified [CompressionOptions]. If none is specified | 211 * to negotiate with the specified [CompressionOptions]. If none is specified |
212 * then the [WebSocket] will be created with the default [CompressionOptions]. | 212 * then the [WebSocket] will be created with the default [CompressionOptions]. |
213 */ | 213 */ |
214 factory WebSocketTransformer( | 214 factory WebSocketTransformer( |
215 {/*String|Future<String>*/ protocolSelector(List<String> protocols), | 215 {protocolSelector(List<String> protocols), |
216 CompressionOptions compression: CompressionOptions.DEFAULT}) { | 216 CompressionOptions compression: CompressionOptions.DEFAULT}) => |
217 return new _WebSocketTransformerImpl(protocolSelector, compression); | 217 new _WebSocketTransformerImpl(protocolSelector, compression); |
218 } | |
219 | 218 |
220 /** | 219 /** |
221 * Upgrades a [HttpRequest] to a [WebSocket] connection. If the | 220 * Upgrades a [HttpRequest] to a [WebSocket] connection. If the |
222 * request is not a valid WebSocket upgrade request an HTTP response | 221 * request is not a valid WebSocket upgrade request an HTTP response |
223 * with status code 500 will be returned. Otherwise the returned | 222 * with status code 500 will be returned. Otherwise the returned |
224 * future will complete with the [WebSocket] when the upgrade pocess | 223 * future will complete with the [WebSocket] when the upgrade pocess |
225 * is complete. | 224 * is complete. |
226 * | 225 * |
227 * If [protocolSelector] is provided, [protocolSelector] will be called to | 226 * If [protocolSelector] is provided, [protocolSelector] will be called to |
228 * select what protocol to use, if any were provided by the client. | 227 * select what protocol to use, if any were provided by the client. |
(...skipping 17 matching lines...) Expand all Loading... |
246 */ | 245 */ |
247 static bool isUpgradeRequest(HttpRequest request) { | 246 static bool isUpgradeRequest(HttpRequest request) { |
248 return _WebSocketTransformerImpl._isUpgradeRequest(request); | 247 return _WebSocketTransformerImpl._isUpgradeRequest(request); |
249 } | 248 } |
250 } | 249 } |
251 | 250 |
252 /** | 251 /** |
253 * A two-way HTTP communication object for client or server applications. | 252 * A two-way HTTP communication object for client or server applications. |
254 * | 253 * |
255 * The stream exposes the messages received. A text message will be of type | 254 * The stream exposes the messages received. A text message will be of type |
256 * `String` and a binary message will be of type `List<int>`. | 255 * [:String:] and a binary message will be of type [:List<int>:]. |
257 */ | 256 */ |
258 abstract class WebSocket | 257 abstract class WebSocket implements Stream, StreamSink { |
259 implements Stream<dynamic/*String|List<int>*/>, | |
260 StreamSink<dynamic/*String|List<int>*/> { | |
261 /** | 258 /** |
262 * Possible states of the connection. | 259 * Possible states of the connection. |
263 */ | 260 */ |
264 static const int CONNECTING = 0; | 261 static const int CONNECTING = 0; |
265 static const int OPEN = 1; | 262 static const int OPEN = 1; |
266 static const int CLOSING = 2; | 263 static const int CLOSING = 2; |
267 static const int CLOSED = 3; | 264 static const int CLOSED = 3; |
268 | 265 |
269 /** | 266 /** |
270 * Set and get the interval for sending ping signals. If a ping message is not | 267 * Set and get the interval for sending ping signals. If a ping message is not |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 /** | 382 /** |
386 * Closes the WebSocket connection. Set the optional [code] and [reason] | 383 * Closes the WebSocket connection. Set the optional [code] and [reason] |
387 * arguments to send close information to the remote peer. If they are | 384 * arguments to send close information to the remote peer. If they are |
388 * omitted, the peer will see [WebSocketStatus.NO_STATUS_RECEIVED] code | 385 * omitted, the peer will see [WebSocketStatus.NO_STATUS_RECEIVED] code |
389 * with no reason. | 386 * with no reason. |
390 */ | 387 */ |
391 Future close([int code, String reason]); | 388 Future close([int code, String reason]); |
392 | 389 |
393 /** | 390 /** |
394 * Sends data on the WebSocket connection. The data in [data] must | 391 * Sends data on the WebSocket connection. The data in [data] must |
395 * be either a `String`, or a `List<int>` holding bytes. | 392 * be either a [:String:], or a [:List<int>:] holding bytes. |
396 */ | 393 */ |
397 void add(/*String|List<int>*/ data); | 394 void add(data); |
398 | 395 |
399 /** | 396 /** |
400 * Sends data from a stream on WebSocket connection. Each data event from | 397 * Sends data from a stream on WebSocket connection. Each data event from |
401 * [stream] will be send as a single WebSocket frame. The data from [stream] | 398 * [stream] will be send as a single WebSocket frame. The data from [stream] |
402 * must be either `String`s, or `List<int>`s holding bytes. | 399 * must be either [:String:]s, or [:List<int>:]s holding bytes. |
403 */ | 400 */ |
404 Future addStream(Stream stream); | 401 Future addStream(Stream stream); |
405 } | 402 } |
406 | 403 |
407 class WebSocketException implements IOException { | 404 class WebSocketException implements IOException { |
408 final String message; | 405 final String message; |
409 | 406 |
410 const WebSocketException([this.message = ""]); | 407 const WebSocketException([this.message = ""]); |
411 | 408 |
412 String toString() => "WebSocketException: $message"; | 409 String toString() => "WebSocketException: $message"; |
413 } | 410 } |
OLD | NEW |