Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Unified Diff: runtime/bin/websocket.dart

Issue 10262031: Add a web socket client (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/websocket.dart
diff --git a/runtime/bin/websocket.dart b/runtime/bin/websocket.dart
index f7a36f8fcfde41fe3e50c8a29e0e99ba28968bc9..342078a3992b7fb19743fc214f40b76995cf7590 100644
--- a/runtime/bin/websocket.dart
+++ b/runtime/bin/websocket.dart
@@ -34,7 +34,7 @@ interface WebSocketHandler default _WebSocketHandler {
/**
- * Web socket connection.
+ * Server web socket connection.
*/
interface WebSocketConnection {
/**
@@ -71,6 +71,76 @@ interface WebSocketConnection {
}
+/**
+ * Client web socket connection.
+ */
+interface WebSocketClientConnection default _WebSocketClientConnection {
+ /**
+ * Creates a new web socket client connection based on a HTTP client
+ * connection. The HTTP client connection must be freshly opened.
+ */
+ 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
+ [List<String> protocols]);
+
+ /**
+ * Sets the callback to be called when the request object for the
+ * opening handshake request is ready. This callback can be used if
+ * one need to add additional headers to the opening handshake
+ * request.
+ */
+ void set onRequest(void callback(HttpClientRequest request));
+
+ /**
+ * 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 a message have been
+ * 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.
+ * [:List<int>:] depending on whether it is a text or binary
+ * message. If the message is empty [message] will be [:null:].
+ */
+ 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.
+
+ /**
+ * Sets the callback to be called when the web socket connection is
+ * closed.
+ */
+ void set onClosed(void callback(int status, String reason));
+
+ /**
+ * Sets the callback to be called when the response object for the
+ * opening handshake did not cause a web socket connection
+ * upgrade. This will be called in case the response status code is
+ * not 101 (Switching Protocols). If this callback is not set the
+ * [:onError:] callback will be called if the server did not upgrade
+ * the connection.
+ */
+ 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.
+
+ /**
+ * Sets the callback to be called when the web socket connection
+ * encountered an error.
+ */
+ void set onError(void callback(e));
+
+ /**
+ * 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.
+ * [:List<int>:]. To send an empty message use either an empty
+ * [:String:] or an empty [:List<int>:]. [:null:] cannot be used.
+ */
+ send(Object message);
+
+ /**
+ * Close the web socket connection. The default value for [status]
+ * and [reason] are [:null:].
+ */
+ close([int status, String reason]);
+}
+
+
class WebSocketException implements Exception {
const WebSocketException([String this.message = ""]);
String toString() => "WebSocketException: $message";

Powered by Google App Engine
This is Rietveld 408576698