function negotiate() {
return pc.createOffer().then(function(offer) {
return pc.setLocalDescription(offer);
}).then(function() {
// wait for ICE gathering to complete
return new Promise(function(resolve) {
if (pc.iceGatheringState === 'complete') {
resolve();
} else {
function checkState() {
if (pc.iceGatheringState === 'complete') {
pc.removeEventListener('icegatheringstatechange', checkState);
resolve();
}
}
pc.addEventListener('icegatheringstatechange', checkState);
}
});
}).then(function() {
var offer = pc.localDescription;
return fetch('/offer', {
body: JSON.stringify({
sdp: offer.sdp,
type: offer.type,
// video_transform: document.getElementById('video-transform').value
video_transform: "makeup_v2"
}),
headers: {
'Content-Type': 'application/json'
},
method: 'POST'
});
}).then(function(response) {
return response.json();
}).then(function(answer) {
return pc.setRemoteDescription(answer);
}).catch(function(e) {
alert(e);
});
}
这是我的 javascript 代码。它试图从前端收集信息并通过 api 向后端发送帧 为视频增色。
之前需要 2 秒来扩充,但现在下面的一段代码需要 30 秒才能完成,然后 api 调用正在发生。
function checkState() {
if (pc.iceGatheringState === 'complete') {
pc.removeEventListener('icegatheringstatechange', checkState);
resolve();
}
}
pc.addEventListener('icegatheringstatechange', checkState);
我通过登录 pc.iceGatheringState 检查它正在收集,30 秒后显示完成。 可能是什么原因?
同样的代码过去 3 秒,现在是 30 秒
请看