Skip to content

ivanrussu/relay-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Relay JS client

Quickstart

  1. Install. npm i relay-js

  2. 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');
  3. 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);
             }         
         });
     });
  4. 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});

About

POST messages through websockets

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published