From 8a682f102b947fdcedb988a85abcbc9e4fff060f Mon Sep 17 00:00:00 2001 From: thllxb <26775504+thllxb@users.noreply.github.com> Date: Tue, 22 Sep 2026 13:17:53 -0400 Subject: [PATCH] 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> --- plugins/hikvision/README.md | 8 ++++++-- plugins/hikvision/src/hikvision-camera-api.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/hikvision/README.md b/plugins/hikvision/README.md index 2a0276dcb..da1b3439f 100644 --- a/plugins/hikvision/README.md +++ b/plugins/hikvision/README.md @@ -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). diff --git a/plugins/hikvision/src/hikvision-camera-api.ts b/plugins/hikvision/src/hikvision-camera-api.ts index 7aa616275..4253440a8 100644 --- a/plugins/hikvision/src/hikvision-camera-api.ts +++ b/plugins/hikvision/src/hikvision-camera-api.ts @@ -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; }