Basic application in meteor. Have my own package which is very much more node based and server-side only.
let Socket = Npm.require('net').Socket;
let EventEmitter = Npm.require('events').EventEmitter;
class CylonSocket extends Socket {
constructor(name, host, port) {
// unimportant details
this._bindEvents();
this.connect(host, port);
}
_bindEvents() {
// take the incoming data, parse it to human readable, then console.log() it.
this.on('data', Meteor.bindEnvironment(this._parseData));
}
}
class Cylon {
constructor(host, port) {
this._messages = new CylonSocket('messages', host, port);
this._commands = new CylonSocket('commands', host, port);
// ... unimportant details again
this._messages.on('connect', Meteor.bindEnvironment(() => {
this._commands.on('connect', Meteor.bindEnvironment(() => {
console.log('Both sockets successfully connected');
this.emit('connect');
}));
}));
}
}
I’m running across a few problems in using this Node-like application with meteor.
- How do I delay the launching of the application until the sockets are bound?
- How can I write the data from my sockets to my client?
Essentially, whenever a message is written to the socket, I just want to throw it over to the client to write on the dom. The most obvious way is to create a collection that is written to, but that’s a lot of writing and the data doesn’t need to be persistent.
Meteor seems to have this “baked in”, but how can it be accessed?