Beispiel #1
0
// Initialization
function connect (opt) {
  options = _.merge({}, defaultOptions, opt)
  if (!options.computer) {
    console.error('Starport - You must set a computer name!')
    return
  }
  if (!options.channel) {
    console.error('Starport - You must set a channel name!')
    return
  }
  if (options.server) setServer(options.server.address, options.server.port)
  spacebroClient.registerToMaster([{
    name: options.channel,
    trigger: function (data) {
      // console.log('received', data)
      if (data.from === options.computer) return
      if (data.to != null && data.to !== options.computer) return
      for (let unpack of filterHooks(data.eventName, unpackers)) {
        let unpacked = unpack(data)
        if (unpacked === false) return
        data = unpacked || data
      }
      if (_.has(events, data.eventName)) {
        events[data.eventName].dispatch(...data.args)
      }
    }
  }], options.computer)
  for (let packer of options.packers) {
    addPacker(packer.handler, packer.priority, packer.eventName)
  }
  for (let unpacker of options.unpackers) {
    addUnpacker(unpacker.handler, unpacker.priority, unpacker.eventName)
  }
  connected = true
}
Beispiel #2
0
  init(){
    var actionList = [
      {
        name: 'shoot',
        trigger: function (data) {
          console.log('SHOOOT !')
        }
      },
      {
        name: 'orientation',
        trigger: function (data) {
          console.log('orientation')
        }
      }
    ]

    spacebroClient.iKnowMyMaster('localhost', 8888)
    spacebroClient.registerToMaster(actionList, 'new-media')
  }
Beispiel #3
0
'use strict'

const spacebroClient = require('spacebro-client')

const actionList = [
  {
    name: 'DMX-data',
    trigger: function (data) {
      console.log(data)
    }
  }
]

spacebroClient.registerToMaster(actionList, 'sendDmx')

setTimeout(function () {
  spacebroClient.emit('DMX-data', {channel: Number(process.argv[2]), level: Number(process.argv[3])})
  setTimeout(function () {
    process.exit()
  }, 500)
}, 1000)