Skip to content

Commit 2df32fb

Browse files
committed
Add session header. Fixes some RTSP clients like VLC
1 parent 9d8748e commit 2df32fb

File tree

5 files changed

+52
-47
lines changed

5 files changed

+52
-47
lines changed

lib/Client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class Client {
128128
} catch(e){
129129
//Ignore
130130
}
131-
}, 30000);
131+
}, 6e4);
132132
}
133133
}
134134

lib/ClientServer.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ class ClientServer {
3939
}
4040

4141
optionsRequest(req, res){
42-
if(req.socket.uuid){
43-
let client = this.clients[req.socket.uuid];
44-
client.keepalive();
42+
// Update the client timeout if they provide a session
43+
if(req.headers.session){
44+
let client = this.clients[req.headers.session];
45+
if (client){
46+
client.keepalive();
47+
} else {
48+
res.statusCode = 454; // Session not found
49+
return res.end();
50+
}
4551
}
4652

47-
res.setHeader('SETUP PLAY STOP', 'OPTIONS');
53+
res.setHeader('DESCRIBE SETUP PLAY STOP', 'OPTIONS');
4854
return res.end();
4955
}
5056

@@ -84,18 +90,18 @@ class ClientServer {
8490
this.clients[client.id] = client;
8591

8692
res.setHeader('Transport', `${req.headers.transport};server_port=${client.rtpStartPort}-${client.rtpEndPort}`);
93+
res.setHeader('Session', `${client.id};30`);
8794
res.end();
8895
}
8996

9097

9198
async playRequest(req, res){
92-
let clientId = req.socket.uuid;
93-
if(!clientId){
94-
res.statusCode = 404;
99+
if(!req.headers.session || !this.clients[req.headers.session]){
100+
res.statusCode = 454;
95101
return res.end();
96102
}
97103

98-
let client = this.clients[clientId];
104+
let client = this.clients[req.headers.session];
99105
client.play();
100106

101107
if(client.mount.range){
@@ -107,13 +113,12 @@ class ClientServer {
107113

108114

109115
teardownRequest(req, res){
110-
let clientId = req.socket.uuid;
111-
if(!clientId){
112-
res.statusCode = 404;
116+
if(!req.headers.session || !this.clients[req.headers.session]){
117+
res.statusCode = 454;
113118
return res.end();
114119
}
115120

116-
let client = this.clients[clientId];
121+
let client = this.clients[req.headers.session];
117122
client.close();
118123

119124
res.end();

lib/Server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Server {
3737
}
3838

3939
optionsRequest(req, res){
40-
res.setHeader('SETUP ANNOUNCE RECORD', 'OPTIONS');
40+
res.setHeader('DESCRIBE SETUP ANNOUNCE RECORD', 'OPTIONS');
4141
return res.end();
4242
}
4343

package-lock.json

+30-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rtsp-streaming-server",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Lightweight RTSP/RTP streaming media server written in Javascript",
55
"main": "rtsp-server.js",
66
"scripts": {
@@ -11,8 +11,8 @@
1111
"license": "GPL-3.0",
1212
"dependencies": {
1313
"rtsp-server": "^1.2.2",
14-
"uuid": "^3.2.1",
15-
"winston": "^2.4.0"
14+
"uuid": "^3.3.2",
15+
"winston": "^2.4.4"
1616
},
1717
"engines": {
1818
"node": "^8.0.0"

0 commit comments

Comments
 (0)