Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event stream stops after some time (days, weeks) #22

Closed
slybit opened this issue Apr 4, 2024 · 2 comments
Closed

Event stream stops after some time (days, weeks) #22

slybit opened this issue Apr 4, 2024 · 2 comments

Comments

@slybit
Copy link

slybit commented Apr 4, 2024

Describe The Problem:

Hello, I am using your nice project as part of a larger home-made alarm system and noticed that after some time (can be multiple weeks), the event stream simply stops. I assume that is because the websocket stream is somehow interrupted and not re-established.

My question:
Is there anything I can do in any of the events thrown by unifi-protect to (1) detect this has happened and (2) reconnect?

Note:
I found this code in your homebridge project:

    // Bootstrap refresh loop.
    const bootstrapRefresh = (): void => {

      // Sleep until it's time to bootstrap again.
      setTimeout(() => void this.bootstrapNvr(), PROTECT_CONTROLLER_REFRESH_INTERVAL * 1000);
    };

    // Let's set a listener to wait for bootstrap events to occur so we can keep ourselves in sync with the Protect controller.
    this.ufpApi.on("bootstrap", () => {

      // Sync our device view.
      syncUfpHomeKit();

      // Refresh our bootstrap.
      bootstrapRefresh();
    });

    // Kickoff our first round of bootstrap refreshes to ensure we stay in sync.
    bootstrapRefresh();

Is that the solution? Keep calling the bootstrap call every x seconds?

To Reproduce:

Register an unifi-protect.on("message") listener
Do a unifi-protect.login()
Do unifi-protect.getBootstrap()
Wait for the on("message") to stop being triggered

Logs:

The unifi-protect logs remain empty (no errors or anything are thrown)

Screenshots:

@slybit
Copy link
Author

slybit commented Apr 4, 2024

After reading all the code in https://github.com/hjdhjd/unifi-protect/blob/main/src/protect-api.ts, I now understand that indeed calling the bootstrap() method will reestablish the ws connection.
I will add similar code to my project to ensure the ws stream gets re-established every "x" seconds.
Closing my own ticket.

@slybit slybit closed this as completed Apr 4, 2024
Copy link

github-actions bot commented Apr 7, 2024

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

@github-actions github-actions bot locked and limited conversation to collaborators Apr 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant