Conveyor SubProtocol
The native JSON action protocol: the handshake, message shape, built-in actions, and custom handlers.
Enable native mode
Constants::WEBSOCKET_SUBPROTOCOL => Constants::SOCKET_CONVEYORThe WebSocket subprotocol value is:
socketconveyor.comConnection info
After a successful native handshake, Conveyor sends a connection-info message:
{
"action": "connection-info",
"data": "{\"fd\":1,\"event\":\"connection-info\"}"
}When acknowledgment is enabled, this message also includes an id.
Message shape
Clients send JSON messages with an action field. Most actions also need action-specific fields.
{
"action": "base-action",
"data": "hello"
}Built-in actions
base-action
Echoes the message back to the current socket.
{
"action": "base-action",
"data": "hello"
}channel-connect
Connects the current socket fd to one channel.
{
"action": "channel-connect",
"channel": "orders.1"
}When Constants::WEBSOCKET_SERVER_TOKEN is configured, include either the server token or a temporary channel token in auth:
{
"action": "channel-connect",
"channel": "orders.1",
"auth": "temporary-token"
}broadcast-action
Sends data to other sockets in the current channel. If the sender is not in a channel, Conveyor broadcasts to sockets that are not in any channel.
{
"action": "broadcast-action",
"data": {
"body": "order updated"
}
}fanout-action
Sends data to every established socket. When Constants::WEBSOCKET_SERVER_TOKEN is configured, auth must contain that server token.
{
"action": "fanout-action",
"data": "hello everyone"
}channel-disconnect
Removes the current socket fd from its channel.
{
"action": "channel-disconnect"
}acknowledge-action
Acknowledges a server message when native acknowledgment is enabled. data carries the message id.
{
"action": "acknowledge-action",
"data": "message-id"
}Channel flow
- The client connects to the WebSocket server.
- The server sends
connection-info. - The client sends
channel-connectwith achannel. - The server records the fd-to-channel association.
- The client sends
broadcast-actionwithdata. - The server wraps outbound data as
action(broadcast-action),data, andfd(the sender's fd). - The server delivers the message to other established sockets in the same channel.
Custom actions
These are native protocol handlers, distinct from hook actions and filters. Pusher mode supports the documented hook callbacks but does not dispatch through Constants::ACTIONS.
Register custom native action handlers through Constants::ACTIONS in conveyorOptions:
use Conveyor\Constants;
use Conveyor\ConveyorServer;
use App\WebSocket\SampleAction;
(new ConveyorServer())
->port(8989)
->conveyorOptions([
Constants::ACTIONS => [
new SampleAction(),
],
])
->start();Each action class implements:
public function execute(array $data): mixed;
public function send(string $data, ?int $fd = null, bool $toChannel = false): void;
public function getName(): string;Prefer a packaged native client? See the JavaScript and PHP client guides.