From a561c20050d6733bad42712bb422f1b47d41e79b Mon Sep 17 00:00:00 2001 From: Ryan Lester Date: Sun, 29 May 2016 18:39:13 -0400 Subject: [PATCH] s/getSessionid/getSessionId/g for consistency with documentation --- latest-v2.js | 2 +- simplewebrtc.bundle.js | 14 +++++++------- simplewebrtc.js | 12 ++++++------ socketioconnection.js | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/latest-v2.js b/latest-v2.js index ff3d5c4e..48d21ddf 100644 --- a/latest-v2.js +++ b/latest-v2.js @@ -3,4 +3,4 @@ return-1!=n&&-1!=o&&(s.source=t,s.host=s.host.substring(1,s.host.length-1).repla e.andyetBatchIce&&(r.batchIceCandidates=e.andyetBatchIce)}),this.batchedIceCandidates=[],t&&t.optional&&"chrome"===i&&t.optional.forEach(function(e){e.andyetFasterICE&&(r.eliminateDuplicateCandidates=e.andyetFasterICE)}),t&&t.optional&&t.optional.forEach(function(e){e.andyetDontSignalCandidates&&(r.dontSignalCandidates=e.andyetDontSignalCandidates)}),this.assumeSetLocalSuccess=!1,t&&t.optional&&t.optional.forEach(function(e){e.andyetAssumeSetLocalSuccess&&(r.assumeSetLocalSuccess=e.andyetAssumeSetLocalSuccess)}),"firefox"===i&&t&&t.optional&&(this.wtFirefox=0,t.optional.forEach(function(e){e.andyetFirefoxMakesMeSad&&(r.wtFirefox=e.andyetFirefoxMakesMeSad,r.wtFirefox>0&&(r.firefoxcandidatebuffer=[]))})),this.pc=new s(e,t),this.getLocalStreams=this.pc.getLocalStreams.bind(this.pc),this.getRemoteStreams=this.pc.getRemoteStreams.bind(this.pc),this.addStream=this.pc.addStream.bind(this.pc),this.removeStream=this.pc.removeStream.bind(this.pc),this.pc.on("*",function(){r.emit.apply(r,arguments)}),this.pc.onremovestream=this.emit.bind(this,"removeStream"),this.pc.onaddstream=this.emit.bind(this,"addStream"),this.pc.onnegotiationneeded=this.emit.bind(this,"negotiationNeeded"),this.pc.oniceconnectionstatechange=this.emit.bind(this,"iceConnectionStateChange"),this.pc.onsignalingstatechange=this.emit.bind(this,"signalingStateChange"),this.pc.onicecandidate=this._onIce.bind(this),this.pc.ondatachannel=this._onDataChannel.bind(this),this.localDescription={contents:[]},this.remoteDescription={contents:[]},this.config={debug:!1,sid:"",isInitiator:!0,sdpSessionID:Date.now(),useJingle:!1},this.iceCredentials={local:{},remote:{}};for(n in e)this.config[n]=e[n];this.config.debug&&this.on("*",function(){var t=e.logger||console;t.log("PeerConnection event:",arguments)}),this.hadLocalStunCandidate=!1,this.hadRemoteStunCandidate=!1,this.hadLocalRelayCandidate=!1,this.hadRemoteRelayCandidate=!1,this.hadLocalIPv6Candidate=!1,this.hadRemoteIPv6Candidate=!1,this._remoteDataChannels=[],this._localDataChannels=[],this._candidateBuffer=[]}var i=e("util"),o=e("sdp-jingle-json"),a=e("wildemitter"),s=e("traceablepeerconnection"),c=e("webrtc-adapter");i.inherits(r,a),Object.defineProperty(r.prototype,"signalingState",{get:function(){return this.pc.signalingState}}),Object.defineProperty(r.prototype,"iceConnectionState",{get:function(){return this.pc.iceConnectionState}}),r.prototype._role=function(){return this.isInitiator?"initiator":"responder"},r.prototype.addStream=function(e){this.localStream=e,this.pc.addStream(e)},r.prototype._checkLocalCandidate=function(e){var t=o.toCandidateJSON(e);"srflx"==t.type?this.hadLocalStunCandidate=!0:"relay"==t.type&&(this.hadLocalRelayCandidate=!0),-1!=t.ip.indexOf(":")&&(this.hadLocalIPv6Candidate=!0)},r.prototype._checkRemoteCandidate=function(e){var t=o.toCandidateJSON(e);"srflx"==t.type?this.hadRemoteStunCandidate=!0:"relay"==t.type&&(this.hadRemoteRelayCandidate=!0),-1!=t.ip.indexOf(":")&&(this.hadRemoteIPv6Candidate=!0)},r.prototype.processIce=function(e,t){t=t||function(){};var n=this;if("closed"===this.pc.signalingState)return t();if(e.contents||e.jingle&&e.jingle.contents){var r=this.remoteDescription.contents.map(function(e){return e.name}),i=e.contents||e.jingle.contents;i.forEach(function(e){var i=e.transport||{},a=i.candidates||[],s=r.indexOf(e.name),c=e.name,p=n.remoteDescription.contents.find(function(t){return t.name===e.name}),d=function(){a.forEach(function(e){var t=o.toCandidateSDP(e)+"\r\n";n.pc.addIceCandidate(new RTCIceCandidate({candidate:t,sdpMLineIndex:s,sdpMid:c}),function(){},function(e){n.emit("error",e)}),n._checkRemoteCandidate(t)}),t()};if(n.iceCredentials.remote[e.name]&&i.ufrag&&n.iceCredentials.remote[e.name].ufrag!==i.ufrag)if(p){p.transport.ufrag=i.ufrag,p.transport.pwd=i.pwd;var u={type:"offer",jingle:n.remoteDescription};u.sdp=o.toSessionSDP(u.jingle,{sid:n.config.sdpSessionID,role:n._role(),direction:"incoming"}),n.pc.setRemoteDescription(new RTCSessionDescription(u),function(){d()},function(e){n.emit("error",e)})}else n.emit("error","ice restart failed to find matching content");else d()})}else{if(e.candidate&&0!==e.candidate.candidate.indexOf("a=")&&(e.candidate.candidate="a="+e.candidate.candidate),this.wtFirefox&&null!==this.firefoxcandidatebuffer&&this.pc.localDescription&&"offer"===this.pc.localDescription.type)return this.firefoxcandidatebuffer.push(e.candidate),t();n.pc.addIceCandidate(new RTCIceCandidate(e.candidate),function(){},function(e){n.emit("error",e)}),n._checkRemoteCandidate(e.candidate.candidate),t()}},r.prototype.offer=function(e,t){var n=this,r=2===arguments.length,i=r&&e?e:{offerToReceiveAudio:1,offerToReceiveVideo:1};return t=r?t:e,t=t||function(){},"closed"===this.pc.signalingState?t("Already closed"):void this.pc.createOffer(function(e){var r={type:"offer",sdp:e.sdp};n.assumeSetLocalSuccess&&(n.emit("offer",r),t(null,r)),n._candidateBuffer=[],n.pc.setLocalDescription(e,function(){var i;n.config.useJingle&&(i=o.toSessionJSON(e.sdp,{role:n._role(),direction:"outgoing"}),i.sid=n.config.sid,n.localDescription=i,i.contents.forEach(function(e){var t=e.transport||{};t.ufrag&&(n.iceCredentials.local[e.name]={ufrag:t.ufrag,pwd:t.pwd})}),r.jingle=i),r.sdp.split("\r\n").forEach(function(e){0===e.indexOf("a=candidate:")&&n._checkLocalCandidate(e)}),n.assumeSetLocalSuccess||(n.emit("offer",r),t(null,r))},function(e){n.emit("error",e),t(e)})},function(e){n.emit("error",e),t(e)},i)},r.prototype.handleOffer=function(e,t){t=t||function(){};var n=this;if(e.type="offer",e.jingle){if(this.enableChromeNativeSimulcast&&e.jingle.contents.forEach(function(e){"video"===e.name&&(e.application.googConferenceFlag=!0)}),this.enableMultiStreamHacks&&e.jingle.contents.forEach(function(e){if("video"===e.name){var t=e.application.sources||[];0!==t.length&&"3735928559"===t[0].ssrc||(t.unshift({ssrc:"3735928559",parameters:[{key:"cname",value:"deadbeef"},{key:"msid",value:"mixyourfecintothis please"}]}),e.application.sources=t)}}),n.restrictBandwidth>0&&e.jingle.contents.length>=2&&"video"===e.jingle.contents[1].name){var r=e.jingle.contents[1],i=r.application&&r.application.bandwidth&&r.application.bandwidth.bandwidth;i||(e.jingle.contents[1].application.bandwidth={type:"AS",bandwidth:n.restrictBandwidth.toString()},e.sdp=o.toSessionSDP(e.jingle,{sid:n.config.sdpSessionID,role:n._role(),direction:"outgoing"}))}e.jingle.contents.forEach(function(e){var t=e.transport||{};t.ufrag&&(n.iceCredentials.remote[e.name]={ufrag:t.ufrag,pwd:t.pwd})}),e.sdp=o.toSessionSDP(e.jingle,{sid:n.config.sdpSessionID,role:n._role(),direction:"incoming"}),n.remoteDescription=e.jingle}e.sdp.split("\r\n").forEach(function(e){0===e.indexOf("a=candidate:")&&n._checkRemoteCandidate(e)}),n.pc.setRemoteDescription(new RTCSessionDescription(e),function(){t()},t)},r.prototype.answerAudioOnly=function(e){var t={mandatory:{OfferToReceiveAudio:!0,OfferToReceiveVideo:!1}};this._answer(t,e)},r.prototype.answerBroadcastOnly=function(e){var t={mandatory:{OfferToReceiveAudio:!1,OfferToReceiveVideo:!1}};this._answer(t,e)},r.prototype.answer=function(e,t){var n=2===arguments.length,r=n?t:e,i=n&&e?e:{mandatory:{OfferToReceiveAudio:!0,OfferToReceiveVideo:!0}};this._answer(i,r)},r.prototype.handleAnswer=function(e,t){t=t||function(){};var n=this;e.jingle&&(e.sdp=o.toSessionSDP(e.jingle,{sid:n.config.sdpSessionID,role:n._role(),direction:"incoming"}),n.remoteDescription=e.jingle,e.jingle.contents.forEach(function(e){var t=e.transport||{};t.ufrag&&(n.iceCredentials.remote[e.name]={ufrag:t.ufrag,pwd:t.pwd})})),e.sdp.split("\r\n").forEach(function(e){0===e.indexOf("a=candidate:")&&n._checkRemoteCandidate(e)}),n.pc.setRemoteDescription(new RTCSessionDescription(e),function(){n.wtFirefox&&window.setTimeout(function(){n.firefoxcandidatebuffer.forEach(function(e){n.pc.addIceCandidate(new RTCIceCandidate(e),function(){},function(e){n.emit("error",e)}),n._checkRemoteCandidate(e.candidate)}),n.firefoxcandidatebuffer=null},n.wtFirefox),t(null)},t)},r.prototype.close=function(){this.pc.close(),this._localDataChannels=[],this._remoteDataChannels=[],this.emit("close")},r.prototype._answer=function(e,t){t=t||function(){};var n=this;if(!this.pc.remoteDescription)throw new Error("remoteDescription not set");return"closed"===this.pc.signalingState?t("Already closed"):void n.pc.createAnswer(function(e){var r=[];if(n.enableChromeNativeSimulcast&&(e.jingle=o.toSessionJSON(e.sdp,{role:n._role(),direction:"outgoing"}),e.jingle.contents.length>=2&&"video"===e.jingle.contents[1].name)){var i=e.jingle.contents[1].application.sourceGroups||[],a=!1;if(i.forEach(function(e){"SIM"==e.semantics&&(a=!0)}),!a&&e.jingle.contents[1].application.sources.length){var s=JSON.parse(JSON.stringify(e.jingle.contents[1].application.sources[0]));s.ssrc=""+Math.floor(4294967295*Math.random()),e.jingle.contents[1].application.sources.push(s),r.push(e.jingle.contents[1].application.sources[0].ssrc),r.push(s.ssrc),i.push({semantics:"SIM",sources:r});var c=JSON.parse(JSON.stringify(s));c.ssrc=""+Math.floor(4294967295*Math.random()),e.jingle.contents[1].application.sources.push(c),i.push({semantics:"FID",sources:[s.ssrc,c.ssrc]}),e.jingle.contents[1].application.sourceGroups=i,e.sdp=o.toSessionSDP(e.jingle,{sid:n.config.sdpSessionID,role:n._role(),direction:"outgoing"})}}var p={type:"answer",sdp:e.sdp};n.assumeSetLocalSuccess&&(n.emit("answer",p),t(null,p)),n._candidateBuffer=[],n.pc.setLocalDescription(e,function(){if(n.config.useJingle){var r=o.toSessionJSON(e.sdp,{role:n._role(),direction:"outgoing"});r.sid=n.config.sid,n.localDescription=r,p.jingle=r}n.enableChromeNativeSimulcast&&(p.jingle||(p.jingle=o.toSessionJSON(e.sdp,{role:n._role(),direction:"outgoing"})),p.jingle.contents[1].application.sources.forEach(function(e,t){e.parameters=e.parameters.map(function(e){return"msid"===e.key&&(e.value+="-"+Math.floor(t/2)),e})}),p.sdp=o.toSessionSDP(p.jingle,{sid:n.sdpSessionID,role:n._role(),direction:"outgoing"})),p.sdp.split("\r\n").forEach(function(e){0===e.indexOf("a=candidate:")&&n._checkLocalCandidate(e)}),n.assumeSetLocalSuccess||(n.emit("answer",p),t(null,p))},function(e){n.emit("error",e),t(e)})},function(e){n.emit("error",e),t(e)},e)},r.prototype._onIce=function(e){var t=this;if(e.candidate){if(this.dontSignalCandidates)return;var n=e.candidate,r={candidate:{candidate:n.candidate,sdpMid:n.sdpMid,sdpMLineIndex:n.sdpMLineIndex}};this._checkLocalCandidate(n.candidate);var i,a,s=o.toCandidateJSON(n.candidate);if(this.eliminateDuplicateCandidates&&"relay"===s.type&&(i=this._candidateBuffer.filter(function(e){return"relay"===e.type}).map(function(e){return e.foundation+":"+e.component}),a=i.indexOf(s.foundation+":"+s.component),a>-1&&s.priority>>24>=i[a].priority>>24))return;if("max-bundle"===this.config.bundlePolicy&&(i=this._candidateBuffer.filter(function(e){return s.type===e.type}).map(function(e){return e.address+":"+e.port}),a=i.indexOf(s.address+":"+s.port),a>-1))return;if("require"===this.config.rtcpMuxPolicy&&"2"===s.component)return;if(this._candidateBuffer.push(s),t.config.useJingle){if(n.sdpMid||(t.pc.remoteDescription&&"offer"===t.pc.remoteDescription.type?n.sdpMid=t.remoteDescription.contents[n.sdpMLineIndex].name:n.sdpMid=t.localDescription.contents[n.sdpMLineIndex].name),!t.iceCredentials.local[n.sdpMid]){var c=o.toSessionJSON(t.pc.localDescription.sdp,{role:t._role(),direction:"outgoing"});c.contents.forEach(function(e){var n=e.transport||{};n.ufrag&&(t.iceCredentials.local[e.name]={ufrag:n.ufrag,pwd:n.pwd})})}if(r.jingle={contents:[{name:n.sdpMid,creator:t._role(),transport:{transportType:"iceUdp",ufrag:t.iceCredentials.local[n.sdpMid].ufrag,pwd:t.iceCredentials.local[n.sdpMid].pwd,candidates:[s]}}]},t.batchIceCandidates>0)return 0===t.batchedIceCandidates.length&&window.setTimeout(function(){var e={};t.batchedIceCandidates.forEach(function(t){t=t.contents[0],e[t.name]||(e[t.name]=t),e[t.name].transport.candidates.push(t.transport.candidates[0])});var n={jingle:{contents:[]}};Object.keys(e).forEach(function(t){n.jingle.contents.push(e[t])}),t.batchedIceCandidates=[],t.emit("ice",n)},t.batchIceCandidates),void t.batchedIceCandidates.push(r.jingle)}this.emit("ice",r)}else this.emit("endOfCandidates")},r.prototype._onDataChannel=function(e){var t=e.channel;this._remoteDataChannels.push(t),this.emit("addChannel",t)},r.prototype.createDataChannel=function(e,t){var n=this.pc.createDataChannel(e,t);return this._localDataChannels.push(n),n},r.prototype.getStats=function(e){this.pc.getStats(null,function(t){e(null,t)},function(t){e(t)})},t.exports=r},{"sdp-jingle-json":48,traceablepeerconnection:64,util:67,"webrtc-adapter":68,wildemitter:78}],48:[function(e,t,n){var r=e("./lib/tosdp"),i=e("./lib/tojson");n.toIncomingSDPOffer=function(e){return r.toSessionSDP(e,{role:"responder",direction:"incoming"})},n.toOutgoingSDPOffer=function(e){return r.toSessionSDP(e,{role:"initiator",direction:"outgoing"})},n.toIncomingSDPAnswer=function(e){return r.toSessionSDP(e,{role:"initiator",direction:"incoming"})},n.toOutgoingSDPAnswer=function(e){return r.toSessionSDP(e,{role:"responder",direction:"outgoing"})},n.toIncomingMediaSDPOffer=function(e){return r.toMediaSDP(e,{role:"responder",direction:"incoming"})},n.toOutgoingMediaSDPOffer=function(e){return r.toMediaSDP(e,{role:"initiator",direction:"outgoing"})},n.toIncomingMediaSDPAnswer=function(e){return r.toMediaSDP(e,{role:"initiator",direction:"incoming"})},n.toOutgoingMediaSDPAnswer=function(e){return r.toMediaSDP(e,{role:"responder",direction:"outgoing"})},n.toCandidateSDP=r.toCandidateSDP,n.toMediaSDP=r.toMediaSDP,n.toSessionSDP=r.toSessionSDP,n.toIncomingJSONOffer=function(e,t){return i.toSessionJSON(e,{role:"responder",direction:"incoming",creators:t})},n.toOutgoingJSONOffer=function(e,t){return i.toSessionJSON(e,{role:"initiator",direction:"outgoing",creators:t})},n.toIncomingJSONAnswer=function(e,t){return i.toSessionJSON(e,{role:"initiator",direction:"incoming",creators:t})},n.toOutgoingJSONAnswer=function(e,t){return i.toSessionJSON(e,{role:"responder",direction:"outgoing",creators:t})},n.toIncomingMediaJSONOffer=function(e,t){return i.toMediaJSON(e,{role:"responder",direction:"incoming",creator:t})},n.toOutgoingMediaJSONOffer=function(e,t){return i.toMediaJSON(e,{role:"initiator",direction:"outgoing",creator:t})},n.toIncomingMediaJSONAnswer=function(e,t){return i.toMediaJSON(e,{role:"initiator",direction:"incoming",creator:t})},n.toOutgoingMediaJSONAnswer=function(e,t){return i.toMediaJSON(e,{role:"responder",direction:"outgoing",creator:t})},n.toCandidateJSON=i.toCandidateJSON,n.toMediaJSON=i.toMediaJSON,n.toSessionJSON=i.toSessionJSON},{"./lib/tojson":51,"./lib/tosdp":52}],49:[function(e,t,n){n.lines=function(e){return e.split("\r\n").filter(function(e){return e.length>0})},n.findLine=function(e,t,n){for(var r=e.length,i=0;i=0?(n.id=r.substr(0,i),n.senders=r.substr(i+1)):(n.id=r,n.senders="sendrecv"),n.uri=t.shift()||"",n},n.rtcpfb=function(e){var t=e.substr(10).split(" "),n={};return n.id=t.shift(),n.type=t.shift(),"trr-int"===n.type?n.value=t.shift():n.subtype=t.shift()||"",n.parameters=t,n},n.candidate=function(e){var t;t=0===e.indexOf("a=candidate:")?e.substring(12).split(" "):e.substring(10).split(" ");for(var n={foundation:t[0],component:t[1],protocol:t[2].toLowerCase(),priority:t[3],ip:t[4],port:t[5],type:t[7],generation:"0"},r=8;r0?u.push("UDP/TLS/RTP/SAVPF"):s.encryption&&s.encryption.length>0?u.push("RTP/SAVPF"):u.push("RTP/AVPF"),p.forEach(function(e){u.push(e.id)})),i.push("m="+u.join(" ")),i.push("c=IN IP4 0.0.0.0"),s.bandwidth&&s.bandwidth.type&&s.bandwidth.bandwidth&&i.push("b="+s.bandwidth.type+":"+s.bandwidth.bandwidth),"rtp"==s.applicationType&&i.push("a=rtcp:1 IN IP4 0.0.0.0"),c){c.ufrag&&i.push("a=ice-ufrag:"+c.ufrag),c.pwd&&i.push("a=ice-pwd:"+c.pwd);var l=!1;d.forEach(function(e){i.push("a=fingerprint:"+e.hash+" "+e.value),e.setup&&!l&&i.push("a=setup:"+e.setup)}),c.sctp&&c.sctp.forEach(function(e){i.push("a=sctpmap:"+e.number+" "+e.protocol+" "+e.streams)})}"rtp"==s.applicationType&&i.push("a="+(r[o][a][e.senders]||"sendrecv")),i.push("a=mid:"+e.name),s.sources&&s.sources.length&&(s.sources[0].parameters||[]).forEach(function(e){"msid"===e.key&&i.push("a=msid:"+e.value)}),s.mux&&i.push("a=rtcp-mux");var f=s.encryption||[];f.forEach(function(e){i.push("a=crypto:"+e.tag+" "+e.cipherSuite+" "+e.keyParams+(e.sessionParams?" "+e.sessionParams:""))}),s.googConferenceFlag&&i.push("a=x-google-flag:conference"),p.forEach(function(e){var t="a=rtpmap:"+e.id+" "+e.name+"/"+e.clockrate;if(e.channels&&"1"!=e.channels&&(t+="/"+e.channels),i.push(t),e.parameters&&e.parameters.length){var n=["a=fmtp:"+e.id],r=[];e.parameters.forEach(function(e){r.push((e.key?e.key+"=":"")+e.value)}),n.push(r.join(";")),i.push(n.join(" "))}e.feedback&&e.feedback.forEach(function(t){"trr-int"===t.type?i.push("a=rtcp-fb:"+e.id+" trr-int "+(t.value?t.value:"0")):i.push("a=rtcp-fb:"+e.id+" "+t.type+(t.subtype?" "+t.subtype:""))})}),s.feedback&&s.feedback.forEach(function(e){"trr-int"===e.type?i.push("a=rtcp-fb:* trr-int "+(e.value?e.value:"0")):i.push("a=rtcp-fb:* "+e.type+(e.subtype?" "+e.subtype:""))});var h=s.headerExtensions||[];h.forEach(function(e){i.push("a=extmap:"+e.id+(e.senders?"/"+r[o][a][e.senders]:"")+" "+e.uri)});var m=s.sourceGroups||[];m.forEach(function(e){i.push("a=ssrc-group:"+e.semantics+" "+e.sources.join(" "))});var g=s.sources||[];g.forEach(function(e){for(var t=0;t0?"m="+e:e).trim()+"\r\n"})},r.matchPrefix=function(e,t){return r.splitLines(e).filter(function(e){return 0===e.indexOf(t)})},r.parseCandidate=function(e){var t;t=0===e.indexOf("a=candidate:")?e.substring(12).split(" "):e.substring(10).split(" ");for(var n={foundation:t[0],component:t[1],protocol:t[2].toLowerCase(),priority:parseInt(t[3],10),ip:t[4],port:parseInt(t[5],10),type:t[7]},r=8;r-1?(n.attribute=e.substr(t+1,r-t-1),n.value=e.substr(r+1)):n.attribute=e.substr(t+1),n},r.getDtlsParameters=function(e,t){var n=r.splitLines(e);n=n.concat(r.splitLines(t));var i=n.filter(function(e){return 0===e.indexOf("a=fingerprint:")})[0].substr(14),o={role:"auto",fingerprints:[{algorithm:i.split(" ")[0],value:i.split(" ")[1]}]};return o},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);n=n.concat(r.splitLines(t));var i={usernameFragment:n.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)};return i},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),i=n[0].split(" "),o=3;o0?"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)}),n+="a=rtcp-mux\r\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,p=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)})});p.length>0&&p[0].length>1&&p[0][0]===c&&(t=p[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:{payloadType:e.payloadType,ssrc:t}};n.push(r),o&&(r=JSON.parse(JSON.stringify(r)),r.fec={ssrc:t,mechanism:a?"red+ulpfec":"red"},n.push(r))}}),0===n.length&&c&&n.push({ssrc:c});var d=r.matchPrefix(e,"b=");return d.length&&(0===d[0].indexOf("b=TIAS:")?d=parseInt(d[0].substr(7),10):0===d[0].indexOf("b=AS:")&&(d=parseInt(d[0].substr(5),10)),n.forEach(function(e){e.maxBitrate=d})),n},r.writeSessionBoilerplate=function(){return"v=0\r\no=thisisadapterortc 8169639915646943137 2 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",o+=e.rtpSender&&e.rtpReceiver?"a=sendrecv\r\n":e.rtpSender?"a=sendonly\r\n":e.rtpReceiver?"a=recvonly\r\n":"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}return o+="a=ssrc:"+e.sendEncodingParameters[0].ssrc+" cname:"+r.localCName+"\r\n"},r.getDirection=function(e,t){for(var n=r.splitLines(e),i=0;i0&&!this.encoding){var e=this.packetBuffer.shift();this.packet(e)}},r.prototype.cleanup=function(){for(var e;e=this.subs.shift();)e.destroy();this.packetBuffer=[],this.encoding=!1,this.decoder.destroy()},r.prototype.close=r.prototype.disconnect=function(){this.skipReconnect=!0,this.backoff.reset(),this.readyState="closed",this.engine&&this.engine.close()},r.prototype.onclose=function(e){d("close"),this.cleanup(),this.backoff.reset(),this.readyState="closed",this.emit("close",e),this._reconnection&&!this.skipReconnect&&this.reconnect()},r.prototype.reconnect=function(){if(this.reconnecting||this.skipReconnect)return this;var e=this;if(this.backoff.attempts>=this._reconnectionAttempts)d("reconnect failed"),this.backoff.reset(),this.emitAll("reconnect_failed"),this.reconnecting=!1;else{var t=this.backoff.duration();d("will wait %dms before reconnect attempt",t),this.reconnecting=!0;var n=setTimeout(function(){e.skipReconnect||(d("attempting reconnect"),e.emitAll("reconnect_attempt",e.backoff.attempts),e.emitAll("reconnecting",e.backoff.attempts),e.skipReconnect||e.open(function(t){t?(d("reconnect attempt error"),e.reconnecting=!1,e.reconnect(),e.emitAll("reconnect_error",t.data)):(d("reconnect success"),e.onreconnect())}))},t);this.subs.push({destroy:function(){clearTimeout(n)}})}},r.prototype.onreconnect=function(){var e=this.backoff.attempts;this.reconnecting=!1,this.backoff.reset(),this.updateSocketIds(),this.emitAll("reconnect",e)}},{"./on":57,"./socket":58,"./url":59,backo2:4,"component-bind":7,"component-emitter":8,debug:10,"engine.io-client":11,indexof:33,"object-component":42,"socket.io-parser":61}],57:[function(e,t,n){function r(e,t,n){return e.on(t,n),{destroy:function(){e.removeListener(t,n)}}}t.exports=r},{}],58:[function(e,t,n){function r(e,t){this.io=e,this.nsp=t,this.json=this,this.ids=0,this.acks={},this.io.autoConnect&&this.open(),this.receiveBuffer=[],this.sendBuffer=[],this.connected=!1,this.disconnected=!0}var i=e("socket.io-parser"),o=e("component-emitter"),a=e("to-array"),s=e("./on"),c=e("component-bind"),p=e("debug")("socket.io-client:socket"),d=e("has-binary");t.exports=n=r;var u={connect:1,connect_error:1,connect_timeout:1,disconnect:1,error:1,reconnect:1,reconnect_attempt:1,reconnect_failed:1,reconnect_error:1,reconnecting:1},l=o.prototype.emit;o(r.prototype),r.prototype.subEvents=function(){if(!this.subs){var e=this.io;this.subs=[s(e,"open",c(this,"onopen")),s(e,"packet",c(this,"onpacket")),s(e,"close",c(this,"onclose"))]}},r.prototype.open=r.prototype.connect=function(){return this.connected?this:(this.subEvents(),this.io.open(),"open"==this.io.readyState&&this.onopen(),this)},r.prototype.send=function(){var e=a(arguments);return e.unshift("message"),this.emit.apply(this,e),this},r.prototype.emit=function(e){if(u.hasOwnProperty(e))return l.apply(this,arguments),this;var t=a(arguments),n=i.EVENT;d(t)&&(n=i.BINARY_EVENT);var r={type:n,data:t};return"function"==typeof t[t.length-1]&&(p("emitting packet with ack id %d",this.ids),this.acks[this.ids]=t.pop(),r.id=this.ids++),this.connected?this.packet(r):this.sendBuffer.push(r),this},r.prototype.packet=function(e){e.nsp=this.nsp,this.io.packet(e)},r.prototype.onopen=function(){p("transport is open - connecting"),"/"!=this.nsp&&this.packet({type:i.CONNECT})},r.prototype.onclose=function(e){p("close (%s)",e),this.connected=!1,this.disconnected=!0,delete this.id,this.emit("disconnect",e)},r.prototype.onpacket=function(e){if(e.nsp==this.nsp)switch(e.type){case i.CONNECT:this.onconnect();break;case i.EVENT:this.onevent(e);break;case i.BINARY_EVENT:this.onevent(e);break;case i.ACK:this.onack(e);break;case i.BINARY_ACK:this.onack(e);break;case i.DISCONNECT:this.ondisconnect();break;case i.ERROR:this.emit("error",e.data)}},r.prototype.onevent=function(e){var t=e.data||[];p("emitting event %j",t),null!=e.id&&(p("attaching ack callback to event"),t.push(this.ack(e.id))),this.connected?l.apply(this,t):this.receiveBuffer.push(t)},r.prototype.ack=function(e){var t=this,n=!1;return function(){if(!n){n=!0;var r=a(arguments);p("sending ack %j",r);var o=d(r)?i.BINARY_ACK:i.ACK;t.packet({type:o,id:e,data:r})}}},r.prototype.onack=function(e){p("calling ack %s with %j",e.id,e.data);var t=this.acks[e.id];t.apply(this,e.data),delete this.acks[e.id]},r.prototype.onconnect=function(){this.connected=!0,this.disconnected=!1,this.emit("connect"),this.emitBuffered()},r.prototype.emitBuffered=function(){var e;for(e=0;ei;)t=e.charCodeAt(i++),t>=55296&&56319>=t&&o>i?(n=e.charCodeAt(i++),56320==(64512&n)?r.push(((1023&t)<<10)+(1023&n)+65536):(r.push(t),i--)):r.push(t);return r}function a(e){for(var t,n=e.length,r=-1,i="";++r65535&&(t-=65536,i+=w(t>>>10&1023|55296),t=56320|1023&t),i+=w(t);return i}function s(e){if(e>=55296&&57343>=e)throw Error("Lone surrogate U+"+e.toString(16).toUpperCase()+" is not a scalar value")}function c(e,t){return w(e>>t&63|128)}function p(e){if(0==(4294967168&e))return w(e);var t="";return 0==(4294965248&e)?t=w(e>>6&31|192):0==(4294901760&e)?(s(e),t=w(e>>12&15|224),t+=c(e,6)):0==(4292870144&e)&&(t=w(e>>18&7|240),t+=c(e,12),t+=c(e,6)),t+=w(63&e|128)}function d(e){for(var t,n=o(e),r=n.length,i=-1,a="";++i=y)throw Error("Invalid byte index");var e=255&v[b];if(b++,128==(192&e))return 63&e;throw Error("Invalid continuation byte")}function l(){var e,t,n,r,i;if(b>y)throw Error("Invalid byte index");if(b==y)return!1;if(e=255&v[b],b++,0==(128&e))return e;if(192==(224&e)){var t=u();if(i=(31&e)<<6|t,i>=128)return i;throw Error("Invalid continuation byte")}if(224==(240&e)){if(t=u(),n=u(),i=(15&e)<<12|t<<6|n,i>=2048)return s(i),i;throw Error("Invalid continuation byte")}if(240==(248&e)&&(t=u(),n=u(),r=u(),i=(15&e)<<18|t<<12|n<<6|r,i>=65536&&1114111>=i))return i;throw Error("Invalid UTF-8 detected")}function f(e){v=o(e),y=v.length,b=0;for(var t,n=[];(t=l())!==!1;)n.push(t);return a(n)}var h="object"==typeof r&&r,m="object"==typeof n&&n&&n.exports==h&&n,g="object"==typeof t&&t;g.global!==g&&g.window!==g||(i=g);var v,y,b,w=String.fromCharCode,S={version:"2.0.0",encode:d,decode:f};if("function"==typeof e&&"object"==typeof e.amd&&e.amd)e(function(){return S});else if(h&&!h.nodeType)if(m)m.exports=S;else{var C={},k=C.hasOwnProperty;for(var E in S)k.call(S,E)&&(h[E]=S[E])}else i.utf8=S}(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],66:[function(e,t,n){t.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},{}],67:[function(e,t,n){(function(t,r){function i(e,t){var r={seen:[],stylize:a};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),m(t)?r.showHidden=t:t&&n._extend(r,t),S(r.showHidden)&&(r.showHidden=!1),S(r.depth)&&(r.depth=2),S(r.colors)&&(r.colors=!1),S(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=o),c(r,e,r.depth)}function o(e,t){var n=i.styles[t];return n?"["+i.colors[n][0]+"m"+e+"["+i.colors[n][1]+"m":e}function a(e,t){return e}function s(e){var t={};return e.forEach(function(e,n){t[e]=!0}),t}function c(e,t,r){if(e.customInspect&&t&&x(t.inspect)&&t.inspect!==n.inspect&&(!t.constructor||t.constructor.prototype!==t)){var i=t.inspect(r,e);return b(i)||(i=c(e,i,r)),i}var o=p(e,t);if(o)return o;var a=Object.keys(t),m=s(a);if(e.showHidden&&(a=Object.getOwnPropertyNames(t)),T(t)&&(a.indexOf("message")>=0||a.indexOf("description")>=0))return d(t);if(0===a.length){if(x(t)){var g=t.name?": "+t.name:"";return e.stylize("[Function"+g+"]","special")}if(C(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(E(t))return e.stylize(Date.prototype.toString.call(t),"date");if(T(t))return d(t)}var v="",y=!1,w=["{","}"];if(h(t)&&(y=!0,w=["[","]"]),x(t)){var S=t.name?": "+t.name:"";v=" [Function"+S+"]"}if(C(t)&&(v=" "+RegExp.prototype.toString.call(t)),E(t)&&(v=" "+Date.prototype.toUTCString.call(t)),T(t)&&(v=" "+d(t)),0===a.length&&(!y||0==t.length))return w[0]+v+w[1];if(0>r)return C(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var k;return k=y?u(e,t,r,m,a):a.map(function(n){return l(e,t,r,m,n,y)}),e.seen.pop(),f(k,v,w)}function p(e,t){if(S(t))return e.stylize("undefined","undefined");if(b(t)){var n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string")}return y(t)?e.stylize(""+t,"number"):m(t)?e.stylize(""+t,"boolean"):g(t)?e.stylize("null","null"):void 0}function d(e){return"["+Error.prototype.toString.call(e)+"]"}function u(e,t,n,r,i){for(var o=[],a=0,s=t.length;s>a;++a)M(t,String(a))?o.push(l(e,t,n,r,String(a),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(l(e,t,n,r,i,!0))}),o}function l(e,t,n,r,i,o){var a,s,p;if(p=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]},p.get?s=p.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):p.set&&(s=e.stylize("[Setter]","special")),M(r,i)||(a="["+i+"]"),s||(e.seen.indexOf(p.value)<0?(s=g(n)?c(e,p.value,null):c(e,p.value,n-1),s.indexOf("\n")>-1&&(s=o?s.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+s.split("\n").map(function(e){return" "+e}).join("\n"))):s=e.stylize("[Circular]","special")),S(a)){if(o&&i.match(/^\d+$/))return s;a=JSON.stringify(""+i),a.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(a=a.substr(1,a.length-2),a=e.stylize(a,"name")):(a=a.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),a=e.stylize(a,"string"))}return a+": "+s}function f(e,t,n){var r=0,i=e.reduce(function(e,t){return r++,t.indexOf("\n")>=0&&r++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?n[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+n[1]:n[0]+t+" "+e.join(", ")+" "+n[1]}function h(e){return Array.isArray(e)}function m(e){return"boolean"==typeof e}function g(e){return null===e}function v(e){return null==e}function y(e){return"number"==typeof e}function b(e){return"string"==typeof e}function w(e){return"symbol"==typeof e}function S(e){return void 0===e}function C(e){return k(e)&&"[object RegExp]"===R(e)}function k(e){return"object"==typeof e&&null!==e}function E(e){return k(e)&&"[object Date]"===R(e)}function T(e){return k(e)&&("[object Error]"===R(e)||e instanceof Error)}function x(e){return"function"==typeof e}function P(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function R(e){return Object.prototype.toString.call(e)}function D(e){return 10>e?"0"+e.toString(10):e.toString(10)}function O(){var e=new Date,t=[D(e.getHours()),D(e.getMinutes()),D(e.getSeconds())].join(":");return[e.getDate(),_[e.getMonth()],t].join(" ")}function M(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var A=/%[sdj%]/g;n.format=function(e){if(!b(e)){for(var t=[],n=0;n=o)return e;switch(e){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return e}}),s=r[n];o>n;s=r[++n])a+=g(s)||!k(s)?" "+s:" "+i(s);return a},n.deprecate=function(e,i){function o(){if(!a){if(t.throwDeprecation)throw new Error(i);t.traceDeprecation?console.trace(i):console.error(i),a=!0}return e.apply(this,arguments)}if(S(r.process))return function(){return n.deprecate(e,i).apply(this,arguments)};if(t.noDeprecation===!0)return e;var a=!1;return o};var j,I={};n.debuglog=function(e){if(S(j)&&(j=t.env.NODE_DEBUG||""),e=e.toUpperCase(),!I[e])if(new RegExp("\\b"+e+"\\b","i").test(j)){var r=t.pid;I[e]=function(){var t=n.format.apply(n,arguments);console.error("%s %d: %s",e,r,t)}}else I[e]=function(){};return I[e]},n.inspect=i,i.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},i.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},n.isArray=h,n.isBoolean=m,n.isNull=g,n.isNullOrUndefined=v,n.isNumber=y,n.isString=b,n.isSymbol=w,n.isUndefined=S,n.isRegExp=C,n.isObject=k,n.isDate=E,n.isError=T,n.isFunction=x,n.isPrimitive=P,n.isBuffer=e("./support/isBuffer");var _=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];n.log=function(){console.log("%s - %s",O(),n.format.apply(n,arguments))},n.inherits=e("inherits"),n._extend=function(e,t){if(!t||!k(t))return e;for(var n=Object.keys(t),r=n.length;r--;)e[n[r]]=t[n[r]];return e}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":66,_process:46,inherits:34}],68:[function(e,t,n){"use strict";!function(){var n=e("./utils").log,r=e("./utils").browserDetails;t.exports.browserDetails=r,t.exports.extractVersion=e("./utils").extractVersion,t.exports.disableLog=e("./utils").disableLog;var i=e("./chrome/chrome_shim")||null,o=e("./edge/edge_shim")||null,a=e("./firefox/firefox_shim")||null,s=e("./safari/safari_shim")||null;switch(r.browser){case"opera":case"chrome":if(!i||!i.shimPeerConnection)return void n("Chrome shim is not included in this adapter release.");n("adapter.js shimming chrome."),t.exports.browserShim=i,i.shimGetUserMedia(),i.shimMediaStream(),i.shimSourceObject(),i.shimPeerConnection(),i.shimOnTrack();break;case"firefox":if(!a||!a.shimPeerConnection)return void n("Firefox shim is not included in this adapter release.");n("adapter.js shimming firefox."),t.exports.browserShim=a,a.shimGetUserMedia(),a.shimSourceObject(),a.shimPeerConnection(),a.shimOnTrack();break;case"edge":if(!o||!o.shimPeerConnection)return void n("MS edge shim is not included in this adapter release.");n("adapter.js shimming edge."),t.exports.browserShim=o,o.shimGetUserMedia(),o.shimPeerConnection();break;case"safari":if(!s)return void n("Safari shim is not included in this adapter release.");n("adapter.js shimming safari."),t.exports.browserShim=s,s.shimGetUserMedia();break;default:n("Unsupported browser!")}}()},{"./chrome/chrome_shim":69,"./edge/edge_shim":71,"./firefox/firefox_shim":73,"./safari/safari_shim":75,"./utils":76}],69:[function(e,t,n){"use strict";var r=e("../utils.js").log,i=e("../utils.js").browserDetails,o={shimMediaStream:function(){window.MediaStream=window.MediaStream||window.webkitMediaStream},shimOnTrack:function(){"object"!=typeof window||!window.RTCPeerConnection||"ontrack"in window.RTCPeerConnection.prototype||Object.defineProperty(window.RTCPeerConnection.prototype,"ontrack",{get:function(){return this._ontrack},set:function(e){var t=this;this._ontrack&&(this.removeEventListener("track",this._ontrack),this.removeEventListener("addstream",this._ontrackpoly)),this.addEventListener("track",this._ontrack=e),this.addEventListener("addstream",this._ontrackpoly=function(e){e.stream.addEventListener("addtrack",function(n){var r=new Event("track");r.track=n.track,r.receiver={track:n.track},r.streams=[e.stream],t.dispatchEvent(r)}),e.stream.getTracks().forEach(function(t){var n=new Event("track");n.track=t,n.receiver={track:t},n.streams=[e.stream],this.dispatchEvent(n)}.bind(this))}.bind(this))}})},shimSourceObject:function(){"object"==typeof window&&(!window.HTMLMediaElement||"srcObject"in window.HTMLMediaElement.prototype||Object.defineProperty(window.HTMLMediaElement.prototype,"srcObject",{get:function(){return this._srcObject},set:function(e){var t=this;return this._srcObject=e,this.src&&URL.revokeObjectURL(this.src),e?(this.src=URL.createObjectURL(e),e.addEventListener("addtrack",function(){t.src&&URL.revokeObjectURL(t.src),t.src=URL.createObjectURL(e)}),void e.addEventListener("removetrack",function(){t.src&&URL.revokeObjectURL(t.src),t.src=URL.createObjectURL(e)})):void(this.src="")}}))},shimPeerConnection:function(){window.RTCPeerConnection=function(e,t){r("PeerConnection"),e&&e.iceTransportPolicy&&(e.iceTransports=e.iceTransportPolicy);var n=new webkitRTCPeerConnection(e,t),i=n.getStats.bind(n);return n.getStats=function(e,t,n){var r=this,o=arguments;if(arguments.length>0&&"function"==typeof e)return i(e,t);var a=function(e){var t={},n=e.result();return n.forEach(function(e){var n={id:e.id,timestamp:e.timestamp,type:e.type};e.names().forEach(function(t){n[t]=e.stat(t)}),t[n.id]=n}),t},s=function(e,t){var n=new Map(Object.keys(e).map(function(t){return[t,e[t]]}));return t=t||e,Object.keys(t).forEach(function(e){n[e]=t[e]}),n};if(arguments.length>=2){var c=function(e){o[1](s(a(e)))};return i.apply(this,[c,arguments[0]])}return new Promise(function(t,n){1===o.length&&"object"==typeof e?i.apply(r,[function(e){t(s(a(e)))},n]):i.apply(r,[function(e){t(s(a(e),e.result()))},n])}).then(t,n)},n},window.RTCPeerConnection.prototype=webkitRTCPeerConnection.prototype,webkitRTCPeerConnection.generateCertificate&&Object.defineProperty(window.RTCPeerConnection,"generateCertificate",{get:function(){return webkitRTCPeerConnection.generateCertificate}}),i.version<51&&(["createOffer","createAnswer"].forEach(function(e){var t=webkitRTCPeerConnection.prototype[e];webkitRTCPeerConnection.prototype[e]=function(){ var e=this;if(arguments.length<1||1===arguments.length&&"object"==typeof arguments[0]){var n=1===arguments.length?arguments[0]:void 0;return new Promise(function(r,i){t.apply(e,[r,i,n])})}return t.apply(this,arguments)}}),["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(e){var t=webkitRTCPeerConnection.prototype[e];webkitRTCPeerConnection.prototype[e]=function(){var e=arguments,n=this,r=new Promise(function(r,i){t.apply(n,[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])})}}));var e=RTCPeerConnection.prototype.addIceCandidate;RTCPeerConnection.prototype.addIceCandidate=function(){return null===arguments[0]?Promise.resolve():e.apply(this,arguments)},["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(e){var t=webkitRTCPeerConnection.prototype[e];webkitRTCPeerConnection.prototype[e]=function(){return arguments[0]=new("addIceCandidate"===e?RTCIceCandidate:RTCSessionDescription)(arguments[0]),t.apply(this,arguments)}})},attachMediaStream:function(e,t){r("DEPRECATED, attachMediaStream will soon be removed."),i.version>=43?e.srcObject=t:"undefined"!=typeof e.src?e.src=URL.createObjectURL(t):r("Error attaching stream to element.")},reattachMediaStream:function(e,t){r("DEPRECATED, reattachMediaStream will soon be removed."),i.version>=43?e.srcObject=t.srcObject:e.src=t.src}};t.exports={shimMediaStream:o.shimMediaStream,shimOnTrack:o.shimOnTrack,shimSourceObject:o.shimSourceObject,shimPeerConnection:o.shimPeerConnection,shimGetUserMedia:e("./getusermedia"),attachMediaStream:o.attachMediaStream,reattachMediaStream:o.reattachMediaStream}},{"../utils.js":76,"./getusermedia":70}],70:[function(e,t,n){"use strict";var r=e("../utils.js").log;t.exports=function(){var e=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={},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},t=function(t,n){if(t=JSON.parse(JSON.stringify(t)),t&&t.audio&&(t.audio=e(t.audio)),t&&"object"==typeof t.video){var i=t.video.facingMode;if(i=i&&("object"==typeof i?i:{ideal:i}),i&&("user"===i.exact||"environment"===i.exact||"user"===i.ideal||"environment"===i.ideal)&&(!navigator.mediaDevices.getSupportedConstraints||!navigator.mediaDevices.getSupportedConstraints().facingMode)&&(delete t.video.facingMode,"environment"===i.exact||"environment"===i.ideal))return navigator.mediaDevices.enumerateDevices().then(function(o){o=o.filter(function(e){return"videoinput"===e.kind});var a=o.find(function(e){return-1!==e.label.toLowerCase().indexOf("back")})||o.length&&o[o.length-1];return a&&(t.video.deviceId=i.exact?{exact:a.deviceId}:{ideal:a.deviceId}),t.video=e(t.video),r("chrome: "+JSON.stringify(t)),n(t)});t.video=e(t.video)}return r("chrome: "+JSON.stringify(t)),n(t)},n=function(e){return{name:{PermissionDeniedError:"NotAllowedError",ConstraintNotSatisfiedError:"OverconstrainedError"}[e.name]||e.name,message:e.message,constraint:e.constraintName,toString:function(){return this.name+(this.message&&": ")+this.message}}},i=function(e,r,i){t(e,function(e){navigator.webkitGetUserMedia(e,r,function(e){i(n(e))})})};navigator.getUserMedia=i;var o=function(e){return new Promise(function(t,n){navigator.getUserMedia(e,t,n)})};if(navigator.mediaDevices||(navigator.mediaDevices={getUserMedia:o,enumerateDevices:function(){return new Promise(function(e){var t={audio:"audioinput",video:"videoinput"};return MediaStreamTrack.getSources(function(n){e(n.map(function(e){return{label:e.label,kind:t[e.kind],deviceId:e.id,groupId:""}}))})})}}),navigator.mediaDevices.getUserMedia){var a=navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);navigator.mediaDevices.getUserMedia=function(e){return t(e,function(e){return a(e)["catch"](function(e){return Promise.reject(n(e))})})}}else navigator.mediaDevices.getUserMedia=function(e){return o(e)};"undefined"==typeof navigator.mediaDevices.addEventListener&&(navigator.mediaDevices.addEventListener=function(){r("Dummy mediaDevices.addEventListener called.")}),"undefined"==typeof navigator.mediaDevices.removeEventListener&&(navigator.mediaDevices.removeEventListener=function(){r("Dummy mediaDevices.removeEventListener called.")})}},{"../utils.js":76}],71:[function(e,t,n){"use strict";var r=e("sdp"),i=e("../utils").log,o={shimPeerConnection:function(){window.RTCIceGatherer&&(window.RTCIceCandidate||(window.RTCIceCandidate=function(e){return e}),window.RTCSessionDescription||(window.RTCSessionDescription=function(e){return e})),window.RTCPeerConnection=function(e){var t=this,n=document.createDocumentFragment();if(["addEventListener","removeEventListener","dispatchEvent"].forEach(function(e){t[e]=n[e].bind(n)}),this.onicecandidate=null,this.onaddstream=null,this.ontrack=null,this.onremovestream=null,this.onsignalingstatechange=null,this.oniceconnectionstatechange=null,this.onnegotiationneeded=null,this.ondatachannel=null,this.localStreams=[],this.remoteStreams=[],this.getLocalStreams=function(){return t.localStreams},this.getRemoteStreams=function(){return t.remoteStreams},this.localDescription=new RTCSessionDescription({type:"",sdp:""}),this.remoteDescription=new RTCSessionDescription({type:"",sdp:""}),this.signalingState="stable",this.iceConnectionState="new",this.iceGatheringState="new",this.iceOptions={gatherPolicy:"all",iceServers:[]},e&&e.iceTransportPolicy)switch(e.iceTransportPolicy){case"all":case"relay":this.iceOptions.gatherPolicy=e.iceTransportPolicy;break;case"none":throw new TypeError('iceTransportPolicy "none" not supported')}e&&e.iceServers&&(this.iceOptions.iceServers=e.iceServers.filter(function(e){return e&&e.urls?(e.urls=e.urls.filter(function(e){return 0===e.indexOf("turn:")&&-1!==e.indexOf("transport=udp")})[0],!!e.urls):!1})),this.transceivers=[],this._localIceCandidatesBuffer=[]},window.RTCPeerConnection.prototype._emitBufferedCandidates=function(){var e=this,t=r.splitSections(e.localDescription.sdp);this._localIceCandidatesBuffer.forEach(function(n){var r=!n.candidate||0===Object.keys(n.candidate).length;if(r)for(var i=1;i-1&&(this.localStreams.splice(t,1),this._maybeFireNegotiationNeeded())},window.RTCPeerConnection.prototype.getSenders=function(){return this.transceivers.filter(function(e){return!!e.rtpSender}).map(function(e){return e.rtpSender})},window.RTCPeerConnection.prototype.getReceivers=function(){return this.transceivers.filter(function(e){return!!e.rtpReceiver}).map(function(e){return e.rtpReceiver})},window.RTCPeerConnection.prototype._getCommonCapabilities=function(e,t){var n={codecs:[],headerExtensions:[],fecMechanisms:[]};return e.codecs.forEach(function(e){for(var r=0;r0;t.forEach(function(e,t){var a=i.transceivers[t],s=a.iceGatherer,c=a.iceTransport,p=a.dtlsTransport,d=a.localCapabilities,u=a.remoteCapabilities,l="0"===e.split("\n",1)[0].split(" ",2)[1];if(!l){var f=r.getIceParameters(e,n);if(o){var h=r.matchPrefix(e,"a=candidate:").map(function(e){return r.parseCandidate(e)}).filter(function(e){return"1"===e.component});c.setRemoteCandidates(h)}c.start(s,f,o?"controlling":"controlled");var m=r.getDtlsParameters(e,n);o&&(m.role="server"),p.start(m);var g=i._getCommonCapabilities(d,u);i._transceive(a,g.codecs.length>0,!1)}})}switch(this.localDescription={type:e.type,sdp:e.sdp},e.type){case"offer":this._updateSignalingState("have-local-offer");break;case"answer":this._updateSignalingState("stable");break;default:throw new TypeError('unsupported type "'+e.type+'"')}var a=arguments.length>1&&"function"==typeof arguments[1];if(a){var s=arguments[1];window.setTimeout(function(){s(),"new"===i.iceGatheringState&&(i.iceGatheringState="gathering"),i._emitBufferedCandidates()},0)}var c=Promise.resolve();return c.then(function(){a||("new"===i.iceGatheringState&&(i.iceGatheringState="gathering"),window.setTimeout(i._emitBufferedCandidates.bind(i),500))}),c},window.RTCPeerConnection.prototype.setRemoteDescription=function(e){var t=this,n=new MediaStream,i=[],o=r.splitSections(e.sdp),a=o.shift(),s=r.matchPrefix(a,"a=ice-lite").length>0;switch(o.forEach(function(o,c){var p,d,u,l,f,h,m,g,v,y,b,w,S=r.splitLines(o),C=S[0].substr(2).split(" "),k=C[0],E="0"===C[1],T=r.getDirection(o,a),x=r.parseRtpParameters(o);E||(b=r.getIceParameters(o,a),w=r.getDtlsParameters(o,a),w.role="client"),g=r.parseRtpEncodingParameters(o);var P=r.matchPrefix(o,"a=mid:");P=P.length?P[0].substr(6):r.generateIdentifier();var R,D=r.matchPrefix(o,"a=ssrc:").map(function(e){return r.parseSsrcMedia(e)}).filter(function(e){return"cname"===e.attribute})[0];D&&(R=D.value);var O=r.matchPrefix(o,"a=end-of-candidates").length>0,M=r.matchPrefix(o,"a=candidate:").map(function(e){return r.parseCandidate(e)}).filter(function(e){return"1"===e.component});if("offer"!==e.type||E)"answer"!==e.type||E||(p=t.transceivers[c],d=p.iceGatherer,u=p.iceTransport,l=p.dtlsTransport,f=p.rtpSender,h=p.rtpReceiver,m=p.sendEncodingParameters,v=p.localCapabilities,t.transceivers[c].recvEncodingParameters=g,t.transceivers[c].remoteCapabilities=x,t.transceivers[c].cname=R,(s||O)&&u.setRemoteCandidates(M),u.start(d,b,"controlling"),l.start(w),t._transceive(p,"sendrecv"===T||"recvonly"===T,"sendrecv"===T||"sendonly"===T),!h||"sendrecv"!==T&&"sendonly"!==T?delete p.rtpReceiver:(y=h.track,i.push([y,h]),n.addTrack(y)));else{var A=t._createIceAndDtlsTransports(P,c);if(O&&A.iceTransport.setRemoteCandidates(M),v=RTCRtpReceiver.getCapabilities(k),m=[{ssrc:1001*(2*c+2)}],h=new RTCRtpReceiver(A.dtlsTransport,k),y=h.track,i.push([y,h]),n.addTrack(y),t.localStreams.length>0&&t.localStreams[0].getTracks().length>=c){var j=t.localStreams[0].getTracks()[c];f=new RTCRtpSender(j,A.dtlsTransport)}t.transceivers[c]={iceGatherer:A.iceGatherer,iceTransport:A.iceTransport,dtlsTransport:A.dtlsTransport,localCapabilities:v,remoteCapabilities:x,rtpSender:f,rtpReceiver:h,kind:k,mid:P,cname:R,sendEncodingParameters:m,recvEncodingParameters:g},t._transceive(t.transceivers[c],!1,"sendrecv"===T||"sendonly"===T)}}),this.remoteDescription={type:e.type,sdp:e.sdp},e.type){case"offer":this._updateSignalingState("have-remote-offer");break;case"answer":this._updateSignalingState("stable");break;default:throw new TypeError('unsupported type "'+e.type+'"')}return n.getTracks().length&&(t.remoteStreams.push(n),window.setTimeout(function(){var e=new Event("addstream");e.stream=n,t.dispatchEvent(e),null!==t.onaddstream&&window.setTimeout(function(){t.onaddstream(e)},0),i.forEach(function(r){var i=r[0],o=r[1],a=new Event("track");a.track=i,a.receiver=o,a.streams=[n],t.dispatchEvent(e),null!==t.ontrack&&window.setTimeout(function(){t.ontrack(a)},0)})},0)),arguments.length>1&&"function"==typeof arguments[1]&&window.setTimeout(arguments[1],0),Promise.resolve()},window.RTCPeerConnection.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")},window.RTCPeerConnection.prototype._updateSignalingState=function(e){this.signalingState=e;var t=new Event("signalingstatechange");this.dispatchEvent(t),null!==this.onsignalingstatechange&&this.onsignalingstatechange(t)},window.RTCPeerConnection.prototype._maybeFireNegotiationNeeded=function(){var e=new Event("negotiationneeded");this.dispatchEvent(e),null!==this.onnegotiationneeded&&this.onnegotiationneeded(e)},window.RTCPeerConnection.prototype._updateConnectionState=function(){var e,t=this,n={"new":0,closed:0,connecting:0,checking:0,connected:0,completed:0,failed:0};if(this.transceivers.forEach(function(e){n[e.iceTransport.state]++,n[e.dtlsTransport.state]++}),n.connected+=n.completed,e="new",n.failed>0?e="failed":n.connecting>0||n.checking>0?e="connecting":n.disconnected>0?e="disconnected":n["new"]>0?e="new":(n.connected>0||n.completed>0)&&(e="connected"),e!==t.iceConnectionState){t.iceConnectionState=e;var r=new Event("iceconnectionstatechange");this.dispatchEvent(r),null!==this.oniceconnectionstatechange&&this.oniceconnectionstatechange(r)}},window.RTCPeerConnection.prototype.createOffer=function(){var e=this;if(this._pendingOffer)throw new Error("createOffer called while there is a pending offer.");var t;1===arguments.length&&"function"!=typeof arguments[0]?t=arguments[0]:3===arguments.length&&(t=arguments[2]);var n=[],i=0,o=0;if(this.localStreams.length&&(i=this.localStreams[0].getAudioTracks().length,o=this.localStreams[0].getVideoTracks().length),t){if(t.mandatory||t.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");void 0!==t.offerToReceiveAudio&&(i=t.offerToReceiveAudio),void 0!==t.offerToReceiveVideo&&(o=t.offerToReceiveVideo)}for(this.localStreams.length&&this.localStreams[0].getTracks().forEach(function(e){n.push({kind:e.kind,track:e,wantReceive:"audio"===e.kind?i>0:o>0}),"audio"===e.kind?i--:"video"===e.kind&&o--});i>0||o>0;)i>0&&(n.push({kind:"audio",wantReceive:!0}),i--),o>0&&(n.push({kind:"video",wantReceive:!0}),o--);var a=r.writeSessionBoilerplate(),s=[];n.forEach(function(t,n){var i,o,c=t.track,p=t.kind,d=r.generateIdentifier(),u=e._createIceAndDtlsTransports(d,n),l=RTCRtpSender.getCapabilities(p),f=[{ssrc:1001*(2*n+1)}];c&&(i=new RTCRtpSender(c,u.dtlsTransport)),t.wantReceive&&(o=new RTCRtpReceiver(u.dtlsTransport,p)),s[n]={iceGatherer:u.iceGatherer,iceTransport:u.iceTransport,dtlsTransport:u.dtlsTransport,localCapabilities:l,remoteCapabilities:null,rtpSender:i,rtpReceiver:o,kind:p,mid:d,sendEncodingParameters:f,recvEncodingParameters:null};var h=s[n];a+=r.writeMediaSection(h,h.localCapabilities,"offer",e.localStreams[0])}),this._pendingOffer=s;var c=new RTCSessionDescription({type:"offer",sdp:a});return arguments.length&&"function"==typeof arguments[0]&&window.setTimeout(arguments[0],0,c),Promise.resolve(c)},window.RTCPeerConnection.prototype.createAnswer=function(){var e=this,t=r.writeSessionBoilerplate();this.transceivers.forEach(function(n){var i=e._getCommonCapabilities(n.localCapabilities,n.remoteCapabilities);t+=r.writeMediaSection(n,i,"answer",e.localStreams[0])});var n=new RTCSessionDescription({type:"answer",sdp:t});return arguments.length&&"function"==typeof arguments[0]&&window.setTimeout(arguments[0],0,n),Promise.resolve(n)},window.RTCPeerConnection.prototype.addIceCandidate=function(e){if(null===e)this.transceivers.forEach(function(e){e.iceTransport.addIceCandidate({})});else{var t=e.sdpMLineIndex;if(e.sdpMid)for(var n=0;n0?r.parseCandidate(e.candidate):{};if("tcp"===o.protocol&&0===o.port)return;if("1"!==o.component)return;"endOfCandidates"===o.type&&(o={}),i.iceTransport.addRemoteCandidate(o);var a=r.splitSections(this.remoteDescription.sdp);a[t+1]+=(o.type?e.candidate.trim():"a=end-of-candidates")+"\r\n",this.remoteDescription.sdp=a.join("")}}return arguments.length>1&&"function"==typeof arguments[1]&&window.setTimeout(arguments[1],0),Promise.resolve()},window.RTCPeerConnection.prototype.getStats=function(){var e=[];this.transceivers.forEach(function(t){["rtpSender","rtpReceiver","iceGatherer","iceTransport","dtlsTransport"].forEach(function(n){t[n]&&e.push(t[n].getStats())})});var t=arguments.length>1&&"function"==typeof arguments[1]&&arguments[1];return new Promise(function(n){var r=new Map;Promise.all(e).then(function(e){e.forEach(function(e){Object.keys(e).forEach(function(t){r.set(t,e[t]),r[t]=e[t]})}),t&&window.setTimeout(t,0,r),n(r)})})}},attachMediaStream:function(e,t){i("DEPRECATED, attachMediaStream will soon be removed."),e.srcObject=t},reattachMediaStream:function(e,t){i("DEPRECATED, reattachMediaStream will soon be removed."),e.srcObject=t.srcObject}};t.exports={shimPeerConnection:o.shimPeerConnection,shimGetUserMedia:e("./getusermedia"),attachMediaStream:o.attachMediaStream,reattachMediaStream:o.reattachMediaStream}},{"../utils":76,"./getusermedia":72,sdp:53}],72:[function(e,t,n){"use strict";t.exports=function(){var e=function(e){return{name:{PermissionDeniedError:"NotAllowedError"}[e.name]||e.name,message:e.message,constraint:e.constraint,toString:function(){return this.name}}},t=navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);navigator.mediaDevices.getUserMedia=function(n){return t(n)["catch"](function(t){return Promise.reject(e(t))})}}},{}],73:[function(e,t,n){"use strict";var r=e("../utils").log,i=e("../utils").browserDetails,o={shimOnTrack:function(){"object"!=typeof window||!window.RTCPeerConnection||"ontrack"in window.RTCPeerConnection.prototype||Object.defineProperty(window.RTCPeerConnection.prototype,"ontrack",{get:function(){return this._ontrack},set:function(e){this._ontrack&&(this.removeEventListener("track",this._ontrack),this.removeEventListener("addstream",this._ontrackpoly)),this.addEventListener("track",this._ontrack=e),this.addEventListener("addstream",this._ontrackpoly=function(e){e.stream.getTracks().forEach(function(t){var n=new Event("track");n.track=t,n.receiver={track:t},n.streams=[e.stream],this.dispatchEvent(n)}.bind(this))}.bind(this))}})},shimSourceObject:function(){"object"==typeof window&&(!window.HTMLMediaElement||"srcObject"in window.HTMLMediaElement.prototype||Object.defineProperty(window.HTMLMediaElement.prototype,"srcObject",{get:function(){return this.mozSrcObject},set:function(e){this.mozSrcObject=e}}))},shimPeerConnection:function(){if("object"==typeof window&&(window.RTCPeerConnection||window.mozRTCPeerConnection)){window.RTCPeerConnection||(window.RTCPeerConnection=function(e,t){if(i.version<38&&e&&e.iceServers){for(var n=[],r=0;r=n&&parseInt(r[n],10)},detectBrowser:function(){var e={};if(e.browser=null,e.version=null,e.minVersion=null,"undefined"==typeof window||!window.navigator)return e.browser="Not a browser.",e;if(navigator.mozGetUserMedia)e.browser="firefox",e.version=this.extractVersion(navigator.userAgent,/Firefox\/([0-9]+)\./,1),e.minVersion=31;else if(navigator.webkitGetUserMedia)if(window.webkitRTCPeerConnection)e.browser="chrome",e.version=this.extractVersion(navigator.userAgent,/Chrom(e|ium)\/([0-9]+)\./,2),e.minVersion=38;else{if(!navigator.userAgent.match(/Version\/(\d+).(\d+)/))return e.browser="Unsupported webkit-based browser with GUM support but no WebRTC support.",e;e.browser="safari",e.version=this.extractVersion(navigator.userAgent,/AppleWebKit\/([0-9]+)\./,1),e.minVersion=602}else{if(!navigator.mediaDevices||!navigator.userAgent.match(/Edge\/(\d+).(\d+)$/))return e.browser="Not a supported browser.",e;e.browser="edge",e.version=this.extractVersion(navigator.userAgent,/Edge\/(\d+).(\d+)$/,2),e.minVersion=10547}return e.version=26||"moz"===r&&i>=33),d=window.AudioContext||window.webkitAudioContext,u=document.createElement("video"),l=u&&u.canPlayType&&"probably"===u.canPlayType('video/webm; codecs="vp8", vorbis'),f=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.msGetUserMedia||navigator.mozGetUserMedia;t.exports={prefix:r,browserVersion:i,support:!!o&&!!f,supportRTCPeerConnection:!!o,supportVp8:l,supportGetUserMedia:!!f,supportDataChannel:!!(o&&o.prototype&&o.prototype.createDataChannel),supportWebAudio:!(!d||!d.prototype.createMediaStreamSource),supportMediaStream:!(!c||!c.prototype.removeTrack),supportScreenSharing:!!p,AudioContext:d,PeerConnection:o,SessionDescription:s,IceCandidate:a,MediaStream:c,getUserMedia:f}},{}],78:[function(e,t,n){function r(){}t.exports=r,r.mixin=function(e){var t=e.prototype||e;t.isWildEmitter=!0,t.on=function(e,t,n){this.callbacks=this.callbacks||{};var r=3===arguments.length,i=r?arguments[1]:void 0,o=r?arguments[2]:arguments[1];return o._groupName=i,(this.callbacks[e]=this.callbacks[e]||[]).push(o),this},t.once=function(e,t,n){function r(){i.off(e,r),s.apply(this,arguments)}var i=this,o=3===arguments.length,a=o?arguments[1]:void 0,s=o?arguments[2]:arguments[1];return this.on(e,a,r),this},t.releaseGroup=function(e){this.callbacks=this.callbacks||{};var t,n,r,i;for(t in this.callbacks)for(i=this.callbacks[t],n=0,r=i.length;r>n;n++)i[n]._groupName===e&&(i.splice(n,1),n--,r--);return this},t.off=function(e,t){this.callbacks=this.callbacks||{};var n,r=this.callbacks[e];return r?1===arguments.length?(delete this.callbacks[e],this):(n=r.indexOf(t),r.splice(n,1),0===r.length&&delete this.callbacks[e],this):this},t.emit=function(e){this.callbacks=this.callbacks||{};var t,n,r,i=[].slice.call(arguments,1),o=this.callbacks[e],a=this.getWildcardCallbacks(e);if(o)for(r=o.slice(),t=0,n=r.length;n>t&&r[t];++t)r[t].apply(this,i);if(a)for(n=a.length,r=a.slice(),t=0,n=r.length;n>t&&r[t];++t)r[t].apply(this,[e].concat(i));return this},t.getWildcardCallbacks=function(e){ -this.callbacks=this.callbacks||{};var t,n,r=[];for(t in this.callbacks)n=t.split("*"),("*"===t||2===n.length&&e.slice(0,n[0].length)===n[0])&&(r=r.concat(this.callbacks[t]));return r}},r.mixin(r)},{}],79:[function(e,t,n){function r(e,t,n){var r;return r=t?new o(e,t):new o(e)}var i=function(){return this}(),o=i.WebSocket||i.MozWebSocket;t.exports=o?r:null,o&&(r.prototype=o.prototype)},{}],80:[function(e,t,n){function r(e){var t=this;s.call(this),this.id=e.id,this.parent=e.parent,this.type=e.type||"video",this.oneway=e.oneway||!1,this.sharemyscreen=e.sharemyscreen||!1,this.browserPrefix=e.prefix,this.stream=e.stream,this.enableDataChannels=void 0===e.enableDataChannels?this.parent.config.enableDataChannels:e.enableDataChannels,this.receiveMedia=e.receiveMedia||this.parent.config.receiveMedia,this.channels={},this.sid=e.sid||Date.now().toString(),this.pc=new a(this.parent.config.peerConnectionConfig,this.parent.config.peerConnectionConstraints),this.pc.on("ice",this.onIceCandidate.bind(this)),this.pc.on("endOfCandidates",function(e){t.send("endOfCandidates",e)}),this.pc.on("offer",function(e){t.parent.config.nick&&(e.nick=t.parent.config.nick),t.send("offer",e)}),this.pc.on("answer",function(e){t.parent.config.nick&&(e.nick=t.parent.config.nick),t.send("answer",e)}),this.pc.on("addStream",this.handleRemoteStreamAdded.bind(this)),this.pc.on("addChannel",this.handleDataChannelAdded.bind(this)),this.pc.on("removeStream",this.handleStreamRemoved.bind(this)),this.pc.on("negotiationNeeded",this.emit.bind(this,"negotiationNeeded")),this.pc.on("iceConnectionStateChange",this.emit.bind(this,"iceConnectionStateChange")),this.pc.on("iceConnectionStateChange",function(){switch(t.pc.iceConnectionState){case"failed":"offer"===t.pc.pc.peerconnection.localDescription.type&&(t.parent.emit("iceFailed",t),t.send("connectivityError"))}}),this.pc.on("signalingStateChange",this.emit.bind(this,"signalingStateChange")),this.logger=this.parent.logger,"screen"===e.type?this.parent.localScreen&&this.sharemyscreen&&(this.logger.log("adding local screen stream to peer connection"),this.pc.addStream(this.parent.localScreen),this.broadcaster=e.broadcaster):this.parent.localStreams.forEach(function(e){t.pc.addStream(e)}),this.on("channelOpen",function(e){e.protocol===p&&(e.onmessage=function(n){var r=JSON.parse(n.data),i=new c.Receiver;i.receive(r,e),t.emit("fileTransfer",r,i),i.on("receivedFile",function(e,t){i.channel.close()})})}),this.on("*",function(){t.parent.emit.apply(t.parent,arguments)})}var i=e("util"),o=e("webrtcsupport"),a=e("rtcpeerconnection"),s=e("wildemitter"),c=e("filetransfer"),p="https://simplewebrtc.com/protocol/filetransfer#inband-v1";i.inherits(r,s),r.prototype.handleMessage=function(e){var t=this;if(this.logger.log("getting",e.type,e),e.prefix&&(this.browserPrefix=e.prefix),"offer"===e.type)this.nick||(this.nick=e.payload.nick),delete e.payload.nick,this.pc.handleOffer(e.payload,function(e){e||t.pc.answer(function(e,t){})});else if("answer"===e.type)this.nick||(this.nick=e.payload.nick),delete e.payload.nick,this.pc.handleAnswer(e.payload);else if("candidate"===e.type)this.pc.processIce(e.payload);else if("connectivityError"===e.type)this.parent.emit("connectivityError",t);else if("mute"===e.type)this.parent.emit("mute",{id:e.from,name:e.payload.name});else if("unmute"===e.type)this.parent.emit("unmute",{id:e.from,name:e.payload.name});else if("endOfCandidates"===e.type){var n=this.pc.pc.peerconnection.transceivers||[];n.forEach(function(e){e.iceTransport&&e.iceTransport.addRemoteCandidate({})})}},r.prototype.send=function(e,t){var n={to:this.id,sid:this.sid,broadcaster:this.broadcaster,roomType:this.type,type:e,payload:t,prefix:o.prefix};this.logger.log("sending",e,n),this.parent.emit("message",n)},r.prototype.sendDirectly=function(e,t,n){var r={type:t,payload:n};this.logger.log("sending via datachannel",e,t,r);var i=this.getDataChannel(e);return"open"!=i.readyState?!1:(i.send(JSON.stringify(r)),!0)},r.prototype._observeDataChannel=function(e){var t=this;e.onclose=this.emit.bind(this,"channelClose",e),e.onerror=this.emit.bind(this,"channelError",e),e.onmessage=function(n){t.emit("channelMessage",t,e.label,JSON.parse(n.data),e,n)},e.onopen=this.emit.bind(this,"channelOpen",e)},r.prototype.getDataChannel=function(e,t){if(!o.supportDataChannel)return this.emit("error",new Error("createDataChannel not supported"));var n=this.channels[e];return t||(t={}),n?n:(n=this.channels[e]=this.pc.createDataChannel(e,t),this._observeDataChannel(n),n)},r.prototype.onIceCandidate=function(e){if(!this.closed)if(e){var t=this.parent.config.peerConnectionConfig;"moz"===o.prefix&&t&&t.iceTransports&&e.candidate&&e.candidate.candidate&&e.candidate.candidate.indexOf(t.iceTransports)<0?this.logger.log("Ignoring ice candidate not matching pcConfig iceTransports type: ",t.iceTransports):this.send("candidate",e)}else this.logger.log("End of candidates.")},r.prototype.start=function(){this.enableDataChannels&&this.getDataChannel("simplewebrtc"),this.pc.offer(this.receiveMedia,function(e,t){})},r.prototype.icerestart=function(){var e=this.receiveMedia;e.mandatory.IceRestart=!0,this.pc.offer(e,function(e,t){})},r.prototype.end=function(){this.closed||(this.pc.close(),this.handleStreamRemoved())},r.prototype.handleRemoteStreamAdded=function(e){var t=this;this.stream?this.logger.warn("Already have a remote stream"):(this.stream=e.stream,this.stream.onended=function(){t.end()},this.parent.emit("peerStreamAdded",this))},r.prototype.handleStreamRemoved=function(){this.parent.peers.splice(this.parent.peers.indexOf(this),1),this.closed=!0,this.parent.emit("peerStreamRemoved",this)},r.prototype.handleDataChannelAdded=function(e){this.channels[e.label]=e,this._observeDataChannel(e)},r.prototype.sendFile=function(e){var t=new c.Sender,n=this.getDataChannel("filetransfer"+(new Date).getTime(),{protocol:p});return n.onopen=function(){n.send(JSON.stringify({size:e.size,name:e.name})),t.send(e,n)},n.onclose=function(){console.log("sender received transfer"),t.emit("complete")},t},t.exports=r},{filetransfer:26,rtcpeerconnection:47,util:67,webrtcsupport:77,wildemitter:78}],81:[function(e,t,n){function r(e){var t,n,r=this,d=e||{},u=this.config={url:"https://sandbox.simplewebrtc.com:443/",socketio:{},connection:null,debug:!1,localVideoEl:"",remoteVideosEl:"",enableDataChannels:!0,autoRequestMedia:!1,autoRemoveVideos:!0,adjustPeerVolume:!1,peerVolumeWhenSpeaking:.25,media:{video:!0,audio:!0},receiveMedia:{offerToReceiveAudio:1,offerToReceiveVideo:1},localVideo:{autoplay:!0,mirror:!0,muted:!0}};this.logger=function(){return e.debug?e.logger||console:e.logger||c}();for(t in d)this.config[t]=d[t];this.capabilities=a,o.call(this),n=null===this.config.connection?this.connection=new p(this.config):this.connection=this.config.connection,n.on("connect",function(){r.emit("connectionReady",n.getSessionid()),r.sessionReady=!0,r.testReadiness()}),n.on("message",function(e){var t,n=r.webrtc.getPeers(e.from,e.roomType);"offer"===e.type?(n.length&&n.forEach(function(n){n.sid==e.sid&&(t=n)}),t||(t=r.webrtc.createPeer({id:e.from,sid:e.sid,type:e.roomType,enableDataChannels:r.config.enableDataChannels&&"screen"!==e.roomType,sharemyscreen:"screen"===e.roomType&&!e.broadcaster,broadcaster:"screen"!==e.roomType||e.broadcaster?null:r.connection.getSessionid()}),r.emit("createdPeer",t)),t.handleMessage(e)):n.length&&n.forEach(function(t){e.sid?t.sid===e.sid&&t.handleMessage(e):t.handleMessage(e)})}),n.on("remove",function(e){e.id!==r.connection.getSessionid()&&r.webrtc.removePeers(e.id,e.type)}),e.logger=this.logger,e.debug=!1,this.webrtc=new i(e),["mute","unmute","pauseVideo","resumeVideo","pause","resume","sendToAll","sendDirectlyToAll","getPeers"].forEach(function(e){r[e]=r.webrtc[e].bind(r.webrtc)}),this.webrtc.on("*",function(){r.emit.apply(r,arguments)}),u.debug&&this.on("*",this.logger.log.bind(this.logger,"SimpleWebRTC event:")),this.webrtc.on("localStream",function(){r.testReadiness()}),this.webrtc.on("message",function(e){r.connection.emit("message",e)}),this.webrtc.on("peerStreamAdded",this.handlePeerStreamAdded.bind(this)),this.webrtc.on("peerStreamRemoved",this.handlePeerStreamRemoved.bind(this)),this.config.adjustPeerVolume&&(this.webrtc.on("speaking",this.setVolumeForAll.bind(this,this.config.peerVolumeWhenSpeaking)),this.webrtc.on("stoppedSpeaking",this.setVolumeForAll.bind(this,1))),n.on("stunservers",function(e){r.webrtc.config.peerConnectionConfig.iceServers=e,r.emit("stunservers",e)}),n.on("turnservers",function(e){r.webrtc.config.peerConnectionConfig.iceServers=r.webrtc.config.peerConnectionConfig.iceServers.concat(e),r.emit("turnservers",e)}),this.webrtc.on("iceFailed",function(e){}),this.webrtc.on("connectivityError",function(e){}),this.webrtc.on("audioOn",function(){r.webrtc.sendToAll("unmute",{name:"audio"})}),this.webrtc.on("audioOff",function(){r.webrtc.sendToAll("mute",{name:"audio"})}),this.webrtc.on("videoOn",function(){r.webrtc.sendToAll("unmute",{name:"video"})}),this.webrtc.on("videoOff",function(){r.webrtc.sendToAll("mute",{name:"video"})}),this.webrtc.on("localScreen",function(e){var t=document.createElement("video"),n=r.getRemoteVideoContainer();t.oncontextmenu=function(){return!1},t.id="localScreen",s(e,t),n&&n.appendChild(t),r.emit("localScreenAdded",t),r.connection.emit("shareScreen"),r.webrtc.peers.forEach(function(e){var t;"video"===e.type&&(t=r.webrtc.createPeer({id:e.id,type:"screen",sharemyscreen:!0,enableDataChannels:!1,receiveMedia:{offerToReceiveAudio:0,offerToReceiveVideo:0},broadcaster:r.connection.getSessionid()}),r.emit("createdPeer",t),t.start())})}),this.webrtc.on("localScreenStopped",function(e){r.stopScreenShare()}),this.webrtc.on("channelMessage",function(e,t,n){"volume"==n.type&&r.emit("remoteVolumeChange",e,n.volume)}),this.config.autoRequestMedia&&this.startLocalVideo()}var i=e("./webrtc"),o=e("wildemitter"),a=e("webrtcsupport"),s=e("attachmediastream"),c=e("mockconsole"),p=e("./socketioconnection");r.prototype=Object.create(o.prototype,{constructor:{value:r}}),r.prototype.leaveRoom=function(){if(this.roomName){for(this.connection.emit("leave");this.webrtc.peers.length;)this.webrtc.peers.shift().end();this.getLocalScreen()&&this.stopScreenShare(),this.emit("leftRoom",this.roomName),this.roomName=void 0}},r.prototype.disconnect=function(){this.connection.disconnect(),delete this.connection},r.prototype.handlePeerStreamAdded=function(e){var t=this,n=this.getRemoteVideoContainer(),r=s(e.stream);e.videoEl=r,r.id=this.getDomId(e),n&&n.appendChild(r),this.emit("videoAdded",r,e),window.setTimeout(function(){t.webrtc.isAudioEnabled()||e.send("mute",{name:"audio"}),t.webrtc.isVideoEnabled()||e.send("mute",{name:"video"})},250)},r.prototype.handlePeerStreamRemoved=function(e){var t=this.getRemoteVideoContainer(),n=e.videoEl;this.config.autoRemoveVideos&&t&&n&&t.removeChild(n),n&&this.emit("videoRemoved",n,e)},r.prototype.getDomId=function(e){return[e.id,e.type,e.broadcaster?"broadcasting":"incoming"].join("_")},r.prototype.setVolumeForAll=function(e){this.webrtc.peers.forEach(function(t){t.videoEl&&(t.videoEl.volume=e)})},r.prototype.joinRoom=function(e,t){var n=this;this.roomName=e,this.connection.emit("join",e,function(r,i){if(console.log("join CB",r,i),r)n.emit("error",r);else{var o,a,s,c;for(o in i.clients){a=i.clients[o];for(s in a)a[s]&&(c=n.webrtc.createPeer({id:o,type:s,enableDataChannels:n.config.enableDataChannels&&"screen"!==s,receiveMedia:{offerToReceiveAudio:"screen"!==s&&n.config.receiveMedia.offerToReceiveAudio?1:0,offerToReceiveVideo:n.config.receiveMedia.offerToReceiveVideo}}),n.emit("createdPeer",c),c.start())}}t&&t(r,i),n.emit("joinedRoom",e)})},r.prototype.getEl=function(e){return"string"==typeof e?document.getElementById(e):e},r.prototype.startLocalVideo=function(){var e=this;this.webrtc.startLocalMedia(this.config.media,function(t,n){t?e.emit("localMediaError",t):s(n,e.getLocalVideoContainer(),e.config.localVideo)})},r.prototype.stopLocalVideo=function(){this.webrtc.stopLocalMedia()},r.prototype.getLocalVideoContainer=function(){var e=this.getEl(this.config.localVideoEl);if(e&&"VIDEO"===e.tagName)return e.oncontextmenu=function(){return!1},e;if(e){var t=document.createElement("video");return t.oncontextmenu=function(){return!1},e.appendChild(t),t}},r.prototype.getRemoteVideoContainer=function(){return this.getEl(this.config.remoteVideosEl)},r.prototype.shareScreen=function(e){this.webrtc.startScreenShare(e)},r.prototype.getLocalScreen=function(){return this.webrtc.localScreen},r.prototype.stopScreenShare=function(){this.connection.emit("unshareScreen");var e=document.getElementById("localScreen"),t=this.getRemoteVideoContainer(),n=this.getLocalScreen();this.config.autoRemoveVideos&&t&&e&&t.removeChild(e),e&&this.emit("videoRemoved",e),n&&n.getTracks().forEach(function(e){e.stop()}),this.webrtc.peers.forEach(function(e){e.broadcaster&&e.end()})},r.prototype.testReadiness=function(){var e=this;this.sessionReady&&(this.config.media.video||this.config.media.audio?this.webrtc.localStreams.length>0&&e.emit("readyToCall",e.connection.getSessionid()):e.emit("readyToCall",e.connection.getSessionid()))},r.prototype.createRoom=function(e,t){this.roomName=e,2===arguments.length?this.connection.emit("create",e,t):this.connection.emit("create",e)},r.prototype.sendFile=function(){return a.dataChannel?void 0:this.emit("error",new Error("DataChannelNotSupported"))},t.exports=r},{"./socketioconnection":82,"./webrtc":83,attachmediastream:3,mockconsole:40,webrtcsupport:77,wildemitter:78}],82:[function(e,t,n){function r(e){this.connection=i.connect(e.url,e.socketio)}var i=e("socket.io-client");r.prototype.on=function(e,t){this.connection.on(e,t)},r.prototype.emit=function(){this.connection.emit.apply(this.connection,arguments)},r.prototype.getSessionid=function(){return this.connection.id},r.prototype.disconnect=function(){return this.connection.disconnect()},t.exports=r},{"socket.io-client":54}],83:[function(e,t,n){function r(e){var t,n=this,r=e||{};this.config={debug:!1,peerConnectionConfig:{iceServers:[{urls:"stun:stun.l.google.com:19302"}]},peerConnectionConstraints:{optional:[]},receiveMedia:{offerToReceiveAudio:1,offerToReceiveVideo:1},enableDataChannels:!0};this.screenSharingSupport=o.screenSharing,this.logger=function(){return e.debug?e.logger||console:e.logger||a}();for(t in r)this.config[t]=r[t];o.support||this.logger.error("Your browser doesn't seem to support WebRTC"),this.peers=[],s.call(this,this.config),this.on("speaking",function(){n.hardMuted||n.peers.forEach(function(e){if(e.enableDataChannels){var t=e.getDataChannel("hark");if("open"!=t.readyState)return;t.send(JSON.stringify({type:"speaking"}))}})}),this.on("stoppedSpeaking",function(){n.hardMuted||n.peers.forEach(function(e){if(e.enableDataChannels){var t=e.getDataChannel("hark");if("open"!=t.readyState)return;t.send(JSON.stringify({type:"stoppedSpeaking"}))}})}),this.on("volumeChange",function(e,t){n.hardMuted||n.peers.forEach(function(t){if(t.enableDataChannels){var n=t.getDataChannel("hark");if("open"!=n.readyState)return;n.send(JSON.stringify({type:"volume",volume:e}))}})}),this.config.debug&&this.on("*",function(e,t,r){var i;i=n.config.logger===a?console:n.logger,i.log("event:",e,t,r)})}var i=e("util"),o=e("webrtcsupport"),a=(e("wildemitter"),e("mockconsole")),s=e("localmedia"),c=e("./peer");i.inherits(r,s),r.prototype.createPeer=function(e){var t;return e.parent=this,t=new c(e),this.peers.push(t),t},r.prototype.removePeers=function(e,t){this.getPeers(e,t).forEach(function(e){e.end()})},r.prototype.getPeers=function(e,t){return this.peers.filter(function(n){return!(e&&n.id!==e||t&&n.type!==t)})},r.prototype.sendToAll=function(e,t){this.peers.forEach(function(n){n.send(e,t)})},r.prototype.sendDirectlyToAll=function(e,t,n){this.peers.forEach(function(r){r.enableDataChannels&&r.sendDirectly(e,t,n)})},t.exports=r},{"./peer":80,localmedia:37,mockconsole:40,util:67,webrtcsupport:77,wildemitter:78}]},{},[81])(81)}); \ No newline at end of file +this.callbacks=this.callbacks||{};var t,n,r=[];for(t in this.callbacks)n=t.split("*"),("*"===t||2===n.length&&e.slice(0,n[0].length)===n[0])&&(r=r.concat(this.callbacks[t]));return r}},r.mixin(r)},{}],79:[function(e,t,n){function r(e,t,n){var r;return r=t?new o(e,t):new o(e)}var i=function(){return this}(),o=i.WebSocket||i.MozWebSocket;t.exports=o?r:null,o&&(r.prototype=o.prototype)},{}],80:[function(e,t,n){function r(e){var t=this;s.call(this),this.id=e.id,this.parent=e.parent,this.type=e.type||"video",this.oneway=e.oneway||!1,this.sharemyscreen=e.sharemyscreen||!1,this.browserPrefix=e.prefix,this.stream=e.stream,this.enableDataChannels=void 0===e.enableDataChannels?this.parent.config.enableDataChannels:e.enableDataChannels,this.receiveMedia=e.receiveMedia||this.parent.config.receiveMedia,this.channels={},this.sid=e.sid||Date.now().toString(),this.pc=new a(this.parent.config.peerConnectionConfig,this.parent.config.peerConnectionConstraints),this.pc.on("ice",this.onIceCandidate.bind(this)),this.pc.on("endOfCandidates",function(e){t.send("endOfCandidates",e)}),this.pc.on("offer",function(e){t.parent.config.nick&&(e.nick=t.parent.config.nick),t.send("offer",e)}),this.pc.on("answer",function(e){t.parent.config.nick&&(e.nick=t.parent.config.nick),t.send("answer",e)}),this.pc.on("addStream",this.handleRemoteStreamAdded.bind(this)),this.pc.on("addChannel",this.handleDataChannelAdded.bind(this)),this.pc.on("removeStream",this.handleStreamRemoved.bind(this)),this.pc.on("negotiationNeeded",this.emit.bind(this,"negotiationNeeded")),this.pc.on("iceConnectionStateChange",this.emit.bind(this,"iceConnectionStateChange")),this.pc.on("iceConnectionStateChange",function(){switch(t.pc.iceConnectionState){case"failed":"offer"===t.pc.pc.peerconnection.localDescription.type&&(t.parent.emit("iceFailed",t),t.send("connectivityError"))}}),this.pc.on("signalingStateChange",this.emit.bind(this,"signalingStateChange")),this.logger=this.parent.logger,"screen"===e.type?this.parent.localScreen&&this.sharemyscreen&&(this.logger.log("adding local screen stream to peer connection"),this.pc.addStream(this.parent.localScreen),this.broadcaster=e.broadcaster):this.parent.localStreams.forEach(function(e){t.pc.addStream(e)}),this.on("channelOpen",function(e){e.protocol===p&&(e.onmessage=function(n){var r=JSON.parse(n.data),i=new c.Receiver;i.receive(r,e),t.emit("fileTransfer",r,i),i.on("receivedFile",function(e,t){i.channel.close()})})}),this.on("*",function(){t.parent.emit.apply(t.parent,arguments)})}var i=e("util"),o=e("webrtcsupport"),a=e("rtcpeerconnection"),s=e("wildemitter"),c=e("filetransfer"),p="https://simplewebrtc.com/protocol/filetransfer#inband-v1";i.inherits(r,s),r.prototype.handleMessage=function(e){var t=this;if(this.logger.log("getting",e.type,e),e.prefix&&(this.browserPrefix=e.prefix),"offer"===e.type)this.nick||(this.nick=e.payload.nick),delete e.payload.nick,this.pc.handleOffer(e.payload,function(e){e||t.pc.answer(function(e,t){})});else if("answer"===e.type)this.nick||(this.nick=e.payload.nick),delete e.payload.nick,this.pc.handleAnswer(e.payload);else if("candidate"===e.type)this.pc.processIce(e.payload);else if("connectivityError"===e.type)this.parent.emit("connectivityError",t);else if("mute"===e.type)this.parent.emit("mute",{id:e.from,name:e.payload.name});else if("unmute"===e.type)this.parent.emit("unmute",{id:e.from,name:e.payload.name});else if("endOfCandidates"===e.type){var n=this.pc.pc.peerconnection.transceivers||[];n.forEach(function(e){e.iceTransport&&e.iceTransport.addRemoteCandidate({})})}},r.prototype.send=function(e,t){var n={to:this.id,sid:this.sid,broadcaster:this.broadcaster,roomType:this.type,type:e,payload:t,prefix:o.prefix};this.logger.log("sending",e,n),this.parent.emit("message",n)},r.prototype.sendDirectly=function(e,t,n){var r={type:t,payload:n};this.logger.log("sending via datachannel",e,t,r);var i=this.getDataChannel(e);return"open"!=i.readyState?!1:(i.send(JSON.stringify(r)),!0)},r.prototype._observeDataChannel=function(e){var t=this;e.onclose=this.emit.bind(this,"channelClose",e),e.onerror=this.emit.bind(this,"channelError",e),e.onmessage=function(n){t.emit("channelMessage",t,e.label,JSON.parse(n.data),e,n)},e.onopen=this.emit.bind(this,"channelOpen",e)},r.prototype.getDataChannel=function(e,t){if(!o.supportDataChannel)return this.emit("error",new Error("createDataChannel not supported"));var n=this.channels[e];return t||(t={}),n?n:(n=this.channels[e]=this.pc.createDataChannel(e,t),this._observeDataChannel(n),n)},r.prototype.onIceCandidate=function(e){if(!this.closed)if(e){var t=this.parent.config.peerConnectionConfig;"moz"===o.prefix&&t&&t.iceTransports&&e.candidate&&e.candidate.candidate&&e.candidate.candidate.indexOf(t.iceTransports)<0?this.logger.log("Ignoring ice candidate not matching pcConfig iceTransports type: ",t.iceTransports):this.send("candidate",e)}else this.logger.log("End of candidates.")},r.prototype.start=function(){this.enableDataChannels&&this.getDataChannel("simplewebrtc"),this.pc.offer(this.receiveMedia,function(e,t){})},r.prototype.icerestart=function(){var e=this.receiveMedia;e.mandatory.IceRestart=!0,this.pc.offer(e,function(e,t){})},r.prototype.end=function(){this.closed||(this.pc.close(),this.handleStreamRemoved())},r.prototype.handleRemoteStreamAdded=function(e){var t=this;this.stream?this.logger.warn("Already have a remote stream"):(this.stream=e.stream,this.stream.onended=function(){t.end()},this.parent.emit("peerStreamAdded",this))},r.prototype.handleStreamRemoved=function(){this.parent.peers.splice(this.parent.peers.indexOf(this),1),this.closed=!0,this.parent.emit("peerStreamRemoved",this)},r.prototype.handleDataChannelAdded=function(e){this.channels[e.label]=e,this._observeDataChannel(e)},r.prototype.sendFile=function(e){var t=new c.Sender,n=this.getDataChannel("filetransfer"+(new Date).getTime(),{protocol:p});return n.onopen=function(){n.send(JSON.stringify({size:e.size,name:e.name})),t.send(e,n)},n.onclose=function(){console.log("sender received transfer"),t.emit("complete")},t},t.exports=r},{filetransfer:26,rtcpeerconnection:47,util:67,webrtcsupport:77,wildemitter:78}],81:[function(e,t,n){function r(e){var t,n,r=this,d=e||{},u=this.config={url:"https://sandbox.simplewebrtc.com:443/",socketio:{},connection:null,debug:!1,localVideoEl:"",remoteVideosEl:"",enableDataChannels:!0,autoRequestMedia:!1,autoRemoveVideos:!0,adjustPeerVolume:!1,peerVolumeWhenSpeaking:.25,media:{video:!0,audio:!0},receiveMedia:{offerToReceiveAudio:1,offerToReceiveVideo:1},localVideo:{autoplay:!0,mirror:!0,muted:!0}};this.logger=function(){return e.debug?e.logger||console:e.logger||c}();for(t in d)this.config[t]=d[t];this.capabilities=a,o.call(this),n=null===this.config.connection?this.connection=new p(this.config):this.connection=this.config.connection,n.on("connect",function(){r.emit("connectionReady",n.getSessionId()),r.sessionReady=!0,r.testReadiness()}),n.on("message",function(e){var t,n=r.webrtc.getPeers(e.from,e.roomType);"offer"===e.type?(n.length&&n.forEach(function(n){n.sid==e.sid&&(t=n)}),t||(t=r.webrtc.createPeer({id:e.from,sid:e.sid,type:e.roomType,enableDataChannels:r.config.enableDataChannels&&"screen"!==e.roomType,sharemyscreen:"screen"===e.roomType&&!e.broadcaster,broadcaster:"screen"!==e.roomType||e.broadcaster?null:r.connection.getSessionId()}),r.emit("createdPeer",t)),t.handleMessage(e)):n.length&&n.forEach(function(t){e.sid?t.sid===e.sid&&t.handleMessage(e):t.handleMessage(e)})}),n.on("remove",function(e){e.id!==r.connection.getSessionId()&&r.webrtc.removePeers(e.id,e.type)}),e.logger=this.logger,e.debug=!1,this.webrtc=new i(e),["mute","unmute","pauseVideo","resumeVideo","pause","resume","sendToAll","sendDirectlyToAll","getPeers"].forEach(function(e){r[e]=r.webrtc[e].bind(r.webrtc)}),this.webrtc.on("*",function(){r.emit.apply(r,arguments)}),u.debug&&this.on("*",this.logger.log.bind(this.logger,"SimpleWebRTC event:")),this.webrtc.on("localStream",function(){r.testReadiness()}),this.webrtc.on("message",function(e){r.connection.emit("message",e)}),this.webrtc.on("peerStreamAdded",this.handlePeerStreamAdded.bind(this)),this.webrtc.on("peerStreamRemoved",this.handlePeerStreamRemoved.bind(this)),this.config.adjustPeerVolume&&(this.webrtc.on("speaking",this.setVolumeForAll.bind(this,this.config.peerVolumeWhenSpeaking)),this.webrtc.on("stoppedSpeaking",this.setVolumeForAll.bind(this,1))),n.on("stunservers",function(e){r.webrtc.config.peerConnectionConfig.iceServers=e,r.emit("stunservers",e)}),n.on("turnservers",function(e){r.webrtc.config.peerConnectionConfig.iceServers=r.webrtc.config.peerConnectionConfig.iceServers.concat(e),r.emit("turnservers",e)}),this.webrtc.on("iceFailed",function(e){}),this.webrtc.on("connectivityError",function(e){}),this.webrtc.on("audioOn",function(){r.webrtc.sendToAll("unmute",{name:"audio"})}),this.webrtc.on("audioOff",function(){r.webrtc.sendToAll("mute",{name:"audio"})}),this.webrtc.on("videoOn",function(){r.webrtc.sendToAll("unmute",{name:"video"})}),this.webrtc.on("videoOff",function(){r.webrtc.sendToAll("mute",{name:"video"})}),this.webrtc.on("localScreen",function(e){var t=document.createElement("video"),n=r.getRemoteVideoContainer();t.oncontextmenu=function(){return!1},t.id="localScreen",s(e,t),n&&n.appendChild(t),r.emit("localScreenAdded",t),r.connection.emit("shareScreen"),r.webrtc.peers.forEach(function(e){var t;"video"===e.type&&(t=r.webrtc.createPeer({id:e.id,type:"screen",sharemyscreen:!0,enableDataChannels:!1,receiveMedia:{offerToReceiveAudio:0,offerToReceiveVideo:0},broadcaster:r.connection.getSessionId()}),r.emit("createdPeer",t),t.start())})}),this.webrtc.on("localScreenStopped",function(e){r.stopScreenShare()}),this.webrtc.on("channelMessage",function(e,t,n){"volume"==n.type&&r.emit("remoteVolumeChange",e,n.volume)}),this.config.autoRequestMedia&&this.startLocalVideo()}var i=e("./webrtc"),o=e("wildemitter"),a=e("webrtcsupport"),s=e("attachmediastream"),c=e("mockconsole"),p=e("./socketioconnection");r.prototype=Object.create(o.prototype,{constructor:{value:r}}),r.prototype.leaveRoom=function(){if(this.roomName){for(this.connection.emit("leave");this.webrtc.peers.length;)this.webrtc.peers.shift().end();this.getLocalScreen()&&this.stopScreenShare(),this.emit("leftRoom",this.roomName),this.roomName=void 0}},r.prototype.disconnect=function(){this.connection.disconnect(),delete this.connection},r.prototype.handlePeerStreamAdded=function(e){var t=this,n=this.getRemoteVideoContainer(),r=s(e.stream);e.videoEl=r,r.id=this.getDomId(e),n&&n.appendChild(r),this.emit("videoAdded",r,e),window.setTimeout(function(){t.webrtc.isAudioEnabled()||e.send("mute",{name:"audio"}),t.webrtc.isVideoEnabled()||e.send("mute",{name:"video"})},250)},r.prototype.handlePeerStreamRemoved=function(e){var t=this.getRemoteVideoContainer(),n=e.videoEl;this.config.autoRemoveVideos&&t&&n&&t.removeChild(n),n&&this.emit("videoRemoved",n,e)},r.prototype.getDomId=function(e){return[e.id,e.type,e.broadcaster?"broadcasting":"incoming"].join("_")},r.prototype.setVolumeForAll=function(e){this.webrtc.peers.forEach(function(t){t.videoEl&&(t.videoEl.volume=e)})},r.prototype.joinRoom=function(e,t){var n=this;this.roomName=e,this.connection.emit("join",e,function(r,i){if(console.log("join CB",r,i),r)n.emit("error",r);else{var o,a,s,c;for(o in i.clients){a=i.clients[o];for(s in a)a[s]&&(c=n.webrtc.createPeer({id:o,type:s,enableDataChannels:n.config.enableDataChannels&&"screen"!==s,receiveMedia:{offerToReceiveAudio:"screen"!==s&&n.config.receiveMedia.offerToReceiveAudio?1:0,offerToReceiveVideo:n.config.receiveMedia.offerToReceiveVideo}}),n.emit("createdPeer",c),c.start())}}t&&t(r,i),n.emit("joinedRoom",e)})},r.prototype.getEl=function(e){return"string"==typeof e?document.getElementById(e):e},r.prototype.startLocalVideo=function(){var e=this;this.webrtc.startLocalMedia(this.config.media,function(t,n){t?e.emit("localMediaError",t):s(n,e.getLocalVideoContainer(),e.config.localVideo)})},r.prototype.stopLocalVideo=function(){this.webrtc.stopLocalMedia()},r.prototype.getLocalVideoContainer=function(){var e=this.getEl(this.config.localVideoEl);if(e&&"VIDEO"===e.tagName)return e.oncontextmenu=function(){return!1},e;if(e){var t=document.createElement("video");return t.oncontextmenu=function(){return!1},e.appendChild(t),t}},r.prototype.getRemoteVideoContainer=function(){return this.getEl(this.config.remoteVideosEl)},r.prototype.shareScreen=function(e){this.webrtc.startScreenShare(e)},r.prototype.getLocalScreen=function(){return this.webrtc.localScreen},r.prototype.stopScreenShare=function(){this.connection.emit("unshareScreen");var e=document.getElementById("localScreen"),t=this.getRemoteVideoContainer(),n=this.getLocalScreen();this.config.autoRemoveVideos&&t&&e&&t.removeChild(e),e&&this.emit("videoRemoved",e),n&&n.getTracks().forEach(function(e){e.stop()}),this.webrtc.peers.forEach(function(e){e.broadcaster&&e.end()})},r.prototype.testReadiness=function(){var e=this;this.sessionReady&&(this.config.media.video||this.config.media.audio?this.webrtc.localStreams.length>0&&e.emit("readyToCall",e.connection.getSessionId()):e.emit("readyToCall",e.connection.getSessionId()))},r.prototype.createRoom=function(e,t){this.roomName=e,2===arguments.length?this.connection.emit("create",e,t):this.connection.emit("create",e)},r.prototype.sendFile=function(){return a.dataChannel?void 0:this.emit("error",new Error("DataChannelNotSupported"))},t.exports=r},{"./socketioconnection":82,"./webrtc":83,attachmediastream:3,mockconsole:40,webrtcsupport:77,wildemitter:78}],82:[function(e,t,n){function r(e){this.connection=i.connect(e.url,e.socketio)}var i=e("socket.io-client");r.prototype.on=function(e,t){this.connection.on(e,t)},r.prototype.emit=function(){this.connection.emit.apply(this.connection,arguments)},r.prototype.getSessionId=function(){return this.connection.id},r.prototype.disconnect=function(){return this.connection.disconnect()},t.exports=r},{"socket.io-client":54}],83:[function(e,t,n){function r(e){var t,n=this,r=e||{};this.config={debug:!1,peerConnectionConfig:{iceServers:[{urls:"stun:stun.l.google.com:19302"}]},peerConnectionConstraints:{optional:[]},receiveMedia:{offerToReceiveAudio:1,offerToReceiveVideo:1},enableDataChannels:!0};this.screenSharingSupport=o.screenSharing,this.logger=function(){return e.debug?e.logger||console:e.logger||a}();for(t in r)this.config[t]=r[t];o.support||this.logger.error("Your browser doesn't seem to support WebRTC"),this.peers=[],s.call(this,this.config),this.on("speaking",function(){n.hardMuted||n.peers.forEach(function(e){if(e.enableDataChannels){var t=e.getDataChannel("hark");if("open"!=t.readyState)return;t.send(JSON.stringify({type:"speaking"}))}})}),this.on("stoppedSpeaking",function(){n.hardMuted||n.peers.forEach(function(e){if(e.enableDataChannels){var t=e.getDataChannel("hark");if("open"!=t.readyState)return;t.send(JSON.stringify({type:"stoppedSpeaking"}))}})}),this.on("volumeChange",function(e,t){n.hardMuted||n.peers.forEach(function(t){if(t.enableDataChannels){var n=t.getDataChannel("hark");if("open"!=n.readyState)return;n.send(JSON.stringify({type:"volume",volume:e}))}})}),this.config.debug&&this.on("*",function(e,t,r){var i;i=n.config.logger===a?console:n.logger,i.log("event:",e,t,r)})}var i=e("util"),o=e("webrtcsupport"),a=(e("wildemitter"),e("mockconsole")),s=e("localmedia"),c=e("./peer");i.inherits(r,s),r.prototype.createPeer=function(e){var t;return e.parent=this,t=new c(e),this.peers.push(t),t},r.prototype.removePeers=function(e,t){this.getPeers(e,t).forEach(function(e){e.end()})},r.prototype.getPeers=function(e,t){return this.peers.filter(function(n){return!(e&&n.id!==e||t&&n.type!==t)})},r.prototype.sendToAll=function(e,t){this.peers.forEach(function(n){n.send(e,t)})},r.prototype.sendDirectlyToAll=function(e,t,n){this.peers.forEach(function(r){r.enableDataChannels&&r.sendDirectly(e,t,n)})},t.exports=r},{"./peer":80,localmedia:37,mockconsole:40,util:67,webrtcsupport:77,wildemitter:78}]},{},[81])(81)}); \ No newline at end of file diff --git a/simplewebrtc.bundle.js b/simplewebrtc.bundle.js index c0b209a9..73d5c926 100644 --- a/simplewebrtc.bundle.js +++ b/simplewebrtc.bundle.js @@ -13908,7 +13908,7 @@ function SimpleWebRTC(opts) { } connection.on('connect', function () { - self.emit('connectionReady', connection.getSessionid()); + self.emit('connectionReady', connection.getSessionId()); self.sessionReady = true; self.testReadiness(); }); @@ -13931,7 +13931,7 @@ function SimpleWebRTC(opts) { type: message.roomType, enableDataChannels: self.config.enableDataChannels && message.roomType !== 'screen', sharemyscreen: message.roomType === 'screen' && !message.broadcaster, - broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionid() : null + broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionId() : null }); self.emit('createdPeer', peer); } @@ -13950,7 +13950,7 @@ function SimpleWebRTC(opts) { }); connection.on('remove', function (room) { - if (room.id !== self.connection.getSessionid()) { + if (room.id !== self.connection.getSessionId()) { self.webrtc.removePeers(room.id, room.type); } }); @@ -14055,7 +14055,7 @@ function SimpleWebRTC(opts) { offerToReceiveAudio: 0, offerToReceiveVideo: 0 }, - broadcaster: self.connection.getSessionid(), + broadcaster: self.connection.getSessionId(), }); self.emit('createdPeer', peer); peer.start(); @@ -14274,9 +14274,9 @@ SimpleWebRTC.prototype.testReadiness = function () { var self = this; if (this.sessionReady) { if (!this.config.media.video && !this.config.media.audio) { - self.emit('readyToCall', self.connection.getSessionid()); + self.emit('readyToCall', self.connection.getSessionId()); } else if (this.webrtc.localStreams.length > 0) { - self.emit('readyToCall', self.connection.getSessionid()); + self.emit('readyToCall', self.connection.getSessionId()); } } }; @@ -14314,7 +14314,7 @@ SocketIoConnection.prototype.emit = function () { this.connection.emit.apply(this.connection, arguments); }; -SocketIoConnection.prototype.getSessionid = function () { +SocketIoConnection.prototype.getSessionId = function () { return this.connection.id; }; diff --git a/simplewebrtc.js b/simplewebrtc.js index f697f154..4300c3ef 100644 --- a/simplewebrtc.js +++ b/simplewebrtc.js @@ -72,7 +72,7 @@ function SimpleWebRTC(opts) { } connection.on('connect', function () { - self.emit('connectionReady', connection.getSessionid()); + self.emit('connectionReady', connection.getSessionId()); self.sessionReady = true; self.testReadiness(); }); @@ -95,7 +95,7 @@ function SimpleWebRTC(opts) { type: message.roomType, enableDataChannels: self.config.enableDataChannels && message.roomType !== 'screen', sharemyscreen: message.roomType === 'screen' && !message.broadcaster, - broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionid() : null + broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionId() : null }); self.emit('createdPeer', peer); } @@ -114,7 +114,7 @@ function SimpleWebRTC(opts) { }); connection.on('remove', function (room) { - if (room.id !== self.connection.getSessionid()) { + if (room.id !== self.connection.getSessionId()) { self.webrtc.removePeers(room.id, room.type); } }); @@ -219,7 +219,7 @@ function SimpleWebRTC(opts) { offerToReceiveAudio: 0, offerToReceiveVideo: 0 }, - broadcaster: self.connection.getSessionid(), + broadcaster: self.connection.getSessionId(), }); self.emit('createdPeer', peer); peer.start(); @@ -438,9 +438,9 @@ SimpleWebRTC.prototype.testReadiness = function () { var self = this; if (this.sessionReady) { if (!this.config.media.video && !this.config.media.audio) { - self.emit('readyToCall', self.connection.getSessionid()); + self.emit('readyToCall', self.connection.getSessionId()); } else if (this.webrtc.localStreams.length > 0) { - self.emit('readyToCall', self.connection.getSessionid()); + self.emit('readyToCall', self.connection.getSessionId()); } } }; diff --git a/socketioconnection.js b/socketioconnection.js index d1e92aa6..cbb0c4b3 100644 --- a/socketioconnection.js +++ b/socketioconnection.js @@ -12,7 +12,7 @@ SocketIoConnection.prototype.emit = function () { this.connection.emit.apply(this.connection, arguments); }; -SocketIoConnection.prototype.getSessionid = function () { +SocketIoConnection.prototype.getSessionId = function () { return this.connection.id; };