1.0.2 • Published 7 years ago

smashcast-ws v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

smashcast-ws

Install

$ npm i -S smashcast-ws

How to use

Import smashcastWs

import smashcastWs from 'smashcast-ws';

Send a message

smashcastWs.sendMessage('service.method', data);

Events

Callback based

Register

smashcastWs.on('service.method', callback);

Unregister

smashcastWs.off('service.method', callback);

RxJs observable

Register

const observable$ = smashcastWs.observe('service.method');
const subscription = observable$.subscribe(callback);

Unregister

subscription.unsubscribe();

Gotchas

Open callback will trigger immediately if smashcastWs is already connected!*

smashcastWs.on('open', callback);

If you send a message when WS is not connected, the message will be sent when the connection is ready again

smashcastWs.sendMessage('service.method', {});

If you don't set the service, chat will be used as default

smashcastWs.sendMessage('method', {});
smashcastWs.on('method', callback);