Skip to content

Commit

Permalink
Release 0.7.2 - additional checks for duplicate sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaquu committed Mar 9, 2022
1 parent 586d6b2 commit df2fc23
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 113 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-unifi-os",
"version": "0.7.1",
"version": "0.7.2",
"description": "Nodes to access UniFi data using endpoints and websockets",
"main": "build/nodes/unifi.js",
"scripts": {
Expand Down Expand Up @@ -49,7 +49,7 @@
"dependencies": {
"@nrchkb/logger": "^1.3.3",
"abortcontroller-polyfill": "^1.7.3",
"axios": "^0.26.0",
"axios": "^0.26.1",
"cookie": "0.4.2",
"ws": "^8.5.0"
},
Expand All @@ -58,12 +58,12 @@
"@types/node": "^12.20.16",
"@types/node-red": "^1.2.0",
"@types/semver": "^7.3.9",
"@types/ws": "^8.2.3",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"@types/ws": "^8.5.2",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/parser": "^5.14.0",
"babel-eslint": "^10.1.0",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.4.0",
"eslint": "^8.10.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"mocha": "^9.2.1",
Expand All @@ -72,8 +72,8 @@
"node-red-node-test-helper": "^0.2.7",
"prettier": "^2.5.1",
"supports-color": "^8.1.1",
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
"ts-node": "^10.7.0",
"typescript": "^4.6.2"
},
"engines": {
"node": ">=10.22.1"
Expand All @@ -84,6 +84,6 @@
],
"optionalDependencies": {
"bufferutil": "^4.0.6",
"utf-8-validate": "^5.0.8"
"utf-8-validate": "^5.0.9"
}
}
20 changes: 15 additions & 5 deletions src/nodes/WebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ module.exports = (RED: NodeAPI) => {
)
}
})

self.ws.on('unexpected-response', (request, response) => {
wsLogger.error('unexpected-response from the server')
try {
wsLogger.error(util.inspect(request))
wsLogger.error(util.inspect(response))
} catch (error: any) {
wsLogger.error(error)
}
})
}
}

Expand Down Expand Up @@ -255,12 +265,8 @@ module.exports = (RED: NodeAPI) => {

self.endpoint = self.config.endpoint

if (self.endpoint?.trim().length) {
await setupWebsocket(self)
}

self.on('input', async (msg) => {
log.debug('Received input message: ' + util.inspect(msg))
log.debug('Received input message: ' + util.inspect(msg?.payload))

const inputPayload =
validateInputPayload<WebSocketNodeInputPayloadType>(
Expand Down Expand Up @@ -308,6 +314,10 @@ module.exports = (RED: NodeAPI) => {
)
})

if (self.endpoint?.trim().length && !!self.ws) {
await setupWebsocket(self)
}

self.status({
fill: 'green',
shape: 'dot',
Expand Down
Loading

0 comments on commit df2fc23

Please sign in to comment.