Register a WebSocket route. Events are produced when a WebSocket connection is established, WebSocket messages are received and when a connection is closed. Message can be responded to with an
A common pattern is routing the
close ports to a connection manager node. The connection manager can then dispatch messages as required. In the example below the manager supports broadcasting a message to all connected clients.
When a WebSocket connection is established by a client an event is routed to the
When a message is received from a connected WebSocket client an event is routed to the
When a WebSocket connection is closed an event is routed to the
All produced events are objects. All events have the following properties:
Events routed to the
message port also has the property
peer property holds a string describing the IP address of the client. (May be a list of IPs if the client is connected through proxies.)
sessionId property holds a string that is unique for the current connection.
method property holds a string corresponding to the HTTP method used to connect.
params property holds an object as described here.
query property holds an object as described here.
headers property holds an object as described here.
message property holds contains the sent WebSocket message.
This functions listens for an event local
response event when a
message event is routed. When a
response event is received, a message is sent to the client the originally triggered the orgininal
The argument for the
response event is expected to be an object of the following form
end is optional. If present and it is truthy, the connection to the client is closed.
body may be any value.
See us use the WebSocket trigger here.
Updated 4 months ago