2025-07-19 09:09:14 +08:00
|
|
|
|
<template>
|
|
|
|
|
<Page class="h-full w-full">
|
|
|
|
|
<!-- 设备分组区域 -->
|
|
|
|
|
<div class="flex h-full gap-[8px]">
|
2025-08-27 20:40:49 +08:00
|
|
|
|
<div class="h-full pb-[5px] c-tree bg-background">
|
|
|
|
|
<ChannelTree
|
|
|
|
|
class="w-[300px]"
|
|
|
|
|
@check="onNodeChecked"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-07-19 09:09:14 +08:00
|
|
|
|
|
|
|
|
|
<!-- 设备分组区域 -->
|
|
|
|
|
<div class="bg-background flex-1">
|
2025-07-25 21:31:43 +08:00
|
|
|
|
<div class="video-play-area flex h-[calc(100%-30px)] flex-wrap">
|
2025-07-19 09:09:14 +08:00
|
|
|
|
<div
|
|
|
|
|
v-for="i in playerNum"
|
2025-07-21 03:38:19 +08:00
|
|
|
|
:style="playerStyle"
|
2025-07-19 09:09:14 +08:00
|
|
|
|
class="player"
|
2025-07-21 03:38:19 +08:00
|
|
|
|
:class="`layer-${i} ${currentSelectPlayerIndex == i ? selected : ''}`"
|
|
|
|
|
@click="playerSelect(i)"
|
|
|
|
|
>
|
|
|
|
|
<video
|
|
|
|
|
style="width: 100%; height: 100%"
|
|
|
|
|
:ref="setItemRef"
|
|
|
|
|
muted
|
|
|
|
|
autoplay
|
|
|
|
|
></video>
|
|
|
|
|
</div>
|
2025-07-19 09:09:14 +08:00
|
|
|
|
</div>
|
2025-07-25 21:31:43 +08:00
|
|
|
|
<div class="player-area flex h-[30px] gap-[5px]">
|
|
|
|
|
<div @click="onPlayerNumChanged(1)" class="h-[20px] w-[20px]">
|
|
|
|
|
<Svg1FrameIcon style="width: 100%; height: 100%" />
|
|
|
|
|
</div>
|
|
|
|
|
<div @click="onPlayerNumChanged(2)" class="h-[20px] w-[20px]">
|
|
|
|
|
<Svg4FrameIcon style="width: 100%; height: 100%" />
|
|
|
|
|
</div>
|
|
|
|
|
<div @click="onPlayerNumChanged(3)" class="h-[20px] w-[20px]">
|
|
|
|
|
<Svg9FrameIcon style="width: 100%; height: 100%" />
|
|
|
|
|
</div>
|
|
|
|
|
<div @click="onPlayerNumChanged(4)" class="h-[20px] w-[20px]">
|
|
|
|
|
<Svg16FrameIcon style="width: 100%; height: 100%" />
|
|
|
|
|
</div>
|
2025-07-19 09:09:14 +08:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Page>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2025-07-21 03:38:19 +08:00
|
|
|
|
import { onMounted, onUnmounted, ref, toRaw } from 'vue';
|
2025-07-19 09:09:14 +08:00
|
|
|
|
import { Page } from '@vben/common-ui';
|
|
|
|
|
import ChannelTree from './channel-tree.vue';
|
2025-07-21 03:38:19 +08:00
|
|
|
|
import mpegts from 'mpegts.js';
|
|
|
|
|
import { message } from 'ant-design-vue';
|
2025-08-10 19:35:45 +08:00
|
|
|
|
import { addFFmpegStreamProxy, addStreamProxy } from '#/api/sis/stream';
|
2025-07-25 21:31:43 +08:00
|
|
|
|
import {
|
|
|
|
|
Svg16FrameIcon,
|
|
|
|
|
Svg1FrameIcon,
|
|
|
|
|
Svg4FrameIcon,
|
|
|
|
|
Svg9FrameIcon,
|
|
|
|
|
} from '@vben/icons';
|
2025-08-10 19:35:45 +08:00
|
|
|
|
import { checkHEVCSupport } from '#/utils/video';
|
|
|
|
|
import type { AddStreamProxyResult } from '#/api/sis/stream/model';
|
2025-07-21 03:38:19 +08:00
|
|
|
|
|
|
|
|
|
const selected = 'selected';
|
|
|
|
|
|
|
|
|
|
const itemRefs = ref<HTMLVideoElement[]>([]);
|
|
|
|
|
const setItemRef = (el: any) => {
|
|
|
|
|
if (el) {
|
|
|
|
|
itemRefs.value.push(el);
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-07-19 09:09:14 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 屏幕播放器数量
|
|
|
|
|
*/
|
|
|
|
|
const playerNum = ref(1);
|
2025-07-21 03:38:19 +08:00
|
|
|
|
/**
|
|
|
|
|
* 屏幕播放器样式
|
|
|
|
|
*/
|
|
|
|
|
const playerStyle = ref({
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
});
|
|
|
|
|
const currentSelectPlayerIndex = ref(-1);
|
|
|
|
|
|
|
|
|
|
function playerSelect(index: number) {
|
|
|
|
|
if (index === currentSelectPlayerIndex.value) {
|
|
|
|
|
currentSelectPlayerIndex.value = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
currentSelectPlayerIndex.value = index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 播放器数量
|
|
|
|
|
* @param val
|
|
|
|
|
*/
|
|
|
|
|
function onPlayerNumChanged(val: number) {
|
|
|
|
|
// 1个屏幕
|
2025-07-22 19:19:59 +08:00
|
|
|
|
const changeBeforeNum = playerNum.value;
|
|
|
|
|
let changeNum = 1;
|
2025-07-21 03:38:19 +08:00
|
|
|
|
if (val === 1) {
|
|
|
|
|
playerStyle.value = {
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
// 4个屏幕 2*2
|
|
|
|
|
else if (val === 2) {
|
|
|
|
|
playerStyle.value = {
|
|
|
|
|
width: '50%',
|
|
|
|
|
height: '50%',
|
|
|
|
|
};
|
2025-07-22 19:19:59 +08:00
|
|
|
|
changeNum = 4;
|
2025-07-21 03:38:19 +08:00
|
|
|
|
}
|
|
|
|
|
// 9个屏幕 3*3
|
|
|
|
|
else if (val === 3) {
|
|
|
|
|
playerStyle.value = {
|
|
|
|
|
width: '33.33%',
|
|
|
|
|
height: '33.33%',
|
|
|
|
|
};
|
2025-07-22 19:19:59 +08:00
|
|
|
|
changeNum = 9;
|
2025-07-21 03:38:19 +08:00
|
|
|
|
}
|
|
|
|
|
// 16个屏幕 4*4
|
|
|
|
|
else {
|
|
|
|
|
playerStyle.value = {
|
|
|
|
|
width: '25%',
|
|
|
|
|
height: '25%',
|
|
|
|
|
};
|
2025-07-22 19:19:59 +08:00
|
|
|
|
changeNum = 16;
|
|
|
|
|
}
|
|
|
|
|
playerNum.value = changeNum;
|
|
|
|
|
// 缩小布局
|
|
|
|
|
if (changeBeforeNum > changeNum) {
|
|
|
|
|
const playerArr = [];
|
|
|
|
|
for (let i = 0; i < playerList.length; i++) {
|
|
|
|
|
const playerBox = playerList[i];
|
|
|
|
|
if (playerBox) {
|
|
|
|
|
playerArr.push(playerBox);
|
|
|
|
|
}
|
|
|
|
|
playerList[i] = null;
|
|
|
|
|
}
|
|
|
|
|
for (let i = 0; i < playerArr.length; i++) {
|
|
|
|
|
const play = playerArr[i];
|
|
|
|
|
if (i < changeNum) {
|
|
|
|
|
// 获取播放元素
|
|
|
|
|
changeElPlayer(play, i);
|
|
|
|
|
} else {
|
|
|
|
|
closePlayVieo(play.player);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-21 03:38:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理带有子节点的数据
|
|
|
|
|
* @param node
|
|
|
|
|
* @param newNode
|
|
|
|
|
*/
|
|
|
|
|
function handleParentNoe(node: any, newNode: any[] = []) {
|
|
|
|
|
if (node.children && node.children.length >= 1) {
|
|
|
|
|
node.children.forEach((item: any) => {
|
|
|
|
|
if (item.level === 2) {
|
|
|
|
|
newNode.push(toRaw(item.data));
|
|
|
|
|
}
|
|
|
|
|
if (item.children && item.children.length >= 1) {
|
|
|
|
|
handleParentNoe(item.children, newNode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 播放器数据, 每一个位置代表页面上行的一个矩形
|
|
|
|
|
const playerList: any[] = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 节点选中时间处理
|
|
|
|
|
* @param _val 选中节点id
|
|
|
|
|
* @param checked 是否选中
|
|
|
|
|
* @param node 节点数据
|
|
|
|
|
*/
|
|
|
|
|
function onNodeChecked(
|
|
|
|
|
_val: any,
|
|
|
|
|
{ checked, node }: { checked: boolean; node: any },
|
|
|
|
|
) {
|
|
|
|
|
// 此次操作需要新增或者删除节点
|
|
|
|
|
let checkNode: any = [];
|
|
|
|
|
if (node.level === 1) {
|
|
|
|
|
handleParentNoe(node, checkNode);
|
|
|
|
|
} else {
|
|
|
|
|
checkNode.push(toRaw(node.data));
|
|
|
|
|
}
|
|
|
|
|
// 新增
|
|
|
|
|
if (checked) {
|
2025-07-22 19:19:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* 如果当前页面有选择播放未知,并且播放视频只有一个,则播放到制定位置
|
|
|
|
|
*/
|
|
|
|
|
if (currentSelectPlayerIndex.value !== -1 && checkNode.length == 1) {
|
|
|
|
|
doPlayer(checkNode[0], currentSelectPlayerIndex.value - 1);
|
2025-07-21 03:38:19 +08:00
|
|
|
|
}
|
|
|
|
|
// 批量播放 currentSelectPlayerIndex 将不再生效
|
|
|
|
|
else {
|
2025-07-28 20:27:58 +08:00
|
|
|
|
// 如果此次播放数量小于当前播能播放
|
|
|
|
|
const freeArr: number[] = []; // 空闲播放器数量
|
|
|
|
|
for (let i = 0; i < playerNum.value; i++) {
|
|
|
|
|
const playerData = playerList[i];
|
|
|
|
|
if (!playerData) {
|
|
|
|
|
freeArr.push(i);
|
2025-07-21 03:38:19 +08:00
|
|
|
|
}
|
2025-07-28 20:27:58 +08:00
|
|
|
|
}
|
|
|
|
|
// 要播放的视频数量,小于等于空闲播放器数量,则填充空闲即可
|
|
|
|
|
if (checkNode.length <= freeArr.length) {
|
|
|
|
|
for (let j = 0; j < checkNode.length; j++) {
|
|
|
|
|
doPlayer(checkNode[j], freeArr[j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 直接覆盖原有的播放视频
|
|
|
|
|
else {
|
|
|
|
|
for (let i = 0; i < playerNum.value; i++) {
|
|
|
|
|
doPlayer(checkNode[i], i);
|
2025-07-21 03:38:19 +08:00
|
|
|
|
}
|
2025-07-28 20:27:58 +08:00
|
|
|
|
}
|
2025-07-21 03:38:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 删除
|
|
|
|
|
else {
|
|
|
|
|
checkNode.forEach((item: any) => {
|
|
|
|
|
for (let i = 0; i < playerNum.value; i++) {
|
|
|
|
|
const player = playerList[i];
|
|
|
|
|
if (player && player.data.id === item.id) {
|
|
|
|
|
closePlayer(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-22 19:19:59 +08:00
|
|
|
|
function changeElPlayer(playerInfo: any, index: number) {
|
|
|
|
|
const playerData = playerInfo.data;
|
|
|
|
|
const oldPlayer = playerInfo.player;
|
|
|
|
|
if (oldPlayer) {
|
|
|
|
|
closePlayVieo(oldPlayer);
|
|
|
|
|
}
|
|
|
|
|
const videoConfig = {
|
|
|
|
|
type: 'flv',
|
|
|
|
|
url: playerData.url,
|
|
|
|
|
isLive: true,
|
|
|
|
|
hasAudio: false,
|
|
|
|
|
hasVideo: true,
|
|
|
|
|
enableWorker: true, // 启用分离的线程进行转码
|
|
|
|
|
enableStashBuffer: false, // 关闭IO隐藏缓冲区
|
|
|
|
|
stashInitialSize: 256, // 减少首帧显示等待时长
|
|
|
|
|
};
|
|
|
|
|
const playerConfig = {
|
|
|
|
|
enableErrorRecover: true, // 启用错误恢复
|
|
|
|
|
autoCleanupMaxBackwardDuration: 30,
|
|
|
|
|
autoCleanupMinBackwardDuration: 10,
|
|
|
|
|
};
|
|
|
|
|
const player = mpegts.createPlayer(videoConfig, playerConfig);
|
|
|
|
|
const videoElement = itemRefs.value[index];
|
|
|
|
|
if (videoElement) {
|
|
|
|
|
player.attachMediaElement(videoElement);
|
|
|
|
|
player.load();
|
|
|
|
|
player.play();
|
|
|
|
|
playerList[index] = {
|
|
|
|
|
player,
|
|
|
|
|
data: playerData,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
console.log('视频播放元素获取异常');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 19:35:45 +08:00
|
|
|
|
function streamProxy(nodeData: any, cb: Function) {
|
|
|
|
|
let params = {};
|
|
|
|
|
if (nodeData.nvrIp) {
|
|
|
|
|
params = {
|
|
|
|
|
videoIp: nodeData.nvrIp,
|
|
|
|
|
videoPort: nodeData.nvrPort,
|
|
|
|
|
factoryNo: nodeData.nvrFactoryNo,
|
|
|
|
|
account: nodeData.nvrAccount,
|
|
|
|
|
pwd: nodeData.nvrPwd,
|
|
|
|
|
channelId: nodeData.nvrChannelNo,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
params = {
|
|
|
|
|
videoIp: nodeData.deviceIp,
|
|
|
|
|
videoPort: nodeData.devicePort,
|
|
|
|
|
factoryNo: nodeData.factoryNo,
|
|
|
|
|
account: nodeData.deviceAccount,
|
|
|
|
|
pwd: nodeData.devicePwd,
|
|
|
|
|
channelId: nodeData.channelNo,
|
|
|
|
|
};
|
2025-08-27 20:40:49 +08:00
|
|
|
|
}
|
|
|
|
|
if (isSupportH265) {
|
|
|
|
|
addStreamProxy(params).then((res) => cb(res));
|
|
|
|
|
} else {
|
|
|
|
|
addFFmpegStreamProxy(params).then((res) => cb(res));
|
|
|
|
|
// addStreamProxy(params).then((res) => cb(res));
|
2025-08-10 19:35:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-21 03:38:19 +08:00
|
|
|
|
/**
|
|
|
|
|
* 开始播放视频流
|
|
|
|
|
* @param nodeData 播放的节点数据
|
|
|
|
|
* @param index 播放器的索引信息
|
|
|
|
|
*/
|
2025-07-28 20:27:58 +08:00
|
|
|
|
function doPlayer(nodeData: any, index: number = 0) {
|
|
|
|
|
console.log('index=', index);
|
2025-07-21 03:38:19 +08:00
|
|
|
|
if (mpegts.isSupported()) {
|
2025-08-10 19:35:45 +08:00
|
|
|
|
streamProxy(nodeData, (res: AddStreamProxyResult) => {
|
2025-08-27 20:40:49 +08:00
|
|
|
|
const url = res.wsFlv;
|
2025-07-22 19:19:59 +08:00
|
|
|
|
// 将url 绑定到 nodeData
|
|
|
|
|
nodeData.url = url;
|
2025-07-21 03:38:19 +08:00
|
|
|
|
closePlayer(index);
|
|
|
|
|
const videoConfig = {
|
|
|
|
|
type: 'flv',
|
|
|
|
|
url: url,
|
|
|
|
|
isLive: true,
|
2025-07-22 19:19:59 +08:00
|
|
|
|
hasAudio: false,
|
2025-07-21 03:38:19 +08:00
|
|
|
|
hasVideo: true,
|
|
|
|
|
enableWorker: true, // 启用分离的线程进行转码
|
|
|
|
|
enableStashBuffer: false, // 关闭IO隐藏缓冲区
|
2025-07-22 19:19:59 +08:00
|
|
|
|
stashInitialSize: 256, // 减少首帧显示等待时长
|
2025-07-21 03:38:19 +08:00
|
|
|
|
};
|
|
|
|
|
const playerConfig = {
|
|
|
|
|
enableErrorRecover: true, // 启用错误恢复
|
|
|
|
|
autoCleanupMaxBackwardDuration: 30,
|
|
|
|
|
autoCleanupMinBackwardDuration: 10,
|
|
|
|
|
};
|
|
|
|
|
const player = mpegts.createPlayer(videoConfig, playerConfig);
|
|
|
|
|
const videoElement = itemRefs.value[index];
|
|
|
|
|
if (videoElement) {
|
|
|
|
|
player.attachMediaElement(videoElement);
|
|
|
|
|
player.load();
|
|
|
|
|
player.play();
|
|
|
|
|
playerList[index] = {
|
|
|
|
|
player,
|
|
|
|
|
data: nodeData,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
console.log('视频播放元素获取异常');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
message.error('浏览器不支持播放');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-22 19:19:59 +08:00
|
|
|
|
function closePlayVieo(plInfo: any) {
|
|
|
|
|
if (plInfo) {
|
|
|
|
|
try {
|
|
|
|
|
plInfo.pause(); // 暂停
|
|
|
|
|
plInfo.unload(); // 卸载
|
|
|
|
|
plInfo.destroy(); // 销毁
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log('播放器关闭失败,e=', e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-21 03:38:19 +08:00
|
|
|
|
function closePlayer(index: number) {
|
|
|
|
|
// 如果播放器存在,尝试关闭
|
|
|
|
|
const pData = playerList[index];
|
|
|
|
|
if (pData) {
|
|
|
|
|
try {
|
|
|
|
|
const player = pData.player;
|
|
|
|
|
player.pause(); // 暂停
|
|
|
|
|
player.unload(); // 卸载
|
|
|
|
|
player.destroy(); // 销毁
|
|
|
|
|
playerList[index] = null;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log('播放器关闭失败,e=', e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-12 15:47:15 +08:00
|
|
|
|
function catchUp() {
|
|
|
|
|
playerList.forEach((playerData) => {
|
|
|
|
|
if (playerData) {
|
|
|
|
|
const { player, el } = playerData;
|
|
|
|
|
const end = player.buffered.end(player.buffered.length - 1);
|
|
|
|
|
const diff = end - el.currentTime;
|
|
|
|
|
if (diff > 2) {
|
|
|
|
|
// 如果延迟超过2秒
|
|
|
|
|
el.currentTime = end - 0.5; // 跳转到接近直播点
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 19:35:45 +08:00
|
|
|
|
let isSupportH265 = false;
|
2025-07-21 03:38:19 +08:00
|
|
|
|
onMounted(() => {
|
2025-08-10 19:35:45 +08:00
|
|
|
|
// 检测浏览器是否支持h265
|
|
|
|
|
isSupportH265 = checkHEVCSupport();
|
2025-08-12 15:47:15 +08:00
|
|
|
|
setInterval(catchUp, 10000);
|
2025-07-21 03:38:19 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
for (let i = 0; i < playerList.length; i++) {
|
|
|
|
|
closePlayer(i);
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-07-19 09:09:14 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
2025-07-21 03:38:19 +08:00
|
|
|
|
<style scoped>
|
|
|
|
|
.player {
|
|
|
|
|
border: 1px solid #e4e4e7;
|
|
|
|
|
cursor: pointer;
|
2025-07-28 20:27:58 +08:00
|
|
|
|
|
|
|
|
|
video {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
object-fit: fill;
|
|
|
|
|
}
|
2025-07-21 03:38:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.player.selected {
|
|
|
|
|
border: 2px solid deepskyblue;
|
|
|
|
|
}
|
2025-07-25 21:31:43 +08:00
|
|
|
|
|
|
|
|
|
.player-area {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
2025-07-21 03:38:19 +08:00
|
|
|
|
</style>
|