-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert: restore the socket middleware functionality
This functionality was removed in [1] (included in 3.0.0), but catch-all listeners and socket middleware features are complementary rather than mutually exclusive. The only difference with the previous implementation is that passing an error to the `next` handler will create an error on the server-side, and not on the client-side anymore. ```js io.on("connection", (socket) => { socket.use(([ event, ...args ], next) => { next(new Error("stop")); }); socket.on("error", (err) => { // to restore the previous behavior socket.emit("error", err); // or close the connection, depending on your use case socket.disconnect(true); }); }); ``` This creates additional possibilities about custom error handlers, which may be implemented in the future. ```js // user-defined error handler socket.use((err, [ event ], next) => { // either handle it socket.disconnect(); // or forward the error to the default error handler next(err); }); // default error handler socket.use((err, _, next) => { socket.emit("error", err); }); ``` Related: #3678 [1]: 5c73733
- Loading branch information
1 parent
170b739
commit bf54327
Showing
2 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters