When Are My CometChat Users Considered Online?

Have more questions? Submit a request

Every CometChat end-user is assigned a unique user ID and the online status of that user is tracked by the user ID's connection to the CometChat server. When that user ID is connected to the server, that user is considered to be active and online and will remain online until disconnected. The connection to the server happens via WebSocket when the user is logged-in to the SDK or UI Kit using their ID. By default, calling the login() function connects the user, but you can change this and manually connect your end-users via the connect() function if you prefer. You will need to associate a unique CometChat user ID with each of your end-users in order to connect those users to CometChat servers and provide them with chat and calling functionality. 

The connection to the server via the WebSocket can be established automatically or manually. This parameter is set during initialization using the property called autoEstablishSocketConnection. If you would like the connection to happen automatically, then when calling the init() function the boolean value should be set to true. This means all end-users will automatically be connected to the WebSocket at the same moment they are “logged-in” to CometChat using the login() function. You can decide when to call the login() function - it can happen at the same time a user logs in to your platform, meaning all users are immediately active on the CometChat server the moment they arrive, or the login() function can be called when an end-user does something specific, such as click on a Chat button or visit a specific page. 

If you prefer not to automatically connect a user when they log in, and would prefer to manage this manually, you can set the boolean value for autoEstablishSocketConnection() to false. Once this is set, you will need to manually connect the user via the connect() function at whatever point in the workflow you determine is appropriate.  

Once a user is connected to the SDK via WebSocket, whether through the login() function or the connect() function, they will remain “online” or “active” until they are disconnected using the disconnect() function. A user will be disconnected if their internet connection fails, if they background the App, if they close the App or browser window, and if they log out. Disconnecting based on backgrounding the App can vary by user device. 

Auto-connecting is important if you want to show users as online the moment they log in, for example in cases where  a user’s online presence indicates to other users that they are available for chatting. Managing the connection manually is helpful if you have large amounts of traffic but not necessarily large amounts of users accessing chat functionality. In this case you can choose to manually connect a user who shows an intention to use chat by clicking a certain button or visiting a certain page. This gives you some control over Monthly Active User numbers.  

Articles in this section

Was this article helpful?
4 out of 4 found this helpful
Share

Comments

0 comments

Please sign in to leave a comment.