* Called upon transport close. * * @private
(reason: string, description?: CloseDetails | Error)
| 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 | /** |
no test coverage detected