question

doldom avatar image
doldom asked

Connect to photon with JavaScript

I am trying to connect to photon with JavaScript.

Both PlayFabClientApi.js and Photon-Javascript_SDK.js are included in the html file.

I followed up Unity example, but can't find equivalent JavaScript api of below.

AuthenticationValues customAuth = new AuthenticationValues();
customAuth.AuthType = CustomAuthenticationType.Custom;
customAuth.AddAuthParameter("username", id);    // expected by PlayFab custom auth service
customAuth.AddAuthParameter("token", ticket);   // expected by PlayFab custom auth service

PlayFabClientSDK.LoginWithCustomID() and PlayFabClientSDK.GetPhotonAuthenticationToken() are successful but without the auth setting, there is error "Client: Error: 3101 NameServer authentication failed" when calling LoadBalancingClient.connectToRegionMaster().

Can you guide how to set authentication?

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

For future reference, here is how to properly connect to authenticate to Photon Cloud from PlayFab using the Photon JavaScript SDK:

  • PLAYFABID: the PlayFabId of the user logged in to PlayFab.
  • TOKEN: token retrieved from PlayFab using GetPhotonAuthenticationToken.
  • regionToken: the code of the Photon Cloud region. More info here.
var client =newPhoton.LoadBalancing.LoadBalancingClient(Photon.ConnectionProtocol.Ws, APPID,"1.0");

var authParam ="username="+ PLAYFABID +"&token="+ TOKEN;

client.setCustomAuthentication(authParam,Photon.LoadBalancing.Constants.CustomAuthenticationType.Custom);

client.connectToRegionMaster(regionToken);
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

This is actually a question about the Photon SDK, as opposed to the PlayFab SDK, so the Exit Games team would be the best folks to answer this. @Hamza Lazaar may be able to provide additional guidance on this, but you may also want to try checking the Photon forums, here: http://forum.photonengine.com/.

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