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:
- GetSessionForCredential - retrieves a session for the specified credentials
- GetSessionForProfile - retrieves a session for the specified profileId
- GetSessionForSessionIdAndProfileId - confirms that a given sessionId and profileId are legitimate. Normally used in validating sessions from remote/custom servers.
- InvalidateSession - invalidates the current session to disconnect the current user from brainCloud.
Caching objects:
- SetSessionCacheObject - stores a JSON object to the session's cache
- GetSessionCacheObject - retrieves a cached object
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:
- GenerateGuid - generates a random GUID
- GetCurrentTimeZoneOffset - returns the current time zone offset (in hours) for a given timezone string. (e.g. "Europe/Oslo")
- SignRSASha256 - generates and returns an SHA256 with RSA signature for a string
Raw API access:
- CallAPI - calls the named API
- CallAPIForSession - calls the named api on behalf of the specified session
Proxy methods retrieve the service proxies. Pass in a session as a parameter if you want to retrieve a proxy for a different session:
- GetAppStoreServiceProxy
- GetAsyncMatchServiceProxy
- GetBlockchainServiceProxy
- GetCustomEntityServiceProxy
- GetDataStreamServiceProxy
- GetEntityServiceProxy - retrieves the proxy for user entities
- GetEventServiceProxy
- GetFileServiceProxy - retrieves the proxy for user files
- GetFriendServiceProxy
- GetGamificationServiceProxy
- GetGlobalAppServiceProxy
- GetGlobalEntityServiceProxy
- GetGlobalFileV3ServiceProxy
- GetGlobalStatisticsServiceProxy
- GetGroupServiceProxy
- GetHttpClientServiceProxy
- GetIdentityServiceProxy
- GetItemCatalogServiceProxy
- GetLeaderboardServiceProxy
- GetLobbyServiceProxy
- GetLogServiceProxy
- GetMailServiceProxy
- GetMatchMakingServiceProxy
- GetMessagingServiceProxy
- GetOnewayMatchServiceProxy
- GetPlaybackStreamServiceProxy
- GetPlayerStateServiceProxy
- GetPlayerStatisticsEventServiceProxy
- GetPlayerStatisticsServiceProxy
- GetPresenceServiceProxy
- GetProductMgmtServiceProxy
- GetProductServiceProxy
- GetProfanityServiceProxy
- GetPromotionsServiceProxy
- GetPushNotificationServiceProxy
- GetRedemptionCodeServiceProxy
- GetS3HandlingServiceProxy - retrieves the proxy for global files
- GetScriptServiceProxy
- GetSegmentServiceProxy
- GetTimeServiceProxy
- GetTournamentServiceProxy
- GetUserItemsServiceProxy
- GetUserServiceProxy
- GetVirtualCurrencyServiceProxy
📄️ CallAPI
A generic method for calling client API services. Useful in some circumstances.
📄️ CallAPIForSession
This is a generic method for calling client API services with a player session context.
📄️ CallScript
This is a shortcut method for calling scripts within scripts.
📄️ DeleteSessionCacheObject
Deletes the named JSON object from the session cache.