-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
app.js
151 lines (104 loc) · 3.45 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Stream = require('node-rtsp-stream');
const onvif = require('node-onvif')
const express = require("express");
const app = express();
const path = require('path');
process.camera = [];
onvif.startProbe().then((device_info_list) => {
console.log(device_info_list.length + ' devices were found.');
// Show the device name and the URL of the end point.
const arr = [];
device_info_list.forEach((info,x) => {
if(x <= 5){
//console.log('- ' + info.urn);
//console.log(' - ' + info.name);
//console.log(' - ' + info.xaddrs[0]);
arr.push(info.xaddrs[0])
}
});
//console.log(arr)
process.camera = arr;
arr.forEach((onCam,i)=>{
let device = new onvif.OnvifDevice({
xaddr: onCam,
user : 'admin',
pass : 'admin'
});
// Initialize the OnvifDevice object
device.init().then(() => {
// Get the UDP stream URL
let url = device.getUdpStreamUrl();
stream = new Stream({
name: 'name',
streamUrl: url,
wsPort: 9000 + i
})
console.log("URL :"+url);
}).catch((error) => {
console.error(error);
});
})
}).catch((error) => {
console.error(error);
});
app.use(express.static(path.join(__dirname, 'public')));
app.get("/",(req,res)=>{
console.log( process.camera)
res.write(`<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<style>
canvas {
display: block;
float: left;
transform: scale(1);
transform-origin: 0% 0% 0px;
}
.camera{
display: block;
margin-left: 10px;
margin-top: 10px;
padding: 0px;
width: 400px;
}
</style>
<title>RTSP STREAMING NODE JS IP CAMERA </title>
<h1>RTSP STREAMING NODE JS IP CAMERA </h1>
${ process.camera.map((can,i)=>{
return ` <div><canvas class="camera" id="videoCanvas${i}" width="640" height="360"></canvas></div>`
}).join("") }
<script type="text/javascript" src="jsmpeg.js"></script>
<script type="text/javascript">
${ process.camera.map((can,i)=>{
return ` var canvas${i} = document.getElementById('videoCanvas${i}');
var ws${i} = new WebSocket("ws://localhost:900${i}")
var player${i} = new jsmpeg(ws${i}, {canvas:canvas${i}, autoplay:true,audio:false,loop: true });
`
}).join("") }
</script>
<body>
</body>
</html>`)
res.end();
})
app.listen(3000)
/*
stream = new Stream({
name: 'name',
streamUrl: 'rtsp://192.168.2.202:554/stream1',
wsPort: 9999
});
Stream = require('node-rtsp-stream');
stream = new Stream({
name: 'name',
streamUrl: 'rtsp://192.168.2.217:554/stream1',
wsPort: 9998
});
Stream = require('node-rtsp-stream');
stream = new Stream({
name: 'name',
streamUrl: 'rtsp://192.168.2.205:554/stream1',
wsPort: 9997
});*/