Skip to content

Commit

Permalink
Add session header. Fixes some RTSP clients like VLC
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswiggins committed May 2, 2019
1 parent 9d8748e commit 2df32fb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 47 deletions.
2 changes: 1 addition & 1 deletion lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Client {
} catch(e){
//Ignore
}
}, 30000);
}, 6e4);
}
}

Expand Down
29 changes: 17 additions & 12 deletions lib/ClientServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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){
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
60 changes: 30 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
Expand Down

0 comments on commit 2df32fb

Please sign in to comment.