Skip to content

an eventsource client lib that doesn't suffer from autoreconnection issues

License

Notifications You must be signed in to change notification settings

night/node-eventsource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-eventsource

The official eventsource library has some reconnect bugs and I've also noticed it fails to detect dropped connections occasionally. This project approaches eventsource with a more modern implementation, and without these bugs.

Usage

const es = new EventSource('https://example.tld/path/to/sse-endpoint');
es.on('connecting', () => console.log('connecting'));
es.on('connected', () => console.log('connected'));
es.on('disconnected', () => console.log('disconnected'));
es.on('some_event_name', ({id, name, data}) => console.log(id, name, data));

This library does not take into account retry events that set reconnection interval since you can configure backoff with options.

new EventSource('https://example.tld/path/to/sse-endpoint', {
  initialReconnectDelay: 2 * 1000, // 2 seconds
  maximumReconnectDelay: 30 * 1000, // 30 seconds
})

About

an eventsource client lib that doesn't suffer from autoreconnection issues

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published