chatkit-client-js
chatkit-client-js copied to clipboard
Access to user presence
I'm trying to build out a live chat customer support portal. I need to ensure the user cannot send a message if the support agent is offline. When checking the object in the console, i am able to see the online status of the user and agent. however, when trying to access it in the code it is non-enumerable and gives me a status of undefined (for the agent from the customer side).
i created a function with the following in Customer.js :
checkSupportStatus = () => {
const { currentRoom, currentUser } = this.state;
console.log("\n\n\n\n\ test current user",currentUser.rooms[0].users[1].presence);
}
I plan to use the above function to set a boolean to display a form instead of chat in case the "support" is offline.
the above code is being called in the createRoom function as below:
const { currentUser } = this.state;
console.log("create room", currentUser.users);
currentUser
.createRoom({
name: currentUser.name,
private: true
})
.then(room => this.connectToRoom(room.id))
.then(() => this.addSupportStaffToRoom())
.then(() => this.checkSupportStatus())
.catch(console.error);
};
the object returned is the following:
e {avatarURL: undefined, createdAt: "2020-03-09T08:37:30Z", customData: undefined, id: "support", name: "support", …}
presence: Object
avatarURL: undefined
createdAt: "2020-03-09T08:37:30Z"
customData: undefined
id: "support"
name: "support"
updatedAt: "2020-03-09T08:37:30Z"
presenceStore: {doubtful amethyst impala: "offline", support: "online"}
__proto__: Object
presence appears unenumerable but when clicked shows the correct online status