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

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: Addressed review comments 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
« no previous file with comments | « runtime/bin/socket_stream_impl.dart ('k') | runtime/bin/websocket_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/websocket.dart
diff --git a/runtime/bin/websocket.dart b/runtime/bin/websocket.dart
index f7a36f8fcfde41fe3e50c8a29e0e99ba28968bc9..cca6747b4ce60edb947764cd99b43ba3015905d9 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,
+ [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 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:].
+ */
+ void set onMessage(void callback(message));
+
+ /**
+ * 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 response));
+
+ /**
+ * 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:] or a
+ * [:List<int>:]. To send an empty message use either an empty
+ * [:String:] or an empty [:List<int>:]. [:null:] cannot be used.
+ */
+ send(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";
« no previous file with comments | « runtime/bin/socket_stream_impl.dart ('k') | runtime/bin/websocket_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698