]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - apps/tidep0084.git/blob - example/iot-gateway/node_modules/aws-iot-device-sdk/node_modules/mqtt/lib/connect/tls.js
Updated to use the latest TI 15.4-Stack v2.1.0 from the SimpleLink CC13x0 SDK v1.30.
[apps/tidep0084.git] / example / iot-gateway / node_modules / aws-iot-device-sdk / node_modules / mqtt / lib / connect / tls.js
1 'use strict';
2 var tls = require('tls');
4 function buildBuilder (mqttClient, opts) {
5   var connection;
6   opts.port = opts.port || 8883;
7   opts.host = opts.hostname || opts.host || 'localhost';
9   opts.rejectUnauthorized = false !== opts.rejectUnauthorized;
11   connection = tls.connect(opts);
12   /*eslint no-use-before-define: [2, "nofunc"]*/
13   connection.on('secureConnect', function () {
14     if (opts.rejectUnauthorized && !connection.authorized) {
15       connection.emit('error', new Error('TLS not authorized'));
16     } else {
17       connection.removeListener('error', handleTLSerrors);
18     }
19   });
21   /*
22    * to comply with strict rules, a function must be
23    * declared before it can be used
24    * so i moved it has to be  moved before its first call
25    * later on maybe we can move all of them to the top of the file
26    * for now i just suppressed the warning
27    */
28   /*jshint latedef:false*/
29   function handleTLSerrors (err) {
30     // How can I get verify this error is a tls error?
31     if (opts.rejectUnauthorized) {
32       mqttClient.emit('error', err);
33     }
35     // close this connection to match the behaviour of net
36     // otherwise all we get is an error from the connection
37     // and close event doesn't fire. This is a work around
38     // to enable the reconnect code to work the same as with
39     // net.createConnection
40     connection.end();
41   }
42   /*jshint latedef:false*/
44   connection.on('error', handleTLSerrors);
45   return connection;
46 }
48 module.exports = buildBuilder;