This commit is contained in:
Samuel Sloniker 2021-06-15 14:24:32 -07:00
parent 5143593d4c
commit d88766ddc0

23
wss.py
View File

@ -16,7 +16,7 @@ def cycle():
except Exception as e: except Exception as e:
#server.send_message_to_all('err%noconn%Server failed to capture screenshot') #server.send_message_to_all('err%noconn%Server failed to capture screenshot')
for client in clients.values(): for client in clients.values():
client.send('err%noconn%Server failed to capture screenshot') client.send('err%noconn%Server failed to capture screenshot', 'ERR')
time.sleep(3) time.sleep(3)
return return
@ -32,25 +32,22 @@ class Client:
self.client = client self.client = client
self.server = server self.server = server
self.queue = queue.Queue() self.queue = queue.Queue()
self.items = {}
self.good = True self.good = True
def send(self, item, name): def send(self, item, name):
self.messages[name] = item self.items[name] = item
def ack(self): def ack(self):
self.queue.put(['ack']) self.server.send_message(self.client, 'ack')
self.good = False
def cycle(self): def cycle(self):
while not self.good: while not self.good:
pass pass
for name, item in self.items.items():
item = self.queue.get() self.server.send_message(self.client, item)
del self.items[name]
if item[0] == 'msg':
self.server.send_message(self.client, item[1])
else:
self.server.send_message(self.client, 'ack')
self.good = False
def run(self): def run(self):
while True: while True:
@ -61,7 +58,7 @@ def do_img(imgname):
#server.send_message_to_all(img(imgname)) #server.send_message_to_all(img(imgname))
for client in clients.values(): for client in clients.values():
print(client) print(client)
client.send(img(imgname), img) client.send(img(imgname), imgname)
def img(imgname): def img(imgname):
@ -99,7 +96,7 @@ def do_touch(client, server, message):
x, y, w = int(x), int(y), int(w) x, y, w = int(x), int(y), int(w)
hcapi.touch(x, y, w) hcapi.touch(x, y, w)
else: else:
clients[client['id']].send(f'badpass') clients[client['id']].send(f'badpass', 'BADPASS')
def do_cycles(): def do_cycles():
while True: while True: