Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comment: write js docs in on #5198

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 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 @@ -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