Advertisement
Ireeb

server.js

Nov 14th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require("express");
  2. const app = express();
  3. const server = require("http").Server(app);
  4. const io = require("socket.io")(server);
  5. const path = require("path");
  6.  
  7. app.use(express.static("public"));
  8.  
  9. app.get("/play", function (req, res) {
  10.     res.sendFile(path.join(__dirname + '/public/playerclient/playerclient.html'))
  11. });
  12.  
  13. app.get("/quizmaster", function (req, res) {
  14.     res.sendFile(path.join(__dirname + '/public/masterclient/masterclient.html'))
  15. });
  16.  
  17. io.on("connection", socket => {
  18.     let referer = socket.handshake.headers.referer;
  19.     if (referer.endsWith("play")) {
  20.         socket.join("players");
  21.     };
  22.  
  23.     socket.on("send-question", questionData => {
  24.         io.in("players").emit("multiple-choice", questionData);
  25.     });
  26.  
  27.     socket.on("next-answer", function(){
  28.         io.in("players").emit("next-answer");
  29.     });
  30.  
  31.     socket.on("reveal-answer", correctAnswerIndex => {
  32.         io.in("players").emit("reveal-answer", correctAnswerIndex);
  33.     });
  34.  
  35.     socket.on("destroy-question", function(){
  36.         io.in("players").emit("destroy-question");
  37.     });
  38.  
  39. });
  40.  
  41. server.listen(80, "0.0.0.0", ()  => console.log("listening..."));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement