Testing WebSocket Events

BETA The event command includes the start-websocket-server subcommand that starts a mock WebSocket server that you can use to test your client.

To use this command, you must first implement a WebSocket client that handles the server’s messages. For details, see Getting Events Using WebSockets.

Starting the server

Use the start-websocket-server subcommand to starts a mock WebSocket server that you use to test your client. In a terminal window, enter:

twitch event start-websocket-server 

To end the server, enter ctrl+c.

Connecting to the server

The URI that you use in your client code to connect your client to the server is: ws://localhost:8080/eventsub.

The messages that the server sends

After connecting your client to the server, the server sends the client a welcome message followed by ping and keepalive messages. To receive a reconnect message, use the --reconnect flag (see below).

Flags to use with the server

Use these flags to change the server’s behavior or send additional messages.

Flag Shorthand Description Example
--reconnect -r Use to ask the mock server to send a reconnect message. The syntax is --reconnect <delay>, where delay is the number of seconds that you want the mock server to wait before sending the reconnect message after your client connects to the server. -r 10
--port -p Use to specify the port number to use in the localhost address. The syntax is --port <number>. The default is 8080. -p 3000