added in-person support

This commit is contained in:
2025-09-20 15:26:19 +02:00
parent 6d9d624510
commit aff4244921
3 changed files with 347 additions and 1 deletions

View File

@ -66,6 +66,10 @@ SERVER_PORT = 5000
async def read_index():
return FileResponse('index.html')
@app.get("/display")
async def read_display():
return FileResponse('player-display.html')
@app.post("/facialexpressions")
def read_item(weights: list[float]):
msg = ';'.join(str(w) for w in weights)
@ -82,13 +86,53 @@ class Word(BaseModel):
class WordList(BaseModel):
words: list[str]
# Global state for current word display
current_word_state = {
"word": "",
"timeSeconds": 0.0,
"lastWordStatus": -1,
"startTime": None
}
@app.post("/word")
def read_word(word: Word):
import time
# Only update global state for player display if word is not empty
# (avoid overwriting with empty words sent to "other" player)
if word.word and word.word.strip():
current_word_state["word"] = word.word
current_word_state["timeSeconds"] = word.timeSeconds
current_word_state["lastWordStatus"] = word.lastWordStatus
current_word_state["startTime"] = time.time() if word.timeSeconds > 0 else None
msg = f"CHARADE:{word.lastWordStatus};{word.timeSeconds};{word.word}"
print(msg)
sock.sendto(msg.encode('utf-8'), (word.target, 5000))
return { "status": "ok" }
@app.get("/current-word")
def get_current_word():
import time
if current_word_state["startTime"] is None:
return {
"word": current_word_state["word"],
"timeRemaining": 0.0,
"lastWordStatus": current_word_state["lastWordStatus"],
"isActive": bool(current_word_state["word"])
}
elapsed = time.time() - current_word_state["startTime"]
time_remaining = max(0, current_word_state["timeSeconds"] - elapsed)
return {
"word": current_word_state["word"],
"timeRemaining": time_remaining,
"lastWordStatus": current_word_state["lastWordStatus"],
"isActive": time_remaining > 0 and bool(current_word_state["word"])
}
@app.post("/shuffle")
def shuffle_words(word_list: WordList):
import random