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

Method _onclose

packages/socket.io/lib/socket.ts:650–673  ·  view source on GitHub ↗

* Called upon closing. Called by `Client`. * * @param {String} reason * @param description * @throw {Error} optional error object * * @private

(reason: DisconnectReason, description?: any)

Source from the content-addressed store, hash-verified

648 * @private
649 */
650 _onclose(reason: DisconnectReason, description?: any): this | undefined {
651 if (!this.connected) return this;
652 debug("closing socket - reason %s", reason);
653 this.emitReserved("disconnecting", reason, description);
654
655 if (
656 this.server._opts.connectionStateRecovery &&
657 RECOVERABLE_DISCONNECT_REASONS.has(reason)
658 ) {
659 debug("connection state recovery is enabled for sid %s", this.id);
660 this.adapter.persistSession({
661 sid: this.id,
662 pid: this.pid,
663 rooms: [...this.rooms],
664 data: this.data,
665 });
666 }
667
668 this._cleanup();
669 this.client._remove(this);
670 this.connected = false;
671 this.emitReserved("disconnect", reason, description);
672 return;
673 }
674
675 /**
676 * Makes the socket leave all the rooms it was part of and prevents it from joining any other room

Callers 4

ondisconnectMethod · 0.95
disconnectMethod · 0.95
oncloseMethod · 0.80
closeMethod · 0.80

Calls 4

_cleanupMethod · 0.95
debugFunction · 0.85
persistSessionMethod · 0.45
_removeMethod · 0.45

Tested by

no test coverage detected