Chromium Code Reviews| Index: runtime/bin/websocket.dart |
| diff --git a/runtime/bin/websocket.dart b/runtime/bin/websocket.dart |
| index cca6747b4ce60edb947764cd99b43ba3015905d9..93ac92c3010fac8096b4c473c98b15c6f3266910 100644 |
| --- a/runtime/bin/websocket.dart |
| +++ b/runtime/bin/websocket.dart |
| @@ -141,6 +141,132 @@ interface WebSocketClientConnection default _WebSocketClientConnection { |
| } |
| +/** |
| + * Base interface for the events generated by the W3C complient |
| + * browser API for web sockets. |
| + */ |
| +interface Event { } |
|
Jacob
2012/05/09 17:06:43
It would be nice if this event interface could be
|
| + |
| +/** |
| + * Event delivered when there is data on a web socket connection. |
| + */ |
| +interface MessageEvent extends Event default _WebSocketMessageEvent { |
| + /** |
| + * The type of [message] is either [:String:] or [:List<int>:] |
| + * depending on whether it is a text or binary message. If the |
| + * message is empty [message] will be [:null:] |
| + */ |
| + get data(); |
| +} |
| + |
| + |
| +/** |
| + * Event delivered when a web socket connection is closed. |
| + */ |
| +interface CloseEvent extends Event default _WebSocketCloseEvent { |
| + /** |
| + * Returns whether the connection was closed cleanly or not. |
| + */ |
| + bool get wasClean(); |
| + |
| + /** |
| + * Returns the web socket connection close code provided by the |
| + * server. |
| + */ |
| + int get code(); |
| + |
| + /** |
| + * Returns the web socket connection close reason provided by the |
| + * server. |
| + */ |
| + String get reason(); |
| +} |
| + |
| + |
| +/** |
| + * Alternative web socket client interface. This interface is compliant |
| + * with the W3C browser API for web sockets specified in |
| + * http://dev.w3.org/html5/websockets/. |
| + */ |
| +interface WebSocket default _WebSocket { |
| + /** |
| + * Possible states of the connection. |
| + */ |
| + static final int CONNECTING = 0; |
| + static final int OPEN = 1; |
| + static final int CLOSING = 2; |
| + static final int CLOSED = 3; |
| + |
| + /** |
| + * Create a new web socket connection. The URL supplied in [url] |
| + * must use the scheme [:ws:]. The [protocols] argument is either a |
| + * [:String:] or [:List<String>:] specifying the subprotocols the |
| + * client is willing to speak. |
| + */ |
| + WebSocket(String url, [protocols]); |
| + |
| + /** |
| + * Returns the current state of the connection. |
| + */ |
| + int get readyState(); |
| + |
| + /** |
| + * Returns the number of bytes currently buffered for transmission. |
| + */ |
| + int get bufferedAmount(); |
| + |
| + /** |
| + * Sets the callback to be called when a web socket connection has |
| + * been established. |
| + */ |
| + void set onopen(void callback()); |
| + |
| + /** |
| + * Sets the callback to be called when the web socket connection |
| + * encountered an error. |
| + */ |
| + void set onerror(void callback(e)); |
| + |
| + /** |
| + * Sets the callback to be called when the web socket connection is |
| + * closed. |
| + */ |
| + void set onclose(void callback(CloseEvent event)); |
| + |
| + /** |
| + * The extensions property is initially the empty string. After the |
| + * web socket connection is established this string reflects the |
| + * extensions used by the server. |
| + */ |
| + String get extensions(); |
| + |
| + /** |
| + * The protocol property is initially the empty string. After the |
| + * web socket connection is established the value is the subprotocol |
| + * selected by the server. If no subprotocol is negotiated the |
| + * value will remain [:null:]. |
| + */ |
| + String get protocol(); |
| + |
| + /** |
| + * Closes the web socket connection. |
| + */ |
| + void close(int code, String reason); |
| + |
| + /** |
| + * Sets the callback to be called when a message have been |
| + * received. |
| + */ |
| + void set onmessage(void callback(MessageEvent event)); |
| + |
| + /** |
| + * Sends data on the web socket connection. The data in [data] must |
| + * be either a [:String:] or [:List<int>:] holding bytes. |
| + */ |
| + void send(data); |
| +} |
| + |
| + |
| class WebSocketException implements Exception { |
| const WebSocketException([String this.message = ""]); |
| String toString() => "WebSocketException: $message"; |