PeerJS:iceConnectionState 已断开连接,关闭与 [userid] 的连接
PeerJS: iceConnectionState is disconnected, closing connections to [userid]
我为我的应用程序 [语音和视频聊天应用程序] 使用了 PeerJS 并且一切正常,连接到对等点,视频和语音通话工作正常,而开发和测试是在同一个网络上完成的,直到我在线托管了该应用程序。它停止连接到对等点并继续报告
PeerJS:iceConnectionState 已断开连接,正在关闭与 [userid] 的连接
和
错误:与 [userid] 的连接协商失败。
在 RTCPeerConnection.pc.oniceconnectionstatechange [as onicechange]。
有解决这个问题的想法吗?
我找到了解决问题的方法。
我不得不从 Twilio 购买 ICE 和 TURN 服务器来修复它。这为我提供了可靠的连接和更快的消息传递。
你可以试试。
找到这个答案并同意 Aminu 的观点。我发现 Twilio 的 TURN 服务器是一个很好的解决方案。我想我会提供更多细节以防它对任何人有帮助。
我已经有一个 Twilio 帐户,所以它变得格外简单。
我做了一个 PHP 函数来给我一些 Ice 服务器。像这样...
define("TWILIO_ACC_ID","AC12345etc...");
define("TWILIO_AUTH_TOKEN","8675309");
require_once '/path/to/my/Twilio/autoload.php';
use Twilio\Rest\Client;
function twilio_iceServers() {
$twilio=new Client(TWILIO_ACC_ID,TWILIO_AUTH_TOKEN);
$token = $twilio->tokens->create();
return json_encode($token->iceServers);
}
然后对于我的javascript,我像这样加载我的 ice 服务器:
var twilio_iceServers=<?php print(twilio_iceServers()); ?>;
然后像这样在我的 peerJS 配置中包含这些 ice 服务器:
var peer_options={
key:'myKey',
host:'my.host.com',
port: 443,
secure: true,
config: {iceServers:twilio_iceServers}
};
这些 Ice Server 似乎将在大约一天后过期。由于使用我的应用程序,人们可能会一次打开 window 数天,因此我必须构建一种方法来更新这些服务器。
//returns current time stamp in seconds
function now() {
return Math.floor(Date.now() / 1000);
}
//some variable that keeps track of whether I'm on a call or not
var call_status=null;
//save the current time stamp into the ice servers object on page load
twilio_iceServers.date=now();
//do a check every 60 seconds to see if the ice servers have expired. yes... not 12 hours
setInterval(function(){
//if ice server issued date is more than 12 hours ago AND we're not on a call. we renew the ice servers. If we are on a call, this will run about a minute after we get off the call. This is why the setInterval is set to be 1 minute instead of 12 hours.
if (twilio_iceServers.date<(now()-43200) && !call_status) {
$.post("/page/on/my/server/that/just/sends/back/twilio_iceServers",{},function(data) {
if (data) {
//save the new ice servers
twilio_iceServers=JSON.parse(data);
//save the new date of the server
twilio_iceServers.date=now();
}
});
}
},60000);
这是做这一切的真正方法吗?我不知道!但这对我有用。原来如此。
我为我的应用程序 [语音和视频聊天应用程序] 使用了 PeerJS 并且一切正常,连接到对等点,视频和语音通话工作正常,而开发和测试是在同一个网络上完成的,直到我在线托管了该应用程序。它停止连接到对等点并继续报告
PeerJS:iceConnectionState 已断开连接,正在关闭与 [userid] 的连接
和
错误:与 [userid] 的连接协商失败。 在 RTCPeerConnection.pc.oniceconnectionstatechange [as onicechange]。
有解决这个问题的想法吗?
我找到了解决问题的方法。
我不得不从 Twilio 购买 ICE 和 TURN 服务器来修复它。这为我提供了可靠的连接和更快的消息传递。
你可以试试。
找到这个答案并同意 Aminu 的观点。我发现 Twilio 的 TURN 服务器是一个很好的解决方案。我想我会提供更多细节以防它对任何人有帮助。
我已经有一个 Twilio 帐户,所以它变得格外简单。
我做了一个 PHP 函数来给我一些 Ice 服务器。像这样...
define("TWILIO_ACC_ID","AC12345etc...");
define("TWILIO_AUTH_TOKEN","8675309");
require_once '/path/to/my/Twilio/autoload.php';
use Twilio\Rest\Client;
function twilio_iceServers() {
$twilio=new Client(TWILIO_ACC_ID,TWILIO_AUTH_TOKEN);
$token = $twilio->tokens->create();
return json_encode($token->iceServers);
}
然后对于我的javascript,我像这样加载我的 ice 服务器:
var twilio_iceServers=<?php print(twilio_iceServers()); ?>;
然后像这样在我的 peerJS 配置中包含这些 ice 服务器:
var peer_options={
key:'myKey',
host:'my.host.com',
port: 443,
secure: true,
config: {iceServers:twilio_iceServers}
};
这些 Ice Server 似乎将在大约一天后过期。由于使用我的应用程序,人们可能会一次打开 window 数天,因此我必须构建一种方法来更新这些服务器。
//returns current time stamp in seconds
function now() {
return Math.floor(Date.now() / 1000);
}
//some variable that keeps track of whether I'm on a call or not
var call_status=null;
//save the current time stamp into the ice servers object on page load
twilio_iceServers.date=now();
//do a check every 60 seconds to see if the ice servers have expired. yes... not 12 hours
setInterval(function(){
//if ice server issued date is more than 12 hours ago AND we're not on a call. we renew the ice servers. If we are on a call, this will run about a minute after we get off the call. This is why the setInterval is set to be 1 minute instead of 12 hours.
if (twilio_iceServers.date<(now()-43200) && !call_status) {
$.post("/page/on/my/server/that/just/sends/back/twilio_iceServers",{},function(data) {
if (data) {
//save the new ice servers
twilio_iceServers=JSON.parse(data);
//save the new date of the server
twilio_iceServers.date=now();
}
});
}
},60000);
这是做这一切的真正方法吗?我不知道!但这对我有用。原来如此。