'Callback function in node.js and socket.io
I need to fire a callback of a function at a specific time, in the index.js (at server side). My problem is that the callback seams to be able to pass only variables but not an entire function. I need to have scope on the entire socket instance to disconnect a specific socket at a specific time.
//index.js (Node.js + socketIO)
let chat = require(chat.js)
let c = new Chat
//Various socketio strings
c.on("example",function(data){
if(socket.id === data){
socket.disconnect()
}
})
//chat.js
class Chat{
events = {};
on(event,callback){
this.events[event] = callback
}
function disconnect(){
if(this.events.example){
this.events.example("example sockeetid")
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
