-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (62 loc) · 1.83 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
74
75
76
77
78
79
var app = require('express')();
var express = require('express');
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = process.env.PORT || 5000;
app.set('view engine', 'ejs');
// make express look in the public directory for assets (css/js/img)
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res){
res.sendFile(__dirname + '/public/index.html');
});
/*
app.get('/:flightId/:userId', function(req, res){
res.render('../index.ejs',req.params);
//res.send(req.params.flightId);
//res.sendFile(__dirname + '/index.html');
});*/
app.get('/lobbypreflight', function(req, res){
// req.query={
// flightId :'CX1230',
// userId : 'Bob'
// };
res.render('lobbypreflight.ejs',req.query);
});
app.get('/lobbyinflight', function(req, res){
// req.query={
// flightId :'CX1230',
// userId : 'Bob'
// };
res.render('lobbyinflight.ejs',req.query);
});
app.get('/lobbyinflight_30', function(req, res){
res.render('lobbyinflight_30.ejs',req.query);
});
app.get('/lobbypostflight', function(req, res){
res.render('lobbypostflight.ejs',req.query);
});
app.get('/:filename', function(req, res){
res.sendFile(__dirname + '/public/' + req.params.filename + '.html');
});
io.on( 'connection', function( socket ) {
var id;
//do nothing when disconnected
socket.on( 'disconnect', function() {
} );
//join the same socket if on same id
socket.on( 'register', function( data ) {
console.log(data);
id = data;
socket.join( data );
} );
//broadcast the message within the same socket
socket.on( 'chat', function( data ) {
io.to( id ).emit( 'chat', data );
} );
} );
/*http.listen(5000, function(){
console.log('listening on *:5000');
});*/
http.listen(port, function() {
console.log('Our app is running on http://localhost:' + port);
});