draft: added a way receive save and load messages
This commit is contained in:
parent
f1e94e4a78
commit
e817dffd8d
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
|
@ -6,14 +6,16 @@
|
|||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/src/server.py",
|
||||
"console": "integratedTerminal"
|
||||
"console": "integratedTerminal",
|
||||
"envFile": ""
|
||||
},
|
||||
{
|
||||
"name": "Emulator",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/src/emulator.py",
|
||||
"console": "integratedTerminal"
|
||||
"console": "integratedTerminal",
|
||||
"envFile": ""
|
||||
}
|
||||
],
|
||||
"compounds": [
|
||||
|
|
|
@ -43,7 +43,7 @@ def next_action():
|
|||
Returns:
|
||||
int: key used by mgba
|
||||
"""
|
||||
votes = list(map(int, r.mget(KEYS_ID)))
|
||||
votes: list[int] = list(map(int, r.mget(KEYS_ID)))
|
||||
if any(votes):
|
||||
r.mset(KEYS_RESET)
|
||||
return votes.index(max(votes))
|
||||
|
@ -79,12 +79,24 @@ stream = Popen(
|
|||
"low_delay",
|
||||
"-strict",
|
||||
"experimental",
|
||||
# "-loglevel",
|
||||
# "quiet",
|
||||
RTMP_STREAM_URI,
|
||||
],
|
||||
stdin=PIPE,
|
||||
)
|
||||
|
||||
|
||||
async def state_manager():
|
||||
ps = r.pubsub()
|
||||
ps.subscribe("admin")
|
||||
while True:
|
||||
message = ps.get_message(ignore_subscribe_messages=True)
|
||||
if message is not None:
|
||||
logging.debug(message)
|
||||
await asyncio.sleep(5.0)
|
||||
|
||||
|
||||
async def emulator():
|
||||
while True:
|
||||
last_frame_t = time.time()
|
||||
|
@ -108,7 +120,9 @@ async def emulator():
|
|||
|
||||
async def main():
|
||||
task_emulator = asyncio.create_task(emulator())
|
||||
task_state_manager = asyncio.create_task(state_manager())
|
||||
await task_emulator
|
||||
await task_state_manager
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -40,6 +40,18 @@ async def parse_message(user: User, message: dict[str, str]) -> None:
|
|||
logging.debug(f"admin authenticated: {user}")
|
||||
await user.send('{"auth":"success"}')
|
||||
|
||||
if "admin" in message:
|
||||
if user == USERS.admin:
|
||||
data = message["admin"]
|
||||
if data == "save":
|
||||
r.publish("admin", "save")
|
||||
elif data == data.startswith("load:"):
|
||||
r.publish("admin", data)
|
||||
else:
|
||||
logging.error(f"unsupported admin action: {data}")
|
||||
else:
|
||||
logging.error(f"user is not admin: {user}")
|
||||
|
||||
if "action" in message:
|
||||
data = message["action"]
|
||||
|
||||
|
|
Loading…
Reference in a new issue