Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MessagesImpl

Implementation of the Messages feature

Hierarchy

  • MessagesImpl

Implements

Index

Constructors

constructor

  • Create a new MessagesImpl instance

    Parameters

    Returns MessagesImpl

Properties

Private MESSAGING_FILTER_SEND

Command service to send request-response messages specifying a filter

Private MESSAGING_RECEIVER_SERVER

Command service to receive request-response messages

Private MESSAGING_SEND

Command service to send request-response messages to a single session

Private deregisterRequestHandler

Command service to deregister a request handler

Private internal

internal: InternalSession

The internal session

Private requestStreams

requestStreams: object

The streams registered for the request-response service

Type declaration

Methods

addRequestHandler

  • Register a request handler to handle requests from other client sessions for a branch of the message path hierarchy.

    Each control session may register a single handler for a branch. When the handler is no longer required, it may be closed using the Registration provided by the result. To change the handler for a particular branch the previous handler must first be closed.

    Example:

    // Create a request handler that handles strings
    var handler = {
          onRequest: function(request, context, responder) {
              console.log(request); // Log the request
              responder.respond('something');
          },
          onError: function() {},
          onClose: function() {}
      };
    
    // Register the handler
    control.messages.addRequestHandler('test/topic', handler).then(function() {
        // Registration happened successfully
    }, function(error) {
        // Registration failed
    });

    Parameters

    Returns Result<Registration>

    the registration Result that resolves when the handler has been registered, returning a Registration which can be used to unregister the handler.

    Otherwise, the Result will fail with an error. Common reasons for failure include:

    • the session is closed;
    • the session has already registered a handler for this message path;
    • the session does not have REGISTER_HANDLER permission to register a request handler on the server;
    • the session does not have VIEW_SESSION permission to access the client's session properties.

removeRequestStream

  • Remove the request stream at a particular path.

    Parameters

    • path: string

    Returns RequestStream | undefined

    the request stream that was removed from the path. If the path does not have a request stream assigned (or the path does not exist), undefined will be returned instead.

sendRequest

  • sendRequest(path: string, request: any, sessionIdOrRequestType?: SessionId | string | DataType<any, any, any>, requestTypeOrResponseType?: DataType<any, any, any>, responseType?: DataType<any, any, any>): Promise<any>
  • inheritdoc

    Parameters

    • path: string
    • request: any
    • Optional sessionIdOrRequestType: SessionId | string | DataType<any, any, any>
    • Optional requestTypeOrResponseType: DataType<any, any, any>
    • Optional responseType: DataType<any, any, any>

    Returns Promise<any>

Private sendRequestToController

  • sendRequestToController(resolve: function, reject: function, path: string, request: any, reqType?: DataType<any, any, any> | string, respType?: DataType<any, any, any> | string): void
  • Send a request to the controller

    This is called by sendRequest when no session was specified

    Parameters

    • resolve: function

      a callback to resolve the request

        • (result: any): void
        • Parameters

          • result: any

          Returns void

    • reject: function

      a callback to signal an error

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    • path: string

      the path to send the request to

    • request: any

      the request to send

    • Optional reqType: DataType<any, any, any> | string
    • Optional respType: DataType<any, any, any> | string

    Returns void

sendRequestToFilter

  • Send a request to all sessions that satisfy a given session filter.

    Example:

    // Send a string request to be received by the server and passed to sessions matching the filter.
    session.messages.sendRequestToFilter('$Principal NE 'control'', 'test/topic', 'string request', {
              onResponse : function(sessionID, response) {
                  console.log(response); // Log the response
              },
              onResponseError : function() {},
              onError : function() {},
              onClose : function() {}});

    Example:

    // Send a JSON request to be received by the server and passed to sessions matching the filter.
    session.messages.sendRequestToFilter('$Principal NE 'control'', 'test/topic',
         { dwarfs: ['sneezy', 'sleepy','dopey' ] },
         {
              onResponse : function(sessionID, response) {
                  console.log(response.get()); // Log the response
              },
              onResponseError : function() {},
              onError : function() {},
              onClose : function() {}}, diffusion.datatypes.json(), diffusion.datatypes.json());

    Parameters

    Returns Result<number>

    a Result that resolves when the server has dispatched all the requests.

    If the server successfully evaluated the filter, the result of this contains the number of sessions the request was sent to. Failure to send a request to a particular matching session is reported to the callback.

    Otherwise, the Result will fail with an Error. Common reasons for failure include:

    • the filter parameter could not be parsed;
    • the calling session does not have SEND_TO_SESSION and VIEW_SESSION permissions;
    • the calling session is closed.

Private sendRequestToSession

  • sendRequestToSession(resolve: function, reject: function, path: string, request: any, sessionId: SessionId, reqType?: DataType<any, any, any> | string, respType?: DataType<any, any, any> | string): void
  • Send a request to a specific session

    This is called by sendRequest when a session was specified

    Parameters

    • resolve: function

      a callback to resolve the request

        • (result: any): void
        • Parameters

          • result: any

          Returns void

    • reject: function

      a callback to signal an error

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    • path: string

      the path to send the request to

    • request: any

      the request to send

    • sessionId: SessionId

      the target recipient's session ID

    • Optional reqType: DataType<any, any, any> | string
    • Optional respType: DataType<any, any, any> | string

    Returns void

setRequestStream

  • Set a request stream to handle requests to a specified path.

    Example:

    // Set a request stream handler to handle string requests to 'test/topic'
    var handler = {
          onRequest: function (path, request, responder) {
              console.log(request);
              responder.respond('hello');
          },
          onError: function() {}
      };
    
    control.messages.setRequestStream('test/topic', handler,
                                         diffusion.datatypes.string(), diffusion.datatypes.string());

    Parameters

    Returns RequestStream | undefined

    undefined if the request stream is the first stream to be set to the path, otherwise this method will return the previously set request stream.