JS realtime communication with PUN
in JavaScript
Hi,
I'm building a cross platform app with PUN for Unity and the Javascript Realtime SDK for HTML5. I have successfully gotten the clients to see each other, create rooms, join sessions, etc. I have been unable to get my messaging to work in both directions.
On the original PUN version, I used RPC calls to send Game Events. I was able to receive these via HandleEvent in Javascript.
When attempting to reply from javascript, the only reference I could find in the SDK is for raiseEvent. I was also able to determine that 200 is the event code for RPC calls. Here is where I start to run into trouble...
When the RPC is received, it fails the following NetworkingPeer.cs check:
if (rpcData == null || !rpcData.ContainsKey((byte)0))
{
Debug.LogError("Malformed RPC; this should never occur. Content: " +
SupportClassPun.DictionaryToString(rpcData));
return;
}
The problem is that even when I send something as simple as:
var data = {};
data[0] = 1;
photonClient.raiseEventAll(200, data); //200 == RPC
the 0 arrives as "0" and is != (byte)0
How am I supposed to send Events/RPCs to PUN from the Javascript Realtime SDK?
Thanks!
Rob
I'm building a cross platform app with PUN for Unity and the Javascript Realtime SDK for HTML5. I have successfully gotten the clients to see each other, create rooms, join sessions, etc. I have been unable to get my messaging to work in both directions.
On the original PUN version, I used RPC calls to send Game Events. I was able to receive these via HandleEvent in Javascript.
When attempting to reply from javascript, the only reference I could find in the SDK is for raiseEvent. I was also able to determine that 200 is the event code for RPC calls. Here is where I start to run into trouble...
When the RPC is received, it fails the following NetworkingPeer.cs check:
if (rpcData == null || !rpcData.ContainsKey((byte)0))
{
Debug.LogError("Malformed RPC; this should never occur. Content: " +
SupportClassPun.DictionaryToString(rpcData));
return;
}
The problem is that even when I send something as simple as:
var data = {};
data[0] = 1;
photonClient.raiseEventAll(200, data); //200 == RPC
the 0 arrives as "0" and is != (byte)0
How am I supposed to send Events/RPCs to PUN from the Javascript Realtime SDK?
Thanks!
Rob
0
Comments
You have two options:
1. Switch to custom events/RPCs based on RaiseEvent with a custom code 0..199 instead of PUN's native RPCs (200). This way you can define structure and types.
2. Change PUN code to handle events incoming from JS clients. I think JS numbers are converted to double, etc.
I recommend option 1.
Thanks for the response. I had previously tried using a 0..199 number. When I do that, I pass the object check, but wind up in the default / unhandled case of OnEvent. I am unable to override OnEvent on my session as OnEvent isn't part of the IPunCallbacks. So, in either case, I am left to edit the NetworkingPeer.cs internal to the SDK to make this work.
I consider SDK modification bad practice, and it really just seems as if I'm not understanding the intended usage.
How can I catch OnEvent in PUN in order to have a custom object?
How can I send an RPC from Javascript to PUN?
That's the solution I arrived on. I didn't initially find it because I was used to using the Photon.Monobehaviour OnXXXX calls. Thanks!
Rob