Realtime > Presence & Typing
Realtime > Presence & TypingKroxt BaaS SDK v1.0.5

Presence & Typing

Track collaborative user presence and broadcast ephemeral state changes.

Track Online presence roster:
presence.ts
1
2
3
4
5
const onPresence = (users) => {
  console.log("Active online collaborators:", users);
};

baas.realtime.presence.onState(onPresence).subscribe();
Typing status broadcasts:
presence.ts
1
2
3
4
5
// 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");

TypeScript Type Integration

Track collaborative presence users with strongly typed fields:

types.ts
1
2
3
4
5
6
7
8
9
10
11
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();