mirror of https://github.com/Askill/r_place.git
js connection to WS
This commit is contained in:
parent
f587f8278f
commit
dc51bc6098
|
|
@ -3,7 +3,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const wsConnection = new WebSocket('ws:localhost:8080/get', 'json');
|
var wsConnection = new WebSocket('ws://localhost:8080/get');
|
||||||
wsConnection.onopen = (e) => {
|
wsConnection.onopen = (e) => {
|
||||||
console.log(`wsConnection open to 127.0.0.1:8080`, e);
|
console.log(`wsConnection open to 127.0.0.1:8080`, e);
|
||||||
};
|
};
|
||||||
|
|
@ -11,8 +11,15 @@ wsConnection.onerror = (e) => {
|
||||||
console.error(`wsConnection error `, e);
|
console.error(`wsConnection error `, e);
|
||||||
};
|
};
|
||||||
wsConnection.onmessage = (e) => {
|
wsConnection.onmessage = (e) => {
|
||||||
console.log(JSON.parse(e.data));
|
//var canvas = document.getElementById("main_canvas");
|
||||||
|
//var ctx = canvas.getContext("2d");
|
||||||
|
let data = JSON.parse(e.data)
|
||||||
|
console.log(data);
|
||||||
|
//ctx.fillStyle = "rgba("+data["color"][0]+","+data["color"][1]+","+data["color"][2]+","+(255)+")";
|
||||||
|
//ctx.fillRect(data["x"], data["y"], 1, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||||
|
|
|
||||||
|
|
@ -62,12 +62,14 @@ func get(w http.ResponseWriter, r *http.Request) {
|
||||||
msg := Message{X: uint32(x), Y: uint32(y), Timestamp: pix.Pixel.Timestamp, UserID: pix.Pixel.UserID, Color: pix.Pixel.Color}
|
msg := Message{X: uint32(x), Y: uint32(y), Timestamp: pix.Pixel.Timestamp, UserID: pix.Pixel.UserID, Color: pix.Pixel.Color}
|
||||||
marshalMsg, err := json.Marshal(msg)
|
marshalMsg, err := json.Marshal(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error while writing image", err)
|
log.Println("error while marshalling image", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
err = c.WriteMessage(1, marshalMsg)
|
err = c.WriteMessage(1, marshalMsg)
|
||||||
_, msg2, _ := c.ReadMessage()
|
if err != nil {
|
||||||
_ = msg2
|
log.Println("error while writing image", err)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := c.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
|
if err := c.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ async def client():
|
||||||
x = pixel(**json.loads(await websocket.recv()))
|
x = pixel(**json.loads(await websocket.recv()))
|
||||||
#image[x.x][x.y] = ([y*255 for y in colors[x.color]])
|
#image[x.x][x.y] = ([y*255 for y in colors[x.color]])
|
||||||
image[x.x][x.y] = ((x.color, x.color, x.color))
|
image[x.x][x.y] = ((x.color, x.color, x.color))
|
||||||
if i% 500000 == 0:
|
if i% 5000 == 0:
|
||||||
cv2.imshow("changes x", image)
|
cv2.imshow("changes x", image)
|
||||||
cv2.waitKey(10) & 0XFF
|
cv2.waitKey(10) & 0XFF
|
||||||
await websocket.send("1")
|
await websocket.send("1")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue