MCPcopy
hub / github.com/socketio/socket.io / _onPacket

Method _onPacket

packages/engine.io-client/lib/socket.ts:594–634  ·  view source on GitHub ↗

* Handles a packet. * * @private

(packet: Packet)

Source from the content-addressed store, hash-verified

592 * @private
593 */
594 private _onPacket(packet: Packet) {
595 if (
596 "opening" === this.readyState ||
597 "open" === this.readyState ||
598 "closing" === this.readyState
599 ) {
600 debug('socket receive: type "%s", data "%s"', packet.type, packet.data);
601
602 this.emitReserved("packet", packet);
603
604 // Socket is live - any packet counts
605 this.emitReserved("heartbeat");
606
607 switch (packet.type) {
608 case "open":
609 this.onHandshake(JSON.parse(packet.data));
610 break;
611
612 case "ping":
613 this._sendPacket("pong");
614 this.emitReserved("ping");
615 this.emitReserved("pong");
616 this._resetPingTimeout();
617 break;
618
619 case "error":
620 const err = new Error("server error");
621 // @ts-ignore
622 err.code = packet.data;
623 this._onError(err);
624 break;
625
626 case "message":
627 this.emitReserved("data", packet.data);
628 this.emitReserved("message", packet.data);
629 break;
630 }
631 } else {
632 debug('packet received with socket readyState "%s"', this.readyState);
633 }
634 }
635
636 /**
637 * Called upon handshake completion.

Callers 1

_hookTransportFunction · 0.80

Calls 5

onHandshakeMethod · 0.95
_sendPacketMethod · 0.95
_resetPingTimeoutMethod · 0.95
_onErrorMethod · 0.95
debugFunction · 0.85

Tested by

no test coverage detected