Quick Start

npm

npm i @buccaneer/rxws --save

yarn

yarn add @buccaneer/rxws

Subscribe to messages from a server

import { share } from 'rxjs/operators';
import { messages, ws } from '@buccaneer/rxws';

const websocketParams = {
  url: 'wss://mysite.com',
  topics: ['message', 'news'],
};
const ws$ = ws(websocketParams).pipe(
  share() // pipe the Observable to a Subject
);

// get a stream of messages from the server:
const message$ = ws$.pipe(
  messages() // get all messages from the WebSocket.
);
message$.subscribe(console.log); // log messages from the server

Publish messages to a server

Handle interruptions to the client's connection

Next steps

Last updated

Was this helpful?