react-native-oksse
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

react-native-oksse

A wrapper around the oksse android package for support in react-native.

Installation

yarn add react-native-oksse

Usage

import EventSource, { RetryError, SSEMessage } from 'react-native-oksse';

// ...

const url = '<some_url>';

// ...

const eventSource = new EventSource(url);

const customEvent = "CUSTOM_EVENT";

const onmessageHandler = (message: SSEMessage) => console.log({ message });

const customEventHandler = (message: SSEMessage) => console.log({ [customEvent]: { message } });

// ...

// add listener for source event
eventSource.onmessage = onmessageHandler;

// ...

// add listener for events comming form the server
eventSource.addEventListener(customEvent, customEventHandler);

// ...

// remove listeners
eventSource.remove(onmessageHandler);
eventSource.remove(customEventHandler);

// close the connection and remove the event source
eventSource.close()

Configuration

EventSource takes an optional configuration object other than the url.

new EventSource(url: string, config?: SSEConnConfig);

Options

interface SSEConnConfig {
  headers?: { [key: string]: string },
  query?: { [key: string]: string }
};

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Package Sidebar

Install

npm i react-native-oksse

Weekly Downloads

59

Version

0.2.0

License

MIT

Unpacked Size

52 kB

Total Files

19

Last publish

Collaborators

  • the_c1oud