Universal Messaging 10.11 | Developer Guide | Web Client APIs | Web Developer's Guide for Javascript | Web Client Development in JavaScript | Creating a Session
 
Creating a Session
To interact with a Universal Messaging Server, the first thing to do is configure and start a Universal Messaging Session object, which is effectively your logical and physical connection to one or more Universal Messaging Realms.
Configuring a Universal Messaging Session Object
A Universal Messaging session object is created using the Nirvana.createSession() function. Once created, a session can be started at will:

var mySession = Nirvana.createSession();
The Nirvana.createSession() function may be passed an optional configuration object as a parameter, as follows:

var mySession = Nirvana.createSession({
realms : [ "http://showcase.um.softwareag.com:80" ],
// this can be an array of realms
debugLevel : 4, // 1-9 (1 = noisy, 8 = severe, 9 = default = off)
sessionTimeoutMs : 10000,
enableDataStreams : false,
drivers : [ // an array of transport drivers in preferred order:
Nirvana.Driver.WEBSOCKET,
Nirvana.Driver.XHR_STREAMING_CORS,
Nirvana.Driver.XDR_STREAMING,
Nirvana.Driver.JSONP_LONGPOLL
]
});
For a full list of the parameters used in this configuration object, please see the JavaScript API Documentation for Nirvana.createSession().
Starting your Session
Once a session object has been created, the session may be started as follows:

var mySession = Nirvana.createSession();
mySession.start();
Session Start Callbacks
When a Universal Messaging Session is successfully started following a call to start(), an asynchronous callback will be fired. You can assign a function to be fired as follows:

function sessionStarted(s) {
console.log("Session started with ID " + s.getSessionID());
}

var mySession = Nirvana.createSession();

mySession.on(Nirvana.Observe.START, sessionStarted);

mySession.start();
For more details on methods available on a session object, please see the JavaScript API Documentation for the Universal Messaging Session object.