| 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 * Web socket status codes used when closing a web socket connection. | 8 * Web socket status codes used when closing a web socket connection. |
| 9 */ | 9 */ |
| 10 abstract class WebSocketStatus { | 10 abstract class WebSocketStatus { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return _WebSocketTransformerImpl._isUpgradeRequest(request); | 73 return _WebSocketTransformerImpl._isUpgradeRequest(request); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * A client or server web socket connection. The stream exposes the | 79 * A client or server web socket connection. The stream exposes the |
| 80 * messages received. A text message will be of type [:String:] and a | 80 * messages received. A text message will be of type [:String:] and a |
| 81 * binary message will be of type [:List<int>:]. | 81 * binary message will be of type [:List<int>:]. |
| 82 */ | 82 */ |
| 83 abstract class WebSocket implements Stream { | 83 abstract class WebSocket implements Stream, StreamSink { |
| 84 /** | 84 /** |
| 85 * Possible states of the connection. | 85 * Possible states of the connection. |
| 86 */ | 86 */ |
| 87 static const int CONNECTING = 0; | 87 static const int CONNECTING = 0; |
| 88 static const int OPEN = 1; | 88 static const int OPEN = 1; |
| 89 static const int CLOSING = 2; | 89 static const int CLOSING = 2; |
| 90 static const int CLOSED = 3; | 90 static const int CLOSED = 3; |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * Create a new web socket connection. The URL supplied in [url] | 93 * Create a new web socket connection. The URL supplied in [url] |
| (...skipping 30 matching lines...) Expand all Loading... |
| 124 */ | 124 */ |
| 125 int get closeCode; | 125 int get closeCode; |
| 126 | 126 |
| 127 /** | 127 /** |
| 128 * The close reason set when the web socket connection is closed. If | 128 * The close reason set when the web socket connection is closed. If |
| 129 * there is no close reason available this property will be [:null:] | 129 * there is no close reason available this property will be [:null:] |
| 130 */ | 130 */ |
| 131 String get closeReason; | 131 String get closeReason; |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * Closes the web socket connection. | 134 * Closes the web socket connection. Set the optional [code] and [reason] |
| 135 * arguments to send close information to the remote peer. If they are |
| 136 * omitted, the peer will see [WebSocketStatus.NO_STATUS_RECEIVED] code |
| 137 * with no reason. |
| 135 */ | 138 */ |
| 136 void close([int code, String reason]); | 139 Future close([int code, String reason]); |
| 137 | 140 |
| 138 /** | 141 /** |
| 139 * Sends data on the web socket connection. The data in [data] must | 142 * Sends data on the web socket connection. The data in [data] must |
| 140 * be either a [:String:], or a [:List<int>:] holding bytes. | 143 * be either a [:String:], or a [:List<int>:] holding bytes. |
| 141 */ | 144 */ |
| 142 void send(data); | 145 void add(data); |
| 146 |
| 147 /** |
| 148 * Sends data from a stream on web socket connection. Each data event from |
| 149 * [stream] will be send as a single WebSocket frame. The data from [stream] |
| 150 * must be either [:String:]s, or [:List<int>:]s holding bytes. |
| 151 */ |
| 152 Future addStream(Stream stream); |
| 143 } | 153 } |
| 144 | 154 |
| 145 | 155 |
| 146 class WebSocketException implements Exception { | 156 class WebSocketException implements Exception { |
| 147 const WebSocketException([String this.message = ""]); | 157 const WebSocketException([String this.message = ""]); |
| 148 String toString() => "WebSocketException: $message"; | 158 String toString() => "WebSocketException: $message"; |
| 149 final String message; | 159 final String message; |
| 150 } | 160 } |
| OLD | NEW |