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

Method close

packages/engine.io-client/lib/socket.ts:841–879  ·  packages/engine.io-client/lib/socket.ts::SocketWithoutUpgrade.close

* Closes the connection.

()

Source from the content-addressed store, hash-verified

839 * Closes the connection.
840 */
841 public close() {
842 const close = () => {
843 this._onClose(class="st">"forced close");
844 debug(class="st">"socket closing - telling transport to close");
845 this.transport.close();
846 };
847
848 const cleanupAndClose = () => {
849 this.off(class="st">"upgrade", cleanupAndClose);
850 this.off(class="st">"upgradeError", cleanupAndClose);
851 close();
852 };
853
854 const waitForUpgrade = () => {
855 class="cm">// wait for upgrade to finish since we can't send packets while pausing a transport
856 this.once(class="st">"upgrade", cleanupAndClose);
857 this.once(class="st">"upgradeError", cleanupAndClose);
858 };
859
860 if (class="st">"opening" === this.readyState || class="st">"open" === this.readyState) {
861 this.readyState = class="st">"closing";
862
863 if (this.writeBuffer.length) {
864 this.once(class="st">"drain", () => {
865 if (this.upgrading) {
866 waitForUpgrade();
867 } else {
868 close();
869 }
870 });
871 } else if (this.upgrading) {
872 waitForUpgrade();
873 } else {
874 close();
875 }
876 }
877
878 return this;
879 }
880
881 /**
882 * Called upon transport error

Callers 15

constructorMethod · 0.45
_onCloseMethod · 0.45
freezeTransportMethod · 0.45
doCloseMethod · 0.45
doCloseFunction · 0.45
socket.jsFile · 0.45
node.jsFile · 0.45
connection.jsFile · 0.45
successFunction · 0.45
webtransport.mjsFile · 0.45
binary-fallback.jsFile · 0.45
transport.jsFile · 0.45

Calls 4

_onCloseMethod · 0.95
debugFunction · 0.85
waitForUpgradeFunction · 0.85
closeFunction · 0.70

Tested by

no test coverage detected