Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to close and restore streaming server #1547

Merged
merged 2 commits into from Jun 11, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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 = (...args) => {
closed = false
server.on('connection', onConnection)
server.on('request', onRequest)
_listen.apply(server, args)
}

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

This comment has been minimized.

Copy link
@alxhotel

alxhotel Apr 7, 2019

Member

Move torrent = null inside server.destroy(cb).

_close.call(server, cb)
}

@@ -38,6 +42,7 @@ function Server (torrent, opts = {}) {
if (!cb) cb = () => {}
if (closed) process.nextTick(cb)
else server.close(cb)
torrent = null
}

function isOriginAllowed (req) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.