question

John Peterson avatar image
John Peterson asked

Photon WebHooks not triggered (redux).

Dear PlayFab community,

I never know whether I need to submit a new post for an ongoing issue. The threading capabilities of these Forums are confusing.

I had an issue with Photon WebHooks earlier today, and have fixed the underlying issue with writing events.

However, when I create a room, join a room, and leave a room -- only the photon_room_left event is getting written. The other two must have an error or are not getting invoked?

Is there any way for me to look at these logs?

Thanks for any help anyone can provide!

Here's the current WebHook code with a verified WritePlayerEvent function:

interface IPhotonResult
{
   ResultCode: number,
   Message:    string
}

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

function returnSuccess(eventName: string, args: any)
{
   WritePlayerEvent(eventName, {Arguments: args});

   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);
}
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;
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.

John Peterson avatar image
John Peterson answered

@Hamza Lazaar worked with me this morning to help me get this issue resolved. Many thanks to his efforts!

It turns out that if you use the PhotonNetwork.JoinOrCreateRoom() (as I was doing), you *must* configure your Photon Webhook "IsPersistent" key to be "true".

Further, just because a PunBehavior override is invoked, it does not mean that the corresponding Webhook will be called. For JoinOrCreateRoom either the PathJoin or PathCreate Webhook will be called, not both, despite the fact that if you create a room, you'll automatically join it too.

I hope this helps someone who might have similar confusions/issues!

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

Is that the whole script? If so, I'm not clear on how photon_room_left is working. The Server API version of WritePlayerEvent requires the PlayFab ID of the user (https://api.playfab.com/documentation/server/method/WritePlayerEvent). Also server API calls in Cloud Script would be made like this:

var writeEventResult = server.WritePlayerEvent({
                
EventName: "photon_room_created",
PlayFabId: currentPlayerId
});

You could then include the args for your handler as the Body of the event.

I'd also recommend putting a try/catch around the Server API call, so that you can catch and return errors.

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

@Brendan, yes, the photon_room_left *is* working. As such, I would expect the others to work, too. That is, all of the WebHooks are going through the same exact code path! So if photon_room_left is working, why aren't the others?

I even passed in an empty object in place of args for the Created/Joined aspect, just in case that object was too large to be part of an Event, and I still get the same behavior:

var RoomCreated = function(args: any, context?: IPlayFabContext): IPhotonResult
{
   return returnSuccess("photon_room_created", {}/*args*/);
}

Can you please answer this question for me:

Is there any way for me to see these logs?

Even if I put a try/catch around the Server API call, how can I get access to any potential logging? For whatever reason, the WebHook invocation aren't showing up in the Playstream (not even recording the CloudScript function call).

Additional thoughts?

I didn't initially include my "wrapper" function around WritePlayerEvent, so here it is:

function WritePlayerEvent(EventName: string, Body?: MapAny, Timestamp?: string): PlayFabServerModels.WriteEventResponse | never
{
   var requestWritePlayerEvent: PlayFabServerModels.WriteServerPlayerEventRequest =
   {
      PlayFabId: currentPlayerId,
      EventName: EventName,
      Timestamp: Timestamp,
      Body:      Body
   };

   var  resultWritePlayerEvent: PlayFabServerModels.WriteEventResponse = server.WritePlayerEvent(requestWritePlayerEvent);
   if (!resultWritePlayerEvent) return FatalError(null, `Error calling server.WritePlayerEvent(${JSON.stringify(requestWritePlayerEvent)}).`);

   return resultWritePlayerEvent;
}

4 comments
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 commented ·

Yes, there's an example of using try/catch to return log info on the errors encountered here: https://community.playfab.com/questions/7595/cloudscript-how-do-i-properly-return-an-error-to-t.html

0 Likes 0 ·
John Peterson avatar image John Peterson brendan commented ·

Thanks @Brendan! I'm familiar with try/catch in the context of CloudScript, and how to propagate that information to the client.

What I'm asking for is actual access to the log files that the CloudScript is generating. I'd like to see if my Create/Join events are getting called. They're pared down to a point where it seems like they should be working (a la the Left event), but I'm still not getting those.

0 Likes 0 ·
brendan avatar image brendan John Peterson commented ·

Logging for Cloud Script is not a file per call. There are log statements in our service in general, which do include errors that occur in Cloud Script calls, but as you can understand, we cannot expose that to anyone outside PlayFab, as it contains information on every running game. Also, while we do have full log info in our ELB data on all calls made, we do not do detailed logging for everything. For example, if a call has bad parameters, we would return the relevant error message to the caller, but that wouldn't get a detailed log statement. In general, detailed logging is for cases where we might need to do investigation due to an unexpected result.

Thanks for the rest of the Cloud Script - your WritePlayerEvent function is what we needed. I'd say continuing to work with Hamza, from the Exit Games team, will be the way to go. Given what you have in the script, I can't see any reason why the calls would act differently, so I have to assume we're not getting those webhook calls at all.

1 Like 1 ·
Show more comments
Hamza Lazaar avatar image
Hamza Lazaar answered

@John Peterson

Thank you for choosing Photon!

Probably the PlayStream events body size are exceeding the default limit for the free tier which is 1,024 bytes.
Try not logging the webhooks arguments or logging a smaller set of those by explicitly specifying which ones you are interested in.

4 comments
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 commented ·

Thanks @Hamza Lazaar! That's what I thought, too, but I ensured that my Body of the event was effectively a blank object. I'm still not getting the create/join Events. :-(

0 Likes 0 ·
Hamza Lazaar avatar image Hamza Lazaar John Peterson commented ·

I would triple check settings and make sure configured path names on Photon dashboard match implemented handlers on PlayFab CloudScript.
I would recommend using a third party logging service I use loggly.
On a separate note, I just created this repo and I thought you might be interested: https://github.com/JohnTube/PhotonWebhooksDefinitionForTypeScript

0 Likes 0 ·
John Peterson avatar image John Peterson Hamza Lazaar commented ·

Thank you, @Hamza Lazaar! I've triple-checked my settings, and the roomLeft WebHook is getting invoked. But I can't seem to get the roomCreated and/or roomJoined. (And I am successfully creating/joining a room from my app.)

Oh! Thank you for the TypeScript definitions for the WebHook elements -- sweet!

0 Likes 0 ·
Show more comments
John Peterson avatar image
John Peterson answered

For @Hamza Lazaar (the Forums won't let me Reply to our thread any more):

> So only "roomLeft" works and others simply fail silently?

Yes -- which is why I thought the same as you, and figured my WritePlayerEvent was failing in some way. However, I've since fixed any issues with it, and have verified that it works as expected (by putting the exact same line of code in another endpoint and invoking it).

I can also hit my CloudScript roomCreate endpoint directly from the PlayFab Dashboard, and it records the Player Event successfully. So it really feels like it's not being invoked by Photon, or there's some other issue at play.

Here is my PlayStream:

The "Player photon session authenticated" and "Photon room left" were generated by my app. During that process, my app created and joined a room, but the corresponding WebHooks weren't called.

The "Photon room created" was generated by me by manually executing the roomCreated CloudScript endpoint from the PlayFab Dashboard -- so I know that endpoint works. The body (Arguments) of the Event is effectively blank (I'm not writing anything substantive).


> Did you enable HasErrorInfo and try to see if you receive any ErrorInfo event in PhotonNetwork.OnEventCallAction (I hope the name is correct)?

Hmmm...I'm not familiar with this. Where can I learn more?


> Are you enabling IsPersistent?

No -- it looks like I just took the defaults for my configuration. My configuration is as follows:


> Are you testing with one client only?

Yes, for now.


10 |1200

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

Hamza Lazaar avatar image
Hamza Lazaar answered
@John Peterson

HasErrorInfo:

http://doc-api.photonengine.com/en/pun/current/class_photon_network.html#a81af9e901341d6b647df1f6d7f2d7583

https://doc.photonengine.com/en-us/pun/current/gameplay/web-extensions/webhooks#options

I suggest you wrap the calls in try/catch block and log events to an external logging service of your choice, e.g. loggly.

Try testing from two clients to make sure game is created properly. One creates and one joins.

Try setting IsPersistent to true.

I have no clue.

Double check webhooks URL, AppId, TitleId, etc.

1 comment
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 commented ·

Hi @Hamza Lazaar!

I'm getting back into this issue after being diverted on other tasks. I tried your suggestions above, with no different behavior.

I am still able to replicate my problems as stated in this thread.

Some additional information: I have a logging statement in each and every override for the PunBehavior. When I run the app in Unity (2018.1.1f1) I see the following:

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

So, from my Unity app, it sure feels like I should see the roomCreated and roomJoined WebHooks getting invoked. But I *only* see the roomLeft WebHook when I stop my Unity app from running.

I'm at a loss for what's going on here and how to properly debug this. I really appreciate any help/advice you can provide!

0 Likes 0 ·
John Peterson avatar image
John Peterson answered

(Starting a new Answer, just so it's easier to read.)

I tried @Hamza Lazaar's suggestions, to no avail.

I have all of the overrides from PunBehavior performing a logging operation, so I can see what gets hit, and when:

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

I removed the CustomHttpHeaders (which was set to "{}") and I finally got the roomCreated WebHook to be invoked!

I would expect to see the roomJoined WebHook too, however. So far, here's my Playstream:

Additional thoughts?


2 comments
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 commented ·

Well...I think I spoke too soon. :-(

With NO changes in code, I am no longer getting the roomCreated event. I thought maybe it was due to that CustomHttpHeaders key, but now I don't think so.

It sure feels like the Photon WebHooks are inconsistent and unreliable. Does this work for anybody?

0 Likes 0 ·
Hamza Lazaar avatar image Hamza Lazaar John Peterson commented ·

Send an email to developer@photonengine.com with all details including AppId and link to this thread.

0 Likes 0 ·

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.