From 27fadf173a9bbe73dd6fbbc6bd0ccd3ddac435e1 Mon Sep 17 00:00:00 2001 From: redhoodsu Date: Fri, 20 Sep 2024 15:52:08 +0800 Subject: [PATCH] chore: small changes --- server/lib/ChannelManager.js | 15 +++++++++++++-- server/lib/util.js | 11 ----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/server/lib/ChannelManager.js b/server/lib/ChannelManager.js index b4f4b175..9e3b414d 100644 --- a/server/lib/ChannelManager.js +++ b/server/lib/ChannelManager.js @@ -2,6 +2,7 @@ const Emitter = require('licia/Emitter'); const truncate = require('licia/truncate'); const ansiColor = require('licia/ansiColor'); const util = require('./util'); +const Channel = require('licia/Channel'); module.exports = class ChannelManager extends Emitter { constructor() { @@ -11,7 +12,7 @@ module.exports = class ChannelManager extends Emitter { this._clients = {}; } createTarget(id, ws, url, title, favicon, ip, userAgent) { - const channel = util.createChannel(ws); + const channel = createChannel(ws); util.log(`${ansiColor.yellow('target')} ${id}:${truncate(title, 10)} ${ansiColor.green('connected')}`); this._targets[id] = { @@ -39,7 +40,7 @@ module.exports = class ChannelManager extends Emitter { return ws.close(); } - const channel = util.createChannel(ws); + const channel = createChannel(ws); util.log( `${ansiColor.blue('client')} ${id} ${ansiColor.green('connected')} to target ${target.id}:${truncate( target.title, @@ -79,3 +80,13 @@ module.exports = class ChannelManager extends Emitter { return this._clients; } }; + +function createChannel(ws) { + const channel = new Channel(); + + ws.on('close', () => channel.destroy()); + ws.on('message', msg => channel.send(msg)); + channel.on('message', msg => ws.send(msg)); + + return channel; +} diff --git a/server/lib/util.js b/server/lib/util.js index 09efeaef..41f481e4 100644 --- a/server/lib/util.js +++ b/server/lib/util.js @@ -1,6 +1,5 @@ const dateFormat = require('licia/dateFormat'); const toArr = require('licia/toArr'); -const Channel = require('licia/Channel'); exports.log = function () { const args = toArr(arguments); @@ -9,13 +8,3 @@ exports.log = function () { console.log.apply(console, args); }; - -exports.createChannel = function (ws) { - const channel = new Channel(); - - ws.on('close', () => channel.destroy()); - ws.on('message', msg => channel.send(msg)); - channel.on('message', msg => ws.send(msg)); - - return channel; -};