indieweb / microsub

For tracking issues on the Microsub specification
24 stars 1 forks source link

Streaming API #20

Open aaronpk opened 6 years ago

aaronpk commented 6 years ago

Clients should have a way to tap in to some sort of streaming API to get updates from the server in realtime.

I've had good luck with the EventSource API on both the client and server side of it. We should define a list of event types that map to the different Microsub actions, so that there's a way for the server to push new events to the client. Things like:

jalcine commented 5 years ago

Regarding new entries, it should be only for the ones that a client chooses to subscribe to (this way, you can subscribe to notifications, a “catch-all” timeline and maybe one crafted particularity for an event).

(Originally published at: https://v2.jacky.wtf/post/6fd5c090-e0be-4030-9267-faf5517b6fcd)

timmarinin commented 5 years ago

@aaronpk what about WebSockets?

I'm thinking along the lines of this:

Another case to be handled somehow is updating the posts that client already has (edits, webmentions count, etc.)

I'm going to experiment with this in a few weeks.

pstuifzand commented 5 years ago

I have tried building the server and client part for EventSource in Ekster, but found that it was quite difficult to get this working with authentication because it was hard to add Authorization headers.

aaronpk commented 5 years ago

The thing I like about EventSource is it's still HTTP, and doesn't require adding another client library into the project (like Websockets). Websockets is also technically overkill since we don't need bi-directional communication for this, just one way.

timmarinin commented 5 years ago

@aaronpk: with bi-directional you can send commands for pausing the stream, e.g., when switching to another tab.

pstuifzand commented 5 years ago

I tried to implement something with EventSource. EventSource itself works great, but I'm not sure how to authenticate it.

This video shows how I can update the unread count of the Home channel. https://www.youtube.com/watch?v=U6gJS9nS220

pstuifzand commented 5 years ago

Here is another video where the items are added automatically to the current timeline. The post is added by curl using Micropub. https://www.youtube.com/watch?v=tKhBKAqqBBs

jalcine commented 5 years ago

I've been experimenting with the idea of real-time updates in Lwa. It's still rough around the edges but I'm planning to implement a bit of what I mentioned on my site, namely:

{
   "name": "Notifications",
   "uid": "notifications",
   "subscriptions": [
     {"type": "websocket", url: "wss://lwa.black.af/endpoints/microsub/ws?action=timeline&channel=notifications"},
     {"type": "eventsource", url: "https://lwa.black.af/endpoints/eventsource/channels/notifications"}
   ]
}

That route could be authenticated the same way as the Microsub endpoint. I made a change to the sample in my original post so that the 'plumbing' needed to connect and subscribe was explicit - less guesswork for clients.