Matias Alejo Garcia
10 years ago
12 changed files with 350 additions and 307 deletions
@ -0,0 +1,17 @@ |
|||
#!/usr/bin/env node
|
|||
|
|||
'use strict'; |
|||
|
|||
var _ = require('lodash'); |
|||
var log = require('npmlog'); |
|||
log.debug = log.verbose; |
|||
|
|||
var config = require('../config'); |
|||
var BlockchainMonitor = require('../lib/blockchainmonitor'); |
|||
|
|||
var bcm = new BlockchainMonitor(); |
|||
bcm.start(config, function(err) { |
|||
if (err) throw err; |
|||
|
|||
console.log('Blockchain monitor started'); |
|||
}); |
@ -0,0 +1,46 @@ |
|||
var $ = require('preconditions').singleton(); |
|||
var _ = require('lodash'); |
|||
var inherits = require('inherits'); |
|||
var events = require('events'); |
|||
var nodeutil = require('util'); |
|||
var log = require('npmlog'); |
|||
log.debug = log.verbose; |
|||
log.disableColor(); |
|||
|
|||
function MessageBroker(opts) { |
|||
var self = this; |
|||
|
|||
opts = opts || {}; |
|||
if (opts.messageBrokerServer) { |
|||
var url = opts.messageBrokerServer.url; |
|||
|
|||
this.remote = true; |
|||
this.mq = require('socket.io-client').connect(url); |
|||
this.mq.on('connect', function() {}); |
|||
this.mq.on('connect_error', function() { |
|||
log.warn('Error connecting to message broker server @ ' + url); |
|||
}); |
|||
|
|||
this.mq.on('msg', function(data) { |
|||
self.emit('msg', data); |
|||
}); |
|||
|
|||
log.info('Using message broker server at ' + url); |
|||
} |
|||
}; |
|||
|
|||
nodeutil.inherits(MessageBroker, events.EventEmitter); |
|||
|
|||
MessageBroker.prototype.send = function(data) { |
|||
if (this.remote) { |
|||
this.mq.emit('msg', data); |
|||
} else { |
|||
this.emit('msg', data); |
|||
} |
|||
}; |
|||
|
|||
MessageBroker.prototype.onMessage = function(handler) { |
|||
this.on('msg', handler); |
|||
}; |
|||
|
|||
module.exports = MessageBroker; |
@ -1,25 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
var log = require('npmlog'); |
|||
log.debug = log.verbose; |
|||
var inherits = require('inherits'); |
|||
var events = require('events'); |
|||
var nodeutil = require('util'); |
|||
|
|||
function NotificationBroadcaster() {}; |
|||
|
|||
nodeutil.inherits(NotificationBroadcaster, events.EventEmitter); |
|||
|
|||
NotificationBroadcaster.prototype.broadcast = function(eventName, notification) { |
|||
this.emit(eventName, notification); |
|||
}; |
|||
|
|||
var _instance; |
|||
NotificationBroadcaster.singleton = function() { |
|||
if (!_instance) { |
|||
_instance = new NotificationBroadcaster(); |
|||
} |
|||
return _instance; |
|||
}; |
|||
|
|||
module.exports = NotificationBroadcaster.singleton(); |
@ -0,0 +1,23 @@ |
|||
#!/usr/bin/env node
|
|||
|
|||
'use strict'; |
|||
|
|||
var $ = require('preconditions').singleton(); |
|||
var io = require('socket.io'); |
|||
var log = require('npmlog'); |
|||
log.debug = log.verbose; |
|||
|
|||
var DEFAULT_PORT = 3380; |
|||
|
|||
var opts = { |
|||
port: parseInt(process.argv[2]) || DEFAULT_PORT, |
|||
}; |
|||
|
|||
var server = io(opts.port); |
|||
server.on('connection', function(socket) { |
|||
socket.on('msg', function(data) { |
|||
server.emit('msg', data); |
|||
}); |
|||
}); |
|||
|
|||
console.log('Message broker server listening on port ' + opts.port) |
Loading…
Reference in new issue