hjdhjd/unifi-protect

How to convert buffers to JSON?

range-of-motion opened this issue · 3 comments

Hey there, thanks for creating this library.

I'm trying to detect doorbell rings and used this project to bootstrap the websocket. I'm currently able to retrieve messages, but they're encoded? I'm not very known with this, what is this? Is there an easy way to convert this to JSON? An example of my messages is below.

Screenshot 2022-02-08 at 12 44 50

Thank you! 🙏

@range-of-motion - this issue is being automatically closed because it does not follow either the feature request or bug report issue template. The issue templates have been designed to help in the troubleshooting (or feature request) process. Please use them and populate it as completely as possible to streamline troubleshooting or feature request discussions.

Hi there…and you’re welcome! The very best place to see an example of this library in action is my Homebridge plugin, which this library was originally a part of. 😄

You can’t “just listen to the websocket”. The data is encoded, largely because of what they’re trying to communicate (JSONs, other types of data). You need to use a set of utility functions in this library to decode them. Websockets are great, but you need some sort of protocol on top of it to send more complex data streams across.

See:

https://github.com/hjdhjd/homebridge-unifi-protect/blob/2b464fb6b190b7a30c93a5f79abb0b4f754a5a21/src/protect-nvr-events.ts#L153

For an example of how to listen in to events and do useful stuff, including doorbell rings with it.

Enjoy!

This issue is locked to prevent necroposting on closed issues. Please create a new issue for related support requests, bug reports, or feature suggestions.