This is what I was looking for:
http://www.ape-project.org/wiki/index.php/Tutorial:Using_sessions 

I'm not sure why I didn't find that before; I think I was looking at the 
documentation, and not the tutorial.

The following code works:

var APEclient;
var queuePubid;
window.onload = function() {
//Use APE JSF build with session APE.Config.scripts = [APE.Config.baseUrl + 
'/Build/uncompressed/apeCoreSession.js']; APEclient = new 
APE.Client();APEclient.load({'identifier': 'myAppName', 
'channel':'myChannelName'});
APEclient.addEvent('load', function() { //core.options.restore is true if a 
session is active if (APEclient.core.options.restore) { //Calling start(); 
without arguments will ask the APE Server for a user 
sessionAPEclient.core.start();} else {//It's not a session restoration, ask 
user for his nameAPEclient.core.start({'name':'myUserName'}); //connect to APE 
server with 
this username } });
APEclient.addEvent('ready', function() { console.log('Your client is now 
connected');
//APEclient.core.join('myChannelName'); APEclient.addEvent('multiPipeCreate', 
function(pipe, options) { queuePubid = pipe.getPubid(); });
APEclient.onRaw('data', function(raw, pipe) { //console.log('Receiving : ' 
+ unescape(raw.data.msg)); alert(unescape(raw.data.msg)); }); });
}
function apeSend() {

APEclient.core.getPipe(queuePubid).send(prompt('Message to send : ?'));

}


I can now reload the page and re-join my persistent app, since it re-fires 
the multiPipeCreate event when the channel is re-joined.

Hope this helps someone.

-Wes

On Friday, June 29, 2012 2:05:17 PM UTC-4, RakonDark wrote:
>
> well did you use the session 
> and restore the pipe like it set in 
> the DEMO chat.js 
>
> https://github.com/APE-Project/APE_JSF/blob/master/Demos/Chat/demo.js 
>
> this is what restore a pipe : 
>
> ************************** 
>
>         start: function(){ 
> //If name is not set & it's not a session restore ask user for his 
> nickname 
> if(!this.options.name && !this.core.options.restore){ 
> this.promptName(); 
> }else{ 
> var opt = {'sendStack': false, 'request': 'stack'}; 
>
> this.core.start({'name':this.options.name}, opt); 
>
> if (this.core.options.restore) { 
> this.core.getSession('currentPipe', function(resp) { 
> this.setCurrentPipe(resp.data.sessions.currentPipe); 
> }.bind(this), opt); 
> } 
>
> this.core.request.stack.send(); 
> } 
> }, 
>
> setPipeName: function(pipe, options) { 
> if (options.name) { 
> pipe.name = options.name; 
> return; 
> } 
> if (options.from) { 
> pipe.name = options.from.properties.name; 
> } else { 
> pipe.name = options.pipe.properties.name; 
> } 
> }, 
>
> getCurrentPipe: function(){ 
> return this.currentPipe; 
> }, 
>
> setCurrentPipe: function(pubid, save){ 
> save = !save; 
> if (this.currentPipe){ 
> this.currentPipe.els.tab.addClass('unactive'); 
> this.currentPipe.els.container.addClass('ape_none'); 
> } 
> this.currentPipe = this.core.getPipe(pubid); 
> this.currentPipe.els.tab.removeClass('new_message'); 
> this.currentPipe.els.tab.removeClass('unactive'); 
> this.currentPipe.els.container.removeClass('ape_none'); 
> this.scrollMsg(this.currentPipe); 
> if (save) 
> this.core.setSession({'currentPipe':this.currentPipe.getPubid()}); 
> return this.currentPipe; 
> }, 
>
>
> ************************************ 
>
> here you see the pipe restore , maybe it helps you to use the session 
> restore , cause this is excatly your proplem i think. 
>
>
>
>
> On 29 June 2012 17:06, waldo22 <> wrote: 
> > Well maybe I'm doing it wrong. 
> > 
> > All my settings are default, except I'm using JSONP transport instead of 
> > default Long Polling for cross-site support. 
> > 
> > Here's my code, pulled straight from "hello world" example: 
> > 
> >> var APEclient; 
> >> var queuePubid; 
> >> 
> >> window.onload = function() { 
> >> APEclient = new APE.Client(); 
> >> APEclient.load(); 
> >> APEclient.addEvent('load', function() { 
> >> APEclient.core.start({'name':'WesG'}); //connect to APE server with 
> this 
> >> username 
> >> }); 
> >> APEclient.addEvent('ready', function() { 
> >> 
> >> //this event only fires when you first load the page.  If you press F5 
> or 
> >> reload page, 
> >>                                 //it doesn't fire because the pipe was 
> >> already created last time 
> >>                                 APEclient.addEvent('multiPipeCreate', 
> >> function(pipe, options) { 
> >> queuePubid = pipe.getPubid(); //queuePubid has a global scope 
> >> }); 
> >>                                 //this event only fires when you first 
> >> load the page.  If you press F5 or reload page, it doesn't fire 
> >> 
> >> //APEclient.core.addEvent('userJoin', function (user, pipe) { 
> >> // queuePubid = pipe.getPubid(); 
> >> //}); 
> >> APEclient.core.join('scratch_queue'); 
> >> APEclient.onRaw('data', function(raw, pipe) { 
> >> alert(unescape(raw.data.msg)); 
> >> }); 
> >> }); 
> >> } 
> >> function apeSend() { 
> >> APEclient.core.getPipe(queuePubid).send(prompt('Message to send : ?')); 
> >> } 
> > 
> > 
> > I'm just testing with two computers by clicking a button like this: 
> >> 
> >> <input type='button' title='Click here to send a message' value='APE 
> >> Message' style='color:black;' onclick='apeSend();'> 
> > 
> > 
> >  Everything works great, and I can send messages back and forth over and 
> > over again... 
> > 
> > ...until I click "refresh" or hit F5 on one of the browsers, then the 
> > messages aren't sent anymore. 
> > 
> > This is because I can't get the pubid in order to access the pipe, 
> because 
> > the multiPipeCreate event only fires when you create the pipe, but if 
> you 
> > refresh the page, APE server knows that this user is already joined to 
> the 
> > pipe, so it doesn't need to be created again. 
> > 
> > I'm not using sessions, as far as I know, unless sessions are 
> automatically 
> > used by default. 
> > 
> > Is there any other way to access a pipe that already exists after you 
> > refresh your browser? 
> > 
> > Thanks so much for taking the time to help me. 
> > 
> > -Wes 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "APE Project" group. 
> > To post to this group, send email to [email protected] 
> > To unsubscribe from this group, send email to 
> > [email protected] 
> > For more options, visit this group at 
> > http://groups.google.com/group/ape-project?hl=en 
> > --- 
> > APE Project (Ajax Push Engine) 
> > Official website : http://www.ape-project.org/ 
> > Git Hub : http://github.com/APE-Project/ 
>
>
>
> -- 
> i cant trust, what i not know 
>

-- 
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ape-project?hl=en
---
APE Project (Ajax Push Engine)
Official website : http://www.ape-project.org/
Git Hub : http://github.com/APE-Project/

Reply via email to