Subj : webv4 add menu items
To : echicken
From : Roxanne
Date : Sun Apr 05 2020 07:32 pm
> Re: webv4 add menu items
> By: Mortifis to echicken on Sun Apr 05 2020 03:54:51
> The file root/api/events.ssjs is an HTTP EventSource and has the emit()
> function in it.
> The client requests this page and remains connected. Events are streamed to
> tbe browser as they happen. This was a change I introduced in a move away
> from having the browser poll the server at intervals for updates (new
> telegrams, who's online, etc.).
> The event emitters are in lib/events/. Clients can subscribe to any of the
> event types in there.
> An event emitter must expose a 'cycle' function. events.ssjs will call this
> function during its loop. The 'cycle' function should check for new data to
> send, and then push it to the client.
> Pushing an event to the client is a matter of calling 'emit', as in:
> On the client side, there's a function included in (I think) every page
> called registerEventListener, so you would need to do something like this,
> client-side, in JS:
> registerEventListener('my_event', function (e) {
> const data = JSON.parse(e.data);
> });
> Now whenever the server pushes a 'my_event' to the client, this function will
> be called. You can do whatever you need to with 'e', which is the object that
> your event emitter passed to emit().
> ---
> echicken
excellent explaination, thank you!
---
� Synchronet � AlleyCat! BBS Lake Echo, NS Canada