Nakama Socket.sendmatchstate receives data as a uint8array(15)

Hello, I am trying to make a multiplayer game where a client can send their x and y position to other clients in the match. To test, I tried to send the coordinates (0, 0) first.

Here is the code I use to send data.

let data = {x: 0, y: 0}
socket.sendMatchState(matchID, OpCodes.position, data);

I connected another client to the same match and it received the data successfully, however, when I am trying to access the data variable I get a uint8array, not the original data object {x: 0, y: 0}.

Here is the code for the listener:
socket.onmatchdata = (result) => {
switch (result.op_code) {
case OpCodes.position: {

When I console log the result object, here is what is displayed:

Is there any way to get the coordinates sent by the original client? Thanks!

Hi alex1,

You should pass the data as a string, using JSON.stringify and then use the inverse function to get back the structure.

Out of curiosity, if you use String.fromCharCode with the byte array you got, you will see that it will print "[object Object]" (the usual javascript serialization of objects to strings)

Screenshot 2022-07-14 at 10.00.17

@alex1 before you JSON.parse the payload you should decode it with TextDecoder