File tree Expand file tree Collapse file tree 4 files changed +50
-1
lines changed Expand file tree Collapse file tree 4 files changed +50
-1
lines changed Original file line number Diff line number Diff line change
1
+ ## 0.1.1
2
+
3
+ - Add the ability to create a ` package:web_socket ` ` WebSocket ` given a
4
+ ` dart:io ` ` WebSocket ` .
5
+
1
6
## 0.1.0
2
7
3
8
- Basic functionality in place.
Original file line number Diff line number Diff line change @@ -49,6 +49,10 @@ class IOWebSocket implements WebSocket {
49
49
return IOWebSocket ._(webSocket);
50
50
}
51
51
52
+ // Create an `IOWebSocket` from an existing `dart:io` `WebSocket`.
53
+ factory IOWebSocket .fromWebSocket (io.WebSocket webSocket) =>
54
+ IOWebSocket ._(webSocket);
55
+
52
56
IOWebSocket ._(this ._webSocket) {
53
57
_webSocket.listen (
54
58
(event) {
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ description: >-
3
3
Any easy-to-use library for communicating with WebSockets
4
4
that has multiple implementations.
5
5
repository : https://github.com/dart-lang/http/tree/master/pkgs/web_socket
6
- version : 0.1.0
6
+ version : 0.1.1
7
7
8
8
environment :
9
9
sdk : ^3.3.0
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
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.
4
+
5
+ @TestOn ('vm' )
6
+ library ;
7
+
8
+ import 'dart:io' as io;
9
+
10
+ import 'package:test/test.dart' ;
11
+ import 'package:web_socket/io_web_socket.dart' ;
12
+ import 'package:web_socket/web_socket.dart' ;
13
+
14
+ void main () {
15
+ group ('fromWebSocket' , () {
16
+ late final io.HttpServer server;
17
+ late io.HttpHeaders headers;
18
+ late Uri uri;
19
+
20
+ setUp (() async {
21
+ server = (await io.HttpServer .bind ('localhost' , 0 ))
22
+ ..listen ((request) async {
23
+ headers = request.headers;
24
+ await io.WebSocketTransformer .upgrade (request)
25
+ .then ((webSocket) => webSocket.listen (webSocket.add));
26
+ });
27
+ uri = Uri .parse ('ws://localhost:${server .port }' );
28
+ });
29
+
30
+ test ('custom headers' , () async {
31
+ final ws = IOWebSocket .fromWebSocket (await io.WebSocket .connect (
32
+ uri.toString (),
33
+ headers: {'fruit' : 'apple' }));
34
+ expect (headers['fruit' ], ['apple' ]);
35
+ ws.sendText ('Hello World!' );
36
+ expect (await ws.events.first, TextDataReceived ('Hello World!' ));
37
+ await ws.close ();
38
+ });
39
+ });
40
+ }
You can’t perform that action at this time.
0 commit comments