librelist archives

« back to archive

Ready and Initialized events

Ready and Initialized events

From:
Rubem Silva
Date:
2015-03-25 @ 11:44
Hi there

I'm trying to figure out which of the above events can be used to display
all the user contacts list after a connection is done.
When i start the browser and then initialized converse, it seems like the
last event is the initialized one, so i set that event to print to console
the user array list of contacts. In the first load, is printed an empty
array, but if i logout and login, the user contacts array is printed.
I set a setTimeout function after initialized event with 3s and the array
is printed well at first load. I dont know if this is the right behavior or
there is some issue here. Also i am receiving 2 ready events and i dont
know why

My code:

require(['converse'], function (converse) {
            converse.listen.on('roster', function (items) {
                console.log(items);
            });
            converse.listen.on('initialized', function () {
                //hide control box when initialized
                console.log("init");
                $('#controlbox').css( "display", "none" );
                setTimeout(function(){printChatUserList(jid);}, 3000);
            });
            converse.listen.on('ready', function () {
                console.log("ready");
            });
            converse.initialize({
                bosh_service_url: 'http://'+url+'/http-bind', //
Please use this connection manager only for testing purposes
                prebind: true,
                jid: jid,
                sid: sid,
                rid: rid,
                i18n: locales['en'], // Refer to ./locale/locales.js
to see which locales are supported
                keepalive: true,
                message_carbons: true,
                play_sounds: true,
                roster_groups: true,
                show_controlbox_by_default: false,
                debug: false,
                xhr_user_search: false
            });

Thank you

Rub

Re: [conversejs] Ready and Initialized events

From:
Jc Brand
Date:
2015-03-25 @ 21:03
On Wed, Mar 25, 2015 at 11:44:42AM +0000, Rubem Silva wrote:
>    Hi there
> 
>    I'm trying to figure out which of the above events can be used to display
>    all the user contacts list after a connection is done.

Neither is appropriate as a measure for when the contacts roster has been
populated.

>    When i start the browser and then initialized converse, it seems like the
>    last event is the initialized one, so i set that event to print to console
>    the user array list of contacts. In the first load, is printed an empty
>    array, but if i logout and login, the user contacts array is printed.

That is because the 2nd time the contacts roster is cached in your browser's
sessionStorage and therefore immediately available.

The 1st time it needs to asynchronously be fetched from the XMPP server.

There is a "roster" event that gets emitted when roster items are received from
the XMPP server. You can subscribe to that, but it will only work the 1st time,
because the 2nd time roster items come from cache and not from the server.

>    I set a setTimeout function after initialized event with 3s and the array
>    is printed well at first load. I dont know if this is the right behavior
>    or there is some issue here. Also i am receiving 2 ready events and i dont
>    know why

You might have registered the handler twice without realising it, or for some
reason the event fires twice.

Re: [conversejs] Ready and Initialized events

From:
Rubem Silva
Date:
2015-03-26 @ 14:07
Also, if you set prebind and keepalive both true, you will receive the
ready event twice, because in initConnection there are 2 calls to
"this.connection.attach".

Thank you
Rub

>    I set a setTimeout function after initialized event with 3s and the
array
>    is printed well at first load. I dont know if this is the right
behavior
>    or there is some issue here. Also i am receiving 2 ready events and i
dont
>    know why

You might have registered the handler twice without realising it, or for
some
reason the event fires twice.

On 25 March 2015 at 21:03, JC Brand <lists@opkode.com> wrote:

> On Wed, Mar 25, 2015 at 11:44:42AM +0000, Rubem Silva wrote:
> >    Hi there
> >
> >    I'm trying to figure out which of the above events can be used to
> display
> >    all the user contacts list after a connection is done.
>
> Neither is appropriate as a measure for when the contacts roster has been
> populated.
>
> >    When i start the browser and then initialized converse, it seems like
> the
> >    last event is the initialized one, so i set that event to print to
> console
> >    the user array list of contacts. In the first load, is printed an
> empty
> >    array, but if i logout and login, the user contacts array is printed.
>
> That is because the 2nd time the contacts roster is cached in your
> browser's
> sessionStorage and therefore immediately available.
>
> The 1st time it needs to asynchronously be fetched from the XMPP server.
>
> There is a "roster" event that gets emitted when roster items are received
> from
> the XMPP server. You can subscribe to that, but it will only work the 1st
> time,
> because the 2nd time roster items come from cache and not from the server.
>
> >    I set a setTimeout function after initialized event with 3s and the
> array
> >    is printed well at first load. I dont know if this is the right
> behavior
> >    or there is some issue here. Also i am receiving 2 ready events and i
> dont
> >    know why
>
> You might have registered the handler twice without realising it, or for
> some
> reason the event fires twice.
>

Re: [conversejs] Ready and Initialized events

From:
Jc Brand
Date:
2015-03-26 @ 14:29
Hi Rubem

On Thu, Mar 26, 2015 at 02:07:06PM +0000, Rubem Silva wrote:
>    Also, if you set prebind and keepalive both true, you will receive the
>    ready event twice, because in initConnection there are 2 calls to
>    "this.connection.attach".

Good catch.

I made a quick change to fix that:
    
http://github.com/jcbrand/converse.js/commit/896b147a40c7f9071a2756aa33898abddc705aea

I don't have the time right now to properly test it. Perhaps you can see if it
works for you?

About the "roster" event, you're right, it gets emitted too quickly.

It therefore seems that there currently isn't an event for informing when the
roster has been populated.

Could you please create a ticket for that in the tracker?

Thanks
JC


>    >    I set a setTimeout function after initialized event with 3s and the
>    array
>    >    is printed well at first load. I dont know if this is the right
>    behavior
>    >    or there is some issue here. Also i am receiving 2 ready events and i
>    dont
>    >    know why
> 
>    You might have registered the handler twice without realising it, or for
>    some
>    reason the event fires twice.
>    On 25 March 2015 at 21:03, JC Brand <[1]lists@opkode.com> wrote:
> 
>      On Wed, Mar 25, 2015 at 11:44:42AM +0000, Rubem Silva wrote:
>      >    Hi there
>      >
>      >    I'm trying to figure out which of the above events can be used to
>      display
>      >    all the user contacts list after a connection is done.
> 
>      Neither is appropriate as a measure for when the contacts roster has
>      been
>      populated.
> 
>      >    When i start the browser and then initialized converse, it seems
>      like the
>      >    last event is the initialized one, so i set that event to print to
>      console
>      >    the user array list of contacts. In the first load, is printed an
>      empty
>      >    array, but if i logout and login, the user contacts array is
>      printed.
> 
>      That is because the 2nd time the contacts roster is cached in your
>      browser's
>      sessionStorage and therefore immediately available.
> 
>      The 1st time it needs to asynchronously be fetched from the XMPP server.
> 
>      There is a "roster" event that gets emitted when roster items are
>      received from
>      the XMPP server. You can subscribe to that, but it will only work the
>      1st time,
>      because the 2nd time roster items come from cache and not from the
>      server.
> 
>      >    I set a setTimeout function after initialized event with 3s and the
>      array
>      >    is printed well at first load. I dont know if this is the right
>      behavior
>      >    or there is some issue here. Also i am receiving 2 ready events and
>      i dont
>      >    know why
> 
>      You might have registered the handler twice without realising it, or for
>      some
>      reason the event fires twice.
> 
> References
> 
>    Visible links
>    1. mailto:lists@opkode.com

Re: [conversejs] Ready and Initialized events

From:
Rubem Silva
Date:
2015-04-27 @ 10:58
Hi JC

Sorry for not get in touch sooner.
The fix for the prebind makes sense and its working, in fact is merged in
the last release.
About the roster event, i found a way around to overcome my problem, but if
you want i could open an issue.

Thanks
R

On 26 March 2015 at 14:29, JC Brand <lists@opkode.com> wrote:

> Hi Rubem
>
> On Thu, Mar 26, 2015 at 02:07:06PM +0000, Rubem Silva wrote:
> >    Also, if you set prebind and keepalive both true, you will receive the
> >    ready event twice, because in initConnection there are 2 calls to
> >    "this.connection.attach".
>
> Good catch.
>
> I made a quick change to fix that:
>
> 
http://github.com/jcbrand/converse.js/commit/896b147a40c7f9071a2756aa33898abddc705aea
>
> I don't have the time right now to properly test it. Perhaps you can see
> if it
> works for you?
>
> About the "roster" event, you're right, it gets emitted too quickly.
>
> It therefore seems that there currently isn't an event for informing when
> the
> roster has been populated.
>
> Could you please create a ticket for that in the tracker?
>
> Thanks
> JC
>
>
> >    >    I set a setTimeout function after initialized event with 3s and
> the
> >    array
> >    >    is printed well at first load. I dont know if this is the right
> >    behavior
> >    >    or there is some issue here. Also i am receiving 2 ready events
> and i
> >    dont
> >    >    know why
> >
> >    You might have registered the handler twice without realising it, or
> for
> >    some
> >    reason the event fires twice.
> >    On 25 March 2015 at 21:03, JC Brand <[1]lists@opkode.com> wrote:
> >
> >      On Wed, Mar 25, 2015 at 11:44:42AM +0000, Rubem Silva wrote:
> >      >    Hi there
> >      >
> >      >    I'm trying to figure out which of the above events can be used
> to
> >      display
> >      >    all the user contacts list after a connection is done.
> >
> >      Neither is appropriate as a measure for when the contacts roster has
> >      been
> >      populated.
> >
> >      >    When i start the browser and then initialized converse, it
> seems
> >      like the
> >      >    last event is the initialized one, so i set that event to
> print to
> >      console
> >      >    the user array list of contacts. In the first load, is printed
> an
> >      empty
> >      >    array, but if i logout and login, the user contacts array is
> >      printed.
> >
> >      That is because the 2nd time the contacts roster is cached in your
> >      browser's
> >      sessionStorage and therefore immediately available.
> >
> >      The 1st time it needs to asynchronously be fetched from the XMPP
> server.
> >
> >      There is a "roster" event that gets emitted when roster items are
> >      received from
> >      the XMPP server. You can subscribe to that, but it will only work
> the
> >      1st time,
> >      because the 2nd time roster items come from cache and not from the
> >      server.
> >
> >      >    I set a setTimeout function after initialized event with 3s
> and the
> >      array
> >      >    is printed well at first load. I dont know if this is the right
> >      behavior
> >      >    or there is some issue here. Also i am receiving 2 ready
> events and
> >      i dont
> >      >    know why
> >
> >      You might have registered the handler twice without realising it,
> or for
> >      some
> >      reason the event fires twice.
> >
> > References
> >
> >    Visible links
> >    1. mailto:lists@opkode.com
>

Re: [conversejs] Ready and Initialized events

From:
Rubem Silva
Date:
2015-03-26 @ 11:38
That will not work either. If you set the roster event, in first time load
that event is fired, but converse.contacts.get() returns empty. It seems
that the event is fired before the items from xmpp server being processed.

Thanks for your reply.
Rub

On 25 March 2015 at 21:03, JC Brand <lists@opkode.com> wrote:

> On Wed, Mar 25, 2015 at 11:44:42AM +0000, Rubem Silva wrote:
> >    Hi there
> >
> >    I'm trying to figure out which of the above events can be used to
> display
> >    all the user contacts list after a connection is done.
>
> Neither is appropriate as a measure for when the contacts roster has been
> populated.
>
> >    When i start the browser and then initialized converse, it seems like
> the
> >    last event is the initialized one, so i set that event to print to
> console
> >    the user array list of contacts. In the first load, is printed an
> empty
> >    array, but if i logout and login, the user contacts array is printed.
>
> That is because the 2nd time the contacts roster is cached in your
> browser's
> sessionStorage and therefore immediately available.
>
> The 1st time it needs to asynchronously be fetched from the XMPP server.
>
> There is a "roster" event that gets emitted when roster items are received
> from
> the XMPP server. You can subscribe to that, but it will only work the 1st
> time,
> because the 2nd time roster items come from cache and not from the server.
>
> >    I set a setTimeout function after initialized event with 3s and the
> array
> >    is printed well at first load. I dont know if this is the right
> behavior
> >    or there is some issue here. Also i am receiving 2 ready events and i
> dont
> >    know why
>
> You might have registered the handler twice without realising it, or for
> some
> reason the event fires twice.
>