Provides the ability for a client session to control other client sessions.
Properties:
Name | Type | Description |
---|---|---|
SessionEventType |
Session.clients.SessionEventType | Event types used within Session.clients.SessionPropertiesListener#onSessionEvent. |
Example
var clients = session.clients;
Classes
Members
-
<static, readonly> SessionEventType
-
Event types used within Session.clients.SessionPropertiesListener#onSessionEvent.
Properties:
Name Type Default Description UPDATED
0 One or more relevant session properties have been updated. RECONNECTED
1 A session has reconnected. FAILED_OVER
2 A session has failed over from one server to another in a cluster. DISCONNECTED
3 A session has disconnected. Example
session.clients.setSessionPropertiesListener(props, { // ... onSessionEvent : function(sessionID, event, properties, previous) { switch (event) { case session.clients.SessionEventType.DISCONNECTED : console.log(sessionID + " has disconnected"); break; case session.clients.SessionEventType.RECONNECTED : console.log(sessionID + " has reconnected"); break; } } // ... });
Methods
-
getSessionProperties(sessionID, requiredProperties) → {Result}
-
Query the server for property values of a specified client session.
See Session.clients.PropertyKeys for a list of the available fixed property keys.To request all fixed properties ALL_FIXED_PROPERTIES may be included as the key.
To request all user properties ALL_USER_PROPERTIES may be included as the key.
Parameters:
Name Type Argument Description sessionID
String Identifies the client session. requiredProperties
Array <optional>
Specifies the keys of the property values required. Returns:
A Result for this operation.- Type
- Result
Examples
// Get values of all fixed properties for client whose session id is 'id'. session.clients.getSessionProperties(id, diffusion.clients.PropertyKeys.ALL_FIXED_PROPERTIES);
// Get values of the 'FOO' and 'BAR' properties for client whose session id is 'id'. session.clients.getSessionProperties(id, ['FOO', 'BAR']).then(function(session, properties) { console.log('Received properties for session', session, properties); }, function(err) { console.log('Unable to receive properties: ', err'); });
-
setSessionPropertiesListener(requiredProperties, listener) → {Result.<undefined>}
-
Register a listener that will be notified when client sessions are opened, disconnected, reconnected, closed or when selected session property values are updated.
When a listener is first set, it will be called with the required properties of all currently open client sessions. The amount of data transferred from the server is proportional to the number of connected clients and is potentially large. The amount of data can be reduced using the requiredProperties parameter.
The requested property set controls the level of detail provided and whether the listener is called for updates to sessions. If no properties are requested then the listener is not called when session properties are updated.
To request all fixed properties ALL_FIXED_PROPERTIES should be included as a key and any other fixed property keys would be ignored. To request all user properties ALL_USER_PROPERTIES should be included as a key and any other user property keys supplied would be ignored.
Parameters:
Name Type Description requiredProperties
Array A set of required property keys. listener
Session.clients.SessionPropertiesListener The listener to register Returns:
A Result.<undefined> for this operation.- Type
- Result.<undefined>
Example
// Specify desired properties to listen to var props = diffusion.clients.PropertyKeys.ALL_FIXED_PROPERTIES; // Create the listener var listener = { onActive : function(deregister) { // Listener is active }, onSessionOpen : function(sessionID, properties) { // A session has been opened }, onSessionEvent : function(sessionID, event, properties, previous) { // A session's properties have changed (specified by 'event') }, onSessionClose : function(sessionID, properties, reason) { // A session has closed }, onClose : function() { // Listener is closed } } session.clients.setSessionPropertiesListener(props, listener).then(function() { // Registration was succesful }, function(err) { // There was an error registering the session listener });
-
subscribe(session, selector) → {Result.<Number>}
-
Subscribe one or more client sessions to topics.
To subscribe a single known session, a session id may be provided; alternatively, a Session Filter may be used, in which case all sessions that satisfy the filter will be subscribed.
The second argument of this function can be a string, a TopicSelector, or an array of strings and TopicSelectors.
Parameters:
Name Type Description session
String The Session ID or Session Filter selector
String | TopicSelector | Array.<String> The Topic Selector to subscribe to Returns:
- A Result.<Number> for this operation. If subscribing with a session filter, the success callback will be given the number of sessions selected by the filter- Type
- Result.<Number>
Examples
// Subscribe a single session via SessionID session.clients.subscribe(otherSessionID, ">foo").then(function() { // Subscribed 'otherSession' to topic "foo" }, function(err) { // Subscription failed console.log("Failed to subscribe session", err); });
// Subscribe multiple sesssions via a Session Filter session.clients.subscribe("$ClientType IS 'JAVA'", ">foo").then(function(selected) { console.log("Subscribed " + selected + " sessions to topic 'foo'"); }, function(err) { // Subscription failed console.log("Failed to subscribe sessions", err); });
-
unsubscribe(session, selector) → {Result.<Number>}
-
Unsubscribe one or more client sessions from topics.
To unsubscribe a single known session, a session id may be provided; alternatively, a Session Filter may be used, in which case all sessions that satisfy the filter will be unsubscribed.
The second argument of this function can be a string, a TopicSelector, or an array of strings and TopicSelectors.
Parameters:
Name Type Description session
String The Session ID or Session Filter selector
String | TopicSelector | Array.<String> The Topic Selector to unsubscribe from Returns:
- A Result.<Number> for this operation. If unsubscribing with a session filter, the success callback will be given the number of sessions selected by the filter- Type
- Result.<Number>
Examples
// Unsubscribe a single session via SessionID session.clients.unsubscribe(otherSessionID, ">foo").then(function() { // Unsubscribed 'otherSession' from topic "foo" }, function(err) { // Unsubscription failed console.log("Failed to unsubscribe session", err); });
// Unsubscribe multiple sesssions via a Session Filter session.clients.unsubscribe("$ClientType IS 'JAVA'", ">foo").then(function(selected) { console.log("Unsubscribed " + selected + " sessions from topic 'foo'"); }, function(err) { // Unsubscription failed console.log("Failed to unsubscribe sessions", err); });