AppEngine Channel API is the best way to check if a channel is open (server side)

In AppEngine, I created an application such as a social network / dating type and am currently in the process of adding a chat created over the feed API. However, the problem is that users can reload or go to new pages while chatting (as is possible on Facebook). This means that the server does not easily know if it should generate a new channel identifier token for this client or if a channel token has already been assigned to this client.

It would be very useful if there was a way to check (on the server side) if a specific client already has a channel open. For example, if I assign the Jack-Jan-21-2010 channel identifier to the Jack client, I would like to be able to check on the server side if the channel associated with the Jack-Jan-21-2010 identifier is already open. It can be (sorted) tracked on the client side by watching the onerror () and onclose () callbacks, but I don’t see anything server-side, which allows me to simply check if the channel associated with this ID is already open.

Does anyone know an intelligent way to check (server side) if the channel is already open when using the AppEngine channel API?

+7
source share
1 answer

Part 1: Solving Your Problem

See part 2 below if you really need to monitor client connections, but I'm not sure about your question if what you ask for solves your problem.

Let me see if I can repeat your problem: you are writing a chat application, but this is for a site that is not completely AJAX (in the sense that, say, gmail); the site contains page navigation where you may need to reconfigure your channel after a user clicks on a link to another page. When the user moves, a new page is displayed, and you want to avoid getting a new token at this point; You want to reuse an existing token and channel with the same client ID.

If this is correct, I have two alternative solutions, one simple but not very convenient user interface, one more complicated, but with a much smoother end result.

  • Save the cookie in a cookie. When you re-advertise your page, just use the token from the cookie and not call channel.create_channel again. When the token expires, you will receive an onerror callback, as if the user remained on the original page; at this point, call channel.create_channel again. The problem is that reconnection can be slow (up to 10 seconds or more in bad cases) due to the nature of the Comet compounds.

  • Wrap an entire non-chat site in an iframe. Put the channel creation code and user interface in the external iframe. This way, you do not need to reconnect every time a user navigates. This avoids downtime when navigating. Note that orkut uses this technique with floating divs, as a small amount of Firebug research will show.

Part 2: Your Function Request

If it turns out that I do not understand, and you really need to monitor client connections:

There is no built-in way to check if the client is connected to the channel identified by the client identifier.

However, I am currently working on adding a “presence” (in the sense of chat) so that your application can register to receive a message when a client connects or disconnects from a channel created with a given client identifier. You can also “probe” the presence, request whether this client identifier is connected or not (still working on the details of this part).

Please note that this will not be based on tokens, but rather on a client identifier.

I don't have a specific release date, but, as I said, I'm actively working on it right now.

In the meantime, you can use the heartbeat HTTP request from your client back to your application that says “hey, I'm still here” every minute or so. You should have some kind of task that starts every, say, 2 minutes, and marks all clients that were not checked as inactive, and you will need to store this data somewhere.

+18
source

All Articles