1.0.0 • Published 2 years ago

ooo-client v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

ooo-client

Test

npm

js client for ooo though the service should be usable with the standard websocket and http/fetch request method, this client provides encode/decode methods and a reconnecting websocket abstraction.

Messages will arrive either as a snapshot or a patch the subscription keeps a cache of the latest state.

how to

install

npm i ooo-client

object

import ooo from 'ooo-client'

const client = ooo('localhost:8800/box')
let msgs = []
client.onopen = async () => {
  await client.publish('box', { name: 'something 🧰' }) // create
  await client.publish('box', { name: 'still something 💾' }) // update
  await client.unpublish('box') // delete
}
client.onmessage = async (msg) => { // read
  msgs.push(msg)
  if (msgs.length === 4) {
    client.close()
    console.log(msgs)
  }
}
client.onerror = (err) => {
  client.close()
}

list

import ooo from 'ooo-client'

const client = ooo('localhost:8800/box/*')
let msgs = []
client.onopen = async () => {
  const id = await client.publish('box/*', { name: 'something 🧰' }) // create
  await client.publish('box/' + id, { name: 'still something 💾' }) // update
  await client.publish('box/custom', { name: 'custom something 🧰' }) // create
  await client.unpublish('box/*') // delete list
}
client.onmessage = async (msg) => { // read
  msgs.push(msg)
  if (msgs.length === 5) {
    client.close()
    console.log(msgs)
  }
}
client.onerror = (err) => {
  client.close()
}