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

Method close

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

* 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("forced close");
844 debug("socket closing - telling transport to close");
845 this.transport.close();
846 };
847
848 const cleanupAndClose = () => {
849 this.off("upgrade", cleanupAndClose);
850 this.off("upgradeError", cleanupAndClose);
851 close();
852 };
853
854 const waitForUpgrade = () => {
855 // wait for upgrade to finish since we can't send packets while pausing a transport
856 this.once("upgrade", cleanupAndClose);
857 this.once("upgradeError", cleanupAndClose);
858 };
859
860 if ("opening" === this.readyState || "open" === this.readyState) {
861 this.readyState = "closing";
862
863 if (this.writeBuffer.length) {
864 this.once("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