Discord 语音消息插件:不支持 getUserMedia()

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)

Men*_*los 3

介绍

基本上,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)

  • @Nuril 我正在考虑直接在 chrome 浏览器中尝试这个插件作为扩展。但我没有时间,我想我必须重写其中的一部分。我更怀疑谷歌浏览器增加了安全限制,因此脚本无法开始记录你。不和谐插件似乎也存在安全问题,这也可能是他们加强安全性的一个原因。例如 https://www.pocket-lint.com/apps/news/152340-discord-malware-is-stealing-users-passwords (2认同)