-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Feat: Record Plugin - Choose Mic #3256
Conversation
src/plugins/record.ts
Outdated
// Request access to the microphone before enumerating devices, otherwise | ||
// the browser will not return any device IDs | ||
let stream: MediaStream | ||
try { | ||
stream = await navigator.mediaDevices.getUserMedia({ | ||
audio: true, | ||
}) | ||
} catch (err) { | ||
throw new Error('Error getting audio devices: ' + (err as Error).message) | ||
} | ||
this.stream = stream | ||
this.stopMic() |
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.
Looks good overall, thank you!
These lines are almost the same as in startMic
, should we just call it here? Or maybe throw an error like Please start the microphone first
.
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.
Possibly. I was concerned about how these lines from startMic
would affect it? It doesn't need to render the stream when calling the function. What do you think?
const onDestroy = this.renderMicStream(stream)
this.subscriptions.push(this.once('destroy', onDestroy))
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.
I could also use this: https://developer.mozilla.org/en-US/docs/Web/API/Permissions/query
Then if no permission - call startMic
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.
Sorry for all the suggestions here. It would be nice if this was actually a static function and didn't touch the main class properties. It would keep similar code here but just use the local variable and use similar code to stopMic
to ensure the steam gets deallocated.
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.
Landed on removing starting a stream and just adding better docs.
The permissions api I shared doesn't support a microphone query in Firefox 🤷🏻♂️
@katspaugh updated. Let me know your thoughts 🙏🏻 |
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.
Thanks!
@katspaugh @tscritch I'm getting an error when trying to use P.S. Thanks for implementing this super useful feature! |
const micSelect = document.querySelector('#mic-select') | ||
{ | ||
// Mic selection | ||
record.getAvailableAudioDevices().then((devices) => { |
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.
I think this needs to be RecordPlugin
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.
Good catch! Could you make a PR?
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.
On it!
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.
Short description
Resolves #3245
Open to feedback!
Implementation details
startMic
andstartRecording
to use a specific mic (via deviceId)getAvailableAudioDevices
How to test it
In Chrome, you can reset the "Allow Mic" permissions by going to Settings > Privacy and Security > Site settings > Microphone > Click trash icon on
wavesurfer.xyz
orlocalhost:9090
.Screenshots
Checklist