Live Connection
Live Connection is a WebSocket management component that opens a two-way interactive communication session between the user's browser and a server. Using this component, users can send messages to a server and receive event-driven responses without having to poll the server for a reply.
info
For more details, refer to WebSocket.
Props
Attribute | Description | Type | Default |
---|---|---|---|
autoConnect | Connection opens automatically while rendering | boolean | false |
enableIamAuth | If enableIamAuth prop is selected true, the first message forwarded to the webSocket will contain the IAM token information as {"token":"XXX"} | boolean | false |
message | String or Json data to be transmitted | object, string | |
reconnect | LiveConnection will try to reconnect until connect successfully , when connection gets error | boolean | false |
reconnectBackOff | Increasing reconnect interval for better browser performance | boolean | false |
reconnectInterval | LiveConnection will try to reconnect after this interval(seconds) until connect successfully, when connection gets error | number | 60 |
secure | Destination url secure prefix. When you don't set url with ws/wss scheme, gets secure info from this prop value. Set true for using URL scheme wss:// or false for using insecure ws:// | boolean | false |
sendQueueMessage | Sending queue message when connection reOpen | boolean | true |
url | Connection destination url | string | |
urlParams | Values of url parameters | object |
info
First 7 fibonacci numbers are used to calculate interval as ratio. After 7 reconnect try, reconnectInterval continue with last calculated number.
# Exp:
# When reconnectInterval set 7;
calculated reconnect intervals: 1 - 3 - 4 - 7 - 11 - 18 - 30 - 30 - 30 ... until connect successfully
# When reconnectInterval set 30;
calculated reconnect intervals: 6 - 12 - 18 - 30 - 48 - 78 - 126 - 126 - 126 ... until connect successfully
Events
Attribute | Description |
---|---|
onConnectionOpen(reason) | Fired when a connection with a WebSocket is opened. Reason for the opening of the connection is as follows: "ConnectionError", "ConnectionClose","UserSend", "AutoConnect" |
onMessageReceived(message) | Fired when message is received through a WebSocket. Message parameter returns json object string. |
onClose(e:CloseEvent) | Fired when a connection with a WebSocket is closed. CloseEvent inherits from event. Detail close event |
onError(error,errorCount) | Fired when a connection with a WebSocket has been closed because of an error, such as when some data couldn't be sent. Returns websocket error event and count of errors. Detail error event |
Methods
Attribute | Description |
---|---|
Send (message?: object | string, urlParams?: object) | Enqueues the specified data to be transmitted to the server over the WebSocket connection. Opens connection if closed and enqueues data to be transmitted. |
Close () | Closes the connection. Component closes all connections automatically when leaving from page. You can call close method if need to close connection a specific event triggered. |
Method Usage
Send
// LiveConnection component ID: connectionComp #
// (Using Eg1) Set component parametres before Send method
components.connectionComp.urlParams = { 'connectionToken': '123456' };
components.connectionComp.message = { 'operation': 'MarketDataBroadcast', "payload": { "userName": "TEST", "password": "TEST" } };
components.connectionComp.Send();
// (Using Eg2) Use Send function with message and urlParams parametres.
components.connectionComp.Send({ 'operation': 'MarketDataBroadcast', "payload": { "userName": "TEST", "password": "TEST" } }, { 'connectionToken': '123456' });
// (Using Eg3) Set initial static message and urlParams for future Send on component settings prop window.
components.connectionComp.Send();
Close
// LiveConnection component ID: connectionComp #
components.connectionComp.Close();
Samples Qjson
DxDataGridArrStoreLiveConDxDataGridArrStoreLiveConReason