Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket connection to group chat problem #58

Closed
SinaZK opened this issue Nov 10, 2020 · 10 comments
Closed

Socket connection to group chat problem #58

SinaZK opened this issue Nov 10, 2020 · 10 comments

Comments

@SinaZK
Copy link

SinaZK commented Nov 10, 2020

In my Godot client when i want to join the group chat i got this error:
NakamaException(StatusCode={-1}, Message=’{ERROR [Channel]: Missing or invalid required prop {content:UserPresence, name:presences, required:True, type:19} = Null:
{group_id:bf5052a9-948c-473b-b81e-ccf76d28126a, id:3.bf5052a9-948c-473b-b81e-ccf76d28126a…, self:{persistence:True, session_id:d2dd400b-22dc-11eb-8d0d-7106fdcb5b46, user_id:20a96d58-4d6f-4338-b487-2bfc10b7a43d, username:QdcBVBRWvL}}}’, GrpcStatusCode={-1})

@novabyte
Copy link
Member

@SinaZK Can you share what your GDScript code looks like when you get this error?

@SinaZK
Copy link
Author

SinaZK commented Nov 10, 2020

Sure.
var team_id = TeamManager.my_team_dict.id
var persistence = true
var hidden = false
var type = NakamaSocket.ChannelType.Group
var channel : NakamaRTAPI.Channel = yield(socket.join_chat_async(team_id, type, persistence, hidden), "completed")
if channel.is_exception():
print("An error occured: %s" % channel)
return

@SinaZK
Copy link
Author

SinaZK commented Nov 10, 2020

Nakama server logs:

`nakama | {"level":"info","ts":"2020-11-10T12:43:03.914Z","caller":"server/session_ws.go:80","msg":"New WebSocket session connected","uid":"20a96d58-4d6f-4338-b487-2bfc10b7a43d","sid":"46542092-2352-11eb-838e-7106fdcb5b46","format":0}

nakama | {"level":"debug","ts":"2020-11-10T12:43:12.522Z","caller":"server/pipeline.go:62","msg":"Received *rtapi.Envelope_ChannelJoin message","uid":"20a96d58-4d6f-4338-b487-2bfc10b7a43d","sid":"46542092-2352-11eb-838e-7106fdcb5b46","cid":"1","message":{"ChannelJoin":{"target":"bf5052a9-948c-473b-b81e-ccf76d28126a","type":3,"persistence":{"value":true},"hidden":{}}}}

nakama | {"level":"debug","ts":"2020-11-10T12:43:12.526Z","caller":"server/session_ws.go:390","msg":"Sending *rtapi.Envelope_Channel message","uid":"20a96d58-4d6f-4338-b487-2bfc10b7a43d","sid":"46542092-2352-11eb-838e-7106fdcb5b46","envelope":"cid:"1" channel:{id:"3.bf5052a9-948c-473b-b81e-ccf76d28126a.." self:{user_id:"20a96d58-4d6f-4338-b487-2bfc10b7a43d" session_id:"46542092-2352-11eb-838e-7106fdcb5b46" username:"QdcBVBRWvL" persistence:true} group_id:"bf5052a9-948c-473b-b81e-ccf76d28126a"}"}

nakama | {"level":"debug","ts":"2020-11-10T12:43:12.526Z","caller":"server/tracker.go:672","msg":"Processing presence event","joins":1,"leaves":0}`

@novabyte
Copy link
Member

@SinaZK Looks like the issue is with how the type is validated when created for the Channel object:

https://github.com/heroiclabs/nakama-godot/blob/master/addons/com.heroiclabs.nakama/api/NakamaRTAPI.gd#L10

I think the serializer needs a small tweak to recognise that the presences can be an empty array if omitted by the server. Can you open a pull request for the change?

@SinaZK
Copy link
Author

SinaZK commented Nov 10, 2020

Thanks for your response. I set the required to false at it solved the issue. Is this the proper way to handle this issue?

@novabyte
Copy link
Member

@SinaZK I think it depends. Ideally we'd want to instruct the serializer to ensure that if the field is not present it just uses a default value as an empty array. The change you've made will actually tell the serializer to leave the field as null which would require you to null check in various places in your code.

I'm not sure whether its possible to set the serializer to use the empty array as the default value when the field is not found in the JSON to be parsed, Fabio will be able to help us though. How would you handle this constraint @Faless?

@Faless
Copy link
Contributor

Faless commented Nov 10, 2020

@novabyte we could define a getter that uses another variable (if it's limited to this specific case):

const _SCHEMA = {
	#[...]
	"presences": {"name": "_presences", "type": TYPE_ARRAY, "required": false, "content": "UserPresence"},
	#[...]
}
#[...]
# The presences visible on the chat channel.
var presences : Array setget , _get_presences # of objects NakamaUserPresence
var _presences : Array = null
func _get_presences():
	return Array() if not _presences is Array else _presences

Or alternatively we could add an optional "default" key to the SCHEMA that the serializer will assign in case the value is not required and not found. Should be quite straight forward too.

@novabyte
Copy link
Member

Thanks @Faless. I think we should take the first route and handle the null scenario as an array of empty presences in the event that the server API returns no field.

Can you open a pull request with that change @SinaZK?

@zaksnet
Copy link

zaksnet commented Jan 27, 2021

Same issue here. I'v also set required to false to overcome this.

const _SCHEMA = {
  ...
  "presences": {"name": "presences", "type": TYPE_ARRAY, "required": false, "content": "UserPresence"},
  ...
}

@Faless
Copy link
Contributor

Faless commented Jul 17, 2021

This is fixed via #73

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants