Skip to main content

session

Session : d2/sdk/utils/session

Session utility. It is a singleton entity in D2SV runtime, used to check state of D2SV session and avail the authenticated connector instance associated with the session. Can also return a reference to the application state data holder a.k.a context associated with the D2SV runtime.

Extends: Marionette.Object
Emits: init, begin, end

session.isInitialized() ⇒ Boolean

Check if the session is initialized or not. Right after a session object is instantiated, it is put to an un-initialized state. The uninitialized state represents that the session is still setting up context, connector and an appropriate authenticator.

Kind: instance method of Session
Returns: Boolean - Whether the session is initialized.

session.isActive() ⇒ Boolean

Checks if the session is active or not. An initialized session automatically tries to validate itself against an authenticated connection. If the validation goes through, then the session becomes an active seesion otherwise it stays inactive and waits for the end user to login into D2SV.

Kind: instance method of Session
Returns: Boolean - Whether the session is active

session.getContext() ⇒ *

Get a reference to the application data holder associated with this session. The context can be used to create or access data created by different data factories.

Kind: instance method of Session
Returns: * - Returns the session context.
See: Context
Example (Code sample to get the connector instance inside any module)


define([
'd2/sdk/utils/session',
'd2/sdk/utils/contexts/factories/connector',
'd2/sdk/models/node.model'
], function(Session, ConnectorFactory, NodeModel){
'use strict';

var context;

function createNodeModel(attributes) {
if(!context) {
context = Session.get().getContext();
}
return new NodeModel(attributes, {connector: context.getObject(ConnectorFactory)});
}

return {
cteateNodeModel: createNodeModel
};
});

"init"

Marks the initialization of a session. The event is emitted when the session has created its pre-requisite objects and it's ready to check authentication status

Kind: event emitted by Session

"begin"

Marks the beginning of a session. The event is emitted when session reaches validated state after fresh login or page reload.

Kind: event emitted by Session

"end"

Marks the end of a session. The event is emitted when session couldn't reach a validated state after page reload or the underlying connection authneticator has detected logout or session expiry.

Kind: event emitted by Session

Session.get() ⇒ Session

Get a reference to the singleton instance.

Kind: static method of Session
Returns: Session - Returns the session instance.