Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,55 @@ def handle_screen_frame(data):
# Broadcast screen frame to all viewers
emit("screen_frame", data, room='viewer')

@socketio.on("end_question")
def handle_end_question(data):
"""
Presenter manually or automatically ends a question.
"""
survey_id = data.get("surveyId") or data.get("survey_id")

print("end_question received:", survey_id)

if not survey_id or survey_id not in surveys:
return


surveys[survey_id]["active"] = False


socketio.emit(
"end_question",
{"surveyId": survey_id},
room=f"survey_{survey_id}"
)

@socketio.on("start_question")
def handle_start_question(data):
"""
Presenter starts a prepared question for students already in the survey room.
"""
survey_id = data.get("surveyId") or data.get("survey_id")
if not survey_id or survey_id not in surveys:
return

duration = data.get("duration", 10)
try:
duration = int(duration)
except (TypeError, ValueError):
duration = 10

socketio.emit(
"start_question",
{
"surveyId": survey_id,
"question": data.get("question", surveys[survey_id].get("question", "Question")),
"options": data.get("options", {}),
"duration": duration
},
room=f"survey_{survey_id}"
)



if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5000, debug=True)
socketio.run(app, host='0.0.0.0', port=5002, debug=True)
9 changes: 9 additions & 0 deletions demo/config/questions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"question": "1+1=2?",
"options": {
"A": "y",
"B": "n"
},
"correct": "A",
"duration": 15
}
26 changes: 26 additions & 0 deletions demo/config/s11.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"widgets": [
{
"id": "qa_widget",
"type": "qa",
"src": "widgets/qa_embed.html",
"x": 0.05,
"y": 0.1,
"width": 0.9,
"height": 0.8,
"zIndex": 10,
"interactive": true,
"questions": [
{
"question": "1+1=2?",
"options": {
"A": "y",
"B": "n"
},
"correct": "A",
"duration": 15
}
]
}
]
}
77 changes: 77 additions & 0 deletions demo/widgets/generate-questions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
$ErrorActionPreference = "Stop"

function Read-NonEmpty($prompt) {
while ($true) {
$value = Read-Host $prompt
if ($value -ne "") { return $value }
Write-Host "Please enter a value."
}
}

function Read-OptionLetter($prompt, $allowed) {
while ($true) {
$value = (Read-Host $prompt).Trim().ToUpper()
if ($allowed -contains $value) { return $value }
Write-Host ("Please enter one of: " + ($allowed -join ", "))
}
}

function Read-OptionCount($prompt) {
while ($true) {
$value = (Read-Host $prompt).Trim()
if ($value -match '^[234]$') { return [int]$value }
Write-Host "Please enter 2, 3, or 4."
}
}

function Read-PositiveInt($prompt, $default) {
while ($true) {
$value = Read-Host $prompt
if ($value -eq "") { return $default }
if ($value -match '^\d+$' -and [int]$value -gt 0) { return [int]$value }
Write-Host "Please enter a positive number."
}
}

$questions = @()

Write-Host "Enter questions for the Q&A widget."
Write-Host "Leave duration blank to use 15 seconds."

while ($true) {
$q = Read-NonEmpty "Question"
$optionCount = Read-OptionCount "How many options for the question? (2/3/4)"
$options = @{}
$allowed = @()
if ($optionCount -ge 2) {
$options["A"] = Read-NonEmpty "Option A"
$options["B"] = Read-NonEmpty "Option B"
$allowed += "A", "B"
}
if ($optionCount -ge 3) {
$options["C"] = Read-NonEmpty "Option C"
$allowed += "C"
}
if ($optionCount -ge 4) {
$options["D"] = Read-NonEmpty "Option D"
$allowed += "D"
}
$correct = Read-OptionLetter ("Correct option (" + ($allowed -join "/") + ")") $allowed
$duration = Read-PositiveInt "Duration in seconds (default 15)" 15

$questions += [pscustomobject]@{
question = $q
options = $options
correct = $correct
duration = $duration
}

$more = (Read-Host "Add another question? (y/n)").Trim().ToLower()
if ($more -ne "y") { break }
}

$json = @($questions) | ConvertTo-Json -Depth 5
$outPath = Join-Path $PSScriptRoot "questions.json"
$json | Set-Content -Path $outPath -Encoding UTF8

Write-Host "Saved $($questions.Count) question(s) to $outPath"
51 changes: 51 additions & 0 deletions demo/widgets/qa_embed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
border: 0;
background: transparent;
}
#host {
width: 100%;
height: 100%;
border: 0;
}
</style>
</head>
<body>
<iframe id="host" title="Q&A Presenter" src="/static/widgets/qa.html?role=presenter"></iframe>

<script>
const frame = document.getElementById("host");
let pendingConfig = null;

const forwardMessage = (data) => {
if (!frame || !frame.contentWindow) return;
frame.contentWindow.postMessage(data, "*");
};

window.addEventListener("message", (e) => {
if (e.data?.type === "widget-config") {
pendingConfig = e.data;
forwardMessage(e.data);
return;
}
if (e.data?.type === "widget-cleanup") {
forwardMessage(e.data);
}
});

frame.addEventListener("load", () => {
if (pendingConfig) {
forwardMessage(pendingConfig);
}
});
</script>
</body>
</html>
Loading