* Called upon closing. Called by `Client`. * * @param {String} reason * @param description * @throw {Error} optional error object * * @private
(reason: DisconnectReason, description?: any)
| 648 | * @private |
| 649 | */ |
| 650 | _onclose(reason: DisconnectReason, description?: any): this | undefined { |
| 651 | if (!this.connected) return this; |
| 652 | debug("closing socket - reason %s", reason); |
| 653 | this.emitReserved("disconnecting", reason, description); |
| 654 | |
| 655 | if ( |
| 656 | this.server._opts.connectionStateRecovery && |
| 657 | RECOVERABLE_DISCONNECT_REASONS.has(reason) |
| 658 | ) { |
| 659 | debug("connection state recovery is enabled for sid %s", this.id); |
| 660 | this.adapter.persistSession({ |
| 661 | sid: this.id, |
| 662 | pid: this.pid, |
| 663 | rooms: [...this.rooms], |
| 664 | data: this.data, |
| 665 | }); |
| 666 | } |
| 667 | |
| 668 | this._cleanup(); |
| 669 | this.client._remove(this); |
| 670 | this.connected = false; |
| 671 | this.emitReserved("disconnect", reason, description); |
| 672 | return; |
| 673 | } |
| 674 | |
| 675 | /** |
| 676 | * Makes the socket leave all the rooms it was part of and prevents it from joining any other room |
no test coverage detected