(function(b){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=b()}else{if(typeof define==="function"&&define.amd){define([],b)}else{var a;if(typeof window!=="undefined"){a=window}else{if(typeof global!=="undefined"){a=global}else{if(typeof self!=="undefined"){a=self}else{a=this}}}a.SdpInterop=b()}}})(function(){var d,b,a;return(function c(f,k,h){function g(q,n){if(!k[q]){if(!f[q]){var m=typeof require=="function"&&require;if(!n&&m){return m(q,!0)}if(e){return e(q,!0)}var p=new Error("Cannot find module '"+q+"'");throw p.code="MODULE_NOT_FOUND",p}var i=k[q]={exports:{}};f[q][0].call(i.exports,function(l){var o=f[q][1][l];return g(o?o:l)},i,i.exports,c,f,k,h)}return k[q].exports}var e=typeof require=="function"&&require;for(var j=0;j=n){return s}var r=p[q];q+=1;switch(s){case"%%":return"%";case"%s":return String(r);case"%d":return Number(r);case"%v":return""}})};var l=function(r,s,o){var t=s.format instanceof Function?(s.format(s.push?o:o[s.name])):s.format;var p=[r+"="+t];if(s.names){for(var q=0;q3||!r.media.every(function(v){return["video","audio","data"].indexOf(v.mid)!==-1})){console.warn("This description does not look like Plan B.");return p}var q=[];r.media.forEach(function(v){q.push(v.mid)});var k=false;if(typeof r.groups!=="undefined"&&Array.isArray(r.groups)){k=r.groups.every(function(v){return v.type!=="BUNDLE"||j.apply(v.mids.sort(),[q.sort()])})}if(!k){throw new Error("Cannot convert to Unified Plan because m-lines that are not bundled were found.")}var m;if(typeof this.cache[p.type]!=="undefined"){m=g.parse(this.cache[p.type])}var o={audio:{},video:{}};var s={};r.media.forEach(function(D){if((typeof D.rtcpMux!=="string"||D.rtcpMux!=="rtcp-mux")&&D.direction!=="inactive"){throw new Error("Cannot convert to Unified Plan because m-lines without the rtcp-mux attribute were found.")}if(D.type==="application"){s[D.mid]=D;return}var v=D.sources;var C=D.ssrcGroups;var B=D.candidates;var A=D.iceUfrag;var E=D.icePwd;var z=D.fingerprint;var w=D.port;delete D.sources;delete D.ssrcGroups;delete D.candidates;delete D.iceUfrag;delete D.icePwd;delete D.fingerprint;delete D.port;delete D.mid;var y={};if(typeof C!=="undefined"&&Array.isArray(C)){C.forEach(function(F){if(F.semantics==="SIM"){return}if(typeof F.ssrcs!=="undefined"&&Array.isArray(F.ssrcs)){F.ssrcs.forEach(function(G){if(typeof y[G]==="undefined"){y[G]=[]}y[G].push(F)})}})}var x={};if(typeof v==="object"){Object.keys(v).forEach(function(F){var G;if(p.type==="offer"){if(!v[F].msid){o[D.type][F]=v[F];return}}if(typeof y[F]!=="undefined"&&Array.isArray(y[F])){y[F].some(function(H){return H.ssrcs.some(function(I){if(typeof x[I]==="object"){G=x[I];return true}})})}if(typeof G==="object"){G.sources[F]=v[F];delete v[F].msid}else{G=Object.create(D);x[F]=G;if(typeof v[F].msid!=="undefined"){G.msid=v[F].msid;G.direction="sendrecv";delete v[F].msid}G.sources={};G.sources[F]=v[F];G.ssrcGroups=y[F];if(typeof m!=="undefined"&&typeof m.media!=="undefined"&&Array.isArray(m.media)){m.media.forEach(function(H){if(typeof H.sources==="object"){Object.keys(H.sources).forEach(function(I){if(I===F){G.mid=H.mid}})}})}if(typeof G.mid==="undefined"){if(p.type==="answer"){throw new Error("An unmapped SSRC was found.")}G.mid=[D.type,"-",F].join("")}G.candidates=B;G.iceUfrag=A;G.icePwd=E;G.fingerprint=z;G.port=w;s[G.mid]=G}})}});r.media=[];q=[];if(p.type==="answer"){for(var n=0;n0){v=u.getFirstSendingIndexFromAnswer(y);if(v===null){for(var x=0;xv){var w=r.media[v];Object.keys(o[y]).forEach(function(z){if(w.sources&&w.sources[z]){console.warn("Replacing an existing SSRC.")}if(!w.sources){w.sources={}}w.sources[z]=o[y][z]})}});r.groups.some(function(v){if(v.type==="BUNDLE"){v.mids=q.join(" ");return true}});r.msidSemantic={semantic:"WMS",token:"*"};var t=g.write(r);this.cache[p.type]=t;return new RTCSessionDescription({type:p.type,sdp:t})}},{"./array-equals":6,"./transform":11}],9:[function(g,h,e){var f=g("../transform");h.exports=function(p,k){if(typeof p!=="object"||p===null||typeof p.sdp!=="string"){console.warn("An empty description was passed as an argument.");return p}var q=f.parse(p.sdp);if(typeof q.media==="undefined"||!Array.isArray(q.media)||q.media.length===0){console.warn("The description has no media.");return p}if(q.media.length<=3&&q.media.every(function(i){return["video","audio","data"].indexOf(i.mid)!==-1})){console.warn("This description does not look like Unified Plan.");return p}var r=false;for(var n=0;n1&&t.type!=="data"){return}else{delete t.mid;t.mid=t.type;q.media.push(t);return}}if(t.type==="application"){q.media.push(t);o.push(t.mid);return}if(typeof t.sources==="object"){Object.keys(t.sources).forEach(function(u){if(typeof j[t.type].sources!=="object"){j[t.type].sources={}}j[t.type].sources[u]=t.sources[u];if(typeof t.msid!=="undefined"){j[t.type].sources[u].msid=t.msid}})}if(typeof t.ssrcGroups!=="undefined"&&Array.isArray(t.ssrcGroups)){if(typeof j[t.type].ssrcGroups==="undefined"||!Array.isArray(j[t.type].ssrcGroups)){j[t.type].ssrcGroups=[]}j[t.type].ssrcGroups=j[t.type].ssrcGroups.concat(t.ssrcGroups)}if(j[t.type]===t){t.candidates=l[0].candidates;t.iceUfrag=l[0].iceUfrag;t.icePwd=l[0].icePwd;t.fingerprint=l[0].fingerprint;t.mid=t.type;delete t.bundleOnly;delete t.msid;o.push(t.type);q.media.push(t)}});q.groups.some(function(i){if(i.type==="BUNDLE"){i.mids=o.join(" ");return true}});q.msidSemantic={semantic:"WMS",token:"*"};var s=f.write(q);return new window.RTCSessionDescription({type:p.type,sdp:s})}},{"../transform":11}],10:[function(h,i,f){var g=h("../transform");var j=h("../array-equals");var e=function(k){return JSON.parse(JSON.stringify(k))};i.exports=function(q,l){if(typeof q!=="object"||q===null||typeof q.sdp!=="string"){console.warn("An empty description was passed as an argument.");return q}var s=g.parse(q.sdp);if(typeof s.media==="undefined"||!Array.isArray(s.media)||s.media.length===0){console.warn("The description has no media.");return q}if(s.media.length>3||!s.media.every(function(v){return["video","audio","data"].indexOf(v.mid)!==-1})){console.warn("This description does not look like Plan B.");return q}var m=[];s.media.forEach(function(v){if(v.port!==0){m.push(v.mid)}});var k=false;if(typeof s.groups!=="undefined"&&Array.isArray(s.groups)){k=s.groups.every(function(v){return v.type!=="BUNDLE"||j.apply(v.mids.sort(),[m.sort()])})}if(!k){throw new Error("Cannot convert to Unified Plan because m-lines that are not bundled were found.")}var t=null;if(typeof l.local!=="undefined"){t=g.parse(l.local)}var n=null;if(typeof l.remote!=="undefined"){n=g.parse(l.remote)}var p=[];s.media.forEach(function(z,y,v){var B;var A;if(z.port===0){if(t!==null&&t.media.length>y){z.mid=t.media[y].mid}p.push(z);return}if(!z.sources){B=e(z);B.sources={};B.mid=B.type+"-"+1;p.push(B);return}var x=z.sources||null;if(!x){throw new Error("can't convert to unified plan - each m-line must have an ssrc")}var C=z.ssrcGroups||[];z.rtcp.port=z.port;var w=Object.keys(x);if(w.length===0){return}else{if(w.length==1){A=w[0];B=e(z);B.mid=B.type+"-"+A;p.push(B)}else{delete z.sources;delete z.ssrcGroups;C.forEach(function(E){var D=E.ssrcs[0];var F=e(z);F.sources={};F.sources[D]=x[D];F.mid=F.type+"-"+D;p.push(F)})}}});if(q.type==="offer"){if(t){while(p.length