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

Cannot overwrite message callback #197

Open
sticmac opened this issue Jul 6, 2022 · 2 comments
Open

Cannot overwrite message callback #197

sticmac opened this issue Jul 6, 2022 · 2 comments

Comments

@sticmac
Copy link

sticmac commented Jul 6, 2022

When using ColyseusRoom.OnMessage twice on the same message ID, I get the following exception:

ArgumentException: An item with the same key has already been added. Key: myMessage

An easy fix would be to modify the OnMessage method to take in consideration if a previous message with the given id already exists. However, I wanted to know if this is a bug or a real design choice before submitting a PR.

@endel
Copy link
Member

endel commented Jul 7, 2022

Thanks for reporting, @sticmac,

We've added support for multiple callbacks on the other clients for upcoming version 0.15 but it turns out the Unity SDK is still missing this feature (on #177)

Ideally, the Unity SDK should be able to attach and detach multiple callbacks, for example:

var detachCallback1 = room.OnMessage("xx", () => { /* first */ });
var detachCallback2 = room.OnMessage("xx", () => { /* second */ });

// detaching the "OnMessage" callback:
detachCallback1();
detachCallback2();

@sticmac
Copy link
Author

sticmac commented Jul 11, 2022

I made a pull request (#199) containing a solution like the example you provide :)

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

No branches or pull requests

2 participants