Skip to content
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