1
0
mirror of https://github.com/eleith/emailjs.git synced 2024-07-05 20:10:37 +00:00

fix socket types

This commit is contained in:
Zack Schuster 2018-07-06 13:21:43 -07:00
parent 60a98f1155
commit 0ca71c4c9c

View File

@ -1,10 +1,14 @@
const SMTPError = require('./error'); const SMTPError = require('./error');
const { TLSSocket } = require('tls');
/**
* @typedef {import('net').Socket} Socket
* @typedef {import('tls').TLSSocket} TLSSocket
*/
class SMTPResponse { class SMTPResponse {
/** /**
* @constructor * @constructor
* @param {NodeJS.Socket | TLSSocket} stream the open socket to stream a response from * @param {Socket | TLSSocket} stream the open socket to stream a response from
* @param {number} timeout the time to wait (in milliseconds) before closing the socket * @param {number} timeout the time to wait (in milliseconds) before closing the socket
* @param {function(Error): void} onerror the function to call on error * @param {function(Error): void} onerror the function to call on error
*/ */
@ -105,32 +109,28 @@ class SMTPResponse {
*/ */
this.stop = err => { this.stop = err => {
stream.removeAllListeners('response'); stream.removeAllListeners('response');
if (stream instanceof TLSSocket) { stream.removeListener('data', watch);
stream.removeListener('data', watch); stream.removeListener('end', end);
stream.removeListener('end', end); stream.removeListener('close', close);
stream.removeListener('close', close); stream.removeListener('error', error);
stream.removeListener('error', error);
}
if (err != null && typeof onerror === 'function') { if (err != null && typeof onerror === 'function') {
onerror(err); onerror(err);
} }
}; };
if (stream instanceof TLSSocket) { stream.on('data', watch);
stream.on('data', watch); stream.on('end', end);
stream.on('end', end); stream.on('close', close);
stream.on('close', close); stream.on('error', error);
stream.on('error', error); stream.setTimeout(timeout, timedout);
stream.setTimeout(timeout, timedout);
}
} }
} }
exports.SMTPResponse = SMTPResponse; exports.SMTPResponse = SMTPResponse;
/** /**
* @param {NodeJS.Socket | TLSSocket} stream the open socket to stream a response from * @param {Socket | TLSSocket} stream the open socket to stream a response from
* @param {number} timeout the time to wait (in milliseconds) before closing the socket * @param {number} timeout the time to wait (in milliseconds) before closing the socket
* @param {function(Error): void} onerror the function to call on error * @param {function(Error): void} onerror the function to call on error
* @returns {SMTPResponse} the smtp response * @returns {SMTPResponse} the smtp response