struct

Amber::WebSockets::ClientSocket

Inherits Struct < Value < Object

ClientSocket struct maps a user to an HTTP::WebSocket. For every websocket connection there will be an associated ClientSocket. Authentication and authorization happen within the ClientSocket. ClientSocket will subscribe to Channels, where incoming and outgoing messages are routed through.

Example:

struct UserSocket < Amber::Websockets::ClientSocket
  channel "user_channel:*", UserChannel
  channel "room_channel:*", RoomChannel

  def on_connect
    return some_auth_method!
  end
end

Constants

BEAT_INTERVAL = 30.seconds
Log = ::Log.for(self)
MAX_SOCKET_IDLE_TIME = 100.seconds

Constructors

Class methods

broadcast(event : String, topic : String, subject : String, payload : Hash)

Broadcast a message to all subscribers of the topic

UserSocket.broadcast("message", "chats_room:1", "msg:new", {"message" => "test"})
Source
channel(channel_path, ch)

Add a channel for this socket to listen, publish to

Source
channels
Source
get_topic_channel(topic_path)
Source

Instance methods

on_connect

Authentication and authorization can happen here

Source
on_disconnect

On socket disconnect functionality

Source
socket
Source