From 2570b37e1f7b90ae89530c4b4fb58d90b048aa7a Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Mon, 26 Jan 2015 11:12:01 -0800 Subject: throw if add or seed after destroy For #254 --- index.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'index.js') diff --git a/index.js b/index.js index 6e5ee0d..6015104 100644 --- a/index.js +++ b/index.js @@ -42,6 +42,7 @@ function WebTorrent (opts) { EventEmitter.call(self) if (!debug.enabled) self.setMaxListeners(0) + self.destroyed = false self.torrentPort = opts.torrentPort || 0 self.tracker = opts.tracker !== undefined ? opts.tracker : true self.rtcConfig = opts.rtcConfig @@ -139,6 +140,7 @@ WebTorrent.prototype.get = function (torrentId) { WebTorrent.prototype.add = WebTorrent.prototype.download = function (torrentId, opts, ontorrent) { var self = this + if (self.destroyed) throw new Error('client is destroyed') debug('add %s', torrentId) if (typeof opts === 'function') { ontorrent = opts @@ -188,6 +190,8 @@ WebTorrent.prototype.download = function (torrentId, opts, ontorrent) { */ WebTorrent.prototype.seed = function (input, opts, onseed) { var self = this + if (self.destroyed) throw new Error('client is destroyed') + debug('seed %s', input) if (typeof opts === 'function') { onseed = opts opts = {} @@ -240,6 +244,7 @@ WebTorrent.prototype.remove = function (torrentId, cb) { */ WebTorrent.prototype.destroy = function (cb) { var self = this + self.destroyed = true debug('destroy') var tasks = self.torrents.map(function (torrent) { -- cgit v1.2.3