I’m new to Nakama, using Unity and Nakama in combination.
I got everything working well, except when I try to send a chat message. The socket is connected, the chat is joined.
Here’s some extremely ugly test code:
await authTask;
var list = _client.ListGroupsAsync(_session, "Test Clan");
await list;
var r = list.Result;
foreach (var g in r.Groups)
{
groupID = g.Id;
break;
}
await _client.JoinGroupAsync(_session, groupID);
Socket = _client.NewSocket();
Socket.Connected += () =>
{
Debug.Log("Socket connected.");
};
Socket.Closed += () =>
{
Debug.Log("Socket closed.");
};
await Socket.ConnectAsync(_session, true);
var b =await Socket.JoinChatAsync(groupID, ChannelType.Group, true);
Debug.Log(b.ToString());
Debug.Log("Chat joined!");
var content = new Dictionary<string, string> {{"Message", "Hello!"}}.ToJson();
await Socket.WriteChatMessageAsync(groupID, content);
Debug.Log("Please get to his point!");
So it never gets to the last debug statement. WriteChatMessageAsync stalls forever, no error is showing on the server log. And when I join the group, it works fine and it shows everyone online correctly.
The Unity client is 2.7.0 and Nakama is 2.12.0+650b506a. (copied from the log).
I started playing around with it yesterday, so maybe I’m missing something important? The authentication works, copied from your site and looking at the nakama admin it has created the users & the group correctly. It’s just the WriteChatMessageAsync that doesn’t work and stalls forever.
EDIT: I’m gonna try using the javascript client, and do the same thing and see what happens
Sound great, and if you want I can send over everything, it’s not much more than what you got already though! Thanks! I tried a quick javascript test but maybe the javascript lib on github (not using NPM) is way out of date, it was from 2018. And I get ‘TypeError: socket.joinChat is not a function’ and looking at the source I couldn’t find a joinChat function. Could be socket.joinChat works for TypeScript? I’ve never really used TS, so a bit lost there…
So I used the group’s ip as the chat id. I thought that would work as the group chat, not sure where I got that from. But when I then changed the groupid to the id fetched from the join call, which is the channel id, then it started working.
I do think that an error should have been thrown if the chat message could not be sent to the channel because the ID was invalid. Do you see an Exception object somewhere in the Unity logs?