Within a package, change the client object from the server


#1

I have a package that is pretty simple. It has a server.es6, client.es6, and common.es6, and exports a single object called Cylon to the client and server.

The following in my server will open two socket connections and change the state of the object on the server

let Cylon = {};
Cylon._connected = false;

function setConnectionStatus (socket, event) {
  socket._connected = event === 'connect';
  this._connected = this._messages.connected && this._commands._connected;
  this._connected ? this.emit('connect') : this.emit('close');
}

Cylon._commands = net.connect(process.env.CONNECTION);
Cylon._messages = net.connect(process.env.CONNECTION);

Cylon._messages.addListener('connect', setConnectionStatus.bind(Cylon, Cylon._messages, 'connect'));
Cylon._commands.addListener('connect', setConnectionStatus.bind(Cylon, Cylon._commands, 'connect'));
Cylon._messages.addListener('close', setConnectionStatus.bind(Cylon, Cylon._messages, 'close'));
Cylon._commands.addListener('close', setConnectionStatus.bind(Cylon, Cylon._commands, 'close'));

But how can I publish the change to Cylon._connected to the client object?