This commit is contained in:
root
2023-08-31 15:30:17 +02:00
commit dea16b40a8
833 changed files with 142024 additions and 0 deletions

View File

@@ -0,0 +1 @@
define(["exports","../../browser.js","./loader.js","../utils/exception.js"],function(_exports,_browser,_loader,_exception){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var FetchStreamLoader=function(_BaseLoader){babelHelpers.inherits(FetchStreamLoader,_BaseLoader);var _super=_createSuper(FetchStreamLoader);function FetchStreamLoader(seekHandler,config){var _this;return babelHelpers.classCallCheck(this,FetchStreamLoader),(_this=_super.call(this,"fetch-stream-loader")).TAG="FetchStreamLoader",_this._seekHandler=seekHandler,_this._config=config,_this._needStash=!0,_this._requestAbort=!1,_this._contentLength=null,_this._receivedLength=0,_this}return babelHelpers.createClass(FetchStreamLoader,[{key:"destroy",value:function(){this.isWorking()&&this.abort(),babelHelpers.get(babelHelpers.getPrototypeOf(FetchStreamLoader.prototype),"destroy",this).call(this)}},{key:"open",value:function(dataSource,range){var _this2=this,sourceURL=(this._dataSource=dataSource,this._range=range,dataSource.url),seekConfig=(this._config.reuseRedirectedURL&&dataSource.redirectedURL&&(sourceURL=dataSource.redirectedURL),this._seekHandler.getConfig(sourceURL,range)),headers=new Headers;if("object"==typeof seekConfig.headers){var key,configHeaders=seekConfig.headers;for(key in configHeaders)Object.hasOwn(configHeaders,key)&&headers.append(key,configHeaders[key])}sourceURL={method:"GET",headers:headers,mode:"cors",cache:"default",referrerPolicy:"no-referrer-when-downgrade"};if("object"==typeof this._config.headers)for(var _key in this._config.headers)headers.append(_key,this._config.headers[_key]);!1===dataSource.cors&&(sourceURL.mode="same-origin"),dataSource.withCredentials&&(sourceURL.credentials="include"),dataSource.referrerPolicy&&(sourceURL.referrerPolicy=dataSource.referrerPolicy),"undefined"!=typeof AbortController&&(this._abortController=new AbortController,sourceURL.signal=this._abortController.signal),this._status=_loader.LoaderStatus.kConnecting,fetch(seekConfig.url,sourceURL).then(function(res){if(_this2._requestAbort)_this2._requestAbort=!1,_this2._status=_loader.LoaderStatus.kIdle,res.body.cancel();else{var redirectedURL;if(res.ok&&200<=res.status&&res.status<=299)return res.url!==seekConfig.url&&_this2._onURLRedirect&&(redirectedURL=_this2._seekHandler.removeURLParameters(res.url),_this2._onURLRedirect(redirectedURL)),null!=(redirectedURL=res.headers.get("Content-Length"))&&(_this2._contentLength=parseInt(redirectedURL),0!==_this2._contentLength)&&_this2._onContentLengthKnown&&_this2._onContentLengthKnown(_this2._contentLength),_this2._pump.call(_this2,res.body.getReader());if(_this2._status=_loader.LoaderStatus.kError,!_this2._onError)throw new _exception.RuntimeException("FetchStreamLoader: Http code invalid, "+res.status+" "+res.statusText);_this2._onError(_loader.LoaderErrors.HTTP_STATUS_CODE_INVALID,{code:res.status,msg:res.statusText})}}).catch(function(e){if(!_this2._abortController||!_this2._abortController.signal.aborted){if(_this2._status=_loader.LoaderStatus.kError,!_this2._onError)throw e;_this2._onError(_loader.LoaderErrors.EXCEPTION,{code:-1,msg:e.message})}})}},{key:"abort",value:function(){this._requestAbort=!0,this._abortController&&this._abortController.abort()}},{key:"_pump",value:function(reader){var _this3=this;return reader.read().then(function(result){if(result.done)if(null!==_this3._contentLength&&_this3._receivedLength<_this3._contentLength){_this3._status=_loader.LoaderStatus.kError;var type=_loader.LoaderErrors.EARLY_EOF,info={code:-1,msg:"Fetch stream meet Early-EOF"};if(!_this3._onError)throw new _exception.RuntimeException(info.msg);_this3._onError(type,info)}else _this3._status=_loader.LoaderStatus.kComplete,_this3._onComplete&&_this3._onComplete(_this3._range.from,_this3._range.from+_this3._receivedLength-1);else{if(!0===_this3._requestAbort)return _this3._requestAbort=!1,_this3._status=_loader.LoaderStatus.kComplete,reader.cancel();_this3._status=_loader.LoaderStatus.kBuffering;type=result.value.buffer,info=_this3._range.from+_this3._receivedLength;_this3._receivedLength+=type.byteLength,_this3._onDataArrival&&_this3._onDataArrival(type,info,_this3._receivedLength),_this3._pump(reader)}}).catch(function(e){if(11!==e.code||!_browser.default.edge){_this3._status=_loader.LoaderStatus.kError;var type=0,info=null,info=19!==e.code&&"network error"!==e.message||!(null===_this3._contentLength||null!==_this3._contentLength&&_this3._receivedLength<_this3._contentLength)?(type=_loader.LoaderErrors.EXCEPTION,{code:e.code,msg:e.message}):(type=_loader.LoaderErrors.EARLY_EOF,{code:e.code,msg:"Fetch stream meet Early-EOF"});if(!_this3._onError)throw new _exception.RuntimeException(info.msg);_this3._onError(type,info)}})}}],[{key:"isSupported",value:function(){try{return"undefined"!=typeof fetch&&"undefined"!=typeof ReadableStream}catch(e){return!1}}}]),FetchStreamLoader}(_loader.BaseLoader);_exports.default=FetchStreamLoader});

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
define(["exports","../utils/exception.js"],function(_exports,_exception){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.LoaderStatus=_exports.LoaderErrors=_exports.BaseLoader=void 0;var LoaderStatus={kIdle:0,kConnecting:1,kBuffering:2,kError:3,kComplete:4},BaseLoader=(_exports.LoaderStatus=LoaderStatus,_exports.LoaderErrors={OK:"OK",EXCEPTION:"Exception",HTTP_STATUS_CODE_INVALID:"HttpStatusCodeInvalid",CONNECTING_TIMEOUT:"ConnectingTimeout",EARLY_EOF:"EarlyEof",UNRECOVERABLE_EARLY_EOF:"UnrecoverableEarlyEof"},function(){function BaseLoader(typeName){babelHelpers.classCallCheck(this,BaseLoader),this._type=typeName||"undefined",this._status=LoaderStatus.kIdle,this._needStash=!1,this._onContentLengthKnown=null,this._onURLRedirect=null,this._onDataArrival=null,this._onError=null,this._onComplete=null}return babelHelpers.createClass(BaseLoader,[{key:"destroy",value:function(){this._status=LoaderStatus.kIdle,this._onContentLengthKnown=null,this._onURLRedirect=null,this._onDataArrival=null,this._onError=null,this._onComplete=null}},{key:"isWorking",value:function(){return this._status===LoaderStatus.kConnecting||this._status===LoaderStatus.kBuffering}},{key:"type",get:function(){return this._type}},{key:"status",get:function(){return this._status}},{key:"needStashBuffer",get:function(){return this._needStash}},{key:"onContentLengthKnown",get:function(){return this._onContentLengthKnown},set:function(callback){this._onContentLengthKnown=callback}},{key:"onURLRedirect",get:function(){return this._onURLRedirect},set:function(callback){this._onURLRedirect=callback}},{key:"onDataArrival",get:function(){return this._onDataArrival},set:function(callback){this._onDataArrival=callback}},{key:"onError",get:function(){return this._onError},set:function(callback){this._onError=callback}},{key:"onComplete",get:function(){return this._onComplete},set:function(callback){this._onComplete=callback}},{key:"open",value:function(dataSource,range){throw new _exception.NotImplementedException("Unimplemented abstract function!")}},{key:"abort",value:function(){throw new _exception.NotImplementedException("Unimplemented abstract function!")}}]),BaseLoader}());_exports.BaseLoader=BaseLoader});

View File

@@ -0,0 +1 @@
define(["exports"],function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_exports.default=function(){function ParamSeekHandler(paramStart,paramEnd){babelHelpers.classCallCheck(this,ParamSeekHandler),this._startName=paramStart,this._endName=paramEnd}return babelHelpers.createClass(ParamSeekHandler,[{key:"getConfig",value:function(baseUrl,range){var needAnd;return 0===range.from&&-1===range.to||(needAnd=!0,-1===baseUrl.indexOf("?")&&(baseUrl+="?",needAnd=!1),needAnd&&(baseUrl+="&"),baseUrl+="".concat(this._startName,"=").concat(range.from.toString()),-1!==range.to&&(baseUrl+="&".concat(this._endName,"=").concat(range.to.toString()))),{url:baseUrl,headers:{}}}},{key:"removeURLParameters",value:function(seekedURL){var params,baseURL=seekedURL.split("?")[0],queryIndex=seekedURL.indexOf("?"),resultParams="";if((params=-1!==queryIndex?seekedURL.substring(queryIndex+1):params)&&0<params.length)for(var pairs=params.split("&"),i=0;i<pairs.length;i++){var pair=pairs[i].split("=");pair[0]!==this._startName&&pair[0]!==this._endName&&(0<i&&(resultParams+="&"),resultParams+=pairs[i])}return 0===resultParams.length?baseURL:baseURL+"?"+resultParams}}]),ParamSeekHandler}()});

View File

@@ -0,0 +1 @@
define(["exports"],function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_exports.default=function(){function RangeSeekHandler(zeroStart){babelHelpers.classCallCheck(this,RangeSeekHandler),this._zeroStart=zeroStart||!1}return babelHelpers.createClass(RangeSeekHandler,[{key:"getConfig",value:function(url,range){var headers={};return 0!==range.from||-1!==range.to?(range=-1!==range.to?"bytes=".concat(range.from.toString(),"-").concat(range.to.toString()):"bytes=".concat(range.from.toString(),"-"),headers.Range=range):this._zeroStart&&(headers.Range="bytes=0-"),{url:url,headers:headers}}},{key:"removeURLParameters",value:function(seekedURL){return seekedURL}}]),RangeSeekHandler}()});

View File

@@ -0,0 +1 @@
define(["exports"],function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_exports.default=function(){function SpeedSampler(){babelHelpers.classCallCheck(this,SpeedSampler),this._firstCheckpoint=0,this._lastCheckpoint=0,this._intervalBytes=0,this._totalBytes=0,this._lastSecondBytes=0,"undefined"!=typeof performance&&performance.now?this._now=performance.now.bind(performance):this._now=Date.now}return babelHelpers.createClass(SpeedSampler,[{key:"reset",value:function(){this._firstCheckpoint=this._lastCheckpoint=0,this._totalBytes=this._intervalBytes=0,this._lastSecondBytes=0}},{key:"addBytes",value:function(bytes){0===this._firstCheckpoint?(this._firstCheckpoint=this._now(),this._lastCheckpoint=this._firstCheckpoint,this._intervalBytes+=bytes,this._totalBytes+=bytes):this._now()-this._lastCheckpoint<1e3?(this._intervalBytes+=bytes,this._totalBytes+=bytes):(this._lastSecondBytes=this._intervalBytes,this._intervalBytes=bytes,this._totalBytes+=bytes,this._lastCheckpoint=this._now())}},{key:"currentKBps",get:function(){this.addBytes(0);var durationSeconds=(this._now()-this._lastCheckpoint)/1e3;return this._intervalBytes/(durationSeconds=0===durationSeconds?1:durationSeconds)/1024}},{key:"lastSecondKBps",get:function(){return this.addBytes(0),0!==this._lastSecondBytes?this._lastSecondBytes/1024:500<=this._now()-this._lastCheckpoint?this.currentKBps:0}},{key:"averageKBps",get:function(){var durationSeconds=(this._now()-this._firstCheckpoint)/1e3;return this._totalBytes/durationSeconds/1024}}]),SpeedSampler}()});