From 93eff57f6e705ddce0f423e146661dcce855f26c Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Mon, 1 Apr 2019 16:43:16 +0100 Subject: [PATCH 1/3] simple chat and device manager configuration updated with domain registry = false --- dist/Connector.hy.js | 2 +- dist/DeviceManager.hy.js | 2 +- dist/SimpleChat.hy.js | 2 +- dist/UserKwhObserver.hy.js | 2 +- src/device-manager/HypertyDescriptor.js | 4 +++- src/observer-kwh/HypertyDescriptor.js | 4 +++- src/simple-chat/HypertyDescriptor.js | 1 + src/simple-chat/SimpleChat.hy.json | 1 + 8 files changed, 12 insertions(+), 6 deletions(-) diff --git a/dist/Connector.hy.js b/dist/Connector.hy.js index cbc7585..6c7eb07 100644 --- a/dist/Connector.hy.js +++ b/dist/Connector.hy.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("activate",[],t):"object"==typeof exports?exports.activate=t():e.activate=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t,r){"use strict";var n=!0,i=!0,o={disableLog:function(e){return"boolean"!=typeof e?new Error("Argument type: "+typeof 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: "+typeof e+". Please use a boolean."):(i=!e,"adapter.js deprecation warnings "+(e?"disabled":"enabled"))},log:function(){if("object"==typeof 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.")},extractVersion:function(e,t,r){var n=e.match(t);return n&&n.length>=r&&parseInt(n[r],10)},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=this.extractVersion(t.userAgent,/Firefox\/(\d+)\./,1);else if(t.webkitGetUserMedia)if(e.webkitRTCPeerConnection)r.browser="chrome",r.version=this.extractVersion(t.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else{if(!t.userAgent.match(/Version\/(\d+).(\d+)/))return r.browser="Unsupported webkit-based browser with GUM support but no WebRTC support.",r;r.browser="safari",r.version=this.extractVersion(t.userAgent,/AppleWebKit\/(\d+)\./,1)}else if(t.mediaDevices&&t.userAgent.match(/Edge\/(\d+).(\d+)$/))r.browser="edge",r.version=this.extractVersion(t.userAgent,/Edge\/(\d+).(\d+)$/,2);else{if(!t.mediaDevices||!t.userAgent.match(/AppleWebKit\/(\d+)\./))return r.browser="Not a supported browser.",r;r.browser="safari",r.version=this.extractVersion(t.userAgent,/AppleWebKit\/(\d+)\./,1)}return r},shimCreateObjectURL:function(e){var t=e&&e.URL;if("object"==typeof e&&e.HTMLMediaElement&&"srcObject"in e.HTMLMediaElement.prototype){var r=t.createObjectURL.bind(t),n=t.revokeObjectURL.bind(t),i=new Map,a=0;t.createObjectURL=function(e){if("getTracks"in e){var t="polyblob:"+ ++a;return i.set(t,e),o.deprecated("URL.createObjectURL(stream)","elem.srcObject = stream"),t}return r(e)},t.revokeObjectURL=function(e){n(e),i.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=i.get(e)||null,s.set.apply(this,[e])}});var c=e.HTMLMediaElement.prototype.setAttribute;e.HTMLMediaElement.prototype.setAttribute=function(){return 2===arguments.length&&"src"===(""+arguments[0]).toLowerCase()&&(this.srcObject=i.get(arguments[1])||null),c.apply(this,arguments)}}}};e.exports={log:o.log,deprecated:o.deprecated,disableLog:o.disableLog,disableWarnings:o.disableWarnings,extractVersion:o.extractVersion,shimCreateObjectURL:o.shimCreateObjectURL,detectBrowser:o.detectBrowser.bind(o)}},function(e,t,r){"use strict";r.d(t,"a",function(){return n});var n={name:"",scheme:"",status:"",owner:"",connectionDescription:{},iceCandidates:[]}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(3),i=r(4),o=r(1);function a(e,t){for(var r=0;r0&&(a=!0),t._controllers[e.from]=o;var a,s=e.identity;s||((s={}).userProfile={picture:"https://www.mybloggerguides.com/wp-content/uploads/2016/01/anonymous_picture.png",name:"anonymous",userURL:"anonymous",preferred_username:"anonymous"}),a?o.decline(486,"Busy Here"):t._onInvitation&&t._onInvitation(o,s.userProfile),console.info("------------------------ END ---------------------- \n")}).catch(function(e){console.error(e)})}},{key:"connect",value:function(e,t,r,n){var o=this,a=o._syncher,s=["connection"],c=["audio","video"];return console.log("connecting: ",e),new Promise(function(d,p){var u,l;console.info("------------------------ Syncher Create ---------------------- \n"),o.search.myIdentity().then(function(t){return console.log("connector searching: ",[e],"at domain ",[n]),console.log("identity: ",t,o.connectionObject),o.search.users([e],[n],s,c)}).then(function(e){l=e[0].hypertyID,console.info("Only support communication one to one, selected hyperty: ",l);var t="Connection";return r&&(t=r),o.connectionObject.name=t,o.connectionObject.scheme="connection",o.connectionObject.owner=o._hypertyURL,o.connectionObject.peer=l,o.connectionObject.status="",a.create(o._objectDescURL,[l],o.connectionObject,!1,!1,r,{},{resources:["audio","video"]})}).catch(function(e){console.error(e),p(e)}).then(function(e){console.info("1. Return Create Data Object Reporter",e),(u=new i.a(a,o._domain,o._configuration,o._removeController,o,l)).mediaStream=t,u.dataObjectReporter=e,o._controllers[l]=u,d(u),console.info("--------------------------- END --------------------------- \n")}).catch(function(e){console.error(e),p(e)})})}},{key:"onInvitation",value:function(e){this._onInvitation=e}},{key:"name",get:function(){return n.a.name}},{key:"descriptor",get:function(){return n.a}},{key:"runtimeHypertyURL",get:function(){return this._hypertyURL}}]),e}();t.default=s},function(e,t,r){"use strict";r.d(t,"a",function(){return n});var n={name:"Connector",configuration:{iceServers:[{urls:"turn:numb.viagenie.ca",credential:"zJcH3erd9cUv5Zh",username:"luis-t-duarte@telecom.pt"},{urls:["stun:stun.voiparound.com","stun:stun.voipbuster.com","stun:stun.voipstunt.com","stun:stun.voxgratia.org","stun:stun.ekiga.net","stun:stun.schlund.de","stun:stun.iptel.org","stun:stun.l.google.com:19302","stun:stun1.l.google.com:19302","stun:stun.ideasip.com","stun:stun4.l.google.com:19302","stun:stun2.l.google.com:19302","stun:stun3.l.google.com:19302"]}],iceTransportPolicy:"all"},constraints:{browser:!0,windowSandbox:!0,mic:!0,camera:!0},hypertyType:["audio","video"],dataObjects:["https://catalogue.%domain%/.well-known/dataschema/Connection"]}},function(e,t,r){"use strict";var n=r(5),i=(r.n(n),r(1));function o(e,t){for(var r=0;r0&&"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"==typeof 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())}}};e.exports={shimMediaStream:o.shimMediaStream,shimOnTrack:o.shimOnTrack,shimAddTrackRemoveTrack:o.shimAddTrackRemoveTrack,shimGetSendersWithDtmf:o.shimGetSendersWithDtmf,shimSourceObject:o.shimSourceObject,shimPeerConnection:o.shimPeerConnection,shimGetUserMedia:r(8)}},function(e,t,r){"use strict";var n=r(0),i=n.log;e.exports=function(e){var t=n.detectBrowser(e),r=e&&e.navigator,o=function(e){if("object"!=typeof 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"==typeof 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((e=JSON.parse(JSON.stringify(e)))&&"object"==typeof 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"==typeof e.video){var s=e.video.facingMode;s=s&&("object"==typeof s?s:{ideal:s});var c,d=t.version<61;if(s&&("user"===s.exact||"environment"===s.exact||"user"===s.ideal||"environment"===s.ideal)&&(!r.mediaDevices.getSupportedConstraints||!r.mediaDevices.getSupportedConstraints().facingMode||d))if(delete e.video.facingMode,"environment"===s.exact||"environment"===s.ideal?c=["back","rear"]:"user"!==s.exact&&"user"!==s.ideal||(c=["front"]),c)return r.mediaDevices.enumerateDevices().then(function(t){var r=(t=t.filter(function(e){return"videoinput"===e.kind})).find(function(e){return c.some(function(t){return-1!==e.label.toLowerCase().indexOf(t)})});return!r&&t.length&&-1!==c.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",InvalidStateError:"NotReadableError",DevicesNotFoundError:"NotFoundError",ConstraintNotSatisfiedError:"OverconstrainedError",TrackStartError:"NotReadableError",MediaDeviceFailedDueToShutdown:"NotReadableError",MediaDeviceKillSwitchOn:"NotReadableError"}[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(s(e))})})};var c=function(e){return new Promise(function(t,n){r.getUserMedia(e,t,n)})};if(r.mediaDevices||(r.mediaDevices={getUserMedia:c,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 d=r.mediaDevices.getUserMedia.bind(r.mediaDevices);r.mediaDevices.getUserMedia=function(e){return a(e,function(e){return d(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 c(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.")})}},function(e,t,r){"use strict";var n=r(0),i=r(10);e.exports={shimGetUserMedia:r(12),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.RTCPeerConnection=i(e,t.version)},shimReplaceTrack:function(e){!e.RTCRtpSender||"replaceTrack"in e.RTCRtpSender.prototype||(e.RTCRtpSender.prototype.replaceTrack=e.RTCRtpSender.prototype.setTrack)}}},function(e,t,r){"use strict";var n=r(11);function i(e,t){var r={codecs:[],headerExtensions:[],fecMechanisms:[]},n=function(e,t){e=parseInt(e,10);for(var r=0;r=14393:(r=!0,!0)}),delete e.url,e.urls=i?n[0]:n,!!n.length}return!1})}(r.iceServers,t)),this._config=r||{},this.transceivers=[],this._localIceCandidatesBuffer=[],this._sdpSessionId=n.generateSessionId()};return r.prototype._emitGatheringStateChange=function(){var e=new Event("icegatheringstatechange");this.dispatchEvent(e),null!==this.onicegatheringstatechange&&this.onicegatheringstatechange(e)},r.prototype._emitBufferedCandidates=function(){var e=this,t=n.splitSections(e.localDescription.sdp);this._localIceCandidatesBuffer.forEach(function(r){if(!r.candidate||0===Object.keys(r.candidate).length)for(var n=1;n0,r={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,wantReceive:!0};if(this.usingBundle&&t)r.iceTransport=this.transceivers[0].iceTransport,r.dtlsTransport=this.transceivers[0].dtlsTransport;else{var n=this._createIceAndDtlsTransports();r.iceTransport=n.iceTransport,r.dtlsTransport=n.dtlsTransport}return this.transceivers.push(r),r},r.prototype.addTrack=function(t,r){for(var n,i=0;i=15025)this.localStreams.push(e),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)}),this.localStreams.push(n)}this._maybeFireNegotiationNeeded()},r.prototype.removeStream=function(e){var t=this.localStreams.indexOf(e);t>-1&&(this.localStreams.splice(t,1),this._maybeFireNegotiationNeeded())},r.prototype.getSenders=function(){return this.transceivers.filter(function(e){return!!e.rtpSender}).map(function(e){return e.rtpSender})},r.prototype.getReceivers=function(){return this.transceivers.filter(function(e){return!!e.rtpReceiver}).map(function(e){return e.rtpReceiver})},r.prototype._createIceGatherer=function(t,r){var i=this,o=new e.RTCIceGatherer(i.iceOptions);return o.onlocalcandidate=function(e){var a=new Event("icecandidate");a.candidate={sdpMid:t,sdpMLineIndex:r};var s=e.candidate,c=!s||0===Object.keys(s).length;c?void 0===o.state&&(o.state="completed"):(s.component=1,a.candidate.candidate=n.writeCandidate(s));var d=n.splitSections(i.localDescription.sdp);d[a.candidate.sdpMLineIndex+1]+=c?"a=end-of-candidates\r\n":"a="+a.candidate.candidate+"\r\n",i.localDescription.sdp=d.join("");var p=(i._pendingOffer?i._pendingOffer:i.transceivers).every(function(e){return e.iceGatherer&&"completed"===e.iceGatherer.state});switch(i.iceGatheringState){case"new":c||i._localIceCandidatesBuffer.push(a),c&&p&&i._localIceCandidatesBuffer.push(new Event("icecandidate"));break;case"gathering":i._emitBufferedCandidates(),c||(i.dispatchEvent(a),null!==i.onicecandidate&&i.onicecandidate(a)),p&&(i.dispatchEvent(new Event("icecandidate")),null!==i.onicecandidate&&i.onicecandidate(new Event("icecandidate")),i.iceGatheringState="complete",i._emitGatheringStateChange())}},o},r.prototype._createIceAndDtlsTransports=function(){var t=this,r=new e.RTCIceTransport(null);r.onicestatechange=function(){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}},r.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)},r.prototype._transceive=function(e,r,o){var a=i(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)),o&&e.rtpReceiver&&("video"===e.kind&&e.recvEncodingParameters&&t<15019&&e.recvEncodingParameters.forEach(function(e){delete e.rtx}),a.encodings=e.recvEncodingParameters,a.rtcp={cname:e.rtcpParameters.cname,compound:e.rtcpParameters.compound},e.sendEncodingParameters.length&&(a.rtcp.ssrc=e.sendEncodingParameters[0].ssrc),e.rtpReceiver.receive(a))},r.prototype.setLocalDescription=function(t){var r,a,s=this;if(!o("setLocalDescription",t.type,this.signalingState)){var c=new Error("Can not set local "+t.type+" in state "+this.signalingState);return c.name="InvalidStateError",arguments.length>2&&"function"==typeof arguments[2]&&e.setTimeout(arguments[2],0,c),Promise.reject(c)}if("offer"===t.type)this._pendingOffer&&(r=n.splitSections(t.sdp),a=r.shift(),r.forEach(function(e,t){var r=n.parseRtpParameters(e);s._pendingOffer[t].localCapabilities=r}),this.transceivers=this._pendingOffer,delete this._pendingOffer);else if("answer"===t.type){r=n.splitSections(s.remoteDescription.sdp),a=r.shift();var d=n.matchPrefix(a,"a=ice-lite").length>0;r.forEach(function(e,t){var r=s.transceivers[t],o=r.iceGatherer,c=r.iceTransport,p=r.dtlsTransport,u=r.localCapabilities,l=r.remoteCapabilities;if(!n.isRejected(e)&&!r.isDatachannel){var f=n.getIceParameters(e,a),m=n.getDtlsParameters(e,a);d&&(m.role="server"),s.usingBundle&&0!==t||(c.start(o,f,d?"controlling":"controlled"),p.start(m));var h=i(u,l);s._transceive(r,h.codecs.length>0,!1)}})}switch(this.localDescription={type:t.type,sdp:t.sdp},t.type){case"offer":this._updateSignalingState("have-local-offer");break;case"answer":this._updateSignalingState("stable");break;default:throw new TypeError('unsupported type "'+t.type+'"')}var p=arguments.length>1&&"function"==typeof arguments[1];if(p){var u=arguments[1];e.setTimeout(function(){u(),"new"===s.iceGatheringState&&(s.iceGatheringState="gathering",s._emitGatheringStateChange()),s._emitBufferedCandidates()},0)}var l=Promise.resolve();return l.then(function(){p||("new"===s.iceGatheringState&&(s.iceGatheringState="gathering",s._emitGatheringStateChange()),e.setTimeout(s._emitBufferedCandidates.bind(s),500))}),l},r.prototype.setRemoteDescription=function(r){var i=this;if(!o("setRemoteDescription",r.type,this.signalingState)){var a=new Error("Can not set remote "+r.type+" in state "+this.signalingState);return a.name="InvalidStateError",arguments.length>2&&"function"==typeof arguments[2]&&e.setTimeout(arguments[2],0,a),Promise.reject(a)}var s={},c=[],d=n.splitSections(r.sdp),p=d.shift(),u=n.matchPrefix(p,"a=ice-lite").length>0,l=n.matchPrefix(p,"a=group:BUNDLE ").length>0;this.usingBundle=l;var f=n.matchPrefix(p,"a=ice-options:")[0];switch(this.canTrickleIceCandidates=!!f&&f.substr(14).split(" ").indexOf("trickle")>=0,d.forEach(function(o,a){var d=n.splitLines(o),f=n.getKind(o),m=n.isRejected(o),h=d[0].substr(2).split(" ")[2],v=n.getDirection(o,p),g=n.parseMsid(o),y=n.getMid(o)||n.generateIdentifier();if("application"!==f||"DTLS/SCTP"!==h){var C,b,S,T,R,P,w,k,_,E,O,D=n.parseRtpParameters(o);m||(E=n.getIceParameters(o,p),(O=n.getDtlsParameters(o,p)).role="client"),w=n.parseRtpEncodingParameters(o);var j=n.parseRtcpParameters(o),x=n.matchPrefix(o,"a=end-of-candidates",p).length>0,I=n.matchPrefix(o,"a=candidate:").map(function(e){return n.parseCandidate(e)}).filter(function(e){return"1"===e.component||1===e.component});("offer"===r.type||"answer"===r.type)&&!m&&l&&a>0&&i.transceivers[a]&&(i._disposeIceAndDtlsTransports(a),i.transceivers[a].iceGatherer=i.transceivers[0].iceGatherer,i.transceivers[a].iceTransport=i.transceivers[0].iceTransport,i.transceivers[a].dtlsTransport=i.transceivers[0].dtlsTransport,i.transceivers[a].rtpSender&&i.transceivers[a].rtpSender.setTransport(i.transceivers[0].dtlsTransport),i.transceivers[a].rtpReceiver&&i.transceivers[a].rtpReceiver.setTransport(i.transceivers[0].dtlsTransport)),"offer"!==r.type||m?"answer"!==r.type||m||(b=(C=i.transceivers[a]).iceGatherer,S=C.iceTransport,T=C.dtlsTransport,R=C.rtpReceiver,P=C.sendEncodingParameters,k=C.localCapabilities,i.transceivers[a].recvEncodingParameters=w,i.transceivers[a].remoteCapabilities=D,i.transceivers[a].rtcpParameters=j,l&&0!==a||((u||x)&&I.length&&S.setRemoteCandidates(I),S.start(b,E,"controlling"),T.start(O)),i._transceive(C,"sendrecv"===v||"recvonly"===v,"sendrecv"===v||"sendonly"===v),!R||"sendrecv"!==v&&"sendonly"!==v?delete C.rtpReceiver:(_=R.track,g?(s[g.stream]||(s[g.stream]=new e.MediaStream),s[g.stream].addTrack(_),c.push([_,R,s[g.stream]])):(s.default||(s.default=new e.MediaStream),s.default.addTrack(_),c.push([_,R,s.default])))):((C=i.transceivers[a]||i._createTransceiver(f)).mid=y,C.iceGatherer||(C.iceGatherer=l&&a>0?i.transceivers[0].iceGatherer:i._createIceGatherer(y,a)),!x||!I.length||l&&0!==a||C.iceTransport.setRemoteCandidates(I),k=e.RTCRtpReceiver.getCapabilities(f),t<15019&&(k.codecs=k.codecs.filter(function(e){return"rtx"!==e.name})),P=[{ssrc:1001*(2*a+2)}],"sendrecv"!==v&&"sendonly"!==v||(_=(R=new e.RTCRtpReceiver(C.dtlsTransport,f)).track,g?(s[g.stream]||(s[g.stream]=new e.MediaStream,Object.defineProperty(s[g.stream],"id",{get:function(){return g.stream}})),Object.defineProperty(_,"id",{get:function(){return g.track}}),s[g.stream].addTrack(_),c.push([_,R,s[g.stream]])):(s.default||(s.default=new e.MediaStream),s.default.addTrack(_),c.push([_,R,s.default]))),C.localCapabilities=k,C.remoteCapabilities=D,C.rtpReceiver=R,C.rtcpParameters=j,C.sendEncodingParameters=P,C.recvEncodingParameters=w,i._transceive(i.transceivers[a],!1,"sendrecv"===v||"sendonly"===v))}else i.transceivers[a]={mid:y,isDatachannel:!0}}),this.remoteDescription={type:r.type,sdp:r.sdp},r.type){case"offer":this._updateSignalingState("have-remote-offer");break;case"answer":this._updateSignalingState("stable");break;default:throw new TypeError('unsupported type "'+r.type+'"')}return Object.keys(s).forEach(function(t){var r=s[t];if(r.getTracks().length){i.remoteStreams.push(r);var n=new Event("addstream");n.stream=r,i.dispatchEvent(n),null!==i.onaddstream&&e.setTimeout(function(){i.onaddstream(n)},0),c.forEach(function(t){var n=t[0],o=t[1];if(r.id===t[2].id){var a=new Event("track");a.track=n,a.receiver=o,a.streams=[r],i.dispatchEvent(a),null!==i.ontrack&&e.setTimeout(function(){i.ontrack(a)},0)}})}}),e.setTimeout(function(){i&&i.transceivers&&i.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),arguments.length>1&&"function"==typeof arguments[1]&&e.setTimeout(arguments[1],0),Promise.resolve()},r.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._updateSignalingState("closed")},r.prototype._updateSignalingState=function(e){this.signalingState=e;var t=new Event("signalingstatechange");this.dispatchEvent(t),null!==this.onsignalingstatechange&&this.onsignalingstatechange(t)},r.prototype._maybeFireNegotiationNeeded=function(){var t=this;"stable"===this.signalingState&&!0!==this.needNegotiation&&(this.needNegotiation=!0,e.setTimeout(function(){if(!1!==t.needNegotiation){t.needNegotiation=!1;var e=new Event("negotiationneeded");t.dispatchEvent(e),null!==t.onnegotiationneeded&&t.onnegotiationneeded(e)}},0))},r.prototype._updateConnectionState=function(){var e,t={new:0,closed:0,connecting:0,checking: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||t.checking>0?e="connecting":t.disconnected>0?e="disconnected":t.new>0?e="new":(t.connected>0||t.completed>0)&&(e="connected"),e!==this.iceConnectionState){this.iceConnectionState=e;var r=new Event("iceconnectionstatechange");this.dispatchEvent(r),null!==this.oniceconnectionstatechange&&this.oniceconnectionstatechange(r)}},r.prototype.createOffer=function(){var r,i=this;if(this._pendingOffer)throw new Error("createOffer called while there is a pending offer.");1===arguments.length&&"function"!=typeof arguments[0]?r=arguments[0]:3===arguments.length&&(r=arguments[2]);var o=this.transceivers.filter(function(e){return"audio"===e.kind}).length,a=this.transceivers.filter(function(e){return"video"===e.kind}).length;if(r){if(r.mandatory||r.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");void 0!==r.offerToReceiveAudio&&(o=!0===r.offerToReceiveAudio?1:!1===r.offerToReceiveAudio?0:r.offerToReceiveAudio),void 0!==r.offerToReceiveVideo&&(a=!0===r.offerToReceiveVideo?1:!1===r.offerToReceiveVideo?0:r.offerToReceiveVideo)}for(this.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&&(this._createTransceiver("audio"),o--),a>0&&(this._createTransceiver("video"),a--);var s=function(e){var t=e.filter(function(e){return"audio"===e.kind}),r=e.filter(function(e){return"video"===e.kind});for(e=[];t.length||r.length;)t.length&&e.push(t.shift()),r.length&&e.push(r.shift());return e}(this.transceivers),c=n.writeSessionBoilerplate(this._sdpSessionId);s.forEach(function(r,o){var a=r.track,c=r.kind,d=n.generateIdentifier();r.mid=d,r.iceGatherer||(r.iceGatherer=i.usingBundle&&o>0?s[0].iceGatherer:i._createIceGatherer(d,o));var p=e.RTCRtpSender.getCapabilities(c);t<15019&&(p.codecs=p.codecs.filter(function(e){return"rtx"!==e.name})),p.codecs.forEach(function(e){"H264"===e.name&&void 0===e.parameters["level-asymmetry-allowed"]&&(e.parameters["level-asymmetry-allowed"]="1")});var u=[{ssrc:1001*(2*o+1)}];a&&t>=15019&&"video"===c&&(u[0].rtx={ssrc:1001*(2*o+1)+1}),r.wantReceive&&(r.rtpReceiver=new e.RTCRtpReceiver(r.dtlsTransport,c)),r.localCapabilities=p,r.sendEncodingParameters=u}),"max-compat"!==this._config.bundlePolicy&&(c+="a=group:BUNDLE "+s.map(function(e){return e.mid}).join(" ")+"\r\n"),c+="a=ice-options:trickle\r\n",s.forEach(function(e,t){c+=n.writeMediaSection(e,e.localCapabilities,"offer",e.stream),c+="a=rtcp-rsize\r\n"}),this._pendingOffer=s;var d=new e.RTCSessionDescription({type:"offer",sdp:c});return arguments.length&&"function"==typeof arguments[0]&&e.setTimeout(arguments[0],0,d),Promise.resolve(d)},r.prototype.createAnswer=function(){var r=n.writeSessionBoilerplate(this._sdpSessionId);this.usingBundle&&(r+="a=group:BUNDLE "+this.transceivers.map(function(e){return e.mid}).join(" ")+"\r\n"),this.transceivers.forEach(function(e,o){if(e.isDatachannel)r+="m=application 0 DTLS/SCTP 5000\r\nc=IN IP4 0.0.0.0\r\na=mid:"+e.mid+"\r\n";else{var a;if(e.stream)"audio"===e.kind?a=e.stream.getAudioTracks()[0]:"video"===e.kind&&(a=e.stream.getVideoTracks()[0]),a&&t>=15019&&"video"===e.kind&&(e.sendEncodingParameters[0].rtx={ssrc:1001*(2*o+2)+1});var s=i(e.localCapabilities,e.remoteCapabilities);!s.codecs.filter(function(e){return"rtx"===e.name.toLowerCase()}).length&&e.sendEncodingParameters[0].rtx&&delete e.sendEncodingParameters[0].rtx,r+=n.writeMediaSection(e,s,"answer",e.stream),e.rtcpParameters&&e.rtcpParameters.reducedSize&&(r+="a=rtcp-rsize\r\n")}});var o=new e.RTCSessionDescription({type:"answer",sdp:r});return arguments.length&&"function"==typeof arguments[0]&&e.setTimeout(arguments[0],0,o),Promise.resolve(o)},r.prototype.addIceCandidate=function(t){if(t){var r=t.sdpMLineIndex;if(t.sdpMid)for(var i=0;i0?n.parseCandidate(t.candidate):{};if("tcp"===a.protocol&&(0===a.port||9===a.port))return Promise.resolve();if(a.component&&"1"!==a.component&&1!==a.component)return Promise.resolve();o.iceTransport.addRemoteCandidate(a);var s=n.splitSections(this.remoteDescription.sdp);s[r+1]+=(a.type?t.candidate.trim():"a=end-of-candidates")+"\r\n",this.remoteDescription.sdp=s.join("")}}else for(var c=0;c1&&"function"==typeof arguments[1]&&e.setTimeout(arguments[1],0),Promise.resolve()},r.prototype.getStats=function(){var t=[];this.transceivers.forEach(function(e){["rtpSender","rtpReceiver","iceGatherer","iceTransport","dtlsTransport"].forEach(function(r){e[r]&&t.push(e[r].getStats())})});var r=arguments.length>1&&"function"==typeof arguments[1]&&arguments[1];return new Promise(function(n){var i=new Map;Promise.all(t).then(function(t){t.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]),i.set(t,e[t])})}),r&&e.setTimeout(r,0,i),n(i)})})},r}},function(e,t,r){"use strict";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],address:t[4],port:parseInt(t[5],10),type:t[7]},n=8;n0?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-1?(r.attribute=e.substr(t+1,n-t-1),r.value=e.substr(n+1)):r.attribute=e.substr(t+1),r},n.parseSsrcGroup=function(e){var t=e.substr(13).split(" ");return{semantics:t.shift(),ssrcs:t.map(function(e){return parseInt(e,10)})}},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;i0?"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&&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){return e.substr(17).split(" ").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)};c&&t&&(n.rtx={ssrc:t}),r.push(n),o&&((n=JSON.parse(JSON.stringify(n))).fec={ssrc:c,mechanism:a?"red+ulpfec":"red"},r.push(n))}}),0===r.length&&c&&r.push({ssrc:c});var p=n.matchPrefix(e,"b=");return p.length&&(p=0===p[0].indexOf("b=TIAS:")?parseInt(p[0].substr(7),10):0===p[0].indexOf("b=AS:")?1e3*parseInt(p[0].substr(5),10)*.95-16e3:void 0,r.forEach(function(e){e.maxBitrate=p})),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,r){var i,o=void 0!==t?t:2;return i=e||n.generateSessionId(),"v=0\r\no="+(r||"thisisadapterortc")+" "+i+" "+o+" 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;i55&&"autoGainControl"in r.mediaDevices.getSupportedConstraints())){var p=function(e,t,r){t in e&&!(r in e)&&(e[r]=e[t],delete e[t])},u=r.mediaDevices.getUserMedia.bind(r.mediaDevices);if(r.mediaDevices.getUserMedia=function(e){return"object"==typeof e&&"object"==typeof e.audio&&(e=JSON.parse(JSON.stringify(e)),p(e.audio,"autoGainControl","mozAutoGainControl"),p(e.audio,"noiseSuppression","mozNoiseSuppression")),u(e)},o&&o.prototype.getSettings){var l=o.prototype.getSettings;o.prototype.getSettings=function(){var e=l.apply(this,arguments);return p(e,"mozAutoGainControl","autoGainControl"),p(e,"mozNoiseSuppression","noiseSuppression"),e}}if(o&&o.prototype.applyConstraints){var f=o.prototype.applyConstraints;o.prototype.applyConstraints=function(e){return"audio"===this.kind&&"object"==typeof e&&(e=JSON.parse(JSON.stringify(e)),p(e,"autoGainControl","mozAutoGainControl"),p(e,"noiseSuppression","mozNoiseSuppression")),f.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)}}},function(e,t,r){"use strict";var n=r(0),i={shimLocalStreamsAPI:function(e){if("object"==typeof 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){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"==typeof 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){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){var t=e.streams[0];if(this._remoteStreams||(this._remoteStreams=[]),!(this._remoteStreams.indexOf(t)>=0)){this._remoteStreams.push(t);var r=new Event("addstream");r.stream=e.streams[0],this.dispatchEvent(r)}}.bind(this))}}))},shimCallbacksAPI:function(e){if("object"==typeof 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=n&&parseInt(r[n],10)},detectBrowser:function(e){var t=e&&e.navigator,n={browser:null,version:null};if(void 0===e||!e.navigator)return n.browser="Not a browser.",n;if(t.mozGetUserMedia)n.browser="firefox",n.version=this.extractVersion(t.userAgent,/Firefox\/(\d+)\./,1);else if(t.webkitGetUserMedia)if(e.webkitRTCPeerConnection)n.browser="chrome",n.version=this.extractVersion(t.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else{if(!t.userAgent.match(/Version\/(\d+).(\d+)/))return n.browser="Unsupported webkit-based browser with GUM support but no WebRTC support.",n;n.browser="safari",n.version=this.extractVersion(t.userAgent,/AppleWebKit\/(\d+)\./,1)}else if(t.mediaDevices&&t.userAgent.match(/Edge\/(\d+).(\d+)$/))n.browser="edge",n.version=this.extractVersion(t.userAgent,/Edge\/(\d+).(\d+)$/,2);else{if(!t.mediaDevices||!t.userAgent.match(/AppleWebKit\/(\d+)\./))return n.browser="Not a supported browser.",n;n.browser="safari",n.version=this.extractVersion(t.userAgent,/AppleWebKit\/(\d+)\./,1)}return n},shimCreateObjectURL:function(e){var t=e&&e.URL;if("object"==typeof e&&e.HTMLMediaElement&&"srcObject"in e.HTMLMediaElement.prototype){var n=t.createObjectURL.bind(t),r=t.revokeObjectURL.bind(t),i=new Map,a=0;t.createObjectURL=function(e){if("getTracks"in e){var t="polyblob:"+ ++a;return i.set(t,e),o.deprecated("URL.createObjectURL(stream)","elem.srcObject = stream"),t}return n(e)},t.revokeObjectURL=function(e){r(e),i.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=i.get(e)||null,s.set.apply(this,[e])}});var c=e.HTMLMediaElement.prototype.setAttribute;e.HTMLMediaElement.prototype.setAttribute=function(){return 2===arguments.length&&"src"===(""+arguments[0]).toLowerCase()&&(this.srcObject=i.get(arguments[1])||null),c.apply(this,arguments)}}}};e.exports={log:o.log,deprecated:o.deprecated,disableLog:o.disableLog,disableWarnings:o.disableWarnings,extractVersion:o.extractVersion,shimCreateObjectURL:o.shimCreateObjectURL,detectBrowser:o.detectBrowser.bind(o)}},function(e,t,n){"use strict";n.d(t,"a",function(){return r});var r={name:"",scheme:"",status:"",owner:"",connectionDescription:{},iceCandidates:[]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(4),o=n(1);function a(e,t){for(var n=0;n0&&(a=!0),t._controllers[e.from]=o;var a,s=e.identity;s||((s={}).userProfile={picture:"https://www.mybloggerguides.com/wp-content/uploads/2016/01/anonymous_picture.png",name:"anonymous",userURL:"anonymous",preferred_username:"anonymous"}),a?o.decline(486,"Busy Here"):t._onInvitation&&t._onInvitation(o,s.userProfile),console.info("------------------------ END ---------------------- \n")}).catch(function(e){console.error(e)})}},{key:"connect",value:function(e,t,n,r){var o=this,a=o._syncher,s=["connection"],c=["audio","video"];return console.log("connecting: ",e),new Promise(function(d,p){var u,l;console.info("------------------------ Syncher Create ---------------------- \n"),o.search.myIdentity().then(function(t){return console.log("connector searching: ",[e],"at domain ",[r]),console.log("identity: ",t,o.connectionObject),o.search.users([e],[r],s,c)}).then(function(e){l=e[0].hypertyID,console.info("Only support communication one to one, selected hyperty: ",l);var t="Connection";return n&&(t=n),o.connectionObject.name=t,o.connectionObject.scheme="connection",o.connectionObject.owner=o._hypertyURL,o.connectionObject.peer=l,o.connectionObject.status="",a.create(o._objectDescURL,[l],o.connectionObject,!1,!1,n,{},{resources:["audio","video"]})}).catch(function(e){console.error(e),p(e)}).then(function(e){console.info("1. Return Create Data Object Reporter",e),(u=new i.a(a,o._domain,o._configuration,o._removeController,o,l)).mediaStream=t,u.dataObjectReporter=e,o._controllers[l]=u,d(u),console.info("--------------------------- END --------------------------- \n")}).catch(function(e){console.error(e),p(e)})})}},{key:"onInvitation",value:function(e){this._onInvitation=e}},{key:"name",get:function(){return r.a.name}},{key:"descriptor",get:function(){return r.a}},{key:"runtimeHypertyURL",get:function(){return this._hypertyURL}}]),e}();t.default=s},function(e,t,n){"use strict";n.d(t,"a",function(){return r});var r={name:"Connector",configuration:{iceServers:[{urls:"turn:numb.viagenie.ca",credential:"zJcH3erd9cUv5Zh",username:"luis-t-duarte@telecom.pt"},{urls:["stun:stun.voiparound.com","stun:stun.voipbuster.com","stun:stun.voipstunt.com","stun:stun.voxgratia.org","stun:stun.ekiga.net","stun:stun.schlund.de","stun:stun.iptel.org","stun:stun.l.google.com:19302","stun:stun1.l.google.com:19302","stun:stun.ideasip.com","stun:stun4.l.google.com:19302","stun:stun2.l.google.com:19302","stun:stun3.l.google.com:19302"]}],iceTransportPolicy:"all"},constraints:{browser:!0,windowSandbox:!0,mic:!0,camera:!0},hypertyType:["audio","video"],dataObjects:["https://catalogue.%domain%/.well-known/dataschema/Connection"]}},function(e,t,n){"use strict";var r=n(5),i=(n.n(r),n(1));function o(e,t){for(var n=0;n0&&"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 n={id:e.id,timestamp:e.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[e.type]||e.type};e.names().forEach(function(t){n[t]=e.stat(t)}),t[n.id]=n}),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(r,[function(t){e(s(a(t)))},t])}).then(t,n)},t.version<51&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(t){var n=e.RTCPeerConnection.prototype[t];e.RTCPeerConnection.prototype[t]=function(){var e=arguments,t=this,r=new Promise(function(r,i){n.apply(t,[e[0],r,i])});return e.length<2?r:r.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 n=e.RTCPeerConnection.prototype[t];e.RTCPeerConnection.prototype[t]=function(){var e=this;if(arguments.length<1||1===arguments.length&&"object"==typeof arguments[0]){var t=1===arguments.length?arguments[0]:void 0;return new Promise(function(r,i){n.apply(e,[r,i,t])})}return n.apply(this,arguments)}}),["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(t){var n=e.RTCPeerConnection.prototype[t];e.RTCPeerConnection.prototype[t]=function(){return arguments[0]=new("addIceCandidate"===t?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),n.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())}}};e.exports={shimMediaStream:o.shimMediaStream,shimOnTrack:o.shimOnTrack,shimAddTrackRemoveTrack:o.shimAddTrackRemoveTrack,shimGetSendersWithDtmf:o.shimGetSendersWithDtmf,shimSourceObject:o.shimSourceObject,shimPeerConnection:o.shimPeerConnection,shimGetUserMedia:n(8)}},function(e,t,n){"use strict";var r=n(0),i=r.log;e.exports=function(e){var t=r.detectBrowser(e),n=e&&e.navigator,o=function(e){if("object"!=typeof e||e.mandatory||e.optional)return e;var t={};return Object.keys(e).forEach(function(n){if("require"!==n&&"advanced"!==n&&"mediaSource"!==n){var r="object"==typeof e[n]?e[n]:{ideal:e[n]};void 0!==r.exact&&"number"==typeof r.exact&&(r.min=r.max=r.exact);var i=function(e,t){return e?e+t.charAt(0).toUpperCase()+t.slice(1):"deviceId"===t?"sourceId":t};if(void 0!==r.ideal){t.optional=t.optional||[];var o={};"number"==typeof r.ideal?(o[i("min",n)]=r.ideal,t.optional.push(o),(o={})[i("max",n)]=r.ideal,t.optional.push(o)):(o[i("",n)]=r.ideal,t.optional.push(o))}void 0!==r.exact&&"number"!=typeof r.exact?(t.mandatory=t.mandatory||{},t.mandatory[i("",n)]=r.exact):["min","max"].forEach(function(e){void 0!==r[e]&&(t.mandatory=t.mandatory||{},t.mandatory[i(e,n)]=r[e])})}}),e.advanced&&(t.optional=(t.optional||[]).concat(e.advanced)),t},a=function(e,r){if((e=JSON.parse(JSON.stringify(e)))&&"object"==typeof e.audio){var a=function(e,t,n){t in e&&!(n in e)&&(e[n]=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"==typeof e.video){var s=e.video.facingMode;s=s&&("object"==typeof s?s:{ideal:s});var c,d=t.version<61;if(s&&("user"===s.exact||"environment"===s.exact||"user"===s.ideal||"environment"===s.ideal)&&(!n.mediaDevices.getSupportedConstraints||!n.mediaDevices.getSupportedConstraints().facingMode||d))if(delete e.video.facingMode,"environment"===s.exact||"environment"===s.ideal?c=["back","rear"]:"user"!==s.exact&&"user"!==s.ideal||(c=["front"]),c)return n.mediaDevices.enumerateDevices().then(function(t){var n=(t=t.filter(function(e){return"videoinput"===e.kind})).find(function(e){return c.some(function(t){return-1!==e.label.toLowerCase().indexOf(t)})});return!n&&t.length&&-1!==c.indexOf("back")&&(n=t[t.length-1]),n&&(e.video.deviceId=s.exact?{exact:n.deviceId}:{ideal:n.deviceId}),e.video=o(e.video),i("chrome: "+JSON.stringify(e)),r(e)});e.video=o(e.video)}return i("chrome: "+JSON.stringify(e)),r(e)},s=function(e){return{name:{PermissionDeniedError:"NotAllowedError",InvalidStateError:"NotReadableError",DevicesNotFoundError:"NotFoundError",ConstraintNotSatisfiedError:"OverconstrainedError",TrackStartError:"NotReadableError",MediaDeviceFailedDueToShutdown:"NotReadableError",MediaDeviceKillSwitchOn:"NotReadableError"}[e.name]||e.name,message:e.message,constraint:e.constraintName,toString:function(){return this.name+(this.message&&": ")+this.message}}};n.getUserMedia=function(e,t,r){a(e,function(e){n.webkitGetUserMedia(e,t,function(e){r(s(e))})})};var c=function(e){return new Promise(function(t,r){n.getUserMedia(e,t,r)})};if(n.mediaDevices||(n.mediaDevices={getUserMedia:c,enumerateDevices:function(){return new Promise(function(t){var n={audio:"audioinput",video:"videoinput"};return e.MediaStreamTrack.getSources(function(e){t(e.map(function(e){return{label:e.label,kind:n[e.kind],deviceId:e.id,groupId:""}}))})})},getSupportedConstraints:function(){return{deviceId:!0,echoCancellation:!0,facingMode:!0,frameRate:!0,height:!0,width:!0}}}),n.mediaDevices.getUserMedia){var d=n.mediaDevices.getUserMedia.bind(n.mediaDevices);n.mediaDevices.getUserMedia=function(e){return a(e,function(e){return d(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 n.mediaDevices.getUserMedia=function(e){return c(e)};void 0===n.mediaDevices.addEventListener&&(n.mediaDevices.addEventListener=function(){i("Dummy mediaDevices.addEventListener called.")}),void 0===n.mediaDevices.removeEventListener&&(n.mediaDevices.removeEventListener=function(){i("Dummy mediaDevices.removeEventListener called.")})}},function(e,t,n){"use strict";var r=n(0),i=n(10);e.exports={shimGetUserMedia:n(12),shimPeerConnection:function(e){var t=r.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 n=Object.getOwnPropertyDescriptor(e.MediaStreamTrack.prototype,"enabled");Object.defineProperty(e.MediaStreamTrack.prototype,"enabled",{set:function(e){n.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.RTCPeerConnection=i(e,t.version)},shimReplaceTrack:function(e){!e.RTCRtpSender||"replaceTrack"in e.RTCRtpSender.prototype||(e.RTCRtpSender.prototype.replaceTrack=e.RTCRtpSender.prototype.setTrack)}}},function(e,t,n){"use strict";var r=n(11);function i(e,t){var n={codecs:[],headerExtensions:[],fecMechanisms:[]},r=function(e,t){e=parseInt(e,10);for(var n=0;n=14393:(n=!0,!0)}),delete e.url,e.urls=i?r[0]:r,!!r.length}return!1})}(n.iceServers,t)),this._config=n||{},this.transceivers=[],this._localIceCandidatesBuffer=[],this._sdpSessionId=r.generateSessionId()};return n.prototype._emitGatheringStateChange=function(){var e=new Event("icegatheringstatechange");this.dispatchEvent(e),null!==this.onicegatheringstatechange&&this.onicegatheringstatechange(e)},n.prototype._emitBufferedCandidates=function(){var e=this,t=r.splitSections(e.localDescription.sdp);this._localIceCandidatesBuffer.forEach(function(n){if(!n.candidate||0===Object.keys(n.candidate).length)for(var r=1;r0,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,wantReceive:!0};if(this.usingBundle&&t)n.iceTransport=this.transceivers[0].iceTransport,n.dtlsTransport=this.transceivers[0].dtlsTransport;else{var r=this._createIceAndDtlsTransports();n.iceTransport=r.iceTransport,n.dtlsTransport=r.dtlsTransport}return this.transceivers.push(n),n},n.prototype.addTrack=function(t,n){for(var r,i=0;i=15025)this.localStreams.push(e),e.getTracks().forEach(function(t){n.addTrack(t,e)});else{var r=e.clone();e.getTracks().forEach(function(e,t){var n=r.getTracks()[t];e.addEventListener("enabled",function(e){n.enabled=e.enabled})}),r.getTracks().forEach(function(e){n.addTrack(e,r)}),this.localStreams.push(r)}this._maybeFireNegotiationNeeded()},n.prototype.removeStream=function(e){var t=this.localStreams.indexOf(e);t>-1&&(this.localStreams.splice(t,1),this._maybeFireNegotiationNeeded())},n.prototype.getSenders=function(){return this.transceivers.filter(function(e){return!!e.rtpSender}).map(function(e){return e.rtpSender})},n.prototype.getReceivers=function(){return this.transceivers.filter(function(e){return!!e.rtpReceiver}).map(function(e){return e.rtpReceiver})},n.prototype._createIceGatherer=function(t,n){var i=this,o=new e.RTCIceGatherer(i.iceOptions);return o.onlocalcandidate=function(e){var a=new Event("icecandidate");a.candidate={sdpMid:t,sdpMLineIndex:n};var s=e.candidate,c=!s||0===Object.keys(s).length;c?void 0===o.state&&(o.state="completed"):(s.component=1,a.candidate.candidate=r.writeCandidate(s));var d=r.splitSections(i.localDescription.sdp);d[a.candidate.sdpMLineIndex+1]+=c?"a=end-of-candidates\r\n":"a="+a.candidate.candidate+"\r\n",i.localDescription.sdp=d.join("");var p=(i._pendingOffer?i._pendingOffer:i.transceivers).every(function(e){return e.iceGatherer&&"completed"===e.iceGatherer.state});switch(i.iceGatheringState){case"new":c||i._localIceCandidatesBuffer.push(a),c&&p&&i._localIceCandidatesBuffer.push(new Event("icecandidate"));break;case"gathering":i._emitBufferedCandidates(),c||(i.dispatchEvent(a),null!==i.onicecandidate&&i.onicecandidate(a)),p&&(i.dispatchEvent(new Event("icecandidate")),null!==i.onicecandidate&&i.onicecandidate(new Event("icecandidate")),i.iceGatheringState="complete",i._emitGatheringStateChange())}},o},n.prototype._createIceAndDtlsTransports=function(){var t=this,n=new e.RTCIceTransport(null);n.onicestatechange=function(){t._updateConnectionState()};var r=new e.RTCDtlsTransport(n);return r.ondtlsstatechange=function(){t._updateConnectionState()},r.onerror=function(){Object.defineProperty(r,"state",{value:"failed",writable:!0}),t._updateConnectionState()},{iceTransport:n,dtlsTransport:r}},n.prototype._disposeIceAndDtlsTransports=function(e){var t=this.transceivers[e].iceGatherer;t&&(delete t.onlocalcandidate,delete this.transceivers[e].iceGatherer);var n=this.transceivers[e].iceTransport;n&&(delete n.onicestatechange,delete this.transceivers[e].iceTransport);var r=this.transceivers[e].dtlsTransport;r&&(delete r.ondtlsstatechange,delete r.onerror,delete this.transceivers[e].dtlsTransport)},n.prototype._transceive=function(e,n,o){var a=i(e.localCapabilities,e.remoteCapabilities);n&&e.rtpSender&&(a.encodings=e.sendEncodingParameters,a.rtcp={cname:r.localCName,compound:e.rtcpParameters.compound},e.recvEncodingParameters.length&&(a.rtcp.ssrc=e.recvEncodingParameters[0].ssrc),e.rtpSender.send(a)),o&&e.rtpReceiver&&("video"===e.kind&&e.recvEncodingParameters&&t<15019&&e.recvEncodingParameters.forEach(function(e){delete e.rtx}),a.encodings=e.recvEncodingParameters,a.rtcp={cname:e.rtcpParameters.cname,compound:e.rtcpParameters.compound},e.sendEncodingParameters.length&&(a.rtcp.ssrc=e.sendEncodingParameters[0].ssrc),e.rtpReceiver.receive(a))},n.prototype.setLocalDescription=function(t){var n,a,s=this;if(!o("setLocalDescription",t.type,this.signalingState)){var c=new Error("Can not set local "+t.type+" in state "+this.signalingState);return c.name="InvalidStateError",arguments.length>2&&"function"==typeof arguments[2]&&e.setTimeout(arguments[2],0,c),Promise.reject(c)}if("offer"===t.type)this._pendingOffer&&(n=r.splitSections(t.sdp),a=n.shift(),n.forEach(function(e,t){var n=r.parseRtpParameters(e);s._pendingOffer[t].localCapabilities=n}),this.transceivers=this._pendingOffer,delete this._pendingOffer);else if("answer"===t.type){n=r.splitSections(s.remoteDescription.sdp),a=n.shift();var d=r.matchPrefix(a,"a=ice-lite").length>0;n.forEach(function(e,t){var n=s.transceivers[t],o=n.iceGatherer,c=n.iceTransport,p=n.dtlsTransport,u=n.localCapabilities,l=n.remoteCapabilities;if(!r.isRejected(e)&&!n.isDatachannel){var f=r.getIceParameters(e,a),m=r.getDtlsParameters(e,a);d&&(m.role="server"),s.usingBundle&&0!==t||(c.start(o,f,d?"controlling":"controlled"),p.start(m));var h=i(u,l);s._transceive(n,h.codecs.length>0,!1)}})}switch(this.localDescription={type:t.type,sdp:t.sdp},t.type){case"offer":this._updateSignalingState("have-local-offer");break;case"answer":this._updateSignalingState("stable");break;default:throw new TypeError('unsupported type "'+t.type+'"')}var p=arguments.length>1&&"function"==typeof arguments[1];if(p){var u=arguments[1];e.setTimeout(function(){u(),"new"===s.iceGatheringState&&(s.iceGatheringState="gathering",s._emitGatheringStateChange()),s._emitBufferedCandidates()},0)}var l=Promise.resolve();return l.then(function(){p||("new"===s.iceGatheringState&&(s.iceGatheringState="gathering",s._emitGatheringStateChange()),e.setTimeout(s._emitBufferedCandidates.bind(s),500))}),l},n.prototype.setRemoteDescription=function(n){var i=this;if(!o("setRemoteDescription",n.type,this.signalingState)){var a=new Error("Can not set remote "+n.type+" in state "+this.signalingState);return a.name="InvalidStateError",arguments.length>2&&"function"==typeof arguments[2]&&e.setTimeout(arguments[2],0,a),Promise.reject(a)}var s={},c=[],d=r.splitSections(n.sdp),p=d.shift(),u=r.matchPrefix(p,"a=ice-lite").length>0,l=r.matchPrefix(p,"a=group:BUNDLE ").length>0;this.usingBundle=l;var f=r.matchPrefix(p,"a=ice-options:")[0];switch(this.canTrickleIceCandidates=!!f&&f.substr(14).split(" ").indexOf("trickle")>=0,d.forEach(function(o,a){var d=r.splitLines(o),f=r.getKind(o),m=r.isRejected(o),h=d[0].substr(2).split(" ")[2],v=r.getDirection(o,p),g=r.parseMsid(o),y=r.getMid(o)||r.generateIdentifier();if("application"!==f||"DTLS/SCTP"!==h){var C,b,S,T,R,P,w,k,_,E,O,D=r.parseRtpParameters(o);m||(E=r.getIceParameters(o,p),(O=r.getDtlsParameters(o,p)).role="client"),w=r.parseRtpEncodingParameters(o);var j=r.parseRtcpParameters(o),x=r.matchPrefix(o,"a=end-of-candidates",p).length>0,I=r.matchPrefix(o,"a=candidate:").map(function(e){return r.parseCandidate(e)}).filter(function(e){return"1"===e.component||1===e.component});("offer"===n.type||"answer"===n.type)&&!m&&l&&a>0&&i.transceivers[a]&&(i._disposeIceAndDtlsTransports(a),i.transceivers[a].iceGatherer=i.transceivers[0].iceGatherer,i.transceivers[a].iceTransport=i.transceivers[0].iceTransport,i.transceivers[a].dtlsTransport=i.transceivers[0].dtlsTransport,i.transceivers[a].rtpSender&&i.transceivers[a].rtpSender.setTransport(i.transceivers[0].dtlsTransport),i.transceivers[a].rtpReceiver&&i.transceivers[a].rtpReceiver.setTransport(i.transceivers[0].dtlsTransport)),"offer"!==n.type||m?"answer"!==n.type||m||(b=(C=i.transceivers[a]).iceGatherer,S=C.iceTransport,T=C.dtlsTransport,R=C.rtpReceiver,P=C.sendEncodingParameters,k=C.localCapabilities,i.transceivers[a].recvEncodingParameters=w,i.transceivers[a].remoteCapabilities=D,i.transceivers[a].rtcpParameters=j,l&&0!==a||((u||x)&&I.length&&S.setRemoteCandidates(I),S.start(b,E,"controlling"),T.start(O)),i._transceive(C,"sendrecv"===v||"recvonly"===v,"sendrecv"===v||"sendonly"===v),!R||"sendrecv"!==v&&"sendonly"!==v?delete C.rtpReceiver:(_=R.track,g?(s[g.stream]||(s[g.stream]=new e.MediaStream),s[g.stream].addTrack(_),c.push([_,R,s[g.stream]])):(s.default||(s.default=new e.MediaStream),s.default.addTrack(_),c.push([_,R,s.default])))):((C=i.transceivers[a]||i._createTransceiver(f)).mid=y,C.iceGatherer||(C.iceGatherer=l&&a>0?i.transceivers[0].iceGatherer:i._createIceGatherer(y,a)),!x||!I.length||l&&0!==a||C.iceTransport.setRemoteCandidates(I),k=e.RTCRtpReceiver.getCapabilities(f),t<15019&&(k.codecs=k.codecs.filter(function(e){return"rtx"!==e.name})),P=[{ssrc:1001*(2*a+2)}],"sendrecv"!==v&&"sendonly"!==v||(_=(R=new e.RTCRtpReceiver(C.dtlsTransport,f)).track,g?(s[g.stream]||(s[g.stream]=new e.MediaStream,Object.defineProperty(s[g.stream],"id",{get:function(){return g.stream}})),Object.defineProperty(_,"id",{get:function(){return g.track}}),s[g.stream].addTrack(_),c.push([_,R,s[g.stream]])):(s.default||(s.default=new e.MediaStream),s.default.addTrack(_),c.push([_,R,s.default]))),C.localCapabilities=k,C.remoteCapabilities=D,C.rtpReceiver=R,C.rtcpParameters=j,C.sendEncodingParameters=P,C.recvEncodingParameters=w,i._transceive(i.transceivers[a],!1,"sendrecv"===v||"sendonly"===v))}else i.transceivers[a]={mid:y,isDatachannel:!0}}),this.remoteDescription={type:n.type,sdp:n.sdp},n.type){case"offer":this._updateSignalingState("have-remote-offer");break;case"answer":this._updateSignalingState("stable");break;default:throw new TypeError('unsupported type "'+n.type+'"')}return Object.keys(s).forEach(function(t){var n=s[t];if(n.getTracks().length){i.remoteStreams.push(n);var r=new Event("addstream");r.stream=n,i.dispatchEvent(r),null!==i.onaddstream&&e.setTimeout(function(){i.onaddstream(r)},0),c.forEach(function(t){var r=t[0],o=t[1];if(n.id===t[2].id){var a=new Event("track");a.track=r,a.receiver=o,a.streams=[n],i.dispatchEvent(a),null!==i.ontrack&&e.setTimeout(function(){i.ontrack(a)},0)}})}}),e.setTimeout(function(){i&&i.transceivers&&i.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),arguments.length>1&&"function"==typeof arguments[1]&&e.setTimeout(arguments[1],0),Promise.resolve()},n.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._updateSignalingState("closed")},n.prototype._updateSignalingState=function(e){this.signalingState=e;var t=new Event("signalingstatechange");this.dispatchEvent(t),null!==this.onsignalingstatechange&&this.onsignalingstatechange(t)},n.prototype._maybeFireNegotiationNeeded=function(){var t=this;"stable"===this.signalingState&&!0!==this.needNegotiation&&(this.needNegotiation=!0,e.setTimeout(function(){if(!1!==t.needNegotiation){t.needNegotiation=!1;var e=new Event("negotiationneeded");t.dispatchEvent(e),null!==t.onnegotiationneeded&&t.onnegotiationneeded(e)}},0))},n.prototype._updateConnectionState=function(){var e,t={new:0,closed:0,connecting:0,checking: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||t.checking>0?e="connecting":t.disconnected>0?e="disconnected":t.new>0?e="new":(t.connected>0||t.completed>0)&&(e="connected"),e!==this.iceConnectionState){this.iceConnectionState=e;var n=new Event("iceconnectionstatechange");this.dispatchEvent(n),null!==this.oniceconnectionstatechange&&this.oniceconnectionstatechange(n)}},n.prototype.createOffer=function(){var n,i=this;if(this._pendingOffer)throw new Error("createOffer called while there is a pending offer.");1===arguments.length&&"function"!=typeof arguments[0]?n=arguments[0]:3===arguments.length&&(n=arguments[2]);var o=this.transceivers.filter(function(e){return"audio"===e.kind}).length,a=this.transceivers.filter(function(e){return"video"===e.kind}).length;if(n){if(n.mandatory||n.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");void 0!==n.offerToReceiveAudio&&(o=!0===n.offerToReceiveAudio?1:!1===n.offerToReceiveAudio?0:n.offerToReceiveAudio),void 0!==n.offerToReceiveVideo&&(a=!0===n.offerToReceiveVideo?1:!1===n.offerToReceiveVideo?0:n.offerToReceiveVideo)}for(this.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&&(this._createTransceiver("audio"),o--),a>0&&(this._createTransceiver("video"),a--);var s=function(e){var t=e.filter(function(e){return"audio"===e.kind}),n=e.filter(function(e){return"video"===e.kind});for(e=[];t.length||n.length;)t.length&&e.push(t.shift()),n.length&&e.push(n.shift());return e}(this.transceivers),c=r.writeSessionBoilerplate(this._sdpSessionId);s.forEach(function(n,o){var a=n.track,c=n.kind,d=r.generateIdentifier();n.mid=d,n.iceGatherer||(n.iceGatherer=i.usingBundle&&o>0?s[0].iceGatherer:i._createIceGatherer(d,o));var p=e.RTCRtpSender.getCapabilities(c);t<15019&&(p.codecs=p.codecs.filter(function(e){return"rtx"!==e.name})),p.codecs.forEach(function(e){"H264"===e.name&&void 0===e.parameters["level-asymmetry-allowed"]&&(e.parameters["level-asymmetry-allowed"]="1")});var u=[{ssrc:1001*(2*o+1)}];a&&t>=15019&&"video"===c&&(u[0].rtx={ssrc:1001*(2*o+1)+1}),n.wantReceive&&(n.rtpReceiver=new e.RTCRtpReceiver(n.dtlsTransport,c)),n.localCapabilities=p,n.sendEncodingParameters=u}),"max-compat"!==this._config.bundlePolicy&&(c+="a=group:BUNDLE "+s.map(function(e){return e.mid}).join(" ")+"\r\n"),c+="a=ice-options:trickle\r\n",s.forEach(function(e,t){c+=r.writeMediaSection(e,e.localCapabilities,"offer",e.stream),c+="a=rtcp-rsize\r\n"}),this._pendingOffer=s;var d=new e.RTCSessionDescription({type:"offer",sdp:c});return arguments.length&&"function"==typeof arguments[0]&&e.setTimeout(arguments[0],0,d),Promise.resolve(d)},n.prototype.createAnswer=function(){var n=r.writeSessionBoilerplate(this._sdpSessionId);this.usingBundle&&(n+="a=group:BUNDLE "+this.transceivers.map(function(e){return e.mid}).join(" ")+"\r\n"),this.transceivers.forEach(function(e,o){if(e.isDatachannel)n+="m=application 0 DTLS/SCTP 5000\r\nc=IN IP4 0.0.0.0\r\na=mid:"+e.mid+"\r\n";else{var a;if(e.stream)"audio"===e.kind?a=e.stream.getAudioTracks()[0]:"video"===e.kind&&(a=e.stream.getVideoTracks()[0]),a&&t>=15019&&"video"===e.kind&&(e.sendEncodingParameters[0].rtx={ssrc:1001*(2*o+2)+1});var s=i(e.localCapabilities,e.remoteCapabilities);!s.codecs.filter(function(e){return"rtx"===e.name.toLowerCase()}).length&&e.sendEncodingParameters[0].rtx&&delete e.sendEncodingParameters[0].rtx,n+=r.writeMediaSection(e,s,"answer",e.stream),e.rtcpParameters&&e.rtcpParameters.reducedSize&&(n+="a=rtcp-rsize\r\n")}});var o=new e.RTCSessionDescription({type:"answer",sdp:n});return arguments.length&&"function"==typeof arguments[0]&&e.setTimeout(arguments[0],0,o),Promise.resolve(o)},n.prototype.addIceCandidate=function(t){if(t){var n=t.sdpMLineIndex;if(t.sdpMid)for(var i=0;i0?r.parseCandidate(t.candidate):{};if("tcp"===a.protocol&&(0===a.port||9===a.port))return Promise.resolve();if(a.component&&"1"!==a.component&&1!==a.component)return Promise.resolve();o.iceTransport.addRemoteCandidate(a);var s=r.splitSections(this.remoteDescription.sdp);s[n+1]+=(a.type?t.candidate.trim():"a=end-of-candidates")+"\r\n",this.remoteDescription.sdp=s.join("")}}else for(var c=0;c1&&"function"==typeof arguments[1]&&e.setTimeout(arguments[1],0),Promise.resolve()},n.prototype.getStats=function(){var t=[];this.transceivers.forEach(function(e){["rtpSender","rtpReceiver","iceGatherer","iceTransport","dtlsTransport"].forEach(function(n){e[n]&&t.push(e[n].getStats())})});var n=arguments.length>1&&"function"==typeof arguments[1]&&arguments[1];return new Promise(function(r){var i=new Map;Promise.all(t).then(function(t){t.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]),i.set(t,e[t])})}),n&&e.setTimeout(n,0,i),r(i)})})},n}},function(e,t,n){"use strict";var r={generateIdentifier:function(){return Math.random().toString(36).substr(2,10)}};r.localCName=r.generateIdentifier(),r.splitLines=function(e){return e.trim().split("\n").map(function(e){return e.trim()})},r.splitSections=function(e){return e.split("\nm=").map(function(e,t){return(t>0?"m="+e:e).trim()+"\r\n"})},r.getDescription=function(e){var t=r.splitSections(e);return t&&t[0]},r.getMediaSections=function(e){var t=r.splitSections(e);return t.shift(),t},r.matchPrefix=function(e,t){return r.splitLines(e).filter(function(e){return 0===e.indexOf(t)})},r.parseCandidate=function(e){for(var t,n={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]},r=8;r0?t[0].split("/")[1]:"sendrecv",uri:t[1]}},r.writeExtmap=function(e){return"a=extmap:"+(e.id||e.preferredId)+(e.direction&&"sendrecv"!==e.direction?"/"+e.direction:"")+" "+e.uri+"\r\n"},r.parseFmtp=function(e){for(var t,n={},r=e.substr(e.indexOf(" ")+1).split(";"),i=0;i-1?(n.attribute=e.substr(t+1,r-t-1),n.value=e.substr(r+1)):n.attribute=e.substr(t+1),n},r.getMid=function(e){var t=r.matchPrefix(e,"a=mid:")[0];if(t)return t.substr(6)},r.parseFingerprint=function(e){var t=e.substr(14).split(" ");return{algorithm:t[0].toLowerCase(),value:t[1]}},r.getDtlsParameters=function(e,t){return{role:"auto",fingerprints:r.matchPrefix(e+t,"a=fingerprint:").map(r.parseFingerprint)}},r.writeDtlsParameters=function(e,t){var n="a=setup:"+t+"\r\n";return e.fingerprints.forEach(function(e){n+="a=fingerprint:"+e.algorithm+" "+e.value+"\r\n"}),n},r.getIceParameters=function(e,t){var n=r.splitLines(e);return{usernameFragment:(n=n.concat(r.splitLines(t))).filter(function(e){return 0===e.indexOf("a=ice-ufrag:")})[0].substr(12),password:n.filter(function(e){return 0===e.indexOf("a=ice-pwd:")})[0].substr(10)}},r.writeIceParameters=function(e){return"a=ice-ufrag:"+e.usernameFragment+"\r\na=ice-pwd:"+e.password+"\r\n"},r.parseRtpParameters=function(e){for(var t={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},n=r.splitLines(e)[0].split(" "),i=3;i0?"9":"0",n+=" UDP/TLS/RTP/SAVPF ",n+=t.codecs.map(function(e){return void 0!==e.preferredPayloadType?e.preferredPayloadType:e.payloadType}).join(" ")+"\r\n",n+="c=IN IP4 0.0.0.0\r\n",n+="a=rtcp:9 IN IP4 0.0.0.0\r\n",t.codecs.forEach(function(e){n+=r.writeRtpMap(e),n+=r.writeFmtp(e),n+=r.writeRtcpFb(e)});var i=0;return t.codecs.forEach(function(e){e.maxptime>i&&(i=e.maxptime)}),i>0&&(n+="a=maxptime:"+i+"\r\n"),n+="a=rtcp-mux\r\n",t.headerExtensions.forEach(function(e){n+=r.writeExtmap(e)}),n},r.parseRtpEncodingParameters=function(e){var t,n=[],i=r.parseRtpParameters(e),o=-1!==i.fecMechanisms.indexOf("RED"),a=-1!==i.fecMechanisms.indexOf("ULPFEC"),s=r.matchPrefix(e,"a=ssrc:").map(function(e){return r.parseSsrcMedia(e)}).filter(function(e){return"cname"===e.attribute}),c=s.length>0&&s[0].ssrc,d=r.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 r={ssrc:c,codecPayloadType:parseInt(e.parameters.apt,10),rtx:{ssrc:t}};n.push(r),o&&((r=JSON.parse(JSON.stringify(r))).fec={ssrc:t,mechanism:a?"red+ulpfec":"red"},n.push(r))}}),0===n.length&&c&&n.push({ssrc:c});var p=r.matchPrefix(e,"b=");return p.length&&(p=0===p[0].indexOf("b=TIAS:")?parseInt(p[0].substr(7),10):0===p[0].indexOf("b=AS:")?1e3*parseInt(p[0].substr(5),10)*.95-16e3:void 0,n.forEach(function(e){e.maxBitrate=p})),n},r.parseRtcpParameters=function(e){var t={},n=r.matchPrefix(e,"a=ssrc:").map(function(e){return r.parseSsrcMedia(e)}).filter(function(e){return"cname"===e.attribute})[0];n&&(t.cname=n.value,t.ssrc=n.ssrc);var i=r.matchPrefix(e,"a=rtcp-rsize");t.reducedSize=i.length>0,t.compound=0===i.length;var o=r.matchPrefix(e,"a=rtcp-mux");return t.mux=o.length>0,t},r.parseMsid=function(e){var t,n=r.matchPrefix(e,"a=msid:");if(1===n.length)return{stream:(t=n[0].substr(7).split(" "))[0],track:t[1]};var i=r.matchPrefix(e,"a=ssrc:").map(function(e){return r.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},r.generateSessionId=function(){return Math.random().toString().substr(2,21)},r.writeSessionBoilerplate=function(e,t){var n=void 0!==t?t:2;return"v=0\r\no=thisisadapterortc "+(e||r.generateSessionId())+" "+n+" IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n"},r.writeMediaSection=function(e,t,n,i){var o=r.writeRtpDescription(e.kind,t);if(o+=r.writeIceParameters(e.iceGatherer.getLocalParameters()),o+=r.writeDtlsParameters(e.dtlsTransport.getLocalParameters(),"offer"===n?"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:"+r.localCName+"\r\n",e.rtpSender&&e.sendEncodingParameters[0].rtx&&(o+="a=ssrc:"+e.sendEncodingParameters[0].rtx.ssrc+" cname:"+r.localCName+"\r\n"),o},r.getDirection=function(e,t){for(var n=r.splitLines(e),i=0;i55&&"autoGainControl"in n.mediaDevices.getSupportedConstraints())){var p=function(e,t,n){t in e&&!(n in e)&&(e[n]=e[t],delete e[t])},u=n.mediaDevices.getUserMedia.bind(n.mediaDevices);if(n.mediaDevices.getUserMedia=function(e){return"object"==typeof e&&"object"==typeof e.audio&&(e=JSON.parse(JSON.stringify(e)),p(e.audio,"autoGainControl","mozAutoGainControl"),p(e.audio,"noiseSuppression","mozNoiseSuppression")),u(e)},o&&o.prototype.getSettings){var l=o.prototype.getSettings;o.prototype.getSettings=function(){var e=l.apply(this,arguments);return p(e,"mozAutoGainControl","autoGainControl"),p(e,"mozNoiseSuppression","noiseSuppression"),e}}if(o&&o.prototype.applyConstraints){var f=o.prototype.applyConstraints;o.prototype.applyConstraints=function(e){return"audio"===this.kind&&"object"==typeof e&&(e=JSON.parse(JSON.stringify(e)),p(e,"autoGainControl","mozAutoGainControl"),p(e,"noiseSuppression","mozNoiseSuppression")),f.apply(this,[e])}}}n.getUserMedia=function(e,i,o){if(t.version<44)return s(e,i,o);r.deprecated("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),n.mediaDevices.getUserMedia(e).then(i,o)}}},function(e,t,n){"use strict";var r=n(0),i={shimLocalStreamsAPI:function(e){if("object"==typeof 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(n){n.id===e&&(t=n)}),this._remoteStreams&&this._remoteStreams.forEach(function(n){n.id===e&&(t=n)}),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 n=this;e.getTracks().forEach(function(r){t.call(n,r,e)})},e.RTCPeerConnection.prototype.addTrack=function(e,n){n&&(this._localStreams?-1===this._localStreams.indexOf(n)&&this._localStreams.push(n):this._localStreams=[n]),t.call(this,e,n)}}"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 n=this,r=e.getTracks();this.getSenders().forEach(function(e){-1!==r.indexOf(e.track)&&n.removeTrack(e)})}})}},shimRemoteStreamsAPI:function(e){"object"==typeof 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){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){var t=e.streams[0];if(this._remoteStreams||(this._remoteStreams=[]),!(this._remoteStreams.indexOf(t)>=0)){this._remoteStreams.push(t);var n=new Event("addstream");n.stream=e.streams[0],this.dispatchEvent(n)}}.bind(this))}}))},shimCallbacksAPI:function(e){if("object"==typeof e&&e.RTCPeerConnection){var t=e.RTCPeerConnection.prototype,n=t.createOffer,r=t.createAnswer,i=t.setLocalDescription,o=t.setRemoteDescription,a=t.addIceCandidate;t.createOffer=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},t.createAnswer=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};var s=function(e,t,n){var r=i.apply(this,[e]);return n?(r.then(t,n),Promise.resolve()):r};t.setLocalDescription=s,s=function(e,t,n){var r=o.apply(this,[e]);return n?(r.then(t,n),Promise.resolve()):r},t.setRemoteDescription=s,s=function(e,t,n){var r=a.apply(this,[e]);return n?(r.then(t,n),Promise.resolve()):r},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,n,r){t.mediaDevices.getUserMedia(e).then(n,r)}.bind(t)))},shimRTCIceServerUrls:function(e){var t=e.RTCPeerConnection;e.RTCPeerConnection=function(e,n){if(e&&e.iceServers){for(var i=[],o=0;o=1,n=arguments.length>=2;if(!(this instanceof i))return r?n?new i(e,t):new i(e):new i;if(void 0===e){if(r)throw new TypeError("undefined is not a valid argument for URI");e="undefined"!=typeof location?location.href+"":""}if(null===e&&r)throw new TypeError("null is not a valid argument for URI");return this.href(e),void 0!==t?this.absoluteTo(t):this}i.version="1.19.1";var a=i.prototype,s=Object.prototype.hasOwnProperty;function u(e){return e.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function c(e){return void 0===e?"Undefined":String(Object.prototype.toString.call(e)).slice(8,-1)}function h(e){return"Array"===c(e)}function l(e,t){var r,n,o={};if("RegExp"===c(t))o=null;else if(h(t))for(r=0,n=t.length;r]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,i.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?«»“”„‘’]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g},i.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},i.hostProtocols=["http","https"],i.invalid_hostname_characters=/[^a-zA-Z0-9\.\-:_]/,i.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"},i.getDomAttribute=function(e){if(e&&e.nodeName){var t=e.nodeName.toLowerCase();if("input"!==t||"image"===e.type)return i.domAttributes[t]}},i.encode=f,i.decode=decodeURIComponent,i.iso8859=function(){i.encode=escape,i.decode=unescape},i.unicode=function(){i.encode=f,i.decode=decodeURIComponent},i.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/gi,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}},i.encodeQuery=function(e,t){var r=i.encode(e+"");return void 0===t&&(t=i.escapeQuerySpace),t?r.replace(/%20/g,"+"):r},i.decodeQuery=function(e,t){e+="",void 0===t&&(t=i.escapeQuerySpace);try{return i.decode(t?e.replace(/\+/g,"%20"):e)}catch(t){return e}};var v,y={encode:"encode",decode:"decode"},b=function(e,t){return function(r){try{return i[t](r+"").replace(i.characters[e][t].expression,function(r){return i.characters[e][t].map[r]})}catch(e){return r}}};for(v in y)i[v+"PathSegment"]=b("pathname",y[v]),i[v+"UrnPathSegment"]=b("urnpath",y[v]);var _=function(e,t,r){return function(n){var o;o=r?function(e){return i[t](i[r](e))}:i[t];for(var a=(n+"").split(e),s=0,u=a.length;s-1&&(t.fragment=e.substring(r+1)||null,e=e.substring(0,r)),(r=e.indexOf("?"))>-1&&(t.query=e.substring(r+1)||null,e=e.substring(0,r)),"//"===e.substring(0,2)?(t.protocol=null,e=e.substring(2),e=i.parseAuthority(e,t)):(r=e.indexOf(":"))>-1&&(t.protocol=e.substring(0,r)||null,t.protocol&&!t.protocol.match(i.protocol_expression)?t.protocol=void 0:"//"===e.substring(r+1,r+3)?(e=e.substring(r+3),e=i.parseAuthority(e,t)):(e=e.substring(r+1),t.urn=!0)),t.path=e,t},i.parseHost=function(e,t){e||(e="");var r,n,o=(e=e.replace(/\\/g,"/")).indexOf("/");if(-1===o&&(o=e.length),"["===e.charAt(0))r=e.indexOf("]"),t.hostname=e.substring(1,r)||null,t.port=e.substring(r+2,o)||null,"/"===t.port&&(t.port=null);else{var a=e.indexOf(":"),s=e.indexOf("/"),u=e.indexOf(":",a+1);-1!==u&&(-1===s||u-1?n:e.length-1);return o>-1&&(-1===n||o-1?d.slice(0,g)+d.slice(g).replace(a,""):d.replace(a,"")).length<=c[0].length||r.ignore&&r.ignore.test(d))){var v=t(d,h,p=h+d.length,e);void 0!==v?(v=String(v),e=e.slice(0,h)+v+e.slice(p),n.lastIndex=h+v.length):n.lastIndex=p}}return n.lastIndex=0,e},i.ensureValidHostname=function(t,r){var n=!!t,o=!1;if(!!r&&(o=p(i.hostProtocols,r)),o&&!n)throw new TypeError("Hostname cannot be empty, if protocol is "+r);if(t&&t.match(i.invalid_hostname_characters)){if(!e)throw new TypeError('Hostname "'+t+'" contains characters other than [A-Z0-9.-:_] and Punycode.js is not available');if(e.toASCII(t).match(i.invalid_hostname_characters))throw new TypeError('Hostname "'+t+'" contains characters other than [A-Z0-9.-:_]')}},i.ensureValidPort=function(e){if(e){var t=Number(e);if(!(function(e){return/^[0-9]+$/.test(e)}(t)&&t>0&&t<65536))throw new TypeError('Port "'+e+'" is not a valid port')}},i.noConflict=function(e){if(e){var t={URI:this.noConflict()};return n.URITemplate&&"function"==typeof n.URITemplate.noConflict&&(t.URITemplate=n.URITemplate.noConflict()),n.IPv6&&"function"==typeof n.IPv6.noConflict&&(t.IPv6=n.IPv6.noConflict()),n.SecondLevelDomains&&"function"==typeof n.SecondLevelDomains.noConflict&&(t.SecondLevelDomains=n.SecondLevelDomains.noConflict()),t}return n.URI===this&&(n.URI=o),this},a.build=function(e){return!0===e?this._deferred_build=!0:(void 0===e||this._deferred_build)&&(this._string=i.build(this._parts),this._deferred_build=!1),this},a.clone=function(){return new i(this)},a.valueOf=a.toString=function(){return this.build(!1)._string},a.protocol=w("protocol"),a.username=w("username"),a.password=w("password"),a.hostname=w("hostname"),a.port=w("port"),a.query=k("query","?"),a.fragment=k("fragment","#"),a.search=function(e,t){var r=this.query(e,t);return"string"==typeof r&&r.length?"?"+r:r},a.hash=function(e,t){var r=this.fragment(e,t);return"string"==typeof r&&r.length?"#"+r:r},a.pathname=function(e,t){if(void 0===e||!0===e){var r=this._parts.path||(this._parts.hostname?"/":"");return e?(this._parts.urn?i.decodeUrnPath:i.decodePath)(r):r}return this._parts.urn?this._parts.path=e?i.recodeUrnPath(e):"":this._parts.path=e?i.recodePath(e):"/",this.build(!t),this},a.path=a.pathname,a.href=function(e,t){var r;if(void 0===e)return this.toString();this._string="",this._parts=i._parts();var n=e instanceof i,o="object"==typeof e&&(e.hostname||e.path||e.pathname);e.nodeName&&(e=e[i.getDomAttribute(e)]||"",o=!1);if(!n&&o&&void 0!==e.pathname&&(e=e.toString()),"string"==typeof e||e instanceof String)this._parts=i.parse(String(e),this._parts);else{if(!n&&!o)throw new TypeError("invalid input");var a=n?e._parts:e;for(r in a)"query"!==r&&s.call(this._parts,r)&&(this._parts[r]=a[r]);a.query&&this.query(a.query,!1)}return this.build(!t),this},a.is=function(e){var t=!1,n=!1,o=!1,a=!1,s=!1,u=!1,c=!1,h=!this._parts.urn;switch(this._parts.hostname&&(h=!1,n=i.ip4_expression.test(this._parts.hostname),o=i.ip6_expression.test(this._parts.hostname),s=(a=!(t=n||o))&&r&&r.has(this._parts.hostname),u=a&&i.idn_expression.test(this._parts.hostname),c=a&&i.punycode_expression.test(this._parts.hostname)),e.toLowerCase()){case"relative":return h;case"absolute":return!h;case"domain":case"name":return a;case"sld":return s;case"ip":return t;case"ip4":case"ipv4":case"inet4":return n;case"ip6":case"ipv6":case"inet6":return o;case"idn":return u;case"url":return!this._parts.urn;case"urn":return!!this._parts.urn;case"punycode":return c}return null};var x=a.protocol,z=a.port,P=a.hostname;a.protocol=function(e,t){if(e&&!(e=e.replace(/:(\/\/)?$/,"")).match(i.protocol_expression))throw new TypeError('Protocol "'+e+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return x.call(this,e,t)},a.scheme=a.protocol,a.port=function(e,t){return this._parts.urn?void 0===e?"":this:(void 0!==e&&(0===e&&(e=null),e&&(":"===(e+="").charAt(0)&&(e=e.substring(1)),i.ensureValidPort(e))),z.call(this,e,t))},a.hostname=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0!==e){var r={preventInvalidHostname:this._parts.preventInvalidHostname};if("/"!==i.parseHost(e,r))throw new TypeError('Hostname "'+e+'" contains characters other than [A-Z0-9.-]');e=r.hostname,this._parts.preventInvalidHostname&&i.ensureValidHostname(e,this._parts.protocol)}return P.call(this,e,t)},a.origin=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e){var r=this.protocol();return this.authority()?(r?r+"://":"")+this.authority():""}var n=i(e);return this.protocol(n.protocol()).authority(n.authority()).build(!t),this},a.host=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e)return this._parts.hostname?i.buildHost(this._parts):"";if("/"!==i.parseHost(e,this._parts))throw new TypeError('Hostname "'+e+'" contains characters other than [A-Z0-9.-]');return this.build(!t),this},a.authority=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e)return this._parts.hostname?i.buildAuthority(this._parts):"";if("/"!==i.parseAuthority(e,this._parts))throw new TypeError('Hostname "'+e+'" contains characters other than [A-Z0-9.-]');return this.build(!t),this},a.userinfo=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e){var r=i.buildUserinfo(this._parts);return r?r.substring(0,r.length-1):r}return"@"!==e[e.length-1]&&(e+="@"),i.parseUserinfo(e,this._parts),this.build(!t),this},a.resource=function(e,t){var r;return void 0===e?this.path()+this.search()+this.hash():(r=i.parse(e),this._parts.path=r.path,this._parts.query=r.query,this._parts.fragment=r.fragment,this.build(!t),this)},a.subdomain=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,r)||""}var n=this._parts.hostname.length-this.domain().length,o=this._parts.hostname.substring(0,n),a=new RegExp("^"+u(o));if(e&&"."!==e.charAt(e.length-1)&&(e+="."),-1!==e.indexOf(":"))throw new TypeError("Domains cannot contain colons");return e&&i.ensureValidHostname(e,this._parts.protocol),this._parts.hostname=this._parts.hostname.replace(a,e),this.build(!t),this},a.domain=function(e,t){if(this._parts.urn)return void 0===e?"":this;if("boolean"==typeof e&&(t=e,e=void 0),void 0===e){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.match(/\./g);if(r&&r.length<2)return this._parts.hostname;var n=this._parts.hostname.length-this.tld(t).length-1;return n=this._parts.hostname.lastIndexOf(".",n-1)+1,this._parts.hostname.substring(n)||""}if(!e)throw new TypeError("cannot set domain empty");if(-1!==e.indexOf(":"))throw new TypeError("Domains cannot contain colons");if(i.ensureValidHostname(e,this._parts.protocol),!this._parts.hostname||this.is("IP"))this._parts.hostname=e;else{var o=new RegExp(u(this.domain())+"$");this._parts.hostname=this._parts.hostname.replace(o,e)}return this.build(!t),this},a.tld=function(e,t){if(this._parts.urn)return void 0===e?"":this;if("boolean"==typeof e&&(t=e,e=void 0),void 0===e){if(!this._parts.hostname||this.is("IP"))return"";var n=this._parts.hostname.lastIndexOf("."),o=this._parts.hostname.substring(n+1);return!0!==t&&r&&r.list[o.toLowerCase()]&&r.get(this._parts.hostname)||o}var i;if(!e)throw new TypeError("cannot set TLD empty");if(e.match(/[^a-zA-Z0-9-]/)){if(!r||!r.is(e))throw new TypeError('TLD "'+e+'" contains characters other than [A-Z0-9]');i=new RegExp(u(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(i,e)}else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");i=new RegExp(u(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(i,e)}return this.build(!t),this},a.directory=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e||!0===e){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var r=this._parts.path.length-this.filename().length-1,n=this._parts.path.substring(0,r)||(this._parts.hostname?"/":"");return e?i.decodePath(n):n}var o=this._parts.path.length-this.filename().length,a=this._parts.path.substring(0,o),s=new RegExp("^"+u(a));return this.is("relative")||(e||(e="/"),"/"!==e.charAt(0)&&(e="/"+e)),e&&"/"!==e.charAt(e.length-1)&&(e+="/"),e=i.recodePath(e),this._parts.path=this._parts.path.replace(s,e),this.build(!t),this},a.filename=function(e,t){if(this._parts.urn)return void 0===e?"":this;if("string"!=typeof e){if(!this._parts.path||"/"===this._parts.path)return"";var r=this._parts.path.lastIndexOf("/"),n=this._parts.path.substring(r+1);return e?i.decodePathSegment(n):n}var o=!1;"/"===e.charAt(0)&&(e=e.substring(1)),e.match(/\.?\//)&&(o=!0);var a=new RegExp(u(this.filename())+"$");return e=i.recodePath(e),this._parts.path=this._parts.path.replace(a,e),o?this.normalizePath(t):this.build(!t),this},a.suffix=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e||!0===e){if(!this._parts.path||"/"===this._parts.path)return"";var r,n,o=this.filename(),a=o.lastIndexOf(".");return-1===a?"":(r=o.substring(a+1),n=/^[a-z0-9%]+$/i.test(r)?r:"",e?i.decodePathSegment(n):n)}"."===e.charAt(0)&&(e=e.substring(1));var s,c=this.suffix();if(c)s=e?new RegExp(u(c)+"$"):new RegExp(u("."+c)+"$");else{if(!e)return this;this._parts.path+="."+i.recodePath(e)}return s&&(e=i.recodePath(e),this._parts.path=this._parts.path.replace(s,e)),this.build(!t),this},a.segment=function(e,t,r){var n=this._parts.urn?":":"/",o=this.path(),i="/"===o.substring(0,1),a=o.split(n);if(void 0!==e&&"number"!=typeof e&&(r=t,t=e,e=void 0),void 0!==e&&"number"!=typeof e)throw new Error('Bad segment "'+e+'", must be 0-based integer');if(i&&a.shift(),e<0&&(e=Math.max(a.length+e,0)),void 0===t)return void 0===e?a:a[e];if(null===e||void 0===a[e])if(h(t)){a=[];for(var s=0,u=t.length;s=1,n=arguments.length>=2;if(!(this instanceof i))return r?n?new i(e,t):new i(e):new i;if(void 0===e){if(r)throw new TypeError("undefined is not a valid argument for URI");e="undefined"!=typeof location?location.href+"":""}if(null===e&&r)throw new TypeError("null is not a valid argument for URI");return this.href(e),void 0!==t?this.absoluteTo(t):this}i.version="1.19.1";var a=i.prototype,s=Object.prototype.hasOwnProperty;function u(e){return e.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function c(e){return void 0===e?"Undefined":String(Object.prototype.toString.call(e)).slice(8,-1)}function h(e){return"Array"===c(e)}function l(e,t){var r,n,o={};if("RegExp"===c(t))o=null;else if(h(t))for(r=0,n=t.length;r]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,i.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?«»“”„‘’]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g},i.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},i.hostProtocols=["http","https"],i.invalid_hostname_characters=/[^a-zA-Z0-9\.\-:_]/,i.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"},i.getDomAttribute=function(e){if(e&&e.nodeName){var t=e.nodeName.toLowerCase();if("input"!==t||"image"===e.type)return i.domAttributes[t]}},i.encode=f,i.decode=decodeURIComponent,i.iso8859=function(){i.encode=escape,i.decode=unescape},i.unicode=function(){i.encode=f,i.decode=decodeURIComponent},i.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/gi,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}},i.encodeQuery=function(e,t){var r=i.encode(e+"");return void 0===t&&(t=i.escapeQuerySpace),t?r.replace(/%20/g,"+"):r},i.decodeQuery=function(e,t){e+="",void 0===t&&(t=i.escapeQuerySpace);try{return i.decode(t?e.replace(/\+/g,"%20"):e)}catch(t){return e}};var v,y={encode:"encode",decode:"decode"},b=function(e,t){return function(r){try{return i[t](r+"").replace(i.characters[e][t].expression,function(r){return i.characters[e][t].map[r]})}catch(e){return r}}};for(v in y)i[v+"PathSegment"]=b("pathname",y[v]),i[v+"UrnPathSegment"]=b("urnpath",y[v]);var _=function(e,t,r){return function(n){var o;o=r?function(e){return i[t](i[r](e))}:i[t];for(var a=(n+"").split(e),s=0,u=a.length;s-1&&(t.fragment=e.substring(r+1)||null,e=e.substring(0,r)),(r=e.indexOf("?"))>-1&&(t.query=e.substring(r+1)||null,e=e.substring(0,r)),"//"===e.substring(0,2)?(t.protocol=null,e=e.substring(2),e=i.parseAuthority(e,t)):(r=e.indexOf(":"))>-1&&(t.protocol=e.substring(0,r)||null,t.protocol&&!t.protocol.match(i.protocol_expression)?t.protocol=void 0:"//"===e.substring(r+1,r+3)?(e=e.substring(r+3),e=i.parseAuthority(e,t)):(e=e.substring(r+1),t.urn=!0)),t.path=e,t},i.parseHost=function(e,t){e||(e="");var r,n,o=(e=e.replace(/\\/g,"/")).indexOf("/");if(-1===o&&(o=e.length),"["===e.charAt(0))r=e.indexOf("]"),t.hostname=e.substring(1,r)||null,t.port=e.substring(r+2,o)||null,"/"===t.port&&(t.port=null);else{var a=e.indexOf(":"),s=e.indexOf("/"),u=e.indexOf(":",a+1);-1!==u&&(-1===s||u-1?n:e.length-1);return o>-1&&(-1===n||o-1?d.slice(0,g)+d.slice(g).replace(a,""):d.replace(a,"")).length<=c[0].length||r.ignore&&r.ignore.test(d))){var v=t(d,h,p=h+d.length,e);void 0!==v?(v=String(v),e=e.slice(0,h)+v+e.slice(p),n.lastIndex=h+v.length):n.lastIndex=p}}return n.lastIndex=0,e},i.ensureValidHostname=function(t,r){var n=!!t,o=!1;if(!!r&&(o=p(i.hostProtocols,r)),o&&!n)throw new TypeError("Hostname cannot be empty, if protocol is "+r);if(t&&t.match(i.invalid_hostname_characters)){if(!e)throw new TypeError('Hostname "'+t+'" contains characters other than [A-Z0-9.-:_] and Punycode.js is not available');if(e.toASCII(t).match(i.invalid_hostname_characters))throw new TypeError('Hostname "'+t+'" contains characters other than [A-Z0-9.-:_]')}},i.ensureValidPort=function(e){if(e){var t=Number(e);if(!(function(e){return/^[0-9]+$/.test(e)}(t)&&t>0&&t<65536))throw new TypeError('Port "'+e+'" is not a valid port')}},i.noConflict=function(e){if(e){var t={URI:this.noConflict()};return n.URITemplate&&"function"==typeof n.URITemplate.noConflict&&(t.URITemplate=n.URITemplate.noConflict()),n.IPv6&&"function"==typeof n.IPv6.noConflict&&(t.IPv6=n.IPv6.noConflict()),n.SecondLevelDomains&&"function"==typeof n.SecondLevelDomains.noConflict&&(t.SecondLevelDomains=n.SecondLevelDomains.noConflict()),t}return n.URI===this&&(n.URI=o),this},a.build=function(e){return!0===e?this._deferred_build=!0:(void 0===e||this._deferred_build)&&(this._string=i.build(this._parts),this._deferred_build=!1),this},a.clone=function(){return new i(this)},a.valueOf=a.toString=function(){return this.build(!1)._string},a.protocol=w("protocol"),a.username=w("username"),a.password=w("password"),a.hostname=w("hostname"),a.port=w("port"),a.query=k("query","?"),a.fragment=k("fragment","#"),a.search=function(e,t){var r=this.query(e,t);return"string"==typeof r&&r.length?"?"+r:r},a.hash=function(e,t){var r=this.fragment(e,t);return"string"==typeof r&&r.length?"#"+r:r},a.pathname=function(e,t){if(void 0===e||!0===e){var r=this._parts.path||(this._parts.hostname?"/":"");return e?(this._parts.urn?i.decodeUrnPath:i.decodePath)(r):r}return this._parts.urn?this._parts.path=e?i.recodeUrnPath(e):"":this._parts.path=e?i.recodePath(e):"/",this.build(!t),this},a.path=a.pathname,a.href=function(e,t){var r;if(void 0===e)return this.toString();this._string="",this._parts=i._parts();var n=e instanceof i,o="object"==typeof e&&(e.hostname||e.path||e.pathname);e.nodeName&&(e=e[i.getDomAttribute(e)]||"",o=!1);if(!n&&o&&void 0!==e.pathname&&(e=e.toString()),"string"==typeof e||e instanceof String)this._parts=i.parse(String(e),this._parts);else{if(!n&&!o)throw new TypeError("invalid input");var a=n?e._parts:e;for(r in a)"query"!==r&&s.call(this._parts,r)&&(this._parts[r]=a[r]);a.query&&this.query(a.query,!1)}return this.build(!t),this},a.is=function(e){var t=!1,n=!1,o=!1,a=!1,s=!1,u=!1,c=!1,h=!this._parts.urn;switch(this._parts.hostname&&(h=!1,n=i.ip4_expression.test(this._parts.hostname),o=i.ip6_expression.test(this._parts.hostname),s=(a=!(t=n||o))&&r&&r.has(this._parts.hostname),u=a&&i.idn_expression.test(this._parts.hostname),c=a&&i.punycode_expression.test(this._parts.hostname)),e.toLowerCase()){case"relative":return h;case"absolute":return!h;case"domain":case"name":return a;case"sld":return s;case"ip":return t;case"ip4":case"ipv4":case"inet4":return n;case"ip6":case"ipv6":case"inet6":return o;case"idn":return u;case"url":return!this._parts.urn;case"urn":return!!this._parts.urn;case"punycode":return c}return null};var x=a.protocol,z=a.port,P=a.hostname;a.protocol=function(e,t){if(e&&!(e=e.replace(/:(\/\/)?$/,"")).match(i.protocol_expression))throw new TypeError('Protocol "'+e+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return x.call(this,e,t)},a.scheme=a.protocol,a.port=function(e,t){return this._parts.urn?void 0===e?"":this:(void 0!==e&&(0===e&&(e=null),e&&(":"===(e+="").charAt(0)&&(e=e.substring(1)),i.ensureValidPort(e))),z.call(this,e,t))},a.hostname=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0!==e){var r={preventInvalidHostname:this._parts.preventInvalidHostname};if("/"!==i.parseHost(e,r))throw new TypeError('Hostname "'+e+'" contains characters other than [A-Z0-9.-]');e=r.hostname,this._parts.preventInvalidHostname&&i.ensureValidHostname(e,this._parts.protocol)}return P.call(this,e,t)},a.origin=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e){var r=this.protocol();return this.authority()?(r?r+"://":"")+this.authority():""}var n=i(e);return this.protocol(n.protocol()).authority(n.authority()).build(!t),this},a.host=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e)return this._parts.hostname?i.buildHost(this._parts):"";if("/"!==i.parseHost(e,this._parts))throw new TypeError('Hostname "'+e+'" contains characters other than [A-Z0-9.-]');return this.build(!t),this},a.authority=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e)return this._parts.hostname?i.buildAuthority(this._parts):"";if("/"!==i.parseAuthority(e,this._parts))throw new TypeError('Hostname "'+e+'" contains characters other than [A-Z0-9.-]');return this.build(!t),this},a.userinfo=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e){var r=i.buildUserinfo(this._parts);return r?r.substring(0,r.length-1):r}return"@"!==e[e.length-1]&&(e+="@"),i.parseUserinfo(e,this._parts),this.build(!t),this},a.resource=function(e,t){var r;return void 0===e?this.path()+this.search()+this.hash():(r=i.parse(e),this._parts.path=r.path,this._parts.query=r.query,this._parts.fragment=r.fragment,this.build(!t),this)},a.subdomain=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,r)||""}var n=this._parts.hostname.length-this.domain().length,o=this._parts.hostname.substring(0,n),a=new RegExp("^"+u(o));if(e&&"."!==e.charAt(e.length-1)&&(e+="."),-1!==e.indexOf(":"))throw new TypeError("Domains cannot contain colons");return e&&i.ensureValidHostname(e,this._parts.protocol),this._parts.hostname=this._parts.hostname.replace(a,e),this.build(!t),this},a.domain=function(e,t){if(this._parts.urn)return void 0===e?"":this;if("boolean"==typeof e&&(t=e,e=void 0),void 0===e){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.match(/\./g);if(r&&r.length<2)return this._parts.hostname;var n=this._parts.hostname.length-this.tld(t).length-1;return n=this._parts.hostname.lastIndexOf(".",n-1)+1,this._parts.hostname.substring(n)||""}if(!e)throw new TypeError("cannot set domain empty");if(-1!==e.indexOf(":"))throw new TypeError("Domains cannot contain colons");if(i.ensureValidHostname(e,this._parts.protocol),!this._parts.hostname||this.is("IP"))this._parts.hostname=e;else{var o=new RegExp(u(this.domain())+"$");this._parts.hostname=this._parts.hostname.replace(o,e)}return this.build(!t),this},a.tld=function(e,t){if(this._parts.urn)return void 0===e?"":this;if("boolean"==typeof e&&(t=e,e=void 0),void 0===e){if(!this._parts.hostname||this.is("IP"))return"";var n=this._parts.hostname.lastIndexOf("."),o=this._parts.hostname.substring(n+1);return!0!==t&&r&&r.list[o.toLowerCase()]&&r.get(this._parts.hostname)||o}var i;if(!e)throw new TypeError("cannot set TLD empty");if(e.match(/[^a-zA-Z0-9-]/)){if(!r||!r.is(e))throw new TypeError('TLD "'+e+'" contains characters other than [A-Z0-9]');i=new RegExp(u(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(i,e)}else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");i=new RegExp(u(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(i,e)}return this.build(!t),this},a.directory=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e||!0===e){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var r=this._parts.path.length-this.filename().length-1,n=this._parts.path.substring(0,r)||(this._parts.hostname?"/":"");return e?i.decodePath(n):n}var o=this._parts.path.length-this.filename().length,a=this._parts.path.substring(0,o),s=new RegExp("^"+u(a));return this.is("relative")||(e||(e="/"),"/"!==e.charAt(0)&&(e="/"+e)),e&&"/"!==e.charAt(e.length-1)&&(e+="/"),e=i.recodePath(e),this._parts.path=this._parts.path.replace(s,e),this.build(!t),this},a.filename=function(e,t){if(this._parts.urn)return void 0===e?"":this;if("string"!=typeof e){if(!this._parts.path||"/"===this._parts.path)return"";var r=this._parts.path.lastIndexOf("/"),n=this._parts.path.substring(r+1);return e?i.decodePathSegment(n):n}var o=!1;"/"===e.charAt(0)&&(e=e.substring(1)),e.match(/\.?\//)&&(o=!0);var a=new RegExp(u(this.filename())+"$");return e=i.recodePath(e),this._parts.path=this._parts.path.replace(a,e),o?this.normalizePath(t):this.build(!t),this},a.suffix=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e||!0===e){if(!this._parts.path||"/"===this._parts.path)return"";var r,n,o=this.filename(),a=o.lastIndexOf(".");return-1===a?"":(r=o.substring(a+1),n=/^[a-z0-9%]+$/i.test(r)?r:"",e?i.decodePathSegment(n):n)}"."===e.charAt(0)&&(e=e.substring(1));var s,c=this.suffix();if(c)s=e?new RegExp(u(c)+"$"):new RegExp(u("."+c)+"$");else{if(!e)return this;this._parts.path+="."+i.recodePath(e)}return s&&(e=i.recodePath(e),this._parts.path=this._parts.path.replace(s,e)),this.build(!t),this},a.segment=function(e,t,r){var n=this._parts.urn?":":"/",o=this.path(),i="/"===o.substring(0,1),a=o.split(n);if(void 0!==e&&"number"!=typeof e&&(r=t,t=e,e=void 0),void 0!==e&&"number"!=typeof e)throw new Error('Bad segment "'+e+'", must be 0-based integer');if(i&&a.shift(),e<0&&(e=Math.max(a.length+e,0)),void 0===t)return void 0===e?a:a[e];if(null===e||void 0===a[e])if(h(t)){a=[];for(var s=0,u=t.length;s0&&t._getRegisteredUser().then(function(o){var a,i=[];n.forEach(function(n){console.log("[SimpleChat.resumeReporter]: ",n),a=r[n].sync().then(function(){console.log("[SimpleChat.resumeReporter] updated Chat ",r[n]);var a=t._factory.createChat(t._syncher,t._domain,o,t._manager);a.dataObjectReporter=r[n],e._manager._reportersControllers[n]=a,t._resumeInterworking(a.dataObjectReporter)}),i.push(a)}),Promise.all(i).then(function(){t._onResumeReporter&&t._onResumeReporter(e._manager._reportersControllers)})})}).catch(function(e){console.info("[SimpleChat.resumeReporters] :",e)})}},{key:"_resumeObservers",value:function(){var e=this,t=this;t._syncher.resumeObservers({store:!0}).then(function(r){console.log("[SimpleChat] resuming observers : ",r,t,t._onResume);var n=Object.keys(r);n.length>0&&t._getRegisteredUser().then(function(o){var a,i=[];n.forEach(function(n){console.log("[SimpleChat].syncher.resumeObserver: ",n),a=r[n].sync().then(function(){var a=r[n],i=t._factory.createChat(t._syncher,t._domain,o,t._manager);i.dataObjectObserver=a,e._manager._observersControllers[n]=i}),i.push(a)}),Promise.all(i).then(function(){t._onResumeObserver&&t._onResumeObserver(e._manager._observersControllers)})})}).catch(function(e){console.info("[SimpleChat] Resume Observer | ",e)})}},{key:"_resumeInterworking",value:function(e){var t=this;if(e.data.participants){var r=e.data.participants,n=e.url,o=e.schema;console.log("[SimpleChat._resumeInterworking for] ",r),Object.keys(r).forEach(function(a){var i=r[a].identity.userProfile.userURL.split("://");if("user"!==i[0]){console.log("[SimpleChat._resumeInterworking for] ",a),i=i[0]+"://"+i[1].split("/")[1];var s={type:"create",from:t._myUrl,to:i,body:{resource:n,schema:o,value:e.metadata}};t._bus.postMessage(s,function(){})}})}}},{key:"create",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{mutual:!1,domain_registration:!1,reuseURL:!0};return this._manager.create(e,t,r)}},{key:"onInvitation",value:function(e){return this._manager.onInvitation(e)}},{key:"onResumeReporter",value:function(e){this._onResumeReporter=e}},{key:"onResumeObserver",value:function(e){this._onResumeObserver=e}},{key:"join",value:function(e){return this._manager.join(e,!1)}},{key:"myIdentity",value:function(e){return console.log("[SimpleChat.myIdentity] ",e),this._manager.myIdentity(e)}},{key:"processNotification",value:function(e){return this._manager.processNotification(e)}},{key:"onInvitation",value:function(e){return this._manager.onInvitation(e)}},{key:"name",get:function(){return n.a.name}},{key:"descriptor",get:function(){return n.a}},{key:"runtimeHypertyURL",get:function(){return this._myUrl}}]),e}();t.default=a},function(e,t,r){"use strict";r.d(t,"a",function(){return n});var n={name:"SimpleChat",language:"javascript",signature:"",configuration:{backup:!0,heartBeat:60,offline:"hyperty://sharing-cities-dsm/offline-sub-mgr"},hypertyType:["chat"],constraints:{browser:!0},dataObjects:["https://catalogue.%domain%/.well-known/dataschema/Communication"]}}]).default}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("activate",[],t):"object"==typeof exports?exports.activate=t():e.activate=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(1);function o(e,t){for(var r=0;r0&&t._getRegisteredUser().then(function(o){var a,i=[];n.forEach(function(n){console.log("[SimpleChat.resumeReporter]: ",n),a=r[n].sync().then(function(){console.log("[SimpleChat.resumeReporter] updated Chat ",r[n]);var a=t._factory.createChat(t._syncher,t._domain,o,t._manager);a.dataObjectReporter=r[n],e._manager._reportersControllers[n]=a,t._resumeInterworking(a.dataObjectReporter)}),i.push(a)}),Promise.all(i).then(function(){t._onResumeReporter&&t._onResumeReporter(e._manager._reportersControllers)})})}).catch(function(e){console.info("[SimpleChat.resumeReporters] :",e)})}},{key:"_resumeObservers",value:function(){var e=this,t=this;t._syncher.resumeObservers({store:!0}).then(function(r){console.log("[SimpleChat] resuming observers : ",r,t,t._onResume);var n=Object.keys(r);n.length>0&&t._getRegisteredUser().then(function(o){var a,i=[];n.forEach(function(n){console.log("[SimpleChat].syncher.resumeObserver: ",n),a=r[n].sync().then(function(){var a=r[n],i=t._factory.createChat(t._syncher,t._domain,o,t._manager);i.dataObjectObserver=a,e._manager._observersControllers[n]=i}),i.push(a)}),Promise.all(i).then(function(){t._onResumeObserver&&t._onResumeObserver(e._manager._observersControllers)})})}).catch(function(e){console.info("[SimpleChat] Resume Observer | ",e)})}},{key:"_resumeInterworking",value:function(e){var t=this;if(e.data.participants){var r=e.data.participants,n=e.url,o=e.schema;console.log("[SimpleChat._resumeInterworking for] ",r),Object.keys(r).forEach(function(a){var i=r[a].identity.userProfile.userURL.split("://");if("user"!==i[0]){console.log("[SimpleChat._resumeInterworking for] ",a),i=i[0]+"://"+i[1].split("/")[1];var s={type:"create",from:t._myUrl,to:i,body:{resource:n,schema:o,value:e.metadata}};t._bus.postMessage(s,function(){})}})}}},{key:"create",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{mutual:!1,domain_registration:!1,reuseURL:!0};return this._manager.create(e,t,r)}},{key:"onInvitation",value:function(e){return this._manager.onInvitation(e)}},{key:"onResumeReporter",value:function(e){this._onResumeReporter=e}},{key:"onResumeObserver",value:function(e){this._onResumeObserver=e}},{key:"join",value:function(e){return this._manager.join(e,!1)}},{key:"myIdentity",value:function(e){return console.log("[SimpleChat.myIdentity] ",e),this._manager.myIdentity(e)}},{key:"processNotification",value:function(e){return this._manager.processNotification(e)}},{key:"onInvitation",value:function(e){return this._manager.onInvitation(e)}},{key:"name",get:function(){return n.a.name}},{key:"descriptor",get:function(){return n.a}},{key:"runtimeHypertyURL",get:function(){return this._myUrl}}]),e}();t.default=a},function(e,t,r){"use strict";r.d(t,"a",function(){return n});var n={name:"SimpleChat",language:"javascript",signature:"",configuration:{domain_registration:!1,backup:!0,heartBeat:60,offline:"hyperty://sharing-cities-dsm/offline-sub-mgr"},hypertyType:["chat"],constraints:{browser:!0},dataObjects:["https://catalogue.%domain%/.well-known/dataschema/Communication"]}}]).default}); \ No newline at end of file diff --git a/dist/UserKwhObserver.hy.js b/dist/UserKwhObserver.hy.js index c4ff9e2..3940927 100644 --- a/dist/UserKwhObserver.hy.js +++ b/dist/UserKwhObserver.hy.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("activate",[],t):"object"==typeof exports?exports.activate=t():e.activate=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1);function o(e,t){for(var n=0;n Date: Thu, 16 May 2019 15:18:40 +0100 Subject: [PATCH 2/3] SimpleChatDemo: added typing events --- examples/simple-chat/demo.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/simple-chat/demo.js b/examples/simple-chat/demo.js index f647fad..67fa0a3 100644 --- a/examples/simple-chat/demo.js +++ b/examples/simple-chat/demo.js @@ -374,6 +374,11 @@ function prepareChat(chatController, isOwner, toReload = null) { console.log('[SimpleChatDemo ] OnChange Event:', event); }); + chatController.onTyping(function (event) { + console.log('[SimpleChatDemo ] onTyping Event:', event); + }); + + chatController.onUserAdded(function (event) { console.log('[SimpleChatDemo ] onUserAdded Event:', event); const participantHypertyURL = event.hypertyURL; @@ -411,6 +416,8 @@ function prepareChat(chatController, isOwner, toReload = null) { inviteParticipants(chatController, isOwner); }); + document.addEventListener('keydown', event => { chatController.typing() } ) + } function inviteParticipants(chatController, isOwner) { From 12541f8cf11ca642305e327535d177878ea020f7 Mon Sep 17 00:00:00 2001 From: suil Date: Thu, 23 May 2019 11:15:54 +0100 Subject: [PATCH 3/3] new version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 05652a4..aadd803 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hyperties", - "version": "0.8.0", + "version": "0.9.0", "files": [ "dist" ],