无法通过 https 读取未定义的 属性 'getusermedia'

cannot read property 'getusermedia' of undefined over https

我有一个 React 应用程序,它应该从麦克风录制音频并将其发送到后端。 麦克风输入是用navigator.mediaDevices.getUserMedia实现的。该页面在本地主机和我的 wifi 网络中的其他设备上完美运行(为此,我必须使用 https 启动我的 React 应用程序)。 但是当我用这个网站测试它时:http://appsimulator.net/webapp/?frame=apple_iphone_6_v,我得到以下错误:TypeError: Cannot read 属性 'getUserMedia' of undefined。 我不知道为什么无法通过该站点测试该应用程序。

直接在MDN documentation for MediaDevices.getUserMedia()中回答:

Note: If the current document isn't loaded securely, navigator.mediaDevices will be undefined, and you cannot use getUserMedia(). See Security for more information on this and other security issues related to using getUserMedia().

AppSimulator.net 未安全呈现,因此此调用将始终以您观察到的方式失败。通过 HTTPS 提供页面。