@@ -2,6 +2,7 @@ const Emitter = require('licia/Emitter');
2
2
const truncate = require ( 'licia/truncate' ) ;
3
3
const ansiColor = require ( 'licia/ansiColor' ) ;
4
4
const util = require ( './util' ) ;
5
+ const Channel = require ( 'licia/Channel' ) ;
5
6
6
7
module . exports = class ChannelManager extends Emitter {
7
8
constructor ( ) {
@@ -11,7 +12,7 @@ module.exports = class ChannelManager extends Emitter {
11
12
this . _clients = { } ;
12
13
}
13
14
createTarget ( id , ws , url , title , favicon , ip , userAgent ) {
14
- const channel = util . createChannel ( ws ) ;
15
+ const channel = createChannel ( ws ) ;
15
16
16
17
util . log ( `${ ansiColor . yellow ( 'target' ) } ${ id } :${ truncate ( title , 10 ) } ${ ansiColor . green ( 'connected' ) } ` ) ;
17
18
this . _targets [ id ] = {
@@ -39,7 +40,7 @@ module.exports = class ChannelManager extends Emitter {
39
40
return ws . close ( ) ;
40
41
}
41
42
42
- const channel = util . createChannel ( ws ) ;
43
+ const channel = createChannel ( ws ) ;
43
44
util . log (
44
45
`${ ansiColor . blue ( 'client' ) } ${ id } ${ ansiColor . green ( 'connected' ) } to target ${ target . id } :${ truncate (
45
46
target . title ,
@@ -79,3 +80,13 @@ module.exports = class ChannelManager extends Emitter {
79
80
return this . _clients ;
80
81
}
81
82
} ;
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
+ }
0 commit comments