hb-zp-tools 1.0.4 → 1.0.6
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/lib/ZpClient.js +9 -6
- package/lib/ZpListener.js +5 -5
- package/lib/ZpTool.js +0 -1
- package/package.json +2 -2
package/lib/ZpClient.js
CHANGED
|
@@ -359,6 +359,7 @@ class ZpClient extends HttpClient {
|
|
|
359
359
|
|
|
360
360
|
this._params = _params
|
|
361
361
|
this._jsonFormatter = new JsonFormatter()
|
|
362
|
+
this._zpListener = this._params.listener
|
|
362
363
|
this._parser = parser
|
|
363
364
|
this._props = {
|
|
364
365
|
address: _params.host,
|
|
@@ -456,7 +457,6 @@ class ZpClient extends HttpClient {
|
|
|
456
457
|
household = zpClient.household
|
|
457
458
|
} else {
|
|
458
459
|
this.on('message', this._handleMessage)
|
|
459
|
-
await this.open()
|
|
460
460
|
await this.subscribe('/ZoneGroupTopology/Event')
|
|
461
461
|
const timeout = setTimeout(() => {
|
|
462
462
|
this.emit('error', new Error(
|
|
@@ -467,7 +467,7 @@ class ZpClient extends HttpClient {
|
|
|
467
467
|
await once(this, 'gotcha')
|
|
468
468
|
} catch (error) {}
|
|
469
469
|
clearTimeout(timeout)
|
|
470
|
-
await this.
|
|
470
|
+
await this.unsubscribe('/ZoneGroupTopology/Event')
|
|
471
471
|
this.removeListener('message', this._handleMessage)
|
|
472
472
|
}
|
|
473
473
|
if (this._zoneGroupState != null) {
|
|
@@ -975,7 +975,9 @@ class ZpClient extends HttpClient {
|
|
|
975
975
|
* reveive the notifications.
|
|
976
976
|
*/
|
|
977
977
|
async open () {
|
|
978
|
-
|
|
978
|
+
if (this._params.callbackUrl != null) {
|
|
979
|
+
return
|
|
980
|
+
}
|
|
979
981
|
this._params.callbackUrl = await this._zpListener.addClient(this)
|
|
980
982
|
this._zpListener.on(this.id, async (message) => {
|
|
981
983
|
try {
|
|
@@ -1026,9 +1028,7 @@ class ZpClient extends HttpClient {
|
|
|
1026
1028
|
* `/MediaRenderer/AVTransport/Event`.
|
|
1027
1029
|
*/
|
|
1028
1030
|
async subscribe (url) {
|
|
1029
|
-
|
|
1030
|
-
throw new SyntaxError('open() not yet called')
|
|
1031
|
-
}
|
|
1031
|
+
await this.open()
|
|
1032
1032
|
const callbackUrl = this._params.callbackUrl + url
|
|
1033
1033
|
const headers = {
|
|
1034
1034
|
TIMEOUT: 'Second-' + this._params.subscriptionTimeout + 30
|
|
@@ -1086,6 +1086,9 @@ class ZpClient extends HttpClient {
|
|
|
1086
1086
|
await this._request('UNSUBSCRIBE', url, undefined, { SID: sid })
|
|
1087
1087
|
} catch (error) { this.error(error) }
|
|
1088
1088
|
}
|
|
1089
|
+
if (Object.keys(this._subscriptions).length === 0) {
|
|
1090
|
+
await this.close()
|
|
1091
|
+
}
|
|
1089
1092
|
}
|
|
1090
1093
|
|
|
1091
1094
|
async _checkBootSeq (bootSeq) {
|
package/lib/ZpListener.js
CHANGED
|
@@ -50,20 +50,20 @@ class ZpListener extends EventEmitter {
|
|
|
50
50
|
response.write('<table>')
|
|
51
51
|
response.write(`<caption><h3>Listening to ${Object.keys(this._clients).length} clients</h3></caption>`)
|
|
52
52
|
response.write('<tr><th scope="col">ZonePlayer</th>')
|
|
53
|
-
|
|
53
|
+
response.write('<th scope="col">ID</th>')
|
|
54
54
|
response.write('<th scope="col">IP Address</th>')
|
|
55
55
|
response.write('<th scope="col">Local IP Address</th>')
|
|
56
56
|
response.write('<th scope="col">Subscriptions</th></tr>')
|
|
57
57
|
const names = {}
|
|
58
58
|
for (const id of Object.keys(this._clients)) {
|
|
59
59
|
const zpClient = this._clients[id]
|
|
60
|
-
const name = zpClient.
|
|
60
|
+
const name = zpClient.zonePlayerName == null ? zpClient.id : zpClient.zonePlayerName
|
|
61
61
|
names[name] = zpClient
|
|
62
62
|
}
|
|
63
63
|
for (const name of Object.keys(names).sort()) {
|
|
64
64
|
const zpClient = names[name]
|
|
65
65
|
response.write(`<tr><td>${name}</td>`)
|
|
66
|
-
|
|
66
|
+
response.write(`<td>${zpClient.id}</td>`)
|
|
67
67
|
response.write(`<td>${zpClient.address}</td>`)
|
|
68
68
|
response.write(`<td>${zpClient.localAddress}</td>`)
|
|
69
69
|
const subs = zpClient.subscriptions.map((sub) => {
|
|
@@ -151,8 +151,8 @@ class ZpListener extends EventEmitter {
|
|
|
151
151
|
* See {@link ZpClient#subscribe subscribe()}.
|
|
152
152
|
*/
|
|
153
153
|
async addClient (zpClient) {
|
|
154
|
-
this._clients[zpClient.id] = zpClient
|
|
155
154
|
await this._listen()
|
|
155
|
+
this._clients[zpClient.id] = zpClient
|
|
156
156
|
const callbackUrl = 'http://' + zpClient.localAddress + ':' + this._myPort +
|
|
157
157
|
'/notify/' + zpClient.id
|
|
158
158
|
return callbackUrl
|
|
@@ -166,7 +166,7 @@ class ZpListener extends EventEmitter {
|
|
|
166
166
|
*/
|
|
167
167
|
async removeClient (zpClient) {
|
|
168
168
|
this.removeAllListeners(zpClient.id)
|
|
169
|
-
delete this._clients[zpClient.id]
|
|
169
|
+
delete this._clients[zpClient.id]
|
|
170
170
|
if (Object.keys(this._clients).length === 0) {
|
|
171
171
|
await this._server.close()
|
|
172
172
|
}
|
package/lib/ZpTool.js
CHANGED
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"ebaauw"
|
|
7
7
|
],
|
|
8
8
|
"license": "Apache-2.0",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.6",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
"./*": "./lib/*.js"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"node": "^22||^20||^18"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"hb-lib-tools": "~2.2.
|
|
27
|
+
"hb-lib-tools": "~2.2.2",
|
|
28
28
|
"he": "^1.2.0",
|
|
29
29
|
"xml2js": "~0.6.2"
|
|
30
30
|
},
|