-
Notifications
You must be signed in to change notification settings - Fork 0
/
ws.py
69 lines (51 loc) · 1.49 KB
/
ws.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import json
import ssl
import time
import websocket
import PySide2.QtCore as QtCore
from data_manager import DataStore
import network
file = None
class WebSocketThread(QtCore.QThread):
api_event = QtCore.Signal(list)
def __init__(self):
super().__init__()
def exit(self):
self.ws.close()
self.wait()
def on_message(self, message):
if message:
msg = json.loads(message)
self.api_event.emit(msg)
def on_error(self, error):
pass
def on_close(self):
pass
def on_open(self):
endpoints = [
'OnJsonApiEvent_lol-gameflow_v1_gameflow-phase',
'OnJsonApiEvent_lol-gameflow_v1_watch'
]
for endpoint in endpoints:
self.ws.send(json.dumps([5, endpoint]))
def run(self):
token, port = DataStore.get_connection_details()
time.sleep(5)
self.ws = websocket.WebSocketApp(
f"wss://127.0.0.1:{port}/",
header={'Authorization': network.get_auth_header(token)},
on_open=self.on_open,
on_message=self.on_message,
on_error=self.on_error,
on_close=self.on_close)
self.ws.run_forever(
sslopt={'cert_reqs': ssl.CERT_NONE}, suppress_origin=True)
if __name__ == "__main__":
websocket.enableTrace(True)
thread = WebSocketThread()
thread.start()
try:
while True:
pass
except KeyboardInterrupt:
thread.exit()