ez-steam-api

0.57.1 • Public • Published

ez-steam-api

This is a Node+JavaScript wrapper around the Steamworks SDK (based on Koffi), originally created for use in an Electron-based game on Steam.

Motivation

I opted to create my own wrapper instead of using Greenworks for a couple of reasons:

  • Greenworks is no longer maintained
  • Greenworks doesn't expose "friend leaderboard" functionality
  • I wanted a wrapper that could be reused easily from any language (with a foreign function interface-friendly, synchronous C API)

Usage

Currently, this library only exposes the functionality I needed for my game. Example code:

const { Steam } = require("ez-steam-api");

const appId = 12345; // Replace with your app id

(async () => {
    const shouldExit = Steam.start(appId);
    if (!shouldExit) {
        try {
            // Log the user's "persona" (display) name
            console.log(`Name: ${Steam.getUserName()}`);

            // Log the chosen language for the current app/game
            console.log(`Name: ${Steam.getAppLanguage()}`);

            // Set an achievement (this assumes an achievement named "FOOBAR" exists for the app)
            const newlyAchieved = Steam.setAchievement("FOOBAR");
            if (newlyAchieved) {
                await Steam.storeAchievementsAsync();
            }
    
            // Get a friend leaderboard (this assumes a leaderboard named "Score" exists for the app)
            const leaderboard = await Steam.getLeaderboardAsync("Score");
            const rows = await leaderboard.getFriendScoresAsync();
    
            console.log("Leaderboard:");
            for (const { name, score } of rows) {
                console.log(`${name}: ${score}`);
            }
        } finally {
            Steam.stop();
        }
    }
})();

Versioning and compatibility

The second (minor) version number corresponds to the Steamworks SDK's second version component. For example, X.57.Y is major version X, targeting Steamworks SDK 1.57, with patch version Y.

Readme

Keywords

none

Package Sidebar

Install

npm i ez-steam-api

Weekly Downloads

0

Version

0.57.1

License

MIT-0

Unpacked Size

388 kB

Total Files

6

Last publish

Collaborators

  • jaredkrinke