Rehatbir Singh
Check their projects out: Free VoIP, Toilet Paper
Once you ship this you can't edit the description of the project, but you'll be able to add more devlogs and re-ship it as you add new features!
And here are WebSockets! They inter-operate with all the other modes as you would expect.
It works very similarly to HTTP/SSE - you connect to ws://address/topic and start receiving all messages from the topic, and all messages you send get published to that topic. Simple! You can also add ?binary=true to the end of the ws:// url to receive binary messages instead of string messages.
Socket.IO is here!
You can now subscribe and publish messages via Socket.IO and inter-operate with the HTTP/SSE modes.
Client to server messages:
- subscribe, topic, mode? - subscribes the current socket to the topic. mode is optional (default is string)
modes:
- string - all messages get converted to strings
- binary - all messages get sent as binary (Buffer in JS)
- json - the server will try to parse all messages as JSON, or will send them as strings if the parsing fails
The server can only send message message, with the first argument being the topic name, and the second one being the data in the selected type (see modes above).
Note: the devlog video contains an older version of the program, where the server only sends the data to the client (and doesn't send the topic name).
So I ditched OpenAPI as it wouldn't serve much purpose here.
Features implemented:
- GET /topic - returns the latest value from that topic
- POST /topic - publishes a value to a topic
- Server-sent-events (JavaScript EventSource) to /topic - subscribes to real-time updates to that topic and sends them as soon as they get published
The handler for GET /topic differentiates between a regular GET request and an SSE subscription by the Accept request header.
For now a topic can't contain slashes, but I'll implement that very soon, so that they can be used for scoping/namespaces.