Waffle uses a WebSocket gateway to transmit various updates from the server to the client and vice-versa (new message, user disconnecting, connect to voice, etc.)
# Gateway Payload format
All payloads sent through the gateway are *string payloads*. They all start with a number represeting the "instruction", followed by a "@" character (to delimit the instruction number from the rest of the payload), after which comes the data for the specific instruction.
Example packet:
```json
23@this is my payload data
```
Note for the example above: The "this is my payload data" text should not be user controlled. If user controlled input is required, it must be sanitized and/or passed as a JSON field.
Packets can also have JSON as a payload:
```json
32@{"name":"Alice"}
```
## Instructions
The terms "channel" and "category" are used interchangeably.
## 0:HELLO
*Part of handshake, Server to client*
Sent by the server to the client as soon as possible after they connect to the gateway.
This payload can contain a JSON object with various information about the server. It should be relied on only when absolutely necessary.
Example:
```json
0@{}
```
## 1:YOO
*Part of handshake, Client to server*
Sent by the client as soon as possible after receiving the HELLO instruction.
If the token is invalid, or the connection is otherwise rejected, the client should be disconnected as soon as possible, and no YOO\_ACK should be sent.
## 2:YOO\_ACK
*Part of handshake, Server to client*
Sent by the server as soon as possible after processing the YOO payload from the client.
Sent by the server after YOO\_ACK, and otherwise when the entire status needs to be updated. Usually, this will be sent only once, and when subsequent user status updates need to happen, EVENT\_CHANNEL\_MEMBER\_UPDATE should be sent.
Sent by the client whenever it wants to initiate a voice session in a specific channel.
JSON data format:
| Field | Description |
| - | - |
| channel | An object that contains "_id", the id of the channel to connect to |
(unfinished)
## 22:ACTION\_VOICE\_BEGIN\_SESSION
*Auth required, Client to server*
Sent by the server when the voice session request has been accepted. If it is rejected, the client MUST be disconnected from the gateway as soon as possible.
JSON data format:
| Field | Description |
| - | - |
| reportTo | The IP and port of the voice server to connect to |
(unfinished)
# Objects and data types
## Message object
| Field | Description |
| - | - |
| content | The text content of the message (max 2000 characters, min 1 character, trimmed) |
| channel | A [message channel object](#message-channel-object) |
| author | A [message author object](#message-author-object) |