last message/last ping in /clients
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.
Yeah, seems like a good addition. I'd be in favor of a last connection used field for both applications and devices.
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?
hi @schoerg @jmattheis @patbel-pwr is this feature still relevant? I would like to implement this feature. Would you guys mind?
@rafimuhammad01 yeah it is still relevant, feel free to tackle this issue.
@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?
@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 == ?
}
}
}
@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! 🍻
@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 https://github.com/gotify/server/issues/400#issuecomment-798640716)
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.
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