[Pas2js] pas2js and server sent events

Mattias Gaertner nc-gaertnma at netcologne.de
Fri Aug 26 11:25:23 CEST 2022


On Fri, 26 Aug 2022 07:39:40 +0000 (UTC)
Luca Olivetti <luca at ventoso.org> wrote:

> Hello,
> 
> I see that pas2js has support for websockets, but I cannot find if it 
> also supports server sent events.

A websocket is bidirectional.

  WebSocket:=TJSWebSocket.new(URL);
  WebSocket.onmessage:=@OnWebSocketMessage;
  WebSocket.binaryType := 'arraybuffer';

function TWebapp.OnWebSocketMessage(Event: TEventListenerEvent
  ): boolean;
var
  MsgEvent: TJSMessageEvent;
  ArrBuffer: TJSArrayBuffer;
begin
  Result:=true;
  MsgEvent:=TJSMessageEvent(Event);
  ArrBuffer:=TJSArrayBuffer(MsgEvent.Data);
  ...
end;

 
> A couple of years ago I implemented an application with sse where I
> used fpWeb and plain html+javascript in the browser.
> 
> Now I need to implement a more complex application and I'd like to
> use pas2js, if it supports sse I can reuse the old server class, if
> it doesn't I'll have to reimplement it as a websocket server.

Mattias


More information about the Pas2js mailing list