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

Modify ISAPI to reliably open connections #967

Merged
merged 2 commits into from
Apr 29, 2024
Merged

Conversation

f1d094
Copy link

@f1d094 f1d094 commented Feb 25, 2024

Hikvision ISAPI may not accept a new open request if the previous one was not closed (e.g. using the test button on-camera or via curl command) but a close request can be sent even if the audio is already closed.

Using go2rtc to load microphone, regardless if using dashboard, WebRTC card, or Frigate card, resulted in ISAPI connections that were constantly failing with 401 errors. Testing revealed that manually sending a close request just before opening microphone url allowed it to proceed.

Modifying func Open in pkg/isapi/client.go to send a 'close' before 'open' seems to be working reliably with Frigate HASS card.

Modified func Close in pkg/isapi/client.go to call /ISAPI/System/TwoWayAudio/channels/<channel id>/close instead of /ISAPI/System/TwoWayAudio/channels/<channel id/close/open

Made minor mod to pkg/tcp/request.go, changing cnonce to 32 bytes. Still temporary/static and needs randomized.

f1d094 added 2 commits February 24, 2024 15:45
…WayAudio/channels/<channel id>/close' instead of '/ISAPI/System/TwoWayAudio/channels/<channel id/close/open'

Modified pkg/isapi/client.go to call 'close' before 'open' to prevent channel left open from prior connection blocking with 401 or 403 errors.
…WayAudio/channels/<channel id>/close' instead of '/ISAPI/System/TwoWayAudio/channels/<channel id/close/open'

Modified pkg/isapi/client.go to call 'close' before 'open' to prevent channel left open from prior connection blocking with 401 or 403 errors.
@pergolafabio
Copy link

Hey @f1d094 , thats interesting, i was also using the Frigate card to start two way audio on my Hikvision intercom.. When the intercom is ringing, i first send the curl command to stop the ringing, so the speaker is idle again

Then with Frigate, i start two way audio by clicking on the mic button, that works, if i then mute/unmute again, it doesnt work anymore... Gonna try sending the curl with the "close" command to see if it indeed resolves the issue, keep you posted

But, whats strange, if i stop the two way audio, and do a full refsresh of the page/view where the frigate card is located, then i can make it work , then i can again start two way audio , so that means the channel is somehow closed anyway?

Also, when using the Webrtc Card by AlexxIT instead of the frigate card, i can mute/unmute as many times i want... it stays working... maybe there is something different in those cards? maybe muting/unmuting on webrtc card is just muting thge sound? while clicking on the microphone button on the frigate card is really stopping the audio? ( or tries to)

@f1d094
Copy link
Author

f1d094 commented Apr 23, 2024

when using the Webrtc Card by AlexxIT instead of the frigate card, i can mute/unmute as many times i want

@pergolafabio: I did not have much luck with the WebRTC Card by AlexxIT. I cannot remember if that was before or after I went to the trouble of doing tcpdumps on the traffic and seeing what was going on. I think my main problem with the WebRTC card was that every time I hit mute/unmute it fully unloaded/reloaded the card and that was much too slow to be useful as an intercom...but I made the aforementioned changes to my own repo and have been using that pretty reliably with the Frigate Lovelace card. This is not yet rock-solid but I suspect that the the remaining inconsistencies reside with the Frigate Lovelace Card itself; I suspect this because my current issue is that every time I enable the mic, the whole video connection restarts. Why the video should need to reload when I enable the two-way audio, I have no idea. Also, about 5% of the time the video never comes back even though the mic/speaker remain on and the buttons still work. I don't know much about how the lovelace card works so I've not looked into it...one issue may well not be related to the other. That said, unlike AlexxIT's WebRTC card, when the Frigate Lovelace Card loads correctly (95% of the time) I can mute/unmute over and over after the initial load and it is instantaneous and does not need to reload the card.

Maybe @dermotduffy can clarify?

@dermotduffy
Copy link

Why the video should need to reload when I enable the two-way audio, I have no idea.

The Frigate card when configured with go2rtc as the live provider, needs to reset the video stream momentarily to add in the separate microphone stream (unless you use the always_connected option, in which case it's included at the start). When I was implementing this, I could not find a way to dynamically do this without resetting the connection. I do plan to revisit this implementation and see if there's a better way, but what you are describing is WAI as coded right now.

@pergolafabio
Copy link

hey @f1d094 , your solution fixed my issue, sending the close command before starting it again, i have now alwaysb 2way audio!!!

@f1d094
Copy link
Author

f1d094 commented Apr 24, 2024

unless you use the always_connected option, in which case it's included at the start

Aha! This is news I can use. I will try that out this evening and see if that smooths out my setup. Thanks!

@pergolafabio
Copy link

unless you use the always_connected option, in which case it's included at the start

Aha! This is news I can use. I will try that out this evening and see if that smooths out my setup. Thanks!

i tried the always_connected option, but the audio was not closed for me

@f1d094
Copy link
Author

f1d094 commented Apr 24, 2024

use the always_connected option

@dermotduffy: I decided this was too exciting and work could wait while I try it out...I can report back that my setup now works flawlessly/seamlessly! THANK YOU.

For your future plans: If you can think of a way to do a push indicator of the mic status and block multiple connections, that would be super helpful. Having more than one of us trying to greet someone at the door may be problematic. Maybe change the mic to no-color if available, red if already in use, and green if in-use-by-you?

Anyhow, what we have is amazing. Many thanks to you and AlexxIT for all your efforts!

@pergolafabio
Copy link

nice!

are you still proceeding the ISAPI close command, that one i need for the hikvision intercom
Or is possible you can create an ADDON repo so i can try the new fix out?

@f1d094
Copy link
Author

f1d094 commented Apr 24, 2024

unless you use the always_connected option, in which case it's included at the start

Aha! This is news I can use. I will try that out this evening and see if that smooths out my setup. Thanks!

i tried the always_connected option, but the audio was not closed for me

@pergolafabio: Please note that I'm using my own patched version of go2rtc. I think you'll have to wait for @AlexxIT to make a similar update for this to work for you when using the standard go2rtc. You can try mine if you like but there are also other changes I made like stripping google's stun server and torrent tunneling (I am morally opposed to internal resources using Things-on-the-Internet™ for internal connectivity) which may affect your setup adversely.

@f1d094
Copy link
Author

f1d094 commented Apr 24, 2024

@pergolafabio: Actually...nevermind what I said above. I forgot I didn't make public many changes. The one I have on github is what I used for doing the PR and only has the ISAPI changes. So it should work...but it is 51 commits behind the current go2rtc so YMMV. But it is working great for me.

@pergolafabio
Copy link

yeah, i tried adding it as a custom addon repo, but it fails

@pergolafabio
Copy link

alex, is using this repo for the addons, such an url i need to add:

https://github.com/AlexxIT/hassio-addons

@pergolafabio
Copy link

or i need to fork this one, and point the url to your github, and remove the image

https://github.com/AlexxIT/hassio-addons/blob/master/go2rtc/config.yaml

@f1d094
Copy link
Author

f1d094 commented Apr 24, 2024

yeah, i tried adding it as a custom addon repo, but it fails

I don't know what this means...

You will need to git clone https://github.com/f1d094/go2rtc and then go build the binary....then you have to copy it to /config/go2rtc dir on Frigate system...assuming this is docker/podman you would have your /config mapped externally and just put it in whatever that dir is.

Hope that helps.

@f1d094
Copy link
Author

f1d094 commented Apr 24, 2024

alex, is using this repo for the addons, such an url i need to add:

https://github.com/AlexxIT/hassio-addons

Ah. I see...I'm afraid I have zero experience with 'addons'. I am running HASS as a container. I've not tried HassOS or native install. Doesn't work with my infrastructure model.

@pergolafabio
Copy link

ok, nevermind, i wait for the fix to be implemented :-)

i now do the isapi curl command before i start the audio, working perfectly :-)

@felipecrs
Copy link
Contributor

@pergolafabio you can just place the binary at /config/go2rtc. The add-on (and Frigate) automatically picks it up instead if it's there.

@AlexxIT can you run the PR checks so that the binaries are archived?

@felipecrs
Copy link
Contributor

@pergolafabio you can just place the binary at /config/go2rtc. The add-on (and Frigate) automatically picks it up instead if it's there.

Ops, sorry. That's not true. It's only true for the Frigate add-on.

@pergolafabio
Copy link

Yeah , indeed, I'm using only the card

@AlexxIT AlexxIT merged commit d967014 into AlexxIT:master Apr 29, 2024
@AlexxIT
Copy link
Owner

AlexxIT commented Apr 29, 2024

Thanks!

AlexxIT added a commit that referenced this pull request Apr 29, 2024
@AlexxIT AlexxIT added this to the v1.9.0 milestone Apr 29, 2024
dnjooiopa added a commit to HYBIOT/go2rtc that referenced this pull request Apr 30, 2024
* Adds automatic extention of nest stream before it expires.

* Updated README with more accurate information regarding nest integration.

* Added support to stream backchannel to a command (outputbc)

* Code Cleanup, rename outputbc to execbc, using buffered Writer

* execbc-source: Merged the dial function to the Client creation

* execbc: increased Buffer Size for IO Operation

* execbc: Removed Buffered IO since it caused delay in the audio output

* fix(log-display): reverse log order to display newest first The

The applyLogStyling function in log.html has been updated to reverse the array of log lines. After parsing the JSON data, reversing the array ensures that the most recent logs appear at the top of the list. This change enhances the readability for users by displaying the logs in a descending chronological order.

* fix(clipboard): fix copy to clipboard functionality

Added a `copyTextToClipboard` function to handle text copying across different browsers and fallback scenarios. This function utilizes the Clipboard API when available, providing an asynchronous method to copy text securely. For browsers where the Clipboard API is not available or the page is not served over a secure context, a fallback method using a temporary textarea element and `document.execCommand` is employed. Replaced direct use of `navigator.clipboard.writeText` with this function in the 'shareget' click event listener to enhance cross-browser support and error handling.

* feat: Add signal related params to exec

* Update build.yml

* Added FreeBSD Binaries (#2)

Co-authored-by: Rob van Oostenrijk <robvanoostenrijk@noreply.users.github.com>

* Updated FreeBSD ffmpeg integrations

* Initial commit

* fix grammar

Co-authored-by: Felipe Santos <felipecassiors@gmail.com>

* pkg/hap/camera/accessory.go

* Fix crash with tapo cameras not returning 201

* feat(app): support daemon mode on non-Windows platforms

Added a new command-line flag `-daemon` to run the application in the background as a daemon. This option is only available for non-Windows operating systems due to platform-specific process handling. When enabled, the application restarts itself with the same arguments except for the `-daemon` flag, prints the PID of the background process, and then exits the current process.

* fix(daemon-mode): handle '-daemon' argument correctly for background execution

This commit fixes the issue where the '-daemon' argument was not being properly handled when re-executing the program in daemon mode. The loop removes the '-daemon' flag from the arguments slice before the program is re-run in the background, ensuring that subsequent executions do not attempt to enter daemon mode again.

The change will prevent potential errors or unexpected behavior due to the presence of the '-daemon' argument in recursive calls, making the daemon mode feature more robust and reliable.

* ci: upgrade GitHub Actions to newer versions

Updated various GitHub Actions used in the CI workflows (build.yml, gh-pages.yml, test.yml) to their latest major versions. This includes actions for checking out code, setting up Go, uploading artifacts, configuring Docker, and deploying to GitHub Pages. The update is part of routine maintenance to ensure compatibility with the latest features and improvements provided by these actions.

* Modified func Close in pkg/isapi/client.go to call '/ISAPI/System/TwoWayAudio/channels/<channel id>/close' instead of '/ISAPI/System/TwoWayAudio/channels/<channel id/close/open'

Modified pkg/isapi/client.go to call 'close' before 'open' to prevent channel left open from prior connection blocking with 401 or 403 errors.

* Modified func Close in pkg/isapi/client.go to call '/ISAPI/System/TwoWayAudio/channels/<channel id>/close' instead of '/ISAPI/System/TwoWayAudio/channels/<channel id/close/open'

Modified pkg/isapi/client.go to call 'close' before 'open' to prevent channel left open from prior connection blocking with 401 or 403 errors.

* fix(streams): handle non-string elements in slice source for NewStream

* Update README.md

fix: Typo in url

* feat(log): introduce toggle for reversing log order

Added a button to the log page allowing users to toggle the order in which logs are displayed (normal or reversed). This feature enhances user experience by providing flexibility in viewing logs. The implementation involves a boolean flag `reverseOrder` to track the current state of log order and dynamically updates the button text to reflect the current mode. Additionally, the log fetching function now conditionally reverses the log array based on this flag, ensuring that the display order matches the user's preference. This change could significantly improve usability for users needing to analyze recent events without scrolling through the entire log history.

* some fixes

* feat(dark-mode): implement dark mode and centralize CSS

Implemented a dark mode feature for the website, including a toggle button in the navigation bar that allows users to switch between light and dark themes. To support this feature, centralized common CSS styles (such as body, table, and button stylings) into main.js to ensure consistent application across all HTML pages. This change improves user experience by providing a visually comfortable alternative for low-light environments and centralizes styling rules for easier maintenance.

- Added dark mode styles for body, table, buttons, and navigation elements in main.js.
- Introduced a toggle mechanism in the navigation bar to switch between light and dark modes.
- Utilized JavaScript to detect system theme preference (`prefers-color-scheme`) and persist user's theme choice using localStorage.
- Removed duplicate and scattered CSS rules from individual HTML files (add.html, index.html, links.html, log.html) and centralized them in main.js to reduce redundancy and facilitate easier updates in the future.

This update enhances accessibility and user preference compliance by allowing users to select their desired theme while simplifying CSS management across the website.

* feat(dark-mode): improve contrast and visited link styles

* Add support for H200 hub and child devices (for example battery powered doorbell D230S1)

* feat(editor-theme): dynamically set editor theme based on dark mode preference

* fix(styles): implement flex layout for body element

* feat(docker): optimize hardware.Dockerfile by cleaning up apt cache

This commit optimizes the Docker image size for the hardware setup by including commands to clean up the APT cache after package installation. This change reduces the overall image size by removing unnecessary files and directories that are not needed in the final image, leading to faster download and deployment times.

* feat(dark-mode): enhance form elements and hr visibility

This commit improves the visibility and aesthetics of form elements (input, select, textarea) and horizontal rules (hr) in dark mode by adjusting their styles. Specifically, it sets a darker background color, lighter text color, and modifies border colors to ensure these elements are both visually appealing and easily distinguishable against the dark background. Additionally, placeholder text color has been adjusted to maintain readability without being overly prominent.

The removal of a fixed width on the navigation bar (`nav`) style is aimed at enhancing responsiveness and flexibility in various screen sizes, promoting a better user experience across devices.

These changes contribute to a more cohesive and accessible dark mode theme, aligning with modern web design practices that prioritize user comfort and interface adaptability.

* fix ivideon source

* feat(logging): more usable exec log

* fix(api): fix potential Slowloris Attack

* feat(index.html): implement auto-reload functionality every 5 seconds

* feat(index.html): optimize stream list update and preserve checkbox states

* feat(autoreload): change interval from 5 seconds to 1 second

* docs(readme): update link for latest binary download method

* add milestione http request api uri

* add milestone implementation webrtc

* fix patch with stream creation

* add insecure Tls param, skip wrong tls vms

* Add Arch dist to readme

* Rename constant back to old name

* feat(editor): upgrade Ace editor version to 1.33.0

* Code refactoring after AlexxIT#855

* Protect Nest API from fail on stop

* Update README.md

Basic spelling fix in README

* chore(gitignore): ignore .DS_Store files

* feat(web-ui): add confirmation dialog before deleting streams

* Code refactoring after AlexxIT#1063

* Add project logo

* Code refactoring for Milestone client

* Fixed possible nil pointer

* Add link to logo creator

* Code refactoring after AlexxIT#1029

* Code refactoring after AlexxIT#967

* Code refactoring after AlexxIT#963

* Code fix after AlexxIT#963

* Simplify restart func

* Code refactoring after AlexxIT#878

* Revert changes in readme file

* feat(logging): enhance log visualization with level-specific colors

- Add CSS classes for log levels (info, debug, error, trace, warn) in main.js to color-code log messages based on their severity.
- Modify log.html to include the log level as a class in each log entry's table row for applying the corresponding color styles.

* Code refactoring after AlexxIT#878

* Code refactoring after AlexxIT#859

* Update readme about exec two way audio

* Code refactoring after AlexxIT#1069

* Fix code style for HTML/JS files

* Fix WebRTC WriteRTP panic AlexxIT#994

* Fix panic on write to WebRTC source AlexxIT#935

* Fix configuration loss when handling concurrent requests (#1)

* [build] custom docker image for private registry (#3)

* [cicd][SRE-415]: build custom image

* [cicd][SRE-415]: change docker image name

* [cicd][SRE-415]: select main and tags for build only

* Add option for skipping RTP header size insufficient for extension error (#4)

Add option for skipping RTSP insufficient header error

* Add bitrate to webrtc/mse/mp4 consumer info (#5)

---------

Co-authored-by: René Simonsen <rss@knowhowdata.dk>
Co-authored-by: Michael Reif <19reifl93@gmail.com>
Co-authored-by: Sergey Krashevich <svk@svk.su>
Co-authored-by: dadav <33197631+dadav@users.noreply.github.com>
Co-authored-by: Rob van Oostenrijk <robvanoostenrijk@users.noreply.github.com>
Co-authored-by: Rob van Oostenrijk <robvanoostenrijk@noreply.users.github.com>
Co-authored-by: Felipe Santos <felipecassiors@gmail.com>
Co-authored-by: civita <14911217+civita@users.noreply.github.com>
Co-authored-by: Josip Janzic <hi@josip.dev>
Co-authored-by: f1d094 <f1d094@example.com>
Co-authored-by: pabst2k <54397544+pabst2k@users.noreply.github.com>
Co-authored-by: April MacDonald <me@aprilmacdonald.com>
Co-authored-by: Евгений <egmen@mail.ru>
Co-authored-by: Alex X <511909+AlexxIT@users.noreply.github.com>
Co-authored-by: Gennaro Gallo <ggallo@integra-sc.it>
Co-authored-by: Alex X <alexey.khit@gmail.com>
Co-authored-by: Jono Gould <78023819+jgould-godaddy@users.noreply.github.com>
Co-authored-by: Pattarapon Theanthong <Pattarapont96@gmail.com>
@AlexxIT
Copy link
Owner

AlexxIT commented Apr 30, 2024

https://github.com/AlexxIT/go2rtc/releases/tag/v1.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants