|
@@ -1,18 +1,51 @@
|
1
|
|
-
|
|
1
|
+/**
|
|
2
|
+ * 将数据打包成ntv接口返回格式
|
|
3
|
+ * @param {json} msg
|
|
4
|
+ */
|
|
5
|
+function ntvMsg(msg){
|
|
6
|
+ if("result" in msg){
|
|
7
|
+ msg.code = msg.result?0:1;
|
|
8
|
+ delete msg.result;
|
|
9
|
+ }
|
|
10
|
+ if("message" in msg){
|
|
11
|
+ msg.err_desc = msg.message;
|
|
12
|
+ delete msg.message;
|
|
13
|
+ }
|
|
14
|
+
|
|
15
|
+ return msg;
|
|
16
|
+}
|
2
|
17
|
//获取所有SIP会话
|
3
|
18
|
function getSessions(req, res, next) {
|
4
|
|
- let sessions = {};
|
5
|
|
-
|
|
19
|
+ let result = { code: 0, err_desc: 'OK' ,data:{}};
|
|
20
|
+ let items = [];
|
|
21
|
+ let index = 0;
|
6
|
22
|
this.sessions.forEach(function (session, id) {
|
7
|
23
|
if (session.TAG === 'sip')
|
8
|
|
- sessions[session.id] = { host: session.via.host, port: session.via.port, info: session.deviceinfo, status: session.devicestatus, catalog: session.catalog };
|
|
24
|
+ items[index++] = { id:session.id,host: session.via.host, port: session.via.port, info: session.deviceinfo, status: session.devicestatus, catalog: session.catalog, playmode:session.playmode };
|
9
|
25
|
});
|
10
|
|
-
|
11
|
|
- res.json(sessions);
|
|
26
|
+ result.data.count=index;
|
|
27
|
+ result.data.items=items;
|
|
28
|
+ res.json(result);
|
12
|
29
|
}
|
13
|
30
|
|
14
|
31
|
//获取指定设备ID的目录数据
|
|
32
|
+//改造成返回某个设备的信息
|
15
|
33
|
function getCatalog(req, res) {
|
|
34
|
+ let result = { code: 1, err_desc: 'OK' };
|
|
35
|
+ if (this.sessions.has(req.params.device)) {
|
|
36
|
+ let session = this.sessions.get(req.params.device);
|
|
37
|
+ result.code = 0;
|
|
38
|
+ result.data = {};
|
|
39
|
+ result.data.count=1;
|
|
40
|
+ result.data.items = [{ id:session.id, host: session.via.host, port: session.via.port, info: session.deviceinfo, status: session.devicestatus, catalog: session.catalog, playmode:session.playmode }];
|
|
41
|
+ }
|
|
42
|
+ else {
|
|
43
|
+ result.err_desc = '设备不在线或没有注册!';
|
|
44
|
+ }
|
|
45
|
+ res.json(result);
|
|
46
|
+}
|
|
47
|
+//原有版本
|
|
48
|
+/*function getCatalog(req, res) {
|
16
|
49
|
let result = { result: false, message: 'OK' };
|
17
|
50
|
if (this.sessions.has(req.params.device)) {
|
18
|
51
|
let session = this.sessions.get(req.params.device);
|
|
@@ -24,7 +57,7 @@ function getCatalog(req, res) {
|
24
|
57
|
result.message = 'device not online.';
|
25
|
58
|
}
|
26
|
59
|
res.json(result);
|
27
|
|
-}
|
|
60
|
+}*/
|
28
|
61
|
|
29
|
62
|
//预览请求
|
30
|
63
|
async function realplay(req, res) {
|
|
@@ -69,7 +102,7 @@ async function realplay(req, res) {
|
69
|
102
|
result.result = false;
|
70
|
103
|
result.message = 'device not online.';
|
71
|
104
|
}
|
72
|
|
- res.json(result);
|
|
105
|
+ res.json(ntvMsg(result));
|
73
|
106
|
}
|
74
|
107
|
|
75
|
108
|
//回看请求
|
|
@@ -113,7 +146,7 @@ async function playback(req, res) {
|
113
|
146
|
result.result = false;
|
114
|
147
|
result.message = 'device not online';
|
115
|
148
|
}
|
116
|
|
- res.json(result);
|
|
149
|
+ res.json(ntvMsg(result));
|
117
|
150
|
}
|
118
|
151
|
|
119
|
152
|
//回看播放控制
|
|
@@ -140,7 +173,7 @@ async function playControl(req, res) {
|
140
|
173
|
result.result = false;
|
141
|
174
|
result.message = 'device not online.';
|
142
|
175
|
}
|
143
|
|
- res.json(result);
|
|
176
|
+ res.json(ntvMsg(result));
|
144
|
177
|
}
|
145
|
178
|
|
146
|
179
|
//云台控制
|
|
@@ -169,7 +202,7 @@ function ptzControl(req, res) {
|
169
|
202
|
result.result = false;
|
170
|
203
|
result.message = 'device not online.';
|
171
|
204
|
}
|
172
|
|
- res.json(result);
|
|
205
|
+ res.json(ntvMsg(result));
|
173
|
206
|
}
|
174
|
207
|
|
175
|
208
|
//录像文件查询
|
|
@@ -209,7 +242,7 @@ async function recordQuery(req, res) {
|
209
|
242
|
result.result = false;
|
210
|
243
|
result.message = 'device not online.';
|
211
|
244
|
}
|
212
|
|
- res.json(result);
|
|
245
|
+ res.json(ntvMsg(result));
|
213
|
246
|
}
|
214
|
247
|
|
215
|
248
|
//关闭流
|
|
@@ -258,7 +291,7 @@ function closeStream(req, res) {
|
258
|
291
|
}
|
259
|
292
|
}
|
260
|
293
|
|
261
|
|
- res.json(result);
|
|
294
|
+ res.json(ntvMsg(result));
|
262
|
295
|
}
|
263
|
296
|
|
264
|
297
|
function _prefixInteger(num, m) {
|