File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -908,10 +908,30 @@ export default class RTSPClient extends EventEmitter {
908908 const key = line . substring ( 0 , indexOf ) . trim ( ) ;
909909 const data = line . substring ( indexOf + 1 ) . trim ( ) ;
910910
911- this . rtspHeaders [ key ] =
912- key != "Session" && data . match ( / ^ [ 0 - 9 ] + $ / )
911+ if ( key == "Session" ) this . rtspHeaders [ key ] = data ;
912+
913+ else if ( key == "WWW-Authenticate" ) {
914+ // Handle multiple WWW-Authenticate entries and pick the 'best'
915+ // We prefer 'Digest' over 'Basic'
916+ // We preger 'Digest SHAxxx' over 'Digest MD5' or 'Digest with no algorithm (defaults to MD5) (STILL TODO)
917+ if ( key in this . rtspHeaders ) {
918+ console . log ( "Duplicate WWW-Authenticate keys" )
919+ if ( data . startsWith ( "Digest" ) && this . rtspHeaders [ key ] ?. startsWith ( "Basic" ) ) {
920+ this . rtspHeaders [ key ] = data ; // Replace Basic with Digest
921+ }
922+ console . log ( "Keeping WWW-Authenticate: " + this . rtspHeaders [ key ] ) ;
923+ } else {
924+ this . rtspHeaders [ key ] = data ;
925+ }
926+ }
927+
928+ else {
929+ // Store the result as either a String type or a Number type
930+ this . rtspHeaders [ key ] =
931+ data . match ( / ^ [ 0 - 9 ] + $ / )
913932 ? parseInt ( data , 10 )
914933 : data ;
934+ }
915935
916936 // workaround for buggy Hipcam RealServer/V1.0 camera which returns Content-length and not Content-Length
917937 if ( key . toLowerCase ( ) == "content-length" ) {
You can’t perform that action at this time.
0 commit comments