Server-Sent Events
Server-Sent Events (SSE) is a technology that enables a browser (client) to receive automatic updates like text-based event data from a server via HTTP connection.
The logic behind SSE is to create a seamless avenue for the browser to automatically receive data from the server without explicitly asking for it. This construct makes working with real-time data very efficient, as it uses just one long-lived HTTP connection,
Step to Use SSE in framework (Developer Only)
Register and deregister the SSE in the form you wish to use by the code given below.
VIS.TestForm.prototype.init = function (windowNo, frame) {
this.frame = frame;
this.windowNo = windowNo;
// Register SSE
VIS.sseManager.register(this);
};
VIS.TestForm.prototype.dispose = function () {
this.disposeComponent();
// Unregister SSE
VIS.sseManager.unregister(this);
};
On server code in class file, add below code inside method to broadcast or unicast message with unique Event
// For Broad Cost
SSEManager.Get().AddMessage((<<Session_ID>>,<<message>>,<<Unique Event>>,SSEManager.Cast.BroadCast);
// For Unicast
SSEManager.Get().AddMessage(<<Session_ID>>,<<message>>,<<Unique Event>>,SSEManager.Cast.Unicast);
// For Example
SSEManager.Get().AddMessage(ctx.GetAD_Session_ID(), " server Started ", "DEMOS", SSEManager.Cast.BroadCast);
Here “Server Started” is broadcast message and “DEMOS” is Unique Event Name that user /dev will receive on client side in js form file.
Add the below code on the form to receive the message which is unicast or broadcast
this.onmessage = function (data) {
/* Event should be unique */
if (data.Event == "DEMOS") {
var msg= data.Message;
// Write your Code
}
};