Detecting when user has left a page

17 views
Skip to first unread message

Xavi Ramirez

unread,
Sep 22, 2009, 4:37:48 PM9/22/09
to liftweb
Hello,

I'm trying to implement a member list for a chat application. The
member list is implemented as a comet actor which receives message
when users visit and leave the chat page.

Currently I detect when a user visits the page by executing a js
function called "joinChat" near the bottom of the page. When
executed, "joinChat" calls (via ajaxInvoke) a scala method that
notifies a list of comet actors that a new visitor has arrived. This
works great.

Unfortunately, I'm having trouble detecting when users leave the chat
page. I've tried using the window.onbeforeunload method, but there is
an outstanding bug in chrome
(http://code.google.com/p/chromium/issues/detail?id=11666) and Opera
which prevent ajax calls from being sent in onbeforeunload.

I've also tried setting the comet actor's lifespan to 5 seconds, but
that seems to destroy comet actors once they've been idle for 5
seconds.

Are there any other mechanisms in lift that could help me solve this
problem. Perhaps, there is some way to hook into the "keepAlive"
signal that lift uses for comet actors? Or maybe there's a setting
that makes lift destroy comet actors as soon as they don't appear on a
page?

Thanks,
Xavi

David Pollak

unread,
Sep 22, 2009, 4:46:28 PM9/22/09
to lif...@googlegroups.com
Lemme see what I can do.  Please open a ticket for this (we're doing changes via tickets).  I'll see if I can get to it today.
 
 Or maybe there's a setting
that makes lift destroy comet actors as soon as they don't appear on a
page?

Thanks,
Xavi





--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

David Pollak

unread,
Oct 16, 2009, 6:03:42 PM10/16/09
to Lift
Sorry. You can set CometActor.lifespan = Full(1 minute) and the
CometActor will be destroyed 1 minute after it's not on a page
anymore. This is the best resolution I can get to.

On Sep 22, 1:46 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> Beginning Scalahttp://www.apress.com/book/view/1430219890
Reply all
Reply to author
Forward
0 new messages