You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was creating a plugin to set the preferred audio out device, but will like to detect connect and disconnect of devices, but using navigator.mediaDevices.ondevicechange is not working.
My code ./plugins/pref-audio-out-device/front.js
module.exports = () => {
document.addEventListener('apiLoaded', apiEvent => {
changeToPrefAudioOutDevice();
navigator.mediaDevices.ondevicechange = (e) => {
changeToPrefAudioOutDevice();
};
}, { once: true, passive: true })
};
function changeToPrefAudioOutDevice() {
const prefAudioOutDeviceId = '74b147ea818349756def2d6dae3a5422f8be7f0ef7b91749f61cfbe7a83730fe'; //TODO load from plugin options
navigator.mediaDevices.enumerateDevices().then((devices) => {
devices.forEach((device) => {
console.log(`${device.kind}: ${device.label} id = ${device.deviceId}`);
if (device.kind === 'audiooutput' && // device type is audio output
device.deviceId === prefAudioOutDeviceId && // preferred audio out device is connected
document.querySelector('.video-stream,.html5-main-video').SinkId !== prefAudioOutDeviceId) { // preferred audio out device is not already set
document.querySelector('.video-stream,.html5-main-video').setSinkId(device.deviceId); // set preferred audio out device
}
});
}).catch((err) => {
console.error(`${err.name}: ${err.message}`);
});
}
This discussion was converted from issue #804 on October 07, 2023 07:46.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I was creating a plugin to set the preferred audio out device, but will like to detect connect and disconnect of devices, but using navigator.mediaDevices.ondevicechange is not working.
My code ./plugins/pref-audio-out-device/front.js
(newbie here, limited knowledge of javascript)
Beta Was this translation helpful? Give feedback.
All reactions