-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (38 loc) · 1.22 KB
/
server.js
File metadata and controls
49 lines (38 loc) · 1.22 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
require('./src/constants');
const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const logger = require('morgan');
const bodyParser = require('body-parser');
const cors = require('cors');
//Controller
const SpeechController = require('./src/Controllers/SpeechController');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(cors({credentials: true, origin: "*"}));
app.get('/', (req, res) => {
return res.sendFile(__dirname + '/public/index.html');
});
const users = [];
io.origins('*:*');
io.on('connection', (socket) => {
console.log('User connected. Socket Id: ' + socket.id);
//Adding a new user socket id
users.push(socket.id);
socket.on('startGoogleCloudStream', (data) => {
SpeechController.initStream();
});
socket.on('endGoogleCloudStream', () => {
SpeechController.endStream();
});
socket.on('binaryData', (data) => {
SpeechController.translate(socket, users, data);
});
});
http.listen(HTTP_PORT, (err) => {
if (err) throw err;
console.log('HTTP server running on port: ' + HTTP_PORT);
});
module.exports = http;