WebRTC: What is the audio / video feature enabled / true for DataChannel only?

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}]; // Whether we gather IPv6 candidates.

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?

+4
1

- . - . .

IP + , . . , / .

, "m-" SDP.

var pc = new RTCPeerConnection();

pc.createDataChannel("dummy");
pc.createOffer().then(({sdp}) =>
   sdp.split('\r\n').filter(s => s.startsWith('m=')).map(s => console.log(s)));
<script src="https://webrtc.imtqy.com/adapter/adapter-latest.js"></script>
Hide result

( , ) , , .

, , , , , .

, , . . , , .

+2

Source: https://habr.com/ru/post/1667191/


All Articles