homebridge-lgwebos-tv 4.2.2-beta.13 → 4.2.2-beta.3
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 +1 -1
- package/src/lgwebossocket.js +26 -25
package/package.json
CHANGED
package/src/lgwebossocket.js
CHANGED
|
@@ -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
|
|
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;
|
|
@@ -321,7 +322,7 @@ class LgWebOsSocket extends EventEmitter {
|
|
|
321
322
|
this.cleanupSocket();
|
|
322
323
|
this.updateTvState();
|
|
323
324
|
})
|
|
324
|
-
.on('open',
|
|
325
|
+
.on('open', () => {
|
|
325
326
|
if (this.logDebug) this.emit('debug', `Plugin received heartbeat from TV`);
|
|
326
327
|
|
|
327
328
|
// connect to device success
|
|
@@ -329,10 +330,8 @@ 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
|
|
334
|
+
if (socket.readyState === socket.OPEN) socket.ping();
|
|
336
335
|
this.heartbeat = setInterval(() => {
|
|
337
336
|
if (socket.readyState === socket.OPEN) {
|
|
338
337
|
if (this.logDebug) this.emit('debug', `Socket send heartbeat`);
|
|
@@ -340,8 +339,11 @@ class LgWebOsSocket extends EventEmitter {
|
|
|
340
339
|
}
|
|
341
340
|
}, 5000);
|
|
342
341
|
})
|
|
343
|
-
.on('pong', () => {
|
|
342
|
+
.on('pong', async () => {
|
|
344
343
|
if (this.logDebug) this.emit('debug', `Socket received heartbeat`);
|
|
344
|
+
|
|
345
|
+
// Register to TV
|
|
346
|
+
if (!this.isRegistered) await this.registerToTv();
|
|
345
347
|
})
|
|
346
348
|
.on('message', async (message) => {
|
|
347
349
|
const parsedMessage = JSON.parse(message);
|
|
@@ -359,6 +361,7 @@ class LgWebOsSocket extends EventEmitter {
|
|
|
359
361
|
break;
|
|
360
362
|
case 'registered':
|
|
361
363
|
if (this.logDebug) this.emit('debug', `Registered to TV with key: ${messageData['client-key']}`);
|
|
364
|
+
this.isRegistered = true;
|
|
362
365
|
|
|
363
366
|
//Save key in file if not saved before
|
|
364
367
|
const pairingKey = messageData['client-key'];
|
|
@@ -367,15 +370,20 @@ class LgWebOsSocket extends EventEmitter {
|
|
|
367
370
|
this.emit('success', 'Pairing key saved');
|
|
368
371
|
}
|
|
369
372
|
|
|
370
|
-
//
|
|
371
|
-
|
|
372
|
-
|
|
373
|
+
//Request system info data
|
|
374
|
+
this.systemInfoId = await this.getCid();
|
|
375
|
+
await this.send('request', ApiUrls.GetSystemInfo, undefined, this.systemInfoId);
|
|
373
376
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
377
|
+
//Request software info data
|
|
378
|
+
this.softwareInfoId = await this.getCid();
|
|
379
|
+
await this.send('request', ApiUrls.GetSoftwareInfo, undefined, this.softwareInfoId);
|
|
380
|
+
|
|
381
|
+
//Subscribe tv status
|
|
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);
|
|
379
387
|
break;
|
|
380
388
|
case 'error':
|
|
381
389
|
if (this.logError) this.emit('error', `Register to TV error: ${stringifyMessage}, trying again`);
|
|
@@ -438,10 +446,6 @@ class LgWebOsSocket extends EventEmitter {
|
|
|
438
446
|
if (this.logDebug) this.emit('debug', `System info: ${stringifyMessage}`);
|
|
439
447
|
this.tvInfo.modelName = messageData.modelName ?? 'LG TV';
|
|
440
448
|
|
|
441
|
-
//Request software info data
|
|
442
|
-
this.softwareInfoId = await this.getCid();
|
|
443
|
-
await this.send('request', ApiUrls.GetSoftwareInfo, undefined, this.softwareInfoId);
|
|
444
|
-
|
|
445
449
|
//restFul
|
|
446
450
|
if (this.restFulEnabled) this.emit('restFul', 'systeminfo', messageData);
|
|
447
451
|
|
|
@@ -471,9 +475,6 @@ class LgWebOsSocket extends EventEmitter {
|
|
|
471
475
|
//emit device info
|
|
472
476
|
this.emit('deviceInfo', this.tvInfo);
|
|
473
477
|
|
|
474
|
-
//Subscribe tv status
|
|
475
|
-
await this.subscribeTvStatus();
|
|
476
|
-
|
|
477
478
|
//restFul
|
|
478
479
|
if (this.restFulEnabled) this.emit('restFul', 'softwareinfo', messageData);
|
|
479
480
|
|