ntv-wangjian 3 years ago
parent
commit
f9c73249d0
5 changed files with 54 additions and 11 deletions
  1. 6
    0
      GB28181Server.js
  2. 38
    9
      GB28181Session.js
  3. 4
    1
      core/ctx.js
  4. 5
    0
      stream/server.js
  5. 1
    1
      stream/session.js

+ 6
- 0
GB28181Server.js View File

219
                 //刷新过期时间
219
                 //刷新过期时间
220
                 session.expires = expires || this.expires;
220
                 session.expires = expires || this.expires;
221
 
221
 
222
+                //ntv add
223
+                if(session.host != remote.address || session.port != remote.port){
224
+                    session.updateRemote({ request: request, info: remote });
225
+                    Logger.log(`[${userId}] device host changed. ${session.host}:${session.port} ---> ${remote.address}:${remote.port} `);
226
+                }
227
+
222
                 Logger.log(`[${userId}] device register refresh.`);
228
                 Logger.log(`[${userId}] device register refresh.`);
223
             }
229
             }
224
             else {
230
             else {

+ 38
- 9
GB28181Session.js View File

27
                 this.expires = this.request.headers.expires;
27
                 this.expires = this.request.headers.expires;
28
         }
28
         }
29
 
29
 
30
-        //主机通讯地址&端口 
30
+        //远程监控设备的主机通讯地址&端口 
31
         this.host = remote.info.address;
31
         this.host = remote.info.address;
32
 
32
 
33
         this.port = remote.info.port;
33
         this.port = remote.info.port;
75
         context.sessions.set(this.id, this);
75
         context.sessions.set(this.id, this);
76
     }
76
     }
77
 
77
 
78
+    //ntv add 更新远程设备信息
79
+    updateRemote(remote){
80
+        this.request = remote.request;
81
+        this.protocol = remote.info.protocol;
82
+        //注册请求
83
+        if (this.request && this.request.headers) {
84
+
85
+            if (this.request.headers.via[0])
86
+                this.via = this.request.headers.via[0];
87
+
88
+            //过期时间 
89
+            if (this.request.headers.expires)
90
+                this.expires = this.request.headers.expires;
91
+        }
92
+
93
+        //主机通讯地址&端口 
94
+        this.host = remote.info.address;
95
+        this.port = remote.info.port;
96
+    }
78
     //启动
97
     //启动
79
     async run(authModule,auto_play) {
98
     async run(authModule,auto_play) {
80
 
99
 
760
 
779
 
761
             for (var key in this.dialogs) {
780
             for (var key in this.dialogs) {
762
                 let session = this.dialogs[key];
781
                 let session = this.dialogs[key];
763
-                if (session.bye && session.port === rport && session.host === rhost && session.channelId === channelId && session.play === 'realplay') {
782
+                if (session.bye && session.port == rport && session.host == rhost && session.channelId == channelId && session.play == 'realplay') {
764
                     isFinded = true;
783
                     isFinded = true;
765
                     findssrc = session.ssrc;
784
                     findssrc = session.ssrc;
766
                     break;
785
                     break;
778
 
797
 
779
             //ssrc is here  -- by ntv wangjian
798
             //ssrc is here  -- by ntv wangjian
780
             //let ssrc = "0" + channelId.substring(16, 20) + channelId.substring(3, 8);
799
             //let ssrc = "0" + channelId.substring(16, 20) + channelId.substring(3, 8);
781
-            let ssed = channelId.substring(13);
782
-            let ised = '' + (parseInt(ssed)*13+10000);
783
-            let ssrc = "1" + ssed + ised.substring(ised.length-2);
784
- 
800
+            let sub1 = 10000 + parseInt(this.id.substring(15));
801
+            let sub2 = channelId.substring(15);
802
+            let ssrc = '' + sub1 + sub2;
803
+
785
             let host = rhost || "127.0.0.1";
804
             let host = rhost || "127.0.0.1";
786
 
805
 
787
             let port = rport || 9200;
806
             let port = rport || 9200;
857
 
876
 
858
                                     context.nodeEvent.emit('sdpReceived', sdp);
877
                                     context.nodeEvent.emit('sdpReceived', sdp);
859
 
878
 
879
+                                    //add ntv
880
+                                    context.ssrcs.set(ssrc,{id:that.id,chid:channelId,play:'realplay'});
881
+
860
                                     //Step 7 SIP服务器收到媒体流发送者返回200 OK响应后,向 媒体流发送者 发送 ACK请求,请求中不携带消息体,完成与媒体流发送者的invite会话建立过程
882
                                     //Step 7 SIP服务器收到媒体流发送者返回200 OK响应后,向 媒体流发送者 发送 ACK请求,请求中不携带消息体,完成与媒体流发送者的invite会话建立过程
861
                                     that.uas.send({
883
                                     that.uas.send({
862
                                         method: 'ACK',
884
                                         method: 'ACK',
888
                                         }
910
                                         }
889
 
911
 
890
                                         that.dialogs[key] = { channelId: channelId, ssrc: ssrc, host: host, port: port, bye: byeRequest, play: 'realplay' };
912
                                         that.dialogs[key] = { channelId: channelId, ssrc: ssrc, host: host, port: port, bye: byeRequest, play: 'realplay' };
913
+                                        
914
+                                        //console.log("BYE INFO:");
915
+                                        //console.log(that.dialogs[key]);
891
                                     }
916
                                     }
892
 
917
 
893
                                     result.data = { ssrc: ssrc };
918
                                     result.data = { ssrc: ssrc };
924
                 //搜索满足条件的会话
949
                 //搜索满足条件的会话
925
                 let session = this.dialogs[key];
950
                 let session = this.dialogs[key];
926
                 //ntv  注释掉多余条件,因为数据类型不同导致找不到
951
                 //ntv  注释掉多余条件,因为数据类型不同导致找不到
927
-                if (session.bye /*&& session.port === rport && session.host === rhost */ && session.channelId === channelId && session.play === 'realplay') {
952
+                if (session.bye && session.port == rport && session.host == rhost && session.channelId == channelId && session.play == 'realplay') {
928
                     //ntv 挪到回调中,TODO 这个指令发不成功!
953
                     //ntv 挪到回调中,TODO 这个指令发不成功!
929
                     //context.nodeEvent.emit('stopPlayed', session.ssrc);
954
                     //context.nodeEvent.emit('stopPlayed', session.ssrc);
955
+                    
956
+                    //add by ntv  强制更新uri地址,因为终端地址会变。
957
+                    session.bye.uri = 'sip:' + this.id + '@' + this.host + ':' + this.port;
958
+
930
                     this.uas.send(session.bye, (response) => {
959
                     this.uas.send(session.bye, (response) => {
931
                         Logger.log(`[${this.id}] StopRealPlay status=${response.status}`);
960
                         Logger.log(`[${this.id}] StopRealPlay status=${response.status}`);
932
                         
961
                         
933
-                        if(response.status==200){
962
+                        //if(response.status==200){  //ntv 注释20210127
934
                             /** 
963
                             /** 
935
                             ntv remove rtp连接断开时再emit这条消息,放到了stream/session中执行
964
                             ntv remove rtp连接断开时再emit这条消息,放到了stream/session中执行
936
                             */
965
                             */
944
                                 }
973
                                 }
945
                                 
974
                                 
946
                             });
975
                             });
947
-                        }
976
+                        //}
948
                     });
977
                     });
949
 
978
 
950
                     //ntv
979
                     //ntv

+ 4
- 1
core/ctx.js View File

12
   outbytes: 0,
12
   outbytes: 0,
13
   accepted: 0
13
   accepted: 0
14
 };
14
 };
15
-module.exports = { sessions, publishers, nodeEvent, stat };
15
+
16
+let ssrcs = new Map();   //ssrc和注册用户映射关系表,键是ssrc, 值是 {id,chid,play}
17
+
18
+module.exports = { sessions, publishers, nodeEvent, stat , ssrcs};

+ 5
- 0
stream/server.js View File

76
                 context.publishers.delete(key);
76
                 context.publishers.delete(key);
77
                 Logger.log("rtmp session removed ",ssrc);
77
                 Logger.log("rtmp session removed ",ssrc);
78
             }
78
             }
79
+            if(context.ssrcs.has(key)){
80
+                //console.log(context.ssrcs.get(key));
81
+                context.ssrcs.delete(key);
82
+                Logger.log("ssrc session removed ",ssrc);
83
+            }
79
         });
84
         });
80
 
85
 
81
         //ntv add 上一个函数主动关闭,或网络异常,或其他原因关闭rtmp
86
         //ntv add 上一个函数主动关闭,或网络异常,或其他原因关闭rtmp

+ 1
- 1
stream/session.js View File

130
 		//ntv-wangjian
130
 		//ntv-wangjian
131
         //Logger.log(`[${ssrc}] RTP Packet: timestamp:${timestamp} seqNumber:${seqNumber} length:${playload.length} `);
131
         //Logger.log(`[${ssrc}] RTP Packet: timestamp:${timestamp} seqNumber:${seqNumber} length:${playload.length} `);
132
         //ntv add
132
         //ntv add
133
-        if(!that.ssrc){
133
+        if(that && !that.ssrc){
134
             that.ssrc = ssrc;
134
             that.ssrc = ssrc;
135
         }
135
         }
136
 
136
 

Loading…
Cancel
Save