asadm / playroom-unity

9 stars 1 forks source link

onPlayerJoin and onQuit should return unregister callbacks #48

Closed asadm closed 2 months ago

asadm commented 3 months ago

The web versions return a function that can be called to unregister the listener

Related: https://discord.com/channels/997752993598419044/1224810795393613904/1224810795393613904

momintlh commented 3 months ago

After invoking the callback(s) we can maybe remove them from the maintained list similar to how RPC callbacks are being handled (or provide a function to remove / unregister)

SaadBazaz commented 3 months ago

After invoking the callback(s) we can maybe remove them from the maintained list similar to how RPC callbacks are being handled

I don't think immediately removing them is the right idea. We want these callbacks to run again and again,

(or provide a function to remove / unregister)

This seems better. We can return a function which deletes the pointer/reference to that callback in the list (i.e. runs a filter on the list and removes the one stored in the function.)

We would just have to cater for race conditions and make sure we handle errors/possible null operations correctly.

SaadBazaz commented 3 months ago

P.S.: A callback management mechanism was also discussed in #40.

momintlh commented 2 months ago

In #51 I have provided function to unsubscribe to listener (similar to the JS side), issue is we can't return a function back to unity to be called like this:

var unsubscribe = OnPlayerJoin(SomeCallcack())

unsubscribe()

current fix in #51 provides separate functions to unsubscribe to the listener (unity side). JS side is implemented similar to the docs.

SaadBazaz commented 2 months ago

Implemented in #51.