5.0.0 • Published 7 years ago

sb-communication v5.0.0

Weekly downloads
9
License
MIT
Repository
github
Last release
7 years ago

SB-Communication

SB-Communication is a base communication low-level library meant to be used in other communication libraries. It allows promise-based communication on both ends, You must write a wrapper for it for your use-case specific stream, socket or resource though. It works in both browsers and node!

Example Communication Implementation

'use babel'

import Communication from 'sb-communication'

const worker = new WebWorker('worker.js')

const communication = new Communication({
  listener(callback) {
    worker.onmessage = callback
  },
  send(data) {
    worker.postMessage = data
  },
})

// Event-Specific bindings
communication.on('count-pi', async function(data) {
  // ^ Handlers can return Promises or be sync
  console.log(data)
  return 'Something else'
})

API

export default class Communication {
  constructor({ listener: Function, send: Function })
  on(event, callback)
  send(event, payload)
  dispose()
}

LICENSE

This project is licensed under the terms of MIT License.

5.0.0

7 years ago

4.0.1

10 years ago

4.0.0

10 years ago

3.1.0

10 years ago

3.0.0

10 years ago

2.0.2

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.0.0

10 years ago

0.0.1

10 years ago