Pergunta

I am using Strophe to connect a XMPP user on a web page, and to send presence before moving to new page, once a user is connected (after successful authentication)

Here is my code:

if (status===Strophe.Status.CONNECTED){
        my_namespace.connection.send($pres());
            console.log('CONNECTION STATUS: CONNECTED');
            $(document).trigger('connected');

Now the issue is that all happens too quick and once i am redirected to new page and get to check my presence in the server console(Openfire), I see myself offline! Why does this presence not get sent to the server?

I searched to find a solution, that is to attach the connection to new page, i am fairly new to javascript and i am unable to understand why my same connection does not prevail to the new page as well?

Upon connecting successfully i am redirecting my page using this code.

$(document).on('connected', function() {
    my_namespace.set_cookies();
    console.log('Cookies set after sending presence in connected function');
    console.log('Trying to redirect now');
    window.location = 'question_section.html';
    console.log('Redirected');
});

code for attach ( attaching previous connection to new page ) which is in the head of incoming html is:

<script type="text/javascript">
        $(function(){
            $(document).trigger('attach', cookie_data);
            console.log('Attach called from the head of new HTML');
        });
    </script>

PS: I get successfully attached. My jid, resource id & session id have been saved in the cookies as well.

Any help would be appreciated.

Foi útil?

Solução

In your connected handler, send your presence.

conn.send($pres({type: 'available'}).c('priority').t(1).up().tree());

Create a handler for listening to presence

conn.addHandler(onPresence, null, 'presence');

Once you get your presence back, then redirect to next page.

var onPresence = function(presence){
    //do redirect
}

You should enable logging and evaluate the presence, it may not be yours that you get (depending on how you set up the chat). Also, remember to increment your RID when you change pages.

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