1-
21declare module "k6/x/socketio" {
3- interface SocketIOOptions {
4- /**
5- * Socket.IO path (default: "/socket.io/")
6- */
7- path ?: string ;
8- /**
9- * Namespace to connect to (default: "/")
10- * Example: "/chat"
11- */
12- namespace ?: string ;
13- /**
14- * Auth payload sent in the connect packet
15- */
16- auth ?: Record < string , any > ;
17- /**
18- * Query parameters appended to the URL
19- */
20- query ?: Record < string , any > ;
21- /**
22- * Passed directly to k6/ws.connect
23- */
24- params ?: {
25- /** Request headers. */
26- headers ?: { [ name : string ] : string } ;
2+ interface SocketIOOptions {
3+ /**
4+ * Socket.IO path (default: "/socket.io/")
5+ */
6+ path ?: string ;
7+ /**
8+ * Namespace to connect to (default: "/")
9+ * Example: "/chat"
10+ */
11+ namespace ?: string ;
12+ /**
13+ * Auth payload sent in the connect packet
14+ */
15+ auth ?: Record < string , any > ;
16+ /**
17+ * Query parameters appended to the URL
18+ */
19+ query ?: Record < string , any > ;
20+ /**
21+ * Passed directly to k6/ws.connect
22+ */
23+ params ?: {
24+ /** Request headers. */
25+ headers ?: { [ name : string ] : string } ;
2726
28- /**
29- * Compression algorithm. The only supported algorithm is `deflate`.
30- * If the option is left unset or empty, it defaults to no compression.
31- */
32- compression ?: string ;
27+ /**
28+ * Compression algorithm. The only supported algorithm is `deflate`.
29+ * If the option is left unset or empty, it defaults to no compression.
30+ */
31+ compression ?: string ;
3332
34- /** Response time metric tags. */
35- tags ?: { [ name : string ] : string } ;
36- } ;
37- }
33+ /** Response time metric tags. */
34+ tags ?: { [ name : string ] : string } ;
35+ } ;
36+ }
3837
39- /**
40- * Socket.IO socket wrapper
41- *
42- * Provides Socket.IO-like API on top of k6/ws WebSocket connection.
43- * Socket.IO-specific methods (on, emit, send) override the original k6/ws methods.
44- * All other k6/ws socket methods are available as-is via the wrapper.
45- */
46- interface Socket {
4738 /**
39+ * Socket.IO socket wrapper
40+ *
41+ * Provides Socket.IO-like API on top of k6/ws WebSocket connection.
42+ * Socket.IO-specific methods (on, emit, send) override the original k6/ws methods.
43+ * All other k6/ws socket methods are available as-is via the wrapper.
44+ */
45+ interface Socket {
46+ /**
4847 * Register an event handler (Socket.IO version)
4948 * Overrides the original k6/ws on() method
5049 *
5150 * @param event - Event name ("connect", "disconnect", or custom event)
5251 * @param handler - Handler function that receives event data
5352 */
54- on ( event : string , handler : ( data ?: any ) => void ) : void ;
53+ on ( event : string , handler : ( data ?: any ) => void ) : void ;
5554
56- /**
57- * Emit an event to the server (Socket.IO specific)
58- *
59- * @param event - Event name
60- * @param data - Optional data to send with the event
61- */
62- emit ( event : string , data ?: any ) : void ;
55+ /**
56+ * Emit an event to the server (Socket.IO specific)
57+ *
58+ * @param event - Event name
59+ * @param data - Optional data to send with the event
60+ */
61+ emit ( event : string , data ?: any ) : void ;
6362
64- /**
65- * Send data (Socket.IO version - alias for emit("message", data))
66- * Overrides the original k6/ws send() method
67- *
68- * @param data - Data to send
69- */
70- send ( data : any ) : void ;
63+ /**
64+ * Send data (Socket.IO version - alias for emit("message", data))
65+ * Overrides the original k6/ws send() method
66+ *
67+ * @param data - Data to send
68+ */
69+ send ( data : any ) : void ;
7170
72- /**
73- * Close connection.
74- * https://grafana.com/docs/k6/latest/javascript-api/k6-ws/socket/socket-close/
75- *
76- * @param code - WebSocket status code.
77- * @example
78- * socket.close();
79- */
80- close ( code ?: number ) : void ;
81- }
71+ /**
72+ * Close connection.
73+ * https://grafana.com/docs/k6/latest/javascript-api/k6-ws/socket/socket-close/
74+ *
75+ * @param code - WebSocket status code.
76+ * @example
77+ * socket.close();
78+ */
79+ close ( code ?: number ) : void ;
80+ }
8281
83- /**
84- * Connect to a Socket.IO server
85- *
86- * @param host - Base URL such as "http://localhost:4000" or "wss://example.com"
87- * @param options - Optional configuration
88- * @param handler - Optional callback function called with a Socket.IO-like socket wrapper
89- * @returns The underlying k6/ws.connect result
90- *
91- * @example
92- * ```typescript
93- * import { io } from "k6/x/socketio";
94- *
95- * io("http://localhost:4000", {}, (socket) => {
96- * socket.on("connect", () => {
97- * socket.emit("hello", { payload: "hi from k6" });
98- * });
99- * });
100- * ```
101- */
102- function io (
103- host : string ,
104- options ?: SocketIOOptions ,
105- handler ?: ( socket : Socket ) => void
106- ) : any ;
82+ /**
83+ * Connect to a Socket.IO server
84+ *
85+ * @param host - Base URL such as "http://localhost:4000" or "wss://example.com"
86+ * @param options - Optional configuration
87+ * @param handler - Optional callback function called with a Socket.IO-like socket wrapper
88+ * @returns The underlying k6/ws.connect result
89+ *
90+ * @example
91+ * ```typescript
92+ * import { io } from "k6/x/socketio";
93+ *
94+ * io("http://localhost:4000", {}, (socket) => {
95+ * socket.on("connect", () => {
96+ * socket.emit("hello", { payload: "hi from k6" });
97+ * });
98+ * });
99+ * ```
100+ */
101+ function io (
102+ host : string ,
103+ options ?: SocketIOOptions ,
104+ handler ?: ( socket : Socket ) => void ,
105+ ) : any ;
107106
108- export { io , Socket , SocketIOOptions } ;
107+ export { io , Socket , SocketIOOptions } ;
109108}
110109
111110declare module "xk6-socketio" {
112- import { io , Socket , SocketIOOptions } from "k6/x/socketio" ;
113- export { io , Socket , SocketIOOptions } ;
114- }
111+ import { io , Socket , SocketIOOptions } from "k6/x/socketio" ;
112+ export { io , Socket , SocketIOOptions } ;
113+ }
0 commit comments