comm works by json both ways now

This commit is contained in:
Stefan Rupp 2020-12-06 21:49:17 +01:00
parent ebf7878397
commit 1b9ccc65ab
3 changed files with 7 additions and 7 deletions

View File

@ -34,10 +34,13 @@
socket.onmessage = function(event) {
//alert(`[message] Data received from server: ${event.data}`);
if (event.data == "reload") {
//if (event.data == "reload") {
let x = JSON.parse(event.data);
let fct = x.fct;
if (fct == "reload") {
location.reload(true);
}
else if (event.data.startsWith("start game: ")) {
else if (fct == "startGame") {
let names = "..."
}
else {

View File

@ -76,15 +76,12 @@ async def websocket(ws):
the_game.websockets.append(ws)
try:
x = await ws.receive_json()
print(x)
fct = x['fct']
if fct == 'playcard':
print("play card :)")
p = int(x['player'])
c = int(x['card'])
await play_card(p, c)
elif fct == 'setTrumpColor':
print("trump color :)")
player = x['player']
color = x['color']
await set_trump_color(player, color)

View File

@ -1,4 +1,3 @@
import random
from operator import attrgetter
@ -215,7 +214,8 @@ class WizGame:
async def send_page_reload(self):
for ws in self.websockets:
try:
await ws.send_text("reload")
msg = {"type": "message", "fct": "reload"};
await ws.send_json(msg)
except Exception as e:
pass