MCPcopy Index your code
hub / github.com/Mathieu2301/TradingView-API / #parsePacket

Method #parsePacket

src/client.js:157–195  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

155 }
156
157 #parsePacket(str) {
158 if (!this.isOpen) return;
159
160 protocol.parseWSPacket(str).forEach((packet) => {
161 if (global.TW_DEBUG) console.log('§90§30§107 CLIENT §0 PACKET', packet);
162 if (typeof packet === 'number') { // Ping
163 this.#ws.send(protocol.formatWSPacket(`~h~${packet}`));
164 this.#handleEvent('ping', packet);
165 return;
166 }
167
168 if (packet.m === 'protocol_error') { // Error
169 this.#handleError('Client critical error:', packet.p);
170 this.#ws.close();
171 return;
172 }
173
174 if (packet.m && packet.p) { // Normal packet
175 const parsed = {
176 type: packet.m,
177 data: packet.p,
178 };
179
180 const session = packet.p[0];
181
182 if (session && this.#sessions[session]) {
183 this.#sessions[session].onData(parsed);
184 return;
185 }
186 }
187
188 if (!this.#logged) {
189 this.#handleEvent('logged', packet);
190 return;
191 }
192
193 this.#handleEvent('data', packet);
194 });
195 }
196
197 #sendQueue = [];
198

Callers 1

constructorMethod · 0.95

Calls 5

#handleEventMethod · 0.95
#handleErrorMethod · 0.95
sendMethod · 0.80
closeMethod · 0.80
onDataMethod · 0.45

Tested by

no test coverage detected