Skip to content

Commit 27fadf1

Browse files
committed
chore: small changes
1 parent bdad810 commit 27fadf1

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

server/lib/ChannelManager.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Emitter = require('licia/Emitter');
22
const truncate = require('licia/truncate');
33
const ansiColor = require('licia/ansiColor');
44
const util = require('./util');
5+
const Channel = require('licia/Channel');
56

67
module.exports = class ChannelManager extends Emitter {
78
constructor() {
@@ -11,7 +12,7 @@ module.exports = class ChannelManager extends Emitter {
1112
this._clients = {};
1213
}
1314
createTarget(id, ws, url, title, favicon, ip, userAgent) {
14-
const channel = util.createChannel(ws);
15+
const channel = createChannel(ws);
1516

1617
util.log(`${ansiColor.yellow('target')} ${id}:${truncate(title, 10)} ${ansiColor.green('connected')}`);
1718
this._targets[id] = {
@@ -39,7 +40,7 @@ module.exports = class ChannelManager extends Emitter {
3940
return ws.close();
4041
}
4142

42-
const channel = util.createChannel(ws);
43+
const channel = createChannel(ws);
4344
util.log(
4445
`${ansiColor.blue('client')} ${id} ${ansiColor.green('connected')} to target ${target.id}:${truncate(
4546
target.title,
@@ -79,3 +80,13 @@ module.exports = class ChannelManager extends Emitter {
7980
return this._clients;
8081
}
8182
};
83+
84+
function createChannel(ws) {
85+
const channel = new Channel();
86+
87+
ws.on('close', () => channel.destroy());
88+
ws.on('message', msg => channel.send(msg));
89+
channel.on('message', msg => ws.send(msg));
90+
91+
return channel;
92+
}

server/lib/util.js

-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const dateFormat = require('licia/dateFormat');
22
const toArr = require('licia/toArr');
3-
const Channel = require('licia/Channel');
43

54
exports.log = function () {
65
const args = toArr(arguments);
@@ -9,13 +8,3 @@ exports.log = function () {
98

109
console.log.apply(console, args);
1110
};
12-
13-
exports.createChannel = function (ws) {
14-
const channel = new Channel();
15-
16-
ws.on('close', () => channel.destroy());
17-
ws.on('message', msg => channel.send(msg));
18-
channel.on('message', msg => ws.send(msg));
19-
20-
return channel;
21-
};

0 commit comments

Comments
 (0)