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 { | |
|
vsm
2012/05/07 15:16:07
Should this correspond to an HTML MessageEvent?
Søren Gjesse
2012/05/09 07:53:44
Yes it should. Renamed to MessageEvent. It still o
| |
| 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 { | |
|
Jacob
2012/05/07 16:31:51
Is there a reason you don't want to have a base ev
Søren Gjesse
2012/05/09 07:53:44
No - I have added an Event interface.
| |
| 161 /** | |
| 162 * Returns whether the connection was closed cleanly or not. | |
| 163 */ | |
| 164 bool get wasClean(); | |
| 165 | |
| 166 /** | |
| 167 * Returns the web socket connection close code provided by the | |
| 168 * server. | |
| 169 */ | |
| 170 int get code(); | |
| 171 | |
| 172 /** | |
| 173 * Returns the web socket connection close reason provided by the | |
| 174 * server. | |
| 175 */ | |
| 176 String get reason(); | |
| 177 } | |
| 178 | |
| 179 | |
| 180 /** | |
| 181 * Alternative web socket client interface. This interface is compliant | |
| 182 * with the W3C browser API for web sockets specified in | |
| 183 * http://dev.w3.org/html5/websockets/. | |
| 184 */ | |
| 185 interface WebSocket default _WebSocket { | |
| 186 /** | |
| 187 * Possible states of the connection. | |
| 188 */ | |
| 189 static final int CONNECTING = 0; | |
| 190 static final int OPEN = 1; | |
| 191 static final int CLOSING = 2; | |
| 192 static final int CLOSED = 3; | |
| 193 | |
| 194 /** | |
| 195 * Create a new web socket connection. The URL supplied in [url] | |
| 196 * must use the scheme [:ws:]. The [protocols] argument is either a | |
| 197 * [:String:] or [:List<String>:] specifying the subprotocols the | |
| 198 * client is willing to speak. | |
| 199 */ | |
| 200 WebSocket(String url, [protocols]); | |
|
vsm
2012/05/07 15:16:07
Just an fyi - it looks like protocols is now suppo
Søren Gjesse
2012/05/09 07:53:44
OK - I also still have to handle protocols in the
| |
| 201 | |
| 202 /** | |
| 203 * Returns the current state of the connection. | |
| 204 */ | |
| 205 int get readyState(); | |
| 206 | |
| 207 /** | |
| 208 * Returns the number of bytes currently buffered for transmission. | |
| 209 */ | |
| 210 int get bufferedAmount(); | |
| 211 | |
| 212 /** | |
| 213 * Sets the callback to be called when a web socket connection has | |
| 214 * been established. | |
| 215 */ | |
| 216 void set onopen(Function callback); | |
| 217 | |
| 218 /** | |
| 219 * Sets the callback to be called when the web socket connection | |
| 220 * encountered an error. | |
| 221 */ | |
| 222 void set onerror(Function callback); | |
|
Jacob
2012/05/07 16:31:51
can these callbacks have a type?
Søren Gjesse
2012/05/09 07:53:44
Sure, added type.
| |
| 223 | |
| 224 /** | |
| 225 * Sets the callback to be called when the web socket connection is | |
| 226 * closed. | |
| 227 */ | |
| 228 void set onclose(void callback(WebSocketCloseEvent event)); | |
| 229 | |
| 230 /** | |
| 231 * The extensions property is initially the empty string. After the | |
| 232 * web socket connection is established this string reflects the | |
| 233 * extensions used by the server. | |
| 234 */ | |
| 235 String get extensions(); | |
| 236 | |
| 237 /** | |
| 238 * The protocol property is initially the empty string. After the | |
| 239 * web socket connection is established the value is the subprotocol | |
| 240 * selected by the server. If no subprotocol is negotiated the | |
| 241 * value will remain [:null:]. | |
| 242 */ | |
| 243 String get protocol(); | |
| 244 | |
| 245 /** | |
| 246 * Closes the web socket connection. | |
| 247 */ | |
| 248 void close(int code, String reason); | |
| 249 | |
| 250 /** | |
| 251 * Sets the callback to be called when a message have been | |
| 252 * received. | |
| 253 */ | |
| 254 void set onmessage(void callback(WebSocketDataEvent event)); | |
| 255 | |
| 256 /** | |
| 257 * Sends data on the web socket connection. The data in [data] must | |
| 258 * be either a [:String:] or [:List<int>:] holding bytes. | |
| 259 */ | |
| 260 void send(data); | |
| 261 } | |
| 262 | |
| 263 | |
| 144 class WebSocketException implements Exception { | 264 class WebSocketException implements Exception { |
| 145 const WebSocketException([String this.message = ""]); | 265 const WebSocketException([String this.message = ""]); |
| 146 String toString() => "WebSocketException: $message"; | 266 String toString() => "WebSocketException: $message"; |
| 147 final String message; | 267 final String message; |
| 148 } | 268 } |
| OLD | NEW |