Skip to content

upgrade: mediastream migration and adaptation upgrade for Solid 2.0#919

Open
davedbase wants to merge 3 commits into
solidjs-community:nextfrom
davedbase:update/v2/mediastream
Open

upgrade: mediastream migration and adaptation upgrade for Solid 2.0#919
davedbase wants to merge 3 commits into
solidjs-community:nextfrom
davedbase:update/v2/mediastream

Conversation

@davedbase
Copy link
Copy Markdown
Member

@davedbase davedbase commented May 23, 2026

Replaces @solid-primitives/stream with a fully Solid 2.0–compatible package. Switches from createResource to reactive signals + split createEffect for async stream acquisition. isServer now imported from @solidjs/web. Return types simplified — mutate/refetch removed; use source accessors for reactivity. Loading/error states handled via <Loading> and <Errored> from @solidjs/web.

Design changes (Step 1)

  • createResource is gone in Solid 2.0 → replaced with createSignal(INTERNAL_OPTIONS) + split createEffect for async stream acquisition
  • An active flag in the effect's apply phase prevents a superseded getUserMedia call from overwriting a newer stream (race condition fix)
  • createAmplitudeFromStream createEffect converted to split compute/apply form
  • The rAF loop() starts synchronously inside createRoot, so setAmplitude needs INTERNAL_OPTIONS to avoid SIGNAL_WRITE_IN_OWNED_SCOPE

API changes

  • createStream / createScreen: return is now [Accessor<MediaStream | undefined>, { stop, mute }]mutate and refetch removed (reactivity is source-driven)
  • createAmplitudeStream: second element simplified to { stream, stop }
  • ResourceActions type export removed

Summary by CodeRabbit

  • New Features

    • Introduced @solid-primitives/mediastream package for Solid.js v2 with media stream utilities
    • Added primitives for creating and managing audio/video input streams from devices
    • Added screen capture functionality
    • Added microphone amplitude detection and audio analysis
    • Added media permission request handling
  • Documentation

    • Added comprehensive README with usage examples
    • Added CHANGELOG documenting API changes and migration guidance

Review Change Stack

@davedbase davedbase added this to the Solid 2.0 Migration milestone May 23, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 23, 2026

🦋 Changeset detected

Latest commit: 875792c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solid-primitives/mediastream Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8ec5223c-b900-46f6-8019-49f47cf2012e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@davedbase davedbase marked this pull request as ready for review May 23, 2026 15:41
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/mediastream/README.md`:
- Line 136: Update the README line about createMediaPermissionRequest to clarify
that it forwards navigator.mediaDevices.getUserMedia behavior: the returned
Promise<void> resolves when permission is granted and rejects if the user denies
permission or getUserMedia fails (include both denial and other errors),
referencing createMediaPermissionRequest and navigator.mediaDevices.getUserMedia
so readers know the rejection semantics.

In `@packages/mediastream/src/index.ts`:
- Around line 83-86: The getUserMedia/getDisplayMedia promises in
createStream/createScreen (navigator.mediaDevices.getUserMedia and
navigator.mediaDevices.getDisplayMedia) lack rejection handling, causing
unhandled rejections and leaving a stale stopped stream in state; update the
calls in the functions that use setStream/stopStream (refer to setStream,
stopStream and the active flag) to catch errors (either add .catch(...) or
convert to async/await with try/catch), and on rejection ensure any previously
created stream is cleared by calling setStream(null/undefined) (and stopStream
on any obtained stream) and log or surface the error so the promise rejection is
handled.
- Around line 159-173: stop() currently disconnects audio nodes but doesn't
cancel the requestAnimationFrame loop, so calling stop() leaves loop() running;
update stop to call cancelAnimationFrame(rafId) (guarded if rafId is set) before
disconnecting/closing and ensure onCleanup either just calls stop() (remove the
separate cancelAnimationFrame(rafId) onCleanup) or keep it idempotent—use the
rafId symbol and the loop/stop functions to implement this change.
- Around line 82-89: The stream state isn't cleared when stopping or while
awaiting re-acquisition, so callers can get a stale stopped MediaStream; update
stopStream to call setStream(undefined) after stopping tracks, and modify
createStream and createScreen to clear the current stream immediately before
calling navigator.mediaDevices.getUserMedia/getDisplayMedia (e.g., call
setStream(undefined) right before the async call) so stream() returns undefined
while re-acquiring and after stopStream runs.

In `@packages/mediastream/test/setup.ts`:
- Around line 14-16: The analyser mock's getByteFrequencyData uses
Math.random(), causing flaky tests; update the function (getByteFrequencyData in
the test setup) to write a deterministic non-zero pattern instead (e.g., use
array.fill(128) or a fixed repeating sequence) so amplitude tests are stable and
still exercise non-zero data; ensure you replace the spread/map approach with
array.fill or an indexed assignment to avoid creating intermediate arrays.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9b193b04-f2c1-4a17-a579-ce982c4e5547

📥 Commits

Reviewing files that changed from the base of the PR and between 76d6f2e and 1b05f75.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (10)
  • .changeset/mediastream-solid2-migration.md
  • packages/mediastream/CHANGELOG.md
  • packages/mediastream/README.md
  • packages/mediastream/dev/index.tsx
  • packages/mediastream/package.json
  • packages/mediastream/src/index.ts
  • packages/mediastream/test/index.test.ts
  • packages/mediastream/test/server.test.ts
  • packages/mediastream/test/setup.ts
  • packages/mediastream/tsconfig.json

Comment thread packages/mediastream/README.md Outdated
Comment thread packages/mediastream/src/index.ts
Comment thread packages/mediastream/src/index.ts
Comment thread packages/mediastream/src/index.ts
Comment thread packages/mediastream/test/setup.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant