Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding all connection options #39

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ const lineDelimiter = new RegExp('\r\n|\r|\n');

const MIN_DELAY_MS = 33;

function Client(server, nick, opt) {
function Client(server, nick, opt = {}) {
const self = this;
/**
* This promise is used to block new sends until the previous one completes.
*/
this.sendingPromise = Promise.resolve();
this.lastSendTime = 0;
self.opt = {
self.opt = { // default options
server: server,
nick: nick,
password: null,
Expand All @@ -60,6 +60,7 @@ function Client(server, nick, opt) {
secure: false,
selfSigned: false,
certExpired: false,
customConnectionOpts: {},
floodProtection: false,
floodProtectionDelay: 1000,
sasl: false,
Expand Down Expand Up @@ -87,14 +88,8 @@ function Client(server, nick, opt) {
}
};

if (typeof opt == 'object') {
const keys = Object.keys(opt);
for (let i = 0; i < keys.length; i++) {
var k = keys[i];
if (opt[k] !== undefined)
self.opt[k] = opt[k];
}
}
// Merge default options with user-supplied options
Object.assign(self.opt, opt)
Half-Shot marked this conversation as resolved.
Show resolved Hide resolved

// Features supported by the server
// (initial values are RFC 1459 defaults. Zeros signify
Expand Down Expand Up @@ -856,12 +851,14 @@ Client.prototype.connect = function(retryCount, callback) {
if (self.opt.secure) {
connectionOpts.rejectUnauthorized = !self.opt.selfSigned;

if (typeof self.opt.secure == 'object') {
// copy "secure" opts to options passed to connect()
for (var f in self.opt.secure) {
connectionOpts[f] = self.opt.secure[f];
}
}
// if (typeof self.opt.secure == 'object') {
Half-Shot marked this conversation as resolved.
Show resolved Hide resolved
// // copy "secure" opts to options passed to connect()
// for (var f in self.opt.secure) {
// connectionOpts[f] = self.opt.secure[f];
// }
// }

Object.assign(connectionOpts, self.opt.customConnectionOpts);

if (self.opt.bustRfc3484) {
// tls.connect on its own doesn't allow you to attach a custom lookup function, meaning we cannot
Expand Down
11 changes: 6 additions & 5 deletions test/test-irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ function runTests(t, isSecure, useSecureObject) {
var client;
if (isSecure && useSecureObject) {
client = new irc.Client('notlocalhost', 'testbot', {
secure: {
host: 'localhost',
port: port,
rejectUnauthorized: false
},
secure: true,
// {
Half-Shot marked this conversation as resolved.
Show resolved Hide resolved
// host: 'localhost',
// port: port,
// rejectUnauthorized: false
// },
selfSigned: true,
retryCount: 0,
debug: true
Expand Down