// 設備列表
var deviceListArray = [
{
szIP: '172.16.77.100',
szPort: '80',
szUsername: 'admin',
szPassword: '*****'
},
{
szIP: '172.16.77.100',
szPort: '80',
szUsername: 'admin',
szPassword: '*****'
},
{
szIP: '172.16.77.100',
szPort: '80',
szUsername: 'admin',
szPassword: '*****'
},
{
szIP: '172.16.77.100',
szPort: '80',
szUsername: 'admin',
szPassword: '*****'
},
{
szIP: '172.16.77.102',
szPort: '80',
szUsername: 'admin',
szPassword: '*****'
},
{
szIP: '172.16.77.102',
szPort: '80',
szUsername: 'admin',
szPassword: '*****'
},
{
szIP: '172.16.77.102',
szPort: '80',
szUsername: 'admin',
szPassword: '*****'
},
{
szIP: '172.16.77.102',
szPort: '80',
szUsername: 'admin',
szPassword: '*****'
},
{
szIP: '172.16.77.103',
szPort: '80',
szUsername: 'admin',
szPassword: '*****'
},
{
szIP: '172.16.77.103',
szPort: '80',
szUsername: 'admin',
szPassword: '*****'
},
{
szIP: '172.16.77.103',
szPort: '80',
szUsername: 'admin',
szPassword: '*****'
},
{
szIP: '172.16.77.103',
szPort: '80',
szUsername: 'admin',
szPassword: '*****'
}
]
// Init plugin
// overall save the current selected window
var g_iWndIndex = 0; //don't have to set the variable; default to use the current selected window without transmiting value when the interface has window parameters
var iWndowType = 2; //設置4*4方格
$(function () {
// check the installation status of plugin
if (-1 == WebVideoCtrl.I_CheckPluginInstall()) {
alert(" If the plugin is uninstalled, please install the WebComponents.exe!");
return;
}
// Init plugin parameters and insert the plugin
WebVideoCtrl.I_InitPlugin('100%', '100%', {
iWndowType: iWndowType,
cbSelWnd: function (xmlDoc) {
g_iWndIndex = $(xmlDoc).find("SelectWnd").eq(0).text();
}
});
WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin");
// check plugin to see whether it is the latest
if (-1 == WebVideoCtrl.I_CheckPluginVersion()) {
alert("Detect the latest version, please double click WebComponents.exe to update!");
return;
}
// 將一維數組按區塊個數分割成二維數組
let deviceList = oneArrayToTwoArray(deviceListArray)
let key = 0
// 自動登錄
clickLogin(deviceList[key])
// 定時器輪播
setInterval(() => {
key++
if (key >= deviceList.length) {
key = 0
}
clickLogin(deviceList[key])
}, 9000)
});
function oneArrayToTwoArray (deviceListArray) {
let twoArray = []
let oneArray = []
let len = iWndowType * iWndowType
for (let b = 0; b < deviceListArray.length; b++) {
if (b % len == 0) {
oneArray = []
}
oneArray.push(deviceListArray[b])
if (b % len == (len - 1)) {
twoArray.push(oneArray)
}
}
return twoArray
}
// login
function clickLogin(deviceList) {
for (let i = 0; i < deviceList.length; i++) {
let index = deviceList[i]
if ("" == index.szIP || "" == index.szPort) {
continue;
}
var iRet = WebVideoCtrl.I_Login(index.szIP, 1, index.szPort, index.szUsername, index.szPassword, {
success: function (xmlDoc) {
console.log(index.szIP + " login success!");
setTimeout(function () {
clickStartRealPlay(index.szIP, i);
}, 100);
},
error: function () {
console.log(index.szIP + " login failed!");
}
});
if (-1 == iRet) {
console.log(index.szIP + " login already !");
setTimeout(() => {
clickStartRealPlay(index.szIP, i);
}, 100);
}
}
}
// strat real play
function clickStartRealPlay(szIP, g_iWndIndex) {
let oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex)
if ("" == szIP) {
return;
}
if (oWndInfo != null) {// stop first
WebVideoCtrl.I_Stop(g_iWndIndex);
}
let iRet = WebVideoCtrl.I_StartRealPlay(szIP, {
iWndIndex: g_iWndIndex
});
if (0 == iRet) {
console.log("start real play success!");
} else {
console.log("start real play failed!");
}
}
複製代碼
如在vue中使用,則需在index.html中引入,由於這個控件js還不支持import導入,而後使用時window.WebVideoCtrljavascript