Class: WebSocketDuplexOutputChannel

WebSocketDuplexOutputChannel

new WebSocketDuplexOutputChannel(webSocketUri, responseReceiverIdopt, protocolFormatteropt)

Duplex output channel using Websocket.
Parameters:
Name Type Attributes Default Description
webSocketUri String address of the service. (e.g. ws://127.0.0.1:8090/MyService/).
responseReceiverId String <optional>
null unique identifier of the client. If null then GUID will be generated.
protocolFormatter EneterProtocolFormatter | EasyProtocolFormatter <optional>
null formatter used to encode/decode messages between output and input channel. So that the channel knows if the received message is 'OpenConnection', 'CloseConnection' or 'DataMessage'. If null then default EneterProtocolFormatter is used.
Source:
Example
// Create the duplex output channel.
var anOutputChannel = new WebSocketDuplexOutputChannel("ws://127.0.0.1:8077/MyService/", null);

// Subscribe for receving messages.
anOutputChannel.onResponseMessageReceived = onResponseMessageReceived;

// Open connection.
anOutputChannel.openConnection();

...

// Send a message.
// Note: the message can be String or ArrayBuffer.
anOutputChannel.sendMessage("Hello World.");

...

// Close connection when not needed.
anOutputChannel.closeConnection();

...

// Your event handler to process received response messages.
function onResponseMessageReceived(duplexChannelMessageEventArgs) {
    var aMessage = duplexChannelMessageEventArgs.Message;
    
    ...
}

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:

onConnectionOpened(duplexChannelEventArgs)

The event is invoked when the connection with the duplex input channel was opened.
Parameters:
Name Type Description
duplexChannelEventArgs DuplexChannelEventArgs
Source:

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.
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.