Skip to content

Send volume and buffer fields as whole numbers - #192

Merged
maximmaxim345 merged 2 commits into
mainfrom
fix/round-integer-fields
Oct 22, 2026
Merged

maximmaxim345 merged 2 commits into
mainfrom
fix/round-integer-fields

Conversation

@maximmaxim345

Copy link
Copy Markdown
Member

What does this implement/fix?

The client sent volume, required_lead_time_ms, min_buffer_ms and buffer_capacity exactly as the app passed them, so a fractional value like 23.4 reached the server even though the spec defines these fields as integers.

They're now rounded before sending, and volume is also clamped to 0-100. setVolume and the volume controller command now throw a RangeError on NaN, which previously reached the server as null.

Related issue or spec PR (if applicable):

Types of changes

  • Bugfix (non-breaking change which fixes an issue): bugfix
  • New feature (non-breaking change which adds functionality): new-feature
  • Enhancement to an existing feature: enhancement
  • Breaking change (changes the public API or the protocol in a way that is not backwards compatible): breaking-change
  • Refactor (no behavior change): refactor
  • Documentation only: documentation
  • Maintenance / chore: maintenance
  • CI / workflow change: ci
  • Dependencies bump: dependencies

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Static review found no blocking issues in these localized changes, and regression tests cover the principal behaviors, though they were not executed.

No open issues 🎉

What changed in this PR

This PR normalizes outgoing volume and buffer values to whole numbers, aligning the SDK’s messages with the Sendspin protocol’s integer fields.

Changes:

  • Rounds buffer capacity and timing values, and rounds and clamps volume to 0–100.
  • Rejects NaN in public volume setters and commands, while retaining stored volume when hardware reports NaN.
  • Adds regression tests and documents the new RangeError behavior.
File Description
tests/​unit/​state-manager.test.ts Tests stored-volume rounding.
tests/​unit/​protocol-handler.test.ts Tests buffer, hardware-volume, and controller-volume normalization.
tests/​unit/​core.test.ts Tests rejection of NaN volume values.
src/​index.ts Documents volume-related RangeError behavior.
src/​core/​state-manager.ts Centralizes volume rounding and clamping.
src/​core/​protocol-handler.ts Normalizes outgoing numeric fields and handles hardware NaN.
src/​core/​core.ts Validates volume before updating state or forwarding commands.

Review effort: Balanced

@maximmaxim345
maximmaxim345 merged commit 4db1185 into main Oct 22, 2026
4 checks passed
@maximmaxim345
maximmaxim345 deleted the fix/round-integer-fields branch October 22, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants