Skip to content

Commit

Permalink
v6.1.0 add meta information to message
Browse files Browse the repository at this point in the history
  • Loading branch information
iamruinous committed Apr 5, 2017
1 parent d9b88de commit ae88479
Show file tree
Hide file tree
Showing 3 changed files with 376 additions and 203 deletions.
26 changes: 20 additions & 6 deletions command-firehose.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ colors = require 'colors'
MeshbluFirehose = require 'meshblu-firehose-socket.io'
commander = require 'commander'
Util = require './src/util'
moment = require 'moment'
prettyBytes = require 'pretty-bytes'

class FirehoseCommand extends Util
constructor: ->
Expand All @@ -19,23 +21,35 @@ class FirehoseCommand extends Util

return {
filename: _.first commander.args
messagePaths: _.split commander.path, ','
messagePaths: _.compact _.split commander.path, ','
}

run: =>
@firehose.connect @afterConnect
@firehose.on 'connect', @afterConnect
@firehose.once 'disconnect', @die
@firehose.on 'message', @onMessage
@firehose.connect()

afterConnect: (error) =>
return @die error if error?
console.log colors.red('FIREHOSE'), 'connected'

onMessage: (message) =>
console.log colors.yellow '========================='
return console.log JSON.stringify(message, null, 2) if _.isEmpty _.compact @messagePaths
_.each @messagePaths, (messagePath) =>
console.log JSON.stringify(_.get(message, messagePath), null, 2)
timestamp = colors.gray moment().format()
route = _.first(_.get message, 'metadata.route', []) ? {}
{from, to, type} = route
from = colors.blue from
to = colors.blue to
type = colors.red type
size = colors.green prettyBytes JSON.stringify(message).length
console.log colors.yellow '============================================================================='
if _.isEmpty @messagePaths
console.log JSON.stringify(message, null, 2)
else
_.each @messagePaths, (messagePath) =>
console.log JSON.stringify(_.get(message, messagePath), null, 2)

console.log "#{timestamp} <#{type}> @#{from}=>#{to} (#{size})"

die: (error) =>
console.error error
Expand Down
28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meshblu-util",
"version": "6.0.2",
"version": "6.1.0",
"description": "Utils for managing Meshblu devices",
"main": "index.js",
"bin": {
Expand Down Expand Up @@ -44,24 +44,26 @@
},
"homepage": "https://github.com/octoblu/meshblu-util",
"devDependencies": {
"chai": "^1.10.0",
"mocha": "^2.1.0",
"sinon": "^1.12.2",
"sinon-chai": "^2.6.0"
"chai": "^3.5.0",
"mocha": "^3.2.0",
"sinon": "^2.1.0",
"sinon-chai": "^2.9.0"
},
"dependencies": {
"coffee-script": "^1.8.0",
"coffee-script": "^1.12.4",
"colors": "^1.0.3",
"commander": "^2.6.0",
"debug": "^2.1.3",
"debug": "^2.6.3",
"gateblu-shadower": "^1.0.1",
"lodash": "^4.17.1",
"meshblu-config": "^6.0.0",
"meshblu-firehose-socket.io": "^2.0.0",
"meshblu-http": "^9.7.1",
"meshblu-json-schema-resolver": "^2.0.0",
"lodash": "^4.17.4",
"meshblu-config": "^7.0.0",
"meshblu-firehose-socket.io": "^4.0.0",
"meshblu-http": "^9.8.0",
"meshblu-json-schema-resolver": "^2.0.4",
"meshblu-websocket": "^4.0.0",
"meshblu-xmpp": "^1.4.4",
"open": "0.0.5"
"moment": "^2.18.1",
"open": "0.0.5",
"pretty-bytes": "^4.0.2"
}
}
Loading

0 comments on commit ae88479

Please sign in to comment.