Skip to main content
Version: 5.7.0

Bridge


// Example of making an call from the context of another user

// First we need the profileId
var profileIdToUse = opponentProfileId;

// Second, retrieve a session for that profile
var otherSession = bridge.getSessionForProfile( profileIdToUse )

// Third, get a service proxy for that session
var lbProxy = bridge.getLeaderboardServiceParty( otherSession );

// Finally, make the API call
var score = opponentScore;
var extraData = {};
var res = lbProxy.postScoreToLeaderboard( "standard", score, extraData );

The primary function of the bridge is to provide a mechanism to access all of brainCloud's services within Cloud Code scripts.

Its important to note that the usage of these services changes depending on whether you call them within the context of a client session. For example, calling RunScript from a client executes the script within the context of that users client session, with full access to that user's profile data, entities, etc.

If there is no client session context when the script is executed (i.e. if script is executed via s2s, scheduled cloud code, etc), the bridge get*ServiceProxy() methods must be provided with a client session directly.

In these specific cases a client session may be retrieved using the GetSessionForProfile method, and passed in to the appropriate get*ServiceProxy() methods.

Helper Methods

The bridge also provides some additional helper methods for convenience:

  • CallScript - call a script from within the current script
  • Include - import the contents of another script into the current script
  • IsClientBridge - is this a client session?
  • IsServerBridge - is this a server/s2s session?
  • IsPeerBridge - is this a peer session?
  • Sleep - wait on the current thread for a specified time.

Team configuration:

  • GetTeamInfo - Retrieves the team info for the current assocaited session as a JSON
  • GetClientTeamInfo - Retrieves the team info for the current user as a JSON (It differenciates from GetTeamInfo when using for the Peer script.)

App configuration:

  • GetAppId - returns the appId that the script is running under (can be useful for determining whether a script is running in developoment vs. production)
  • GetAppName - returns the name of the app that the script is running under
  • GetAppVersion - returns the version of the client app
  • GetEnvironmentName - returns the name of the deployment environment that the app is running within
  • GetGlobalProperty - retrieve a global property
  • GetScriptName - returns the name of the currently running script

Information about the current user:

  • GetProfileId - return the profileId of the user associated with the current session
  • GetName - retrieves the name property of the user associated with the current session
  • GetEmail - returns the contact email address of the user associated with the current session (note - may not be the same as their email login)

Retrieving a session for another user:

Caching objects:

Logging methods:

  • LogDebug - Logs a debug message with string-based context.
  • LogDebugJson - Logs a debug message with json context.
  • LogInfo - Logs an info message with string-based context.
  • LogInfoJson - Logs an info message with string-based context.
  • LogWarning - Logs an warning with string-based context.
  • LogWarningJson - Logs an warning with json context.
  • LogError - Logs an error with string-based context.
  • LogErrorJson - Logs an error with json context.

Useful utility methods:

Raw API access:

Proxy methods retrieve the service proxies. Pass in a session as a parameter if you want to retrieve a proxy for a different session: