首页 > 解决方案 > WebRTC RTCDataChannel readyState 什么时候打开?

问题描述

我在 WebRTC 中创建了一个简单的原型,它使用 Google 提供的测试 STUN 服务器:

var servers = [
   "stun:stun.l.google.com:19302",
   ...
];

我运行了两个独立的应用程序(没有本地服务器 - 即 NodeJS)。
我只是通过网络浏览器直接打开了文件。

它成功地创建了一个RTCPeerConnectionRTCDataChannel对象。

但是,onopen处理程序RTCDataChannel从未被触发。数据通道始终处于“连接”状态
readyState

示例代码:

  window.localConnection = localConnection =
      new RTCPeerConnection(configuration); // configuration.iceServer

  localChannel = localConnection.createDataChannel('data');
  localChannel.onopen = function () { // never triggered
     var readyState = localChannel.readyState;
     console.log('Local channel state is: ' + readyState);
  }

问题:

1. 我需要一个服务器(如 NodeJS)来readyState设置“打开”吗?
2. 什么时候readyState转换到“开放”状态?

标签: javascriptwebrtcpeer

解决方案


推荐阅读