B4J Question [SOLVED] Pocketbase SSE (using GET & POST)

tchart

Well-Known Member
Licensed User
Longtime User
SSE is server side events. It’s like a one way web socket - hence the real-time name

see here

 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
Also worth reading this

 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
I have come to understand what the issue is. In terms of these docs, one can have SSE working by first executing a GET & POST requests.


So I assumed that this was possible with HttpJob. I could be wrong, it does not seem possible.

How to reproduce.

1. Start pocketbase in debug mode to see what happens

pocketbase serve --debug

2. Execute a httpjob poststring to This gives one a client id immediately on pocketbase, but the issue is getting this back on b4j.

B4X:
Dim j As HttpJob
    j.Initialize("pb", Me)
    j.Download($"${baseUrl}/realtime"$)
    Wait For (j) JobDone(j As HttpJob)

By the time wait for fires, the session is closed and the client id cancelled.
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
So I assumed that this was possible with HttpJob. I could be wrong, it does not seem possible.
Thats my understanding as well - at least not out of the box.

If you look at the W3 example, the JavaScript initiates the "EventSource" and then waits for messages.

B4X:
var source = new EventSource("demo_sse.php");
  source.onmessage = function(event) {
    document.getElementById("result").innerHTML += event.data + "<br>";
  };

There is a B4A library here that may help you but it depends what you are trying to do;


It appears to use this library;


But I think this is for a B4A application receiving SSE from a web server.
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
I see and thanks @tchart .

I have been working on a b4x jPocketbase class that enables anyone to use Pocketbase within the b4x ecosystem.

The only thing outstanding is SSE.


The JavaScript calls for this from their documentation is not a train smash and as I am using the JS Dev Kit on that front, all is good.

I did check the B4a link for the SSE, looks very promising.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…