-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
73 lines (51 loc) · 1.67 KB
/
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
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
// var app = require('express')();
// var http = require('http').Server(app);
// app.get('/', function(req, res){
// res.send('<h1>Hello world</h1>');
// });
// http.listen(3000, function(){
// console.log('listening on *:3000');
// });
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var bodyParser = require('body-parser')
// var redis = require("redis")
// , subscriber = redis.createClient()
// , publisher = redis.createClient();
app.use(bodyParser.json());
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
// res.sendfile('index.html');
});
app.post('/send/:room/', function(req, res) {
var room = req.params.room;
// var message = req.body;
// var msgg = JSON.stringify(req);
// console.log("Session: %j", req.params);
console.log(req.body);
console.log('listening on * '+room);
io.emit('chat message', room);
// io.sockets.in(room).emit('message', { room: room, message: message });
res.end('message sent');
});
// io.on('connection', function(socket){
// console.log('a user connected');
// });
io.on('connection', function(socket){
// socket.broadcast.emit('hi');
// socket.broadcast.emit('user connected');
// var subscribe = redis.createClient();
// subscribe.subscribe('pubsub');
console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
socket.on('chat message', function(msg){
io.emit('chat message', msg);
socket.broadcast.emit('chat message','user connected');
});
});
http.listen(8080, function(){
console.log('listening on *:8080');
});