-
Notifications
You must be signed in to change notification settings - Fork 136
Save the preferred device when the user is prompted? #565
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
Conversation
If we request an undefined device with no permission, browsers will prompt the user. We want to save their selection as the device we should use when available.
WalkthroughIntroduces early-exit permission checks and error swallowing in device permission flow, captures and stores deviceId after media acquisition, and adjusts microphone deviceId constraint handling to treat empty strings as valid and persist user-chosen device when none was explicitly requested. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Device as Device.requestPermission()
participant Browser as navigator.mediaDevices
Note over Device: Early exit if permission already granted
User->>Device: requestPermission()
alt permission already granted
Device-->>User: return (no-op)
else
Device->>Browser: getUserMedia(constraints)
alt success
Browser-->>Device: MediaStream
Note right of Device: Read first track settings.deviceId<br/>Update preferred if present
Device-->>User: resolved
else error
Browser-->>Device: Error
Note right of Device: catch(() => undefined)
Device-->>User: resolved (undefined)
end
end
sequenceDiagram
autonumber
actor User
participant Mic as Microphone.acquire()
participant Device as Device (preferred)
participant Browser as navigator.mediaDevices
Mic->>Mic: Build constraints
Note over Mic: deviceId constraint set if device !== undefined<br/>(empty string allowed)
Mic->>Browser: getUserMedia(constraints)
Browser-->>Mic: MediaStream with track
Mic->>Mic: Read track.settings.deviceId
alt device was undefined in request
Note right of Mic: Persist settings.deviceId to Device.preferred
else
Note right of Mic: Do not overwrite preferred
end
Mic-->>User: Stream/track
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
js/hang/src/publish/source/device.ts (2)
126-127: Early-exit may skip legitimate refresh flows; consider making this awaitable.If site permission was changed externally (browser settings) while
permissionstayed true, this early return prevents re-checking. Also, returning a Promise lets callers await completion if they do want to prompt. Optional tweak below keeps behavior but is awaitable and logs denials.- requestPermission() { - if (this.permission.peek()) return; + requestPermission(): Promise<void> { + if (this.permission.peek()) return Promise.resolve();And consider:
- .catch(() => undefined); + .catch((err) => { + console.debug(`getUserMedia(${this.kind}) denied or failed`, err); + });
133-137: Persisting the user-chosen deviceId is the right move; pick the track by kind to be explicit.- const deviceId = stream.getTracks().at(0)?.getSettings().deviceId; + const track = + this.kind === "audio" ? stream.getAudioTracks().at(0) : stream.getVideoTracks().at(0); + const deviceId = track?.getSettings().deviceId;js/hang/src/publish/source/microphone.ts (2)
39-40: Guard against empty-string deviceId;exact: ""can cause OverconstrainedError.An empty string is not a valid concrete deviceId in constraints. Recommend reverting to truthy (or explicit non-empty) check.
- deviceId: device !== undefined ? { exact: device } : undefined, + // Ignore empty-string sentinel values + deviceId: device && device !== "" ? { exact: device } : undefined,
65-68: Persist only when a real deviceId exists and it differs to avoid redundant emits/reacquire.- if (device === undefined) { - // Save the device that the user selected during the dialog prompt. - this.device.preferred.set(settings.deviceId); - } + if ( + device === undefined && + settings.deviceId && + this.device.preferred.peek() !== settings.deviceId + ) { + // Save the device the user selected during the dialog prompt. + this.device.preferred.set(settings.deviceId); + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
js/hang/src/publish/source/device.ts(1 hunks)js/hang/src/publish/source/microphone.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
{rs,js}/hang/**
📄 CodeRabbit inference engine (CLAUDE.md)
All media logic belongs in the hang layer (rs/hang and js/hang)
Files:
js/hang/src/publish/source/microphone.tsjs/hang/src/publish/source/device.ts
js/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place JS/TS packages under the js/ directory
Files:
js/hang/src/publish/source/microphone.tsjs/hang/src/publish/source/device.ts
🧬 Code graph analysis (1)
js/hang/src/publish/source/microphone.ts (1)
js/hang/src/publish/element.ts (2)
device(108-110)device(112-114)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Check
If we request an undefined device with no permission, browsers will prompt the user. We want to save their selection as the device we should use when available.
Summary by CodeRabbit
New Features
Bug Fixes