mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
[@types/socket.io] fix: socket.use (#24574)
This commit is contained in:
22
types/socket.io/index.d.ts
vendored
22
types/socket.io/index.d.ts
vendored
@@ -474,6 +474,21 @@ declare namespace SocketIO {
|
||||
compress( compress: boolean ): Namespace;
|
||||
}
|
||||
|
||||
interface Packet extends Array<any> {
|
||||
/**
|
||||
* Event name
|
||||
*/
|
||||
[0]: string;
|
||||
/**
|
||||
* Packet data
|
||||
*/
|
||||
[1]: any;
|
||||
/**
|
||||
* Ack function
|
||||
*/
|
||||
[2]: (...args: any[]) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* The socket, which handles our connection for a namespace. NOTE: while
|
||||
* we technically extend NodeJS.EventEmitter, we're not putting it here
|
||||
@@ -612,6 +627,13 @@ declare namespace SocketIO {
|
||||
*/
|
||||
in( room: string ): Socket;
|
||||
|
||||
/**
|
||||
* Registers a middleware, which is a function that gets executed for every incoming Packet and receives as parameter the packet and a function to optionally defer execution to the next registered middleware.
|
||||
*
|
||||
* Errors passed to middleware callbacks are sent as special error packets to clients.
|
||||
*/
|
||||
use( fn: ( packet: Packet, next: (err?: any) => void ) => void ): Socket;
|
||||
|
||||
/**
|
||||
* Sends a 'message' event
|
||||
* @see emit( event, ...args )
|
||||
|
||||
@@ -180,3 +180,12 @@ function testVolatileServerMessages() {
|
||||
var io = socketIO.listen(80);
|
||||
io.volatile.emit('volatile', 'Lost data');
|
||||
}
|
||||
|
||||
function testSocketUse() {
|
||||
var io = socketIO.listen(80);
|
||||
io.on('connection', (socket) => {
|
||||
socket.use((packet, next) => {
|
||||
console.log(packet);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user