Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get JID and Service info when Strophe attaches a session #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WasserX
Copy link

@WasserX WasserX commented Mar 12, 2012

The function onStatus of the pubsub plugin sets the JID and Service vars needed for executing actions when Strophe sends an status of CONNECTED.

If the user is reattaching / attaching to an existing session, those variables are not initialized.

This commit makes it possible to update those variables when Strophe reports the status ATTACHED.

@astro
Copy link
Collaborator

astro commented Mar 12, 2012

Hi

Do you use this for BOSH prebinding? Do you mind sharing additional bits of code? Example usage would be great.

@WasserX
Copy link
Author

WasserX commented Mar 13, 2012

So, I use sessionStorage and my objective is that if you reload the page, you do not start a new connection, so the code is more or less like this:

this.conn = new Strophe.Connection(this.options.gateway.bosh.endpoint); //Snippets of code for understanding

if(!force && typeof sessionStorage.getItem('JID') === 'string'){
                    sessionStorage.setItem('RID', parseInt(sessionStorage.getItem('RID'))+1);
                    this.conn.attach(
                        sessionStorage.getItem('JID'),
                        sessionStorage.getItem('SID'),
                        sessionStorage.getItem('RID'),
                        this.onStatus.bind(this),
                        null, null, null)
                } else{
                    this.conn.connect(
                        this.options.username,
                        this.options.password,
                        this.onStatus.bind(this),
                        null, null, null);
                }

The function onStatus is called whenever the status changes.

When we do an attach, onStatus receives Strophe.Status.ATTACHED but it will never receive Strophe.Status.CONNECTED, but once we receive ATTACHED, we start receiving all new published events.

So, once I receive an Strophe.Status.ATTACHED I assume I was in the same state as before.

The problem is that once i'm reattached and I try to do a 'subscribe' op, the JID inside strophe.pubsub because they are filled from strophe when strophe sends a status of Strophe.Status.CONNECTED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants