-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shanmite
committed
Apr 13, 2021
0 parents
commit cd45048
Showing
12 changed files
with
1,875 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"env": { | ||
"commonjs": true, | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 12 | ||
}, | ||
"rules": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
{ | ||
"HttpRequest-get": { | ||
"scope": "javascript,typescript", | ||
"prefix": "hrget", | ||
"body": [ | ||
"HttpRequest({", | ||
" method: 'GET',", | ||
" url: '$1',", | ||
" query: {", | ||
" $2", | ||
" },", | ||
" headers: {", | ||
" accept: 'application/json, text/plain, */*',", | ||
" cookie: '$3',", | ||
" },", | ||
" success: res => {", | ||
" $4", | ||
" },", | ||
" failure: err => {", | ||
" $5", | ||
" }", | ||
"})$6" | ||
], | ||
"description": "简化http-get请求" | ||
}, | ||
"HttpRequest-post": { | ||
"scope": "javascript,typescript", | ||
"prefix": "hrpost", | ||
"body": [ | ||
"HttpRequest({", | ||
" method: 'POST',", | ||
" url: '$1',", | ||
" contents: {", | ||
" $2", | ||
" },", | ||
" headers: {", | ||
" accept: 'application/json, text/plain, */*',", | ||
" 'content-type': 'application/x-www-form-urlencoded; charset=utf-8',", | ||
" cookie: '$3',", | ||
" },", | ||
" success: res => {", | ||
" $4", | ||
" },", | ||
" failure: err => {", | ||
" $5", | ||
" }", | ||
"})$6" | ||
], | ||
"description": "简化http-post请求" | ||
}, | ||
"CORSajax-get": { | ||
"scope": "javascript,typescript", | ||
"prefix": "corsget", | ||
"body": [ | ||
"CORSajax.get({", | ||
" proxy_link: '$1',", | ||
" proxy_querystring: {", | ||
" $2", | ||
" },", | ||
" proxy_headers: {", | ||
" Cookie: '$3'", | ||
" },", | ||
"},chunk => {", | ||
" $4", | ||
"})$5" | ||
], | ||
"description": "简化跨域Ajax本地nodejsのget代理" | ||
}, | ||
"CORSajax-post": { | ||
"scope": "javascript,typescript", | ||
"prefix": "corspost", | ||
"body": [ | ||
"CORSajax.post({", | ||
" proxy_link: '$1',", | ||
" proxy_headers: {", | ||
" 'content-type': 'application/x-www-form-urlencoded; charset=utf-8',", | ||
" cookie: '$2'", | ||
" },", | ||
" proxy_body: {", | ||
" $3", | ||
" },", | ||
"},chunk => {", | ||
" $4", | ||
"})$5" | ||
], | ||
"description": "简化跨域Ajax本地nodejsのpost代理" | ||
}, | ||
"Ajax-get": { | ||
"scope": "javascript,typescript", | ||
"prefix": "myget", | ||
"body": [ | ||
"Ajax.get({", | ||
" url: '$1',", | ||
" queryStringsObj: {", | ||
" $2", | ||
" },", | ||
" hasCookies: true,", | ||
" success: responseText => {", | ||
" $3", | ||
" }", | ||
"})", | ||
], | ||
"description": "简化AjaxのGet请求" | ||
}, | ||
"Ajax-post": { | ||
"scope": "javascript,typescript", | ||
"prefix": "mypost", | ||
"body": [ | ||
"Ajax.post({", | ||
" url: '$1',", | ||
" hasCookies: true,", | ||
" dataType: 'application/x-www-form-urlencoded',", | ||
" data: {", | ||
" $2", | ||
" },", | ||
" success: responseText => {", | ||
" $3", | ||
" }", | ||
"})", | ||
], | ||
"description": "简化Ajaxのpost请求" | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# BiliBili 直播间弹幕 | ||
包括全区礼物广播, 投喂信息, 入场信息, 人气值等 | ||
|
||
直播间`WebSocket`传输数据格式 | ||
``` | ||
Packet Header Format | ||
0 1 | ||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| PL |HL |PV | Op |Seq ID | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| | | ||
| Data | | ||
| | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
PL: 4 bits | ||
Packet Length | ||
HL: 2 bits | ||
Header Length | ||
16 - HEADER_TOTAL_LENGTH | ||
PV: 2 bits | ||
Protocol Version | ||
1 - HEADER_DEFAULT_VERSION | ||
0 - BODY_PROTOCOL_VERSION_NORMAL | ||
2 - BODY_PROTOCOL_VERSION_DEFLATE | ||
Op: 4 bits | ||
Operation | ||
1 - HEADER_DEFAULT_OPERATION | ||
2 - OP_HEARTBEAT | ||
3 - OP_HEARTBEAT_REPLY | ||
5 - OP_MESSAGE | ||
7 - OP_USER_AUTHENTICATION | ||
8 - OP_CONNECT_SUCCESS | ||
Seq ID: 4 bits | ||
Sequence Id | ||
1 - HEADER_DEFAULT_SEQUENCE | ||
Data: ANY bits | ||
if PV = 0 then Data is UTF-8 Code JSON Format | ||
if PV = 2 then Data is Gzip | ||
Unzip: Data -> Header0 + Data0 + Header1 + Data1 + ... | ||
And Data(n) is also UTF-8 Code JSON Format | ||
``` | ||
|
||
## 初始化 | ||
`GET` [https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo](https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo) | ||
|
||
获取所需的`HostList` `key` | ||
|
||
<table border="1" cellpadding="1" cellspacing="1" style="width:500px"> | ||
<tbody> | ||
<tr> | ||
<td>HostList</td> | ||
<td>WebSocket主机列表</td> | ||
</tr> | ||
<tr> | ||
<td>key</td> | ||
<td>身份识别</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
连接至WebSocket服务器 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* mergeArrayBuffer | ||
* @param {ArrayBuffer[]} arrays | ||
* @returns {ArrayBuffer} | ||
*/ | ||
function mergeArrayBuffer(...arrays) { | ||
let totalLen = 0 | ||
for (let i = 0; i < arrays.length; i++) { | ||
arrays[i] = new Uint8Array(arrays[i]) | ||
totalLen += arrays[i].length | ||
} | ||
|
||
let res = new Uint8Array(totalLen) | ||
|
||
let offset = 0 | ||
for(let arr of arrays) { | ||
res.set(arr, offset) | ||
offset += arr.length | ||
} | ||
|
||
return res.buffer | ||
} | ||
|
||
module.exports = { | ||
mergeArrayBuffer | ||
} |
Oops, something went wrong.