Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sw.min.js - github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 31527ca2fab2b92783faf00d4faadf9c3e5034aa (plain)
1
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){"use strict";async function serve({request}){const{url,method,headers,destination}=request,clientlist=await clients.matchAll({type:"window",includeUncontrolled:!0}),[data,port]=await new Promise(resolve=>{for(const client of clientlist){const messageChannel=new MessageChannel,{port1,port2}=messageChannel;port1.onmessage=({data})=>{resolve([data,port1])},client.postMessage({url,method,headers:Object.fromEntries(headers.entries()),scope:self.registration.scope,destination,type:"webtorrent"},[port2])}});let timeOut=null;const cleanup=()=>{port.postMessage(!1),clearTimeout(timeOut),port.onmessage=null};return"STREAM"===data.body?new Response(new ReadableStream({pull(controller){return new Promise(resolve=>{port.onmessage=({data})=>{data?controller.enqueue(data):(cleanup(),controller.close()),resolve()},cancellable||(clearTimeout(timeOut),"document"!==destination&&(timeOut=setTimeout(()=>{cleanup(),resolve()},portTimeoutDuration))),port.postMessage(!0)})},cancel(){cleanup()}}),data):(cleanup(),new Response(data.body,data))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;const portTimeoutDuration=5e3;let cancellable=!1;exports.default=event=>{const{url}=event.request;return url.includes(self.registration.scope+"webtorrent/")?url.includes(self.registration.scope+"webtorrent/keepalive/")?new Response:url.includes(self.registration.scope+"webtorrent/cancel/")?new Response(new ReadableStream({cancel(){cancellable=!0}})):serve(event):null}},{}],2:[function(require){"use strict";var _workerServer=function(obj){return obj&&obj.__esModule?obj:{default:obj}}(require("./worker-server.js"));self.addEventListener("install",()=>{self.skipWaiting()}),self.addEventListener("fetch",event=>{const res=(0,_workerServer.default)(event);res&&event.respondWith(res)}),self.addEventListener("activate",()=>{self.clients.claim()})},{"./worker-server.js":1}]},{},[2]);