Just a second...

Managing clients

A client with the appropriate permissions can receive notifications and information about other client sessions. A client with the appropriate permissions can also manage these client sessions.

Session properties

Each client session has a number of properties associated with it. Properties are keys and values. Both the key and the value are case sensitive. These session properties can be used by other clients to select sets of client session to perform actions on.

For more information, see Session properties.

Receiving notifications of client session events and their session properties

Required permissions: view_session

To receive notifications when any client session opens, closes, or is updated, register a listener to listen for these events:

JavaScript
// Register a listener for session properties
session.clients.setSessionPropertiesListener(diffusion.clients.PropertyKeys.ALL_FIXED_PROPERTIES) 
    .then(function() {
        
        var listener = session.clients.getSessionPropertiesListener();
        listener
            .on('onSessionOpen', function(event) {
                // The action to take on a client session open notification
            })
            .on('onSessionUpdate', function(event) {
                // The action to take on a client session update notification
            })
            .on('onSessionClose', function(event) {
                // The action to take on a client session close notification
            });
    }, function(err) {
        console.log('An error has occurred:', err);
    });
Java and Android
ClientControl clientControl = session.feature(ClientControl.class);

clientControl.setSessionPropertiesListener(
    new ClientControl.SessionPropertiesListener.Default() {
        @Override
        public void onSessionOpen(){
            // The action to take on a client session open notification
        }
        @Override
        public void onSessionEvent(){
            // The action to take on a client session update notification
        }
        @Override
        public void onSessionClose(){
            // The action to take on a client session close notification
        }
    },
    // The session properties to receive
    "$Country", "$Department");
.NET
var _clientControl = session.GetClientControlFeature();

// Set up a listener to receive notification of all sessions
_clientControl.SetSessionPropertiesListener( propertyListener, "$Country", "Department" );
C
/*
* Register a session properties listener.
*
* Requests all "fixed" properties, i.e. those defined by
* Diffusion rather than user-defined properties.
*/
SET_T *required_properties = set_new_string(5);
set_add(required_properties, PROPERTIES_SELECTOR_ALL_FIXED_PROPERTIES);
        
// Set the parameters to callbacks previously defined
SESSION_PROPERTIES_REGISTRATION_PARAMS_T params = {
      .on_registered = on_registered,
      .on_registration_error = on_registration_error,
      .on_session_open = on_session_open,
      .on_session_close = on_session_close,
      .on_session_update = on_session_update,
      .on_session_error = on_session_error,
      .required_properties = required_properties
};
session_properties_listener_register(session, params);

When registering this listener, specify which session properties to receive for each client session:

JavaScript
// Receive all fixed properties
session.clients.setSessionPropertiesListener(diffusion.clients.PropertyKeys.ALL_FIXED_PROPERTIES, listener) 
    .then(function() {

     });
// OR                
// Receive all user-defined properties
session.clients.setSessionPropertiesListener(diffusion.clients.PropertyKeys.ALL_USER_PROPERTIES, listener) 
    .then(function() {

    });
// OR     
// Receive all properties
session.clients.setSessionPropertiesListener([diffusion.clients.PropertyKeys.ALL_FIXED_PROPERTIES, diffusion.clients.PropertyKeys.ALL_USER_PROPERTIES], listener) 
   .then(function() {

    });
Java and Android
// Define individual session properties to receive
clientControl.setSessionPropertiesListener(
    new ClientControl.SessionPropertiesListener.Default() {
       // Define callbacks
    },
    "$Country", "$Department");
// OR
// Receive all fixed properties
clientControl.setSessionPropertiesListener(
    new ClientControl.SessionPropertiesListener.Default() {
       // Define callbacks
    },
    Session.ALL_FIXED_PROPERTIES);
// OR
// Receive all user-defined properties
clientControl.setSessionPropertiesListener(
    new ClientControl.SessionPropertiesListener.Default() {
       // Define callbacks
    },
    Session.ALL_USER_PROPERTIES);
.NET
// Define individual session properties to receive
_clientControl.SetSessionPropertiesListener(propertiesListener, "$Country", "Department" );
// OR
// Receive all fixed properties
_clientControl.SetSessionPropertiesListener(propertiesListener, SessionControlConstants.AllFixedProperties );
// OR
// Receive all user-defined properties
_clientControl.SetSessionPropertiesListener(propertiesListener, SessionControlConstants.AllUserProperties );
C
// Receive all fixed properties
SET_T *required_properties = set_new_string(5);
set_add(required_properties, PROPERTIES_SELECTOR_ALL_FIXED_PROPERTIES);
        
SESSION_PROPERTIES_REGISTRATION_PARAMS_T params = {
      //Other parameters  
      .required_properties = required_properties
};
// OR                 
// Receive all user-defined properties
SET_T *required_properties = set_new_string(5);
set_add(required_properties, PROPERTIES_SELECTOR_ALL_USER_PROPERTIES);
        
SESSION_PROPERTIES_REGISTRATION_PARAMS_T params = {
      //Other parameters  
      .required_properties = required_properties
};
// OR                
// Receive all properties
SET_T *required_properties = set_new_string(5);
set_add(required_properties, PROPERTIES_SELECTOR_ALL_FIXED_PROPERTIES);
set_add(required_properties, PROPERTIES_SELECTOR_ALL_USER_PROPERTIES);
        
SESSION_PROPERTIES_REGISTRATION_PARAMS_T params = {
      //Other parameters  
      .required_properties = required_properties
};

When the listening client first registers a listener, it receives a notification for every client session that is currently open. When subsequent client sessions open, the listening client receives a notification for those clients.

When the listening client is notified of a session event, it receives the requested session properties as a map of keys and values.

When the listening client is notified of a session closing, it also receives the reason that the session was closed. If the client session becomes disconnected from the Diffusion™ server, the listener might not receive notification of session close immediately. If reconnection is configured for the client, when the client disconnects, its session goes into reconnecting state for the configured time (the default is 60 seconds) before going into a closed state.

Getting details of specific clients

Required permissions: view_session

A client can make an asynchronous request the session properties of any client session from the Diffusion server, providing the requesting client knows the session ID of the target client.

JavaScript
// Get fixed session properties
 session.clients.getSessionProperties(sessionID, diffusion.clients.PropertyKeys.ALL_FIXED_PROPERTIES)
     .then(function{
     
     });
Java and Android
// Get fixed session properties
ClientControl clientControl = session.feature(ClientControl.class);
clientControl.getSessionProperties(sessionID, Session.ALL_FIXED_PROPERTIES, sessionPropertiesCallback);
.NET
var _clientControl = session.GetClientControlFeature();
_clientControl.GetSessionProperties( sessionID, SessionControlConstants.AllFixedProperties, sessionPropertiesCallback );
C
        GET_SESSION_PROPERTIES_PARAMS_T params = {
                .session_id = session_id,
                .required_properties = properties,
                .on_session_properties = on_session_properties
        };

        get_session_properties(session, params);

Closing client sessions

Required permissions: view_session, modify_session

A client can close any client session, providing the requesting client knows the session ID of the target client.

Java and Android
ClientControl clientControl = session.feature(ClientControl.class);
clientControl.close(sessionID,callback);
.NET
var _clientControl = session.GetClientControlFeature();
_clientControl.Close( sessionID, callback );