UNPKG

@juzi/wechaty

Version:

Wechaty is a RPA SDK for Chatbot Makers.

82 lines 2.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Doctor = void 0; /** * Wechaty Chatbot SDK - https://github.com/wechaty/wechaty * * @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and * Wechaty Contributors <https://github.com/wechaty>. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ const net_1 = require("net"); const child_process_1 = require("child_process"); const wechaty_puppet_1 = require("@juzi/wechaty-puppet"); class Doctor { constructor() { wechaty_puppet_1.log.verbose('Doctor', 'constructor()'); } chromedriverVersion() { let version; try { const cmd = (0, child_process_1.spawnSync)('chromedriver', ['--version']); version = String(cmd.error) || cmd.stdout.toString() || cmd.stderr.toString(); } catch (e) { version = e.message; } return version; } /** * https://gist.github.com/tedmiston/5935757 */ testTcp() { wechaty_puppet_1.log.verbose('Doctor', 'testTcp()'); return new Promise((resolve, reject) => { /** * Server */ const server = (0, net_1.createServer)(socket => socket.pipe(socket)); /** * Promise Reject */ server.on('error', reject); server.on('close', () => wechaty_puppet_1.log.silly('Doctor', 'testTcp() server closed')); server.listen(8788, 'localhost', () => { /** * Client */ const client = new net_1.Socket(); client.connect(8788, 'localhost', () => { wechaty_puppet_1.log.silly('Doctor', 'testTcp() client connected'); client.write('ding'); }); client.on('data', () => { /** * Promise Resolve */ resolve(true); client.destroy(); // kill client after server's response }); /** * Promise Reject */ client.on('error', reject); client.on('close', () => server.close()); }); }); } } exports.Doctor = Doctor; //# sourceMappingURL=doctor.js.map