Compare commits
No commits in common. "db3d21a1fe52104bf79be33ed64726c121c0eb40" and "e1aa97aa712f3cf1605106d05ae355d0f9c4971a" have entirely different histories.
db3d21a1fe
...
e1aa97aa71
33
model.py
33
model.py
@ -12,17 +12,7 @@ def generate_random_id(_s=set()):
|
||||
return new_id
|
||||
|
||||
|
||||
class Model(object):
|
||||
|
||||
global api_methods
|
||||
api_methods = {}
|
||||
|
||||
def api_method():
|
||||
global api_methods
|
||||
def wrapper(fun):
|
||||
api_methods[fun.__name__] = fun
|
||||
return wrapper
|
||||
|
||||
class Model:
|
||||
def __init__(self, filename = "tehmodel.json"):
|
||||
self.sockets = {} # mapping: client -> socket
|
||||
self.filename = filename
|
||||
@ -43,16 +33,11 @@ class Model(object):
|
||||
if not "sessions" in self.model:
|
||||
self.model["sessions"] = {}
|
||||
|
||||
@api_method()
|
||||
async def create_session(self, clientid) -> str:
|
||||
sessionname = generate_random_id()
|
||||
newsession = {"id": sessionname, "owner": clientid, "clients": []}
|
||||
self.model["sessions"][sessionname] = newsession
|
||||
return sessionname
|
||||
|
||||
@api_method()
|
||||
async def join_session(self, clientid, sessionid):
|
||||
self.model["sessions"][sessionid]
|
||||
async def handle_post(self, clientid, data):
|
||||
print(f"I have received P O S T data: {data} from {clientid}")
|
||||
print("let me tell everyone")
|
||||
await self.send_state(clientid)
|
||||
return True
|
||||
|
||||
async def send_state(self, clientid):
|
||||
# TODO: compute state, send to client
|
||||
@ -81,6 +66,12 @@ class Model(object):
|
||||
self.model["clients"][clientname] = newclient
|
||||
return clientname
|
||||
|
||||
def create_session(self, clientid) -> str:
|
||||
sessionname = generate_random_id()
|
||||
newsession = {"id": sessionname, "owner": clientid, "clients": []}
|
||||
self.model["sessions"][sessionname] = newsession
|
||||
return sessionname
|
||||
|
||||
def subscribe(self, clientid, socket):
|
||||
if not clientid in self.sockets:
|
||||
self.sockets[clientid] = []
|
||||
|
Loading…
Reference in New Issue
Block a user