mirror of
https://github.com/randyjc/Rahoot.git
synced 2026-03-13 20:15:35 +01:00
adding manager UI and audio and video (youtube) questions
This commit is contained in:
@@ -7,9 +7,18 @@ import Registry from "@rahoot/socket/services/registry"
|
||||
import { withGame } from "@rahoot/socket/utils/game"
|
||||
import { Server as ServerIO } from "socket.io"
|
||||
|
||||
const corsOrigins =
|
||||
process.env.NODE_ENV !== "production"
|
||||
? "*"
|
||||
: env.WEB_ORIGIN === "*"
|
||||
? "*"
|
||||
: [env.WEB_ORIGIN, "http://localhost:3000", "http://127.0.0.1:3000"]
|
||||
|
||||
const io: Server = new ServerIO({
|
||||
cors: {
|
||||
origin: [env.WEB_ORIGIN],
|
||||
origin: corsOrigins,
|
||||
methods: ["GET", "POST"],
|
||||
credentials: false,
|
||||
},
|
||||
})
|
||||
Config.init()
|
||||
@@ -66,6 +75,42 @@ io.on("connection", (socket) => {
|
||||
}
|
||||
})
|
||||
|
||||
socket.on("manager:getQuizz", (quizzId) => {
|
||||
const quizz = Config.getQuizz(quizzId)
|
||||
|
||||
if (!quizz) {
|
||||
socket.emit("manager:errorMessage", "Quizz not found")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
socket.emit("manager:quizzLoaded", quizz)
|
||||
})
|
||||
|
||||
socket.on("manager:saveQuizz", ({ id, quizz }) => {
|
||||
if (!quizz?.subject || !Array.isArray(quizz?.questions)) {
|
||||
socket.emit("manager:errorMessage", "Invalid quizz payload")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const saved = Config.saveQuizz(id || null, quizz)
|
||||
|
||||
if (!saved) {
|
||||
socket.emit("manager:errorMessage", "Failed to save quizz")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
socket.emit("manager:quizzSaved", saved)
|
||||
socket.emit("manager:quizzList", Config.quizz())
|
||||
} catch (error) {
|
||||
console.error("Failed to save quizz", error)
|
||||
socket.emit("manager:errorMessage", "Failed to save quizz")
|
||||
}
|
||||
})
|
||||
|
||||
socket.on("game:create", (quizzId) => {
|
||||
const quizzList = Config.quizz()
|
||||
const quizz = quizzList.find((q) => q.id === quizzId)
|
||||
|
||||
Reference in New Issue
Block a user