Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if(!current){
console.log("user has entered for the first time", newPres)
} else {
console.log("user additional presence", newPres)
}
};
const onLeave = (id: string, current: any, leftPres: any) => {
if(current.metas.length === 0){
console.log("user has left from all devices", leftPres)
} else {
console.log("user left from a device", leftPres)
}
};
state = Presence.syncState(state, stateFromServer, onJoin, onLeave);
const listBy = (id: string, {metas: [first, ...rest]} : {metas: any[]}) => {
first.count = rest.length + 1;
first.id = id;
return first;
};
const onlineUsers = Presence.list(state, listBy);
}
interfaceChannel.on('presence_state', state => {
presences = Presence.syncState(presences, state)
dispatch(updatePresences(Presence.list(presences, listBy)))
})
this.channel.on("presence_state", state => {
this.setState({
...this.state,
presences: Presence.syncState(this.state.presences, state)
});
});
channel.on('presence_state', (state) => {
presences = Presence.syncState(presences, state);
syncPresentUsers(dispatch, presences);
});
const handlePresenceState = (initialPresence) => {
const syncedPresence = Presence.syncState(this.stateBuffer.presence, initialPresence);
this.updateState({ presence: { $set: syncedPresence } });
Object.keys(syncedPresence).forEach(this.handleJoin);
};
channel.on('presence_state', (state) => {
presences = Presence.syncState(presences, state)
store.dispatch('syncPresentUsers', presences)
})
room.on("presence_state", state => {
presences = Presence.syncState(presences, state)
const users = values(presences).map(presence => presence.user)
this.setState({ users })
})