Class BrainCloudClient

java.lang.Object
com.bitheads.braincloud.client.BrainCloudClient

public class BrainCloudClient
extends Object
  • Field Details

  • Constructor Details

    • BrainCloudClient

      public BrainCloudClient()
  • Method Details

    • getRttConnectionId

      public String getRttConnectionId()
    • getInstance

      public static BrainCloudClient 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

      public static void setInstance​(BrainCloudClient client)
    • getRestClient

      public BrainCloudRestClient getRestClient()
    • getRTTComms

      public RTTComms getRTTComms()
    • getRelayComms

      public RelayComms getRelayComms()
    • initialize

      public void initialize​(String appId, String secretKey, String appVersion)
      Initializes the brainCloud client with your app information. This method must be called before any API method is invoked.
      Parameters:
      appId - The app id
      secretKey - The app secret
      appVersion - The app version (e.g. "1.0.0").
    • initialize

      public void initialize​(String serverURL, String appId, String secretKey, String appVersion)
      Method initializes the BrainCloudClient.
      Parameters:
      serverURL - The server URL
      secretKey - The app id
      appId - The map of appId to secret
      appVersion - The app version (e.g. "1.0.0").
    • initializeWithApps

      public void initializeWithApps​(String appId, Map<String,​String> secretMap, String appVersion)
      Method initializes the BrainCloudClient.
      Parameters:
      appId - The app id
      secretMap - The map of appId to secret
      appVersion - 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 URL
      appId - The app id
      secretMap - The map of appId to secret
      appVersion - The app version (e.g. "1.0.0").
    • initializeIdentity

      public void initializeIdentity​(String profileId, String anonymousId)
      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

      public void runCallbacks​(BrainCloudClient.BrainCloudUpdateType updateType)
      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

      public void restoreRecentSession​(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. 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

      public void registerEventCallback​(IEventCallback callback)
      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

      public void registerRewardCallback​(IRewardCallback in_rewardCallback)
      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

      public void registerFileUploadCallback​(IFileUploadCallback fileUploadCallback)
      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

      public void registerGlobalErrorCallback​(IGlobalErrorCallback in_globalErrorCallback)
      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

      public void registerNetworkErrorCallback​(INetworkErrorCallback in_networkErrorCallback)
      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

      public ArrayList<Integer> getPacketTimeouts()
      Returns the list of packet timeouts.
      Returns:
      The list of packet timeouts
    • setPacketTimeouts

      public void setPacketTimeouts​(ArrayList<Integer> in_packetTimeouts)
      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

      public void sendRequest​(ServerCall serverCall)
    • getSessionId

      public void getSessionId()
      Returns the sessionId or empty string if no session present.
    • getAppId

      public String getAppId()
    • getReleasePlatform

      public Platform getReleasePlatform()
    • setReleasePlatform

      public void setReleasePlatform​(Platform _releasePlatform)
    • getAppVersion

      public String getAppVersion()
    • setAppVersion

      public void setAppVersion​(String appVersion)
    • getBrainCloudVersion

      public String getBrainCloudVersion()
    • getCountryCode

      public String getCountryCode()
    • overrideCountryCode

      public void overrideCountryCode​(String countryCode)
      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

      public String getLanguageCode()
    • getHeartbeatInterval

      public long getHeartbeatInterval()
    • setHeartbeatInterval

      public void setHeartbeatInterval​(long intervalMillis)
    • overrideLanguageCode

      public void overrideLanguageCode​(String languageCode)
      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

      public AppStoreService getAppStoreService()
    • getAuthenticationService

      public AuthenticationService getAuthenticationService()
    • getAsyncMatchService

      public AsyncMatchService getAsyncMatchService()
    • getChatService

      public ChatService getChatService()
    • getLobbyService

      public LobbyService getLobbyService()
    • getDataStreamService

      public DataStreamService getDataStreamService()
    • getEntityService

      public EntityService getEntityService()
    • getEventService

      public EventService getEventService()
    • getFileService

      public FileService getFileService()
    • getFriendService

      public FriendService getFriendService()
    • getGamificationService

      public GamificationService getGamificationService()
    • getGlobalAppService

      public GlobalAppService getGlobalAppService()
    • getGlobalEntityService

      public GlobalEntityService getGlobalEntityService()
    • getGlobalStatisticsService

      public GlobalStatisticsService getGlobalStatisticsService()
    • getGroupFileService

      public GroupFileService getGroupFileService()
    • getGroupService

      public GroupService getGroupService()
    • getIdentityService

      public IdentityService getIdentityService()
    • getMailService

      public MailService getMailService()
    • getMessagingService

      public MessagingService getMessagingService()
    • getBlockchainService

      public BlockchainService getBlockchainService()
    • getMatchMakingService

      public MatchMakingService getMatchMakingService()
    • getOneWayMatchService

      public OneWayMatchService getOneWayMatchService()
    • getPlaybackStreamService

      public PlaybackStreamService getPlaybackStreamService()
    • getPlayerStateService

      public PlayerStateService getPlayerStateService()
    • getPlayerStatisticsService

      public PlayerStatisticsService getPlayerStatisticsService()
    • getPlayerStatisticsEventService

      public PlayerStatisticsEventService getPlayerStatisticsEventService()
    • getPresenceService

      public PresenceService getPresenceService()
    • getVirtualCurrencyService

      public VirtualCurrencyService getVirtualCurrencyService()
    • getProfanityService

      public ProfanityService getProfanityService()
    • getPushNotificationService

      public PushNotificationService getPushNotificationService()
    • getRedemptionCodeService

      public RedemptionCodeService getRedemptionCodeService()
    • getRelayService

      public RelayService getRelayService()
    • getRTTService

      public RTTService getRTTService()
    • getS3HandlingService

      public S3HandlingService getS3HandlingService()
    • getScriptService

      public ScriptService getScriptService()
    • getSocialLeaderboardService

      public SocialLeaderboardService getSocialLeaderboardService()
    • getLeaderboardService

      public SocialLeaderboardService getLeaderboardService()
    • getTimeService

      public TimeService getTimeService()
    • getTournamentService

      public TournamentService getTournamentService()
    • getGlobalFileService

      public GlobalFileService getGlobalFileService()
    • getCustomEntityService

      public CustomEntityService getCustomEntityService()
    • getItemCatalogService

      public ItemCatalogService getItemCatalogService()
    • getUserItemsService

      public UserItemsService getUserItemsService()