I am trying to understand how WebRTC works, mainly for using only the DataChannel for the gaming network. And this is what I have done so far. He collects ICE footage. I have two questions.
- Should I offer to collect ICE?
- Why
offerToReceiveAudioor offerToReceiveVideoshould be set to true, I use only Datachannel. (without one of these options being set to true, ICE does not appear) (resolved, see EDIT below)
Here comes the fiddle:
https://jsfiddle.net/t431a815/9/
and code:
var iceServers = [
]
var config = {
iceServers: iceServers,
iceTransportPolicy: "all",
rtcpMuxPolicy: 'negotiate'
};
var pcConstraints = {};
var offerOptions = {offerToReceiveAudio: true};
pcConstraints.optional = [{'googIPv6': true}];
var pc = new RTCPeerConnection(config, pcConstraints);
pc.onicecandidate = iceCallback;
pc.createOffer(
offerOptions
).then(
gotDescription,
error
);
function gotDescription(desc) {
console.log("OFFER DESC:", desc);
pc.setLocalDescription(desc);
}
function error() {
console.log("sth goes wrong", arguments);
}
function iceCallback(event) {
console.log("ICE!", JSON.stringify(event.candidate));
}
EDIT:
found a solution, but this is strange, you just need to create one datachannel before the sentence, then it works with offerToReceiveAudio: false, offerToReceiveVideo: false
var offererDataChannel = pc.createDataChannel('channel', {});
but why? What if I want to create it later?