question

John Peterson avatar image
John Peterson asked

Photon PathEvent Webhook getting triggered multiple times?

Dear PlayFab community,

I am working with PlayFab, Photon, and Unity. I recently developed a better understanding of Photon Webhooks after wrestling with some issues explained here.

The link above still pertains to my "test bed" and various configurations, but I can provide the most recent examples if anyone needs.

My current issue is that it seems if PlayFab is generating multiple PathEvent Webhook calls under a certain set of circumstances.

Consider the following C# snippet in my Photon PunBehavior's OnRoomJoined() override:

public override void OnJoinedRoom()
{
   Log.Debug("OnJoinedRoom()");

   RaiseEventOptions rvo = new RaiseEventOptions();
   rvo.ForwardToWebhook = true;
   PhotonNetwork.RaiseEvent(0 /*EvCode*/, null, true, rvo);

#if TEST
   Hashtable hash = new Hashtable();
   hash.Add("key", "value");
   PhotonNetwork.room.SetCustomProperties(hash, null, true);
   PhotonNetwork.player.SetCustomProperties(hash, null, true);
#endif
}

When TEST is defined, the code is setting some arbitrary properties in the Photon room.

Here is my PlayStream output, first with TEST not defined (green outline), then with it defined (purple outline):

According to @Hamza Lazaar, who was helping me debug a previous issue, only *one* PathEvent Webhook was issued by Photon (he was monitoring my traffic via proxy) when 3 events showed up on my PlayStream.

Here are the contents of the PlayStream events for those three PathEvent entries (in order by Timestamp):

Note that each PlayStream event has their own unique EventId value, indicating that they're separate instances.

What's weird, is that it looks like those secondary events have the PathGameProperties Webhook-type "residue" in them. The first event has the EvCode, as expected, but the others don't. The third one has a TargetActor key in it that looks interesting and possibly meaningful in troubleshooting this issue?

This behavior is unexpected (I believe), and, according to @Hamza Lazaar, only one invocation to the PathEvent was made from Photon. This suggests that maybe there's something awry with the Photon/PlayFab integration for the Webhooks?

I'm hoping that someone can explore this issue and let me know if this is expected behavior or if it's a configuration-related problem or a bug.

As always, thanks in advance for any help anyone can provide!

photonwebhooks
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

I can't speak to what's happening in the Photon code, but I can say that if your Cloud Script code only generates one event, it's being called three times if you see three events. And the only difference in whether you get one event in PlayStream or three is your inclusion of the code that calls two SetCustomProperty calls. That would seem to imply that the webhook call to PlayFab occurs on each of those calls, as well. Have you tried removing the RaiseEvent call and only making one of the SetCustomProperty calls, to test this?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

John Peterson avatar image
John Peterson answered

Thanks for the reply, @Brendan!

I'm starting a new "Answer", since the threading capabilities of this forum software are a little restrictive.

I should have posted what @Brendan suggested originally. I changed the code to the following:

public override void OnJoinedRoom()
{
   Log.Debug("OnJoinedRoom()");

/*
   RaiseEventOptions rvo = new RaiseEventOptions();
   rvo.ForwardToWebhook = true;
   PhotonNetwork.RaiseEvent(0, null, true, rvo);
*/

   Hashtable hash = new Hashtable();
   hash.Add("key", "value");
   PhotonNetwork.room.SetCustomProperties(hash, null, true);
   PhotonNetwork.player.SetCustomProperties(hash, null, true);
}

I was certain that @Hamza Lazaar and I tried this yesterday and saw the expected results. However, I see 2x PathEvent Webhooks called instead of 1x PathGameProperties Webhook call, which is wholly unexpected. (But, this certainly is in line with the results from this original post.)

Looking closer at my Photon calls, I see the culprit:

interface IPhotonResult
{
   ResultCode: number,
   Message:    string
}

const photonSuccess: IPhotonResult = { ResultCode: 0, Message: 'Success' };

function returnSuccess(eventName: string, args: any)
{
   const MAX_LENGTH: number = 500;

   var json: string = JSON.stringify(args);
   if (json.length > MAX_LENGTH) args = json.slice(0, MAX_LENGTH);

   WritePlayerEvent(eventName, {Arguments: args});

/*
   const url: string = `http://logs-01.loggly.com/inputs/57f0a22d-92f9-4f5b-b13f-026231d2dd2f/tag/http/`;

   args["EventName"] = eventName;
   var response: string = http.request(url, "post", JSON.stringify(args), "application/json", {});
*/

   return photonSuccess;
}
var RoomCreated = function(args: any, context?: IPlayFabContext): IPhotonResult
{
   return returnSuccess("photon_room_created", args);
}
var RoomClosed = function(args: any, context?: IPlayFabContext): IPhotonResult
{
   return returnSuccess("photon_room_closed", args);
}
var RoomJoined = function(args: any, context?: IPlayFabContext): IPhotonResult
{
   return returnSuccess("photon_room_joined", args);
}
var RoomLeft = function(args: any, context?: IPlayFabContext): IPhotonResult
{
   return returnSuccess("photon_room_left", args);
}
var RoomEventRaised = function(args: any, context?: IPlayFabContext): IPhotonResult
{
   return returnSuccess("photon_room_event_raised", args);
}
var RoomPropertyUpdated = function(args: any, context?: IPlayFabContext): IPhotonResult
{
   return returnSuccess("photon_room_event_raised", args); // Copy and paste error!
}
var WebRPCTest = function(args: any, context?: IPlayFabContext): IPhotonResult
{
   return returnSuccess("photon_webrpc_test", args);
}

handlers["roomCreated"]         = RoomCreated;
handlers["roomClosed"]          = RoomClosed;
handlers["roomJoined"]          = RoomJoined;
handlers["roomLeft"]            = RoomLeft;
handlers["roomEventRaised"]     = RoomEventRaised;
handlers["roomPropertyUpdated"] = RoomPropertyUpdated;
handlers["webRPCTest"]          = WebRPCTest;

It looks like I have a cut-and-paste error in my PathGameProperties Webhook (it's showing the event name as "photon_room_event_raised" in the RoomPropertyUpdated function.)

Sorry...I should have re-reviewed the code first. <blush>

That begs the question, however: should there be 2x PathGameProperties invoked for this issue? Here are the PunBehavior overrides that get invoked with the current code flow:

OnConnectedToPhoton()
OnConnectedToMaster()
OnPhotonCustomRoomPropertiesChanged()
OnCreatedRoom()
OnJoinedRoom()
OnPhotonCustomRoomPropertiesChanged()
OnPhotonPlayerPropertiesChanged()

I'm guessing that it's called 1x for the PhotonNetwork.room.SetCustomProperties() and 1x for the PhotonNetwork.player.SetCustomProperties() (though it seems weird that the player.SetCustomProperties() would invoke the Webhook for a room property change)?

Maybe @Hamza Lazaar can confirm?


10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]