@@ -12,6 +12,9 @@ function MonitorStream(monitorData) {
1212 this . RTSP2WebEnabled = monitorData . RTSP2WebEnabled ;
1313 this . RTSP2WebType = monitorData . RTSP2WebType ;
1414 this . webrtc = null ;
15+ this . hls = null ;
16+ this . mse = null ;
17+ this . wsMSE = null ;
1518 this . mseStreamingStarted = false ;
1619 this . mseQueue = [ ] ;
1720 this . mseSourceBuffer = null ;
@@ -272,9 +275,9 @@ function MonitorStream(monitorData) {
272275 }
273276 */
274277 if ( Hls . isSupported ( ) ) {
275- const hls = new Hls ( ) ;
276- hls . loadSource ( hlsUrl . href ) ;
277- hls . attachMedia ( videoEl ) ;
278+ this . hls = new Hls ( ) ;
279+ this . hls . loadSource ( hlsUrl . href ) ;
280+ this . hls . attachMedia ( videoEl ) ;
278281 } else if ( video . canPlayType ( 'application/vnd.apple.mpegurl' ) ) {
279282 videoEl . src = hlsUrl . href ;
280283 }
@@ -349,6 +352,15 @@ function MonitorStream(monitorData) {
349352 if ( this . webrtc ) {
350353 this . webrtc . close ( ) ;
351354 this . webrtc = null ;
355+ } else if ( this . hls ) {
356+ this . hls . destroy ( ) ;
357+ this . hls = null ;
358+ } else if ( this . wsMSE ) {
359+ this . mse . endOfStream ( ) ;
360+ this . wsMSE . close ( ) ;
361+ this . wsMSE = null ;
362+ this . mseStreamingStarted = false ;
363+ this . mseSourceBuffer = null ;
352364 }
353365 } ;
354366
@@ -683,6 +695,7 @@ function MonitorStream(monitorData) {
683695 } // end if have a new auth hash
684696 } // end if has state
685697 } else {
698+ if ( ! this . started ) return ;
686699 console . error ( respObj . message ) ;
687700 // Try to reload the image stream.
688701 if ( stream . src ) {
@@ -1034,14 +1047,14 @@ function startRTSP2WebPlay(videoEl, url, stream) {
10341047}
10351048
10361049function startMsePlay ( context , videoEl , url ) {
1037- const mse = new MediaSource ( ) ;
1038- mse . addEventListener ( 'sourceopen' , function ( ) {
1039- const ws = new WebSocket ( url ) ;
1040- ws . binaryType = 'arraybuffer' ;
1041- ws . onopen = function ( event ) {
1050+ context . mse = new MediaSource ( ) ;
1051+ context . mse . addEventListener ( 'sourceopen' , function ( ) {
1052+ context . wsMSE = new WebSocket ( url ) ;
1053+ context . wsMSE . binaryType = 'arraybuffer' ;
1054+ context . wsMSE . onopen = function ( event ) {
10421055 console . log ( 'Connect to ws' ) ;
10431056 } ;
1044- ws . onmessage = function ( event ) {
1057+ context . wsMSE . onmessage = function ( event ) {
10451058 const data = new Uint8Array ( event . data ) ;
10461059 if ( data [ 0 ] === 9 ) {
10471060 let mimeCodec ;
@@ -1051,15 +1064,15 @@ function startMsePlay(context, videoEl, url) {
10511064 } else {
10521065 console . log ( "Browser too old. Doesn't support TextDecoder" ) ;
10531066 }
1054- context . mseSourceBuffer = mse . addSourceBuffer ( 'video/mp4; codecs="' + mimeCodec + '"' ) ;
1067+ context . mseSourceBuffer = context . mse . addSourceBuffer ( 'video/mp4; codecs="' + mimeCodec + '"' ) ;
10551068 context . mseSourceBuffer . mode = 'segments' ;
10561069 context . mseSourceBuffer . addEventListener ( 'updateend' , pushMsePacket , videoEl , context ) ;
10571070 } else {
10581071 readMsePacket ( event . data , videoEl , context ) ;
10591072 }
10601073 } ;
10611074 } , false ) ;
1062- videoEl . src = window . URL . createObjectURL ( mse ) ;
1075+ videoEl . src = window . URL . createObjectURL ( context . mse ) ;
10631076}
10641077
10651078function pushMsePacket ( videoEl , context ) {
0 commit comments