pier92
pier92

Reputation: 397

Parsing SDP in WebRTC

i have an html+javascript code that simulates a webrtc videocall between me and myself (i act as first and second peer).

I'd like identifying and showing to console only a=fingerprint SDP attribute. In javascript, i can i do this? I can do that after peerconnection.createOffer() return offer.

Upvotes: 2

Views: 2999

Answers (2)

Shahid Ali
Shahid Ali

Reputation: 87

SDP (Session Description Protocol) needs to be separated for visualizing. You can parse the SDP here https://wrtc.dev/sdp-transform/index.html

Upvotes: 0

Philipp Hancke
Philipp Hancke

Reputation: 17340

SDP is a line oriented format so you'd split it into lines, then search for the one starting with 'a=fingerprint:' and then split that up into its components (which are the hash algorithm and the fingerprint itself). Like this (requires Chrome 56+ or Firefox):

var pc = new RTCPeerConnection();
pc.createOffer({offerToReceiveAudio: 1})
.then(function (offer) {
  let lines = offer.sdp.split('\n')
      .map(l => l.trim()); // split and remove trailing CR
  lines.forEach(function(line) {
    if (line.indexOf('a=fingerprint:') === 0) {     
      let parts = line.substr(14).split(' ');
      console.log('algorithm', parts[0]);
      console.log('fingerprint', parts[1]);
    }
  })
})

Upvotes: 4

Related Questions