2016-07-17 11:43:13 +00:00
|
|
|
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)
|
2016-11-02 08:19:48 +00:00
|
|
|
Kemal.config.add_handler self
|
2017-08-20 17:01:49 +00:00
|
|
|
Kemal::RouteHandler::INSTANCE.add_ws_route @path
|
2016-07-17 11:43:13 +00:00
|
|
|
end
|
2015-12-15 21:11:21 +00:00
|
|
|
|
2016-07-17 11:43:13 +00:00
|
|
|
def call(context)
|
2017-08-20 17:01:49 +00:00
|
|
|
raise Kemal::Exceptions::RouteNotFound.new(context) unless context.ws_route_defined?
|
2016-07-17 11:43:13 +00:00
|
|
|
super
|
|
|
|
end
|
2015-12-15 21:11:21 +00:00
|
|
|
end
|
|
|
|
end
|