abstract class Launch::WebSockets::Channel

Overview

Sockets subscribe to Channels, where the communication log is handled. The channel provides functionality to handle socket join #handle_joined and socket messages handle_message(msg).

Example:

class ChatChannel < Launch::Websockets::Channel
  def handle_joined(client_socket)
    # functionality when the user joins the channel, optional
  end

  def handle_leave(client_socket)
    # functionality when the user leaves the channel, optional
  end

  # functionality when a socket sends a message to a channel, required
  def handle_message(msg)
    rebroadcast!(msg)
  end
end

Defined in:

launch/websockets/channel.cr

Constructors

Instance Method Summary

Instance methods inherited from class Object

blank? blank?, present? present?

Constructor Detail

def self.new(topic_path : String) #

[View source]

Instance Method Detail

def handle_joined(client_socket, message) #

Authorization can happen here


[View source]
def handle_leave(client_socket) #

[View source]
abstract def handle_message(client_socket, msg) #

[View source]
def on_message(client_socket_id, message) #

Called from proc when message is returned from the pubsub service


[View source]