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 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 /** | 28 /** |
| 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 * Web socket connection. | 37 * Server web socket connection. |
| 38 */ | 38 */ |
| 39 interface WebSocketConnection { | 39 interface WebSocketConnection { |
| 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 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 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 } | 71 } |
| 72 | 72 |
| 73 | 73 |
| 74 /** | |
| 75 * Client web socket connection. | |
| 76 */ | |
| 77 interface WebSocketClientConnection default _WebSocketClientConnection { | |
| 78 /** | |
| 79 * Creates a new web socket client connection based on a HTTP client | |
| 80 * connection. The HTTP client connection must be freshly opened. | |
| 81 */ | |
| 82 WebSocketClientConnection(HttpClientConnection conn, | |
|
Anders Johnsen
2012/05/02 07:51:57
Should we add a convenient constructor that just t
Søren Gjesse
2012/05/02 10:22:45
After having discussed this off-line we will make
| |
| 83 [List<String> protocols]); | |
| 84 | |
| 85 /** | |
| 86 * Sets the callback to be called when the request object for the | |
| 87 * opening handshake request is ready. This callback can be used if | |
| 88 * one need to add additional headers to the opening handshake | |
| 89 * request. | |
| 90 */ | |
| 91 void set onRequest(void callback(HttpClientRequest request)); | |
| 92 | |
| 93 /** | |
| 94 * Sets the callback to be called when a web socket connection has | |
| 95 * been established. | |
| 96 */ | |
| 97 void set onOpen(void callback()); | |
| 98 | |
| 99 /** | |
| 100 * Sets the callback to be called when a message have been | |
| 101 * received. The type on [message] is either [:String:] or | |
|
Mads Ager (google)
2012/05/02 08:18:17
The type on -> The type of
Søren Gjesse
2012/05/02 10:22:45
Done.
| |
| 102 * [:List<int>:] depending on whether it is a text or binary | |
| 103 * message. If the message is empty [message] will be [:null:]. | |
| 104 */ | |
| 105 void set onMessage(void callback(message)); | |
|
Anders Johnsen
2012/05/02 07:51:57
Add 'Object' type to match send.
Søren Gjesse
2012/05/02 10:22:45
Removed Object from send instead.
| |
| 106 | |
| 107 /** | |
| 108 * Sets the callback to be called when the web socket connection is | |
| 109 * closed. | |
| 110 */ | |
| 111 void set onClosed(void callback(int status, String reason)); | |
| 112 | |
| 113 /** | |
| 114 * Sets the callback to be called when the response object for the | |
| 115 * opening handshake did not cause a web socket connection | |
| 116 * upgrade. This will be called in case the response status code is | |
| 117 * not 101 (Switching Protocols). If this callback is not set the | |
| 118 * [:onError:] callback will be called if the server did not upgrade | |
| 119 * the connection. | |
| 120 */ | |
| 121 void set onNoUpgrade(void callback(HttpClientResponse request)); | |
|
Anders Johnsen
2012/05/02 07:51:57
request->response.
Søren Gjesse
2012/05/02 10:22:45
Done.
| |
| 122 | |
| 123 /** | |
| 124 * Sets the callback to be called when the web socket connection | |
| 125 * encountered an error. | |
| 126 */ | |
| 127 void set onError(void callback(e)); | |
| 128 | |
| 129 /** | |
| 130 * Sends a message. The [message] must be a [:String:] a | |
|
Mads Ager (google)
2012/05/02 08:18:17
[:String:] or a
Søren Gjesse
2012/05/02 10:22:45
Done.
| |
| 131 * [:List<int>:]. To send an empty message use either an empty | |
| 132 * [:String:] or an empty [:List<int>:]. [:null:] cannot be used. | |
| 133 */ | |
| 134 send(Object message); | |
| 135 | |
| 136 /** | |
| 137 * Close the web socket connection. The default value for [status] | |
| 138 * and [reason] are [:null:]. | |
| 139 */ | |
| 140 close([int status, String reason]); | |
| 141 } | |
| 142 | |
| 143 | |
| 74 class WebSocketException implements Exception { | 144 class WebSocketException implements Exception { |
| 75 const WebSocketException([String this.message = ""]); | 145 const WebSocketException([String this.message = ""]); |
| 76 String toString() => "WebSocketException: $message"; | 146 String toString() => "WebSocketException: $message"; |
| 77 final String message; | 147 final String message; |
| 78 } | 148 } |
| OLD | NEW |