heroiclabs / nakama-defold

Defold client for Nakama server.
https://heroiclabs.com
Apache License 2.0
78 stars 13 forks source link

socket functions are not wrapped as intended #82

Open ChrisYo-o opened 2 days ago

ChrisYo-o commented 2 days ago

According to the official Nakama docs here: https://heroiclabs.com/docs/nakama/concepts/chat/

This code should return a table with id as a child

local roomname = "MarvelMovieFans"
local persistence = true
local hidden = false

local channel = socket.channel_join(roomname, socket.CHANNELTYPE_ROOM, persistence, hidden)

print("Now connected to channel id: " .. channel.id);

The way it currently works in defold is that a table containing a channel table is returned, so in defold we would have to use channel.channel.id to get the correct channel id.

Also, for some reason I cannot understand, the channel_id is a very unintuitive name like 1...MarvelMovieFans or 2...MarvelMovieFans instead of MarvelMovieFans. I'm not sure if the defold wrapper is the one messing up the channel_id and requires the weird name to be used, or if nakama is bugged - but I suspect it's the nakama-defold implementation.

The nakama-defold documentation is also wrong because of this:

-- send channel join message
local channel_id = "pineapple-pizza-lovers-room"
local result = socket.channel_join(socket, 1, channel_id, false, false)

-- send channel messages
local result = socket.channel_message_send(channel_id, "Pineapple doesn't belong on a pizza!")

It's my understanding that this WOULD work if we could actually use the channel_id as the nakama docs intend for us to (no weird 2.. prefix), so if that's fixed this documentation may be automatically fixed - that's the ideal situation.

linear[bot] commented 2 days ago

SDK-850 socket functions are not wrapped as intended

ChrisYo-o commented 2 days ago

Here is a pretty printed result of pprinting what socket.channel_join returns using MarvelMovieFans as roomname image

at first glance, it appears the nakama implementation wraps everything into a channel table to have a cid outside of it. it would be better if cid was return within channel and then the channel table is returned directly. Also, the way the channel.id is generated needs to be investigated as it seems to be incorrect, it should be the same as room_name in this case.

Please note though that passing MarvelMovieFans as the channel_id for socket.channel_message_send does not work within defold as the Nakama docs say it should - and the nakama-defold docs say it should - because nakama-defold is expecting that weird 2...MarvelMovieFans id.