我正在尝试为 WebRTC 应用程序设置对等连接。我已经阅读了论坛和讨论组,这些论坛和讨论组让我明白,同样需要 STUN/TURN 服务器。以下是详细信息:
- 我从https://code.google.com/p/rfc5766-turn-server/下载了 STUN/TURN 服务器的开源实现
- 在我的本地 Mac OS X 机器上安装服务器并在 localhost:3478 上打开服务器
- 当我使用客户端脚本测试服务器时,我能够从服务器取回远程地址。
- 但是,当我在创建对等连接时尝试从我的 JavaScript 代码访问服务器时,它并没有访问服务器本身。
下面是我正在使用的代码:
function createPeerConnection() {
var pc_config = {'iceServers': [{'url':'turn:127.0.0.1:3478', 'credential':'Apple123'}]};
try {
// Create an RTCPeerConnection via the polyfill (adapter.js).
pc = new webkitRTCPeerConnection(pc_config);
pc.onicecandidate = gotLocalCandidate;
trace("Created RTCPeerConnnection with config:\n" + " \"" +JSON.stringify(pc_config) + "\".");
} catch (e) {
trace("Failed to create PeerConnection, exception: " + e.message);
alert("Cannot create RTCPeerConnection object; WebRTC is not supported by this browser.");
return;
}
pc.onconnecting = onSessionConnecting;
pc.onopen = onSessionOpened;
pc.onaddstream = onRemoteStreamAdded;
pc.onremovestream = onRemoteStreamRemoved;
}
感谢在这件事上的任何指导,因为我完全被困在这一点上。还有一个问题:如何为内部网络上同时存在对等点 A 和 B 的 WebRTC 应用程序设置点对点连接?那么是否需要 STUN/TURN 服务器?