flvjs 添加AbortController来终止fetch,修复播放器在destroy后仍然会下载数据的问题

转载自github:https://github.com/bilibili/flv.js/pull/448/files

防止丢失记录,要修改源码:

flvjs 添加AbortController来终止fetch,修复播放器在destroy后仍然会下载数据的问题_第1张图片

@@ -117,6 +117,12 @@ class FetchStreamLoader extends BaseLoader {

params.referrerPolicy \= dataSource.referrerPolicy;

}

  

// add abort controller, by wmlgl 2019-5-10 12:21:27

if (self.AbortController) {

this.\_abortController \= new self.AbortController();

params.signal \= this.\_abortController.signal;

}

  

this.\_status \= LoaderStatus.kConnecting;

self.fetch(seekConfig.url, params).then((res) \=> {

if (this.\_requestAbort) {

[](https://github.com/bilibili/flv.js/pull/448/files#diff-2236408d6aad747aed1a901e3aac73fe "Expand Down")[](https://github.com/bilibili/flv.js/pull/448/files#diff-2236408d6aad747aed1a901e3aac73fe "Expand Up")

@@ -152,6 +158,10 @@ class FetchStreamLoader extends BaseLoader {

}

}

}).catch((e) \=> {

if (this.\_abortController && this.\_abortController.signal.aborted) {

return;

}

  

this.\_status \= LoaderStatus.kError;

if (this.\_onError) {

this.\_onError(LoaderErrors.EXCEPTION, {code: \-1, msg: e.message});

[](https://github.com/bilibili/flv.js/pull/448/files#diff-2236408d6aad747aed1a901e3aac73fe "Expand All")

@@ -163,6 +173,10 @@ class FetchStreamLoader extends BaseLoader {

  

abort() {

this.\_requestAbort \= true;

  

if (this.\_abortController) {

this.\_abortController.abort();

}

}

  

\_pump(reader) { // ReadableStreamReader

相关评论:
flvjs 添加AbortController来终止fetch,修复播放器在destroy后仍然会下载数据的问题_第2张图片

你可能感兴趣的:(前端,直播,多媒体,html5)