Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bosscheng committed Jun 15, 2024
1 parent 4b859cd commit 08a416d
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 16 deletions.
2 changes: 1 addition & 1 deletion demo/public/decoder.js.map

Large diffs are not rendered by default.

102 changes: 95 additions & 7 deletions demo/public/jessibuca.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion demo/public/jessibuca.js.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions dist/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
var jessibuca = null;

function create() {
jessibuca = null;
jessibuca = new Jessibuca({
container: $container,
videoBuffer: 0.2, // 缓存时长
Expand Down Expand Up @@ -173,9 +174,13 @@

$destroy.addEventListener('click', function () {
if (jessibuca) {
jessibuca.destroy();
jessibuca.destroy().then(()=>{
create();
});
}
else {
create();
}
create();
})

</script>
Expand Down
2 changes: 1 addition & 1 deletion dist/jessibuca.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/constant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const FILE_SUFFIX = {

export const MEDIA_SOURCE_UPDATE_END_TIMEOUT = 10 * 1000

export const CONTAINER_DATA_SET_KEY = 'jessibuca'


// default player options
export const DEFAULT_PLAYER_OPTIONS = {
Expand Down
57 changes: 53 additions & 4 deletions src/jessibuca.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import Player from './player';
import Events from "./utils/events";
import {DEMUX_TYPE, EVENTS, EVENTS_ERROR, JESSIBUCA_EVENTS, PLAYER_PLAY_PROTOCOL, SCALE_MODE_TYPE} from "./constant";
import {isEmpty, isMobile, isNotEmpty, supportWCS, uuid16} from "./utils";
import {
CONTAINER_DATA_SET_KEY,
DEMUX_TYPE,
EVENTS,
EVENTS_ERROR,
JESSIBUCA_EVENTS,
PLAYER_PLAY_PROTOCOL,
SCALE_MODE_TYPE
} from "./constant";
import {
getElementDataset,
isEmpty,
isMobile,
isNotEmpty,
removeElementDataset,
setElementDataset,
supportWCS,
uuid16
} from "./utils";
import Emitter from "./utils/emitter";
import Debug from "./utils/debug";

Expand Down Expand Up @@ -36,9 +53,15 @@ class Jessibuca extends Emitter {
return;
}


if (this._checkHasCreated($container)) {
throw new Error(`Jessibuca container has been created and can not be created again`, $container);
return;
}

// videoBuffer set too long
if (_opt.videoBuffer > 10) {
console.warn('JbPro', `videoBuffer ${_opt.videoBuffer}s is too long, will black screen for ${_opt.videoBuffer}s , it is recommended to set it to less than 10s`);
console.warn('Jessibuca', `videoBuffer ${_opt.videoBuffer}s is too long, will black screen for ${_opt.videoBuffer}s , it is recommended to set it to less than 10s`);
}

if (!$container.classList) {
Expand All @@ -47,6 +70,7 @@ class Jessibuca extends Emitter {
}

$container.classList.add('jessibuca-container');
setElementDataset($container, CONTAINER_DATA_SET_KEY, uuid16());

delete _opt.container;

Expand Down Expand Up @@ -78,6 +102,7 @@ class Jessibuca extends Emitter {
this.$container = $container;
this._loadingTimeoutReplayTimes = 0;
this._heartTimeoutReplayTimes = 0;
this._destroyed = false;
this.events = new Events(this);
this.debug = new Debug(this);
this._initPlayer($container, _opt);
Expand All @@ -87,6 +112,7 @@ class Jessibuca extends Emitter {
*
*/
async destroy() {
this._destroyed = true;
if (this.events) {
this.events.destroy();
this.events = null;
Expand All @@ -96,7 +122,13 @@ class Jessibuca extends Emitter {
await this.player.destroy();
this.player = null;
}
this.$container = null;
if(this.$container){
this.$container.classList.remove('jessibuca-container');
this.$container.classList.remove('jessibuca-fullscreen-web');
removeElementDataset(this.$container, CONTAINER_DATA_SET_KEY);
this.$container = null;
}

this._opt = null;
this._loadingTimeoutReplayTimes = 0;
this._heartTimeoutReplayTimes = 0;
Expand Down Expand Up @@ -130,6 +162,14 @@ class Jessibuca extends Emitter {
})
}

/**
* 是否销毁
* @returns {boolean}
*/
isDestroyed(){
return this._destroyed;
}

/**
* 是否开启控制台调试打印
* @param value {Boolean}
Expand Down Expand Up @@ -758,6 +798,15 @@ class Jessibuca extends Emitter {
return this.player.recorder.recording;
}

_checkHasCreated(element){
if (!element) return false;
const gbProV = getElementDataset(element, CONTAINER_DATA_SET_KEY);
if (gbProV) {
return true;
}
return false;
}


}

Expand Down
35 changes: 35 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,38 @@ export function isTrue(value) {
export function isFalse(value) {
return value !== true && value !== 'true';
}

export function getElementDataset(element, key) {
if (!element) {
return '';
}

if (element.dataset) {
return element.dataset[key];
}
return element.getAttribute('data-' + key);
}

export function setElementDataset(element, key, value) {
if (!element) {
return;
}

if (element.dataset) {
element.dataset[key] = value;
} else {
element.setAttribute('data-' + key, value);
}
}

export function removeElementDataset(element, key) {
if (!element) {
return;
}

if (element.dataset) {
delete element.dataset[key];
} else {
element.removeAttribute('data-' + key);
}
}

0 comments on commit 08a416d

Please sign in to comment.