From 2df32fbba478f23ce74fd70c927d7ddcddb4557f Mon Sep 17 00:00:00 2001 From: Chris Wiggins Date: Thu, 2 May 2019 14:59:07 +1200 Subject: [PATCH] Add session header. Fixes some RTSP clients like VLC --- lib/Client.js | 2 +- lib/ClientServer.js | 29 +++++++++++++--------- lib/Server.js | 2 +- package-lock.json | 60 ++++++++++++++++++++++----------------------- package.json | 6 ++--- 5 files changed, 52 insertions(+), 47 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 8469ac1..313ef5d 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -128,7 +128,7 @@ class Client { } catch(e){ //Ignore } - }, 30000); + }, 6e4); } } diff --git a/lib/ClientServer.js b/lib/ClientServer.js index b42c6dd..957baff 100644 --- a/lib/ClientServer.js +++ b/lib/ClientServer.js @@ -39,12 +39,18 @@ class ClientServer { } optionsRequest(req, res){ - if(req.socket.uuid){ - let client = this.clients[req.socket.uuid]; - client.keepalive(); + // Update the client timeout if they provide a session + if(req.headers.session){ + let client = this.clients[req.headers.session]; + if (client){ + client.keepalive(); + } else { + res.statusCode = 454; // Session not found + return res.end(); + } } - res.setHeader('SETUP PLAY STOP', 'OPTIONS'); + res.setHeader('DESCRIBE SETUP PLAY STOP', 'OPTIONS'); return res.end(); } @@ -84,18 +90,18 @@ class ClientServer { this.clients[client.id] = client; res.setHeader('Transport', `${req.headers.transport};server_port=${client.rtpStartPort}-${client.rtpEndPort}`); + res.setHeader('Session', `${client.id};30`); res.end(); } async playRequest(req, res){ - let clientId = req.socket.uuid; - if(!clientId){ - res.statusCode = 404; + if(!req.headers.session || !this.clients[req.headers.session]){ + res.statusCode = 454; return res.end(); } - let client = this.clients[clientId]; + let client = this.clients[req.headers.session]; client.play(); if(client.mount.range){ @@ -107,13 +113,12 @@ class ClientServer { teardownRequest(req, res){ - let clientId = req.socket.uuid; - if(!clientId){ - res.statusCode = 404; + if(!req.headers.session || !this.clients[req.headers.session]){ + res.statusCode = 454; return res.end(); } - let client = this.clients[clientId]; + let client = this.clients[req.headers.session]; client.close(); res.end(); diff --git a/lib/Server.js b/lib/Server.js index f93d3a4..4f866f6 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -37,7 +37,7 @@ class Server { } optionsRequest(req, res){ - res.setHeader('SETUP ANNOUNCE RECORD', 'OPTIONS'); + res.setHeader('DESCRIBE SETUP ANNOUNCE RECORD', 'OPTIONS'); return res.end(); } diff --git a/package-lock.json b/package-lock.json index 7dd6105..5fc6526 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "node-rtsp-streaming-server", - "version": "1.0.0", + "name": "rtsp-streaming-server", + "version": "1.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -42,8 +42,8 @@ "resolved": "https://registry.npmjs.org/http-headers/-/http-headers-1.2.0.tgz", "integrity": "sha1-DHVCOfwUrshYvaHL0Gnxcb+mo/o=", "requires": { - "next-line": "1.1.0", - "strip-lines": "1.0.1" + "next-line": "^1.0.0", + "strip-lines": "^1.0.1" } }, "inherits": { @@ -81,13 +81,13 @@ "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", "integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==", "requires": { - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "1.0.7", - "safe-buffer": "5.1.1", - "string_decoder": "1.0.3", - "util-deprecate": "1.0.2" + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~1.0.6", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.0.3", + "util-deprecate": "~1.0.1" } }, "rtsp-server": { @@ -95,8 +95,8 @@ "resolved": "https://registry.npmjs.org/rtsp-server/-/rtsp-server-1.2.2.tgz", "integrity": "sha1-BuSymJSKA9g6XHFzMK/2aGiLGr8=", "requires": { - "debug": "2.6.9", - "rtsp-stream": "1.0.0" + "debug": "^2.2.0", + "rtsp-stream": "^1.0.0" } }, "rtsp-stream": { @@ -104,10 +104,10 @@ "resolved": "https://registry.npmjs.org/rtsp-stream/-/rtsp-stream-1.0.0.tgz", "integrity": "sha1-n+oNf4GGfB8nI7pU8W3PawUY55U=", "requires": { - "debug": "2.6.9", - "http-headers": "1.2.0", - "next-line": "1.1.0", - "readable-stream": "2.3.3" + "debug": "^2.2.0", + "http-headers": "^1.2.0", + "next-line": "^1.1.0", + "readable-stream": "^2.0.2" } }, "safe-buffer": { @@ -125,7 +125,7 @@ "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", "requires": { - "safe-buffer": "5.1.1" + "safe-buffer": "~5.1.0" } }, "strip-lines": { @@ -139,21 +139,21 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "uuid": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz", - "integrity": "sha512-jZnMwlb9Iku/O3smGWvZhauCf6cvvpKi4BKRiliS3cxnI+Gz9j5MEpTz2UFuXiKPJocb7gnsLHwiS05ige5BEA==" + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", + "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==" }, "winston": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.0.tgz", - "integrity": "sha1-gIBQuT1SZh7Z+2wms/DIJnCLCu4=", + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.4.tgz", + "integrity": "sha512-NBo2Pepn4hK4V01UfcWcDlmiVTs7VTB1h7bgnB0rgP146bYhMxX0ypCz3lBOfNxCO4Zuek7yeT+y/zM1OfMw4Q==", "requires": { - "async": "1.0.0", - "colors": "1.0.3", - "cycle": "1.0.3", - "eyes": "0.1.8", - "isstream": "0.1.2", - "stack-trace": "0.0.10" + "async": "~1.0.0", + "colors": "1.0.x", + "cycle": "1.0.x", + "eyes": "0.1.x", + "isstream": "0.1.x", + "stack-trace": "0.0.x" } } } diff --git a/package.json b/package.json index f05d946..b063287 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rtsp-streaming-server", - "version": "1.0.1", + "version": "1.0.2", "description": "Lightweight RTSP/RTP streaming media server written in Javascript", "main": "rtsp-server.js", "scripts": { @@ -11,8 +11,8 @@ "license": "GPL-3.0", "dependencies": { "rtsp-server": "^1.2.2", - "uuid": "^3.2.1", - "winston": "^2.4.0" + "uuid": "^3.3.2", + "winston": "^2.4.4" }, "engines": { "node": "^8.0.0"