Skip to content

Full Example: Realtime Chat ​

The Realtime Chat page is a group chat with private messages, built on Skapi's realtime connection. It needs a logged-in user. Open it in another browser or device with a second account and join the same group to chat.

Enter your project ID to open the demo.

You need your project ID to open the demo.

What it demonstrates ​

FeatureHow the page does it
ConnectingconnectRealtime() opens the WebSocket connection once the user is known, with one callback that receives every message.
Listing and creating groupsgetRealtimeGroups() lists the groups that have someone in them. Creating a group is joining a name nobody has joined yet.
Joining a groupjoinRealtime() with the group name from the URL hash; getRealtimeUsers() lists who is already there, and their profiles come from getUsers().
Group messagespostRealtime() with the form and the group name. Everyone in the group, including the sender, receives it as a message.
Private messagesClicking a name in the participant list opens a dialog; postRealtime() with a user ID instead of a group name delivers the message to that user only, as a private message.
Joining and leavingThe notice messages with the codes USER_JOINED, USER_LEFT and USER_DISCONNECTED keep the participant list current.

Download ​

The page is part of the full template: skapi-templates.zip. See Full Examples for how to run it.