Skip to content

Instantly share code, notes, and snippets.

@sqrtofsaturn
Created April 12, 2016 00:24
Show Gist options
  • Save sqrtofsaturn/62074cacce891d96409386e28725c9bc to your computer and use it in GitHub Desktop.
Save sqrtofsaturn/62074cacce891d96409386e28725c9bc to your computer and use it in GitHub Desktop.
async = require 'async'
MeshbluConfig = require 'meshblu-config'
MeshbluXMPP = require 'meshblu-xmpp'
TARGET_UUID = 'c571e559-0cab-445a-bc3e-e4f9247f805b'
class Command
panic: (error) =>
console.error error.stack
process.exit 1
run: =>
@config = (new MeshbluConfig()).toJSON()
@meshblu = new MeshbluXMPP @config
@meshblu.connect (error) =>
return @panic error if error?
console.log 'connected'
@subscribe()
@update()
@meshblu.on 'error', @panic
@meshblu.on 'message', @onMessage
onMessage: (message) =>
console.log 'message', JSON.stringify(message, null, 2)
subscribe: =>
subscriptions = [{
type: 'configure.received'
emitterUuid: @config.uuid
subscriberUuid: @config.uuid
}, {
type: 'configure.sent'
emitterUuid: TARGET_UUID
subscriberUuid: @config.uuid
}, {
type: 'broadcast.received'
emitterUuid: @config.uuid
subscriberUuid: @config.uuid
}, {
type: 'broadcast.sent'
emitterUuid: TARGET_UUID
subscriberUuid: @config.uuid
},{
type: 'message.received'
emitterUuid: @config.uuid
subscriberUuid: @config.uuid
}]
async.each subscriptions, async.apply(@meshblu.subscribe, @config.uuid), (error) =>
return @panic error if error?
console.log 'subscribed'
update: =>
operations = [
$unset:
discoverWhitelist: 1
configureWhitelist: 1
sendWhitelist: 1
receiveWhitelist: 1
,
$set:
'meshblu.version': '2.0.0'
'meshblu.whitelists.message.from': {"#{TARGET_UUID}": {}}
]
async.each operations, async.apply(@meshblu.update, @config.uuid), (error) =>
return @panic error if error?
console.log 'updated'
@whoami()
whoami: =>
@meshblu.whoami (error, device) =>
console.log 'whoami', JSON.stringify(device, null, 2)
module.exports = Command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment