richtier/alexa-browser-client

View on GitHub
alexa_browser_client/static/main.js

Summary

Maintainability
A
0 mins
Test Coverage

function AlexaBrowserClient(props) {

  // WAD (https://github.com/rserota/wad)
  !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Wad=t():e.Wad=t()}(window,function(){return function(e){var t={};function a(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,a),n.l=!0,n.exports}return a.m=e,a.c=t,a.d=function(e,t,i){a.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:i})},a.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=2)}([function(e,t,a){!function(){var t,a,i=function(e,t){e.value=t},n=Object.create(null,{activate:{writable:!0,value:function(e){e?(this.input.disconnect(),this.input.connect(this.activateNode),this.activateCallback&&this.activateCallback(e)):(this.input.disconnect(),this.input.connect(this.output))}},bypass:{get:function(){return this._bypass},set:function(e){this._lastBypassValue!==e&&(this._bypass=e,this.activate(!e),this._lastBypassValue=e)}},connect:{value:function(e){this.output.connect(e)}},disconnect:{value:function(e){this.output.disconnect(e)}},connectInOrder:{value:function(e){for(var t=e.length-1;t--;){if(!e[t].connect)return console.error("AudioNode.connectInOrder: TypeError: Not an AudioNode.",e[t]);e[t+1].input?e[t].connect(e[t+1].input):e[t].connect(e[t+1])}}},getDefaults:{value:function(){var e={};for(var t in this.defaults)e[t]=this.defaults[t].value;return e}},automate:{value:function(e,a,i,n){var s,o=n?~~(n/1e3):t.currentTime,r=i?~~(i/1e3):0,u=this.defaults[e],l=this[e];l?u.automatable?(i?(s="linearRampToValueAtTime",l.cancelScheduledValues(o),l.setValueAtTime(l.value,o)):s="setValueAtTime",l[s](a,r+o)):l=a:console.error("Invalid Property for "+this.name)}}}),s="float",o="boolean",r="int";function u(e){if(!(this instanceof u))return new u(e);var i="undefined"==typeof window?{}:window;if(i.AudioContext||(i.AudioContext=i.webkitAudioContext),e||(console.log("tuna.js: Missing audio context! Creating a new context for you."),e=i.AudioContext&&new i.AudioContext),!e)throw new Error("Tuna cannot initialize because this environment does not support web audio.");!function(e){if(!0===e.__connectified__)return;var t=e.createGain(),a=Object.getPrototypeOf(Object.getPrototypeOf(t)),i=a.connect;a.connect=function(){var e=arguments[0];return arguments[0]=n.isPrototypeOf?n.isPrototypeOf(e)?e.input:e:e.input||e,i.apply(this,arguments),e},e.__connectified__=!0}(e),t=e,a=this}function l(e){return Math.max(0,Math.round(100*Math.pow(2,e/6))/100)}function c(e,t){var a,i,n,s=0,o=0,r=0;return a=e.toExponential().match(/^.\.?(.*)e(.+)$/),s=parseInt(a[2],10)-(a[1]+"").length,a=t.toExponential().match(/^.\.?(.*)e(.+)$/),(n=parseInt(a[2],10)-(a[1]+"").length)>s&&(s=n),i=e%t,s<-100||s>20?(o=Math.round(Math.log(i)/Math.log(10)),(i/(r=Math.pow(10,o))).toFixed(o-s)*r):parseFloat(i.toFixed(-s))}function h(e){return 0===e?1:Math.abs(e)/e}function p(e){return(Math.exp(e)-Math.exp(-e))/(Math.exp(e)+Math.exp(-e))}function f(e,t){return void 0===e?t:e}void 0!==e&&e.exports?e.exports=u:window.define("Tuna",function(){return u}),u.prototype.Bitcrusher=function(e){e||(e=this.getDefaults()),this.bufferSize=e.bufferSize||this.defaults.bufferSize.value,this.input=t.createGain(),this.activateNode=t.createGain(),this.processor=t.createScriptProcessor(this.bufferSize,1,1),this.output=t.createGain(),this.activateNode.connect(this.processor),this.processor.connect(this.output);var a,i,n,s,o,r=0,u=0;this.processor.onaudioprocess=function(e){for(a=e.inputBuffer.getChannelData(0),i=e.outputBuffer.getChannelData(0),n=Math.pow(.5,this.bits),o=a.length,s=0;s<o;s++)(r+=this.normfreq)>=1&&(r-=1,u=n*Math.floor(a[s]/n+.5)),i[s]=u},this.bits=e.bits||this.defaults.bits.value,this.normfreq=f(e.normfreq,this.defaults.normfreq.value),this.bypass=e.bypass||!1},u.prototype.Bitcrusher.prototype=Object.create(n,{name:{value:"Bitcrusher"},defaults:{writable:!0,value:{bits:{value:4,min:1,max:16,automatable:!1,type:r},bufferSize:{value:4096,min:256,max:16384,automatable:!1,type:r},bypass:{value:!1,automatable:!1,type:o},normfreq:{value:.1,min:1e-4,max:1,automatable:!1,type:s}}},bits:{enumerable:!0,get:function(){return this.processor.bits},set:function(e){this.processor.bits=e}},normfreq:{enumerable:!0,get:function(){return this.processor.normfreq},set:function(e){this.processor.normfreq=e}}}),u.prototype.Cabinet=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.activateNode=t.createGain(),this.convolver=this.newConvolver(e.impulsePath||"../impulses/impulse_guitar.wav"),this.makeupNode=t.createGain(),this.output=t.createGain(),this.activateNode.connect(this.convolver.input),this.convolver.output.connect(this.makeupNode),this.makeupNode.connect(this.output),this.makeupGain=f(e.makeupGain,this.defaults.makeupGain),this.bypass=e.bypass||!1},u.prototype.Cabinet.prototype=Object.create(n,{name:{value:"Cabinet"},defaults:{writable:!0,value:{makeupGain:{value:1,min:0,max:20,automatable:!0,type:s},bypass:{value:!1,automatable:!1,type:o}}},makeupGain:{enumerable:!0,get:function(){return this.makeupNode.gain},set:function(e){this.makeupNode.gain.value=e}},newConvolver:{value:function(e){return new a.Convolver({impulse:e,dryLevel:0,wetLevel:1})}}}),u.prototype.Chorus=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.attenuator=this.activateNode=t.createGain(),this.splitter=t.createChannelSplitter(2),this.delayL=t.createDelay(),this.delayR=t.createDelay(),this.feedbackGainNodeLR=t.createGain(),this.feedbackGainNodeRL=t.createGain(),this.merger=t.createChannelMerger(2),this.output=t.createGain(),this.lfoL=new a.LFO({target:this.delayL.delayTime,callback:i}),this.lfoR=new a.LFO({target:this.delayR.delayTime,callback:i}),this.input.connect(this.attenuator),this.attenuator.connect(this.output),this.attenuator.connect(this.splitter),this.splitter.connect(this.delayL,0),this.splitter.connect(this.delayR,1),this.delayL.connect(this.feedbackGainNodeLR),this.delayR.connect(this.feedbackGainNodeRL),this.feedbackGainNodeLR.connect(this.delayR),this.feedbackGainNodeRL.connect(this.delayL),this.delayL.connect(this.merger,0,0),this.delayR.connect(this.merger,0,1),this.merger.connect(this.output),this.feedback=f(e.feedback,this.defaults.feedback.value),this.rate=f(e.rate,this.defaults.rate.value),this.delay=f(e.delay,this.defaults.delay.value),this.depth=f(e.depth,this.defaults.depth.value),this.lfoR.phase=Math.PI/2,this.attenuator.gain.value=.6934,this.lfoL.activate(!0),this.lfoR.activate(!0),this.bypass=e.bypass||!1},u.prototype.Chorus.prototype=Object.create(n,{name:{value:"Chorus"},defaults:{writable:!0,value:{feedback:{value:.4,min:0,max:.95,automatable:!1,type:s},delay:{value:.0045,min:0,max:1,automatable:!1,type:s},depth:{value:.7,min:0,max:1,automatable:!1,type:s},rate:{value:1.5,min:0,max:8,automatable:!1,type:s},bypass:{value:!1,automatable:!1,type:o}}},delay:{enumerable:!0,get:function(){return this._delay},set:function(e){this._delay=2*Math.pow(10,e)*2e-4,this.lfoL.offset=this._delay,this.lfoR.offset=this._delay,this._depth=this._depth}},depth:{enumerable:!0,get:function(){return this._depth},set:function(e){this._depth=e,this.lfoL.oscillation=this._depth*this._delay,this.lfoR.oscillation=this._depth*this._delay}},feedback:{enumerable:!0,get:function(){return this._feedback},set:function(e){this._feedback=e,this.feedbackGainNodeLR.gain.value=this._feedback,this.feedbackGainNodeRL.gain.value=this._feedback}},rate:{enumerable:!0,get:function(){return this._rate},set:function(e){this._rate=e,this.lfoL.frequency=this._rate,this.lfoR.frequency=this._rate}}}),u.prototype.Compressor=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.compNode=this.activateNode=t.createDynamicsCompressor(),this.makeupNode=t.createGain(),this.output=t.createGain(),this.compNode.connect(this.makeupNode),this.makeupNode.connect(this.output),this.automakeup=f(e.automakeup,this.defaults.automakeup.value),this.makeupGain=f(e.makeupGain,this.defaults.makeupGain.value),this.threshold=f(e.threshold,this.defaults.threshold.value),this.release=f(e.release,this.defaults.release.value),this.attack=f(e.attack,this.defaults.attack.value),this.ratio=e.ratio||this.defaults.ratio.value,this.knee=f(e.knee,this.defaults.knee.value),this.bypass=e.bypass||!1},u.prototype.Compressor.prototype=Object.create(n,{name:{value:"Compressor"},defaults:{writable:!0,value:{threshold:{value:-20,min:-60,max:0,automatable:!0,type:s},release:{value:250,min:10,max:2e3,automatable:!0,type:s},makeupGain:{value:1,min:1,max:100,automatable:!0,type:s},attack:{value:1,min:0,max:1e3,automatable:!0,type:s},ratio:{value:4,min:1,max:50,automatable:!0,type:s},knee:{value:5,min:0,max:40,automatable:!0,type:s},automakeup:{value:!1,automatable:!1,type:o},bypass:{value:!1,automatable:!1,type:o}}},computeMakeup:{value:function(){var e=this.compNode;return-(e.threshold.value-e.threshold.value/e.ratio.value)/4}},automakeup:{enumerable:!0,get:function(){return this._automakeup},set:function(e){this._automakeup=e,this._automakeup&&(this.makeupGain=this.computeMakeup())}},threshold:{enumerable:!0,get:function(){return this.compNode.threshold},set:function(e){this.compNode.threshold.value=e,this._automakeup&&(this.makeupGain=this.computeMakeup())}},ratio:{enumerable:!0,get:function(){return this.compNode.ratio},set:function(e){this.compNode.ratio.value=e,this._automakeup&&(this.makeupGain=this.computeMakeup())}},knee:{enumerable:!0,get:function(){return this.compNode.knee},set:function(e){this.compNode.knee.value=e,this._automakeup&&(this.makeupGain=this.computeMakeup())}},attack:{enumerable:!0,get:function(){return this.compNode.attack},set:function(e){this.compNode.attack.value=e/1e3}},release:{enumerable:!0,get:function(){return this.compNode.release},set:function(e){this.compNode.release.value=e/1e3}},makeupGain:{enumerable:!0,get:function(){return this.makeupNode.gain},set:function(e){this.makeupNode.gain.value=l(e)}}}),u.prototype.Convolver=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.activateNode=t.createGain(),this.convolver=t.createConvolver(),this.dry=t.createGain(),this.filterLow=t.createBiquadFilter(),this.filterHigh=t.createBiquadFilter(),this.wet=t.createGain(),this.output=t.createGain(),this.activateNode.connect(this.filterLow),this.activateNode.connect(this.dry),this.filterLow.connect(this.filterHigh),this.filterHigh.connect(this.convolver),this.convolver.connect(this.wet),this.wet.connect(this.output),this.dry.connect(this.output),this.dryLevel=f(e.dryLevel,this.defaults.dryLevel.value),this.wetLevel=f(e.wetLevel,this.defaults.wetLevel.value),this.highCut=e.highCut||this.defaults.highCut.value,this.buffer=e.impulse||"../impulses/ir_rev_short.wav",this.lowCut=e.lowCut||this.defaults.lowCut.value,this.level=f(e.level,this.defaults.level.value),this.filterHigh.type="lowpass",this.filterLow.type="highpass",this.bypass=e.bypass||!1},u.prototype.Convolver.prototype=Object.create(n,{name:{value:"Convolver"},defaults:{writable:!0,value:{highCut:{value:22050,min:20,max:22050,automatable:!0,type:s},lowCut:{value:20,min:20,max:22050,automatable:!0,type:s},dryLevel:{value:1,min:0,max:1,automatable:!0,type:s},wetLevel:{value:1,min:0,max:1,automatable:!0,type:s},level:{value:1,min:0,max:1,automatable:!0,type:s}}},lowCut:{get:function(){return this.filterLow.frequency},set:function(e){this.filterLow.frequency.value=e}},highCut:{get:function(){return this.filterHigh.frequency},set:function(e){this.filterHigh.frequency.value=e}},level:{get:function(){return this.output.gain},set:function(e){this.output.gain.value=e}},dryLevel:{get:function(){return this.dry.gain},set:function(e){this.dry.gain.value=e}},wetLevel:{get:function(){return this.wet.gain},set:function(e){this.wet.gain.value=e}},buffer:{enumerable:!1,get:function(){return this.convolver.buffer},set:function(e){var a=this.convolver,i=new XMLHttpRequest;e?(i.open("GET",e,!0),i.responseType="arraybuffer",i.onreadystatechange=function(){4===i.readyState&&(i.status<300&&i.status>199||302===i.status)&&t.decodeAudioData(i.response,function(e){a.buffer=e},function(e){e&&console.log("Tuna.Convolver.setBuffer: Error decoding data"+e)})},i.send(null)):console.log("Tuna.Convolver.setBuffer: Missing impulse path!")}}}),u.prototype.Delay=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.activateNode=t.createGain(),this.dry=t.createGain(),this.wet=t.createGain(),this.filter=t.createBiquadFilter(),this.delay=t.createDelay(10),this.feedbackNode=t.createGain(),this.output=t.createGain(),this.activateNode.connect(this.delay),this.activateNode.connect(this.dry),this.delay.connect(this.filter),this.filter.connect(this.feedbackNode),this.feedbackNode.connect(this.delay),this.feedbackNode.connect(this.wet),this.wet.connect(this.output),this.dry.connect(this.output),this.delayTime=e.delayTime||this.defaults.delayTime.value,this.feedback=f(e.feedback,this.defaults.feedback.value),this.wetLevel=f(e.wetLevel,this.defaults.wetLevel.value),this.dryLevel=f(e.dryLevel,this.defaults.dryLevel.value),this.cutoff=e.cutoff||this.defaults.cutoff.value,this.filter.type="lowpass",this.bypass=e.bypass||!1},u.prototype.Delay.prototype=Object.create(n,{name:{value:"Delay"},defaults:{writable:!0,value:{delayTime:{value:100,min:20,max:1e3,automatable:!1,type:s},feedback:{value:.45,min:0,max:.9,automatable:!0,type:s},cutoff:{value:2e4,min:20,max:2e4,automatable:!0,type:s},wetLevel:{value:.5,min:0,max:1,automatable:!0,type:s},dryLevel:{value:1,min:0,max:1,automatable:!0,type:s}}},delayTime:{enumerable:!0,get:function(){return this.delay.delayTime},set:function(e){this.delay.delayTime.value=e/1e3}},wetLevel:{enumerable:!0,get:function(){return this.wet.gain},set:function(e){this.wet.gain.value=e}},dryLevel:{enumerable:!0,get:function(){return this.dry.gain},set:function(e){this.dry.gain.value=e}},feedback:{enumerable:!0,get:function(){return this.feedbackNode.gain},set:function(e){this.feedbackNode.gain.value=e}},cutoff:{enumerable:!0,get:function(){return this.filter.frequency},set:function(e){this.filter.frequency.value=e}}}),u.prototype.Filter=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.activateNode=t.createGain(),this.filter=t.createBiquadFilter(),this.output=t.createGain(),this.activateNode.connect(this.filter),this.filter.connect(this.output),this.frequency=e.frequency||this.defaults.frequency.value,this.Q=e.resonance||this.defaults.Q.value,this.filterType=f(e.filterType,this.defaults.filterType.value),this.gain=f(e.gain,this.defaults.gain.value),this.bypass=e.bypass||!1},u.prototype.Filter.prototype=Object.create(n,{name:{value:"Filter"},defaults:{writable:!0,value:{frequency:{value:800,min:20,max:22050,automatable:!0,type:s},Q:{value:1,min:.001,max:100,automatable:!0,type:s},gain:{value:0,min:-40,max:40,automatable:!0,type:s},bypass:{value:!1,automatable:!1,type:o},filterType:{value:"lowpass",automatable:!1,type:"string"}}},filterType:{enumerable:!0,get:function(){return this.filter.type},set:function(e){this.filter.type=e}},Q:{enumerable:!0,get:function(){return this.filter.Q},set:function(e){this.filter.Q.value=e}},gain:{enumerable:!0,get:function(){return this.filter.gain},set:function(e){this.filter.gain.value=e}},frequency:{enumerable:!0,get:function(){return this.filter.frequency},set:function(e){this.filter.frequency.value=e}}}),u.prototype.Gain=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.activateNode=t.createGain(),this.gainNode=t.createGain(),this.output=t.createGain(),this.activateNode.connect(this.gainNode),this.gainNode.connect(this.output),this.gain=f(e.gain,this.defaults.gain.value),this.bypass=e.bypass||!1},u.prototype.Gain.prototype=Object.create(n,{name:{value:"Gain"},defaults:{writable:!0,value:{bypass:{value:!1,automatable:!1,type:o},gain:{value:1,automatable:!0,type:s}}},gain:{enumerable:!0,get:function(){return this.gainNode.gain},set:function(e){this.gainNode.gain.value=e}}}),u.prototype.MoogFilter=function(e){var a,i,n,s,o,r,u,l,c,h,p,d,v,m,y;e||(e=this.getDefaults()),this.bufferSize=e.bufferSize||this.defaults.bufferSize.value,this.input=t.createGain(),this.activateNode=t.createGain(),this.processor=t.createScriptProcessor(this.bufferSize,1,1),this.output=t.createGain(),this.activateNode.connect(this.processor),this.processor.connect(this.output),a=i=n=s=o=r=u=l=0,this.processor.onaudioprocess=function(e){for(c=e.inputBuffer.getChannelData(0),h=e.outputBuffer.getChannelData(0),p=1.16*this.cutoff,y=p*p*.35013*(p*p),d=this.resonance*(1-.15*p*p),m=c.length,v=0;v<m;v++)c[v]-=l*d,c[v]*=y,o=c[v]+.3*a+(1-p)*o,a=c[v],r=o+.3*i+(1-p)*r,i=o,u=r+.3*n+(1-p)*u,n=r,l=u+.3*s+(1-p)*l,s=u,h[v]=l},this.cutoff=f(e.cutoff,this.defaults.cutoff.value),this.resonance=f(e.resonance,this.defaults.resonance.value),this.bypass=e.bypass||!1},u.prototype.MoogFilter.prototype=Object.create(n,{name:{value:"MoogFilter"},defaults:{writable:!0,value:{bufferSize:{value:4096,min:256,max:16384,automatable:!1,type:r},bypass:{value:!1,automatable:!1,type:o},cutoff:{value:.065,min:1e-4,max:1,automatable:!1,type:s},resonance:{value:3.5,min:0,max:4,automatable:!1,type:s}}},cutoff:{enumerable:!0,get:function(){return this.processor.cutoff},set:function(e){this.processor.cutoff=e}},resonance:{enumerable:!0,get:function(){return this.processor.resonance},set:function(e){this.processor.resonance=e}}}),u.prototype.Overdrive=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.activateNode=t.createGain(),this.inputDrive=t.createGain(),this.waveshaper=t.createWaveShaper(),this.outputDrive=t.createGain(),this.output=t.createGain(),this.activateNode.connect(this.inputDrive),this.inputDrive.connect(this.waveshaper),this.waveshaper.connect(this.outputDrive),this.outputDrive.connect(this.output),this.ws_table=new Float32Array(this.k_nSamples),this.drive=f(e.drive,this.defaults.drive.value),this.outputGain=f(e.outputGain,this.defaults.outputGain.value),this.curveAmount=f(e.curveAmount,this.defaults.curveAmount.value),this.algorithmIndex=f(e.algorithmIndex,this.defaults.algorithmIndex.value),this.bypass=e.bypass||!1},u.prototype.Overdrive.prototype=Object.create(n,{name:{value:"Overdrive"},defaults:{writable:!0,value:{drive:{value:1,min:0,max:1,automatable:!0,type:s,scaled:!0},outputGain:{value:1,min:0,max:1,automatable:!0,type:s,scaled:!0},curveAmount:{value:.725,min:0,max:1,automatable:!1,type:s},algorithmIndex:{value:0,min:0,max:5,automatable:!1,type:r}}},k_nSamples:{value:8192},drive:{get:function(){return this.inputDrive.gain},set:function(e){this._drive=e}},curveAmount:{get:function(){return this._curveAmount},set:function(e){this._curveAmount=e,void 0===this._algorithmIndex&&(this._algorithmIndex=0),this.waveshaperAlgorithms[this._algorithmIndex](this._curveAmount,this.k_nSamples,this.ws_table),this.waveshaper.curve=this.ws_table}},outputGain:{get:function(){return this.outputDrive.gain},set:function(e){this._outputGain=l(e)}},algorithmIndex:{get:function(){return this._algorithmIndex},set:function(e){this._algorithmIndex=e,this.curveAmount=this._curveAmount}},waveshaperAlgorithms:{value:[function(e,t,a){var i,n,s=2*(e=Math.min(e,.9999))/(1-e);for(i=0;i<t;i++)n=2*i/t-1,a[i]=(1+s)*n/(1+s*Math.abs(n))},function(e,t,a){var i,n,s;for(i=0;i<t;i++)n=2*i/t-1,s=(.5*Math.pow(n+1.4,2)-1)*s>=0?5.8:1.2,a[i]=p(s)},function(e,t,a){var i,n,s,o=1-e;for(i=0;i<t;i++)s=(n=2*i/t-1)<0?-Math.pow(Math.abs(n),o+.04):Math.pow(n,o),a[i]=p(2*s)},function(e,t,a){var i,n,s,o,r=1-e>.99?.99:1-e;for(i=0;i<t;i++)n=2*i/t-1,(o=Math.abs(n))<r?s=o:o>r?s=r+(o-r)/(1+Math.pow((o-r)/(1-r),2)):o>1&&(s=o),a[i]=h(n)*s*(1/((r+1)/2))},function(e,t,a){var i,n;for(i=0;i<t;i++)n=2*i/t-1,a[i]=n<-.08905?-.75*(1-Math.pow(1-(Math.abs(n)-.032857),12)+1/3*(Math.abs(n)-.032847))+.01:n>=-.08905&&n<.320018?n*n*-6.153+3.9375*n:.630035},function(e,t,a){var i,n,s=2+Math.round(14*e),o=Math.round(Math.pow(2,s-1));for(i=0;i<t;i++)n=2*i/t-1,a[i]=Math.round(n*o)/o}]}}),u.prototype.Panner=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.activateNode=t.createGain(),this.panner=t.createStereoPanner(),this.output=t.createGain(),this.activateNode.connect(this.panner),this.panner.connect(this.output),this.pan=f(e.pan,this.defaults.pan.value),this.bypass=e.bypass||!1},u.prototype.Panner.prototype=Object.create(n,{name:{value:"Panner"},defaults:{writable:!0,value:{bypass:{value:!1,automatable:!1,type:o},pan:{value:0,min:-1,max:1,automatable:!0,type:s}}},pan:{enumerable:!0,get:function(){return this.panner.pan},set:function(e){this.panner.pan.value=e}}}),u.prototype.Phaser=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.splitter=this.activateNode=t.createChannelSplitter(2),this.filtersL=[],this.filtersR=[],this.feedbackGainNodeL=t.createGain(),this.feedbackGainNodeR=t.createGain(),this.merger=t.createChannelMerger(2),this.filteredSignal=t.createGain(),this.output=t.createGain(),this.lfoL=new a.LFO({target:this.filtersL,callback:this.callback}),this.lfoR=new a.LFO({target:this.filtersR,callback:this.callback});for(var i=this.stage;i--;)this.filtersL[i]=t.createBiquadFilter(),this.filtersR[i]=t.createBiquadFilter(),this.filtersL[i].type="allpass",this.filtersR[i].type="allpass";this.input.connect(this.splitter),this.input.connect(this.output),this.splitter.connect(this.filtersL[0],0,0),this.splitter.connect(this.filtersR[0],1,0),this.connectInOrder(this.filtersL),this.connectInOrder(this.filtersR),this.filtersL[this.stage-1].connect(this.feedbackGainNodeL),this.filtersL[this.stage-1].connect(this.merger,0,0),this.filtersR[this.stage-1].connect(this.feedbackGainNodeR),this.filtersR[this.stage-1].connect(this.merger,0,1),this.feedbackGainNodeL.connect(this.filtersL[0]),this.feedbackGainNodeR.connect(this.filtersR[0]),this.merger.connect(this.output),this.rate=f(e.rate,this.defaults.rate.value),this.baseModulationFrequency=e.baseModulationFrequency||this.defaults.baseModulationFrequency.value,this.depth=f(e.depth,this.defaults.depth.value),this.feedback=f(e.feedback,this.defaults.feedback.value),this.stereoPhase=f(e.stereoPhase,this.defaults.stereoPhase.value),this.lfoL.activate(!0),this.lfoR.activate(!0),this.bypass=e.bypass||!1},u.prototype.Phaser.prototype=Object.create(n,{name:{value:"Phaser"},stage:{value:4},defaults:{writable:!0,value:{rate:{value:.1,min:0,max:8,automatable:!1,type:s},depth:{value:.6,min:0,max:1,automatable:!1,type:s},feedback:{value:.7,min:0,max:1,automatable:!1,type:s},stereoPhase:{value:40,min:0,max:180,automatable:!1,type:s},baseModulationFrequency:{value:700,min:500,max:1500,automatable:!1,type:s}}},callback:{value:function(e,t){for(var a=0;a<4;a++)e[a].frequency.value=t}},depth:{get:function(){return this._depth},set:function(e){this._depth=e,this.lfoL.oscillation=this._baseModulationFrequency*this._depth,this.lfoR.oscillation=this._baseModulationFrequency*this._depth}},rate:{get:function(){return this._rate},set:function(e){this._rate=e,this.lfoL.frequency=this._rate,this.lfoR.frequency=this._rate}},baseModulationFrequency:{enumerable:!0,get:function(){return this._baseModulationFrequency},set:function(e){this._baseModulationFrequency=e,this.lfoL.offset=this._baseModulationFrequency,this.lfoR.offset=this._baseModulationFrequency,this._depth=this._depth}},feedback:{get:function(){return this._feedback},set:function(e){this._feedback=e,this.feedbackGainNodeL.gain.value=this._feedback,this.feedbackGainNodeR.gain.value=this._feedback}},stereoPhase:{get:function(){return this._stereoPhase},set:function(e){this._stereoPhase=e;var t=this.lfoL._phase+this._stereoPhase*Math.PI/180;t=c(t,2*Math.PI),this.lfoR._phase=t}}}),u.prototype.PingPongDelay=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.wetLevel=t.createGain(),this.stereoToMonoMix=t.createGain(),this.feedbackLevel=t.createGain(),this.output=t.createGain(),this.delayLeft=t.createDelay(10),this.delayRight=t.createDelay(10),this.activateNode=t.createGain(),this.splitter=t.createChannelSplitter(2),this.merger=t.createChannelMerger(2),this.activateNode.connect(this.splitter),this.splitter.connect(this.stereoToMonoMix,0,0),this.splitter.connect(this.stereoToMonoMix,1,0),this.stereoToMonoMix.gain.value=.5,this.stereoToMonoMix.connect(this.wetLevel),this.wetLevel.connect(this.delayLeft),this.feedbackLevel.connect(this.delayLeft),this.delayLeft.connect(this.delayRight),this.delayRight.connect(this.feedbackLevel),this.delayLeft.connect(this.merger,0,0),this.delayRight.connect(this.merger,0,1),this.merger.connect(this.output),this.activateNode.connect(this.output),this.delayTimeLeft=void 0!==e.delayTimeLeft?e.delayTimeLeft:this.defaults.delayTimeLeft.value,this.delayTimeRight=void 0!==e.delayTimeRight?e.delayTimeRight:this.defaults.delayTimeRight.value,this.feedbackLevel.gain.value=void 0!==e.feedback?e.feedback:this.defaults.feedback.value,this.wetLevel.gain.value=void 0!==e.wetLevel?e.wetLevel:this.defaults.wetLevel.value,this.bypass=e.bypass||!1},u.prototype.PingPongDelay.prototype=Object.create(n,{name:{value:"PingPongDelay"},delayTimeLeft:{enumerable:!0,get:function(){return this._delayTimeLeft},set:function(e){this._delayTimeLeft=e,this.delayLeft.delayTime.value=e/1e3}},delayTimeRight:{enumerable:!0,get:function(){return this._delayTimeRight},set:function(e){this._delayTimeRight=e,this.delayRight.delayTime.value=e/1e3}},defaults:{writable:!0,value:{delayTimeLeft:{value:200,min:1,max:1e4,automatable:!1,type:r},delayTimeRight:{value:400,min:1,max:1e4,automatable:!1,type:r},feedback:{value:.3,min:0,max:1,automatable:!1,type:s},wetLevel:{value:.5,min:0,max:1,automatable:!1,type:s}}}}),u.prototype.Tremolo=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.splitter=this.activateNode=t.createChannelSplitter(2),this.amplitudeL=t.createGain(),this.amplitudeR=t.createGain(),this.merger=t.createChannelMerger(2),this.output=t.createGain(),this.lfoL=new a.LFO({target:this.amplitudeL.gain,callback:i}),this.lfoR=new a.LFO({target:this.amplitudeR.gain,callback:i}),this.input.connect(this.splitter),this.splitter.connect(this.amplitudeL,0),this.splitter.connect(this.amplitudeR,1),this.amplitudeL.connect(this.merger,0,0),this.amplitudeR.connect(this.merger,0,1),this.merger.connect(this.output),this.rate=e.rate||this.defaults.rate.value,this.intensity=f(e.intensity,this.defaults.intensity.value),this.stereoPhase=f(e.stereoPhase,this.defaults.stereoPhase.value),this.lfoL.offset=1-this.intensity/2,this.lfoR.offset=1-this.intensity/2,this.lfoL.phase=this.stereoPhase*Math.PI/180,this.lfoL.activate(!0),this.lfoR.activate(!0),this.bypass=e.bypass||!1},u.prototype.Tremolo.prototype=Object.create(n,{name:{value:"Tremolo"},defaults:{writable:!0,value:{intensity:{value:.3,min:0,max:1,automatable:!1,type:s},stereoPhase:{value:0,min:0,max:180,automatable:!1,type:s},rate:{value:5,min:.1,max:11,automatable:!1,type:s}}},intensity:{enumerable:!0,get:function(){return this._intensity},set:function(e){this._intensity=e,this.lfoL.offset=1-this._intensity/2,this.lfoR.offset=1-this._intensity/2,this.lfoL.oscillation=this._intensity,this.lfoR.oscillation=this._intensity}},rate:{enumerable:!0,get:function(){return this._rate},set:function(e){this._rate=e,this.lfoL.frequency=this._rate,this.lfoR.frequency=this._rate}},stereoPhase:{enumerable:!0,get:function(){return this._stereoPhase},set:function(e){this._stereoPhase=e;var t=this.lfoL._phase+this._stereoPhase*Math.PI/180;t=c(t,2*Math.PI),this.lfoR.phase=t}}}),u.prototype.WahWah=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.activateNode=t.createGain(),this.envelopeFollower=new a.EnvelopeFollower({target:this,callback:function(e,t){e.sweep=t}}),this.filterBp=t.createBiquadFilter(),this.filterPeaking=t.createBiquadFilter(),this.output=t.createGain(),this.activateNode.connect(this.filterBp),this.filterBp.connect(this.filterPeaking),this.filterPeaking.connect(this.output),this.init(),this.automode=f(e.automode,this.defaults.automode.value),this.resonance=e.resonance||this.defaults.resonance.value,this.sensitivity=f(e.sensitivity,this.defaults.sensitivity.value),this.baseFrequency=f(e.baseFrequency,this.defaults.baseFrequency.value),this.excursionOctaves=e.excursionOctaves||this.defaults.excursionOctaves.value,this.sweep=f(e.sweep,this.defaults.sweep.value),this.activateNode.gain.value=2,this.envelopeFollower.activate(!0),this.bypass=e.bypass||!1},u.prototype.WahWah.prototype=Object.create(n,{name:{value:"WahWah"},defaults:{writable:!0,value:{automode:{value:!0,automatable:!1,type:o},baseFrequency:{value:.5,min:0,max:1,automatable:!1,type:s},excursionOctaves:{value:2,min:1,max:6,automatable:!1,type:s},sweep:{value:.2,min:0,max:1,automatable:!1,type:s},resonance:{value:10,min:1,max:100,automatable:!1,type:s},sensitivity:{value:.5,min:-1,max:1,automatable:!1,type:s}}},automode:{get:function(){return this._automode},set:function(e){this._automode=e,e?(this.activateNode.connect(this.envelopeFollower.input),this.envelopeFollower.activate(!0)):(this.envelopeFollower.activate(!1),this.activateNode.disconnect(),this.activateNode.connect(this.filterBp))}},filterFreqTimeout:{value:0},setFilterFreq:{value:function(){try{this.filterBp.frequency.value=Math.min(22050,this._baseFrequency+this._excursionFrequency*this._sweep),this.filterPeaking.frequency.value=Math.min(22050,this._baseFrequency+this._excursionFrequency*this._sweep)}catch(e){clearTimeout(this.filterFreqTimeout),this.filterFreqTimeout=setTimeout(function(){this.setFilterFreq()}.bind(this),0)}}},sweep:{enumerable:!0,get:function(){return this._sweep},set:function(e){this._sweep=Math.pow(e>1?1:e<0?0:e,this._sensitivity),this.setFilterFreq()}},baseFrequency:{enumerable:!0,get:function(){return this._baseFrequency},set:function(e){this._baseFrequency=50*Math.pow(10,2*e),this._excursionFrequency=Math.min(t.sampleRate/2,this.baseFrequency*Math.pow(2,this._excursionOctaves)),this.setFilterFreq()}},excursionOctaves:{enumerable:!0,get:function(){return this._excursionOctaves},set:function(e){this._excursionOctaves=e,this._excursionFrequency=Math.min(t.sampleRate/2,this.baseFrequency*Math.pow(2,this._excursionOctaves)),this.setFilterFreq()}},sensitivity:{enumerable:!0,get:function(){return this._sensitivity},set:function(e){this._sensitivity=Math.pow(10,e)}},resonance:{enumerable:!0,get:function(){return this._resonance},set:function(e){this._resonance=e,this.filterPeaking.Q=this._resonance}},init:{value:function(){this.output.gain.value=1,this.filterPeaking.type="peaking",this.filterBp.type="bandpass",this.filterPeaking.frequency.value=100,this.filterPeaking.gain.value=20,this.filterPeaking.Q.value=5,this.filterBp.frequency.value=100,this.filterBp.Q.value=1}}}),u.prototype.EnvelopeFollower=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.jsNode=this.output=t.createScriptProcessor(this.buffersize,1,1),this.input.connect(this.output),this.attackTime=f(e.attackTime,this.defaults.attackTime.value),this.releaseTime=f(e.releaseTime,this.defaults.releaseTime.value),this._envelope=0,this.target=e.target||{},this.callback=e.callback||function(){},this.bypass=e.bypass||!1},u.prototype.EnvelopeFollower.prototype=Object.create(n,{name:{value:"EnvelopeFollower"},defaults:{value:{attackTime:{value:.003,min:0,max:.5,automatable:!1,type:s},releaseTime:{value:.5,min:0,max:.5,automatable:!1,type:s}}},buffersize:{value:256},envelope:{value:0},sampleRate:{value:44100},attackTime:{enumerable:!0,get:function(){return this._attackTime},set:function(e){this._attackTime=e,this._attackC=Math.exp(-1/this._attackTime*this.sampleRate/this.buffersize)}},releaseTime:{enumerable:!0,get:function(){return this._releaseTime},set:function(e){this._releaseTime=e,this._releaseC=Math.exp(-1/this._releaseTime*this.sampleRate/this.buffersize)}},callback:{get:function(){return this._callback},set:function(e){"function"==typeof e?this._callback=e:console.error("tuna.js: "+this.name+": Callback must be a function!")}},target:{get:function(){return this._target},set:function(e){this._target=e}},activate:{value:function(e){this.activated=e,e?(this.jsNode.connect(t.destination),this.jsNode.onaudioprocess=this.returnCompute(this)):(this.jsNode.disconnect(),this.jsNode.onaudioprocess=null),this.activateCallback&&this.activateCallback(e)}},returnCompute:{value:function(e){return function(t){e.compute(t)}}},compute:{value:function(e){var t,a,i,n,s=e.inputBuffer.getChannelData(0).length,o=e.inputBuffer.numberOfChannels;if(a=i=n=0,o>1)for(n=0;n<s;++n)for(;a<o;++a)i+=(t=e.inputBuffer.getChannelData(a)[n])*t/o;else for(n=0;n<s;++n)i+=(t=e.inputBuffer.getChannelData(0)[n])*t;i=Math.sqrt(i),this._envelope<i?(this._envelope*=this._attackC,this._envelope+=(1-this._attackC)*i):(this._envelope*=this._releaseC,this._envelope+=(1-this._releaseC)*i),this._callback(this._target,this._envelope)}}}),u.prototype.LFO=function(e){e||(e=this.getDefaults()),this.input=t.createGain(),this.output=t.createScriptProcessor(256,1,1),this.activateNode=t.destination,this.frequency=f(e.frequency,this.defaults.frequency.value),this.offset=f(e.offset,this.defaults.offset.value),this.oscillation=f(e.oscillation,this.defaults.oscillation.value),this.phase=f(e.phase,this.defaults.phase.value),this.target=e.target||{},this.output.onaudioprocess=this.callback(e.callback||function(){}),this.bypass=e.bypass||!1},u.prototype.LFO.prototype=Object.create(n,{name:{value:"LFO"},bufferSize:{value:256},sampleRate:{value:44100},defaults:{value:{frequency:{value:1,min:0,max:20,automatable:!1,type:s},offset:{value:.85,min:0,max:22049,automatable:!1,type:s},oscillation:{value:.3,min:-22050,max:22050,automatable:!1,type:s},phase:{value:0,min:0,max:2*Math.PI,automatable:!1,type:s}}},frequency:{get:function(){return this._frequency},set:function(e){this._frequency=e,this._phaseInc=2*Math.PI*this._frequency*this.bufferSize/this.sampleRate}},offset:{get:function(){return this._offset},set:function(e){this._offset=e}},oscillation:{get:function(){return this._oscillation},set:function(e){this._oscillation=e}},phase:{get:function(){return this._phase},set:function(e){this._phase=e}},target:{get:function(){return this._target},set:function(e){this._target=e}},activate:{value:function(e){e?(this.output.connect(t.destination),this.activateCallback&&this.activateCallback(e)):this.output.disconnect()}},callback:{value:function(e){var t=this;return function(){t._phase+=t._phaseInc,t._phase>2*Math.PI&&(t._phase=0),e(t._target,t._offset+t._oscillation*Math.sin(t._phase))}}}}),u.toString=u.prototype.toString=function(){return"Please visit https://github.com/Theodeus/tuna/wiki for instructions on how to use Tuna.js"}}()},function(e,t){e.exports=function(e){if(!e.webpackPolyfill){var t=Object.create(e);t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),Object.defineProperty(t,"exports",{enumerable:!0}),t.webpackPolyfill=1}return t}},function(e,t,a){"use strict";a.r(t),function(e){var i,n=a(0),s=a.n(n),o=window.AudioContext||window.webkitAudioContext,r=document.querySelector("a-scene");r&&r.audioListener&&r.audioListener.context?(i=r.audioListener.context,console.log("An A-Frame scene has been detected.")):i=new o;var u=function(){"suspended"===i.state?i.resume():"running"===i.state&&(console.log("The audio context is running.",i),window.removeEventListener("mousemove",u),window.removeEventListener("touchstart",u),window.removeEventListener("touchend",u))};window.addEventListener("mousemove",u),window.addEventListener("touchstart",u),window.addEventListener("touchend",u);var l=function(e){if(e.navigator.mediaDevices&&e.navigator.mediaDevices.getUserMedia)return e.navigator.mediaDevices.getUserMedia.bind(e.navigator.mediaDevices);var t=e.navigator.getUserMedia||e.navigator.webkitGetUserMedia||e.navigator.mozGetUserMedia;return t?function(a){return new Promise(function(i,n){t.call(e.navigator,a,i,n)})}:function(){throw"getUserMedia is unsupported"}}(window);l?console.log("Your browser supports getUserMedia."):console.log("Your browser does not support getUserMedia.");var c=function(){var e=function(){Math.seed=6,Math.seededRandom=function(e,t){return e=e||1,t=t||0,Math.seed=(9301*Math.seed+49297)%233280,t+Math.seed/233280*(e-t)};for(var e=2*i.sampleRate,t=i.createBuffer(1,e,i.sampleRate),a=t.getChannelData(0),n=0;n<e;n++)a[n]=2*Math.seededRandom()-1;return t}(),t=function(e){return"[object Array]"===Object.prototype.toString.call(e)},a=function(e,a){a.filter?t(a.filter)?e.filter=a.filter.map(function(e){return{type:e.type||"lowpass",frequency:e.frequency||600,q:e.q||1,env:e.env||null}}):e.filter=[{type:a.filter.type||"lowpass",frequency:a.filter.frequency||600,q:a.filter.q||1,env:a.filter.env||null}]:a.filter=null},n=function(e,t){t.vibrato?e.vibrato={shape:k(t.vibrato.shape,"sine"),speed:k(t.vibrato.speed,1),magnitude:k(t.vibrato.magnitude,5),attack:k(t.vibrato.attack,0)}:e.vibrato=null},o=function(e,t){t.tremolo?e.tremolo={shape:k(t.tremolo.shape,"sine"),speed:k(t.tremolo.speed,1),magnitude:k(t.tremolo.magnitude,5),attack:k(t.tremolo.attack,1)}:e.tremolo=null},r=function(e,t){if(t.reverb){e.reverb={wet:k(t.reverb.wet,1)};var a=t.reverb.impulse||f.defaultImpulse,n=new XMLHttpRequest;n.open("GET",a,!0),n.responseType="arraybuffer",e.playable--,n.onload=function(){i.decodeAudioData(n.response,function(a){e.reverb.buffer=a,e.playable++,e.playOnLoad&&e.play(e.playOnLoadArg),e instanceof f.Poly&&e.setUp(t),"mic"===e.source&&e.reverb&&e.reverb.buffer&&e.reverb.node&&!e.reverb.node.buffer&&(e.reverb.node.convolver.buffer=e.reverb.buffer)})},n.send()}else e.reverb=null},u=function(e,t){"panning"in t?(e.panning={location:t.panning},"number"==typeof t.panning?e.panning.type="stereo":(e.panning.type="3d",e.panning.panningModel=t.panningModel||"equalpower")):e.panning={location:0,type:"stereo"},"stereo"!==e.panning.type||i.createStereoPanner||(console.log("Your browser does not support stereo panning. Falling back to 3D panning."),e.panning={location:[0,0,0],type:"3d",panningModel:"equalpower"})},c=function(e,t){t.delay?e.delay={delayTime:k(t.delay.delayTime,.5),maxDelayTime:k(t.delay.maxDelayTime,2),feedback:k(t.delay.feedback,.25),wet:k(t.delay.wet,.25)}:e.delay=null},h=function(e,t){return e.nodes=[],e.mediaStreamSource=null,e.gain=null,l({audio:!0,video:!1}).then(function(a){return e.mediaStreamSource=i.createMediaStreamSource(a),f.micConsent=!0,p(e,t),e}).catch(function(e){console.log("Error setting up microphone input: ",e)})},p=function(e,t){e.nodes=[],e.gain=i.createGain(),e.gain.gain.value=k(t.volume,e.volume),e.nodes.push(e.mediaStreamSource),e.nodes.push(e.gain),(e.filter||t.filter)&&v(e,t),(e.reverb||t.reverb)&&m(e,t),u(e,t),y(e,t),(e.delay||t.delay)&&b(e,t),g(e,t),e.setUpExternalFxOnPlay(t,i)},f=function(t){if(this.source=t.source,this.destination=t.destination||i.destination,this.volume=k(t.volume,1),this.defaultVolume=this.volume,this.playable=1,this.pitch=f.pitches[t.pitch]||t.pitch||440,this.gain=[],this.detune=t.detune||0,this.globalReverb=t.globalReverb||!1,this.offset=t.offset||0,this.loop=t.loop||!1,this.tuna=t.tuna||null,this.rate=t.rate||1,this.sprite=t.sprite||null,function(e,t){e.env={attack:t.env?k(t.env.attack,1):0,decay:t.env?k(t.env.decay,0):0,sustain:t.env?k(t.env.sustain,1):1,hold:t.env?k(t.env.hold,3.14159):3.14159,release:t.env?k(t.env.release,0):0},e.defaultEnv={attack:t.env?k(t.env.attack,1):0,decay:t.env?k(t.env.decay,0):0,sustain:t.env?k(t.env.sustain,1):1,hold:t.env?k(t.env.hold,3.14159):3.14159,release:t.env?k(t.env.release,0):0}}(this,t),a(this,t),n(this,t),o(this,t),r(this,t),this.constructExternalFx(t,i),u(this,t),c(this,t),"noise"===this.source)this.decodedBuffer=e;else if("mic"===this.source)h(this,t);else if(this.source in{sine:0,sawtooth:0,square:0,triangle:0})t.callback&&t.callback(this);else if(p=this,d=t.callback,(v=new XMLHttpRequest).open("GET",p.source,!0),v.responseType="arraybuffer",p.playable--,v.onload=function(){i.decodeAudioData(v.response,function(e){p.decodedBuffer=e,3.14159===p.env.hold&&(p.defaultEnv.hold=p.decodedBuffer.duration+1,p.env.hold=p.decodedBuffer.duration+1),d&&d(p),p.playable++,p.playOnLoad&&p.play(p.playOnLoadArg)})},v.send(),this.sprite){var s=this;for(var l in this.sprite)this[l]={sprite:this.sprite[l],play:function(e){return(e=e||{}).env=e.env||{},e.env.hold=this.sprite[1]-this.sprite[0],e.offset=this.sprite[0],s.play(e)}}}var p,d,v};f.micConsent=!1,f.audioContext=i,void 0!=typeof s.a&&(f.tuna=new s.a(f.audioContext));var d=function(e,t){for(var a=t&&t.destination||e.destination,i=1;i<e.nodes.length;i++){if("custom"===e.nodes[i-1].interface)var n=e.nodes[i-1].output;else n=e.nodes[i-1];if("custom"===e.nodes[i].interface)var s=e.nodes[i].input;else s=e.nodes[i];n.connect(s)}if("custom"===e.nodes[e.nodes.length-1].interface)var o=e.nodes[e.nodes.length-1].output;else o=e.nodes[e.nodes.length-1];o.connect(a),f.reverb&&e.globalReverb&&(e.nodes[e.nodes.length-1].connect(f.reverb.node),f.reverb.node.connect(f.reverb.gain),f.reverb.gain.connect(a))},v=function(e,a){a.filter&&!t(a.filter)&&(a.filter=[a.filter]),e.filter.forEach(function(t,n){t.node=i.createBiquadFilter(),t.node.type=t.type,t.node.frequency.value=a.filter&&a.filter[n]&&a.filter[n].frequency||t.frequency,t.node.Q.value=a.filter&&a.filter[n]&&a.filter[n].q||t.q,(a.filter&&a.filter[n].env||e.filter[n].env)&&"mic"!==e.source&&(t.env={attack:a.filter&&a.filter[n].env&&a.filter[n].env.attack||e.filter[n].env.attack,frequency:a.filter&&a.filter[n].env&&a.filter[n].env.frequency||e.filter[n].env.frequency}),e.nodes.push(t.node)})},m=function(e,t){var a={interface:"custom",input:i.createGain(),convolver:i.createConvolver(),wet:i.createGain(),output:i.createGain()};a.convolver.buffer=e.reverb.buffer,a.wet.gain.value=e.reverb.wet,a.input.connect(a.convolver),a.input.connect(a.output),a.convolver.connect(a.wet),a.wet.connect(a.output),e.reverb.node=a,e.nodes.push(e.reverb.node)},y=function(e,t){var a=t&&t.panning;void 0===a&&(a=e.panning.location),"number"==typeof a?(e.panning.node=i.createStereoPanner(),e.panning.node.pan.value=a,e.panning.type="stereo"):(e.panning.node=i.createPanner(),e.panning.node.setPosition(a[0],a[1],a[2]),e.panning.node.panningModel=t.panningModel||e.panningModel||"equalpower",e.panning.type="3d"),e.nodes.push(e.panning.node)},b=function(e,t){if(e.delay){t.delay||(t.delay={});var a={interface:"custom",input:i.createGain(),output:i.createGain(),delayNode:i.createDelay(e.delay.maxDelayTime),feedbackNode:i.createGain(),wetNode:i.createGain()};a.delayNode.delayTime.value=k(t.delay.delayTime,e.delay.delayTime),a.feedbackNode.gain.value=k(t.delay.feedback,e.delay.feedback),a.wetNode.gain.value=k(t.delay.wet,e.delay.wet),a.input.connect(a.delayNode),a.input.connect(a.output),a.delayNode.connect(a.feedbackNode),a.delayNode.connect(a.wetNode),a.feedbackNode.connect(a.delayNode),a.wetNode.connect(a.output),e.delay.delayNode=a,e.nodes.push(a)}},g=function(e,t){if(e.tuna||t.tuna){var a={};if(e.tuna)for(var i in e.tuna)a[i]=e.tuna[i];if(t.tuna)for(var i in t.tuna)a[i]=t.tuna[i];for(var i in a){var n=new f.tuna[i](a[i]);e.nodes.push(n)}}};f.prototype.constructExternalFx=function(e,t){},f.prototype.setUpExternalFxOnPlay=function(e,t){},f.prototype.play=function(e){var s;e=e||{arg:null},this.playable<1?(this.playOnLoad=!0,this.playOnLoadArg=e):"mic"===this.source?f.micConsent?null===e.arg?d(this,e):(a(this,e),n(this,e),o(this,e),r(this,e),this.constructExternalFx(e,i),u(this,e),c(this,e),p(this,e),d(this,e)):(console.log("You have not given your browser permission to use your microphone."),h(this,e).then(function(t){t.play(e)})):(this.nodes=[],e.wait||(e.wait=0),e.volume?this.volume=e.volume:this.volume=this.defaultVolume,e.offset=e.offset||this.offset||0,this.source in{sine:0,sawtooth:0,square:0,triangle:0}?function(e,t){t=t||{},e.soundSource=i.createOscillator(),e.soundSource.type=e.source,t.pitch?t.pitch in f.pitches?e.soundSource.frequency.value=f.pitches[t.pitch]:e.soundSource.frequency.value=t.pitch:e.soundSource.frequency.value=e.pitch}(this,e):(this.soundSource=i.createBufferSource(),this.soundSource.buffer=this.decodedBuffer,("noise"===this.source||this.loop||e.loop)&&(this.soundSource.loop=!0)),this.soundSource.playbackRate&&(this.soundSource.playbackRate.value=e.rate||this.rate),this.soundSource.detune&&(this.soundSource.detune.value=e.detune||this.detune),void 0===e.wait&&(e.wait=0),void 0===e.exactTime&&(e.exactTime=i.currentTime+e.wait),this.nodes.push(this.soundSource),function(e,t){t&&t.env?(e.env.attack=k(t.env.attack,e.defaultEnv.attack),e.env.decay=k(t.env.decay,e.defaultEnv.decay),e.env.sustain=k(t.env.sustain,e.defaultEnv.sustain),e.env.hold=k(t.env.hold,e.defaultEnv.hold),e.env.release=k(t.env.release,e.defaultEnv.release)):e.env={attack:e.defaultEnv.attack,decay:e.defaultEnv.decay,sustain:e.defaultEnv.sustain,hold:e.defaultEnv.hold,release:e.defaultEnv.release}}(this,e),function(e,a){a&&a.filter&&e.filter?(t(a.filter)||(a.filter=[a.filter]),v(e,a)):e.filter&&v(e,e)}(this,e),g(this,e),this.setUpExternalFxOnPlay(e,i),this.gain.unshift(i.createGain()),this.gain[0].label=e.label,this.nodes.push(this.gain[0]),this.gain.length>15&&(this.gain.length=15),this.reverb&&m(this,e),y(this,e),b(this,e),d(this,e),this.filter&&this.filter[0].env&&function(e,t){e.filter.forEach(function(e,a){e.node.frequency.linearRampToValueAtTime(e.frequency,t.exactTime),e.node.frequency.linearRampToValueAtTime(e.env.frequency,t.exactTime+e.env.attack)})}(this,e),function(e,t){if(-1===e.env.hold)var a=999;else a=e.env.hold;e.gain[0].gain.linearRampToValueAtTime(1e-4,t.exactTime),e.gain[0].gain.linearRampToValueAtTime(e.volume,t.exactTime+e.env.attack+1e-5),e.gain[0].gain.linearRampToValueAtTime(e.volume*e.env.sustain,t.exactTime+e.env.attack+e.env.decay+2e-5),e.gain[0].gain.linearRampToValueAtTime(e.volume*e.env.sustain,t.exactTime+e.env.attack+e.env.decay+a+3e-5),e.gain[0].gain.linearRampToValueAtTime(1e-4,t.exactTime+e.env.attack+e.env.decay+a+e.env.release+4e-5),e.soundSource.start(t.exactTime,t.offset),e.soundSource.stop(t.exactTime+e.env.attack+e.env.decay+a+e.env.release)}(this,e),this.vibrato&&((s=this).vibrato.wad=new f({source:s.vibrato.shape,pitch:s.vibrato.speed,volume:s.vibrato.magnitude,env:{attack:s.vibrato.attack},destination:s.soundSource.frequency}),s.vibrato.wad.play()),this.tremolo&&function(e,t){e.tremolo.wad=new f({source:e.tremolo.shape,pitch:e.tremolo.speed,volume:e.tremolo.magnitude,env:{attack:e.tremolo.attack,hold:10},destination:e.gain[0].gain}),e.tremolo.wad.play()}(this)),e.callback&&e.callback(this);var l=this;return new Promise(function(t,a){setTimeout(function(){t(l)},(e.wait+l.env.attack+l.env.decay+l.env.hold+l.env.release)*(1/(e.rate||l.rate||1))*1e3)})},f.prototype.setVolume=function(e){return this.defaultVolume=e,this.gain.length>0&&(this.gain[0].gain.value=e),this},f.prototype.setRate=function(e){var t;return t=e&&e>0?e:0,this.soundSource?this.soundSource.playbackRate.value=t:console.log("Sorry, but the wad does not contain a soundSource!"),this},f.prototype.setPitch=function(e){return e in f.pitches?(this.soundSource&&(this.soundSource.frequency.value=f.pitches[e]),this.pitch=f.pitches[e]):(console.log("else"),this.soundSource&&(this.soundSource.frequency.value=e),this.pitch=e),this},f.prototype.setDetune=function(e,t){return t=t||.01,this.soundSource.detune.setTargetAtTime(e,i.currentTime,t),this},f.prototype.setPanning=function(e,a){return a=a||.01,this.panning.location=e,t(e)&&"3d"===this.panning.type&&this.panning.node?this.panning.node.setPosition(e[0],e[1],e[2]):"number"==typeof e&&"stereo"===this.panning.type&&this.panning.node&&this.panning.node.pan.setTargetAtTime(e,i.currentTime,a),t(e)?this.panning.type="3d":"number"==typeof e&&(this.panning.type="stereo"),this},f.prototype.setReverb=function(e){var t;return t=e&&e>0&&e<1?e:e>=1?1:0,this.reverb?(this.reverb.wet=t,this.reverb.node&&(this.reverb.node.wet.gain.value=t)):console.log("Sorry, but the wad does not contain Reverb!"),this},f.prototype.setDelay=function(e,t,a){var i,n,s;return i=e&&e>0?e:0,n=t&&t>0&&t<1?t:t>=1?1:0,s=a&&a>0&&a<1?a:a>=1?1:0,this.delay?(this.delay.delayTime=i,this.delay.wet=n,this.delay.feedback=s,this.delay.delayNode&&(this.delay.delayNode.delayNode.delayTime.value=i,this.delay.delayNode.wetNode.gain.value=n,this.delay.delayNode.feedbackNode.gain.value=s)):console.log("Sorry, but the wad does not contain delay!"),this},f.prototype.stop=function(e){if("mic"!==this.source){if(!this.gain||!this.gain.length)return void console.log("You tried to stop a Wad that never played. ",this);if(e)for(var t=0;t<this.gain.length;t++)this.gain[t].label===e&&(this.gain[t].gain.cancelScheduledValues(i.currentTime),this.gain[t].gain.setValueAtTime(this.gain[t].gain.value,i.currentTime),this.gain[t].gain.linearRampToValueAtTime(1e-4,i.currentTime+this.env.release));else e||(this.gain[0].gain.cancelScheduledValues(i.currentTime),this.gain[0].gain.setValueAtTime(this.gain[0].gain.value,i.currentTime),this.gain[0].gain.linearRampToValueAtTime(1e-4,i.currentTime+this.env.release))}else f.micConsent?this.mediaStreamSource.disconnect(0):console.log("You have not given your browser permission to use your microphone.");this.tremolo&&this.tremolo.wad.stop()};var w=new Uint8Array(2048);f.Poly=function(e){e||(e={}),this.isSetUp=!1,this.playable=1,e.reverb?r(this,e):this.setUp(e)},f.Poly.prototype.setUp=function(e){this.wads=[],this.input=i.createAnalyser(),this.input.fftSize=2048,this.nodes=[this.input],this.destination=e.destination||i.destination,this.volume=e.volume||1,this.output=i.createGain(),this.output.gain.value=this.volume,this.tuna=e.tuna||null,this.globalReverb=e.globalReverb||!1,a(this,e),this.filter&&v(this,e),this.reverb&&m(this,e),this.constructExternalFx(e,i),u(this,e),y(this,e),e.compressor&&function(e,t){e.compressor=i.createDynamicsCompressor(),e.compressor.attack.value=k(t.compressor.attack,e.compressor.attack.value),e.compressor.knee.value=k(t.compressor.knee,e.compressor.knee.value),e.compressor.ratio.value=k(t.compressor.ratio,e.compressor.ratio.value),e.compressor.release.value=k(t.compressor.release,e.compressor.release.value),e.compressor.threshold.value=k(t.compressor.threshold,e.compressor.threshold.value),e.nodes.push(e.compressor)}(this,e),c(this,e),b(this,e),g(this,e),this.nodes.push(this.output),d(this,e),this.isSetUp=!0,e.callback&&e.callback(this)},f.Poly.prototype.updatePitch=function(e){this.input.getByteTimeDomainData(w);var t,a,n=function(e,t){var a=-1,i=0,n=0,s=!1;if(e.length<1996)return-1;for(var o=0;o<1e3;o++){var r=(e[o]-128)/128;n+=r*r}if((n=Math.sqrt(n/1e3))<.01)return-1;for(var u=1,l=4;l<=1e3;l++){var c=0;for(o=0;o<1e3;o++)c+=Math.abs((e[o]-128)/128-(e[o+l]-128)/128);if((c=1-c/1e3)>.9&&c>u)s=!0;else if(s)return t/a;u=c,c>i&&(i=c,a=l)}return i>.01?t/a:-1}(w,i.sampleRate);if(-1!==n&&11025!==n&&12e3!==n){var s=n;this.pitch=Math.floor(s);var o=(t=s,a=Math.log(t/440)/Math.log(2)*12,Math.round(a)+69);this.noteName=f.pitchesArray[o-12]}var r=this;r.rafID=window.requestAnimationFrame(function(){r.updatePitch()})},f.Poly.prototype.stopUpdatingPitch=function(){cancelAnimationFrame(this.rafID)},f.Poly.prototype.setVolume=function(e){return this.isSetUp?this.output.gain.value=e:console.log("This PolyWad is not set up yet."),this},f.Poly.prototype.setPitch=function(e){this.wads.forEach(function(t){return e in f.pitches?(t.soundSource&&(t.soundSource.frequency.value=f.pitches[e]),t.pitch=f.pitches[e]):(console.log("else"),t.soundSource&&(t.soundSource.frequency.value=e),t.pitch=e),this})},f.Poly.prototype.play=function(e){if(this.isSetUp)if(this.playable<1)this.playOnLoad=!0,this.playOnLoadArg=e;else{e&&e.volume&&(this.output.gain.value=e.volume,e.volume=void 0);for(var t=0;t<this.wads.length;t++)this.wads[t].play(e)}else console.log("This PolyWad is not set up yet.");return this},f.Poly.prototype.stop=function(e){if(this.isSetUp)for(var t=0;t<this.wads.length;t++)this.wads[t].stop(e)},f.Poly.prototype.add=function(e){return this.isSetUp?(e.destination=this.input,this.wads.push(e),e instanceof f.Poly&&(e.output.disconnect(0),e.output.connect(this.input))):console.log("This PolyWad is not set up yet."),this},f.Poly.prototype.remove=function(e){if(this.isSetUp)for(var t=0;t<this.wads.length;t++)this.wads[t]===e&&(this.wads[t].destination=i.destination,this.wads.splice(t,1),e instanceof f.Poly&&(e.output.disconnect(0),e.output.connect(i.destination)));return this},f.Poly.prototype.constructExternalFx=function(e,t){},f.defaultImpulse="https://www.codecur.io/audio/widehall.wav",f.setGlobalReverb=function(e){f.reverb={},f.reverb.node=i.createConvolver(),f.reverb.gain=i.createGain(),f.reverb.gain.gain.value=e.wet;var t=e.impulse||f.defaultImpulse,a=new XMLHttpRequest;a.open("GET",t,!0),a.responseType="arraybuffer",a.onload=function(){i.decodeAudioData(a.response,function(e){f.reverb.node.buffer=e})},a.send()};var k=function(e,t){return null==e?t:e};f.pitches={A0:27.5,"A#0":29.1352,Bb0:29.1352,B0:30.8677,"B#0":32.7032,Cb1:30.8677,C1:32.7032,"C#1":34.6478,Db1:34.6478,D1:36.7081,"D#1":38.8909,Eb1:38.8909,E1:41.2034,Fb1:41.2034,"E#1":43.6535,F1:43.6535,"F#1":46.2493,Gb1:46.2493,G1:48.9994,"G#1":51.9131,Ab1:51.9131,A1:55,"A#1":58.2705,Bb1:58.2705,B1:61.7354,Cb2:61.7354,"B#1":65.4064,C2:65.4064,"C#2":69.2957,Db2:69.2957,D2:73.4162,"D#2":77.7817,Eb2:77.7817,E2:82.4069,Fb2:82.4069,"E#2":87.3071,F2:87.3071,"F#2":92.4986,Gb2:92.4986,G2:97.9989,"G#2":103.826,Ab2:103.826,A2:110,"A#2":116.541,Bb2:116.541,B2:123.471,Cb3:123.471,"B#2":130.813,C3:130.813,"C#3":138.591,Db3:138.591,D3:146.832,"D#3":155.563,Eb3:155.563,E3:164.814,Fb3:164.814,"E#3":174.614,F3:174.614,"F#3":184.997,Gb3:184.997,G3:195.998,"G#3":207.652,Ab3:207.652,A3:220,"A#3":233.082,Bb3:233.082,B3:246.942,Cb4:246.942,"B#3":261.626,C4:261.626,"C#4":277.183,Db4:277.183,D4:293.665,"D#4":311.127,Eb4:311.127,E4:329.628,Fb4:329.628,"E#4":349.228,F4:349.228,"F#4":369.994,Gb4:369.994,G4:391.995,"G#4":415.305,Ab4:415.305,A4:440,"A#4":466.164,Bb4:466.164,B4:493.883,Cb5:493.883,"B#4":523.251,C5:523.251,"C#5":554.365,Db5:554.365,D5:587.33,"D#5":622.254,Eb5:622.254,E5:659.255,Fb5:659.255,"E#5":698.456,F5:698.456,"F#5":739.989,Gb5:739.989,G5:783.991,"G#5":830.609,Ab5:830.609,A5:880,"A#5":932.328,Bb5:932.328,B5:987.767,Cb6:987.767,"B#5":1046.5,C6:1046.5,"C#6":1108.73,Db6:1108.73,D6:1174.66,"D#6":1244.51,Eb6:1244.51,Fb6:1318.51,E6:1318.51,"E#6":1396.91,F6:1396.91,"F#6":1479.98,Gb6:1479.98,G6:1567.98,"G#6":1661.22,Ab6:1661.22,A6:1760,"A#6":1864.66,Bb6:1864.66,B6:1975.53,Cb7:1975.53,"B#6":2093,C7:2093,"C#7":2217.46,Db7:2217.46,D7:2349.32,"D#7":2489.02,Eb7:2489.02,E7:2637.02,Fb7:2637.02,"E#7":2793.83,F7:2793.83,"F#7":2959.96,Gb7:2959.96,G7:3135.96,"G#7":3322.44,Ab7:3322.44,A7:3520,"A#7":3729.31,Bb7:3729.31,B7:3951.07,Cb8:3951.07,"B#7":4186.01,C8:4186.01},f.pitchesArray=["C0","C#0","D0","D#0","E0","F0","F#0","G0","G#0","A0","A#0","B0","C1","C#1","D1","D#1","E1","F1","F#1","G1","G#1","A1","A#1","B1","C2","C#2","D2","D#2","E2","F2","F#2","G2","G#2","A2","A#2","B2","C3","C#3","D3","D#3","E3","F3","F#3","G3","G#3","A3","A#3","B3","C4","C#4","D4","D#4","E4","F4","F#4","G4","G#4","A4","A#4","B4","C5","C#5","D5","D#5","E5","F5","F#5","G5","G#5","A5","A#5","B5","C6","C#6","D6","D#6","E6","F6","F#6","G6","G#6","A6","A#6","B6","C7","C#7","D7","D#7","E7","F7","F#7","G7","G#7","A7","A#7","B7","C8"],f.assignMidiMap=function(e,t,a,i){t=t||0;navigator.requestMIDIAccess().then(function(){f.midiInputs[t]?(f.midiInputs[t].onmidimessage=e,"function"==typeof a&&a()):"function"==typeof i&&i()})},f.midiInstrument={play:function(){console.log("playing midi")},stop:function(){console.log("stopping midi")}},f.midiInputs=[];var _=function(e){console.log(e.receivedTime,e.data),144===e.data[0]?0===e.data[2]?(console.log("|| stopping note: ",f.pitchesArray[e.data[1]-12]),f.midiInstrument.stop(f.pitchesArray[e.data[1]-12])):e.data[2]>0&&(console.log("> playing note: ",f.pitchesArray[e.data[1]-12]),f.midiInstrument.play({pitch:f.pitchesArray[e.data[1]-12],label:f.pitchesArray[e.data[1]-12],callback:function(e){}})):176===e.data[0]?(console.log("controller"),46==e.data[1]&&(127==e.data[2]?f.midiInstrument.pedalMod=!0:0==e.data[2]&&(f.midiInstrument.pedalMod=!1))):224===e.data[0]&&console.log("pitch bend")};if(navigator&&navigator.requestMIDIAccess)try{navigator.requestMIDIAccess().then(function(e){f.midiInputs=[];for(var t=e.inputs.values(),a=t.next();!a.done;a=t.next())f.midiInputs.push(a.value);console.log("MIDI inputs: ",f.midiInputs);for(var i=0;i<f.midiInputs.length;i++)f.midiInputs[i].onmidimessage=_},function(e){console.log("Failed to get MIDI access",e)})}catch(e){console.log("Failed to get MIDI access",e)}return f.presets={hiHatClosed:{source:"noise",env:{attack:.001,decay:.008,sustain:.2,hold:.03,release:.01},filter:{type:"highpass",frequency:400,q:1}},snare:{source:"noise",env:{attack:.001,decay:.01,sustain:.2,hold:.03,release:.02},filter:{type:"bandpass",frequency:300,q:.18}},hiHatOpen:{source:"noise",env:{attack:.001,decay:.008,sustain:.2,hold:.43,release:.01},filter:{type:"highpass",frequency:100,q:.2}},ghost:{source:"square",volume:.3,env:{attack:.01,decay:.002,sustain:.5,hold:2.5,release:.3},filter:{type:"lowpass",frequency:600,q:7,env:{attack:.7,frequency:1600}},vibrato:{attack:8,speed:8,magnitude:100}},piano:{source:"square",volume:1.4,env:{attack:.01,decay:.005,sustain:.2,hold:.015,release:.3},filter:{type:"lowpass",frequency:1200,q:8.5,env:{attack:.2,frequency:600}}}},f}();void 0!==e&&e.exports&&(e.exports=c),t.default=c}.call(this,a(1)(e))}]).default});

  var statusLabel = props.statusLabel;
  var websocketUrl = props.websocketUrl;
  var loginUrl = props.loginUrl;
  var isPlaying = false;
  var directiveQueue = [];
  this.wadSound = null;

  function getWadConfig(config) {
    return props.getWadConfig ? props.getWadConfig(config) : config;
  }

  function send(contents) {
    socket.readyState === WebSocket.OPEN && socket.send(contents);
  }

  function sendAudio(event) {
    send(event.inputBuffer.getChannelData(0));
  }

  function consumeDirectiveQueue(){
    if (directiveQueue.length > 0 && !isPlaying) {
      var directive = directiveQueue.shift();
      updateStatusLabel(directive.name);
      if (directive.name == 'Speak') {
        playAudioHandler(directive.payload);
      } else if (directive.name == 'ExpectSpeech') {
        send('ExpectSpeech');
      }
    }
  }

  function getDuration(source) {
    return new Promise(function(resolve) {
      var audio = new Audio();
      audio.onloadedmetadata = function() {
        resolve(audio.duration);
      }
      audio.src = source;
    });
  }

  function playAudioHandler(samples) {
    var blob = new Blob([samples]);
    var source = URL.createObjectURL(blob)
    getDuration(source)
      .then(function(length) {
        this.wadSound = new Wad(getWadConfig({source: source}));
        wadSound.defaultEnv.hold = length;
        isPlaying = true;
        return this.wadSound.play({wait: 0})
      })
      .then(function(){
        console.log('fin')
        isPlaying = false;
      });
  }

  function handleGetUserMediaSuccess(stream) {
    var audioInput = context.createMediaStreamSource(stream);
    var recorder = context.createScriptProcessor(4096, 1, 1);
    recorder.onaudioprocess = sendAudio;

    audioInput.connect(recorder);
    recorder.connect(context.destination);
    setInterval(consumeDirectiveQueue, 100);
  }

  function handleWebsocketMessage(event) {
    if (event.data instanceof ArrayBuffer) {
      directiveQueue.push({'name': 'Speak', 'payload': event.data});
    } else {
      var message = JSON.parse(event.data);
      directiveQueue.push({'name': message.type})
    }
  }

  function updateStatusLabel(messageId) {
    if (messageId == 'EXPECTING_COMMAND') {
      statusLabel.innerText = 'Listening...';
    } else if (messageId === 'EXPECTING_WAKEWORD') {
      statusLabel.innerText = 'Say "Alexa"';
    } else if (messageId === 'CONNECTING') {
      statusLabel.innerText = 'Connecting to Alexa';
    } else if (messageId === 'Speak') {
      statusLabel.innerText = 'Alexa is talking'
    }
  }

  function handleWebsocketClose(event) {
   if (event.code == 3000) {
      statusLabel.innerText = 'Login required. redirecting...'
      setTimeout(handleLoginRequired, 1000);
    }
  }

  function handleLoginRequired() {
    window.location.href = loginUrl;
  }

  function createWebsocket(){
    socket = new WebSocket(websocketUrl) ;
    socket.binaryType = 'arraybuffer';
    socket.onmessage = handleWebsocketMessage;
    socket.onclose = handleWebsocketClose;
  }

  function websocketReconnectionMangaer(){
    socket.readyState === WebSocket.CLOSED && createWebsocket();
  }

  var context = new window.AudioContext();
  var socket;
  createWebsocket();
  setInterval(websocketReconnectionMangaer, 1000);
  navigator.mediaDevices.getUserMedia({audio:true})
    .then(handleGetUserMediaSuccess);

  return this;
}