@@ -468,7 +468,8 @@ function fetchImage(streamImage) {
468468function handleClick ( event ) {
469469 const targetId = event . target . id ;
470470 if ( targetId . indexOf ( "nav-link" ) >= 0 ) { //Navigation through monitors
471- cycleStop ( event . target ) ;
471+ cycleStop ( ) ;
472+ monIdx = event . target . getAttribute ( 'data-monIdx' ) ;
472473 const oldId = stringToNumber ( document . querySelector ( '[id ^= "liveStream"]' ) . id ) ;
473474 const newId = stringToNumber ( targetId ) ;
474475 streamReStart ( oldId , newId ) ;
@@ -778,7 +779,7 @@ function streamPrepareStart(monitor=null) {
778779 // Update table links each time after new data is loaded
779780 table . on ( 'post-body.bs.table' , function ( data ) {
780781 const thumb_ndx = $j ( '#eventList tr th' ) . filter ( function ( ) {
781- return $j ( this ) . text ( ) . trim ( ) == 'Thumbnail ' ;
782+ return $j ( this ) . attr ( 'data-field' ) . toLowerCase ( ) . trim ( ) == 'thumbnail ' ;
782783 } ) . index ( ) ;
783784 table . find ( "tr td:nth-child(" + ( thumb_ndx + 1 ) + ")" ) . addClass ( 'colThumbnail' ) ;
784785 } ) ;
@@ -887,15 +888,17 @@ function streamReStart(oldId, newId) {
887888 monitorId = newId ;
888889 filterQuery = '&filter[Query][terms][0][attr]=MonitorId&filter[Query][terms][0][op]=%3d&filter[Query][terms][0][val]=' + monitorId ;
889890
890- const newMonitorName = document . getElementById ( 'nav-item-cycle' + newId ) . querySelector ( 'a' ) . textContent ;
891- document . querySelector ( 'title' ) . textContent = newMonitorName ;
891+ // const newMonitorName = document.getElementById('nav-item-cycle'+newId).querySelector('a').textContent;
892+ document . querySelector ( 'title' ) . textContent = currentMonitor . name ;
892893 const url = new URL ( document . location . href ) ;
893894 url . searchParams . set ( 'mid' , monitorId ) ;
894895 history . pushState ( null , "" , url ) ;
895896
896897 zmPanZoom . action ( 'disable' , { id : oldId } ) ;
897898 if ( monitorStream ) {
898899 monitorStream . kill ( ) ;
900+ } else {
901+ console . log ( "No monitorStream?" ) ;
899902 }
900903
901904 const el = document . querySelector ( '.imageFeed' ) ;
@@ -1120,7 +1123,7 @@ function watchAllEvents() {
11201123 window . location . replace ( currentMonitor . urlForAllEvents ) ;
11211124}
11221125
1123- var intervalId ;
1126+ var cycleIntervalId ;
11241127var secondsToCycle = 0 ;
11251128
11261129function nextCycleView ( ) {
@@ -1132,58 +1135,51 @@ function nextCycleView() {
11321135}
11331136
11341137function cyclePause ( ) {
1135- clearInterval ( intervalId ) ;
1138+ clearInterval ( cycleIntervalId ) ;
11361139 cycle = false ;
11371140 $j ( '#cyclePauseBtn' ) . hide ( ) ;
11381141 $j ( '#cyclePlayBtn' ) . show ( ) ;
11391142}
11401143
11411144function cycleStart ( ) {
11421145 if ( secondsToCycle == 0 ) secondsToCycle = $j ( '#cyclePeriod' ) . val ( ) ;
1143- intervalId = setInterval ( nextCycleView , 1000 ) ;
1146+ cycleIntervalId = setInterval ( nextCycleView , 1000 ) ;
11441147 cycle = true ;
11451148 $j ( '#cyclePauseBtn' ) . show ( ) ;
11461149 $j ( '#cyclePlayBtn' ) . hide ( ) ;
11471150}
11481151
1149- function cycleStop ( target ) {
1152+ function cycleStop ( ) {
11501153 secondsToCycle = 0 ;
1151- monIdx = target . getAttribute ( 'data-monIdx' ) ;
11521154 $j ( '#secondsToCycle' ) . text ( '' ) ;
11531155 cyclePause ( ) ;
11541156}
11551157
11561158// FIXME this runs within the interval handler and can take >50ms which will cause chrome to complain.
11571159function cycleNext ( ) {
1158- monIdx ++ ;
1159- if ( monIdx >= monitorData . length ) {
1160- monIdx = 0 ;
1161- }
1160+ clearInterval ( cycleIntervalId ) ;
1161+ const oldId = monitorData [ monIdx ] . id ;
1162+ monIdx = ( monIdx >= monitorData . length ) ? 0 : parseInt ( monIdx ) + 1 ;
11621163 if ( ! monitorData [ monIdx ] ) {
11631164 console . log ( 'No monitorData for ' + monIdx ) ;
11641165 }
1165- clearInterval ( intervalId ) ;
1166+ const newId = monitorData [ monIdx ] . id ;
11661167
11671168 // +++ Start next monitor
1168- const oldId = monitorData [ ( monIdx == 0 ) ? monitorData . length - 1 : monIdx - 1 ] . id ;
1169- const newId = monitorData [ monIdx ] . id ;
11701169 streamReStart ( oldId , newId ) ;
11711170 if ( cycle ) cycleStart ( ) ;
11721171}
11731172
11741173function cyclePrev ( ) {
1175- monIdx -- ;
1176- if ( monIdx < 0 ) {
1177- monIdx = monitorData . length - 1 ;
1178- }
1174+ clearInterval ( cycleIntervalId ) ;
1175+ const oldId = monitorData [ monIdx ] . id ;
1176+ monIdx = ( monIdx <= 0 ) ? monitorData . length - 1 : monIdx - 1 ;
11791177 if ( ! monitorData [ monIdx ] ) {
11801178 console . log ( 'No monitorData for ' + monIdx ) ;
11811179 }
1182- clearInterval ( intervalId ) ;
1180+ const newId = monitorData [ monIdx ] . id ;
11831181
11841182 // +++ Start previous monitor
1185- const oldId = monitorData [ ( monIdx == monitorData . length - 1 ) ? 0 : monIdx + 1 ] . id ;
1186- const newId = monitorData [ monIdx ] . id ;
11871183 streamReStart ( oldId , newId ) ;
11881184 if ( cycle ) cycleStart ( ) ;
11891185}
0 commit comments