tiktok-live-api 1.2.18 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import WebSocket from 'ws';
2
+
1
3
  /**
2
4
  * Type definitions for TikTok LIVE API events.
3
5
  *
@@ -54,12 +56,12 @@ interface SocialEvent {
54
56
  user: TikTokUser;
55
57
  eventType: string;
56
58
  }
57
- /** Payload for `roomUserSeq` (viewer count) events. */
59
+ /** Payload for `roomUserSeq` / `roomUser` (viewer count) events. */
58
60
  interface RoomUserSeqEvent {
59
61
  viewerCount: number;
60
62
  topViewers: TikTokUser[];
61
63
  }
62
- /** Payload for `battle` events. */
64
+ /** Payload for `battle` / `linkMicBattle` events. */
63
65
  interface BattleEvent {
64
66
  type: string;
65
67
  teams: Array<Record<string, unknown>>;
@@ -84,6 +86,60 @@ interface RoomPinEvent {
84
86
  /** User ID of the operator who pinned the message. */
85
87
  operatorUserId: string;
86
88
  }
89
+ /** Payload for `superFan` events. */
90
+ interface SuperFanEvent {
91
+ user: TikTokUser;
92
+ level: number;
93
+ displayType: string;
94
+ }
95
+ /** Payload for `superFanJoin` events. */
96
+ interface SuperFanJoinEvent {
97
+ user: TikTokUser;
98
+ displayType: string;
99
+ }
100
+ /** Payload for `superFanBox` events. */
101
+ interface SuperFanBoxEvent {
102
+ user: TikTokUser;
103
+ envelopeId: string;
104
+ diamondCount: number;
105
+ }
106
+ /** Payload for `barrage` events. */
107
+ interface BarrageEvent {
108
+ user: TikTokUser;
109
+ label: string;
110
+ displayType: string;
111
+ content: string;
112
+ }
113
+ /** Payload for `emoteChat` / `emote` events. */
114
+ interface EmoteChatEvent {
115
+ user: TikTokUser;
116
+ emoteId: string;
117
+ emoteUrl: string;
118
+ }
119
+ /** Payload for `question` / `questionNew` events. */
120
+ interface QuestionEvent {
121
+ user: TikTokUser;
122
+ questionText: string;
123
+ }
124
+ /** Payload for `control` events. */
125
+ interface ControlEvent {
126
+ action: number;
127
+ }
128
+ /** Payload for `liveIntro` events. */
129
+ interface LiveIntroEvent {
130
+ title: string;
131
+ [key: string]: unknown;
132
+ }
133
+ /** Payload for `rankUpdate` events. */
134
+ interface RankUpdateEvent {
135
+ rankType: string;
136
+ [key: string]: unknown;
137
+ }
138
+ /** Payload for `linkMic` events. */
139
+ interface LinkMicEvent {
140
+ action: string;
141
+ [key: string]: unknown;
142
+ }
87
143
  /** Payload for `caption` events from {@link TikTokCaptions}. */
88
144
  interface CaptionEvent {
89
145
  text: string;
@@ -117,6 +173,8 @@ interface ErrorEvent {
117
173
  }
118
174
  /**
119
175
  * Map of event names to their payload types for {@link TikTokLive}.
176
+ *
177
+ * Includes native TikTools events and TTLC-compatible aliases.
120
178
  */
121
179
  interface TikTokLiveEventMap {
122
180
  chat: ChatEvent;
@@ -126,16 +184,47 @@ interface TikTokLiveEventMap {
126
184
  share: SocialEvent;
127
185
  member: MemberEvent;
128
186
  subscribe: SocialEvent;
187
+ social: SocialEvent;
129
188
  roomUserSeq: RoomUserSeqEvent;
130
189
  battle: BattleEvent;
131
190
  roomPin: RoomPinEvent;
132
191
  envelope: Record<string, unknown>;
133
192
  streamEnd: Record<string, unknown>;
134
193
  roomInfo: Record<string, unknown>;
194
+ emoteChat: EmoteChatEvent;
195
+ question: QuestionEvent;
196
+ control: ControlEvent;
197
+ liveIntro: LiveIntroEvent;
198
+ rankUpdate: RankUpdateEvent;
199
+ linkMic: LinkMicEvent;
200
+ battleArmies: Record<string, unknown>;
201
+ room: Record<string, unknown>;
202
+ unknown: Record<string, unknown>;
203
+ superFan: SuperFanEvent;
204
+ superFanJoin: SuperFanJoinEvent;
205
+ superFanBox: SuperFanBoxEvent;
206
+ barrage: BarrageEvent;
207
+ /** @alias roomUserSeq */
208
+ roomUser: RoomUserSeqEvent;
209
+ /** @alias question */
210
+ questionNew: QuestionEvent;
211
+ /** @alias battle */
212
+ linkMicBattle: BattleEvent;
213
+ /** @alias battleArmies */
214
+ linkMicArmies: Record<string, unknown>;
215
+ /** @alias emoteChat */
216
+ emote: EmoteChatEvent;
135
217
  connected: ConnectedEvent;
136
218
  disconnected: DisconnectedEvent;
137
219
  error: ErrorEvent;
220
+ /** Catch-all: fires for every incoming event with full raw payload. */
138
221
  event: Record<string, unknown>;
222
+ /** rawData: fires for every event (TTLC compat). Same as `event`. */
223
+ rawData: Record<string, unknown>;
224
+ /** decodedData: fires for every event (TTLC compat). Same as `event`. */
225
+ decodedData: Record<string, unknown>;
226
+ /** websocketConnected: fires when WS connects (TTLC compat). */
227
+ websocketConnected: Record<string, unknown>;
139
228
  }
140
229
  /**
141
230
  * Map of event names to their payload types for {@link TikTokCaptions}.
@@ -177,10 +266,28 @@ interface TikTokCaptionsEventMap {
177
266
  interface TikTokLiveOptions {
178
267
  /** Your TikTool API key. Get one free at https://tik.tools */
179
268
  apiKey?: string;
269
+ /**
270
+ * Euler Stream API key — for users migrating from TikTok-Live-Connector.
271
+ * If provided and `apiKey` is not set, this is used as the API key.
272
+ * @alias apiKey
273
+ */
274
+ signApiKey?: string;
180
275
  /** Auto-reconnect on disconnect (default: true). */
181
276
  autoReconnect?: boolean;
182
277
  /** Max reconnection attempts (default: 5). */
183
278
  maxReconnectAttempts?: number;
279
+ /** @deprecated Handled server-side. Accepted for TTLC compatibility. */
280
+ processInitialData?: boolean;
281
+ /** @deprecated Handled server-side. Accepted for TTLC compatibility. */
282
+ fetchRoomInfoOnConnect?: boolean;
283
+ /** @deprecated Always enabled server-side. Accepted for TTLC compatibility. */
284
+ enableExtendedGiftInfo?: boolean;
285
+ /** @deprecated Accepted for TTLC compatibility. */
286
+ enableWebsocketUpgrade?: boolean;
287
+ /** @deprecated Accepted for TTLC compatibility. */
288
+ requestPollingIntervalMs?: number;
289
+ /** TikTok session ID for authenticated features. */
290
+ sessionId?: string;
184
291
  }
185
292
  type EventHandler$1<T> = (data: T) => void | Promise<void>;
186
293
  /**
@@ -203,12 +310,14 @@ declare class TikTokLive {
203
310
  readonly autoReconnect: boolean;
204
311
  /** Maximum reconnection attempts. */
205
312
  readonly maxReconnectAttempts: number;
206
- private _handlers;
207
- private _ws;
208
- private _connected;
209
- private _intentionalClose;
210
- private _reconnectAttempts;
211
- private _eventCount;
313
+ protected _handlers: Map<string, Set<EventHandler$1<any>>>;
314
+ protected _ws: WebSocket | null;
315
+ protected _connected: boolean;
316
+ protected _intentionalClose: boolean;
317
+ protected _reconnectAttempts: number;
318
+ protected _eventCount: number;
319
+ protected _roomId: string;
320
+ protected _roomInfo: Record<string, any> | null;
212
321
  /**
213
322
  * Create a new TikTokLive client.
214
323
  *
@@ -228,15 +337,16 @@ declare class TikTokLive {
228
337
  /**
229
338
  * Register an event handler.
230
339
  *
340
+ * Supports both native TikTools event names and TTLC-compatible aliases:
341
+ * - `roomUser` → `roomUserSeq`
342
+ * - `questionNew` → `question`
343
+ * - `linkMicBattle` → `battle`
344
+ * - `linkMicArmies` → `battleArmies`
345
+ * - `emote` → `emoteChat`
346
+ *
231
347
  * @param event - Event name (chat, gift, like, follow, etc.)
232
348
  * @param handler - Callback function
233
349
  * @returns this (for chaining)
234
- *
235
- * @example
236
- * ```typescript
237
- * client.on('chat', (event) => console.log(event.comment));
238
- * client.on('gift', (event) => console.log(event.giftName));
239
- * ```
240
350
  */
241
351
  on<K extends keyof TikTokLiveEventMap>(event: K, handler: EventHandler$1<TikTokLiveEventMap[K]>): this;
242
352
  on(event: string, handler: EventHandler$1<any>): this;
@@ -247,7 +357,7 @@ declare class TikTokLive {
247
357
  * @param handler - The handler to remove
248
358
  */
249
359
  off(event: string, handler: EventHandler$1<any>): this;
250
- private _emit;
360
+ protected _emit(event: string, data: any): void;
251
361
  /**
252
362
  * Connect to the TikTok LIVE stream.
253
363
  *
@@ -263,6 +373,19 @@ declare class TikTokLive {
263
373
  * Disconnect from the stream.
264
374
  */
265
375
  disconnect(): void;
376
+ /**
377
+ * Get current connection state (TTLC-compatible).
378
+ */
379
+ getState(): {
380
+ isConnected: boolean;
381
+ roomId: string;
382
+ roomInfo: Record<string, any> | null;
383
+ uniqueId: string;
384
+ };
385
+ /**
386
+ * Get room info (TTLC-compatible).
387
+ */
388
+ getRoomInfo(): Record<string, any> | null;
266
389
  private _maybeReconnect;
267
390
  }
268
391
 
@@ -371,4 +494,140 @@ declare class TikTokCaptions {
371
494
  disconnect(): void;
372
495
  }
373
496
 
374
- export { type BattleEvent, type CaptionEvent, type ChatEvent, type ConnectedEvent, type CreditsEvent, type DisconnectedEvent, type ErrorEvent, type GiftEvent, type LikeEvent, type MemberEvent, type RoomUserSeqEvent, type SocialEvent, TikTokCaptions, type TikTokCaptionsEventMap, type TikTokCaptionsOptions, TikTokLive, type TikTokLiveEventMap, type TikTokLiveOptions, type TikTokUser, type TranslationEvent };
497
+ /**
498
+ * TikTok-Live-Connector (TTLC) compatibility layer.
499
+ *
500
+ * Drop-in replacement for `WebcastPushConnection` from `tiktok-live-connector`.
501
+ * Users can switch to TikTools by changing a single import line:
502
+ *
503
+ * ```diff
504
+ * - const { WebcastPushConnection } = require('tiktok-live-connector');
505
+ * + const { WebcastPushConnection } = require('tiktok-live-api');
506
+ * ```
507
+ *
508
+ * All TTLC event names, constructor options, and methods are supported.
509
+ *
510
+ * @packageDocumentation
511
+ */
512
+
513
+ /**
514
+ * Control events matching TikTok-Live-Connector's ControlEvents.
515
+ */
516
+ declare const ControlEvents: {
517
+ readonly CONNECTED: "connected";
518
+ readonly DISCONNECTED: "disconnected";
519
+ readonly ERROR: "error";
520
+ readonly RAWDATA: "rawData";
521
+ readonly DECODEDDATA: "decodedData";
522
+ readonly STREAMEND: "streamEnd";
523
+ readonly WSCONNECTED: "websocketConnected";
524
+ };
525
+ /**
526
+ * Message events matching TikTok-Live-Connector's MessageEvents.
527
+ */
528
+ declare const MessageEvents: {
529
+ readonly CHAT: "chat";
530
+ readonly MEMBER: "member";
531
+ readonly GIFT: "gift";
532
+ readonly ROOMUSER: "roomUser";
533
+ readonly SOCIAL: "social";
534
+ readonly LIKE: "like";
535
+ readonly QUESTIONNEW: "questionNew";
536
+ readonly LINKMICBATTLE: "linkMicBattle";
537
+ readonly LINKMICARMIES: "linkMicArmies";
538
+ readonly LIVEINTRO: "liveIntro";
539
+ readonly EMOTE: "emote";
540
+ readonly ENVELOPE: "envelope";
541
+ readonly SUBSCRIBE: "subscribe";
542
+ readonly BARRAGE: "barrage";
543
+ readonly SUPERFAN: "superFan";
544
+ readonly SUPERFANJOIN: "superFanJoin";
545
+ readonly SUPERFANBOX: "superFanBox";
546
+ readonly ROOMPIN: "roomPin";
547
+ };
548
+ /**
549
+ * Custom events matching TikTok-Live-Connector's CustomEvents.
550
+ */
551
+ declare const CustomEvents: {
552
+ readonly FOLLOW: "follow";
553
+ readonly SHARE: "share";
554
+ };
555
+ interface WebcastPushConnectionOptions extends TikTokLiveOptions {
556
+ /** Euler Stream API key (maps to TikTools apiKey). */
557
+ signApiKey?: string;
558
+ /** @deprecated Handled server-side. Accepted for compatibility. */
559
+ processInitialData?: boolean;
560
+ /** @deprecated Handled server-side. Accepted for compatibility. */
561
+ fetchRoomInfoOnConnect?: boolean;
562
+ /** @deprecated Always enabled. Accepted for compatibility. */
563
+ enableExtendedGiftInfo?: boolean;
564
+ /** @deprecated Always true. Accepted for compatibility. */
565
+ enableWebsocketUpgrade?: boolean;
566
+ /** @deprecated Not used. Accepted for compatibility. */
567
+ enableRequestPolling?: boolean;
568
+ /** @deprecated Not used. Accepted for compatibility. */
569
+ requestPollingIntervalMs?: number;
570
+ /** TikTok session ID. */
571
+ sessionId?: string;
572
+ /** @deprecated Not used. Accepted for compatibility. */
573
+ clientParams?: Record<string, any>;
574
+ /** @deprecated Not used. Accepted for compatibility. */
575
+ requestHeaders?: Record<string, string>;
576
+ /** @deprecated Not used. Accepted for compatibility. */
577
+ websocketHeaders?: Record<string, string>;
578
+ /** @deprecated Not used. Accepted for compatibility. */
579
+ requestOptions?: Record<string, any>;
580
+ /** @deprecated Not used. Accepted for compatibility. */
581
+ websocketOptions?: Record<string, any>;
582
+ /** @deprecated Not used. Accepted for compatibility. */
583
+ signProviderOptions?: Record<string, any>;
584
+ }
585
+ /**
586
+ * Drop-in replacement for TikTok-Live-Connector's `WebcastPushConnection`.
587
+ *
588
+ * Accepts the exact same constructor signature and event names.
589
+ * Under the hood, connects to the TikTools managed WebSocket API
590
+ * for 99.9% uptime and zero maintenance.
591
+ *
592
+ * @example
593
+ * ```typescript
594
+ * // Before (TikTok-Live-Connector):
595
+ * // const { WebcastPushConnection } = require('tiktok-live-connector');
596
+ *
597
+ * // After (TikTools — one-line change):
598
+ * const { WebcastPushConnection } = require('tiktok-live-api');
599
+ *
600
+ * const connection = new WebcastPushConnection('username', {
601
+ * signApiKey: 'YOUR_TIKTOOL_API_KEY', // Get free at tik.tools
602
+ * });
603
+ *
604
+ * connection.on('chat', (data) => {
605
+ * console.log(`${data.uniqueId}: ${data.comment}`);
606
+ * });
607
+ *
608
+ * connection.connect();
609
+ * ```
610
+ */
611
+ declare class WebcastPushConnection extends TikTokLive {
612
+ constructor(uniqueId: string, options?: WebcastPushConnectionOptions);
613
+ /**
614
+ * Get current connection state — TTLC-compatible shape.
615
+ *
616
+ * Returns the same structure as TikTok-Live-Connector's `getState()`.
617
+ */
618
+ getState(): {
619
+ isConnected: boolean;
620
+ upgradedToWebsocket: boolean;
621
+ roomId: string;
622
+ roomInfo: Record<string, any> | null;
623
+ availableGifts: never[];
624
+ uniqueId: string;
625
+ };
626
+ /**
627
+ * Get available gifts — TTLC-compatible.
628
+ * Note: Gift info is included in event payloads automatically.
629
+ */
630
+ getAvailableGifts(): any[];
631
+ }
632
+
633
+ export { type BarrageEvent, type BattleEvent, type CaptionEvent, type ChatEvent, type ConnectedEvent, type ControlEvent, ControlEvents, type CreditsEvent, CustomEvents, type DisconnectedEvent, type EmoteChatEvent, type ErrorEvent, type GiftEvent, type LikeEvent, type LinkMicEvent, type LiveIntroEvent, type MemberEvent, MessageEvents, type QuestionEvent, type RankUpdateEvent, type RoomPinEvent, type RoomUserSeqEvent, type SocialEvent, type SuperFanBoxEvent, type SuperFanEvent, type SuperFanJoinEvent, TikTokCaptions, type TikTokCaptionsEventMap, type TikTokCaptionsOptions, TikTokLive, type TikTokLiveEventMap, type TikTokLiveOptions, type TikTokUser, type TranslationEvent, WebcastPushConnection, type WebcastPushConnectionOptions };
package/dist/index.js CHANGED
@@ -30,15 +30,32 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ ControlEvents: () => ControlEvents,
34
+ CustomEvents: () => CustomEvents,
35
+ MessageEvents: () => MessageEvents,
33
36
  TikTokCaptions: () => TikTokCaptions,
34
- TikTokLive: () => TikTokLive
37
+ TikTokLive: () => TikTokLive,
38
+ WebcastPushConnection: () => WebcastPushConnection
35
39
  });
36
40
  module.exports = __toCommonJS(index_exports);
37
41
 
38
42
  // src/client.ts
39
43
  var import_ws = __toESM(require("ws"));
40
44
  var WS_BASE = "wss://api.tik.tools";
41
- var VERSION = "1.0.0";
45
+ var VERSION = "2.0.0";
46
+ var EVENT_ALIASES = {
47
+ roomUserSeq: ["roomUser"],
48
+ question: ["questionNew"],
49
+ battle: ["linkMicBattle"],
50
+ battleArmies: ["linkMicArmies"],
51
+ emoteChat: ["emote"]
52
+ };
53
+ var REVERSE_ALIASES = {};
54
+ for (const [native, aliases] of Object.entries(EVENT_ALIASES)) {
55
+ for (const alias of aliases) {
56
+ REVERSE_ALIASES[alias] = native;
57
+ }
58
+ }
42
59
  var TikTokLive = class {
43
60
  /**
44
61
  * Create a new TikTokLive client.
@@ -58,8 +75,10 @@ var TikTokLive = class {
58
75
  this._intentionalClose = false;
59
76
  this._reconnectAttempts = 0;
60
77
  this._eventCount = 0;
78
+ this._roomId = "";
79
+ this._roomInfo = null;
61
80
  this.uniqueId = uniqueId.replace(/^@/, "");
62
- this.apiKey = options.apiKey || process.env.TIKTOOL_API_KEY || "";
81
+ this.apiKey = options.apiKey || options.signApiKey || process.env.TIKTOOL_API_KEY || "";
63
82
  if (!this.apiKey) {
64
83
  throw new Error("apiKey is required. Get a free key at https://tik.tools");
65
84
  }
@@ -75,10 +94,17 @@ var TikTokLive = class {
75
94
  return this._eventCount;
76
95
  }
77
96
  on(event, handler) {
78
- if (!this._handlers.has(event)) {
79
- this._handlers.set(event, /* @__PURE__ */ new Set());
97
+ const nativeEvent = REVERSE_ALIASES[event] || event;
98
+ if (!this._handlers.has(nativeEvent)) {
99
+ this._handlers.set(nativeEvent, /* @__PURE__ */ new Set());
100
+ }
101
+ this._handlers.get(nativeEvent).add(handler);
102
+ if (nativeEvent !== event) {
103
+ if (!this._handlers.has(event)) {
104
+ this._handlers.set(event, /* @__PURE__ */ new Set());
105
+ }
106
+ this._handlers.get(event).add(handler);
80
107
  }
81
- this._handlers.get(event).add(handler);
82
108
  return this;
83
109
  }
84
110
  /**
@@ -88,22 +114,47 @@ var TikTokLive = class {
88
114
  * @param handler - The handler to remove
89
115
  */
90
116
  off(event, handler) {
91
- this._handlers.get(event)?.delete(handler);
117
+ const nativeEvent = REVERSE_ALIASES[event] || event;
118
+ this._handlers.get(nativeEvent)?.delete(handler);
119
+ if (nativeEvent !== event) {
120
+ this._handlers.get(event)?.delete(handler);
121
+ }
92
122
  return this;
93
123
  }
94
124
  _emit(event, data) {
95
125
  const handlers = this._handlers.get(event);
96
- if (!handlers) return;
97
- for (const handler of handlers) {
98
- try {
99
- const result = handler(data);
100
- if (result instanceof Promise) {
101
- result.catch(
102
- (err) => console.error(`Error in '${event}' handler:`, err)
103
- );
126
+ if (handlers) {
127
+ for (const handler of handlers) {
128
+ try {
129
+ const result = handler(data);
130
+ if (result instanceof Promise) {
131
+ result.catch(
132
+ (err) => console.error(`Error in '${event}' handler:`, err)
133
+ );
134
+ }
135
+ } catch (err) {
136
+ console.error(`Error in '${event}' handler:`, err);
137
+ }
138
+ }
139
+ }
140
+ const aliases = EVENT_ALIASES[event];
141
+ if (aliases) {
142
+ for (const alias of aliases) {
143
+ const aliasHandlers = this._handlers.get(alias);
144
+ if (aliasHandlers) {
145
+ for (const handler of aliasHandlers) {
146
+ try {
147
+ const result = handler(data);
148
+ if (result instanceof Promise) {
149
+ result.catch(
150
+ (err) => console.error(`Error in '${alias}' handler:`, err)
151
+ );
152
+ }
153
+ } catch (err) {
154
+ console.error(`Error in '${alias}' handler:`, err);
155
+ }
156
+ }
104
157
  }
105
- } catch (err) {
106
- console.error(`Error in '${event}' handler:`, err);
107
158
  }
108
159
  }
109
160
  }
@@ -128,6 +179,7 @@ var TikTokLive = class {
128
179
  this._connected = true;
129
180
  this._reconnectAttempts = 0;
130
181
  this._emit("connected", { uniqueId: this.uniqueId });
182
+ this._emit("websocketConnected", { uniqueId: this.uniqueId });
131
183
  resolve();
132
184
  });
133
185
  this._ws.on("message", (raw) => {
@@ -136,14 +188,27 @@ var TikTokLive = class {
136
188
  this._eventCount++;
137
189
  const eventType = event.event || "unknown";
138
190
  const data = event.data || event;
191
+ if (eventType === "roomInfo") {
192
+ this._roomId = event.roomId || data.roomId || this._roomId;
193
+ this._roomInfo = data;
194
+ }
139
195
  this._emit("event", event);
196
+ this._emit("rawData", event);
197
+ this._emit("decodedData", event);
140
198
  this._emit(eventType, data);
199
+ if (eventType === "control" && data.action === 3) {
200
+ this._emit("streamEnd", data);
201
+ }
141
202
  } catch {
142
203
  }
143
204
  });
144
- this._ws.on("close", () => {
205
+ this._ws.on("close", (code, reason) => {
145
206
  this._connected = false;
146
- this._emit("disconnected", { uniqueId: this.uniqueId });
207
+ this._emit("disconnected", {
208
+ uniqueId: this.uniqueId,
209
+ code,
210
+ reason: reason?.toString()
211
+ });
147
212
  this._maybeReconnect();
148
213
  });
149
214
  this._ws.on("error", (err) => {
@@ -163,6 +228,23 @@ var TikTokLive = class {
163
228
  }
164
229
  this._connected = false;
165
230
  }
231
+ /**
232
+ * Get current connection state (TTLC-compatible).
233
+ */
234
+ getState() {
235
+ return {
236
+ isConnected: this._connected,
237
+ roomId: this._roomId,
238
+ roomInfo: this._roomInfo,
239
+ uniqueId: this.uniqueId
240
+ };
241
+ }
242
+ /**
243
+ * Get room info (TTLC-compatible).
244
+ */
245
+ getRoomInfo() {
246
+ return this._roomInfo;
247
+ }
166
248
  async _maybeReconnect() {
167
249
  if (this._intentionalClose || !this.autoReconnect || this._reconnectAttempts >= this.maxReconnectAttempts) {
168
250
  return;
@@ -284,8 +366,78 @@ var TikTokCaptions = class {
284
366
  this._connected = false;
285
367
  }
286
368
  };
369
+
370
+ // src/compat.ts
371
+ var ControlEvents = {
372
+ CONNECTED: "connected",
373
+ DISCONNECTED: "disconnected",
374
+ ERROR: "error",
375
+ RAWDATA: "rawData",
376
+ DECODEDDATA: "decodedData",
377
+ STREAMEND: "streamEnd",
378
+ WSCONNECTED: "websocketConnected"
379
+ };
380
+ var MessageEvents = {
381
+ CHAT: "chat",
382
+ MEMBER: "member",
383
+ GIFT: "gift",
384
+ ROOMUSER: "roomUser",
385
+ SOCIAL: "social",
386
+ LIKE: "like",
387
+ QUESTIONNEW: "questionNew",
388
+ LINKMICBATTLE: "linkMicBattle",
389
+ LINKMICARMIES: "linkMicArmies",
390
+ LIVEINTRO: "liveIntro",
391
+ EMOTE: "emote",
392
+ ENVELOPE: "envelope",
393
+ SUBSCRIBE: "subscribe",
394
+ BARRAGE: "barrage",
395
+ SUPERFAN: "superFan",
396
+ SUPERFANJOIN: "superFanJoin",
397
+ SUPERFANBOX: "superFanBox",
398
+ ROOMPIN: "roomPin"
399
+ };
400
+ var CustomEvents = {
401
+ FOLLOW: "follow",
402
+ SHARE: "share"
403
+ };
404
+ var WebcastPushConnection = class extends TikTokLive {
405
+ constructor(uniqueId, options = {}) {
406
+ const opts = {
407
+ ...options,
408
+ apiKey: options.apiKey || options.signApiKey
409
+ };
410
+ super(uniqueId, opts);
411
+ }
412
+ /**
413
+ * Get current connection state — TTLC-compatible shape.
414
+ *
415
+ * Returns the same structure as TikTok-Live-Connector's `getState()`.
416
+ */
417
+ getState() {
418
+ return {
419
+ isConnected: this._connected,
420
+ upgradedToWebsocket: this._connected,
421
+ roomId: this._roomId,
422
+ roomInfo: this._roomInfo,
423
+ availableGifts: [],
424
+ uniqueId: this.uniqueId
425
+ };
426
+ }
427
+ /**
428
+ * Get available gifts — TTLC-compatible.
429
+ * Note: Gift info is included in event payloads automatically.
430
+ */
431
+ getAvailableGifts() {
432
+ return [];
433
+ }
434
+ };
287
435
  // Annotate the CommonJS export names for ESM import in node:
288
436
  0 && (module.exports = {
437
+ ControlEvents,
438
+ CustomEvents,
439
+ MessageEvents,
289
440
  TikTokCaptions,
290
- TikTokLive
441
+ TikTokLive,
442
+ WebcastPushConnection
291
443
  });