Class: AuthenticatedDuplexOutputChannel

AuthenticatedDuplexOutputChannel

new AuthenticatedDuplexOutputChannel(underlyingDuplexOutputChannel, getLoginMessageCallback, getHandshakeResponseMessageCallback)

Output channel which provides the authentication mechanism.

Here is how the authentication procedure works:
  1. AuthenticatedDuplexOutputChannel calls getLoginMessage callback and gets the login message. Then sends it to AuthenticatedDuplexInputChannel.
  2. AuthenticatedDuplexInputChannel receives the login message and calls getHandshakeMessage callback. The returned handshake message is sent to AuthenticatedDuplexOutputChannel.
  3. AuthenticatedDuplexOutputChannel receives the handshake message and calls getHandshakeResponseMessage. The returned handshake response message is then sent to AuthenticatedDuplexInputChannel.
  4. AuthenticatedDuplexInputChannel receives the handshake response message and calls authenticate callback. if it returns true the connection is established.
Parameters:
Name Type Description
underlyingDuplexOutputChannel WebSocketDuplexOutputChannel | MessageBusOutputChannel underlying output channel which shall be used for the communication.
getLoginMessageCallback AuthenticatedDuplexOutputChannel~getLoginMessageCallback callback method returning login message.
getHandshakeResponseMessageCallback AuthenticatedDuplexOutputChannel~getHandshakeResponseMessageCallback callback method returning response message for the handshake message.
Source:
Example
// Create websocket output channel.
var anUnderlyingOutputChannel = new WebSocketDuplexOutputChannel("ws://127.0.0.1:8033/Service/", null);

// Create authenticated output channel based on websocket output channel.
var anOutputChannel = new AuthenticatedDuplexOutputChannel(anUnderlyingOutputChannel, onGetLogin, onGetHandshakeResponse);

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

// Register message handler
aSender.registerResponseMessageReceiver(onMyMessageTypeResponseReceived, "MyMessageType");


...
// Callback method called from AuthenticatedDuplexOutputChannel to get the login.
function onGetLogin(channelId, responseReceiverId) {
    var aLogin = document.getElementById("login").value;
    return aLogin;
}

// Callback method called from AuthenticatedDuplexOutputChannel to get the password.
function onGetHandshakeResponse(channelId, responseReceiverId, handshakeMessage) {
    var aPassword = document.getElementById("password").value;
    return aPassword;
}


// Method called when login is pressed.
function onLogin() {
    // Attach output channel and be able to send messages and receive responses.
    // Note: the attached authenticated output channel ensures the authentication sequence is performed.
    aSender.attachDuplexOutputChannel(anOutputChannel);
};

// Method called when logout is pressed.
function onLogout() {
    // Detach output channel and stop listening to responses.
    aSender.detachDuplexOutputChannel();
};

Methods

closeConnection()

Closes connection with the duplex input channel.
Source:

getChannelId() → {String}

Returns the channel id. It represents the service address.
Source:
Returns:
Type
String

getResponseReceiverId() → {String}

Returns the response receiver id. It uniquely represents this client at the service.
Source:
Returns:
Type
String

isConnected() → {Boolean}

Returns true if the connection with the duplex input channel is open.
Source:
Returns:
Type
Boolean

onConnectionClosed(duplexChannelEventArgs)

The event is invoked when the connection with the duplex input channel was closed.
Parameters:
Name Type Description
duplexChannelEventArgs DuplexChannelEventArgs
Source:
Example
// Set your handler to receive close connection notification.
aSender.onConnectionClosed = yourOnConnectionClosed;

onConnectionOpened(duplexChannelEventArgs)

The event is invoked when the connection with the duplex input channel was opened.
Parameters:
Name Type Description
duplexChannelEventArgs DuplexChannelEventArgs
Source:
Example
// Set your handler to receive open connection notification. 
aSender.onConnectionOpened = yourOnConnectionOpened;

onResponseMessageReceived(duplexChannelMessageEventArgs)

The event is invoked when a response message was received.
Parameters:
Name Type Description
duplexChannelMessageEventArgs DuplexChannelMessageEventArgs
Source:

openConnection()

Opens connection with the duplex input channel.
When opening it performes the authentication sequence.
Source:
Throws:
Throws error if connection could not be open.

sendMessage(message)

Sends the message to the duplex input channel.
Parameters:
Name Type Description
message String | ArrayBuffer message to be sent
Source:
Throws:
Throws error if sending fails.

Type Definitions

getHandshakeResponseMessageCallback(channelId, responseReceiverId, handshakeMessage) → {String|ArrayBuffer}

Callback method which is used by AuthenticatedDuplexOutputChannel to get the response for the handshake message.
Parameters:
Name Type Description
channelId String address which shall be connected.
responseReceiverId String unique id representing the connection.
handshakeMessage String | ArrayBuffer handshake message received from the service.
Source:
Returns:
response for the handshake message.
Type
String | ArrayBuffer

getLoginMessageCallback(channelId, responseReceiverId) → {String|ArrayBuffer}

Callback method which is used by AuthenticatedDuplexOutputChannel to get the login message.
Parameters:
Name Type Description
channelId String address which shall be connected.
responseReceiverId String unique id representing the connection.
Source:
Returns:
login message
Type
String | ArrayBuffer