@laplace.live/ws 6.3.1 → 6.3.2
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/package.json +1 -1
- package/src/browser.ts +6 -6
- package/src/common.ts +1 -1
- package/src/index.test.ts +2 -2
- package/src/index.ts +9 -9
- package/src/inflate/browser.ts +1 -1
- package/src/tcp.ts +10 -5
- package/src/ws.ts +17 -6
package/package.json
CHANGED
package/src/browser.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { KeepLive } from './common'
|
|
2
|
-
import { inflates } from './inflate/browser'
|
|
3
|
-
import { LiveWSBase, type WSOptions } from './ws'
|
|
1
|
+
import { KeepLive } from './common.ts'
|
|
2
|
+
import { inflates } from './inflate/browser.ts'
|
|
3
|
+
import { LiveWSBase, type WSOptions } from './ws.ts'
|
|
4
4
|
|
|
5
|
-
export type { LiveOptions } from './common'
|
|
6
|
-
export type { WSOptions } from './ws'
|
|
5
|
+
export type { LiveOptions } from './common.ts'
|
|
6
|
+
export type { WSOptions } from './ws.ts'
|
|
7
7
|
|
|
8
|
-
export { relayEvent } from './common'
|
|
8
|
+
export { relayEvent } from './common.ts'
|
|
9
9
|
|
|
10
10
|
export class LiveWS extends LiveWSBase {
|
|
11
11
|
constructor(roomid: number, opts?: WSOptions) {
|
package/src/common.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'events'
|
|
2
2
|
|
|
3
|
-
import { encoder, type Inflates, makeDecoder } from './buffer'
|
|
3
|
+
import { encoder, type Inflates, makeDecoder } from './buffer.ts'
|
|
4
4
|
|
|
5
5
|
export type LiveOptions = { protover?: 1 | 2 | 3; key?: string; authBody?: any; uid?: number; buvid?: string }
|
|
6
6
|
|
package/src/index.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test'
|
|
2
2
|
import { once } from 'events'
|
|
3
3
|
|
|
4
|
-
import { KeepLiveWS as KeepLiveWSBrowser, LiveWS as LiveWSBrowser } from './browser'
|
|
5
|
-
import { getConf, getRoomid, KeepLiveTCP, KeepLiveWS, LiveTCP, LiveWS } from './index'
|
|
4
|
+
import { KeepLiveWS as KeepLiveWSBrowser, LiveWS as LiveWSBrowser } from './browser.ts'
|
|
5
|
+
import { getConf, getRoomid, KeepLiveTCP, KeepLiveWS, LiveTCP, LiveWS } from './index.ts'
|
|
6
6
|
|
|
7
7
|
const TIMEOUT = 1000 * 25
|
|
8
8
|
const watch = (
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { KeepLive } from './common'
|
|
2
|
-
import { inflates } from './inflate/node'
|
|
3
|
-
import { LiveTCPBase, type TCPOptions } from './tcp'
|
|
4
|
-
import { LiveWSBase, type WSOptions } from './ws'
|
|
1
|
+
import { KeepLive } from './common.ts'
|
|
2
|
+
import { inflates } from './inflate/node.ts'
|
|
3
|
+
import { LiveTCPBase, type TCPOptions } from './tcp.ts'
|
|
4
|
+
import { LiveWSBase, type WSOptions } from './ws.ts'
|
|
5
5
|
|
|
6
|
-
export type { LiveOptions } from './common'
|
|
7
|
-
export type { TCPOptions } from './tcp'
|
|
8
|
-
export type { WSOptions } from './ws'
|
|
6
|
+
export type { LiveOptions } from './common.ts'
|
|
7
|
+
export type { TCPOptions } from './tcp.ts'
|
|
8
|
+
export type { WSOptions } from './ws.ts'
|
|
9
9
|
|
|
10
|
-
export { relayEvent } from './common'
|
|
11
|
-
export { getConf, getRoomid } from './extra'
|
|
10
|
+
export { relayEvent } from './common.ts'
|
|
11
|
+
export { getConf, getRoomid } from './extra.ts'
|
|
12
12
|
|
|
13
13
|
export class LiveWS extends LiveWSBase {
|
|
14
14
|
constructor(roomid: number, opts?: WSOptions) {
|
package/src/inflate/browser.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Buffer } from 'buffer'
|
|
2
2
|
import { inflate } from 'pako'
|
|
3
3
|
|
|
4
|
-
import { BrotliDecode } from './brotli'
|
|
4
|
+
import { BrotliDecode } from './brotli.ts'
|
|
5
5
|
|
|
6
6
|
const inflateAsync = (d: Buffer) => Buffer.from(inflate(d))
|
|
7
7
|
const brotliDecompressAsync = (d: Buffer) => Buffer.from(BrotliDecode(Int8Array.from(d)))
|
package/src/tcp.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import net, { Socket } from 'net'
|
|
1
|
+
import net, { type Socket } from 'net'
|
|
2
2
|
|
|
3
|
-
import { Inflates } from './buffer'
|
|
4
|
-
import { LiveOptions, Live } from './common'
|
|
3
|
+
import type { Inflates } from './buffer.ts'
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
import { Live, type LiveOptions } from './common.ts'
|
|
6
|
+
|
|
7
|
+
export type TCPOptions = LiveOptions & { host?: string; port?: number }
|
|
7
8
|
|
|
8
9
|
export class LiveTCPBase extends Live {
|
|
9
10
|
socket: Socket
|
|
10
11
|
buffer: Buffer
|
|
11
12
|
i: number
|
|
12
13
|
|
|
13
|
-
constructor(
|
|
14
|
+
constructor(
|
|
15
|
+
inflates: Inflates,
|
|
16
|
+
roomid: number,
|
|
17
|
+
{ host = 'broadcastlv.chat.bilibili.com', port = 2243, ...options }: TCPOptions = {}
|
|
18
|
+
) {
|
|
14
19
|
const socket = net.connect(port, host)
|
|
15
20
|
const send = (data: Buffer) => {
|
|
16
21
|
socket.write(data)
|
package/src/ws.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { EventEmitter } from 'events'
|
|
2
|
-
import { Agent } from 'http'
|
|
2
|
+
import type { Agent } from 'http'
|
|
3
3
|
import IsomorphicWebSocket from 'isomorphic-ws'
|
|
4
4
|
|
|
5
|
-
import { Inflates } from './buffer'
|
|
6
|
-
import { LiveOptions, Live } from './common'
|
|
5
|
+
import type { Inflates } from './buffer.ts'
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
import { Live, type LiveOptions } from './common.ts'
|
|
8
|
+
|
|
9
|
+
export type WSOptions = LiveOptions & { address?: string; agent?: Agent }
|
|
9
10
|
|
|
10
11
|
export const isNode = !!IsomorphicWebSocket.Server
|
|
11
12
|
|
|
@@ -19,7 +20,13 @@ class WebSocket extends EventEmitter {
|
|
|
19
20
|
this.ws = ws
|
|
20
21
|
|
|
21
22
|
ws.onopen = () => this.emit('open')
|
|
22
|
-
ws.onmessage = isNode
|
|
23
|
+
ws.onmessage = isNode
|
|
24
|
+
? ({ data }) => this.emit('message', data)
|
|
25
|
+
: async ({ data }) =>
|
|
26
|
+
this.emit(
|
|
27
|
+
'message',
|
|
28
|
+
inflates.Buffer.from(await new Response(data as unknown as InstanceType<typeof Blob>).arrayBuffer())
|
|
29
|
+
)
|
|
23
30
|
ws.onerror = () => this.emit('error')
|
|
24
31
|
ws.onclose = () => this.emit('close')
|
|
25
32
|
}
|
|
@@ -40,7 +47,11 @@ class WebSocket extends EventEmitter {
|
|
|
40
47
|
export class LiveWSBase extends Live {
|
|
41
48
|
ws: InstanceType<typeof WebSocket>
|
|
42
49
|
|
|
43
|
-
constructor(
|
|
50
|
+
constructor(
|
|
51
|
+
inflates: Inflates,
|
|
52
|
+
roomid: number,
|
|
53
|
+
{ address = 'wss://broadcastlv.chat.bilibili.com/sub', agent, ...options }: WSOptions = {}
|
|
54
|
+
) {
|
|
44
55
|
const ws = new WebSocket(address, inflates, { agent })
|
|
45
56
|
const send = (data: Buffer) => {
|
|
46
57
|
if (ws.readyState === 1) {
|