{"id":13431539,"url":"https://github.com/simon300000/bilibili-live-ws","last_synced_at":"2026-02-15T01:37:49.648Z","repository":{"id":38308087,"uuid":"182231865","full_name":"simon300000/bilibili-live-ws","owner":"simon300000","description":"Bilibili live WebSocket/tcp API","archived":false,"fork":false,"pushed_at":"2023-09-13T20:57:40.000Z","size":499,"stargazers_count":321,"open_issues_count":17,"forks_count":32,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-10-19T08:43:57.853Z","etag":null,"topics":["bilibili","bilibili-api","bilibili-live","bilibili-live-ws","bilibili-websocket-api","tcp","websocket"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simon300000.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-04-19T08:36:15.000Z","updated_at":"2025-10-18T22:32:48.000Z","dependencies_parsed_at":"2024-02-26T19:57:53.273Z","dependency_job_id":null,"html_url":"https://github.com/simon300000/bilibili-live-ws","commit_stats":{"total_commits":157,"total_committers":6,"mean_commits":"26.166666666666668","dds":0.4394904458598726,"last_synced_commit":"856c064a8d0afa1d2c42518a6ce8f9440711783d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/simon300000/bilibili-live-ws","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon300000%2Fbilibili-live-ws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon300000%2Fbilibili-live-ws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon300000%2Fbilibili-live-ws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon300000%2Fbilibili-live-ws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simon300000","download_url":"https://codeload.github.com/simon300000/bilibili-live-ws/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon300000%2Fbilibili-live-ws/sbom","scorecard":{"id":824592,"data":{"date":"2025-08-11","repo":{"name":"github.com/simon300000/bilibili-live-ws","commit":"cfc05e027ef468862b137a0c1c3fdb85c90e1043"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.7,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":1,"reason":"Found 1/10 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/simon300000/bilibili-live-ws/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:46: update your workflow using https://app.stepsecurity.io/secureworkflow/simon300000/bilibili-live-ws/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:57: update your workflow using https://app.stepsecurity.io/secureworkflow/simon300000/bilibili-live-ws/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:71: update your workflow using https://app.stepsecurity.io/secureworkflow/simon300000/bilibili-live-ws/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/simon300000/bilibili-live-ws/nodejs.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/simon300000/bilibili-live-ws/nodejs.yml/master?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/nodejs.yml:23","Info:   0 out of   6 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:28","Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:29","Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1","Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/simon300000/.github/SECURITY.md:1","Info: Found linked content: github.com/simon300000/.github/SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/simon300000/.github/SECURITY.md:1","Info: Found text in security policy: github.com/simon300000/.github/SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":7,"reason":"SAST tool detected but not run on all commits","details":["Info: SAST configuration detected: CodeQL","Warn: 0 commits out of 21 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"10 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-23T16:23:24.201Z","repository_id":38308087,"created_at":"2025-08-23T16:23:24.201Z","updated_at":"2025-08-23T16:23:24.201Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29464470,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-15T01:01:38.065Z","status":"ssl_error","status_checked_at":"2026-02-15T01:01:23.809Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bilibili","bilibili-api","bilibili-live","bilibili-live-ws","bilibili-websocket-api","tcp","websocket"],"created_at":"2024-07-31T02:01:03.910Z","updated_at":"2026-02-15T01:37:49.632Z","avatar_url":"https://github.com/simon300000.png","language":"TypeScript","funding_links":[],"categories":["开发"],"sub_categories":["直播脚本"],"readme":"# bilibili-live-ws [![npm](https://img.shields.io/npm/v/bilibili-live-ws.svg)](https://www.npmjs.com/package/bilibili-live-ws) ![Node CI](https://github.com/simon300000/bilibili-live-ws/workflows/Node%20CI/badge.svg)\n\nBilibili 直播 WebSocket/TCP API\n\nLiveWS/KeepLiveWS 支持浏览器 *(实验性)*\n\n应该支持 bilibili直播开放平台 \u003chttps://open-live.bilibili.com\u003e\n\n注：如果在浏览器环境遇到问题，可以尝试手动指定引入 `bilibili-live-ws/browser`\n\n## API\n\n```javascript\nconst { LiveWS, LiveTCP, KeepLiveWS, KeepLiveTCP } = require('bilibili-live-ws')\nconst live = new LiveWS(roomid)\n// 或\nconst live = new LiveTCP(roomid)\n```\n\n举个栗子:\n\n```javascript\nconst live = new LiveWS(14275133)\n\nlive.on('open', () =\u003e console.log('Connection is established'))\n// Connection is established\nlive.on('live', () =\u003e {\n  live.on('heartbeat', console.log)\n  // 74185\n})\n```\n\n或者用TCP (新功能):\n\n```javascript\nconst live = new LiveTCP(26283)\n\nlive.on('open', () =\u003e console.log('Connection is established'))\n// Connection is established\nlive.on('live', () =\u003e {\n  live.on('heartbeat', console.log)\n  // 13928\n})\n```\n\n\u003e 晚上做梦梦到一个白胡子的老爷爷和我说TCP更节约内存哦！\n\n## Class: LiveWS / LiveTCP / KeepLiveWS / KeepLiveTCP\n\n(Keep)LiveWS 和 (Keep)LiveTCP 的大部分API基本上一样, 区别在本文末尾有注明\n\n### new LiveWS(roomid [, { address, protover, key, authBody, uid, buvid }])\n\n### new LiveTCP(roomid [, { host, port, protover, key, authBody, uid, buvid }])\n\n- `roomid` 房间号\n\n  比如 https://live.bilibili.com/14327465 中的 `14327465`\n  \n- `address` 可选, WebSocket连接的地址\n\n  默认 `'wss://broadcastlv.chat.bilibili.com/sub'`\n\n- `host` 可选, TCP连接的地址\n\n  默认 `'broadcastlv.chat.bilibili.com'`\n\n- `port` 可选, TCP连接的端口\n\n  默认 `2243`\n  \n- `protover` 可选 (1, 2, 3)\n\n  默认 `2`\n  \n  * 1 (见 [#17](https://github.com/simon300000/bilibili-live-ws/issues/17))\n  * 2 (zlib.inflate)\n  * 3 (brotliDecompress)\n  \n- `uid` 可选, WS握手的 uid [#397](https://github.com/simon300000/bilibili-live-ws/issues/397)\n\n- `key` 可选, WS握手的 Token [#397](https://github.com/simon300000/bilibili-live-ws/issues/397)\n\n- `buvid` 可选, WS握手的 Token [#397](https://github.com/simon300000/bilibili-live-ws/issues/397)\n\n- `authBody` 可选, 可以和 \u003chttps://open-live.bilibili.com/document/\u003e 配合使用, 会覆盖掉 `protover` `roomid` `key` `uid` `buvid`. 如果是 `object` 会按照握手包编码，如果是 `string`/`Buffer` 会直接发送\n\n#### live.on('open')\n\nWebSocket连接上了\n\n#### live.on('live')\n\n成功登入房间\n\n#### live.on('heartbeat', (online) =\u003e ...)\n\n收到服务器心跳包，会在30秒之后自动发送心跳包。\n\n- `online` 当前人气值\n\n#### live.on('msg', (data) =\u003e ...)\n\n- `data` 收到信息/弹幕/广播等\n\n  data的例子: (我simon3000送了一个辣条)\n\n  ```javascript\n  {\n    cmd: 'SEND_GIFT',\n    data: {\n      giftName: '辣条',\n      num: 1,\n      uname: 'simon3000',\n      face: 'http://i1.hdslb.com/bfs/face/c26b9f670b10599ad105e2a7fea4b5f21c0f0bcf.jpg',\n      guard_level: 0,\n      rcost: 2318827,\n      uid: 3499295,\n      top_list: [],\n      timestamp: 1555690631,\n      giftId: 1,\n      giftType: 0,\n      action: '喂食',\n      super: 0,\n      super_gift_num: 0,\n      price: 100,\n      rnd: '1555690616',\n      newMedal: 0,\n      newTitle: 0,\n      medal: [],\n      title: '',\n      beatId: '0',\n      biz_source: 'live',\n      metadata: '',\n      remain: 6,\n      gold: 0,\n      silver: 0,\n      eventScore: 0,\n      eventNum: 0,\n      smalltv_msg: [],\n      specialGift: null,\n      notice_msg: [],\n      capsule: null,\n      addFollow: 0,\n      effect_block: 1,\n      coin_type: 'silver',\n      total_coin: 100,\n      effect: 0,\n      tag_image: '',\n      user_count: 0\n    }\n  }\n  ```\n\n#### live.on(cmd, (data) =\u003e ...)\n\n用法如上，只不过只会收到特定cmd的Event。\n\n比如 `live.on('DANMU_MSG')` 只会收到弹幕Event，一个弹幕Event的Data例子如下: (我simon3000发了个`233`)\n\n```javascript\n{\n  cmd: 'DANMU_MSG',\n  info: [\n    [0, 1, 25, 16777215, 1555692037, 1555690616, 0, 'c5c630b1', 0, 0, 0],\n    '233',\n    [3499295, 'simon3000', 0, 0, 0, 10000, 1, ''],\n    [5, '財布', '神楽めあOfficial', 12235923, 5805790, ''],\n    [11, 0, 6406234, '\u003e50000'],\n    ['title-58-1', 'title-58-1'],\n    0,\n    0,\n    null,\n    { ts: 1555692037, ct: '2277D56A' }\n  ]\n}\n```\n\n\n\n#### live.on('close')\n\n连接关闭事件\n\n#### live.on('error', (e) =\u003e ...)\n\n连接 error 事件，连接同时也会关闭\n\n#### live.heartbeat()\n\n无视30秒时间，直接发送一个心跳包。\n\n如果连接正常，会收到来自服务器的心跳包，也就是 `live.on('heartbeat')`，可以用于更新人气值。\n\n#### live.close()\n\n关闭WebSocket/TCP Socket连接。\n\n#### live.getOnline()\n\n立即调用 `live.heartbeat()` 刷新人气数值，并且返回 Promise，resolve 人气刷新后数值\n\n#### live.on('message')\n\nWebSocket/TCP收到的Raw Buffer（不推荐直接使用）\n\n#### live.send(buffer)\n\n使用 WebSocket 或者 TCP 发送信息\n\n### getConf(roomid)\n\n选一个cdn，Resolve host, address 和 key, 可以直接放进(Keep)LiveWS/TCP设置\n\n```typescript\nconst { getConf } = require('bilibili-live-ws')\n\ngetConf(roomid)\n// Return\nPromise\u003c{\n    key: string;\n    host: string;\n    address: string;\n}\u003e\n```\n\n### getRoomid(short)\n\n通过短房间号获取长房间号\n\n```typescript\nconst { getRoomid } = require('bilibili-live-ws')\n\ngetRoomid(255)\n// Return Promise\u003cnumber\u003e: 48743\n```\n\n\u003chr\u003e\n\n### Keep和无Keep的区别\n\nKeepLiveWS 和 KeepLiveTCP 有断线重新连接的功能\n\n#### new KeepLiveWS(roomid [, { address, protover, key }])\n\n#### new KeepLiveTCP(roomid [, { host, port, protover, key }])\n\n所有上方的API都是一样的, 只不过会有以下微小的区别\n\n* 收到error或者close事件的时候并不代表连接关闭, 必须要手动调用`live.close()`来关闭连接\n* 内部的连接对象(`LiveWS`/`LiveTCP`)在`live.connection`中\n* 内部的连接关闭了之后, 如果不是因为`live.close()`关闭, 会在100毫秒之后自动打开一个新的连接。\n  * 这个100毫秒可以通过改变`live.interval`来设置\n* 内部的boolean, `live.closed`, 用于判断是否是因为`live.close()`关闭。\n\n\u003chr\u003e\n\n### LiveWS 和 LiveTCP 的区别\n\n#### LiveWS.ws\n\nLiveWS 内部 WebSocket 对象，需要时可以直接操作\n\nDoc: \u003chttps://github.com/websockets/ws/blob/master/doc/ws.md#class-websocket\u003e\n\n#### LiveTCP.socket\n\nLiveTCP 内部 TCP Socket 对象，需要时可以直接操作\n\nDoc: \u003chttps://nodejs.org/api/net.html#net_class_net_socket\u003e\n\n#### LiveTCP.buffer\n\nLiveTCP内部TCP流的Buffer缓冲区，有不完整的包\n\n#### LiveTCP.splitBuffer()\n\n处理LiveTCP内部TCP流的Buffer缓冲区，把其中完整的包交给decoder处理\n\n### BenchMark 简单对比\n\n在连接了640个直播间后过了一分钟左右(@2.0.0)\n\n|          | LiveWS (wss) | LiveWS (ws) | LiveTCP |\n| -------- | ------------ | ----------- | ------- |\n| 内存占用 | 63 MB        | 26 MB       | 18 MB   |\n\n\u003chr\u003e\n\n参考资料: \u003chttps://github.com/lovelyyoshino/Bilibili-Live-API/blob/master/API.WebSocket.md\u003e\n\n# 贡献\n\n欢迎Issue和Pull Request！\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimon300000%2Fbilibili-live-ws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimon300000%2Fbilibili-live-ws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimon300000%2Fbilibili-live-ws/lists"}