Nur*_*ril 6 javascript plugins discord discord.js
请修复 Discord 语音消息插件中的错误。
错误:无法启动 MediaRecorder:无法在“MediaDevices”上执行“getUserMedia”:不支持 getUserMedia。
原文:https : //github.com/MKSx/Send-Audio-Plugin-BetterDiscord 第 1026 行错误。
有问题的代码:
changeMedia(device=false, changing=false){
const plugin = this;
const change = () => {
plugin.media = null;
plugin.mediaInfo.ready = false;
plugin.mediaInfo.error = false;
navigator.mediaDevices.getUserMedia({audio: (device != false ? device : plugin.settings.devices)}).then(s => {
plugin.media = new MediaRecorder(s);
Logger.log("MediaRecorder started successfully");
plugin.media.addEventListener('dataavailable', e => plugin.onRecordingData(e.data));
plugin.media.addEventListener('start', _ => plugin.onRecordingStateChange(0));
plugin.media.addEventListener('stop', _ => plugin.onRecordingStateChange(1));
plugin.media.addEventListener('pause', _ => plugin.onRecordingStateChange(2));
plugin.media.addEventListener('resume', _ => plugin.onRecordingStateChange(3));
plugin.media.addEventListener('error', error => {
Logger.error('Recording error:', error);
});
plugin.mediaInfo.ready = true;
plugin.mediaInfo.error = false;
if(typeof plugin.buttons == 'object' && plugin.buttons.record instanceof Element)
plugin.buttons.record.disabled = false;
}).catch(err => {
plugin.mediaInfo.ready = false;
plugin.mediaInfo.error = true;
if(typeof plugin.buttons == 'object' &&plugin.buttons.record instanceof Element)
plugin.buttons.record.disabled = true;
Logger.error("Failed to start MediaRecorder:", err.message);
if(!changing){
Logger.log("Changing to the default");
plugin.changeMedia('default', true);
}
});
};
if(this.media instanceof MediaRecorder){
this.mediaInfo.notSave = true;
if(this.media.state != 'inactive')
this.media.stop().then(_ => change()).catch(_ => change());
}
else{
change();
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,Better Discord 本质上是一个在 Chrome 浏览器之类的应用程序中运行的应用程序。您可以通过点击CTRL+ SHIFT+来验证这一点I。
该问题看起来像是 Chrome 中与访问麦克风相关的安全问题。我也会在接下来的几天里看看,但以下解决方案可能适合您:
我发现您可以通过以下链接向不和谐应用程序添加标志: https: //www.reddit.com/r/discordapp/comments/91btrn/adding_electron_flags_to_discord_startup/
有潜在命令行开关的完整列表@ https://peter.sh/experiments/chromium-command-line-switches/。
您可能需要在参数后设置正确的 URL/域,例如
Discord.exe --unsafely-treat-insecure-origin-as-secure=
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
563 次 |
| 最近记录: |