-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (39 loc) · 1.25 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
const express = require("express");
const bodyParser = require('body-parser');
const ejs = require('ejs');
const socketio = require('socket.io');
let port = process.env.PORT; // Heroku
if(port == null || port == ""){
port = 3000;
}
const app = express();
const expressServer = app.listen(port, function(){
console.log('listening on port', port);
});
const io = socketio(expressServer);
app.use(bodyParser.urlencoded({extended:true})); // bodyParser
app.use(express.static('public')); // express.static
app.set('view engine','ejs'); // ejs
app.get("/",function(req,res){
res.render('home',{
});
});
app.get("/game",function(req,res){
res.render('game',{
});
});
io.on('connection', (socket) => {
console.log(socket.id + 'connected');
socket.on('disconnect', () => {
console.log(socket.id + 'disconnected');
});
socket.on('phoneConnected',(roomName)=>{
io.to(roomName).emit('joinRoom');
});
socket.on('room',(roomName)=>{
socket.join(roomName);
});
socket.on('alpha',(alpha,roomName)=>{
socket.broadcast.to(roomName).emit('alpha',alpha);
});
});