Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require("express");
- const app = express();
- const server = require("http").Server(app);
- const io = require("socket.io")(server);
- const path = require("path");
- app.use(express.static("public"));
- app.get("/play", function (req, res) {
- res.sendFile(path.join(__dirname + '/public/playerclient/playerclient.html'))
- });
- app.get("/quizmaster", function (req, res) {
- res.sendFile(path.join(__dirname + '/public/masterclient/masterclient.html'))
- });
- io.on("connection", socket => {
- let referer = socket.handshake.headers.referer;
- if (referer.endsWith("play")) {
- socket.join("players");
- };
- socket.on("send-question", questionData => {
- io.in("players").emit("multiple-choice", questionData);
- });
- socket.on("next-answer", function(){
- io.in("players").emit("next-answer");
- });
- socket.on("reveal-answer", correctAnswerIndex => {
- io.in("players").emit("reveal-answer", correctAnswerIndex);
- });
- socket.on("destroy-question", function(){
- io.in("players").emit("destroy-question");
- });
- });
- server.listen(80, "0.0.0.0", () => console.log("listening..."));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement