Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Gamebase

Hierarchy

  • Gamebase

Index

Methods

Static addEventHandler

  • addEventHandler(eventHandler: EventHandlerEvent): void
  • description

    Add a Gamebase event handler to be called when every events are arrived.

    SERVER_PUSH : Receive messages from the Gamebase server.

    OBSERVER : This is an event that fires when the launch, login account(hearbeat), or network connection 'status changes', webview event, introspect fail event.

    Since Added 2.10.0.

    example
    
    toast.Gamebase.addEventHandler((message) => {
        const category = message.category;
        const data = message.data;
        switch (category) {
            case GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT:
                // Kicked out from Gamebase server.(Maintenance, banned or etc..)
                // Return to title and initialize Gamebase again.
                break;
            case GamebaseEventCategory.SERVER_PUSH_TRANSFER_KICKOUT:
                // If the user wants to move the guest account to another device,
                // if the account transfer is successful,
                // the login of the previous device is released,
                // so go back to the title and try to log in again.
                break;
            case GamebaseEventCategory.OBSERVER_LAUNCHING:
                checkLaunchingStatus(JSON.parse(message.data));
                break;
            case GamebaseEventCategory.OBSERVER_NETWORK:
                checkNetworkStatus(JSON.parse(message.data));
                break;
            case GamebaseEventCategory.OBSERVER_HEARTBEAT:
                checkHeartbeat(JSON.parse(message.data));
                break;
            case GamebaseEventCategory.OBSERVER_INTROSPECT:
                // Introspect error
                var observerData = JSON.parse(message.data);
                var errorCode = observerData.code;
                var errorMessage = observerData.message;
                break;
        }
    });
    
    function checkLaunchingStatus(data) {
        var code = data.code;
    
        var isPlayable = toast.GamebaseLaunching.isPlayable(code);
        if (isPlayable) {
            // 'The Game is playable'
        } else {
            // 'The Game is not playable'
        }
    }
    
    function checkHeartbeat(data) {
        var code = data.code;
        if (code === toast.GamebaseConstant.INVALID_MEMBER) {
            // You should to write the code necessary in game. (End the session.)
        } else if (code === toast.GamebaseConstant.BANNED_MEMBER) {
            // The ban information can be found by using the GetBanInfo API.
            // Show kickout message to user and need kickout in game.
        } else {
            console.log('Heartbeat code: ' + code);
        }
    }
    
    function checkNetworkStatus(data) {
        var code = data.code;
        if (code === toast.GamebaseNetworkType.TYPE_NOT) {
            // Network disconnected
        } else {
            // Network connected
        }
    }

    Parameters

    • eventHandler: EventHandlerEvent

    Returns void

Static addObserver

  • addObserver(observer: Observer): void
  • description

    Add observer. Through this observer, you can receive the several useful notification such as "user ban", "network status change" and "launching status change"(playable or not).

    Since Added 2.0.0.

    example
    
    toast.Gamebase.addObserver((event) => {
        const type = event.type;
        const data = event.data;
        const code = data.code;
    
        if (type === 'network') {
            if (code === -1) console.log('network offline');
            else             console.log('network online');
        } else if (type === 'heartbeat') {
             if (code === 6) console.log('user banned');
             if (code === 7) console.log('invalid user');
        } else if (type === 'launching') {
             if (200 =< code && code < 300) console.log('playable');
             else if (code === 303) console.log('service is on inspecting.');
             else if (code === 304) console.log('Gamebase is on inspecting.');
             else                   console.log('not playable');
        }
    });

    Parameters

    • observer: Observer

    Returns void

Static addServerPushEvent

  • addServerPushEvent(serverPushEvent: ServerPushEvent): void
  • description

    Add server push event. Through this server push event, you can receive the several useful notification such as "app kickout". This event is occured by WebSocket server push event from TOAST Gamebase Console.

    Since Added 2.0.0.

    example
    
    toast.Gamebase.addServerPushEvent((event) => {
        const type = event.type;
        const data = event.data;
    
        if (type === 'appKickout') {
            console.log('App Kickout occured.');
        } else {
             console.log('other server push event occured.');
             console.log(event);
        }
    });

    Parameters

    • serverPushEvent: ServerPushEvent

    Returns void

Static getAccessToken

  • getAccessToken(): string
  • description

    This method returns the Gamebase access token.

    Since Added 2.0.0.

    Returns string

    string

Static getAuthToken

  • getAuthToken(): AuthToken
  • description

    This method returns the current AuthToken that has several information such as user id and access token.

    Since Added 2.0.0.

    Returns AuthToken

    AuthToken

Static getBanInfo

  • getBanInfo(): AuthBanInfo
  • description

    This method returns user's ban information. If user is banned through TOAST Gamebase console(or other method), it returns useful information. But user is normal user(not banned), it will return null.

    Since Added 2.0.0.

    Returns AuthBanInfo

    AuthBanInfo

Static getCountryCode

  • getCountryCode(): string
  • description

    This method returns device country code using browser API, navigator.language.

    Since Added 2.0.0.

    Returns string

    string

Static getDisplayLanguageCode

  • getDisplayLanguageCode(): string
  • description

    This method returns Gamebase display language code. Gamebase uses this display language code to Gamebase UI such as maintenace modal and user banned modal.

    Since Added 2.0.0.

    Returns string

    string

Static getDisplayLanguageTable

  • getDisplayLanguageTable(): any
  • description

    This method returns Gamebase Display Language Table. Gamebase uses this display language table to find out which text should be rendered at Gamebase UI such as maintenace modal and user banned modal. You can checek the default display language table through the toast.Gamebase.getDisplayLanguageTable() API.

    Since Added 2.0.0.

    Returns any

    any

Static getLanguageCode

  • getLanguageCode(): string
  • description

    This method returns device language code using browser API, navigator.language.

    Since Added 2.0.0.

    Returns string

    string

Static getLastLoggedInProvider

  • getLastLoggedInProvider(): string
  • description

    This method returns the last logged in provider. If Gamebase is not initialized or does not have login history, it will return null. As Gamebase uses the cookie for saving several information, when cookie is cleared, it could return the null.

    Since Added 2.0.0.

    Returns string

    string

Static getSDKVersion

  • getSDKVersion(): string
  • description

    This method returns the Gamebase sdk version.

    Since Added 2.0.0.

    Returns string

    string

Static getUserID

  • getUserID(): string
  • description

    This method returns the Gamebase userId who is already logged in.

    Since Added 2.0.0.

    Returns string

    string

Static initialize

  • initialize(config: GamebaseConfiguration, callback: GamebaseDataCallback<LaunchingInfo>): void
  • description

    This method initializes the Gamebase.

    Since Added 2.0.0.

    example
    
    toast.Gamebase.initialize({
        appId: 't0AsT',          // TOAST Project ID
        clientVersion: '1.0.0',  // TOAST Console > Gamebase > App > Client Version
        displayLanguageCode: 'en',
        enableDebugMode: true,
        uiConfiguration: {
            enablePopup: true,   // Use Gamebase UI Popup
            enableLaunchingStatusPopup: true,
            enableBanPopup: true,
        }
    }, (launchingInfo, error) => {
        if (error) {
            console.log('Gamebase initialization failed');
            console.log(error);
            return;
        }
    
        const statusCode = launchingInfo.launching.status.code;
        if (200 <= statusCode && statusCode < 300) {
            console.log('Playable!');
        } else {
            console.log('Not Playable!');
        }
    });

    Parameters

    • config: GamebaseConfiguration
    • callback: GamebaseDataCallback<LaunchingInfo>

    Returns void

Static isInitialized

  • isInitialized(): boolean
  • description

    This method returns true if Gamebase is initialized.

    Since Added 2.0.0.

    Returns boolean

    boolean

Static isSandbox

  • isSandbox(): boolean
  • description

    Gamebase provides the sandbox mode. This method returns wheater this project is on sandbox or not. If you want to set the project with sandbox mode, please contact us.

    Since Added 2.0.0.

    Returns boolean

    boolean

Static isSuccess

  • isSuccess(error: GamebaseError): boolean
  • description

    This method returns the result that Gamebase API success or not.

    Since Added 2.0.0.

    Parameters

    • error: GamebaseError

    Returns boolean

    boolean

Static login

  • login(providerName: string, callback: GamebaseDataCallback<AuthToken>): void
  • description

    Try to login to provider

    Since Added 2.0.0.

    example
    
    toast.Gamebase.login('google', (authToken, error) => {
        if (error) {
            console.log('login failed');
            console.log(error);
            return;
        }
    
        console.log('login success');
        const userId = authToken.member.userId; // Gamebase UserId
        const accessToken = authToken.token.accessToken; // Gamebase AccessToken
    });

    Parameters

    • providerName: string

      guest, google, facebook, twitter, line, payco, and so on.

    • callback: GamebaseDataCallback<AuthToken>

      AuthToken has several information such as token, member and ban information.

    Returns void

Static loginWithAdditionalInfo

  • loginWithAdditionalInfo(providerName: string, additionalInfo: any, callback: GamebaseDataCallback<AuthToken>): void
  • description

    Try to login to provider with additionalInformation that is actually provider specified information.

    Since Added 2.0.0.

    example
    
    toast.Gamebase.login('google', {
        permmission: ['name', 'email', 'friends'],
    }, (authToken, error) => {
        if (error) {
            console.log('login failed');
            console.log(error);
            return;
        }
    
        console.log('login success');
        const userId = authToken.member.userId; // Gamebase UserId
        const accessToken = authToken.token.accessToken; // Gamebase AccessToken
    });

    Parameters

    • providerName: string
    • additionalInfo: any
    • callback: GamebaseDataCallback<AuthToken>

    Returns void

Static loginWithCredential

  • loginWithCredential(credential: any, callback: GamebaseDataCallback<AuthToken>): void
  • description

    Try to login with credential that has provider and token information.

    Since Added 2.0.0.

    example
    
    toast.Gamebase.loginWithCredential(
        { provider_name: 'facebook',
          access_token: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
          access_token_secret: 'SECRETISVERYIMPORTANT' },
        (authToken, error) => {
            if (error) {
                console.log('login failed');
                console.log(error);
                return;
            }
    
            console.log('login success');
            const userId = authToken.member.userId; // Gamebase UserId
            const accessToken = authToken.token.accessToken; // Gamebase AccessToken
        }
    );

    Parameters

    • credential: any
    • callback: GamebaseDataCallback<AuthToken>

    Returns void

Static logout

  • logout(callback: GamebaseCallback): void
  • description

    Try to logout.

    Since Added 2.0.0.

    Parameters

    • callback: GamebaseCallback

    Returns void

Static removeAllEventHandler

  • removeAllEventHandler(): void
  • description

    Remove all registered event handler.

    Since Added 2.10.0.

    Returns void

Static removeAllObserver

  • removeAllObserver(): void
  • description

    Remove all registered observers.

    Since Added 2.0.0.

    Returns void

Static removeAllServerPushEvent

  • removeAllServerPushEvent(): void
  • description

    Remove all registered server push events.

    Since Added 2.0.0.

    Returns void

Static removeEventHandler

  • removeEventHandler(eventHandler: EventHandlerEvent): void
  • description

    Remove the event handler.

    Since Added 2.10.0.

    Parameters

    • eventHandler: EventHandlerEvent

    Returns void

Static removeObserver

  • removeObserver(observer: Observer): void
  • description

    Remove the observer.

    Since Added 2.0.0.

    Parameters

    • observer: Observer

    Returns void

Static removeServerPushEvent

  • removeServerPushEvent(serverPushEvent: ServerPushEvent): void
  • description

    Remove the server push event.

    Since Added 2.0.0.

    Parameters

    • serverPushEvent: ServerPushEvent

    Returns void

Static setDebugMode

  • setDebugMode(isDebugMode: boolean): void
  • description

    Set the debug mode. If debugmode is enabled, Gamebase write logs to console. As These logs could be sensitive, be careful to set it enabled. You can hook the whole logs using toast.GamebaseLogger.registerLogger(new CustomLogger()); And you can set it off using toast.GamebaseLogger.enableLog = false;

    Since Added 2.0.0.

    Parameters

    • isDebugMode: boolean

    Returns void

Static setDisplayLanguageCode

  • setDisplayLanguageCode(languageCode: string): void
  • description

    Set Gamebase display language code. Gamebase uses this display language code to Gamebase UI such as maintenace modal and user banned modal.

    Since Added 2.0.0.

    Parameters

    • languageCode: string

    Returns void

Static setDisplayLanguageTable

  • setDisplayLanguageTable(displayLanguageTable: string): void
  • description

    Set Gamebase Display Language Table. Gamebase uses this display language table to find out which text should be rendered at Gamebase UI such as maintenace modal and user banned modal. What is important is that default display language table is embeded in Gamebase sdk, and if you set the display language table through this mehtod, Gamebase internally merged both of the table. You can checek the default display language table through the toast.Gamebase.getDisplayLanguageTable() API.

    Since Added 2.0.0.

    example
    
    toast.Gamebase.setDisplayLanguageTable({
        en: {
            common_ok_button: 'Customized OK Text',
            common_cancel_button: 'Customized Cancel Text',
            ...
        },
        ko: {
            common_ok_button: '예',
            common_cancel_button: '아니오',
            ...
        },
        ....
    });

    Parameters

    • displayLanguageTable: string

    Returns void

Static withdraw

  • withdraw(callback: GamebaseCallback): void
  • description

    Try to withdraw.

    Since Added 2.0.0.

    Parameters

    • callback: GamebaseCallback

    Returns void

Object literals

Static Analytics

Analytics: object

Analytics classes

setGameUserData

  • setGameUserData(gameUserData: GameUserData): void
  • This method sends level information to the server. This method is used to transfer level information to the server if the game is successful.

    Since Added 2.0.0.

    Parameters

    • gameUserData: GameUserData

      Level information of the user received from the game server after login.

    Returns void

traceLevelUp

  • traceLevelUp(levelUpData: LevelUpData): void
  • This method sends level-up information to the server. This method is used to send level-up information to the server when level up in game.

    Since Added 2.0.0.

    Parameters

    • levelUpData: LevelUpData

      User level up information

    Returns void

Static Launching

Launching: object

Launching classes

getLaunchingInformations

  • getLaunchingInformations(): LaunchingInfo
  • This method returns Gamebase launching information.

    Since Added 2.0.0.

    Returns LaunchingInfo

getLaunchingStatus

  • getLaunchingStatus(): number
  • This method returns Gamebase launching status.

    Since Added 2.0.0.

    Returns number

Static Network

Network: object

Network classes

isConnected

  • isConnected(): boolean
  • This method returns network connecting status using browser API navigator.onLine.

    Since Added 2.0.0.

    Returns boolean

    boolean

Static Point

Point: object

charge

  • charge(callback: GamebaseDataCallback<PointBalance>): void
  • Charge your points

    Since Added 2.8.0.

    Parameters

    • callback: GamebaseDataCallback<PointBalance>

    Returns void

inquiryBalance

  • inquiryBalance(callback: GamebaseDataCallback<PointBalance>): void
  • Request a item list which is purchasable. This list has items which are registered in both Market(AppStore) and ToastCloud IAP Console.

    Since Added 2.8.0.

    Parameters

    • callback: GamebaseDataCallback<PointBalance>

    Returns void

purchase

  • purchase(productId: string, callback: GamebaseDataCallback<PurchasableReceipt>): void
  • Call following API of an item to purchase by using itemId to send a purchase request. When a game user cancels purchasing, the PURCHASE_USER_CANCELED error will be returned.

    Since Added 2.8.0.

    Parameters

    • productId: string
    • callback: GamebaseDataCallback<PurchasableReceipt>

    Returns void

requestConsumablePurchases

  • requestConsumablePurchases(callback: GamebaseDataCallback<PurchasableReceipt[]>): void
  • Request for a list of non-consumed items, which have not been normally consumed (delivered, or provided) after purchase. In case of non-purchased items, ask the game server (item server) to proceed with item delivery (supply).

    Since Added 2.14.0.

    Parameters

    • callback: GamebaseDataCallback<PurchasableReceipt[]>

    Returns void

requestProductDetails

  • requestProductDetails(callback: GamebaseDataCallback<PurchasableItem[]>): void
  • Call following API of an item to purchase by using itemId to send a purchase request. When a game user cancels purchasing, the PURCHASE_USER_CANCELED error will be returned.

    Since Added 2.8.0.

    Parameters

    • callback: GamebaseDataCallback<PurchasableItem[]>

    Returns void

Static TemporaryWithdrawal

TemporaryWithdrawal: object

TemporaryWithdrawal classes

cancelWithdrawal

  • cancelWithdrawal(callback: GamebaseCallback): void
  • If the user has requested to withdraw, cancel it. If the user has never requested to leave, the function call will fail.

    Since Added 2.9.0.

    Parameters

    • callback: GamebaseCallback

    Returns void

requestWithdrawal

  • requestWithdrawal(callback: GamebaseDataCallback<TemporaryWithdrawalInfo>): void
  • Request to Temporary Withdrawal. If the user who requested the temporary withdrawal logs in, you can check the grace expiration time through the AuthToken.member.temporaryWithdrawalInfo.gracePeriodDate.

    Since Added 2.9.0.

    Parameters

    • callback: GamebaseDataCallback<TemporaryWithdrawalInfo>

    Returns void

withdrawImmediately

  • withdrawImmediately(callback: GamebaseCallback): void
  • This function ignores the withdrawal grace period and proceeds withdrawal immediately.

    Since Added 2.9.0.

    Parameters

    • callback: GamebaseCallback

    Returns void

Static Util

Util: object
description

Utility classes

showAlert

  • showAlert(message: string, callback: function): void
  • This method shows alert using browser API alert().

    Since Added 2.0.0.

    Parameters

    • message: string
    • callback: function
        • (): void
        • Returns void

    Returns void

showConfirm

  • showConfirm(message: string, callback: function): void
  • This method shows confirm alert using browser API confirm().

    Since Added 2.0.0.

    Parameters

    • message: string
    • callback: function
        • (isConfirmed: boolean): void
        • Parameters

          • isConfirmed: boolean

          Returns void

    Returns void