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

Method _onClose

packages/engine.io-client/lib/socket.ts:909–960  ·  view source on GitHub ↗

* Called upon transport close. * * @private

(reason: string, description?: CloseDetails | Error)

Source from the content-addressed store, hash-verified

907 * @private
908 */
909 private _onClose(reason: string, description?: CloseDetails | Error) {
910 if (
911 "opening" === this.readyState ||
912 "open" === this.readyState ||
913 "closing" === this.readyState
914 ) {
915 debug('socket close with reason: "%s"', reason);
916
917 // clear timers
918 this.clearTimeoutFn(this._pingTimeoutTimer);
919
920 // stop event from firing again for transport
921 this.transport.removeAllListeners("close");
922
923 // ensure transport won't stay open
924 this.transport.close();
925
926 // ignore further transport communication
927 this.transport.removeAllListeners();
928
929 if (withEventListeners) {
930 if (this._beforeunloadEventListener) {
931 removeEventListener(
932 "beforeunload",
933 this._beforeunloadEventListener,
934 false,
935 );
936 }
937 if (this._offlineEventListener) {
938 const i = OFFLINE_EVENT_LISTENERS.indexOf(this._offlineEventListener);
939 if (i !== -1) {
940 debug("removing listener for the 'offline' event");
941 OFFLINE_EVENT_LISTENERS.splice(i, 1);
942 }
943 }
944 }
945
946 // set ready state
947 this.readyState = "closed";
948
949 // clear session id
950 this.id = null;
951
952 // emit close event
953 this.emitReserved("close", reason, description);
954
955 // clean buffers after, so users can still
956 // grab the buffers on `close` event
957 this.writeBuffer = [];
958 this._prevBufferLen = 0;
959 }
960 }
961}
962
963/**

Callers 10

constructorMethod · 0.95
setTransportMethod · 0.95
_resetPingTimeoutMethod · 0.95
_hasPingExpiredMethod · 0.95
closeMethod · 0.95
_onErrorMethod · 0.95
_hookTransportFunction · 0.80
SocketWithoutUpgradeFunction · 0.80
socket.io.jsFile · 0.80
closeFunction · 0.80

Calls 2

debugFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected