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

Side by Side Diff: sdk/lib/io/websocket.dart

Issue 91223002: Add support for Websocket protocols. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart.io; 5 part of dart.io;
6 6
7 /** 7 /**
8 * Web socket status codes used when closing a web socket connection. 8 * Web socket status codes used when closing a web socket connection.
9 */ 9 */
10 abstract class WebSocketStatus { 10 abstract class WebSocketStatus {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 * stream transformer that transforms a stream of HttpRequest into a 46 * stream transformer that transforms a stream of HttpRequest into a
47 * stream of WebSockets by upgrading each HttpRequest from the HTTP or 47 * stream of WebSockets by upgrading each HttpRequest from the HTTP or
48 * HTTPS server, to the WebSocket protocol. 48 * HTTPS server, to the WebSocket protocol.
49 * 49 *
50 * server.transform(new WebSocketTransformer()).listen((webSocket) => ...); 50 * server.transform(new WebSocketTransformer()).listen((webSocket) => ...);
51 * 51 *
52 * This transformer strives to implement web sockets as specified by RFC6455. 52 * This transformer strives to implement web sockets as specified by RFC6455.
53 */ 53 */
54 abstract class WebSocketTransformer 54 abstract class WebSocketTransformer
55 implements StreamTransformer<HttpRequest, WebSocket> { 55 implements StreamTransformer<HttpRequest, WebSocket> {
56 factory WebSocketTransformer() => new _WebSocketTransformerImpl(); 56
57 factory WebSocketTransformer({protocolSelector(List<String> protocols)})
58 => new _WebSocketTransformerImpl(protocolSelector);
57 59
58 /** 60 /**
59 * Upgrades a [HttpRequest] to a [WebSocket] connection. If the 61 * Upgrades a [HttpRequest] to a [WebSocket] connection. If the
60 * request is not a valid web socket upgrade request a HTTP response 62 * request is not a valid web socket upgrade request a HTTP response
61 * with status code 500 will be returned. Otherwise the returned 63 * with status code 500 will be returned. Otherwise the returned
62 * future will complete with the [WebSocket] when the upgrade pocess 64 * future will complete with the [WebSocket] when the upgrade pocess
63 * is complete. 65 * is complete.
64 */ 66 */
65 static Future<WebSocket> upgrade(HttpRequest request) { 67 static Future<WebSocket> upgrade(HttpRequest request,
66 return _WebSocketTransformerImpl._upgrade(request); 68 {protocolSelector(List<String> protocols)}) {
69 return _WebSocketTransformerImpl._upgrade(request, protocolSelector);
67 } 70 }
68 71
69 /** 72 /**
70 * Checks whether the request is a valid WebSocket upgrade request. 73 * Checks whether the request is a valid WebSocket upgrade request.
71 */ 74 */
72 static bool isUpgradeRequest(HttpRequest request) { 75 static bool isUpgradeRequest(HttpRequest request) {
73 return _WebSocketTransformerImpl._isUpgradeRequest(request); 76 return _WebSocketTransformerImpl._isUpgradeRequest(request);
74 } 77 }
75 } 78 }
76 79
77 80
78 /** 81 /**
79 * A two-way HTTP communication object for client or server applications. 82 * A two-way HTTP communication object for client or server applications.
80 * 83 *
81 * The stream exposes the messages received. A text message will be of type 84 * The stream exposes the messages received. A text message will be of type
82 * [:String:] and a binary message will be of type [:List<int>:]. 85 * [:String:] and a binary message will be of type [:List<int>:].
83 */ 86 */
84 abstract class WebSocket implements Stream, StreamSink { 87 abstract class WebSocket implements Stream, StreamSink {
85 /** 88 /**
86 * Possible states of the connection. 89 * Possible states of the connection.
87 */ 90 */
88 static const int CONNECTING = 0; 91 static const int CONNECTING = 0;
89 static const int OPEN = 1; 92 static const int OPEN = 1;
90 static const int CLOSING = 2; 93 static const int CLOSING = 2;
91 static const int CLOSED = 3; 94 static const int CLOSED = 3;
92 95
93 /** 96 /**
94 * Create a new web socket connection. The URL supplied in [url] 97 * Create a new web socket connection. The URL supplied in [url]
95 * must use the scheme [:ws:] or [:wss:]. The [protocols] argument is either 98 * must use the scheme [:ws:] or [:wss:]. The [protocols] argument is
96 * a [:String:] or [:List<String>:] specifying the subprotocols the 99 * specifying the subprotocols the client is willing to speak.
97 * client is willing to speak.
98 */ 100 */
99 static Future<WebSocket> connect(String url, [protocols]) => 101 static Future<WebSocket> connect(String url,
102 {List<String> protocols: const []}) =>
100 _WebSocketImpl.connect(url, protocols); 103 _WebSocketImpl.connect(url, protocols);
101 104
102 /** 105 /**
103 * Returns the current state of the connection. 106 * Returns the current state of the connection.
104 */ 107 */
105 int get readyState; 108 int get readyState;
106 109
107 /** 110 /**
108 * The extensions property is initially the empty string. After the 111 * The extensions property is initially the empty string. After the
109 * web socket connection is established this string reflects the 112 * web socket connection is established this string reflects the
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 */ 171 */
169 Future addStream(Stream stream); 172 Future addStream(Stream stream);
170 } 173 }
171 174
172 175
173 class WebSocketException implements IOException { 176 class WebSocketException implements IOException {
174 const WebSocketException([String this.message = ""]); 177 const WebSocketException([String this.message = ""]);
175 String toString() => "WebSocketException: $message"; 178 String toString() => "WebSocketException: $message";
176 final String message; 179 final String message;
177 } 180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698