@@ -397,6 +397,25 @@ function MonitorStream(monitorData) {
397397 return channelMap [ channel ] !== undefined ? channelMap [ channel ] : 0 ;
398398 } ;
399399
400+ this . handlerEventListenerStream = function ( stream = null ) {
401+ if ( ! stream ) stream = this . getAVStream ( ) ;
402+ if ( ! stream ) {
403+ console . debug ( `Stream for monitor ID=${ this . id } not found. Assigning listeners is not possible.` ) ;
404+ return ;
405+ }
406+ this . handlerEventListener [ 'playStream' ] = manageEventListener . addEventListener ( stream , 'play' ,
407+ ( e ) => {
408+ this . createVolumeSlider ( ) ;
409+ getTracksFromStream ( this ) ; //Go2rtc
410+ }
411+ ) ;
412+ this . handlerEventListener [ 'pauseStream' ] = manageEventListener . addEventListener ( stream , 'pause' ,
413+ ( e ) => {
414+ manageEventListener . removeEventListener ( this . handlerEventListener [ 'volumechange' ] ) ;
415+ }
416+ ) ;
417+ } ;
418+
400419 this . start = function ( streamChannel = 'default' ) {
401420 if ( streamChannel === null || streamChannel === '' || currentView == 'montage' ) streamChannel = 'default' ;
402421 // Normalize channel name for internal tracking
@@ -433,13 +452,9 @@ function MonitorStream(monitorData) {
433452 if ( - 1 != this . player . indexOf ( '_' ) ) {
434453 stream . mode = this . player . substring ( this . player . indexOf ( '_' ) + 1 ) ;
435454 }
436- const video_el = document . querySelector ( '#liveStream' + this . id + ' video' ) ;
437- if ( video_el ) {
438- video_el . muted = this . muted ;
439- video_el . addEventListener ( 'play' , ( e ) => {
440- this . createVolumeSlider ( ) ;
441- } , this ) ;
442- }
455+ const video_el = this . getAVStream ( ) ;
456+ if ( video_el ) video_el . muted = this . muted ;
457+ this . handlerEventListenerStream ( video_el ) ;
443458
444459 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
445460 this . statusCmdTimer = setInterval ( this . statusCmdQuery . bind ( this ) , statusRefreshTimeout ) ;
@@ -460,12 +475,9 @@ function MonitorStream(monitorData) {
460475 stream . srcObject = null ;
461476 stream . setAttribute ( "autoplay" , "" ) ;
462477 stream . setAttribute ( "muted" , this . muted ) ;
463- const video_el = document . querySelector ( '#liveStream' + this . id ) ;
464- if ( video_el ) {
465- video_el . addEventListener ( 'play' , ( e ) => {
466- this . createVolumeSlider ( ) ;
467- } , this ) ;
468- }
478+ const video_el = this . getAVStream ( ) ;
479+ if ( video_el ) video_el . muted = this . muted ;
480+ this . handlerEventListenerStream ( video_el ) ;
469481 if ( ZM_JANUS_PATH ) {
470482 server = ZM_JANUS_PATH ;
471483 } else if ( this . server_id && Servers [ this . server_id ] ) {
@@ -503,13 +515,9 @@ function MonitorStream(monitorData) {
503515 const useSSL = ( url . protocol == 'https' ) ;
504516
505517 const rtsp2webModUrl = url ;
506- const video_el = document . querySelector ( 'video#liveStream' + this . id ) ;
507- if ( video_el ) {
508- video_el . muted = this . muted ;
509- video_el . addEventListener ( 'play' , ( e ) => {
510- this . createVolumeSlider ( ) ;
511- } , this ) ;
512- }
518+ const video_el = this . getAVStream ( ) ;
519+ if ( video_el ) video_el . muted = this . muted ;
520+ this . handlerEventListenerStream ( video_el ) ;
513521 rtsp2webModUrl . username = '' ;
514522 rtsp2webModUrl . password = '' ;
515523 //.urlParts.length > 1 ? urlParts[1] : urlParts[0]; // drop the username and password for viewing
@@ -533,7 +541,7 @@ function MonitorStream(monitorData) {
533541 this . hls . on ( Hls . Events . MEDIA_ATTACHED , function ( event , data ) {
534542 console . log ( `Video and hls.js are now bound together for monitor ID=${ this . id } ` ) ;
535543 this . updateStreamInfo ( '' , '' ) ; //HLS
536- getTracksFromStream ( this ) ; //HLS
544+ // getTracksFromStream(this); //HLS
537545 } , this ) ;
538546 this . hls . loadSource ( hlsUrl . href ) ;
539547 this . hls . attachMedia ( stream ) ;
@@ -628,6 +636,9 @@ function MonitorStream(monitorData) {
628636
629637 this . stop = function ( ) {
630638 manageEventListener . removeEventListener ( this . handlerEventListener [ 'killStream' ] ) ;
639+ manageEventListener . removeEventListener ( this . handlerEventListener [ 'playStream' ] ) ;
640+ if ( manageEventListener . removeEventListener ( this . handlerEventListener [ 'volumechange' ] ) == this . handlerEventListener [ 'volumechange' ] ) this . handlerEventListener [ 'volumechange' ] = null ;
641+ manageEventListener . removeEventListener ( this . handlerEventListener [ 'pauseStream' ] ) ;
631642
632643 /* Stop should stop the stream (killing zms) but NOT set src=''; This leaves the last jpeg up on screen instead of a broken image */
633644 const stream = this . getElement ( ) ;
@@ -893,7 +904,7 @@ function MonitorStream(monitorData) {
893904 return ( document . getElementById ( 'controlMute' ) ) ? document . getElementById ( 'controlMute' ) : document . getElementById ( 'controlMute' + this . id ) ;
894905 } ;
895906
896- this . getAudioStream = function ( ) {
907+ this . getAVStream = function ( ) {
897908 /*
898909 Go2RTC uses <video-stream id='liveStreamXX'><video></video></video-stream>,
899910 RTSP2Web uses <video id='liveStreamXX'></video>
@@ -932,10 +943,17 @@ function MonitorStream(monitorData) {
932943
933944 this . createVolumeSlider = function ( ) {
934945 const volumeSlider = this . getVolumeSlider ( ) ;
935- const audioStream = this . getAudioStream ( ) ;
946+ const audioStream = this . getAVStream ( ) ;
936947 if ( ! volumeSlider || ! audioStream ) return ;
937948 const iconMute = this . getIconMute ( ) ;
938949 $j ( '#volumeControls' + this . id ) . show ( ) ;
950+ if ( ! this . handlerEventListener [ 'volumechange' ] ) {
951+ this . handlerEventListener [ 'volumechange' ] = manageEventListener . addEventListener ( audioStream , 'volumechange' ,
952+ ( event ) => {
953+ this . listenerVolumechange ( event ) ;
954+ }
955+ ) ;
956+ }
939957 if ( volumeSlider . noUiSlider ) return ;
940958 const defaultVolume = ( volumeSlider . getAttribute ( "data-volume" ) || 50 ) ;
941959
@@ -956,15 +974,13 @@ function MonitorStream(monitorData) {
956974 } ) ;
957975 volumeSlider . allowSetValue = true ;
958976 volumeSlider . noUiSlider . on ( 'update' , function onUpdateUiSlider ( values , handle ) {
959- if ( audioStream ) {
960- audioStream . volume = values [ 0 ] / 100 ;
961- if ( values [ 0 ] > 0 && ! audioStream . muted ) {
962- iconMute . innerHTML = 'volume_up' ;
963- volumeSlider . classList . remove ( 'noUi-mute' ) ;
964- } else {
965- iconMute . innerHTML = 'volume_off' ;
966- volumeSlider . classList . add ( 'noUi-mute' ) ;
967- }
977+ audioStream . volume = values [ 0 ] / 100 ;
978+ if ( values [ 0 ] > 0 && ! audioStream . muted ) {
979+ iconMute . innerHTML = 'volume_up' ;
980+ volumeSlider . classList . remove ( 'noUi-mute' ) ;
981+ } else {
982+ iconMute . innerHTML = 'volume_off' ;
983+ volumeSlider . classList . add ( 'noUi-mute' ) ;
968984 }
969985 //console.log("Audio volume slider event: 'update'");
970986 } ) ;
@@ -992,12 +1008,6 @@ function MonitorStream(monitorData) {
9921008 } else {
9931009 this . controlMute ( 'on' ) ;
9941010 }
995-
996- if ( audioStream ) {
997- audioStream . addEventListener ( 'volumechange' , ( event ) => {
998- this . listenerVolumechange ( event ) ;
999- } ) ;
1000- }
10011011 } ;
10021012
10031013 this . destroyVolumeSlider = function ( ) {
@@ -1054,7 +1064,7 @@ function MonitorStream(monitorData) {
10541064 */
10551065 this . controlMute = function ( mode = 'switch' ) {
10561066 let volumeSlider = this . getVolumeSlider ( ) ;
1057- const audioStream = this . getAudioStream ( ) ;
1067+ const audioStream = this . getAVStream ( ) ;
10581068 const volumeControls = this . getVolumeControls ( ) ;
10591069 const disabled = ( volumeControls ) ? volumeControls . classList . contains ( 'disabled' ) : false ;
10601070
@@ -1800,7 +1810,7 @@ async function attachVideo(monitorStream) {
18001810 monitorStream . restart ( ) ;
18011811 }
18021812 monitorStream . updateStreamInfo ( '' , '' ) ; //JANUS
1803- getTracksFromStream ( monitorStream ) ; //JANUS
1813+ // getTracksFromStream(monitorStream); //JANUS
18041814 }
18051815 } ,
18061816 onremotetrack : function ( track , mid , on ) {
@@ -1988,7 +1998,7 @@ function startRTSP2WebPlay(videoEl, url, stream) {
19881998 const webrtcSendChannel = stream . webrtc . createDataChannel ( 'rtsptowebSendChannel' ) ;
19891999 webrtcSendChannel . onopen = ( event ) => {
19902000 stream . updateStreamInfo ( '' , '' ) ; //WEBRTC
1991- getTracksFromStream ( stream ) ; //WEBRTC
2001+ // getTracksFromStream(stream); //WEBRTC
19922002 console . log ( `${ webrtcSendChannel . label } for camera ID=${ stream . id } has opened` ) ;
19932003 webrtcSendChannel . send ( 'ping' ) ;
19942004 } ;
@@ -2083,7 +2093,7 @@ function startMsePlay(context, videoEl, url) {
20832093 context . mse = new MediaSource ( ) ;
20842094 videoEl . onplay = ( event ) => {
20852095 context . updateStreamInfo ( '' , '' ) ; //MSE
2086- getTracksFromStream ( context ) ; //MSE
2096+ // getTracksFromStream(context); //MSE
20872097 context . streamStartTime = ( Date . now ( ) / 1000 ) . toFixed ( 2 ) ;
20882098 if ( videoEl . buffered . length > 0 && videoEl . currentTime < videoEl . buffered . end ( videoEl . buffered . length - 1 ) - 0.1 ) {
20892099 //For example, after a pause you press Play, you need to adjust the time.
0 commit comments