Skip to content

Commit

Permalink
Release 0.2.1 - proper ws closing
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaquu committed Feb 12, 2021
1 parent c5166bd commit 5136313
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 184 deletions.
4 changes: 2 additions & 2 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.2.0",
"version": "0.2.1",
"description": "Nodes to access UniFi data using endpoints and websockets",
"main": "build/nodes/unifi.js",
"scripts": {
Expand Down Expand Up @@ -67,7 +67,7 @@
"eslint-plugin-prettier": "^3.3.1",
"husky": "^5.0.9",
"lint-staged": "^10.5.4",
"mocha": "^8.2.1",
"mocha": "^8.3.0",
"node-red": "^1.2.9",
"node-red-node-test-helper": "^0.2.6",
"prettier": "^2.2.1",
Expand Down
20 changes: 18 additions & 2 deletions src/nodes/WebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { endpoints } from '../Endpoints'
import { logger } from '@nrchkb/logger'

module.exports = (RED: NodeAPI) => {
const setupWebsocket = async (self: WebSocketNodeType) => {
const setupWebsocket = async (
self: WebSocketNodeType
): Promise<WebSocket> => {
const log = logger('UniFi', 'WebSocket', self.name, self)

const url =
Expand Down Expand Up @@ -151,7 +153,21 @@ module.exports = (RED: NodeAPI) => {
const self = this
const log = logger('UniFi', 'WebSocket', self.name, self)

setupWebsocket(self)
const wsPromise = setupWebsocket(self)

self.on('close', () => {
self.status({
fill: 'grey',
shape: 'dot',
text: 'Disconnecting',
})

log.debug('Disconnecting')

wsPromise.then((ws) => {
ws.close()
})
})

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

0 comments on commit 5136313

Please sign in to comment.