UNPKG

chattervox

Version:

An AX.25 packet radio chat protocol with support for digital signatures and binary compression. Like IRC over radio waves 📡〰.

91 lines • 3.46 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const util_1 = require("util"); const child_process_1 = require("child_process"); const command_exists_1 = require("command-exists"); const exists = command_exists_1.sync('direwolf'); // quiet the decoding of APRS packets const path = 'direwolf'; const args = ['-p', '-q', 'd', '-t', '0']; let proc = null; // export interface OnError { (error: Error): void } // export interface OnExit { (code: number): void } // export interface OnClose { (code: number): void } // export let onError: OnError = function() {} // export let onExit: OnExit = function() {} // export let onClose: OnClose = function() {} function installed(direwolfPath) { return typeof direwolfPath === 'undefined' ? exists : command_exists_1.sync(direwolfPath); } exports.installed = installed; function running(direwolfPath) { return __awaiter(this, void 0, void 0, function* () { if (typeof direwolfPath === 'undefined' && proc) return !proc.killed; const platform = process.platform; const query = direwolfPath || 'direwolf'; let cmd = ''; switch (platform) { case 'win32': cmd = `tasklist`; break; case 'darwin': cmd = `ps -ax | grep ${query}`; break; case 'linux': cmd = `ps -A`; break; default: break; } const { stdout } = yield util_1.promisify(child_process_1.exec)(cmd); return stdout.toLowerCase().indexOf(query.toLowerCase()) > -1; }); } exports.running = running; function start(direwolfPath) { return __awaiter(this, void 0, void 0, function* () { const isUp = yield running(direwolfPath); if (isUp || proc) return; else { if (!installed(direwolfPath)) throw Error(`${direwolfPath} is not installed`); proc = child_process_1.spawn(direwolfPath || path, args); // proc.on('error', onError) // proc.on('exit', onExit) // proc.on('close', onClose) } }); } exports.start = start; /** * Kill a process that was launched with start() */ function kill() { return __awaiter(this, void 0, void 0, function* () { const promise = new Promise((resolve, reject) => { if (proc) { proc.on('close', () => { proc = null; resolve(); }); proc.on('error', reject); proc.kill(); } else { reject(TypeError('The process object is null. Cannot kill null process.')); } }); return promise; }); } exports.kill = kill; //# sourceMappingURL=DirewolfManager.js.map