@emeryld/rrroutes-server 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +190 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +190 -73
- package/dist/index.js.map +1 -1
- package/dist/sockets/socket.server.index.d.ts +59 -0
- package/package.json +2 -2
|
@@ -18,6 +18,8 @@ export interface SocketConnection<T extends EventMap> {
|
|
|
18
18
|
on<K extends keyof T & string>(eventName: K, handler: (payload: Payload<T, K>, ctx: HandlerCtx) => void | Promise<void>): () => void;
|
|
19
19
|
off<K extends keyof T & string>(eventName: K): void;
|
|
20
20
|
emit<K extends keyof T & string>(eventName: K, payload: Payload<T, K>, toRooms?: string[] | string, metadata?: Record<string, unknown>, onAck?: (ack: unknown) => void): void;
|
|
21
|
+
/** Dispose all listeners, timers, and room memberships created by this instance. */
|
|
22
|
+
destroy(): void;
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* Grouped debug types:
|
|
@@ -99,9 +101,66 @@ export type HeartbeatServerOptions<Ping extends ZodType, Pong extends ZodType> =
|
|
|
99
101
|
/** Optionally validate the outgoing pong object before emit. */
|
|
100
102
|
pongSchema?: Pong;
|
|
101
103
|
};
|
|
104
|
+
/** === Server sys-event types (inspired by client) === */
|
|
105
|
+
type BaseSysServerArgs = {
|
|
106
|
+
socket: Socket;
|
|
107
|
+
next: () => void;
|
|
108
|
+
};
|
|
109
|
+
export type SysServerConnectHandlerArgs = BaseSysServerArgs & {
|
|
110
|
+
name: 'sys:connect';
|
|
111
|
+
};
|
|
112
|
+
export type SysServerDisconnectHandlerArgs = BaseSysServerArgs & {
|
|
113
|
+
name: 'sys:disconnect';
|
|
114
|
+
reason: string;
|
|
115
|
+
};
|
|
116
|
+
export type SysServerPingHandlerArgs<Ping extends ZodType = ZodType, Pong extends ZodType = ZodType> = {
|
|
117
|
+
name: 'sys:ping';
|
|
118
|
+
socket: Socket;
|
|
119
|
+
raw: {
|
|
120
|
+
payload?: unknown;
|
|
121
|
+
} | undefined;
|
|
122
|
+
ack?: (x: {
|
|
123
|
+
serverNow: string;
|
|
124
|
+
}) => void;
|
|
125
|
+
next: () => void;
|
|
126
|
+
};
|
|
127
|
+
export type SysServerPongHandlerArgs<Pong extends ZodType = ZodType> = {
|
|
128
|
+
name: 'sys:pong';
|
|
129
|
+
socket: Socket;
|
|
130
|
+
payload: NoInfer<z.infer<Pong>> | unknown;
|
|
131
|
+
next: () => void;
|
|
132
|
+
};
|
|
133
|
+
export type SysServerRoomHandlerArgs = {
|
|
134
|
+
name: 'sys:room_join' | 'sys:room_leave';
|
|
135
|
+
socket: Socket;
|
|
136
|
+
rooms: string[];
|
|
137
|
+
next: () => void;
|
|
138
|
+
};
|
|
139
|
+
export type SysServerEventMap<Ping extends ZodType = ZodType, Pong extends ZodType = ZodType> = {
|
|
140
|
+
'sys:connect'?: {
|
|
141
|
+
sysHandler: (args: SysServerConnectHandlerArgs) => void | Promise<void>;
|
|
142
|
+
};
|
|
143
|
+
'sys:disconnect'?: {
|
|
144
|
+
sysHandler: (args: SysServerDisconnectHandlerArgs) => void | Promise<void>;
|
|
145
|
+
};
|
|
146
|
+
'sys:ping'?: {
|
|
147
|
+
sysHandler: (args: SysServerPingHandlerArgs<Ping, Pong>) => void | Promise<void>;
|
|
148
|
+
};
|
|
149
|
+
'sys:pong'?: {
|
|
150
|
+
sysHandler: (args: SysServerPongHandlerArgs<Pong>) => void | Promise<void>;
|
|
151
|
+
};
|
|
152
|
+
'sys:room_join'?: {
|
|
153
|
+
sysHandler: (args: SysServerRoomHandlerArgs) => void | Promise<void>;
|
|
154
|
+
};
|
|
155
|
+
'sys:room_leave'?: {
|
|
156
|
+
sysHandler: (args: SysServerRoomHandlerArgs) => void | Promise<void>;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
102
159
|
export declare function createSocketConnections<Ping extends ZodType, Pong extends ZodType, T extends EventMap>(io: Server, events: T, opts?: {
|
|
103
160
|
debug?: SocketDebugOptions<Ping, Pong>;
|
|
104
161
|
rooms?: BuiltInRoomHooks;
|
|
105
162
|
heartbeat: HeartbeatServerOptions<Ping, Pong>;
|
|
163
|
+
/** NEW: system event customization (connect / disconnect / ping / pong / room join/leave) */
|
|
164
|
+
sys?: SysServerEventMap<Ping, Pong>;
|
|
106
165
|
}): SocketConnection<T>;
|
|
107
166
|
export type { EventMap, Payload };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emeryld/rrroutes-server",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@emeryld/rrroutes-contract": "^
|
|
20
|
+
"@emeryld/rrroutes-contract": "^2.0.3",
|
|
21
21
|
"jose": "^6.1.1",
|
|
22
22
|
"socket.io": "^4.8.1",
|
|
23
23
|
"zod": "^4.1.12"
|