rn-eventsource

1.0.0 • Public • Published

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)
}

Readme

Keywords

none

Package Sidebar

Install

npm i rn-eventsource

Weekly Downloads

22

Version

1.0.0

License

MIT

Unpacked Size

55.8 kB

Total Files

10

Last publish

Collaborators

  • adamchel_mongodb