dsc-itv2-client 1.0.10 → 1.0.11

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/ITV2Client.js +21 -4
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsc-itv2-client",
3
3
  "author": "fajitacat",
4
- "version": "1.0.10",
4
+ "version": "1.0.11",
5
5
  "description": "Reverse engineered DSC ITV2 Protocol Client Library for TL280R Communicator - Monitor and control DSC alarm panels",
6
6
  "main": "src/index.js",
7
7
  "type": "module",
package/src/ITV2Client.js CHANGED
@@ -196,8 +196,6 @@ export class ITV2Client extends EventEmitter {
196
196
  const logger = this.logLevel === 'verbose' ? this._log.bind(this) : () => {
197
197
  };
198
198
  this.session = new ITv2Session(this.integrationId, this.accessCode, logger);
199
- this.emit('session:connecting');
200
- this._logMinimal(`[Session] Panel connecting from ${this.panelAddress}`);
201
199
  }
202
200
 
203
201
  const parsed = this.session.parsePacket(data);
@@ -223,12 +221,27 @@ export class ITV2Client extends EventEmitter {
223
221
  this._routePacket(parsed);
224
222
 
225
223
  } catch (err) {
224
+ // During WAITING state, parse errors are expected (stale encrypted packets from previous session)
225
+ if (this.handshakeState === 'WAITING') {
226
+ this._log(`[Recovery] Ignoring malformed packet while waiting for fresh handshake: ${err.message}`);
227
+ // Reset session to ensure we start fresh on next valid packet
228
+ if (this.session) {
229
+ this.session.disableAes();
230
+ this.session = null;
231
+ }
232
+ return;
233
+ }
234
+
226
235
  this._log(`[Error] ${err.message}`);
227
236
  this.emit('error', err);
228
237
 
229
- // Reset on parse errors
230
- if (this.handshakeState !== 'WAITING' && this.handshakeState !== 'SENT_CMD_RESPONSE_1') {
238
+ // Reset on parse errors during handshake
239
+ if (this.handshakeState !== 'SENT_CMD_RESPONSE_1') {
231
240
  this._log('[Recovery] Parse error, resetting to wait for panel restart');
241
+ if (this.session) {
242
+ this.session.disableAes();
243
+ this.session = null;
244
+ }
232
245
  this.handshakeState = 'WAITING';
233
246
  }
234
247
  }
@@ -295,6 +308,10 @@ export class ITV2Client extends EventEmitter {
295
308
  this._log(`[Session] OPEN_SESSION received:`);
296
309
  this._log(` Device Type: ${deviceType}`);
297
310
  this._log(` Encryption Type: ${encryptionType}`);
311
+
312
+ // Emit connecting event now that we have a valid OPEN_SESSION
313
+ this.emit('session:connecting');
314
+ this._logMinimal(`[Session] Panel connecting from ${this.panelAddress}`);
298
315
  this._logMinimal('[Handshake] Starting session establishment...');
299
316
 
300
317
  // Handle panel restart mid-handshake