-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
81 lines (61 loc) · 2.52 KB
/
Copy pathserver.js
File metadata and controls
81 lines (61 loc) · 2.52 KB
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
74
75
76
77
78
79
80
81
/**
* A simple webserver serving the interface
*
*/
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var process = require('process');
// conf = require('./config.json');
var uuid = require('node-uuid');
var debug = require('debug');
var debuglog = debug('server');
var botdialog = require('./gen/bot/smartdialog.js');
//var botdialog = require('./gen/bot/dialog.js');
var htmlconnector = require('./gen/ui/htmlconnector.js');
// Create bot and bind to console
var connector = new htmlconnector.HTMLConnector();
botdialog.makeBot(connector);
//botdialog.makeBot(connector);
app.use(express.static(__dirname + '/public'));
app.get('/', function (req, res) {
res.sendfile(__dirname + '/public/index.html');
});
server.listen(process.env.PORT || 42043);
io.sockets.on('connection', function (socket) {
var id = uuid.v4().toString(); // '' + Date.now();
socket.id = id; //uuid.v4();// id;
console.log('Client connected' + Object.keys(io.clients).join(' '));
// console.log('Got answer : ' + sAnswer + '\n');
// not now htmlconnector.startConversation({ id : id } , function() {});
connector.setAnswerHook(function (sAnswer, oCommand, sId) {
debuglog('sending answer for ' + sId + ' to ' + id + ' > ' + sAnswer);
socket.emit('wosap',{ time : new Date(),
name : 'unknown' ,
command : oCommand,
text : sAnswer
});
}, id);
//socket.emit('register', { id : id });
// io.clients(0).send('chat' ,{ time : new Date(), name : 'HUGO', text: 'something'});
socket.on('disconnect', () => {
console.log('Client disconnected'); });
// der Client ist verbunden
socket.emit('wosap', { time : new Date(), text: 'Indicate your query or wish:' });
console.log('got a message from ' + id);
// wenn ein Benutzer einen Text senden
socket.on('wosap', function (data) {
// so wird dieser Text an alle anderen Benutzer gesendet
debuglog('another request from ' + id + ' ' + data.text);
connector.processMessage(data.text, id);
// echo request:
// socket.emit('chat', { time : new Date(), name: data.name || 'Anonym', text: data.text
// + ' nr clients : ' +
// + Object.keys(io.sockets.connected).length
// });
// io.sockets.emit('chat' , { data : 'someone else is talking' + id , name : id });
// io.sockets.connected[Object.keys(io.sockets.connected)[0]].emit('chat', {time : new Date(), name : 'curosr',
// text : ' you are ' + Object.keys(io.sockets.connected)[0]});
});
});