fix: audio attachments cannot be seeked using the progress slider

Merged
AB
3mo ago
+103-9

Proposed changes (including videos or screenshots)

Seeking an audio (or video) attachment with the progress slider snapped back to 0 and would not move. The browser reported the media as non-seekable (seekable = [[0, 0]]) despite a known duration and buffered data.

The root cause was server-side. Media requests are answered by getFileRange, whose header parser only matched fully-closed ranges (bytes=a-b). Browsers request media with open-ended ranges instead: bytes=0- on load and bytes=N- on seek. These failed to parse, so the server fell through to a gzipped 200 response instead of a 206 Partial Content, and a 200/gzip response is non-seekable by definition.

Changes:

  • Parse open-ended (bytes=N-) and suffix (bytes=-N) ranges, not just closed ones, and anchor the pattern to the bytes= unit.
  • Resolve any omitted bound against the file size per the HTTP spec, and clamp/flag out-of-range requests correctly (drives a proper 416).
  • Always advertise Accept-Ranges: bytes so browsers know ranged requests are supported.

With a valid range parsed, the server takes the 206 + range-extract branch and bypasses gzip, restoring seekability for all audio/video served from both GridFS and FileSystem storage. Added unit tests for getFileRange covering open-ended, closed, suffix, clamping, and out-of-range cases.

Issue(s)

CORE-2477

Steps to test or reproduce

  1. Send or open a room with an audio message attachment.
  2. Start playback, then drag the progress slider to a different position.
  3. Expected: playback seeks to the dragged position and continues from there (previously it snapped back to 0 and would not seek).

Further comments

Server-side change β€” a full Meteor server restart is required to pick it up (client HMR is not enough).

CORE-2477

Summary by CodeRabbit

  • Bug Fixes
    • Audio attachments now support seeking with the playback progress slider.
    • Improved handling of byte-range requests, including open-ended, suffix, and out-of-range ranges.
    • File downloads now advertise byte-range support for more reliable media playback and navigation.