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) { socket.onmessage = function(event) {
//alert(`[message] Data received from server: ${event.data}`); //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); location.reload(true);
} }
else if (event.data.startsWith("start game: ")) { else if (fct == "startGame") {
let names = "..." let names = "..."
} }
else { else {

View File

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

View File

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