2014-01-13 13:13:41 -08:00
|
|
|
'use strict';
|
|
|
|
|
2014-01-14 10:20:59 -08:00
|
|
|
// server-side socket behaviour
|
2014-01-16 18:23:10 -08:00
|
|
|
// io is a variable already taken in express
|
|
|
|
var ios = null;
|
2014-01-14 11:56:02 -08:00
|
|
|
|
|
|
|
module.exports.init = function(app, io_ext) {
|
2014-01-16 18:23:10 -08:00
|
|
|
ios = io_ext;
|
|
|
|
ios.set('log level', 1); // reduce logging
|
2014-01-17 10:25:15 -08:00
|
|
|
ios.sockets.on('connection', function(socket) {
|
|
|
|
socket.on('subscribe', function(topic) {
|
|
|
|
socket.join(topic);
|
|
|
|
});
|
2014-01-13 13:13:41 -08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-01-14 11:56:02 -08:00
|
|
|
module.exports.broadcast_tx = function(tx) {
|
2014-01-17 10:25:15 -08:00
|
|
|
ios.sockets.in('inv').emit('tx', tx);
|
2014-01-14 11:56:02 -08:00
|
|
|
};
|
2014-01-14 14:42:38 -08:00
|
|
|
|
|
|
|
module.exports.broadcast_block = function(block) {
|
2014-01-17 10:25:15 -08:00
|
|
|
ios.sockets.in('inv').emit('block', block);
|
2014-01-14 14:42:38 -08:00
|
|
|
};
|
2014-01-17 10:25:15 -08:00
|
|
|
|
|
|
|
module.exports.broadcast_address_tx = function(address, tx) {
|
2014-01-20 09:30:25 -08:00
|
|
|
ios.sockets.in(address).emit('atx', tx);
|
2014-01-17 10:25:15 -08:00
|
|
|
};
|
|
|
|
|
2014-01-19 07:33:39 -08:00
|
|
|
module.exports.broadcastSyncInfo = function(syncInfo) {
|
2014-01-21 06:51:34 -08:00
|
|
|
ios.sockets.in('sync').emit('status', syncInfo);
|
2014-01-19 07:33:39 -08:00
|
|
|
};
|