Skip to content

Commit

Permalink
Accept options object in MqttSecureServer
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Rudd committed Nov 23, 2013
1 parent a41fa1d commit 356da39
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/server.js
Expand Up @@ -36,21 +36,25 @@ util.inherits(MqttServer, net.Server);
/**
* MqttSecureServer
*
* @param {String} privateKeyPath
* @param {String} publicCertPath
* @param {Object} opts - server options
* @param {Function} listener
*/
var MqttSecureServer = module.exports.MqttSecureServer =
function SecureServer(keyPath, certPath, listener) {
function SecureServer (opts, listener) {
if (!(this instanceof SecureServer)) {
return new SecureServer(listener);
return new SecureServer(listener, opts);
}

// new MqttSecureServer(function(){})
if ('function' === typeof opts) {
listener = opts;
opts = {};
}

var self = this;

tls.Server.call(self, {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath)
});
tls.Server.call(self, opts);

if (listener) {
self.on('client', listener);
}
Expand Down

0 comments on commit 356da39

Please sign in to comment.