Skip to content

UserPresence.activeLogs and callback method are not matching #49

@vodkhang

Description

@vodkhang

Hi all,

I am using Rocket.chat for my project and need to keep track if visitor is online, away or offline.

My Code:

Meteor.startup(() => {
	UserPresenceEvents.on('setStatus', (session, status, metadata) => {
		console.log('setStatus - status:  ', status);
		console.log('setStatus - session: ', session);
		console.log('setStatus - metadata: ', metadata);
		const logs = UserPresence.activeLogs();
		console.log('UserPresence - log: ', logs);

		if (metadata && metadata.visitor) {
			RocketChat.models.LivechatInquiry.updateVisitorStatus(metadata.visitor, status);
			RocketChat.models.Rooms.updateVisitorStatus(metadata.visitor, status);
		}
	});
});

I leave the client for 60 seconds so a message away is sent from client to server. The server part of UserPresence captures that correctly, but somehow my callback method receives a different value

Server's log:

I20190804-16:18:33.801(10)? [user-presence] setConnection tb5TEakSDWMqPWPG5 fKcSmu6Xs3zxucra5 away
I20190804-16:18:33.831(10)? setStatus - status:   online
I20190804-16:18:33.831(10)? setStatus - session:  tb5TEakSDWMqPWPG5
I20190804-16:18:33.832(10)? setStatus - metadata:  { visitor: 'tb5TEakSDWMqPWPG5' }

When I turned off the tab, the server receives a remove connection message, but my method callback still receives an online status. I am doing this correctly, or any setting needs to be turned on?

I20190804-16:30:48.574(10)? [user-presence] removeConnection fKcSmu6Xs3zxucra5
I20190804-16:30:48.586(10)? setStatus - status:   online
I20190804-16:30:48.586(10)? setStatus - session:  2DBBuWjyvEbf2maLN
I20190804-16:30:48.587(10)? setStatus - metadata:  undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions