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

Method _onClose

packages/engine.io-client/lib/socket.ts:909–960  ·  packages/engine.io-client/lib/socket.ts::SocketWithoutUpgrade._onClose

* 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 class="st">"opening" === this.readyState ||
912 class="st">"open" === this.readyState ||
913 class="st">"closing" === this.readyState
914 ) {
915 debug(class="st">'socket close with reason: "%s"', reason);
916
917 class="cm">// clear timers
918 this.clearTimeoutFn(this._pingTimeoutTimer);
919
920 class="cm">// stop event from firing again for transport
921 this.transport.removeAllListeners(class="st">"close");
922
923 class="cm">// ensure transport won't stay open
924 this.transport.close();
925
926 class="cm">// ignore further transport communication
927 this.transport.removeAllListeners();
928
929 if (withEventListeners) {
930 if (this._beforeunloadEventListener) {
931 removeEventListener(
932 class="st">"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(class="st">"removing listener for the 'offline' event");
941 OFFLINE_EVENT_LISTENERS.splice(i, 1);
942 }
943 }
944 }
945
946 class="cm">// set ready state
947 this.readyState = class="st">"closed";
948
949 class="cm">// clear session id
950 this.id = null;
951
952 class="cm">// emit close event
953 this.emitReserved(class="st">"close", reason, description);
954
955 class="cm">// clean buffers after, so users can still
956 class="cm">// 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