Skip to content

Instantly share code, notes, and snippets.

@elliottwilliams
Last active August 28, 2016 04:04
Show Gist options
  • Save elliottwilliams/40a94bd5486d0d30f7a5246d4582360a to your computer and use it in GitHub Desktop.
Save elliottwilliams/40a94bd5486d0d30f7a5246d4582360a to your computer and use it in GitHub Desktop.

Usage

$ npm i
$ node last_event.js vehicles.4008
var autobahn = require('autobahn');
var colors = require('colors');
if (process.argv.length < 3) {
console.error('Usage: last_event.js identifier'.yellow);
return;
}
var connection = new autobahn.Connection({
url: 'ws://shark-nyc1.transio.us:8080/ws',
//url: 'ws://localhost:8080/ws',
realm: 'realm1',
authid: 'consumer1',
authmethod: ['anonymous']
});
function getLastEvent(session, identifier) {
var err = console.error.bind(this, identifier.red);
session.call('meta.last_event', [identifier, identifier]).then(
function (args) {
if (args && args.length >= 1) {
console.log(JSON.stringify(args[0][0], null, ' '));
} else {
err('meta.last_event unexpected response:', args);
}
},
function (errArgs) {
err(errArgs);
}
)
}
connection.onopen = function (session) {
getLastEvent(session, process.argv[2]);
}
connection.open();
{
"name": "last_event",
"version": "0.1.0",
"description": "",
"main": "last_event.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Elliott Williams",
"license": "ISC",
"dependencies": {
"autobahn": "^0.10.1",
"colors": "^1.1.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment