示例代码
nodenvr.realPlay()示例
html
<!DOCTYPE html>
<html>
<head>
<title>实时预览示例</title>
<style>
body {
margin: 0;
padding: 0;
}
#container {
height: 100vh;
}
</style>
</head>
<body>
<div id="container">
</div>
<script src="js/glow.nodenvr.js"></script>
<script>
var host = "192.168.0.10";//域名或IP
var port = 9527;//端口号必须是整数
var id = 1;//通道号必须是整数
var player = nodenvr.realPlay(host, port, id);
player.play();
var container = document.getElementById("container");
container.appendChild(player.rootElement);
</script>
</body>
</html>
nodenvr.realPlayHLS()示例
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HLS流媒体播放测试测试</title>
<style>
html,
body {
margin: 0;
padding: 0;
}
#container {
height: 100vh;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="js/glow.nodenvr.js"></script>
<script>
let callback = result => {
if (result.error) {
alert(result.error);
}
else {
document.getElementById("container").appendChild(result.player.rootElement);
//不建议调用player.play()进行播放,而是通过手动点击播放按钮
}
};
nodenvr.realPlayHLS('192.168.0.10', 9527, 4, false, callback);
</script>
</body>
</html>
nodenvr.realPlayHK()示例
html
<!DOCTYPE html>
<html>
<head>
<title>海康综合安防管理平台预览示例</title>
<style>
body {
margin: 0;
padding: 0;
}
#container {
height: 100vh;
}
</style>
</head>
<body>
<div id="container">
</div>
<script src="js/glow.nodenvr.js"></script>
<script>
var host = "192.168.0.10";//域名或IP
var port = 9527;//端口号必须是整数
var cameraIndexCode = '3146dbf1123a4edc8d38e0afda47b1e0';//视频监控点唯一标识
var player = nodenvr.realPlayHK(host, port, cameraIndexCode);
player.play();
var container = document.getElementById("container");
container.appendChild(player.rootElement);
</script>
</body>
</html>
nodenvr.realPlayGB()示例
html
<!DOCTYPE html>
<html>
<head>
<title>国标实时预览示例</title>
<style>
body {
margin: 0;
padding: 0;
}
#container {
height: 100vh;
}
</style>
</head>
<body>
<div id="container">
</div>
<script src="js/glow.nodenvr.js"></script>
<script>
var host = "192.168.0.10";//域名或IP
var port = 9527;//端口号必须是整数
var sipId = "34020000001110000001";//设备国标编码
var channelId= "34020000001320000002";//视频通道国标编码
var player = nodenvr.realPlayGB(host, port, id, sipId, channelId);
player.play();
var container = document.getElementById("container");
container.appendChild(player.rootElement);
</script>
</body>
</html>
nodenvr.playBack()示例
html
<!DOCTYPE html>
<html>
<head>
<title>录像回放示例</title>
<style>
body {
margin: 0;
padding: 0;
}
#container {
height: 100vh;
}
</style>
</head>
<body>
<div id="container">
</div>
<script src="js/glow.nodenvr.js"></script>
<script>
var host = "192.168.0.10";//域名或IP
var port = 9527;//端口号必须是整数
var id = 1;//通道号必须是整数
var startTime = "20201029180310";//录像回放开始时间
var endTime = "20201029180410";//录像回放结束时间
var player = nodenvr.playBack(host, port, id, startTime, endTime);
player.play();
var container = document.getElementById("container");
container.appendChild(player.rootElement);
</script>
</body>
</html>
nodenvr.playBackHLS()示例
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HLS流媒体播放测试测试</title>
<style>
html,
body {
margin: 0;
padding: 0;
}
#container {
height: 100vh;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="js/glow.nodenvr.js"></script>
<script>
let callback = result => {
if (result.error) {
alert(result.error);
}
else {
document.getElementById("container").appendChild(result.player.rootElement);
//不建议调用player.play()进行播放,而是通过手动点击播放按钮
}
};
nodenvr.playBackHLS('192.168.0.10', 9527, 2, '20210413222000', '20210413222030', false, callback);
</script>
</body>
</html>
nodenvr.playBackHK()示例
html
<!DOCTYPE html>
<html>
<head>
<title>海康综合安防管理平台回放示例</title>
<style>
body {
margin: 0;
padding: 0;
}
#container {
height: 100vh;
}
</style>
</head>
<body>
<div id="container">
</div>
<script src="js/glow.nodenvr.js"></script>
<script>
var host = "192.168.0.10";//域名或IP
var port = 9527;//端口号必须是整数
var cameraIndexCode = '3146dbf1123a4edc8d38e0afda47b1e0';//视频监控点唯一标识
var startTime = "20201029180310";//录像回放开始时间
var endTime = "20201029180410";//录像回放结束时间
var player = nodenvr.playBackHK(host, port, cameraIndexCode, startTime, endTime);
player.play();
var container = document.getElementById("container");
container.appendChild(player.rootElement);
</script>
</body>
</html>
nodenvr.playBackGB()示例
html
<!DOCTYPE html>
<html>
<head>
<title>国标录像回放示例</title>
<style>
body {
margin: 0;
padding: 0;
}
#container {
height: 100vh;
}
</style>
</head>
<body>
<div id="container">
</div>
<script src="js/glow.nodenvr.js"></script>
<script>
var host = "192.168.0.10";//域名或IP
var port = 9527;//端口号必须是整数
var sipId = "34020000001110000001";//设备国标编码
var channelId= "34020000001320000002";//视频通道国标编码
var startTime = "20201029180310";//录像回放开始时间
var endTime = "20201029180410";//录像回放结束时间
var player = nodenvr.playBackGB(host, port, sipId, channelId, startTime, endTime);
player.play();
var container = document.getElementById("container");
container.appendChild(player.rootElement);
</script>
</body>
</html>
nodenvr.Player示例1
html
<!DOCTYPE html>
<html>
<head>
<title>实时预览示例</title>
<style>
body {
margin: 0;
padding: 0;
}
#container {
height: 100vh;
}
</style>
</head>
<body>
<div id="container">
</div>
<script src="js/glow.nodenvr.js"></script>
<script>
var url = "ws://192.168.0.10:9527/live/1.flv";//实时预览通道视频源地址
var player = new nodenvr.Player(url);
player.play();
var container = document.getElementById("container");
container.appendChild(player.rootElement);
</script>
</body>
</html>
nodenvr.Player示例2
html
<!DOCTYPE html>
<html>
<head>
<title>录像回放示例</title>
<style>
body {
margin: 0;
padding: 0;
}
#container {
height: 100vh;
}
</style>
</head>
<body>
<div id="container">
</div>
<script src="js/glow.nodenvr.js"></script>
<script>
var url = "ws://192.168.0.10:9527/vod/1.flv?starttime=20201029180310&endtime=20201029180410";//录像回放通道地址
var player = new nodenvr.Player(url);
player.play();
var container = document.getElementById("container");
container.appendChild(player.rootElement);
</script>
</body>
</html>
HTTP接口示例代码
html
<!DOCTYPE html>
<html>
<head>
<title>API测试</title>
</head>
<body>
<script src="js/jsencrypt.js"></script>
<script>
//如果在配置文件中设置了token节点的值,则必须添加HTTP请求标头,并携带正确的token值
const headers = new Headers();
headers.append('token', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
//敏感信息需要使用RSA加密或解密
//公钥
const publicKey = `-----BEGIN PUBLIC KEY-----
MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgG2CKPoayirsqic3eooiV8hm7Q/s
G4QHk1+la7fExuqvb4KK9JFb4YrkKURpZ6zZUUGlV+lKX3cDaW6qTCpQ7WCw7+Nt
FS1HTa3Jx32U0Pk4/UBwx1bvppeWnMtoN8FA5N4n+ofs+mSrHQu4qMsKEVNxqYlR
wycB/jxkmF+oDTDRAgMBAAE=
-----END PUBLIC KEY-----`;
//私钥
const privateKey = `-----BEGIN RSA PRIVATE KEY-----
MIICWgIBAAKBgG2CKPoayirsqic3eooiV8hm7Q/sG4QHk1+la7fExuqvb4KK9JFb
4YrkKURpZ6zZUUGlV+lKX3cDaW6qTCpQ7WCw7+NtFS1HTa3Jx32U0Pk4/UBwx1bv
ppeWnMtoN8FA5N4n+ofs+mSrHQu4qMsKEVNxqYlRwycB/jxkmF+oDTDRAgMBAAEC
gYAMR506tohXGeTWsvTtyn4Xfds1ft9zBbpz7kPO/qTjqjqR4+0a47e98GnkPwGe
M1xWRSk/gtSDrwFCpJwX3q1PlSBg9IZnkKWcU+pnkwaVajeTr2mViBDk6ORtCHk8
4Y7YiMyhxT301UHkfZ2BUt6an7N3pM5UEzuZnBdENQXaAQJBAMvNeAePLvaqBmiq
nRqF1I0dem7MAdIYiHfExExnUDpHQAgqQU7o0j4BmmAj1GTf4g6T7INrxkH8gviR
6SfXBfECQQCJjjH1Ilz1gXJyeEQXAlu3lC+Ft5S8WfJ+ayMehZqx+hm65EkzGdM+
/uMZHtSQXVFCRFlAh8R2TtGkkPSFyHjhAkAAlBK1IsjlVlIyVdmgS6TwyZahXd7b
c8pfXKWZ+ekWYUFjRItu5+ZA2sxPXYqqxp/jnrPbI6EqascMYY2h2VBhAkA152Uo
XMj05D9HIF3+bkwmyok860376Xufkrh2c4DFke6XUHJm9g3UN+oio/REhm0bfNFE
+m9AtW5uAOfxrTfBAkAx/2KoEicPt9Rkt49Yol51onw8NCiHayeTty5iFqxBMIBQ
NxwTtWeRM0Ulz7HjBnB1EI40KIgWPuO4xCpazCDH
-----END RSA PRIVATE KEY-----`;
//RSA加密
function rsaEncode(text) {
if (!text) return '';
let rsa = new JSEncrypt();
rsa.setPublicKey(publicKey);
return rsa.encrypt(text);
}
//RSA解密
function rsaDecode(text) {
if (!text) return '';
let rsa = new JSEncrypt();
rsa.setPrivateKey(privateKey);
return rsa.decrypt(text);
}
function save(blob, fileName) {
let downLink = document.createElement('a');
downLink.download = fileName;
downLink.href = URL.createObjectURL(blob);
document.body.appendChild(downLink);
downLink.click();
document.body.removeChild(downLink);
}
async function post(url, params = {}) {
let res = await fetch(url, {
method: 'POST',
mode: 'cors',
headers,
body: JSON.stringify(params)
});
return await res.json();
}
async function get(url) {
let res = await fetch(url, {
method: 'GET',
mode: 'cors',
headers
});
return await res.json();
}
async function realPlay_screenShot() {
let result = await post('api/realplay_screenshot', { channelId: 1 });
if (result.error) {
console.log(result.error);
return;
}
let view = new Uint8Array(result.data);
let blob = new Blob([view], { type: 'image/png' });
save(blob, '截图.png');
}
async function realPlay_capture() {
let result = await post('api/realplay_capture', { channelId: 1, time: 60 });
if (result.error) {
console.log(result.error);
return;
}
let view = new Uint8Array(result.data);
let blob = new Blob([view], { type: 'flv-application/octet-stream' });
save(blob, '录像.flv');
}
async function realPlay_getList() {
let result = await get('api/realplay_getlist');
console.log(result);
}
async function realPlay_insert() {
let result = await post('api/realplay_insert', {
enable: 1,
mode: 1,
name: '测试通道',
source: rsaEncode('rtsp://192.168.0.10:554'),
fixTimespan: 0,
audio: 0,
hls: 0
});
console.log(result);
}
async function realPlay_update() {
let result = await post('api/realplay_update', {
id: 8,
enable: 1,
mode: 1,
name: '测试通道',
source: rsaEncode('rtsp://192.168.0.10:554'),
fixTimespan: 0,
audio: 0,
hls: 0
});
console.log(result);
}
async function realPlay_delete() {
let result = await post('api/realplay_delete', {
id: 9
});
console.log(result);
}
async function realPlay_insertPush() {
let result = await post('api/realplay_insertpush', {
id: 8,
target: 'rtmp://192.168.1.10:9526/live/1.flv'
});
console.log(result);
}
async function realPlay_deletePush() {
let result = await post('api/realplay_deletepush', {
id: 8,
target: 'rtmp://192.168.1.10:9526/live/1.flv'
});
console.log(result);
}
async function realPlay_getPushList() {
let result = await post('api/realplay_getpushlist', {
id: 8
});
console.log(result);
}
async function playBack_screenShot() {
let result = await post('api/playback_screenshot', { channelId: 1, starttime: '20230529110000', endtime: '20230529110030' });
if (result.error) {
console.log(result.error);
return;
}
let view = new Uint8Array(result.data);
let blob = new Blob([view], { type: 'image/png' });
save(blob, '回放截图.png');
}
async function playBack_capture() {
let result = await post('api/playback_capture', { channelId: 1, starttime: '20230529110000', endtime: '20230529110030' });
if (result.error) {
console.log(result.error);
return;
}
let view = new Uint8Array(result.data);
let blob = new Blob([view], { type: 'flv-application/octet-stream' });
save(blob, '回放录像.flv');
}
async function playBack_getList() {
let result = await get('api/playback_getlist');
console.log(result);
}
async function playBack_insert() {
let result = await post('api/playback_insert', {
enable: 1,
mode: 1,
name: '测试通道',
source: rsaEncode('rtsp://192.168.0.10:554'),
fixTimespan: 0,
audio: 0,
hls: 0
});
console.log(result);
}
async function playBack_update() {
let result = await post('api/playback_update', {
id: 4,
enable: 0,
mode: 1,
name: '测试通道',
source: rsaEncode('rtsp://192.168.0.10:554'),
fixTimespan: 0,
audio: 0,
hls: 0
});
console.log(result);
}
async function playBack_delete() {
let result = await post('api/playback_delete', {
id: 4
});
console.log(result);
}
async function playBack_insertPush() {
let result = await post('api/playback_insertpush', {
id: 1,
target: 'ws://192.168.1.10:9527/vod/1.flv'
});
console.log(result);
}
async function playBack_deletePush() {
let result = await post('api/playback_deletepush', {
id: 1,
target: 'ws://192.168.1.10:9527/vod/1.flv'
});
console.log(result);
}
async function playBack_getPushList() {
let result = await post('api/playback_getpushlist', {
id: 1
});
console.log(result);
}
async function playBack_anyOne() {
let result = await post('api/playback_anyone', { channelId: 1 });
console.log(result);
}
async function parseURL_get() {
let result = await get('api/parseurl_get');
console.log(result);
}
async function parseURL_reset() {
let result = await get('api/parseurl_reset');
console.log(result);
}
async function parseURL_update() {
let result = await post('api/parseurl_update', {
newScript: 'function parseURL(url, startTime, endTime) {}; return parseURL;'
});
console.log(result);
}
async function getPerformanceData() {
let result = await get('api/getperformancedata');
console.log(result);
}
async function license_get() {
let result = await get('api/license_get');
console.log(result);
}
async function license_set() {
let result = await post('api/license_set', {
license: '这里是授权码'
});
console.log(result);
}
async function update_channels() {
let result = await post('api/update_channels', [
{
id: 1,
mode: 1,
enable: 1,
name: '测试',
source: rsaEncode('rtsp://admin:admin123@192.168.0.121:554/Streaming/Channels/101?transportmode=unicast'),
playBackSource: rsaEncode('rtsp://admin:admin123@192.168.0.121:554/Streaming/tracks/101?starttime={0}&endtime={1}'),
fixTimespan: 0,
audio: 0,
hls: 0
}
]);
console.log(result);
}
async function gb28181_device_catalog() {
let result = await get('api/gb28181_device_catalog');
console.log(result);
}
async function gb28181_ptz_enable() {
let result = await post('api/gb28181_ptz_enable', {
sipId: '34020000001110000001'
});
console.log(result);
}
async function gb28181_ptz() {
let result = await post('api/gb28181_ptz', {
sipId: '34020000001110000001',
channelId: '34020000001320000002',
cmdCode: 1,
timeout: 50
});
console.log(result);
}
async function gb28181_query_record() {
let result = await post('api/gb28181_query_record', {
sipId: '34020000001110000002',
channelId: '34020000001320000001',
startTime: '20240716000000',
endTime: '20240717235959'
});
console.log(result);
}
async function onvif_ptz_enable() {
let result = await post('api/onvif_ptz_enable', {
hostName: '192.168.0.104',
userName: 'admin',
password: rsaEncode('admin123'),
port: 2020
});
console.log(result);
}
async function onvif_ptz() {
let result = await post('api/onvif_ptz', {
hostName: '192.168.0.104',
userName: 'admin',
password: rsaEncode('admin123'),
port: 2020,
cmdCode: 3,
timeout: 50
});
console.log(result);
}
async function onvif_discovery() {
let result = await get('api/onvif_discovery');
console.log(result);
}
async function hkisc_insert() {
let result = await post('api/hkisc_insert', {
appId: 2,
enable: 1,
appKey: rsaEncode('23175691'),
appSecret: rsaEncode('xK8YE6lXSrMBlRO8Xjk8'),
ip: '10.6.201.109',
port: 443,
isHttps: 1,
streamType: 1
});
console.log(result);
}
async function hkisc_update() {
let result = await post('api/hkisc_update', {
appId: 2,
enable: 0,
appKey: rsaEncode('23175691'),
appSecret: rsaEncode('xK8YE6lXSrMBlRO8Xjk8'),
ip: '10.6.201.109',
port: 443,
isHttps: 1,
streamType: 1
});
console.log(result);
}
async function hkisc_delete() {
let result = await post('api/hkisc_delete', {
appId: 2
});
console.log(result);
}
async function hkisc_getList() {
let result = await get('api/hkisc_getlist');
console.log(result);
}
async function hkisc_getCameras() {
let result = await post('api/hkisc_getcameras', {
//appId: 1
});
console.log(result);
}
async function hkisc_ptz() {
let result = await post('api/hkisc_ptz', {
cameraIndexCode: '3146dbf1123a4edc8d38e0afda47b1e0',
cmd: 'LEFT',
action: 0
});
console.log(result);
}
async function hkisc_screenShot() {
let result = await post('api/hkisc_screenshot', { cameraIndexCode: '3146dbf1123a4edc8d38e0afda47b1e0' });
if (result.error) {
console.log(result.error);
return;
}
let view = new Uint8Array(result.data);
let blob = new Blob([view], { type: 'image/png' });
save(blob, '截图.png');
}
async function hkisc_capture() {
let result = await post('api/hkisc_capture', { cameraIndexCode: '3146dbf1123a4edc8d38e0afda47b1e0', time: 60 });
if (result.error) {
console.log(result.error);
return;
}
let view = new Uint8Array(result.data);
let blob = new Blob([view], { type: 'flv-application/octet-stream' });
save(blob, '录像.flv');
}
</script>
<button onclick="realPlay_screenShot()">实时预览通道截图</button>
<br /><br />
<button onclick="realPlay_capture()">实时预览通道录像</button>
<br /><br />
<button onclick="realPlay_getList()">获取实时预览通道列表</button>
<br /><br />
<button onclick="realPlay_insert()">插入实时预览通道</button>
<br /><br />
<button onclick="realPlay_update()">修改实时预览通道</button>
<br /><br />
<button onclick="realPlay_delete()">删除实时预览通道</button>
<br /><br />
<button onclick="realPlay_insertPush()">插入实时预览通道推流</button>
<br /><br />
<button onclick="realPlay_deletePush()">删除实时预览通道推流</button>
<br /><br />
<button onclick="realPlay_getPushList()">获取实时预览通道推流列表</button>
<br /><br />
<button onclick="playBack_screenShot()">录像回放通道截图</button>
<br /><br />
<button onclick="playBack_capture()">录像回放通道录制</button>
<br /><br />
<button onclick="playBack_getList()">获取录像回放通道列表</button>
<br /><br />
<button onclick="playBack_insert()">插入录像回放通道</button>
<br /><br />
<button onclick="playBack_update()">修改录像回放通道</button>
<br /><br />
<button onclick="playBack_delete()">删除录像回放通道</button>
<br /><br />
<button onclick="playBack_insertPush()">插入录像回放通道推流</button>
<br /><br />
<button onclick="playBack_deletePush()">删除录像回放通道推流</button>
<br /><br />
<button onclick="playBack_getPushList()">获取录像回放通道推流列表</button>
<br /><br />
<button onclick="playBack_anyOne()">判断录像回放通道对应的NVR是否有人占用</button>
<br /><br />
<button onclick="parseURL_get()">获取视频源地址转换代码</button>
<br /><br />
<button onclick="parseURL_reset()">恢复默认的视频源地址转换代码</button>
<br /><br />
<button onclick="parseURL_update()">修改视频源地址转换代码</button>
<br /><br />
<button onclick="getPerformanceData()">获取运行监控性能数据</button>
<br /><br />
<button onclick="license_get()">获取软件授权信息</button>
<br /><br />
<button onclick="license_set()">设置软件授权码</button>
<br /><br />
<button onclick="update_channels()">批量更新通道配置</button>
<br /><br />
<button onclick="gb28181_device_catalog()">获取GB28181设备树</button>
<br /><br />
<button onclick="gb28181_query_record()">GB28181查询录像文件</button>
<br /><br />
<button onclick="gb28181_ptz_enable()">获取GB28181云台控制命令是否可用</button>
<br /><br />
<button onclick="gb28181_ptz()">执行GB28181云台控制命令</button>
<br /><br />
<button onclick="onvif_ptz_enable()">获取onvif云台控制命令是否可用</button>
<br /><br />
<button onclick="onvif_ptz()">执行onvif云台控制命令</button>
<br /><br />
<button onclick="onvif_discovery()">发现onvif设备</button>
<br /><br />
<button onclick="hkisc_insert()">海康安防平台 —— 插入平台记录</button>
<br /><br />
<button onclick="hkisc_update()">海康安防平台 —— 修改平台记录</button>
<br /><br />
<button onclick="hkisc_delete()">海康安防平台 —— 删除平台记录</button>
<br /><br />
<button onclick="hkisc_getList()">海康安防平台 —— 获取所有平台列表</button>
<br /><br />
<button onclick="hkisc_getCameras()">海康安防平台 —— 获取视频监控点列表</button>
<br /><br />
<button onclick="hkisc_ptz()">海康安防平台 —— 云台控制</button>
<br /><br />
<button onclick="hkisc_screenShot()">海康安防平台 —— 实时预览截图</button>
<br /><br />
<button onclick="hkisc_capture()">海康安防平台 —— 实时预览录像</button>
</body>
</html>