-
Notifications
You must be signed in to change notification settings - Fork 1
/
tt2http.js
73 lines (66 loc) · 1.76 KB
/
tt2http.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
// The real TeamTalk client.
var TeamTalk = require('./tt/tt.js');
var tt = new TeamTalk("172.18.0.236", 8000);
tt.connect();
var logedin = function(){
console.log('logedin');
tt.list('buddies');
tt.list('departments');
tt.list('groups');
}
tt.login('test', 'pl,okm123');
tt.on('message', function(message){
if(message.service == 0x001){ //login
if(message.command == 0x104){
logedin();
}
}else if(message.service == 0x002){ ///buddy
if(message.command == 0x209){ ///user list
console.log(message);
}else if(message.command == 0x211){ ///departments
console.log(message);
}
}else if(message.service == 0x004){ ///group
if(message.command == 0x402){ ///normal list
console.log(message);
}
}
});
tt.on('closed', function(){});
*/
var http = require("http");
var server = http.createServer(function(req, res) {
res.writeHead(500, {"Content-Type": "text/html"});
res.end("NEVER DO THIS");
});
server.listen(8081);
server.on("listening", function() {
console.log("Server started");
});
server.on("error", function(err) {
console.log("Failed to start server:", err);
process.exit(1);
});
//Web Socket adapter to receive message from web pages.
var ws = require("ws");
var wss = new ws.Server({server: server});
wss.on("connection", function(socket) {
console.log("New WebSocket connection");
socket.on("close", function() {
console.log("WebSocket disconnected");
});
socket.on("message", function(data, flags) {
if (flags.binary) {
try {
socket.send(data);
console.log("Sent: " + data);
} catch (err) {
console.log("Processing failed:", err);
}
} else {
console.log("Not binary data");
socket.send("HEY");
}
});
});