MCPcopy Index your code
hub / github.com/socketio/socket.io / _onclose

Method _onclose

lib/socket.ts:743–766  ·  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

741 * @private
742 */
743 _onclose(reason: DisconnectReason, description?: any): this | undefined {
744 if (!this.connected) return this;
745 debug("closing socket - reason %s", reason);
746 this.emitReserved("disconnecting", reason, description);
747
748 if (
749 this.server._opts.connectionStateRecovery &&
750 RECOVERABLE_DISCONNECT_REASONS.has(reason)
751 ) {
752 debug("connection state recovery is enabled for sid %s", this.id);
753 this.adapter.persistSession({
754 sid: this.id,
755 pid: this.pid,
756 rooms: [...this.rooms],
757 data: this.data,
758 });
759 }
760
761 this._cleanup();
762 this.client._remove(this);
763 this.connected = false;
764 this.emitReserved("disconnect", reason, description);
765 return;
766 }
767
768 /**
769 * 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 3

_cleanupMethod · 0.95
persistSessionMethod · 0.80
_removeMethod · 0.45

Tested by

no test coverage detected