Track collaborative user presence and broadcast ephemeral state changes.
const onPresence = (users) => {
console.log("Active online collaborators:", users);
};
baas.realtime.presence.onState(onPresence).subscribe();// Trigger typing starts in room 'chat-room-101'
baas.realtime.presence.startTyping("chat-room-101");
// Trigger typing stops
baas.realtime.presence.stopTyping("chat-room-101");Track collaborative presence users with strongly typed fields:
interface PresenceUser {
userId: string;
displayName: string;
status: "online" | "offline" | "away";
}
baas.realtime.presence
.onState((users: PresenceUser[]) => {
users.forEach(u => console.log(u.displayName, "is currently", u.status));
})
.subscribe();