Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 21, 2025

Recording streams were failing immediately with a TypeError when cameras had recording and prebuffering enabled. The error occurred because the handleRecordingStreamRequest method was yielding empty objects instead of proper RecordingPacket structures.

Root Cause

The original implementation yielded an empty object:

async *handleRecordingStreamRequest(streamId: number): AsyncGenerator<RecordingPacket, any, any> {
  // For now, just yield an empty RecordingPacket
  yield {} as RecordingPacket
}

But HAP-nodejs expects RecordingPacket objects with this structure:

interface RecordingPacket {
  data: Buffer;
  isLast: boolean;
}

When HAP-nodejs tried to access packet.data.length, it got undefined.length causing the TypeError.

Solution

This PR fixes the issue with minimal changes:

  1. Fixed updateRecordingConfiguration method signature to properly accept the recording configuration parameter as required by the HomeKit interface
  2. Implemented proper handleRecordingStreamRequest that yields valid RecordingPacket objects with actual video data from the existing fragment generation pipeline
  3. Added comprehensive error handling and configuration validation

The fix connects the recording stream to the existing handleFragmentsRequests method which properly generates MP4 video fragments using FFmpeg, ensuring that every packet contains valid data: Buffer and isLast: boolean properties.

Users can now successfully record video with cameras that have both recording and prebuffering enabled without encountering the TypeError.

Fixes #1505.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor Author

Copilot AI commented Aug 21, 2025

@donavanbecker 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI and others added 2 commits August 21, 2025 13:28
…tructure

Co-authored-by: donavanbecker <9875439+donavanbecker@users.noreply.github.com>
Co-authored-by: donavanbecker <9875439+donavanbecker@users.noreply.github.com>
Copilot AI changed the title [WIP] Recording stream fails with "Cannot read properties of undefined (reading 'length')" Fix recording stream failure with "Cannot read properties of undefined (reading 'length')" error Aug 21, 2025
Copilot AI requested a review from donavanbecker August 21, 2025 13:33
@donavanbecker donavanbecker changed the base branch from latest to beta-4.1.0 September 10, 2025 05:08
@donavanbecker donavanbecker marked this pull request as ready for review September 10, 2025 05:08
@donavanbecker donavanbecker changed the base branch from beta-4.1.0 to latest September 18, 2025 11:48
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.

Recording stream fails with "Cannot read properties of undefined (reading 'length')"

2 participants