"use strict";(self.webpackChunklernplattform_frontend=self.webpackChunklernplattform_frontend||[]).push([[22916],{655803:function(t,e,i){Object.defineProperty(e,"__esModule",{value:!0});const n=i(79762),s=i(660356),r=i(12049);class o{constructor(t){this.sdp=t}clone(){return new o(this.sdp)}static isRTPCandidate(t){const e=/candidate[:](\S+) (\d+)/g.exec(t);return null!==e&&"1"===e[2]}static linesToSDP(t){return new o(t.join(o.CRLF))}static candidateTypeFromString(t){switch(t){case n.default.Host:return n.default.Host;case n.default.ServerReflexive:return n.default.ServerReflexive;case n.default.PeerReflexive:return n.default.PeerReflexive;case n.default.Relay:return n.default.Relay}return null}static candidateType(t){const e=/a[=]candidate[:].* typ ([a-z]+) /g.exec(t);return null===e?null:o.candidateTypeFromString(e[1])}static mediaType(t){const e=/m=(audio|video)/g.exec(t);if(null!==e)return e[1]}static mid(t){if(t.includes("a=mid:"))return t.replace(/^(a=mid:)/,"")}static direction(t){const e=/a=(sendrecv|sendonly|recvonly|inactive)/g.exec(t);if(null!==e)return e[1]}static splitLines(t){return t.trim().split("\n").map((t=>t.trim()))}static splitSections(t){return t.split("\nm=").map(((t,e)=>(e>0?"m="+t:t).trim()+o.CRLF))}static findActiveCameraSection(t){let e=0,i=!1;for(const n of t){if(/^m=video/.test(n)&&(n.indexOf("sendrecv")>-1||-1===n.indexOf("sendonly")&&-1===n.indexOf("recvonly")&&-1===n.indexOf("inactive"))){i=!0;break}e++}return!1===i&&(e=-1),e}static extractSSRCsFromFIDGroupLine(t){return/^a=ssrc-group:FID\s(.+)/.exec(t)[1]}static matchPrefix(t,e){return o.splitLines(t).filter((t=>0===t.indexOf(e)))}lines(){return this.sdp.split(o.CRLF)}hasVideo(){return null!==/^m=video/gm.exec(this.sdp)}hasCandidates(){return null!==/a[=]candidate[:]/g.exec(this.sdp)}hasCandidatesForAllMLines(){return!(this.sdp.indexOf("c=IN IP4 0.0.0.0")>-1)}withoutCandidateType(t){return o.linesToSDP(this.lines().filter((e=>o.candidateType(e)!==t)))}withoutServerReflexiveCandidates(){return this.withoutCandidateType(n.default.ServerReflexive)}withAudioMaxAverageBitrate(t){if(!t)return this.clone();t=Math.trunc(Math.min(Math.max(t,o.rfc7587LowestBitrate),o.rfc7587HighestBitrate));const e=this.lines(),i=o.findOpusFmtpAttributes(e),n=o.updateOpusFmtpAttributes(e,i,[`maxaveragebitrate=${t}`]);return o.linesToSDP(n)}withStereoAudio(){const t=this.lines(),e=o.findOpusFmtpAttributes(t),i=o.updateOpusFmtpAttributes(t,e,["stereo=1","sprop-stereo=1"]);return o.linesToSDP(i)}static findOpusFmtpAttributes(t){const e=/^a=rtpmap:\s*(\d+)\s+opus\/48000/;let i=!1;const n=[];for(const s of t)if(s.startsWith("m=audio")&&(n.push(null),i=!0),s.startsWith("m=video")&&(i=!1),i){const t=e.exec(s);null!==t&&(n[n.length-1]=`a=fmtp:${t[1]} `)}return n}static updateOpusFmtpAttributes(t,e,i){const n=[];let s=0,r=null;for(const o of t)if(o.startsWith("m=audio")&&(r=e[s],s++),o.startsWith("m=video")&&(r=null),r&&o.startsWith(r)){const t=o.slice(r.length).split(";"),e=[];for(const n of t)i.findIndex((t=>t.startsWith(n.split("=")[0])))<0&&e.push(n);for(const t of i)e.push(t);n.push(r+e.join(";"))}else n.push(o);return n}withUnifiedPlanFormat(){let t=this.sdp;return t.includes("mozilla")?this.clone():(t=t.replace("o=-","o=mozilla-chrome"),new o(t))}getUniqueRtpHeaderExtensionId(t){const e=[];for(const i of t)if(/^a=extmap:/.test(i.trim())){const t=+i.split("a=extmap:")[1].split(" ")[0];e.includes(t)||e.push(t)}e.sort(((t,e)=>t-e));let i=0;for(const t of e){if(t-i>1)return i+1;i=t}return 14===i?-1:i+1}withVideoLayersAllocationRtpHeaderExtension(t){const e="http://www.webrtc.org/experiments/rtp-hdrext/video-layers-allocation00",i=t?t.getRtpHeaderExtensionId(e):-1,n=-1===i?this.getUniqueRtpHeaderExtensionId(o.splitLines(this.sdp)):i,s=o.splitSections(this.sdp),r=[];for(let t of s){if(/^m=video/.test(t)&&-1===o.getRtpHeaderExtensionIdInSection(t,e)){const i=o.splitLines(t),s=[];if(-1===n||this.hasRtpHeaderExtensionId(n)){r.push(t);continue}for(const t of i)if(s.push(t),/^a=sendrecv/.test(t.trim())){const t="a=extmap:"+n+" "+e;s.push(t)}t=s.join(o.CRLF)+o.CRLF}else if(-1!==i&&/^m=video/.test(t)&&o.getRtpHeaderExtensionIdInSection(t,e)!==i){const n=o.splitLines(t),s=[];for(const t of n)if(/^a=extmap:/.test(t.trim())&&t.split("a=extmap:")[1].split(" ")[1]===e){if(!this.hasRtpHeaderExtensionId(i)){const t="a=extmap:"+i+" "+e;s.push(t)}}else s.push(t);t=s.join(o.CRLF)+o.CRLF}r.push(t)}const a=r.join("");return new o(a)}ssrcForVideoSendingSection(){const t=this.sdp,e=o.splitSections(t);if(e.length<2)return"";const i=o.findActiveCameraSection(e);if(-1===i)return"";const n=o.matchPrefix(e[i],"a=ssrc-group:FID ");if(n.length<1)return"";const s=o.extractSSRCsFromFIDGroupLine(n[0]),[r]=s.split(" ").map((t=>parseInt(t,10)));return r.toString()}videoSendSectionHasDifferentSSRC(t){const e=this.ssrcForVideoSendingSection(),i=t.ssrcForVideoSendingSection();return""!==e&&""!==i&&parseInt(e,10)!==parseInt(i,10)}removeH264SupportFromSendSection(){const t=this.sdp,e=o.splitSections(t),i=o.findActiveCameraSection(e);if(-1===i)return new o(this.sdp);const n=e[i],s=o.splitLines(n),r=[],a=new Map;s.forEach((t=>{if(/^a=rtpmap:/.test(t)){const e=/^a=rtpmap:([0-9]+)\s/.exec(t);e&&t.toLowerCase().includes("h264")&&r.push(parseInt(e[1],10))}if(/^a=fmtp:/.test(t)){const e=/^a=fmtp:([0-9]+) apt=([0-9]+)/.exec(t);if(e&&3===e.length){const t=parseInt(e[1],10),i=parseInt(e[2],10);a.has(i)?a.get(i).push(t):a.set(i,[t])}}}));const c=new Set;for(const t of r){c.add(t);const e=a.get(t);if(e)for(const t of e)c.add(t)}if(r.length>0){const t=s[0].split(" ");s[0]=t.filter((t=>!c.has(parseInt(t)))).join(" ")}const d=s.filter((t=>{if(!t.includes("rtpmap")&&!t.includes("rtcp-fb")&&!t.includes("fmtp"))return!0;for(const e of c)if(t.includes(e.toString()))return!1;return!0}));e[i]=d.join(o.CRLF)+o.CRLF;const p=e.join("");return new o(p)}mediaSections(){const t=o.splitSections(this.sdp);if(t.length<2)return[];const e=[];for(let i=1;i<t.length;i++){const n=new s.default,r=o.splitLines(t[i]);for(const t of r){const e=o.mediaType(t);if(void 0!==e){n.mediaType=e;continue}const i=o.direction(t);if(void 0!==i){n.direction=i;continue}const s=o.mid(t);void 0===s||(n.mid=s)}e.push(n)}return e}static getRtpHeaderExtensionIdInSection(t,e){const i=o.splitLines(t);for(const t of i)if(/^a=extmap:/.test(t.trim())){const i=t.split("a=extmap:")[1].split(" "),n=+i[0];if(i[1]===e)return n}return-1}getRtpHeaderExtensionId(t){const e=o.splitSections(this.sdp);for(const i of e)if(/^m=video/.test(i)){const e=o.getRtpHeaderExtensionIdInSection(i,t);if(-1!==e)return e}return-1}hasRtpHeaderExtensionId(t){const e=o.splitLines(this.sdp);for(const i of e)if(/^a=extmap:/.test(i.trim())&&+i.split("a=extmap:")[1].split(" ")[0]===t)return!0;return!1}withVideoSendCodecPreferences(t){const e=this.sdp,i=o.splitSections(e),n=o.findActiveCameraSection(i);if(-1===n)return new o(this.sdp);i[n]=this.sectionWithCodecPreferences(i[n],t);const s=i.join("");return new o(s)}sectionWithCodecPreferences(t,e){const i=new Map,n=o.splitLines(t);n.forEach((t=>{if(/^a=rtpmap:/.test(t))for(const s of e){if(!t.includes(`${s.codecName}/${s.codecCapability.clockRate}`))continue;const e=/^a=rtpmap:([0-9]+)\s/.exec(t);let r=!1;if(void 0!==s.codecCapability.sdpFmtpLine){for(const t of n)if(t.startsWith(`a=fmtp:${e[1]} ${s.codecCapability.sdpFmtpLine}`)){r=!0;break}}else r=!0;if(r){i.set(s.codecName,e[1]);break}}}));const s=new Set(i.values()),r=n[0].split(" ").filter((t=>!s.has(t))),a=Array.from(i.values()).sort(((t,n)=>e.findIndex((e=>i.get(e.codecName)===t))-e.findIndex((t=>i.get(t.codecName)===n))));return r.splice(3,0,...a.values()),n[0]=r.join(" "),n.join(o.CRLF)+o.CRLF}highestPriorityVideoSendCodec(){const t=this.sdp,e=o.splitSections(t),i=o.findActiveCameraSection(e);if(-1===i)return;const n=o.splitLines(e[i]),s=n[0].split(" ");if(s.length<4)return;const a=s[3];let c,d,p;for(const t of n){const e=/^a=rtpmap:([0-9]+)\s/.exec(t);if(null===e||e.length<2||e[1]!==a)continue;const i=t.split(" ")[1].split("/");if(!(void 0===i||i.length<2)){c=i[0],d=i[1];for(const t of n)if(t.startsWith(`a=fmtp:${a}`)){const e=t.split(" ");if(void 0===e||e.length<2)return;p=e[1]}break}}return void 0!==c?new r.default(c,{clockRate:parseInt(d),mimeType:`video/${c}`,sdpFmtpLine:p}):void 0}}e.default=o,o.CRLF="\r\n",o.rfc7587LowestBitrate=6e3,o.rfc7587HighestBitrate=51e4}}]);