-
Notifications
You must be signed in to change notification settings - Fork 1
/
host.py
24 lines (22 loc) · 938 Bytes
/
host.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
import json
import uuid
import websocket
class host():
def __init__(self, appTag):
self.appTag = appTag.value
import http.client
conn = http.client.HTTPSConnection("ecast.jackboxgames.com")
conn.request("POST", "/api/v2/rooms?userId="+str(uuid.uuid4())+"&appTag="+self.appTag)
res = conn.getresponse()
data = res.read().decode("utf-8")
response = json.loads(data)
self.token = response["body"]["token"]
self.code = response["body"]["code"]
print("Game Code: " + self.code)
self.host = response["body"]["host"]
self.connectWS()
def connectWS(self):
def on_message(wsapp, message):
print(message)
wsapp = websocket.WebSocketApp("wss://"+self.host+"/api/v2/rooms/"+self.code+"/play?role=host&format=json&host-token="+self.token, subprotocols=["ecast-v0"], on_message=on_message)
wsapp.run_forever()