Presence Protocol
Channel-based user presence awareness for real-time applications. Know who is online, track join/leave events, and build collaborative experiences.
Channel-based user presence awareness for real-time applications. Know who is online, track join/leave events, and build collaborative experiences.
Track connected users across channels for chat rooms, collaborative editing, shared browsing, and multiplayer games.
The Presence protocol enables awareness of which users are subscribed to a channel. When a user joins or leaves, all other channel members receive a notification. This is essential for applications that need to display online user lists, typing indicators, active collaborator cursors, or player status in multiplayer games. The protocol supports multiple simultaneous channels per user and provides a full member list on join.
Join a channel and track other users' presence.
uses
sgcWebSocket_Client, sgcWebSocket_Types,
sgcWebSocket_Protocol_Presence_Client;
var
WSClient: TsgcWebSocketClient;
PresenceProtocol: TsgcWSPClient_Presence;
procedure TForm1.FormCreate(Sender: TObject);
begin
WSClient := TsgcWebSocketClient.Create(nil);
WSClient.Host := 'myserver.example.com';
WSClient.Port := 443;
PresenceProtocol := TsgcWSPClient_Presence.Create(nil);
PresenceProtocol.Client := WSClient;
PresenceProtocol.OnMemberJoin := OnMemberJoin;
PresenceProtocol.OnMemberLeave := OnMemberLeave;
WSClient.Active := True;
end;
procedure TForm1.ButtonJoinClick(Sender: TObject);
begin
PresenceProtocol.Join('chat-room-1', 'Alice');
end;
procedure TForm1.OnMemberJoin(Sender: TObject;
const aChannel, aMember: string);
begin
ListBox1.Items.Add(aMember + ' joined');
end;
Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.