@@ -4,6 +4,7 @@ const streaming = [];
4
4
5
5
function MonitorStream ( monitorData ) {
6
6
this . id = monitorData . id ;
7
+ this . name = monitorData . name ;
7
8
this . started = false ;
8
9
this . connKey = monitorData . connKey ;
9
10
this . url = monitorData . url ;
@@ -22,6 +23,7 @@ function MonitorStream(monitorData) {
22
23
this . streamStartTime = 0 ; // Initial point of flow start time. Used for flow lag time analysis.
23
24
this . waitingStart ;
24
25
this . mseListenerSourceopenBind = null ;
26
+ this . streamListenerBind = null ;
25
27
this . mseSourceBufferListenerUpdateendBind = null ;
26
28
this . mseStreamingStarted = false ;
27
29
this . mseQueue = [ ] ;
@@ -46,6 +48,7 @@ function MonitorStream(monitorData) {
46
48
} ;
47
49
this . ajaxQueue = null ;
48
50
this . type = monitorData . type ;
51
+ this . capturing = monitorData . capturing ;
49
52
this . refresh = monitorData . refresh ;
50
53
51
54
this . buttons = { } ; // index by name
@@ -240,6 +243,8 @@ function MonitorStream(monitorData) {
240
243
241
244
this . start = function ( streamChannel = 'default' ) {
242
245
console . debug ( `! ${ dateTimeToISOLocal ( new Date ( ) ) } Stream for ID=${ this . id } STARTED` ) ;
246
+ this . streamListenerBind = streamListener . bind ( null , this ) ;
247
+
243
248
if ( this . janusEnabled ) {
244
249
let server ;
245
250
if ( ZM_JANUS_PATH ) {
@@ -261,6 +266,7 @@ function MonitorStream(monitorData) {
261
266
attachVideo ( parseInt ( this . id ) , this . janusPin ) ;
262
267
this . statusCmdTimer = setInterval ( this . statusCmdQuery . bind ( this ) , statusRefreshTimeout ) ;
263
268
this . started = true ;
269
+ this . streamListenerBind ( ) ;
264
270
return ;
265
271
}
266
272
if ( this . RTSP2WebEnabled ) {
@@ -305,6 +311,7 @@ function MonitorStream(monitorData) {
305
311
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
306
312
this . statusCmdTimer = setInterval ( this . statusCmdQuery . bind ( this ) , statusRefreshTimeout ) ;
307
313
this . started = true ;
314
+ this . streamListenerBind ( ) ;
308
315
return ;
309
316
} else {
310
317
console . log ( "ZM_RTSP2WEB_PATH is empty. Go to Options->System and set ZM_RTSP2WEB_PATH accordingly." ) ;
@@ -338,6 +345,7 @@ function MonitorStream(monitorData) {
338
345
stream . onerror = this . img_onerror . bind ( this ) ;
339
346
stream . onload = this . img_onload . bind ( this ) ;
340
347
this . started = true ;
348
+ this . streamListenerBind ( ) ;
341
349
} ; // this.start
342
350
343
351
this . stop = function ( ) {
@@ -1133,6 +1141,14 @@ const waitUntil = (condition) => {
1133
1141
} ;
1134
1142
1135
1143
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
+
1136
1152
const mediaStream = new MediaStream ( ) ;
1137
1153
if ( stream . webrtc ) {
1138
1154
stream . webrtc . close ( ) ;
@@ -1218,14 +1234,16 @@ function startRTSP2WebPlay(videoEl, url, stream) {
1218
1234
webrtcSendChannel . onmessage = ( event ) => console . log ( event . data ) ;
1219
1235
}
1220
1236
1237
+ function streamListener ( stream ) {
1238
+ window . addEventListener ( 'beforeunload' , function ( event ) {
1239
+ stream . kill ( ) ;
1240
+ } ) ;
1241
+ }
1242
+
1221
1243
function mseListenerSourceopen ( context , videoEl , url ) {
1222
1244
context . wsMSE = new WebSocket ( url ) ;
1223
1245
context . wsMSE . binaryType = 'arraybuffer' ;
1224
1246
1225
- window . addEventListener ( 'beforeunload' , function ( event ) {
1226
- this . started = false ;
1227
- context . closeWebSocket ( ) ;
1228
- } ) ;
1229
1247
context . wsMSE . onopen = function ( event ) {
1230
1248
console . log ( `Connect to ws for a video object ID=${ context . id } ` ) ;
1231
1249
} ;
@@ -1252,8 +1270,11 @@ function mseListenerSourceopen(context, videoEl, url) {
1252
1270
if ( MediaSource . isTypeSupported ( 'video/mp4; codecs="' + mimeCodec + '"' ) ) {
1253
1271
console . log ( `For a video object ID=${ context . id } codec used: ${ mimeCodec } ` ) ;
1254
1272
} 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 ) ) ;
1256
1276
context . stop ( ) ;
1277
+ context . RTSP2WebType = null ; // Avoid repeated restarts
1257
1278
return ;
1258
1279
}
1259
1280
0 commit comments