I'm trying to associate each instance of a class with an event emitter. I'm trying the following:
const events = require("events");
const eventEmitter = new events.EventEmitter();
class Camera {
constructor(ip) {
this.ip = ip;
eventEmitter.on("recordVideo", function() {
this.recordClip();
});
}
recordClip() {
console.log("record " + this.ip);
}
}
var cam = new Camera("0.0.0.0");
eventEmitter.emit("recordVideo");
But I get back:
TypeError: this.recordClip is not a function
How can I have each instance of my class listen for the event?