Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * The web socket protocol is implemented by a HTTP server handler | 6 * The web socket protocol is implemented by a HTTP server handler |
| 7 * which can be instantiated like this: | 7 * which can be instantiated like this: |
| 8 * | 8 * |
| 9 * WebSocketHandler wsHandler = new WebSocketHandler(); | 9 * WebSocketHandler wsHandler = new WebSocketHandler(); |
| 10 * | 10 * |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 send(message); | 134 send(message); |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * Close the web socket connection. The default value for [status] | 137 * Close the web socket connection. The default value for [status] |
| 138 * and [reason] are [:null:]. | 138 * and [reason] are [:null:]. |
| 139 */ | 139 */ |
| 140 close([int status, String reason]); | 140 close([int status, String reason]); |
| 141 } | 141 } |
| 142 | 142 |
| 143 | 143 |
| 144 /** | |
| 145 * Event delivered when there is data on a web socket connection. | |
| 146 */ | |
| 147 interface WebSocketDataEvent default _WebSocketDataEvent { | |
| 148 /** | |
| 149 * The type of [message] is either [:String:] or [:List<int>:] | |
| 150 * depending on whether it is a text or binary message. If the | |
| 151 * message is empty [message] will be [:null:] | |
| 152 */ | |
| 153 get data(); | |
| 154 } | |
| 155 | |
| 156 | |
| 157 /** | |
| 158 * Event delivered when a web socket connection is closed. | |
| 159 */ | |
| 160 interface WebSocketCloseEvent default _WebSocketCloseEvent { | |
| 161 bool get wasClean(); | |
|
Mads Ager (google)
2012/05/07 13:01:35
Document the getters?
Søren Gjesse
2012/05/07 13:59:20
Done.
| |
| 162 int get code(); | |
| 163 String get reason(); | |
| 164 } | |
| 165 | |
| 166 | |
| 167 /** | |
| 168 * Alternative web socket client interface. This interface is compliant | |
| 169 * with the W3C browser API for web sockets specified in | |
| 170 * http://dev.w3.org/html5/websockets/. | |
| 171 */ | |
| 172 interface WebSocket default _WebSocket { | |
| 173 /** | |
| 174 * Possible states of the connection. | |
| 175 */ | |
| 176 static final int CONNECTING = 0; | |
| 177 static final int OPEN = 1; | |
| 178 static final int CLOSING = 2; | |
| 179 static final int CLOSED = 3; | |
| 180 | |
| 181 /** | |
| 182 * Create a new web socket connection. The URL supplied in [url] | |
| 183 * must use the scheme [:ws:]. The [protocols] argument is either a | |
| 184 * [:String:] or [:List<String>:] specifying the subprotocols the | |
|
Mads Ager (google)
2012/05/07 13:01:35
Should we just make this List<String> to simplify
Søren Gjesse
2012/05/07 13:59:20
The constructor defined in http://dev.w3.org/html5
| |
| 185 * client is willing to speak. | |
| 186 */ | |
| 187 WebSocket(String url, [protocols]); | |
| 188 | |
| 189 /** | |
| 190 * Returns the current state of the connection. | |
| 191 */ | |
| 192 int get readyState(); | |
| 193 | |
| 194 /** | |
| 195 * Returns the number of bytes currently buffered for transmission. | |
| 196 */ | |
| 197 int get bufferedAmount(); | |
| 198 | |
| 199 /** | |
| 200 * Sets the callback to be called when a web socket connection has | |
| 201 * been established. | |
| 202 */ | |
| 203 void set onopen(Function callback); | |
| 204 | |
| 205 /** | |
| 206 * Sets the callback to be called when the web socket connection | |
| 207 * encountered an error. | |
| 208 */ | |
| 209 void set onerror(Function callback); | |
| 210 | |
| 211 /** | |
| 212 * Sets the callback to be called when the web socket connection is | |
| 213 * closed. | |
| 214 */ | |
| 215 void set onclose(void callback(WebSocketCloseEvent event)); | |
| 216 | |
| 217 /** | |
| 218 * The extensions property is initially the empty string. After the | |
| 219 * web socket connection is established this string reflects the | |
| 220 * extensions used by the server. | |
| 221 */ | |
| 222 String get extensions(); | |
| 223 | |
| 224 /** | |
| 225 * The protocol property is initially the empty string. After the | |
| 226 * web socket connection is established the value is the subprotocol | |
| 227 * selected by the server. If no subprotocol is negotiated the | |
| 228 * value will remain [:null:]. | |
| 229 */ | |
| 230 String get protocol(); | |
| 231 | |
| 232 /** | |
| 233 * Closes the web socket connection. | |
| 234 */ | |
| 235 void close(int code, String reason); | |
| 236 | |
| 237 /** | |
| 238 * Sets the callback to be called when a message have been | |
| 239 * received. | |
| 240 */ | |
| 241 void set onmessage(void callback(WebSocketDataEvent event)); | |
| 242 | |
| 243 /** | |
| 244 * Sends data on the web socket connection. The data in [data] must | |
| 245 * be either a [:String:] or [:List<int>:] holding bytes. | |
| 246 */ | |
| 247 void send(data); | |
| 248 } | |
| 249 | |
| 250 | |
| 144 class WebSocketException implements Exception { | 251 class WebSocketException implements Exception { |
| 145 const WebSocketException([String this.message = ""]); | 252 const WebSocketException([String this.message = ""]); |
| 146 String toString() => "WebSocketException: $message"; | 253 String toString() => "WebSocketException: $message"; |
| 147 final String message; | 254 final String message; |
| 148 } | 255 } |
| OLD | NEW |