All Projects → EventSource → Eventsource

EventSource / Eventsource

Licence: mit
EventSource client for Node.js and Browser (polyfill)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Eventsource

Php Sse
A simple and efficient library implemented HTML5's server-sent events by PHP, is used to real-time push events from server to client, and easier than Websocket, instead of AJAX request.
Stars: ✭ 237 (-56.19%)
Mutual labels:  eventsource, sse, server-sent-events
Demo Spring Sse
'Server-Sent Events (SSE) in Spring 5 with Web MVC and Web Flux' article and source code.
Stars: ✭ 102 (-81.15%)
Mutual labels:  eventsource, sse, server-sent-events
fetch-event-source
A better API for making Event Source requests, with all the features of fetch()
Stars: ✭ 120 (-77.82%)
Mutual labels:  server-sent-events, eventsource
eventsource ex
Elixir EventSource (Server-Sent Events) client
Stars: ✭ 16 (-97.04%)
Mutual labels:  server-sent-events, eventsource
Swell
Swell: API development tool that enables developers to test endpoints served over streaming technologies including Server-Sent Events (SSE), WebSockets, HTTP2, GraphQL, and gRPC.
Stars: ✭ 517 (-4.44%)
Mutual labels:  sse, server-sent-events
go-sse
Server-Sent Events for Go
Stars: ✭ 106 (-80.41%)
Mutual labels:  sse, server-sent-events
go-sse
Fully featured, spec-compliant HTML5 server-sent events library
Stars: ✭ 165 (-69.5%)
Mutual labels:  sse, server-sent-events
Demo.AspNetCore.ServerSentEvents
Demo project for demonstrating functionality of Lib.AspNetCore.ServerSentEvents
Stars: ✭ 52 (-90.39%)
Mutual labels:  sse, server-sent-events
sseserver
🏄 High-performance Server-Sent Events endpoint for Go
Stars: ✭ 88 (-83.73%)
Mutual labels:  sse, eventsource
okhttp-eventsource
Server-sent events (SSE) client implementation for Java, based on OkHttp: http://javadoc.io/doc/com.launchdarkly/okhttp-eventsource
Stars: ✭ 70 (-87.06%)
Mutual labels:  server-sent-events, eventsource
ruby-eventsource
Server-sent events (SSE) client implementation for Ruby
Stars: ✭ 19 (-96.49%)
Mutual labels:  server-sent-events, eventsource
sseclient
Pure-Python Server Side Events (SSE) client
Stars: ✭ 85 (-84.29%)
Mutual labels:  sse, server-sent-events
rust-eventsource-client
Server-sent events (SSE) client implementation for Rust
Stars: ✭ 24 (-95.56%)
Mutual labels:  server-sent-events, eventsource
react-native-sse
Event Source implementation for React Native. Server-Sent Events (SSE) for iOS and Android 🚀
Stars: ✭ 51 (-90.57%)
Mutual labels:  sse, eventsource
Eventsource
A simple Swift client library for the Server Sent Events (SSE)
Stars: ✭ 241 (-55.45%)
Mutual labels:  eventsource, sse
sse
HTML5 Server-Sent-Events for Go
Stars: ✭ 84 (-84.47%)
Mutual labels:  sse, server-sent-events
http-event-stream
📡 Modern spec-compliant Server Sent Events stream implementation.
Stars: ✭ 16 (-97.04%)
Mutual labels:  sse, server-sent-events
Aiohttp Sse
Server-sent events support for aiohttp
Stars: ✭ 125 (-76.89%)
Mutual labels:  eventsource, server-sent-events
Unifrost
Making it easier to push pubsub events directly to the browser.
Stars: ✭ 166 (-69.32%)
Mutual labels:  eventsource, sse
geo-smart-system
Open Source Realtime Tracking System
Stars: ✭ 36 (-93.35%)
Mutual labels:  sse, server-sent-events

EventSource npm versionBuild StatusNPM DownloadsDependencies

This library is a pure JavaScript implementation of the EventSource client. The API aims to be W3C compatible.

You can use it with Node.js or as a browser polyfill for browsers that don't have native EventSource support.

Install

npm install eventsource

Example

npm install
node ./example/sse-server.js
node ./example/sse-client.js    # Node.js client
open http://localhost:8080      # Browser client - both native and polyfill
curl http://localhost:8080/sse  # Enjoy the simplicity of SSE

Browser Polyfill

Just add example/eventsource-polyfill.js file to your web page:

<script src=/eventsource-polyfill.js></script>

Now you will have two global constructors:

window.EventSourcePolyfill
window.EventSource // Unchanged if browser has defined it. Otherwise, same as window.EventSourcePolyfill

If you're using webpack or browserify you can of course build your own. (The example/eventsource-polyfill.js is built with webpack).

Extensions to the W3C API

Setting HTTP request headers

You can define custom HTTP headers for the initial HTTP request. This can be useful for e.g. sending cookies or to specify an initial Last-Event-ID value.

HTTP headers are defined by assigning a headers attribute to the optional eventSourceInitDict argument:

var eventSourceInitDict = {headers: {'Cookie': 'test=test'}};
var es = new EventSource(url, eventSourceInitDict);

Allow unauthorized HTTPS requests

By default, https requests that cannot be authorized will cause the connection to fail and an exception to be emitted. You can override this behaviour, along with other https options:

var eventSourceInitDict = {https: {rejectUnauthorized: false}};
var es = new EventSource(url, eventSourceInitDict);

Note that for Node.js < v0.10.x this option has no effect - unauthorized HTTPS requests are always allowed.

HTTP status code on error events

Unauthorized and redirect error status codes (for example 401, 403, 301, 307) are available in the status property in the error event.

es.onerror = function (err) {
  if (err) {
    if (err.status === 401 || err.status === 403) {
      console.log('not authorized');
    }
  }
};

HTTP/HTTPS proxy

You can define a proxy option for the HTTP request to be used. This is typically useful if you are behind a corporate firewall.

var es = new EventSource(url, {proxy: 'http://your.proxy.com'});

License

MIT-licensed. See LICENSE

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].