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

请修复 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();
        }
    }

以上是Discord语音消息插件:不支持getUserMedia()的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>