OLD | NEW |
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 abstract class WebSocket implements Stream, StreamSink { | 102 abstract class WebSocket implements Stream, StreamSink { |
103 /** | 103 /** |
104 * Possible states of the connection. | 104 * Possible states of the connection. |
105 */ | 105 */ |
106 static const int CONNECTING = 0; | 106 static const int CONNECTING = 0; |
107 static const int OPEN = 1; | 107 static const int OPEN = 1; |
108 static const int CLOSING = 2; | 108 static const int CLOSING = 2; |
109 static const int CLOSED = 3; | 109 static const int CLOSED = 3; |
110 | 110 |
111 /** | 111 /** |
| 112 * Set and get the interval for sending ping signals. If a ping message is not |
| 113 * answered by a pong message from the peer, the `WebSocket` is assumed |
| 114 * disconnected and the connection is closed with a |
| 115 * [WebSocketStatus.GOING_AWAY] close code. When a ping signal is sent, the |
| 116 * pong message must be received within [pingInterval]. |
| 117 * |
| 118 * There are never two outstanding pings at any given time, and the next ping |
| 119 * timer starts when the pong is received. |
| 120 * |
| 121 * Set the [pingInterval] to `null` to disable sending ping messages. |
| 122 * |
| 123 * The default value is `null`. |
| 124 */ |
| 125 Duration pingInterval; |
| 126 |
| 127 /** |
112 * Create a new web socket connection. The URL supplied in [url] | 128 * Create a new web socket connection. The URL supplied in [url] |
113 * must use the scheme [:ws:] or [:wss:]. The [protocols] argument is | 129 * must use the scheme [:ws:] or [:wss:]. The [protocols] argument is |
114 * specifying the subprotocols the client is willing to speak. | 130 * specifying the subprotocols the client is willing to speak. |
115 */ | 131 */ |
116 static Future<WebSocket> connect(String url, | 132 static Future<WebSocket> connect(String url, |
117 {List<String> protocols: const []}) => | 133 {List<String> protocols: const []}) => |
118 _WebSocketImpl.connect(url, protocols); | 134 _WebSocketImpl.connect(url, protocols); |
119 | 135 |
120 /** | 136 /** |
121 * Returns the current state of the connection. | 137 * Returns the current state of the connection. |
(...skipping 21 matching lines...) Expand all Loading... |
143 */ | 159 */ |
144 int get closeCode; | 160 int get closeCode; |
145 | 161 |
146 /** | 162 /** |
147 * The close reason set when the web socket connection is closed. If | 163 * The close reason set when the web socket connection is closed. If |
148 * there is no close reason available this property will be [:null:] | 164 * there is no close reason available this property will be [:null:] |
149 */ | 165 */ |
150 String get closeReason; | 166 String get closeReason; |
151 | 167 |
152 /** | 168 /** |
153 * Set and get the interval for sending ping signals. If a ping message is not | |
154 * answered by a pong message from the peer, the `WebSocket` is assumed | |
155 * disconnected and the connection is closed with a | |
156 * [WebSocketStatus.GOING_AWAY] close code. When a ping signal is sent, the | |
157 * pong message must be received within [pingInterval]. | |
158 * | |
159 * There are never two outstanding pings at any given time, and the next ping | |
160 * timer starts when the pong is received. | |
161 * | |
162 * Set the [pingInterval] to `null` to disable sending ping messages. | |
163 * | |
164 * The default value is `null`. | |
165 */ | |
166 Duration pingInterval; | |
167 | |
168 /** | |
169 * Closes the web socket connection. Set the optional [code] and [reason] | 169 * Closes the web socket connection. Set the optional [code] and [reason] |
170 * arguments to send close information to the remote peer. If they are | 170 * arguments to send close information to the remote peer. If they are |
171 * omitted, the peer will see [WebSocketStatus.NO_STATUS_RECEIVED] code | 171 * omitted, the peer will see [WebSocketStatus.NO_STATUS_RECEIVED] code |
172 * with no reason. | 172 * with no reason. |
173 */ | 173 */ |
174 Future close([int code, String reason]); | 174 Future close([int code, String reason]); |
175 | 175 |
176 /** | 176 /** |
177 * Sends data on the web socket connection. The data in [data] must | 177 * Sends data on the web socket connection. The data in [data] must |
178 * be either a [:String:], or a [:List<int>:] holding bytes. | 178 * be either a [:String:], or a [:List<int>:] holding bytes. |
179 */ | 179 */ |
180 void add(data); | 180 void add(data); |
181 | 181 |
182 /** | 182 /** |
183 * Sends data from a stream on web socket connection. Each data event from | 183 * Sends data from a stream on web socket connection. Each data event from |
184 * [stream] will be send as a single WebSocket frame. The data from [stream] | 184 * [stream] will be send as a single WebSocket frame. The data from [stream] |
185 * must be either [:String:]s, or [:List<int>:]s holding bytes. | 185 * must be either [:String:]s, or [:List<int>:]s holding bytes. |
186 */ | 186 */ |
187 Future addStream(Stream stream); | 187 Future addStream(Stream stream); |
188 } | 188 } |
189 | 189 |
190 | 190 |
191 class WebSocketException implements IOException { | 191 class WebSocketException implements IOException { |
192 const WebSocketException([String this.message = ""]); | 192 final String message; |
| 193 const WebSocketException([this.message = ""]); |
193 String toString() => "WebSocketException: $message"; | 194 String toString() => "WebSocketException: $message"; |
194 final String message; | |
195 } | 195 } |
OLD | NEW |