File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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+
16## 0.1.0
27
38- Basic functionality in place.
Original file line number Diff line number Diff line change @@ -49,6 +49,10 @@ class IOWebSocket implements WebSocket {
4949 return IOWebSocket ._(webSocket);
5050 }
5151
52+ // Create an `IOWebSocket` from an existing `dart:io` `WebSocket`.
53+ factory IOWebSocket .fromWebSocket (io.WebSocket webSocket) =>
54+ IOWebSocket ._(webSocket);
55+
5256 IOWebSocket ._(this ._webSocket) {
5357 _webSocket.listen (
5458 (event) {
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ description: >-
33 Any easy-to-use library for communicating with WebSockets
44 that has multiple implementations.
55repository : https://github.com/dart-lang/http/tree/master/pkgs/web_socket
6- version : 0.1.0
6+ version : 0.1.1
77
88environment :
99 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