When I receive broadcasted messages from Nakama to the JavaScript Client SDK, I get this which is a protobuf:
{
match_id: '5160bac8-bd5d-4319-a9e9-4075bd5f1ecc.nakama',
op_code: 1,
data: Uint8Array(1239) [
123, 34, 110, 101, 120, 116, 71, 97, 109, 101, 82, 101,
109, 97, 105, 110, 105, 110, 103, 84, 105, 99, 107, 115,
34, 58, 48, 44, 34, 100, 101, 99, 107, 115, 34, 58,
123, 34, 115, 112, 101, 101, 100, 34, 58, 91, 49, 49,
44, 51, 44, 50, 44, 54, 44, 55, 44, 52, 44, 57,
44, 49, 50, 44, 49, 51, 44, 53, 44, 49, 52, 93,
44, 34, 97, 116, 116, 97, 99, 107, 34, 58, 91, 51,
44, 49, 51, 44, 56, 44, 52, 44, 49, 52, 44, 49,
50, 44, 57, 44,
... 1139 more items
],
reliable: true
}
I want to make the data
into a JavaScript Object, so I thought maybe I could use the nakama-js-protobuf
package but the instructions on that README: nakama-js/packages/nakama-js-protobuf at master · heroiclabs/nakama-js · GitHub don’t work:
import { WebSocketAdapterPb } from "@heroiclabs/nakama-js-protobuf"
...
const socket = client.createSocket(false, false, new WebSocketAdapterPb())
I get the following typescript error:
Argument of type 'WebSocketAdapterPb' is not assignable to parameter of type 'WebSocketAdapter'. Property 'isOpen' is missing in type 'WebSocketAdapterPb' but required in type 'WebSocketAdapter'. typescript (2345) [36, 44]
If I try to run it anyway, it tells me isOpen()
is missing from WebSocketAdapterPb:
test-client.ts:36:44 - error TS2345: Argument of type 'WebSocketAdapterPb' is not assignable to parameter of type 'WebSocketAdapter'.
Property 'isOpen' is missing in type 'WebSocketAdapterPb' but required in type 'WebSocketAdapter'.
36 s1 = c1.createSocket(false, false, new WebSocketAdapterPb())
~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/@heroiclabs+nakama-js@2.6.1/node_modules/@heroiclabs/nakama-js/dist/web_socket_adapter.d.ts:36:5
36 isOpen(): boolean;
~~~~~~~~~~~~~~~~~~
'isOpen' is declared here.
I’m wondering if I am doing this correctly? At the moment this I use TextDecoder to deserialize:
const data = JSON.parse(new TextDecoder().decode(result.data))
This works but I don’t think this is the intended way to do this, could someone help thank you!
- Versions: Nakama 3.15.0 Docker, nakama-js 2.6.1, nakama-js-protobuf 1.2.1
- Server Framework Runtime language: TS