Package com.bitheads.braincloud.client
Class BrainCloudClient
java.lang.Object
com.bitheads.braincloud.client.BrainCloudClient
public class BrainCloudClient extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBrainCloudClient.BrainCloudUpdateType -
Field Summary
Fields Modifier and Type Field Description static booleanEnableSingletonModestatic StringSingletonUseErrorMessage -
Constructor Summary
Constructors Constructor Description BrainCloudClient() -
Method Summary
Modifier and Type Method Description voidderegisterEventCallback()Deregisters the event callbackvoidderegisterFileUploadCallback()Deregisters the file upload callbackvoidderegisterGlobalErrorCallback()Deregisters the global error callbackvoidderegisterNetworkErrorCallback()Deregisters the network error callbackvoidderegisterRewardCallback()Deregisters the reward callbackvoiddisableCompression()Disable compression in comms transactionsvoidenableCompression()Enable compression in comms transactionsvoidenableLogging(boolean shouldEnable)voidenableNetworkErrorMessageCaching(boolean in_enabled)Enables the message caching upon network error, which is disabled by default.voidflushCachedMessages(boolean in_sendApiErrorCallbacks)Flushs the cached messages to resume api call processing.StringgetAppId()AppStoreServicegetAppStoreService()StringgetAppVersion()AsyncMatchServicegetAsyncMatchService()intgetAuthenticationPacketTimeout()Gets the authentication packet timeout which is tracked separately from all other packets.AuthenticationServicegetAuthenticationService()BlockchainServicegetBlockchainService()StringgetBrainCloudVersion()ChatServicegetChatService()StringgetCountryCode()CustomEntityServicegetCustomEntityService()DataStreamServicegetDataStreamService()EntityServicegetEntityService()EventServicegetEventService()FileServicegetFileService()FriendServicegetFriendService()GamificationServicegetGamificationService()GlobalAppServicegetGlobalAppService()GlobalEntityServicegetGlobalEntityService()GlobalFileServicegetGlobalFileService()GlobalStatisticsServicegetGlobalStatisticsService()GroupFileServicegetGroupFileService()GroupServicegetGroupService()longgetHeartbeatInterval()IdentityServicegetIdentityService()static BrainCloudClientgetInstance()Deprecated.Use of the *singleton* has been deprecated.ItemCatalogServicegetItemCatalogService()StringgetLanguageCode()SocialLeaderboardServicegetLeaderboardService()LobbyServicegetLobbyService()MailServicegetMailService()MatchMakingServicegetMatchMakingService()MessagingServicegetMessagingService()OneWayMatchServicegetOneWayMatchService()ArrayList<Integer>getPacketTimeouts()Returns the list of packet timeouts.PlaybackStreamServicegetPlaybackStreamService()PlayerStateServicegetPlayerStateService()PlayerStatisticsEventServicegetPlayerStatisticsEventService()PlayerStatisticsServicegetPlayerStatisticsService()PresenceServicegetPresenceService()ProfanityServicegetProfanityService()PushNotificationServicegetPushNotificationService()RedemptionCodeServicegetRedemptionCodeService()RelayCommsgetRelayComms()RelayServicegetRelayService()PlatformgetReleasePlatform()BrainCloudRestClientgetRestClient()RTTCommsgetRTTComms()StringgetRttConnectionId()RTTServicegetRTTService()S3HandlingServicegetS3HandlingService()ScriptServicegetScriptService()voidgetSessionId()Returns the sessionId or empty string if no session present.SocialLeaderboardServicegetSocialLeaderboardService()TimeServicegetTimeService()doublegetTimeZoneOffset()TournamentServicegetTournamentService()intgetUploadLowTransferRateThreshold()Returns the low transfer rate threshold in bytes/secintgetUploadLowTransferRateTimeout()Returns the low transfer rate timeout in secsUserItemsServicegetUserItemsService()VirtualCurrencyServicegetVirtualCurrencyService()voidinitialize(String appId, String secretKey, String appVersion)Initializes the brainCloud client with your app information.voidinitialize(String serverURL, String appId, String secretKey, String appVersion)Method initializes the BrainCloudClient.voidinitializeIdentity(String profileId, String anonymousId)Initialize - initializes the identity service with the saved anonymous installation id and most recently used profile idvoidinitializeWithApps(String serverUrl, String appId, Map<String,String> secretMap, String appVersion)Method initializes the BrainCloudClient.voidinitializeWithApps(String appId, Map<String,String> secretMap, String appVersion)Method initializes the BrainCloudClient.voidinsertEndOfMessageBundleMarker()Inserts a marker which will tell the brainCloud comms layer to close the message bundle off at this point.booleanisAuthenticated()Returns whether the client is authenticated with the brainCloud server.booleanisInitialized()Returns whether the client is initialized.voidoverrideCountryCode(String countryCode)Sets the country code sent to brainCloud when a user authenticates.voidoverrideLanguageCode(String languageCode)Sets the language code sent to brainCloud when a user authenticates.voidregisterEventCallback(IEventCallback callback)Sets a callback handler for any out of band event messages that come from brainCloud.voidregisterFileUploadCallback(IFileUploadCallback fileUploadCallback)Registers a file upload callback handler to listen for status updates on uploadsvoidregisterGlobalErrorCallback(IGlobalErrorCallback in_globalErrorCallback)Registers a callback that is invoked for all errors generatedvoidregisterNetworkErrorCallback(INetworkErrorCallback in_networkErrorCallback)Registers a callback that is invoked for network errors.voidregisterRewardCallback(IRewardCallback in_rewardCallback)Sets a reward handler for any api call results that return rewards.voidresetCommunication()voidrestoreRecentSession(String sessionId)The brainCloud client considers itself reauthenticated with the given session Warning: ensure the user is within your session expiry (set on the dashboard) before using this call.voidretryCachedMessages()Attempts to resend any cached messages.voidrunCallbacks()Run callbacks, to be called every so often (e.g.voidrunCallbacks(BrainCloudClient.BrainCloudUpdateType updateType)Run callbacks, to be called every so often (e.g.voidsendRequest(ServerCall serverCall)voidsetAppVersion(String appVersion)voidsetAuthenticationPacketTimeout(int in_timeoutSecs)Sets the authentication packet timeout which is tracked separately from all other packets.voidsetHeartbeatInterval(long intervalMillis)static voidsetInstance(BrainCloudClient client)voidsetOldStyleStatusMessageErrorCallback(boolean in_enabled)Sets the error callback to return the status message instead of the error json string.voidsetPacketTimeouts(ArrayList<Integer> in_packetTimeouts)Sets the packet timeouts using a list of integers that represent timeout values in seconds for each packet retry.voidsetPacketTimeoutsToDefault()Sets the packet timeouts back to the default ie {10, 10, 10}voidsetReleasePlatform(Platform _releasePlatform)voidsetUploadLowTransferRateThreshold(int bytesPerSec)Sets the low transfer rate threshold of an upload in bytes/sec.voidsetUploadLowTransferRateTimeout(int timeoutSecs)Sets the timeout in seconds of a low speed upload (ie transfer rate which is underneath the low transfer rate threshold).
-
Field Details
-
EnableSingletonMode
public static final boolean EnableSingletonMode- See Also:
- Constant Field Values
-
SingletonUseErrorMessage
- See Also:
- Constant Field Values
-
-
Constructor Details
-
BrainCloudClient
public BrainCloudClient()
-
-
Method Details
-
getRttConnectionId
-
getInstance
Deprecated.Use of the *singleton* has been deprecated. We recommend that you create your own *variable* to hold an instance of the brainCloudWrapper. Explanation here: http://getbraincloud.com/apidocs/wrappers-clients-and-inconvenient-singletons/- Returns:
- AssertionError warning of disabled singleton usage
-
setInstance
-
getRestClient
-
getRTTComms
-
getRelayComms
-
initialize
Initializes the brainCloud client with your app information. This method must be called before any API method is invoked.- Parameters:
appId- The app idsecretKey- The app secretappVersion- The app version (e.g. "1.0.0").
-
initialize
Method initializes the BrainCloudClient.- Parameters:
serverURL- The server URLsecretKey- The app idappId- The map of appId to secretappVersion- The app version (e.g. "1.0.0").
-
initializeWithApps
Method initializes the BrainCloudClient.- Parameters:
appId- The app idsecretMap- The map of appId to secretappVersion- The app version (e.g. "1.0.0").
-
initializeWithApps
public void initializeWithApps(String serverUrl, String appId, Map<String,String> secretMap, String appVersion)Method initializes the BrainCloudClient.- Parameters:
serverUrl- The server URLappId- The app idsecretMap- The map of appId to secretappVersion- The app version (e.g. "1.0.0").
-
initializeIdentity
Initialize - initializes the identity service with the saved anonymous installation id and most recently used profile id- Parameters:
profileId- The id of the profile id that was most recently used by the app (on this device)anonymousId- The anonymous installation id that was generated for this device
-
resetCommunication
public void resetCommunication() -
runCallbacks
public void runCallbacks()Run callbacks, to be called every so often (e.g. once per frame) from your main thread. -
runCallbacks
Run callbacks, to be called every so often (e.g. once per frame) from your main thread.- Parameters:
updateType- An enum denoting which callback service to run
-
enableCompression
public void enableCompression()Enable compression in comms transactions -
disableCompression
public void disableCompression()Disable compression in comms transactions -
isAuthenticated
public boolean isAuthenticated()Returns whether the client is authenticated with the brainCloud server.- Returns:
- True if authenticated, false otherwise.
-
isInitialized
public boolean isInitialized()Returns whether the client is initialized.- Returns:
- True if initialized, false otherwise.
-
enableLogging
public void enableLogging(boolean shouldEnable) -
restoreRecentSession
The brainCloud client considers itself reauthenticated with the given session Warning: ensure the user is within your session expiry (set on the dashboard) before using this call. This optional method exists to reduce authentication calls, in event the user needs to restart the app in rapid succession.- Parameters:
sessionId- {string} - A recently returned session Id
-
registerEventCallback
Sets a callback handler for any out of band event messages that come from brainCloud.- Parameters:
callback- The event callback The json format looks like the following: { "events": [{ "fromPlayerId": "178ed06a-d575-4591-8970-e23a5d35f9df", "eventId": 3967, "createdAt": 1441742105908, "gameId": "123", "toPlayerId": "178ed06a-d575-4591-8970-e23a5d35f9df", "eventType": "test", "eventData": {"testData": 117} }], ] }
-
deregisterEventCallback
public void deregisterEventCallback()Deregisters the event callback -
registerRewardCallback
Sets a reward handler for any api call results that return rewards. See The brainCloud apidocs site for more information on the return JSON- Parameters:
in_rewardCallback- The reward callback handler.
-
deregisterRewardCallback
public void deregisterRewardCallback()Deregisters the reward callback -
registerFileUploadCallback
Registers a file upload callback handler to listen for status updates on uploads- Parameters:
fileUploadCallback- The file upload callback handler.
-
deregisterFileUploadCallback
public void deregisterFileUploadCallback()Deregisters the file upload callback -
registerGlobalErrorCallback
Registers a callback that is invoked for all errors generated- Parameters:
in_globalErrorCallback- The global error callback handler.
-
deregisterGlobalErrorCallback
public void deregisterGlobalErrorCallback()Deregisters the global error callback -
registerNetworkErrorCallback
Registers a callback that is invoked for network errors. Note this is only called if enableNetworkErrorMessageCaching has been set to true.- Parameters:
in_networkErrorCallback- The network error callback handler.
-
deregisterNetworkErrorCallback
public void deregisterNetworkErrorCallback()Deregisters the network error callback -
getPacketTimeouts
Returns the list of packet timeouts.- Returns:
- The list of packet timeouts
-
setPacketTimeouts
Sets the packet timeouts using a list of integers that represent timeout values in seconds for each packet retry. The first item in the list represents the timeout for the first packet attempt, the second for the second packet attempt, and so on. The number of entries in this array determines how many packet retries will occur. By default, the packet timeout array is {10, 10, 10} Note that this method does not change the timeout for authentication packets (use setAuthenticationPacketTimeout method).- Parameters:
in_packetTimeouts- An ArrayList of packet timeouts.
-
setPacketTimeoutsToDefault
public void setPacketTimeoutsToDefault()Sets the packet timeouts back to the default ie {10, 10, 10} -
getAuthenticationPacketTimeout
public int getAuthenticationPacketTimeout()Gets the authentication packet timeout which is tracked separately from all other packets. Note that authentication packets are never retried and so this value represents the total time a client would wait to receive a reply to an authentication api call. By default this timeout is set to 15 seconds.- Returns:
- The timeout in seconds
-
setAuthenticationPacketTimeout
public void setAuthenticationPacketTimeout(int in_timeoutSecs)Sets the authentication packet timeout which is tracked separately from all other packets. Note that authentication packets are never retried and so this value represents the total time a client would wait to receive a reply to an authentication api call. By default this timeout is set to 15 seconds.- Parameters:
in_timeoutSecs- The timeout in seconds
-
setOldStyleStatusMessageErrorCallback
public void setOldStyleStatusMessageErrorCallback(boolean in_enabled)Sets the error callback to return the status message instead of the error json string. This flag is used to conform to pre-2.17 client behaviour.- Parameters:
in_enabled- If set to true, enable
-
getUploadLowTransferRateTimeout
public int getUploadLowTransferRateTimeout()Returns the low transfer rate timeout in secs- Returns:
- The low transfer rate timeout in secs
-
setUploadLowTransferRateTimeout
public void setUploadLowTransferRateTimeout(int timeoutSecs)Sets the timeout in seconds of a low speed upload (ie transfer rate which is underneath the low transfer rate threshold). By default this is set to 120 secs. Setting this value to 0 will turn off the timeout.- Parameters:
timeoutSecs- The timeout in secs
-
getUploadLowTransferRateThreshold
public int getUploadLowTransferRateThreshold()Returns the low transfer rate threshold in bytes/sec- Returns:
- The low transfer rate threshold in bytes/sec
-
setUploadLowTransferRateThreshold
public void setUploadLowTransferRateThreshold(int bytesPerSec)Sets the low transfer rate threshold of an upload in bytes/sec. If the transfer rate dips below the given threshold longer than the specified timeout, the transfer will fail. By default this is set to 50 bytes/sec. Note that this setting only works on platforms that use libcurl (non-windows and win32 but not windows store or phone apps).- Parameters:
bytesPerSec- The low transfer rate threshold in bytes/sec
-
enableNetworkErrorMessageCaching
public void enableNetworkErrorMessageCaching(boolean in_enabled)Enables the message caching upon network error, which is disabled by default. Once enabled, if a client side network error is encountered (i.e. brainCloud server is unreachable presumably due to the client network being down) the sdk will do the following: 1 - cache the currently queued messages to brainCloud 2 - call the network error callback 3 - then expect the app to call either: a) retryCachedMessages() to retry sending to brainCloud b) flushCachedMessages() to dump all messages in the queue. Between steps 2 and 3, the app can prompt the user to retry connecting to brainCloud to determine whether to follow path 3a or 3b. Note that if path 3a is followed, and another network error is encountered, the process will begin all over again from step 1. WARNING - the brainCloud sdk will cache *all* api calls sent when a network error is encountered if this mechanism is enabled. This effectively freezes all communication with brainCloud. Apps must call either retryCachedMessages() or flushCachedMessages() for the brainCloud SDK to resume sending messages. resetCommunication() will also clear the message cache.- Parameters:
in_enabled- True if message should be cached on timeout
-
retryCachedMessages
public void retryCachedMessages()Attempts to resend any cached messages. If no messages are in the cache, this method does nothing. -
flushCachedMessages
public void flushCachedMessages(boolean in_sendApiErrorCallbacks)Flushs the cached messages to resume api call processing. This will dump all of the cached messages in the queue.- Parameters:
in_sendApiErrorCallbacks- If set to true API error callbacks will be called for every cached message with statusCode CLIENT_NETWORK_ERROR and reasonCode CLIENT_NETWORK_ERROR_TIMEOUT.
-
insertEndOfMessageBundleMarker
public void insertEndOfMessageBundleMarker()Inserts a marker which will tell the brainCloud comms layer to close the message bundle off at this point. Any messages queued before this method was called will likely be bundled together in the next send to the server. To ensure that only a single message is sent to the server you would do something like this: InsertEndOfMessageBundleMarker() SomeApiCall() InsertEndOfMessageBundleMarker() -
sendRequest
-
getSessionId
public void getSessionId()Returns the sessionId or empty string if no session present. -
getAppId
-
getReleasePlatform
-
setReleasePlatform
-
getAppVersion
-
setAppVersion
-
getBrainCloudVersion
-
getCountryCode
-
overrideCountryCode
Sets the country code sent to brainCloud when a user authenticates. Will override any auto detected country.- Parameters:
countryCode- ISO 3166-1 two-letter country code
-
getLanguageCode
-
getHeartbeatInterval
public long getHeartbeatInterval() -
setHeartbeatInterval
public void setHeartbeatInterval(long intervalMillis) -
overrideLanguageCode
Sets the language code sent to brainCloud when a user authenticates. If the language is set to a non-ISO 639-1 standard value the app default will be used instead. Will override any auto detected language.- Parameters:
languageCode- ISO 639-1 two-letter language code
-
getTimeZoneOffset
public double getTimeZoneOffset() -
getAppStoreService
-
getAuthenticationService
-
getAsyncMatchService
-
getChatService
-
getLobbyService
-
getDataStreamService
-
getEntityService
-
getEventService
-
getFileService
-
getFriendService
-
getGamificationService
-
getGlobalAppService
-
getGlobalEntityService
-
getGlobalStatisticsService
-
getGroupFileService
-
getGroupService
-
getIdentityService
-
getMailService
-
getMessagingService
-
getBlockchainService
-
getMatchMakingService
-
getOneWayMatchService
-
getPlaybackStreamService
-
getPlayerStateService
-
getPlayerStatisticsService
-
getPlayerStatisticsEventService
-
getPresenceService
-
getVirtualCurrencyService
-
getProfanityService
-
getPushNotificationService
-
getRedemptionCodeService
-
getRelayService
-
getRTTService
-
getS3HandlingService
-
getScriptService
-
getSocialLeaderboardService
-
getLeaderboardService
-
getTimeService
-
getTournamentService
-
getGlobalFileService
-
getCustomEntityService
-
getItemCatalogService
-
getUserItemsService
-