forked from deStrO/eBot-CSGO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
websocket_relay.js
35 lines (28 loc) · 1.03 KB
/
websocket_relay.js
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
var http = require('http');
var udp_ip = process.argv[2];
var udp_port = process.argv[3];
var relay_ip = process.argv[4];
var relay_port = process.argv[5];
var server = http.createServer(function(request, response) {
});
server.listen(udp_port, function() {
console.log((new Date()) + ' Server is listening on port ' + udp_port);
});
var io = require('socket.io').listen(server);
io.set('log level', 0);
io.sockets.on('connection', function(socket) {
socket.on('identify', function(data) {
if (data.type === "alive") {
socket.join("alive");
} else if ((data.type === "livemap") && data.match_id) {
socket.join("livemap-" + data.match_id);
} else if (data.type === "matchs") {
socket.join("matchs");
}
});
});
var socketClient = require('socket.io-client').connect('http://' + relay_ip + ':' + relay_port);
socketClient.emit("identify", { type: "relay" });
socketClient.on('relay', function(datas) {
io.sockets.in(datas.channel).emit(datas.method, datas.content);
});