Trello shows the information of online/offline/idle status very accurately as I personally saw. There are several solutions for tracking users online statuses, and to do so accurately requires a serious overhead. There are also the traditional problems of not knowing if a user closed the browser, disconnected etc. that cause inaccuracy in showing the offline/idle status. For a platform that does not have chat functionality (which, I believe, which would have taken the overhead of tracking users' status and therefore makes the task finally easy) how is Trello achieving this, albeit without much overhead?
Also Trello is able to detect disconnects and resume connection (not so smoothly though).
The Pushing and Polling layer of Trello is described here
Each browser tab is considered to be a session, associated with one user. Each session's activity level is tracked separately, with a user being shown with the highest activity level of all of its sessions (where active is highest, then idle, then disconnected).
Each tab periodically sends its current status to the server - every minute if it has a working WebSocket, every 5 minutes otherwise. Current status is reset to active every time the tab gains focus, or there is a keydown or mousedown event. It goes idle if it has been more than 5 minutes since the most recent of those events. The tab sends a status of disconnected in the onunload event, but we don't depend on this.
Every time a session sends its status to the server, the server looks at all of that user's sessions to determine whether that indicates a change to the user's status. If it does, it broadcasts that new status to every person watching every board that user is on (this goes through the same framework that the rest of Trello's instant updates go through, and is too complicated to explain here).
The server also checks each session to see if its been too long since we've heard from that session (2 minutes if its a WebSocket session, 10 minutes otherwise) and removes the session if it has been (removing a session indicates it is disconnected).
There are a couple of optimizations hiding in there, but that's the main story.
Trello using socket.io.. so when ever a user login it broadcast a message that user has logged in , then they show him as online.
Once he disconnects they send a message on socket again to show him offline.
Many realtime apps using socket.io for showing realtime activities.
Related
I have created an app that uses push notifications to notify people about important events during their day. For a regular user, the app can create anywhere between 120 to 350 notifications every 7 days (we create all the notifications for the upcoming week). In some cases when users change their accounts, we are renewing the notification by canceling them and creating them again. This can happen 2 to 4 times in a span of a few minutes.
We had situations when the app users reported OLD notifications still being sent when those should have been canceled.
We tested this multiple times while adding logs for each notification that got canceled or added - and each time this worked ok - the logs matched the total we were expecting.
Is there a limitation to the number of notifications that can be canceled or added at one single time by the APP? Is there something that could break the requests?
Is there a way to see if the notifications got created or not, other than checking the response of the requests?
Thanks in advance!
I am developing a REST API based on Node / Express and a frontend for it based on React / Redux. Users can login (which gives them access to additional functionality) but they can use basic functionality also without logging in.
When a user logs in, the client makes an HTTP call with the credentials, the server creates a session and returns a user object (user_id and some other data) as well as a session cookie. The React app saves the user object in its Redux state. In subsequent HTTP calls, the user is authenticated through the cookie.
When rendering the user interface, the React app determines whether it is logged in or not by checking for a user object in its state. This is used to grey out some buttons which are only available to logged in users, or to hide the login link when the user is already logged in.
The problem
It could occur that the session expires, or that the user logs out in a different browser tab. The React app has no way of knowing this and thinks it is still logged in (i.e. app state mismatches reality), leading to wrong UI display.
What pattern to solve this?
Put a hook on all Ajax calls to check for 401 and update the
state?
Return session state in HTTP headers (and then?)
A Comet pattern for the server to notify the client that it has been logged out? (not a REST API anymore then)
Additional calls before actual API calls to make sure user is still logged in? (seems wasteful)
And how to deal with this once the client detects it is no longer logged in during an ongoing operation? I'd prefer to handle this in one place rather than all functions making API calls...
I'd be thankful for some best practice!
There are two straightforward ways to deal with this issue in a React application that I can think of. Both inspired by a colleague of mine few days ago.
Use SSE (server-side-events) technology to PUSH notifications. As you correctly pointed out, this makes your API less pure. This approach should be quite an acceptable sacrifice where flawless UX is required AND/OR your server might need to push other notifications to the app.
Establish a short term timer somewhere in your client app (e.g.: setTimeout(...)) that makes periodic calls to a "ping" API endpoint that will return current user/session information. This approach will impact UX for the duration of timeout, often negligible, and is commonly known as polling.
Hope this helps!
As an alternative to the naive polling, you can make it a little smarter by adding an endpoint that lets you know in how many seconds timeout is set to occur for the session at that point in time.
Then ping just before that time (instead of at a certain poll-rate) and update accordingly.
Logging out in another tab would return with an invalid token so would be picked up, too, but not as quickly if this is your main concern.
For this you could use broadcasting to let the other tabs know immediately (or use sessionStorage's change event to simulate a broadcast on unsupported browsers).
Otherwise the best way would be to implement a ServiceWorker; these can handle all requests for your app to the server. It's a centralised piece of code separate from your app that can broadcast to all tabs that a session is lost the moment it sees that one of its requests was rejected, and you can efficiently naively poll from this one place (instead of in each individual tab's runtime).
Since I am using token from the API Server that is valid for a specific period of time. So in addition to setting token in session storage I was thinking of setting up another session storage variable that stores the timestamp at which the token was generated. Then, in my js code I plan to add the validity period (say, 3600 seconds) and check if the token is still valid or not. If it is valid then the user session is valid else it is invalid.
Wanted to know if there is any way to find when your session is about to expire while using class Ext.data.Session, as the Ext.data.Session does not provide any event. As per the definition of the class it is used to store session information with the server data being loaded.
What I want do in my application is user login session management. That is when a user logs in it starts a session and when the session is about the expire I prompt to the user that your session is about to expire. Any event performed in the application resets the session timeout time.
I have checked this example on Miami code but as per the logic, the session will be tracked from the time of loging in. But wont be updated whenever there is some event in the application. Hence irrespective of user performing any event the user will be promted that his session is about to expire. This not helping me, as I need to reset the timer if the user performs some activity.
Let me know if I am driving the question in the right direction, else will rephrase accordingly.
Well, Ext.data.Session and User Login Session what you need are two entirely different things.
Ext.data.Session manages data stored in various records such a way that it ensures consistency, uniqueness of the data and saving data to the server.
Thus, Ext.data.Session cannot be used for your purpose.
I am trying to develop a solution to following problem. I need to store in db information about time when user logged in and is on page. Currently I am writing to db when user login and logout with WCF service, but how to deal with situation when user closes window or goes to other webpage.
I am wondering if threaded function which calls every user every minute to check if he's alive is a good solution. Any help will be nice. Thanks.
If You can wait for data a bit(depending on Your aplication usage), You could save data to IsolatedStorage, and send it when user starts application again. It's pretty simple solution, but You will have to wait for data and some data will be lost, if user don't open application again(Again, depends on Your app).
Other solution would be sending data from JavaScript (How to call WCF from JS) during OnUnload or OnBeforeUnload event. Or even doing a simple HttpRequest from JS to some aspx site, passing time in query.
EDIT: Another thread is a nice idea(I have solution like this in my current project) but running it too often can clog IIS (depend on number of users, bandwidth etc). It also will prevent Session from timing out, even if user does nothing (that's main purpose for using this solution in my project).
I need to develop a windows application with .NET 3.5 that needs to have a calendar and user can schedule appointments.
I want (not with a windows-service) that while the application is on, all the reminders that are set up for this user + reminders that admins set them up, should trigger an event in the application so I can handle it (showing the user a message, notify icon or whatever), once its datetime becomes now.
The data is saved in SQL Server and accessible from many computers, the admin should be able to externally create reminders for users.
Any approaches?
Locally, you could trigger the events using a timer that check the current time e.g. every 10 seconds or more often. The clients should regularily synchronize with the database server, querying all data for the current day or (on user demand) later events. This allows the clients to run and to remind the user even when the network fails for some time.
Another very interesting option is a server side reminder tool next to the database. It generates reminders and sends them via XMPP to the clients. The client machines don't need a special software anymore - any Jabber client would be sufficient, although a special software acting as an XMPP client would be possible, too.
You should really avoid popups. Popups are generally considered not user friendly. They interrupt the user's work flow. Even worse, they steal the keyboard input. What if the users was typing an important email right now?
Instead you might provide a nice, pleasant sound and a task bar bubble or similar.