Skip to content

Commit 6d99ff5

Browse files
authored
Merge pull request #1420 from dart-lang/merge-web_socket_channel-package
Merge `package:web_socket_channel`
2 parents 27184eb + 40a83eb commit 6d99ff5

24 files changed

+1893
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: "package:web_socket_channel"
3+
about: "Create a bug or file a feature request against package:web_socket_channel."
4+
labels: "package:web_socket_channel"
5+
---

.github/labeler.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
- changed-files:
3333
- any-glob-to-any-file: 'pkgs/http_parser/**'
3434

35+
'package:web_socket_channel':
36+
- changed-files:
37+
- any-glob-to-any-file: 'pkgs/web_socket_channel/**'
38+
3539
'package:web_socket_conformance_tests':
3640
- changed-files:
37-
- any-glob-to-any-file: 'pkgs/web_socket_conformance_tests/**'
41+
- any-glob-to-any-file: 'pkgs/http_client_conformance_tests/**'
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: package:web_socket_channel
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- '.github/workflows/web_socket_channel.yaml'
9+
- 'pkgs/web_socket_channel/**'
10+
pull_request:
11+
paths:
12+
- '.github/workflows/web_socket_channel.yaml'
13+
- 'pkgs/web_socket_channel/**'
14+
schedule:
15+
- cron: "0 0 * * 0"
16+
17+
defaults:
18+
run:
19+
working-directory: pkgs/web_socket_channel/
20+
21+
env:
22+
PUB_ENVIRONMENT: bot.github
23+
24+
jobs:
25+
# Check code formatting and static analysis on a single OS (linux)
26+
# against Dart dev.
27+
analyze:
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
sdk: [dev]
32+
steps:
33+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
34+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
35+
with:
36+
sdk: ${{ matrix.sdk }}
37+
- id: install
38+
name: Install dependencies
39+
run: dart pub get
40+
- name: Check formatting
41+
run: dart format --output=none --set-exit-if-changed .
42+
if: always() && steps.install.outcome == 'success'
43+
- name: Analyze code
44+
run: dart analyze
45+
if: always() && steps.install.outcome == 'success'
46+
47+
test:
48+
needs: analyze
49+
runs-on: ${{ matrix.os }}
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
os: [ubuntu-latest]
54+
sdk: [3.3, dev]
55+
steps:
56+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
57+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
58+
with:
59+
sdk: ${{ matrix.sdk }}
60+
- id: install
61+
name: Install dependencies
62+
run: dart pub get
63+
- name: Run VM tests
64+
run: dart test --platform vm
65+
if: always() && steps.install.outcome == 'success'
66+
- name: Run Chrome tests
67+
run: dart test --platform chrome
68+
if: always() && steps.install.outcome == 'success'
69+
- name: Run Chrome tests - wasm
70+
run: dart test --platform chrome --compiler dart2wasm
71+
if: always() && steps.install.outcome == 'success' && matrix.sdk == 'dev'
72+
73+
# Run analysis against the oldest supported pub constraints.
74+
downgrade:
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
78+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
79+
- run: dart pub downgrade
80+
- run: dart analyze

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and the browser.
2121
| [http_profile](pkgs/http_profile/) | A library used by HTTP client authors to integrate with the DevTools Network View. | [![pub package](https://img.shields.io/pub/v/http_profile.svg)](https://pub.dev/packages/http_profile) |
2222
| [ok_http](pkgs/ok_http/) | An Android Flutter plugin that provides access to the [OkHttp](https://square.github.io/okhttp/) HTTP client and the OkHttp [WebSocket](https://square.github.io/okhttp/5.x/okhttp/okhttp3/-web-socket/index.html) API. | [![pub package](https://img.shields.io/pub/v/ok_http.svg)](https://pub.dev/packages/ok_http) |
2323
| [web_socket](pkgs/web_socket/) | Any easy-to-use library for communicating with WebSockets that has multiple implementations. | [![pub package](https://img.shields.io/pub/v/web_socket.svg)](https://pub.dev/packages/web_socket) |
24+
| [web_socket_channel](pkgs/web_socket_channel/) | StreamChannel wrappers for WebSockets. Provides a cross-platform WebSocketChannel API. | [![package issues](https://img.shields.io/badge/package:web_socket_channel-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aweb_socket_channel) | [![pub package](https://img.shields.io/pub/v/web_socket_channel.svg)](https://pub.dev/packages/web_socket_channel) |
2425
| [web_socket_conformance_tests](pkgs/web_socket_conformance_tests/) | A library that tests whether implementations of `package:web_socket`'s `WebSocket` class behave as expected. | |
2526

2627
## Contributing

pkgs/web_socket_channel/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.dart_tool/
2+
.packages
3+
pubspec.lock

pkgs/web_socket_channel/CHANGELOG.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
## 3.0.2
2+
3+
- Move to `dart-lang/http` monorepo.
4+
5+
## 3.0.1
6+
7+
- Remove unnecessary `dependency_overrides`.
8+
- Remove obsolete documentation for `WebSocketChannel.new`.
9+
- Update package `web: '>=0.5.0 <2.0.0'`.
10+
11+
## 3.0.0
12+
13+
- Provide an adapter around `package:web_socket` `WebSocket`s and make it the
14+
default implementation for `WebSocketChannel.connect`.
15+
- **BREAKING**: Remove `WebSocketChannel` constructor.
16+
- **BREAKING**: Make `WebSocketChannel` an `abstract interface`.
17+
- **BREAKING**: `IOWebSocketChannel.ready` will throw
18+
`WebSocketChannelException` instead of `WebSocketException`.
19+
20+
## 2.4.5
21+
22+
- use secure random number generator for frame masking.
23+
24+
## 2.4.4
25+
26+
- Require Dart `^3.3`
27+
- Require `package:web` `^0.5.0`.
28+
29+
## 2.4.3
30+
31+
- `HtmlWebSocketChannel`: Relax the type of the websocket parameter to the
32+
constructor in order to mitigate a breaking change introduced in `2.4.1`.
33+
34+
## 2.4.2 (retracted)
35+
36+
- Allow `web: '>=0.3.0 <0.5.0'`
37+
38+
## 2.4.1
39+
40+
- Update the examples to use `WebSocketChannel.ready` and clarify that
41+
`WebSocketChannel.ready` should be awaited before sending data over the
42+
`WebSocketChannel`.
43+
- Mention `ready` in the docs for `connect`.
44+
- Bump minimum Dart version to 3.2.0
45+
- Move to `pkg:web` to support WebAssembly compilation.
46+
47+
## 2.4.0
48+
49+
- Add a `customClient` parameter to the `IOWebSocketChannel.connect` factory,
50+
which allows the user to provide a custom `HttpClient` instance to use for the
51+
WebSocket connection
52+
- Bump minimum Dart version to 2.15.0
53+
54+
## 2.3.0
55+
56+
- Added a Future `ready` property to `WebSocketChannel`, which completes when
57+
the connection is established
58+
- Added a `connectTimeout` parameter to the `IOWebSocketChannel.connect` factory,
59+
which controls the timeout of the WebSocket Future.
60+
- Use platform agnostic code in README example.
61+
62+
## 2.2.0
63+
64+
- Add `HtmlWebSocketChannel.innerWebSocket` getter to access features not exposed
65+
through the shared `WebSocketChannel` interface.
66+
67+
## 2.1.0
68+
69+
- Add `IOWebSocketChannel.innerWebSocket` getter to access features not exposed
70+
through the shared `WebSocketChannel` interface.
71+
72+
## 2.0.0
73+
74+
- Support null safety.
75+
- Require Dart 2.12.
76+
77+
## 1.2.0
78+
79+
* Add `protocols` argument to `WebSocketChannel.connect`. See the docs for
80+
`WebSocket.connet`.
81+
* Allow the latest crypto release (`3.x`).
82+
83+
## 1.1.0
84+
85+
* Add `WebSocketChannel.connect` factory constructor supporting platform
86+
independent creation of WebSockets providing the lowest common denominator
87+
of support on dart:io and dart:html.
88+
89+
## 1.0.15
90+
91+
* bug fix don't pass protocols parameter to WebSocket.
92+
93+
## 1.0.14
94+
95+
* Updates to handle `Socket implements Stream<Uint8List>`
96+
97+
## 1.0.13
98+
99+
* Internal changes for consistency with the Dart SDK.
100+
101+
## 1.0.12
102+
103+
* Allow `stream_channel` version 2.x
104+
105+
## 1.0.11
106+
107+
* Fixed description in pubspec.
108+
109+
* Fixed lints in README.md.
110+
111+
## 1.0.10
112+
113+
* Fixed links in README.md.
114+
115+
* Added an example.
116+
117+
* Fixed analysis lints that affected package score.
118+
119+
## 1.0.9
120+
121+
* Set max SDK version to `<3.0.0`.
122+
123+
## 1.0.8
124+
125+
* Remove use of deprecated constant name.
126+
127+
## 1.0.7
128+
129+
* Support the latest dev SDK.
130+
131+
## 1.0.6
132+
133+
* Declare support for `async` 2.0.0.
134+
135+
## 1.0.5
136+
137+
* Increase the SDK version constraint to `<2.0.0-dev.infinity`.
138+
139+
## 1.0.4
140+
141+
* Support `crypto` 2.0.0.
142+
143+
## 1.0.3
144+
145+
* Fix all strong-mode errors and warnings.
146+
147+
* Fix a bug where `HtmlWebSocketChannel.close()` would crash on non-Dartium
148+
browsers if the close code and reason weren't provided explicitly.
149+
150+
## 1.0.2
151+
152+
* Properly use `BASE64` from `dart:convert` rather than `crypto`.
153+
154+
## 1.0.1
155+
156+
* Add support for `crypto` 1.0.0.
157+
158+
## 1.0.0
159+
160+
* Initial version

pkgs/web_socket_channel/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2016, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/web_socket_channel/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[![pub package](https://img.shields.io/pub/v/web_socket_channel.svg)](https://pub.dev/packages/web_socket_channel)
2+
[![package publisher](https://img.shields.io/pub/publisher/web_socket_channel.svg)](https://pub.dev/packages/web_socket_channel/publisher)
3+
4+
`package:web_socket_channel` provides cross-platform
5+
[`StreamChannel`][stream_channel] wrappers for WebSocket connections.
6+
7+
## Docs and Usage
8+
9+
It provides a cross-platform
10+
[`WebSocketChannel`][WebSocketChannel] API, a cross-platform implementation of
11+
that API that communicates over an underlying [`StreamChannel`][stream_channel],
12+
[an implementation][IOWebSocketChannel] that wraps `dart:io`'s `WebSocket`
13+
class, and [a similar implementation][HtmlWebSocketChannel] that wraps
14+
`dart:html`'s.
15+
16+
[stream_channel]: https://pub.dev/packages/stream_channel
17+
[WebSocketChannel]: https://pub.dev/documentation/web_socket_channel/latest/web_socket_channel/WebSocketChannel-class.html
18+
[IOWebSocketChannel]: https://pub.dev/documentation/web_socket_channel/latest/web_socket_channel.io/IOWebSocketChannel-class.html
19+
[HtmlWebSocketChannel]: https://pub.dev/documentation/web_socket_channel/latest/web_socket_channel.html/HtmlWebSocketChannel-class.html
20+
21+
It also provides constants for the WebSocket protocol's pre-defined status codes
22+
in the [`status.dart` library][status]. It's strongly recommended that users
23+
import this library with the prefix `status`.
24+
25+
[status]: https://pub.dev/documentation/web_socket_channel/latest/status/status-library.html
26+
27+
```dart
28+
import 'package:web_socket_channel/web_socket_channel.dart';
29+
import 'package:web_socket_channel/status.dart' as status;
30+
31+
main() async {
32+
final wsUrl = Uri.parse('ws://example.com');
33+
final channel = WebSocketChannel.connect(wsUrl);
34+
35+
await channel.ready;
36+
37+
channel.stream.listen((message) {
38+
channel.sink.add('received!');
39+
channel.sink.close(status.goingAway);
40+
});
41+
}
42+
```
43+
44+
## `WebSocketChannel`
45+
46+
The [`WebSocketChannel`][WebSocketChannel] class's most important role is as the
47+
interface for WebSocket stream channels across all implementations and all
48+
platforms. In addition to the base `StreamChannel` interface, it adds a
49+
[`protocol`][protocol] getter that returns the negotiated protocol for the
50+
socket, as well as [`closeCode`][closeCode] and [`closeReason`][closeReason]
51+
getters that provide information about why the socket closed.
52+
53+
[protocol]: https://pub.dev/documentation/web_socket_channel/latest/web_socket_channel/WebSocketChannel/protocol.html
54+
[closeCode]: https://pub.dev/documentation/web_socket_channel/latest/web_socket_channel/WebSocketChannel/closeCode.html
55+
[closeReason]: https://pub.dev/documentation/web_socket_channel/latest/web_socket_channel/WebSocketChannel/closeReason.html
56+
57+
The channel's [`sink` property][sink] is also special. It returns a
58+
[`WebSocketSink`][WebSocketSink], which is just like a `StreamSink` except that
59+
its [`close()`][sink.close] method supports optional `closeCode` and
60+
`closeReason` parameters. These parameters allow the caller to signal to the
61+
other socket exactly why they're closing the connection.
62+
63+
[sink]: https://pub.dev/documentation/web_socket_channel/latest/web_socket_channel/WebSocketChannel/sink.html
64+
[WebSocketSink]: https://pub.dev/documentation/web_socket_channel/latest/web_socket_channel/WebSocketSink-class.html
65+
[sink.close]: https://pub.dev/documentation/web_socket_channel/latest/web_socket_channel/WebSocketSink/close.html
66+
67+
`WebSocketChannel` also works as a cross-platform implementation of the
68+
WebSocket protocol. The [`WebSocketChannel.connect` constructor][connect]
69+
connects to a listening server using the appropriate implementation for the
70+
platform.
71+
72+
[connect]: https://pub.dev/documentation/web_socket_channel/latest/web_socket_channel/WebSocketChannel/WebSocketChannel.connect.html

0 commit comments

Comments
 (0)