JulianFP / project-W

A self-hostable platform on which users can create transcripts of their audio files (speech-to-text) using Whisper AI
GNU Affero General Public License v3.0
2 stars 0 forks source link

Add websocket route so that server can notify clients about job progress #15

Open JulianFP opened 6 months ago

JulianFP commented 6 months ago

Currently the frontend has to call the /api/jobs/info route periodically (every 15 seconds) for all jobs it wants to keep up-to-date. This has some problems:

Proposed solution: Add a new route (like /api/jobs/subscribe) that provides a websocket endpoint. When a client calls this route a websocket connection will be created between client and server and the server stores this connection in an array. When the server receives a progress update from a runner over the heartbeat, it will forward it to all connections in that array. This will effectively notify the clients of a progress change, there is no need anymore for the clients to periodically query the api.

The /api/jobs/info route should stay unaffected by this since it will be easier to use than a websocket and some clients (like e.g. bash or python scripts) will still prefer to use it.