0

刷新页面时,我在控制台上收到此错误.. 其他一切正常,聊天和一切.. 只是流媒体部分不起作用

NotSupportedError: MediaStreamError
    at module.exports (http://192.168.1.10:9966/index.js:3081:17)
    at Object.1.getusermedia (http://192.168.1.10:9966/index.js:4:1)
    at o (http://192.168.1.10:9966/index.js:1:265)
    at r (http://192.168.1.10:9966/index.js:1:431)
    at http://192.168.1.10:9966/index.js:1:460

在创建视频聊天应用程序时

这是我的 index.js

var getUserMedia = require('getusermedia')

getUserMedia({video: true, audio: false}, function (err, stream) {
    var Peer = require('simple-peer')
    var peer = new Peer({
        initiator: location.hash === '#init',
        trickle: false,
        stream: stream
    })

    peer.on('signal', function (data) {
        document.getElementById('yourId').value = JSON.stringify(data)
    })

    document.getElementById('connect').addEventListener('click', function () {
        var otherId = JSON.parse(document.getElementById('otherId').value)
        peer.signal(otherId)
    })

    document.getElementById('send').addEventListener('click', function () {
        var yourMessage = document.getElementById('yourMessage').value
        peer.send(yourMessage)
    })

    peer.on('data', function (data) {
        document.getElementById('messages').textContent += data + '\n'
    })

    peer.on('stream', function (stream) {
        var video = document.createElement('video')
        document.body.appendChild(video)

        video.src = window.URL.createObjectURL(stream)
        video.play()
    })
})

这是我的 index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>CHatting Video</title>
</head>
<body>

<label>Your ID:</label><br/>
<textarea id="yourId"></textarea><br/>
<label>Other ID:</label><br/>
<textarea id="otherId"></textarea>
<button id="connect">connect</button>
<br/>

<label>Enter Message:</label><br/>
<textarea id="yourMessage"></textarea>
<button id="send">send</button>
<pre id="messages"></pre>

<script src="index.js" charset="utf-8"></script>
</body>
</html>

当我向其他浏览器发送消息时它工作正常,但对于视频聊天它不起作用关于如何解决这个问题的任何想法.????

4

1 回答 1

0

我得到了错误..我正在使用getUserMedia而不是navigator.getUserMedia

getUserMedia 已被弃用。

于 2020-08-29T14:49:08.983 回答