API Reference
Close Codes
WebSocket close codes returned by the Euler Stream WebSocket server and what they mean.
The Euler Stream WebSocket server uses standard and custom close codes to indicate why a connection was terminated.
Close Code Reference
enum ClientCloseCode {
/** Responding to a client's close request normally */
NORMAL = 1000,
/** Error updating presence on connect, or upstream error */
INTERNAL_SERVER_ERROR = 1011,
/** Error fetching the /webcast/fetch endpoint */
WEBCAST_FETCH_ERROR = 4556,
/** Error fetching the /webcast/room_info endpoint */
ROOM_INFO_FETCH_ERROR = 4557,
/** TikTok closed the connection unexpectedly */
TIKTOK_CLOSED_CONNECTION = 4500,
/** Account has too many connections or is connecting too quickly */
TOO_MANY_CONNECTIONS = 4429,
/** Invalid context (e.g., invalid uniqueId or JWT key) */
INVALID_OPTIONS = 4400,
/** The requested streamer is not live */
NOT_LIVE = 4404,
/** The TikTok stream ended */
STREAM_END = 4005,
/** No messages received within timeout period */
NO_MESSAGES_TIMEOUT = 4006,
/** Invalid authentication credentials */
INVALID_AUTH = 4401,
/** JWT does not grant access to this creator */
NO_PERMISSION = 4403,
/** WebSocket exceeded 8-hour maximum lifetime */
MAX_LIFETIME_EXCEEDED = 4555,
}
Handling Close Codes
import WebSocket from "ws";
const ws = new WebSocket(
`wss://ws.eulerstream.com?uniqueId=tv_asahi_news&apiKey=${process.env.EULER_API_KEY}`
);
ws.on("close", (code: number, reason: Buffer) => {
switch (code) {
case 4404:
console.log("Creator is not currently live");
break;
case 4005:
console.log("Stream ended");
break;
case 4429:
console.log("Too many connections - back off and retry");
break;
case 4401:
console.log("Authentication failed - check your API key or JWT");
break;
default:
console.log(`Connection closed: ${code} - ${reason.toString()}`);
}
});
Common Scenarios
| Code | Scenario | Action |
|---|---|---|
1000 | Normal close | No action needed |
4404 | Creator offline | Wait and retry when they go live |
4005 | Stream ended | Connection complete, no retry needed |
4429 | Rate limited | Exponential backoff before reconnecting |
4401 | Bad credentials | Verify your API key or provision a new JWT |
4403 | JWT scope mismatch | Ensure the JWT includes this creator in allowedCreators |
4006 | Idle timeout | Reconnect - the connection went stale |
4555 | 8-hour limit | Reconnect - WebSocket connections are limited to 8 hours |