ntv-wangjian 3 år sedan
förälder
incheckning
f9c73249d0
5 ändrade filer med 54 tillägg och 11 borttagningar
  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 Visa fil

@@ -219,6 +219,12 @@ class NodeSIPServer {
219 219
                 //刷新过期时间
220 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 228
                 Logger.log(`[${userId}] device register refresh.`);
223 229
             }
224 230
             else {

+ 38
- 9
GB28181Session.js Visa fil

@@ -27,7 +27,7 @@ class NodeSipSession {
27 27
                 this.expires = this.request.headers.expires;
28 28
         }
29 29
 
30
-        //主机通讯地址&端口 
30
+        //远程监控设备的主机通讯地址&端口 
31 31
         this.host = remote.info.address;
32 32
 
33 33
         this.port = remote.info.port;
@@ -75,6 +75,25 @@ class NodeSipSession {
75 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 98
     async run(authModule,auto_play) {
80 99
 
@@ -760,7 +779,7 @@ class NodeSipSession {
760 779
 
761 780
             for (var key in this.dialogs) {
762 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 783
                     isFinded = true;
765 784
                     findssrc = session.ssrc;
766 785
                     break;
@@ -778,10 +797,10 @@ class NodeSipSession {
778 797
 
779 798
             //ssrc is here  -- by ntv wangjian
780 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 804
             let host = rhost || "127.0.0.1";
786 805
 
787 806
             let port = rport || 9200;
@@ -857,6 +876,9 @@ class NodeSipSession {
857 876
 
858 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 882
                                     //Step 7 SIP服务器收到媒体流发送者返回200 OK响应后,向 媒体流发送者 发送 ACK请求,请求中不携带消息体,完成与媒体流发送者的invite会话建立过程
861 883
                                     that.uas.send({
862 884
                                         method: 'ACK',
@@ -888,6 +910,9 @@ class NodeSipSession {
888 910
                                         }
889 911
 
890 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 918
                                     result.data = { ssrc: ssrc };
@@ -924,13 +949,17 @@ class NodeSipSession {
924 949
                 //搜索满足条件的会话
925 950
                 let session = this.dialogs[key];
926 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 953
                     //ntv 挪到回调中,TODO 这个指令发不成功!
929 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 959
                     this.uas.send(session.bye, (response) => {
931 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 964
                             ntv remove rtp连接断开时再emit这条消息,放到了stream/session中执行
936 965
                             */
@@ -944,7 +973,7 @@ class NodeSipSession {
944 973
                                 }
945 974
                                 
946 975
                             });
947
-                        }
976
+                        //}
948 977
                     });
949 978
 
950 979
                     //ntv

+ 4
- 1
core/ctx.js Visa fil

@@ -12,4 +12,7 @@ let stat = {
12 12
   outbytes: 0,
13 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 Visa fil

@@ -76,6 +76,11 @@ class NodeGB28181StreamServer {
76 76
                 context.publishers.delete(key);
77 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 86
         //ntv add 上一个函数主动关闭,或网络异常,或其他原因关闭rtmp

+ 1
- 1
stream/session.js Visa fil

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

Laddar…
Avbryt
Spara