UNPKG

huawei-wingle-4g

Version:

This is a module NodeJS allowing to drive Huawei Wingle 4G. This module can :

55 lines 2.84 kB
"use strict"; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const log4js_1 = __importDefault(require("log4js")); const StringUtils_1 = require("../../utils/StringUtils"); class default_1 { constructor(connection) { this.connection = connection; this.logger = log4js_1.default.getLogger(StringUtils_1.substringAfter(__filename, 'huawei-wingle-4g')); } activeLog(activeLog) { this.logger.level = activeLog ? 'debug' : 'OFF'; this.connection.activeLog(activeLog); } getCurrentConnection() { var _a, _b, _c; return __awaiter(this, void 0, void 0, function* () { yield this.connection.openHomePage(); const response = yield this.connection.get('/api/monitoring/traffic-statistics'); const document = response.document; const rawReceived = (_a = document.querySelector('CurrentDownload')) === null || _a === void 0 ? void 0 : _a.textContent; if (!rawReceived) { throw new Error('Unable to retrieve received data'); } const rawSent = (_b = document.querySelector('CurrentUpload')) === null || _b === void 0 ? void 0 : _b.textContent; if (!rawSent) { throw new Error('Unable to retrieve sent data'); } const rawDuration = (_c = document.querySelector('CurrentConnectTime')) === null || _c === void 0 ? void 0 : _c.textContent; if (!rawDuration) { throw new Error('Unable to retrieve duration data'); } const received = +rawReceived; this.logger.debug(`Received : ${rawReceived}`); const sent = +rawSent; this.logger.debug(`Sent : ${rawSent}`); const duration = +rawDuration * 1000; this.logger.debug(`Duration : ${duration}`); return { received, sent, duration }; }); } } exports.default = default_1; //# sourceMappingURL=CurrentConnectionExtractor.js.map