send a message to all client when a user leave channel

8 views
Skip to first unread message

rico

unread,
Jun 30, 2009, 10:16:16 AM6/30/09
to meteorserver
Hello :)

I wonder how it could be possible to send a message when a user leave
the channel.

In the case of a chat example, when a user join the chanel and send
his first message, all client could see his nickname on a sidelist.

But when this user leave the channel, how can we tell all subscribers
to remove this nickname in this sidelist ?


thanks by advance for response

rico

Jan Hančič

unread,
Jun 30, 2009, 11:17:40 AM6/30/09
to meteor...@googlegroups.com
Hi,

define a unload event handler and make a AJAX call to your server, telling it the client is logging off. And send an updated list of present users trough a channel.
Just make sure you make a synchronous AJAX request (some browsers do not allow asynchronous requests in the unload event).

There will still be cases where you will have "zombie" users, because, for some reason or other, the unload event won't fire.
I solved this so that every client updates it's last seen flag on the server every X minutes, and then I made a cron script that runs every X minutes and removes the "zombie" clients and sends a new list to connected clients.

Hope this helps.

--
Jan Hančič
http://hancic.info

rico

unread,
Jul 1, 2009, 5:01:07 AM7/1/09
to meteorserver
Hi Jan,

thanks a lot for response.

i was thinking about an unload event handler so i think i will follow
the way you did it.

have a nice day

rico

On 30 juin, 17:17, Jan Hančič <jan.han...@gmail.com> wrote:
> Hi,
> define a unload event handler and make a AJAX call to your server, telling
> it the client is logging off. And send an updated list of present users
> trough a channel.
> Just make sure you make a synchronous AJAX request (some browsers do not
> allow asynchronous requests in the unload event).
>
> There will still be cases where you will have "zombie" users, because, for
> some reason or other, the unload event won't fire.
> I solved this so that every client updates it's last seen flag on the server
> every X minutes, and then I made a cron script that runs every X minutes and
> removes the "zombie" clients and sends a new list to connected clients.
>
> Hope this helps.
>
> --
> Jan Hančičhttp://hancic.info
Reply all
Reply to author
Forward
0 new messages