MCPcopy
hub / github.com/socketio/socket.io / #onMessage

Method #onMessage

examples/basic-websocket-client/src/index.js:78–112  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

76 }
77
78 #onMessage(data) {
79 if (typeof data !== "string") {
80 // TODO handle binary payloads
81 return;
82 }
83
84 switch (data[0]) {
85 case EIOPacketType.OPEN:
86 this.#onOpen(data);
87 break;
88
89 case EIOPacketType.CLOSE:
90 this.#onClose("transport close");
91 break;
92
93 case EIOPacketType.PING:
94 this.#resetPingTimeout();
95 this.#send(EIOPacketType.PONG);
96 break;
97
98 case EIOPacketType.MESSAGE:
99 let packet;
100 try {
101 packet = decode(data);
102 } catch (e) {
103 return this.#onClose("parse error");
104 }
105 this.#onPacket(packet);
106 break;
107
108 default:
109 this.#onClose("parse error");
110 break;
111 }
112 }
113
114 #onOpen(data) {
115 let handshake;

Callers 1

#openMethod · 0.95

Calls 6

#onOpenMethod · 0.95
#onCloseMethod · 0.95
#resetPingTimeoutMethod · 0.95
#sendMethod · 0.95
#onPacketMethod · 0.95
decodeFunction · 0.70

Tested by

no test coverage detected