I'm trying to implement Server Side Events (SSE) in APEX to built a small chat application. If it works it I could expand the functionality to actual work related systems.
The idea is to keep the connection open and receive the data to update the chat box as soon as something new comes up. So far so good.
But I've noticed that the network keeps opening and closing request, which defeats the purpose since I could do a simple setInterval in JS instead of the whole thing.
Currently I've tried the code below (with variations)
AJAX Callback application process
v_result clob := '';
-- while 1 = 1 loop
SELECT JSON_ARRAYAGG( /**** LOTS OPF COLUMNS ***/RETURNING CLOB )
if v_result is null then
v_result := '';
:AI_LAST_UPDATE := to_char(sysdate, 'DD-MM-YYYY HH24:MI:SS');
htp.p('data:' || v_result);
-- end loop;
let source = new EventSource("f?p=&APP_ID.:0:&APP_SESSION.:APPLICATION_PROCESS=Notifications:");
source.addEventListener("message", e => console.log('SSE Package:\n',e.data));
But by adding the loop in the PLSQL code it stops printing the responses.
If I add
owa_util.http_header_close; inside the loop I also don't get any response.
What is the code missing to be able to provide a stable open connection with the server?