const mixinafWebSockets::WebSockets
afWebSockets::WebSockets
(Service) The main service for handling WebSocket
connections.
If creating a BedApp
- broadcast
abstract Void broadcast(Str msg, Uri[]? webSocketIds := null)
Broadcasts the given message to all open WebSockets, or to just the WebSockets associated with the given IDs. This is a safe operation, as in if a WebSocket for a given ID could not be found, it is silently ignored.
- get
abstract WebSocket? get(Uri webSocketId, Bool checked := true)
Returns the
WebSocket
associated with the given ID. Note that closed WebSockets no longer exist.If a WebSocket could not be found then either
null
is returned or anArgErr
is thrown dependant on the value ofchecked
.- make
static new make(ActorPool actorPool, |This? f := null)
Creates a
WebSockets
instance.- onUpgrade
abstract |WebReq,WebRes,WebSocket,TcpSocket? onUpgrade
Hook to allow negotiation of websocket protocols and extensions. Called after the socket upgrade has been verified but before the response has been committed (and before the response headers have been sent).
This field may be set at any time.
- service
abstract Void service(WebSocket webSocket, WebReq req, WebRes res)
Services the given
WebSocket
. The active HTTP request is upgraded to a WebSocket connection. This call then enters a read loop and blocks until the WebSocket is closed.- shutdown
abstract Void shutdown()
Closes all open WebSockets.
- socketReadTimeOut
abstract Duration? socketReadTimeOut
The maximum amount of time a websocket blocks for while waiting for a message from the client. After this time the socket times out and the WebSocket closes.
Set to
null
for an infinite timeout - but a word of caution, this then leaves you vulnerable to DOS attacks.This field may be set at any time, but only affects WebSockets connected after the change.
Defaults to
5min
.