Answer the question
In order to leave comments, you need to log in
How does this piece of js code work?
In one of the modules received from npm I saw this at the end
return this.on('camdata', function(data) {
return self.wsServer.broadcast(data);
});
};
VideoStream.prototype.pipeStreamToSocketServer = function() {
var self;
self = this;
this.wsServer = new ws.Server({
port: this.wsPort
});
this.wsServer.on("connection", function(socket) {
return self.onSocketConnect(socket);
});
this.wsServer.broadcast = function(data, opts) {
var i, results;
results = [];
for (i in this.clients) {
if (this.clients[i].readyState === 1) {
results.push(this.clients[i].send(data, opts));
} else {
results.push(console.log("Error: Client (" + i + ") not connected."));
}
}
return results;
};
return this.on('camdata', function(data) {
return self.wsServer.broadcast(data);
});
};
(function() {
var VideoStream;
VideoStream = require('./videoStream');
module.exports = VideoStream;
}).call(this);
VideoStream = function(options) {
this.name = options.name;
this.streamUrl = options.streamUrl;
this.width = options.width;
this.height = options.height;
this.wsPort = options.wsPort;
this.inputStreamStarted = false;
this.stream = void 0;
this.startMpeg1Stream();
this.pipeStreamToSocketServer();
return this;
};
Answer the question
In order to leave comments, you need to log in
But what does return this.on(...); ? If nothing, what's the point?
Returns a reference to the EventEmitter, so that calls can be chained
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question