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",
|
"type": "python",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/src/server.py",
|
"program": "${workspaceFolder}/src/server.py",
|
||||||
"console": "integratedTerminal"
|
"console": "integratedTerminal",
|
||||||
|
"envFile": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Emulator",
|
"name": "Emulator",
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/src/emulator.py",
|
"program": "${workspaceFolder}/src/emulator.py",
|
||||||
"console": "integratedTerminal"
|
"console": "integratedTerminal",
|
||||||
|
"envFile": ""
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"compounds": [
|
"compounds": [
|
||||||
|
|
|
@ -43,7 +43,7 @@ def next_action():
|
||||||
Returns:
|
Returns:
|
||||||
int: key used by mgba
|
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):
|
if any(votes):
|
||||||
r.mset(KEYS_RESET)
|
r.mset(KEYS_RESET)
|
||||||
return votes.index(max(votes))
|
return votes.index(max(votes))
|
||||||
|
@ -79,12 +79,24 @@ stream = Popen(
|
||||||
"low_delay",
|
"low_delay",
|
||||||
"-strict",
|
"-strict",
|
||||||
"experimental",
|
"experimental",
|
||||||
|
# "-loglevel",
|
||||||
|
# "quiet",
|
||||||
RTMP_STREAM_URI,
|
RTMP_STREAM_URI,
|
||||||
],
|
],
|
||||||
stdin=PIPE,
|
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():
|
async def emulator():
|
||||||
while True:
|
while True:
|
||||||
last_frame_t = time.time()
|
last_frame_t = time.time()
|
||||||
|
@ -108,7 +120,9 @@ async def emulator():
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
task_emulator = asyncio.create_task(emulator())
|
task_emulator = asyncio.create_task(emulator())
|
||||||
|
task_state_manager = asyncio.create_task(state_manager())
|
||||||
await task_emulator
|
await task_emulator
|
||||||
|
await task_state_manager
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -40,6 +40,18 @@ async def parse_message(user: User, message: dict[str, str]) -> None:
|
||||||
logging.debug(f"admin authenticated: {user}")
|
logging.debug(f"admin authenticated: {user}")
|
||||||
await user.send('{"auth":"success"}')
|
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:
|
if "action" in message:
|
||||||
data = message["action"]
|
data = message["action"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue