Skip to content

Commit

Permalink
refactor(sio): export the DefaultEventsMap type
Browse files Browse the repository at this point in the history
Related: #4747
  • Loading branch information
darrachequesne committed Sep 16, 2024
1 parent 02d59a0 commit fd99f2e
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions packages/socket.io/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,68 @@ interface ServerOptions extends EngineOptions, AttachOptions {
* io.listen(3000);
*/
export class Server<
/**
* Types for the events received from the clients.
*
* @example
* interface ClientToServerEvents {
* hello: (arg: string) => void;
* }
*
* const io = new Server<ClientToServerEvents>();
*
* io.on("connection", (socket) => {
* socket.on("hello", (arg) => {
* // `arg` is inferred as string
* });
* });
*/
ListenEvents extends EventsMap = DefaultEventsMap,
/**
* Types for the events sent to the clients.
*
* @example
* interface ServerToClientEvents {
* hello: (arg: string) => void;
* }
*
* const io = new Server<DefaultEventMap, ServerToClientEvents>();
*
* io.emit("hello", "world");
*/
EmitEvents extends EventsMap = ListenEvents,
/**
* Types for the events received from and sent to the other servers.
*
* @example
* interface InterServerEvents {
* ping: (arg: number) => void;
* }
*
* const io = new Server<DefaultEventMap, DefaultEventMap, ServerToClientEvents>();
*
* io.serverSideEmit("ping", 123);
*
* io.on("ping", (arg) => {
* // `arg` is inferred as number
* });
*/
ServerSideEvents extends EventsMap = DefaultEventsMap,
/**
* Additional properties that can be attached to the socket instance.
*
* Note: any property can be attached directly to the socket instance (`socket.foo = "bar"`), but the `data` object
* will be included when calling {@link Server#fetchSockets}.
*
* @example
* io.on("connection", (socket) => {
* socket.data.eventsCount = 0;
*
* socket.onAny(() => {
* socket.data.eventsCount++;
* });
* });
*/
SocketData = any,
> extends StrictEventEmitter<
ServerSideEvents,
Expand Down Expand Up @@ -1117,5 +1176,6 @@ export {
Namespace,
BroadcastOperator,
RemoteSocket,
DefaultEventsMap,
};
export { Event } from "./socket";

0 comments on commit fd99f2e

Please sign in to comment.