我正试图跟随这个例子来创建DataChannel。
对于信令,我使用websockets,它的行为如下所示:
User A joins
User B joins
User B asks User A to create an offer
-> A opens datachannel before creating an offer
-> A sets his local description
User A sends his offer to User B
-> B answers the offer
-> B sets local and remote description
User B sends A his local description(用户B不直接向用户A发送消息,这是通过websocket与中间服务器一起完成的,中间服务器持有websocket会话,为了简单起见跳过了该部分)
为用户A创建的提供代码如下:
let pc = new RTCPeerConnection({
iceServers: [
{
urls: "stun:stun.l.google.com:19302",
}
]
});
let dc = pc.createDataChannel("Base");
dc.onbufferedamountlow = function(){
console.error("dataChannel.onbufferedamountlow");
};
dc.onclose = function(){
console.error("dataChannel.onclose");
};
dc.onerror = function(){
console.error("dataChannel.onerror");
};
dc.onmessage = function(){
console.error("dataChannel.onmessage");
};
dc.onopen = function(){
console.error("dataChannel.onopen");
};
let offer = await pc.createOffer();
await pc.setLocalDescription(offer);
let offerString = JSON.stringify(pc.localDescription); //Is sent to B用户B的完整代码如下:
let pc = new RTCPeerConnection({
iceServers: [
{
urls: "stun:stun.l.google.com:19302",
}
]
});
await pc.setRemoteDescription(new RTCSessionDescription(offer)); //From A
let answer = await pc.createAnswer();
await pc.setLocalDescription(answer);
let answerString = JSON.stringify(pc.localDescription); //Returns to A所以当A收到B的回答时,它只是:
await pc.setRemoteDescription(new RTCSessionDescription(answer));A的目的:

B的目的:

我也尝试过但没有成功:
在两个用户都建立了连接之后,-opening数据通道,没有任何事件会被触发,一些更新如下:

-opening数据通道在B上,当A仍在等待B的响应返回时,数据通道on关闭事件被触发,甚至不触发打开的事件.
-using https://test.webrtc.org/进行测试,这是结果:

-我也一直在寻找其他的问题或类似于我的,论坛,博客等.从2岁到5岁的所有答案似乎都过时了,而且不管用.
-creating海峡两边的情况如下:
pc.createDataChannel("Test", {
id: 1,
negotiated: true,
})在其中一个客户端指向OperationError: Id is in use。如何通过通道的ID 如果DOC声明加入通道:
或者(真),他们可以谈判出-带,其中双方调用createDataChannel与一个商定的id.
如果我必须通过ID连接一个通道,但是在创建对象时我得到了正在使用的Id,我如何加入它?
如果我没有指定一个id,我就得到TypeError: id is required when negotiated is true
医生说:
ID:可选-通道的16位数字ID;允许值为0-65534.如果不包括此选项,用户代理将为您选择一个ID。
await pc.addIceCandidate();或await pc.addIceCandidate(null);。iceServer中使用眩晕和旋转服务器。问题:
1)数据通道何时开始开放?在两个客户都完成了重组之后,pc.connectionState是稳定的吗?在创建连接对象之后?在设置本地描述之前还是之后?
发布于 2020-04-11 11:30:06
问题是您需要在信号上交换冰信息(而不仅仅是SDP信息)。
冰是告诉远程同行知道如何连接,SDP就像是我能提供的内容。
https://stackoverflow.com/questions/61107353
复制相似问题