abstract struct Launch::WebSockets::ClientSocket

Overview

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 < Launch::Websockets::ClientSocket
  channel "user_channel:*", UserChannel
  channel "room_channel:*", RoomChannel

  def on_connect
    return some_auth_method!
  end
end

Defined in:

launch/websockets/client_socket.cr

Constant Summary

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

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Object

blank? blank?, present? present?

Constructor Detail

def self.new(socket : HTTP::WebSocket, context : HTTP::Server::Context) #

[View source]

Class Method Detail

def self.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"})

[View source]
def self.channel(channel_path, ch) #

Add a channel for this socket to listen, publish to


[View source]
def self.channels #

[View source]
def self.get_topic_channel(topic_path) #

[View source]

Instance Method Detail

def on_connect : Bool #

Authentication and authorization can happen here


[View source]
def on_disconnect #

On socket disconnect functionality


[View source]
def socket : HTTP::WebSocket #

[View source]