Skip to content

Commit

Permalink
修改 destroy promise 返回类型
Browse files Browse the repository at this point in the history
  • Loading branch information
bosscheng committed Jun 3, 2024
1 parent 791f775 commit 5bb7ea2
Show file tree
Hide file tree
Showing 32 changed files with 392 additions and 171 deletions.
9 changes: 8 additions & 1 deletion demo/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,16 @@ jessibuca.close();
### destroy()

- **用法**: 关闭视频,释放底层资源
- **返回**
- `{Promise}`

```js
jessibuca.destroy()
jessibuca.destroy().then(()=>{
// todo: next
})

// 或者
await jessibuca.destroy();
```

### clearView()
Expand Down
14 changes: 6 additions & 8 deletions demo/components/DemoPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ export default {
this.create();
window.onerror = (msg) => (this.err = msg);
},
unmounted() {
async unmounted() {
if (this.$options && this.$options.jessibuca) {
this.$options.jessibuca.destroy();
await this.$options.jessibuca.destroy();
}
this.vConsole.destroy();
},
Expand Down Expand Up @@ -373,9 +373,9 @@ export default {
rotateChange() {
this.$options.jessibuca.setRotate(this.rotate);
},
destroy() {
async destroy() {
if (this.$options.jessibuca) {
this.$options.jessibuca.destroy();
await this.$options.jessibuca.destroy()
}
this.create();
this.playing = false;
Expand All @@ -400,13 +400,11 @@ export default {
this.$options.jessibuca.stopRecordAndSave();
},
screenShot() {
this.$options.jessibuca.screenshot();
},
restartPlay(type) {
async restartPlay(type) {
if (type === 'mse') {
this.useWCS = false;
Expand All @@ -423,7 +421,7 @@ export default {
this.useOffscreen = false;
}
this.destroy();
await this.destroy();
setTimeout(() => {
this.play();
}, 100)
Expand Down
38 changes: 24 additions & 14 deletions demo/public/2x2-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
var showOperateBtns = true; // 是否显示按钮
var forceNoOffscreen = true; //
var playList = [];
var size = 4;

function create(id) {
var $container = document.getElementById('container' + id);
Expand Down Expand Up @@ -190,7 +191,7 @@
}


for (let i = 0; i < 4; i++) {
for (let i = 0; i < size; i++) {
create(i + 1);
$player.style.display = 'inline-block';
$pause.style.display = 'none';
Expand All @@ -199,7 +200,7 @@


$player.addEventListener('click', function () {
for (let i = 0; i < 4; i++) {
for (let i = 0; i < size; i++) {
var id = i + 1;
var $playHref = document.getElementById('playUrl' + id);
let player = playList[i];
Expand All @@ -225,26 +226,35 @@
$pause.addEventListener('click', function () {
$player.style.display = 'inline-block';
$pause.style.display = 'none';
for (let i = 0; i < 4; i++) {
for (let i = 0; i < size; i++) {
let player = playList[i];
player && player.pause()
}
})

$destroy.addEventListener('click', function () {
for (let i = 0; i < 4; i++) {
const destroyList = [];
for (let i = 0; i < size; i++) {
let player = playList[i];
player && player.destroy()
}
playList = [];
setTimeout(() => {
for (let i = 0; i < 4; i++) {
create(i + 1);
if (player) {
destroyList.push(player.destroy());
}
$player.style.display = 'inline-block';
$pause.style.display = 'none';
$destroy.style.display = 'none';
}, 100)
}
Promise.all(destroyList).then(() => {
playList = [];
setTimeout(() => {
for (let i = 0; i < size; i++) {
create(i + 1);
}
$player.style.display = 'inline-block';
$pause.style.display = 'none';
$destroy.style.display = 'none';
}, 100)
}).catch((e) => {
console.error(e);
})


})

</script>
Expand Down
40 changes: 25 additions & 15 deletions demo/public/3x3-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
var showOperateBtns = true; // 是否显示按钮
var forceNoOffscreen = true; //
var playList = [];
var size = 9;

function create(id) {
var $container = document.getElementById('container' + id);
Expand All @@ -223,7 +224,7 @@
isResize: false,
text: "",
loadingText: "加载中",
debug: true,
debug: false,
showBandwidth: showOperateBtns, // 显示网速
operateBtns: {
fullscreen: showOperateBtns,
Expand All @@ -245,7 +246,7 @@
}


for (let i = 0; i < 9; i++) {
for (let i = 0; i < size; i++) {
create(i + 1);
$player.style.display = 'inline-block';
$pause.style.display = 'none';
Expand All @@ -254,7 +255,7 @@


$player.addEventListener('click', function () {
for (let i = 0; i < 9; i++) {
for (let i = 0; i < size; i++) {
var id = i + 1;
var $playHref = document.getElementById('playUrl' + id);
let player = playList[i];
Expand All @@ -280,26 +281,35 @@
$pause.addEventListener('click', function () {
$player.style.display = 'inline-block';
$pause.style.display = 'none';
for (let i = 0; i < 9; i++) {
for (let i = 0; i < size; i++) {
let player = playList[i];
player && player.pause()
}
})

$destroy.addEventListener('click', function () {
for (let i = 0; i < 9; i++) {
const destroyList = [];
for (let i = 0; i < size; i++) {
let player = playList[i];
player && player.destroy()
}
playList = [];
setTimeout(() => {
for (let i = 0; i < 9; i++) {
create(i + 1);
if (player) {
destroyList.push(player.destroy());
}
$player.style.display = 'inline-block';
$pause.style.display = 'none';
$destroy.style.display = 'none';
}, 100)
}
Promise.all(destroyList).then(() => {
playList = [];
setTimeout(() => {
for (let i = 0; i < size; i++) {
create(i + 1);
}
$player.style.display = 'inline-block';
$pause.style.display = 'none';
$destroy.style.display = 'none';
}, 100)
}).catch((e) => {
console.error(e);
})


})

</script>
Expand Down
44 changes: 27 additions & 17 deletions demo/public/MSE-2x2-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<input
autocomplete="on"
id="playUrl2"
value="http://flv.bdplay.nodemedia.cn/live/bbb.flv"
value="http://flv.bdplay.nodemedia.cn/live/bbb_264.flv"
/>
</div>
<div class="input">
Expand All @@ -138,7 +138,7 @@
<input
autocomplete="on"
id="playUrl4"
value="http://flv.bdplay.nodemedia.cn/live/bbb.flv"
value="http://flv.bdplay.nodemedia.cn/live/bbb_264.flv"
/>
</div>
<div class="input">
Expand All @@ -160,6 +160,7 @@
var showOperateBtns = true; // 是否显示按钮
var forceNoOffscreen = true; //
var playList = [];
var size = 4;

function create(id) {
var $container = document.getElementById('container' + id);
Expand All @@ -170,7 +171,7 @@
isResize: false,
text: "",
loadingText: "加载中",
debug: true,
debug: false,
showBandwidth: showOperateBtns, // 显示网速
operateBtns: {
fullscreen: showOperateBtns,
Expand All @@ -192,7 +193,7 @@
}


for (let i = 0; i < 4; i++) {
for (let i = 0; i < size; i++) {
create(i + 1);
$player.style.display = 'inline-block';
$pause.style.display = 'none';
Expand All @@ -201,7 +202,7 @@


$player.addEventListener('click', function () {
for (let i = 0; i < 4; i++) {
for (let i = 0; i < size; i++) {
var id = i + 1;
var $playHref = document.getElementById('playUrl' + id);
let player = playList[i];
Expand All @@ -227,26 +228,35 @@
$pause.addEventListener('click', function () {
$player.style.display = 'inline-block';
$pause.style.display = 'none';
for (let i = 0; i < 4; i++) {
for (let i = 0; i < size; i++) {
let player = playList[i];
player && player.pause()
}
})

$destroy.addEventListener('click', function () {
for (let i = 0; i < 4; i++) {
const destroyList = [];
for (let i = 0; i < size; i++) {
let player = playList[i];
player && player.destroy()
}
playList = [];
setTimeout(() => {
for (let i = 0; i < 4; i++) {
create(i + 1);
if (player) {
destroyList.push(player.destroy());
}
$player.style.display = 'inline-block';
$pause.style.display = 'none';
$destroy.style.display = 'none';
}, 100)
}
Promise.all(destroyList).then(() => {
playList = [];
setTimeout(() => {
for (let i = 0; i < size; i++) {
create(i + 1);
}
$player.style.display = 'inline-block';
$pause.style.display = 'none';
$destroy.style.display = 'none';
}, 100)
}).catch((e) => {
console.error(e);
})


})

</script>
Expand Down
Loading

0 comments on commit 5bb7ea2

Please sign in to comment.