PresenceMixin — live avatars in 6 lines
Open this page in a second browser tab (or send the URL to a friend). You'll appear in each other's presence list, and disappear when you close the tab.
Online right now (1)
live- guest-d40 — since 1777793332.7137089
Presence is keyed on apps.realtime.views_presence.PresenceDemoView's presence_key. Each connected WebSocket session shows up here. Disconnect → auto-removed.
The whole pattern
from djust.presence import PresenceMixin
class ChatRoomView(PresenceMixin, LiveView):
presence_key = 'chat:{room_id}'
def mount(self, request, **kwargs):
self.track_presence(meta={
'name': request.user.username,
'avatar': request.user.profile.avatar_url,
})
def get_context_data(self, **kwargs):
return {'online_users': self.list_presences()}
See docs.djust.org/api/presence/ for cursor tracking, ephemeral metadata, and the full API.