Skip to content

Fix recording stream failure with "Cannot read properties of undefined (reading 'length')" error #1506

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

Draft
wants to merge 3 commits into
base: latest
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot 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
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 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 finished work on behalf of donavanbecker August 21, 2025 13:33
@Copilot Copilot AI requested a review from donavanbecker August 21, 2025 13:33
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