Skip to content

Commit

Permalink
Merge pull request #1264 from dart-lang/merge-sse-package
Browse files Browse the repository at this point in the history
Merge `package:sse`
  • Loading branch information
mosuem authored Dec 11, 2024
2 parents a946edf + 456e9aa commit 5590447
Show file tree
Hide file tree
Showing 22 changed files with 10,048 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/sse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: "package:sse"
about: "Create a bug or file a feature request against package:sse."
labels: "package:sse"
---
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
- changed-files:
- any-glob-to-any-file: 'pkgs/source_span/**'

'package:sse':
- changed-files:
- any-glob-to-any-file: 'pkgs/sse/**'

'package:unified_analytics':
- changed-files:
- any-glob-to-any-file: 'pkgs/unified_analytics/**'
73 changes: 73 additions & 0 deletions .github/workflows/sse.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: package:sse

on:
# Run on PRs and pushes to the default branch.
push:
branches: [ main ]
paths:
- '.github/workflows/sse.yaml'
- 'pkgs/sse/**'
pull_request:
branches: [ main ]
paths:
- '.github/workflows/sse.yaml'
- 'pkgs/sse/**'
schedule:
- cron: "0 0 * * 0"

env:
PUB_ENVIRONMENT: bot.github


defaults:
run:
working-directory: pkgs/sse/

jobs:
# Check code formatting and static analysis on a single OS (linux)
# against Dart dev.
analyze:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

# Run tests on a matrix consisting of two dimensions:
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
# 2. release channel: dev
test:
needs: analyze
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [3.3, dev]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- uses: nanasess/setup-chromedriver@42cc2998329f041de87dc3cfa33a930eacd57eaa
- id: install
name: Install dependencies
run: dart pub get
- name: Run VM tests
run: dart test --platform vm --test-randomize-ordering-seed=random -j 1
if: always() && steps.install.outcome == 'success'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ don't naturally belong to other topic monorepos (like
| [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) |
| [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) |
| [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) |
| [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) |
| [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) |

## Publishing automation
Expand Down
3 changes: 3 additions & 0 deletions pkgs/sse/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.dart_tool
pubspec.lock
test/web/index.dart.js.deps
6 changes: 6 additions & 0 deletions pkgs/sse/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Below is a list of people and organizations that have contributed
# to the Dart project. Names should be added to the list like so:
#
# Name/Organization <email address>

Google Inc.
178 changes: 178 additions & 0 deletions pkgs/sse/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
## 4.1.7

- Move to `dart-lang/tools` monorepo.

## 4.1.6

- Require package `web: '>=0.5.0 <2.0.0'`.

## 4.1.5

- Drop unneeded dependency on `package:js`.
- Update the minimum Dart SDK version to `3.3.0`.
- Support the latest `package:web`.

## 4.1.4

- Fix incorrect cast causing failure with `dart2wasm`.

## 4.1.3

- Update the minimum Dart SDK version to `3.2.0`.

## 4.1.2

- Send `fetch` requests instead of `XHR` requests.
- Add an optional `debugKey` parameter to `SseClient` to include in logging.
- Add a dependency on `package:js`.
- Update the minimum Dart SDK version to `2.16.0`.

## 4.1.1

- Apply `keepAlive` logic to `SocketException`s.
- Switch from using `package:pedantic` to `package:lints`
- Rev the minimum required SDK to 2.15.
- Populate the pubspec `repository` field.

## 4.1.0

- Limit the number of concurrent requests to prevent Chrome from automatically
dropping them on the floor.

## 4.0.0

- Support null safety.

## 3.8.3

- Require the latest shelf and remove dead code.

## 3.8.2

- Complete `onConnected` with an error if the `SseClient` receives an error
before the connection is successfully opened.

## 3.8.1

- Fix an issue where closing the `SseConnection` stream would result in an
error.

## 3.8.0

- Add `onConnected` to replace `onOpen`.
- Fix an issue where failed requests would not add a `done` event to the
connection `sink`.

## 3.7.0

- Deprecate the client's `onOpen` getter. Messages will now be buffered until a
connection is established.

## 3.6.1

- Drop dependency on `package:uuid`.

## 3.6.0

- Improve performance by buffering out of order messages in the server instead
of the client.

\*\* Note \*\* This is not modelled as a breaking change as the server can
handle messages from older clients. However, clients should be using the latest
server if they require order guarantees.

## 3.5.0

- Add new `shutdown` methods on `SseHandler` and `SseConnection` to allow
closing connections immediately, ignoring any keep-alive periods.

## 3.4.0

- Remove `onClose` from `SseConnection` and ensure the corresponding
`sink.close` correctly fires.

## 3.3.0

- Add an `onClose` event to the `SseConnection`. This allows consumers to listen
to this event in lue of `sseConnection.sink.done` as that is not guaranteed to
fire.

## 3.2.2

- Fix an issue where `keepAlive` may cause state errors when attempting to send
messages on a closed stream.

## 3.2.1

- Fix an issue where `keepAlive` would only allow a single reconnection.

## 3.2.0

- Re-expose `isInKeepAlivePeriod` flag on `SseConnection`. This flag will be
`true` when a connection has been dropped and is in the keep-alive period
waiting for a client to reconnect.

## 3.1.2

- Fix an issue where the `SseClient` would not send a `done` event when there
was an error with the SSE connection.

## 3.1.1

- Make `isInKeepAlive` on `SseConnection` private.

**Note that this is a breaking change but in actuality no one should be
depending on this API.**

## 3.1.0

- Add optional `keepAlive` parameter to the `SseHandler`. If `keepAlive` is
supplied, the connection will remain active for this period after a disconnect
and can be reconnected transparently. If there is no reconnect within that
period, the connection will be closed normally.

## 3.0.0

- Add retry logic.

**Possible Breaking Change Error messages may now be delayed up to 5 seconds in
the client.**

## 2.1.2

- Remove `package:http` dependency.

## 2.1.1

- Use proper headers delimiter.

## 2.1.0

- Support Firefox.

## 2.0.3

- Fix an issue where messages could come out of order.

## 2.0.2

- Support the latest `package:stream_channel`.
- Require Dart SDK `>=2.1.0 <3.0.0`.

## 2.0.1

- Update to `package:uuid` version 2.0.

## 2.0.0

- No longer expose `close` and `onClose` on an `SseConnection`. This is simply
handled by the underlying `stream` / `sink`.
- Fix a bug where resources of the `SseConnection` were not properly closed.

## 1.0.0

- Internal cleanup.

## 0.0.1

- Initial commit.
27 changes: 27 additions & 0 deletions pkgs/sse/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2019, the Dart project authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 changes: 14 additions & 0 deletions pkgs/sse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[![Build Status](https://github.com/dart-lang/tools/actions/workflows/sse.yaml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/sse.yaml)
[![pub package](https://img.shields.io/pub/v/sse.svg)](https://pub.dev/packages/sse)
[![package publisher](https://img.shields.io/pub/publisher/sse.svg)](https://pub.dev/packages/sse/publisher)

This package provides support for bi-directional communication through Server
Sent Events and corresponding POST requests.

This package is not intended to be a general purpose SSE package, but instead is
a bidirectional protocol for use when Websockets are unavailable. That is, both
the client and the server expose a `sink` and `stream` on which to send and
receive messages respectively.

Both the server and client have implicit assumptions on each other and therefore
a client from this package must be paired with a server from this package.
13 changes: 13 additions & 0 deletions pkgs/sse/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://dart.dev/guides/language/analysis-options
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true

linter:
rules:
- avoid_unused_constructor_parameters
- cancel_subscriptions
- literal_only_boolean_expressions
- no_adjacent_strings_in_list
15 changes: 15 additions & 0 deletions pkgs/sse/example/index.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:sse/client/sse_client.dart';

/// A basic example which should be used in a browser that supports SSE.
void main() {
var channel = SseClient('/sseHandler');

channel.stream.listen((s) {
// Listen for messages and send them back.
channel.sink.add(s);
});
}
21 changes: 21 additions & 0 deletions pkgs/sse/example/server.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:shelf/shelf_io.dart' as io;
import 'package:sse/server/sse_handler.dart';

/// A basic server which sets up an SSE handler.
///
/// When a client connects it will send a simple message and print the
/// response.
void main() async {
var handler = SseHandler(Uri.parse('/sseHandler'));
await io.serve(handler.handler, 'localhost', 0);
var connections = handler.connections;
while (await connections.hasNext) {
var connection = await connections.next;
connection.sink.add('foo');
connection.stream.listen(print);
}
}
Loading

0 comments on commit 5590447

Please sign in to comment.