1+
2+ declare 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 } ;
27+
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 ;
33+
34+ /** Response time metric tags. */
35+ tags ?: { [ name : string ] : string } ;
36+ } ;
37+ }
38+
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 {
47+ /**
48+ * Register an event handler (Socket.IO version)
49+ * Overrides the original k6/ws on() method
50+ *
51+ * @param event - Event name ("connect", "disconnect", or custom event)
52+ * @param handler - Handler function that receives event data
53+ */
54+ on ( event : string , handler : ( data ?: any ) => void ) : void ;
55+
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 ;
63+
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 ;
71+
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+ }
82+
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 ;
107+
108+ export { io , Socket , SocketIOOptions } ;
109+ }
110+
111+ declare module "xk6-socketio" {
112+ import { io , Socket , SocketIOOptions } from "k6/x/socketio" ;
113+ export { io , Socket , SocketIOOptions } ;
114+ }
0 commit comments