Skip to content

Commit

Permalink
refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
asapach committed May 9, 2014
1 parent ff327a6 commit 22c85f3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions server/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,41 @@ module.exports = function (server) {
});
});

store.on('torrent', function (infoHash, engine) {
engine.once('verifying', function () {
store.on('torrent', function (infoHash, torrent) {
torrent.once('verifying', function () {
var notifyProgress = _.throttle(function () {
io.sockets.emit('download', infoHash, progress(engine.bitfield.buffer));
io.sockets.emit('download', infoHash, progress(torrent.bitfield.buffer));
}, 1000);

io.sockets.emit('verifying', infoHash, stats());

engine.once('ready', function () {
torrent.once('ready', function () {
io.sockets.emit('ready', infoHash, stats());
});

engine.on('uninterested', function () {
torrent.on('uninterested', function () {
io.sockets.emit('uninterested', infoHash);
});

engine.on('interested', function () {
torrent.on('interested', function () {
io.sockets.emit('interested', infoHash);
});

var interval = setInterval(function () {
io.sockets.emit('stats', infoHash, stats());
}, 1000);

engine.on('verify', notifyProgress);
torrent.on('verify', notifyProgress);

engine.once('destroyed', function () {
torrent.once('destroyed', function () {
clearInterval(interval);
io.sockets.emit('destroyed', infoHash);
engine = null;
torrent = null;
});
});

var stats = function () {
var swarm = engine.swarm;
var swarm = torrent.swarm;
return {
peers: {
total: swarm.wires.length,
Expand Down

0 comments on commit 22c85f3

Please sign in to comment.