desktopCapture-p2p/bower_components/kurento-utils/js/kurento-utils.min.js

56 lines
54 KiB
JavaScript
Raw Normal View History

2018-05-30 19:07:43 +00:00
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.kurentoUtils = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
function noop(e){e&&logger.error(e)}function trackStop(e){e.stop&&e.stop()}function streamStop(e){e.getTracks().forEach(trackStop)}function bufferizeCandidates(e,n){var t=[];return e.addEventListener("signalingstatechange",function(){if("stable"===this.signalingState)for(;t.length;){var n=t.shift();e.addIceCandidate(n.candidate,n.callback,n.callback)}}),function(r,i){switch(i=i||n,e.signalingState){case"closed":i(new Error("PeerConnection object is closed"));break;case"stable":if(e.remoteDescription){e.addIceCandidate(r,i,i);break}default:t.push({candidate:r,callback:i})}}}function removeFIDFromOffer(e){var n=e.indexOf("a=ssrc-group:FID");return n>0?e.slice(0,n):e}function getSimulcastInfo(e){var n=e.getVideoTracks();if(!n.length)return logger.warn("No video tracks available in the video stream"),"";var t=["a=x-google-flag:conference","a=ssrc-group:SIM 1 2 3","a=ssrc:1 cname:localVideo","a=ssrc:1 msid:"+e.id+" "+n[0].id,"a=ssrc:1 mslabel:"+e.id,"a=ssrc:1 label:"+n[0].id,"a=ssrc:2 cname:localVideo","a=ssrc:2 msid:"+e.id+" "+n[0].id,"a=ssrc:2 mslabel:"+e.id,"a=ssrc:2 label:"+n[0].id,"a=ssrc:3 cname:localVideo","a=ssrc:3 msid:"+e.id+" "+n[0].id,"a=ssrc:3 mslabel:"+e.id,"a=ssrc:3 label:"+n[0].id];return t.push(""),t.join("\n")}function WebRtcPeer(e,n,t){function r(){if(l){l.pause();var e=p.getRemoteStreams()[0];l.srcObject=e,logger.debug("Remote stream:",e),l.load()}}function i(e){return R&&("Chrome"===browser.name||"Chromium"===browser.name?(logger.debug("Adding multicast info"),e=new RTCSessionDescription({type:e.type,sdp:removeFIDFromOffer(e.sdp)+getSimulcastInfo(u)})):logger.warn("Simulcast is only available in Chrome browser.")),e}function o(){"closed"===p.signalingState&&t('The peer connection object is in "closed" state. This is most likely due to an invocation of the dispose method before accepting in the dialogue'),u&&d&&c.showLocalVideo(),u&&p.addStream(u),f&&p.addStream(f);var n=parser.getBrowser();"sendonly"!==e||"Chrome"!==n.name&&"Chromium"!==n.name||39!==n.major||(e="sendrecv"),t()}function a(e){void 0===e&&(e=MEDIA_CONSTRAINTS),navigator.mediaDevices.getUserMedia(e).then(function(e){u=e,o()}).catch(t)}if(!(this instanceof WebRtcPeer))return new WebRtcPeer(e,n,t);WebRtcPeer.super_.call(this),n instanceof Function&&(t=n,n=void 0),n=n||{},t=(t||noop).bind(this);var s,c=this,d=n.localVideo,l=n.remoteVideo,u=n.videoStream,f=n.audioStream,g=n.mediaConstraints,p=(n.connectionConstraints,n.peerConnection),h=n.sendSource||"webcam",b=n.dataChannelConfig,m=n.dataChannels||!1,v=uuid.v4(),P=recursive({iceServers:freeice()},n.configuration),S=n.onicecandidate;S&&this.on("icecandidate",S);var w=n.oncandidategatheringdone;w&&this.on("candidategatheringdone",w);var R=n.simulcast,C=n.multistream,y=new sdpTranslator.Interop,D=[],W=!1;if(Object.defineProperties(this,{peerConnection:{get:function(){return p}},id:{value:n.id||v,writable:!1},remoteVideo:{get:function(){return l}},localVideo:{get:function(){return d}},dataChannel:{get:function(){return s}},currentFrame:{get:function(){if(l){if(l.readyState<l.HAVE_CURRENT_DATA)throw new Error("No video stream data available");var e=document.createElement("canvas");return e.width=l.videoWidth,e.height=l.videoHeight,e.getContext("2d").drawImage(l,0,0),e}}}}),!p&&(p=new RTCPeerConnection(P),m&&!s)){var E="WebRtcPeer-"+c.id,T=void 0;b&&(E=b.id||E,T=b.options),s=p.createDataChannel(E,T),b&&(s.onopen=b.onopen,s.onclose=b.onclose,s.onmessage=b.onmessage,s.onbufferedamountlow=b.onbufferedamountlow,s.onerror=b.onerror||noop)}p.addEventListener("icecandidate",function(e){var n=e.candidate;if(EventEmitter.listenerCount(c,"icecandidate")||EventEmitter.listenerCount(c,"candidategatheringdone"))if(n){var t;t=C&&usePlanB?y.candidateToUnifiedPlan(n):n,c.emit("icecandidate",t),W=!1}else W||(c.emit("candidategatheringdone"),W=!0);else W||(D.push(n),n||(W=!0))}),p.onaddstream=n.onaddstream,p.onnegotiationneeded=n.onnegotiationneeded,this.on("newListener",function(e,n){if("icecandidate"===e||"candidategatheringdone"===e)for(;D.length;){var t=D.shift();!t==("candidategatheringdone"===e)&&n(t)}});var k=b
},{"events":4,"freeice":5,"hark":8,"inherits":9,"kurento-browser-extensions":10,"merge":11,"sdp-translator":18,"ua-parser-js":21,"uuid":23}],2:[function(require,module,exports){
window.addEventListener&&(module.exports=require("./index"));
},{"./index":3}],3:[function(require,module,exports){
var WebRtcPeer=require("./WebRtcPeer");exports.WebRtcPeer=WebRtcPeer;
},{"./WebRtcPeer":1}],4:[function(require,module,exports){
function EventEmitter(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function isFunction(e){return"function"==typeof e}function isNumber(e){return"number"==typeof e}function isObject(e){return"object"==typeof e&&null!==e}function isUndefined(e){return void 0===e}module.exports=EventEmitter,EventEmitter.EventEmitter=EventEmitter,EventEmitter.prototype._events=void 0,EventEmitter.prototype._maxListeners=void 0,EventEmitter.defaultMaxListeners=10,EventEmitter.prototype.setMaxListeners=function(e){if(!isNumber(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},EventEmitter.prototype.emit=function(e){var t,i,n,s,r,o;if(this._events||(this._events={}),"error"===e&&(!this._events.error||isObject(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var h=new Error('Uncaught, unspecified "error" event. ('+t+")");throw h.context=t,h}if(i=this._events[e],isUndefined(i))return!1;if(isFunction(i))switch(arguments.length){case 1:i.call(this);break;case 2:i.call(this,arguments[1]);break;case 3:i.call(this,arguments[1],arguments[2]);break;default:s=Array.prototype.slice.call(arguments,1),i.apply(this,s)}else if(isObject(i))for(s=Array.prototype.slice.call(arguments,1),o=i.slice(),n=o.length,r=0;r<n;r++)o[r].apply(this,s);return!0},EventEmitter.prototype.addListener=function(e,t){var i;if(!isFunction(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,isFunction(t.listener)?t.listener:t),this._events[e]?isObject(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,isObject(this._events[e])&&!this._events[e].warned&&(i=isUndefined(this._maxListeners)?EventEmitter.defaultMaxListeners:this._maxListeners)&&i>0&&this._events[e].length>i&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},EventEmitter.prototype.on=EventEmitter.prototype.addListener,EventEmitter.prototype.once=function(e,t){function i(){this.removeListener(e,i),n||(n=!0,t.apply(this,arguments))}if(!isFunction(t))throw TypeError("listener must be a function");var n=!1;return i.listener=t,this.on(e,i),this},EventEmitter.prototype.removeListener=function(e,t){var i,n,s,r;if(!isFunction(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],s=i.length,n=-1,i===t||isFunction(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(isObject(i)){for(r=s;r-- >0;)if(i[r]===t||i[r].listener&&i[r].listener===t){n=r;break}if(n<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(n,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},EventEmitter.prototype.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],isFunction(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},EventEmitter.prototype.listeners=function(e){return this._events&&this._events[e]?isFunction(this._events[e])?[this._events[e]]:this._events[e].slice():[]},EventEmitter.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(isFunction(t))return 1;if(t)return t.length}return 0},EventEmitter.listenerCount=function(e,t){return e.listenerCount(t)};
},{}],5:[function(require,module,exports){
"use strict";var normalice=require("normalice"),freeice=module.exports=function(n){function t(n,t){for(var r,u=[],o=[].concat(e[n]);o.length&&u.length<t;)r=Math.random()*o.length|0,u=u.concat(o.splice(r,1));return u.map(function(t){return"string"==typeof t||t instanceof String?normalice(n+":"+t):t})}var r,e={stun:(n||{}).stun||require("./stun.json"),turn:(n||{}).turn||require("./turn.json")},u=(n||{}).stunCount||2,o=(n||{}).turnCount||0;return r=[].concat(t("stun",u)),o&&(r=r.concat(t("turn",o))),r};
},{"./stun.json":6,"./turn.json":7,"normalice":12}],6:[function(require,module,exports){
module.exports=["stun.l.google.com:19302","stun1.l.google.com:19302","stun2.l.google.com:19302","stun3.l.google.com:19302","stun4.l.google.com:19302","stun.ekiga.net","stun.ideasip.com","stun.schlund.de","stun.stunprotocol.org:3478","stun.voiparound.com","stun.voipbuster.com","stun.voipstunt.com","stun.voxgratia.org","stun.services.mozilla.com"]
},{}],7:[function(require,module,exports){
module.exports=[]
},{}],8:[function(require,module,exports){
function getMaxVolume(e,t){var i=-1/0;e.getFloatFrequencyData(t);for(var n=4,o=t.length;n<o;n++)t[n]>i&&t[n]<0&&(i=t[n]);return i}var WildEmitter=require("wildemitter"),audioContextType=window.AudioContext||window.webkitAudioContext,audioContext=null;module.exports=function(e,t){var i=new WildEmitter;if(!audioContextType)return i;var t=t||{},n=t.smoothing||.1,o=t.interval||50,a=t.threshold,r=t.play,s=t.history||10,u=!0;audioContext||(audioContext=new audioContextType);var p,g,d;d=audioContext.createAnalyser(),d.fftSize=512,d.smoothingTimeConstant=n,g=new Float32Array(d.fftSize),e.jquery&&(e=e[0]),e instanceof HTMLAudioElement||e instanceof HTMLVideoElement?(p=audioContext.createMediaElementSource(e),void 0===r&&(r=!0),a=a||-50):(p=audioContext.createMediaStreamSource(e),a=a||-50),p.connect(d),r&&d.connect(audioContext.destination),i.speaking=!1,i.setThreshold=function(e){a=e},i.setInterval=function(e){o=e},i.stop=function(){u=!1,i.emit("volume_change",-100,a),i.speaking&&(i.speaking=!1,i.emit("stopped_speaking"))},i.speakingHistory=[];for(var l=0;l<s;l++)i.speakingHistory.push(0);var f=function(){setTimeout(function(){if(u){var e=getMaxVolume(d,g);i.emit("volume_change",e,a);var t=0;if(e>a&&!i.speaking){for(var n=i.speakingHistory.length-3;n<i.speakingHistory.length;n++)t+=i.speakingHistory[n];t>=2&&(i.speaking=!0,i.emit("speaking"))}else if(e<a&&i.speaking){for(var n=0;n<i.speakingHistory.length;n++)t+=i.speakingHistory[n];0==t&&(i.speaking=!1,i.emit("stopped_speaking"))}i.speakingHistory.shift(),i.speakingHistory.push(0+(e>a)),f()}},o)};return f(),i};
},{"wildemitter":24}],9:[function(require,module,exports){
"function"==typeof Object.create?module.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:module.exports=function(t,e){t.super_=e;var o=function(){};o.prototype=e.prototype,t.prototype=new o,t.prototype.constructor=t};
},{}],10:[function(require,module,exports){
},{}],11:[function(require,module,exports){
!function(e){function o(e,r){if("object"!==n(e))return r;for(var t in r)"object"===n(e[t])&&"object"===n(r[t])?e[t]=o(e[t],r[t]):e[t]=r[t];return e}function r(e,r,c){var u=c[0],f=c.length;(e||"object"!==n(u))&&(u={});for(var i=0;i<f;++i){var l=c[i];if("object"===n(l))for(var a in l){var v=e?t.clone(l[a]):l[a];u[a]=r?o(u[a],v):v}}return u}function n(e){return{}.toString.call(e).slice(8,-1).toLowerCase()}var t=function(e){return r(!0===e,!1,arguments)};t.recursive=function(e){return r(!0===e,!0,arguments)},t.clone=function(e){var o,r,c=e,u=n(e);if("array"===u)for(c=[],r=e.length,o=0;o<r;++o)c[o]=t.clone(e[o]);else if("object"===u){c={};for(o in e)c[o]=t.clone(e[o])}return c},e?module.exports=t:window.merge=t}("object"==typeof module&&module&&"object"==typeof module.exports&&module.exports);
},{}],12:[function(require,module,exports){
var protocols=["stun:","turn:"];module.exports=function(e){var r,t,n=(e||{}).url||e,l={};return"string"==typeof n||n instanceof String?(n=n.trim(),(r=protocols[protocols.indexOf(n.slice(0,5))])?(n=n.slice(5),t=n.split("@"),l.username=e.username,l.credential=e.credential,t.length>1&&(n=t[1],t=t[0].split(":"),l.username=t[0],l.credential=(e||{}).credential||t[1]||""),l.url=r+n,l.urls=[l.url],l):e):e};
},{}],13:[function(require,module,exports){
var grammar=module.exports={v:[{name:"version",reg:/^(\d*)$/}],o:[{name:"origin",reg:/^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,names:["username","sessionId","sessionVersion","netType","ipVer","address"],format:"%s %s %d %s IP%d %s"}],s:[{name:"name"}],i:[{name:"description"}],u:[{name:"uri"}],e:[{name:"email"}],p:[{name:"phone"}],z:[{name:"timezones"}],r:[{name:"repeats"}],t:[{name:"timing",reg:/^(\d*) (\d*)/,names:["start","stop"],format:"%d %d"}],c:[{name:"connection",reg:/^IN IP(\d) (\S*)/,names:["version","ip"],format:"IN IP%d %s"}],b:[{push:"bandwidth",reg:/^(TIAS|AS|CT|RR|RS):(\d*)/,names:["type","limit"],format:"%s:%s"}],m:[{reg:/^(\w*) (\d*) ([\w\/]*)(?: (.*))?/,names:["type","port","protocol","payloads"],format:"%s %d %s %s"}],a:[{push:"rtp",reg:/^rtpmap:(\d*) ([\w\-]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,names:["payload","codec","rate","encoding"],format:function(e){return e.encoding?"rtpmap:%d %s/%s/%s":e.rate?"rtpmap:%d %s/%s":"rtpmap:%d %s"}},{push:"fmtp",reg:/^fmtp:(\d*) ([\S| ]*)/,names:["payload","config"],format:"fmtp:%d %s"},{name:"control",reg:/^control:(.*)/,format:"control:%s"},{name:"rtcp",reg:/^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,names:["port","netType","ipVer","address"],format:function(e){return null!=e.address?"rtcp:%d %s IP%d %s":"rtcp:%d"}},{push:"rtcpFbTrrInt",reg:/^rtcp-fb:(\*|\d*) trr-int (\d*)/,names:["payload","value"],format:"rtcp-fb:%d trr-int %d"},{push:"rtcpFb",reg:/^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,names:["payload","type","subtype"],format:function(e){return null!=e.subtype?"rtcp-fb:%s %s %s":"rtcp-fb:%s %s"}},{push:"ext",reg:/^extmap:([\w_\/]*) (\S*)(?: (\S*))?/,names:["value","uri","config"],format:function(e){return null!=e.config?"extmap:%s %s %s":"extmap:%s %s"}},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(e){return null!=e.sessionConfig?"crypto:%d %s %s %s":"crypto:%d %s %s"}},{name:"setup",reg:/^setup:(\w*)/,format:"setup:%s"},{name:"mid",reg:/^mid:([^\s]*)/,format:"mid:%s"},{name:"msid",reg:/^msid:(.*)/,format:"msid:%s"},{name:"ptime",reg:/^ptime:(\d*)/,format:"ptime:%d"},{name:"maxptime",reg:/^maxptime:(\d*)/,format:"maxptime:%d"},{name:"direction",reg:/^(sendrecv|recvonly|sendonly|inactive)/},{name:"icelite",reg:/^(ice-lite)/},{name:"iceUfrag",reg:/^ice-ufrag:(\S*)/,format:"ice-ufrag:%s"},{name:"icePwd",reg:/^ice-pwd:(\S*)/,format:"ice-pwd:%s"},{name:"fingerprint",reg:/^fingerprint:(\S*) (\S*)/,names:["type","hash"],format:"fingerprint:%s %s"},{push:"candidates",reg:/^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?/,names:["foundation","component","transport","priority","ip","port","type","raddr","rport","tcptype","generation"],format:function(e){var r="candidate:%s %d %s %d %s %d typ %s";return r+=null!=e.raddr?" raddr %s rport %d":"%v%v",r+=null!=e.tcptype?" tcptype %s":"%v",null!=e.generation&&(r+=" generation %d"),r}},{name:"endOfCandidates",reg:/^(end-of-candidates)/},{name:"remoteCandidates",reg:/^remote-candidates:(.*)/,format:"remote-candidates:%s"},{name:"iceOptions",reg:/^ice-options:(\S*)/,format:"ice-options:%s"},{push:"ssrcs",reg:/^ssrc:(\d*) ([\w_]*):(.*)/,names:["id","attribute","value"],format:"ssrc:%d %s:%s"},{push:"ssrcGroups",reg:/^ssrc-group:(\w*) (.*)/,names:["semantics","ssrcs"],format:"ssrc-group:%s %s"},{name:"msidSemantic",reg:/^msid-semantic:\s?(\w*) (\S*)/,names:["semantic","token"],format:"msid-semantic: %s %s"},{push:"groups",reg:/^group:(\w*) (.*)/,names:["type","mids"],format:"group:%s %s"},{name:"rtcpMux",reg:/^(rtcp-mux)/},{name:"rtcpRsize",reg:/^(rtcp-rsize)/},{push:"invalid",names:["value"]}]};Object.keys(grammar).forEach(function(e){grammar[e].forEach(function(e){e.reg||(e.reg=/(.*)/),e.format||(e.format="%s")})});
},{}],14:[function(require,module,exports){
var parser=require("./parser"),writer=require("./writer");exports.write=writer,exports.parse=parser.parse,exports.parseFmtpConfig=parser.parseFmtpConfig,exports.parsePayloads=parser.parsePayloads,exports.parseRemoteCandidates=parser.parseRemoteCandidates;
},{"./parser":15,"./writer":16}],15:[function(require,module,exports){
var toIntIfInt=function(t){return String(Number(t))===t?Number(t):t},attachProperties=function(t,r,e,n){if(n&&!e)r[n]=toIntIfInt(t[1]);else for(var a=0;a<e.length;a+=1)null!=t[a+1]&&(r[e[a]]=toIntIfInt(t[a+1]))},parseReg=function(t,r,e){var n=t.name&&t.names;t.push&&!r[t.push]?r[t.push]=[]:n&&!r[t.name]&&(r[t.name]={});var a=t.push?{}:n?r[t.name]:r;attachProperties(e.match(t.reg),a,t.names,t.name),t.push&&r[t.push].push(a)},grammar=require("./grammar"),validLine=RegExp.prototype.test.bind(/^([a-z])=(.*)/);exports.parse=function(t){var r={},e=[],n=r;return t.split(/(\r\n|\r|\n)/).filter(validLine).forEach(function(t){var r=t[0],a=t.slice(2);"m"===r&&(e.push({rtp:[],fmtp:[]}),n=e[e.length-1]);for(var p=0;p<(grammar[r]||[]).length;p+=1){var s=grammar[r][p];if(s.reg.test(a))return parseReg(s,n,a)}}),r.media=e,r};var fmtpReducer=function(t,r){var e=r.split("=");return 2===e.length&&(t[e[0]]=toIntIfInt(e[1])),t};exports.parseFmtpConfig=function(t){return t.split(/\;\s?/).reduce(fmtpReducer,{})},exports.parsePayloads=function(t){return t.split(" ").map(Number)},exports.parseRemoteCandidates=function(t){for(var r=[],e=t.split(" ").map(toIntIfInt),n=0;n<e.length;n+=3)r.push({component:e[n],ip:e[n+1],port:e[n+2]});return r};
},{"./grammar":13}],16:[function(require,module,exports){
var grammar=require("./grammar"),formatRegExp=/%[sdv%]/g,format=function(n){var r=1,e=arguments,a=e.length;return n.replace(formatRegExp,function(n){if(r>=a)return n;var u=e[r];switch(r+=1,n){case"%%":return"%";case"%s":return String(u);case"%d":return Number(u);case"%v":return""}})},makeLine=function(n,r,e){var a=r.format instanceof Function?r.format(r.push?e:e[r.name]):r.format,u=[n+"="+a];if(r.names)for(var m=0;m<r.names.length;m+=1){var t=r.names[m];r.name?u.push(e[r.name][t]):u.push(e[r.names[m]])}else u.push(e[r.name]);return format.apply(null,u)},defaultOuterOrder=["v","o","s","i","u","e","p","c","b","t","r","z","a"],defaultInnerOrder=["i","c","b","a"];module.exports=function(n,r){r=r||{},null==n.version&&(n.version=0),null==n.name&&(n.name=" "),n.media.forEach(function(n){null==n.payloads&&(n.payloads="")});var e=r.outerOrder||defaultOuterOrder,a=r.innerOrder||defaultInnerOrder,u=[];return e.forEach(function(r){grammar[r].forEach(function(e){e.name in n&&null!=n[e.name]?u.push(makeLine(r,e,n)):e.push in n&&null!=n[e.push]&&n[e.push].forEach(function(n){u.push(makeLine(r,e,n))})})}),n.media.forEach(function(n){u.push(makeLine("m",grammar.m[0],n)),a.forEach(function(r){grammar[r].forEach(function(e){e.name in n&&null!=n[e.name]?u.push(makeLine(r,e,n)):e.push in n&&null!=n[e.push]&&n[e.push].forEach(function(n){u.push(makeLine(r,e,n))})})})}),u.join("\r\n")+"\r\n"};
},{"./grammar":13}],17:[function(require,module,exports){
module.exports=function r(t){if(!t)return!1;if(this.length!=t.length)return!1;for(var e=0,n=this.length;e<n;e++)if(this[e]instanceof Array&&t[e]instanceof Array){if(!r.apply(this[e],[t[e]]))return!1}else if(this[e]!=t[e])return!1;return!0};
},{}],18:[function(require,module,exports){
exports.Interop=require("./interop");
},{"./interop":19}],19:[function(require,module,exports){
"use strict";function Interop(){this.cache={mlB2UMap:{},mlU2BMap:{}}}function addSetupAttr(e){void 0!==e.setup&&("active"===e.setup?e.setup="passive":"passive"===e.setup&&(e.setup="active"))}var transform=require("./transform"),arrayEquals=require("./array-equals");module.exports=Interop,Interop.prototype.candidateToUnifiedPlan=function(e){var r=new RTCIceCandidate(e);return r.sdpMLineIndex=this.cache.mlB2UMap[r.sdpMLineIndex],r},Interop.prototype.candidateToPlanB=function(e){var r=new RTCIceCandidate(e);if(0===r.sdpMid.indexOf("audio"))r.sdpMid="audio";else{if(0!==r.sdpMid.indexOf("video"))throw new Error("candidate with "+r.sdpMid+" not allowed");r.sdpMid="video"}return r.sdpMLineIndex=this.cache.mlU2BMap[r.sdpMLineIndex],r},Interop.prototype.getFirstSendingIndexFromAnswer=function(e){if(!this.cache.answer)return null;var r=transform.parse(this.cache.answer);if(r&&r.media&&Array.isArray(r.media))for(var i=0;i<r.media.length;i++)if(r.media[i].type==e&&(!r.media[i].direction||"sendrecv"===r.media[i].direction||"sendonly"===r.media[i].direction))return i;return null},Interop.prototype.toPlanB=function(e){var r=this;if("object"!=typeof e||null===e||"string"!=typeof e.sdp)return console.warn("An empty description was passed as an argument."),e;var i=transform.parse(e.sdp);if(void 0===i.media||!Array.isArray(i.media)||0===i.media.length)return console.warn("The description has no media."),e;if(i.media.length<=3&&i.media.every(function(e){return-1!==["video","audio","data"].indexOf(e.mid)}))return console.warn("This description does not look like Unified Plan."),e;for(var t=e.sdp,o=!1,n=0;n<i.media.length;n++){i.media[n].rtp.forEach(function(e){if("NULL"===e.codec){o=!0;var i=transform.parse(r.cache.offer);e.codec=i.media[n].rtp[0].codec}})}o&&(t=transform.write(i)),this.cache[e.type]=t;var s=i.media;i.media=[];var a={},d=[];s.forEach(function(e){if(("string"!=typeof e.rtcpMux||"rtcp-mux"!==e.rtcpMux)&&"inactive"!==e.direction)throw new Error("Cannot convert to Plan B because m-lines without the rtcp-mux attribute were found.");if(void 0!==a[e.type]&&"inactive"!==a[e.type].direction||(a[e.type]=e),e.protocol!=a[e.type].protocol)throw new Error("Cannot convert to Plan B because m-lines have different protocols and this library does not have support for that");if(e.payloads!=a[e.type].payloads)throw new Error("Cannot convert to Plan B because m-lines have different payloads and this library does not have support for that")}),s.forEach(function(e){if("application"===e.type)return i.media.push(e),void d.push(e.mid);"object"==typeof e.sources&&Object.keys(e.sources).forEach(function(r){"object"!=typeof a[e.type].sources&&(a[e.type].sources={}),a[e.type].sources[r]=e.sources[r],void 0!==e.msid&&(a[e.type].sources[r].msid=e.msid)}),void 0!==e.ssrcGroups&&Array.isArray(e.ssrcGroups)&&(void 0!==a[e.type].ssrcGroups&&Array.isArray(a[e.type].ssrcGroups)||(a[e.type].ssrcGroups=[]),a[e.type].ssrcGroups=a[e.type].ssrcGroups.concat(e.ssrcGroups)),a[e.type]===e&&(e.mid=e.type,delete e.bundleOnly,delete e.msid,e.type==s[0].type?(d.unshift(e.type),i.media.unshift(e)):(d.push(e.type),i.media.push(e)))}),void 0!==i.groups&&i.groups.some(function(e){if("BUNDLE"===e.type)return e.mids=d.join(" "),!0}),i.msidSemantic={semantic:"WMS",token:"*"};var c=transform.write(i);return new RTCSessionDescription({type:e.type,sdp:c})},Interop.prototype.toUnifiedPlan=function(e){var r=this;if("object"!=typeof e||null===e||"string"!=typeof e.sdp)return console.warn("An empty description was passed as an argument."),e;var i=transform.parse(e.sdp);if(void 0===i.media||!Array.isArray(i.media)||0===i.media.length)return console.warn("The description has no media."),e;if(i.media.length>3||!i.media.every(function(e){return-1!==["video","audio","data"].indexOf(e.mid)}))return console.warn("This description does not look like Plan B."),e;var t=[];i.media.forEach(function(e){t.push(e.mid)});var o=!1;if(void 0!==i.groups&&Array.isArray(i.groups)&&(o=i.groups.every(function(e){return"BUNDLE"!==e.type||arrayEquals.apply(e.mids.sort(),[t.sort()])})),!o){var n=!1;if(i.media.f
},{"./array-equals":17,"./transform":20}],20:[function(require,module,exports){
var transform=require("sdp-transform");exports.write=function(s,r){return void 0!==s&&void 0!==s.media&&Array.isArray(s.media)&&s.media.forEach(function(s){void 0!==s.sources&&0!==Object.keys(s.sources).length&&(s.ssrcs=[],Object.keys(s.sources).forEach(function(r){var o=s.sources[r];Object.keys(o).forEach(function(i){s.ssrcs.push({id:r,attribute:i,value:o[i]})})}),delete s.sources),void 0!==s.ssrcGroups&&Array.isArray(s.ssrcGroups)&&s.ssrcGroups.forEach(function(s){void 0!==s.ssrcs&&Array.isArray(s.ssrcs)&&(s.ssrcs=s.ssrcs.join(" "))})}),void 0!==s&&void 0!==s.groups&&Array.isArray(s.groups)&&s.groups.forEach(function(s){void 0!==s.mids&&Array.isArray(s.mids)&&(s.mids=s.mids.join(" "))}),transform.write(s,r)},exports.parse=function(s){var r=transform.parse(s);return void 0!==r&&void 0!==r.media&&Array.isArray(r.media)&&r.media.forEach(function(s){void 0!==s.ssrcs&&Array.isArray(s.ssrcs)&&(s.sources={},s.ssrcs.forEach(function(r){s.sources[r.id]||(s.sources[r.id]={}),s.sources[r.id][r.attribute]=r.value}),delete s.ssrcs),void 0!==s.ssrcGroups&&Array.isArray(s.ssrcGroups)&&s.ssrcGroups.forEach(function(s){"string"==typeof s.ssrcs&&(s.ssrcs=s.ssrcs.split(" "))})}),void 0!==r&&void 0!==r.groups&&Array.isArray(r.groups)&&r.groups.forEach(function(s){"string"==typeof s.mids&&(s.mids=s.mids.split(" "))}),r};
},{"sdp-transform":14}],21:[function(require,module,exports){
!function(i,s){"use strict";var e="model",o="name",r="type",n="vendor",a="version",t="mobile",d="tablet",l={extend:function(i,s){var e={};for(var o in i)s[o]&&s[o].length%2==0?e[o]=s[o].concat(i[o]):e[o]=i[o];return e},has:function(i,s){return"string"==typeof i&&-1!==s.toLowerCase().indexOf(i.toLowerCase())},lowerize:function(i){return i.toLowerCase()},major:function(i){return"string"==typeof i?i.replace(/[^\d\.]/g,"").split(".")[0]:void 0},trim:function(i){return i.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}},w={rgx:function(i,s){for(var e,o,r,n,a,t,d=0;d<s.length&&!a;){var l=s[d],w=s[d+1];for(e=o=0;e<l.length&&!a;)if(a=l[e++].exec(i))for(r=0;r<w.length;r++)t=a[++o],n=w[r],"object"==typeof n&&n.length>0?2==n.length?"function"==typeof n[1]?this[n[0]]=n[1].call(this,t):this[n[0]]=n[1]:3==n.length?"function"!=typeof n[1]||n[1].exec&&n[1].test?this[n[0]]=t?t.replace(n[1],n[2]):void 0:this[n[0]]=t?n[1].call(this,t,n[2]):void 0:4==n.length&&(this[n[0]]=t?n[3].call(this,t.replace(n[1],n[2])):void 0):this[n]=t||void 0;d+=2}},str:function(i,s){for(var e in s)if("object"==typeof s[e]&&s[e].length>0){for(var o=0;o<s[e].length;o++)if(l.has(s[e][o],i))return"?"===e?void 0:e}else if(l.has(s[e],i))return"?"===e?void 0:e;return i}},u={browser:{oldsafari:{version:{"1.0":"/8",1.2:"/1",1.3:"/3","2.0":"/412","2.0.2":"/416","2.0.3":"/417","2.0.4":"/419","?":"/"}}},device:{amazon:{model:{"Fire Phone":["SD","KF"]}},sprint:{model:{"Evo Shift 4G":"7373KT"},vendor:{HTC:"APA",Sprint:"Sprint"}}},os:{windows:{version:{ME:"4.90","NT 3.11":"NT3.51","NT 4.0":"NT4.0",2000:"NT 5.0",XP:["NT 5.1","NT 5.2"],Vista:"NT 6.0",7:"NT 6.1",8:"NT 6.2",8.1:"NT 6.3",10:["NT 6.4","NT 10.0"],RT:"ARM"}}}},c={browser:[[/(opera\smini)\/([\w\.-]+)/i,/(opera\s[mobiletab]+).+version\/([\w\.-]+)/i,/(opera).+version\/([\w\.]+)/i,/(opera)[\/\s]+([\w\.]+)/i],[o,a],[/(opios)[\/\s]+([\w\.]+)/i],[[o,"Opera Mini"],a],[/\s(opr)\/([\w\.]+)/i],[[o,"Opera"],a],[/(kindle)\/([\w\.]+)/i,/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]+)*/i,/(avant\s|iemobile|slim|baidu)(?:browser)?[\/\s]?([\w\.]*)/i,/(?:ms|\()(ie)\s([\w\.]+)/i,/(rekonq)\/([\w\.]+)*/i,/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser)\/([\w\.-]+)/i],[o,a],[/(trident).+rv[:\s]([\w\.]+).+like\sgecko/i],[[o,"IE"],a],[/(edge)\/((\d+)?[\w\.]+)/i],[o,a],[/(yabrowser)\/([\w\.]+)/i],[[o,"Yandex"],a],[/(puffin)\/([\w\.]+)/i],[[o,"Puffin"],a],[/((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i],[[o,"UCBrowser"],a],[/(comodo_dragon)\/([\w\.]+)/i],[[o,/_/g," "],a],[/(micromessenger)\/([\w\.]+)/i],[[o,"WeChat"],a],[/(QQ)\/([\d\.]+)/i],[o,a],[/m?(qqbrowser)[\/\s]?([\w\.]+)/i],[o,a],[/xiaomi\/miuibrowser\/([\w\.]+)/i],[a,[o,"MIUI Browser"]],[/;fbav\/([\w\.]+);/i],[a,[o,"Facebook"]],[/headlesschrome(?:\/([\w\.]+)|\s)/i],[a,[o,"Chrome Headless"]],[/\swv\).+(chrome)\/([\w\.]+)/i],[[o,/(.+)/,"$1 WebView"],a],[/((?:oculus|samsung)browser)\/([\w\.]+)/i],[[o,/(.+(?:g|us))(.+)/,"$1 $2"],a],[/android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i],[a,[o,"Android Browser"]],[/(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i],[o,a],[/(dolfin)\/([\w\.]+)/i],[[o,"Dolphin"],a],[/((?:android.+)crmo|crios)\/([\w\.]+)/i],[[o,"Chrome"],a],[/(coast)\/([\w\.]+)/i],[[o,"Opera Coast"],a],[/fxios\/([\w\.-]+)/i],[a,[o,"Firefox"]],[/version\/([\w\.]+).+?mobile\/\w+\s(safari)/i],[a,[o,"Mobile Safari"]],[/version\/([\w\.]+).+?(mobile\s?safari|safari)/i],[a,o],[/webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i],[[o,"GSA"],a],[/webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i],[o,[a,w.str,u.browser.oldsafari.version]],[/(konqueror)\/([\w\.]+)/i,/(webkit|khtml)\/([\w\.]+)/i],[o,a],[/(navigator|netscape)\/([\w\.-]+)/i],[[o,"Netscape"],a],[/(swiftfox)/i,/(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,/(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix)\/([\w\.-]+)/i,/(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i,/(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,/(links)\s\(([
},{}],22:[function(require,module,exports){
(function (global){
var rng,crypto=global.crypto||global.msCrypto;if(crypto&&crypto.getRandomValues){var _rnds8=new Uint8Array(16);rng=function(){return crypto.getRandomValues(_rnds8),_rnds8}}if(!rng){var _rnds=new Array(16);rng=function(){for(var r,n=0;n<16;n++)0==(3&n)&&(r=4294967296*Math.random()),_rnds[n]=r>>>((3&n)<<3)&255;return _rnds}}module.exports=rng;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],23:[function(require,module,exports){
function parse(e,s,r){var t=s&&r||0,n=0;for(s=s||[],e.toLowerCase().replace(/[0-9a-f]{2}/g,function(e){n<16&&(s[t+n++]=_hexToByte[e])});n<16;)s[t+n++]=0;return s}function unparse(e,s){var r=s||0,t=_byteToHex;return t[e[r++]]+t[e[r++]]+t[e[r++]]+t[e[r++]]+"-"+t[e[r++]]+t[e[r++]]+"-"+t[e[r++]]+t[e[r++]]+"-"+t[e[r++]]+t[e[r++]]+"-"+t[e[r++]]+t[e[r++]]+t[e[r++]]+t[e[r++]]+t[e[r++]]+t[e[r++]]}function v1(e,s,r){var t=s&&r||0,n=s||[];e=e||{};var o=void 0!==e.clockseq?e.clockseq:_clockseq,a=void 0!==e.msecs?e.msecs:(new Date).getTime(),u=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,c=a-_lastMSecs+(u-_lastNSecs)/1e4;if(c<0&&void 0===e.clockseq&&(o=o+1&16383),(c<0||a>_lastMSecs)&&void 0===e.nsecs&&(u=0),u>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=a,_lastNSecs=u,_clockseq=o,a+=122192928e5;var i=(1e4*(268435455&a)+u)%4294967296;n[t++]=i>>>24&255,n[t++]=i>>>16&255,n[t++]=i>>>8&255,n[t++]=255&i;var _=a/4294967296*1e4&268435455;n[t++]=_>>>8&255,n[t++]=255&_,n[t++]=_>>>24&15|16,n[t++]=_>>>16&255,n[t++]=o>>>8|128,n[t++]=255&o;for(var d=e.node||_nodeId,v=0;v<6;v++)n[t+v]=d[v];return s||unparse(n)}function v4(e,s,r){var t=s&&r||0;"string"==typeof e&&(s="binary"==e?new Array(16):null,e=null),e=e||{};var n=e.random||(e.rng||_rng)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,s)for(var o=0;o<16;o++)s[t+o]=n[o];return s||unparse(n)}for(var _rng=require("./rng"),_byteToHex=[],_hexToByte={},i=0;i<256;i++)_byteToHex[i]=(i+256).toString(16).substr(1),_hexToByte[_byteToHex[i]]=i;var _seedBytes=_rng(),_nodeId=[1|_seedBytes[0],_seedBytes[1],_seedBytes[2],_seedBytes[3],_seedBytes[4],_seedBytes[5]],_clockseq=16383&(_seedBytes[6]<<8|_seedBytes[7]),_lastMSecs=0,_lastNSecs=0,uuid=v4;uuid.v1=v1,uuid.v4=v4,uuid.parse=parse,uuid.unparse=unparse,module.exports=uuid;
},{"./rng":22}],24:[function(require,module,exports){
function WildEmitter(){}module.exports=WildEmitter,WildEmitter.mixin=function(t){var l=t.prototype||t;l.isWildEmitter=!0,l.on=function(t,l,i){this.callbacks=this.callbacks||{};var s=3===arguments.length,c=s?arguments[1]:void 0,a=s?arguments[2]:arguments[1];return a._groupName=c,(this.callbacks[t]=this.callbacks[t]||[]).push(a),this},l.once=function(t,l,i){function s(){c.off(t,s),h.apply(this,arguments)}var c=this,a=3===arguments.length,e=a?arguments[1]:void 0,h=a?arguments[2]:arguments[1];return this.on(t,e,s),this},l.releaseGroup=function(t){this.callbacks=this.callbacks||{};var l,i,s,c;for(l in this.callbacks)for(c=this.callbacks[l],i=0,s=c.length;i<s;i++)c[i]._groupName===t&&(c.splice(i,1),i--,s--);return this},l.off=function(t,l){this.callbacks=this.callbacks||{};var i,s=this.callbacks[t];return s?1===arguments.length?(delete this.callbacks[t],this):(i=s.indexOf(l),s.splice(i,1),0===s.length&&delete this.callbacks[t],this):this},l.emit=function(t){this.callbacks=this.callbacks||{};var l,i,s,c=[].slice.call(arguments,1),a=this.callbacks[t],e=this.getWildcardCallbacks(t);if(a)for(s=a.slice(),l=0,i=s.length;l<i&&s[l];++l)s[l].apply(this,c);if(e)for(i=e.length,s=e.slice(),l=0,i=s.length;l<i&&s[l];++l)s[l].apply(this,[t].concat(c));return this},l.getWildcardCallbacks=function(t){this.callbacks=this.callbacks||{};var l,i,s=[];for(l in this.callbacks)i=l.split("*"),("*"===l||2===i.length&&t.slice(0,i[0].length)===i[0])&&(s=s.concat(this.callbacks[l]));return s}},WildEmitter.mixin(WildEmitter);
},{}]},{},[2])(2)
});
//# sourceMappingURL=kurento-utils.map