gpt4 book ai didi

javascript - RTCPeerConnection.setRemoteDescription 参数不足

转载 作者:行者123 更新时间:2023-12-01 01:22:38 28 4
gpt4 key购买 nike

目前,Firefox 64 中出现以下错误,我一直在网上搜索有效的修复程序,但找不到该错误。

TypeError: "Not enough arguments to RTCPeerConnection.setRemoteDescription."

已使用一些链接进行修复,但无济于事,而且后者已过时。

https://developer.mozilla.org/en-US/docs/Web/API/RTCSessionDescription

WebRTC Firefox: Not enough arguments to RTCPeerConnection.setLocalDescription

Chrome 触发了另一个错误 main.js:58 Uncaught TypeError: Cannot read property 'type' of undefined这是当有一个 if 语句来检查 Remotedescription.type 是否与 Offer 匹配时

如果有人知道解决办法,我将不胜感激。

 'use strict';

var configuration = {
iceServers: [
{
urls: 'stun:stun.l.google.com:19302'
}
]
};
var pc = new RTCPeerConnection(configuration);

// Define action buttons.
const callButton = document.getElementById('callButton');
const hangupButton = document.getElementById('hangupButton');

/////////////////////////////////////////////

window.room = prompt('Enter room name:');

var socket = io.connect();

if (room !== '') {
console.log('Message from client: Asking to join room ' + room);
socket.emit('create or join', room);
}

socket.on('created', function(room) {
console.log('Created room ' + room);
startVideo();
});

socket.on('full', function(room) {
console.log('Message from client: Room ' + room + ' is full :^(');
});

socket.on('joined', function(room) {
console.log('joined: ' + room);
startVideo();
callButton.disabled = true;
});

socket.on('log', function(array) {
console.log.apply(console, array);
});

////////////////////////////////////////////////

async function sendMessage(message) {
console.log('Client sending message: ', message);
await socket.emit('message', message);
}

// This client receives a message
socket.on('message', async message => {
if (message.sdp) {
await pc
.setRemoteDescription(new RTCSessionDescription(message.sdp), () => {
if (pc.remotedescription.type === 'offer') {
pc.setLocalDescription(pc.createAnswer())
.then(function() {
sendMessage({ sdp: pc.localDescription });
})
.catch(function(err) {
console.log(err.name + ': ' + err.message);
});
} else {
pc.addIceCandidate(new RTCIceCandidate(message.candidate)).catch(
error => console.error(error)
);
}
})
.catch(error => console.error(error));
}
});

pc.onicecandidate = event => {
if (event.candidate) {
sendMessage({ candidate: event.candidate });
}
};

pc.ontrack = event => {
if (remoteVideo.srcObject !== event.streams[0]) {
remoteVideo.srcObject = event.streams[0];
console.log('Got remote stream');
}
};

////////////////////////////////////////////////////

const localVideo = document.querySelector('#localVideo');
const remoteVideo = document.querySelector('#remoteVideo');

// Set up initial action buttons status: disable call and hangup.
callButton.disabled = true;
hangupButton.disabled = true;

// Add click event handlers for buttons.
callButton.addEventListener('click', callStart);
hangupButton.addEventListener('click', hangupCall);

function startVideo() {
navigator.mediaDevices
.getUserMedia({
audio: true,
video: true
})
.then(function(stream) {
localVideo.srcObject = stream;
stream.getTracks().forEach(track => pc.addTrack(track, stream));
})
.catch(function(err) {
console.log('getUserMedia() error: ' + err.name);
});
callButton.disabled = false;
}

async function callStart() {
callButton.disabled = true;
hangupButton.disabled = false;

console.log('Sending offer to peer');
await pc
.setLocalDescription(await pc.createOffer())
.then(function() {
sendMessage(pc.localDescription);
})
.catch(err => {
console.log(err.name + ': ' + err.message);
});
}

/////////////////////////////////////////////////////////

function hangupCall() {
pc.close();
pc = null;
callButton.disabled = false;
hangupButton.disabled = true;
console.log('Call Ended');
}

最佳答案

您正在调用pc.setRemoteDescription(desc, callback)但不提供错误回调,使用 .catch反而。 Firefox 不喜欢在不提供错误回调的情况下使用回调,这会导致“参数不足”错误。

不要将已弃用的回调与 Promise 混合在一起,而是使用 pc.setRemoteDescription(desc).then(() => ...).catch(...)

关于javascript - RTCPeerConnection.setRemoteDescription 参数不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54097287/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com