Skip to content

Commit

Permalink
feat(server): extend event emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
trs committed Feb 10, 2018
1 parent b07e018 commit 6ea6bac
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ const buyan = require('bunyan');
const net = require('net');
const tls = require('tls');
const fs = require('fs');
const EventEmitter = require('events');

const Connection = require('./connection');
const resolveHost = require('./helpers/resolve-host');

class FtpServer {
class FtpServer extends EventEmitter {
constructor(url, options = {}) {
super();
this.options = _.merge({
log: buyan.createLogger({name: 'ftp-srv'}),
anonymous: false,
Expand Down Expand Up @@ -47,9 +49,6 @@ class FtpServer {

this.server = (this.isTLS ? tls : net).createServer(serverOptions, serverConnectionHandler);
this.server.on('error', err => this.log.error(err, '[Event] error'));
this.on = this.server.on.bind(this.server);
this.once = this.server.once.bind(this.server);
this.listeners = this.server.listeners.bind(this.server);

process.on('SIGTERM', () => this.quit());
process.on('SIGINT', () => this.quit());
Expand Down Expand Up @@ -81,14 +80,10 @@ class FtpServer {
emitPromise(action, ...data) {
return new Promise((resolve, reject) => {
const params = _.concat(data, [resolve, reject]);
this.server.emit(action, ...params);
this.emit.call(this, action, ...params);
});
}

emit(action, ...data) {
this.server.emit(action, ...data);
}

setupTLS(_tls) {
if (!_tls) return false;
return _.assign({}, _tls, {
Expand Down

0 comments on commit 6ea6bac

Please sign in to comment.