anxiao_web/pages/cmddispatch/js/openMoveDeviceVideo.js

131 lines
3.9 KiB
JavaScript
Raw Normal View History

2024-07-24 09:22:32 +08:00
import { loginUser } from "../../../public/js/url.js";
import { currentEventData } from "./orgApi/getAlarmEventList.js";
import { mqttUrl } from "../../../public/js/url.js";
import { deviceHash } from "../api/moveDeviceWebsocket.js";
var currentVideoPage={};//保存当前页面打开的视频
var currentStation="";
function openMoveDeviceVideo(deviceArr){
var deviceidArr=[];
for(let i=0;i<deviceArr.length;i++){
var deviceid=deviceArr[i]["deviceid"];
if(deviceid in deviceHash){
var status=deviceHash[deviceid]["status"];
if(status=="online"){
deviceidArr.push(deviceid);
}
}
}
currentStation=currentEventData["station"];
createVideoOpenData(deviceidArr);
currentPageOpenVideo(deviceidArr);
}
function createVideoOpenData(deviceidArr){
var videoCallObj={
"rtmpflag":0,
"camera":1,
"rotation":0
}
var rtmObj=getRtmData("videocall",JSON.stringify(videoCallObj),deviceidArr);
//发送开启视频的指令
sendMqttData(rtmObj);
}
//发送mqqt接口数据
function sendMqttData(obj){
var mqttObj={
"topic":`${currentStation}/ter_cmd`,
"message":JSON.stringify(obj)
}
return axios({
method: 'post',
url:mqttUrl,
data: mqttObj
})
}
function getRtmData(title,data,receiver){
return {
"title":title,
"sender":loginUser,
"department":"",
"scope":"",
"receiver":receiver,
"video":"",
"rtm":(new Date().getTime()).toString(),
"data":data,
"userScope":"",
"userBragide":"",
"userDetachchment":"",
"userBorough":"",
"name":"web",
}
}
//当前页面打开视频
function currentPageOpenVideo(deviceArr){
setTimeout(()=>{
var urlArr=[];
for(let i=0;i<deviceArr.length;i++){
var deviceid=deviceArr[i];
if(deviceid in deviceHash){
let showname=deviceHash[deviceid]["showname"];
let station=deviceHash[deviceid]["station"];
let power=0;
let url=`./rtc/deviceAlarmVideo.html?id=${deviceid}&power=${power}&mdDeviceName=${encodeURI(encodeURI(showname))}&station=${encodeURI(encodeURI(station))}&username=${loginUser}`;
urlArr.push(url);
$(`.videoMonitor>div:nth-child(${i+1})`).attr("deviceid",deviceid)
}
}
urlArr.forEach((item,index)=>{
$(`.videoMonitor>div:nth-child(${index+1})`).html(`<iframe src='${item}'></iframe>`);
})
},1500)
}
//单独打开视频
function aloneOpenVideo(obj){
let deviceid=obj["deviceid"];
let showname=obj["showname"];
let station=obj["station"];
currentStation=station;
let power=0;
let url=`./rtc/moveDeviceVideoOne.html?id=${deviceid}&power=${power}&mdDeviceName=${encodeURI(encodeURI(showname))}&station=${encodeURI(encodeURI(station))}&username=${loginUser}`;
createVideoOpenData([obj["deviceid"]])
window.open(url,'',"width=1280,height=720,top=0,left=0,status='no',location='no',resizable='no',toolbar='no'");
}
//监听iframe过来的数据改变页面
window.addEventListener('message', function(e) {
var data=e.data
var cmd=data["cmd"];
var deviceid=data["deviceid"];
if(cmd=="closePage"){
var mdiv= $(`.videoMonitor>div`);
for(var i=0;i<mdiv.length;i++){
var tmdev=mdiv[i];
if($(tmdev).attr("deviceid")==deviceid){
$(tmdev).html(`<div><img src="./pages/cmddispatch/image/play.png" alt=""></div>`)
}
}
}
})
function sendCloseVideo(deviceid){
var videoCallObj={
"rtmpflag":0,
"camera":1,
"rotation":0
}
var rtmObj=getRtmData("videoclose",JSON.stringify(videoCallObj),[deviceid]);
//发送开启视频的指令
sendMqttData(rtmObj);
}
export {
openMoveDeviceVideo,
aloneOpenVideo
}