Atmosphere JS keeps sending get request after socket open

456 views Asked by At

I'm using Long Polling with Atmosphere JS for session timeout, so the server tells me when the user has been logged out.

The issue is that once subscribed, Atmosphere JS keeps sending a get request every 60 seconds, which restarts the user session and never logs them out.

I've read the documentation and searched around, but can't see any way to stop this happening. Here is my code:

var socket = atmosphere;
var subSocket;

// subscribe
function subscribe() {
    var request = {
        url : "/web-service/notifier",
        transport: 'long-polling'
    };

    request.onMessage = function (response) {                     
        var jsonStringArray = response.responseBody.split('|');

        // go through each notification and convert from string to object
        $.each(jsonStringArray, function(index, elem){                        
            if (elem != ""){
                var parsedObject = JSON.parse(elem);

                // if notification states user is logged out, log them out
                if (parsedObject.action === 'LOGGED_OUT'){
                    // DO LOGOUT STUFF
                }
            }                                        
        });

    };

    subSocket = socket.subscribe(request);
}

Thanks for any help.

1

There are 1 answers

1
jfarcand On BEST ANSWER

That's how long-polling works, e.g the connection will be closed/resumed by the server after 60 seconds (you have set that value server side...check your code)

-- Jeanfrancois