Skip to content

Commit

Permalink
temporary
Browse files Browse the repository at this point in the history
  • Loading branch information
shanmite committed Apr 14, 2021
1 parent 14aa086 commit efc7bbe
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,33 @@ 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
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
2 - HEARTBEAT
3 - HEARTBEAT_REPLY
5 - MESSAGE
7 - USER_AUTHENTICATION
8 - CONNECT_SUCCESS
Seq ID: 4 bits
Expand All @@ -80,8 +82,7 @@ Data: ANY bits
if PV = 0 then Data is utf-8 encoded format json string
if PV = 2 then Data is Gzip(deflate)
Unzip: Data -> Header0 + Data0 + Header1 + Data1 + ...
PV in Header(n) is 0
Data(n) is also utf-8 encoded format json string
Here, in header(n) the value of the PV field is 0
```

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/Convert.js → lib/_convert.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { mergeArrayBuffer } = require("./Base");
const { mergeArrayBuffer } = require("./base");
const { inflateSync } = require('zlib');
const WS = {
OP_HEARTBEAT: 2,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/LiveAPI.js → lib/live_api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { HttpRequest } = require("./HttpRequest");
const { HttpRequest } = require("./http_request");

const LiveAPI = {
HOST: 'https://api.live.bilibili.com',
Expand Down
18 changes: 9 additions & 9 deletions lib/LiveChat.js → lib/live_chat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const WebSocket = require("ws");
const convert = require("./Convert");
const LiveAPI = require("./LiveAPI");
const Convert = require("./convert");
const LiveAPI = require("./live_api");

class ServerInfo {
constructor() {
Expand All @@ -11,7 +11,7 @@ class ServerInfo {
this.userAuthentication = {
uid: 0,
roomid: 0,
protover: convert.WS.BODY_PROTOCOL_VERSION_DEFLATE,
protover: Convert.WS.BODY_PROTOCOL_VERSION_DEFLATE,
platform: "web",
clientver: "2.6.42",
type: 2,
Expand Down Expand Up @@ -128,9 +128,9 @@ class LiveChat extends ServerInfo {
return setInterval(() => {
console.log('chat_client -> heartBeat');
this.ws.send(
convert.toArrayBuffer(
Convert.toArrayBuffer(
{}.toString(),
convert.WS.OP_HEARTBEAT
Convert.WS.OP_HEARTBEAT
)
)
}, this.option.heartBeatInterval);
Expand All @@ -139,9 +139,9 @@ class LiveChat extends ServerInfo {
onOpen() {
console.log('chat_client -> connent to ' + this.wss_url);
this.ws.send(
convert.toArrayBuffer(
Convert.toArrayBuffer(
JSON.stringify(this.userAuthentication),
convert.WS.OP_USER_AUTHENTICATION
Convert.WS.OP_USER_AUTHENTICATION
)
);
}
Expand All @@ -155,9 +155,9 @@ class LiveChat extends ServerInfo {
} else if (raw_data instanceof ArrayBuffer) {
raw_data_toArrayBuffer = raw_data
}
const { totalLen, body, op, popular_count } = convert.toObject(raw_data_toArrayBuffer);
const { totalLen, body, op, popular_count } = Convert.toObject(raw_data_toArrayBuffer);
if (totalLen > 0) {
const { WS } = convert;
const { WS } = Convert;
switch (op) {
case WS.OP_MESSAGE:
msg.type = 'MESSAGE';
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const LiveChat = require("./lib/LiveChat");
const LiveChat = require("./lib/live_chat");

(function () {
const LiveChatCLient = new LiveChat();
LiveChatCLient
const chat_client = new LiveChat();
chat_client
.setRoomId(1)
.setUid(1)
.setMessageHandle((msg) => {
Expand All @@ -13,10 +13,10 @@ const LiveChat = require("./lib/LiveChat");
const stdin = data.toString().trim();
switch (stdin) {
case 'c':
LiveChatCLient.close();
chat_client.close();
break;
case 'r':
LiveChatCLient.run();
chat_client.run();
break;
case 'q':
process.exit(0);
Expand Down

0 comments on commit efc7bbe

Please sign in to comment.