question

Francisco Facal avatar image
Francisco Facal asked

Can I setup and observable on the client side to listen specific actions/events using cloudscript API?

I'm building a GameLauncher that syncs with diff game titles. I would like to listen to a few events at the title level to trigger notifications, unblock games, etc. on the GameLauncher side.

I don't see a direct method within the docs to listen to a playstream event directly from a client side so was wondering if there's somehting I can do using a cloudscript function return tied up with a playstream event / action.

CloudScriptPlayStream
10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

Hi @Francisco Facal,

Based on your description, the features of your Game Launcher (and looks like it’s on mobile devices) looks like this, please correct me if I mistook something:

  1. Each title can send notifications to the Game Launcher side to notify the user when some events occur.
  2. Game Launcher can listen to a playstream event generated in titles directly and react to it to unblock games or any another operations.

For feature 1), it’s possible for you to utilize Actions and rules to react to specific PlayStream events and send notifications to them.

For feature 2), listening PlayStream events directly from the client side is not supported. Using Action and rules feature can trigger a PlayStream event to execute certain Cloud Script functions specified in the “Actions” tab, those functions can access the event data and hence return it, however, you need to call ExecuteCloudSctipt API from the client side in order to receive it from the response. As I see it, a possible solution would be making Webhook calls with the event data from CloudScript to your dedicated server which manages a key-value pair of User – List<PlayStream Event>, the users can then poll the server to retrieve the events specific to themselves.

10 |1200

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

Francisco Facal avatar image
Francisco Facal answered

@Citrus Yan thank you!! this is helpful!

Indeed, the client code is in javascript actually (Electron/React/Redux).

I understand from your answer that there's no direct way to observe a Cloud Script function return value directly. I understand ExecuteCloudSctipt method acts as any other API endpoint? and the only way I can achieve a pub/sub model is creating a middleware (own server) that leverages actions/triggers and Cloud Scripts to expose that event/channel to my client side app.

Is this assumption correct?

3 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.

Citrus Yan avatar image Citrus Yan commented ·

Hi @Francisco Facal

>>I understand ExecuteCloudSctipt method acts as any other API endpoint?

Yes, it is.

>>and the only way I can achieve a pub/sub model is creating a middleware (own server) that leverages actions/triggers and Cloud Scripts to expose that event/channel to my client side app. Is this assumption correct?

For current public features, yes, it's correct. you need to create a middleware to enable such functionality. However, PlayFab PubSub is currently in Private Preview, this can enable a flexible system for pushing information in real-time between services and clients, which will fulfill your needs. If you are interested, please contact us at helloplayfab@microsoft.com

1 Like 1 ·
Francisco Facal avatar image Francisco Facal Citrus Yan commented ·

Thanks @Citrus Yan, crystal clear! We'll implement this workaround for our V1 and might apply for the Pub/Sub preview for our next version :)

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Francisco Facal commented ·

Glad it helped:)

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.