@hieuxyz/rpc 1.2.0 → 1.2.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/README.md CHANGED
@@ -219,7 +219,7 @@ Main builder class for RPC.
219
219
  - `new LocalImage(filePath, fileName?)`: Upload a photo from your device.
220
220
  - `new RawImage(assetKey)`: Use an existing asset key directly (e.g., `spotify:track_id`).
221
221
  - `new DiscordImage(key)`: Use assets already on Discord (e.g., `mp:attachments/...`).
222
-
222
+ - `new ApplicationImage(name)`: Use an asset name from your Discord Application (requires .setApplicationId()).
223
223
  ## Author
224
224
 
225
225
  Developed by **hieuxyz**.
@@ -55,7 +55,7 @@ class Client {
55
55
  * Displays information about the library.
56
56
  */
57
57
  printAbout() {
58
- const version = '1.2.0';
58
+ const version = '1.2.01';
59
59
  console.log(`
60
60
  _ _
61
61
  | |__ (_) ___ _ ___ ___ _ ______
@@ -22,6 +22,7 @@ export declare class DiscordWebSocket {
22
22
  private permanentClose;
23
23
  private connectTimeout;
24
24
  private resolveReady;
25
+ private lastHeartbeatAck;
25
26
  /**
26
27
  * Current logged in user info.
27
28
  */
@@ -59,6 +59,7 @@ class DiscordWebSocket {
59
59
  permanentClose = false;
60
60
  connectTimeout = null;
61
61
  resolveReady = () => { };
62
+ lastHeartbeatAck = true;
62
63
  /**
63
64
  * Current logged in user info.
64
65
  */
@@ -138,7 +139,7 @@ class DiscordWebSocket {
138
139
  this.connectTimeout = null;
139
140
  }
140
141
  this.isReconnecting = false;
141
- if (code === 4004) {
142
+ if (code === 4004 || code === 4999) {
142
143
  this.sessionId = null;
143
144
  this.sequence = null;
144
145
  this.resumeGatewayUrl = null;
@@ -200,6 +201,7 @@ class DiscordWebSocket {
200
201
  break;
201
202
  case OpCode_1.OpCode.HEARTBEAT_ACK:
202
203
  logger_1.logger.info('Heartbeat acknowledged.');
204
+ this.lastHeartbeatAck = true;
203
205
  break;
204
206
  case OpCode_1.OpCode.INVALID_SESSION:
205
207
  logger_1.logger.warn(`Received INVALID_SESSION. Resumable: ${payload.d}`);
@@ -207,6 +209,8 @@ class DiscordWebSocket {
207
209
  this.ws?.close(4000, 'Invalid session, attempting to resume.');
208
210
  }
209
211
  else {
212
+ this.sessionId = null;
213
+ this.sequence = null;
210
214
  this.ws?.close(4004, 'Invalid session, starting a new session.');
211
215
  }
212
216
  break;
@@ -220,16 +224,23 @@ class DiscordWebSocket {
220
224
  }
221
225
  startHeartbeating() {
222
226
  this.cleanupHeartbeat();
227
+ this.lastHeartbeatAck = true;
223
228
  setTimeout(() => {
224
229
  if (this.ws?.readyState === ws_1.default.OPEN) {
225
230
  this.sendHeartbeat();
226
231
  }
227
232
  this.heartbeatInterval = setInterval(() => {
233
+ if (!this.lastHeartbeatAck) {
234
+ logger_1.logger.warn('Heartbeat ACK missing. Connection is zombie. Terminating to resume...');
235
+ this.ws?.terminate();
236
+ return;
237
+ }
228
238
  if (this.ws?.readyState !== ws_1.default.OPEN) {
229
239
  logger_1.logger.warn('Heartbeat skipped: WebSocket is not open.');
230
240
  this.cleanupHeartbeat();
231
241
  return;
232
242
  }
243
+ this.lastHeartbeatAck = false;
233
244
  this.sendHeartbeat();
234
245
  }, this.heartbeatIntervalValue);
235
246
  }, this.heartbeatIntervalValue * Math.random());
@@ -303,8 +314,6 @@ class DiscordWebSocket {
303
314
  }
304
315
  }
305
316
  shouldReconnect(code) {
306
- if (code === 1006)
307
- return true;
308
317
  const fatalErrorCodes = [4004, 4010, 4011, 4013, 4014];
309
318
  if (fatalErrorCodes.includes(code)) {
310
319
  logger_1.logger.error(`Fatal WebSocket error received (code: ${code}). Will not reconnect.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hieuxyz/rpc",
3
- "version": "1.2.0",
3
+ "version": "1.2.01",
4
4
  "description": "A Discord Rich Presence library for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",