buzzk 1.9.10 → 1.9.12

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.
Files changed (2) hide show
  1. package/lib/chat.js +28 -11
  2. package/package.json +1 -1
package/lib/chat.js CHANGED
@@ -79,7 +79,25 @@ class chzzkChat {
79
79
  //Connect Web Socket
80
80
 
81
81
  //WS Open
82
+ await this.#openHandler(this.#status.wsID);
83
+ //WS Open
84
+
85
+ this.#ws.on("error", console.error);
86
+
87
+ this.#closeHandler(this.#status.wsID);
88
+
89
+ //WS Message
90
+ await this.#connectHandler(this.#status.wsID);
91
+ return resolve(true);
92
+ //WS Message
93
+
94
+ });
95
+ }
96
+
97
+ #openHandler(wsID) {
98
+ return new Promise(async (resolve, reject) => {
82
99
  this.#ws.on("open", () => {
100
+ if (wsID != this.#status.wsID) return;
83
101
  console.log("[WS] Connected!");
84
102
 
85
103
  //WS First Connect
@@ -94,22 +112,27 @@ class chzzkChat {
94
112
  "accTkn": this.#accTkn,
95
113
  "auth":"SEND",
96
114
  "devName": "BUZZK/" + vm.getVersion(),
115
+ "libVer": vm.getVersion(),
97
116
  "locale": "ko",
98
117
  "osVer": "Windows/10",
99
118
  "timezone": "Asia/Seoul"
100
119
  },
101
120
  "tid": 1
102
121
  };
103
-
122
+
104
123
  this.#ws.send(JSON.stringify(connectOpt));
124
+ return resolve(true);
105
125
  //WS First Connect
106
126
  });
107
- //WS Open
108
-
109
- this.#ws.on("error", console.error);
127
+ });
128
+ }
110
129
 
130
+ #closeHandler(wsID) {
131
+ return new Promise(async (resolve, reject) => {
111
132
  this.#ws.on("close", () => {
112
133
  console.log("[WS] Disconnect!");
134
+ if (wsID != this.#status.wsID) return;
135
+ if (this.#status.reconnect) return;
113
136
  this.#ws = null;
114
137
  this.#status.ws = false;
115
138
  this.#status.wsID++;
@@ -120,12 +143,6 @@ class chzzkChat {
120
143
  this.connect();
121
144
  }, 2000);
122
145
  });
123
-
124
- //WS Message
125
- await this.#connectHandler(this.#status.wsID);
126
- return resolve(true);
127
- //WS Message
128
-
129
146
  });
130
147
  }
131
148
 
@@ -201,7 +218,7 @@ class chzzkChat {
201
218
  //WS Send
202
219
  let date = new Date();
203
220
  let sendOpt = {
204
- "ver": "2",
221
+ "ver": "3",
205
222
  "cmd": 3101,
206
223
  "svcid": this.#svcid,
207
224
  "cid": this.#chatID,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "buzzk",
3
3
  "displayName": "BUZZK",
4
- "version": "1.9.10",
4
+ "version": "1.9.12",
5
5
  "description": "뿌지직 (BUZZK) - 치지직(CHZZK) 챗봇을 더욱 쉽게 개발할 수 있도록 돕는 비공식 라이브러리.",
6
6
  "main": "lib/index.js",
7
7
  "type": "commonjs",