Skip to content

Commit 5590447

Browse files
authored
Merge pull request #1264 from dart-lang/merge-sse-package
Merge `package:sse`
2 parents a946edf + 456e9aa commit 5590447

File tree

22 files changed

+10048
-0
lines changed

22 files changed

+10048
-0
lines changed

.github/ISSUE_TEMPLATE/sse.md

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

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@
104104
- changed-files:
105105
- any-glob-to-any-file: 'pkgs/source_span/**'
106106

107+
'package:sse':
108+
- changed-files:
109+
- any-glob-to-any-file: 'pkgs/sse/**'
110+
107111
'package:unified_analytics':
108112
- changed-files:
109113
- any-glob-to-any-file: 'pkgs/unified_analytics/**'

.github/workflows/sse.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: package:sse
2+
3+
on:
4+
# Run on PRs and pushes to the default branch.
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- '.github/workflows/sse.yaml'
9+
- 'pkgs/sse/**'
10+
pull_request:
11+
branches: [ main ]
12+
paths:
13+
- '.github/workflows/sse.yaml'
14+
- 'pkgs/sse/**'
15+
schedule:
16+
- cron: "0 0 * * 0"
17+
18+
env:
19+
PUB_ENVIRONMENT: bot.github
20+
21+
22+
defaults:
23+
run:
24+
working-directory: pkgs/sse/
25+
26+
jobs:
27+
# Check code formatting and static analysis on a single OS (linux)
28+
# against Dart dev.
29+
analyze:
30+
runs-on: ubuntu-latest
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
sdk: [dev]
35+
steps:
36+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
37+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
38+
with:
39+
sdk: ${{ matrix.sdk }}
40+
- id: install
41+
name: Install dependencies
42+
run: dart pub get
43+
- name: Check formatting
44+
run: dart format --output=none --set-exit-if-changed .
45+
if: always() && steps.install.outcome == 'success'
46+
- name: Analyze code
47+
run: dart analyze --fatal-infos
48+
if: always() && steps.install.outcome == 'success'
49+
50+
# Run tests on a matrix consisting of two dimensions:
51+
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
52+
# 2. release channel: dev
53+
test:
54+
needs: analyze
55+
runs-on: ${{ matrix.os }}
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
# Add macos-latest and/or windows-latest if relevant for this package.
60+
os: [ubuntu-latest]
61+
sdk: [3.3, dev]
62+
steps:
63+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
64+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
65+
with:
66+
sdk: ${{ matrix.sdk }}
67+
- uses: nanasess/setup-chromedriver@42cc2998329f041de87dc3cfa33a930eacd57eaa
68+
- id: install
69+
name: Install dependencies
70+
run: dart pub get
71+
- name: Run VM tests
72+
run: dart test --platform vm --test-randomize-ordering-seed=random -j 1
73+
if: always() && steps.install.outcome == 'success'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ don't naturally belong to other topic monorepos (like
3939
| [source_map_stack_trace](pkgs/source_map_stack_trace/) | A package for applying source maps to stack traces. | [![package issues](https://img.shields.io/badge/package:source_map_stack_trace-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Asource_map_stack_trace) | [![pub package](https://img.shields.io/pub/v/source_map_stack_trace.svg)](https://pub.dev/packages/source_map_stack_trace) |
4040
| [source_maps](pkgs/source_maps/) | A library to programmatically manipulate source map files. | [![package issues](https://img.shields.io/badge/package:source_maps-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Asource_maps) | [![pub package](https://img.shields.io/pub/v/source_maps.svg)](https://pub.dev/packages/source_maps) |
4141
| [source_span](pkgs/source_span/) | Provides a standard representation for source code locations and spans. | [![package issues](https://img.shields.io/badge/package:source_span-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Asource_span) | [![pub package](https://img.shields.io/pub/v/source_span.svg)](https://pub.dev/packages/source_span) |
42+
| [sse](pkgs/sse/) | Provides client and server functionality for setting up bi-directional communication through Server Sent Events (SSE) and corresponding POST requests. | [![package issues](https://img.shields.io/badge/package:sse-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Asse) | [![pub package](https://img.shields.io/pub/v/sse.svg)](https://pub.dev/packages/sse) |
4243
| [unified_analytics](pkgs/unified_analytics/) | A package for logging analytics for all Dart and Flutter related tooling to Google Analytics. | [![package issues](https://img.shields.io/badge/package:unified_analytics-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aunified_analytics) | [![pub package](https://img.shields.io/pub/v/unified_analytics.svg)](https://pub.dev/packages/unified_analytics) |
4344

4445
## Publishing automation

pkgs/sse/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.dart_tool
2+
pubspec.lock
3+
test/web/index.dart.js.deps

pkgs/sse/AUTHORS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Below is a list of people and organizations that have contributed
2+
# to the Dart project. Names should be added to the list like so:
3+
#
4+
# Name/Organization <email address>
5+
6+
Google Inc.

pkgs/sse/CHANGELOG.md

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
## 4.1.7
2+
3+
- Move to `dart-lang/tools` monorepo.
4+
5+
## 4.1.6
6+
7+
- Require package `web: '>=0.5.0 <2.0.0'`.
8+
9+
## 4.1.5
10+
11+
- Drop unneeded dependency on `package:js`.
12+
- Update the minimum Dart SDK version to `3.3.0`.
13+
- Support the latest `package:web`.
14+
15+
## 4.1.4
16+
17+
- Fix incorrect cast causing failure with `dart2wasm`.
18+
19+
## 4.1.3
20+
21+
- Update the minimum Dart SDK version to `3.2.0`.
22+
23+
## 4.1.2
24+
25+
- Send `fetch` requests instead of `XHR` requests.
26+
- Add an optional `debugKey` parameter to `SseClient` to include in logging.
27+
- Add a dependency on `package:js`.
28+
- Update the minimum Dart SDK version to `2.16.0`.
29+
30+
## 4.1.1
31+
32+
- Apply `keepAlive` logic to `SocketException`s.
33+
- Switch from using `package:pedantic` to `package:lints`
34+
- Rev the minimum required SDK to 2.15.
35+
- Populate the pubspec `repository` field.
36+
37+
## 4.1.0
38+
39+
- Limit the number of concurrent requests to prevent Chrome from automatically
40+
dropping them on the floor.
41+
42+
## 4.0.0
43+
44+
- Support null safety.
45+
46+
## 3.8.3
47+
48+
- Require the latest shelf and remove dead code.
49+
50+
## 3.8.2
51+
52+
- Complete `onConnected` with an error if the `SseClient` receives an error
53+
before the connection is successfully opened.
54+
55+
## 3.8.1
56+
57+
- Fix an issue where closing the `SseConnection` stream would result in an
58+
error.
59+
60+
## 3.8.0
61+
62+
- Add `onConnected` to replace `onOpen`.
63+
- Fix an issue where failed requests would not add a `done` event to the
64+
connection `sink`.
65+
66+
## 3.7.0
67+
68+
- Deprecate the client's `onOpen` getter. Messages will now be buffered until a
69+
connection is established.
70+
71+
## 3.6.1
72+
73+
- Drop dependency on `package:uuid`.
74+
75+
## 3.6.0
76+
77+
- Improve performance by buffering out of order messages in the server instead
78+
of the client.
79+
80+
\*\* Note \*\* This is not modelled as a breaking change as the server can
81+
handle messages from older clients. However, clients should be using the latest
82+
server if they require order guarantees.
83+
84+
## 3.5.0
85+
86+
- Add new `shutdown` methods on `SseHandler` and `SseConnection` to allow
87+
closing connections immediately, ignoring any keep-alive periods.
88+
89+
## 3.4.0
90+
91+
- Remove `onClose` from `SseConnection` and ensure the corresponding
92+
`sink.close` correctly fires.
93+
94+
## 3.3.0
95+
96+
- Add an `onClose` event to the `SseConnection`. This allows consumers to listen
97+
to this event in lue of `sseConnection.sink.done` as that is not guaranteed to
98+
fire.
99+
100+
## 3.2.2
101+
102+
- Fix an issue where `keepAlive` may cause state errors when attempting to send
103+
messages on a closed stream.
104+
105+
## 3.2.1
106+
107+
- Fix an issue where `keepAlive` would only allow a single reconnection.
108+
109+
## 3.2.0
110+
111+
- Re-expose `isInKeepAlivePeriod` flag on `SseConnection`. This flag will be
112+
`true` when a connection has been dropped and is in the keep-alive period
113+
waiting for a client to reconnect.
114+
115+
## 3.1.2
116+
117+
- Fix an issue where the `SseClient` would not send a `done` event when there
118+
was an error with the SSE connection.
119+
120+
## 3.1.1
121+
122+
- Make `isInKeepAlive` on `SseConnection` private.
123+
124+
**Note that this is a breaking change but in actuality no one should be
125+
depending on this API.**
126+
127+
## 3.1.0
128+
129+
- Add optional `keepAlive` parameter to the `SseHandler`. If `keepAlive` is
130+
supplied, the connection will remain active for this period after a disconnect
131+
and can be reconnected transparently. If there is no reconnect within that
132+
period, the connection will be closed normally.
133+
134+
## 3.0.0
135+
136+
- Add retry logic.
137+
138+
**Possible Breaking Change Error messages may now be delayed up to 5 seconds in
139+
the client.**
140+
141+
## 2.1.2
142+
143+
- Remove `package:http` dependency.
144+
145+
## 2.1.1
146+
147+
- Use proper headers delimiter.
148+
149+
## 2.1.0
150+
151+
- Support Firefox.
152+
153+
## 2.0.3
154+
155+
- Fix an issue where messages could come out of order.
156+
157+
## 2.0.2
158+
159+
- Support the latest `package:stream_channel`.
160+
- Require Dart SDK `>=2.1.0 <3.0.0`.
161+
162+
## 2.0.1
163+
164+
- Update to `package:uuid` version 2.0.
165+
166+
## 2.0.0
167+
168+
- No longer expose `close` and `onClose` on an `SseConnection`. This is simply
169+
handled by the underlying `stream` / `sink`.
170+
- Fix a bug where resources of the `SseConnection` were not properly closed.
171+
172+
## 1.0.0
173+
174+
- Internal cleanup.
175+
176+
## 0.0.1
177+
178+
- Initial commit.

pkgs/sse/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2019, 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/sse/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[![Build Status](https://github.com/dart-lang/tools/actions/workflows/sse.yaml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/sse.yaml)
2+
[![pub package](https://img.shields.io/pub/v/sse.svg)](https://pub.dev/packages/sse)
3+
[![package publisher](https://img.shields.io/pub/publisher/sse.svg)](https://pub.dev/packages/sse/publisher)
4+
5+
This package provides support for bi-directional communication through Server
6+
Sent Events and corresponding POST requests.
7+
8+
This package is not intended to be a general purpose SSE package, but instead is
9+
a bidirectional protocol for use when Websockets are unavailable. That is, both
10+
the client and the server expose a `sink` and `stream` on which to send and
11+
receive messages respectively.
12+
13+
Both the server and client have implicit assumptions on each other and therefore
14+
a client from this package must be paired with a server from this package.

pkgs/sse/analysis_options.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# https://dart.dev/guides/language/analysis-options
2+
include: package:dart_flutter_team_lints/analysis_options.yaml
3+
4+
analyzer:
5+
language:
6+
strict-casts: true
7+
8+
linter:
9+
rules:
10+
- avoid_unused_constructor_parameters
11+
- cancel_subscriptions
12+
- literal_only_boolean_expressions
13+
- no_adjacent_strings_in_list

pkgs/sse/example/index.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2019, 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+
import 'package:sse/client/sse_client.dart';
6+
7+
/// A basic example which should be used in a browser that supports SSE.
8+
void main() {
9+
var channel = SseClient('/sseHandler');
10+
11+
channel.stream.listen((s) {
12+
// Listen for messages and send them back.
13+
channel.sink.add(s);
14+
});
15+
}

pkgs/sse/example/server.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2019, 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+
import 'package:shelf/shelf_io.dart' as io;
6+
import 'package:sse/server/sse_handler.dart';
7+
8+
/// A basic server which sets up an SSE handler.
9+
///
10+
/// When a client connects it will send a simple message and print the
11+
/// response.
12+
void main() async {
13+
var handler = SseHandler(Uri.parse('/sseHandler'));
14+
await io.serve(handler.handler, 'localhost', 0);
15+
var connections = handler.connections;
16+
while (await connections.hasNext) {
17+
var connection = await connections.next;
18+
connection.sink.add('foo');
19+
connection.stream.listen(print);
20+
}
21+
}

0 commit comments

Comments
 (0)