@laplace.live/ws 6.3.6 → 6.3.8
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/README.md +66 -257
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +15 -8
- package/dist/{common-D1XOmtU3.d.ts → common-CdO2EmGc.d.ts} +5 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +15 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,294 +1,103 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @laplace.live/ws
|
|
2
2
|
|
|
3
|
-
Bilibili
|
|
3
|
+
Bilibili Live WebSocket/TCP API. Browser support via `@laplace.live/ws/browser` (experimental).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Based on [bilibili-live-ws](https://github.com/simon300000/bilibili-live-ws).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## API
|
|
12
|
-
|
|
13
|
-
```javascript
|
|
14
|
-
const { LiveWS, LiveTCP, KeepLiveWS, KeepLiveTCP } = require('bilibili-live-ws')
|
|
15
|
-
const live = new LiveWS(roomid)
|
|
16
|
-
// 或
|
|
17
|
-
const live = new LiveTCP(roomid)
|
|
9
|
+
```bash
|
|
10
|
+
npm install @laplace.live/ws
|
|
18
11
|
```
|
|
19
12
|
|
|
20
|
-
|
|
13
|
+
## Usage
|
|
21
14
|
|
|
22
15
|
```javascript
|
|
23
|
-
|
|
16
|
+
import { LiveWS, LiveTCP, KeepLiveWS, KeepLiveTCP } from "@laplace.live/ws";
|
|
24
17
|
|
|
25
|
-
live
|
|
26
|
-
// Connection is established
|
|
27
|
-
live.on('live', () => {
|
|
28
|
-
live.on('heartbeat', console.log)
|
|
29
|
-
// 74185
|
|
30
|
-
})
|
|
31
|
-
```
|
|
18
|
+
const live = new LiveWS(14275133);
|
|
32
19
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
live.on('open', () => console.log('Connection is established'))
|
|
39
|
-
// Connection is established
|
|
40
|
-
live.on('live', () => {
|
|
41
|
-
live.on('heartbeat', console.log)
|
|
42
|
-
// 13928
|
|
43
|
-
})
|
|
20
|
+
live.on("open", () => console.log("Connection established"));
|
|
21
|
+
live.on("live", () => {
|
|
22
|
+
live.on("heartbeat", console.log);
|
|
23
|
+
});
|
|
44
24
|
```
|
|
45
25
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
## Class: LiveWS / LiveTCP / KeepLiveWS / KeepLiveTCP
|
|
49
|
-
|
|
50
|
-
(Keep)LiveWS 和 (Keep)LiveTCP 的大部分API基本上一样, 区别在本文末尾有注明
|
|
51
|
-
|
|
52
|
-
### new LiveWS(roomid [, { address, protover, key, authBody, uid, buvid }])
|
|
53
|
-
|
|
54
|
-
### new LiveTCP(roomid [, { host, port, protover, key, authBody, uid, buvid }])
|
|
55
|
-
|
|
56
|
-
- `roomid` 房间号
|
|
57
|
-
|
|
58
|
-
比如 https://live.bilibili.com/14327465 中的 `14327465`
|
|
59
|
-
|
|
60
|
-
- `address` 可选, WebSocket连接的地址
|
|
61
|
-
|
|
62
|
-
默认 `'wss://broadcastlv.chat.bilibili.com/sub'`
|
|
63
|
-
|
|
64
|
-
- `host` 可选, TCP连接的地址
|
|
65
|
-
|
|
66
|
-
默认 `'broadcastlv.chat.bilibili.com'`
|
|
67
|
-
|
|
68
|
-
- `port` 可选, TCP连接的端口
|
|
69
|
-
|
|
70
|
-
默认 `2243`
|
|
71
|
-
|
|
72
|
-
- `protover` 可选 (1, 2, 3)
|
|
73
|
-
|
|
74
|
-
默认 `2`
|
|
75
|
-
|
|
76
|
-
* 1 (见 [#17](https://github.com/simon300000/bilibili-live-ws/issues/17))
|
|
77
|
-
* 2 (zlib.inflate)
|
|
78
|
-
* 3 (brotliDecompress)
|
|
79
|
-
|
|
80
|
-
- `uid` 可选, WS握手的 uid [#397](https://github.com/simon300000/bilibili-live-ws/issues/397)
|
|
81
|
-
|
|
82
|
-
- `key` 可选, WS握手的 Token [#397](https://github.com/simon300000/bilibili-live-ws/issues/397)
|
|
83
|
-
|
|
84
|
-
- `buvid` 可选, WS握手的 Token [#397](https://github.com/simon300000/bilibili-live-ws/issues/397)
|
|
85
|
-
|
|
86
|
-
- `authBody` 可选, 可以和 <https://open-live.bilibili.com/document/> 配合使用, 会覆盖掉 `protover` `roomid` `key` `uid` `buvid`. 如果是 `object` 会按照握手包编码,如果是 `string`/`Buffer` 会直接发送
|
|
87
|
-
|
|
88
|
-
#### live.on('open')
|
|
89
|
-
|
|
90
|
-
WebSocket连接上了
|
|
91
|
-
|
|
92
|
-
#### live.on('live')
|
|
93
|
-
|
|
94
|
-
成功登入房间
|
|
95
|
-
|
|
96
|
-
#### live.on('heartbeat', (online) => ...)
|
|
97
|
-
|
|
98
|
-
收到服务器心跳包,会在30秒之后自动发送心跳包。
|
|
99
|
-
|
|
100
|
-
- `online` 当前人气值
|
|
101
|
-
|
|
102
|
-
#### live.on('msg', (data) => ...)
|
|
103
|
-
|
|
104
|
-
- `data` 收到信息/弹幕/广播等
|
|
105
|
-
|
|
106
|
-
data的例子: (我simon3000送了一个辣条)
|
|
107
|
-
|
|
108
|
-
```javascript
|
|
109
|
-
{
|
|
110
|
-
cmd: 'SEND_GIFT',
|
|
111
|
-
data: {
|
|
112
|
-
giftName: '辣条',
|
|
113
|
-
num: 1,
|
|
114
|
-
uname: 'simon3000',
|
|
115
|
-
face: 'http://i1.hdslb.com/bfs/face/c26b9f670b10599ad105e2a7fea4b5f21c0f0bcf.jpg',
|
|
116
|
-
guard_level: 0,
|
|
117
|
-
rcost: 2318827,
|
|
118
|
-
uid: 3499295,
|
|
119
|
-
top_list: [],
|
|
120
|
-
timestamp: 1555690631,
|
|
121
|
-
giftId: 1,
|
|
122
|
-
giftType: 0,
|
|
123
|
-
action: '喂食',
|
|
124
|
-
super: 0,
|
|
125
|
-
super_gift_num: 0,
|
|
126
|
-
price: 100,
|
|
127
|
-
rnd: '1555690616',
|
|
128
|
-
newMedal: 0,
|
|
129
|
-
newTitle: 0,
|
|
130
|
-
medal: [],
|
|
131
|
-
title: '',
|
|
132
|
-
beatId: '0',
|
|
133
|
-
biz_source: 'live',
|
|
134
|
-
metadata: '',
|
|
135
|
-
remain: 6,
|
|
136
|
-
gold: 0,
|
|
137
|
-
silver: 0,
|
|
138
|
-
eventScore: 0,
|
|
139
|
-
eventNum: 0,
|
|
140
|
-
smalltv_msg: [],
|
|
141
|
-
specialGift: null,
|
|
142
|
-
notice_msg: [],
|
|
143
|
-
capsule: null,
|
|
144
|
-
addFollow: 0,
|
|
145
|
-
effect_block: 1,
|
|
146
|
-
coin_type: 'silver',
|
|
147
|
-
total_coin: 100,
|
|
148
|
-
effect: 0,
|
|
149
|
-
tag_image: '',
|
|
150
|
-
user_count: 0
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
#### live.on(cmd, (data) => ...)
|
|
156
|
-
|
|
157
|
-
用法如上,只不过只会收到特定cmd的Event。
|
|
158
|
-
|
|
159
|
-
比如 `live.on('DANMU_MSG')` 只会收到弹幕Event,一个弹幕Event的Data例子如下: (我simon3000发了个`233`)
|
|
160
|
-
|
|
161
|
-
```javascript
|
|
162
|
-
{
|
|
163
|
-
cmd: 'DANMU_MSG',
|
|
164
|
-
info: [
|
|
165
|
-
[0, 1, 25, 16777215, 1555692037, 1555690616, 0, 'c5c630b1', 0, 0, 0],
|
|
166
|
-
'233',
|
|
167
|
-
[3499295, 'simon3000', 0, 0, 0, 10000, 1, ''],
|
|
168
|
-
[5, '財布', '神楽めあOfficial', 12235923, 5805790, ''],
|
|
169
|
-
[11, 0, 6406234, '>50000'],
|
|
170
|
-
['title-58-1', 'title-58-1'],
|
|
171
|
-
0,
|
|
172
|
-
0,
|
|
173
|
-
null,
|
|
174
|
-
{ ts: 1555692037, ct: '2277D56A' }
|
|
175
|
-
]
|
|
176
|
-
}
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
#### live.on('close')
|
|
182
|
-
|
|
183
|
-
连接关闭事件
|
|
184
|
-
|
|
185
|
-
#### live.on('error', (e) => ...)
|
|
186
|
-
|
|
187
|
-
连接 error 事件,连接同时也会关闭
|
|
188
|
-
|
|
189
|
-
#### live.heartbeat()
|
|
190
|
-
|
|
191
|
-
无视30秒时间,直接发送一个心跳包。
|
|
26
|
+
## API
|
|
192
27
|
|
|
193
|
-
|
|
28
|
+
### `new LiveWS(roomid [, options])` / `new LiveTCP(roomid [, options])`
|
|
194
29
|
|
|
195
|
-
|
|
30
|
+
| Option | Description | Default |
|
|
31
|
+
| ---------- | ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
|
|
32
|
+
| `address` | WebSocket URL (LiveWS only) | `wss://broadcastlv.chat.bilibili.com/sub` |
|
|
33
|
+
| `host` | TCP host (LiveTCP only) | `broadcastlv.chat.bilibili.com` |
|
|
34
|
+
| `port` | TCP port (LiveTCP only) | `2243` |
|
|
35
|
+
| `protover` | Protocol version: `1`, `2` (zlib), `3` (brotli) | `2` |
|
|
36
|
+
| `uid` | User ID for handshake | |
|
|
37
|
+
| `key` | Auth token for handshake | |
|
|
38
|
+
| `buvid` | Browser unique ID for handshake | |
|
|
39
|
+
| `authBody` | Custom auth body. Overrides `protover`, `roomid`, `key`, `uid`, `buvid`. Accepts `object`, `string`, or `Buffer`. | |
|
|
196
40
|
|
|
197
|
-
|
|
41
|
+
### Events
|
|
198
42
|
|
|
199
|
-
|
|
43
|
+
| Event | Callback | Description |
|
|
44
|
+
| ----------- | -------------------------- | ---------------------------------------------------------- |
|
|
45
|
+
| `open` | `() => void` | Connection opened |
|
|
46
|
+
| `live` | `() => void` | Successfully joined the room |
|
|
47
|
+
| `heartbeat` | `(online: number) => void` | Server heartbeat received. Auto-sends heartbeat every 30s. |
|
|
48
|
+
| `msg` | `(data: object) => void` | Any message (danmaku, gift, broadcast, etc.) |
|
|
49
|
+
| `<cmd>` | `(data: object) => void` | Specific command, e.g. `DANMU_MSG`, `SEND_GIFT` |
|
|
50
|
+
| `close` | `() => void` | Connection closed |
|
|
51
|
+
| `error` | `(error: Error) => void` | Connection error (also closes the connection) |
|
|
52
|
+
| `message` | `(buffer: Buffer) => void` | Raw buffer (advanced use) |
|
|
200
53
|
|
|
201
|
-
|
|
54
|
+
### Methods
|
|
202
55
|
|
|
203
|
-
|
|
56
|
+
| Method | Description |
|
|
57
|
+
| ------------------- | ------------------------------------------------------------------- |
|
|
58
|
+
| `live.heartbeat()` | Send a heartbeat immediately |
|
|
59
|
+
| `live.close()` | Close the connection |
|
|
60
|
+
| `live.getOnline()` | Send heartbeat and return `Promise<number>` with current popularity |
|
|
61
|
+
| `live.send(buffer)` | Send raw data |
|
|
204
62
|
|
|
205
|
-
|
|
63
|
+
### `KeepLiveWS` / `KeepLiveTCP`
|
|
206
64
|
|
|
207
|
-
|
|
65
|
+
Same API as `LiveWS` / `LiveTCP` with automatic reconnection:
|
|
208
66
|
|
|
209
|
-
|
|
67
|
+
- Reconnects automatically after disconnection (default 100ms delay, configurable via `live.interval`)
|
|
68
|
+
- `live.connection` exposes the underlying `LiveWS` / `LiveTCP` instance
|
|
69
|
+
- `live.closed` indicates whether `close()` was called manually
|
|
70
|
+
- `error` / `close` events do not mean the connection is permanently closed; call `live.close()` to stop reconnecting
|
|
210
71
|
|
|
211
|
-
### getConf(roomid)
|
|
72
|
+
### `getConf(roomid)`
|
|
212
73
|
|
|
213
|
-
|
|
74
|
+
Resolve CDN host, WebSocket address, and auth key for a room.
|
|
214
75
|
|
|
215
76
|
```typescript
|
|
216
|
-
|
|
77
|
+
import { getConf } from "@laplace.live/ws";
|
|
217
78
|
|
|
218
|
-
getConf(roomid)
|
|
219
|
-
// Return
|
|
220
|
-
Promise<{
|
|
221
|
-
key: string;
|
|
222
|
-
host: string;
|
|
223
|
-
address: string;
|
|
224
|
-
}>
|
|
79
|
+
const { key, host, address } = await getConf(roomid);
|
|
225
80
|
```
|
|
226
81
|
|
|
227
|
-
### getRoomid(short)
|
|
82
|
+
### `getRoomid(short)`
|
|
228
83
|
|
|
229
|
-
|
|
84
|
+
Resolve a short room ID to a full room ID.
|
|
230
85
|
|
|
231
86
|
```typescript
|
|
232
|
-
|
|
87
|
+
import { getRoomid } from "@laplace.live/ws";
|
|
233
88
|
|
|
234
|
-
getRoomid(255)
|
|
235
|
-
// Return Promise<number>: 48743
|
|
89
|
+
const roomid = await getRoomid(255); // 48743
|
|
236
90
|
```
|
|
237
91
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
### Keep和无Keep的区别
|
|
241
|
-
|
|
242
|
-
KeepLiveWS 和 KeepLiveTCP 有断线重新连接的功能
|
|
243
|
-
|
|
244
|
-
#### new KeepLiveWS(roomid [, { address, protover, key }])
|
|
245
|
-
|
|
246
|
-
#### new KeepLiveTCP(roomid [, { host, port, protover, key }])
|
|
247
|
-
|
|
248
|
-
所有上方的API都是一样的, 只不过会有以下微小的区别
|
|
249
|
-
|
|
250
|
-
* 收到error或者close事件的时候并不代表连接关闭, 必须要手动调用`live.close()`来关闭连接
|
|
251
|
-
* 内部的连接对象(`LiveWS`/`LiveTCP`)在`live.connection`中
|
|
252
|
-
* 内部的连接关闭了之后, 如果不是因为`live.close()`关闭, 会在100毫秒之后自动打开一个新的连接。
|
|
253
|
-
* 这个100毫秒可以通过改变`live.interval`来设置
|
|
254
|
-
* 内部的boolean, `live.closed`, 用于判断是否是因为`live.close()`关闭。
|
|
255
|
-
|
|
256
|
-
<hr>
|
|
257
|
-
|
|
258
|
-
### LiveWS 和 LiveTCP 的区别
|
|
259
|
-
|
|
260
|
-
#### LiveWS.ws
|
|
261
|
-
|
|
262
|
-
LiveWS 内部 WebSocket 对象,需要时可以直接操作
|
|
263
|
-
|
|
264
|
-
Doc: <https://github.com/websockets/ws/blob/master/doc/ws.md#class-websocket>
|
|
265
|
-
|
|
266
|
-
#### LiveTCP.socket
|
|
267
|
-
|
|
268
|
-
LiveTCP 内部 TCP Socket 对象,需要时可以直接操作
|
|
269
|
-
|
|
270
|
-
Doc: <https://nodejs.org/api/net.html#net_class_net_socket>
|
|
271
|
-
|
|
272
|
-
#### LiveTCP.buffer
|
|
273
|
-
|
|
274
|
-
LiveTCP内部TCP流的Buffer缓冲区,有不完整的包
|
|
275
|
-
|
|
276
|
-
#### LiveTCP.splitBuffer()
|
|
277
|
-
|
|
278
|
-
处理LiveTCP内部TCP流的Buffer缓冲区,把其中完整的包交给decoder处理
|
|
279
|
-
|
|
280
|
-
### BenchMark 简单对比
|
|
281
|
-
|
|
282
|
-
在连接了640个直播间后过了一分钟左右(@2.0.0)
|
|
283
|
-
|
|
284
|
-
| | LiveWS (wss) | LiveWS (ws) | LiveTCP |
|
|
285
|
-
| -------- | ------------ | ----------- | ------- |
|
|
286
|
-
| 内存占用 | 63 MB | 26 MB | 18 MB |
|
|
287
|
-
|
|
288
|
-
<hr>
|
|
92
|
+
### Internals
|
|
289
93
|
|
|
290
|
-
|
|
94
|
+
| Property | Description |
|
|
95
|
+
| ----------------------- | --------------------------------------------------------------------------------- |
|
|
96
|
+
| `LiveWS.ws` | Underlying [WebSocket](https://github.com/websockets/ws) instance |
|
|
97
|
+
| `LiveTCP.socket` | Underlying [net.Socket](https://nodejs.org/api/net.html#class-netsocket) instance |
|
|
98
|
+
| `LiveTCP.buffer` | Internal TCP stream buffer |
|
|
99
|
+
| `LiveTCP.splitBuffer()` | Process buffered TCP data into complete packets |
|
|
291
100
|
|
|
292
|
-
|
|
101
|
+
## License
|
|
293
102
|
|
|
294
|
-
|
|
103
|
+
MIT
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as Live, I as Inflates, a as LiveOptions, K as KeepLive } from './common-
|
|
2
|
-
export { D as DataEvent, E as EventEvent } from './common-
|
|
1
|
+
import { L as Live, I as Inflates, a as LiveOptions, K as KeepLive } from './common-CdO2EmGc.js';
|
|
2
|
+
export { D as DataEvent, E as EventEvent } from './common-CdO2EmGc.js';
|
|
3
3
|
|
|
4
4
|
type WSOptions = LiveOptions & {
|
|
5
5
|
address?: string;
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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) {
|
|
@@ -200,6 +195,12 @@ var Live = class extends EventTarget {
|
|
|
200
195
|
(resolve) => this.addEventListener("heartbeat", (e) => resolve(e.data), { once: true })
|
|
201
196
|
);
|
|
202
197
|
}
|
|
198
|
+
on(type, listener, options) {
|
|
199
|
+
this.addEventListener(type, listener, options);
|
|
200
|
+
}
|
|
201
|
+
off(type, listener, options) {
|
|
202
|
+
this.removeEventListener(type, listener, options);
|
|
203
|
+
}
|
|
203
204
|
};
|
|
204
205
|
var KeepLive = class extends EventTarget {
|
|
205
206
|
params;
|
|
@@ -279,6 +280,12 @@ var KeepLive = class extends EventTarget {
|
|
|
279
280
|
send(data) {
|
|
280
281
|
return this.connection.send(data);
|
|
281
282
|
}
|
|
283
|
+
on(type, listener, options) {
|
|
284
|
+
this.addEventListener(type, listener, options);
|
|
285
|
+
}
|
|
286
|
+
off(type, listener, options) {
|
|
287
|
+
this.removeEventListener(type, listener, options);
|
|
288
|
+
}
|
|
282
289
|
};
|
|
283
290
|
|
|
284
291
|
// src/inflate/browser.ts
|
|
@@ -6,7 +6,7 @@ type Inflates = {
|
|
|
6
6
|
type LiveOptions = {
|
|
7
7
|
protover?: 1 | 2 | 3;
|
|
8
8
|
key?: string;
|
|
9
|
-
authBody?:
|
|
9
|
+
authBody?: Uint8Array | Record<string, unknown>;
|
|
10
10
|
uid?: number;
|
|
11
11
|
buvid?: string;
|
|
12
12
|
};
|
|
@@ -33,6 +33,8 @@ declare class Live extends EventTarget {
|
|
|
33
33
|
dispatchEvent(event: Event): boolean;
|
|
34
34
|
heartbeat(): void;
|
|
35
35
|
getOnline(): Promise<number>;
|
|
36
|
+
on<T = unknown>(type: string, listener: (event: DataEvent<T>) => void, options?: boolean | AddEventListenerOptions): void;
|
|
37
|
+
off<T = unknown>(type: string, listener: (event: DataEvent<T>) => void, options?: boolean | EventListenerOptions): void;
|
|
36
38
|
}
|
|
37
39
|
declare class KeepLive<Base extends typeof Live> extends EventTarget {
|
|
38
40
|
params: ConstructorParameters<Base>;
|
|
@@ -50,6 +52,8 @@ declare class KeepLive<Base extends typeof Live> extends EventTarget {
|
|
|
50
52
|
heartbeat(): void;
|
|
51
53
|
getOnline(): Promise<number>;
|
|
52
54
|
send(data: Uint8Array): void;
|
|
55
|
+
on<T = unknown>(type: string, listener: (event: DataEvent<T>) => void, options?: boolean | AddEventListenerOptions): void;
|
|
56
|
+
off<T = unknown>(type: string, listener: (event: DataEvent<T>) => void, options?: boolean | EventListenerOptions): void;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
export { DataEvent as D, EventEvent as E, type Inflates as I, KeepLive as K, Live as L, type LiveOptions as a };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as Live, I as Inflates, a as LiveOptions, K as KeepLive } from './common-
|
|
2
|
-
export { D as DataEvent, E as EventEvent } from './common-
|
|
1
|
+
import { L as Live, I as Inflates, a as LiveOptions, K as KeepLive } from './common-CdO2EmGc.js';
|
|
2
|
+
export { D as DataEvent, E as EventEvent } from './common-CdO2EmGc.js';
|
|
3
3
|
import { Socket } from 'node:net';
|
|
4
4
|
import { Agent } from 'node:http';
|
|
5
5
|
import WS from 'ws';
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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) {
|
|
@@ -200,6 +195,12 @@ var Live = class extends EventTarget {
|
|
|
200
195
|
(resolve) => this.addEventListener("heartbeat", (e) => resolve(e.data), { once: true })
|
|
201
196
|
);
|
|
202
197
|
}
|
|
198
|
+
on(type, listener, options) {
|
|
199
|
+
this.addEventListener(type, listener, options);
|
|
200
|
+
}
|
|
201
|
+
off(type, listener, options) {
|
|
202
|
+
this.removeEventListener(type, listener, options);
|
|
203
|
+
}
|
|
203
204
|
};
|
|
204
205
|
var KeepLive = class extends EventTarget {
|
|
205
206
|
params;
|
|
@@ -279,6 +280,12 @@ var KeepLive = class extends EventTarget {
|
|
|
279
280
|
send(data) {
|
|
280
281
|
return this.connection.send(data);
|
|
281
282
|
}
|
|
283
|
+
on(type, listener, options) {
|
|
284
|
+
this.addEventListener(type, listener, options);
|
|
285
|
+
}
|
|
286
|
+
off(type, listener, options) {
|
|
287
|
+
this.removeEventListener(type, listener, options);
|
|
288
|
+
}
|
|
282
289
|
};
|
|
283
290
|
|
|
284
291
|
// src/inflate/node.ts
|