release: xgplayer-streaming-shared@3.0.11-rc.2

This commit is contained in:
李璐 2024-08-20 15:28:50 +08:00
parent 4b365e74a6
commit 46dd3185f7
4 changed files with 20 additions and 4 deletions

View File

@ -103,6 +103,7 @@
plugins: [Mp4Plugin],
mp4plugin: {
// enableWorker:true,
disableBufferBreakCheck:true,
memoryOpt:true,
}
});

View File

@ -1,6 +1,6 @@
{
"name": "xgplayer-streaming-shared",
"version": "3.0.11-rc.1",
"version": "3.0.11-rc.2",
"main": "dist/index.min.js",
"module": "es/index.js",
"typings": "es/index.d.ts",

View File

@ -28,6 +28,7 @@ export function getConfig (cfg) {
referrerPolicy: undefined,
integrity: undefined,
onProcessMinLen: 0,
processMaxGapTime: Infinity, // process流式获取数据时在请求没有结束前两次读取到数据的最大超时时间
...cfg
}
}

View File

@ -19,6 +19,7 @@ export class FetchLoader extends EventEmitter {
_onProcessMinLen = 0
_onCancel = null
_priOptions = null // 比较私有化的参数传递,回调时候透传
_processMaxGapTime = Infinity
constructor () {
super()
@ -49,6 +50,7 @@ export class FetchLoader extends EventEmitter {
referrer,
referrerPolicy,
onProcessMinLen,
processMaxGapTime,
priOptions
}) {
this._logger = logger
@ -61,6 +63,7 @@ export class FetchLoader extends EventEmitter {
this._range = range || [0, 0]
this._vid = vid || url
this._priOptions = priOptions || {}
this._processMaxGapTime = processMaxGapTime
const init = {
method,
headers,
@ -94,9 +97,9 @@ export class FetchLoader extends EventEmitter {
}
if (timeout) {
this._timeoutTimer = setTimeout(() => {
this._timeoutTimer = setTimeout(async () => {
isTimeout = true
this.cancel()
await this.cancel()
if (onTimeout) {
const error = new NetError(url, init, null, 'timeout')
error.isTimeout = true
@ -216,6 +219,7 @@ export class FetchLoader extends EventEmitter {
let startTime
let endTime
let lastReadDataTime = Date.now()
const pump = async () => {
startTime = Date.now()
try {
@ -240,7 +244,7 @@ export class FetchLoader extends EventEmitter {
}
const curLen = data.value ? data.value.byteLength : 0
this._receivedLength += curLen
this._logger.debug('【fetchLoader,onProgress call】,task,', this._range, ', start,', startByte, ', end,', startRange + this._receivedLength, ', done,', data.done)
// this._logger.debug('【fetchLoader,onProgress call】,task,', this._range, ', start,', startByte, ', end,', startRange + this._receivedLength, ', done,', data.done)
let retData
if (this._onProcessMinLen > 0) {
if (this._writeIdx + curLen >= this._onProcessMinLen || data.done) {
@ -269,6 +273,7 @@ export class FetchLoader extends EventEmitter {
retData = data.value
}
if (retData && retData.byteLength > 0 || data.done) {
this._logger.debug('【fetchLoader,onProgress call】,task,', this._range, ', start,', startByte, ', end,', startRange + this._receivedLength, ', done,', data.done,st )
onProgress(retData, data.done, {
range: [this._range[0] + this._receivedLength - (retData ? retData.byteLength : 0), this._range[0] + this._receivedLength],
vid: this._vid,
@ -279,6 +284,15 @@ export class FetchLoader extends EventEmitter {
firstByteTime,
priOptions:this._priOptions
}, response)
lastReadDataTime = Date.now()
} else if (Date.now() - lastReadDataTime > this._processMaxGapTime) {
this._logger.debug(`[onProgress timeout],task: ${JSON.stringify(this._range)} done: ${data.done} processMaxGapTime: ${this._processMaxGapTime}`)
const error = new NetError(response.url, null, response, 'process timeout')
error.options = {index: this._index, range: this._range, vid: this._vid, priOptions: this._priOptions}
this.running = false
await this.cancel()
this.reject(error)
return
}
if (!data.done) {
pump()