Compare commits

..

No commits in common. "f966ee4abc277bb728011717cb82f555e71c0547" and "4eb1009afecc9a62af75e4bfd7b192b253633201" have entirely different histories.

5 changed files with 11 additions and 22 deletions

View File

@ -20,9 +20,9 @@ this is the base site
<script> <script>
document.getElementById("btn_dunno").onclick = async function (e) { document.getElementById("btn_dunno").onclick = async function (e) {
let text = document.getElementById("some_input").value; let text = document.getElementById("some_input").value;
let data = {"username": text}; let data = {"sessionid": text};
await fetch('/newclient', { await fetch('api/join_session', {
method: 'POST', method: 'POST',
body: JSON.stringify(data), body: JSON.stringify(data),
}) })

15
main.py
View File

@ -95,19 +95,12 @@ async def handler(request):
return aiohttp.web.FileResponse('index.html') return aiohttp.web.FileResponse('index.html')
@routes.post('/newclient') @routes.get('/newclient')
async def handler(request): async def handler(request):
model = request.app['model'] model = request.app['model']
data = await request.json()
username = data.get("username") client = model.create_client()
print(f"{username=}") raise aiohttp.web.HTTPFound(f"/{client}/")
if username:
client = model.create_client(username)
print(f"werked?")
raise aiohttp.web.HTTPFound(f"/{client}/")
print(f"werked?")
else:
raise aiohttp.web.HTTPFound(f"/newclient")
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -77,8 +77,7 @@ class Model(object):
if "session" in self.model["clients"][clientid]: if "session" in self.model["clients"][clientid]:
session = self.model["clients"][clientid]["session"] session = self.model["clients"][clientid]["session"]
allsessions = [ name for name in self.model["sessions"] ] allsessions = [ name for name in self.model["sessions"] ]
username = self.model["clients"][clientid]["name"] if "name" in self.model["clients"][clientid] else "Joe" data = {"currentsession": session, "allsessions": allsessions}
data = {"currentsession": session, "allsessions": allsessions, "username": username}
for socket in self.sockets[clientid]: for socket in self.sockets[clientid]:
await socket.send_json(data) await socket.send_json(data)
@ -97,9 +96,9 @@ class Model(object):
def exists_client(self, clientid: str) -> bool: def exists_client(self, clientid: str) -> bool:
return clientid in self.model["clients"] return clientid in self.model["clients"]
def create_client(self, name="Joe") -> str: def create_client(self) -> str:
clientname = generate_random_id() clientname = generate_random_id()
newclient = {"id": clientname, "name": name} newclient = {"id": clientname}
self.model["clients"][clientname] = newclient self.model["clients"][clientname] = newclient
return clientname return clientname

View File

@ -10,9 +10,6 @@ ws.onmessage = function(event) {
if (msg.hasOwnProperty('currentsession')) { if (msg.hasOwnProperty('currentsession')) {
document.getElementById('current_session').innerText = msg.currentsession; document.getElementById('current_session').innerText = msg.currentsession;
} }
if (msg.hasOwnProperty('username')) {
document.getElementById('greeting').innerText = "Hello, " + msg.username + "!";
}
if (msg.hasOwnProperty('allsessions')) { if (msg.hasOwnProperty('allsessions')) {
const all_sessions = document.getElementById('all_sessions'); const all_sessions = document.getElementById('all_sessions');

View File

@ -7,7 +7,7 @@
</head> </head>
<body> <body>
<span id="greeting"></span><br> this is the UI
<br> <br>
<span id="current_session">You are not in any session.</span><br> <span id="current_session">You are not in any session.</span><br>
<div id="all_sessions"></div><br> <div id="all_sessions"></div><br>