socket.on("details", (...args) => {
// ...
});
socket.once("details", (...args) => {
// ...
});
const listener = (...args) => {
console.log(args);
}
socket.on("details", listener);
// and then later...
socket.off("details", listener);
// for a specific event
socket.removeAllListeners("details");
// for all events
socket.removeAllListeners();
socket.onAny((eventName, ...args) => {
// ...
});
socket.prependAny((eventName, ...args) => {
// ...
});
const listener = (eventName, ...args) => {
console.log(eventName, args);
}
socket.onAny(listener);
// and then later...
socket.offAny(listener);
// or all listeners
socket.offAny();
io.on("connection", (socket) => {
socket.on("list items", async (callback) => {
try {
const items = await findItems();
callback({
status: "OK",
items
});
} catch (e) {
callback({
status: "NOK"
});
}
});
});