-
Notifications
You must be signed in to change notification settings - Fork 3
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
RPC API #43
Conversation
## Changes: * Added RPC.register * Added RPC.call * Added enum for RPC Modes. ## Next ToDo: * Currently Only String data can be passed, need to use JSON. * Callback in RPCregister from Unity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs clarification.
Issue: RPC event with same name and different callbacks only calls the latest callback.
The issue where callback was getting overridden is fixed, so now each RPC event can call its own callback, but when the same event has different callbacks, only the latest one gets invoked. Current solution I have is to change the Changes are in this commit: c60dc8d |
I think your approach is fine. Do you have any other solutions in mind? |
RpcRegister: function (name) {
if (!window.Playroom) {
console.error("Playroom library is not loaded. Please make sure to call InsertCoin first.");
return;
}
function registerCallback(data, sender) {
//TODO: callback from unity here? dynCall('vi', callback, [data, sender])
console.log(`${sender.id} played their turn!`);
console.log(`recieving: ${data}`);
return 'okay!';
}
// Register the callback for the RPC
Playroom.RPC.register(UTF8ToString(name), registerCallback);
}, I believe the (data, sender) should be accessible from with unity, right? for that I can have a dynCall() within registerCallback and pass the data, sender as arguments, to do something after the rpcCall has invoked its callback. ^ is this the correct architecture here? @SaadBazaz |
Looks about right, what if we need multiple? 😬 Does the PlayroomKit JS support multiple callbacks? |
multiple callbacks for one rpc? yes. |
DEMO game: https://mmntlh.itch.io/playroom-demo Score (UI) is updated using RPC now. I tried using rpc for syncing movement (instead of using get/set state) but it was super laggy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with comments.
} | ||
else | ||
{ | ||
Debug.Log($"{data} is '{data.GetType()}' which is currently not supported by RPC!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you drop an explainer why this is necessary? Why can't we support these types?
Changes:
Next Tasks:
Testing:
Verified the changes by testing RPC registrations and calls with different modes from both C# and JavaScript. Checked the sequence of ENUM values and ensured correct callback invocations.
Test Results:
based on #37
Final demo output: https://mmntlh.itch.io/playroom-demo