buzzk 1.9.9 → 1.9.11

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 +29 -15
  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
@@ -100,16 +118,20 @@ class chzzkChat {
100
118
  },
101
119
  "tid": 1
102
120
  };
103
-
121
+
104
122
  this.#ws.send(JSON.stringify(connectOpt));
123
+ return resolve(true);
105
124
  //WS First Connect
106
125
  });
107
- //WS Open
108
-
109
- this.#ws.on("error", console.error);
126
+ });
127
+ }
110
128
 
129
+ #closeHandler(wsID) {
130
+ return new Promise(async (resolve, reject) => {
111
131
  this.#ws.on("close", () => {
112
132
  console.log("[WS] Disconnect!");
133
+ if (wsID != this.#status.wsID) return;
134
+ if (this.#status.reconnect) return;
113
135
  this.#ws = null;
114
136
  this.#status.ws = false;
115
137
  this.#status.wsID++;
@@ -120,12 +142,6 @@ class chzzkChat {
120
142
  this.connect();
121
143
  }, 2000);
122
144
  });
123
-
124
- //WS Message
125
- await this.#connectHandler(this.#status.wsID);
126
- return resolve(true);
127
- //WS Message
128
-
129
145
  });
130
146
  }
131
147
 
@@ -542,9 +558,7 @@ class chzzkChat {
542
558
  }
543
559
  //Get ChatID
544
560
 
545
- let interval;
546
- if (cidRes && cidRes.polling && cidRes.polling.callPeriodMilliSecond) interval = cidRes.polling.callPeriodMilliSecond;
547
- else interval = 30000;
561
+ let interval = 30000;
548
562
 
549
563
  setTimeout(() => {
550
564
  return this.#polling();
@@ -565,12 +579,12 @@ class chzzkChat {
565
579
  catch (error) {
566
580
  return setTimeout(async () => {
567
581
  return this.#ping(pingID);
568
- }, 20000);
582
+ }, 30000);
569
583
  }
570
584
 
571
585
  setTimeout(() => {
572
586
  return this.#ping(pingID);
573
- }, 20000);
587
+ }, 30000);
574
588
  }
575
589
  }
576
590
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "buzzk",
3
3
  "displayName": "BUZZK",
4
- "version": "1.9.9",
4
+ "version": "1.9.11",
5
5
  "description": "뿌지직 (BUZZK) - 치지직(CHZZK) 챗봇을 더욱 쉽게 개발할 수 있도록 돕는 비공식 라이브러리.",
6
6
  "main": "lib/index.js",
7
7
  "type": "commonjs",