1.0.2 • Published 4 years ago
relay-js v1.0.2
Relay JS client
Quickstart
Install.
npm i relay-js
Establish a connection. Use
Relay
class and a link from backend:const Relay = require('relay-js'); const relay = new Relay('http://example.com/?id=259360a3-0082-4503-94bf-9385a5df42');
Subscribe to channels. Ask backend about available channels and join them if you need to. Example:
relay.connect().then(() => { relay.subscribe(['notifications'], {token: 'secret'}, (channel, data) => { if(channel === 'notifications') { Notification.show(data.message); } }); });
Make a request to the server. With Relay you can respond to channels messages or make independent requests. Relay will transmit the server's response.
let data = await relay.request({action: "notification_read", id: 795});