0

我正在开发一个基于 node.js 和 Kurento 的 WebRTC 应用程序,我想使用数据通道实现聊天。

我已经看过浏览器的 javascript 版本,我想将它集成到一对一的 node.js 示例中。

我做了什么

1.- 我创建了两个具有数据通道功能的 WebRTCEndpoints,如下所示:pipeline.create('WebRtcEndpoint', {useDataChannels: true}, function(error, calleeWebRtcEndpoint) {...}
2.- 然后我创建了<textarea>一个<button>用于发送消息和一个<div>用于查看消息的。

所以我的问题是,当我在客户端创建数据通道时,我必须放置哪些服务器? 此片段来自浏览器 javascript 数据通道教程,但在文件开头我们可以清楚地看到 ICE 服务器在连接创建中忽略。另外,我不知道您如何在 node.js 教程中管理它们,所以我在这里有点迷失。

peerConnection = new RTCPeerConnection(servers, configuration);

channel = peerConnection.createDataChannel(getChannelName(), dataConstraints);

channel.onopen = onSendChannelStateChange;
channel.onclose = onSendChannelStateChange;
channel.onmessage = onMessage;`

谢谢您的帮助。

4

1 回答 1

0

我发现我做错了什么,现在我可以通过数据通道发送消息。

基本上我所做的是向peerConnection选项对象添加选项。接下来,该选项对象被传递给WebRtcPeerSendrecv连接方法,它就完成了!

var options = {
    peerConnection: peerConnection, //Must be passed as a field in options to make DataChannels work
    localVideo : videoInput,
    remoteVideo : videoOutput,
    onicecandidate : onIceCandidate
}

webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerSendrecv(options, function(){...});
于 2016-05-11T15:29:34.323 回答