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

Function _onUpgradeSuccess

packages/socket.io-cluster-engine/lib/engine.ts:576–638  ·  packages/socket.io-cluster-engine/lib/engine.ts::_onUpgradeSuccess
(
    sid: SessionId,
    transport: Transport,
    req: any,
    senderId: NodeId,
  )

Source from the content-addressed store, hash-verified

574 }
575
576 private _onUpgradeSuccess(
577 sid: SessionId,
578 transport: Transport,
579 req: any,
580 senderId: NodeId,
581 ) {
582 debug(class="st">"upgrade success");
583 this._hookTransport(sid, transport, class="st">"read", senderId);
584
585 const requestId = ++this._requestCount as RequestId;
586
587 const onSuccess = (takeOver: boolean, packets: Packet[]) => {
588 if (takeOver) {
589 this._remoteTransports.delete(sid);
590
591 const send = transport.send;
592 transport.send = () => {};
593 const socket = new Socket(sid, this, transport, req, 4);
594 transport.send = send;
595
596 this.clients[sid] = socket;
597 this.clientsCount++;
598
599 socket.once(class="st">"close", () => {
600 delete this.clients[sid];
601 this.clientsCount--;
602 });
603
604 super.emit(class="st">"connection", socket);
605 socket.emit(class="st">"upgrade");
606 for (const packet of packets) {
607 class="cm">// @ts-expect-error onPacket() is private
608 socket.onPacket(packet);
609 }
610 }
611 };
612
613 const onError = () => {
614 transport.close();
615 };
616
617 const timer = setTimeout(() => {
618 this._requests.delete(requestId);
619 onError();
620 }, this._opts.responseTimeout);
621
622 this._requests.set(requestId, {
623 timer,
624 onSuccess,
625 onError,
626 });
627
628 this.publishMessage({
629 requestId,
630 senderId: this._nodeId,
631 recipientId: senderId,
632 type: MessageType.UPGRADE,
633 data: {

Callers

nothing calls this directly

Calls 3

debugFunction · 0.85
onErrorFunction · 0.70
publishMessageMethod · 0.45

Tested by

no test coverage detected