| 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 18 matching lines...) Expand all Loading... |
| 29 * Sets the callback to be called when a new web socket connection | 29 * Sets the callback to be called when a new web socket connection |
| 30 * has been established. | 30 * has been established. |
| 31 */ | 31 */ |
| 32 void set onOpen(callback(WebSocketConnection connection)); | 32 void set onOpen(callback(WebSocketConnection connection)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * Server web socket connection. | 37 * Server web socket connection. |
| 38 */ | 38 */ |
| 39 interface WebSocketConnection { | 39 interface WebSocketConnection extends Hashable { |
| 40 /** | 40 /** |
| 41 * Sets the callback to be called when a message have been | 41 * Sets the callback to be called when a message have been |
| 42 * received. The type on [message] is either [:String:] or | 42 * received. The type on [message] is either [:String:] or |
| 43 * [:List<int>:] depending on whether it is a text or binary | 43 * [:List<int>:] depending on whether it is a text or binary |
| 44 * message. If the message is empty [message] will be [:null:]. | 44 * message. If the message is empty [message] will be [:null:]. |
| 45 */ | 45 */ |
| 46 void set onMessage(void callback(message)); | 46 void set onMessage(void callback(message)); |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Sets the callback to be called when the web socket connection is | 49 * Sets the callback to be called when the web socket connection is |
| (...skipping 11 matching lines...) Expand all Loading... |
| 61 * Sends a message. The [message] must be a [:String:] a | 61 * Sends a message. The [message] must be a [:String:] a |
| 62 * [:List<int>:] or [:null:]. | 62 * [:List<int>:] or [:null:]. |
| 63 */ | 63 */ |
| 64 send(Object message); | 64 send(Object message); |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * Close the web socket connection. The default value for [status] | 67 * Close the web socket connection. The default value for [status] |
| 68 * and [reason] are [:null:]. | 68 * and [reason] are [:null:]. |
| 69 */ | 69 */ |
| 70 close([int status, String reason]); | 70 close([int status, String reason]); |
| 71 |
| 72 /** |
| 73 * WebSocketConnection is hashable. |
| 74 */ |
| 75 int hashCode(); |
| 71 } | 76 } |
| 72 | 77 |
| 73 | 78 |
| 74 /** | 79 /** |
| 75 * Client web socket connection. | 80 * Client web socket connection. |
| 76 */ | 81 */ |
| 77 interface WebSocketClientConnection default _WebSocketClientConnection { | 82 interface WebSocketClientConnection |
| 83 extends Hashable default _WebSocketClientConnection { |
| 78 /** | 84 /** |
| 79 * Creates a new web socket client connection based on a HTTP client | 85 * Creates a new web socket client connection based on a HTTP client |
| 80 * connection. The HTTP client connection must be freshly opened. | 86 * connection. The HTTP client connection must be freshly opened. |
| 81 */ | 87 */ |
| 82 WebSocketClientConnection(HttpClientConnection conn, | 88 WebSocketClientConnection(HttpClientConnection conn, |
| 83 [List<String> protocols]); | 89 [List<String> protocols]); |
| 84 | 90 |
| 85 /** | 91 /** |
| 86 * Sets the callback to be called when the request object for the | 92 * Sets the callback to be called when the request object for the |
| 87 * opening handshake request is ready. This callback can be used if | 93 * opening handshake request is ready. This callback can be used if |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 * [:List<int>:]. To send an empty message use either an empty | 137 * [:List<int>:]. To send an empty message use either an empty |
| 132 * [:String:] or an empty [:List<int>:]. [:null:] cannot be used. | 138 * [:String:] or an empty [:List<int>:]. [:null:] cannot be used. |
| 133 */ | 139 */ |
| 134 send(message); | 140 send(message); |
| 135 | 141 |
| 136 /** | 142 /** |
| 137 * Close the web socket connection. The default value for [status] | 143 * Close the web socket connection. The default value for [status] |
| 138 * and [reason] are [:null:]. | 144 * and [reason] are [:null:]. |
| 139 */ | 145 */ |
| 140 close([int status, String reason]); | 146 close([int status, String reason]); |
| 147 |
| 148 /** |
| 149 * WebSocketClientConnection is hashable. |
| 150 */ |
| 151 int hashCode(); |
| 141 } | 152 } |
| 142 | 153 |
| 143 | 154 |
| 144 /** | 155 /** |
| 145 * Base interface for the events generated by the W3C complient | 156 * Base interface for the events generated by the W3C complient |
| 146 * browser API for web sockets. | 157 * browser API for web sockets. |
| 147 */ | 158 */ |
| 148 interface Event { } | 159 interface Event { } |
| 149 | 160 |
| 150 /** | 161 /** |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 */ | 276 */ |
| 266 void send(data); | 277 void send(data); |
| 267 } | 278 } |
| 268 | 279 |
| 269 | 280 |
| 270 class WebSocketException implements Exception { | 281 class WebSocketException implements Exception { |
| 271 const WebSocketException([String this.message = ""]); | 282 const WebSocketException([String this.message = ""]); |
| 272 String toString() => "WebSocketException: $message"; | 283 String toString() => "WebSocketException: $message"; |
| 273 final String message; | 284 final String message; |
| 274 } | 285 } |
| OLD | NEW |