nodejs-insta-private-api-mqtt 1.1.8 → 1.1.9

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.
@@ -2,27 +2,43 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MQTToTConnection = void 0;
4
4
  const thrift_1 = require("../thrift");
5
+
5
6
  class MQTToTConnection {
6
7
  constructor(connectionData) {
7
8
  this.fbnsConnectionData = connectionData;
8
9
  }
10
+
9
11
  toThrift() {
10
- // ANTI-BOT: Ensure User-Agent is explicitly set to the Android string in MQTT connection
11
- if (this.fbnsConnectionData.clientInfo) {
12
- this.fbnsConnectionData.clientInfo.clientType = Buffer.from('com.instagram.android');
13
- // Ensure it uses the same UA as the REST API for consistency
14
- if (this.fbnsConnectionData.clientInfo.userAgent) {
15
- // Ensure we are using the correct buffer format for Thrift
16
- this.fbnsConnectionData.clientInfo.userAgent = Buffer.from(this.fbnsConnectionData.clientInfo.userAgent);
17
- }
12
+ // Clone safely DO NOT mutate original objects used by MQTT
13
+ const connCopy = Object.assign({}, this.fbnsConnectionData);
14
+ const originalClientInfo = this.fbnsConnectionData && this.fbnsConnectionData.clientInfo;
15
+ const clientInfoCopy = originalClientInfo ? Object.assign({}, originalClientInfo) : undefined;
16
+
17
+ if (clientInfoCopy) {
18
+ // MQTT REQUIRES STRING
19
+ if (typeof clientInfoCopy.userAgent !== 'string' || !clientInfoCopy.userAgent) {
20
+ clientInfoCopy.userAgent = 'Instagram 289.0.0.77.109 Android';
21
+ }
22
+
23
+ // ✅ MQTT REQUIRES STRING
24
+ if (typeof clientInfoCopy.clientType !== 'string' || !clientInfoCopy.clientType) {
25
+ clientInfoCopy.clientType = 'com.instagram.android';
26
+ }
27
+
28
+ connCopy.clientInfo = clientInfoCopy;
18
29
  }
19
- return (0, thrift_1.thriftWriteFromObject)(this.fbnsConnectionData, MQTToTConnection.thriftConfig);
30
+
31
+ // ✅ Thrift will serialize binary fields correctly
32
+ return (0, thrift_1.thriftWriteFromObject)(connCopy, MQTToTConnection.thriftConfig);
20
33
  }
34
+
21
35
  toString() {
22
36
  return this.toThrift().toString();
23
37
  }
24
38
  }
39
+
25
40
  exports.MQTToTConnection = MQTToTConnection;
41
+
26
42
  MQTToTConnection.thriftConfig = [
27
43
  thrift_1.ThriftDescriptors.binary('clientIdentifier', 1),
28
44
  thrift_1.ThriftDescriptors.binary('willTopic', 2),
@@ -56,10 +72,8 @@ MQTToTConnection.thriftConfig = [
56
72
  thrift_1.ThriftDescriptors.int64('anotherUnknown', 26),
57
73
  ]),
58
74
  thrift_1.ThriftDescriptors.binary('password', 5),
59
- // polyfill
60
75
  thrift_1.ThriftDescriptors.int16('unknown', 5),
61
76
  thrift_1.ThriftDescriptors.listOfBinary('getDiffsRequests', 6),
62
77
  thrift_1.ThriftDescriptors.binary('zeroRatingTokenHash', 9),
63
78
  thrift_1.ThriftDescriptors.mapBinaryBinary('appSpecificInfo', 10),
64
79
  ];
65
- //# sourceMappingURL=mqttot.connection.js.map
@@ -189,8 +189,18 @@ class RealtimeClient extends eventemitter3_1.EventEmitter {
189
189
  }
190
190
  }
191
191
  constructConnection() {
192
- const userAgent = this.ig.state.appUserAgent;
193
- const deviceId = this.ig.state.phoneId;
192
+ // --- SAFE userAgent resolution (fix for "Value of userAgent is not a string") ---
193
+ const userAgent =
194
+ typeof this.ig.state.userAgent === 'string'
195
+ ? this.ig.state.userAgent
196
+ : typeof this.ig.state.appUserAgent === 'string'
197
+ ? this.ig.state.appUserAgent
198
+ : typeof this.ig.state.deviceString === 'string'
199
+ ? this.ig.state.deviceString
200
+ : 'Instagram 155.0.0.37.107 Android';
201
+
202
+ // Ensure deviceId is a string to avoid substring errors
203
+ const deviceId = String(this.ig.state.phoneId || this.ig.state.deviceId || 'device_unknown');
194
204
  let sessionid;
195
205
  // First try: Extract from JWT authorization header (PRIMARY METHOD)
196
206
  sessionid = this.extractSessionIdFromJWT();
@@ -225,15 +235,15 @@ class RealtimeClient extends eventemitter3_1.EventEmitter {
225
235
  }
226
236
  // Last resort: Generate from userId + timestamp
227
237
  if (!sessionid) {
228
- const userId = this.ig.state.cookieUserId;
229
- sessionid = userId + '_' + Date.now();
238
+ const userId = this.ig.state.cookieUserId || this.ig.state.userId || '0';
239
+ sessionid = String(userId) + '_' + Date.now();
230
240
  this.realtimeDebug(`SessionID generated (fallback): ${sessionid}`);
231
241
  }
232
242
  const password = `sessionid=${sessionid}`;
233
243
  this.connection = new mqttot_1.MQTToTConnection({
234
244
  clientIdentifier: deviceId.substring(0, 20),
235
245
  clientInfo: {
236
- userId: BigInt(Number(this.ig.state.cookieUserId)),
246
+ userId: BigInt(Number(this.ig.state.cookieUserId || this.ig.state.userId || 0)),
237
247
  userAgent,
238
248
  clientCapabilities: 183,
239
249
  endpointCapabilities: 0,
@@ -263,7 +273,7 @@ class RealtimeClient extends eventemitter3_1.EventEmitter {
263
273
  presence_subscribe: '17846944882223835',
264
274
  }),
265
275
  'User-Agent': userAgent,
266
- 'Accept-Language': this.ig.state.language.replace('_', '-'),
276
+ 'Accept-Language': (this.ig.state.language || 'en_US').replace('_', '-'),
267
277
  },
268
278
  });
269
279
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs-insta-private-api-mqtt",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
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": {