WSS Player with auto-play and auto-restore if lost stream

Hello!

How to configure autoplay on embed player using WebRTC.
And is possible to configure to auto reload or auto restore player if lost connection?
 

Max

Administrator
Staff member
Good day.
How to configure autoplay on embed player using WebRTC.
To confugure autoplay, use URL parameter, for example
HTML:
<iframe id='fp_embed_player' src='https://WCS:8444/embed_player?urlServer=wss://WCS:8443&streamName=&mediaProviders=WebRTC,Flash,MSE,WSPlayer&autoplay=true'></iframe>
And is possible to configure to auto reload or auto restore player if lost connection?
You can modify player code to automatically restart stream playback, for example:
JavaScript:
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);
    }
}
 

Max

Administrator
Staff member
Good day.
You should pass session to playStream function to create a new stream
Code:
function retryToRestart(){
    console.log("Into the Function");
    if (retryCount < retryMaxTimes){
        setTimeout(function(){
            if (stream   && (stream.status() != STREAM_STATUS.PLAYING)){
                if (Flashphoner.getSessions().length > 0) {
                    var session = Flashphoner.getSessions()[0];
                    playStream(session);
                }
                retryToRestartTimeout = retryToRestartTimeout + addMilesecondsToRestartTryOnEveryFailed;
                retryCount++;
            }
        },retryToRestartTimeout);
    }
}
Otherwise, an exception will be trown on createStream() call
Code:
function playStream(session) {
    ...
    stream = session.createStream(options).on(STREAM_STATUS.PENDING, function(stream) {
    ...
    });
}
 
Top