Skip to content

Commit 445c306

Browse files
Merge pull request #4304 from IgorA100/patch-922375
Control RTCPeerConnection and video codec support, stop all monitors when closing the page, etc. (Monitor Stream)
2 parents 33cb2ec + 63a54f7 commit 445c306

File tree

6 files changed

+36
-5
lines changed

6 files changed

+36
-5
lines changed

web/js/MonitorStream.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const streaming = [];
44

55
function MonitorStream(monitorData) {
66
this.id = monitorData.id;
7+
this.name = monitorData.name;
78
this.started = false;
89
this.connKey = monitorData.connKey;
910
this.url = monitorData.url;
@@ -22,6 +23,7 @@ function MonitorStream(monitorData) {
2223
this.streamStartTime = 0; // Initial point of flow start time. Used for flow lag time analysis.
2324
this.waitingStart;
2425
this.mseListenerSourceopenBind = null;
26+
this.streamListenerBind = null;
2527
this.mseSourceBufferListenerUpdateendBind = null;
2628
this.mseStreamingStarted = false;
2729
this.mseQueue = [];
@@ -46,6 +48,7 @@ function MonitorStream(monitorData) {
4648
};
4749
this.ajaxQueue = null;
4850
this.type = monitorData.type;
51+
this.capturing = monitorData.capturing;
4952
this.refresh = monitorData.refresh;
5053

5154
this.buttons = {}; // index by name
@@ -240,6 +243,8 @@ function MonitorStream(monitorData) {
240243

241244
this.start = function(streamChannel = 'default') {
242245
console.debug(`! ${dateTimeToISOLocal(new Date())} Stream for ID=${this.id} STARTED`);
246+
this.streamListenerBind = streamListener.bind(null, this);
247+
243248
if (this.janusEnabled) {
244249
let server;
245250
if (ZM_JANUS_PATH) {
@@ -261,6 +266,7 @@ function MonitorStream(monitorData) {
261266
attachVideo(parseInt(this.id), this.janusPin);
262267
this.statusCmdTimer = setInterval(this.statusCmdQuery.bind(this), statusRefreshTimeout);
263268
this.started = true;
269+
this.streamListenerBind();
264270
return;
265271
}
266272
if (this.RTSP2WebEnabled) {
@@ -305,6 +311,7 @@ function MonitorStream(monitorData) {
305311
clearInterval(this.statusCmdTimer); // Fix for issues in Chromium when quickly hiding/showing a page. Doesn't clear statusCmdTimer when minimizing a page https://stackoverflow.com/questions/9501813/clearinterval-not-working
306312
this.statusCmdTimer = setInterval(this.statusCmdQuery.bind(this), statusRefreshTimeout);
307313
this.started = true;
314+
this.streamListenerBind();
308315
return;
309316
} else {
310317
console.log("ZM_RTSP2WEB_PATH is empty. Go to Options->System and set ZM_RTSP2WEB_PATH accordingly.");
@@ -338,6 +345,7 @@ function MonitorStream(monitorData) {
338345
stream.onerror = this.img_onerror.bind(this);
339346
stream.onload = this.img_onload.bind(this);
340347
this.started = true;
348+
this.streamListenerBind();
341349
}; // this.start
342350

343351
this.stop = function() {
@@ -1133,6 +1141,14 @@ const waitUntil = (condition) => {
11331141
};
11341142

11351143
function startRTSP2WebPlay(videoEl, url, stream) {
1144+
if (typeof RTCPeerConnection !== 'function') {
1145+
const msg = `Your browser does not support 'RTCPeerConnection'. Monitor '${stream.name}' ID=${stream.id} not started.`;
1146+
console.log(msg);
1147+
stream.getElement().before(document.createTextNode(msg));
1148+
stream.RTSP2WebType = null; // Avoid repeated restarts.
1149+
return;
1150+
}
1151+
11361152
const mediaStream = new MediaStream();
11371153
if (stream.webrtc) {
11381154
stream.webrtc.close();
@@ -1218,14 +1234,16 @@ function startRTSP2WebPlay(videoEl, url, stream) {
12181234
webrtcSendChannel.onmessage = (event) => console.log(event.data);
12191235
}
12201236

1237+
function streamListener(stream) {
1238+
window.addEventListener('beforeunload', function(event) {
1239+
stream.kill();
1240+
});
1241+
}
1242+
12211243
function mseListenerSourceopen(context, videoEl, url) {
12221244
context.wsMSE = new WebSocket(url);
12231245
context.wsMSE.binaryType = 'arraybuffer';
12241246

1225-
window.addEventListener('beforeunload', function(event) {
1226-
this.started = false;
1227-
context.closeWebSocket();
1228-
});
12291247
context.wsMSE.onopen = function(event) {
12301248
console.log(`Connect to ws for a video object ID=${context.id}`);
12311249
};
@@ -1252,8 +1270,11 @@ function mseListenerSourceopen(context, videoEl, url) {
12521270
if (MediaSource.isTypeSupported('video/mp4; codecs="' + mimeCodec + '"')) {
12531271
console.log(`For a video object ID=${context.id} codec used: ${mimeCodec}`);
12541272
} else {
1255-
console.log(`For a video object ID=${context.id} codec '${mimeCodec}' not supported.`);
1273+
const msg = `For a video object ID=${context.id} codec '${mimeCodec}' not supported. Monitor '${context.name}' ID=${context.id} not starting.`;
1274+
console.log(msg);
1275+
context.getElement().before(document.createTextNode(msg));
12561276
context.stop();
1277+
context.RTSP2WebType = null; // Avoid repeated restarts
12571278
return;
12581279
}
12591280

web/skins/classic/views/js/cycle.js.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
?>
1717
monitorData[monitorData.length] = {
1818
'id': <?php echo $monitor->Id() ?>,
19+
'name': '<?php echo $monitor->Name() ?>',
1920
'connKey': '<?php echo $monitor->connKey() ?>',
2021
'width': <?php echo $monitor->ViewWidth() ?>,
2122
'height':<?php echo $monitor->ViewHeight() ?>,
2223
'url': '<?php echo $monitor->UrlToIndex() ?>',
2324
'onclick': function(){window.location.assign( '?view=watch&mid=<?php echo $monitor->Id() ?>' );},
2425
'type': '<?php echo $monitor->Type() ?>',
26+
'capturing': '<?php echo $monitor->Capturing() ?>',
2527
'refresh': '<?php echo $monitor->Refresh() ?>',
2628
'RTSP2WebEnabled': <?php echo $monitor->RTSP2WebEnabled() ?>,
2729
'RTSP2WebType': '<?php echo $monitor->RTSP2WebType() ?>',

web/skins/classic/views/js/montage.js.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
?>
2222
monitorData[monitorData.length] = {
2323
'id': <?php echo $monitor->Id() ?>,
24+
'name': '<?php echo $monitor->Name() ?>',
2425
'server_id': '<?php echo $monitor->ServerId() ?>',
2526
'connKey': '<?php echo $monitor->connKey() ?>',
2627
'width': <?php echo $monitor->ViewWidth() ?>,
@@ -35,6 +36,7 @@
3536
'url_to_snapshot': '<?php echo $monitor->UrlToZMS(ZM_MIN_STREAMING_PORT ? ($monitor->Id() + ZM_MIN_STREAMING_PORT) : '').'&mode=single' ?>',
3637
'onclick': function(){window.location.assign( '?view=watch&mid=<?php echo $monitor->Id() ?>' );},
3738
'type': '<?php echo $monitor->Type() ?>',
39+
'capturing': '<?php echo $monitor->Capturing() ?>',
3840
'refresh': '<?php echo $monitor->Refresh() ?>',
3941
'janus_pin': '<?php echo $monitor->Janus_Pin() ?>'
4042
};

web/skins/classic/views/js/watch.js.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
?>
4444
monitorData[monitorData.length] = {
4545
'id': <?php echo $m->Id() ?>,
46+
'name': '<?php echo $m->Name() ?>',
4647
'server_id': '<?php echo $m->ServerId() ?>',
4748
'connKey': <?php echo $m->connKey() ?>,
4849
'width': <?php echo $m->ViewWidth() ?>,
@@ -55,6 +56,7 @@
5556
'url': '<?php echo $m->UrlToIndex(ZM_MIN_STREAMING_PORT ? ($m->Id() + ZM_MIN_STREAMING_PORT) : '') ?>',
5657
'onclick': function(){window.location.assign( '?view=watch&mid=<?php echo $m->Id() ?>' );},
5758
'type': '<?php echo $m->Type() ?>',
59+
'capturing': '<?php echo $m->Capturing() ?>',
5860
'refresh': '<?php echo $m->Refresh() ?>',
5961
'janus_pin': '<?php echo $m->Janus_Pin() ?>',
6062
'streamHTML': '<?php echo str_replace(array("\r\n", "\r", "\n"), '', $monitorsExtraData[$m->Id()]['StreamHTML']) ?>',

web/skins/classic/views/js/zone.js.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
var monitorData = new Array();
6868
monitorData[monitorData.length] = {
6969
'id': <?php echo $monitor->Id() ?>,
70+
'name': '<?php echo $monitor->Name() ?>',
7071
'connKey': <?php echo $monitor->connKey() ?>,
7172
'width': <?php echo $monitor->ViewWidth() ?>,
7273
'height':<?php echo $monitor->ViewHeight() ?>,
@@ -77,6 +78,7 @@
7778
'url': '<?php echo $monitor->UrlToIndex( ZM_MIN_STREAMING_PORT ? ($monitor->Id() + ZM_MIN_STREAMING_PORT) : '') ?>',
7879
'url_to_zms': '<?php echo $monitor->UrlToZMS( ZM_MIN_STREAMING_PORT ? ($monitor->Id() + ZM_MIN_STREAMING_PORT) : '') ?>',
7980
'type': '<?php echo $monitor->Type() ?>',
81+
'capturing': '<?php echo $monitor->Capturing() ?>',
8082
'refresh': '<?php echo $monitor->Refresh() ?>',
8183
'janus_pin': '<?php echo $monitor->Janus_Pin() ?>'
8284
};

web/skins/classic/views/js/zones.js.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
?>
1212
monitorData[monitorData.length] = {
1313
'id': <?php echo $monitor->Id() ?>,
14+
'name': '<?php echo $monitor->Name() ?>',
1415
'connKey': <?php echo $monitor->connKey() ?>,
1516
'width': <?php echo $monitor->ViewWidth() ?>,
1617
'height':<?php echo $monitor->ViewHeight() ?>,
@@ -21,6 +22,7 @@
2122
'url': '<?php echo $monitor->UrlToIndex( ZM_MIN_STREAMING_PORT ? ($monitor->Id() + ZM_MIN_STREAMING_PORT) : '') ?>',
2223
'url_to_zms': '<?php echo $monitor->UrlToZMS( ZM_MIN_STREAMING_PORT ? ($monitor->Id() + ZM_MIN_STREAMING_PORT) : '') ?>',
2324
'type': '<?php echo $monitor->Type() ?>',
25+
'capturing': '<?php echo $monitor->Capturing() ?>',
2426
'refresh': '<?php echo $monitor->Refresh() ?>',
2527
'janus_pin': '<?php echo $monitor->Janus_Pin() ?>'
2628
};

0 commit comments

Comments
 (0)