annotation ActionController::Route::WebSocket

Overview

define a new route that responds to websocket requests

SOCKETS = [] of HTTP::WebSocket

@[AC::Route::WebSocket("/websocket/:name")]
def websocket(socket, name : String)
  socket.on_message do |message|
    SOCKETS.each &.send("#{name}: #{message}")
  end

  socket.on_close do
    SOCKETS.delete(socket)
  end
end

Defined in:

action-controller/router/builder.cr