Commands
Kanalo offers JSON structured commands that let Functions respond with data or lifecycle operations. These are sent to Kanalo in the HTTP response to incoming data, as an array of command objects. An example of a command object is:
{
"command": "message",
"params": {
"sockets": ["6041043d-5c57-4756-9a82-3c6ca9c51e59"],
"message": "I am a message",
}
}
The general properties of the object are as follows:
method
is the string name of the method to be invoked.params
is an object containing the parameters to pass to the method call. Depends onmethod
.
Available Commands
The commands available on the Kanalo system are:
Method | Parameters | Description |
---|---|---|
message | - sockets (optional string[]): The IDs of socket(s) to message- tags (optional string[]): The tag(s) to message- message (string): The data to send | Sends the data directly to the specified sockets or all sockets associated with the given tags. At least one of sockets or tags must be included. |
disconnect | - sockets (optional string[]): The IDs of socket(s) to disconnect- tags (optional string[]): The tag(s) identifying sockets to disconnect- code (number): The disconnect code (see here for valid codes)- reason (string): The disconnect message | Disconnects the specified socket(s) or all sockets associated with the given tags. At least one of sockets or tags must be included. |
tag | - sockets (string[]): The IDs of socket(s) to add- tags (optional string[]): The tag(s) identifying sockets to add- tagsToAdd (string[]): The tag(s) each socket is added to | Associate the specified socket(s) with the specified tag(s). |
untag | - sockets (string[]): The IDs of socket(s) to remove- tags (optional string[]): The tag(s) identifying sockets to remove- tagsToRemove (string[]): The tag(s) each socket is removed from | De-associate the specified socket(s) from the specified tag(s). |
set | - sockets (string[]): The IDs of socket(s) to set metadata on- tags (optional string[]): The tag(s) identifying sockets to set metadata on- entries (Record<string, string>): Key-value pairs of metadata | Set arbitrary metadata values on the given sockets or tags. |
Sending Commands
Commands are sent as a JSON array in the body of the HTTP response to incoming data that arrives as a PUT to your backend. This allows for adding the response commands individually while processing the batched event data from Kanalo, and then responding with a single batched array. For an example of a server responding with a command, see the echo example in the Server Quickstart.