sablierapp / sablier

Start your containers on demand, shut them down automatically when there's no activity. Docker, Docker Swarm Mode and Kubernetes compatible.
https://sablierapp.dev/
GNU Affero General Public License v3.0
1.46k stars 48 forks source link

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

Open Exitium-DEV opened 2 months ago

Exitium-DEV commented 2 months 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 2 months ago

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

acouvreur commented 2 months 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 2 months 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

acouvreur commented 4 weeks ago

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

I need to try this out, this seems "hacky" but that could work I guess?

If you can provide some kind of proof of concept that'd be amazing.

No need to connect with Sablier whatsoever, just a simple auto upgrade to websocket or something else.


To be fair, I doubt this is technically doable ? How one request would upgrade to websocket but still serve content ?

Without an websocket client on the client side, the websocket switching protocol response will just be dropped