module Amber::WebSockets::Presence

Overview

Module-level presence tracking for WebSocket channels.

This module stores presence data outside the Channel class hierarchy to avoid Crystal's class variable inheritance behavior where each subclass gets its own copy of @@ variables. By using a module with extend self, all channel classes share the same presence store.

Presence data tracks which client sockets are present in each channel topic, along with metadata such as when they joined. This enables features like user lists, online indicators, and presence_diff events.

Extended Modules

Defined in:

amber/websockets/presence.cr

Instance Method Summary

Instance Method Detail

def count(topic_path : String) : Int32 #

Returns the number of sockets present in the given topic.


[View source]
def has_socket?(topic_path : String, socket_id : String) : Bool #

Returns whether a socket is present in the given topic.


[View source]
def list(topic_path : String) : Hash(String, Hash(String, String)) #

Returns all presence entries for the given topic.


[View source]
def reset #

Clears all presence data. Useful for testing.


[View source]
def track(topic_path : String, socket_id : String, metadata : Hash(String, String)) #

Tracks a client socket's presence in the given topic.


[View source]
def untrack(topic_path : String, socket_id : String) : Hash(String, String) #

Removes a client socket's presence from the given topic. Returns the metadata that was removed, or an empty hash if not found.


[View source]