Skip to content
An EventSource implementation built on top of React Native's low-level Networking API
JavaScript
Branch: master
Clone or download
Latest commit 4fcedf9 Jan 31, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src import EventTarget correctly Jan 30, 2020
.babelrc initial commit Jan 30, 2020
.flowconfig initial commit Jan 30, 2020
.gitignore initial commit Jan 30, 2020
README.md bump version to 0.0.2 Jan 30, 2020
babel.config.js initial commit Jan 30, 2020
jest.config.js initial commit Jan 30, 2020
package-lock.json add package-lock.json Jan 30, 2020
package.json bump to 1.0.0 release Jan 30, 2020

README.md

rn-eventsource

This package that implements the EventSource web standard using low-level React Native networking primitives.

There are several EventSource polyfills today, but none of them satisfy the following three goals:

  • Don't depend on the Node.js standard library
    • The Node.js standard library isn't supported by React Native.
  • Don't depend on a native module
    • This makes it harder to work with simple Expo-based apps.
  • Don't implement with XmlHttpRequest
    • Existing polyfills that use XmlHttpRequest are not optimal for streaming sources because they cache the entire stream of data until the request is over.

Thanks to the low-level network primitives exposed in React Native 0.62, it became possible to build this native EventSource implementation for React Native. See this thread in react-native-community for a longer discussion around the motivations of this implementation.

Usage

Install the package in your React Native project with:

npm install --save rn-eventsource

To import the library in your project:

const EventSource = require('rn-eventsource');

Once imported, you can use it like any other EventSource. See the MDN Documentation for more usage examples.

const ticker = new EventSource('https://www.example.com/stream?token=blah');

ticker.onmessage = (message) => {
    console.log(message.data)
}
You can’t perform that action at this time.