nodejs-insta-private-api-mqtt 1.3.45 → 1.3.46
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.
|
@@ -118,6 +118,9 @@ class RealtimeClient extends eventemitter3_1.EventEmitter {
|
|
|
118
118
|
this._mqttSessionId = null; // actual server-provided mqtt session id (string)
|
|
119
119
|
this._mqttSessionPersistIntervalId = null; // periodic persist interval handler
|
|
120
120
|
|
|
121
|
+
// Active keepalive/query timer (added)
|
|
122
|
+
this._activeKeepaliveTimer = null;
|
|
123
|
+
|
|
121
124
|
// Persisted identity items that must survive reconnects:
|
|
122
125
|
// - clientMqttSessionId must NOT be re-generated each connect
|
|
123
126
|
// - _clientContext for EnhancedDirectCommands (for message identity)
|
|
@@ -800,6 +803,17 @@ class RealtimeClient extends eventemitter3_1.EventEmitter {
|
|
|
800
803
|
} catch(e) {}
|
|
801
804
|
} catch (error) {}
|
|
802
805
|
this._setupMessageHandlers();
|
|
806
|
+
|
|
807
|
+
// --- START: Active MQTT query keepalive ---
|
|
808
|
+
// Start a periodic "active query" that touches PUBSUB and REALTIME_SUB topics
|
|
809
|
+
// to keep the connection considered alive by the server, especially across long idle periods.
|
|
810
|
+
try {
|
|
811
|
+
// call wrapper which will set/clear the timer idempotently
|
|
812
|
+
this._startActiveQueryKeepalive();
|
|
813
|
+
} catch (e) {
|
|
814
|
+
this.realtimeDebug('[ACTIVE_QUERY] failed to start:', e?.message || e);
|
|
815
|
+
}
|
|
816
|
+
// --- END: Active MQTT query keepalive ---
|
|
803
817
|
}
|
|
804
818
|
|
|
805
819
|
/**
|
|
@@ -1264,6 +1278,12 @@ class RealtimeClient extends eventemitter3_1.EventEmitter {
|
|
|
1264
1278
|
clearInterval(this._mqttSessionPersistIntervalId);
|
|
1265
1279
|
this._mqttSessionPersistIntervalId = null;
|
|
1266
1280
|
}
|
|
1281
|
+
|
|
1282
|
+
// Clear the active keepalive/query timer if running
|
|
1283
|
+
if (this._activeKeepaliveTimer) {
|
|
1284
|
+
clearInterval(this._activeKeepaliveTimer);
|
|
1285
|
+
this._activeKeepaliveTimer = null;
|
|
1286
|
+
}
|
|
1267
1287
|
} catch (e) {}
|
|
1268
1288
|
// persist final session snapshot
|
|
1269
1289
|
try { this._persistMqttSession(); } catch (e) {}
|
|
@@ -1328,5 +1348,70 @@ class RealtimeClient extends eventemitter3_1.EventEmitter {
|
|
|
1328
1348
|
},
|
|
1329
1349
|
});
|
|
1330
1350
|
}
|
|
1351
|
+
|
|
1352
|
+
/**
|
|
1353
|
+
* Start an "active query" keepalive loop
|
|
1354
|
+
* - This sends a lightweight PUBSUB foreground pulse and a REALTIME_SUB reaffirmation
|
|
1355
|
+
* on a periodic basis to keep the server-side connection state active.
|
|
1356
|
+
*
|
|
1357
|
+
* Behavior & protections:
|
|
1358
|
+
* - Idle-aware: will skip sending if client received traffic within idleThresholdMs (to avoid unnecessary traffic).
|
|
1359
|
+
* - Interval configurable via initOptions.activeKeepaliveMs (default 45s).
|
|
1360
|
+
* - GraphQL subs reaffirmation uses initOptions.graphQlSubs or defaultGraphQlSubs.
|
|
1361
|
+
*/
|
|
1362
|
+
_startActiveQueryKeepalive() {
|
|
1363
|
+
try {
|
|
1364
|
+
// Clear any existing timer idempotently
|
|
1365
|
+
if (this._activeKeepaliveTimer) {
|
|
1366
|
+
clearInterval(this._activeKeepaliveTimer);
|
|
1367
|
+
this._activeKeepaliveTimer = null;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
const ms = (this.initOptions && this.initOptions.activeKeepaliveMs) ? this.initOptions.activeKeepaliveMs : 45000;
|
|
1371
|
+
const idleThresholdMs = (this.initOptions && this.initOptions.activeKeepaliveIdleThresholdMs) ? this.initOptions.activeKeepaliveIdleThresholdMs : 30000;
|
|
1372
|
+
|
|
1373
|
+
// small wrapper to avoid unhandled rejection inside setInterval
|
|
1374
|
+
this._activeKeepaliveTimer = setInterval(async () => {
|
|
1375
|
+
try {
|
|
1376
|
+
if (!this.commands) return;
|
|
1377
|
+
|
|
1378
|
+
// Do not send keepalive if we received traffic recently — avoids noisy pulses during active use.
|
|
1379
|
+
const idle = Date.now() - (this._lastMessageAt || 0);
|
|
1380
|
+
if (idle < idleThresholdMs) {
|
|
1381
|
+
// skip sending if not idle enough
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
// 1) PUBSUB "foreground pulse" with a tiny timestamp payload (safe, no side-effects)
|
|
1386
|
+
try {
|
|
1387
|
+
await this.commands.updateSubscriptions({
|
|
1388
|
+
topic: constants_1.Topics.PUBSUB,
|
|
1389
|
+
data: { foreground: true, keepalive_ts: Date.now() }
|
|
1390
|
+
});
|
|
1391
|
+
} catch (e) {
|
|
1392
|
+
// log but continue to attempt realtime-sub reaffirmation
|
|
1393
|
+
this.realtimeDebug('[ACTIVE_QUERY] PUBSUB foreground pulse failed:', e?.message || e);
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
// 2) REALTIME_SUB reaffirmation of GraphQL subs (lightweight)
|
|
1397
|
+
try {
|
|
1398
|
+
const subs = (this.initOptions && this.initOptions.graphQlSubs && this.initOptions.graphQlSubs.length) ? this.initOptions.graphQlSubs : this.defaultGraphQlSubs;
|
|
1399
|
+
await this.commands.updateSubscriptions({
|
|
1400
|
+
topic: constants_1.Topics.REALTIME_SUB,
|
|
1401
|
+
data: { sub: subs, keepalive_ts: Date.now() }
|
|
1402
|
+
});
|
|
1403
|
+
} catch (e) {
|
|
1404
|
+
this.realtimeDebug('[ACTIVE_QUERY] REALTIME_SUB reaffirmation failed:', e?.message || e);
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
this.realtimeDebug('[ACTIVE_QUERY] keepalive query sent (idle ms: ' + idle + ')');
|
|
1408
|
+
} catch (e) {
|
|
1409
|
+
this.realtimeDebug('[ACTIVE_QUERY] unexpected error in keepalive loop:', e?.message || e);
|
|
1410
|
+
}
|
|
1411
|
+
}, ms);
|
|
1412
|
+
} catch (e) {
|
|
1413
|
+
this.realtimeDebug('[ACTIVE_QUERY] could not start keepalive timer:', e?.message || e);
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1331
1416
|
}
|
|
1332
1417
|
exports.RealtimeClient = RealtimeClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodejs-insta-private-api-mqtt",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.46",
|
|
4
4
|
"description": "Complete Instagram MQTT protocol with FULL iOS + Android support. 33 device presets (21 iOS + 12 Android). iPhone 16/15/14/13/12, iPad Pro, Samsung, Pixel, Huawei. Real-time DM messaging, view-once media extraction, sub-500ms latency.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|