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.
📄️ GenerateGuid
Generate a random GUID.
📄️ GetAppId
This returns the appId of the script context.
📄️ GetAppName
Returns the name of the app.
📄️ GetAppStoreServiceProxy
Retrieves a AppStoreService proxy object.
📄️ GetAppVersion
Returns the version of the client app.
📄️ GetAsyncMatchServiceProxy
Retrieves an asyncMatchService proxy object.
📄️ GetBlockchainServiceProxy
Retrieves a BlockchainService proxy object.
📄️ GetChatServiceProxy
Retrieves a ChatService proxy object.
📄️ GetClientSessionId
Retrieves the client's session ID for the current user as a string.
📄️ GetClientTeamInfo
Retrieves the team info for the current user as a JSON.
📄️ GetCurrentTimezoneOffset
Get the timezone offset from UTC.
📄️ GetCustomEntityServiceProxy
Retrieves a CustomEntityService proxy object.
📄️ GetDataStreamServiceProxy
Retrieves a DataStreamService proxy object.
📄️ GetEmail
Retrieves the email of the current user as a string.
📄️ GetEntityServiceProxy
Retrieves an EntityService proxy object.
📄️ GetEnvironmentName
This returns the name of the deployment environment that app is running within.
📄️ GetEventServiceProxy
Retrieves an EventService proxy object.
📄️ GetFileServiceProxy
Retrieves a FileService proxy object.
📄️ GetFriendServiceProxy
Retrieves a FriendService proxy object.
📄️ GetGamificationServiceProxy
Retrieves a GamificationService proxy object.
📄️ GetGlobalAppServiceProxy
Retrieves a GlobalAppService proxy object.
📄️ GetGlobalEntityServiceProxy
Retrieves a GlobalEntitysService proxy object.
📄️ GetGlobalFileV3ServiceProxy
Retrieves a GlobalFileV3ServiceProxy proxy object.
📄️ GetGlobalProperty
This is basically a shortcut method for retrieving a specified global property which is predefined on portal.
📄️ GetGlobalStatisticsServiceProxy
Retrieves a GlobalGameStatisticsService proxy object.
📄️ GetGroupServiceProxy
Retrieves a GroupServiceProxy proxy object.
📄️ GetHttpClientServiceProxy
Retrieves an HttpClientService proxy object.
📄️ GetIdentityServiceProxy
Retrieves an IdentityService proxy object.
📄️ GetItemCatalogServiceProxy
Retrieves a ItemCatalogServiceProxy proxy object.
📄️ GetLeaderboardServiceProxy
Retrieves a LeaderboardService proxy object.
📄️ GetLobbyServiceProxy
Retrieves a LobbyService proxy object.
📄️ GetLogServiceProxy
Retrieves a LogService proxy object.
📄️ GetMailServiceProxy
Retrieves a MailService proxy object.
📄️ GetMatchMakingServiceProxy
Retrieves a MatchMakingService proxy object.
📄️ GetMessagingServiceProxy
Retrieves a MessagingServiceProxy proxy object.
📄️ GetName
Retrieves the name of the current user as a string.
📄️ GetOnewayMatchServiceProxy
Retrieves a OnewayMatchService proxy object.
📄️ GetPlaybackStreamServiceProxy
Retrieves a PlaybackStreamService proxy object.
📄️ GetPlayerStateServiceProxy
Retrieves a PlayerState proxy object.
📄️ GetPlayerStatisticsEventServiceProxy
Retrieves a PlayerStatisticsEventService proxy object.
📄️ GetPlayerStatisticsServiceProxy
Retrieves a PlayerStatisticsServiceProxy proxy object.
📄️ GetPresenceServiceProxy
Retrieves a PresenceServiceProxy proxy object.
📄️ GetProductMgmtServiceProxy
Retrieves a ProductMgmtService proxy object.
📄️ GetProductServiceProxy
Retrieves a ProductService proxy object.
📄️ GetProfanityServiceProxy
Retrieves a ProfanityService proxy object.
📄️ GetProfileId
Retrieves the profile ID for the current user as a string.
📄️ GetPromotionsServiceProxy
Retrieves a PromotionsService proxy object.
📄️ GetPushNotificationServiceProxy
Retrieves a PushNotificationService proxy object.
📄️ GetRedemptionCodeServiceProxy
Retrieves a RedemptionCodeService proxy object.
📄️ GetS3HandlingServiceProxy
Retrieves a S3HandlingService proxy object.
📄️ GetScriptName
This returns the name of the currently running script.
📄️ GetScriptServiceProxy
Retrieves a ScriptService proxy object.
📄️ GetSegmentServiceProxy
Retrieves a SegmentService proxy object.
📄️ GetServerSessionId
Retrieves the server's session ID for the server context, otherwise returns null.
📄️ GetSessionCacheObject
Retrieves the named JSON object from the session cache. Returns null if the object cannot be found.
📄️ GetSessionForCredential
Creates and returns a session for the credentials provided.
📄️ GetSessionForProfile
Creates and returns a session for the profileId provided.
📄️ GetSessionForSessionIdAndProfileId
Retrieves a session object based on the provided sessionId and profileId. Can be passed into the proxy service getter methods.
📄️ GetSessionForValidatedCredential
Creates and returns a session for the credentials provided.
📄️ GetTeamInfo
Retrieves the team info for the current assocaited session as a JSON.
📄️ GetTimeServiceProxy
Retrieves a TimeService proxy object.
📄️ GetTournamentServiceProxy
Retrieves a TournamentService proxy object.
📄️ GetUserItemsServiceProxy
Retrieves a UserItemsService proxy object.
📄️ GetUserServiceProxy
Retrieves a UserService proxy object.
📄️ GetVirtualCurrencyServiceProxy
Retrieves a VirtualCurrencyService proxy object.
📄️ Include
Use for including a share script into the current script. The included script is pre-rendered and combined into the current script.
📄️ InvalidateSession
Invalidates the current session, thus disconnecting the user from .
📄️ IsClientBridge
This returns true if the script context is client.
📄️ IsPeerBridge
This returns true if the script context is client.
📄️ IsServerBridge
This returns true if the script context is server.
📄️ LogDebug
Use this call to log messages to the API Explorer or Cloud Code Editor's log display only. It does not write to the persistant error logs. This method does nothing when calls from a cloud code script in normal execution circumstances.
📄️ LogDebugJson
Use this call to log messages to the API Explorer or Cloud Code Editor's log display only. It does not write to the persistant error logs. This method does nothing when calls from a cloud code script in normal execution circumstances.
📄️ LogError
Logs an App Error message to the error log.
📄️ LogErrorJson
Logs an App Error message to the error log.
📄️ LogInfo
Logs an App Info message to the error log.
📄️ LogInfoJson
Logs an App Info message to the error log.
📄️ LogWarning
Logs an App Warning message to the error log.
📄️ LogWarningJson
Logs an App Warning message to the error log.
📄️ SetSessionCacheObject
Stores a JSON object temporarily within the current session. Note that the data will be lost when the session expires.
📄️ SignHMACSha256
Given a piece of data and a shared secrect key, calculates an SHA-256 with HMAC signature for the data.
📄️ SignRSASha256
Given a piece of data and a private key, calculates an SHA-256 with RSA (SHA256withRSA) signature for the data. This signature can then be verified as authentic by a receiver with access to an associated public key.
📄️ Sleep
Note that the max time you can sleep for is the timeout value of the script it is called from.