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>
document.getElementById("btn_dunno").onclick = async function (e) {
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',
body: JSON.stringify(data),
})

15
main.py
View File

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

View File

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

View File

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

View File

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