The websocket is created in the OnCreate of MainForm. With a code like this
UniSession.AddJS(ReadString(Size) + #13 + 'socket=new sgcWebSocket(''ws'
+ Copy(UniServerModule.ServidorWebSocket, 5,
Length(UniServerModule.ServidorWebSocket) - 4) + '/sgc/auth/session/'
+ Token + ''');' + #13 +
'socket.on(''open'', function(event) { ajaxRequest(' + Name +'.form,''Open'', []);});' + #13 +
'socket.on(''close'', function(event) { ajaxRequest(' + Name +'.form,''Closed'', [event.message]); });' + #13 +
'socket.on(''error'', function(event) { ajaxRequest(' + Name +'.form,''Error'', [event.message]); });' + #13 +
'socket.on(''message'', function(event) { ajaxRequest(' + Name +'.form,''Message'', [event.message]); });');
when the websocket client receives a message send an ajaxRequest to the MainForm with the Message "Message". So simply, i capture the message on the OnAjaxEvent of MainForm.