-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·35 lines (29 loc) · 1.18 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
/* LIBRAIRIES */
var express = require('express'), //librairie for make path easier
app = express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server),
ent = require('ent'), // Disable HTML caracters (equal htmlentities in PHP)
fs = require('fs');
/* SERVER CONFIG */
app.use(express.static(__dirname + '/public_html'));//all the client part here
/* WHEN SOMEONE IS CONNECTING TO THE SERVER */
io.sockets.on('connection', function (socket) {
socket.on("nouveauMsg", function(data){
if(data == "1"){
socket.join("salon");
socket.emit("reponse", "Vous êtes connecté au salon privé");
}
else if(data == "0"){
socket.leave("salon");
socket.emit("reponse", "Vous êtes déconnecté au salon privé");
}
socket.broadcast.emit("reponse",data);
socket.emit("reponse",data);
});
socket.on("msgPrive", function(data){
io.to("salon").emit("reponsePrivee", data);
});
});
server.listen(4445);
console.log("Serveur ON (localhost:" + 4445 + ")");