Chromium Code Reviews| Index: runtime/bin/websocket.dart |
| diff --git a/runtime/bin/websocket.dart b/runtime/bin/websocket.dart |
| index cca6747b4ce60edb947764cd99b43ba3015905d9..edaf8289468c6a170a665c60a1cc9ba4712efbfc 100644 |
| --- a/runtime/bin/websocket.dart |
| +++ b/runtime/bin/websocket.dart |
| @@ -141,6 +141,126 @@ interface WebSocketClientConnection default _WebSocketClientConnection { |
| } |
| +/** |
| + * Event delivered when there is data on a web socket connection. |
| + */ |
| +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
|
| + /** |
| + * 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 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.
|
| + /** |
| + * 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]); |
|
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
|
| + |
| + /** |
| + * 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(Function callback); |
| + |
| + /** |
| + * Sets the callback to be called when the web socket connection |
| + * encountered an error. |
| + */ |
| + 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.
|
| + |
| + /** |
| + * Sets the callback to be called when the web socket connection is |
| + * closed. |
| + */ |
| + void set onclose(void callback(WebSocketCloseEvent 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(WebSocketDataEvent 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"; |