rohrpost
v0.6.0
Published
Rohrpost Client for the Browser
Downloads
77
Readme
rohrpost-js
Client
Constructor
new RohrpostClient(URL, {pingInterval: 5000, token: $YOUR_JWT})
Subscribe to a group
subscribe(groupObject)
groupObject
is defined by the application, for example {type: 'collection', id: 5}
returns a Promise, resolves with groupName
string, use this to listen to events
Unsubscribe from a group
unsubscribe(groupObject)
Listen to events on a group
on(groupName, function(err, data))
Example
const url = 'wss://api-stage.ax-semantics.com/ws/rohrpost/'
const token = 'ey-jwt'
const colletionId = 23
const client = new RohrpostClient(url, {token})
client.on('open', () => {
client.subscribe({type:'collection', id: collectionId}).then((data) => {
console.log(`subscribed to ${data.group}`)
client.on(data.group, (err, data) => {
console.log(`got ${data.type} on ${data.group} : ${JSON.stringify(data.object)}`)
})
}).catch((err) => {
console.error(err)
})
})