@laplace.live/ws 6.3.7 → 7.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/browser.d.ts CHANGED
@@ -1,13 +1,5 @@
1
- import { L as Live, I as Inflates, a as LiveOptions, K as KeepLive } from './common-DWwvds2J.js';
2
- export { D as DataEvent, E as EventEvent } from './common-DWwvds2J.js';
3
-
4
- type WSOptions = LiveOptions & {
5
- address?: string;
6
- };
7
- declare class LiveWSBase extends Live {
8
- ws: WebSocket;
9
- constructor(inflates: Inflates, roomid: number, { address, ...options }?: WSOptions);
10
- }
1
+ import { K as KeepLive, b as LiveWSBase, W as WSOptions } from './ws-DVInVzNN.js';
2
+ export { D as DataEvent, E as EventEvent, a as LiveOptions } from './ws-DVInVzNN.js';
11
3
 
12
4
  declare class LiveWS extends LiveWSBase {
13
5
  constructor(roomid: number, opts?: WSOptions);
@@ -16,4 +8,4 @@ declare class KeepLiveWS extends KeepLive<typeof LiveWSBase> {
16
8
  constructor(roomid: number, opts?: WSOptions);
17
9
  }
18
10
 
19
- export { KeepLiveWS, LiveOptions, LiveWS, type WSOptions };
11
+ export { KeepLiveWS, LiveWS, WSOptions };
package/dist/browser.js CHANGED
@@ -65,12 +65,10 @@ var makeDecoder = ({ inflateAsync: inflateAsync2, brotliDecompressAsync: brotliD
65
65
  return decoder;
66
66
  };
67
67
  var encoder = (type, body = "") => {
68
- if (typeof body !== "string") {
69
- body = JSON.stringify(body);
70
- }
68
+ const encoded = typeof body === "string" ? body : JSON.stringify(body);
71
69
  const head = new Uint8Array(16);
72
70
  const headView = new DataView(head.buffer, head.byteOffset, head.byteLength);
73
- const buffer = textEncoder.encode(body);
71
+ const buffer = textEncoder.encode(encoded);
74
72
  headView.setInt32(0, buffer.length + head.length);
75
73
  headView.setInt16(4, 16);
76
74
  headView.setInt16(6, 1);
@@ -162,10 +160,7 @@ var Live = class extends EventTarget {
162
160
  });
163
161
  this.addEventListener("open", () => {
164
162
  if (authBody) {
165
- if (typeof authBody === "object") {
166
- authBody = encoder("join", authBody);
167
- }
168
- this.send(authBody);
163
+ this.send(authBody instanceof Uint8Array ? authBody : encoder("join", authBody));
169
164
  } else {
170
165
  const hi = { uid, roomid, protover, platform: "web", type: 2 };
171
166
  if (key) {
@@ -2082,7 +2077,7 @@ var inflateAsync = (d) => inflate(d);
2082
2077
  var brotliDecompressAsync = (d) => Uint8Array.from(BrotliDecode(Int8Array.from(d)));
2083
2078
  var inflates = { inflateAsync, brotliDecompressAsync };
2084
2079
 
2085
- // src/ws-client.ts
2080
+ // src/ws.ts
2086
2081
  var LiveWSBase = class extends Live {
2087
2082
  ws;
2088
2083
  constructor(inflates2, roomid, { address = "wss://broadcastlv.chat.bilibili.com/sub", ...options } = {}) {
package/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- import { L as Live, I as Inflates, a as LiveOptions, K as KeepLive } from './common-DWwvds2J.js';
2
- export { D as DataEvent, E as EventEvent } from './common-DWwvds2J.js';
1
+ import { L as Live, I as Inflates, a as LiveOptions, K as KeepLive, b as LiveWSBase, W as WSOptions } from './ws-DVInVzNN.js';
2
+ export { D as DataEvent, E as EventEvent } from './ws-DVInVzNN.js';
3
3
  import { Socket } from 'node:net';
4
- import { Agent } from 'node:http';
5
- import WS from 'ws';
6
4
 
7
5
  type TCPOptions = LiveOptions & {
8
6
  host?: string;
@@ -16,15 +14,6 @@ declare class LiveTCPBase extends Live {
16
14
  splitBuffer(): void;
17
15
  }
18
16
 
19
- type WSOptions = LiveOptions & {
20
- address?: string;
21
- agent?: Agent;
22
- };
23
- declare class LiveWSBase extends Live {
24
- ws: WS;
25
- constructor(inflates: Inflates, roomid: number, { address, agent, ...options }?: WSOptions);
26
- }
27
-
28
17
  type GET_DANMU_INFO = {
29
18
  code: number;
30
19
  message: string;
@@ -65,4 +54,4 @@ declare class KeepLiveTCP extends KeepLive<typeof LiveTCPBase> {
65
54
  constructor(roomid: number, opts?: TCPOptions);
66
55
  }
67
56
 
68
- export { KeepLiveTCP, KeepLiveWS, LiveOptions, LiveTCP, LiveWS, type TCPOptions, type WSOptions, getConf, getRoomid };
57
+ export { KeepLiveTCP, KeepLiveWS, LiveOptions, LiveTCP, LiveWS, type TCPOptions, WSOptions, getConf, getRoomid };
package/dist/index.js CHANGED
@@ -65,12 +65,10 @@ var makeDecoder = ({ inflateAsync: inflateAsync2, brotliDecompressAsync: brotliD
65
65
  return decoder;
66
66
  };
67
67
  var encoder = (type, body = "") => {
68
- if (typeof body !== "string") {
69
- body = JSON.stringify(body);
70
- }
68
+ const encoded = typeof body === "string" ? body : JSON.stringify(body);
71
69
  const head = new Uint8Array(16);
72
70
  const headView = new DataView(head.buffer, head.byteOffset, head.byteLength);
73
- const buffer = textEncoder.encode(body);
71
+ const buffer = textEncoder.encode(encoded);
74
72
  headView.setInt32(0, buffer.length + head.length);
75
73
  headView.setInt16(4, 16);
76
74
  headView.setInt16(6, 1);
@@ -162,10 +160,7 @@ var Live = class extends EventTarget {
162
160
  });
163
161
  this.addEventListener("open", () => {
164
162
  if (authBody) {
165
- if (typeof authBody === "object") {
166
- authBody = encoder("join", authBody);
167
- }
168
- this.send(authBody);
163
+ this.send(authBody instanceof Uint8Array ? authBody : encoder("join", authBody));
169
164
  } else {
170
165
  const hi = { uid, roomid, protover, platform: "web", type: 2 };
171
166
  if (key) {
@@ -341,12 +336,11 @@ var LiveTCPBase = class extends Live {
341
336
  }
342
337
  };
343
338
 
344
- // src/ws-node.ts
345
- import WS from "ws";
339
+ // src/ws.ts
346
340
  var LiveWSBase = class extends Live {
347
341
  ws;
348
- constructor(inflates2, roomid, { address = "wss://broadcastlv.chat.bilibili.com/sub", agent, ...options } = {}) {
349
- const ws = new WS(address, { agent });
342
+ constructor(inflates2, roomid, { address = "wss://broadcastlv.chat.bilibili.com/sub", ...options } = {}) {
343
+ const ws = new WebSocket(address);
350
344
  const send = (data) => {
351
345
  if (ws.readyState === 1) {
352
346
  ws.send(data);
@@ -354,10 +348,14 @@ var LiveWSBase = class extends Live {
354
348
  };
355
349
  const close = () => this.ws.close();
356
350
  super(inflates2, roomid, { send, close, ...options });
357
- ws.on("open", () => this.dispatchEvent(new Event("open")));
358
- ws.on("message", (data) => this.dispatchEvent(new DataEvent("message", data)));
359
- ws.on("close", () => this.dispatchEvent(new Event("close")));
360
- ws.on("error", () => this.dispatchEvent(new Event("_error")));
351
+ ws.binaryType = "arraybuffer";
352
+ ws.addEventListener("open", (e) => this.dispatchEvent(new Event(e.type)));
353
+ ws.addEventListener(
354
+ "message",
355
+ (e) => this.dispatchEvent(new DataEvent("message", new Uint8Array(e.data)))
356
+ );
357
+ ws.addEventListener("close", (e) => this.dispatchEvent(new Event(e.type)));
358
+ ws.addEventListener("error", () => this.dispatchEvent(new Event("_error")));
361
359
  this.ws = ws;
362
360
  }
363
361
  };
@@ -6,7 +6,7 @@ type Inflates = {
6
6
  type LiveOptions = {
7
7
  protover?: 1 | 2 | 3;
8
8
  key?: string;
9
- authBody?: any;
9
+ authBody?: Uint8Array | Record<string, unknown>;
10
10
  uid?: number;
11
11
  buvid?: string;
12
12
  };
@@ -56,4 +56,12 @@ declare class KeepLive<Base extends typeof Live> extends EventTarget {
56
56
  off<T = unknown>(type: string, listener: (event: DataEvent<T>) => void, options?: boolean | EventListenerOptions): void;
57
57
  }
58
58
 
59
- export { DataEvent as D, EventEvent as E, type Inflates as I, KeepLive as K, Live as L, type LiveOptions as a };
59
+ type WSOptions = LiveOptions & {
60
+ address?: string;
61
+ };
62
+ declare class LiveWSBase extends Live {
63
+ ws: WebSocket;
64
+ constructor(inflates: Inflates, roomid: number, { address, ...options }?: WSOptions);
65
+ }
66
+
67
+ export { DataEvent as D, EventEvent as E, type Inflates as I, KeepLive as K, Live as L, type WSOptions as W, type LiveOptions as a, LiveWSBase as b };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laplace.live/ws",
3
- "version": "6.3.7",
3
+ "version": "7.0.0",
4
4
  "description": "Bilibili Live WebSocket/TCP API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -60,14 +60,12 @@
60
60
  "provenance": true
61
61
  },
62
62
  "dependencies": {
63
- "pako": "^2.1.0",
64
- "ws": "^8.19.0"
63
+ "pako": "^2.1.0"
65
64
  },
66
65
  "devDependencies": {
67
66
  "@biomejs/biome": "^2.4.6",
68
67
  "@types/bun": "^1.3.10",
69
68
  "@types/pako": "^2.0.4",
70
- "@types/ws": "^8.18.1",
71
69
  "tsup": "^8.5.1",
72
70
  "typescript": "^5.9.3"
73
71
  }