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);
}
}
We discuss this problem in this topicThe problem is that in iphone the phone side get disconnected after 1 min
You should adopt the example from this post to resume stream publishing, i.e. use STREAM_STATUS.PUBLISHING to check the stream status, move createStream() and publish() calls to separate function to call it when stream goes to FAILED status etc.I want to restart the camera and publish the stream
You should wrap publishing code to the function publishStreamFunc()should I replace playStream() function with publishStream() function ?
function publishStreamFunc() {
pubStream = session.createStream(optionsStream).on(STREAM_STATUS.PUBLISHING, function (pubStream) {
...
}).publish();
}
function retryToRestart(){
if (retryCount < retryMaxTimes) {
setTimeout(function(){
if (pubStream && (pubStream.status() != STREAM_STATUS.PLAYING)){
publishStreamFunc();
retryToRestartTimeout = retryToRestartTimeout + addMilesecondsToRestartTryOnEveryFailed;
retryCount++;
}
},retryToRestartTimeout);
}
}
Yes. The UNPUBLISHED status means that the stream was stopped by client. To ensure stream is manually stopped you should set the variable isManualStopped to true when user presses Stop button or something. Then check this variable and do not resume publishing in this case.should I react differently to FAILED status and UNPUBLISHED ?