Skip to content

Commit 8aa9499

Browse files
Hackatoshdarrachequesne
authored andcommittedFeb 4, 2023
feat: add description to the disconnecting and disconnect events (#4622)
See also: socketio/socket.io-client@b862924
1 parent 4e64123 commit 8aa9499

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed
 

‎lib/client.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -311,17 +311,21 @@ export class Client<
311311
* Called upon transport close.
312312
*
313313
* @param reason
314+
* @param description
314315
* @private
315316
*/
316-
private onclose(reason: CloseReason | "forced server close"): void {
317+
private onclose(
318+
reason: CloseReason | "forced server close",
319+
description?: any
320+
): void {
317321
debug("client close with reason %s", reason);
318322

319323
// ignore a potential subsequent `close` event
320324
this.destroy();
321325

322326
// `nsps` and `sockets` are cleaned up seamlessly
323327
for (const socket of this.sockets.values()) {
324-
socket._onclose(reason);
328+
socket._onclose(reason, description);
325329
}
326330
this.sockets.clear();
327331

‎lib/socket.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ const RECOVERABLE_DISCONNECT_REASONS: ReadonlySet<DisconnectReason> = new Set([
5656
]);
5757

5858
export interface SocketReservedEventsMap {
59-
disconnect: (reason: DisconnectReason) => void;
60-
disconnecting: (reason: DisconnectReason) => void;
59+
disconnect: (reason: DisconnectReason, description?: any) => void;
60+
disconnecting: (reason: DisconnectReason, description?: any) => void;
6161
error: (err: Error) => void;
6262
}
6363

@@ -749,14 +749,15 @@ export class Socket<
749749
* Called upon closing. Called by `Client`.
750750
*
751751
* @param {String} reason
752+
* @param description
752753
* @throw {Error} optional error object
753754
*
754755
* @private
755756
*/
756-
_onclose(reason: DisconnectReason): this | undefined {
757+
_onclose(reason: DisconnectReason, description?: any): this | undefined {
757758
if (!this.connected) return this;
758759
debug("closing socket - reason %s", reason);
759-
this.emitReserved("disconnecting", reason);
760+
this.emitReserved("disconnecting", reason, description);
760761

761762
if (RECOVERABLE_DISCONNECT_REASONS.has(reason)) {
762763
debug("connection state recovery is enabled for sid %s", this.id);
@@ -772,7 +773,7 @@ export class Socket<
772773
this.nsp._remove(this);
773774
this.client._remove(this);
774775
this.connected = false;
775-
this.emitReserved("disconnect", reason);
776+
this.emitReserved("disconnect", reason, description);
776777
return;
777778
}
778779

0 commit comments

Comments
 (0)
Please sign in to comment.