npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hmscore/hms-js-gameservice

v5.2.0-300

Published

HMS JS GameService

Readme

JSB GameService

Contents

1. Introduction

2. Installation Guide

Creating a Project in AppGallery Connect

Creating an app in AppGallery Connect is required in order to communicate with the Huawei services. To create an app, perform the following steps:

Step 1. Sign in to AppGallery Connect and select My projects.

Step 2. Select your project from the project list or create a new one by clicking the Add Project button.

Step 3. Go to Project Setting > General information, and click Add app. If an app exists in the project and you need to add a new one, expand the app selection area on the top of the page and click Add app.

Step 4. On the Add app page, enter the app information, and click OK.

  • A signing certificate fingerprint is used to verify the authenticity of an app when it attempts to access an HMS Core service through the HMS Core SDK. Before using HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in AppGallery Connect. Ensure that the JDK has been installed on your computer.

Configuring the Signing Certificate Fingerprint

Step 1. Go to Project Setting > General information. In the App information field, click the icon next to SHA-256 certificate fingerprint, and enter the obtained SHA256 certificate fingerprint.

Step 2. After completing the configuration, click check mark.

React-Native Integration

Step 1: Sign in to AppGallery Connect and select My projects.

Step 2: Find your app project, and click the desired app name.

Step 3: Go to Project Setting > General information. In the App information section, click agconnect-service.json to download the configuration file.

Step 4: Create a React Native project if you do not have one.

Step 5: Copy the agconnect-service.json file to the android/app directory of your React Native project.

Step 6: Copy the signature file that generated in Generating a Signing Certificate section, to the android/app directory of your React Native project.

Step 7: Check whether the agconnect-services.json file and signature file are successfully added to the android/app directory of the React Native project.

Step 8: Open the AndroidManifest.xml file, add the following lines, and replace the value <app_id> with the value you found in the agconnect-services.json file.

<application>
...
  <meta-data
    android:name="com.huawei.hms.client.appid"
    android:value="appid=<app_id>" />
</application>

Step 9: Open the build.gradle file in the android directory of your React Native project.

  • Go to buildscript then configure the Maven repository address and agconnect plugin for the HMS SDK.
buildscript {
  repositories {
    google()
    jcenter()
    maven { url 'https://developer.huawei.com/repo/' }
  }

  dependencies {
    /*
      * <Other dependencies>
      */
    classpath 'com.huawei.agconnect:agcp:1.4.2.301'
  }
}
  • Go to allprojects then configure the Maven repository address for the HMS SDK.
allprojects {
  repositories {
    /*
      * <Other repositories>
      */
    maven { url 'https://developer.huawei.com/repo/' }
  }
}

Step 10: Open the build.gradle file in the android/app directory of your React Native project.

  • Package name must match with the package_name entry in agconnect-services.json file.
defaultConfig {
  applicationId "<package_name>"
  minSdkVersion 19
  /*
   * <Other configurations>
   */
}
android {
  /*
   * <Other configurations>
   */

  signingConfigs {
    config {
      storeFile file('<keystore_file>.jks')
      storePassword '<keystore_password>'
      keyAlias '<key_alias>'
      keyPassword '<key_password>'
    }
  }

  buildTypes {
    debug {
      signingConfig signingConfigs.config
    }
    release {
      signingConfig signingConfigs.config
      minifyEnabled enableProguardInReleaseBuilds
      ...
    }
  }
}

Step 11: Open the build.gradle file in the android/app directory of your React Native project.

  • Configure build dependencies.
buildscript {
  ...
  dependencies {
    /*
    * <Other dependencies>
    */
    implementation ('com.huawei.hms:rn-adapter:5.2.0.300'){
        exclude group: 'com.facebook.react'
    }
    ...
  }
}

Step 12: Import the following class to the MainApplication.java file of your project.

import com.huawei.hms.jsb.adapter.rn.RnJSBReactPackage;

Then, add the RnJSBReactPackage() to your getPackages method. In the end, your file will be similar to the following:

@Override
protected List<ReactPackage> getPackages() {
    List<ReactPackage> packages = new PackageList(this).getPackages();
    packages.add(new RnJSBReactPackage()); // <-- Add this line
    return packages;
}
...

Step 13: Download js-sdk using command below.

npm i @hmscore/hms-js-gameservice

Step 14: Import HMSGameService in App.js as following line.

import HMSGameService from "@hmscore/hms-js-gameservice";

Step 15: First you have to call the init function.

import {NativeModules, DeviceEventEmitter} from "react-native";
...
HMSGameService.init(NativeModules, DeviceEventEmitter);

Step 16: Run your project.

  • Run the following command to the project directory.
react-native run-android

Cordova Integration

Step 1: Install Cordova CLI if haven't done before.

npm install -g cordova

Step 2: Create a new Cordova project or use the existing one.

  • To create new Cordova project, you can use cordova create path [id [name [config]]] [options] command. For more details please follow CLI Reference - Apache Cordova.

Step 3: Update the widget id property which is specified in the config.xml file. It must be same with package_name value of the agconnect-services.json file.

Step 4: Add the Android platform to the project if haven't done before.

cordova platform add android

Step 5: Download plugin using command below.

cordova plugin add @hmscore/hms-js-gameservice

Step 6: Copy agconnect-services.json file to <project_root>/platforms/android/app directory.

Step 7: Add keystore(.jks) and build.json files to your project's root directory.

  • You can refer to 3rd and 4th steps of Generating a Signing Certificate Codelab tutorial page for generating keystore file.

  • Fill build.json file according to your keystore information. For example:

    {
      "android": {
        "debug": {
          "keystore": "<keystore_file>.jks",
          "storePassword": "<keystore_password>",
          "alias": "<key_alias>",
          "password": "<key_password>"
        },
        "release": {
          "keystore": "<keystore_file>.jks",
          "storePassword": "<keystore_password>",
          "alias": "<key_alias>",
          "password": "<key_password>"
        }
      }
    }

**Step 8:** Import the following class to the **MainActivity.java** file of your project. You can find this file in **`platforms/android/app/src/main/java/<your_package_name>`** directory.

​```java
import com.huawei.hms.jsb.adapter.cordova.CordovaJSBInit;

Step 9: In the same file, add CordovaJSBInit.initJSBFramework(this) line after the super.onCreate(savedInstanceState) method call.

  • In the end, your file will be similar to the following:
  ...

  import com.huawei.hms.jsb.adapter.cordova.CordovaJSBInit;

  public class MainActivity extends CordovaActivity
  {
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          CordovaJSBInit.initJSBFramework(this);

          ...
      }
      ...
  }

**Step 10:** Open the **AndroidManifest.xml** file, add the following lines, and replace the value **<app_id>** with the **app_id** value that can be found in the **agconnect-services.json** file.

​```xml
<application>
...
     <meta-data
            android:name="com.huawei.hms.client.appid"
            android:value="appid=<app_id>" />
</application>

Step 11: Run the app

cordova run android

Ionic Integration

Install Ionic CLI and other required tools if haven't done before.

npm install -g @ionic/cli cordova-res native-run

Ionic with Cordova Runtime

Step 1: Enable the Cordova integration if haven't done before.

ionic integrations enable cordova

Step 2: Update the widget id property which is specified in the config.xml file. It must be same with package_name value of the agconnect-services.json file.

Step 3: Add the Android platform to the project if haven't done before.

ionic cordova platform add android

Step 4: Install HMS Game Service Plugin to the project.

ionic cordova plugin add @hmscore/hms-js-gameservice

Step 5: Copy agconnect-services.json file to <project_root>/platforms/android/app directory.

Step 6: Add keystore(.jks) and build.json files to your project's root directory.

  • You can refer to 3rd and 4th steps of Generating a Signing Certificate Codelab tutorial page for generating keystore file.

  • Fill build.json file according to your keystore information. For example:

{
  "android": {
    "debug": {
      "keystore": "<keystore_file>.jks",
      "storePassword": "<keystore_password>",
      "alias": "<key_alias>",
      "password": "<key_password>"
    },
    "release": {
      "keystore": "<keystore_file>.jks",
      "storePassword": "<keystore_password>",
      "alias": "<key_alias>",
      "password": "<key_password>"
    }
  }
}

Step 7: Import the following class to the MainActivity.java file of your project. You can find this file in platforms/android/app/src/main/java/<your_package_name> directory.

import com.huawei.hms.jsb.adapter.cordova.CordovaJSBInit;

Step 8: In the same file, add CordovaJSBInit.initJSBFramework(this) line after the super.onCreate(savedInstanceState) method call.

  • In the end, your file will be similar to the following:
...

import com.huawei.hms.jsb.adapter.cordova.CordovaJSBInit;

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        CordovaJSBInit.initJSBFramework(this);

        ...
    }
    ...
}

Step 9: Open the AndroidManifest.xml file, add the following lines, and replace the value <app_id> with the app_id value that can be found in the agconnect-services.json file.

<application>
...
  <meta-data
    android:name="com.huawei.hms.client.appid"
    android:value="appid=<app_id>" />
</application>

Step 10: Run the application.

ionic cordova run android --device

Ionic with Capacitor Runtime

Step 1: Enable the Capacitor integration if haven't done before.

ionic integrations enable capacitor

Step 2: Initialize Capacitor if haven't done before.

npx cap init [appName] [appId]

Step 3: Update the appId property which is specified in the capacitor.config.json file according to your project. It must be same with package_name value of the agconnect-services.json file.

Step 4: Install HMS Game Service plugin to the project.

npm install @hmscore/hms-js-gameservice

Step 5: Build Ionic app to generate resource files.

ionic build

Step 6: Add the Android platform to the project.

npx cap add android

Step 7: Copy keystore(.jks) and agconnect-services.json files to <project_root>/android/app directory.

Step 8: Open the build.gradle file in the <project_root>/android/app directory.

  • Add signingConfigs entry to the android section and modify it according to your keystore.

  • Enable signingConfig configuration for debug and release flavors.

...

android {

    ...

    // Modify signingConfigs according to your keystore
    signingConfigs {
        config {
            storeFile file('<keystore_file>.jks')
            storePassword '<keystore_password>'
            keyAlias '<key_alias>'
            keyPassword '<key_password>'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.config // Enable signingConfig for debug flavor
        }
        release {
            signingConfig signingConfigs.config // Enable signingConfig for release flavor
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

...
  • Add apply plugin:'com.huawei.agconnect to top of your build gradle file in the <project_root>/android/app directory.

Step 9: Open the build.gradle file in the <project_root>/android directory. Add Huawei's maven repositories and agconnect classpath to the file.

buildscript {
    repositories {
        /*
            <Other repositories>
        */
        maven { url 'https://developer.huawei.com/repo/' }
    }
    dependencies {
        /*
            <Other dependencies>
        */
        classpath 'com.huawei.agconnect:agcp:1.4.2.301'
    }
}

/*
    <Other build.gradle entries>
*/

allprojects {
    repositories {
        /*
            <Other repositories>
        */
        maven { url 'https://developer.huawei.com/repo/' }
    }
}

Step 10: Import the following class to the MainActivity.java file of your project. You can find this file in android/app/src/main/java/<your_package_name> directory.

import com.huawei.hms.js.gameservice.HMSGameService;

Step 11: In the same file, add add(HMSGameService.class); line to the ArrayList.

  • In the end, your file will be similar to the following:

    ...
    import com.huawei.hms.js.gameservice.HMSGameService;
    public class MainActivity extends BridgeActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
    
      // Initializes the Bridge
      this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
          add(HMSGameService.class);
      }});
    }
    ...

Step 12: Open the AndroidManifest.xml file, add the following lines, and replace the value <app_id> with the app_id value that can be found in the agconnect-services.json file.

<application>
...
     <meta-data
            android:name="com.huawei.hms.client.appid"
            android:value="appid=<app_id>" />
</application>

Step 13: Updates dependencies, and copy any web assets to your project.

npx cap sync

Step 14: Open the project in Android Studio and run it.

npx cap open android

3. API Reference

HMSGameService

Public Method Summary

| Method | Return Type | Description | | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | | signIn | Promise<Result<void>> | This API allows you to log in for the huawei game service. | | silenSignIn | Promise<Result<void>> | The silentSignIn method allows users to use the same HUAWEI ID without authorization for subsequent sign-ins. | | signOut | Promise<Result<void>> | This API allows you to log out for the huawei game service. | | isShowBuoy | Promise<Result<void>> | Displays the floating window. | | getCurrentPlayer | Promise<Result<Player>> | Obtains the object of the current player. | | getCachePlayerId() | Promise<Result<String>> | Obtains the locally cached player ID of the current player. | | getCachePlayer() | Promise<Result<Player>> | Obtains the locally cached player information of the current player. | | getAchievementsIntent() | Promise<Result<void>> | Obtains the list of all game achievements of the current player. | | incrementAchievement(achievementId,numSteps) | Promise<Result<void>> | Asynchronously increases an achievement by the given number of steps. | | incrementAchievementImmediate(achievementId,numSteps) | Promise<Result<Boolean>> | Synchronously increases an achievement by the given number of steps. | | loadAchievementList(forceLoad) | Promise<Result<List<Achievement>>> | Obtains the list of achievements in all statuses for the current player. | | eventIncrement(eventId,incrementAmount) | Promise<Result<void>> | Submits the event data of the current player. | | revealAchievement(achievementId) | Promise<Result<void>> | Asynchronously reveals a hidden achievement to the current player. | | revealAchievementImmediate(achievementId) | Promise<Result<void>> | Synchronously reveals a hidden achievement to the current player. | | setAchievementSteps(achievementId,numSteps) | Promise<Result<void>> | Asynchronously sets an achievement to have the given number of steps completed. | | setAchievementStepsImmediate(achievementId,numSteps) | Promise<Result<Boolean>> | Synchronously sets an achievement to have the given number of steps completed. | | unlockAchievement(achievementId) | Promise<Result<void>> | Asynchronously unlocks an achievement for the current player. | | unlockAchievementImmediate(achievementId) | Promise<Result<void>> | Synchronously unlocks an achievement for the current player. | | loadEventList(forceReload, eventIds) | Promise<Result<List<Event>>> | Obtains all event data of the current player with ID or without ID. | | getAllRankingsIntent() | Promise<Result<void>> | Obtains the Intent object of the leaderboard list page. | | getRankingByTimeIntent(rankingId,timeDimension) | Promise<Result<void>> | Obtains the Intent object of the page for a specified leaderboard in a specified time frame. | | getRankingIntent(rankingId) | Promise<Result<void>> | Obtains the Intent object of the page for a specified leaderboard in all time frames. | | loadTopScorePage(rankingId,timeDimension, maxResults,offsetPlayerRank,pageDirection) | Promise<Result<RankingScores>> | Obtains the scores on the first page of a leaderboard from Huawei game server. | | loadTopScore(rankingId,timeDimension, maxResults,isRealTime) | Promise<Result<RankingScores>> | Obtains scores on the first page of a leaderboard. The data can be obtained from the local cache. | | submitScore(rankingId,score) | Promise<Result<void>> | Asynchronously submits the score of the current player without a custom unit. | | submitScoreTag(rankingId,score,scoreTips) | Promise<Result<void>> | Asynchronously submits the score of the current player with a custom unit. | | submitScoreImmediate(rankingId,score) | Promise<Result<ScoreSubmissionInfo>> | Synchronously submits the score of the current player without a custom unit. | | submitScoreImmediateTag(rankingId,score,scoreTips) | Promise<Result<ScoreSubmissionInfo>> | Synchronously submits the score of the current player with a custom unit. | | getRankingsSwitchStatus() | Promise<Result<Number>> | Obtains the current player's leaderboard switch setting. | | setRankingsSwitchStatus(status) | Promise<Result<Number>> | Sets the leaderboard switch for the current player. | | getCurrentGameMetadata() | Promise<Result<GameSummary>> | Obtains the information about the current game from the local cache. | | loadGameMetadata() | Promise<Result<GameSummary>> | Obtains the information about the current game from Huawei game server. If the obtaining fails, the information will then be obtained from the local cache. | | loadGamePlayerStats(isRealTime) | Promise<Result<GamePlayerStatistics>> | Obtains the statistics of the current player, such as the session duration and rank. | | loadCurrentPlayerRankingScore(rankingId,timeDimension) | Promise<Result<RankingScores>> | Obtains the score of a player on a specified leaderboard in a specified time frame. | | loadRankingMetadata(rankingId,isRealTime) | Promise<Result<RankingScores>> | Obtains the data of a leaderboard. The data can be obtained from the local cache. | | loadRankingsMetadata(isRealTime) | Promise<Result<RankingScores>> | Obtains all leaderboard data. The data can be obtained from the local cache. | | loadMoreScores(rankingId,offsetPlayerRank,maxResults, pageDirection,timeDimension) | Promise<Result<RankingScores>> | Obtains scores on a leaderboard in a specified time frame in pagination mode. | | loadPlayerCenteredPageScores(rankingId,timeDimension,maxResults,offsetPlayerRank, pageDirection) | Promise<Result<RankingScores>> | Obtains scores of a leaderboard with the current player's score displayed in the page center from Huawei game server. | | loadPlayerCenteredScores(rankingId,timeDimension,maxResults, isRealTime) | Promise<Result<RankingScores>> | Obtains scores of a leaderboard with the current player's score displayed in the page center. The data can be obtained from the local cache. | | getPlayerExtraInfo(transactionId) | Promise<Result<PlayerExtraInfo>> | Obtains the additional information about a player. | | submitPlayerEvent(playerId,eventId,eventType) | Promise<Result<String>> | Reports player behavior events. | | savePlayerInfo(rank, role, area, sociaty, playerId, openId) | Promise<Result<String>> | Saves the information about the player in the current game. | | checkGameServiceLite() | Promise<Result<void>> | Checks game service. | | checkMobile(checkWithOpenId, mobile, gameAppId, playerId, ts, transactionId, inputSign) | Promise<Result<void>> | | | cancelGameService() | Promise<Result<Boolean>> | Revokes the authorization to HUAWEI Game Service. | | getPlayerRestTime(transactionId) | Promise<Result<String>> | Returns player real name |

3.1.2 Public Methods

signIn()

| Return Type | Description | | ---------------------- | ------------------------------------------- | | Promise<Result<void>> | Returns object containing login information |

Call Example

HMSGameService.signIn()
    .then((res) =>{console.log(JSON.stringify(res))})    
    .catch((err) =>{console.log(JSON.stringify(err))})

signOut()

| Return Type | Description | | ---------------------- | -------------------------------------------- | | Promise<Result<void>> | Returns object containing logout information |

Call Example

HMSGameService.signOut()
    .then((res) =>{console.log(JSON.stringify(res))})    
    .catch((err) =>{console.log(JSON.stringify(err))})

silenSignIn ()

| Return Type | Description | | ---------------------- | -------------------------------------------- | | Promise<Result<void>> | Returns object containing sign in information |

Call Example

HMSGameService.silenSignIn()
    .then((res) =>{console.log(JSON.stringify(res))})    
    .catch((err) =>{console.log(JSON.stringify(err))})

isShowBuoy()

| Return Type | Description | | ---------------------- | ----------------------------- | | Promise<Result<void>> | Displays the floating window. |

Call Example

HMSGameService.isShowBuoy()
     .then((res) =>{console.log(JSON.stringify(res))})
     .catch((err) =>{console.log(JSON.stringify(err))})

getCurrentPlayer()

| Return Type | Description | | ------------------------ | ----------------------------------- | | Promise<Result<Player>> | Returns the details about a player. |

Call Example

HMSGameService.getCurrentPlayer()
     .then((player) => {console.log(JSON.stringify(player))})     
     .catch((err) =>{console.log(JSON.stringify(err))})

getCachePlayerId()

| Return Type | Description | | ------------------------ | ------------------------- | | Promise<Result<string>> | ID of a player in a game. |

Call Example

HMSGameService.getCachePlayerId()
     .then((player) => {console.log(JSON.stringify(player))})
     .catch((err) =>{console.log(JSON.stringify(err))})

getCachePlayer()

| Return Type | Description | | ------------------------ | ------------------------- | | Promise<Result<Player>> | ID of a player in a game. |

Call Example

HMSGameService.getCachePlayer()
     .then((player) => {console.log(JSON.stringify(player))})     
     .catch((err) =>{console.log(JSON.stringify(err))})

getAchievementsIntent()

| Return Type | Description | | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------- | | Promise<Result<void>> | Intent object containing the achievement list. An app can call the startActivityForResult method to access the achievement list. |

Call Example

HMSGameService.getAchievementsIntent()
     .then((res) =>{console.log(JSON.stringify(res))})    
     .catch((err) =>{console.log(JSON.stringify(err))})

incrementAchievement(achievementId,numSteps)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------------------------------------ | | achievementId | string | ID of the achievement requiring step increase. | | numSteps | number | Number of steps to be increased. The value must be greater than 0. |

| Return Type | Description | | ---------------------- | --------------------------------------------------------------------- | | Promise<Result<void>> | Asynchronously increases an achievement by the given number of steps. |

Call Example

HMSGameService.getAchievementsIntent()
     .then((res) =>{console.log(JSON.stringify(res))})
     .catch((err) =>{console.log(JSON.stringify(err))})

incrementAchievementImmediate(achievementId,numSteps)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------------------------------------ | | achievementId | string | ID of the achievement requiring step increase. | | numSteps | number | Number of steps to be increased. The value must be greater than 0. |

| Return Type | Description | | ------------------------- | ------------------------------------------------------------ | | Promise<Result<boolean>> | true if the execution is successful; false if the API call is successful but the execution fails. If false is returned, ensure that the achievement ID and number of steps to be increased are correct. |

Call Example

const achievementId = "958D2546B5663BE6D439A7A2C505422127CB661952D**********"
const numSteps = 1
HMSGameService.incrementAchievementImmediate(achievementId,numSteps)
     .then((res) =>{console.log(JSON.stringify(res))})
     .catch((err) =>{console.log(JSON.stringify(err))})

loadAchievementList(forceLoad)

| Parameter | Type | Description | | --------- | ------- | ------------------------------------------------------------------------------------------------------- | | forceLoad | boolean | Indicates whether to obtain the achievement list from the server or client. The options are as follows:true: server false: client |

| Return Type | Description | | ----------------------------------------------- | --------------------------- | | Promise<Result<Achievement[]>> | Return a Achievement array. |

Call Example

const forceReload = true
HMSGameService.loadAchievementList(forceReload)   
    .then((res) =>{console.log(JSON.stringify(res))})    
    .catch((err) =>{console.log(JSON.stringify(err))})

eventIncrement(eventId,incrementAmount)

| Parameter | Type | Description | | --------------- | ------ | ------------------------------------------------------------------------------------- | | eventId | string | ID of the event to be submitted. The value is obtained after you configure the event. | | incrementAmount | number | Increment amount of the existing event value. |

| Return Type | Description | | ---------------------- | ------------------- | | Promise<Result<void>> | Submits event data. |

Call Example

const eventId = "E5E02A4A2D6A0C36C45A77CDF11D24D785C030ABE49A*********"
const growAmount = 1
HMSGameService.eventIncrement(eventId, growAmount)
    .then((res) =>{console.log(JSON.stringify(res))})
    .catch((err) =>{console.log(JSON.stringify(err))})

revealAchievement(achievementId)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | achievementId | string | ID of the achievement to be revealed. |

| Return Type | Description | | ---------------------- | ------------------------------------------------------ | | Promise<Result<void>> | Asynchronously reveals a hidden achievement of a game. |

Call Example

const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
HMSGameService.revealAchievement(achievementId)
    .then((res) =>{console.log(JSON.stringify(res))})
    .catch((err) =>{console.log(JSON.stringify(err))})

revealAchievementImmediate(achievementId)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | achievementId | string | ID of the achievement to be revealed. |

| Return Type | Description | | ---------------------- | --------------------------------------------------- | | Promise<Result<void>> | Immediately reveals a hidden achievement of a game. |

Call Example

const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
HMSGameService.revealAchievementImmediate(achievementId)
    .then((res) =>{console.log(JSON.stringify(res))})
    .catch((err) =>{console.log(JSON.stringify(err))})

setAchievementSteps(achievementId,numSteps)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------------------------------ | | achievementId | string | ID of the achievement requiring step setting. | | numSteps | number | Number of steps to be set. The value must be greater than 0. |

| Return Type | Description | | ---------------------- | ------------------------------------------------------------ | | Promise<Result<void>> | Asynchronously sets the number of completed steps of an achievement. |

Call Example

const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
var numSteps = 3;
HMSGameService.setAchievementSteps(achievementId, numSteps)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))})

setAchievementStepsImmediate(achievementId,numSteps)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------------------------------ | | achievementId | string | ID of the achievement requiring step setting. | | numSteps | number | Number of steps to be set. The value must be greater than 0. |

| Return Type | Description | | ------------------------- | ------------------------------------------------------------ | | Promise<Result<boolean>> | true if the execution is successful; false if the API call is successful but the execution fails. If false is returned, ensure that the achievement ID and number of steps to be increased are correct. |

Call Example

const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
var numSteps = 3;
HMSGameService.setAchievementSteps(achievementId, numSteps)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))})

unlockAchievement(achievementId)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | achievementId | string | ID of the achievement to be unlocked. |

| Return Type | Description | | ---------------------- | ------------------------------------------------------------ | | Promise<Result<void>> | Asynchronously unlocks an achievement for the current player. |

Call Example

const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
HMSGameService.unlockAchievement(achievementId)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))})

unlockAchievementImmediate(achievementId)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | achievementId | string | ID of the achievement to be unlocked. |

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<void>> | Immediately unlocks an achievement for the current player. |

Call Example

const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
HMSGameService.unlockAchievementImmediate(achievementId)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))})

loadEventList(forceReload, eventIds)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | achievementId | string | Indicates whether to load the event list stored on the server or cached locally. The options are as follows: true: server false: local cache | | eventIds | string[] | IDs of the events to be obtained. The value is a string array. |

| Return Type | Description | | ----------------------------------- | ---------------------- | | Promise<Result<Event[]>> | Return an Event array. |

Call Example

const forceReload = true;
const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
HMSGameService.loadEventList(forceReload, eventId)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))})   

getAllRankingsIntent()

| Return Type | Description | | ---------------------- | ------------------------------- | | Promise<Result<void>> | Intent object of a leaderboard. |

Call Example

HMSGameService.getAllRankingsIntent()
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

getRankingByTimeIntent()

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------------------------------ | | rankingId | string | ID of a leaderboard for which data is to be obtained. | | timeDimension | number | Time frame. The options are as follows: 0: The daily leaderboard is obtained. 1: The weekly leaderboard is obtained. 2: The all-time leaderboard is obtained. |

| Return Type | Description | | ---------------------- | ------------------------------------------- | | Promise<Result<void>> | Intent object of the leaderboard list page. |

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const timeDimension = 1;
HMSGameService.getRankingByTimeIntent(rankingId, timeDimension)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

getRankingIntent(rankingId)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rankingId | string | ID of a leaderboard for which data is to be obtained. |

| Return Type | Description | | ---------------------- | ------------------------------- | | Promise<Result<void>> | Intent object of a leaderboard. |

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
HMSGameService.getRankingIntent(rankingId)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadTopScorePage(rankingId,timeDimension, maxResults,offsetPlayerRank,pageDirection)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rankingId | string | ID of a leaderboard for which data is to be obtained. | | timeDimension | number | Time frame. The options are as follows: 0: daily 1: weekly 2: all-time | | maxResults | number | Maximum number of records on each page. The value is an number ranging from 1 to 21. | | offsetPlayerRank | number | IRank specified by offsetPlayerRank. Then one page of scores before or after (specified by pageDirection) a rank will be loaded. The value of offsetPlayerRank must be 0 or a positive number. | | pageDirection | number | Data obtaining direction. Currently, only the value 0 is supported, indicating that data of the next page is obtained. |

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<RankingScores>> | Scores on the first page of a leaderboard.|

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const timeDimension = 2;
const maxResults = 20;
const offsetPlayerRank = 0;
const pageDirection = 0;
HMSGameService.loadTopScorePage(
rankingId,
    timeDimension,
    maxResults,
    offsetPlayerRank,
    pageDirection
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadTopScore(rankingId,timeDimension, maxResults,isRealTime)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rankingId | string | ID of a leaderboard for which data is to be obtained. | | timeDimension | number | Time frame. The options are as follows: 0: daily1: weekly2: all-time | | maxResults | number | Maximum number of records on each page. The value is an number ranging from 1 to 21. | | isRealTime | boolean | Indicates whether to obtain leaderboard data from Huawei game server. The options are as follows:true: Obtain data from Huawei game server. false: Obtain data from the local cache.|

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<RankingScores>> | Scores on the first page of a leaderboard.|

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const timeDimension = 2;
const maxResults = 20;
const isRealTime = true;
HMSGameService.loadTopScore(
    rankingId,
    timeDimension,
    maxResults,
    isRealTime
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

submitScore(rankingId,score)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rankingId | string | ID of a leaderboard for which data is to be obtained. | | score | number | Score of the current player. |

| Return Type | Description | | ---------------------- | ------------------------------------------------------------ | | Promise<Result<void>> | Asynchronously submits the score of the current player without a custom unit. |

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const score = 20
HMSGameService.submitScore(rankingId, score)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

submitScoreTag(rankingId,score,scoreTips)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rankingId | string | ID of a leaderboard for which data is to be obtained. | | score | number | Score of the current player. | | scoreTips | number | Score custom unit. Only letters, digits, underscores (_), and hyphens (-) are supported. |

| Return Type | Description | | ---------------------- | ------------------------------------------------------------ | | Promise<Result<void>> | Asynchronously submits the score of the current player with a custom unit. |

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const score = 10;
const scoreTips = "scoreTips";
HMSGameService.submitScoreTag(rankingId, score, scoreTips)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

submitScoreImmediate(rankingId,score)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rankingId | string | ID of a leaderboard for which data is to be obtained. | | score | number | Score of the current player. |

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<ScoreSubmissionInfo>> | Score submission result. |

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const score = 10;
HMSGameService.submitScoreImmediate(rankingId, score)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

submitScoreImmediateTag(rankingId,score,scoreTips)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rankingId | string | ID of a leaderboard for which data is to be obtained. | | score | number | Score of the current player. | | scoreTips | number | Score custom unit. Only letters, digits, underscores (_), and hyphens (-) are supported. |

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<ScoreSubmissionInfo>> | Score submission result. |

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const score = 100;
const scoreTips = "scoreTips";
HMSGameService.submitScoreImmediateTag(
  rankingId,
  score,
  scoreTips
)
    .then((res) => {console.log(JSON.stringify(res))})
    .catch((err) => {console.log(JSON.stringify(err))})

getRankingsSwitchStatus()

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | [Promise<Result<number>> | Leaderboard switch setting. The setting is returned asynchronously and has the following options: 0: off 1: no |

Call Example

 HMSGameService.getRankingsSwitchStatus()
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

setRankingsSwitchStatus(status)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | status | number | Status of the leaderboard switch to be set. 0: off 1: no |

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | [Promise<Result<number>> | Leaderboard switch setting. The setting is returned asynchronously and has the following options: 0: off 1: no |

Call Example

const status = 0 
HMSGameService.setRankingsSwitchStatus(status)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

getCurrentGameMetadata()

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<GameSummary>> | A GameSummary object that contains the information about the current game. |

Call Example

HMSGameService.getCurrentGameMetadata()
    .then((res) => {console.log(JSON.stringify(res))})
    .catch((err) => {console.log(JSON.stringify(err))})

loadGameMetadata()

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<GameSummary>> | Information about the current game. |

Call Example

HMSGameService.loadGameMetadata()
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadGamePlayerStats(isRealTime)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | isRealTime | number | Indicates whether to obtain data from Huawei game server. The options are as follows: true: Obtain data from Huawei game server false: Obtain data from the local cache. Data is kept in the local cache for 5 minutes. If there is no local cache or the cache times out, data will be obtained from the game server. |

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<GamePlayerStatistics>> | Statistics of the current player. |

Call Example

const isRealTime = true
HMSGameService.loadGamePlayerStats(isRealTime)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadCurrentPlayerRankingScore(rankingId,timeDimension)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rankingId | string | ID of a leaderboard for which data is to be obtained. | | timeDimension | number |Time frame. The options are as follows: 0: The daily leaderboard is obtained. 1: The weekly leaderboard is obtained. 2: The all-time leaderboard is obtained. |

| Return Type | Description | | ------------------------------------------------- | ------------------------------------------------------------ | | Promise<Result<RankingScores>> | Score of a player on a leaderboard, which is obtained from the RankingScores object that is returned. |

Call Example

const timeDimension = 2;
const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
HMSGameService.loadCurrentPlayerRankingScore(
    rankingId,
    timeDimension
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadRankingMetadata(rankingId,isRealTime)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rankingId | string | ID of a leaderboard for which data is to be obtained. | | isRealTime | number |Indicates whether to obtain leaderboard data from Huawei game server. The options are as follows: true: Obtain data from Huawei game server. false: Obtain data from the local cache. |

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<RankingScore>> | Data of the current leaderboard. |

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const isRealTime = "true";
HMSGameService.loadRankingMetadata(
    rankingId,
    isRealTime
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadRankingsMetadata(isRealTime)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | isRealTime | number |Indicates whether to obtain leaderboard data from Huawei game server. The options are as follows: true: Obtain data from Huawei game server. false: Obtain data from the local cache. |

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<RankingScore>> | Data of the current leaderboard. |

Call Example

const isRealTime = "true";
HMSGameService.loadRankingsMetadata(isRealTime)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadMoreScores(rankingId,offsetPlayerRank,maxResults,pageDirection,timeDimension)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rankingId | string |ID of a leaderboard for which data is to be obtained. | | offsetPlayerRank | number |Rank specified by offsetPlayerRank. Then one page of scores before or after (specified by pageDirection) a rank will be loaded. | | maxResults | number |Maximum number of records on each page. The value is an number ranging from 1 to 21.| | pageDirection | number |Data obtaining direction. The options are as follows: 0: next page 1: previous page | | timeDimension | number | Time frame in which a leaderboard is to be obtained. The options are as follows: 0: The daily leaderboard is obtained. 1: The weekly leaderboard is obtained. 2: The all-time leaderboard is obtained. |

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<RankingScore>> | Data of the current leaderboard. |

Call Example

const offsetPlayerRank = 5;
const maxResults = 15;
const pageDirection = 0;
const timeDimension = 2;
const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
HMSGameService.loadMoreScores(
  rankingId,
  offsetPlayerRank,
  maxResults,
  pageDirection,
  timeDimension
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadPlayerCenteredPageScores(rankingId,timeDimension,maxResults,offsetPlayerRank,pageDirection)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rankingId | string |ID of a leaderboard for which data is to be obtained. | | offsetPlayerRank | number |Rank specified by offsetPlayerRank. Then one page of scores before or after (specified by pageDirection) a rank will be loaded. | | maxResults | number |Maximum number of records on each page. The value is an number ranging from 1 to 21.| | pageDirection | number |Data obtaining direction. The options are as follows: 0: next page 1: previous page | | timeDimension | number | Time frame in which a leaderboard is to be obtained. The options are as follows: 0: The daily leaderboard is obtained. 1: The weekly leaderboard is obtained. 2: The all-time leaderboard is obtained. |

| Return Type | Description | | ------------------------------------------------- | -------------------------------- | | Promise<Result<RankingScores>> | Data of the current leaderboard. |

Call Example

const timeDimension = 2;
const maxResults = 15;
const offsetPlayerRank = 0;
const pageDirection = 1;
const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
HMSGameService.loadPlayerCenteredPageScores(
    rankingId,
    timeDimension,
    maxResults,
    offsetPlayerRank,
    pageDirection
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadPlayerCenteredScores(rankingId,timeDimension,maxResults,isRealTime)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rankingId | string |ID of a leaderboard for which data is to be obtained. | | timeDimension | number | Time frame in which a leaderboard is to be obtained. The options are as follows: 0: The daily leaderboard is obtained.1: The weekly leaderboard is obtained.2: The all-time leaderboard is obtained. | | maxResults | number |Maximum number of records on each page. The value is an number ranging from 1 to 21.| | isRealTime | number | Indicates whether to obtain leaderboard data from Huawei game server. The options are as follows:true: Obtain data from Huawei game server.false: Obtain data from the local cache.|

| Return Type | Description | | ------------------------------------------------- | -------------------------------- | | Promise<Result<RankingScores>> | Data of the current leaderboard. |

Call Example

const timeDimension = 2;
const maxResults = 15;
const isRealTime = true;
const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
HMSGameService.loadPlayerCenteredScores(
  rankingId,
  timeDimension,
  maxResults,
  isRealTime
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

getPlayerExtraInfo(transactionId)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | transactionId | string | Transaction ID returned by Huawei game server after an app calls the submitPlayerEvent method to report a player event of entering a game. If a transaction ID exists, the ID is passed. If a transaction ID does not exist, null is passed. |

| Return Type | Description | | ----------------------------------------------------- | -------------------------------- | | Promise<Result<PlayerExtraInfo>> | Return a PlayerExtraInfo object. |

Call Example

const transactionId = "A1:736563***************"
HMSGameService.getPlayerExtraInfo(transactionId)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

submitPlayerEvent(playerId,eventId,eventType)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | playerId | string | ID of the current player. | | eventId | string | Player event ID. | | eventType | string | Event type. The options are as follows:GAMEBEGIN: A player enters your game. GAMEEND: A player exits your game. |

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<string>> | Transaction ID allocated by Huawei game server to a player in the scenario where eventType is set to GAMEBEGIN. In other scenarios, null is returned |

Call Example

const playerId = "718*******"
const eventType = "GAMEBEGIN"
const eventId = "F3845094040940********"
HMSGameService.submitPlayerEvent(playerId, eventId, eventType)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

savePlayerInfo(rank,role,area,sociaty,playerId,openId)

| Parameter | Type | Description | | ------------- | ------ | ------------------------------------- | | rank | string | Obtains the level of a player in a game. | | role | string | Obtains the role of a player in a game. | | area | string | Obtains the server region of a player in a game. | | sociaty | string | Obtains the guild information of a player in a game. | | playerId | string | Obtains the ID of a player in a game. | | openId | string | Obtains the OpenId of a player in a game. The OpenId uniquely identifies a HUAWEI ID in an app. |

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<void>> | Return a Result object. |

Call Example

const rank = 1
const role = 0
const area = 1
const sociaty = 1
const playerId = "718*******"
const openId = "718*******"
HMSGameService.savePlayerInfo(rank, role, area, sociaty, playerId, openId)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

checkGameServiceLite()

| Return Type | Description | | ---------------------- | ---------------------------------------------------------- | | Promise<Result<void>> | Return a Result object. |

Call Example

HMSGameService.checkGameServiceLite()
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

checkMobile(checkWithOpenId, m