diff options
author | Arnaldas Augutis <info@untitled.lt> | 2018-11-22 16:38:05 +0300 |
---|---|---|
committer | Arnaldas Augutis <info@untitled.lt> | 2019-06-12 00:39:27 +0300 |
commit | 144812c09316d9016a87d6a8e5096ddb7fbf5f63 (patch) | |
tree | 6dc7a068c3dbd264217831eeb87bfec2a152f370 | |
parent | f8923a66a8b1178a412b067bc913e267025b3d57 (diff) |
ability to close and restore streamin server
-rw-r--r-- | lib/server.js | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/server.js b/lib/server.js index 60595a8..2988f27 100644 --- a/lib/server.js +++ b/lib/server.js @@ -12,11 +12,16 @@ function Server (torrent, opts = {}) { const sockets = [] const pendingReady = [] let closed = false + const _listen = server.listen + const _close = server.close - server.on('connection', onConnection) - server.on('request', onRequest) + server.listen = port => { + closed = false + server.on('connection', onConnection) + server.on('request', onRequest) + _listen.call(server, port) + } - const _close = server.close server.close = cb => { closed = true server.removeListener('connection', onConnection) @@ -25,7 +30,6 @@ function Server (torrent, opts = {}) { const onReady = pendingReady.pop() torrent.removeListener('ready', onReady) } - torrent = null _close.call(server, cb) } |