ntv-wangjian 3 anos atrás
pai
commit
9b1c50e850
3 arquivos alterados com 33 adições e 51 exclusões
  1. 30
    9
      GB28181Session.js
  2. 3
    2
      NtvAuthModule.js
  3. 0
    40
      config.js

+ 30
- 9
GB28181Session.js Ver arquivo

@@ -127,10 +127,20 @@ class NodeSipSession {
127 127
         //获取设备目录
128 128
         this.catalog = await this.getCatalog();
129 129
 
130
+        //console.log(this.catalog);
131
+        let channels = "";
132
+        let firstChid= "";
133
+        for(var key in this.catalog.devicelist){
134
+            let chn = this.catalog.devicelist[key];
135
+            channels += chn.DeviceID + "=" + chn.Name + "|";
136
+            if(firstChid=="") firstChid = chn.DeviceID;
137
+        }
138
+        //console.log(channels);
139
+
130 140
         //ntv 提交状态,自动开启视频... 
131 141
         this.authModule = authModule;
132 142
         this.auto_play  = auto_play;
133
-        this.authModule.status(this.id,1,(data)=>{
143
+        this.authModule.status(this.id,1,channels,(data)=>{
134 144
             if(data.code==0){
135 145
                 Logger.log("设备在线状态已上报!");
136 146
             }else{
@@ -139,17 +149,27 @@ class NodeSipSession {
139 149
             
140 150
         });
141 151
         
142
-        await this.startRealPlay(this.id,auto_play);
152
+        //ntv 尝试自动开启视频,只开启第一个通道。 TODO: 对于硬盘录像机,应可以开启多个通道
153
+        await this.startRealPlay(firstChid,auto_play);
143 154
     }
144 155
 
145 156
     //ntv add 自动发realplay消息 TODO streamServer配置项增加服务器ip选项,使摄像头可以推送到其他服务器。
146 157
     async startRealPlay(channelId,auto_play) {
147 158
         let config = this.config;
148
-        if(config.GB28181.streamServer.enable && (auto_play || config.GB28181.streamServer.auto_play)){
149
-            let host = config.GB28181.sipServer.host;
150
-            let port = config.GB28181.streamServer.listen;
151
-            let mode = 1;
152
-            Logger.log(`[${channelId}] auto send real play message`);
159
+        if(auto_play || (config.GB28181.streamServer.enable && config.GB28181.streamServer.auto_play) ){
160
+            let host = config.GB28181.rtp_server.server;
161
+            let port = config.GB28181.rtp_server.port;
162
+            let mode = config.GB28181.rtp_server.mode;
163
+            if(host==""){
164
+                if(config.GB28181.streamServer.enable){
165
+                    host = config.GB28181.sipServer.host;
166
+                }else{
167
+                    Logger.log("No stream server is defined!");
168
+                    return;
169
+                }
170
+                
171
+            }
172
+            Logger.log(`[${channelId}] auto send real play message.`);
153 173
             this.sendRealPlayMessage(channelId,host,port,mode);
154 174
         }
155 175
     }
@@ -166,7 +186,7 @@ class NodeSipSession {
166 186
             this.isStarting = false;
167 187
             context.sessions.delete(this.id);
168 188
 
169
-            this.authModule.status(this.id,0,(data)=>{
189
+            this.authModule.status(this.id,0,"",(data)=>{
170 190
                 if(data.code==0){
171 191
                     Logger.log("设备离线状态已上报!");
172 192
                 }else{
@@ -768,7 +788,7 @@ class NodeSipSession {
768 788
 
769 789
     //预览 channelId 通道国标编码
770 790
     sendRealPlayMessage(channelId, rhost, rport, mode) {
771
-
791
+        Logger.log("Start real play " + this.id + ":" + channelId + " " + rhost + ":" + rport + " mode:" + mode);
772 792
         return new Promise((resolve, reject) => {
773 793
 
774 794
             let result = { result: true, message: 'OK' };
@@ -942,6 +962,7 @@ class NodeSipSession {
942 962
 
943 963
     //停止实时预览
944 964
     async sendStopRealPlayMessage(channelId, rhost, rport) {
965
+        Logger.log("Stop real play " + this.id + ":" + channelId + " " + rhost + ":" + rport);
945 966
         return new Promise((resolve, reject) => {
946 967
             let result = { result: false, message: '没有找到视频通道!' };
947 968
 

+ 3
- 2
NtvAuthModule.js Ver arquivo

@@ -102,12 +102,13 @@ class NtvAuthModule {
102 102
 	 * 
103 103
 	 * @param {*} usrId 
104 104
 	 * @param {*} status  1 = online
105
+	 * @param {string} channels  id=name|id=name
105 106
 	 * @param {*} callback 
106 107
 	 */
107
-	status(usrId,status,callback){
108
+	status(usrId,status,channels,callback){
108 109
 		var config = this.config;
109 110
 		var path = "/api/sipMgr/";
110
-		var paras= "action=sip_status&id=" + usrId +"&status=" + status;
111
+		var paras= "action=sip_status&id=" + usrId +"&status=" + status + "&chn=" + encodeURIComponent(channels);
111 112
 		var host = config.host;
112 113
 		var port = config.port;
113 114
 		this.postCall(host,port,path,paras,callback);

+ 0
- 40
config.js Ver arquivo

@@ -1,40 +0,0 @@
1
-var config = module.exports = {
2
-    GB28181: {
3
-        sipServer: {
4
-            ping: 60,               //心跳周期(秒)
5
-            ping_timeout: 3,        //最大心跳超时次数
6
-            expires: 3600,          //注册有效期(秒)
7
-            host: '8.131.101.81',   //SIP服务器通讯IP地址,如果使用内网映射到公网IP需要设置为公网IP地址
8
-            serial: '34020000002000000001', //SIP服务器编号
9
-            listen: 5060,                   //SIP通信端口
10
-            realm: '3402000000',            //SIP服务器域
11
-            password: '123456',             //默认密码
12
-            ack_timeout: 30                 //服务端发送ack后,接收回应的超时时间,单位为秒,如果指定时间没有回应,认为失败
13
-        },
14
-        streamServer: {
15
-            enable: true,         //是否启用内置流媒体服务 接收/转码/RTMP推送功能,如有支持GB PS RTP 收流服务器,可以设置为flase
16
-            listen: 9200,         //接收设备端rtp流的多路复用端口
17
-            audio_enable: false,  //是否转发音频流
18
-            rtp_idle_timeout: 30, //rtp包空闲等待时间,如果指定时间没有收到任何包,rtp监听连接自动停止,发送BYE命令
19
-            rtp_mix_port: 9300,  //rtp接收监听端口范围,最小值
20
-            rtp_max_port: 9400,  //rtp接收监听端口范围,最大值           
21
-            invite_port_fixed: true, //设备将流发送的端口,是否固定,true:发送流到多路复用端口 如9200,false:动从rtp_mix_port - rtp_max_port 之间的值中选一个可以用的端口
22
-            host: '0.0.0.0',         //本地地址
23
-            rtmpServer: 'rtmp://60.205.164.47/liveshow'  //RTMP服务器基地址
24
-        }
25
-    },
26
-    VAG: {
27
-        http: {
28
-            port: 82,
29
-            allow_origin: '*'
30
-        },
31
-        auth: {
32
-            api: false,          // true to open base auth
33
-            api_user: 'admin', //default admin
34
-            api_pass: 'admin', //default admin
35
-            play: true,
36
-            publish: true,
37
-            secret: 'nodemedia2017privatekey'
38
-        }
39
-    }
40
-};

Carregando…
Cancelar
Salvar