-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (27 loc) · 974 Bytes
/
index.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
var express = require("express");
var translate = require("node-google-translate");
//var https = require('https'); // for Google API
var app = express();
var port = 3700;
var key = 'AIzaSyDuBr3MZJSXOHpUghzKaj2lkXjrXrwDvKE';
app.set('views', __dirname + '/tpl');
app.set('view engine', 'jade');
app.engine('jade', require('jade').__express);
app.use(express.static(__dirname + '/public'));
app.get("/", function(req, res) {
res.render('page');
});
var io = require('socket.io').listen(app.listen(port))
io.sockets.on('connection', function(socket) {
socket.emit('message', { message: 'welcome to the chat' });
socket.on('send', function(data) {
// Send the normal text to all clients
io.sockets.emit('message', data);
translate({key: key, q: data.message, target: 'fr'}, function(result){
console.log(result);
data.message = result[data.message];
io.sockets.emit('translate', data);
});
});
});
console.log("Listening on port " + port);