-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelay.js
More file actions
38 lines (29 loc) · 684 Bytes
/
relay.js
File metadata and controls
38 lines (29 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const readline = require('readline');
const fs = require('fs');
const WebSocket = require('ws');
require('./common');
process.stdout.setEncoding('utf-8');
var buffer = [];
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('line', function(line){
buffer.push(line);
});
var ws_connect = 'ws://127.0.0.1:' + relay_internal_port;
const ws = new WebSocket(ws_connect);
ws.on('message', function(message) {
process.stdout.write(message);
rl.question('', function(line){
ws.send(line);
});
});
ws.on('open', function() {
setTimeout(function() {
buffer.forEach(function(line){
ws.send(line);
});
buffer = [];
}, 200);
});