npm.io
1.0.9 • Published 3 years ago

@asaje/sse-push-event

Licence
MIT
Version
1.0.9
Deps
0
Size
4 kB
Vulns
0
Weekly
0
Stars
2

SSE-PUSH-EVENT

Description

Lightweight package for SSE push events handling

Installation

npm i @asaje/sse-push-event

or

yarn add @asaje/sse-push-event

How to use

Client Side
import {
  addPushEventListener,
  initPushEvent,
  joinPushEventRoom,
} from '@asaje/sse-push-event';

initPushEvent('http://localhost:3000/events');

joinPushEventRoom('test-room');

addPushEventListener('TEST', (data) => {
  console.log('Received: ', data);
});
Server Side
// Example of NestJS controller
@Sse('events')
notify(): Observable<any> {
  return initPushEventSubscription();
}


// Sending event
sendPushEvent({
  event: 'TEST',
  data: { msg: 'Hello' },
  room: 'test-room',
})