我正在尝试使p2p应用程序在浏览器中提供音频聊天。我正在使用peerjs。我已经托管了自己的peerjs-server,并且我的应用程序托管于HTTPS协议。问题是打电话时我连接成功,但是没有声音,我什么也听不见。这是我的代码:
要调用的函数:
private makeCall() {
let self = this;
var options = {
'constraints': {
'mandatory': {
'OfferToReceiveAudio': true,
'OfferToReceiveVideo': true
}
}
}
navigator.getUserMedia({audio: true, video: true}, function(stream){
var call = self.peer.call(self.idToConnect, stream, options);
call.on('stream', function(stream) {
console.log('STREAM');
console.log(stream);
})
},
err => console.log(err));
}
这是我接听电话的方式:
this.peer.on('call', function(call) {
navigator.getUserMedia({
audio: true,
video: true
}, function(stream) {
call.answer(stream);
call.on('stream', function(stream) {
console.log('RESPONED CALL');
console.log(stream)
});
}, function(error) {
//...
});
});
我错过了什么吗?