Skip to content

Commit

Permalink
add initDecoderWorkerTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
bosscheng committed Aug 8, 2024
1 parent fb7ba83 commit 188bad5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
Binary file modified demo/public/dist.zip
Binary file not shown.
Binary file modified demo/public/qrcode.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dist/jessibuca.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/constant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const DEFAULT_PLAYER_OPTIONS = {
wasmDecodeAudioSyncVideo: false,// wasm 解码之后音视频同步
recordType: FILE_SUFFIX.webm,
useWebFullScreen: false, // use web full screen
initDecoderWorkerTimeout: 10 //
}


Expand Down Expand Up @@ -198,7 +199,7 @@ export const EVENTS_ERROR = {
fetchError: "fetchError",
websocketError: 'websocketError',
webcodecsH265NotSupport: 'webcodecsH265NotSupport',
webcodecsConfigureError:'webcodecsConfigureError',
webcodecsConfigureError: 'webcodecsConfigureError',
webcodecsDecodeError: 'webcodecsDecodeError',
webcodecsWidthOrHeightChange: 'webcodecsWidthOrHeightChange',
mediaSourceH265NotSupport: 'mediaSourceH265NotSupport',
Expand Down
33 changes: 32 additions & 1 deletion src/jessibuca.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Jessibuca extends Emitter {
this.$container = $container;
this._loadingTimeoutReplayTimes = 0;
this._heartTimeoutReplayTimes = 0;
this.initDecoderWorkerTimeout = null;
this._destroyed = false;
this.events = new Events(this);
this.debug = new Debug(this);
Expand All @@ -116,6 +117,7 @@ class Jessibuca extends Emitter {
async destroy() {
this._destroyed = true;
this.off();
this._clearInitDecoderWorkerTimeout();
if (this.player) {
await this.player.destroy();
this.player = null;
Expand Down Expand Up @@ -295,7 +297,7 @@ class Jessibuca extends Emitter {
*/
play(url, options = {}) {
return new Promise((resolve, reject) => {
if(this.isDestroyed()){
if (this.isDestroyed()) {
reject('Jessibuca is destroyed')
return;
}
Expand Down Expand Up @@ -657,7 +659,14 @@ class Jessibuca extends Emitter {
})
})
} else {
this.debug.log('Jessibuca', '_play ant waiting decoderWorkerInit');
this._checkInitDecoderWorkerTimeout();
this.player.once(EVENTS.decoderWorkerInit, () => {
this._clearInitDecoderWorkerTimeout();
if (this.isDestroyed()) {
return;
}
this.debug.log('Jessibuca', '_play decoderWorkerInit success and play');
this.player.play(url, options).then(() => {
resolve();
}).catch((e) => {
Expand Down Expand Up @@ -834,6 +843,28 @@ class Jessibuca extends Emitter {
return result;
}

_clearInitDecoderWorkerTimeout() {
if (this.initDecoderWorkerTimeout) {
clearTimeout(this.initDecoderWorkerTimeout);
this.initDecoderWorkerTimeout = null;
}
}

_checkInitDecoderWorkerTimeout() {
this._clearInitDecoderWorkerTimeout();
this.initDecoderWorkerTimeout = setTimeout(() => {
this._handleInitDecoderWorkerTimeout();
}, this._opt.initDecoderWorkerTimeout * 1000);
}


_handleInitDecoderWorkerTimeout() {
this.pause().then(() => {
this.debug.log('Jessibuca', 'init decoder worker timeout and pause play')
}).catch((e) => {
this.debug.warn('Jessibuca', 'init decoder worker timeout and pause play error', e)
})
}
}


Expand Down

0 comments on commit 188bad5

Please sign in to comment.