-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
129 lines (100 loc) · 3.27 KB
/
server.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const express = require('express');
var session = require('express-session');
const server = express();
const http = require('http').Server(server);
const io = require('socket.io')(http);
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var morgan = require('morgan');
server.use(express.static('views'));
const users = {};
const perdoruesit = ["Zgjim Haziri","Qendresa Bekaj","Loreta Shala","Vegim Shala","Behar Rexhepi","Erona Vrapcani","Arti Sadikaj","Rea Kasumi"];
var z = 0;
http.listen(3000, () => {
console.log('Server started at: 3000');
});
/*server.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});*/
var ll = 0;
var vs = 0;
console.log(z);
io.on('connection', function (socket) {
io.sockets.emit('user-joined', { clients: Object.keys(io.sockets.clients().sockets), count: io.engine.clientsCount, joinedUserId: socket.id, joinedUsers: perdoruesit});
console.log(users);
socket.on('signaling', function(data) {
io.to(data.toId).emit('signaling', { fromId: socket.id, ...data });
});
socket.on('disconnect', function() {
io.sockets.emit('user-left', socket.id)
});
socket.on('add-presence', data => {
if(ll+1<=z)
{
ll++;
}
console.log(ll);
io.sockets.emit('presence-number', {prezenca: perdoruesit.slice(0,ll)});
});
//prej chat-it
socket.on('new-user', name => {
users[socket.id] = perdoruesit[z];
socket.broadcast.emit('user-connected', users[socket.id]);
z++;
});
socket.on('send-chat-message', message => {
socket.broadcast.emit('chat-message', { message: message, name: users[socket.id] })
});
socket.on('disconnect', () => {
socket.broadcast.emit('user-disconnected', users[socket.id]);
delete users[socket.id]
});
socket.on('micCamChange',(data) => {
socket.broadcast.emit('mc-changes-return', { mic: data.mic, vid: data.vid, clients: Object.keys(io.sockets.clients().sockets)});
});
connection.query('SELECT * FROM users', function (error, results, fields) {
if (error)
throw error;
socket.emit('sql_config', {res: results});
results.forEach(result => {
});
});
});
/*const loogS = window.document.getElementById("login-submit");
console.log(loogS);*/
/*server.get('/loginhtml.html', function(req, res) {
var name = 'hello';
res.render(__dirname + "/views/loginhtml.html", {name:name});
});*/
var passport = require('passport');
var flash = require('connect-flash');
require('./config/passport')(passport);
server.use(morgan('dev'));
server.use(cookieParser());
server.use(bodyParser.urlencoded({
extended: true
}));
server.set('view engine', 'ejs');
server.use(session({
secret: 'justasecret',
resave:true,
saveUninitialized: true
}));
server.use(passport.initialize());
server.use(passport.session());
server.use(flash());
require('./app/routes.js')(server, passport);
//DATABAZA
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
database : 'pd',
user : 'root',
password : ''
});
connection.connect(function(err) {
if (err) {
console.error('Error connecting: ' + err.stack);
return;
}
});