-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (33 loc) · 1.08 KB
/
app.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
var express = require('express')
, exphbs = require('express3-handlebars')
, app = express()
, http = require('http')
, server = http.createServer(app)
, io = require('socket.io').listen(server);
//io.configure(function () {
// io.set("transports", ["xhr-polling"]);
// io.set("polling duration", 10);
//});
app.use(
"/static", //the URL throught which you want to access to you static content
express.static(__dirname + "/static") //where your static content is located in your filesystem
);
app.engine('handlebars', exphbs({}));
app.set('view engine', 'handlebars');
app.get('/', function (req, res) {
res.render('index');
});
io.sockets.on('connection', function (socket) {
socket.broadcast.emit('status', "Someone joined");
socket.on('message', function(message) {
socket.broadcast.emit('message', message);
})
socket.on('typing', function(message) {
socket.broadcast.emit('typing', message);
})
socket.on('disconnect', function() {
socket.broadcast.emit('status', "Someone left");
})
});
var port = Number(process.env.PORT || 3000);
server.listen(port);