Closed marcus-j-davies closed 2 years ago
@Shaquu @crxporter I feel this can be put to BETA?
Please review the last commit.: https://github.com/NRCHKB/node-red-contrib-unifi-os/pull/48/commits/3bf7a970feb114eb873d1f2d9a7884bb5fa17069 This commit adds a robust (in testing 😅) recovery mechanism via the web socket Ping/Pong protocol.
The Web socket reconfiguring after a new update ID has been fetched - usually triggered by the 30 minutely re-login that occurs in the access controller.
A recovery after a network connection drop. This recovery is only put into high alert after we first successfully get a connection to the web socket, adding recovery to a web socket that was never successful could cause a continuous recovery loop, that will never end.
@crxporter @Shaquu
All comments have been addressed.
I have also found out that in NR, if a config node has user properties set to undefined
(Evan if not required), it causes an error flag on the nodes that use it (this @Shaquu was the reason for the error indicator) normal nodes don't seem to have this problem (at least I have never seen this happen for non config nodes)
This becomes a problem if an update means new config params are added - as they will be undefined
, therefore I have made them required.
Users just need to open up the config node and save to apply a value of 0, 0 sets timeouts to use defaults (90000/15000).
Bootstrap is now a type (types/Bootstrap.ts
)
Lastly, my PR is based on the Main branch, since switching to dev - the PR brings in changes that were not apart of the dev branch.
@crxporter @Shaquu Below is what I have built and is ready for review.
self.bootstrapObject
self.protectSharedWS
This has 2 important methodsregisterInterest
degisterInterest
Adds a
unifi-protect
node - that allows controlling and listening for camera eventsself.bootstrapObject
andself.protectSharedWS
are only instantiated if the bootstrap was successfully retrieved. the Protect node will warn the user if a Protect instance was not found.I issue a
501 - Not Implemented
when the node is trying to obtain the cameras.unifi-protect
will call intoself.accessControllerNode.protectSharedWS?.registerInterest(self.id, I)
self.accessControllerNode.protectSharedWS?.degisterInterest(self.id)
accoridngly, i.e when such node is deployed and removed
Each event type is based on an
EventModel
shapeProfile
Is the object that is designed to match (at least) the incoming payload (it useslodash.isMatch
)metadata
Is the settings/behaviour for that event. the HTML file uses themetadata.id
to subscribe to that event (supports multiple)some models have a
valueExpression
property and this uses JSONata to extract a value from the payload and passes it on to the user (aspayload.value
)- these do not support a duration (hasDuration: false
) as these are more a constant value change as opposed to an on going eventThe combination of
hasDuration: true
with avalueExpression
is marked as invalid in the typescriptLastley, there is
thumbnailSupport : enum
and this states whether or not a snapshot is supported with this event. themotion detection
event for example, does not seem to produce a snapshot in my early testing.Below is the
thumbnailSupport
enumThere is
snapshotAvailability
in the payloads to identify to the user the readiness of a snapshot, a 2nd pin is used for delayed snapshots - with the associated event idhttps://github.com/marcus-j-davies/node-red-contrib-unifi-os/blob/protect-node/src/EventModels.ts
Some areas may have room for improvements of course, such as creating a new access controller, from within a protect node, it will try and call into the bootstrap before the bootstrap has had a chance to be fetched by the controller (it does this to fetch the cameras using an HTTPAdmin endpoint
they will get a
501 - Not Implemented
because the bootstrap has not yet been received.But other than delaying this request (for new controllers being spawned) - not sure how else it can be achieved, as waiting will add some delay to the cameras being listed.
For already running access controllers - this is not a problem (as the Bootstrap is ready before hand), that is if Protect is running on the target hardware of course else 501