Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Clone this wiki locally
APE has a cool feature called sessions which allows you to make your application "persistent". When a user browses your website or reloads the page, session will restore your APE application environment.
How to enable sessions
If you are using APE JSF build, instead of using apeCore.js, use apeCoreSession.js. If you are using APE JSF multiple file loading, add this line to your config file:
APE.Config.scripts.push(APE.Config.baseUrl + 'Core/Session.js');
How sessions works
Maybe you already noticed the number before each request sent to the APE server:
This number is called frequency. Each time the APE JSF is loaded, the frequency is incremented. This allows the APE Server to detect that the user loaded a new page.
- If APE JSF is loaded without sessions, the frequency is only used to bypass some browser limitations.
- If APE JSF is loaded with sessions, instead of sending a connect command when start(); is called, it asks the APE server for the user's session.
The server then sends the Multi and Uni pipes the user was connected to, so the APE JSF will fire multiPipeCreate and uniPipeCreate events.
How to save custom data in session
APE allows you to store custom data (string, array, object) in sessions with setSession() and getSession()
- scenario, how is storing data in a session useful, channels and users can also have public properties and these are also resended on a page refresh. Is the difference with public variables, that stored data in an ape session is only retrievable by the client with the correct session?
Could this be usefull for:
- storing message history?
Please add real word use scenarios
Please also append to APE Server Private Public and Session Properties
An example with sessions
This example connects a user to an APE server, joins a channel and saves a custom session named key1 with the value value1: