diff --git a/chrome extension/dat_error.js b/chrome extension/dat_error.js index b71c81d..2538435 100644 --- a/chrome extension/dat_error.js +++ b/chrome extension/dat_error.js @@ -28,7 +28,7 @@ var onx = document.createElement('br'); document.body.appendChild(onx); var datLink = document.createElement('a'); -datLink.href = "dat://"+datHash+"/"+datPath; +datLink.href = "dat://"+datHash+datPath; datLink.innerText = "Dat link"; datLink.className = "button"; document.body.appendChild(datLink); \ No newline at end of file diff --git a/chrome extension/manifest.json b/chrome extension/manifest.json index 7a6b546..c1fe4d2 100644 --- a/chrome extension/manifest.json +++ b/chrome extension/manifest.json @@ -3,8 +3,8 @@ "short_name": "DatPart", "description": "DatPart extension.", "manifest_version": 2, - "version": "0.0.5", - "version_name": "0.0.5 alpha", + "version": "0.0.6", + "version_name": "0.0.6 alpha", "permissions": ["tabs", "webRequestBlocking", "webRequest", "webNavigation", "proxy", "*://*.dat_site/*", "*://*.torrent_site/*", "storage", "unlimitedStorage", "nativeMessaging"], "optional_permissions": [ "tabs", "notifications", "background", "*://*/", "" ], "externally_connectable": { "ids": [ "pgdnnmekclkafnpfofleebhhnmolopgl" ] }, diff --git a/electron app/resources/datpart/launch.js b/electron app/resources/datpart/launch.js index f375cca..a44ee0a 100644 --- a/electron app/resources/datpart/launch.js +++ b/electron app/resources/datpart/launch.js @@ -1,13 +1,9 @@ -var dev = true; - -if (typeof process === 'object') { - if (typeof process.versions === 'object') { - if (typeof process.versions['electron'] !== 'undefined') { +var dev = false; const {app, BrowserWindow, Menu, Tray} = require('electron') const path = require('path') const url = require('url') -const fs = require('fs'); +const fs = require('fs') // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. @@ -19,77 +15,46 @@ var appName = app.getName(); var appIcon = __dirname+'/logo_128.png'; var appPath = app.getAppPath(); -if (fs.existsSync(appPath + "/dats/")) { - fs.mkdir(appPath + "/dats/"); -} - -app.on('ready', () => { - tray = new Tray(appIcon) - const contextMenu = Menu.buildFromTemplate([ - {label: 'Show', click: function() {win.show();}}, - {label: 'Quit', click: function() {app.isQuiting = true; app.quit();}} - ]) - tray.setToolTip(appName + " v" + versionNumber) - tray.setContextMenu(contextMenu) - tray.on('click', () => { - win.show() - }) - - if(app.isDefaultProtocolClient(appName)) { - - } else { - app.setAsDefaultProtocolClient(appName) - } - - /* - if(app.isDefaultProtocolClient('dat')) { - - } else { - app.setAsDefaultProtocolClient('dat') + if (!fs.existsSync(__dirname + '/../../dats/')) { + fs.mkdirSync(__dirname + '/../../dats/'); } - */ - - process.argv.forEach(function (val, index, array) { - console.log(index + ': ' + val); -}); - -}) - -const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => { - // Someone tried to run a second instance, we should focus our window. - if (win) { - if (win.isMinimized()) win.restore() - win.show() - win.focus() - } -}) - -if (isSecondInstance) { - app.quit() -} function createWindow () { // Create the browser window. - win = new BrowserWindow( - { + win = new BrowserWindow({ width: 800, height: 600, - icon: __dirname+'/logo_128.png', + icon: appIcon, backgroundColor: '#424242', show: false }) - win.setMenu(null) - - // and load the index.html of the app. - win.loadURL('file://' + __dirname + '/server_app.html') - + const devTopMenu = Menu.buildFromTemplate([ + {label: appName + " v" + versionNumber + " dev mode"}, + {label: 'Quit for real', click: function() {app.isQuiting = true; app.quit();}} + ]) // Open the DevTools if dev is true. if(dev == true) { - win.webContents.openDevTools({mode:'detach'}) + win.setMenu(devTopMenu) + win.setThumbnailToolTip(appName + " v" + versionNumber + " dev mode") + win.setTitle(appName + " v" + versionNumber + " dev mode") + win.webContents.openDevTools({mode:'detach'}) + } else if (dev != true) { + win.setMenu(null) + win.setThumbnailToolTip(appName + " v" + versionNumber) + win.setTitle(appName + " v" + versionNumber) } + win.on('show', () => { + if(dev == true) { + win.webContents.openDevTools({mode:'detach'}) + } + }) + + // and load the index.html of the app. + win.loadURL('file://' + __dirname + '/server_app.html') + win.on('close', function (event) { if( !app.isQuiting){ event.preventDefault() @@ -105,13 +70,63 @@ function createWindow () { // when you should delete the corresponding element. win = null }) - + } -// This method will be called when Electron has finished -// initialization and is ready to create browser windows. -// Some APIs can only be used after this event occurs. -app.on('ready', createWindow) + const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => { + // Someone tried to run a second instance, we should focus our window. + if (win) { + if (win.isMinimized()) win.restore() + win.show() + win.focus() + } + }) + + if (isSecondInstance) { + app.quit() + } + +app.on('ready', () => { + if (!fs.existsSync(__dirname + '/../../dats/')) { + fs.mkdirSync(__dirname + '/../../dats/'); + } + + tray = new Tray(appIcon) + + const contextMenu = Menu.buildFromTemplate([ + {label: 'Show', click: function() {win.show();}}, + {label: 'Quit', click: function() {app.isQuiting = true; app.quit();}} + ]) + + const devContextMenu = Menu.buildFromTemplate([ + {label: 'Show', click: function() {win.show();}}, + {label: 'Quit', click: function() {app.isQuiting = true; app.quit();}}, + {label: appName + " v" + versionNumber + " dev mode"} + ]) + + if(dev == true) { + tray.setContextMenu(devContextMenu) + tray.setToolTip(appName + " v" + versionNumber + " dev mode") + } else if (dev != true) { + tray.setContextMenu(contextMenu) + tray.setToolTip(appName + " v" + versionNumber) + } + + tray.on('click', () => { + win.show() + }) + + if(app.isDefaultProtocolClient(appName)) { + + } else { + app.setAsDefaultProtocolClient(appName) + } + + //var openingNotification = new Notification({title: "ggggggggo", body: "lol"}) + //openingNotification.show() + + createWindow(); +}) app.on('activate', () => { // On macOS it's common to re-create a window in the app when the @@ -119,51 +134,4 @@ app.on('activate', () => { if (win === null) { createWindow() } -}) - -// In this file you can include the rest of your app's specific main process -// code. You can also put them in separate files and require them here. - -}}} else if (window && window.chrome && chrome.runtime && chrome.runtime.id) { - -chrome.app.runtime.onLaunched.addListener(function() { - chrome.app.window.create('/server_app.html?platform=chromeApp', { - 'innerBounds': { - 'width': 800, - 'height': 600 - }, - 'minWidth': 800, - 'minHeight': 400, - 'frame': { - 'type': 'chrome', - 'color': '#424242', - 'activeColor': '#ffffff', - 'inactiveColor': '#424242' - }, - id: 'other_web_server' - }); -}); - -chrome.runtime.onMessageExternal.addListener(function() { -if(chrome.app.window.get('other_web_server')){ - //Do Nothing -} else { - chrome.app.window.create('/server_app.html?platform=chromeApp', { - 'innerBounds': { - 'width': 800, - 'height': 600 - }, - 'minWidth': 800, - 'minHeight': 400, - 'state': 'minimized', - 'frame': { - 'type': 'chrome', - 'color': '#424242', - 'activeColor': '#ffffff', - 'inactiveColor': '#424242' - }, - id: 'other_web_server' - }); -} -}); -} \ No newline at end of file +}) \ No newline at end of file diff --git a/electron app/resources/datpart/package.json b/electron app/resources/datpart/package.json index 984a1c1..971faba 100644 --- a/electron app/resources/datpart/package.json +++ b/electron app/resources/datpart/package.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/HughIsaacs2/DatPart.git" }, - "version": "0.0.5", + "version": "0.0.6", "author": "Hugh Isaacs II ", "license": "MIT", "main": "launch.js", diff --git a/electron app/resources/datpart/server_script.js b/electron app/resources/datpart/server_script.js index a660021..3214f31 100644 --- a/electron app/resources/datpart/server_script.js +++ b/electron app/resources/datpart/server_script.js @@ -1,27 +1,93 @@ "use strict"; - // content of index.js - const {shell} = require('electron'); - const http = require('http'); - var dat = require('dat-node'); + // content of index.js + const {shell} = require('electron'); + const http = require('http'); + const url = require("url"); + const path = require("path"); + const dat = require('dat-node'); + const fs = require('fs') - var host = "127.0.0.1"; - var port = "9989"; - - var serverSocketId = null; - var filesMap = {}; - - var rootDir = null; - var packDir = null; - - //var versionNumber = app.getVersion(); - //var appName = app.getName(); - //var appIcon = __dirname+'/logo_128.png'; - //app.getAppPath() + var host = "127.0.0.1"; + var port = "9989"; + + var mimeTypes = { + //text formats + "html": "text/html", + "xhtml": "application/xhtml+xml", + "js": "text/javascript", + "css": "text/css", + "txt": "text/plain", + "appcache": "text/cache-manifest", + "htc": "text/x-component", + //image formats + "svg": "image/svg+xml", + "svgz": "image/svg+xml", + "jpeg": "image/jpeg", + "jpg": "image/jpeg", + "png": "image/png", + "apng": "image/png", + "webp": "image/webp", + "gif": "image/gif", + "ico": "image/x-icon", + //font formats + "woff": "application/font-woff", + "woff2": "font/woff2", + "ttf": "application/x-font-ttf", + "ttc": "application/x-font-ttf", + "otf": "font/opentype", + "eot": "application/vnd.ms-fontobject", + //video formats + "webm": "video/webm", + "mp4": "video/mp4", + "m4v": "video/m4v", + "ogv": "video/ogg", + //audio formats + "ogg": "audio/ogg", + "oga": "audio/ogg", + "aac": "audio/x-aac", + "mp3": "audio/mpeg", + "weba": "audio/webm", + //application file formats + "wasm": "application/wasm", + "nexe": "application/x-nacl", + "xml": "application/xml", + "json": "application/json", + "map": "application/json", + "rss": "application/rss+xml", + "atom": "application/atom+xml", + "opensearchxml": "application/opensearchdescription+xml", + "torrent": "application/x-bittorrent", + "webmanifest": "application/manifest+json", + //browser extension file formats + "crx": "application/x-chrome-extension", + "xpi": "application/x-xpinstall", + "nex": "application/x-navigator-extension", + //plugin file formats + "swf": "application/x-shockwave-flash", + "xap": "application/x-silverlight-app", + "unity3d": "application/vnd.unity", + "jar": "application/java-archive", + "class": "application/x-java-applet", + //random Misc + "webapp": "application/x-web-app-manifest+json", + "pdf": "application/pdf", + "ics": "text/calendar", + "pkpass": "application/vnd.apple.pkpass", + "mobileconfig": "application/x-apple-aspen-config", + "prs": "application/x-psp-radio-skin", + "p3t": "application/x-ps3-theme", + "ptf": "application/x-psp-theme", + "pbp": "application/x-psp-game" + }; - document.querySelectorAll("a.external-link").forEach(function (el) { - el.onclick = function(){shell.openExternal(el.href);return false;}; - }); + document.querySelectorAll("a.external-link").forEach(function (el) { + el.onclick = function(){shell.openExternal(el.href);return false;}; + }); + + if (!fs.existsSync(__dirname + '/../../dats/')) { + fs.mkdirSync(__dirname + '/../../dats/'); + } const requestHandler = (request, response) => { console.log(request.url); @@ -39,11 +105,21 @@ const requestHandler = (request, response) => { console.log("TLD: " + currentTLD + " Hash: " + currentURLhostNoTLD); /* if(currentTLD == 'dat_site') { - fileSearch = "/dat/" + currentURLhostNoTLD + currentURLRequest.pathname; + fileSearch = "/dats/" + currentURLhostNoTLD + currentURLRequest.pathname; console.log(fileSearch); } */ - + var uri = url.parse(request.url).pathname, + filename = path.join(process.cwd(), uri); + + var mimeType = mimeTypes[filename.split('.').pop()]; + + if (!mimeType) { + mimeType = 'text/plain'; + } + +if(currentTLD == 'dat_site' && fs.existsSync(__dirname + "/../../dats/")) { + dat( __dirname + '/../../dats/'+currentURLhostNoTLD, { // 2. Tell Dat what link I want key: currentURLhostNoTLD, temp: false, sparse: true // (a 64 character hash from above) @@ -65,6 +141,7 @@ if (lastChar == '/') { // If the last character is not a slash dat.archive.readFile(fileSearch+'/index.html', function (err, content) { console.log(content); + response.writeHead(200, { "Content-Type": "text/html" }); response.end(content); if (err) {throw err;console.log(err)} }); @@ -73,6 +150,7 @@ if (lastChar == '/') { // If the last character is not a slash dat.archive.readFile(fileSearch, function (err, content) { console.log(content); + response.writeHead(200, { "Content-Type": mimeType }); response.end(content); if (err) {throw err;console.log(err)} }); @@ -81,6 +159,29 @@ if (lastChar == '/') { // If the last character is not a slash }); +} else if(fs.existsSync(__dirname + "/../../dats/")) { + +console.log(request.url); + + var currentURLRequest = document.createElement('a'); + currentURLRequest.href = request.url; + + var currentTLD = currentURLRequest.hostname.split(".").pop(); + var currentURLhostNoTLD = currentURLRequest.hostname.split(".")[0]; + + var fileSearch = currentURLRequest.pathname; + + console.log(fileSearch); + + console.log("TLD: " + currentTLD + " Hash: " + currentURLhostNoTLD); + +} else { + + fs.mkdirSync(appPath + "/dats/"); + console.log(request.url); + +} + }; const server = http.createServer(requestHandler); diff --git a/electron app/resources/datpart/version b/electron app/resources/datpart/version deleted file mode 100644 index 01990b4..0000000 --- a/electron app/resources/datpart/version +++ /dev/null @@ -1 +0,0 @@ -v1.7.9 \ No newline at end of file diff --git a/electron app/resources/datpart/webtorrent.min.js b/electron app/resources/datpart/webtorrent.min.js deleted file mode 100644 index 6edb33a..0000000 --- a/electron app/resources/datpart/webtorrent.min.js +++ /dev/null @@ -1,2 +0,0 @@ -(function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"==typeof window?"undefined"==typeof global?"undefined"==typeof self?this:self:global:window,t.WebTorrent=e()}})(function(){var t=Math.pow,r=Math.floor,o=Math.abs,e=String.fromCharCode,s=Math.ceil,n=Math.max,d=Math.min,i;return function d(c,e,t){function r(s,o){if(!e[s]){if(!c[s]){var i="function"==typeof require&&require;if(!o&&i)return i(s,!0);if(n)return n(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var p=e[s]={exports:{}};c[s][0].call(p.exports,function(t){var e=c[s][1][t];return r(e?e:t)},p,p.exports,d,c,e,t)}return e[s].exports}for(var n="function"==typeof require&&require,s=0;se||t2*(r._numConns-r.numPeers)&&e.amInterested?e.destroy():(o=setTimeout(t,z),o.unref&&o.unref()))}function n(){if(e.peerPieces.buffer.length===r.bitfield.buffer.length){for(s=0;s131072?e.destroy():void(r.pieces[t]||r.store.get(t,{offset:n,length:o},s))}),e.bitfield(r.bitfield),e.interested(),e.peerExtensions.dht&&r.client.dht&&r.client.dht.listening&&e.port(r.client.dht.address().port),"webSeed"!==e.type&&(o=setTimeout(t,z),o.unref&&o.unref()),e.isSeeder=!1,n()},i.prototype._updateSelections=function(){var e=this;!e.ready||e.destroyed||(r.nextTick(function(){e._gcSelections()}),e._updateInterest(),e._update())},i.prototype._gcSelections=function(){for(var e=this,t=0;t=t&&s<=n&&!(s in r)&&e.peerPieces.get(s)&&(!o||o(s))}}function r(){if(!e.requests.length)for(var n=d._selections.length;n--;){var r=d._selections[n],o;if("rarest"===d.strategy)for(var s=r.from+r.offset,i=r.to,a={},c=0,p=t(s,i,a);co));){if(d._request(e,o,!1))return;a[o]=!0,c+=1}else for(o=r.to;o>=r.from+r.offset;--o)if(e.peerPieces.get(o)&&d._request(e,o,!1))return}}function o(){var t=e.downloadSpeed()||1;if(t>V)return function(){return!0};var r=n(1,e.requests.length)*U.BLOCK_LENGTH/t,o=10,s=0;return function(e){if(!o||d.bitfield.get(e))return!0;for(var n=d.pieces[e].missing;s=p)return!0;for(var r=o(),a=0;ac));){for(;d._request(e,c,d._critical[c]||n););if(e.requests.length=c)){var p=a(e,G);i(!1)||i(!0)}}},i.prototype._rechoke=function(){function e(e,t){return e.downloadSpeed===t.downloadSpeed?e.uploadSpeed===t.uploadSpeed?e.wire.amChoking===t.wire.amChoking?e.salt-t.salt:e.wire.amChoking?1:-1:t.uploadSpeed-e.uploadSpeed:t.downloadSpeed-e.downloadSpeed}var t=this;if(t.ready){0=V||2*p>o||p>d||(a=i,d=p)}}if(!a)return!1;for(c=0;c=u)return!1;var f=s.pieces[t],h=l?f.reserveRemaining():f.reserve();if(-1===h&&n&&s._hotswap(e,t)&&(h=l?f.reserveRemaining():f.reserve()),-1===h)return!1;var m=s._reservations[t];m||(m=s._reservations[t]=[]);var g=m.indexOf(null);-1===g&&(g=m.length),m[g]=e;var i=f.chunkOffset(h),_=l?f.chunkLengthRemaining(h):f.chunkLength(h);return e.request(t,i,_,function n(r,d){if(!s.destroyed){if(!s.ready)return s.once("ready",function(){n(r,d)});if(m[g]===e&&(m[g]=null),f!==s.pieces[t])return o();if(r)return s._debug("error getting piece %s (offset: %s length: %s) from %s: %s",t,i,_,e.remoteAddress+":"+e.remotePort,r.message),l?f.cancelRemaining(h):f.cancel(h),void o();if(s._debug("got piece %s (offset: %s length: %s) from %s",t,i,_,e.remoteAddress+":"+e.remotePort),!f.set(h,d,e))return o();var a=f.flush();O(a,function(e){if(!s.destroyed){if(e===s._hashes[t]){if(!s.pieces[t])return;s._debug("piece verified %s",t),s.pieces[t]=null,s._reservations[t]=null,s.bitfield.set(t,!0),s.store.put(t,a),s.wires.forEach(function(e){e.have(t)}),s._checkDone()&&!s.destroyed&&s.discovery.complete()}else s.pieces[t]=new U(f.length),s.emit("warning",new Error("Piece "+t+" failed verification"));o()}})}}),!0},i.prototype._checkDone=function(){var e=this;if(!e.destroyed){e.files.forEach(function(t){if(!t.done){for(var n=t._startPiece;n<=t._endPiece;++n)if(!e.bitfield.get(n))return;t.done=!0,t.emit("done"),e._debug("file done: "+t.name)}});for(var t=!0,n=0,r;n=e.client.maxConns)){this._debug("drain (%s queued, %s/%s peers)",e._numQueued,e.numPeers,e.client.maxConns);var t=e._queue.shift();if(t){this._debug("tcp connect attempt to %s",t.addr);var n=u(t.addr),r={host:n[0],port:n[1]},o=t.conn=E.connect(r);o.once("connect",function(){t.onConnect()}),o.once("error",function(e){t.destroy(e)}),t.startConnectTimeout(),o.on("close",function(){if(!e.destroyed){if(t.retries>=X.length)return void e._debug("conn %s closed: will not re-add (max %s attempts)",t.addr,X.length);var n=X[t.retries];e._debug("conn %s closed: will re-add to queue in %sms (attempt %s)",t.addr,n,t.retries+1);var r=setTimeout(function(){var n=e._addPeer(t.addr);n&&(n.retries=t.retries+1)},n);r.unref&&r.unref()}})}}},i.prototype._validAddr=function(e){var t;try{t=u(e)}catch(t){return!1}var n=t[0],r=t[1];return 0r&&("127.0.0.1"!==n||r!==this.client.torrentPort)}}).call(this,e("_process"),"undefined"==typeof global?"undefined"==typeof self?"undefined"==typeof window?{}:window:self:global)},{"../package.json":136,"./file":2,"./peer":3,"./rarity-map":4,"./server":25,_process:69,"addr-to-ip-port":7,bitfield:13,"chunk-store-stream/write":29,debug:33,events:37,fs:26,"fs-chunk-store":53,"immediate-chunk-store":43,inherits:44,multistream:61,net:25,os:25,"parse-torrent":65,path:66,pump:70,"random-iterate":75,"run-parallel":92,"run-parallel-limit":91,"simple-get":96,"simple-sha1":100,speedometer:104,"torrent-discovery":116,"torrent-piece":119,uniq:122,ut_metadata:126,ut_pex:25,xtend:133,"xtend/mutable":134}],6:[function(e,t){function r(e,t){l.call(this),this.url=e,this.webPeerId=p.sync(e),this._torrent=t,this._init()}t.exports=r;var o=e("bitfield"),s=e("safe-buffer").Buffer,i=e("debug")("webtorrent:webconn"),a=e("simple-get"),c=e("inherits"),p=e("simple-sha1"),l=e("bittorrent-protocol"),u=e("../package.json").version;c(r,l),r.prototype._init=function(){var e=this;e.setKeepAlive(!0),e.once("handshake",function(t){if(!e.destroyed){e.handshake(t,e.webPeerId);for(var n=e._torrent.pieces.length,r=new o(n),s=0;s<=n;s++)r.set(s,!0);e.bitfield(r)}}),e.once("interested",function(){i("interested"),e.unchoke()}),e.on("uninterested",function(){i("uninterested")}),e.on("choke",function(){i("choke")}),e.on("unchoke",function(){i("unchoke")}),e.on("bitfield",function(){i("bitfield")}),e.on("request",function(t,n,r,o){i("request pieceIndex=%d offset=%d length=%d",t,n,r),e.httpRequest(t,n,r,o)})},r.prototype.httpRequest=function(e,t,r,o){var c=this,p=e*c._torrent.pieceLength,l=p+t,f=l+r-1,h=c._torrent.files,m;if(1>=h.length)m=[{url:c.url,start:l,end:f}];else{var g=h.filter(function(e){return e.offset<=f&&e.offset+e.length>l});if(1>g.length)return o(new Error("Could not find file corresponnding to web seed range request"));m=g.map(function(e){var t=e.offset+e.length-1,r=c.url+("/"===c.url[c.url.length-1]?"":"/")+e.path;return{url:r,fileOffsetInRange:n(e.offset-l,0),start:n(l-e.offset,0),end:d(t,f-e.offset)}})}var _=0,y=!1,b;1e.statusCode||300<=e.statusCode?(y=!0,o(new Error("Unexpected HTTP status code "+e.statusCode))):void(i("Got data of length %d",t.length),1===m.length?o(null,t):(t.copy(b,n.fileOffsetInRange),++_===m.length&&o(null,b)))}var d=n.url,c=n.start,p=n.end;i("Requesting url=%s pieceIndex=%d offset=%d length=%d start=%d end=%d",d,e,t,r,c,p);var l={url:d,method:"GET",headers:{"user-agent":"WebTorrent/"+u+" (https://webtorrent.io)",range:"bytes="+c+"-"+p}};a.concat(l,function(e,t,n){return y?void 0:e?"undefined"==typeof window||d.startsWith(window.location.origin+"/")?(y=!0,o(e)):a.head(d,function(t,n){return y?void 0:t?(y=!0,o(t)):200>n.statusCode||300<=n.statusCode?(y=!0,o(new Error("Unexpected HTTP status code "+n.statusCode))):n.url===d?(y=!0,o(e)):void(l.url=n.url,a.concat(l,function(e,t,n){return y?void 0:e?(y=!0,o(e)):void s(t,n)}))}):void s(t,n)})})},r.prototype.destroy=function(){l.prototype.destroy.call(this),this._torrent=null}},{"../package.json":136,bitfield:13,"bittorrent-protocol":14,debug:33,inherits:44,"safe-buffer":94,"simple-get":96,"simple-sha1":100}],7:[function(e,t){var n=/^\[?([^\]]+)\]?:(\d+)$/,r={},o=0;t.exports=function(e){if(1e5==o&&t.exports.reset(),!r[e]){var s=n.exec(e);if(!s)throw new Error("invalid addr: "+e);r[e]=[s[1],+s[2]],o+=1}return r[e]},t.exports.reset=function(){r={},o=0}},{}],8:[function(e,t,n){"use strict";function r(e){var t=e.length;if(0>18]+d[63&e>>12]+d[63&e>>6]+d[63&e]}function s(e,t,n){for(var r=[],s=t,i;s>16,d[p++]=255&s>>8,d[p++]=255&s;return 2===i?(s=a[e.charCodeAt(n)]<<2|a[e.charCodeAt(n+1)]>>4,d[p++]=255&s):1===i&&(s=a[e.charCodeAt(n)]<<10|a[e.charCodeAt(n+1)]<<4|a[e.charCodeAt(n+2)]>>2,d[p++]=255&s>>8,d[p++]=255&s),d},n.fromByteArray=function(e){for(var t=e.length,n=t%3,r="",o=[],a=16383,c=0,i=t-n,p;ci?i:c+a));return 1==n?(p=e[t-1],r+=d[p>>2],r+=d[63&p<<4],r+="=="):2==n&&(p=(e[t-2]<<8)+e[t-1],r+=d[p>>10],r+=d[63&p>>4],r+=d[63&p<<2],r+="="),o.push(r),o.join("")};for(var d=[],a=[],c="undefined"==typeof Uint8Array?Array:Uint8Array,p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=0,i=p.length;li&&48<=i){r=10*r+(i-48);continue}if(s!==t||43!==i){if(s===t&&45===i){o=-1;continue}if(46===i)break;throw new Error("not a number: buffer["+s+"] = "+i)}}return r*o}function o(e,n,r,s){return null==e||0===e.length?null:("number"!=typeof n&&null==s&&(s=n,n=void 0),"number"!=typeof r&&null==s&&(s=r,r=void 0),o.position=0,o.encoding=s||null,o.data=t.isBuffer(e)?e.slice(n,r):new t(e),o.bytes=o.data.length,o.next())}const s=101;o.bytes=0,o.position=0,o.data=null,o.encoding=null,o.next=function(){switch(o.data[o.position]){case 100:return o.dictionary();case 108:return o.list();case 105:return o.integer();default:return o.buffer();}},o.find=function(t){for(var n=o.position,r=o.data.length,s=o.data;nr||r>=e.length)throw new RangeError("invalid lower bound");if(void 0===o)o=e.length-1;else if(o|=0,o=e.length)throw new RangeError("invalid upper bound");for(;r<=o;)if(s=r+(o-r>>1),i=+n(e[s],t,s,e),0>i)r=s+1;else if(0>3;return 0!=e%8&&t++,t}var s="undefined"==typeof e?"undefined"==typeof Int8Array?function(e){for(var t=Array(e),n=0;n>3;return t>e%8)},r.prototype.set=function(e,t){var r=e>>3;t||1===arguments.length?(this.buffer.length>e%8):r>e%8))},r.prototype._grow=function(e){if(this.buffer.length=this._parserSize;){var r=1===this._buffer.length?this._buffer[0]:a.concat(this._buffer);this._bufferSize-=this._parserSize,this._buffer=this._bufferSize?[r.slice(this._parserSize)]:[],this._parser(r.slice(0,this._parserSize))}n(null)},r.prototype._callback=function(e,t,n){e&&(this._clearTimeout(),!this.peerChoking&&!this._finished&&this._updateTimeout(),e.callback(t,n))},r.prototype._clearTimeout=function(){this._timeout&&(clearTimeout(this._timeout),this._timeout=null)},r.prototype._updateTimeout=function(){var e=this;e._timeoutMs&&e.requests.length&&!e._timeout&&(e._timeout=setTimeout(function(){e._onTimeout()},e._timeoutMs),e._timeoutUnref&&e._timeout.unref&&e._timeout.unref())},r.prototype._parse=function(e,t){this._parserSize=e,this._parser=t},r.prototype._onMessageLength=function(e){var t=e.readUInt32BE(0);0=this.size;){var o=n.concat(this._buffered);this._bufferedBytes-=this.size,this.push(o.slice(0,this.size)),this._buffered=[o.slice(this.size,o.length)]}r()},r.prototype._flush=function(){if(this._bufferedBytes&&this._zeroPadding){var e=new n(this.size-this._bufferedBytes);e.fill(0),this._buffered.push(e),this.push(n.concat(this._buffered)),this._buffered=null}else this._bufferedBytes&&(this.push(n.concat(this._buffered)),this._buffered=null);this.push(null)}}).call(this,e("buffer").Buffer)},{buffer:27,defined:35,inherits:44,"readable-stream":86}],25:[function(){},{}],26:[function(e,t,n){arguments[4][25][0].apply(n,arguments)},{dup:25}],27:[function(n,r,o){"use strict";function s(e){if(e>Q)throw new RangeError("Invalid typed array length");var t=new Uint8Array(e);return t.__proto__=c.prototype,t}function c(e,t,n){if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return l(e)}return i(e,t,n)}function i(e,t,n){if("number"==typeof e)throw new TypeError("\"value\" argument must not be a number");return e instanceof ArrayBuffer?h(e,t,n):"string"==typeof e?u(e,t):m(e)}function a(e){if("number"!=typeof e)throw new TypeError("\"size\" argument must be a number");else if(0>e)throw new RangeError("\"size\" argument must not be negative")}function p(e,t,n){return a(e),0>=e?s(e):void 0===t?s(e):"string"==typeof n?s(e).fill(t,n):s(e).fill(t)}function l(e){return a(e),s(0>e?0:0|g(e))}function u(e,t){if(("string"!=typeof t||""===t)&&(t="utf8"),!c.isEncoding(t))throw new TypeError("\"encoding\" must be a valid string encoding");var n=0|_(e,t),r=s(n),o=r.write(e,t);return o!==n&&(r=r.slice(0,o)),r}function f(e){for(var t=0>e.length?0:0|g(e.length),n=s(t),r=0;rt||e.byteLength=Q)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Q.toString(16)+" bytes");return 0|e}function _(e,t){if(c.isBuffer(e))return e.length;if(K(e)||e instanceof ArrayBuffer)return e.byteLength;"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return D(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return V(e).length;default:if(r)return D(e).length;t=(""+t).toLowerCase(),r=!0;}}function y(e,t,n){var r=!1;if((void 0===t||0>t)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),0>=n)return"";if(n>>>=0,t>>>=0,n<=t)return"";for(e||(e="utf8");;)switch(e){case"hex":return R(this,t,n);case"utf8":case"utf-8":return L(this,t,n);case"ascii":return A(this,t,n);case"latin1":case"binary":return U(this,t,n);case"base64":return I(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0;}}function b(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function w(e,t,n,r,o){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):2147483647n&&(n=-2147483648),n=+n,X(n)&&(n=o?0:e.length-1),0>n&&(n=e.length+n),n>=e.length){if(o)return-1;n=e.length-1}else if(0>n)if(o)n=0;else return-1;if("string"==typeof t&&(t=c.from(t,r)),c.isBuffer(t))return 0===t.length?-1:k(e,t,n,r,o);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):k(e,[t],n,r,o);throw new TypeError("val must be string, number or Buffer")}function k(e,t,n,r,o){function s(e,t){return 1==d?e[t]:e.readUInt16BE(t*d)}var d=1,a=e.length,c=t.length;if(void 0!==r&&(r=(r+"").toLowerCase(),"ucs2"===r||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(2>e.length||2>t.length)return-1;d=2,a/=2,c/=2,n/=2}var p;if(o){var i=-1;for(p=n;pa&&(n=a-c),p=n;0<=p;p--){for(var l=!0,u=0;uo&&(r=o)):r=o;var s=t.length;if(0!=s%2)throw new TypeError("Invalid hex string");r>s/2&&(r=s/2);for(var d=0,i;ds&&(i=s):2==a?(c=e[o+1],128==(192&c)&&(u=(31&s)<<6|63&c,127u||57343u&&(i=u))):void 0}null===i?(i=65533,a=1):65535>>10),i=56320|1023&i),r.push(i),o+=a}return T(r)}function T(t){var n=t.length;if(n<=J)return e.apply(String,t);for(var r="",o=0;ot)&&(t=0),(!n||0>n||n>r)&&(n=r);for(var o="",s=t;se)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function H(e,t,n,r,o,s){if(!c.isBuffer(e))throw new TypeError("\"buffer\" argument must be a Buffer instance");if(t>o||te.length)throw new RangeError("Index out of range")}function M(e,t,n,r){if(n+r>e.length)throw new RangeError("Index out of range");if(0>n)throw new RangeError("Index out of range")}function q(e,t,n,r,o){return t=+t,n>>>=0,o||M(e,t,n,4,3.4028234663852886e38,-3.4028234663852886e38),$.write(e,t,n,r,23,4),n+4}function j(e,t,n,r,o){return t=+t,n>>>=0,o||M(e,t,n,8,1.7976931348623157e308,-1.7976931348623157e308),$.write(e,t,n,r,52,8),n+8}function N(e){if(e=e.trim().replace(Z,""),2>e.length)return"";for(;0!=e.length%4;)e+="=";return e}function F(e){return 16>e?"0"+e.toString(16):e.toString(16)}function D(e,t){t=t||Infinity;for(var n=e.length,r=null,o=[],s=0,i;si){if(!r){if(56319i){-1<(t-=3)&&o.push(239,191,189),r=i;continue}i=(r-55296<<10|i-56320)+65536}else r&&-1<(t-=3)&&o.push(239,191,189);if(r=null,128>i){if(0>(t-=1))break;o.push(i)}else if(2048>i){if(0>(t-=2))break;o.push(192|i>>6,128|63&i)}else if(65536>i){if(0>(t-=3))break;o.push(224|i>>12,128|63&i>>6,128|63&i)}else if(1114112>i){if(0>(t-=4))break;o.push(240|i>>18,128|63&i>>12,128|63&i>>6,128|63&i)}else throw new Error("Invalid code point")}return o}function W(e){for(var t=[],n=0;n(t-=2));++r)o=e.charCodeAt(r),s=o>>8,i=o%256,n.push(i),n.push(s);return n}function V(e){return Y.toByteArray(N(e))}function G(e,t,n,r){for(var o=0;o=t.length||o>=e.length);++o)t[o+n]=e[o];return o}function K(e){return"function"==typeof ArrayBuffer.isView&&ArrayBuffer.isView(e)}function X(e){return e!==e}var Y=n("base64-js"),$=n("ieee754");o.Buffer=c,o.SlowBuffer=function(e){return+e!=e&&(e=0),c.alloc(+e)},o.INSPECT_MAX_BYTES=50;var Q=2147483647;o.kMaxLength=Q,c.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(t){return!1}}(),c.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),"undefined"!=typeof Symbol&&Symbol.species&&c[Symbol.species]===c&&Object.defineProperty(c,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),c.poolSize=8192,c.from=function(e,t,n){return i(e,t,n)},c.prototype.__proto__=Uint8Array.prototype,c.__proto__=Uint8Array,c.alloc=function(e,t,n){return p(e,t,n)},c.allocUnsafe=function(e){return l(e)},c.allocUnsafeSlow=function(e){return l(e)},c.isBuffer=function(e){return null!=e&&!0===e._isBuffer},c.compare=function(e,t){if(!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,o=0,s=d(n,r);ot&&(e+=" ... ")),""},c.prototype.compare=function(e,t,n,r,o){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),0>t||n>e.length||0>r||o>this.length)throw new RangeError("out of range index");if(r>=o&&t>=n)return 0;if(r>=o)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,r>>>=0,o>>>=0,this===e)return 0;for(var s=o-r,a=n-t,p=d(s,a),l=this.slice(r,o),u=e.slice(t,n),f=0;f>>=0,isFinite(n)?(n>>>=0,void 0===r&&(r="utf8")):(r=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var o=this.length-t;if((void 0===n||n>o)&&(n=o),0n||0>t)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var s=!1;;)switch(r){case"hex":return x(this,e,t,n);case"utf8":case"utf-8":return v(this,e,t,n);case"ascii":return S(this,e,t,n);case"latin1":case"binary":return C(this,e,t,n);case"base64":return E(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0;}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var J=4096;c.prototype.slice=function(e,t){var n=this.length;e=~~e,t=void 0===t?n:~~t,0>e?(e+=n,0>e&&(e=0)):e>n&&(e=n),0>t?(t+=n,0>t&&(t=0)):t>n&&(t=n),t>>=0,t>>>=0,n||O(e,t,this.length);for(var r=this[e],o=1,s=0;++s>>=0,t>>>=0,n||O(e,t,this.length);for(var r=this[e+--t],o=1;0>>=0,t||O(e,1,this.length),this[e]},c.prototype.readUInt16LE=function(e,t){return e>>>=0,t||O(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUInt16BE=function(e,t){return e>>>=0,t||O(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUInt32LE=function(e,t){return e>>>=0,t||O(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUInt32BE=function(e,t){return e>>>=0,t||O(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readIntLE=function(e,n,r){e>>>=0,n>>>=0,r||O(e,n,this.length);for(var o=this[e],s=1,d=0;++d=s&&(o-=t(2,8*n)),o},c.prototype.readIntBE=function(e,n,r){e>>>=0,n>>>=0,r||O(e,n,this.length);for(var o=n,s=1,i=this[e+--o];0=s&&(i-=t(2,8*n)),i},c.prototype.readInt8=function(e,t){return e>>>=0,t||O(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){e>>>=0,t||O(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt16BE=function(e,t){e>>>=0,t||O(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt32LE=function(e,t){return e>>>=0,t||O(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return e>>>=0,t||O(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readFloatLE=function(e,t){return e>>>=0,t||O(e,4,this.length),$.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return e>>>=0,t||O(e,4,this.length),$.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return e>>>=0,t||O(e,8,this.length),$.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return e>>>=0,t||O(e,8,this.length),$.read(this,e,!1,52,8)},c.prototype.writeUIntLE=function(e,n,r,o){if(e=+e,n>>>=0,r>>>=0,!o){var s=t(2,8*r)-1;H(this,e,n,r,s,0)}var d=1,a=0;for(this[n]=255&e;++a>>=0,r>>>=0,!o){var s=t(2,8*r)-1;H(this,e,n,r,s,0)}var d=r-1,i=1;for(this[n+d]=255&e;0<=--d&&(i*=256);)this[n+d]=255&e/i;return n+r},c.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||H(this,e,t,1,255,0),this[t]=255&e,t+1},c.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||H(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||H(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||H(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},c.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||H(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeIntLE=function(e,n,r,o){if(e=+e,n>>>=0,!o){var s=t(2,8*r-1);H(this,e,n,r,s-1,-s)}var d=0,i=1,a=0;for(this[n]=255&e;++de&&0==a&&0!==this[n+d-1]&&(a=1),this[n+d]=255&(e/i>>0)-a;return n+r},c.prototype.writeIntBE=function(e,n,r,o){if(e=+e,n>>>=0,!o){var s=t(2,8*r-1);H(this,e,n,r,s-1,-s)}var d=r-1,i=1,a=0;for(this[n+d]=255&e;0<=--d&&(i*=256);)0>e&&0==a&&0!==this[n+d+1]&&(a=1),this[n+d]=255&(e/i>>0)-a;return n+r},c.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||H(this,e,t,1,127,-128),0>e&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||H(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||H(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||H(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},c.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||H(this,e,t,4,2147483647,-2147483648),0>e&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeFloatLE=function(e,t,n){return q(this,e,t,!0,n)},c.prototype.writeFloatBE=function(e,t,n){return q(this,e,t,!1,n)},c.prototype.writeDoubleLE=function(e,t,n){return j(this,e,t,!0,n)},c.prototype.writeDoubleBE=function(e,t,n){return j(this,e,t,!1,n)},c.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),0t)throw new RangeError("targetStart out of bounds");if(0>n||n>=this.length)throw new RangeError("sourceStart out of bounds");if(0>r)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-to)for(s=0;so&&(e=o)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!c.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof e&&(e&=255);if(0>t||this.length>>=0,n=n===void 0?this.length:n>>>0,e||(e=0);var s;if("number"==typeof e)for(s=t;s>1),c=t[a]-e,0>c?s=a+1:0t.path.length?d=null:0===n&&1e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,o,a,c,i;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length))if(t=arguments[1],t instanceof Error)throw t;else{var p=new Error("Uncaught, unspecified \"error\" event. ("+t+")");throw p.context=t,p}if(n=this._events[e],d(n))return!1;if(r(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),n.apply(this,a);}else if(s(n))for(a=Array.prototype.slice.call(arguments,1),i=n.slice(),o=i.length,c=0;co&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),o||(o=!0,t.apply(this,arguments))}if(!r(t))throw TypeError("listener must be a function");var o=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,o,d,a;if(!r(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],d=n.length,o=-1,n===t||r(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(n)){for(a=d;0o)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],r(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?r(this._events[e])?[this._events[e]]:this._events[e].slice():[],t},n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(r(t))return 1;if(t)return t.length}return 0},n.listenerCount=function(e,t){return e.listenerCount(t)}},{}],38:[function(e,t){function r(e,t){var s=this;return this instanceof r?void(t=t||{},o.call(this,t),this._offset=0,this._ready=!1,this._file=e,this._size=e.size,this._chunkSize=t.chunkSize||n(this._size/1e3,204800),this.reader=new FileReader,this._generateHeaderBlocks(e,t,function(e,t){return e?s.emit("error",e):void(Array.isArray(t)&&t.forEach(function(e){s.push(e)}),s._ready=!0,s.emit("_ready"))})):new r(e,t)}var o=e("readable-stream").Readable,s=e("inherits"),i=/^.*\.(\w+)$/,d=e("typedarray-to-buffer");s(r,o),t.exports=r,r.prototype._generateHeaderBlocks=function(e,t,n){n(null,[])},r.prototype._read=function(){if(!this._ready)return void this.once("_ready",this._read.bind(this));var e=this,t=this.reader,n=this._offset,r=this._offset+this._chunkSize;return r>this._size&&(r=this._size),n===this._size?(this.destroy(),void this.push(null)):void(t.onload=function(){e._offset=r,e.push(d(t.result))},t.onerror=function(){e.emit("error",t.error)},t.readAsArrayBuffer(this._file.slice(n,r)))},r.prototype.destroy=function(){if(this._file=null,this.reader){this.reader.onload=null,this.reader.onerror=null;try{this.reader.abort()}catch(t){}}this.reader=null}},{inherits:44,"readable-stream":86,"typedarray-to-buffer":120}],39:[function(e,t){t.exports=function(e,t){function n(e,r){return e.reduce(function(e,o){return Array.isArray(o)&&r>1,f=-7,h=o?c-1:0,i=o?-1:1,d=n[r+h],s,e;for(h+=i,s=d&(1<<-f)-1,d>>=-f,f+=p;0>=-f,f+=a;0>1,y=23===u?5.960464477539063e-8-6.617444900424222e-24:0,b=l?0:f-1,i=l?1:-1,d=0>a||0===a&&0>1/a?1:0,s,w,m;for(a=o(a),isNaN(a)||a===Infinity?(w=isNaN(a)?1:0,s=g):(s=r(Math.log(a)/Math.LN2),1>a*(m=t(2,-s))&&(s--,m*=2),a+=1<=s+_?y/m:y*t(2,1-_),2<=a*m&&(s++,m/=2),s+_>=g?(w=0,s=g):1<=s+_?(w=(a*m-1)*t(2,u),s+=_):(w=a*t(2,_-1)*t(2,u),s=0));8<=u;n[p+b]=255&w,b+=i,w/=256,u-=8);for(s=s<127)return!1;return!0}},{}],46:[function(e,t){function n(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function r(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&n(e.slice(0,0))}t.exports=function(e){return null!=e&&(n(e)||r(e)||!!e._isBuffer)}},{}],47:[function(e,t){"use strict";function n(e){return r.existsSync(e)&&r.statSync(e).isFile()}var r=e("fs");t.exports=function(e,t){return t?void r.stat(e,function(e,n){return e?t(e):t(null,n.isFile())}):n(e)},t.exports.sync=n},{fs:26}],48:[function(e,t){function n(e){return r(e)||o(e)}function r(e){return e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array}function o(e){return i[s.call(e)]}t.exports=n,n.strict=r,n.loose=o;var s=Object.prototype.toString,i={"[object Int8Array]":!0,"[object Int16Array]":!0,"[object Int32Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Uint16Array]":!0,"[object Uint32Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0}},{}],49:[function(e,t){var n={}.toString;t.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},{}],50:[function(e,t,n){"use strict";n.regex=n.re=/^npm-debug\.log$|^\..*\.swp$|^\.DS_Store$|^\.AppleDouble$|^\.LSOverride$|^Icon\r$|^\._.*|^\.Spotlight-V100(?:$|\/)|\.Trashes|^__MACOSX$|~$|^Thumbs\.db$|^ehthumbs\.db$|^Desktop\.ini$|^@eaDir$/,n.is=(e)=>n.re.test(e),n.not=(e)=>!n.is(e)},{}],51:[function(e,t){function n(e){var t={},n=e.split("magnet:?")[1],s=n&&0<=n.length?n.split("&"):[];s.forEach(function(e){var n=e.split("=");if(2===n.length){var r=n[0],o=n[1];if("dn"===r&&(o=decodeURIComponent(o).replace(/\+/g," ")),("tr"===r||"xs"===r||"as"===r||"ws"===r)&&(o=decodeURIComponent(o)),"kt"===r&&(o=decodeURIComponent(o).split("+")),"ix"===r&&(o=+o),!t[r])t[r]=o;else if(Array.isArray(t[r]))t[r].push(o);else{var s=t[r];t[r]=[s,o]}}});var d;if(t.xt){var a=Array.isArray(t.xt)?t.xt:[t.xt];a.forEach(function(e){if(d=e.match(/^urn:btih:(.{40})/))t.infoHash=d[1].toLowerCase();else if(d=e.match(/^urn:btih:(.{32})/)){var n=r.decode(d[1]);t.infoHash=o.from(n,"binary").toString("hex")}})}return t.infoHash&&(t.infoHashBuffer=o.from(t.infoHash,"hex")),t.dn&&(t.name=t.dn),t.kt&&(t.keywords=t.kt),t.announce="string"==typeof t.tr?[t.tr]:Array.isArray(t.tr)?t.tr:[],t.urlList=[],("string"==typeof t.as||Array.isArray(t.as))&&(t.urlList=t.urlList.concat(t.as)),("string"==typeof t.ws||Array.isArray(t.ws))&&(t.urlList=t.urlList.concat(t.ws)),i(t.announce),i(t.urlList),t}t.exports=n,t.exports.decode=n,t.exports.encode=function(e){e=s(e),e.infoHashBuffer&&(e.xt="urn:btih:"+e.infoHashBuffer.toString("hex")),e.infoHash&&(e.xt="urn:btih:"+e.infoHash),e.name&&(e.dn=e.name),e.keywords&&(e.kt=e.keywords),e.announce&&(e.tr=e.announce),e.urlList&&(e.ws=e.urlList,delete e.as);var t="magnet:?";return Object.keys(e).filter(function(e){return 2===e.length}).forEach(function(n,r){var o=Array.isArray(e[n])?e[n]:[e[n]];o.forEach(function(e,o){(0e._bufferDuration)&&e._cb){var t=e._cb;e._cb=null,t()}};r.prototype._getBufferDuration=function(){for(var e=this,t=e._sourceBuffer.buffered,n=e._elem.currentTime,r=-1,o=0;on)break;else(0<=r||n<=i)&&(r=i)}var d=r-n;return 0>d&&(d=0),d}},{inherits:44,"readable-stream":86,"to-arraybuffer":115}],53:[function(e,t){(function(e){function n(e,t){if(!(this instanceof n))return new n(e,t);if(t||(t={}),this.chunkLength=+e,!this.chunkLength)throw new Error("First argument must be a chunk length");this.chunks=[],this.closed=!1,this.length=+t.length||Infinity,this.length!==Infinity&&(this.lastChunkLength=this.length%this.chunkLength||this.chunkLength,this.lastChunkIndex=s(this.length/this.chunkLength)-1)}function r(t,n,r){e.nextTick(function(){t&&t(n,r)})}t.exports=n,n.prototype.put=function(e,t,n){if(this.closed)return r(n,new Error("Storage is closed"));var o=e===this.lastChunkIndex;return o&&t.length!==this.lastChunkLength?r(n,new Error("Last chunk length must be "+this.lastChunkLength)):o||t.length===this.chunkLength?void(this.chunks[e]=t,r(n,null)):r(n,new Error("Chunk length must be "+this.chunkLength))},n.prototype.get=function(e,t,n){if("function"==typeof t)return this.get(e,null,t);if(this.closed)return r(n,new Error("Storage is closed"));var o=this.chunks[e];if(!o)return r(n,new Error("Chunk not found"));if(!t)return r(n,null,o);var s=t.offset||0,i=t.length||o.length-s;r(n,null,o.slice(s,i+s))},n.prototype.close=n.prototype.destroy=function(e){return this.closed?r(e,new Error("Storage is closed")):void(this.closed=!0,this.chunks=null,r(e,null))}}).call(this,e("_process"))},{_process:69}],54:[function(e,t,n){(function(t){function o(e,t,n){for(var r=t;r>3:0,p=null;return d&&(p=d.toString(16),c&&(p+="."+c)),{mimeCodec:p,buffer:new t(e.slice(0))}},n.esds.encodingLength=function(e){return e.buffer.length},n.stsz={},n.stsz.encode=function(e,r,o){var s=e.entries||[];r=r?r.slice(o):t(n.stsz.encodingLength(e)),r.writeUInt32BE(0,0),r.writeUInt32BE(s.length,4);for(var d=0;ds&&(c=1),t.writeUInt32BE(c,n),t.write(e.type,n+4,4,"ascii");var p=n+8;if(1===c&&(r.encode(e.length,t,p),p+=8),o.fullBoxes[a]&&(t.writeUInt32BE(e.flags||0,p),t.writeUInt8(e.version||0,p),p+=4),d[a]){var l=d[a];l.forEach(function(n){if(5===n.length){var r=e[n]||[];n=n.substr(0,4),r.forEach(function(e){i._encode(e,t,p),p+=i.encode.bytes})}else e[n]&&(i._encode(e[n],t,p),p+=i.encode.bytes)}),e.otherBoxes&&e.otherBoxes.forEach(function(e){i._encode(e,t,p),p+=i.encode.bytes})}else if(o[a]){var u=o[a].encode;u(e,t,p),p+=u.bytes}else if(e.buffer){var f=e.buffer;f.copy(t,p),p+=e.buffer.length}else throw new Error("Either `type` must be set to a known type (not'"+a+"') or `buffer` must be set");return i.encode.bytes=p-n,t},i.readHeaders=function(e,t,n){if(t=t||0,n=n||e.length,8>n-t)return 8;var s=e.readUInt32BE(t),i=e.toString("ascii",t+4,t+8),d=t+8;if(1===s){if(16>n-t)return 16;s=r.decode(e,d),d+=8}var a,c;return o.fullBoxes[i]&&(a=e.readUInt8(d),c=16777215&e.readUInt32BE(d),d+=4),{length:s,headersLen:d-t,contentLen:s-(d-t),type:i,version:a,flags:c}},i.decode=function(e,t,n){t=t||0,n=n||e.length;var r=i.readHeaders(e,t,n);if(!r||r.length>n-t)throw new Error("Data too short");return i.decodeWithoutHeaders(r,e,t+r.headersLen,t+r.length)},i.decodeWithoutHeaders=function(e,n,r,s){r=r||0,s=s||n.length;var a=e.type,c={};if(d[a]){c.otherBoxes=[];for(var p=d[a],l=r,u;8<=s-l;)if(u=i.decode(n,l,s),l+=u.length,0<=p.indexOf(u.type))c[u.type]=u;else if(0<=p.indexOf(u.type+"s")){var f=u.type+"s",h=c[f]=c[f]||[];h.push(u)}else c.otherBoxes.push(u)}else if(o[a]){var m=o[a].decode;c=m(n,r,s)}else c.buffer=new t(n.slice(r,s));return c.length=e.length,c.contentLen=e.contentLen,c.type=e.type,c.version=e.version,c.flags=e.flags,c},i.encodingLength=function(e){var t=e.type,n=8;if(o.fullBoxes[t]&&(n+=4),d[t]){var r=d[t];r.forEach(function(t){if(5===t.length){var r=e[t]||[];t=t.substr(0,4),r.forEach(function(e){e.type=t,n+=i.encodingLength(e)})}else if(e[t]){var o=e[t];o.type=t,n+=i.encodingLength(o)}}),e.otherBoxes&&e.otherBoxes.forEach(function(e){n+=i.encodingLength(e)})}else if(o[t])n+=o[t].encodingLength(e);else if(e.buffer)n+=e.buffer.length;else throw new Error("Either `type` must be set to a known type (not'"+t+"') or `buffer` must be set");return n>s&&(n+=8),e.length=n,n}}).call(this,e("buffer").Buffer)},{"./boxes":54,buffer:27,uint64be:121}],57:[function(e,t){(function(n){function r(){return this instanceof r?void(s.Writable.call(this),this.destroyed=!1,this._pending=0,this._missing=0,this._buf=null,this._str=null,this._cb=null,this._ondrain=null,this._writeBuffer=null,this._writeCb=null,this._ondrain=null,this._kick()):new r}function o(e){this._parent=e,this.destroyed=!1,s.PassThrough.call(this)}var s=e("readable-stream"),i=e("inherits"),d=e("next-event"),a=e("mp4-box-encoding"),c=new n(0);t.exports=r,i(r,s.Writable),r.prototype.destroy=function(e){this.destroyed||(this.destroyed=!0,e&&this.emit("error",e),this.emit("close"))},r.prototype._write=function(e,t,n){if(!this.destroyed){for(var r=!this._str||!this._str._writableState.needDrain;e.length&&!this.destroyed;){if(!this._missing)return this._writeBuffer=e,void(this._writeCb=n);var o=e.length=u?t(e/u)+"d":e>=l?t(e/l)+"h":e>=p?t(e/p)+"m":e>=c?t(e/c)+"s":e+"ms"}function i(e){return a(e,u,"day")||a(e,l,"hour")||a(e,p,"minute")||a(e,c,"second")||e+" ms"}function a(e,t,n){return en?[]:e.slice(t,n-t+1)}e=n.resolve(e).substr(1),t=n.resolve(t).substr(1);for(var o=r(e.split("/")),s=r(t.split("/")),a=d(o.length,s.length),c=a,p=0;ps++;)i.push(t(2,s));n.exports=function(e){return r(e/o,i)}},{"closest-to":30}],68:[function(e,t){(function(e){"use strict";t.exports=e.version&&0!==e.version.indexOf("v0.")&&(0!==e.version.indexOf("v1.")||0===e.version.indexOf("v1.8."))?e.nextTick:function(t,n,r,o){if("function"!=typeof t)throw new TypeError("\"callback\" argument must be a function");var s=arguments.length,d,a;switch(s){case 0:case 1:return e.nextTick(t);case 2:return e.nextTick(function(){t.call(null,n)});case 3:return e.nextTick(function(){t.call(null,n,r)});case 4:return e.nextTick(function(){t.call(null,n,r,o)});default:for(d=Array(s-1),a=0;ae.length)throw new Error("pump requires two streams per minimum");var n=e.map(function(o,s){var i=s=o&&n>>10),e=56320|1023&e),t+=O(e),t}).join("")}function u(e){return 10>e-48?e-22:26>e-65?e-65:26>e-97?e-97:v}function f(e,t){return e+22+75*(26>e)-((0!=t)<<5)}function h(e,t,n){var r=0;for(e=n?P(e/E):e>>1,e+=P(e/t);e>R*C>>1;r+=v)e=P(e/R);return P(r+(R+1)*e/(e+w))}function m(e){var r=[],o=e.length,s=0,i=I,n=B,a,c,p,f,m,g,_,y,b,t;for(c=e.lastIndexOf(L),0>c&&(c=0),p=0;p=o&&d("invalid-input"),y=u(e.charCodeAt(f++)),(y>=v||y>P((x-s)/g))&&d("overflow"),s+=y*g,b=_<=n?S:_>=n+C?C:_-n,yP(x/t)&&d("overflow"),g*=t}a=r.length+1,n=h(s-m,a,0==m),P(s/a)>x-i&&d("overflow"),i+=P(s/a),s%=a,r.splice(s++,0,i)}return l(r)}function g(e){var r=[],o,n,s,i,a,c,l,u,m,g,t,_,y,b,w;for(e=p(e),_=e.length,o=I,n=0,a=B,c=0;c<_;++c)t=e[c],128>t&&r.push(O(t));for(s=i=r.length,i&&r.push(L);s<_;){for(l=x,c=0;c<_;++c)t=e[c],t>=o&&tP((x-n)/y)&&d("overflow"),n+=(l-o)*y,o=l,c=0;c<_;++c)if(t=e[c],tx&&d("overflow"),t==o){for(u=n,m=v;;m+=v){if(g=m<=a?S:m>=a+C?C:m-a,u= 0x80 (not a basic code point)","invalid-input":"Invalid input"},R=v-S,P=r,O=e,H,M;if(H={version:"1.4.1",ucs2:{decode:p,encode:l},decode:m,encode:g,toASCII:function(e){return c(e,function(e){return T.test(e)?"xn--"+g(e):e})},toUnicode:function(e){return c(e,function(e){return k.test(e)?m(e.slice(4).toLowerCase()):e})}},"function"==typeof i&&"object"==typeof i.amd&&i.amd)i("punycode",function(){return H});else if(!(_&&y))s.punycode=H;else if(n.exports==_)y.exports=H;else for(M in H)H.hasOwnProperty(M)&&(_[M]=H[M])})(this)}).call(this,"undefined"==typeof global?"undefined"==typeof self?"undefined"==typeof window?{}:window:self:global)},{}],72:[function(e,t){"use strict";function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.exports=function(e,t,o,s){t=t||"&",o=o||"=";var d={};if("string"!=typeof e||0===e.length)return d;var a=/\+/g;e=e.split(t);var c=1e3;s&&"number"==typeof s.maxKeys&&(c=s.maxKeys);var p=e.length;0c&&(p=c);for(var l=0;l=e.length)return o._position+=e.length,r(null);var c;if(a>e.length){o._position+=e.length,c=0===d?e:e.slice(d),s=i.stream.write(c)&&s;break}o._position+=a,c=0===d&&a===e.length?e:e.slice(d,a),s=i.stream.write(c)&&s,i.last&&i.stream.end(),e=e.slice(a),o._queue.shift()}s?r(null):i.stream.once("drain",r.bind(null,null))},r.prototype.slice=function(e){var t=this;if(t.destroyed)return null;e instanceof Array||(e=[e]);var n=new s.PassThrough;return e.forEach(function(r,o){t._queue.push({start:r.start,end:r.end,stream:n,last:o===e.length-1})}),t._buffer&&t._write(t._buffer,null,t._cb),n},r.prototype.destroy=function(e){var t=this;t.destroyed||(t.destroyed=!0,e&&t.emit("error",e))}},{inherits:44,"readable-stream":86}],78:[function(e,t){"use strict";function n(e){return this instanceof n?void(a.call(this,e),c.call(this,e),e&&!1===e.readable&&(this.readable=!1),e&&!1===e.writable&&(this.writable=!1),this.allowHalfOpen=!0,e&&!1===e.allowHalfOpen&&(this.allowHalfOpen=!1),this.once("end",r)):new n(e)}function r(){this.allowHalfOpen||this._writableState.ended||s(o,this)}function o(e){e.end()}var s=e("process-nextick-args"),i=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};t.exports=n;var d=e("core-util-is");d.inherits=e("inherits");var a=e("./_stream_readable"),c=e("./_stream_writable");d.inherits(n,a);for(var p=i(c.prototype),l=0,u;l=X?e=X:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function m(e,t){return 0>=e||0===t.length&&t.ended?0:t.objectMode?1:e===e?(e>t.highWaterMark&&(t.highWaterMark=h(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0)):t.flowing&&t.length?t.buffer.head.data.length:t.length}function g(e,t){if(!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,_(e)}}function _(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(W("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?R(y,e):y(e))}function y(e){W("emit readable"),e.emit("readable"),C(e)}function b(e,t){t.readingMore||(t.readingMore=!0,R(w,e,t))}function w(e,t){for(var n=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=t.length?(r=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.head.data:t.buffer.concat(t.length),t.buffer.clear()):r=B(e,t.buffer,t.decoder),r}function B(e,t,n){var r;return es.length?s.length:e;if(o+=i===s.length?s:s.slice(0,e),e-=i,0===e){i===s.length?(++r,t.head=n.next?n.next:t.tail=null):(t.head=n,n.data=s.slice(i));break}++r}return t.length-=r,o}function L(e,t){var n=j.allocUnsafe(e),r=t.head,o=1;for(r.data.copy(n),e-=r.data.length;r=r.next;){var s=r.data,i=e>s.length?s.length:e;if(s.copy(n,n.length-e,0,i),e-=i,0===e){i===s.length?(++o,t.head=r.next?r.next:t.tail=null):(t.head=r,r.data=s.slice(i));break}++o}return t.length-=o,n}function T(e){var t=e._readableState;if(0=t.highWaterMark||t.ended))return W("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?T(this):_(this),null;if(e=m(e,t),0===e&&t.ended)return 0===t.length&&T(this),null;var r=t.needReadable;W("need readable",r),(0===t.length||t.length-e>>0),n=this.head,s=0;n;)r(n.data,t,s),s+=n.data.length,n=n.next;return t},e}()},{"safe-buffer":94}],84:[function(e,t){"use strict";function n(e,t){e.emit("error",t)}var r=e("process-nextick-args");t.exports={destroy:function(e,t){var o=this,s=this._readableState&&this._readableState.destroyed,i=this._writableState&&this._writableState.destroyed;return s||i?void(t?t(e):e&&(!this._writableState||!this._writableState.errorEmitted)&&r(n,this,e)):void(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(e){!t&&e?(r(n,o,e),o._writableState&&(o._writableState.errorEmitted=!0)):t&&t(e)}))},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}}},{"process-nextick-args":68}],85:[function(e,t){t.exports=e("events").EventEmitter},{events:37}],86:[function(e,t,n){n=t.exports=e("./lib/_stream_readable.js"),n.Stream=n,n.Readable=n,n.Writable=e("./lib/_stream_writable.js"),n.Duplex=e("./lib/_stream_duplex.js"),n.Transform=e("./lib/_stream_transform.js"),n.PassThrough=e("./lib/_stream_passthrough.js")},{"./lib/_stream_duplex.js":78,"./lib/_stream_passthrough.js":79,"./lib/_stream_readable.js":80,"./lib/_stream_transform.js":81,"./lib/_stream_writable.js":82}],87:[function(e,t,n){function r(e,t,n,r){function s(){S.removeEventListener("loadstart",s),n.autoplay&&S.play()}function d(){S.removeEventListener("canplay",d),r(null,S)}function u(){S=t("iframe"),o(e,function(e,t){return e?w(e):void(S.src=t,".pdf"!==x&&(S.sandbox="allow-forms allow-scripts"),r(null,S))})}function w(t){t.message="Error rendering file \""+e.name+"\": "+t.message,a(t.message),r(t)}var x=l.extname(e.name).toLowerCase(),v=0,S;0<=g.indexOf(x)?function(){function r(){a("Use MediaSource API for "+e.name),g(),S.addEventListener("error",u),S.addEventListener("loadstart",s),S.addEventListener("canplay",d);var t=new p(S),n=t.createWriteStream(i(e.name));e.createReadStream().pipe(n),v&&(S.currentTime=v)}function c(){a("Use Blob URL for "+e.name),g(),S.addEventListener("error",w),S.addEventListener("loadstart",s),S.addEventListener("canplay",d),o(e,function(e,t){return e?w(e):void(S.src=t,v&&(S.currentTime=v))})}function l(e){a("videostream error: fallback to MediaSource API: %o",e.message||e),S.removeEventListener("error",l),S.removeEventListener("canplay",d),r()}function u(t){return a("MediaSource API error: fallback to Blob URL: %o",t.message||t),"number"==typeof e.length&&e.length>n.maxBlobLength?(a("File length too large for Blob URL approach: %d (max: %d)",e.length,n.maxBlobLength),w(new Error("File length too large for Blob URL approach: "+e.length+" (max: "+n.maxBlobLength+")"))):void(S.removeEventListener("error",u),S.removeEventListener("canplay",d),c())}function g(){S||(S=t(_),S.addEventListener("progress",function(){v=S.currentTime}))}var _=0<=m.indexOf(x)?"video":"audio";k?0<=h.indexOf(x)?function(){a("Use `videostream` package for "+e.name),g(),S.addEventListener("error",l),S.addEventListener("loadstart",s),S.addEventListener("canplay",d),f(e,S)}():r():c()}():0<=_.indexOf(x)?function(){S=t("audio"),o(e,function(e,t){return e?w(e):void(S.addEventListener("error",w),S.addEventListener("loadstart",s),S.addEventListener("canplay",d),S.src=t)})}():0<=y.indexOf(x)?function(){S=t("img"),o(e,function(t,n){return t?w(t):void(S.src=n,S.alt=e.name,r(null,S))})}():0<=b.indexOf(x)?u():function(){a("Unknown file extension \"%s\" - will attempt to render into iframe",x);var t="";e.createReadStream({start:0,end:1e3}).setEncoding("utf8").on("data",function(e){t+=e}).on("end",function(){c(t)?(a("File extension \"%s\" appears ascii, so will render.",x),u()):(a("File extension \"%s\" appears non-ascii, will not render.",x),r(new Error("Unsupported file type \""+x+"\": Cannot append to DOM")))}).on("error",r)}()}function o(e,t){var r=l.extname(e.name).toLowerCase();u(e.createReadStream(),n.mime[r],t)}function s(e){if(null==e)throw new Error("file cannot be null or undefined");if("string"!=typeof e.name)throw new Error("missing or invalid file.name property");if("function"!=typeof e.createReadStream)throw new Error("missing or invalid file.createReadStream property")}function i(e){var t=l.extname(e).toLowerCase();return{".m4a":"audio/mp4; codecs=\"mp4a.40.5\"",".m4v":"video/mp4; codecs=\"avc1.640029, mp4a.40.5\"",".mkv":"video/webm; codecs=\"avc1.640029, mp4a.40.5\"",".mp3":"audio/mpeg",".mp4":"video/mp4; codecs=\"avc1.640029, mp4a.40.5\"",".webm":"video/webm; codecs=\"vorbis, vp8\""}[t]}function d(e){null==e.autoplay&&(e.autoplay=!0),null==e.controls&&(e.controls=!0),null==e.maxBlobLength&&(e.maxBlobLength=w)}n.render=function(e,t,n,o){"function"==typeof n&&(o=n,n={}),n||(n={}),o||(o=function(){}),s(e),d(n),"string"==typeof t&&(t=document.querySelector(t)),r(e,function(n){if(t.nodeName!==n.toUpperCase()){var r=l.extname(e.name).toLowerCase();throw new Error("Cannot render \""+r+"\" inside a \""+t.nodeName.toLowerCase()+"\" element, expected \""+n+"\"")}return t},n,o)},n.append=function(e,t,n,o){function i(e){var r=a(e);return n.controls&&(r.controls=!0),n.autoplay&&(r.autoplay=!0),t.appendChild(r),r}function a(e){var n=document.createElement(e);return t.appendChild(n),n}if("function"==typeof n&&(o=n,n={}),n||(n={}),o||(o=function(){}),s(e),d(n),"string"==typeof t&&(t=document.querySelector(t)),t&&("VIDEO"===t.nodeName||"AUDIO"===t.nodeName))throw new Error("Invalid video/audio node argument. Argument must be root element that video/audio tag will be appended to.");r(e,function(e){return"video"===e||"audio"===e?i(e):a(e)},n,function(e,t){e&&t&&t.remove(),o(e,t)})},n.mime=e("./lib/mime.json");var a=e("debug")("render-media"),c=e("is-ascii"),p=e("mediasource"),l=e("path"),u=e("stream-to-blob-url"),f=e("videostream"),h=[".m4a",".m4v",".mp4"],m=[".m4v",".mkv",".mp4",".webm"],g=[].concat(m,[".m4a",".mp3"]),_=[".aac",".oga",".ogg",".wav"],y=[".bmp",".gif",".jpeg",".jpg",".png",".svg"],b=[".css",".html",".js",".md",".pdf",".txt"],w=200000000,k="undefined"!=typeof window&&window.MediaSource},{"./lib/mime.json":88,debug:89,"is-ascii":45,mediasource:52,path:66,"stream-to-blob-url":109,videostream:131}],88:[function(e,t){t.exports={".3gp":"video/3gpp",".aac":"audio/aac",".aif":"audio/x-aiff",".aiff":"audio/x-aiff",".atom":"application/atom+xml",".avi":"video/x-msvideo",".bmp":"image/bmp",".bz2":"application/x-bzip2",".conf":"text/plain",".css":"text/css",".csv":"text/plain",".diff":"text/x-diff",".doc":"application/msword",".flv":"video/x-flv",".gif":"image/gif",".gz":"application/x-gzip",".htm":"text/html",".html":"text/html",".ico":"image/vnd.microsoft.icon",".ics":"text/calendar",".iso":"application/octet-stream",".jar":"application/java-archive",".jpeg":"image/jpeg",".jpg":"image/jpeg",".js":"application/javascript",".json":"application/json",".less":"text/css",".log":"text/plain",".m3u":"audio/x-mpegurl",".m4a":"audio/mp4",".m4v":"video/mp4",".manifest":"text/cache-manifest",".markdown":"text/x-markdown",".mathml":"application/mathml+xml",".md":"text/x-markdown",".mid":"audio/midi",".midi":"audio/midi",".mov":"video/quicktime",".mp3":"audio/mpeg",".mp4":"video/mp4",".mp4v":"video/mp4",".mpeg":"video/mpeg",".mpg":"video/mpeg",".odp":"application/vnd.oasis.opendocument.presentation",".ods":"application/vnd.oasis.opendocument.spreadsheet",".odt":"application/vnd.oasis.opendocument.text",".oga":"audio/ogg",".ogg":"application/ogg",".pdf":"application/pdf",".png":"image/png",".pps":"application/vnd.ms-powerpoint",".ppt":"application/vnd.ms-powerpoint",".ps":"application/postscript",".psd":"image/vnd.adobe.photoshop",".qt":"video/quicktime",".rar":"application/x-rar-compressed",".rdf":"application/rdf+xml",".rss":"application/rss+xml",".rtf":"application/rtf",".svg":"image/svg+xml",".svgz":"image/svg+xml",".swf":"application/x-shockwave-flash",".tar":"application/x-tar",".tbz":"application/x-bzip-compressed-tar",".text":"text/plain",".tif":"image/tiff",".tiff":"image/tiff",".torrent":"application/x-bittorrent",".ttf":"application/x-font-ttf",".txt":"text/plain",".wav":"audio/wav",".webm":"video/webm",".wma":"audio/x-ms-wma",".wmv":"video/x-ms-wmv",".xls":"application/vnd.ms-excel",".xml":"application/xml",".yaml":"text/yaml",".yml":"text/yaml",".zip":"application/zip"}},{}],89:[function(e,t,n){arguments[4][15][0].apply(n,arguments)},{"./debug":90,_process:69,dup:15}],90:[function(e,t,n){arguments[4][16][0].apply(n,arguments)},{dup:16,ms:60}],91:[function(e,t){(function(e){t.exports=function(t,n,r){function o(t){function n(){r&&r(t,d),r=null}i?e.nextTick(n):n()}function s(e,n,r){if(d[e]=r,n&&(l=!0),0==--c||n)o(n);else if(!l&&u>2)+1;s>2]|=128<<24-(t%4<<3),e[(-16&(t>>2)+2)+14]=0|n/536870912,e[(-16&(t>>2)+2)+15]=n<<3},p=function(e,t,n,r,o){var s=this,i=o%4,d=(r+i)%4,a=r-d,c;switch(i){case 0:e[o]=s.charCodeAt(n+3);case 1:e[0|o+1-(i<<1)]=s.charCodeAt(n+2);case 2:e[0|o+2-(i<<1)]=s.charCodeAt(n+1);case 3:e[0|o+3-(i<<1)]=s.charCodeAt(n);}if(!(r>2]=s.charCodeAt(n+c)<<24|s.charCodeAt(n+c+1)<<16|s.charCodeAt(n+c+2)<<8|s.charCodeAt(n+c+3);switch(d){case 3:e[0|o+a+1]=s.charCodeAt(n+a+2);case 2:e[0|o+a+2]=s.charCodeAt(n+a+1);case 1:e[0|o+a+3]=s.charCodeAt(n+a);}}},l=function(e,t,n,r,o){var s=this,i=o%4,d=(r+i)%4,a=r-d,c;switch(i){case 0:e[o]=s[n+3];case 1:e[0|o+1-(i<<1)]=s[n+2];case 2:e[0|o+2-(i<<1)]=s[n+1];case 3:e[0|o+3-(i<<1)]=s[n];}if(!(r>2]=s[n+c]<<24|s[n+c+1]<<16|s[n+c+2]<<8|s[n+c+3];switch(d){case 3:e[0|o+a+1]=s[n+a+2];case 2:e[0|o+a+2]=s[n+a+1];case 1:e[0|o+a+3]=s[n+a];}}},u=function(e,t,n,r,s){var i=this,d=s%4,a=(r+d)%4,c=r-a,p=new Uint8Array(o.readAsArrayBuffer(i.slice(n,n+r))),l;switch(d){case 0:e[s]=p[3];case 1:e[0|s+1-(d<<1)]=p[2];case 2:e[0|s+2-(d<<1)]=p[1];case 3:e[0|s+3-(d<<1)]=p[0];}if(!(r>2]=p[l]<<24|p[l+1]<<16|p[l+2]<<8|p[l+3];switch(a){case 3:e[0|s+c+1]=p[c+2];case 2:e[0|s+c+2]=p[c+1];case 1:e[0|s+c+3]=p[c];}}},f=function(e){switch(r.getDataType(e)){case"string":return p.bind(e);case"array":return l.bind(e);case"buffer":return l.bind(e);case"arraybuffer":return l.bind(new Uint8Array(e));case"view":return l.bind(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));case"blob":return u.bind(e);}},h=Array(256),m=0;256>m;m++)h[m]=(16>m?"0":"")+m.toString(16);var i=function(e){for(var t=new Uint8Array(e),n=Array(e.byteLength),r=0;r=e)return 65536;if(16777216>e)for(t=1;t>2);return a(o,e),c(o,e,n),r},b=function(e,n,r,o){f(e)(t.h8,t.h32,n,r,o||0)},w=function(e,n,r,o,s){var i=r;b(e,n,r),s&&(i=y(r,o)),t.core.hash(i,t.padMaxChunkLen)},k=function(e,t){var n=new Int32Array(e,t+320,5),r=new Int32Array(5),o=new DataView(r.buffer);return o.setInt32(0,n[0],!1),o.setInt32(4,n[1],!1),o.setInt32(8,n[2],!1),o.setInt32(12,n[3],!1),o.setInt32(16,n[4],!1),r},x=this.rawDigest=function(e){var n=e.byteLength||e.length||e.size||0;_(t.heap,t.padMaxChunkLen);var r=0,o=t.maxChunkLen;for(r=0;n>r+o;r+=o)w(e,r,o,n,!1);return w(e,r,n-r,n,!0),k(t.heap,t.padMaxChunkLen)};this.digest=this.digestFromString=this.digestFromBuffer=this.digestFromArrayBuffer=function(e){return i(x(e).buffer)},this.resetState=function(){return _(t.heap,t.padMaxChunkLen),this},this.append=function(e){var n=0,r=e.byteLength||e.length||e.size||0,o=t.offset%t.maxChunkLen,s;for(t.offset+=r;n>2],d=0|r[t+324>>2],c=0|r[t+328>>2],l=0|r[t+332>>2],f=0|r[t+336>>2],n=0;(0|n)<(0|e);n=0|n+64){for(i=s,a=d,p=c,u=l,h=f,o=0;64>(0|o);o=0|o+4)g=0|r[n+o>>2],m=0|(0|(s<<5|s>>>27)+(d&c|~d&l))+(0|(0|g+f)+1518500249),f=l,l=c,c=d<<30|d>>>2,d=s,s=m,r[e+o>>2]=g;for(o=0|e+64;(0|o)<(0|e+80);o=0|o+4)g=(r[o-12>>2]^r[o-32>>2]^r[o-56>>2]^r[o-64>>2])<<1|(r[o-12>>2]^r[o-32>>2]^r[o-56>>2]^r[o-64>>2])>>>31,m=0|(0|(s<<5|s>>>27)+(d&c|~d&l))+(0|(0|g+f)+1518500249),f=l,l=c,c=d<<30|d>>>2,d=s,s=m,r[o>>2]=g;for(o=0|e+80;(0|o)<(0|e+160);o=0|o+4)g=(r[o-12>>2]^r[o-32>>2]^r[o-56>>2]^r[o-64>>2])<<1|(r[o-12>>2]^r[o-32>>2]^r[o-56>>2]^r[o-64>>2])>>>31,m=0|(0|(s<<5|s>>>27)+(d^c^l))+(0|(0|g+f)+1859775393),f=l,l=c,c=d<<30|d>>>2,d=s,s=m,r[o>>2]=g;for(o=0|e+160;(0|o)<(0|e+240);o=0|o+4)g=(r[o-12>>2]^r[o-32>>2]^r[o-56>>2]^r[o-64>>2])<<1|(r[o-12>>2]^r[o-32>>2]^r[o-56>>2]^r[o-64>>2])>>>31,m=0|(0|(s<<5|s>>>27)+(d&c|d&l|c&l))+(0|(0|g+f)-1894007588),f=l,l=c,c=d<<30|d>>>2,d=s,s=m,r[o>>2]=g;for(o=0|e+240;(0|o)<(0|e+320);o=0|o+4)g=(r[o-12>>2]^r[o-32>>2]^r[o-56>>2]^r[o-64>>2])<<1|(r[o-12>>2]^r[o-32>>2]^r[o-56>>2]^r[o-64>>2])>>>31,m=0|(0|(s<<5|s>>>27)+(d^c^l))+(0|(0|g+f)-899497514),f=l,l=c,c=d<<30|d>>>2,d=s,s=m,r[o>>2]=g;s=0|s+i,d=0|d+a,c=0|c+p,l=0|l+u,f=0|f+h}r[t+320>>2]=s,r[t+324>>2]=d,r[t+328>>2]=c,r[t+332>>2]=l,r[t+336>>2]=f}}},"undefined"==typeof t?"undefined"!=typeof window&&(window.Rusha=n):t.exports=n,"undefined"!=typeof FileReaderSync){var o=new FileReaderSync,s=function(e,t,n){try{return n(null,e.digest(t))}catch(t){return n(t)}},i=function(e,t,n,r,o){var s=new self.FileReader;s.onloadend=function(){var d=s.result;t+=s.result.byteLength;try{e.append(d)}catch(t){return void o(t)}tn.statusCode&&"location"in n.headers)return e.url=n.headers.location,n.resume(),void(0p?(r._debug("start backpressure: bufferedAmount %d",r._channel.bufferedAmount),r._cb=n):n(null)}else r._debug("write before connect"),r._chunk=e,r._cb=n},r.prototype._onFinish=function(){function e(){setTimeout(function(){t._destroy()},1e3)}var t=this;t.destroyed||(t.connected?e():t.once("connect",e))},r.prototype._createOffer=function(){var e=this;e.destroyed||e._pc.createOffer(function(t){function n(){var n=e._pc.localDescription||t;e._debug("signal"),e.emit("signal",{type:n.type,sdp:n.sdp})}e.destroyed||(t.sdp=e.sdpTransform(t.sdp),e._pc.setLocalDescription(t,function(){e.destroyed||(e.trickle||e._iceComplete?n():e.once("_iceComplete",n))},function(t){e._destroy(t)}))},function(t){e._destroy(t)},e.offerConstraints)},r.prototype._createAnswer=function(){var e=this;e.destroyed||e._pc.createAnswer(function(t){function n(){var n=e._pc.localDescription||t;e._debug("signal"),e.emit("signal",{type:n.type,sdp:n.sdp})}e.destroyed||(t.sdp=e.sdpTransform(t.sdp),e._pc.setLocalDescription(t,function(){e.destroyed||(e.trickle||e._iceComplete?n():e.once("_iceComplete",n))},function(t){e._destroy(t)}))},function(t){e._destroy(t)},e.answerConstraints)},r.prototype._onIceStateChange=function(){var e=this;if(!e.destroyed){var t=e._pc.iceConnectionState,n=e._pc.iceGatheringState;e._debug("iceStateChange (connection: %s) (gathering: %s)",t,n),e.emit("iceStateChange",t,n),("connected"===t||"completed"===t)&&(clearTimeout(e._reconnectTimeout),e._pcReady=!0,e._maybeReady()),"disconnected"===t&&(e.reconnectTimer?(clearTimeout(e._reconnectTimeout),e._reconnectTimeout=setTimeout(function(){e._destroy()},e.reconnectTimer)):e._destroy()),"failed"===t&&e._destroy(new Error("Ice connection failed.")),"closed"===t&&e._destroy()}},r.prototype.getStats=function(e){var t=this;0===t._pc.getStats.length?t._pc.getStats().then(function(t){var n=[];t.forEach(function(e){n.push(e)}),e(null,n)},function(t){e(t)}):t._isReactNativeWebrtc?t._pc.getStats(null,function(t){var n=[];t.forEach(function(e){n.push(e)}),e(null,n)},function(t){e(t)}):0p)&&this._onChannelBufferedAmountLow()},r.prototype._onSignalingStateChange=function(){var e=this;e.destroyed||(e._debug("signalingStateChange %s",e._pc.signalingState),e.emit("signalingStateChange",e._pc.signalingState))},r.prototype._onIceCandidate=function(e){var t=this;t.destroyed||(e.candidate&&t.trickle?t.emit("signal",{candidate:{candidate:e.candidate.candidate,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid}}):!e.candidate&&(t._iceComplete=!0,t.emit("_iceComplete")))},r.prototype._onChannelMessage=function(e){var t=this;if(!t.destroyed){var r=e.data;r instanceof ArrayBuffer&&(r=n.from(r)),t.push(r)}},r.prototype._onChannelBufferedAmountLow=function(){var e=this;if(!e.destroyed&&e._cb){e._debug("ending backpressure: bufferedAmount %d",e._channel.bufferedAmount);var t=e._cb;e._cb=null,t(null)}},r.prototype._onChannelOpen=function(){var e=this;e.connected||e.destroyed||(e._debug("on channel open"),e._channelReady=!0,e._maybeReady())},r.prototype._onChannelClose=function(){var e=this;e.destroyed||(e._debug("on channel close"),e._destroy())},r.prototype._onAddStream=function(e){var t=this;t.destroyed||(t._debug("on add stream"),t.emit("stream",e.stream))},r.prototype._onTrack=function(e){var t=this;if(!t.destroyed){t._debug("on track");var n=e.streams[0].id;-1!==t._previousStreams.indexOf(n)||(t._previousStreams.push(n),t.emit("stream",e.streams[0]))}},r.prototype._debug=function(){var e=this,t=[].slice.call(arguments);t[0]="["+e._id+"] "+t[0],s.apply(null,t)},r.prototype._transformConstraints=function(e){var t=this;if(0===Object.keys(e).length)return e;if((e.mandatory||e.optional)&&!t._isChromium){var n=Object.assign({},e.optional,e.mandatory);return void 0!==n.OfferToReceiveVideo&&(n.offerToReceiveVideo=n.OfferToReceiveVideo,delete n.OfferToReceiveVideo),void 0!==n.OfferToReceiveAudio&&(n.offerToReceiveAudio=n.OfferToReceiveAudio,delete n.OfferToReceiveAudio),n}return e.mandatory||e.optional||!t._isChromium?e:(void 0!==e.offerToReceiveVideo&&(e.OfferToReceiveVideo=e.offerToReceiveVideo,delete e.offerToReceiveVideo),void 0!==e.offerToReceiveAudio&&(e.OfferToReceiveAudio=e.offerToReceiveAudio,delete e.offerToReceiveAudio),{mandatory:e})}}).call(this,e("buffer").Buffer)},{buffer:27,debug:98,"get-browser-rtc":40,inherits:44,randombytes:76,"readable-stream":86}],98:[function(e,t,n){arguments[4][15][0].apply(n,arguments)},{"./debug":99,_process:69,dup:15}],99:[function(e,t,n){arguments[4][16][0].apply(n,arguments)},{dup:16,ms:60}],100:[function(e,t){function n(e){return i.digest(e)}function r(e){for(var t=e.length,n=new Uint8Array(t),r=0;r>>4).toString(16)),n.push((15&o).toString(16));return n.join("")}var s=e("rusha"),i=new s,d="undefined"==typeof window?self:window,a=d.crypto||d.msCrypto||{},c=a.subtle||a.webkitSubtle;try{c.digest({name:"sha-1"},new Uint8Array).catch(function(){c=!1})}catch(e){c=!1}t.exports=function(e,t){return c?void("string"==typeof e&&(e=r(e)),c.digest({name:"sha-1"},e).then(function(e){t(o(new Uint8Array(e)))},function(){t(n(e))})):void setTimeout(t,0,n(e))},t.exports.sync=n},{rusha:93}],101:[function(e,t){(function(n){function r(e){var t=this;if(!(t instanceof r))return new r(e);if(e||(e={}),"string"==typeof e&&(e={url:e}),null==e.url&&null==e.socket)throw new Error("Missing required `url` or `socket` option");if(null!=e.url&&null!=e.socket)throw new Error("Must specify either `url` or `socket` option, not both");if(t._id=d(4).toString("hex").slice(0,7),t._debug("new websocket: %o",e),e=Object.assign({allowHalfOpen:!1},e),a.Duplex.call(t,e),t.connected=!1,t.destroyed=!1,t._chunk=null,t._cb=null,t._interval=null,e.socket)t.url=e.socket.url,t._ws=e.socket;else{t.url=e.url;try{t._ws="function"==typeof c?new p(e.url,e):new p(e.url)}catch(e){return void n.nextTick(function(){t._destroy(e)})}}t._ws.binaryType="arraybuffer",t._ws.onopen=function(){t._onOpen()},t._ws.onmessage=function(e){t._onMessage(e)},t._ws.onclose=function(){t._onClose()},t._ws.onerror=function(){t._destroy(new Error("connection error to "+t.url))},t._onFinishBound=function(){t._onFinish()},t.once("finish",t._onFinishBound)}t.exports=r;var o=e("safe-buffer").Buffer,s=e("debug")("simple-websocket"),i=e("inherits"),d=e("randombytes"),a=e("readable-stream"),c=e("ws"),p="function"==typeof c?c:WebSocket,l=65536;i(r,a.Duplex),r.WEBSOCKET_SUPPORT=!!p,r.prototype.send=function(e){this._ws.send(e)},r.prototype.destroy=function(e){this._destroy(null,e)},r.prototype._destroy=function(e,t){var n=this;if(!n.destroyed){if(t&&n.once("close",t),n._debug("destroy (error: %s)",e&&(e.message||e)),n.readable=n.writable=!1,n._readableState.ended||n.push(null),n._writableState.finished||n.end(),n.connected=!1,n.destroyed=!0,clearInterval(n._interval),n._interval=null,n._chunk=null,n._cb=null,n._onFinishBound&&n.removeListener("finish",n._onFinishBound),n._onFinishBound=null,n._ws){var r=n._ws,o=function(){r.onclose=null};if(r.readyState===p.CLOSED)o();else try{r.onclose=o,r.close()}catch(e){o()}r.onopen=null,r.onmessage=null,r.onerror=null}n._ws=null,e&&n.emit("error",e),n.emit("close")}},r.prototype._read=function(){},r.prototype._write=function(e,t,n){if(this.destroyed)return n(new Error("cannot write after socket is destroyed"));if(this.connected){try{this.send(e)}catch(e){return this._destroy(e)}"function"!=typeof c&&this._ws.bufferedAmount>l?(this._debug("start backpressure: bufferedAmount %d",this._ws.bufferedAmount),this._cb=n):n(null)}else this._debug("write before connect"),this._chunk=e,this._cb=n},r.prototype._onFinish=function(){function e(){setTimeout(function(){t._destroy()},1e3)}var t=this;t.destroyed||(t.connected?e():t.once("connect",e))},r.prototype._onMessage=function(e){if(!this.destroyed){var t=e.data;t instanceof ArrayBuffer&&(t=o.from(t)),this.push(t)}},r.prototype._onOpen=function(){var e=this;if(!(e.connected||e.destroyed)){if(e.connected=!0,e._chunk){try{e.send(e._chunk)}catch(t){return e._destroy(t)}e._chunk=null,e._debug("sent chunk from \"write before connect\"");var t=e._cb;e._cb=null,t(null)}"function"!=typeof c&&(e._interval=setInterval(function(){e._onInterval()},150),e._interval.unref&&e._interval.unref()),e._debug("connect"),e.emit("connect")}},r.prototype._onInterval=function(){if(this._cb&&this._ws&&!(this._ws.bufferedAmount>l)){this._debug("ending backpressure: bufferedAmount %d",this._ws.bufferedAmount);var e=this._cb;this._cb=null,e(null)}},r.prototype._onClose=function(){this.destroyed||(this._debug("on close"),this._destroy())},r.prototype._debug=function(){var e=[].slice.call(arguments);e[0]="["+this._id+"] "+e[0],s.apply(null,e)}}).call(this,e("_process"))},{_process:69,debug:102,inherits:44,randombytes:76,"readable-stream":86,"safe-buffer":94,ws:25}],102:[function(e,t,n){arguments[4][15][0].apply(n,arguments)},{"./debug":103,_process:69,dup:15}],103:[function(e,t,n){arguments[4][16][0].apply(n,arguments)},{dup:16,ms:60}],104:[function(e,t){var n=1,r=65535,o=4,s=setInterval(function(){n=n+1&r},0|1e3/o);s.unref&&s.unref(),t.exports=function(e){var t=o*(e||5),s=[0],i=1,d=n-1&r;return function(e){var a=n-d&r;for(a>t&&(a=t),d=n;a--;)i==t&&(i=0),s[i]=s[0==i?t-1:i-1],i++;e&&(s[i-1]+=e);var c=s[i-1],p=s.lengthe._pos){var s=n.substr(e._pos);if("x-user-defined"===e._charset){for(var d=new o(s.length),c=0;ce._pos&&(e.push(new o(new Uint8Array(i.result.slice(e._pos)))),e._pos=i.result.byteLength)},i.onload=function(){e.push(null)},i.readAsArrayBuffer(n);}e._xhr.readyState===a.DONE&&"ms-stream"!==e._mode&&e.push(null)}}).call(this,e("_process"),"undefined"==typeof global?"undefined"==typeof self?"undefined"==typeof window?{}:window:self:global,e("buffer").Buffer)},{"./capability":106,_process:69,buffer:27,inherits:44,"readable-stream":86}],109:[function(e,t){var n=e("stream-to-blob");t.exports=function e(t,r,o){return"function"==typeof r?e(t,null,r):void n(t,r,function(e,t){if(e)return o(e);var n=URL.createObjectURL(t);o(null,n)})}},{"stream-to-blob":110}],110:[function(e,t){var n=e("once");t.exports=function e(t,r,o){if("function"==typeof r)return e(t,null,r);o=n(o);var s=[];t.on("data",function(e){s.push(e)}).on("end",function(){var e=r?new Blob(s,{type:r}):new Blob(s);o(null,e)}).on("error",o)}},{once:63}],111:[function(e,t){(function(n){var r=e("once");t.exports=function(e,t,o){o=r(o);var s=new n(t),i=0;e.on("data",function(e){e.copy(s,i),i+=e.length}).on("end",function(){o(null,s)}).on("error",o)}}).call(this,e("buffer").Buffer)},{buffer:27,once:63}],112:[function(e,t,n){"use strict";function r(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0;}}function o(e){var t=r(e);if("string"!=typeof t&&(g.isEncoding===_||!_(e)))throw new Error("Unknown encoding: "+e);return t||e}function s(e){this.encoding=o(e);var t;switch(this.encoding){case"utf16le":this.text=p,this.end=l,t=4;break;case"utf8":this.fillLast=c,t=4;break;case"base64":this.text=u,this.end=f,t=3;break;default:return this.write=h,void(this.end=m);}this.lastNeed=0,this.lastTotal=0,this.lastChar=g.allocUnsafe(t)}function d(e){if(127>=e)return 0;return 6==e>>5?2:14==e>>4?3:30==e>>3?4:-1}function a(e,t,n){var r=t.length-1;if(r=r)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function l(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,n)}return t}function u(e,t){var r=(e.length-t)%3;return 0==r?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,1==r?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function f(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function h(e){return e.toString(this.encoding)}function m(e){return e&&e.length?this.write(e):""}var g=e("safe-buffer").Buffer,_=g.isEncoding||function(e){switch(e=""+e,e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1;}};n.StringDecoder=s,s.prototype.write=function(e){if(0===e.length)return"";var t,n;if(this.lastNeed){if(t=this.fillLast(e),void 0===t)return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n>s,s=(s+5)%8,i=i<>8-s,r++):(i=31&a>>8-(s+5),s=(s+5)%8,0==s&&r++),d[o]="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".charCodeAt(i),o++}for(r=o;r=n?(n=(n+5)%8,0==n?(a|=r,c[d]=a,d++,a=0):a|=255&r<<8-n):(n=(n+5)%8,a|=255&r>>>n,c[d]=a,d++,a=255&r<<8-n);else throw new Error("Invalid input - it is not base32 encoded string")}return c.slice(0,d)}}).call(this,e("buffer").Buffer)},{buffer:27}],115:[function(e,t){var n=e("buffer").Buffer;t.exports=function(e){if(e instanceof Uint8Array){if(0===e.byteOffset&&e.byteLength===e.buffer.byteLength)return e.buffer;if("function"==typeof e.buffer.slice)return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}if(n.isBuffer(e)){for(var t=new Uint8Array(e.length),r=e.length,o=0;o=e.length||0>t)){var n=e.pop();if(t","\"","`"," ","\r","\n","\t"]),u=["'"].concat(p),l=["%","/","?",";","#"].concat(u),f=["/","?","#"],h=/^[+a-z0-9A-Z_-]{0,63}$/,m=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,g={javascript:!0,"javascript:":!0},_={javascript:!0,"javascript:":!0},y={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},b=e("querystring");r.prototype.parse=function(e,t,n){if(!d.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var r=e.indexOf("?"),o=-1!==r&&r255?"":this.hostname.toLowerCase(),U||(this.hostname=s.toASCII(this.hostname));var F=this.port?":"+this.port:"",p=this.hostname||"";this.host=p+F,this.href+=this.host,U&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==v[0]&&(v="/"+v))}if(!g[E])for(var L=0,P=u.length,D;Lb.length&&b.unshift(""),n.pathname=b.join("/")}else n.pathname=e.pathname;if(n.search=e.search,n.query=e.query,n.host=e.host||"",n.auth=e.auth,n.hostname=e.hostname||e.host,n.port=e.port,n.pathname||n.search){var w=n.pathname||"",p=n.search||"";n.path=w+p}return n.slashes=n.slashes||e.slashes,n.href=n.format(),n}var s=n.pathname&&"/"===n.pathname.charAt(0),k=e.host||e.pathname&&"/"===e.pathname.charAt(0),x=k||s||n.host&&e.pathname,v=x,S=n.pathname&&n.pathname.split("/")||[],b=e.pathname&&e.pathname.split("/")||[],C=n.protocol&&!y[n.protocol];if(C&&(n.hostname="",n.port=null,n.host&&(""===S[0]?S[0]=n.host:S.unshift(n.host)),n.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===b[0]?b[0]=e.host:b.unshift(e.host)),e.host=null),x=x&&(""===b[0]||""===S[0])),k)n.host=e.host||""===e.host?e.host:n.host,n.hostname=e.hostname||""===e.hostname?e.hostname:n.hostname,n.search=e.search,n.query=e.query,S=b;else if(b.length)S||(S=[]),S.pop(),S=S.concat(b),n.search=e.search,n.query=e.query;else if(!d.isNullOrUndefined(e.search)){if(C){n.hostname=n.host=S.shift();var E=n.host&&0=e.metadata_size?this.emit("warning",new Error("Peer gave invalid metadata size")):void(this._metadataSize=e.metadata_size,this._numPieces=s(this._metadataSize/l),this._remainingRejects=2*this._numPieces,this._fetching&&this._requestPieces()):this.emit("warning",new Error("Peer does not have metadata")):this.emit("warning",new Error("Peer does not support ut_metadata"))},t.prototype.onMessage=function(e){var t,r;try{var o=e.toString(),s=o.indexOf("ee")+2;t=n.decode(o.substring(0,s)),r=e.slice(s)}catch(e){return}switch(t.msg_type){case 0:this._onRequest(t.piece);break;case 1:this._onData(t.piece,r,t.total_size);break;case 2:this._onReject(t.piece);}},t.prototype.fetch=function(){this._metadataComplete||(this._fetching=!0,this._metadataSize&&this._requestPieces())},t.prototype.cancel=function(){this._fetching=!1},t.prototype.setMetadata=function(e){if(this._metadataComplete)return!0;i("set metadata");try{var t=n.decode(e).info;t&&(e=n.encode(t))}catch(e){}return this._infoHash&&this._infoHash!==c.sync(e)?!1:(this.cancel(),this.metadata=e,this._metadataComplete=!0,this._metadataSize=this.metadata.length,this._wire.extendedHandshake.metadata_size=this._metadataSize,this.emit("metadata",n.encode({info:n.decode(this.metadata)})),!0)},t.prototype._send=function(e,t){var r=n.encode(e);o.isBuffer(t)&&(r=o.concat([r,t])),this._wire.extended("ut_metadata",r)},t.prototype._request=function(e){this._send({msg_type:0,piece:e})},t.prototype._data=function(e,t,n){var r={msg_type:1,piece:e};"number"==typeof n&&(r.total_size=n),this._send(r,t)},t.prototype._reject=function(e){this._send({msg_type:2,piece:e})},t.prototype._onRequest=function(e){if(!this._metadataComplete)return void this._reject(e);var t=e*l,n=t+l;n>this._metadataSize&&(n=this._metadataSize);var r=this.metadata.slice(t,n);this._data(e,r,this._metadataSize)},t.prototype._onData=function(e,t){t.length>l||(t.copy(this.metadata,e*l),this._bitfield.set(e),this._checkDone())},t.prototype._onReject=function(e){0=e._entries[e._index][e._countName]&&(e._index++,e._offset=0),e.value=e._entries[e._index]},o.prototype._processMoov=function(e){var t=this,r=e.traks;t._tracks=[],t._hasVideo=!1,t._hasAudio=!1;for(var o=0;o=a.stsz.entries.length)break;if(g++,y+=C,g>=S.samplesPerChunk){g=0,y=0,_++;var L=a.stsc.entries[b+1];L&&_+1>=L.firstChunk&&b++}w+=E,k.inc(),x&&x.inc(),I&&v++}i.mdia.mdhd.duration=0,i.tkhd.duration=0;var T=S.sampleDescriptionId,A={type:"moov",mvhd:e.mvhd,traks:[{tkhd:i.tkhd,mdia:{mdhd:i.mdia.mdhd,hdlr:i.mdia.hdlr,elng:i.mdia.elng,minf:{vmhd:i.mdia.minf.vmhd,smhd:i.mdia.minf.smhd,dinf:i.mdia.minf.dinf,stbl:{stsd:a.stsd,stts:d(),ctts:d(),stsc:d(),stsz:d(),stco:d(),stss:d()}}}}],mvex:{mehd:{fragmentDuration:e.mvhd.duration},trexs:[{trackId:i.tkhd.trackId,defaultSampleDescriptionIndex:T,defaultSampleDuration:0,defaultSampleSize:0,defaultSampleFlags:0}]}};t._tracks.push({trackId:i.tkhd.trackId,timeScale:i.mdia.mdhd.timeScale,samples:h,currSample:null,currTime:null,moov:A,mime:f})}if(0===t._tracks.length)return void t.emit("error",new Error("no playable tracks"));e.mvhd.duration=0,t._ftyp={type:"ftyp",brand:"iso5",brandVersion:0,compatibleBrands:["iso5"]};var U=l.encode(t._ftyp),R=t._tracks.map(function(e){var t=l.encode(e.moov);return{mime:e.mime,init:n.concat([U,t])}});t.emit("ready",R)},o.prototype.seek=function(e){var t=this;if(!t._tracks)throw new Error("Not ready yet; wait for 'ready' event");t._fileStream&&(t._fileStream.destroy(),t._fileStream=null);var n=-1;if(t._tracks.map(function(r,o){function s(e){i.destroyed||i.box(e.moof,function(n){if(n)return t.emit("error",n);if(!i.destroyed){var d=r.inStream.slice(e.ranges);d.pipe(i.mediaData(e.length,function(e){if(e)return t.emit("error",e);if(!i.destroyed){var n=t._generateFragment(o);return n?void s(n):i.finalize()}}))}})}r.outStream&&r.outStream.destroy(),r.inStream&&(r.inStream.destroy(),r.inStream=null);var i=r.outStream=p.encode(),d=t._generateFragment(o,e);return d?void((-1==n||d.ranges[0].startd&&(d=-d-2);!o.samples[d].sync;)d--;return d};o.prototype._generateFragment=function(e,t){var n=this,r=n._tracks[e],o;if(o=void 0===t?r.currSample:n._findSampleBefore(e,t),o>=r.samples.length)return null;for(var s=r.samples[o].dts,i=0,d=[],a=o,c;a=r.timeScale*1));a++){i+=c.size;var p=d.length-1;0>p||d[p].end!==c.offset?d.push({start:c.offset,end:c.offset+c.size}):d[p].end+=c.size}return r.currSample=a,{moof:n._generateMoof(e,o,a),ranges:d,length:i}},o.prototype._generateMoof=function(e,t,n){for(var r=this,o=r._tracks[e],s=[],i=t,d;i