Anything other than a JS alert can delay a window close?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Anything other than a JS alert can delay a window close?

Wally Kolcz
Pretty much what I asked in the subject line. I need Flash to submit to a database before the window closes and the flash instance dies.

Don't think that a pop up (alert) is an option for our sites.

Using JS and ExternalInterface to communicate with flash (AS) to push to a HTTPRequest data to insert.

ANY ideas? Any?

Reply | Threaded
Open this post in threaded view
|

RE: Anything other than a JS alert can delay a window close?

Tracy Spratt
Use javascript and XMLHTTP to update the database instead of Flex?

Tracy

 

________________________________

From: [hidden email] [mailto:[hidden email]] On
Behalf Of wkolcz
Sent: Tuesday, December 09, 2008 5:34 PM
To: [hidden email]
Subject: [flexcoders] Anything other than a JS alert can delay a window
close?

 

Pretty much what I asked in the subject line. I need Flash to submit to
a database before the window closes and the flash instance dies.

Don't think that a pop up (alert) is an option for our sites.

Using JS and ExternalInterface to communicate with flash (AS) to push to
a HTTPRequest data to insert.

ANY ideas? Any?

 

Reply | Threaded
Open this post in threaded view
|

Re: Anything other than a JS alert can delay a window close?

valdhor-3
Another idea...

How about setting up a timer in Flex to poll the server. If the server
does not receive the poll in a certain amount of time then the client
has disconnected and you can write the data to the database.

It may work even better with BlazeDS (I don't know this - I'm kinda
hoping it works). Hopefully you can tell if a client disconnects from
something they have subscribed to via RTMP. Does anyone know?


--- In [hidden email], "Tracy Spratt" <tspratt@...> wrote:

>
> Use javascript and XMLHTTP to update the database instead of Flex?
>
> Tracy
>
>  
>
> ________________________________
>
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of wkolcz
> Sent: Tuesday, December 09, 2008 5:34 PM
> To: [hidden email]
> Subject: [flexcoders] Anything other than a JS alert can delay a window
> close?
>
>  
>
> Pretty much what I asked in the subject line. I need Flash to submit to
> a database before the window closes and the flash instance dies.
>
> Don't think that a pop up (alert) is an option for our sites.
>
> Using JS and ExternalInterface to communicate with flash (AS) to push to
> a HTTPRequest data to insert.
>
> ANY ideas? Any?
>


Reply | Threaded
Open this post in threaded view
|

RE: Re: Anything other than a JS alert can delay a window close?

Seth Hodgson
HTTP session timeout at the server is the only sure-fire way to detect a client has left. Catching Javascript events at the client and attempting to notify the server may shortcut this process _when_ it works - but it provides no guarantees that it will. Even if your Javascript is able to put a request onto the network or get Flash to issue a request via ExternalInterface before the browser closes, the notification over the network could be lost, for instance if an intermediate router crashes.

Depending on the behavior of your app, you can shorten this time interval by lowering your session timeout in web.xml.

If you're trying to detect the client leaving specific pages this is more difficult with HTTP because your "connection" (i.e. session) spans all the pages of your site that are loaded in the browser process. When the session times out, you could treat this as a "leave" for all pages the client has viewed during its session.

For RTMP (not available in BlazeDS) because we're dealing with a stateful connection (unlike HTTP where connections are stateless) as soon as the RTMP connection closes when the user closes their browser or navigates away from a page containing your Flex app, we detect that and you can respond to this event on the server.

In this case, if different pages contain individual swfs that you're tracking, as soon as the client leaves a page and the connection closes you can track that directly.

Best,
Seth

From: [hidden email] [mailto:[hidden email]] On Behalf Of valdhor
Sent: Wednesday, December 10, 2008 5:58 AM
To: [hidden email]
Subject: [flexcoders] Re: Anything other than a JS alert can delay a window close?

Another idea...

How about setting up a timer in Flex to poll the server. If the server
does not receive the poll in a certain amount of time then the client
has disconnected and you can write the data to the database.

It may work even better with BlazeDS (I don't know this - I'm kinda
hoping it works). Hopefully you can tell if a client disconnects from
something they have subscribed to via RTMP. Does anyone know?


Reply | Threaded
Open this post in threaded view
|

RE: Re: Anything other than a JS alert can delay a window close?

Maciek Sakrejda
One could hack around this by faking state, no? Have the client open a
socket to the server and the server can just manually heartbeat it so
that the connection is not dropped (the client of course must read off
and discard the heartbeats). We're doing this (and more along the same
lines) at Truviso and it works reasonably well (although there are some
pretty hideous corner-case problems with--surprise--Internet Explorer).

Doing this with URLStream (the way we do) will count a connection
against your total open limit (discussed in a number of places; e.g.,
here:
http://www.openajax.org/runtime/wiki/The_Two_HTTP_Connection_Limit_Issue ). Note also that maintaining an open connection (and more importantly, a thread) per client is not very efficient, and may not be appropriate for all setups.

Doing this with a raw Socket should also be possible (though you'd need
an open port), would avoid the connection limit issue, and (I'm pretty
sure) would be more scalable.

Also, you may need to deal with temporary disconnections when the socket
connection fails, but the client is still there. For us, we just
disconnect the client entirely and try to reconnect with a fresh start,
but that might be less than ideal.
--
Maciek Sakrejda
Truviso, Inc.
http://www.truviso.com

-----Original Message-----
From: Seth Hodgson <[hidden email]>
Reply-To: [hidden email]
To: [hidden email] <[hidden email]>
Subject: RE: [flexcoders] Re: Anything other than a JS alert can delay a
window close?
Date: Mon, 15 Dec 2008 11:40:24 -0800

HTTP session timeout at the server is the only sure-fire way to detect a
client has left. Catching Javascript events at the client and attempting
to notify the server may shortcut this process _when_ it works - but it
provides no guarantees that it will. Even if your Javascript is able to
put a request onto the network or get Flash to issue a request via
ExternalInterface before the browser closes, the notification over the
network could be lost, for instance if an intermediate router crashes.

Depending on the behavior of your app, you can shorten this time
interval by lowering your session timeout in web.xml.

If you're trying to detect the client leaving specific pages this is
more difficult with HTTP because your "connection" (i.e. session) spans
all the pages of your site that are loaded in the browser process. When
the session times out, you could treat this as a "leave" for all pages
the client has viewed during its session.

For RTMP (not available in BlazeDS) because we're dealing with a
stateful connection (unlike HTTP where connections are stateless) as
soon as the RTMP connection closes when the user closes their browser or
navigates away from a page containing your Flex app, we detect that and
you can respond to this event on the server.

In this case, if different pages contain individual swfs that you're
tracking, as soon as the client leaves a page and the connection closes
you can track that directly.

Best,
Seth

From: [hidden email] [mailto:[hidden email]] On
Behalf Of valdhor
Sent: Wednesday, December 10, 2008 5:58 AM
To: [hidden email]
Subject: [flexcoders] Re: Anything other than a JS alert can delay a
window close?

Another idea...

How about setting up a timer in Flex to poll the server. If the server
does not receive the poll in a certain amount of time then the client
has disconnected and you can write the data to the database.

It may work even better with BlazeDS (I don't know this - I'm kinda
hoping it works). Hopefully you can tell if a client disconnects from
something they have subscribed to via RTMP. Does anyone know?




 


Reply | Threaded
Open this post in threaded view
|

Re: Anything other than a JS alert can delay a window close?

OsmanUllah
In reply to this post by Wally Kolcz
We have had success in onBeforeUnload, make the final request, and
then in onUnload, create a 500ms loop in JS which gives the networking
layer enough time to put the request on the wire before the flash is
torn down.

This was for a logout call, and it worked pretty well except in Safari
(it might work on safari now, I am not sure). Since it was only a
logout call and we had a timeout after 30 seconds anyway, it was not a
huge issue if it was not 100% successful. But in practice it works
pretty well.

It's one of those crazy ideas that you just do if you absolutely need
to. I think gmail might do the same thing for gchat; if you close a
gmail window you will notice a slight delay. I haven't looked at their
code though so I don't know for sure.



--- In [hidden email], "wkolcz" <wkolcz@...> wrote:
>
> Pretty much what I asked in the subject line. I need Flash to submit
to a database before the window closes and the flash instance dies.
>
> Don't think that a pop up (alert) is an option for our sites.
>
> Using JS and ExternalInterface to communicate with flash (AS) to
push to a HTTPRequest data to insert.
>
> ANY ideas? Any?
>