io.pedestal.http.jetty.websockets
add-ws-endpoints
(add-ws-endpoints ctx ws-paths)
(add-ws-endpoints ctx ws-paths opts)
Given a ServletContextHandler and a map of WebSocket (String) paths to action maps, produce corresponding Servlets per path and add them to the context. Return the context when complete.
You may optionally also pass in a map of options. Currently supported options: :listener-fn - A function of 3 args, the ServletUpgradeRequest, ServletUpgradeResponse, and the WS-Map that returns a WebSocketListener.
make-ws-listener
(make-ws-listener ws-map)
Given a map representing WebSocket actions (:on-connect, :on-close, :on-error, :on-text, :on-binary), return a WebSocketConnectionListener. Values for the map are functions with the same arity as the interface.
start-ws-connection
(start-ws-connection on-connect-fn)
(start-ws-connection on-connect-fn send-buffer-or-n)
Given a function of two arguments (the Jetty WebSocket Session and its paired core.async ‘send’ channel), and optionall a buffer-or-n for the ‘send’ channel, return a function that can be used as an OnConnect handler.
Notes: - You can control the entire WebSocket Session per client with the session object. - If you close the send
channel, Pedestal will close the WS connection.
start-ws-connection-with-fc-support
(start-ws-connection-with-fc-support on-connect-fn)
(start-ws-connection-with-fc-support on-connect-fn send-buffer-or-n)
Like start-ws-connection
but transmission is non-blocking and supports conveying transmission results. This allows services to implement flow control.
Notes:
Putting a sequential value on the send
channel signals that a transmission response is desired. In this case the value is expected to be a 2-tuple of msg
resp-ch
where msg
is the message to be sent and resp-ch
is the channel in which the transmission result will be put.
WebSocketSend
protocol
members
ws-send
(ws-send msg remote-endpoint)
Sends msg
to remote-endpoint
. May block.
WebSocketSendAsync
protocol
members
ws-send-async
(ws-send-async msg remote-endpoint)
Sends msg
to remote-endpoint
. Returns a promise channel from which the result can be taken.
ws-servlet
(ws-servlet creation-fn)
Given a function (that takes a ServletUpgradeRequest and ServletUpgradeResponse and returns a WebSocketListener), return a WebSocketServlet that uses the function to create new WebSockets (via a factory).