MCPcopy Index your code
hub / github.com/socketio/socket.io / ondecoded

Method ondecoded

lib/client.ts:268–295  ·  view source on GitHub ↗

* Called when parser fully decodes a packet. * * @private

(packet: Packet)

Source from the content-addressed store, hash-verified

266 * @private
267 */
268 private ondecoded(packet: Packet): void {
269 let namespace: string;
270 let authPayload: Record<string, unknown>;
271 if (this.conn.protocol === 3) {
272 const parsed = url.parse(packet.nsp, true);
273 namespace = parsed.pathname!;
274 authPayload = parsed.query;
275 } else {
276 namespace = packet.nsp;
277 authPayload = packet.data;
278 }
279 const socket = this.nsps.get(namespace);
280
281 if (!socket && packet.type === PacketType.CONNECT) {
282 this.connect(namespace, authPayload);
283 } else if (
284 socket &&
285 packet.type !== PacketType.CONNECT &&
286 packet.type !== PacketType.CONNECT_ERROR
287 ) {
288 process.nextTick(function () {
289 socket._onpacket(packet);
290 });
291 } else {
292 debug("invalid state (packet type: %s)", packet.type);
293 this.close();
294 }
295 }
296
297 /**
298 * Handles an error.

Callers

nothing calls this directly

Calls 3

connectMethod · 0.95
closeMethod · 0.95
_onpacketMethod · 0.80

Tested by

no test coverage detected