platform/packages/eventsource
2021-09-12 22:12:18 +08:00
..
.idea Add 'packages/eventsource/' from commit 'bc079d37353d94d827290914523b2757fb392ff9' 2020-02-15 18:29:05 -05:00
example Add 'packages/eventsource/' from commit 'bc079d37353d94d827290914523b2757fb392ff9' 2020-02-15 18:29:05 -05:00
lib Add 'packages/eventsource/' from commit 'bc079d37353d94d827290914523b2757fb392ff9' 2020-02-15 18:29:05 -05:00
.gitignore Add 'packages/eventsource/' from commit 'bc079d37353d94d827290914523b2757fb392ff9' 2020-02-15 18:29:05 -05:00
analysis_options.yaml Add 'packages/eventsource/' from commit 'bc079d37353d94d827290914523b2757fb392ff9' 2020-02-15 18:29:05 -05:00
eventsource.iml Add 'packages/eventsource/' from commit 'bc079d37353d94d827290914523b2757fb392ff9' 2020-02-15 18:29:05 -05:00
LICENSE Updated license 2021-06-14 11:52:58 +08:00
pubspec.yaml Fixed warnings 2021-09-12 22:12:18 +08:00
README.md Add 'packages/eventsource/' from commit 'bc079d37353d94d827290914523b2757fb392ff9' 2020-02-15 18:29:05 -05:00

eventsource

Server-sent Events (SSE) plugin for Angel.

Installation

In your pubspec.yaml:

dependencies:
    angel_eventsource: ^1.0.0

Usage

SSE and WebSockets are somewhat similar in that they allow pushing of events from server to client. SSE is not bi-directional, but the same abstractions used for WebSockets can be applied to SSE easily.

For this reason, the AngelEventSourcePublisher class is a simple adapter that hands control of SSE requests to an existing AngelWebSocket driver.

So, using this is pretty straightforward. You can dispatch events via WebSocket as per usual, and have them propagated to SSE clients as well.

var app = new Angel();
var ws = new AngelWebSocket(app);
var events = new AngelEventSourcePublisher(ws);

await app.configure(ws.configureServer);

app.all('/ws', ws.handleRequest);
app.get('/events', events.handleRequest);