var retryToRestartTimeout = 3000; //ms
var addMilesecondsToRestartTryOnEveryFailed = 1000; //ms
var retryMaxTimes = 100;
var retryCount = 0;
var isManualStopped = false;
...
function playStream() {
...
stream = session.createStream(options).on(STREAM_STATUS.PENDING, function(stream) {
...
}).on(STREAM_STATUS.FAILED, function () {
console.log("streamStatus",stream.status());
setStatus(STREAM_STATUS.FAILED);
onStopped();
//try to restart
retryToRestart();
});
stream.play();
}
...
function retryToRestart(){
if (retryCount < retryMaxTimes){
setTimeout(function(){
if (stream && (stream.status() != STREAM_STATUS.PLAYING)){
playStream();
retryToRestartTimeout = retryToRestartTimeout + addMilesecondsToRestartTryOnEveryFailed;
retryCount++;
}
},retryToRestartTimeout);
}
}