Skip to content
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

fix: the mic is selected as default and video is used deviceId anywhere #981

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 5 additions & 30 deletions src/widget/tabs/camera-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,6 @@ class CameraTab {
}

__checkCompatibility() {
if (navigator.mediaDevices?.getSupportedConstraints) {
const supportedConstraints =
navigator.mediaDevices.getSupportedConstraints()
const { groupId: isGroupIdConstraintSupported } = supportedConstraints

/**
* In Safari v17.6 (probably earlier versions too) groupId constraint is not supported for some unknown reason.
* So we're getting "OverconstrainedError" when trying to use it.
* In this case we should force use deviceId constraint instead of groupId.
*/
this.__mediaIdProperty = isGroupIdConstraintSupported
? 'groupId'
: 'deviceId'
}
if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices) {
this.enumerateVideoDevices = () =>
navigator.mediaDevices.enumerateDevices().then((mediaDevices) => {
Expand Down Expand Up @@ -233,7 +219,7 @@ class CameraTab {
})
.then((devices) => {
// select first device, it should be default one in browser/os
this.__mediaId = devices?.[0]?.[this.__mediaIdProperty]
this.__mediaId = devices?.[0]?.deviceId
this.__renderDevicesList(devices)
})
.then(() => this.__requestCamera())
Expand Down Expand Up @@ -266,20 +252,9 @@ class CameraTab {
}

if (this.__mediaId) {
constraints.video[this.__mediaIdProperty] = {
constraints.video.deviceId = {
exact: this.__mediaId
}
/**
* In case when the deviceId constraint is used, we can't request browser to use the same camera for audio and video.
* So we leave it on the browser to decide which audio device to use.
*/
if (this.__mediaIdProperty === 'groupId') {
constraints.audio = constraints.audio && {
[this.__mediaIdProperty]: {
exact: this.__mediaId
}
}
}
}

return this.getUserMedia
Expand Down Expand Up @@ -478,11 +453,11 @@ class CameraTab {
deviceSelect.empty()
devices.forEach((device, idx) => {
const selected = this.__mediaId
? device[this.__mediaIdProperty] === this.__mediaId
? device.deviceId === this.__mediaId
: idx === 0
deviceSelect.append(
$('<option>', {
value: device[this.__mediaIdProperty],
value: device.deviceId,
// Browsers could return empty labels in some cases, so fallback it to the camera index
text:
device.label ||
Expand All @@ -504,7 +479,7 @@ class CameraTab {
}
const firstTrack = videoTracks[0]
const trackSettings = firstTrack.getSettings()
return trackSettings[this.__mediaIdProperty]
return trackSettings.deviceId
}

__guessExtensionByMime(mime) {
Expand Down
Loading