UNPKG

@eulerstream/euler-websocket-sdk

Version:

Browser & Node.JS cross-compatible module for the Euler Stream WebSocket service.

176 lines 8.46 kB
import { z } from "zod"; import { DecodedData, SchemaVersion } from "../webcast"; export declare enum ClientCloseCode { /** * Error updating presence on connect, or upstream error on connect in the proxy. */ INTERNAL_SERVER_ERROR = 1011, /** * TikTok closed the connected unexpectedly. */ TIKTOK_CLOSED_CONNECTION = 4500, /** * The account has too many connections. */ TOO_MANY_CONNECTIONS = 4429, /** * The client provided invalid options, such as an invalid uniqueId or JWT key. */ INVALID_OPTIONS = 4401, /** * The requested streamer is not live. */ NOT_LIVE = 4404, /** * The TikTok stream ended. */ STREAM_END = 4005, /** * There were no messages in the timeout period, the WebSocket was assumed dead and closed. */ NO_MESSAGES_TIMEOUT = 4006 } export declare const CloseMessageMap: Record<ClientCloseCode, string>; export declare const WebSocketFeatureFlags: z.ZodObject<{ /** * When enabled, the client will bundle multiple messages into a single event. This is more efficient * than sending messages individually. */ bundleEvents: z.ZodDefault<z.ZodEffects<z.ZodEnum<["true", "false", "1", "0"]>, boolean, "0" | "1" | "false" | "true">>; /** * When enabled, the client will act as a pass-through proxy for raw messages. You will lose out on * additional features like presence messages, but this will fit nicely into existing libraries. */ rawMessages: z.ZodDefault<z.ZodEffects<z.ZodEnum<["true", "false", "1", "0"]>, boolean, "0" | "1" | "false" | "true">>; /** * Whether to normalize uniqueIds in URL format, @uniqueId format, etc., or treat them as-is. */ normalizeUniqueId: z.ZodDefault<z.ZodEffects<z.ZodEnum<["true", "false", "1", "0"]>, boolean, "0" | "1" | "false" | "true">>; /** * When enabled, the client will calculate presence information for users in the room. * This enables us to give custom SyntheticJoinMessage and SyntheticLeaveMessage, a full presence system. */ syntheticPresence: z.ZodDefault<z.ZodEffects<z.ZodEnum<["true", "false", "1", "0"]>, boolean, "0" | "1" | "false" | "true">>; /** * Configures how long a user must be inactive before we send a SyntheticLeaveMessage. */ syntheticPresenceLeaveAfter: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>, number, string | undefined>, number, string | undefined>, number, string | undefined>; /** * Configures how long we can wait with NO messages coming from TikTok before we assume the WebSocket * is dead and close it. */ closeInactiveWebSocketAfter: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>, number, string | undefined>, number, string | undefined>, number, string | undefined>; /** * The TikTok protobuf schema version to use for decoding messages. */ schemaVersion: z.ZodDefault<z.ZodNativeEnum<typeof SchemaVersion>>; }, "strip", z.ZodTypeAny, { bundleEvents: boolean; rawMessages: boolean; normalizeUniqueId: boolean; syntheticPresence: boolean; syntheticPresenceLeaveAfter: number; closeInactiveWebSocketAfter: number; schemaVersion: SchemaVersion; }, { bundleEvents?: "0" | "1" | "false" | "true" | undefined; rawMessages?: "0" | "1" | "false" | "true" | undefined; normalizeUniqueId?: "0" | "1" | "false" | "true" | undefined; syntheticPresence?: "0" | "1" | "false" | "true" | undefined; syntheticPresenceLeaveAfter?: string | undefined; closeInactiveWebSocketAfter?: string | undefined; schemaVersion?: SchemaVersion | undefined; }>; export declare const WebSocketOptionsSchema: z.ZodObject<{ uniqueId: z.ZodString; jwtKey: z.ZodNullable<z.ZodOptional<z.ZodString>>; apiKey: z.ZodNullable<z.ZodOptional<z.ZodString>>; features: z.ZodDefault<z.ZodObject<{ /** * When enabled, the client will bundle multiple messages into a single event. This is more efficient * than sending messages individually. */ bundleEvents: z.ZodDefault<z.ZodEffects<z.ZodEnum<["true", "false", "1", "0"]>, boolean, "0" | "1" | "false" | "true">>; /** * When enabled, the client will act as a pass-through proxy for raw messages. You will lose out on * additional features like presence messages, but this will fit nicely into existing libraries. */ rawMessages: z.ZodDefault<z.ZodEffects<z.ZodEnum<["true", "false", "1", "0"]>, boolean, "0" | "1" | "false" | "true">>; /** * Whether to normalize uniqueIds in URL format, @uniqueId format, etc., or treat them as-is. */ normalizeUniqueId: z.ZodDefault<z.ZodEffects<z.ZodEnum<["true", "false", "1", "0"]>, boolean, "0" | "1" | "false" | "true">>; /** * When enabled, the client will calculate presence information for users in the room. * This enables us to give custom SyntheticJoinMessage and SyntheticLeaveMessage, a full presence system. */ syntheticPresence: z.ZodDefault<z.ZodEffects<z.ZodEnum<["true", "false", "1", "0"]>, boolean, "0" | "1" | "false" | "true">>; /** * Configures how long a user must be inactive before we send a SyntheticLeaveMessage. */ syntheticPresenceLeaveAfter: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>, number, string | undefined>, number, string | undefined>, number, string | undefined>; /** * Configures how long we can wait with NO messages coming from TikTok before we assume the WebSocket * is dead and close it. */ closeInactiveWebSocketAfter: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>, number, string | undefined>, number, string | undefined>, number, string | undefined>; /** * The TikTok protobuf schema version to use for decoding messages. */ schemaVersion: z.ZodDefault<z.ZodNativeEnum<typeof SchemaVersion>>; }, "strip", z.ZodTypeAny, { bundleEvents: boolean; rawMessages: boolean; normalizeUniqueId: boolean; syntheticPresence: boolean; syntheticPresenceLeaveAfter: number; closeInactiveWebSocketAfter: number; schemaVersion: SchemaVersion; }, { bundleEvents?: "0" | "1" | "false" | "true" | undefined; rawMessages?: "0" | "1" | "false" | "true" | undefined; normalizeUniqueId?: "0" | "1" | "false" | "true" | undefined; syntheticPresence?: "0" | "1" | "false" | "true" | undefined; syntheticPresenceLeaveAfter?: string | undefined; closeInactiveWebSocketAfter?: string | undefined; schemaVersion?: SchemaVersion | undefined; }>>; }, "strip", z.ZodTypeAny, { uniqueId: string; features: { bundleEvents: boolean; rawMessages: boolean; normalizeUniqueId: boolean; syntheticPresence: boolean; syntheticPresenceLeaveAfter: number; closeInactiveWebSocketAfter: number; schemaVersion: SchemaVersion; }; jwtKey?: string | null | undefined; apiKey?: string | null | undefined; }, { uniqueId: string; jwtKey?: string | null | undefined; apiKey?: string | null | undefined; features?: { bundleEvents?: "0" | "1" | "false" | "true" | undefined; rawMessages?: "0" | "1" | "false" | "true" | undefined; normalizeUniqueId?: "0" | "1" | "false" | "true" | undefined; syntheticPresence?: "0" | "1" | "false" | "true" | undefined; syntheticPresenceLeaveAfter?: string | undefined; closeInactiveWebSocketAfter?: string | undefined; schemaVersion?: SchemaVersion | undefined; } | undefined; }>; export type ParsedWebSocketOptions = Omit<z.infer<typeof WebSocketOptionsSchema>, 'features'> & { features: WebSocketFeatureFlags; }; export type WebSocketFeatureFlags = z.infer<typeof WebSocketFeatureFlags>; export type WebSocketOptions = Omit<ParsedWebSocketOptions, 'features'> & { features?: Partial<WebSocketFeatureFlags>; }; export type ClientMessageBundle = { timestamp: number; messages: DecodedData[]; }; //# sourceMappingURL=types.d.ts.map