homebridge-lgwebos-tv 4.2.2-beta.13 → 4.2.2-beta.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "LG webOS TV",
3
3
  "name": "homebridge-lgwebos-tv",
4
- "version": "4.2.2-beta.13",
4
+ "version": "4.2.2-beta.2",
5
5
  "description": "Homebridge plugin to control LG webOS TV.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -32,6 +32,7 @@ class LgWebOsSocket extends EventEmitter {
32
32
  this.socketConnected = false;
33
33
  this.specializedSocketConnected = false;
34
34
  this.cidCount = 0;
35
+ this.isRegistered = false;
35
36
 
36
37
  this.power = false;
37
38
  this.screenState = 'Suspend';
@@ -67,7 +68,10 @@ class LgWebOsSocket extends EventEmitter {
67
68
  if (this.logDebug) this.emit('debug', `Plugin send heartbeat to TV`);
68
69
 
69
70
  const state = await this.functions.ping(this.host, this.webSocketPort);
70
- if (!state.online || this.socketConnected || this.connecting) return;
71
+ if (!state.online) {
72
+ return;
73
+ }
74
+
71
75
  if (this.logDebug) this.emit('debug', `Plugin received heartbeat from TV`);
72
76
 
73
77
  this.connecting = true;
@@ -97,6 +101,7 @@ class LgWebOsSocket extends EventEmitter {
97
101
  this.cidCount = 0;
98
102
  this.power = false;
99
103
  this.screenState = 'Suspend';
104
+ this.isRegistered = false;
100
105
  };
101
106
 
102
107
  updateTvState() {
@@ -206,10 +211,6 @@ class LgWebOsSocket extends EventEmitter {
206
211
  await this.send('subscribe', ApiUrls.GetForegroundAppMediaInfo, undefined, this.mediaInfoId);
207
212
  }
208
213
 
209
- //Request specjalized socket
210
- this.specializedSocketId = await this.getCid();
211
- await this.send('request', ApiUrls.SocketUrl, undefined, this.specializedSocketId);
212
-
213
214
  if (this.logDebug) this.emit('debug', `Subscribe tv status successful`);
214
215
 
215
216
  return true;
@@ -329,9 +330,6 @@ class LgWebOsSocket extends EventEmitter {
329
330
  if (!this.socketConnected) this.emit('success', `Socket Connect Success`);
330
331
  this.socketConnected = true;
331
332
 
332
- // Register to TV
333
- await this.registerToTv();
334
-
335
333
  // start heartbeat
336
334
  this.heartbeat = setInterval(() => {
337
335
  if (socket.readyState === socket.OPEN) {
@@ -340,8 +338,11 @@ class LgWebOsSocket extends EventEmitter {
340
338
  }
341
339
  }, 5000);
342
340
  })
343
- .on('pong', () => {
341
+ .on('pong', async () => {
344
342
  if (this.logDebug) this.emit('debug', `Socket received heartbeat`);
343
+
344
+ // Register to TV
345
+ if (!this.isRegistered) await this.registerToTv();
345
346
  })
346
347
  .on('message', async (message) => {
347
348
  const parsedMessage = JSON.parse(message);
@@ -359,6 +360,7 @@ class LgWebOsSocket extends EventEmitter {
359
360
  break;
360
361
  case 'registered':
361
362
  if (this.logDebug) this.emit('debug', `Registered to TV with key: ${messageData['client-key']}`);
363
+ this.isRegistered = true;
362
364
 
363
365
  //Save key in file if not saved before
364
366
  const pairingKey = messageData['client-key'];
@@ -367,15 +369,20 @@ class LgWebOsSocket extends EventEmitter {
367
369
  this.emit('success', 'Pairing key saved');
368
370
  }
369
371
 
370
- //Send initial power state
371
- if (!this.power) {
372
- this.emit('powerState', true, 'Active');
372
+ //Request specjalized socket
373
+ this.specializedSocketId = await this.getCid();
374
+ await this.send('request', ApiUrls.SocketUrl, undefined, this.specializedSocketId);
373
375
 
374
- //Request system info data
375
- this.systemInfoId = await this.getCid();
376
- await this.send('request', ApiUrls.GetSystemInfo, undefined, this.systemInfoId);
377
- this.power = true;
378
- }
376
+ //Request system info data
377
+ this.systemInfoId = await this.getCid();
378
+ await this.send('request', ApiUrls.GetSystemInfo, undefined, this.systemInfoId);
379
+
380
+ //Request software info data
381
+ this.softwareInfoId = await this.getCid();
382
+ await this.send('request', ApiUrls.GetSoftwareInfo, undefined, this.softwareInfoId);
383
+
384
+ //Subscribe tv status
385
+ await this.subscribeTvStatus();
379
386
  break;
380
387
  case 'error':
381
388
  if (this.logError) this.emit('error', `Register to TV error: ${stringifyMessage}, trying again`);
@@ -438,10 +445,6 @@ class LgWebOsSocket extends EventEmitter {
438
445
  if (this.logDebug) this.emit('debug', `System info: ${stringifyMessage}`);
439
446
  this.tvInfo.modelName = messageData.modelName ?? 'LG TV';
440
447
 
441
- //Request software info data
442
- this.softwareInfoId = await this.getCid();
443
- await this.send('request', ApiUrls.GetSoftwareInfo, undefined, this.softwareInfoId);
444
-
445
448
  //restFul
446
449
  if (this.restFulEnabled) this.emit('restFul', 'systeminfo', messageData);
447
450
 
@@ -471,9 +474,6 @@ class LgWebOsSocket extends EventEmitter {
471
474
  //emit device info
472
475
  this.emit('deviceInfo', this.tvInfo);
473
476
 
474
- //Subscribe tv status
475
- await this.subscribeTvStatus();
476
-
477
477
  //restFul
478
478
  if (this.restFulEnabled) this.emit('restFul', 'softwareinfo', messageData);
479
479