16 lines
555 B
Crystal
16 lines
555 B
Crystal
module Kemal
|
|
# Kemal::WebSocketHandler is used for building a WebSocket route.
|
|
# For each WebSocket route a new handler is created and registered to global handlers.
|
|
class WebSocketHandler < HTTP::WebSocketHandler
|
|
def initialize(@path : String, &@proc : HTTP::WebSocket, HTTP::Server::Context -> Void)
|
|
Kemal.config.add_handler self
|
|
Kemal::RouteHandler::INSTANCE.add_ws_route @path
|
|
end
|
|
|
|
def call(context)
|
|
raise Kemal::Exceptions::RouteNotFound.new(context) unless context.ws_route_defined?
|
|
super
|
|
end
|
|
end
|
|
end
|