web-api-server-sent-events
Reactive icon

Web API Server Sent Events

Stable version 0.4.0 (Compatible with OutSystems 11)
Uploaded
 on 20 January 2022
 by 
0.0
 (0 ratings)
web-api-server-sent-events

Web API Server Sent Events

Documentation
0.4.0

How to use this component

Simply drop the block on your screen and fill in the parameters:

  • URL - the complete URL to the page that is emitting the events
  • withCredentials - A boolean value indicating whether the EventSource object was instantiated with cross-origin (CORS) credentials set (true), or not (false, the default).
  • Events - A list of strings with the events you whish to subscribe 


You can then handle the events bubbled up from the block:

  • OnMessage (mandatory) - Fired when a message arrives
  • OnOpen - Fired when the connections is open
  • OnClose - Fired when the connection is closed
  • OnError - Fired when an error occurs. Note the very generic error message.


The message structure:

  • data - The actual data being sent. This is a text and usually represents a JSON.
  • origin - The URL of the event emitter
  • lastEventId - A text representing a unique ID for the event.
  • type - String representing the message type (topic) or as referred by the Web API as the "Event" it self.
  • srcElement - A MessageEventSource representing the message emitter.
    • readyState - A number representing the state of the connection. Possible values are CONNECTING (0), OPEN (1), or CLOSED (2).
    • url - A text representing the URL of the source.
    • withCredentials - A boolean value indicating whether the EventSource object was instantiated with cross-origin (CORS) credentials set (true), or not (false, the default).


Take a look at the demo to see an implementation example.

On the demo the events look like this:


event: message 

id: 1634920174825 

retry: 500 

data: "Fri, 22 Oct 2021 16:29:34 GMT" 


event: est 

id: 1634920174827 

retry: 500 

data: "10/22/2021, 12:29:34 PM EDT" 


event: pdt 

id: 1634920174827 

retry: 500 

data: "10/22/2021, 9:29:34 AM PDT"


"Event: message" or "event: " represent the same concept. If you do not specify what to subscribe you will get these types of messages, i.e., messages without an event or with an event set to "message".

You can subscribe multiple events, for example "est" or  "pdt" or both on the examples.

No matter what your subscribe you'll always get the "message" or not specified type events.