Pergunta

The issue I we face currently has to do with the loading and the reloading of the scenes content. The app as it works today does not respond well to network disconnection and reconnection.

For example ,there are states where ajax-state is 200 / fine .. but data coming in is NULL -> leads to empty scenes.

Here is the snippet from my controller as it looks now :

Controller.assignEvents = function() {
    var player = document.getElementById('pluginObjectPlayer');
    player.OnConnectionFailed = 'Controller.ConnectionFailed';
    player.OnNetworkDisconnected = 'Controller.NetworkDisconnected';
    player.OnStreamNotFound = 'Controller.StreamNotFound';

    $$(document).ajaxError(function(e, xhr, settings, exception) {
       alert('error (' + xhr.status + ') ' + 'in: ' + settings.url + ' | error: ' + exception);
       if(xhr.status === 0 || xhr.status === 408 || xhr.status === 504) Controller.NetworkDisconnected();
    });

    $$(document).ajaxSuccess(function(event, xhr, settings){
        alert('ajaxSuccess('+xhr.status+'): ' + settings.url);
        if(settings.url.indexOf('http:') === 0) {
            if(Controller.no_network) {
                Controller.no_network = false;
                Controller.hideNotification();
            }
        }
    });
}

Controller.ConnectionFailed = function() {
    alert("Stream connection failed");
    Controller.no_network = true;
    Controller.showNotification('Nema mreze');
}

Controller.NetworkDisconnected = function() {
    alert('NetworkDisconnected');

    Controller.no_network = true;
    Controller.showNotification('Nema mreze');


    if(typeof sf.scene.get('Youtube') != 'undefined' && sf.scene.get('Youtube').isVideoPlaying){
        sf.scene.hide('Overlay');
    } else {

        sf.scene.get('Content').streamStop(false);
    }

    sf.scene.get('Content').streamStop(false);
}

Controller.NetworkResumed = function() {
    alert('NetworkResumed');

    Controller.no_network = false;

    Controller.hideNotification();

    if(Controller.starting){
        Controller.startup();
    } else {
        alert("Start timeout on resume");
        $('#buffering').show();
        setTimeout(function(){
            sf.scene.get('Content').streamResume(false);
            $('#buffering').hide();
        }, 5000);
    }
}

Controller.isConnectionAvailable = function() {

    if(sf.core.getEnvValue("modelid") == 'SDK') return Controller.SDK_NETWORK;

    var network = document.getElementById('pluginObjectNetwork');

    var interfaceType = network.GetActiveType();

    if(interfaceType === -1) return false;

    var physicalConn = network.CheckPhysicalConnection(interfaceType);

    if(physicalConn !== 1) return false;

    var httpStatus = network.CheckHTTP(interfaceType);

    if(physicalConn !== 1) return false;

    return true;
}

Controller.pollNetwork = function() {
    alert('polling network');

    var prevStatus = Controller.no_network;
    Controller.no_network = !Controller.isConnectionAvailable();

    if(! Controller.no_network && prevStatus) {
        Controller.NetworkResumed();
    }
    else if(Controller.no_network && ! prevStatus) {
        Controller.NetworkDisconnected();
    }

    setTimeout(Controller.pollNetwork, 2000);
}

Does anyone have an Idea how to fix this ? Thanks !

Foi útil?

Solução

I suggest you to check the xhr.responseText also before deciding it's succeed. Sometimes it happened with 200 code status but the response body is empty

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top