Real-time online/offline functionality

Hello,

We are experiencing some issues with the real-time online/offline functionality. We are using JavaScript SDK chat@2.1.6 for our Angular 1 app and “@cometchat-pro/cordova-ionic-chat”: “^2.1.1” and “@cometchat-pro/ionic-calls”: “0.0.6” for our Ionic app.

For the Online/Offline user status functionality, after a successful cometchat login for our user we create listener, please see below a snippet of our code:

$scope.ListenForUsers = function () {

    var userListenerId = (((new Date()).getTime() * 10000) + 621355968000000000) + makeid(10);

        CometChat.addUserListener(

          userListenerId,

          new CometChat.UserListener({

              onUserOnline: onlineUser => {

                  console.log(onlineUser);

              },

              onUserOffline: offlineUser => {

                  console.log(offlineUser);

              }

          })

        ); 

    }

}

While testing we observed that the listener catches online/offline event notification for all of the users stored withing our CometChat app, not just the users which are in the list of connections or friends of the logged in user. Is there a way that we can set an array of users that we want to lister for their activity within the system?

Also right now we receive multiple connect and disconnect events during our work session, actually the onUserOnline and onUserOffline is triggered multiple times within a minute (without us manually triggering a logout and log back in into CometChat) and a lot of times for the logged in user – is there anything that can be done for this?

Additionally, we noticed that the onUserOffline event is triggered with a bit of a delay (more that few minutes 3-4, and sometimes not at all). Although less often, we experienced delays in the onUserOnline section as well, sometimes they are of 1-2 minutes. Please note that the delays that are problematic for us are the ones greater than 5-10 seconds.

Thank you,

Ciprian

Hello @CiprianDaniel,

While testing we observed that the listener catches online/offline event notifications for all of the users stored within our CometChat app, not just the users which are in the list of connections or friends of the logged-in user. Is there a way that we can set an array of users that we want to lister for their activity within the system?

  • If you are using the friend’s system of CometChat (API to add friends), you need to subscribe for the presence of friends only. This can be achieved by calling the subscribePresenceForFriends() instead of subscribePresenceForAllUsers() of the AppSettingsBuilder(). You can also fetch the presence of users based on their roles by using subscribePresenceForRoles(roles). You can read more about this here.

Also right now we receive multiple connect and disconnect events during our work session, actually, the onUserOnline and onUserOffline are triggered multiple times within a minute (without us manually triggering a logout and log back in into CometChat) and a lot of times for the logged-in user – is there anything that can be done for this?

  • This can be an issue where your internet is either fluctuating or your network is not able to connect to our WebSockets Server. If possible please share a screen recording of the issue and if you have your website hosted anywhere, please share the link with us.

Additionally, we noticed that the onUserOffline event is triggered with a bit of a delay (more than few minutes 3-4, and sometimes not at all). Although less often, we experienced delays in the onUserOnline section as well, sometimes they are of 1-2 minutes. Please note that the delays that are problematic for us are the ones greater than 5-10 seconds.

  • Again this looks like a network issue to me. Please check on multiple networks and share your result with us.

One suggestion would be to update the SDKs to the latest version. The latest version of both JS & Cordova Ionic SDK is 2.2.1.

Warm Regards,

CometChat Pro
Mayur Bhandari

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.