WebSocket

 

External Notifications can be used by a user to update a job or device, instantly when their status is changed and without making calls at regular intervals.

To receive external notifications you need the following:

    1. WebSocket Client

This can be implemented in the MIS System by following the below sample:

Install WebSocket4Net(open source websocket client implementation) nuget package:PM – Install-Package WebSocket4Net

    1. First a WebSocket connection is established between a user and the WebSocket server. URL: “ws://notification.aurelon.com:8080”

The Authorization is done using a MisKey which must be added by the user in WebSocket connection header fields with the key “MisKey” and the value of the MisKey.

//add MisKey in header
var customHeaderItems = new List{KeyValuePair{string, string}}();
customHeaderItems.Add(new KeyValuePair{string, string}(“MisKey”, miskey));

//create WebSocketClient
WebSocket webSocketClient = new WebSocket(“ws://notification.aurelon.com:8080”, “”, null, customHeaderItems, “”, “”, WebSocketVersion.None, null);

//open WebSocketClient connection
webSocketClient.Open();

    1. Register to Server events

The WebSocket Server will notify connected users with a JSON message when the status of a job or device has changed.

//attach to WebSocketClient events
webSocketClient.Error += new
EventHandler{SuperSocket.ClientEngine.ErrorEventArgs}(webSocketClient_Error);
webSocketClient.Opened += new EventHandler(webSocketClient_Opened);
webSocketClient.Closed += new EventHandler(webSocketClient_Closed);
webSocketClient.MessageReceived += new
EventHandler{MessageReceivedEventArgs}(webSocketClient_MessageReceived);

JSON message ex:
– for Job: {“JobGUID”:”DD6BDDF6-74BA-4BD0-AC48-94A251A8ECA6″}
– for Device: {“DeviceGUID”:”8F1D80AB-06D5-43F8-A015-20347D9DE22C”}

    1. Get updates

Once the notifications are received, you need to call the corresponding method to get the updates from the server.
In this step the user knows that an entity (job or device) has been modified and should make a REST call to External REST API (presented in details at point 1) get the latest values.

To connect to WebSocket Server (URL: “ws://notification.aurelon.com:8080”), the users must use a WebSocket Client.

MisKey

The MisKey value is generated in HUB Application in “Settings” -> “External API” page as shown in the next image

The user can regenerate the MisKey for an unlimited number of times using the “Generate” button. Using “Cancel” button the user will delete the MisKey stopping his access to notifications server.

Updated on May 29, 2020

Was this article helpful?

Related Articles