Class: MultiTypedMessageSender

MultiTypedMessageSender

new MultiTypedMessageSender()

Sends and receives messages of multiple types.
Messages are serialized/deserialized using Json.
Source:
Example
// Declare response message.
function MyResponseMessage1 {
   this.Number;
};

// Declare some other type of response message.
function MyResponseMessage2 {
   this.Name;
   this.Count;
};

// Create the duplex output channel.
var anOutputChannel = new WebSocketDuplexOutputChannel("ws://127.0.0.1:8890/MyService/", null);

// Create MultiTypedMessageSender.
var aSender = new MultiTypedMessageSender();

// Register handlers to receive messages.
aSender.registerResponseMessageReceiver(onResponseMessage1, "MyResponseMessage1");
aSender.registerResponseMessageReceiver(onResponseMessage2, "MyResponseMessage2");

// Attach output channel and be able to send messages and receive responses.
aSender.attachDuplexOutputChannel(anOutputChannel);

...

// Message which shall be sent. 
function RequestMessage(name) {
    this.Name = name;
};

// Send a message.
var aMessage = new RequestMessage("Hello World.");
aSender.sendRequestMessage(aMessage, aMessage.constructor.name);

...

// Detach output channel and stop listening to responses.
aSender.detachDuplexOutputChannel();

...

// Handler processing response message 1
function onResponseMessage1(typedResponseReceivedEventArgs) {

    // Note: aMessage is already deserialized message.
    var aMessage = typedResponseReceivedEventArgs.ResponseMessage;
    ...
};

// Handler processing response message 2
function onResponseMessage1(typedResponseReceivedEventArgs) {

    // Note: aMessage is already deserialized message.
    var aMessage = typedResponseReceivedEventArgs.ResponseMessage;
    ...
};

Methods

attachDuplexOutputChannel(outputChannel)

Attaches the duplex output channel and opens the connection for sending request messages and receiving response messages.
Parameters:
Name Type Description
outputChannel WebSocketDuplexOutputChannel
Source:
Throws:
Throws an error if attaching fails.

detachDuplexOutputChannel()

Detaches the duplex output channel and stops listening to response messages.
Source:

getAttachedDuplexOutputChannel()

Returns attached duplex output channel.
Source:

getRegisteredResponseMessageTypes() → {Array.<String>}

Returns array of types which have registered handlers.
Source:
Returns:
type names which are registered for receiving.
Type
Array.<String>

isDuplexOutputChannelAttached()

Returns true if the reference to the duplex output channel is stored.
Source:

onConnectionClosed()

The event which can be subscribed to receive the notification when the connection was closed.
Source:
Example
// Set your handler to receive close connection notification.
aSender.onConnectionClosed = yourOnConnectionClosed;

onConnectionOpened()

The event which can be subscribed to receive the notification when the connection is open.
Source:
Example
// Set your handler to receive open connection notification. 
aSender.onConnectionOpened = yourOnConnectionOpened;

registerResponseMessageReceiver(handler, clazz)

Registers response message handler for specified message type.
Parameters:
Name Type Description
handler TypedResponseReceivedEventArgs function expecting TypedResponseReceivedEventArgs as input parameter.
clazz String name of the message type.
Source:
Throws:
Throws an error if a handler for the specified message type is already registered.

sendRequestMessage(message, clazz)

Sends a message.
Parameters:
Name Type Description
message object which shall be sent.
clazz String message object type name.
Source:

unregisterResponseMessageReceiver(clazz)

Unregisters the message handler.
Parameters:
Name Type Description
clazz String message type for which the handler shall be unregistered.
Source: