@elysionjs/dylive-ws 0.0.0-stage → 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.mjs","names":[],"sources":["../src/protocol.ts"],"sourcesContent":["import { gunzipSync } from 'node:zlib';\n\nimport { ProtoMessage } from './protobuf';\n\nexport interface RawMessage {\n method: string;\n payload: Uint8Array;\n id?: string;\n}\n\nconst maxFrameBytes = 16 * 1024 * 1024;\nconst controlTypes = new Set(['hb', 'ack', 'pong']);\n\nexport function decodeMessages(frame: Uint8Array): RawMessage[] {\n return decodeFrame(frame).messages;\n}\n\nexport function decodeFrame(frame: Uint8Array): {\n messages: RawMessage[];\n ack?: { logId: bigint; payload: Uint8Array };\n} {\n if (frame.length > maxFrameBytes) {\n throw new Error('WebSocket message exceeds the size limit');\n }\n\n const push = new ProtoMessage(frame, [2, 6, 7, 8]);\n const type = push.string(7) ?? '';\n const payload = push.dataField(8);\n\n if (!payload?.length || controlTypes.has(type)) {\n return { messages: [] };\n }\n\n const body = expandPayload(payload, push.string(6));\n const response = new ProtoMessage(body, [1, 5, 9]);\n\n const messages = response.repeatedBytes(1).map(bytes => {\n const message = new ProtoMessage(bytes, [1, 2, 3]);\n\n return {\n method: message.string(1) ?? '',\n payload: message.dataField(2) ?? new Uint8Array(),\n id: message.uint64(3),\n };\n });\n\n if (response.uint64(9) === '1') {\n const logId = BigInt(push.uint64(2) ?? '0');\n const payload = response.dataField(5) ?? new Uint8Array();\n\n return { messages, ack: { logId, payload } };\n }\n\n return { messages };\n}\n\nexport function decodeCdpPayload(payloadData: string): RawMessage[] {\n if (payloadData.length > Math.ceil(maxFrameBytes / 3) * 4) {\n throw new Error('CDP payload exceeds the size limit');\n }\n\n const bytes = Buffer.from(payloadData, 'base64');\n\n if (bytes.toString('base64') !== payloadData) {\n throw new Error('Invalid CDP Base64 payload');\n }\n\n return decodeMessages(bytes);\n}\n\nfunction expandPayload(payload: Uint8Array, encoding = ''): Uint8Array {\n if (encoding === 'gzip' || (payload[0] === 0x1f && payload[1] === 0x8b)) {\n return gunzipSync(payload, { maxOutputLength: maxFrameBytes });\n }\n\n if (encoding && encoding !== 'identity') {\n throw new Error(`Unsupported payload encoding: ${encoding}`);\n }\n\n return payload;\n}\n"],"mappings":";;;AAUA,MAAM,gBAAgB;AACtB,MAAM,+BAAe,IAAI,IAAI;CAAC;CAAM;CAAO;AAAM,CAAC;AAElD,SAAgB,eAAe,OAAiC;CAC9D,OAAO,YAAY,KAAK,CAAC,CAAC;AAC5B;AAEA,SAAgB,YAAY,OAG1B;CACA,IAAI,MAAM,SAAS,eACjB,MAAM,IAAI,MAAM,0CAA0C;CAG5D,MAAM,OAAO,IAAI,aAAa,OAAO;EAAC;EAAG;EAAG;EAAG;CAAC,CAAC;CACjD,MAAM,OAAO,KAAK,OAAO,CAAC,KAAK;CAC/B,MAAM,UAAU,KAAK,UAAU,CAAC;CAEhC,IAAI,CAAC,SAAS,UAAU,aAAa,IAAI,IAAI,GAC3C,OAAO,EAAE,UAAU,CAAC,EAAE;CAGxB,MAAM,OAAO,cAAc,SAAS,KAAK,OAAO,CAAC,CAAC;CAClD,MAAM,WAAW,IAAI,aAAa,MAAM;EAAC;EAAG;EAAG;CAAC,CAAC;CAEjD,MAAM,WAAW,SAAS,cAAc,CAAC,CAAC,CAAC,KAAI,UAAS;EACtD,MAAM,UAAU,IAAI,aAAa,OAAO;GAAC;GAAG;GAAG;EAAC,CAAC;EAEjD,OAAO;GACL,QAAQ,QAAQ,OAAO,CAAC,KAAK;GAC7B,SAAS,QAAQ,UAAU,CAAC,qBAAK,IAAI,WAAW;GAChD,IAAI,QAAQ,OAAO,CAAC;EACtB;CACF,CAAC;CAED,IAAI,SAAS,OAAO,CAAC,MAAM,KAIzB,OAAO;EAAE;EAAU,KAAK;GAAE,OAHZ,OAAO,KAAK,OAAO,CAAC,KAAK,GAGT;GAAG,SAFjB,SAAS,UAAU,CAAC,qBAAK,IAAI,WAAW;EAEf;CAAE;CAG7C,OAAO,EAAE,SAAS;AACpB;AAEA,SAAgB,iBAAiB,aAAmC;CAClE,IAAI,YAAY,SAAS,KAAK,KAAK,gBAAgB,CAAC,IAAI,GACtD,MAAM,IAAI,MAAM,oCAAoC;CAGtD,MAAM,QAAQ,OAAO,KAAK,aAAa,QAAQ;CAE/C,IAAI,MAAM,SAAS,QAAQ,MAAM,aAC/B,MAAM,IAAI,MAAM,4BAA4B;CAG9C,OAAO,eAAe,KAAK;AAC7B;AAEA,SAAS,cAAc,SAAqB,WAAW,IAAgB;CACrE,IAAI,aAAa,UAAW,QAAQ,OAAO,MAAQ,QAAQ,OAAO,KAChE,OAAO,WAAW,SAAS,EAAE,iBAAiB,cAAc,CAAC;CAG/D,IAAI,YAAY,aAAa,YAC3B,MAAM,IAAI,MAAM,iCAAiC,UAAU;CAG7D,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,87 @@
1
1
  {
2
2
  "name": "@elysionjs/dylive-ws",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Read-only Douyin live chat decoding and Electron CDP capture.",
5
+ "homepage": "https://github.com/elysion-labs/dylive-ws#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/elysion-labs/dylive-ws/issues"
8
+ },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/elysion-labs/dylive-ws.git"
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "type": "module",
18
+ "sideEffects": false,
19
+ "exports": {
20
+ ".": {
21
+ "source": "./src/index.ts",
22
+ "types": "./dist/index.d.mts",
23
+ "default": "./dist/index.mjs"
24
+ },
25
+ "./protocol": {
26
+ "source": "./src/protocol.ts",
27
+ "types": "./dist/protocol.d.mts",
28
+ "default": "./dist/protocol.mjs"
29
+ },
30
+ "./parser": {
31
+ "source": "./src/parser.ts",
32
+ "types": "./dist/parser.d.mts",
33
+ "default": "./dist/parser.mjs"
34
+ },
35
+ "./electron": {
36
+ "source": "./src/electron.ts",
37
+ "types": "./dist/electron.d.mts",
38
+ "default": "./dist/electron.mjs"
39
+ }
40
+ },
41
+ "publishConfig": {
42
+ "access": "public",
43
+ "provenance": true
44
+ },
45
+ "scripts": {
46
+ "build": "vp pack",
47
+ "changeset": "changeset",
48
+ "check": "vp check",
49
+ "example:live": "bun examples/live.ts",
50
+ "example:parse": "bun examples/parse.ts",
51
+ "ready": "vp check && vp run typecheck && vp run test && vp run build",
52
+ "release": "changeset publish",
53
+ "test": "bun test",
54
+ "typecheck": "tsc --noEmit",
55
+ "version": "changeset version && vp install --lockfile-only && vp fmt package.json CHANGELOG.md"
56
+ },
57
+ "dependencies": {
58
+ "ws": "^8.23.0"
59
+ },
60
+ "devDependencies": {
61
+ "@byc/vp-config": "^0.1.0",
62
+ "@changesets/changelog-github": "^1.0.1",
63
+ "@changesets/cli": "^3.0.3",
64
+ "@stylistic/eslint-plugin": "^6.0.0",
65
+ "@types/bun": "^1.4.4",
66
+ "@types/ws": "^8.18.1",
67
+ "typescript": "^7.0.2",
68
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.6.0",
69
+ "vite-plus": "1.6.0"
70
+ },
71
+ "peerDependencies": {
72
+ "electron": "*"
73
+ },
74
+ "peerDependenciesMeta": {
75
+ "electron": {
76
+ "optional": true
77
+ }
78
+ },
79
+ "overrides": {
80
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.6.0"
81
+ },
82
+ "engines": {
83
+ "bun": ">=1.4.4",
84
+ "node": ">=24.0.0"
85
+ },
86
+ "packageManager": "bun@1.4.4"
87
+ }