UNPKG

@iotize/cli

Version:
235 lines 14 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); require("@iotize/device-client.js/ext/configurator"); const device_client_js_1 = require("@iotize/device-client.js"); const clime_1 = require("clime"); const ui_1 = require("../../../ui"); const device_1 = require("../../options/device"); class MyOptions extends device_1.DeviceOptions { } __decorate([ clime_1.option({ default: false, toggle: true }), __metadata("design:type", Boolean) ], MyOptions.prototype, "showOnly", void 0); exports.MyOptions = MyOptions; let default_1 = class default_1 extends clime_1.Command { execute(options) { return __awaiter(this, void 0, void 0, function* () { const tap = yield options.getDevice(true, false, true); const isConfigured = yield tap.configurator.isConfigured(); if (isConfigured) { const configVersion = (yield tap.service.interface.getConfigVersion()).body(); ui_1.display.success(`✅ Tap is configured. Version: ${configVersion.major}.${configVersion.minor}.${configVersion.patch}`); } else { ui_1.display.warn(`❌ Tap is not configured.`); } if (!isConfigured && !options.showOnly) { yield tap.configurator.setupConfigState(); } const hostProtocols = (yield tap.service.interface.getAvailableHostProtocols()).body(); ui_1.display.infonl(`Detected protocols: ${hostProtocols.map(p => device_client_js_1.HostProtocol[p]).join(', ')}`); if (hostProtocols.indexOf(device_client_js_1.HostProtocol.WIFI) >= 0) { ui_1.display.message(`Tap has Wi-Fi capabilities`); const { ssid, wepKey, networkMode, hostname, ip, gatewayIp, ipMask } = yield ui_1.getBodys({ ssid: tap.service.interface.getWifiSSID(), wepKey: tap.service.interface.getWepKey(), networkMode: tap.service.interface.getNetworkMode(), ip: tap.service.interface.getNetworkInfraIp(), hostname: tap.service.interface.getWifiHostname(), ipMask: tap.service.interface.getNetworkInfraIpMask(), gatewayIp: tap.service.interface.getNetworkGatewayIp() }); const DHCP_IP = '0.0.0.0'; ui_1.display.table({ SSID: ssid, key: wepKey, mode: device_client_js_1.NetworkMode[networkMode], 'IP/hostname': hostname, DHCP: `${ip !== DHCP_IP ? `NO (${ip})` : 'YES'}`, mask: ipMask, 'Gateway IP': gatewayIp }); if (!options.showOnly && (yield ui_1.input.confirm(`Would you like to reconfigure the Wi-Fi ?`, true))) { const SSID = yield ui_1.input.string(`Enter the SSID (Wi-Fi network name)`, { default: ssid }); const password = yield ui_1.input.password(`Enter the Wi-Fi key`, { // default: wepKey }); const newNetworkMode = yield ui_1.input.enum(`Enter the network mode`, device_client_js_1.NetworkMode, networkMode); let ipAddress = DHCP_IP; if (newNetworkMode === device_client_js_1.NetworkMode.INFRASTRUCTURE_ONLY) { if (!(yield ui_1.input.confirm(`Let your Tap device assigns an IP addres (DHCP)?`, true))) { ipAddress = yield ui_1.input.ipv4(`Enter ip address ?`); } } (yield tap.service.interface.putWepKey(password)).successful(); (yield tap.service.interface.putWifiSSID(SSID)).successful(); (yield tap.service.interface.putNetworkMode(newNetworkMode)).successful(); (yield tap.service.interface.putNetworkInfraIp(ipAddress)).successful(); } } // const { securityOptions } = await getBodys({ // securityOptions: tap.service.interface.getLock() // }); // display.table({ encryption: securityOptions.scramActivated}); // if (await input.confirm(`Do you want to change security options ?`, true)) { // // let enableSecurity = await input.confirm(`Enable security`); // let newNfcPairingMode = await input.enum(`NFC pairing mode`, NfcPairingMode, nfcPairingMode); // // securityOptions.scramActivated = enableSecurity; // // (await tap.service.interface.putLock(securityOptions)).successful(); // (await tap.service.interface.putNfcPairingMode(newNfcPairingMode)).successful(); // } if (hostProtocols.indexOf(device_client_js_1.HostProtocol.NFC) >= 0) { const { nfcPriority, nfcPairingMode } = yield ui_1.getBodys({ nfcPriority: tap.service.interface.getNfcConnectionPriority(), nfcPairingMode: tap.service.interface.getNfcPairingMode() }); ui_1.display.table({ 'NFC pairing mode': device_client_js_1.NfcPairingMode[nfcPairingMode], 'NFC priority mode': device_client_js_1.NfcConnectionPriority[nfcPriority] }); if (!options.showOnly && (yield ui_1.input.confirm(`Do you want to change NFC options ?`, true))) { const newNfcPairingMode = yield ui_1.input.enum(`NFC pairing mode`, device_client_js_1.NfcPairingMode, nfcPairingMode); const newPriorityMode = yield ui_1.input.enum(`NFC priority mode`, device_client_js_1.NfcConnectionPriority, nfcPriority); (yield tap.service.interface.putNfcConnectionPriority(newPriorityMode)).successful(); (yield tap.service.interface.putNfcPairingMode(newNfcPairingMode)).successful(); } } const { appUrl, androidAppId, universalLink } = yield ui_1.getBodys({ appUrl: tap.service.interface.getAppUrl(), androidAppId: tap.service.interface.getAndroidApplicationId(), universalLink: tap.service.interface.getUniversalLink() }); ui_1.display.table({ 'App url': appUrl || 'NONE', 'Android application id': androidAppId, 'Univeral link (iOS)': universalLink }); if (!options.showOnly && (yield ui_1.input.confirm(`Do you want change mobile application config?`, true))) { if (yield ui_1.input.confirm(`Do you want to configure an Android application to launch when using NFC tag?`)) { const newAndroidAppId = yield ui_1.input.androidApplicationRecord(`What's your Android Application Record (AAR) identifier (Something like com.domain.appname)`, androidAppId); (yield tap.service.interface.putAndroidApplicationId(newAndroidAppId)).successful(); } else { } if (yield ui_1.input.confirm(`Do you want to configure an iOS application to launch when using NFC tag?`)) { const newUniversalLink = yield ui_1.input.url(`What's your univeral link ?`, universalLink); (yield tap.service.interface.putUniversalLink(newUniversalLink)).successful(); } else { } } const { inactivityPeriod, powerOptiLevel } = yield ui_1.getBodys({ inactivityPeriod: tap.service.interface.getHostInactivityPeriod(), powerOptiLevel: tap.service.interface.getPowerOptimisationLevel() }); ui_1.display.table({ 'Host inactivity period': `${inactivityPeriod} seconds(s)`, 'Power optimization level': `${device_client_js_1.LowPowerOptimisationLevel[powerOptiLevel]}` }); if (!options.showOnly && (yield ui_1.input.confirm(`Do you want change power options?`, true))) { const newInactivityPeriod = yield ui_1.input.number('Enter inactivity period ?', { default: inactivityPeriod, min: 1, max: 0xFF }); const newPowerOptiLevel = yield ui_1.input.enum('Enter power optimization level ?', device_client_js_1.LowPowerOptimisationLevel, powerOptiLevel); (yield tap.service.interface.putHostInactivityPeriod(newInactivityPeriod)).successful(); (yield tap.service.interface.putPowerOptimisationLevel(newPowerOptiLevel)).successful(); } if (!isConfigured) { const newVersion = yield ui_1.input.semanticVersion(`New config version`, { default: '1.0.0' }); yield tap.configurator.applyConfig(newVersion); } if (yield ui_1.input.confirm(`Your device need to restart to apply the new configuration. Do you want to restart now ?`, true)) { yield tap.service.device.reboot().catch(err => { if (process.env.DEBUG) { console.error(`Error code: ${err.code}, message: ${err.message}`, err); } // if (err instanceof Timeout) }); } yield tap.disconnect().catch(err => { }); }); } }; __decorate([ clime_1.metadata, __metadata("design:type", Function), __metadata("design:paramtypes", [MyOptions]), __metadata("design:returntype", Promise) ], default_1.prototype, "execute", null); default_1 = __decorate([ clime_1.command({ description: 'Tap configuration assistant' }) ], default_1); exports.default = default_1; function selectWifiNetwork() { return __awaiter(this, void 0, void 0, function* () { // wifi.scan(function (err, networks) { // if (err) { // console.log(err); // } else { // console.log(networks); // /* // networks = [ // { // ssid: '...', // bssid: '...', // mac: '...', // equals to bssid (for retrocompatibility) // channel: <number>, // frequency: <number>, // in MHz // signal_level: <number>, // in dB // quality: <number>, // same as signal level but in % // security: 'WPA WPA2' // format depending on locale for open networks in Windows // security_flags: '...' // encryption protocols (format currently depending of the OS) // mode: '...' // network mode like Infra (format currently depending of the OS) // }, // ... // ]; // */ // } // }); // List the current wifi connections // wifi.getCurrentConnections(function (err, currentConnections) { // if (err) { // console.log(err); // } // console.log(currentConnections); // /* // // you may have several connections // [ // { // iface: '...', // network interface used for the connection, not available on macOS // ssid: '...', // bssid: '...', // mac: '...', // equals to bssid (for retrocompatibility) // channel: <number>, // frequency: <number>, // in MHz // signal_level: <number>, // in dB // quality: <number>, // same as signal level but in % // security: '...' // // security_flags: '...' // encryption protocols (format currently depending of the OS) // mode: '...' // network mode like Infra (format currently depending of the OS) // } // ] // */ // }); }); } //# sourceMappingURL=assistant.js.map