How to use nanobus - 10 common examples

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 hypermodules / hyperamp / renderer / audio / audio-player.js View on Github external
this._endedListener = this.audio.addEventListener('ended', function () {
    if (!self.seeking) self.emit('ended')
  })

  this._timeListener = this.audio.addEventListener('timeupdate', function (ev) {
    if (self.seeking) return
    var timeupdate = Math.floor(self.audio.currentTime)
    if (self.timeupdate === timeupdate) return
    self.timeupdate = timeupdate
    self.emit('timeupdate', self.timeupdate)
  })

  this.emit('initialized', this)
}

AudioPlayer.prototype = Object.create(Nanobus.prototype)

AudioPlayer.prototype.seekDebounce = function () {
  this.seeking = true
  if (this.seekDebounceTimer) clearTimeout(this.seekDebounceTimer)
  var self = this
  this.seekDebounceTimer = setTimeout(function () {
    self.emit('debounce cleared')
    self.seeking = false
    self.seekDebounceTimer = null
    // TODO: check if we are at the end and we lost the endedEvent
  }, 1000)
}

AudioPlayer.prototype.queue = function (newIndex) {
  this.currentIndex = newIndex
  var key = this.trackOrder[this.currentIndex]
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 decentralized-identity / element / packages / element-app / src / components / InfrastructureDiagnostic / ServiceBus.stories.js View on Github external
import React, { Component } from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import PropTypes from 'prop-types';
import { Paper, Button } from '@material-ui/core';
import nanobus from 'nanobus';

const serviceBus = nanobus();

export class ServiceBusSummary extends Component {
  state = {};

  componentWillMount() {
    serviceBus.on('element:sidetree:transaction', ({ transaction }) => {
      action('event received: ')(transaction);
    });
  }

  render() {
    return (
      
        <button> {
            serviceBus.emit('element:sidetree:transaction', {</button>
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))
}

nanobus

Tiny message bus

MIT
Latest version published 4 years ago

Package Health Score

57 / 100
Full package analysis

Popular nanobus functions