node-hue-api
Version:
Philips Hue API Library for Node.js
42 lines (41 loc) • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalInsecureBootstrap = void 0;
const Transport_1 = require("./Transport");
const Api_1 = require("../Api");
const HttpClientFetch_1 = require("./HttpClientFetch");
const urlUtil_1 = require("./urlUtil");
const SUPPRESS_WARNING = process.env.NODE_HUE_API_USE_INSECURE_CONNECTION != null;
class LocalInsecureBootstrap {
constructor(hostname, rateLimits, port) {
this.baseUrl = (0, urlUtil_1.getHttpUrl)(hostname, port || 80);
this.hostname = hostname;
this.rateLimits = rateLimits;
}
connect(username, clientkey, timeout) {
const baseUrl = this.baseUrl, rateLimits = this.rateLimits;
if (!SUPPRESS_WARNING) {
console.log('WARNING: You are using this library in an insecure way!\n'
+ 'The Hue bridge supports HTTPS connections locally and it is highly recommended that you use an HTTPS\n'
+ 'method to communicate with the bridge.');
}
return (0, HttpClientFetch_1.request)({ method: 'GET', url: `${baseUrl.href}api/config` })
.then(() => {
const apiBaseUrl = `${baseUrl.href}api`, fetchConfig = {
baseURL: apiBaseUrl,
timeout: getTimeout(timeout)
}, transport = new Transport_1.Transport((0, HttpClientFetch_1.create)(fetchConfig), rateLimits.transportRateLimit, username), config = {
remote: false,
baseUrl: apiBaseUrl,
bridgeName: this.hostname,
clientKey: clientkey,
username: username,
};
return new Api_1.Api(config, transport, rateLimits);
});
}
}
exports.LocalInsecureBootstrap = LocalInsecureBootstrap;
function getTimeout(timeout) {
return timeout || 20000;
}