fix(hikvision): restore two way audio by honoring the body argument in HikvisionCameraAPI.request (#2153)

* fix(hikvision): restore two way audio by honoring the body argument

HikvisionCameraAPI.request(urlOrOptions, body) ignored the `body`
argument whenever `urlOrOptions` was an options object. startIntercom()
calls it as request({ url, method, headers }, passthrough), so the audio
PassThrough was silently discarded and the camera received an empty PUT.
Talkback was inaudible and the session tore down almost immediately.

This regressed in 1cd5c194c, which replaced plain `body,` with a
conditional so that callers passing `body` inside the options object
(putVcaResource) would not have it clobbered by the trailing shorthand.
That change ignored the second argument, which startIntercom has used
since fa50d6faa.

Fall back to the second argument when the options object has no body,
which satisfies both call styles.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(hikvision): update Two Way Audio codec support

The Hikvision two way audio option is no longer untested: with the
request body fix in this PR it is confirmed working on real hardware
with both G.711ulaw and G.711alaw.

Also correct the claim that any codec other than G.711ulaw fails.
G.711alaw works; startIntercom has mapped it to pcm_alaw for some time.
Non-G.711 codecs (AAC) remain unsupported - startIntercom logs
"Unknown codec" and falls back to pcm_mulaw, so the camera receives
mu-law it cannot decode and plays nothing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
thllxb
2026-09-22 13:17:53 -04:00
committed by GitHub
parent 835ff8c7ac
commit 8a682f102b
2 changed files with 7 additions and 3 deletions

View File

@@ -9,9 +9,13 @@ If the camera or NVR do not have motion detection, you will have to use a separa
There are two options for Two Way Audio:
* ONVIF (Recommended)
* Hikvision (Untested)
* Hikvision
Two Way Audio is supported if the audio codec is set to G.711ulaw on the camera, which is usually the default audio codec. This audio codec will also work with HomeKit. Changing the audio codec from G.711ulaw will cause Two Way Audio to fail on the cameras that were tested.
Two Way Audio is supported if the audio codec is set to G.711ulaw or G.711alaw on the camera. G.711ulaw is usually the default audio codec, and will also work with HomeKit.
The `Hikvision` option uses the camera's ISAPI two way audio endpoint, and is confirmed working with both G.711ulaw and G.711alaw.
Audio codecs other than G.711 (such as AAC) are not supported for Two Way Audio. The plugin will log `Unknown codec` and fall back to G.711ulaw, which results in no audio from the camera speaker.
## Codec Settings
Configure optimal codec settings (as required by HomeKit) through Hikvision's configuration webpage or device interface (not Scrypted).

View File

@@ -79,7 +79,7 @@ export class HikvisionCameraAPI implements HikvisionAPI {
},
rejectUnauthorized: false,
credential: this.credential,
body: typeof urlOrOptions !== 'string' && !(urlOrOptions instanceof URL) ? urlOrOptions?.body : body,
body: typeof urlOrOptions !== 'string' && !(urlOrOptions instanceof URL) ? (urlOrOptions?.body ?? body) : body,
});
return response;
}