eventsource

Server-sent Events (SSE) plugin for Angel.

Installation

In your pubspec.yaml:

  1. dependencies:
  2. angel_eventsource: ^1.0.0

Usage

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

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

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

  1. var app = new Angel();
  2. var ws = new AngelWebSocket(app);
  3. var events = new AngelEventSourcePublisher(ws);
  4.  
  5. await app.configure(ws.configureServer);
  6.  
  7. app.all('/ws', ws.handleRequest);
  8. app.get('/events', events.handleRequest);