Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

last message/last ping in /clients #400

Closed
schoerg opened this issue Mar 13, 2021 · 9 comments · Fixed by #582
Closed

last message/last ping in /clients #400

schoerg opened this issue Mar 13, 2021 · 9 comments · Fixed by #582
Labels
a:feature New feature or request

Comments

@schoerg
Copy link

schoerg commented Mar 13, 2021

Is your feature request related to a problem? Please describe.
If you use gotify to handle notifications it would be nice to know if clients are still reachable (or have the app installed, app killed). You can then fallback to another channel (email, sms ...) to not miss updates.

Describe the solution you'd like
/client already returns the list of clients, add another field like last_message or last_keepalive/lastping to show when that client has last received a message or last responded to a ping.

@schoerg schoerg added the a:feature New feature or request label Mar 13, 2021
@jmattheis
Copy link
Member

Yeah, seems like a good addition. I'd be in favor of a last connection used field for both applications and devices.

@patbel-pwr
Copy link

I just wanted to post new issue on that, but I see that idea is not new :)

I'd love to have a chance to get sort of heartbeat feature, I'd like to check from time to time if my cron isn't dead.
What if each app would have second token for sending heartbeats, and if those hearbeats come within (earlier set) time range i.e. 5min webapp and android app would show little green dot in corner of app name/logo or red dot if service hasn't sent hearbeat within that time range?

@rafimuhammad01
Copy link

hi @schoerg @jmattheis @patbel-pwr is this feature still relevant? I would like to implement this feature. Would you guys mind?

@jmattheis
Copy link
Member

@rafimuhammad01 yeah it is still relevant, feel free to tackle this issue.

@rafimuhammad01
Copy link

@jmattheis My first approach is to create new column on Client table that named LastConnection then in NotifyClose() or Close() will have operation that write to that table and save the current timestamp. So if the client close the connection it will save it last online.

I think it will be better if we have another field called isConnect on client table, if the client is still connected, for this I think we can do the operation on startReading() function if this function is mean to start the connection.

Do you have any concern for this approach?

@jmattheis
Copy link
Member

jmattheis commented Sep 13, 2022

@rafimuhammad01

We could do this, but the connections are normally long-running meaning they could be active for a long time, additionally, it is possible to have multiple connections that use the same client token, so something like isConnected could be misleading.

Clients should update their last connection timestamp, if the token was used for something different, like creating an application or changing their password.

I propose that the last active time stamp is updated when the client token is used for authentication (here https://github.com/gotify/server/blob/master/auth/authentication.go#L61) and periodically, when the client has an active websocket connection. Every 5 minutes (or so) we could iterate over all the websocket clients in api/stream/stream.go and update the timestamp for these clients.

func (a *API) UpdateLastActiveTimestamps() {
	a.lock.Lock()
	defer a.lock.Unlock()
	for userID, clients := range a.clients {
		for _, client := range clients {
			? = client.token;
			// UPDATE clients SET last_active = now() where token == ?
		}
	}
}

@rafimuhammad01
Copy link

rafimuhammad01 commented Sep 13, 2022

@jmattheis I think it is good idea, but does it means that the updated timestamps is not the real time that client is last connected? if so, will it be okay? With this approach of course we can get the real time by using 1 second for the period but I think it's not a good idea because it will lead to performance issue, right?

I actually prefer to update the timestamp after the client is closing the connection so we will get the real time for client being disconnected. For the long running connection I think it will not be a problem since what I thinking first is just called the function when client close their connection and not running forever until they close their connection. Is there any operation that run every time client lost their connection and we can make sure that the token is unique for every client?

cheers! 🍻

@jmattheis
Copy link
Member

@rafimuhammad01 Ahh, I misunderstood the issue. I thought this would be a last activity/used thing like it is commonly done for users or access tokens. (hence my comment about applications in #400 (comment))

I think my "understanding" has a clear use-case: deleting clients / apps that weren't recently used.

I'm not sure, if I support the need for real-time up-to-dateness, if the client has an active connection. Firstly, some clients will never open the websocket because these clients only use the http api. Secondly, if the use-case is to detect "broken" clients and then send the message over another medium, then you probably shouldn't use gotify, because it isn't build for "critical messaging".

If it is only to detect broken clients that the last active timestamp with a delay up to 5 minutes should be good enough.

Don't get me wrong, having the information if a client is currently connected sounds cool, but I don't really see the use-cases for this.

@powellnorma
Copy link

powellnorma commented Mar 2, 2023

if the use-case is to detect "broken" clients and then send the message over another medium, then you probably shouldn't use gotify

Do you know of an alternative app that one could try, if one needs this? Thank you

eternal-flame-AD added a commit to eternal-flame-AD/gotify-server that referenced this issue Jul 23, 2023
eternal-flame-AD added a commit to eternal-flame-AD/gotify-server that referenced this issue Jul 23, 2023
eternal-flame-AD added a commit to eternal-flame-AD/gotify-server that referenced this issue Jul 23, 2023
eternal-flame-AD added a commit to eternal-flame-AD/gotify-server that referenced this issue Jul 24, 2023
jmattheis added a commit that referenced this issue Aug 6, 2023
add last seen field to client (fixes #400)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:feature New feature or request
Development

Successfully merging a pull request may close this issue.

5 participants