1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 16:12:19 +00:00
ghostream/web/static/ovenplayer/ovenplayer.provider.WebRTCProvider-0.9.0.js
2020-11-20 02:46:25 +01:00

2 lines
93 KiB
JavaScript

/*! For license information please see ovenplayer.provider.WebRTCProvider-0.9.0.js.LICENSE */
(window.webpackJsonp=window.webpackJsonp||[]).push([[7],{312:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=d(r(318)),i=d(r(319)),o=d(r(66)),a=d(r(313)),s=r(308),c=r(1);function d(e){return e&&e.__esModule?e:{default:e}}t.default=function(e,t,r){OvenPlayerConsole.log("[Provider] loaded. ");var d={};(0,o.default)(d);var u=e.element,p=null,l=null;e.adTagUrl&&(OvenPlayerConsole.log("[Provider] Ad Client - ",t.getAdClient()),(p=t.getAdClient()===c.AD_CLIENT_VAST?(0,i.default)(u,d,t,e.adTagUrl):(0,n.default)(u,d,t,e.adTagUrl))||console.log("Can not load due to google ima for Ads.")),l=(0,a.default)(u,d,p?p.videoEndedCallback:null,t),u.playbackRate=u.defaultPlaybackRate=t.getPlaybackRate();var f=function(n){var i=e.sources[e.currentSource];if(e.framerate=i.framerate,d.setVolume(t.getVolume()),e.framerate||t.setTimecodeMode(!0),r)r(i,n);else{OvenPlayerConsole.log("source loaded : ",i,"lastPlayPosition : "+n);var o=u.src;i.file!==o&&(u.src=i.file,(o||""===o)&&u.load(),n&&n>0&&d.seek(n)),n>0&&(d.seek(n),t.isAutoStart()),t.isAutoStart()}};return d.getName=function(){return e.name},d.canSeek=function(){return e.canSeek},d.setCanSeek=function(t){e.canSeek=t},d.isSeeking=function(){return e.seeking},d.setSeeking=function(t){e.seeking=t},d.setMetaLoaded=function(){e.isLoaded=!0},d.metaLoaded=function(){return e.isLoaded},d.setState=function(t){if(e.state!==t){var r=e.state;if(OvenPlayerConsole.log("Provider : setState()",t),r===c.STATE_AD_PLAYING&&(t===c.STATE_ERROR||t===c.STATE_IDLE))return!1;switch(OvenPlayerConsole.log("Provider : triggerSatatus",t),t){case c.STATE_COMPLETE:d.trigger(c.PLAYER_COMPLETE);break;case c.STATE_PAUSED:d.trigger(c.PLAYER_PAUSE,{prevState:e.state,newstate:c.STATE_PAUSED});break;case c.STATE_AD_PAUSED:d.trigger(c.PLAYER_PAUSE,{prevState:e.state,newstate:c.STATE_AD_PAUSED});break;case c.STATE_PLAYING:d.trigger(c.PLAYER_PLAY,{prevState:e.state,newstate:c.STATE_PLAYING});case c.STATE_AD_PLAYING:d.trigger(c.PLAYER_PLAY,{prevState:e.state,newstate:c.STATE_AD_PLAYING})}e.state=t,d.trigger(c.PLAYER_STATE,{prevstate:r,newstate:e.state})}},d.getState=function(){return e.state},d.setBuffer=function(t){e.buffer=t},d.getBuffer=function(){return e.buffer},d.isLive=function(){return!!e.isLive||u.duration===1/0},d.getDuration=function(){return d.isLive()?1/0:u.duration},d.getPosition=function(){return u?u.currentTime:0},d.setVolume=function(e){if(!u)return!1;u.volume=e/100},d.getVolume=function(){return u?100*u.volume:0},d.setMute=function(e){return!!u&&(void 0===e?(u.muted=!u.muted,d.trigger(c.CONTENT_MUTE,{mute:u.muted})):(u.muted=e,d.trigger(c.CONTENT_MUTE,{mute:u.muted})),u.muted)},d.getMute=function(){return!!u&&u.muted},d.preload=function(r,n){return e.sources=r,e.currentSource=(0,s.pickCurrentSource)(r,e.currentSource,t),f(n||0),new Promise(function(e,r){t.isMute()&&d.setMute(!0),t.getVolume()&&d.setVolume(t.getVolume()),e()})},d.load=function(r){e.sources=r,e.currentSource=(0,s.pickCurrentSource)(r,e.currentSource,t),f(e.sources.starttime||0)},d.play=function(){if(OvenPlayerConsole.log("Provider : play()"),!u)return!1;if(d.getState()!==c.STATE_PLAYING)if(p&&p.isActive()||p&&!p.started())p.play().then(function(e){OvenPlayerConsole.log("Provider : ads play success")}).catch(function(e){OvenPlayerConsole.log("Provider : ads play fail",e)});else{var e=u.play();void 0!==e?e.then(function(){OvenPlayerConsole.log("Provider : video play success")}).catch(function(e){OvenPlayerConsole.log("Provider : video play error",e.message)}):OvenPlayerConsole.log("Provider : video play success (ie)")}},d.pause=function(){if(OvenPlayerConsole.log("Provider : pause()"),!u)return!1;d.getState()===c.STATE_PLAYING?u.pause():d.getState()===c.STATE_AD_PLAYING&&p.pause()},d.seek=function(e){if(!u)return!1;u.currentTime=e},d.setPlaybackRate=function(e){return!!u&&(d.trigger(c.PLAYBACK_RATE_CHANGED,{playbackRate:e}),u.playbackRate=u.defaultPlaybackRate=e)},d.getPlaybackRate=function(){return u?u.playbackRate:0},d.getSources=function(){return u?e.sources.map(function(e,t){var r={file:e.file,type:e.type,label:e.label,index:t,sectionStart:e.sectionStart,sectionEnd:e.sectionEnd,gridThumbnail:e.gridThumbnail};return e.lowLatency&&(r.lowLatency=e.lowLatency),r}):[]},d.getCurrentSource=function(){return e.currentSource},d.setCurrentSource=function(r,n){if(r>-1&&e.sources&&e.sources.length>r)return OvenPlayerConsole.log("source changed : "+r),e.currentSource=r,d.trigger(c.CONTENT_SOURCE_CHANGED,{currentSource:r}),t.setSourceIndex(r),d.setState(c.STATE_IDLE),n&&f(u.currentTime||0),e.currentSource},d.getQualityLevels=function(){return u?e.qualityLevels:[]},d.getCurrentQuality=function(){return u?e.currentQuality:null},d.setCurrentQuality=function(e){},d.isAutoQuality=function(){},d.setAutoQuality=function(e){},d.getFramerate=function(){return e.framerate},d.setFramerate=function(t){return e.framerate=t},d.seekFrame=function(t){var r=e.framerate,n=(u.currentTime*r+t)/r;n+=1e-5,d.pause(),d.seek(n)},d.stop=function(){if(!u)return!1;for(OvenPlayerConsole.log("CORE : stop() "),u.removeAttribute("preload"),u.removeAttribute("src");u.firstChild;)u.removeChild(u.firstChild);d.pause(),d.setState(c.STATE_IDLE)},d.destroy=function(){if(!u)return!1;d.stop(),l.destroy(),p&&(p.destroy(),p=null),d.off(),OvenPlayerConsole.log("CORE : destroy() player stop, listener, event destroied")},d.super=function(e){var t=d[e];return function(){return t.apply(d,arguments)}},d}},313:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(1),i=r(308);t.default=function(e,t,r,o){var a={};OvenPlayerConsole.log("EventListener loaded.",e,t);var s={},c=-1,d=e;return a.canplay=function(){t.setCanSeek(!0),t.trigger(n.CONTENT_BUFFER_FULL),OvenPlayerConsole.log("EventListener : on canplay")},a.durationchange=function(){a.progress(),OvenPlayerConsole.log("EventListener : on durationchange")},a.ended=function(){OvenPlayerConsole.log("EventListener : on ended"),t.getState()!==n.STATE_IDLE&&t.getState()!==n.STATE_COMPLETE&&t.getState()!==n.STATE_ERROR&&(r?r(function(){t.setState(n.STATE_COMPLETE)}):t.setState(n.STATE_COMPLETE))},a.loadeddata=function(){},a.loadedmetadata=function(){var e=t.getSources(),r=t.getCurrentSource(),i=r>-1?e[r].type:"",o={duration:t.isLive()?1/0:d.duration,type:i};t.setMetaLoaded(),OvenPlayerConsole.log("EventListener : on loadedmetadata",o),t.trigger(n.CONTENT_META,o)},a.pause=function(){return t.getState()!==n.STATE_COMPLETE&&t.getState()!==n.STATE_ERROR&&!d.ended&&!d.error&&d.currentTime!==d.duration&&(OvenPlayerConsole.log("EventListener : on pause"),void t.setState(n.STATE_PAUSED))},a.loadstart=function(){o&&!o.getConfig().showBigPlayButton&&o.getConfig().autoStart&&t.setState(n.STATE_LOADING)},a.play=function(){c=-1,d.paused||t.getState()===n.STATE_PLAYING||t.setState(n.STATE_LOADING)},a.playing=function(){OvenPlayerConsole.log("EventListener : on playing"),c<0&&t.setState(n.STATE_PLAYING)},a.progress=function(){var e=d.buffered;if(!e)return!1;var r=d.duration,i=d.currentTime,o=function(e,t,r){return Math.max(Math.min(e,r),t)}((e.length>0?e.end(e.length-1):0)/r,0,1);t.setBuffer(100*o),t.trigger(n.CONTENT_BUFFER,{bufferPercent:100*o,position:i,duration:r}),OvenPlayerConsole.log("EventListener : on progress",100*o)},a.timeupdate=function(){var e=d.currentTime,r=d.duration;if(!isNaN(r)){var i=t.getSources()[t.getCurrentSource()].sectionStart;i&&e<i&&t.getState()===n.STATE_PLAYING&&t.seek(i);var o=t.getSources()[t.getCurrentSource()].sectionEnd;if(o&&e>o&&t.getState()===n.STATE_PLAYING)return t.stop(),void t.setState(n.STATE_COMPLETE);r>9e15&&(r=1/0),t.isSeeking()||d.paused||t.getState()!==n.STATE_STALLED&&t.getState()!==n.STATE_LOADING&&t.getState()!==n.STATE_AD_PLAYING||function(e,t){return e.toFixed(2)===t.toFixed(2)}(c,e)||(c=-1,t.setState(n.STATE_PLAYING)),i&&i>0&&(e-=i)<0&&(e=0),o&&(r=o),i&&(r-=i),(t.getState()===n.STATE_PLAYING||t.isSeeking())&&t.trigger(n.CONTENT_TIME,{position:e,duration:r})}},a.seeking=function(){t.setSeeking(!0),OvenPlayerConsole.log("EventListener : on seeking",d.currentTime),t.trigger(n.CONTENT_SEEK,{position:d.currentTime})},a.seeked=function(){t.isSeeking()&&(OvenPlayerConsole.log("EventListener : on seeked"),t.setSeeking(!1),t.trigger(n.CONTENT_SEEKED))},a.stalled=function(){OvenPlayerConsole.log("EventListener : on stalled")},a.waiting=function(){OvenPlayerConsole.log("EventListener : on waiting",t.getState()),t.isSeeking()?t.setState(n.STATE_LOADING):t.getState()===n.STATE_PLAYING&&(c=d.currentTime,t.setState(n.STATE_STALLED))},a.volumechange=function(){OvenPlayerConsole.log("EventListener : on volumechange",Math.round(100*d.volume)),t.trigger(n.CONTENT_VOLUME,{volume:Math.round(100*d.volume),mute:d.muted})},a.error=function(){var e=d.error&&d.error.code||0,r={0:n.PLAYER_UNKNWON_ERROR,1:n.PLAYER_UNKNWON_OPERATION_ERROR,2:n.PLAYER_UNKNWON_NETWORK_ERROR,3:n.PLAYER_UNKNWON_DECODE_ERROR,4:n.PLAYER_FILE_ERROR}[e]||0;OvenPlayerConsole.log("EventListener : on error",r),(0,i.errorTrigger)(n.ERRORS.codes[r],t)},Object.keys(a).forEach(function(e){d.removeEventListener(e,a[e]),d.addEventListener(e,a[e])}),s.destroy=function(){OvenPlayerConsole.log("EventListener : destroy()"),Object.keys(a).forEach(function(e){d.removeEventListener(e,a[e])})},s}},389:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});a(r(390));var n=a(r(7)),i=r(26),o=r(1);function a(e){return e&&e.__esModule?e:{default:e}}t.default=function(e,t,r,a,s){var c={iceServers:[{urls:"stun:stun.l.google.com:19302"}]};s.getConfig().webrtcConfig&&(s.getConfig().webrtcConfig.iceServers&&(c.iceServers=s.getConfig().webrtcConfig.iceServers),s.getConfig().webrtcConfig.iceTransportPolicy&&(c.iceTransportPolicy=s.getConfig().webrtcConfig.iceTransportPolicy));var d={},u=null,p=null,l=null,f=null,m={},v=!1,h=null,g=(0,i.analUserAgent)();function C(e){var t=null;return f&&e===f.id?t=f.peerConnection:m[e]&&(t=m[e].peerConnection),t}function T(e,t,i,a,d){var p=new RTCPeerConnection(c);f={id:e,peerId:t,peerConnection:p},p.setRemoteDescription(new RTCSessionDescription(i)).then(function(){p.createAnswer().then(function(r){OvenPlayerConsole.log("create Host Answer : success"),p.setLocalDescription(r).then(function(){var r=p.localDescription;OvenPlayerConsole.log("Local SDP",r),P(u,{id:e,peer_id:t,command:"answer",sdp:r})}).catch(function(e){var t=o.ERRORS.codes[o.PLAYER_WEBRTC_SET_LOCAL_DESC_ERROR];t.error=e,R(t)})}).catch(function(e){var t=o.ERRORS.codes[o.PLAYER_WEBRTC_CREATE_ANSWER_ERROR];t.error=e,R(t)})}).catch(function(e){var t=o.ERRORS.codes[o.PLAYER_WEBRTC_SET_REMOTE_DESC_ERROR];t.error=e,R(t)}),a&&S(p,a),p.onicecandidate=function(r){r.candidate&&(OvenPlayerConsole.log("WebRTCLoader send candidate to server : "+r.candidate),P(u,{id:e,peer_id:t,command:"candidate",candidates:[r.candidate]}))},p.onconnectionstatechange=function(e){OvenPlayerConsole.log("[on connection state change]",p.connectionState,e)},p.oniceconnectionstatechange=function(e){OvenPlayerConsole.log("[on ice connection state change]",p.iceConnectionState,e),("disconnected"===p.iceConnectionState||"closed"===p.iceConnectionState)&&(v||f&&R(o.ERRORS.codes[o.PLAYER_WEBRTC_UNEXPECTED_DISCONNECT]))},p.ontrack=function(e){OvenPlayerConsole.log("stream received."),function e(t){t.statisticsTimer&&clearTimeout(t.statisticsTimer),t.status||(t.status={},t.status.lostPacketsArr=[],t.status.slotLength=8,t.status.prevPacketsLost=0,t.status.avg8Losses=0,t.status.avgMoreThanThresholdCount=0,t.status.threshold=40);var r=t.status.lostPacketsArr,i=t.status.slotLength,a=t.status.prevPacketsLost,c=t.status.avg8Losses,d=t.status.threshold;t.statisticsTimer=setTimeout(function(){if(!t.peerConnection)return!1;t.peerConnection.getStats().then(function(u){u&&s.getConfig().autoFallback&&u&&(u.forEach(function(e){if("inbound-rtp"===e.type&&"video"===e.kind&&!e.isRemote){var s=parseInt(e.packetsLost)-parseInt(a);r.push(parseInt(e.packetsLost)-parseInt(a)),r.length>i&&r.shift(),r.length===i&&(c=n.default.reduce(r,function(e,t){return e+t},0)/i,OvenPlayerConsole.log("Last8 LOST PACKET AVG : "+c,"Current Packet LOST: "+s,"Total Packet Lost: "+e.packetsLost,r),c>d?(t.status.avgMoreThanThresholdCount=t.status.avgMoreThanThresholdCount+1,t.status.avgMoreThanThresholdCount>=60&&(OvenPlayerConsole.log("NETWORK UNSTABLED!!! "),R(o.ERRORS.codes[o.PLAYER_WEBRTC_NETWORK_SLOW]))):t.status.avgMoreThanThresholdCount=0),t.status.prevPacketsLost=e.packetsLost}}),e(t))})},2e3)}(f),l=e.streams[0],r(e.streams[0])}}!function(){var e=window.onbeforeunload;window.onbeforeunload=function(t){e&&e(t),OvenPlayerConsole.log("This calls auto when browser closed."),R()}}();var y=function(e){var r=n.default.clone(e);function i(e){var t,r="";return(t=e.match(new RegExp("\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b","gi")))&&(r=t[0]),r}var o=function(e){var t,r="";return(t=e.match(/^(?:wss?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n\?\=]+)/im))&&(r=t[1]),r}(t),a=i(r.candidate);return""===a||a===o?null:new Promise(function(e,t){"Firefox"!==g.browser||i(o)?(r.candidate=r.candidate.replace(a,o),e(r)):fetch("https://dns.google.com/resolve?name="+o).then(function(e){return e.json()}).then(function(t){if(!(t&&t.Answer&&t.Answer.length>0))return null;if(!t.Answer[0].data)return null;var n=t.Answer[0].data;r.candidate=r.candidate.replace(a,n),e(r)})})};function S(e,t){for(var r=0;r<t.length;r++)if(t[r]&&t[r].candidate){var n=t[r],i=y(n);e.addIceCandidate(new RTCIceCandidate(n)).then(function(){OvenPlayerConsole.log("addIceCandidate : success")}).catch(function(e){var t=o.ERRORS.codes[o.PLAYER_WEBRTC_ADD_ICECANDIDATE_ERROR];t.error=e,R(t)}),i&&i.then(function(t){t&&e.addIceCandidate(new RTCIceCandidate(t)).then(function(){OvenPlayerConsole.log("cloned addIceCandidate : success")}).catch(function(e){var t=o.ERRORS.codes[o.PLAYER_WEBRTC_ADD_ICECANDIDATE_ERROR];t.error=e,R(t)})})}}function E(r,n){try{(u=new WebSocket(t)).onopen=function(){P(u,{command:"request_offer"})},u.onmessage=function(t){var r=JSON.parse(t.data);if(r.error){var n=o.ERRORS.codes[o.PLAYER_WEBRTC_WS_ERROR];return n.error=r.error,void R(n)}0!==Object.keys(r).length||r.constructor!==Object?"ping"!==r.command?r.id?("offer"===r.command&&(T(r.id,r.peer_id,r.sdp,r.candidates),0===r.peer_id?e.trigger(o.OME_P2P_MODE,!1):e.trigger(o.OME_P2P_MODE,!0)),"request_offer_p2p"===r.command&&function e(t,r){if(l){var n=new RTCPeerConnection(c);m[r]={id:r,peerId:t,peerConnection:n},n.addStream(l),n.createOffer(function(e){n.setLocalDescription(e),P(u,{id:t,peer_id:r,sdp:e,command:"offer_p2p"})},function(e){},{}),n.onicecandidate=function(e){e.candidate&&(OvenPlayerConsole.log("WebRTCLoader send candidate to server : "+e.candidate),P(u,{id:t,peer_id:r,command:"candidate_p2p",candidates:[e.candidate]}))}}else setTimeout(function(){e(t,r)},100)}(r.id,r.peer_id),"answer_p2p"===r.command&&C(r.peer_id).setRemoteDescription(new RTCSessionDescription(r.sdp)).then(function(e){}).catch(function(e){var t=o.ERRORS.codes[o.PLAYER_WEBRTC_SET_REMOTE_DESC_ERROR];t.error=e,R(t)}),"candidate"===r.command&&S(C(r.id),r.candidates),"candidate_p2p"===r.command&&S(C(r.peer_id),r.candidates),"stop"===r.command&&(f.peerId===r.peer_id?(l=null,f.peerConnection.close(),f=null,e.pause(),P(u,{command:"request_offer"})):m[r.peer_id]&&(m[r.peer_id].peerConnection.close(),delete m[r.peer_id]))):OvenPlayerConsole.log("ID must be not null"):P(u,{command:"pong"}):OvenPlayerConsole.log("Empty Message")},u.onclose=function(){if(!v){var e=o.ERRORS.codes[o.PLAYER_WEBRTC_WS_ERROR];f&&(e=o.ERRORS.codes[o.PLAYER_WEBRTC_UNEXPECTED_DISCONNECT]),R(e)}},u.onerror=function(e){if(!v){var t=o.ERRORS.codes[o.PLAYER_WEBRTC_WS_ERROR];t.error=e,R(t)}}}catch(e){R(e)}}function R(t){if(OvenPlayerConsole.log("WebRTC Loader closePeer()"),t||(v=!0),f&&(f.statisticsTimer&&clearTimeout(f.statisticsTimer),l=null,OvenPlayerConsole.log("Closing main peer connection..."),h&&clearTimeout(h),f.peerConnection.close(),f.peerConnection=null,f=null),Object.keys(m).length>0){for(var r in m){var n=m[r].peerConnection;OvenPlayerConsole.log("Closing client peer connection..."),n.close(),n=null}m={}}clearInterval(p),p=null,u?(OvenPlayerConsole.log("Closing websocket connection..."),OvenPlayerConsole.log("Send Signaling : Stop."),0!==u.readyState&&1!==u.readyState||(v=!0,f&&P(u,{command:"stop",id:f.id}),u.close())):v=!1,u=null,t&&a(t,e)}function P(e,t){e&&e.send(JSON.stringify(t))}return d.connect=function(){return OvenPlayerConsole.log("WebRTCLoader connecting..."),new Promise(function(e,r){OvenPlayerConsole.log("WebRTCLoader url : "+t),E()})},d.destroy=function(){R()},d}},390:function(e,t,r){"use strict";(function(r){var n,i,o,a,s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(r){"object"===c(t)&&void 0!==e?e.exports=r():(i=[],void 0===(o="function"==typeof(n=r)?n.apply(t,i):n)||(e.exports=o))}(function(){return function e(t,r,n){function i(s,c){if(!r[s]){if(!t[s]){if(!c&&("function"==typeof a&&a))return a(s,!0);if(o)return o(s,!0);var d=new Error("Cannot find module '"+s+"'");throw d.code="MODULE_NOT_FOUND",d}var u=r[s]={exports:{}};t[s][0].call(u.exports,function(e){var r=t[s][1][e];return i(r||e)},u,u.exports,e,t,r,n)}return r[s].exports}for(var o="function"==typeof a&&a,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(e,t,r){var n=e("sdp");function i(e,t,r,i,o){var a=n.writeRtpDescription(e.kind,t);if(a+=n.writeIceParameters(e.iceGatherer.getLocalParameters()),a+=n.writeDtlsParameters(e.dtlsTransport.getLocalParameters(),"offer"===r?"actpass":o||"active"),a+="a=mid:"+e.mid+"\r\n",e.rtpSender&&e.rtpReceiver?a+="a=sendrecv\r\n":e.rtpSender?a+="a=sendonly\r\n":e.rtpReceiver?a+="a=recvonly\r\n":a+="a=inactive\r\n",e.rtpSender){var s=e.rtpSender._initialTrackId||e.rtpSender.track.id;e.rtpSender._initialTrackId=s;var c="msid:"+(i?i.id:"-")+" "+s+"\r\n";a+="a="+c,a+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" "+c,e.sendEncodingParameters[0].rtx&&(a+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" "+c,a+="a=ssrc-group:FID "+e.sendEncodingParameters[0].ssrc+" "+e.sendEncodingParameters[0].rtx.ssrc+"\r\n")}return a+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" cname:"+n.localCName+"\r\n",e.rtpSender&&e.sendEncodingParameters[0].rtx&&(a+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" cname:"+n.localCName+"\r\n"),a}function o(e,t){var r={codecs:[],headerExtensions:[],fecMechanisms:[]},n=function(e,t){e=parseInt(e,10);for(var r=0;r<t.length;r++)if(t[r].payloadType===e||t[r].preferredPayloadType===e)return t[r]},i=function(e,t,r,i){var o=n(e.parameters.apt,r),a=n(t.parameters.apt,i);return o&&a&&o.name.toLowerCase()===a.name.toLowerCase()};return e.codecs.forEach(function(n){for(var o=0;o<t.codecs.length;o++){var a=t.codecs[o];if(n.name.toLowerCase()===a.name.toLowerCase()&&n.clockRate===a.clockRate){if("rtx"===n.name.toLowerCase()&&n.parameters&&a.parameters.apt&&!i(n,a,e.codecs,t.codecs))continue;(a=JSON.parse(JSON.stringify(a))).numChannels=Math.min(n.numChannels,a.numChannels),r.codecs.push(a),a.rtcpFeedback=a.rtcpFeedback.filter(function(e){for(var t=0;t<n.rtcpFeedback.length;t++)if(n.rtcpFeedback[t].type===e.type&&n.rtcpFeedback[t].parameter===e.parameter)return!0;return!1});break}}}),e.headerExtensions.forEach(function(e){for(var n=0;n<t.headerExtensions.length;n++){var i=t.headerExtensions[n];if(e.uri===i.uri){r.headerExtensions.push(i);break}}}),r}function a(e,t,r){return-1!=={offer:{setLocalDescription:["stable","have-local-offer"],setRemoteDescription:["stable","have-remote-offer"]},answer:{setLocalDescription:["have-remote-offer","have-local-pranswer"],setRemoteDescription:["have-local-offer","have-remote-pranswer"]}}[t][e].indexOf(r)}function c(e,t){var r=e.getRemoteCandidates().find(function(e){return t.foundation===e.foundation&&t.ip===e.ip&&t.port===e.port&&t.priority===e.priority&&t.protocol===e.protocol&&t.type===e.type});return r||e.addRemoteCandidate(t),!r}function d(e,t){var r=new Error(t);return r.name=e,r.code={NotSupportedError:9,InvalidStateError:11,InvalidAccessError:15,TypeError:void 0,OperationError:void 0}[e],r}t.exports=function(e,t){function r(t,r){r.addTrack(t),r.dispatchEvent(new e.MediaStreamTrackEvent("addtrack",{track:t}))}function u(t,r,n,i){var o=new Event("track");o.track=r,o.receiver=n,o.transceiver={receiver:n},o.streams=i,e.setTimeout(function(){t._dispatchEvent("track",o)})}var p=function(r){var i=this,o=document.createDocumentFragment();if(["addEventListener","removeEventListener","dispatchEvent"].forEach(function(e){i[e]=o[e].bind(o)}),this.canTrickleIceCandidates=null,this.needNegotiation=!1,this.localStreams=[],this.remoteStreams=[],this.localDescription=null,this.remoteDescription=null,this.signalingState="stable",this.iceConnectionState="new",this.connectionState="new",this.iceGatheringState="new",r=JSON.parse(JSON.stringify(r||{})),this.usingBundle="max-bundle"===r.bundlePolicy,"negotiate"===r.rtcpMuxPolicy)throw d("NotSupportedError","rtcpMuxPolicy 'negotiate' is not supported");switch(r.rtcpMuxPolicy||(r.rtcpMuxPolicy="require"),r.iceTransportPolicy){case"all":case"relay":break;default:r.iceTransportPolicy="all"}switch(r.bundlePolicy){case"balanced":case"max-compat":case"max-bundle":break;default:r.bundlePolicy="balanced"}if(r.iceServers=function(e,t){var r=!1;return(e=JSON.parse(JSON.stringify(e))).filter(function(e){if(e&&(e.urls||e.url)){var n=e.urls||e.url;e.url&&!e.urls&&console.warn("RTCIceServer.url is deprecated! Use urls instead.");var i="string"==typeof n;return i&&(n=[n]),n=n.filter(function(e){return 0!==e.indexOf("turn:")||-1===e.indexOf("transport=udp")||-1!==e.indexOf("turn:[")||r?0===e.indexOf("stun:")&&t>=14393&&-1===e.indexOf("?transport=udp"):(r=!0,!0)}),delete e.url,e.urls=i?n[0]:n,!!n.length}})}(r.iceServers||[],t),this._iceGatherers=[],r.iceCandidatePoolSize)for(var a=r.iceCandidatePoolSize;a>0;a--)this._iceGatherers.push(new e.RTCIceGatherer({iceServers:r.iceServers,gatherPolicy:r.iceTransportPolicy}));else r.iceCandidatePoolSize=0;this._config=r,this.transceivers=[],this._sdpSessionId=n.generateSessionId(),this._sdpSessionVersion=0,this._dtlsRole=void 0,this._isClosed=!1};p.prototype.onicecandidate=null,p.prototype.onaddstream=null,p.prototype.ontrack=null,p.prototype.onremovestream=null,p.prototype.onsignalingstatechange=null,p.prototype.oniceconnectionstatechange=null,p.prototype.onconnectionstatechange=null,p.prototype.onicegatheringstatechange=null,p.prototype.onnegotiationneeded=null,p.prototype.ondatachannel=null,p.prototype._dispatchEvent=function(e,t){this._isClosed||(this.dispatchEvent(t),"function"==typeof this["on"+e]&&this["on"+e](t))},p.prototype._emitGatheringStateChange=function(){var e=new Event("icegatheringstatechange");this._dispatchEvent("icegatheringstatechange",e)},p.prototype.getConfiguration=function(){return this._config},p.prototype.getLocalStreams=function(){return this.localStreams},p.prototype.getRemoteStreams=function(){return this.remoteStreams},p.prototype._createTransceiver=function(e,t){var r=this.transceivers.length>0,n={track:null,iceGatherer:null,iceTransport:null,dtlsTransport:null,localCapabilities:null,remoteCapabilities:null,rtpSender:null,rtpReceiver:null,kind:e,mid:null,sendEncodingParameters:null,recvEncodingParameters:null,stream:null,associatedRemoteMediaStreams:[],wantReceive:!0};if(this.usingBundle&&r)n.iceTransport=this.transceivers[0].iceTransport,n.dtlsTransport=this.transceivers[0].dtlsTransport;else{var i=this._createIceAndDtlsTransports();n.iceTransport=i.iceTransport,n.dtlsTransport=i.dtlsTransport}return t||this.transceivers.push(n),n},p.prototype.addTrack=function(t,r){if(this._isClosed)throw d("InvalidStateError","Attempted to call addTrack on a closed peerconnection.");var n;if(this.transceivers.find(function(e){return e.track===t}))throw d("InvalidAccessError","Track already exists.");for(var i=0;i<this.transceivers.length;i++)this.transceivers[i].track||this.transceivers[i].kind!==t.kind||(n=this.transceivers[i]);return n||(n=this._createTransceiver(t.kind)),this._maybeFireNegotiationNeeded(),-1===this.localStreams.indexOf(r)&&this.localStreams.push(r),n.track=t,n.stream=r,n.rtpSender=new e.RTCRtpSender(t,n.dtlsTransport),n.rtpSender},p.prototype.addStream=function(e){var r=this;if(t>=15025)e.getTracks().forEach(function(t){r.addTrack(t,e)});else{var n=e.clone();e.getTracks().forEach(function(e,t){var r=n.getTracks()[t];e.addEventListener("enabled",function(e){r.enabled=e.enabled})}),n.getTracks().forEach(function(e){r.addTrack(e,n)})}},p.prototype.removeTrack=function(t){if(this._isClosed)throw d("InvalidStateError","Attempted to call removeTrack on a closed peerconnection.");if(!(t instanceof e.RTCRtpSender))throw new TypeError("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.");var r=this.transceivers.find(function(e){return e.rtpSender===t});if(!r)throw d("InvalidAccessError","Sender was not created by this connection.");var n=r.stream;r.rtpSender.stop(),r.rtpSender=null,r.track=null,r.stream=null,-1===this.transceivers.map(function(e){return e.stream}).indexOf(n)&&this.localStreams.indexOf(n)>-1&&this.localStreams.splice(this.localStreams.indexOf(n),1),this._maybeFireNegotiationNeeded()},p.prototype.removeStream=function(e){var t=this;e.getTracks().forEach(function(e){var r=t.getSenders().find(function(t){return t.track===e});r&&t.removeTrack(r)})},p.prototype.getSenders=function(){return this.transceivers.filter(function(e){return!!e.rtpSender}).map(function(e){return e.rtpSender})},p.prototype.getReceivers=function(){return this.transceivers.filter(function(e){return!!e.rtpReceiver}).map(function(e){return e.rtpReceiver})},p.prototype._createIceGatherer=function(t,r){var n=this;if(r&&t>0)return this.transceivers[0].iceGatherer;if(this._iceGatherers.length)return this._iceGatherers.shift();var i=new e.RTCIceGatherer({iceServers:this._config.iceServers,gatherPolicy:this._config.iceTransportPolicy});return Object.defineProperty(i,"state",{value:"new",writable:!0}),this.transceivers[t].bufferedCandidateEvents=[],this.transceivers[t].bufferCandidates=function(e){var r=!e.candidate||0===Object.keys(e.candidate).length;i.state=r?"completed":"gathering",null!==n.transceivers[t].bufferedCandidateEvents&&n.transceivers[t].bufferedCandidateEvents.push(e)},i.addEventListener("localcandidate",this.transceivers[t].bufferCandidates),i},p.prototype._gather=function(t,r){var i=this,o=this.transceivers[r].iceGatherer;if(!o.onlocalcandidate){var a=this.transceivers[r].bufferedCandidateEvents;this.transceivers[r].bufferedCandidateEvents=null,o.removeEventListener("localcandidate",this.transceivers[r].bufferCandidates),o.onlocalcandidate=function(e){if(!(i.usingBundle&&r>0)){var a=new Event("icecandidate");a.candidate={sdpMid:t,sdpMLineIndex:r};var c=e.candidate,d=!c||0===Object.keys(c).length;if(d)"new"!==o.state&&"gathering"!==o.state||(o.state="completed");else{"new"===o.state&&(o.state="gathering"),c.component=1,c.ufrag=o.getLocalParameters().usernameFragment;var u=n.writeCandidate(c);a.candidate=s(a.candidate,n.parseCandidate(u)),a.candidate.candidate=u,a.candidate.toJSON=function(){return{candidate:a.candidate.candidate,sdpMid:a.candidate.sdpMid,sdpMLineIndex:a.candidate.sdpMLineIndex,usernameFragment:a.candidate.usernameFragment}}}var p=n.getMediaSections(i.localDescription.sdp);p[a.candidate.sdpMLineIndex]+=d?"a=end-of-candidates\r\n":"a="+a.candidate.candidate+"\r\n",i.localDescription.sdp=n.getDescription(i.localDescription.sdp)+p.join("");var l=i.transceivers.every(function(e){return e.iceGatherer&&"completed"===e.iceGatherer.state});"gathering"!==i.iceGatheringState&&(i.iceGatheringState="gathering",i._emitGatheringStateChange()),d||i._dispatchEvent("icecandidate",a),l&&(i._dispatchEvent("icecandidate",new Event("icecandidate")),i.iceGatheringState="complete",i._emitGatheringStateChange())}},e.setTimeout(function(){a.forEach(function(e){o.onlocalcandidate(e)})},0)}},p.prototype._createIceAndDtlsTransports=function(){var t=this,r=new e.RTCIceTransport(null);r.onicestatechange=function(){t._updateIceConnectionState(),t._updateConnectionState()};var n=new e.RTCDtlsTransport(r);return n.ondtlsstatechange=function(){t._updateConnectionState()},n.onerror=function(){Object.defineProperty(n,"state",{value:"failed",writable:!0}),t._updateConnectionState()},{iceTransport:r,dtlsTransport:n}},p.prototype._disposeIceAndDtlsTransports=function(e){var t=this.transceivers[e].iceGatherer;t&&(delete t.onlocalcandidate,delete this.transceivers[e].iceGatherer);var r=this.transceivers[e].iceTransport;r&&(delete r.onicestatechange,delete this.transceivers[e].iceTransport);var n=this.transceivers[e].dtlsTransport;n&&(delete n.ondtlsstatechange,delete n.onerror,delete this.transceivers[e].dtlsTransport)},p.prototype._transceive=function(e,r,i){var a=o(e.localCapabilities,e.remoteCapabilities);r&&e.rtpSender&&(a.encodings=e.sendEncodingParameters,a.rtcp={cname:n.localCName,compound:e.rtcpParameters.compound},e.recvEncodingParameters.length&&(a.rtcp.ssrc=e.recvEncodingParameters[0].ssrc),e.rtpSender.send(a)),i&&e.rtpReceiver&&a.codecs.length>0&&("video"===e.kind&&e.recvEncodingParameters&&t<15019&&e.recvEncodingParameters.forEach(function(e){delete e.rtx}),e.recvEncodingParameters.length?a.encodings=e.recvEncodingParameters:a.encodings=[{}],a.rtcp={compound:e.rtcpParameters.compound},e.rtcpParameters.cname&&(a.rtcp.cname=e.rtcpParameters.cname),e.sendEncodingParameters.length&&(a.rtcp.ssrc=e.sendEncodingParameters[0].ssrc),e.rtpReceiver.receive(a))},p.prototype.setLocalDescription=function(e){var t,r,i=this;if(-1===["offer","answer"].indexOf(e.type))return Promise.reject(d("TypeError",'Unsupported type "'+e.type+'"'));if(!a("setLocalDescription",e.type,i.signalingState)||i._isClosed)return Promise.reject(d("InvalidStateError","Can not set local "+e.type+" in state "+i.signalingState));if("offer"===e.type)t=n.splitSections(e.sdp),r=t.shift(),t.forEach(function(e,t){var r=n.parseRtpParameters(e);i.transceivers[t].localCapabilities=r}),i.transceivers.forEach(function(e,t){i._gather(e.mid,t)});else if("answer"===e.type){t=n.splitSections(i.remoteDescription.sdp),r=t.shift();var s=n.matchPrefix(r,"a=ice-lite").length>0;t.forEach(function(e,t){var a=i.transceivers[t],c=a.iceGatherer,d=a.iceTransport,u=a.dtlsTransport,p=a.localCapabilities,l=a.remoteCapabilities;if(!(n.isRejected(e)&&0===n.matchPrefix(e,"a=bundle-only").length)&&!a.rejected){var f=n.getIceParameters(e,r),m=n.getDtlsParameters(e,r);s&&(m.role="server"),i.usingBundle&&0!==t||(i._gather(a.mid,t),"new"===d.state&&d.start(c,f,s?"controlling":"controlled"),"new"===u.state&&u.start(m));var v=o(p,l);i._transceive(a,v.codecs.length>0,!1)}})}return i.localDescription={type:e.type,sdp:e.sdp},"offer"===e.type?i._updateSignalingState("have-local-offer"):i._updateSignalingState("stable"),Promise.resolve()},p.prototype.setRemoteDescription=function(i){var o=this;if(-1===["offer","answer"].indexOf(i.type))return Promise.reject(d("TypeError",'Unsupported type "'+i.type+'"'));if(!a("setRemoteDescription",i.type,o.signalingState)||o._isClosed)return Promise.reject(d("InvalidStateError","Can not set remote "+i.type+" in state "+o.signalingState));var s={};o.remoteStreams.forEach(function(e){s[e.id]=e});var p=[],l=n.splitSections(i.sdp),f=l.shift(),m=n.matchPrefix(f,"a=ice-lite").length>0,v=n.matchPrefix(f,"a=group:BUNDLE ").length>0;o.usingBundle=v;var h=n.matchPrefix(f,"a=ice-options:")[0];return o.canTrickleIceCandidates=!!h&&h.substr(14).split(" ").indexOf("trickle")>=0,l.forEach(function(a,d){var u=n.splitLines(a),l=n.getKind(a),h=n.isRejected(a)&&0===n.matchPrefix(a,"a=bundle-only").length,g=u[0].substr(2).split(" ")[2],C=n.getDirection(a,f),T=n.parseMsid(a),y=n.getMid(a)||n.generateIdentifier();if("application"===l&&"DTLS/SCTP"===g||h)o.transceivers[d]={mid:y,kind:l,rejected:!0};else{var S,E,R,P,_,b,O,k,w;!h&&o.transceivers[d]&&o.transceivers[d].rejected&&(o.transceivers[d]=o._createTransceiver(l,!0));var L,D,A=n.parseRtpParameters(a);h||(L=n.getIceParameters(a,f),(D=n.getDtlsParameters(a,f)).role="client"),O=n.parseRtpEncodingParameters(a);var M=n.parseRtcpParameters(a),x=n.matchPrefix(a,"a=end-of-candidates",f).length>0,I=n.matchPrefix(a,"a=candidate:").map(function(e){return n.parseCandidate(e)}).filter(function(e){return 1===e.component});if(("offer"===i.type||"answer"===i.type)&&!h&&v&&d>0&&o.transceivers[d]&&(o._disposeIceAndDtlsTransports(d),o.transceivers[d].iceGatherer=o.transceivers[0].iceGatherer,o.transceivers[d].iceTransport=o.transceivers[0].iceTransport,o.transceivers[d].dtlsTransport=o.transceivers[0].dtlsTransport,o.transceivers[d].rtpSender&&o.transceivers[d].rtpSender.setTransport(o.transceivers[0].dtlsTransport),o.transceivers[d].rtpReceiver&&o.transceivers[d].rtpReceiver.setTransport(o.transceivers[0].dtlsTransport)),"offer"!==i.type||h)"answer"!==i.type||h||(E=(S=o.transceivers[d]).iceGatherer,R=S.iceTransport,P=S.dtlsTransport,_=S.rtpReceiver,b=S.sendEncodingParameters,k=S.localCapabilities,o.transceivers[d].recvEncodingParameters=O,o.transceivers[d].remoteCapabilities=A,o.transceivers[d].rtcpParameters=M,I.length&&"new"===R.state&&(!m&&!x||v&&0!==d?I.forEach(function(e){c(S.iceTransport,e)}):R.setRemoteCandidates(I)),v&&0!==d||("new"===R.state&&R.start(E,L,"controlling"),"new"===P.state&&P.start(D)),o._transceive(S,"sendrecv"===C||"recvonly"===C,"sendrecv"===C||"sendonly"===C),!_||"sendrecv"!==C&&"sendonly"!==C?delete S.rtpReceiver:(w=_.track,T?(s[T.stream]||(s[T.stream]=new e.MediaStream),r(w,s[T.stream]),p.push([w,_,s[T.stream]])):(s.default||(s.default=new e.MediaStream),r(w,s.default),p.push([w,_,s.default]))));else{(S=o.transceivers[d]||o._createTransceiver(l)).mid=y,S.iceGatherer||(S.iceGatherer=o._createIceGatherer(d,v)),I.length&&"new"===S.iceTransport.state&&(!x||v&&0!==d?I.forEach(function(e){c(S.iceTransport,e)}):S.iceTransport.setRemoteCandidates(I)),k=e.RTCRtpReceiver.getCapabilities(l),t<15019&&(k.codecs=k.codecs.filter(function(e){return"rtx"!==e.name})),b=S.sendEncodingParameters||[{ssrc:1001*(2*d+2)}];var j,N=!1;if("sendrecv"===C||"sendonly"===C){if(N=!S.rtpReceiver,_=S.rtpReceiver||new e.RTCRtpReceiver(S.dtlsTransport,l),N)w=_.track,T&&"-"===T.stream||(T?(s[T.stream]||(s[T.stream]=new e.MediaStream,Object.defineProperty(s[T.stream],"id",{get:function(){return T.stream}})),Object.defineProperty(w,"id",{get:function(){return T.track}}),j=s[T.stream]):(s.default||(s.default=new e.MediaStream),j=s.default)),j&&(r(w,j),S.associatedRemoteMediaStreams.push(j)),p.push([w,_,j])}else S.rtpReceiver&&S.rtpReceiver.track&&(S.associatedRemoteMediaStreams.forEach(function(t){var r=t.getTracks().find(function(e){return e.id===S.rtpReceiver.track.id});r&&function(t,r){r.removeTrack(t),r.dispatchEvent(new e.MediaStreamTrackEvent("removetrack",{track:t}))}(r,t)}),S.associatedRemoteMediaStreams=[]);S.localCapabilities=k,S.remoteCapabilities=A,S.rtpReceiver=_,S.rtcpParameters=M,S.sendEncodingParameters=b,S.recvEncodingParameters=O,o._transceive(o.transceivers[d],!1,N)}}}),void 0===o._dtlsRole&&(o._dtlsRole="offer"===i.type?"active":"passive"),o.remoteDescription={type:i.type,sdp:i.sdp},"offer"===i.type?o._updateSignalingState("have-remote-offer"):o._updateSignalingState("stable"),Object.keys(s).forEach(function(t){var r=s[t];if(r.getTracks().length){if(-1===o.remoteStreams.indexOf(r)){o.remoteStreams.push(r);var n=new Event("addstream");n.stream=r,e.setTimeout(function(){o._dispatchEvent("addstream",n)})}p.forEach(function(e){var t=e[0],n=e[1];r.id===e[2].id&&u(o,t,n,[r])})}}),p.forEach(function(e){e[2]||u(o,e[0],e[1],[])}),e.setTimeout(function(){o&&o.transceivers&&o.transceivers.forEach(function(e){e.iceTransport&&"new"===e.iceTransport.state&&e.iceTransport.getRemoteCandidates().length>0&&(console.warn("Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification"),e.iceTransport.addRemoteCandidate({}))})},4e3),Promise.resolve()},p.prototype.close=function(){this.transceivers.forEach(function(e){e.iceTransport&&e.iceTransport.stop(),e.dtlsTransport&&e.dtlsTransport.stop(),e.rtpSender&&e.rtpSender.stop(),e.rtpReceiver&&e.rtpReceiver.stop()}),this._isClosed=!0,this._updateSignalingState("closed")},p.prototype._updateSignalingState=function(e){this.signalingState=e;var t=new Event("signalingstatechange");this._dispatchEvent("signalingstatechange",t)},p.prototype._maybeFireNegotiationNeeded=function(){var t=this;"stable"===this.signalingState&&!0!==this.needNegotiation&&(this.needNegotiation=!0,e.setTimeout(function(){if(t.needNegotiation){t.needNegotiation=!1;var e=new Event("negotiationneeded");t._dispatchEvent("negotiationneeded",e)}},0))},p.prototype._updateIceConnectionState=function(){var e,t={new:0,closed:0,checking:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(e){t[e.iceTransport.state]++}),e="new",t.failed>0?e="failed":t.checking>0?e="checking":t.disconnected>0?e="disconnected":t.new>0?e="new":t.connected>0?e="connected":t.completed>0&&(e="completed"),e!==this.iceConnectionState){this.iceConnectionState=e;var r=new Event("iceconnectionstatechange");this._dispatchEvent("iceconnectionstatechange",r)}},p.prototype._updateConnectionState=function(){var e,t={new:0,closed:0,connecting:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(e){t[e.iceTransport.state]++,t[e.dtlsTransport.state]++}),t.connected+=t.completed,e="new",t.failed>0?e="failed":t.connecting>0?e="connecting":t.disconnected>0?e="disconnected":t.new>0?e="new":t.connected>0&&(e="connected"),e!==this.connectionState){this.connectionState=e;var r=new Event("connectionstatechange");this._dispatchEvent("connectionstatechange",r)}},p.prototype.createOffer=function(){var r=this;if(r._isClosed)return Promise.reject(d("InvalidStateError","Can not call createOffer after close"));var o=r.transceivers.filter(function(e){return"audio"===e.kind}).length,a=r.transceivers.filter(function(e){return"video"===e.kind}).length,s=arguments[0];if(s){if(s.mandatory||s.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");void 0!==s.offerToReceiveAudio&&(o=!0===s.offerToReceiveAudio?1:!1===s.offerToReceiveAudio?0:s.offerToReceiveAudio),void 0!==s.offerToReceiveVideo&&(a=!0===s.offerToReceiveVideo?1:!1===s.offerToReceiveVideo?0:s.offerToReceiveVideo)}for(r.transceivers.forEach(function(e){"audio"===e.kind?--o<0&&(e.wantReceive=!1):"video"===e.kind&&--a<0&&(e.wantReceive=!1)});o>0||a>0;)o>0&&(r._createTransceiver("audio"),o--),a>0&&(r._createTransceiver("video"),a--);var c=n.writeSessionBoilerplate(r._sdpSessionId,r._sdpSessionVersion++);r.transceivers.forEach(function(i,o){var a=i.track,s=i.kind,c=i.mid||n.generateIdentifier();i.mid=c,i.iceGatherer||(i.iceGatherer=r._createIceGatherer(o,r.usingBundle));var d=e.RTCRtpSender.getCapabilities(s);t<15019&&(d.codecs=d.codecs.filter(function(e){return"rtx"!==e.name})),d.codecs.forEach(function(e){"H264"===e.name&&void 0===e.parameters["level-asymmetry-allowed"]&&(e.parameters["level-asymmetry-allowed"]="1"),i.remoteCapabilities&&i.remoteCapabilities.codecs&&i.remoteCapabilities.codecs.forEach(function(t){e.name.toLowerCase()===t.name.toLowerCase()&&e.clockRate===t.clockRate&&(e.preferredPayloadType=t.payloadType)})}),d.headerExtensions.forEach(function(e){(i.remoteCapabilities&&i.remoteCapabilities.headerExtensions||[]).forEach(function(t){e.uri===t.uri&&(e.id=t.id)})});var u=i.sendEncodingParameters||[{ssrc:1001*(2*o+1)}];a&&t>=15019&&"video"===s&&!u[0].rtx&&(u[0].rtx={ssrc:u[0].ssrc+1}),i.wantReceive&&(i.rtpReceiver=new e.RTCRtpReceiver(i.dtlsTransport,s)),i.localCapabilities=d,i.sendEncodingParameters=u}),"max-compat"!==r._config.bundlePolicy&&(c+="a=group:BUNDLE "+r.transceivers.map(function(e){return e.mid}).join(" ")+"\r\n"),c+="a=ice-options:trickle\r\n",r.transceivers.forEach(function(e,t){c+=i(e,e.localCapabilities,"offer",e.stream,r._dtlsRole),c+="a=rtcp-rsize\r\n",!e.iceGatherer||"new"===r.iceGatheringState||0!==t&&r.usingBundle||(e.iceGatherer.getLocalCandidates().forEach(function(e){e.component=1,c+="a="+n.writeCandidate(e)+"\r\n"}),"completed"===e.iceGatherer.state&&(c+="a=end-of-candidates\r\n"))});var u=new e.RTCSessionDescription({type:"offer",sdp:c});return Promise.resolve(u)},p.prototype.createAnswer=function(){var r=this;if(r._isClosed)return Promise.reject(d("InvalidStateError","Can not call createAnswer after close"));if("have-remote-offer"!==r.signalingState&&"have-local-pranswer"!==r.signalingState)return Promise.reject(d("InvalidStateError","Can not call createAnswer in signalingState "+r.signalingState));var a=n.writeSessionBoilerplate(r._sdpSessionId,r._sdpSessionVersion++);r.usingBundle&&(a+="a=group:BUNDLE "+r.transceivers.map(function(e){return e.mid}).join(" ")+"\r\n");var s=n.getMediaSections(r.remoteDescription.sdp).length;r.transceivers.forEach(function(e,n){if(!(n+1>s)){if(e.rejected)return"application"===e.kind?a+="m=application 0 DTLS/SCTP 5000\r\n":"audio"===e.kind?a+="m=audio 0 UDP/TLS/RTP/SAVPF 0\r\na=rtpmap:0 PCMU/8000\r\n":"video"===e.kind&&(a+="m=video 0 UDP/TLS/RTP/SAVPF 120\r\na=rtpmap:120 VP8/90000\r\n"),void(a+="c=IN IP4 0.0.0.0\r\na=inactive\r\na=mid:"+e.mid+"\r\n");var c;if(e.stream)"audio"===e.kind?c=e.stream.getAudioTracks()[0]:"video"===e.kind&&(c=e.stream.getVideoTracks()[0]),c&&t>=15019&&"video"===e.kind&&!e.sendEncodingParameters[0].rtx&&(e.sendEncodingParameters[0].rtx={ssrc:e.sendEncodingParameters[0].ssrc+1});var d=o(e.localCapabilities,e.remoteCapabilities);!d.codecs.filter(function(e){return"rtx"===e.name.toLowerCase()}).length&&e.sendEncodingParameters[0].rtx&&delete e.sendEncodingParameters[0].rtx,a+=i(e,d,"answer",e.stream,r._dtlsRole),e.rtcpParameters&&e.rtcpParameters.reducedSize&&(a+="a=rtcp-rsize\r\n")}});var c=new e.RTCSessionDescription({type:"answer",sdp:a});return Promise.resolve(c)},p.prototype.addIceCandidate=function(e){var t,r=this;return e&&void 0===e.sdpMLineIndex&&!e.sdpMid?Promise.reject(new TypeError("sdpMLineIndex or sdpMid required")):new Promise(function(i,o){if(!r.remoteDescription)return o(d("InvalidStateError","Can not add ICE candidate without a remote description"));if(e&&""!==e.candidate){var a=e.sdpMLineIndex;if(e.sdpMid)for(var s=0;s<r.transceivers.length;s++)if(r.transceivers[s].mid===e.sdpMid){a=s;break}var u=r.transceivers[a];if(!u)return o(d("OperationError","Can not add ICE candidate"));if(u.rejected)return i();var p=Object.keys(e.candidate).length>0?n.parseCandidate(e.candidate):{};if("tcp"===p.protocol&&(0===p.port||9===p.port))return i();if(p.component&&1!==p.component)return i();if((0===a||a>0&&u.iceTransport!==r.transceivers[0].iceTransport)&&!c(u.iceTransport,p))return o(d("OperationError","Can not add ICE candidate"));var l=e.candidate.trim();0===l.indexOf("a=")&&(l=l.substr(2)),(t=n.getMediaSections(r.remoteDescription.sdp))[a]+="a="+(p.type?l:"end-of-candidates")+"\r\n",r.remoteDescription.sdp=n.getDescription(r.remoteDescription.sdp)+t.join("")}else for(var f=0;f<r.transceivers.length&&(r.transceivers[f].rejected||(r.transceivers[f].iceTransport.addRemoteCandidate({}),(t=n.getMediaSections(r.remoteDescription.sdp))[f]+="a=end-of-candidates\r\n",r.remoteDescription.sdp=n.getDescription(r.remoteDescription.sdp)+t.join(""),!r.usingBundle));f++);i()})},p.prototype.getStats=function(){var e=[];this.transceivers.forEach(function(t){["rtpSender","rtpReceiver","iceGatherer","iceTransport","dtlsTransport"].forEach(function(r){t[r]&&e.push(t[r].getStats())})});return new Promise(function(t){var r=new Map;Promise.all(e).then(function(e){e.forEach(function(e){Object.keys(e).forEach(function(t){e[t].type=function(e){return{inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[e.type]||e.type}(e[t]),r.set(t,e[t])})}),t(r)})})};var l=["createOffer","createAnswer"];return l.forEach(function(e){var t=p.prototype[e];p.prototype[e]=function(){var e=arguments;return"function"==typeof e[0]||"function"==typeof e[1]?t.apply(this,[arguments[2]]).then(function(t){"function"==typeof e[0]&&e[0].apply(null,[t])},function(t){"function"==typeof e[1]&&e[1].apply(null,[t])}):t.apply(this,arguments)}}),(l=["setLocalDescription","setRemoteDescription","addIceCandidate"]).forEach(function(e){var t=p.prototype[e];p.prototype[e]=function(){var e=arguments;return"function"==typeof e[1]||"function"==typeof e[2]?t.apply(this,arguments).then(function(){"function"==typeof e[1]&&e[1].apply(null)},function(t){"function"==typeof e[2]&&e[2].apply(null,[t])}):t.apply(this,arguments)}}),["getStats"].forEach(function(e){var t=p.prototype[e];p.prototype[e]=function(){var e=arguments;return"function"==typeof e[1]?t.apply(this,arguments).then(function(){"function"==typeof e[1]&&e[1].apply(null)}):t.apply(this,arguments)}}),p}},{sdp:2}],2:[function(e,t,r){var n={generateIdentifier:function(){return Math.random().toString(36).substr(2,10)}};n.localCName=n.generateIdentifier(),n.splitLines=function(e){return e.trim().split("\n").map(function(e){return e.trim()})},n.splitSections=function(e){return e.split("\nm=").map(function(e,t){return(t>0?"m="+e:e).trim()+"\r\n"})},n.getDescription=function(e){var t=n.splitSections(e);return t&&t[0]},n.getMediaSections=function(e){var t=n.splitSections(e);return t.shift(),t},n.matchPrefix=function(e,t){return n.splitLines(e).filter(function(e){return 0===e.indexOf(t)})},n.parseCandidate=function(e){for(var t,r={foundation:(t=0===e.indexOf("a=candidate:")?e.substring(12).split(" "):e.substring(10).split(" "))[0],component:parseInt(t[1],10),protocol:t[2].toLowerCase(),priority:parseInt(t[3],10),ip:t[4],port:parseInt(t[5],10),type:t[7]},n=8;n<t.length;n+=2)switch(t[n]){case"raddr":r.relatedAddress=t[n+1];break;case"rport":r.relatedPort=parseInt(t[n+1],10);break;case"tcptype":r.tcpType=t[n+1];break;case"ufrag":r.ufrag=t[n+1],r.usernameFragment=t[n+1];break;default:r[t[n]]=t[n+1]}return r},n.writeCandidate=function(e){var t=[];t.push(e.foundation),t.push(e.component),t.push(e.protocol.toUpperCase()),t.push(e.priority),t.push(e.ip),t.push(e.port);var r=e.type;return t.push("typ"),t.push(r),"host"!==r&&e.relatedAddress&&e.relatedPort&&(t.push("raddr"),t.push(e.relatedAddress),t.push("rport"),t.push(e.relatedPort)),e.tcpType&&"tcp"===e.protocol.toLowerCase()&&(t.push("tcptype"),t.push(e.tcpType)),(e.usernameFragment||e.ufrag)&&(t.push("ufrag"),t.push(e.usernameFragment||e.ufrag)),"candidate:"+t.join(" ")},n.parseIceOptions=function(e){return e.substr(14).split(" ")},n.parseRtpMap=function(e){var t=e.substr(9).split(" "),r={payloadType:parseInt(t.shift(),10)};return t=t[0].split("/"),r.name=t[0],r.clockRate=parseInt(t[1],10),r.numChannels=3===t.length?parseInt(t[2],10):1,r},n.writeRtpMap=function(e){var t=e.payloadType;return void 0!==e.preferredPayloadType&&(t=e.preferredPayloadType),"a=rtpmap:"+t+" "+e.name+"/"+e.clockRate+(1!==e.numChannels?"/"+e.numChannels:"")+"\r\n"},n.parseExtmap=function(e){var t=e.substr(9).split(" ");return{id:parseInt(t[0],10),direction:t[0].indexOf("/")>0?t[0].split("/")[1]:"sendrecv",uri:t[1]}},n.writeExtmap=function(e){return"a=extmap:"+(e.id||e.preferredId)+(e.direction&&"sendrecv"!==e.direction?"/"+e.direction:"")+" "+e.uri+"\r\n"},n.parseFmtp=function(e){for(var t,r={},n=e.substr(e.indexOf(" ")+1).split(";"),i=0;i<n.length;i++)r[(t=n[i].trim().split("="))[0].trim()]=t[1];return r},n.writeFmtp=function(e){var t="",r=e.payloadType;if(void 0!==e.preferredPayloadType&&(r=e.preferredPayloadType),e.parameters&&Object.keys(e.parameters).length){var n=[];Object.keys(e.parameters).forEach(function(t){n.push(t+"="+e.parameters[t])}),t+="a=fmtp:"+r+" "+n.join(";")+"\r\n"}return t},n.parseRtcpFb=function(e){var t=e.substr(e.indexOf(" ")+1).split(" ");return{type:t.shift(),parameter:t.join(" ")}},n.writeRtcpFb=function(e){var t="",r=e.payloadType;return void 0!==e.preferredPayloadType&&(r=e.preferredPayloadType),e.rtcpFeedback&&e.rtcpFeedback.length&&e.rtcpFeedback.forEach(function(e){t+="a=rtcp-fb:"+r+" "+e.type+(e.parameter&&e.parameter.length?" "+e.parameter:"")+"\r\n"}),t},n.parseSsrcMedia=function(e){var t=e.indexOf(" "),r={ssrc:parseInt(e.substr(7,t-7),10)},n=e.indexOf(":",t);return n>-1?(r.attribute=e.substr(t+1,n-t-1),r.value=e.substr(n+1)):r.attribute=e.substr(t+1),r},n.getMid=function(e){var t=n.matchPrefix(e,"a=mid:")[0];if(t)return t.substr(6)},n.parseFingerprint=function(e){var t=e.substr(14).split(" ");return{algorithm:t[0].toLowerCase(),value:t[1]}},n.getDtlsParameters=function(e,t){return{role:"auto",fingerprints:n.matchPrefix(e+t,"a=fingerprint:").map(n.parseFingerprint)}},n.writeDtlsParameters=function(e,t){var r="a=setup:"+t+"\r\n";return e.fingerprints.forEach(function(e){r+="a=fingerprint:"+e.algorithm+" "+e.value+"\r\n"}),r},n.getIceParameters=function(e,t){var r=n.splitLines(e);return{usernameFragment:(r=r.concat(n.splitLines(t))).filter(function(e){return 0===e.indexOf("a=ice-ufrag:")})[0].substr(12),password:r.filter(function(e){return 0===e.indexOf("a=ice-pwd:")})[0].substr(10)}},n.writeIceParameters=function(e){return"a=ice-ufrag:"+e.usernameFragment+"\r\na=ice-pwd:"+e.password+"\r\n"},n.parseRtpParameters=function(e){for(var t={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},r=n.splitLines(e)[0].split(" "),i=3;i<r.length;i++){var o=r[i],a=n.matchPrefix(e,"a=rtpmap:"+o+" ")[0];if(a){var s=n.parseRtpMap(a),c=n.matchPrefix(e,"a=fmtp:"+o+" ");switch(s.parameters=c.length?n.parseFmtp(c[0]):{},s.rtcpFeedback=n.matchPrefix(e,"a=rtcp-fb:"+o+" ").map(n.parseRtcpFb),t.codecs.push(s),s.name.toUpperCase()){case"RED":case"ULPFEC":t.fecMechanisms.push(s.name.toUpperCase())}}}return n.matchPrefix(e,"a=extmap:").forEach(function(e){t.headerExtensions.push(n.parseExtmap(e))}),t},n.writeRtpDescription=function(e,t){var r="";r+="m="+e+" ",r+=t.codecs.length>0?"9":"0",r+=" UDP/TLS/RTP/SAVPF ",r+=t.codecs.map(function(e){return void 0!==e.preferredPayloadType?e.preferredPayloadType:e.payloadType}).join(" ")+"\r\n",r+="c=IN IP4 0.0.0.0\r\n",r+="a=rtcp:9 IN IP4 0.0.0.0\r\n",t.codecs.forEach(function(e){r+=n.writeRtpMap(e),r+=n.writeFmtp(e),r+=n.writeRtcpFb(e)});var i=0;return t.codecs.forEach(function(e){e.maxptime>i&&(i=e.maxptime)}),i>0&&(r+="a=maxptime:"+i+"\r\n"),r+="a=rtcp-mux\r\n",t.headerExtensions.forEach(function(e){r+=n.writeExtmap(e)}),r},n.parseRtpEncodingParameters=function(e){var t,r=[],i=n.parseRtpParameters(e),o=-1!==i.fecMechanisms.indexOf("RED"),a=-1!==i.fecMechanisms.indexOf("ULPFEC"),s=n.matchPrefix(e,"a=ssrc:").map(function(e){return n.parseSsrcMedia(e)}).filter(function(e){return"cname"===e.attribute}),c=s.length>0&&s[0].ssrc,d=n.matchPrefix(e,"a=ssrc-group:FID").map(function(e){var t=e.split(" ");return t.shift(),t.map(function(e){return parseInt(e,10)})});d.length>0&&d[0].length>1&&d[0][0]===c&&(t=d[0][1]),i.codecs.forEach(function(e){if("RTX"===e.name.toUpperCase()&&e.parameters.apt){var n={ssrc:c,codecPayloadType:parseInt(e.parameters.apt,10),rtx:{ssrc:t}};r.push(n),o&&((n=JSON.parse(JSON.stringify(n))).fec={ssrc:t,mechanism:a?"red+ulpfec":"red"},r.push(n))}}),0===r.length&&c&&r.push({ssrc:c});var u=n.matchPrefix(e,"b=");return u.length&&(u=0===u[0].indexOf("b=TIAS:")?parseInt(u[0].substr(7),10):0===u[0].indexOf("b=AS:")?1e3*parseInt(u[0].substr(5),10)*.95-16e3:void 0,r.forEach(function(e){e.maxBitrate=u})),r},n.parseRtcpParameters=function(e){var t={},r=n.matchPrefix(e,"a=ssrc:").map(function(e){return n.parseSsrcMedia(e)}).filter(function(e){return"cname"===e.attribute})[0];r&&(t.cname=r.value,t.ssrc=r.ssrc);var i=n.matchPrefix(e,"a=rtcp-rsize");t.reducedSize=i.length>0,t.compound=0===i.length;var o=n.matchPrefix(e,"a=rtcp-mux");return t.mux=o.length>0,t},n.parseMsid=function(e){var t,r=n.matchPrefix(e,"a=msid:");if(1===r.length)return{stream:(t=r[0].substr(7).split(" "))[0],track:t[1]};var i=n.matchPrefix(e,"a=ssrc:").map(function(e){return n.parseSsrcMedia(e)}).filter(function(e){return"msid"===e.attribute});return i.length>0?{stream:(t=i[0].value.split(" "))[0],track:t[1]}:void 0},n.generateSessionId=function(){return Math.random().toString().substr(2,21)},n.writeSessionBoilerplate=function(e,t){var r=void 0!==t?t:2;return"v=0\r\no=thisisadapterortc "+(e||n.generateSessionId())+" "+r+" IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n"},n.writeMediaSection=function(e,t,r,i){var o=n.writeRtpDescription(e.kind,t);if(o+=n.writeIceParameters(e.iceGatherer.getLocalParameters()),o+=n.writeDtlsParameters(e.dtlsTransport.getLocalParameters(),"offer"===r?"actpass":"active"),o+="a=mid:"+e.mid+"\r\n",e.direction?o+="a="+e.direction+"\r\n":e.rtpSender&&e.rtpReceiver?o+="a=sendrecv\r\n":e.rtpSender?o+="a=sendonly\r\n":e.rtpReceiver?o+="a=recvonly\r\n":o+="a=inactive\r\n",e.rtpSender){var a="msid:"+i.id+" "+e.rtpSender.track.id+"\r\n";o+="a="+a,o+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" "+a,e.sendEncodingParameters[0].rtx&&(o+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" "+a,o+="a=ssrc-group:FID "+e.sendEncodingParameters[0].ssrc+" "+e.sendEncodingParameters[0].rtx.ssrc+"\r\n")}return o+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" cname:"+n.localCName+"\r\n",e.rtpSender&&e.sendEncodingParameters[0].rtx&&(o+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" cname:"+n.localCName+"\r\n"),o},n.getDirection=function(e,t){for(var r=n.splitLines(e),i=0;i<r.length;i++)switch(r[i]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return r[i].substr(2)}return t?n.getDirection(t):"sendrecv"},n.getKind=function(e){return n.splitLines(e)[0].split(" ")[0].substr(2)},n.isRejected=function(e){return"0"===e.split(" ",2)[1]},n.parseMLine=function(e){var t=n.splitLines(e)[0].substr(2).split(" ");return{kind:t[0],port:parseInt(t[1],10),protocol:t[2],fmt:t.slice(3).join(" ")}},n.parseOLine=function(e){var t=n.matchPrefix(e,"o=")[0].substr(2).split(" ");return{username:t[0],sessionId:t[1],sessionVersion:parseInt(t[2],10),netType:t[3],addressType:t[4],address:t[5]}},"object"===(void 0===t?"undefined":c(t))&&(t.exports=n)},{}],3:[function(e,t,n){(function(r){var n=e("./adapter_factory.js");t.exports=n({window:r.window})}).call(this,void 0!==r?r:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./adapter_factory.js":4}],4:[function(e,t,r){var n=e("./utils");t.exports=function(t,r){var i=t&&t.window,o={shimChrome:!0,shimFirefox:!0,shimEdge:!0,shimSafari:!0};for(var a in r)hasOwnProperty.call(r,a)&&(o[a]=r[a]);var s=n.log,c=n.detectBrowser(i),d=e("./chrome/chrome_shim")||null,u=e("./edge/edge_shim")||null,p=e("./firefox/firefox_shim")||null,l=e("./safari/safari_shim")||null,f=e("./common_shim")||null,m={browserDetails:c,commonShim:f,extractVersion:n.extractVersion,disableLog:n.disableLog,disableWarnings:n.disableWarnings};switch(c.browser){case"chrome":if(!d||!d.shimPeerConnection||!o.shimChrome)return s("Chrome shim is not included in this adapter release."),m;s("adapter.js shimming chrome."),m.browserShim=d,f.shimCreateObjectURL(i),d.shimGetUserMedia(i),d.shimMediaStream(i),d.shimSourceObject(i),d.shimPeerConnection(i),d.shimOnTrack(i),d.shimAddTrackRemoveTrack(i),d.shimGetSendersWithDtmf(i),f.shimRTCIceCandidate(i),f.shimMaxMessageSize(i),f.shimSendThrowTypeError(i);break;case"firefox":if(!p||!p.shimPeerConnection||!o.shimFirefox)return s("Firefox shim is not included in this adapter release."),m;s("adapter.js shimming firefox."),m.browserShim=p,f.shimCreateObjectURL(i),p.shimGetUserMedia(i),p.shimSourceObject(i),p.shimPeerConnection(i),p.shimOnTrack(i),p.shimRemoveStream(i),f.shimRTCIceCandidate(i),f.shimMaxMessageSize(i),f.shimSendThrowTypeError(i);break;case"edge":if(!u||!u.shimPeerConnection||!o.shimEdge)return s("MS edge shim is not included in this adapter release."),m;s("adapter.js shimming edge."),m.browserShim=u,f.shimCreateObjectURL(i),u.shimGetUserMedia(i),u.shimPeerConnection(i),u.shimReplaceTrack(i),f.shimMaxMessageSize(i),f.shimSendThrowTypeError(i);break;case"safari":if(!l||!o.shimSafari)return s("Safari shim is not included in this adapter release."),m;s("adapter.js shimming safari."),m.browserShim=l,f.shimCreateObjectURL(i),l.shimRTCIceServerUrls(i),l.shimCallbacksAPI(i),l.shimLocalStreamsAPI(i),l.shimRemoteStreamsAPI(i),l.shimTrackEventTransceiver(i),l.shimGetUserMedia(i),l.shimCreateOfferLegacy(i),f.shimRTCIceCandidate(i),f.shimMaxMessageSize(i),f.shimSendThrowTypeError(i);break;default:s("Unsupported browser!")}return m}},{"./chrome/chrome_shim":5,"./common_shim":7,"./edge/edge_shim":8,"./firefox/firefox_shim":10,"./safari/safari_shim":12,"./utils":13}],5:[function(e,t,r){var n=e("../utils.js"),i=n.log;t.exports={shimGetUserMedia:e("./getusermedia"),shimMediaStream:function(e){e.MediaStream=e.MediaStream||e.webkitMediaStream},shimOnTrack:function(e){if("object"!==(void 0===e?"undefined":c(e))||!e.RTCPeerConnection||"ontrack"in e.RTCPeerConnection.prototype)"RTCRtpTransceiver"in e||n.wrapPeerConnectionEvent(e,"track",function(e){return e.transceiver||(e.transceiver={receiver:e.receiver}),e});else{Object.defineProperty(e.RTCPeerConnection.prototype,"ontrack",{get:function(){return this._ontrack},set:function(e){this._ontrack&&this.removeEventListener("track",this._ontrack),this.addEventListener("track",this._ontrack=e)}});var t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){var r=this;return r._ontrackpoly||(r._ontrackpoly=function(t){t.stream.addEventListener("addtrack",function(n){var i;i=e.RTCPeerConnection.prototype.getReceivers?r.getReceivers().find(function(e){return e.track&&e.track.id===n.track.id}):{track:n.track};var o=new Event("track");o.track=n.track,o.receiver=i,o.transceiver={receiver:i},o.streams=[t.stream],r.dispatchEvent(o)}),t.stream.getTracks().forEach(function(n){var i;i=e.RTCPeerConnection.prototype.getReceivers?r.getReceivers().find(function(e){return e.track&&e.track.id===n.id}):{track:n};var o=new Event("track");o.track=n,o.receiver=i,o.transceiver={receiver:i},o.streams=[t.stream],r.dispatchEvent(o)})},r.addEventListener("addstream",r._ontrackpoly)),t.apply(r,arguments)}}},shimGetSendersWithDtmf:function(e){if("object"===(void 0===e?"undefined":c(e))&&e.RTCPeerConnection&&!("getSenders"in e.RTCPeerConnection.prototype)&&"createDTMFSender"in e.RTCPeerConnection.prototype){var t=function(e,t){return{track:t,get dtmf(){return void 0===this._dtmf&&("audio"===t.kind?this._dtmf=e.createDTMFSender(t):this._dtmf=null),this._dtmf},_pc:e}};if(!e.RTCPeerConnection.prototype.getSenders){e.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};var r=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,n){var i=r.apply(this,arguments);return i||(i=t(this,e),this._senders.push(i)),i};var n=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){n.apply(this,arguments);var t=this._senders.indexOf(e);-1!==t&&this._senders.splice(t,1)}}var i=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(e){var r=this;r._senders=r._senders||[],i.apply(r,[e]),e.getTracks().forEach(function(e){r._senders.push(t(r,e))})};var o=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){var t=this;t._senders=t._senders||[],o.apply(t,[e]),e.getTracks().forEach(function(e){var r=t._senders.find(function(t){return t.track===e});r&&t._senders.splice(t._senders.indexOf(r),1)})}}else if("object"===(void 0===e?"undefined":c(e))&&e.RTCPeerConnection&&"getSenders"in e.RTCPeerConnection.prototype&&"createDTMFSender"in e.RTCPeerConnection.prototype&&e.RTCRtpSender&&!("dtmf"in e.RTCRtpSender.prototype)){var a=e.RTCPeerConnection.prototype.getSenders;e.RTCPeerConnection.prototype.getSenders=function(){var e=this,t=a.apply(e,[]);return t.forEach(function(t){t._pc=e}),t},Object.defineProperty(e.RTCRtpSender.prototype,"dtmf",{get:function(){return void 0===this._dtmf&&("audio"===this.track.kind?this._dtmf=this._pc.createDTMFSender(this.track):this._dtmf=null),this._dtmf}})}},shimSourceObject:function(e){var t=e&&e.URL;"object"===(void 0===e?"undefined":c(e))&&(!e.HTMLMediaElement||"srcObject"in e.HTMLMediaElement.prototype||Object.defineProperty(e.HTMLMediaElement.prototype,"srcObject",{get:function(){return this._srcObject},set:function(e){var r=this;this._srcObject=e,this.src&&t.revokeObjectURL(this.src),e?(this.src=t.createObjectURL(e),e.addEventListener("addtrack",function(){r.src&&t.revokeObjectURL(r.src),r.src=t.createObjectURL(e)}),e.addEventListener("removetrack",function(){r.src&&t.revokeObjectURL(r.src),r.src=t.createObjectURL(e)})):this.src=""}}))},shimAddTrackRemoveTrackWithNative:function(e){e.RTCPeerConnection.prototype.getLocalStreams=function(){var e=this;return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map(function(t){return e._shimmedLocalStreams[t][0]})};var t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,r){if(!r)return t.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};var n=t.apply(this,arguments);return this._shimmedLocalStreams[r.id]?-1===this._shimmedLocalStreams[r.id].indexOf(n)&&this._shimmedLocalStreams[r.id].push(n):this._shimmedLocalStreams[r.id]=[r,n],n};var r=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(e){var t=this;this._shimmedLocalStreams=this._shimmedLocalStreams||{},e.getTracks().forEach(function(e){if(t.getSenders().find(function(t){return t.track===e}))throw new DOMException("Track already exists.","InvalidAccessError")});var n=t.getSenders();r.apply(this,arguments);var i=t.getSenders().filter(function(e){return-1===n.indexOf(e)});this._shimmedLocalStreams[e.id]=[e].concat(i)};var n=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[e.id],n.apply(this,arguments)};var i=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){var t=this;return this._shimmedLocalStreams=this._shimmedLocalStreams||{},e&&Object.keys(this._shimmedLocalStreams).forEach(function(r){var n=t._shimmedLocalStreams[r].indexOf(e);-1!==n&&t._shimmedLocalStreams[r].splice(n,1),1===t._shimmedLocalStreams[r].length&&delete t._shimmedLocalStreams[r]}),i.apply(this,arguments)}},shimAddTrackRemoveTrack:function(e){var t=n.detectBrowser(e);if(e.RTCPeerConnection.prototype.addTrack&&t.version>=65)return this.shimAddTrackRemoveTrackWithNative(e);var r=e.RTCPeerConnection.prototype.getLocalStreams;e.RTCPeerConnection.prototype.getLocalStreams=function(){var e=this,t=r.apply(this);return e._reverseStreams=e._reverseStreams||{},t.map(function(t){return e._reverseStreams[t.id]})};var i=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(t){var r=this;if(r._streams=r._streams||{},r._reverseStreams=r._reverseStreams||{},t.getTracks().forEach(function(e){if(r.getSenders().find(function(t){return t.track===e}))throw new DOMException("Track already exists.","InvalidAccessError")}),!r._reverseStreams[t.id]){var n=new e.MediaStream(t.getTracks());r._streams[t.id]=n,r._reverseStreams[n.id]=t,t=n}i.apply(r,[t])};var o=e.RTCPeerConnection.prototype.removeStream;function a(e,t){var r=t.sdp;return Object.keys(e._reverseStreams||[]).forEach(function(t){var n=e._reverseStreams[t],i=e._streams[n.id];r=r.replace(new RegExp(i.id,"g"),n.id)}),new RTCSessionDescription({type:t.type,sdp:r})}e.RTCPeerConnection.prototype.removeStream=function(e){var t=this;t._streams=t._streams||{},t._reverseStreams=t._reverseStreams||{},o.apply(t,[t._streams[e.id]||e]),delete t._reverseStreams[t._streams[e.id]?t._streams[e.id].id:e.id],delete t._streams[e.id]},e.RTCPeerConnection.prototype.addTrack=function(t,r){var n=this;if("closed"===n.signalingState)throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");var i=[].slice.call(arguments,1);if(1!==i.length||!i[0].getTracks().find(function(e){return e===t}))throw new DOMException("The adapter.js addTrack polyfill only supports a single stream which is associated with the specified track.","NotSupportedError");if(n.getSenders().find(function(e){return e.track===t}))throw new DOMException("Track already exists.","InvalidAccessError");n._streams=n._streams||{},n._reverseStreams=n._reverseStreams||{};var o=n._streams[r.id];if(o)o.addTrack(t),Promise.resolve().then(function(){n.dispatchEvent(new Event("negotiationneeded"))});else{var a=new e.MediaStream([t]);n._streams[r.id]=a,n._reverseStreams[a.id]=r,n.addStream(a)}return n.getSenders().find(function(e){return e.track===t})},["createOffer","createAnswer"].forEach(function(t){var r=e.RTCPeerConnection.prototype[t];e.RTCPeerConnection.prototype[t]=function(){var e=this,t=arguments;return arguments.length&&"function"==typeof arguments[0]?r.apply(e,[function(r){var n=a(e,r);t[0].apply(null,[n])},function(e){t[1]&&t[1].apply(null,e)},arguments[2]]):r.apply(e,arguments).then(function(t){return a(e,t)})}});var s=e.RTCPeerConnection.prototype.setLocalDescription;e.RTCPeerConnection.prototype.setLocalDescription=function(){return arguments.length&&arguments[0].type?(arguments[0]=function(e,t){var r=t.sdp;return Object.keys(e._reverseStreams||[]).forEach(function(t){var n=e._reverseStreams[t],i=e._streams[n.id];r=r.replace(new RegExp(n.id,"g"),i.id)}),new RTCSessionDescription({type:t.type,sdp:r})}(this,arguments[0]),s.apply(this,arguments)):s.apply(this,arguments)};var c=Object.getOwnPropertyDescriptor(e.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(e.RTCPeerConnection.prototype,"localDescription",{get:function(){var e=c.get.apply(this);return""===e.type?e:a(this,e)}}),e.RTCPeerConnection.prototype.removeTrack=function(e){var t,r=this;if("closed"===r.signalingState)throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");if(!e._pc)throw new DOMException("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.","TypeError");if(!(e._pc===r))throw new DOMException("Sender was not created by this connection.","InvalidAccessError");r._streams=r._streams||{},Object.keys(r._streams).forEach(function(n){r._streams[n].getTracks().find(function(t){return e.track===t})&&(t=r._streams[n])}),t&&(1===t.getTracks().length?r.removeStream(r._reverseStreams[t.id]):t.removeTrack(e.track),r.dispatchEvent(new Event("negotiationneeded")))}},shimPeerConnection:function(e){var t=n.detectBrowser(e);if(!e.RTCPeerConnection&&e.webkitRTCPeerConnection)e.RTCPeerConnection=function(t,r){return i("PeerConnection"),t&&t.iceTransportPolicy&&(t.iceTransports=t.iceTransportPolicy),new e.webkitRTCPeerConnection(t,r)},e.RTCPeerConnection.prototype=e.webkitRTCPeerConnection.prototype,e.webkitRTCPeerConnection.generateCertificate&&Object.defineProperty(e.RTCPeerConnection,"generateCertificate",{get:function(){return e.webkitRTCPeerConnection.generateCertificate}});else{var r=e.RTCPeerConnection;e.RTCPeerConnection=function(e,t){if(e&&e.iceServers){for(var i=[],o=0;o<e.iceServers.length;o++){var a=e.iceServers[o];!a.hasOwnProperty("urls")&&a.hasOwnProperty("url")?(n.deprecated("RTCIceServer.url","RTCIceServer.urls"),(a=JSON.parse(JSON.stringify(a))).urls=a.url,i.push(a)):i.push(e.iceServers[o])}e.iceServers=i}return new r(e,t)},e.RTCPeerConnection.prototype=r.prototype,Object.defineProperty(e.RTCPeerConnection,"generateCertificate",{get:function(){return r.generateCertificate}})}var o=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(e,t,r){var n=this,i=arguments;if(arguments.length>0&&"function"==typeof e)return o.apply(this,arguments);if(0===o.length&&(0===arguments.length||"function"!=typeof arguments[0]))return o.apply(this,[]);var a=function(e){var t={};return e.result().forEach(function(e){var r={id:e.id,timestamp:e.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[e.type]||e.type};e.names().forEach(function(t){r[t]=e.stat(t)}),t[r.id]=r}),t},s=function(e){return new Map(Object.keys(e).map(function(t){return[t,e[t]]}))};if(arguments.length>=2){return o.apply(this,[function(e){i[1](s(a(e)))},arguments[0]])}return new Promise(function(e,t){o.apply(n,[function(t){e(s(a(t)))},t])}).then(t,r)},t.version<51&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(t){var r=e.RTCPeerConnection.prototype[t];e.RTCPeerConnection.prototype[t]=function(){var e=arguments,t=this,n=new Promise(function(n,i){r.apply(t,[e[0],n,i])});return e.length<2?n:n.then(function(){e[1].apply(null,[])},function(t){e.length>=3&&e[2].apply(null,[t])})}}),t.version<52&&["createOffer","createAnswer"].forEach(function(t){var r=e.RTCPeerConnection.prototype[t];e.RTCPeerConnection.prototype[t]=function(){var e=this;if(arguments.length<1||1===arguments.length&&"object"===c(arguments[0])){var t=1===arguments.length?arguments[0]:void 0;return new Promise(function(n,i){r.apply(e,[n,i,t])})}return r.apply(this,arguments)}}),["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(t){var r=e.RTCPeerConnection.prototype[t];e.RTCPeerConnection.prototype[t]=function(){return arguments[0]=new("addIceCandidate"===t?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),r.apply(this,arguments)}});var a=e.RTCPeerConnection.prototype.addIceCandidate;e.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?a.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())}}}},{"../utils.js":13,"./getusermedia":6}],6:[function(e,t,r){var n=e("../utils.js"),i=n.log;t.exports=function(e){var t=n.detectBrowser(e),r=e&&e.navigator,o=function(e){if("object"!==(void 0===e?"undefined":c(e))||e.mandatory||e.optional)return e;var t={};return Object.keys(e).forEach(function(r){if("require"!==r&&"advanced"!==r&&"mediaSource"!==r){var n="object"===c(e[r])?e[r]:{ideal:e[r]};void 0!==n.exact&&"number"==typeof n.exact&&(n.min=n.max=n.exact);var i=function(e,t){return e?e+t.charAt(0).toUpperCase()+t.slice(1):"deviceId"===t?"sourceId":t};if(void 0!==n.ideal){t.optional=t.optional||[];var o={};"number"==typeof n.ideal?(o[i("min",r)]=n.ideal,t.optional.push(o),(o={})[i("max",r)]=n.ideal,t.optional.push(o)):(o[i("",r)]=n.ideal,t.optional.push(o))}void 0!==n.exact&&"number"!=typeof n.exact?(t.mandatory=t.mandatory||{},t.mandatory[i("",r)]=n.exact):["min","max"].forEach(function(e){void 0!==n[e]&&(t.mandatory=t.mandatory||{},t.mandatory[i(e,r)]=n[e])})}}),e.advanced&&(t.optional=(t.optional||[]).concat(e.advanced)),t},a=function(e,n){if(t.version>=61)return n(e);if((e=JSON.parse(JSON.stringify(e)))&&"object"===c(e.audio)){var a=function(e,t,r){t in e&&!(r in e)&&(e[r]=e[t],delete e[t])};a((e=JSON.parse(JSON.stringify(e))).audio,"autoGainControl","googAutoGainControl"),a(e.audio,"noiseSuppression","googNoiseSuppression"),e.audio=o(e.audio)}if(e&&"object"===c(e.video)){var s=e.video.facingMode;s=s&&("object"===(void 0===s?"undefined":c(s))?s:{ideal:s});var d,u=t.version<66;if(s&&("user"===s.exact||"environment"===s.exact||"user"===s.ideal||"environment"===s.ideal)&&(!r.mediaDevices.getSupportedConstraints||!r.mediaDevices.getSupportedConstraints().facingMode||u))if(delete e.video.facingMode,"environment"===s.exact||"environment"===s.ideal?d=["back","rear"]:"user"!==s.exact&&"user"!==s.ideal||(d=["front"]),d)return r.mediaDevices.enumerateDevices().then(function(t){var r=(t=t.filter(function(e){return"videoinput"===e.kind})).find(function(e){return d.some(function(t){return-1!==e.label.toLowerCase().indexOf(t)})});return!r&&t.length&&-1!==d.indexOf("back")&&(r=t[t.length-1]),r&&(e.video.deviceId=s.exact?{exact:r.deviceId}:{ideal:r.deviceId}),e.video=o(e.video),i("chrome: "+JSON.stringify(e)),n(e)});e.video=o(e.video)}return i("chrome: "+JSON.stringify(e)),n(e)},s=function(e){return{name:{PermissionDeniedError:"NotAllowedError",PermissionDismissedError:"NotAllowedError",InvalidStateError:"NotAllowedError",DevicesNotFoundError:"NotFoundError",ConstraintNotSatisfiedError:"OverconstrainedError",TrackStartError:"NotReadableError",MediaDeviceFailedDueToShutdown:"NotAllowedError",MediaDeviceKillSwitchOn:"NotAllowedError",TabCaptureError:"AbortError",ScreenCaptureError:"AbortError",DeviceCaptureError:"AbortError"}[e.name]||e.name,message:e.message,constraint:e.constraintName,toString:function(){return this.name+(this.message&&": ")+this.message}}};r.getUserMedia=function(e,t,n){a(e,function(e){r.webkitGetUserMedia(e,t,function(e){n&&n(s(e))})})};var d=function(e){return new Promise(function(t,n){r.getUserMedia(e,t,n)})};if(r.mediaDevices||(r.mediaDevices={getUserMedia:d,enumerateDevices:function(){return new Promise(function(t){var r={audio:"audioinput",video:"videoinput"};return e.MediaStreamTrack.getSources(function(e){t(e.map(function(e){return{label:e.label,kind:r[e.kind],deviceId:e.id,groupId:""}}))})})},getSupportedConstraints:function(){return{deviceId:!0,echoCancellation:!0,facingMode:!0,frameRate:!0,height:!0,width:!0}}}),r.mediaDevices.getUserMedia){var u=r.mediaDevices.getUserMedia.bind(r.mediaDevices);r.mediaDevices.getUserMedia=function(e){return a(e,function(e){return u(e).then(function(t){if(e.audio&&!t.getAudioTracks().length||e.video&&!t.getVideoTracks().length)throw t.getTracks().forEach(function(e){e.stop()}),new DOMException("","NotFoundError");return t},function(e){return Promise.reject(s(e))})})}}else r.mediaDevices.getUserMedia=function(e){return d(e)};void 0===r.mediaDevices.addEventListener&&(r.mediaDevices.addEventListener=function(){i("Dummy mediaDevices.addEventListener called.")}),void 0===r.mediaDevices.removeEventListener&&(r.mediaDevices.removeEventListener=function(){i("Dummy mediaDevices.removeEventListener called.")})}},{"../utils.js":13}],7:[function(e,t,r){var n=e("sdp"),i=e("./utils");t.exports={shimRTCIceCandidate:function(e){if(e.RTCIceCandidate&&!(e.RTCIceCandidate&&"foundation"in e.RTCIceCandidate.prototype)){var t=e.RTCIceCandidate;e.RTCIceCandidate=function(e){if("object"===(void 0===e?"undefined":c(e))&&e.candidate&&0===e.candidate.indexOf("a=")&&((e=JSON.parse(JSON.stringify(e))).candidate=e.candidate.substr(2)),e.candidate&&e.candidate.length){var r=new t(e),i=n.parseCandidate(e.candidate),o=s(r,i);return o.toJSON=function(){return{candidate:o.candidate,sdpMid:o.sdpMid,sdpMLineIndex:o.sdpMLineIndex,usernameFragment:o.usernameFragment}},o}return new t(e)},e.RTCIceCandidate.prototype=t.prototype,i.wrapPeerConnectionEvent(e,"icecandidate",function(t){return t.candidate&&Object.defineProperty(t,"candidate",{value:new e.RTCIceCandidate(t.candidate),writable:"false"}),t})}},shimCreateObjectURL:function(e){var t=e&&e.URL;if("object"===(void 0===e?"undefined":c(e))&&e.HTMLMediaElement&&"srcObject"in e.HTMLMediaElement.prototype&&t.createObjectURL&&t.revokeObjectURL){var r=t.createObjectURL.bind(t),n=t.revokeObjectURL.bind(t),o=new Map,a=0;t.createObjectURL=function(e){if("getTracks"in e){var t="polyblob:"+ ++a;return o.set(t,e),i.deprecated("URL.createObjectURL(stream)","elem.srcObject = stream"),t}return r(e)},t.revokeObjectURL=function(e){n(e),o.delete(e)};var s=Object.getOwnPropertyDescriptor(e.HTMLMediaElement.prototype,"src");Object.defineProperty(e.HTMLMediaElement.prototype,"src",{get:function(){return s.get.apply(this)},set:function(e){return this.srcObject=o.get(e)||null,s.set.apply(this,[e])}});var d=e.HTMLMediaElement.prototype.setAttribute;e.HTMLMediaElement.prototype.setAttribute=function(){return 2===arguments.length&&"src"===(""+arguments[0]).toLowerCase()&&(this.srcObject=o.get(arguments[1])||null),d.apply(this,arguments)}}},shimMaxMessageSize:function(e){if(!e.RTCSctpTransport&&e.RTCPeerConnection){var t=i.detectBrowser(e);"sctp"in e.RTCPeerConnection.prototype||Object.defineProperty(e.RTCPeerConnection.prototype,"sctp",{get:function(){return void 0===this._sctp?null:this._sctp}});var r=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,function(e){var t=n.splitSections(e.sdp);return t.shift(),t.some(function(e){var t=n.parseMLine(e);return t&&"application"===t.kind&&-1!==t.protocol.indexOf("SCTP")})}(arguments[0])){var e,i=function(e){var t=e.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(null===t||t.length<2)return-1;var r=parseInt(t[1],10);return r!=r?-1:r}(arguments[0]),o=function(e){var r=65536;return"firefox"===t.browser&&(r=t.version<57?-1===e?16384:2147483637:57===t.version?65535:65536),r}(i),a=function(e,r){var i=65536;"firefox"===t.browser&&57===t.version&&(i=65535);var o=n.matchPrefix(e.sdp,"a=max-message-size:");return o.length>0?i=parseInt(o[0].substr(19),10):"firefox"===t.browser&&-1!==r&&(i=2147483637),i}(arguments[0],i);e=0===o&&0===a?Number.POSITIVE_INFINITY:0===o||0===a?Math.max(o,a):Math.min(o,a);var s={};Object.defineProperty(s,"maxMessageSize",{get:function(){return e}}),this._sctp=s}return r.apply(this,arguments)}}},shimSendThrowTypeError:function(e){if(e.RTCPeerConnection&&"createDataChannel"in e.RTCPeerConnection.prototype){var t=e.RTCPeerConnection.prototype.createDataChannel;e.RTCPeerConnection.prototype.createDataChannel=function(){var e=this,r=t.apply(e,arguments),n=r.send;return r.send=function(){var t=arguments[0];if((t.length||t.size||t.byteLength)>e.sctp.maxMessageSize)throw new DOMException("Message too large (can send a maximum of "+e.sctp.maxMessageSize+" bytes)","TypeError");return n.apply(this,arguments)},r}}}}},{"./utils":13,sdp:2}],8:[function(e,t,r){var n=e("../utils"),i=e("rtcpeerconnection-shim");t.exports={shimGetUserMedia:e("./getusermedia"),shimPeerConnection:function(e){var t=n.detectBrowser(e);if(e.RTCIceGatherer&&(e.RTCIceCandidate||(e.RTCIceCandidate=function(e){return e}),e.RTCSessionDescription||(e.RTCSessionDescription=function(e){return e}),t.version<15025)){var r=Object.getOwnPropertyDescriptor(e.MediaStreamTrack.prototype,"enabled");Object.defineProperty(e.MediaStreamTrack.prototype,"enabled",{set:function(e){r.set.call(this,e);var t=new Event("enabled");t.enabled=e,this.dispatchEvent(t)}})}!e.RTCRtpSender||"dtmf"in e.RTCRtpSender.prototype||Object.defineProperty(e.RTCRtpSender.prototype,"dtmf",{get:function(){return void 0===this._dtmf&&("audio"===this.track.kind?this._dtmf=new e.RTCDtmfSender(this):"video"===this.track.kind&&(this._dtmf=null)),this._dtmf}}),e.RTCDtmfSender&&!e.RTCDTMFSender&&(e.RTCDTMFSender=e.RTCDtmfSender),e.RTCPeerConnection=i(e,t.version)},shimReplaceTrack:function(e){!e.RTCRtpSender||"replaceTrack"in e.RTCRtpSender.prototype||(e.RTCRtpSender.prototype.replaceTrack=e.RTCRtpSender.prototype.setTrack)}}},{"../utils":13,"./getusermedia":9,"rtcpeerconnection-shim":1}],9:[function(e,t,r){t.exports=function(e){var t=e&&e.navigator,r=t.mediaDevices.getUserMedia.bind(t.mediaDevices);t.mediaDevices.getUserMedia=function(e){return r(e).catch(function(e){return Promise.reject(function(e){return{name:{PermissionDeniedError:"NotAllowedError"}[e.name]||e.name,message:e.message,constraint:e.constraint,toString:function(){return this.name}}}(e))})}}},{}],10:[function(e,t,r){var n=e("../utils");t.exports={shimGetUserMedia:e("./getusermedia"),shimOnTrack:function(e){"object"!==(void 0===e?"undefined":c(e))||!e.RTCPeerConnection||"ontrack"in e.RTCPeerConnection.prototype||Object.defineProperty(e.RTCPeerConnection.prototype,"ontrack",{get:function(){return this._ontrack},set:function(e){this._ontrack&&(this.removeEventListener("track",this._ontrack),this.removeEventListener("addstream",this._ontrackpoly)),this.addEventListener("track",this._ontrack=e),this.addEventListener("addstream",this._ontrackpoly=function(e){e.stream.getTracks().forEach(function(t){var r=new Event("track");r.track=t,r.receiver={track:t},r.transceiver={receiver:r.receiver},r.streams=[e.stream],this.dispatchEvent(r)}.bind(this))}.bind(this))}}),"object"===(void 0===e?"undefined":c(e))&&e.RTCTrackEvent&&"receiver"in e.RTCTrackEvent.prototype&&!("transceiver"in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,"transceiver",{get:function(){return{receiver:this.receiver}}})},shimSourceObject:function(e){"object"===(void 0===e?"undefined":c(e))&&(!e.HTMLMediaElement||"srcObject"in e.HTMLMediaElement.prototype||Object.defineProperty(e.HTMLMediaElement.prototype,"srcObject",{get:function(){return this.mozSrcObject},set:function(e){this.mozSrcObject=e}}))},shimPeerConnection:function(e){var t=n.detectBrowser(e);if("object"===(void 0===e?"undefined":c(e))&&(e.RTCPeerConnection||e.mozRTCPeerConnection)){e.RTCPeerConnection||(e.RTCPeerConnection=function(r,n){if(t.version<38&&r&&r.iceServers){for(var i=[],o=0;o<r.iceServers.length;o++){var a=r.iceServers[o];if(a.hasOwnProperty("urls"))for(var s=0;s<a.urls.length;s++){var c={url:a.urls[s]};0===a.urls[s].indexOf("turn")&&(c.username=a.username,c.credential=a.credential),i.push(c)}else i.push(r.iceServers[o])}r.iceServers=i}return new e.mozRTCPeerConnection(r,n)},e.RTCPeerConnection.prototype=e.mozRTCPeerConnection.prototype,e.mozRTCPeerConnection.generateCertificate&&Object.defineProperty(e.RTCPeerConnection,"generateCertificate",{get:function(){return e.mozRTCPeerConnection.generateCertificate}}),e.RTCSessionDescription=e.mozRTCSessionDescription,e.RTCIceCandidate=e.mozRTCIceCandidate),["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(t){var r=e.RTCPeerConnection.prototype[t];e.RTCPeerConnection.prototype[t]=function(){return arguments[0]=new("addIceCandidate"===t?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),r.apply(this,arguments)}});var r=e.RTCPeerConnection.prototype.addIceCandidate;e.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?r.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())};var i={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},o=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(e,r,n){return o.apply(this,[e||null]).then(function(e){if(t.version<48&&(e=function(e){var t=new Map;return Object.keys(e).forEach(function(r){t.set(r,e[r]),t[r]=e[r]}),t}(e)),t.version<53&&!r)try{e.forEach(function(e){e.type=i[e.type]||e.type})}catch(t){if("TypeError"!==t.name)throw t;e.forEach(function(t,r){e.set(r,s({},t,{type:i[t.type]||t.type}))})}return e}).then(r,n)}}},shimRemoveStream:function(e){!e.RTCPeerConnection||"removeStream"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.removeStream=function(e){var t=this;n.deprecated("removeStream","removeTrack"),this.getSenders().forEach(function(r){r.track&&-1!==e.getTracks().indexOf(r.track)&&t.removeTrack(r)})})}}},{"../utils":13,"./getusermedia":11}],11:[function(e,t,r){var n=e("../utils"),i=n.log;t.exports=function(e){var t=n.detectBrowser(e),r=e&&e.navigator,o=e&&e.MediaStreamTrack,a=function(e){return{name:{InternalError:"NotReadableError",NotSupportedError:"TypeError",PermissionDeniedError:"NotAllowedError",SecurityError:"NotAllowedError"}[e.name]||e.name,message:{"The operation is insecure.":"The request is not allowed by the user agent or the platform in the current context."}[e.message]||e.message,constraint:e.constraint,toString:function(){return this.name+(this.message&&": ")+this.message}}},s=function(e,n,o){var s=function(e){if("object"!==(void 0===e?"undefined":c(e))||e.require)return e;var t=[];return Object.keys(e).forEach(function(r){if("require"!==r&&"advanced"!==r&&"mediaSource"!==r){var n=e[r]="object"===c(e[r])?e[r]:{ideal:e[r]};if(void 0===n.min&&void 0===n.max&&void 0===n.exact||t.push(r),void 0!==n.exact&&("number"==typeof n.exact?n.min=n.max=n.exact:e[r]=n.exact,delete n.exact),void 0!==n.ideal){e.advanced=e.advanced||[];var i={};"number"==typeof n.ideal?i[r]={min:n.ideal,max:n.ideal}:i[r]=n.ideal,e.advanced.push(i),delete n.ideal,Object.keys(n).length||delete e[r]}}}),t.length&&(e.require=t),e};return e=JSON.parse(JSON.stringify(e)),t.version<38&&(i("spec: "+JSON.stringify(e)),e.audio&&(e.audio=s(e.audio)),e.video&&(e.video=s(e.video)),i("ff37: "+JSON.stringify(e))),r.mozGetUserMedia(e,n,function(e){o(a(e))})};if(r.mediaDevices||(r.mediaDevices={getUserMedia:function(e){return new Promise(function(t,r){s(e,t,r)})},addEventListener:function(){},removeEventListener:function(){}}),r.mediaDevices.enumerateDevices=r.mediaDevices.enumerateDevices||function(){return new Promise(function(e){e([{kind:"audioinput",deviceId:"default",label:"",groupId:""},{kind:"videoinput",deviceId:"default",label:"",groupId:""}])})},t.version<41){var d=r.mediaDevices.enumerateDevices.bind(r.mediaDevices);r.mediaDevices.enumerateDevices=function(){return d().then(void 0,function(e){if("NotFoundError"===e.name)return[];throw e})}}if(t.version<49){var u=r.mediaDevices.getUserMedia.bind(r.mediaDevices);r.mediaDevices.getUserMedia=function(e){return u(e).then(function(t){if(e.audio&&!t.getAudioTracks().length||e.video&&!t.getVideoTracks().length)throw t.getTracks().forEach(function(e){e.stop()}),new DOMException("The object can not be found here.","NotFoundError");return t},function(e){return Promise.reject(a(e))})}}if(!(t.version>55&&"autoGainControl"in r.mediaDevices.getSupportedConstraints())){var p=function(e,t,r){t in e&&!(r in e)&&(e[r]=e[t],delete e[t])},l=r.mediaDevices.getUserMedia.bind(r.mediaDevices);if(r.mediaDevices.getUserMedia=function(e){return"object"===(void 0===e?"undefined":c(e))&&"object"===c(e.audio)&&(e=JSON.parse(JSON.stringify(e)),p(e.audio,"autoGainControl","mozAutoGainControl"),p(e.audio,"noiseSuppression","mozNoiseSuppression")),l(e)},o&&o.prototype.getSettings){var f=o.prototype.getSettings;o.prototype.getSettings=function(){var e=f.apply(this,arguments);return p(e,"mozAutoGainControl","autoGainControl"),p(e,"mozNoiseSuppression","noiseSuppression"),e}}if(o&&o.prototype.applyConstraints){var m=o.prototype.applyConstraints;o.prototype.applyConstraints=function(e){return"audio"===this.kind&&"object"===(void 0===e?"undefined":c(e))&&(e=JSON.parse(JSON.stringify(e)),p(e,"autoGainControl","mozAutoGainControl"),p(e,"noiseSuppression","mozNoiseSuppression")),m.apply(this,[e])}}}r.getUserMedia=function(e,i,o){if(t.version<44)return s(e,i,o);n.deprecated("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),r.mediaDevices.getUserMedia(e).then(i,o)}}},{"../utils":13}],12:[function(e,t,r){var n=e("../utils");t.exports={shimLocalStreamsAPI:function(e){if("object"===(void 0===e?"undefined":c(e))&&e.RTCPeerConnection){if("getLocalStreams"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),"getStreamById"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getStreamById=function(e){var t=null;return this._localStreams&&this._localStreams.forEach(function(r){r.id===e&&(t=r)}),this._remoteStreams&&this._remoteStreams.forEach(function(r){r.id===e&&(t=r)}),t}),!("addStream"in e.RTCPeerConnection.prototype)){var t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addStream=function(e){this._localStreams||(this._localStreams=[]),-1===this._localStreams.indexOf(e)&&this._localStreams.push(e);var r=this;e.getTracks().forEach(function(n){t.call(r,n,e)})},e.RTCPeerConnection.prototype.addTrack=function(e,r){return r&&(this._localStreams?-1===this._localStreams.indexOf(r)&&this._localStreams.push(r):this._localStreams=[r]),t.call(this,e,r)}}"removeStream"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.removeStream=function(e){this._localStreams||(this._localStreams=[]);var t=this._localStreams.indexOf(e);if(-1!==t){this._localStreams.splice(t,1);var r=this,n=e.getTracks();this.getSenders().forEach(function(e){-1!==n.indexOf(e.track)&&r.removeTrack(e)})}})}},shimRemoteStreamsAPI:function(e){"object"===(void 0===e?"undefined":c(e))&&e.RTCPeerConnection&&("getRemoteStreams"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getRemoteStreams=function(){return this._remoteStreams?this._remoteStreams:[]}),"onaddstream"in e.RTCPeerConnection.prototype||Object.defineProperty(e.RTCPeerConnection.prototype,"onaddstream",{get:function(){return this._onaddstream},set:function(e){var t=this;this._onaddstream&&(this.removeEventListener("addstream",this._onaddstream),this.removeEventListener("track",this._onaddstreampoly)),this.addEventListener("addstream",this._onaddstream=e),this.addEventListener("track",this._onaddstreampoly=function(e){e.streams.forEach(function(e){if(t._remoteStreams||(t._remoteStreams=[]),!(t._remoteStreams.indexOf(e)>=0)){t._remoteStreams.push(e);var r=new Event("addstream");r.stream=e,t.dispatchEvent(r)}})})}}))},shimCallbacksAPI:function(e){if("object"===(void 0===e?"undefined":c(e))&&e.RTCPeerConnection){var t=e.RTCPeerConnection.prototype,r=t.createOffer,n=t.createAnswer,i=t.setLocalDescription,o=t.setRemoteDescription,a=t.addIceCandidate;t.createOffer=function(e,t){var n=arguments.length>=2?arguments[2]:arguments[0],i=r.apply(this,[n]);return t?(i.then(e,t),Promise.resolve()):i},t.createAnswer=function(e,t){var r=arguments.length>=2?arguments[2]:arguments[0],i=n.apply(this,[r]);return t?(i.then(e,t),Promise.resolve()):i};var s=function(e,t,r){var n=i.apply(this,[e]);return r?(n.then(t,r),Promise.resolve()):n};t.setLocalDescription=s,s=function(e,t,r){var n=o.apply(this,[e]);return r?(n.then(t,r),Promise.resolve()):n},t.setRemoteDescription=s,s=function(e,t,r){var n=a.apply(this,[e]);return r?(n.then(t,r),Promise.resolve()):n},t.addIceCandidate=s}},shimGetUserMedia:function(e){var t=e&&e.navigator;t.getUserMedia||(t.webkitGetUserMedia?t.getUserMedia=t.webkitGetUserMedia.bind(t):t.mediaDevices&&t.mediaDevices.getUserMedia&&(t.getUserMedia=function(e,r,n){t.mediaDevices.getUserMedia(e).then(r,n)}.bind(t)))},shimRTCIceServerUrls:function(e){var t=e.RTCPeerConnection;e.RTCPeerConnection=function(e,r){if(e&&e.iceServers){for(var i=[],o=0;o<e.iceServers.length;o++){var a=e.iceServers[o];!a.hasOwnProperty("urls")&&a.hasOwnProperty("url")?(n.deprecated("RTCIceServer.url","RTCIceServer.urls"),(a=JSON.parse(JSON.stringify(a))).urls=a.url,delete a.url,i.push(a)):i.push(e.iceServers[o])}e.iceServers=i}return new t(e,r)},e.RTCPeerConnection.prototype=t.prototype,"generateCertificate"in e.RTCPeerConnection&&Object.defineProperty(e.RTCPeerConnection,"generateCertificate",{get:function(){return t.generateCertificate}})},shimTrackEventTransceiver:function(e){"object"===(void 0===e?"undefined":c(e))&&e.RTCPeerConnection&&"receiver"in e.RTCTrackEvent.prototype&&!e.RTCTransceiver&&Object.defineProperty(e.RTCTrackEvent.prototype,"transceiver",{get:function(){return{receiver:this.receiver}}})},shimCreateOfferLegacy:function(e){var t=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(e){var r=this;if(e){void 0!==e.offerToReceiveAudio&&(e.offerToReceiveAudio=!!e.offerToReceiveAudio);var n=r.getTransceivers().find(function(e){return e.sender.track&&"audio"===e.sender.track.kind});!1===e.offerToReceiveAudio&&n?"sendrecv"===n.direction?n.setDirection?n.setDirection("sendonly"):n.direction="sendonly":"recvonly"===n.direction&&(n.setDirection?n.setDirection("inactive"):n.direction="inactive"):!0!==e.offerToReceiveAudio||n||r.addTransceiver("audio"),void 0!==e.offerToReceiveAudio&&(e.offerToReceiveVideo=!!e.offerToReceiveVideo);var i=r.getTransceivers().find(function(e){return e.sender.track&&"video"===e.sender.track.kind});!1===e.offerToReceiveVideo&&i?"sendrecv"===i.direction?i.setDirection("sendonly"):"recvonly"===i.direction&&i.setDirection("inactive"):!0!==e.offerToReceiveVideo||i||r.addTransceiver("video")}return t.apply(r,arguments)}}}},{"../utils":13}],13:[function(e,t,r){var n=!0,i=!0;function o(e,t,r){var n=e.match(t);return n&&n.length>=r&&parseInt(n[r],10)}t.exports={extractVersion:o,wrapPeerConnectionEvent:function(e,t,r){if(e.RTCPeerConnection){var n=e.RTCPeerConnection.prototype,i=n.addEventListener;n.addEventListener=function(e,n){if(e!==t)return i.apply(this,arguments);var o=function(e){n(r(e))};return this._eventMap=this._eventMap||{},this._eventMap[n]=o,i.apply(this,[e,o])};var o=n.removeEventListener;n.removeEventListener=function(e,r){if(e!==t||!this._eventMap||!this._eventMap[r])return o.apply(this,arguments);var n=this._eventMap[r];return delete this._eventMap[r],o.apply(this,[e,n])},Object.defineProperty(n,"on"+t,{get:function(){return this["_on"+t]},set:function(e){this["_on"+t]&&(this.removeEventListener(t,this["_on"+t]),delete this["_on"+t]),e&&this.addEventListener(t,this["_on"+t]=e)}})}},disableLog:function(e){return"boolean"!=typeof e?new Error("Argument type: "+(void 0===e?"undefined":c(e))+". Please use a boolean."):(n=e,e?"adapter.js logging disabled":"adapter.js logging enabled")},disableWarnings:function(e){return"boolean"!=typeof e?new Error("Argument type: "+(void 0===e?"undefined":c(e))+". Please use a boolean."):(i=!e,"adapter.js deprecation warnings "+(e?"disabled":"enabled"))},log:function(){if("object"===("undefined"==typeof window?"undefined":c(window))){if(n)return;"undefined"!=typeof console&&"function"==typeof console.log&&console.log.apply(console,arguments)}},deprecated:function(e,t){i&&console.warn(e+" is deprecated, please use "+t+" instead.")},detectBrowser:function(e){var t=e&&e.navigator,r={browser:null,version:null};if(void 0===e||!e.navigator)return r.browser="Not a browser.",r;if(t.mozGetUserMedia)r.browser="firefox",r.version=o(t.userAgent,/Firefox\/(\d+)\./,1);else if(t.webkitGetUserMedia)r.browser="chrome",r.version=o(t.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(t.mediaDevices&&t.userAgent.match(/Edge\/(\d+).(\d+)$/))r.browser="edge",r.version=o(t.userAgent,/Edge\/(\d+).(\d+)$/,2);else{if(!e.RTCPeerConnection||!t.userAgent.match(/AppleWebKit\/(\d+)\./))return r.browser="Not a supported browser.",r;r.browser="safari",r.version=o(t.userAgent,/AppleWebKit\/(\d+)\./,1)}return r}}},{}]},{},[3])(3)})}).call(this,r(65))},73:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=c(r(312)),i=c(r(389)),o=r(27),a=r(308),s=r(1);function c(e){return e&&e.__esModule?e:{default:e}}t.default=function(e,t,r){var c={},d=null,u=null,p={name:s.PROVIDER_WEBRTC,element:e,mse:null,listener:null,isLoaded:!1,canSeek:!1,isLive:!1,seeking:!1,state:s.STATE_IDLE,buffer:0,framerate:0,currentQuality:-1,currentSource:-1,qualityLevels:[],sources:[],adTagUrl:r};return c=(0,n.default)(p,t,function(r){(0,o.isWebRTC)(r.file,r.type)&&(OvenPlayerConsole.log("WEBRTC : onBeforeLoad : ",r),d&&(d.destroy(),d=null),(d=(0,i.default)(c,r.file,function(t){e.srcObject&&(e.srcObject=null),e.srcObject=t},a.errorTrigger,t)).connect(function(){}).catch(function(e){}),c.on(s.CONTENT_META,function(){t.isAutoStart()},c))}),u=c.super("destroy"),OvenPlayerConsole.log("WEBRTC PROVIDER LOADED."),c.destroy=function(){d&&(d.destroy(),e.srcObject=null,d=null),c.off(s.CONTENT_META,null,c),OvenPlayerConsole.log("WEBRTC : PROVIDER DESTROYED."),u()},c}}}]);