module Orion::DSL::WebSockets

Overview

The websocket handlers allow you to easily add websocket support to your application.

Defined in:

orion/dsl/websockets.cr

Macro Summary

Macro Detail

macro ws(path, ws_callable, *, helper = nil) #

Defines a websocket route to a callable object.

You can route to any object that responds to call with a HTTP::WebSocket and an HTTP::Server::Context.

router MyRouter do
  ws "/path", Callable
end

module Callable
  def call(ws : HTTP::WebSocket, cxt : HTTP::Server::Context)
    # ... do something
  end
end

[View source]
macro ws(path, *, to, helper = nil) #

Defines a websocket route to a websocket compatible controller and action (short form). You can route to a controller and action by passing the to argument in the form of "MyWebSocket#action".

router WebApp do
  ws "/path", to: "Sample#ws"
end

class SampleController < WebApp::BaseController
  def ws
    # ... do something
  end
end

[View source]
macro ws(path, *, action, controller = CONTROLLER, helper = nil) #

Defines a match route to a controller and action (long form). You can route to a controller and action by passing the controller and action arguments, if action is omitted it will default to match.

router WebApp do
  ws "/path", controller: SampleController, action: ws
end

class SampleController < WebApp::BaseController
  def ws
    # ... do something
  end
end

[View source]
macro ws(path, *, helper = nil, &block) #

Defines a match route with a block.

Pass a block as the response and it will be evaluated as a controller 0..2 block parameters are accepted. The block itself will always be evaluated as a controller and have access to all controller methods and macros.

router MyRouter do
  ws "/path" do |websocket, context|
    # ... do something
  end
end

[View source]