ooo-client
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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()
}

Readme

Keywords

none

Package Sidebar

Install

npm i ooo-client

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

30.3 kB

Total Files

13

Last publish

Collaborators

  • benitogf