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

Side by Side 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, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/socket_stream_impl.dart ('k') | runtime/bin/websocket_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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,
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 of [message] is either [:String:] or
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));
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 response));
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:] or a
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(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 }
OLDNEW
« 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