Skip to content

Commit 1b52354

Browse files
Merge pull request #93 from RogerHardiman/master
Multiple WWW-Authenticate, Add -t to Demo Example, handle RTP/AVP/UDP
2 parents 0f518df + 55a6837 commit 1b52354

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

examples/demo.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ program.description("Yellowstone RTSP Client Test Software");
2323
program.option('-u, --username <value>', 'Optional RTSP Username');
2424
program.option('-p, --password <value>', 'Optional RTSP Password');
2525
program.option('-o, --outfile <value>', 'Optional Output File with no File Extension for captured H264/H265/AV1/AAC');
26+
program.option('-t, --transport <value>', 'Optional RTP Transport - UDP or TCP');
2627

2728
program.argument('<rtsp url eg rtsp://1.2.3.4/stream1>');
2829

@@ -36,7 +37,10 @@ let password = "";
3637
if ('username' in options) username = options.username;
3738
if ('password' in options) password = options.password;
3839

39-
const filename = "outfile"
40+
let transport = "tcp";
41+
if ('transport' in options) transport = options.transport.toString().toLowerCase();
42+
43+
const filename = "outfile"
4044

4145
console.log("Connecting to " + url);
4246

@@ -48,7 +52,7 @@ const client = new RTSPClient(username, password);
4852
// "keepAlive" option is set to true by default
4953
// "connection" option is set to "udp" by default and defines the method the RTP media packets are set to Yellowstone. Options are "udp" or "tcp" (where RTP media packets are sent down the RTSP connection)
5054
// "secure" option is set to true when connecting with TLS to the RTSP Server (eg for RTSPS)
51-
client.connect(url, { connection: "tcp", secure: false })
55+
client.connect(url, { connection: transport, secure: false })
5256
.then(async (detailsArray) => {
5357
console.log("Connected");
5458

lib/RTSPClient.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,15 @@ export default class RTSPClient extends EventEmitter {
504504

505505
const transport = parseTransport(headers.Transport);
506506
if (
507+
// TCP
507508
transport.protocol !== "RTP/AVP/TCP" &&
508-
transport.protocol !== "RTP/AVP"
509+
// UDP
510+
transport.protocol !== "RTP/AVP" &&
511+
// UDP
512+
transport.protocol !== "RTP/AVP/UDP" // Panasonic cameras send this
509513
) {
510514
throw new Error(
511-
"Only RTSP servers supporting RTP/AVP(unicast) or RTP/AVP/TCP are supported at this time."
515+
"Only RTSP servers supporting RTP/AVP or RTP/AVP/UDP or RTP/AVP/TCP are supported at this time."
512516
);
513517
}
514518

@@ -889,10 +893,30 @@ export default class RTSPClient extends EventEmitter {
889893
const key = line.substring(0, indexOf).trim();
890894
const data = line.substring(indexOf + 1).trim();
891895

892-
this.rtspHeaders[key] =
893-
key != "Session" && data.match(/^[0-9]+$/)
896+
if (key == "Session") this.rtspHeaders[key] = data;
897+
898+
else if (key == "WWW-Authenticate") {
899+
// Handle multiple WWW-Authenticate entries and pick the 'best'
900+
// We prefer 'Digest' over 'Basic'
901+
// We preger 'Digest SHAxxx' over 'Digest MD5' or 'Digest with no algorithm (defaults to MD5) (STILL TODO)
902+
if (key in this.rtspHeaders) {
903+
console.log("Duplicate WWW-Authenticate keys")
904+
if (data.startsWith("Digest") && this.rtspHeaders[key]?.startsWith("Basic")) {
905+
this.rtspHeaders[key] = data; // Replace Basic with Digest
906+
}
907+
console.log("Keeping WWW-Authenticate: " + this.rtspHeaders[key]);
908+
} else {
909+
this.rtspHeaders[key] = data;
910+
}
911+
}
912+
913+
else {
914+
// Store the result as either a String type or a Number type
915+
this.rtspHeaders[key] =
916+
data.match(/^[0-9]+$/)
894917
? parseInt(data, 10)
895918
: data;
919+
}
896920

897921
// workaround for buggy Hipcam RealServer/V1.0 camera which returns Content-length and not Content-Length
898922
if (key.toLowerCase() == "content-length") {

0 commit comments

Comments
 (0)