Skip to content

Commit 37e7da4

Browse files
Don't keep our own copy of auth credentials. Use the global ones. When getting new auth from status request, update auth_relay as well.
1 parent 1b36941 commit 37e7da4

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

web/js/MonitorStream.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const streaming = [];
55
function MonitorStream(monitorData) {
66
this.id = monitorData.id;
77
this.connKey = monitorData.connKey;
8-
this.auth_relay = auth_relay;
9-
this.auth_hash = auth_hash;
108
this.url = monitorData.url;
119
this.url_to_zms = monitorData.url_to_zms;
1210
this.width = monitorData.width;
@@ -85,7 +83,7 @@ function MonitorStream(monitorData) {
8583
this.show = function() {
8684
const stream = this.getElement();
8785
if (!stream.src) {
88-
stream.src = this.url_to_zms+"&mode=single&scale="+this.scale+"&connkey="+this.connKey+this.auth_relay;
86+
stream.src = this.url_to_zms+"&mode=single&scale="+this.scale+"&connkey="+this.connKey+'&'+auth_relay;
8987
}
9088
};
9189

@@ -311,7 +309,7 @@ function MonitorStream(monitorData) {
311309
stream.setAttribute('loading', 'eager');
312310
}
313311
let src = stream.src.replace(/mode=single/i, 'mode=jpeg');
314-
src = src.replace(/auth=\w+/i, 'auth='+this.auth_hash);
312+
src = src.replace(/auth=\w+/i, 'auth='+auth_hash);
315313
if (-1 == src.search('connkey')) {
316314
src += '&connkey='+this.connKey;
317315
}
@@ -650,10 +648,11 @@ function MonitorStream(monitorData) {
650648
} // end if canEdit.Monitors
651649

652650
if (this.status.auth) {
653-
if (this.status.auth != this.auth_hash) {
651+
if (this.status.auth != auth_hash) {
654652
// Don't reload the stream because it causes annoying flickering. Wait until the stream breaks.
655-
console.log("Changed auth from " + this.auth_hash + " to " + this.status.auth);
656-
this.streamCmdParms.auth = auth_hash = this.auth_hash = this.status.auth;
653+
console.log("Changed auth from " + auth_hash + " to " + this.status.auth);
654+
auth_hash = this.status.auth;
655+
auth_relay = this.status.auth_relay;
657656
}
658657
} // end if have a new auth hash
659658
} // end if has state
@@ -663,7 +662,7 @@ function MonitorStream(monitorData) {
663662
if (stream.src) {
664663
console.log('Reloading stream: ' + stream.src);
665664
let src = stream.src.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) ));
666-
src = src.replace(/auth=\w+/i, 'auth='+this.auth_hash);
665+
src = src.replace(/auth=\w+/i, 'auth='+auth_hash);
667666
// Maybe updated auth
668667
if (src != stream.src) {
669668
stream.src = '';
@@ -756,20 +755,20 @@ function MonitorStream(monitorData) {
756755
this.setAlarmState(monitorStatus);
757756

758757
if (respObj.auth_hash) {
759-
if (this.auth_hash != respObj.auth_hash) {
758+
if (auth_hash != respObj.auth_hash) {
760759
// Don't reload the stream because it causes annoying flickering. Wait until the stream breaks.
761-
console.log("Changed auth from " + this.auth_hash + " to " + respObj.auth_hash);
762-
this.streamCmdParms.auth = this.auth_hash = respObj.auth_hash;
763-
this.auth_relay = respObj.auth_relay;
760+
console.log("Changed auth from " + auth_hash + " to " + respObj.auth_hash);
761+
auth_hash = respObj.auth_hash;
762+
auth_relay = respObj.auth_relay;
764763
}
765764
} // end if have a new auth hash
766765
} else {
767766
checkStreamForErrors('getStatusCmdResponse', respObj);
768767
}
769768
}; // this.getStatusCmdResponse
770769

771-
this.statusCmdQuery=function() {
772-
$j.getJSON(this.url + '?view=request&request=status&entity=monitor&element[]=Status&element[]=CaptureFPS&element[]=AnalysisFPS&element[]=Analysing&element[]=Recording&id='+this.id+'&'+this.auth_relay)
770+
this.statusCmdQuery = function() {
771+
$j.getJSON(this.url + '?view=request&request=status&entity=monitor&element[]=Status&element[]=CaptureFPS&element[]=AnalysisFPS&element[]=Analysing&element[]=Recording&id='+this.id+'&'+auth_relay)
773772
.done(this.getStatusCmdResponse.bind(this))
774773
.fail(logAjaxFail);
775774
};
@@ -805,7 +804,7 @@ function MonitorStream(monitorData) {
805804

806805
this.alarmCommand = function(command) {
807806
if (this.ajaxQueue) {
808-
console.log("Aborting in progress ajax for alarm");
807+
console.log('Aborting in progress ajax for alarm');
809808
// Doing this for responsiveness, but we could be aborting something important. Need smarter logic
810809
this.ajaxQueue.abort();
811810
}
@@ -818,7 +817,7 @@ function MonitorStream(monitorData) {
818817
url: this.url + (auth_relay?'?'+auth_relay:''),
819818
xhrFields: {withCredentials: true},
820819
data: alarmCmdParms,
821-
dataType: "json"
820+
dataType: 'json'
822821
})
823822
.done(this.getStreamCmdResponse.bind(this))
824823
.fail(this.onFailure.bind(this));
@@ -832,7 +831,7 @@ function MonitorStream(monitorData) {
832831
url: this.url + (auth_relay?'?'+auth_relay:''),
833832
xhrFields: {withCredentials: true},
834833
data: streamCmdParms,
835-
dataType: "json"
834+
dataType: 'json'
836835
})
837836
.done(this.getStreamCmdResponse.bind(this))
838837
.fail(this.onFailure.bind(this));

0 commit comments

Comments
 (0)