steamworks-ffi-node 0.4.2 → 0.5.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.
Files changed (46) hide show
  1. package/README.md +59 -1
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +7 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/SteamAPICore.d.ts +23 -0
  7. package/dist/internal/SteamAPICore.d.ts.map +1 -1
  8. package/dist/internal/SteamAPICore.js +30 -0
  9. package/dist/internal/SteamAPICore.js.map +1 -1
  10. package/dist/internal/SteamFriendsManager.d.ts +365 -0
  11. package/dist/internal/SteamFriendsManager.d.ts.map +1 -0
  12. package/dist/internal/SteamFriendsManager.js +602 -0
  13. package/dist/internal/SteamFriendsManager.js.map +1 -0
  14. package/dist/internal/SteamLibraryLoader.d.ts +23 -0
  15. package/dist/internal/SteamLibraryLoader.d.ts.map +1 -1
  16. package/dist/internal/SteamLibraryLoader.js +32 -0
  17. package/dist/internal/SteamLibraryLoader.js.map +1 -1
  18. package/dist/internal/SteamOverlayManager.d.ts +407 -0
  19. package/dist/internal/SteamOverlayManager.d.ts.map +1 -0
  20. package/dist/internal/SteamOverlayManager.js +523 -0
  21. package/dist/internal/SteamOverlayManager.js.map +1 -0
  22. package/dist/internal/SteamRichPresenceManager.d.ts +265 -0
  23. package/dist/internal/SteamRichPresenceManager.d.ts.map +1 -0
  24. package/dist/internal/SteamRichPresenceManager.js +374 -0
  25. package/dist/internal/SteamRichPresenceManager.js.map +1 -0
  26. package/dist/steam.d.ts +98 -0
  27. package/dist/steam.d.ts.map +1 -1
  28. package/dist/steam.js +12 -0
  29. package/dist/steam.js.map +1 -1
  30. package/dist/types/friends.d.ts +68 -0
  31. package/dist/types/friends.d.ts.map +1 -0
  32. package/dist/types/friends.js +55 -0
  33. package/dist/types/friends.js.map +1 -0
  34. package/dist/types/index.d.ts +6 -0
  35. package/dist/types/index.d.ts.map +1 -1
  36. package/dist/types/index.js +9 -0
  37. package/dist/types/index.js.map +1 -1
  38. package/dist/types/overlay.d.ts +72 -0
  39. package/dist/types/overlay.d.ts.map +1 -0
  40. package/dist/types/overlay.js +79 -0
  41. package/dist/types/overlay.js.map +1 -0
  42. package/dist/types/richpresence.d.ts +43 -0
  43. package/dist/types/richpresence.d.ts.map +1 -0
  44. package/dist/types/richpresence.js +33 -0
  45. package/dist/types/richpresence.js.map +1 -0
  46. package/package.json +14 -6
@@ -0,0 +1,265 @@
1
+ import { SteamLibraryLoader } from './SteamLibraryLoader';
2
+ import { SteamAPICore } from './SteamAPICore';
3
+ /**
4
+ * Manager for Steam Rich Presence API operations
5
+ *
6
+ * The SteamRichPresenceManager allows games to set custom status information
7
+ * that appears in the Steam friends list and chat. This provides players with
8
+ * context about what their friends are doing in your game.
9
+ *
10
+ * Rich Presence is automatically shared between friends who are in the same game.
11
+ * Each user has a set of key/value pairs that can be queried by other players.
12
+ *
13
+ * @remarks
14
+ * Special keys recognized by Steam:
15
+ * - `status` - UTF-8 string shown in 'view game info' dialog
16
+ * - `connect` - Command-line for how friends can connect to your game
17
+ * - `steam_display` - Localization token for display in user's language
18
+ * - `steam_player_group` - Group identifier for organizing players
19
+ * - `steam_player_group_size` - Total number of players in the group
20
+ *
21
+ * Limits:
22
+ * - Maximum 30 keys per user
23
+ * - Keys: Max 64 characters
24
+ * - Values: Max 256 characters
25
+ *
26
+ * @example Set basic rich presence
27
+ * ```typescript
28
+ * const steam = SteamworksSDK.getInstance();
29
+ * steam.init({ appId: 480 });
30
+ *
31
+ * // Set status visible to friends
32
+ * steam.richPresence.setRichPresence('status', 'Playing Capture the Flag');
33
+ * steam.richPresence.setRichPresence('connect', '+connect 192.168.1.100:27015');
34
+ *
35
+ * // Clear all rich presence when leaving game
36
+ * steam.richPresence.clearRichPresence();
37
+ * ```
38
+ *
39
+ * @example Read friend's rich presence
40
+ * ```typescript
41
+ * const friends = steam.friends.getAllFriends();
42
+ *
43
+ * friends.forEach(friend => {
44
+ * // Request friend's rich presence data
45
+ * steam.richPresence.requestFriendRichPresence(friend.steamId);
46
+ *
47
+ * // After data arrives, read it
48
+ * const status = steam.richPresence.getFriendRichPresence(friend.steamId, 'status');
49
+ * if (status) {
50
+ * console.log(`${friend.personaName}: ${status}`);
51
+ * }
52
+ * });
53
+ * ```
54
+ *
55
+ * @example Player groups
56
+ * ```typescript
57
+ * // Show player is in a squad of 4
58
+ * steam.richPresence.setRichPresence('steam_player_group', 'squad_alpha');
59
+ * steam.richPresence.setRichPresence('steam_player_group_size', '4');
60
+ * steam.richPresence.setRichPresence('status', 'In Squad Alpha (4/4)');
61
+ * ```
62
+ *
63
+ * @see {@link https://partner.steamgames.com/doc/api/ISteamFriends#richpresencelocalization Rich Presence Localization}
64
+ * @see {@link https://partner.steamgames.com/doc/api/ISteamFriends ISteamFriends Documentation}
65
+ */
66
+ export declare class SteamRichPresenceManager {
67
+ /** Steam library loader for FFI function calls */
68
+ private libraryLoader;
69
+ /** Steam API core for initialization and callback management */
70
+ private apiCore;
71
+ /**
72
+ * Creates a new SteamRichPresenceManager instance
73
+ *
74
+ * @param libraryLoader - The Steam library loader for FFI calls
75
+ * @param apiCore - The Steam API core for lifecycle management
76
+ */
77
+ constructor(libraryLoader: SteamLibraryLoader, apiCore: SteamAPICore);
78
+ /**
79
+ * Sets a Rich Presence key/value pair for the current user
80
+ *
81
+ * @param key - The rich presence key (max 64 characters)
82
+ * @param value - The rich presence value (max 256 characters), or null/empty to delete the key
83
+ * @returns True if the key was set successfully, false otherwise
84
+ *
85
+ * @remarks
86
+ * - Setting a value to null or empty string deletes the key
87
+ * - Key/value pairs are automatically shared with friends in the same game
88
+ * - Steam has special handling for keys: 'status', 'connect', 'steam_display',
89
+ * 'steam_player_group', 'steam_player_group_size'
90
+ * - Changes take effect immediately for friends viewing your status
91
+ *
92
+ * @example Set game mode status
93
+ * ```typescript
94
+ * // Set status visible in friends list
95
+ * steam.richPresence.setRichPresence('status', 'Playing Capture the Flag');
96
+ *
97
+ * // Set connect string for join functionality
98
+ * steam.richPresence.setRichPresence('connect', '+connect 192.168.1.100:27015');
99
+ *
100
+ * // Use localization token
101
+ * steam.richPresence.setRichPresence('steam_display', '#Status_InGame');
102
+ *
103
+ * // Delete a key
104
+ * steam.richPresence.setRichPresence('connect', '');
105
+ * ```
106
+ *
107
+ * @example Player group/squad
108
+ * ```typescript
109
+ * // Indicate player is in a group
110
+ * steam.richPresence.setRichPresence('steam_player_group', 'lobby_12345');
111
+ * steam.richPresence.setRichPresence('steam_player_group_size', '8');
112
+ * ```
113
+ *
114
+ * @see {@link RichPresenceKeys} for standard key names
115
+ * @see {@link RichPresenceLimits} for length limits
116
+ */
117
+ setRichPresence(key: string, value: string | null): boolean;
118
+ /**
119
+ * Clears all Rich Presence data for the current user
120
+ *
121
+ * @remarks
122
+ * This removes all key/value pairs that were set via setRichPresence().
123
+ * Call this when the player leaves your game or exits a match to clear their status.
124
+ *
125
+ * @example Clear presence on match end
126
+ * ```typescript
127
+ * // During gameplay
128
+ * steam.richPresence.setRichPresence('status', 'Playing Deathmatch');
129
+ * steam.richPresence.setRichPresence('connect', '+connect server:27015');
130
+ *
131
+ * // When match ends
132
+ * steam.richPresence.clearRichPresence();
133
+ *
134
+ * // Or set to menu status
135
+ * steam.richPresence.setRichPresence('status', 'In Main Menu');
136
+ * ```
137
+ */
138
+ clearRichPresence(): void;
139
+ /**
140
+ * Gets a Rich Presence value for a specific friend
141
+ *
142
+ * @param steamId - The friend's Steam ID
143
+ * @param key - The rich presence key to retrieve
144
+ * @returns The rich presence value, or empty string if not set or unavailable
145
+ *
146
+ * @remarks
147
+ * - Data may not be immediately available for friends you haven't interacted with recently
148
+ * - Call requestFriendRichPresence() first to ensure data is downloaded
149
+ * - Only works for friends who are playing the same game
150
+ * - Returns empty string if friend has no value for that key
151
+ *
152
+ * @example Read friend status
153
+ * ```typescript
154
+ * const friends = steam.friends.getAllFriends();
155
+ *
156
+ * friends.forEach(friend => {
157
+ * // Request data first
158
+ * steam.richPresence.requestFriendRichPresence(friend.steamId);
159
+ *
160
+ * // Read status
161
+ * const status = steam.richPresence.getFriendRichPresence(friend.steamId, 'status');
162
+ * const connect = steam.richPresence.getFriendRichPresence(friend.steamId, 'connect');
163
+ *
164
+ * if (status) {
165
+ * console.log(`${friend.personaName}: ${status}`);
166
+ * if (connect) {
167
+ * console.log(` Join with: ${connect}`);
168
+ * }
169
+ * }
170
+ * });
171
+ * ```
172
+ */
173
+ getFriendRichPresence(steamId: string, key: string): string;
174
+ /**
175
+ * Gets the number of Rich Presence keys set for a specific friend
176
+ *
177
+ * @param steamId - The friend's Steam ID
178
+ * @returns Number of rich presence keys, or 0 if none set or unavailable
179
+ *
180
+ * @remarks
181
+ * Use this with getFriendRichPresenceKeyByIndex() to iterate through
182
+ * all rich presence data for a friend.
183
+ *
184
+ * @example List all rich presence data
185
+ * ```typescript
186
+ * const friends = steam.friends.getAllFriends();
187
+ *
188
+ * friends.forEach(friend => {
189
+ * steam.richPresence.requestFriendRichPresence(friend.steamId);
190
+ *
191
+ * const keyCount = steam.richPresence.getFriendRichPresenceKeyCount(friend.steamId);
192
+ * console.log(`${friend.personaName} has ${keyCount} rich presence keys:`);
193
+ *
194
+ * for (let i = 0; i < keyCount; i++) {
195
+ * const key = steam.richPresence.getFriendRichPresenceKeyByIndex(friend.steamId, i);
196
+ * const value = steam.richPresence.getFriendRichPresence(friend.steamId, key);
197
+ * console.log(` ${key}: ${value}`);
198
+ * }
199
+ * });
200
+ * ```
201
+ */
202
+ getFriendRichPresenceKeyCount(steamId: string): number;
203
+ /**
204
+ * Gets a Rich Presence key name by index for a specific friend
205
+ *
206
+ * @param steamId - The friend's Steam ID
207
+ * @param index - Index of the key (0 to getFriendRichPresenceKeyCount() - 1)
208
+ * @returns The key name, or empty string if invalid index
209
+ *
210
+ * @remarks
211
+ * Use this with getFriendRichPresenceKeyCount() to iterate through all keys.
212
+ * Then use getFriendRichPresence() to get the value for each key.
213
+ *
214
+ * @example Iterate all rich presence data
215
+ * ```typescript
216
+ * const steamId = '76561198012345678';
217
+ *
218
+ * steam.richPresence.requestFriendRichPresence(steamId);
219
+ *
220
+ * const keyCount = steam.richPresence.getFriendRichPresenceKeyCount(steamId);
221
+ * console.log(`Friend has ${keyCount} rich presence keys:`);
222
+ *
223
+ * for (let i = 0; i < keyCount; i++) {
224
+ * const key = steam.richPresence.getFriendRichPresenceKeyByIndex(steamId, i);
225
+ * const value = steam.richPresence.getFriendRichPresence(steamId, key);
226
+ * console.log(` ${key} = ${value}`);
227
+ * }
228
+ * ```
229
+ */
230
+ getFriendRichPresenceKeyByIndex(steamId: string, index: number): string;
231
+ /**
232
+ * Requests Rich Presence data for a specific friend
233
+ *
234
+ * @param steamId - The friend's Steam ID
235
+ *
236
+ * @remarks
237
+ * This asynchronously downloads rich presence data for the specified friend.
238
+ * Call this before attempting to read a friend's rich presence values.
239
+ *
240
+ * Data arrival is not immediate - allow a short delay before calling
241
+ * getFriendRichPresence() after requesting.
242
+ *
243
+ * @example Request and read rich presence
244
+ * ```typescript
245
+ * const friends = steam.friends.getAllFriends();
246
+ *
247
+ * // Request all friends' rich presence
248
+ * friends.forEach(friend => {
249
+ * steam.richPresence.requestFriendRichPresence(friend.steamId);
250
+ * });
251
+ *
252
+ * // Wait a moment for data to arrive
253
+ * setTimeout(() => {
254
+ * friends.forEach(friend => {
255
+ * const status = steam.richPresence.getFriendRichPresence(friend.steamId, 'status');
256
+ * if (status) {
257
+ * console.log(`${friend.personaName}: ${status}`);
258
+ * }
259
+ * });
260
+ * }, 1000);
261
+ * ```
262
+ */
263
+ requestFriendRichPresence(steamId: string): void;
264
+ }
265
+ //# sourceMappingURL=SteamRichPresenceManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SteamRichPresenceManager.d.ts","sourceRoot":"","sources":["../../src/internal/SteamRichPresenceManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,qBAAa,wBAAwB;IACnC,kDAAkD;IAClD,OAAO,CAAC,aAAa,CAAqB;IAE1C,gEAAgE;IAChE,OAAO,CAAC,OAAO,CAAe;IAE9B;;;;;OAKG;gBACS,aAAa,EAAE,kBAAkB,EAAE,OAAO,EAAE,YAAY;IAKpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACH,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAyB3D;;;;;;;;;;;;;;;;;;;OAmBG;IACH,iBAAiB,IAAI,IAAI;IAmBzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IA0B3D;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAyBtD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,+BAA+B,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IA0BvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAsBjD"}
@@ -0,0 +1,374 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SteamRichPresenceManager = void 0;
4
+ /**
5
+ * Manager for Steam Rich Presence API operations
6
+ *
7
+ * The SteamRichPresenceManager allows games to set custom status information
8
+ * that appears in the Steam friends list and chat. This provides players with
9
+ * context about what their friends are doing in your game.
10
+ *
11
+ * Rich Presence is automatically shared between friends who are in the same game.
12
+ * Each user has a set of key/value pairs that can be queried by other players.
13
+ *
14
+ * @remarks
15
+ * Special keys recognized by Steam:
16
+ * - `status` - UTF-8 string shown in 'view game info' dialog
17
+ * - `connect` - Command-line for how friends can connect to your game
18
+ * - `steam_display` - Localization token for display in user's language
19
+ * - `steam_player_group` - Group identifier for organizing players
20
+ * - `steam_player_group_size` - Total number of players in the group
21
+ *
22
+ * Limits:
23
+ * - Maximum 30 keys per user
24
+ * - Keys: Max 64 characters
25
+ * - Values: Max 256 characters
26
+ *
27
+ * @example Set basic rich presence
28
+ * ```typescript
29
+ * const steam = SteamworksSDK.getInstance();
30
+ * steam.init({ appId: 480 });
31
+ *
32
+ * // Set status visible to friends
33
+ * steam.richPresence.setRichPresence('status', 'Playing Capture the Flag');
34
+ * steam.richPresence.setRichPresence('connect', '+connect 192.168.1.100:27015');
35
+ *
36
+ * // Clear all rich presence when leaving game
37
+ * steam.richPresence.clearRichPresence();
38
+ * ```
39
+ *
40
+ * @example Read friend's rich presence
41
+ * ```typescript
42
+ * const friends = steam.friends.getAllFriends();
43
+ *
44
+ * friends.forEach(friend => {
45
+ * // Request friend's rich presence data
46
+ * steam.richPresence.requestFriendRichPresence(friend.steamId);
47
+ *
48
+ * // After data arrives, read it
49
+ * const status = steam.richPresence.getFriendRichPresence(friend.steamId, 'status');
50
+ * if (status) {
51
+ * console.log(`${friend.personaName}: ${status}`);
52
+ * }
53
+ * });
54
+ * ```
55
+ *
56
+ * @example Player groups
57
+ * ```typescript
58
+ * // Show player is in a squad of 4
59
+ * steam.richPresence.setRichPresence('steam_player_group', 'squad_alpha');
60
+ * steam.richPresence.setRichPresence('steam_player_group_size', '4');
61
+ * steam.richPresence.setRichPresence('status', 'In Squad Alpha (4/4)');
62
+ * ```
63
+ *
64
+ * @see {@link https://partner.steamgames.com/doc/api/ISteamFriends#richpresencelocalization Rich Presence Localization}
65
+ * @see {@link https://partner.steamgames.com/doc/api/ISteamFriends ISteamFriends Documentation}
66
+ */
67
+ class SteamRichPresenceManager {
68
+ /**
69
+ * Creates a new SteamRichPresenceManager instance
70
+ *
71
+ * @param libraryLoader - The Steam library loader for FFI calls
72
+ * @param apiCore - The Steam API core for lifecycle management
73
+ */
74
+ constructor(libraryLoader, apiCore) {
75
+ this.libraryLoader = libraryLoader;
76
+ this.apiCore = apiCore;
77
+ }
78
+ /**
79
+ * Sets a Rich Presence key/value pair for the current user
80
+ *
81
+ * @param key - The rich presence key (max 64 characters)
82
+ * @param value - The rich presence value (max 256 characters), or null/empty to delete the key
83
+ * @returns True if the key was set successfully, false otherwise
84
+ *
85
+ * @remarks
86
+ * - Setting a value to null or empty string deletes the key
87
+ * - Key/value pairs are automatically shared with friends in the same game
88
+ * - Steam has special handling for keys: 'status', 'connect', 'steam_display',
89
+ * 'steam_player_group', 'steam_player_group_size'
90
+ * - Changes take effect immediately for friends viewing your status
91
+ *
92
+ * @example Set game mode status
93
+ * ```typescript
94
+ * // Set status visible in friends list
95
+ * steam.richPresence.setRichPresence('status', 'Playing Capture the Flag');
96
+ *
97
+ * // Set connect string for join functionality
98
+ * steam.richPresence.setRichPresence('connect', '+connect 192.168.1.100:27015');
99
+ *
100
+ * // Use localization token
101
+ * steam.richPresence.setRichPresence('steam_display', '#Status_InGame');
102
+ *
103
+ * // Delete a key
104
+ * steam.richPresence.setRichPresence('connect', '');
105
+ * ```
106
+ *
107
+ * @example Player group/squad
108
+ * ```typescript
109
+ * // Indicate player is in a group
110
+ * steam.richPresence.setRichPresence('steam_player_group', 'lobby_12345');
111
+ * steam.richPresence.setRichPresence('steam_player_group_size', '8');
112
+ * ```
113
+ *
114
+ * @see {@link RichPresenceKeys} for standard key names
115
+ * @see {@link RichPresenceLimits} for length limits
116
+ */
117
+ setRichPresence(key, value) {
118
+ if (!this.apiCore.isInitialized()) {
119
+ console.error('[SteamRichPresence] Cannot set rich presence: Steam not initialized');
120
+ return false;
121
+ }
122
+ const friendsInterface = this.apiCore.getFriendsInterface();
123
+ if (!friendsInterface) {
124
+ console.error('[SteamRichPresence] Friends interface not available');
125
+ return false;
126
+ }
127
+ try {
128
+ const result = this.libraryLoader.SteamAPI_ISteamFriends_SetRichPresence(friendsInterface, key, value || '');
129
+ return result;
130
+ }
131
+ catch (error) {
132
+ console.error('[SteamRichPresence] Error setting rich presence:', error);
133
+ return false;
134
+ }
135
+ }
136
+ /**
137
+ * Clears all Rich Presence data for the current user
138
+ *
139
+ * @remarks
140
+ * This removes all key/value pairs that were set via setRichPresence().
141
+ * Call this when the player leaves your game or exits a match to clear their status.
142
+ *
143
+ * @example Clear presence on match end
144
+ * ```typescript
145
+ * // During gameplay
146
+ * steam.richPresence.setRichPresence('status', 'Playing Deathmatch');
147
+ * steam.richPresence.setRichPresence('connect', '+connect server:27015');
148
+ *
149
+ * // When match ends
150
+ * steam.richPresence.clearRichPresence();
151
+ *
152
+ * // Or set to menu status
153
+ * steam.richPresence.setRichPresence('status', 'In Main Menu');
154
+ * ```
155
+ */
156
+ clearRichPresence() {
157
+ if (!this.apiCore.isInitialized()) {
158
+ console.error('[SteamRichPresence] Cannot clear rich presence: Steam not initialized');
159
+ return;
160
+ }
161
+ const friendsInterface = this.apiCore.getFriendsInterface();
162
+ if (!friendsInterface) {
163
+ console.error('[SteamRichPresence] Friends interface not available');
164
+ return;
165
+ }
166
+ try {
167
+ this.libraryLoader.SteamAPI_ISteamFriends_ClearRichPresence(friendsInterface);
168
+ }
169
+ catch (error) {
170
+ console.error('[SteamRichPresence] Error clearing rich presence:', error);
171
+ }
172
+ }
173
+ /**
174
+ * Gets a Rich Presence value for a specific friend
175
+ *
176
+ * @param steamId - The friend's Steam ID
177
+ * @param key - The rich presence key to retrieve
178
+ * @returns The rich presence value, or empty string if not set or unavailable
179
+ *
180
+ * @remarks
181
+ * - Data may not be immediately available for friends you haven't interacted with recently
182
+ * - Call requestFriendRichPresence() first to ensure data is downloaded
183
+ * - Only works for friends who are playing the same game
184
+ * - Returns empty string if friend has no value for that key
185
+ *
186
+ * @example Read friend status
187
+ * ```typescript
188
+ * const friends = steam.friends.getAllFriends();
189
+ *
190
+ * friends.forEach(friend => {
191
+ * // Request data first
192
+ * steam.richPresence.requestFriendRichPresence(friend.steamId);
193
+ *
194
+ * // Read status
195
+ * const status = steam.richPresence.getFriendRichPresence(friend.steamId, 'status');
196
+ * const connect = steam.richPresence.getFriendRichPresence(friend.steamId, 'connect');
197
+ *
198
+ * if (status) {
199
+ * console.log(`${friend.personaName}: ${status}`);
200
+ * if (connect) {
201
+ * console.log(` Join with: ${connect}`);
202
+ * }
203
+ * }
204
+ * });
205
+ * ```
206
+ */
207
+ getFriendRichPresence(steamId, key) {
208
+ if (!this.apiCore.isInitialized()) {
209
+ console.error('[SteamRichPresence] Cannot get friend rich presence: Steam not initialized');
210
+ return '';
211
+ }
212
+ const friendsInterface = this.apiCore.getFriendsInterface();
213
+ if (!friendsInterface) {
214
+ console.error('[SteamRichPresence] Friends interface not available');
215
+ return '';
216
+ }
217
+ try {
218
+ const steamId64 = BigInt(steamId);
219
+ const value = this.libraryLoader.SteamAPI_ISteamFriends_GetFriendRichPresence(friendsInterface, steamId64, key);
220
+ return value || '';
221
+ }
222
+ catch (error) {
223
+ console.error('[SteamRichPresence] Error getting friend rich presence:', error);
224
+ return '';
225
+ }
226
+ }
227
+ /**
228
+ * Gets the number of Rich Presence keys set for a specific friend
229
+ *
230
+ * @param steamId - The friend's Steam ID
231
+ * @returns Number of rich presence keys, or 0 if none set or unavailable
232
+ *
233
+ * @remarks
234
+ * Use this with getFriendRichPresenceKeyByIndex() to iterate through
235
+ * all rich presence data for a friend.
236
+ *
237
+ * @example List all rich presence data
238
+ * ```typescript
239
+ * const friends = steam.friends.getAllFriends();
240
+ *
241
+ * friends.forEach(friend => {
242
+ * steam.richPresence.requestFriendRichPresence(friend.steamId);
243
+ *
244
+ * const keyCount = steam.richPresence.getFriendRichPresenceKeyCount(friend.steamId);
245
+ * console.log(`${friend.personaName} has ${keyCount} rich presence keys:`);
246
+ *
247
+ * for (let i = 0; i < keyCount; i++) {
248
+ * const key = steam.richPresence.getFriendRichPresenceKeyByIndex(friend.steamId, i);
249
+ * const value = steam.richPresence.getFriendRichPresence(friend.steamId, key);
250
+ * console.log(` ${key}: ${value}`);
251
+ * }
252
+ * });
253
+ * ```
254
+ */
255
+ getFriendRichPresenceKeyCount(steamId) {
256
+ if (!this.apiCore.isInitialized()) {
257
+ console.error('[SteamRichPresence] Cannot get key count: Steam not initialized');
258
+ return 0;
259
+ }
260
+ const friendsInterface = this.apiCore.getFriendsInterface();
261
+ if (!friendsInterface) {
262
+ console.error('[SteamRichPresence] Friends interface not available');
263
+ return 0;
264
+ }
265
+ try {
266
+ const steamId64 = BigInt(steamId);
267
+ const count = this.libraryLoader.SteamAPI_ISteamFriends_GetFriendRichPresenceKeyCount(friendsInterface, steamId64);
268
+ return count;
269
+ }
270
+ catch (error) {
271
+ console.error('[SteamRichPresence] Error getting key count:', error);
272
+ return 0;
273
+ }
274
+ }
275
+ /**
276
+ * Gets a Rich Presence key name by index for a specific friend
277
+ *
278
+ * @param steamId - The friend's Steam ID
279
+ * @param index - Index of the key (0 to getFriendRichPresenceKeyCount() - 1)
280
+ * @returns The key name, or empty string if invalid index
281
+ *
282
+ * @remarks
283
+ * Use this with getFriendRichPresenceKeyCount() to iterate through all keys.
284
+ * Then use getFriendRichPresence() to get the value for each key.
285
+ *
286
+ * @example Iterate all rich presence data
287
+ * ```typescript
288
+ * const steamId = '76561198012345678';
289
+ *
290
+ * steam.richPresence.requestFriendRichPresence(steamId);
291
+ *
292
+ * const keyCount = steam.richPresence.getFriendRichPresenceKeyCount(steamId);
293
+ * console.log(`Friend has ${keyCount} rich presence keys:`);
294
+ *
295
+ * for (let i = 0; i < keyCount; i++) {
296
+ * const key = steam.richPresence.getFriendRichPresenceKeyByIndex(steamId, i);
297
+ * const value = steam.richPresence.getFriendRichPresence(steamId, key);
298
+ * console.log(` ${key} = ${value}`);
299
+ * }
300
+ * ```
301
+ */
302
+ getFriendRichPresenceKeyByIndex(steamId, index) {
303
+ if (!this.apiCore.isInitialized()) {
304
+ console.error('[SteamRichPresence] Cannot get key by index: Steam not initialized');
305
+ return '';
306
+ }
307
+ const friendsInterface = this.apiCore.getFriendsInterface();
308
+ if (!friendsInterface) {
309
+ console.error('[SteamRichPresence] Friends interface not available');
310
+ return '';
311
+ }
312
+ try {
313
+ const steamId64 = BigInt(steamId);
314
+ const key = this.libraryLoader.SteamAPI_ISteamFriends_GetFriendRichPresenceKeyByIndex(friendsInterface, steamId64, index);
315
+ return key || '';
316
+ }
317
+ catch (error) {
318
+ console.error('[SteamRichPresence] Error getting key by index:', error);
319
+ return '';
320
+ }
321
+ }
322
+ /**
323
+ * Requests Rich Presence data for a specific friend
324
+ *
325
+ * @param steamId - The friend's Steam ID
326
+ *
327
+ * @remarks
328
+ * This asynchronously downloads rich presence data for the specified friend.
329
+ * Call this before attempting to read a friend's rich presence values.
330
+ *
331
+ * Data arrival is not immediate - allow a short delay before calling
332
+ * getFriendRichPresence() after requesting.
333
+ *
334
+ * @example Request and read rich presence
335
+ * ```typescript
336
+ * const friends = steam.friends.getAllFriends();
337
+ *
338
+ * // Request all friends' rich presence
339
+ * friends.forEach(friend => {
340
+ * steam.richPresence.requestFriendRichPresence(friend.steamId);
341
+ * });
342
+ *
343
+ * // Wait a moment for data to arrive
344
+ * setTimeout(() => {
345
+ * friends.forEach(friend => {
346
+ * const status = steam.richPresence.getFriendRichPresence(friend.steamId, 'status');
347
+ * if (status) {
348
+ * console.log(`${friend.personaName}: ${status}`);
349
+ * }
350
+ * });
351
+ * }, 1000);
352
+ * ```
353
+ */
354
+ requestFriendRichPresence(steamId) {
355
+ if (!this.apiCore.isInitialized()) {
356
+ console.error('[SteamRichPresence] Cannot request rich presence: Steam not initialized');
357
+ return;
358
+ }
359
+ const friendsInterface = this.apiCore.getFriendsInterface();
360
+ if (!friendsInterface) {
361
+ console.error('[SteamRichPresence] Friends interface not available');
362
+ return;
363
+ }
364
+ try {
365
+ const steamId64 = BigInt(steamId);
366
+ this.libraryLoader.SteamAPI_ISteamFriends_RequestFriendRichPresence(friendsInterface, steamId64);
367
+ }
368
+ catch (error) {
369
+ console.error('[SteamRichPresence] Error requesting rich presence:', error);
370
+ }
371
+ }
372
+ }
373
+ exports.SteamRichPresenceManager = SteamRichPresenceManager;
374
+ //# sourceMappingURL=SteamRichPresenceManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SteamRichPresenceManager.js","sourceRoot":"","sources":["../../src/internal/SteamRichPresenceManager.ts"],"names":[],"mappings":";;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,MAAa,wBAAwB;IAOnC;;;;;OAKG;IACH,YAAY,aAAiC,EAAE,OAAqB;QAClE,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACH,eAAe,CAAC,GAAW,EAAE,KAAoB;QAC/C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;YAClC,OAAO,CAAC,KAAK,CAAC,qEAAqE,CAAC,CAAC;YACrF,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,CAAC;QAC5D,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAC;YACrE,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,sCAAsC,CACtE,gBAAgB,EAChB,GAAG,EACH,KAAK,IAAI,EAAE,CACZ,CAAC;YACF,OAAO,MAAiB,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAA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