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

Method onPacket

packages/engine.io/lib/socket.ts:153–193  ·  packages/engine.io/lib/socket.ts::Socket.onPacket

* Called upon transport packet. * * @param {Object} packet * @private

(packet: Packet)

Source from the content-addressed store, hash-verified

151 * @private
152 */
153 private onPacket(packet: Packet) {
154 if (class="st">"open" !== this.readyState) {
155 return debug(class="st">"packet received with closed socket");
156 }
157 class="cm">// export packet event
158 debug(`received packet ${packet.type}`);
159 this.emit(class="st">"packet", packet);
160
161 switch (packet.type) {
162 case class="st">"ping":
163 if (this.transport.protocol !== 3) {
164 this.onError(new Error(class="st">"invalid heartbeat direction"));
165 return;
166 }
167 debug(class="st">"got ping");
168 this.pingTimeoutTimer.refresh();
169 this.sendPacket(class="st">"pong");
170 this.emit(class="st">"heartbeat");
171 break;
172
173 case class="st">"pong":
174 if (this.transport.protocol === 3) {
175 this.onError(new Error(class="st">"invalid heartbeat direction"));
176 return;
177 }
178 debug(class="st">"got pong");
179 clearTimeout(this.pingTimeoutTimer);
180 this.pingIntervalTimer.refresh();
181 this.emit(class="st">"heartbeat");
182 break;
183
184 case class="st">"error":
185 this.onClose(class="st">"parse error");
186 break;
187
188 case class="st">"message":
189 this.emit(class="st">"data", packet.data);
190 this.emit(class="st">"message", packet.data);
191 break;
192 }
193 }
194
195 /**
196 * Called upon transport error.

Callers 8

onSuccessFunction · 0.95
onDataFunction · 0.45
readMethod · 0.45
callbackFunction · 0.45
onDataFunction · 0.45
callbackMethod · 0.45
constructorMethod · 0.45
callbackMethod · 0.45

Calls 11

emitMethod · 0.95
onErrorMethod · 0.95
sendPacketMethod · 0.95
onCloseMethod · 0.95
clearTransportMethod · 0.95
setTransportMethod · 0.95
flushMethod · 0.95
debugFunction · 0.85
cleanupFunction · 0.85
sendMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected