Skip to content

Commit

Permalink
comment: overwrite on method & write addtional js docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nayounsang committed Oct 23, 2024
1 parent 1eeac1b commit 5dbedff
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions packages/socket.io-client/lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
EventParams,
EventsMap,
Emitter,
ReservedOrUserEventNames,
ReservedOrUserListener,
} from "@socket.io/component-emitter";
import debugModule from "debug"; // debug()

Expand All @@ -18,6 +20,8 @@ type PrependTimeoutError<T extends any[]> = {
: T[K];
};

interface ReservedEvents extends EventsMap {}

/**
* Utility type to decorate the acknowledgement callbacks with a timeout error.
*
Expand Down Expand Up @@ -116,7 +120,7 @@ interface SocketReservedEvents {
connect_error: (err: Error) => void;
disconnect: (
reason: Socket.DisconnectReason,
description?: DisconnectDescription,
description?: DisconnectDescription
) => void;
}

Expand Down Expand Up @@ -551,7 +555,7 @@ export class Socket<
debug(
"packet [%d] is discarded after %d tries",
packet.id,
packet.tryCount,
packet.tryCount
);
this._queue.shift();
if (ack) {
Expand Down Expand Up @@ -588,7 +592,7 @@ export class Socket<
if (packet.pending && !force) {
debug(
"packet [%d] has already been sent and is waiting for an ack",
packet.id,
packet.id
);
return;
}
Expand Down Expand Up @@ -662,7 +666,7 @@ export class Socket<
*/
private onclose(
reason: Socket.DisconnectReason,
description?: DisconnectDescription,
description?: DisconnectDescription
): void {
debug("close (%s)", reason);
this.connected = false;
Expand All @@ -680,7 +684,7 @@ export class Socket<
private _clearAcks() {
Object.keys(this.acks).forEach((id) => {
const isBuffered = this.sendBuffer.some(
(packet) => String(packet.id) === id,
(packet) => String(packet.id) === id
);
if (!isBuffered) {
// note: handlers that do not accept an error as first argument are ignored here
Expand Down Expand Up @@ -713,8 +717,8 @@ export class Socket<
this.emitReserved(
"connect_error",
new Error(
"It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)",
),
"It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"
)
);
}
break;
Expand Down Expand Up @@ -964,7 +968,7 @@ export class Socket<
* @returns self
*/
public timeout(
timeout: number,
timeout: number
): Socket<ListenEvents, DecorateAcknowledgements<EmitEvents>> {
this.flags.timeout = timeout;
return this;
Expand Down Expand Up @@ -1145,6 +1149,22 @@ export class Socket<
}
}
}

/**
* @param ev Name of the event
* @param listener Callback function
* @reserved
* - `connect`: This event is fired by the Socket instance upon connection **and** reconnection.
* - `connect_error`: This event is fired upon connection failure.
* - `disconnect`: This event is fired upon disconnection.
* @see [client-api-events](https://socket.io/docs/v4/client-api/#events-1)
*/
public on<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
ev: Ev,
listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
): this {
return super.on<Ev>(ev, listener);
}
}

export namespace Socket {
Expand Down

0 comments on commit 5dbedff

Please sign in to comment.