@dsh0416/steamworks.js 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Gabriel Francisco Dos Santos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ [![Build Status](https://github.com/ceifa/steamworks.js/actions/workflows/publish.yml/badge.svg)](https://github.com/ceifa/steamworks.js/actions/workflows/publish.yml)
2
+ [![npm](https://img.shields.io/npm/v/steamworks.js.svg)](https://npmjs.com/package/steamworks.js)
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![Chat](https://img.shields.io/discord/663831597690257431?label=chat&logo=discord)](https://discord.gg/H6B7UE7fMY)
5
+
6
+ # Steamworks.js
7
+
8
+ A modern implementation of the Steamworks SDK for HTML/JS and NodeJS based applications.
9
+
10
+ ## Why
11
+
12
+ I used [greenworks](https://github.com/greenheartgames/greenworks) for a long time and it's great, but I gave up for the following reasons.
13
+
14
+ * It's not being maintained anymore.
15
+ * It's not up to date.
16
+ * It's not context-aware.
17
+ * You have to build the binaries by yourself.
18
+ * Don't have typescript definitions.
19
+ * The API it's not trustful.
20
+ * The API implement callbacks instead of return flags or promises.
21
+ * I hate C++.
22
+
23
+ ## API
24
+
25
+ ```js
26
+ const steamworks = require('steamworks.js')
27
+
28
+ // You can pass an appId, or don't pass anything and use a steam_appid.txt file
29
+ const client = steamworks.init(480)
30
+
31
+ // Print Steam username
32
+ console.log(client.localplayer.getName())
33
+
34
+ // Tries to activate an achievement
35
+ if (client.achievement.activate('ACHIEVEMENT')) {
36
+ // ...
37
+ }
38
+ ```
39
+
40
+ You can refer to the [declarations file](https://github.com/ceifa/steamworks.js/blob/main/client.d.ts) to check the API support and get more detailed documentation of each function.
41
+
42
+ ## Installation
43
+
44
+ To use steamworks.js you don't have to build anything, just install it from npm:
45
+
46
+ ```sh
47
+ $: npm i steamworks.js
48
+ ```
49
+
50
+ ### Electron
51
+
52
+ Steamworks.js is a native module and cannot be used by default in the renderer process. To enable the usage of native modules on the renderer process, the following configurations should be made on `main.js`:
53
+
54
+ ```js
55
+ const mainWindow = new BrowserWindow({
56
+ // ...
57
+ webPreferences: {
58
+ // ...
59
+ contextIsolation: false,
60
+ nodeIntegration: true
61
+ }
62
+ })
63
+ ```
64
+
65
+ To make the steam overlay working, call the `electronEnableSteamOverlay` on the end of your `main.js` file:
66
+
67
+ ```js
68
+ require('steamworks.js').electronEnableSteamOverlay()
69
+ ```
70
+
71
+ For the production build, copy the relevant distro files from `sdk/redistributable_bin/{YOUR_DISTRO}` into the root of your build. If you are using electron-forge, look for [#75](https://github.com/ceifa/steamworks.js/issues/75).
72
+
73
+
74
+ ## How to build
75
+
76
+ > You **only** need to build if you are going to change something on steamworks.js code, if you are looking to just consume the library or use it in your game, refer to the [installation section](#installation).
77
+
78
+ Make sure you have the latest [node.js](https://nodejs.org/en/), [Rust](https://www.rust-lang.org/tools/install) and [Clang](https://rust-lang.github.io/rust-bindgen/requirements.html). We also need [Steam](https://store.steampowered.com/about/) installed and running.
79
+
80
+ Install dependencies with `npm install` and then run `npm run build:debug` to build the library.
81
+
82
+ There is no way to build for all targets easily. The good news is that you don't need to. You can develop and test on your current target, and open a PR. When the code is merged to main, a github action will build for all targets and publish a new version.
83
+
84
+ ### Testing Electron
85
+
86
+ Go to the [test/electron](./test/electron) directory. There, you can run `npm install` and then `npm start` to run the Electron app.
87
+
88
+ Click "activate overlay" to test the overlay.
package/callbacks.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ import client = require('./client')
2
+
3
+ export const enum ChatMemberStateChange {
4
+ /** This user has joined or is joining the lobby. */
5
+ Entered,
6
+ /** This user has left or is leaving the lobby. */
7
+ Left,
8
+ /** User disconnected without leaving the lobby first. */
9
+ Disconnected,
10
+ /** The user has been kicked. */
11
+ Kicked,
12
+ /** The user has been kicked and banned. */
13
+ Banned,
14
+ }
15
+
16
+ export interface CallbackReturns {
17
+ [client.callback.SteamCallback.PersonaStateChange]: {
18
+ steam_id: bigint
19
+ flags: { bits: number }
20
+ }
21
+ [client.callback.SteamCallback.SteamServersConnected]: {}
22
+ [client.callback.SteamCallback.SteamServersDisconnected]: {
23
+ reason: number
24
+ }
25
+ [client.callback.SteamCallback.SteamServerConnectFailure]: {
26
+ reason: number
27
+ still_retrying: boolean
28
+ }
29
+ [client.callback.SteamCallback.LobbyDataUpdate]: {
30
+ lobby: bigint
31
+ member: bigint
32
+ success: boolean
33
+ }
34
+ [client.callback.SteamCallback.LobbyChatUpdate]: {
35
+ lobby: bigint
36
+ user_changed: bigint
37
+ making_change: bigint
38
+ member_state_change: ChatMemberStateChange
39
+ }
40
+ [client.callback.SteamCallback.P2PSessionRequest]: {
41
+ remote: bigint
42
+ }
43
+ [client.callback.SteamCallback.P2PSessionConnectFail]: {
44
+ remote: bigint
45
+ error: number
46
+ }
47
+ [client.callback.SteamCallback.GameLobbyJoinRequested]: {
48
+ lobby_steam_id: bigint
49
+ friend_steam_id: bigint
50
+ }
51
+ [client.callback.SteamCallback.MicroTxnAuthorizationResponse]: {
52
+ app_id: number
53
+ order_id: number | bigint
54
+ authorized: boolean
55
+ }
56
+ }
package/client.d.ts ADDED
@@ -0,0 +1,486 @@
1
+ /// <reference types="node" />
2
+ export declare function init(appId?: number | undefined | null): void
3
+
4
+ export interface PlayerSteamId {
5
+ steamId64: bigint
6
+ steamId32: string
7
+ accountId: number
8
+ }
9
+
10
+ export declare function restartAppIfNecessary(appId: number): boolean
11
+
12
+ export declare function runCallbacks(): void
13
+
14
+ export declare namespace achievement {
15
+ export function activate(achievement: string): boolean
16
+ export function clear(achievement: string): boolean
17
+ export function isActivated(achievement: string): boolean
18
+ export function names(): Array<string>
19
+ }
20
+
21
+ export declare namespace apps {
22
+ export function appBuildId(): number
23
+ export function appInstallDir(appId: number): string
24
+ export function appOwner(): PlayerSteamId
25
+ export function availableGameLanguages(): Array<string>
26
+ export function currentBetaName(): string | null
27
+ export function currentGameLanguage(): string
28
+ export function isAppInstalled(appId: number): boolean
29
+ export function isCybercafe(): boolean
30
+ export function isDlcInstalled(appId: number): boolean
31
+ export function isLowViolence(): boolean
32
+ export function isSubscribed(): boolean
33
+ export function isSubscribedApp(appId: number): boolean
34
+ export function isSubscribedFromFreeWeekend(): boolean
35
+ export function isVacBanned(): boolean
36
+ }
37
+
38
+ export declare namespace auth {
39
+ export class Ticket {
40
+ cancel(): void
41
+ getBytes(): Buffer
42
+ }
43
+ export function getAuthTicketForWebApi(identity: string, timeoutSeconds?: number | undefined | null): Promise<Ticket>
44
+ /**
45
+ * @param ip - The string of IPv4 or IPv6 address. Use as NetworkIdentity of the remote system that will authenticate the ticket.
46
+ * @param timeoutSeconds - The number of seconds to wait for the ticket to be validated. Default value is 10 seconds.
47
+ */
48
+ export function getSessionTicketWithIp(ip: string, timeoutSeconds?: number | undefined | null): Promise<Ticket>
49
+ /**
50
+ * @param steamId64 - The user steam id or game server steam id. Use as NetworkIdentity of the remote system that will authenticate the ticket. If it is peer-to-peer then the user steam ID. If it is a game server, then the game server steam ID may be used if it was obtained from a trusted 3rd party
51
+ * @param timeoutSeconds - The number of seconds to wait for the ticket to be validated. Default value is 10 seconds.
52
+ */
53
+ export function getSessionTicketWithSteamId(steamId64: bigint, timeoutSeconds?: number | undefined | null): Promise<Ticket>
54
+ }
55
+
56
+ export declare namespace callback {
57
+ export class Handle {
58
+ disconnect(): void
59
+ }
60
+ export function register<C extends keyof import('./callbacks').CallbackReturns>(steamCallback: C, handler: (value: import('./callbacks').CallbackReturns[C]) => void): Handle
61
+ export const enum SteamCallback {
62
+ PersonaStateChange = 0,
63
+ SteamServersConnected = 1,
64
+ SteamServersDisconnected = 2,
65
+ SteamServerConnectFailure = 3,
66
+ LobbyDataUpdate = 4,
67
+ LobbyChatUpdate = 5,
68
+ P2PSessionRequest = 6,
69
+ P2PSessionConnectFail = 7,
70
+ GameLobbyJoinRequested = 8,
71
+ MicroTxnAuthorizationResponse = 9
72
+ }
73
+ }
74
+
75
+ export declare namespace cloud {
76
+ export function deleteFile(name: string): boolean
77
+ export function fileExists(name: string): boolean
78
+ export interface FileInfo {
79
+ name: string
80
+ size: bigint
81
+ }
82
+ export function isEnabledForAccount(): boolean
83
+ export function isEnabledForApp(): boolean
84
+ export function listFiles(): Array<FileInfo>
85
+ export function readFile(name: string): string
86
+ export function setEnabledForApp(enabled: boolean): void
87
+ export function writeFile(name: string, content: string): boolean
88
+ }
89
+
90
+ export declare namespace input {
91
+ export class Controller {
92
+ activateActionSet(actionSetHandle: bigint): void
93
+ isDigitalActionPressed(actionHandle: bigint): boolean
94
+ getAnalogActionVector(actionHandle: bigint): AnalogActionVector
95
+ getType(): InputType
96
+ getHandle(): bigint
97
+ }
98
+ export interface AnalogActionVector {
99
+ x: number
100
+ y: number
101
+ }
102
+ export function getActionSet(actionSetName: string): bigint
103
+ export function getAnalogAction(actionName: string): bigint
104
+ export function getControllers(): Array<Controller>
105
+ export function getDigitalAction(actionName: string): bigint
106
+ export function init(): void
107
+ export const enum InputType {
108
+ Unknown = 'Unknown',
109
+ SteamController = 'SteamController',
110
+ XBox360Controller = 'XBox360Controller',
111
+ XBoxOneController = 'XBoxOneController',
112
+ GenericGamepad = 'GenericGamepad',
113
+ PS4Controller = 'PS4Controller',
114
+ AppleMFiController = 'AppleMFiController',
115
+ AndroidController = 'AndroidController',
116
+ SwitchJoyConPair = 'SwitchJoyConPair',
117
+ SwitchJoyConSingle = 'SwitchJoyConSingle',
118
+ SwitchProController = 'SwitchProController',
119
+ MobileTouch = 'MobileTouch',
120
+ PS3Controller = 'PS3Controller',
121
+ PS5Controller = 'PS5Controller',
122
+ SteamDeckController = 'SteamDeckController'
123
+ }
124
+ export function shutdown(): void
125
+ }
126
+
127
+ export declare namespace localplayer {
128
+ /** @returns the 2 digit ISO 3166-1-alpha-2 format country code which client is running in, e.g. "US" or "UK". */
129
+ export function getIpCountry(): string
130
+ export function getLevel(): number
131
+ export function getName(): string
132
+ export function getSteamId(): PlayerSteamId
133
+ export function setRichPresence(key: string, value?: string | undefined | null): void
134
+ }
135
+
136
+ export declare namespace matchmaking {
137
+ export class Lobby {
138
+ get id(): bigint
139
+ join(): Promise<Lobby>
140
+ leave(): void
141
+ openInviteDialog(): void
142
+ getMemberCount(): bigint
143
+ getMemberLimit(): bigint | null
144
+ getMembers(): Array<PlayerSteamId>
145
+ getOwner(): PlayerSteamId
146
+ setJoinable(joinable: boolean): boolean
147
+ getData(key: string): string | null
148
+ setData(key: string, value: string): boolean
149
+ deleteData(key: string): boolean
150
+ /** Get an object containing all the lobby data */
151
+ getFullData(): Record<string, string>
152
+ /**
153
+ * Merge current lobby data with provided data in a single batch
154
+ * @returns true if all data was set successfully
155
+ */
156
+ mergeFullData(data: Record<string, string>): boolean
157
+ }
158
+ export function createLobby(lobbyType: LobbyType, maxMembers: number): Promise<Lobby>
159
+ export function getLobbies(): Promise<Array<Lobby>>
160
+ export function joinLobby(lobbyId: bigint): Promise<Lobby>
161
+ export const enum LobbyType {
162
+ Private = 0,
163
+ FriendsOnly = 1,
164
+ Public = 2,
165
+ Invisible = 3
166
+ }
167
+ }
168
+
169
+ export declare namespace networking {
170
+ export function acceptP2PSession(steamId64: bigint): void
171
+ export function isP2PPacketAvailable(): number
172
+ export interface P2PPacket {
173
+ data: Buffer
174
+ size: number
175
+ steamId: PlayerSteamId
176
+ }
177
+ export function readP2PPacket(size: number): P2PPacket
178
+ export function sendP2PPacket(steamId64: bigint, sendType: SendType, data: Buffer): boolean
179
+ /** The method used to send a packet */
180
+ export const enum SendType {
181
+ /**
182
+ * Send the packet directly over udp.
183
+ *
184
+ * Can't be larger than 1200 bytes
185
+ */
186
+ Unreliable = 0,
187
+ /**
188
+ * Like `Unreliable` but doesn't buffer packets
189
+ * sent before the connection has started.
190
+ */
191
+ UnreliableNoDelay = 1,
192
+ /**
193
+ * Reliable packet sending.
194
+ *
195
+ * Can't be larger than 1 megabyte.
196
+ */
197
+ Reliable = 2,
198
+ /**
199
+ * Like `Reliable` but applies the nagle
200
+ * algorithm to packets being sent
201
+ */
202
+ ReliableWithBuffering = 3
203
+ }
204
+ }
205
+
206
+ export declare namespace overlay {
207
+ export function activateDialog(dialog: Dialog): void
208
+ export function activateDialogToUser(dialog: Dialog, steamId64: bigint): void
209
+ export function activateInviteDialog(lobbyId: bigint): void
210
+ export function activateToStore(appId: number, flag: StoreFlag): void
211
+ export function activateToWebPage(url: string): void
212
+ export const enum Dialog {
213
+ Friends = 0,
214
+ Community = 1,
215
+ Players = 2,
216
+ Settings = 3,
217
+ OfficialGameGroup = 4,
218
+ Stats = 5,
219
+ Achievements = 6
220
+ }
221
+ export const enum StoreFlag {
222
+ None = 0,
223
+ AddToCart = 1,
224
+ AddToCartAndShow = 2
225
+ }
226
+ }
227
+
228
+ export declare namespace stats {
229
+ export function getInt(name: string): number | null
230
+ export function resetAll(achievementsToo: boolean): boolean
231
+ export function setInt(name: string, value: number): boolean
232
+ export function store(): boolean
233
+ }
234
+
235
+ export declare namespace utils {
236
+ export const enum FloatingGamepadTextInputMode {
237
+ SingleLine = 0,
238
+ MultipleLines = 1,
239
+ Email = 2,
240
+ Numeric = 3
241
+ }
242
+ export const enum GamepadTextInputLineMode {
243
+ SingleLine = 0,
244
+ MultipleLines = 1
245
+ }
246
+ export const enum GamepadTextInputMode {
247
+ Normal = 0,
248
+ Password = 1
249
+ }
250
+ export function getAppId(): number
251
+ export function getServerRealTime(): number
252
+ export function isSteamRunningOnSteamDeck(): boolean
253
+ /** @returns true if the floating keyboard was shown, otherwise, false */
254
+ export function showFloatingGamepadTextInput(keyboardMode: FloatingGamepadTextInputMode, x: number, y: number, width: number, height: number): Promise<boolean>
255
+ /** @returns the entered text, or null if cancelled or could not show the input */
256
+ export function showGamepadTextInput(inputMode: GamepadTextInputMode, inputLineMode: GamepadTextInputLineMode, description: string, maxCharacters: number, existingText?: string | undefined | null): Promise<string | null>
257
+ }
258
+
259
+ export declare namespace workshop {
260
+ export interface AppIDs {
261
+ creator?: number
262
+ consumer?: number
263
+ }
264
+ export function createItem(appId?: number | undefined | null): Promise<UgcResult>
265
+ export function deleteItem(itemId: bigint): Promise<void>
266
+ /**
267
+ * Download or update a workshop item.
268
+ *
269
+ * @param highPriority - If high priority is true, start the download in high priority mode, pausing any existing in-progress Steam downloads and immediately begin downloading this workshop item.
270
+ * @returns true or false
271
+ *
272
+ * {@link https://partner.steamgames.com/doc/api/ISteamUGC#DownloadItem}
273
+ */
274
+ export function download(itemId: bigint, highPriority: boolean): boolean
275
+ /**
276
+ * Get info about a pending download of a workshop item.
277
+ *
278
+ * @returns an object with the properties {current, total}
279
+ *
280
+ * {@link https://partner.steamgames.com/doc/api/ISteamUGC#GetItemDownloadInfo}
281
+ */
282
+ export function downloadInfo(itemId: bigint): DownloadInfo | null
283
+ export interface DownloadInfo {
284
+ current: bigint
285
+ total: bigint
286
+ }
287
+ export function getAllItems(page: number, queryType: UGCQueryType, itemType: UGCType, creatorAppId: number, consumerAppId: number, queryConfig?: WorkshopItemQueryConfig | undefined | null): Promise<WorkshopPaginatedResult>
288
+ export function getItem(item: bigint, queryConfig?: WorkshopItemQueryConfig | undefined | null): Promise<WorkshopItem | null>
289
+ export function getItems(items: Array<bigint>, queryConfig?: WorkshopItemQueryConfig | undefined | null): Promise<WorkshopItemsResult>
290
+ /**
291
+ * Get all subscribed workshop items.
292
+ * @returns an array of subscribed workshop item ids
293
+ */
294
+ export function getSubscribedItems(includeLocallyDisabled: boolean): Array<bigint>
295
+ export function getUserItems(page: number, accountId: number, listType: UserListType, itemType: UGCType, sortOrder: UserListOrder, appIds: AppIDs, queryConfig?: WorkshopItemQueryConfig | undefined | null): Promise<WorkshopPaginatedResult>
296
+ /**
297
+ * Gets info about currently installed content on the disc for workshop item.
298
+ *
299
+ * @returns an object with the the properties {folder, size_on_disk, timestamp}
300
+ *
301
+ * {@link https://partner.steamgames.com/doc/api/ISteamUGC#GetItemInstallInfo}
302
+ */
303
+ export function installInfo(itemId: bigint): InstallInfo | null
304
+ export interface InstallInfo {
305
+ folder: string
306
+ sizeOnDisk: bigint
307
+ timestamp: number
308
+ }
309
+ /**
310
+ * Gets the current state of a workshop item on this client. States can be combined.
311
+ *
312
+ * @returns a number with the current item state, e.g. 9
313
+ * 9 = 1 (The current user is subscribed to this item) + 8 (The item needs an update)
314
+ *
315
+ * {@link https://partner.steamgames.com/doc/api/ISteamUGC#GetItemState}
316
+ * {@link https://partner.steamgames.com/doc/api/ISteamUGC#EItemState}
317
+ */
318
+ export function state(itemId: bigint): number
319
+ /**
320
+ * Subscribe to a workshop item. It will be downloaded and installed as soon as possible.
321
+ *
322
+ * {@link https://partner.steamgames.com/doc/api/ISteamUGC#SubscribeItem}
323
+ */
324
+ export function subscribe(itemId: bigint): Promise<void>
325
+ export const enum UgcItemVisibility {
326
+ Public = 0,
327
+ FriendsOnly = 1,
328
+ Private = 2,
329
+ Unlisted = 3
330
+ }
331
+ export const enum UGCQueryType {
332
+ RankedByVote = 0,
333
+ RankedByPublicationDate = 1,
334
+ AcceptedForGameRankedByAcceptanceDate = 2,
335
+ RankedByTrend = 3,
336
+ FavoritedByFriendsRankedByPublicationDate = 4,
337
+ CreatedByFriendsRankedByPublicationDate = 5,
338
+ RankedByNumTimesReported = 6,
339
+ CreatedByFollowedUsersRankedByPublicationDate = 7,
340
+ NotYetRated = 8,
341
+ RankedByTotalVotesAsc = 9,
342
+ RankedByVotesUp = 10,
343
+ RankedByTextSearch = 11,
344
+ RankedByTotalUniqueSubscriptions = 12,
345
+ RankedByPlaytimeTrend = 13,
346
+ RankedByTotalPlaytime = 14,
347
+ RankedByAveragePlaytimeTrend = 15,
348
+ RankedByLifetimeAveragePlaytime = 16,
349
+ RankedByPlaytimeSessionsTrend = 17,
350
+ RankedByLifetimePlaytimeSessions = 18,
351
+ RankedByLastUpdatedDate = 19
352
+ }
353
+ export interface UgcResult {
354
+ itemId: bigint
355
+ needsToAcceptAgreement: boolean
356
+ }
357
+ export const enum UGCType {
358
+ Items = 0,
359
+ ItemsMtx = 1,
360
+ ItemsReadyToUse = 2,
361
+ Collections = 3,
362
+ Artwork = 4,
363
+ Videos = 5,
364
+ Screenshots = 6,
365
+ AllGuides = 7,
366
+ WebGuides = 8,
367
+ IntegratedGuides = 9,
368
+ UsableInGame = 10,
369
+ ControllerBindings = 11,
370
+ GameManagedItems = 12,
371
+ All = 13
372
+ }
373
+ export interface UgcUpdate {
374
+ title?: string
375
+ description?: string
376
+ changeNote?: string
377
+ previewPath?: string
378
+ contentPath?: string
379
+ tags?: Array<string>
380
+ visibility?: UgcItemVisibility
381
+ }
382
+ /**
383
+ * Unsubscribe from a workshop item. This will result in the item being removed after the game quits.
384
+ *
385
+ * {@link https://partner.steamgames.com/doc/api/ISteamUGC#UnsubscribeItem}
386
+ */
387
+ export function unsubscribe(itemId: bigint): Promise<void>
388
+ export function updateItem(itemId: bigint, updateDetails: UgcUpdate, appId?: number | undefined | null): Promise<UgcResult>
389
+ export function updateItemWithCallback(itemId: bigint, updateDetails: UgcUpdate, appId: number | undefined | null, successCallback: (data: UgcResult) => void, errorCallback: (err: any) => void, progressCallback?: (data: UpdateProgress) => void, progressCallbackIntervalMs?: number | undefined | null): void
390
+ export interface UpdateProgress {
391
+ status: UpdateStatus
392
+ progress: bigint
393
+ total: bigint
394
+ }
395
+ export const enum UpdateStatus {
396
+ Invalid = 0,
397
+ PreparingConfig = 1,
398
+ PreparingContent = 2,
399
+ UploadingContent = 3,
400
+ UploadingPreviewFile = 4,
401
+ CommittingChanges = 5
402
+ }
403
+ export const enum UserListOrder {
404
+ CreationOrderAsc = 0,
405
+ CreationOrderDesc = 1,
406
+ TitleAsc = 2,
407
+ LastUpdatedDesc = 3,
408
+ SubscriptionDateDesc = 4,
409
+ VoteScoreDesc = 5,
410
+ ForModeration = 6
411
+ }
412
+ export const enum UserListType {
413
+ Published = 0,
414
+ VotedOn = 1,
415
+ VotedUp = 2,
416
+ VotedDown = 3,
417
+ Favorited = 4,
418
+ Subscribed = 5,
419
+ UsedOrPlayed = 6,
420
+ Followed = 7
421
+ }
422
+ export interface WorkshopItem {
423
+ publishedFileId: bigint
424
+ creatorAppId?: number
425
+ consumerAppId?: number
426
+ title: string
427
+ description: string
428
+ owner: PlayerSteamId
429
+ /** Time created in unix epoch seconds format */
430
+ timeCreated: number
431
+ /** Time updated in unix epoch seconds format */
432
+ timeUpdated: number
433
+ /** Time when the user added the published item to their list (not always applicable), provided in Unix epoch format (time since Jan 1st, 1970). */
434
+ timeAddedToUserList: number
435
+ visibility: UgcItemVisibility
436
+ banned: boolean
437
+ acceptedForUse: boolean
438
+ tags: Array<string>
439
+ tagsTruncated: boolean
440
+ url: string
441
+ numUpvotes: number
442
+ numDownvotes: number
443
+ numChildren: number
444
+ previewUrl?: string
445
+ statistics: WorkshopItemStatistic
446
+ }
447
+ export interface WorkshopItemQueryConfig {
448
+ cachedResponseMaxAge?: number
449
+ includeMetadata?: boolean
450
+ includeLongDescription?: boolean
451
+ includeAdditionalPreviews?: boolean
452
+ onlyIds?: boolean
453
+ onlyTotal?: boolean
454
+ language?: string
455
+ matchAnyTag?: boolean
456
+ requiredTags?: Array<string>
457
+ excludedTags?: Array<string>
458
+ searchText?: string
459
+ rankedByTrendDays?: number
460
+ }
461
+ export interface WorkshopItemsResult {
462
+ items: Array<WorkshopItem | undefined | null>
463
+ wasCached: boolean
464
+ }
465
+ export interface WorkshopItemStatistic {
466
+ numSubscriptions?: bigint
467
+ numFavorites?: bigint
468
+ numFollowers?: bigint
469
+ numUniqueSubscriptions?: bigint
470
+ numUniqueFavorites?: bigint
471
+ numUniqueFollowers?: bigint
472
+ numUniqueWebsiteViews?: bigint
473
+ reportScore?: bigint
474
+ numSecondsPlayed?: bigint
475
+ numPlaytimeSessions?: bigint
476
+ numComments?: bigint
477
+ numSecondsPlayedDuringTimePeriod?: bigint
478
+ numPlaytimeSessionsDuringTimePeriod?: bigint
479
+ }
480
+ export interface WorkshopPaginatedResult {
481
+ items: Array<WorkshopItem | undefined | null>
482
+ returnedResults: number
483
+ totalResults: number
484
+ wasCached: boolean
485
+ }
486
+ }
Binary file
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export function init(appId?: number): Omit<Client, "init" | "runCallbacks">;
2
+ export function restartAppIfNecessary(appId: number): boolean;
3
+ export function electronEnableSteamOverlay(disableEachFrameInvalidation?: boolean): void;
4
+ export type Client = typeof import("./client.d");
5
+ export const SteamCallback: typeof import("./client.d").callback.SteamCallback;
package/index.js ADDED
@@ -0,0 +1,77 @@
1
+ const { platform, arch } = process
2
+
3
+ /** @typedef {typeof import('./client.d')} Client */
4
+ /** @type {Client} */
5
+ let nativeBinding = undefined
6
+
7
+ if (platform === 'win32' && arch === 'x64') {
8
+ nativeBinding = require('./dist/win64/steamworksjs.win32-x64-msvc.node')
9
+ } else if (platform === 'linux' && arch === 'x64') {
10
+ nativeBinding = require('./dist/linux64/steamworksjs.linux-x64-gnu.node')
11
+ } else if (platform === 'darwin') {
12
+ if (arch === 'x64') {
13
+ nativeBinding = require('./dist/osx/steamworksjs.darwin-x64.node')
14
+ } else if (arch === 'arm64') {
15
+ nativeBinding = require('./dist/osx/steamworksjs.darwin-arm64.node')
16
+ }
17
+ } else {
18
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
19
+ }
20
+
21
+ let runCallbacksInterval = undefined
22
+
23
+ /**
24
+ * Initialize the steam client or throw an error if it fails
25
+ * @param {number} [appId] - App ID of the game to load, if undefined, will search for a steam_appid.txt file
26
+ * @returns {Omit<Client, 'init' | 'runCallbacks'>}
27
+ */
28
+ module.exports.init = (appId) => {
29
+ const { init: internalInit, runCallbacks, restartAppIfNecessary, ...api } = nativeBinding
30
+
31
+ internalInit(appId)
32
+
33
+ clearInterval(runCallbacksInterval)
34
+ runCallbacksInterval = setInterval(runCallbacks, 1000 / 30)
35
+
36
+ return api
37
+ }
38
+
39
+ /**
40
+ * @param {number} appId - App ID of the game to load
41
+ * {@link https://partner.steamgames.com/doc/api/steam_api#SteamAPI_RestartAppIfNecessary}
42
+ * @returns {boolean}
43
+ */
44
+ module.exports.restartAppIfNecessary = (appId) => nativeBinding.restartAppIfNecessary(appId);
45
+
46
+ /**
47
+ * Enable the steam overlay on electron
48
+ * @param {boolean} [disableEachFrameInvalidation] - Should attach a single pixel to be rendered each frame
49
+ */
50
+ module.exports.electronEnableSteamOverlay = (disableEachFrameInvalidation) => {
51
+ const electron = require('electron')
52
+ if (!electron) {
53
+ throw new Error('Electron module not found')
54
+ }
55
+
56
+ electron.app.commandLine.appendSwitch('in-process-gpu')
57
+ electron.app.commandLine.appendSwitch('disable-direct-composition')
58
+
59
+ if (!disableEachFrameInvalidation) {
60
+ /** @param {electron.BrowserWindow} browserWindow */
61
+ const attachFrameInvalidator = (browserWindow) => {
62
+ browserWindow.steamworksRepaintInterval = setInterval(() => {
63
+ if (browserWindow.isDestroyed()) {
64
+ clearInterval(browserWindow.steamworksRepaintInterval)
65
+ } else if (!browserWindow.webContents.isPainting()) {
66
+ browserWindow.webContents.invalidate()
67
+ }
68
+ }, 1000 / 60)
69
+ }
70
+
71
+ electron.BrowserWindow.getAllWindows().forEach(attachFrameInvalidator)
72
+ electron.app.on('browser-window-created', (_, bw) => attachFrameInvalidator(bw))
73
+ }
74
+ }
75
+
76
+ const SteamCallback = nativeBinding.callback.SteamCallback
77
+ module.exports.SteamCallback = SteamCallback
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@dsh0416/steamworks.js",
3
+ "version": "0.4.1",
4
+ "main": "index.js",
5
+ "types": "index.d.ts",
6
+ "napi": {
7
+ "binaryName": "steamworksjs",
8
+ "targets": [
9
+ "x86_64-pc-windows-msvc",
10
+ "x86_64-unknown-linux-gnu",
11
+ "x86_64-apple-darwin",
12
+ "aarch64-apple-darwin"
13
+ ]
14
+ },
15
+ "files": [
16
+ "dist/*",
17
+ "index.js",
18
+ "*.d.ts",
19
+ "README.md"
20
+ ],
21
+ "license": "MIT",
22
+ "devDependencies": {
23
+ "@napi-rs/cli": "^3.7.0",
24
+ "electron": "^42.3.3",
25
+ "rimraf": "^6.1.3",
26
+ "typescript": "^6.0.3"
27
+ },
28
+ "dependencies": {
29
+ "@types/node": "^25.9.1"
30
+ },
31
+ "engines": {
32
+ "node": ">= 14"
33
+ },
34
+ "scripts": {
35
+ "build": "npm run types && node build --release",
36
+ "build:debug": "node build",
37
+ "prune": "rimraf dist target client.d.ts",
38
+ "format": "cargo clippy --fix --allow-staged && cargo fmt",
39
+ "types": "tsc index.js --allowJs --declaration --emitDeclarationOnly"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/dsh0416/steamworks.js"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "registry": "https://registry.npmjs.org"
48
+ }
49
+ }