How to use the nanobus.call function in nanobus

To help you get started, we’ve selected a few nanobus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github t-mullen / simple-signal / client / src / simple-signal-client.js View on Github external
function SimpleSignalClient (socket, metadata) {
  var self = this
  if (!(self instanceof SimpleSignalClient)) return new SimpleSignalClient(socket, metadata)

  EventEmitter.call(this)

  metadata = metadata || {}

  self._peers = {}
  self._requests = {}
  self.id = null
  self.socket = socket

  // Discover own socket.id
  socket.on('connect', function () {
    socket.emit('simple-signal[discover]', metadata)
  })
  if (socket.connected) {
    socket.emit('simple-signal[discover]', metadata)
  }
github t-mullen / realtime-collaboration-spec / implementations / js / src / filesystem / fileIndex.js View on Github external
function FileIndex (uuid) {
  if (!(this instanceof FileIndex)) return new FileIndex(uuid)

  EventEmitter.call(this)

  this._uuid = uuid
  this._counter = 0
  this._map = new CRDTMap(uuid)
  this._files = {}

  this._map.on('set', this._onSet.bind(this))
  this._map.on('remove', this._onRemove.bind(this))
  this._map.on('operation', (op) => {
    this.emit('operation', op)
  })
}
github hypermodules / hyperamp / renderer / audio / audio-player.js View on Github external
function AudioPlayer (audioNode, state) {
  if (!(this instanceof AudioPlayer)) return new AudioPlayer(audioNode, state)
  Nanobus.call(this, 'hyperaudio')

  var self = this

  this.audio = audioNode
  this.trackDict = state.trackDict
  this.trackOrder = state.trackOrder
  this.currentIndex = state.currentIndex
  this.queue(state.currentIndex)
  this.audio.volume = state.volume
  this.audio.muted = state.muted
  this.seeking = false
  this.seekDebounceTimer = null
  this.timeupdate = null

  this._endedListener = this.audio.addEventListener('ended', function () {
    if (!self.seeking) self.emit('ended')
github t-mullen / shh-signal / index.js View on Github external
function ShhSignalClient (web3, options = {}) {
  if (!(this instanceof ShhSignalClient)) return new ShhSignalClient(web3, options)

  EventEmitter.call(this)

  const { connectionTimeout = 1000 * 1000, roomPassword = '' } = options

  this.web3 = web3
  this._connectionTimeout = connectionTimeout

  this._peers = {}
  this._sessionQueues = {}
  this._timers = new Map()

  async function init () {
    this._roomKeyID = await web3.shh.generateSymKeyFromPassword(roomPassword)
    this._mySigID = await web3.shh.newKeyPair()
    this._keyPairID = await web3.shh.newKeyPair()

    this._myPublicKey = await web3.shh.getPublicKey(this._keyPairID)
github choojs / nanostate / index.js View on Github external
function Nanostate (initialState, transitions) {
  if (!(this instanceof Nanostate)) return new Nanostate(initialState, transitions)
  assert.equal(typeof initialState, 'string', 'nanostate: initialState should be type string')
  assert.equal(typeof transitions, 'object', 'nanostate: transitions should be type object')

  this.transitions = transitions
  this.state = initialState
  this.submachines = {}
  this._submachine = null

  Nanobus.call(this)
}
github t-mullen / simple-signal / server / src / index.js View on Github external
function SimpleSignalServer (io) {
  if (!(this instanceof SimpleSignalServer)) return new SimpleSignalServer(io)

  EventEmitter.call(this)

  this._sockets = {}

  io.on('connection', (socket) => {
    socket.on('simple-signal[discover]', this._onDiscover.bind(this, socket))
    socket.on('disconnect', this._onDisconnect.bind(this, socket));
  })
}
github lrlna / nanoidb / index.js View on Github external
function Nanoidb (name, version) {
  if (!(this instanceof Nanoidb)) return new Nanoidb(name, version)
  Nanobus.call(this, 'Nanoidb')

  this._name = name
  this._version = version

  assert.equal(typeof name, 'string', 'Nanoidb: name should be type string')
  assert.equal(typeof version, 'number', 'Nanoidb: version should be type number')

  this.upgrade(this._version)
}
github t-mullen / simple-signal / client / src / index.js View on Github external
function SimpleSignalClient (socket) {
  if (!(this instanceof SimpleSignalClient)) return new SimpleSignalClient(socket)

  EventEmitter.call(this)

  this.id = null
  this.socket = socket

  this._peers = {}
  this._sessionQueues = {}

  this.socket.on('simple-signal[discover]', this._onDiscover.bind(this))
  this.socket.on('simple-signal[offer]', this._onOffer.bind(this))
  this.socket.on('simple-signal[signal]', this._onSignal.bind(this))
  this.socket.on('simple-signal[reject]', this._onReject.bind(this))
}
github t-mullen / simple-signal / server / src / simple-signal-server.js View on Github external
function SimpleSignalServer (io) {
  var self = this
  if (!(self instanceof SimpleSignalServer)) return new SimpleSignalServer(io)

  EventEmitter.call(self)

  self._sockets = {}

  io.on('connection', self._onConnect.bind(self))
}
github t-mullen / realtime-collaboration-spec / implementations / js / src / filesystem / file.js View on Github external
function File (path, siteId, uuid) {
  EventEmitter.call(this)

  this.removed = false
  this.path = path

  this._uuid = uuid
  this._siteId = siteId
  this._sequence = new CRDTSequence(siteId, uuid)

  this._cursors = {}
}

nanobus

Tiny message bus

MIT
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis

Popular nanobus functions