Embed: don't trigger more errors when the stream has died
This commit is contained in:
		
							parent
							
								
									be7e44727f
								
							
						
					
					
						commit
						7a0b425fc4
					
				
					 4 changed files with 46 additions and 25 deletions
				
			
		
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							|  | @ -72,6 +72,7 @@ function MistVideo(streamName,options) { | |||
|     start: function(callback,delay){ | ||||
|       var i = setTimeout(function(){ | ||||
|         delete MistVideo.timers.list[i]; | ||||
|         if (MistVideo.destroyed) return; | ||||
|         callback(); | ||||
|       },delay); | ||||
|       this.list[i] = new Date(new Date().getTime() + delay); | ||||
|  | @ -1017,7 +1018,9 @@ function MistVideo(streamName,options) { | |||
|               } | ||||
|             }, | ||||
|             report: function(d){ | ||||
|               MistVideo.socket.send(JSON.stringify(d)); | ||||
|               if (MistVideo.socket.readyState == 1) { | ||||
|                 MistVideo.socket.send(JSON.stringify(d)); | ||||
|               } | ||||
|             }, | ||||
|             reportStats: function(){ | ||||
|               var d = {}; | ||||
|  | @ -1093,22 +1096,22 @@ function MistVideo(streamName,options) { | |||
|                 }); | ||||
|                 Object.defineProperty(d,"videoHeight",{ | ||||
|                   get: function(){ | ||||
|                     return MistVideo.video.videoHeight; | ||||
|                     return MistVideo.video ? MistVideo.video.videoHeight : null; | ||||
|                   } | ||||
|                 }); | ||||
|                 Object.defineProperty(d,"videoWidth",{ | ||||
|                   get: function(){ | ||||
|                     return MistVideo.video.videoWidth; | ||||
|                     return MistVideo.video ? MistVideo.video.videoWidth : null; | ||||
|                   } | ||||
|                 }); | ||||
|                 Object.defineProperty(d,"playerHeight",{ | ||||
|                   get: function(){ | ||||
|                     return MistVideo.video.clientHeight; | ||||
|                     return MistVideo.video ? MistVideo.video.clientHeight : null; | ||||
|                   } | ||||
|                 }); | ||||
|                 Object.defineProperty(d,"playerWidth",{ | ||||
|                   get: function(){ | ||||
|                     return MistVideo.video.clientWidth; | ||||
|                     return MistVideo.video ? MistVideo.video.clientWidth : null; | ||||
|                   } | ||||
|                 }); | ||||
| 
 | ||||
|  | @ -1354,6 +1357,7 @@ function MistVideo(streamName,options) { | |||
|     } | ||||
|     if (this.socket) { | ||||
|       if (this.reporting) { | ||||
|         this.reporting.reportStats(); | ||||
|         this.reporting.report({unload:reason ? reason : null}); | ||||
|       } | ||||
|       this.socket.destroy(); | ||||
|  |  | |||
|  | @ -123,11 +123,11 @@ p.prototype.build = function (MistVideo,callback) { | |||
|         resolve(); | ||||
|       }; | ||||
|       player.ms.onsourceclose = function(e){ | ||||
|         console.error("ms close",e); | ||||
|         if (player.debugging) console.error("ms close",e); | ||||
|         send({type:"stop"}); //stop sending data please something went wrong
 | ||||
|       }; | ||||
|       player.ms.onsourceended = function(e){ | ||||
|         console.error("ms ended",e); | ||||
|         if (player.debugging) console.error("ms ended",e); | ||||
|          | ||||
|         //for debugging
 | ||||
|          | ||||
|  | @ -282,21 +282,34 @@ p.prototype.build = function (MistVideo,callback) { | |||
|         player.sb.appendBuffer(data); | ||||
|       } | ||||
|       catch(e){ | ||||
|         if (e.name == "QuotaExceededError") { | ||||
|           if (video.buffered.length) { | ||||
|             if (video.currentTime - video.buffered.start(0) > 1) { | ||||
|               //clear as much from the buffer as we can
 | ||||
|               MistVideo.log("Triggered QuotaExceededError: cleaning up "+(Math.round((video.currentTime - video.buffered.start(0) - 1)*10)/10)+"s"); | ||||
|               player.sb._clean(1); | ||||
|         switch (e.name) { | ||||
|           case "QuotaExceededError": { | ||||
|             if (video.buffered.length) { | ||||
|               if (video.currentTime - video.buffered.start(0) > 1) { | ||||
|                 //clear as much from the buffer as we can
 | ||||
|                 MistVideo.log("Triggered QuotaExceededError: cleaning up "+(Math.round((video.currentTime - video.buffered.start(0) - 1)*10)/10)+"s"); | ||||
|                 player.sb._clean(1); | ||||
|               } | ||||
|               else { | ||||
|                 var bufferEnd = video.buffered.end(video.buffered.length-1); | ||||
|                 MistVideo.log("Triggered QuotaExceededError but there is nothing to clean: skipping ahead "+(Math.round((bufferEnd - video.currentTime)*10)/10)+"s"); | ||||
|                 video.currentTime = bufferEnd; | ||||
|               } | ||||
|               player.sb._busy = false; | ||||
|               player.sb._append(data); //now try again
 | ||||
|               return; | ||||
|             } | ||||
|             else { | ||||
|               var bufferEnd = video.buffered.end(video.buffered.length-1); | ||||
|               MistVideo.log("Triggered QuotaExceededError but there is nothing to clean: skipping ahead "+(Math.round((bufferEnd - video.currentTime)*10)/10)+"s"); | ||||
|               video.currentTime = bufferEnd; | ||||
|             break; | ||||
|           } | ||||
|           case "InvalidStateError": { | ||||
|             player.api.pause(); //playback is borked, so stop downloading more data
 | ||||
|             if (MistVideo.video.error) { | ||||
|               //Failed to execute 'appendBuffer' on 'SourceBuffer': The HTMLMediaElement.error attribute is not null
 | ||||
| 
 | ||||
|               //the video element error is already triggering the showError()
 | ||||
|               return; | ||||
|             } | ||||
|             player.sb._busy = false; | ||||
|             player.sb._append(data); //now try again
 | ||||
|             return; | ||||
|             break; | ||||
|           } | ||||
|         } | ||||
|         MistVideo.showError(e.message); | ||||
|  | @ -371,7 +384,7 @@ p.prototype.build = function (MistVideo,callback) { | |||
|       }; | ||||
|       this.ws.onclose = function(e){ | ||||
|         MistVideo.log("MP4 over WS: websocket closed"); | ||||
|         if (this.wasConnected && (!MistVideo.destroyed) && (MistVideo.state == "Stream is online")) { | ||||
|         if (this.wasConnected && (!MistVideo.destroyed) && (MistVideo.state == "Stream is online") && (!MistVideo.video.error)) { | ||||
|           MistVideo.log("MP4 over WS: reopening websocket"); | ||||
|           player.wsconnect().then(function(){ | ||||
|             if (!player.sb) { | ||||
|  | @ -680,8 +693,12 @@ p.prototype.build = function (MistVideo,callback) { | |||
|         } | ||||
|         var data = new Uint8Array(e.data); | ||||
|         if (data) { | ||||
|           for (var i in player.monitor.bitCounter) { | ||||
|             player.monitor.bitCounter[i] += e.data.byteLength*8; | ||||
|           //if (new Date().getTime() - MistVideo.bootMs > 15e3) { data.fill(0,0,Math.floor(data.length*0.1)); } //corrupt the data pl0x :D 
 | ||||
|            | ||||
|           if (player.monitor && player.monitor.bitCounter) { | ||||
|             for (var i in player.monitor.bitCounter) { | ||||
|               player.monitor.bitCounter[i] += e.data.byteLength*8; | ||||
|             } | ||||
|           } | ||||
|           if ((player.sb) && (!player.msgqueue)) { | ||||
|             if (player.sb.updating || player.sb.queue.length || player.sb._busy) { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Cat
						Cat