acouvreur / sablier

Start your containers on demand, shut them down automatically when there's no activity. Docker, Docker Swarm Mode and Kubernetes compatible.
https://acouvreur.github.io/sablier/
GNU Affero General Public License v3.0
1.29k stars 46 forks source link

[SUGGESTION] Add feature to keep instance running if the webpage is still open #402

Open Exitium-DEV opened 1 week ago

Exitium-DEV commented 1 week ago

Could we please get an option to not start the countdown until after the user has closed the tab?

I have a sandbox container running coder/code-server to allow remote development. With a 1m timeout, the container gets destroyed as I didn't navigate to another page.

I propose you to do this using WebSockets, as the close() event would fire once the tab is closed, as the websocket connection is destroyed.

So, the config option I propose is openTabsMaintainSession: true With this set to true, when you connect to Sablier, it upgrades your connection to a socket connection; it pauses the countdown timer, and unpauses the timer once the close() event fires.

I'm not proficient in GoLang so I can't do a PR for this myself I'm sorry!

Exitium-DEV commented 1 week ago

Ah wrong label sorry, it won't let me change it now

acouvreur commented 6 days ago

I don't think it's possible to inject a websocket connection inside your webpage.

However, we could create a specific endpoint on Sablier directly, which you could connect from your website.

But this require being able to alter the source code of the webpage.

You could do that, or we could also consider a browser extension.

What do you think?

Exitium-DEV commented 6 days ago

I don't think it's possible to inject a websocket connection inside your webpage.

However, we could create a specific endpoint on Sablier directly, which you could connect from your website.

But this require being able to alter the source code of the webpage.

You could do that, or we could also consider a browser extension.

What do you think?

The issue is I don't have access to alter the source. (Well I do, but it's a container) It should be entirely possible if Sablier is acting as a proxy; you'd just upgrade the existing HTTP request.

If Sablier stops acting as a proxy then I can see the issue; however my understanding is that Trafik proxies to Sablier which proxies to the container

Essentially, the existing HTTP server that you use as the landing page, it just needs to pass the headers to upgrade to a WS connection (there may be a helper function in Go); at this point nothing else changes, except that the connection will stay alive and you can just listen to the socket closing