transform server.js into an es6 class

This commit is contained in:
Romain Beaumont 2015-09-20 21:36:59 +02:00
parent 78ff667c1f
commit 6e399122bf

View file

@ -1,23 +1,20 @@
var net = require('net')
, EventEmitter = require('events').EventEmitter
, util = require('util')
, Client = require('./client')
, states = require('./transforms/serializer').states
;
var net = require('net');
var EventEmitter = require('events').EventEmitter;
var Client = require('./client');
var states = require('./transforms/serializer').states;
module.exports = Server;
function Server() {
EventEmitter.call(this);
class Server extends EventEmitter
{
constructor() {
super();
this.socketServer = null;
this.cipher = null;
this.decipher = null;
this.clients = {};
}
util.inherits(Server, EventEmitter);
}
Server.prototype.listen = function(port, host) {
listen(port, host) {
var self = this;
var nextId = 0;
self.socketServer = net.createServer();
@ -51,9 +48,9 @@ Server.prototype.listen = function(port, host) {
self.emit('listening');
});
self.socketServer.listen(port, host);
};
}
Server.prototype.close = function() {
close() {
var client;
for(var clientId in this.clients) {
if(!this.clients.hasOwnProperty(clientId)) continue;
@ -62,4 +59,7 @@ Server.prototype.close = function() {
client.end('ServerShutdown');
}
this.socketServer.close();
};
}
}
module.exports = Server;