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

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.2",
4
+ "version": "4.2.2-beta.4",
5
5
  "description": "Homebridge plugin to control LG webOS TV.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -322,7 +322,7 @@ class LgWebOsSocket extends EventEmitter {
322
322
  this.cleanupSocket();
323
323
  this.updateTvState();
324
324
  })
325
- .on('open', async () => {
325
+ .on('open', () => {
326
326
  if (this.logDebug) this.emit('debug', `Plugin received heartbeat from TV`);
327
327
 
328
328
  // connect to device success
@@ -331,18 +331,19 @@ class LgWebOsSocket extends EventEmitter {
331
331
  this.socketConnected = true;
332
332
 
333
333
  // start heartbeat
334
- this.heartbeat = setInterval(() => {
335
- if (socket.readyState === socket.OPEN) {
336
- if (this.logDebug) this.emit('debug', `Socket send heartbeat`);
337
- socket.ping();
338
- }
339
- }, 5000);
334
+ socket.ping();
335
+ if (this.logDebug) this.emit('debug', `Socket send heartbeat`);
340
336
  })
341
337
  .on('pong', async () => {
342
338
  if (this.logDebug) this.emit('debug', `Socket received heartbeat`);
343
339
 
344
340
  // Register to TV
345
341
  if (!this.isRegistered) await this.registerToTv();
342
+
343
+ this.heartbeat = setTimeout(() => {
344
+ if (this.logDebug) this.emit('debug', `Socket send heartbeat`);
345
+ this.socket.ping();
346
+ }, 5000);
346
347
  })
347
348
  .on('message', async (message) => {
348
349
  const parsedMessage = JSON.parse(message);
@@ -369,10 +370,6 @@ class LgWebOsSocket extends EventEmitter {
369
370
  this.emit('success', 'Pairing key saved');
370
371
  }
371
372
 
372
- //Request specjalized socket
373
- this.specializedSocketId = await this.getCid();
374
- await this.send('request', ApiUrls.SocketUrl, undefined, this.specializedSocketId);
375
-
376
373
  //Request system info data
377
374
  this.systemInfoId = await this.getCid();
378
375
  await this.send('request', ApiUrls.GetSystemInfo, undefined, this.systemInfoId);
@@ -383,6 +380,10 @@ class LgWebOsSocket extends EventEmitter {
383
380
 
384
381
  //Subscribe tv status
385
382
  await this.subscribeTvStatus();
383
+
384
+ //Request specjalized socket
385
+ this.specializedSocketId = await this.getCid();
386
+ await this.send('request', ApiUrls.SocketUrl, undefined, this.specializedSocketId);
386
387
  break;
387
388
  case 'error':
388
389
  if (this.logError) this.emit('error', `Register to TV error: ${stringifyMessage}, trying again`);