@eulerstream/euler-websocket-sdk

中文文档
1.1.0发布于 2026/10/26MITTypeScriptES Module构建来源已验证近 30 天下载 2.6万

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

原始使用文档
文档目录8 节
  1. Enterprise Solutions
  2. Community
  3. Installation
  4. Supported Runtimes
  5. Protobuf Schema Versions
  6. Quick Start
  7. What You Get
  8. WebSocket Close Codes

EulerStream WebSocket SDK

TypeScript SDK for the Euler Stream TikTok LIVE WebSocket service. Build URLs, decode protobuf frames, and consume strongly-typed Webcast events from any JavaScript runtime.

LinkedIn Patrons Connections Stars Issues

Enterprise Solutions




Euler Stream is a paid TikTok LIVE service providing managed TikTok LIVE WebSocket connections, increased access, TikTok LIVE alerts, JWT authentication and more.

Community

Join the EulerStream discord for questions, concerns, or just a good chat.

Installation

npm install @eulerstream/euler-websocket-sdk
# or
pnpm add @eulerstream/euler-websocket-sdk

Supported Runtimes

The package ships dual builds via the exports map in package.json. Your bundler / runtime picks the right one automatically — no configuration needed.

RuntimeEntry resolvedNotes
Node.js (≥ 18)dist/node/*.jsReads EULER_WS_URL from process.env to override the default host.
Browserdist/web/*.jsNo process access; defaults to wss://ws.eulerstream.com.
Bundlers (Vite, webpack, esbuild, Rollup, Next.js, etc.)resolved via the browser / import conditionsESM-only, tree-shakeable.

All builds are ESM. There is no CommonJS build — consume from import syntax or via a bundler that handles ESM.

Protobuf Schema Versions

TikTok's Webcast protobuf schemas are re-exported from tiktok-live-proto. Two schema versions ship side-by-side and you can pick which one the SDK decodes with at runtime:

VersionSubpath importWhen to use
v2@eulerstream/euler-websocket-sdk/v2 (default)Current schema. Recommended for all new integrations.
v1@eulerstream/euler-websocket-sdk/v1Legacy schema for older consumers that haven't migrated yet.

Select the schema at connect time via the schemaVersion feature flag (defaults to v2):

import { createWebSocketUrl, SchemaVersion } from '@eulerstream/euler-websocket-sdk';

const url = createWebSocketUrl({
  uniqueId: '@someuser',
  features: { schemaVersion: SchemaVersion.v2 },
});

Import message types directly from a versioned subpath when you need them:

import type { WebcastChatMessage, WebcastGiftMessage } from '@eulerstream/euler-websocket-sdk/v2';

The top-level entry re-exports the v2 schema for convenience, so import { WebcastChatMessage } from '@eulerstream/euler-websocket-sdk' also works.

Quick Start

import { createWebSocketUrl, ClientCloseCode } from '@eulerstream/euler-websocket-sdk';

const url = createWebSocketUrl({
  uniqueId: '@someuser',
  jwtKey: process.env.EULER_JWT,
  features: {
    bundleEvents: true,
    syntheticPresence: true,
  },
});

const ws = new WebSocket(url);
ws.addEventListener('close', (e) => {
  if (e.code === ClientCloseCode.NOT_LIVE) console.log('streamer is offline');
});

What You Get

  1. createWebSocketUrl(options) — builds a fully-qualified WS URL with feature flags flattened into query params.
  2. Strongly-typed Webcast message interfaces (v1 and v2) re-exported from tiktok-live-proto.
  3. Protobuf decode utilities for raw frames (DecodedData, decodeFrame, etc.) when running in rawMessages mode.
  4. WebcastEventEmitter — a typed eventemitter3 subclass keyed off the schema's event names.
  5. ClientCloseCode enum + CloseMessageMap for interpreting WebSocket close codes from the server.

WebSocket Close Codes

export enum ClientCloseCode {
  // Standard
  NORMAL = 1000,
  INTERNAL_SERVER_ERROR = 1011,

  // Custom (4000–4999)
  STREAM_END = 4005,
  NO_MESSAGES_TIMEOUT = 4006,
  INVALID_OPTIONS = 4400,
  INVALID_AUTH = 4401,
  NO_PERMISSION = 4403,
  NOT_LIVE = 4404,
  KEEPALIVE_TIMEOUT = 4408,
  TOO_MANY_CONNECTIONS = 4429,
  TIKTOK_CLOSED_CONNECTION = 4500,
  MAX_LIFETIME_EXCEEDED = 4555,
  WEBCAST_FETCH_ERROR = 4556,
  ROOM_INFO_FETCH_ERROR = 4557,
}

版本与发布记录

@eulerstream/euler-websocket-sdk 共发布 10 个版本,首次发布于 2025/05/30;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.0latest2026/10/2619 天前
1.0.02026/04/296 个月前
0.0.62025/08/301.2 年前
0.0.6-beta12025/06/161.4 年前
0.0.6-alpha12025/06/151.4 年前
0.0.52025/06/101.4 年前

关于 @eulerstream/euler-websocket-sdk 的常见问题

@eulerstream/euler-websocket-sdk 是什么?

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

如何安装 @eulerstream/euler-websocket-sdk?

在项目目录运行 npm install @eulerstream/euler-websocket-sdk,或使用 pnpm add / yarn add / bun add。

@eulerstream/euler-websocket-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@eulerstream/euler-websocket-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@eulerstream/euler-websocket-sdk 可以商用吗?

@eulerstream/euler-websocket-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@eulerstream/euler-websocket-sdk 的下载量有多少?

根据 npm 官方下载统计,@eulerstream/euler-websocket-sdk 在 2026/10/14 – 2026/11/12 这 30 天内被下载 25,909 次,日均约 864 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@eulerstream/euler-websocket-sdk 还在维护吗?

最新版本 1.1.0 发布于 2026/10/26(19 天前);至今共发布 10 个版本,其中过去 12 个月发布了 2 个;首次发布于 2025/05/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。