text: !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.gamepad=e()}}(function(){var e;return function t(e,n,r){function i(s,c){if(!n[s]){if(!e[s]){var a="function"==typeof require&&require;if(!c&&a)return a(s,!0);if(o)return o(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var l=n[s]={exports:{}};e[s][0].call(l.exports,function(t){var n=e[s][1][t];return i(n?n:t)},l,l.exports,t,e,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<r.length;s++)i(r[s]);return i}({1:[function(e,t){!function(n,r){"use strict";function i(e){h=this,e||(e={}),Object.keys(d).forEach(function(t){this[t]=t in e?e[t]:d[t]}.bind(this)),this.state={}}var o=e("plink"),s=e("./lib/modal")(n,r),c=e("./settings"),a=e("./lib/utils")(n,r),u=e("./lib/routes"),l=a.error,f=a.trace,p=a.warn;a.polyfill();var h,d={protocol:"webrtc"},m={get:function(){return h},init:function(e){return h||new i({protocol:e})}};i.prototype.version=m.version=c.VERSION,i.prototype.getGamepadOrigin=m.getGamepadOrigin=function(){var e=r.querySelector("[data-gamepad-origin]");return e?e.dataset.gamepadOrigin:c.GAMEPAD_ORIGIN},i.prototype._reverse_url=function(e){if(!(e in u))throw"No route matches for that name: "+e;return this.getGamepadOrigin()+u[e]},i.prototype._pair=function(e){return new Promise(function(t,r){e||(e=a.getPeerKey()),f("Peer key: "+e);var i=0,s=o.create();f("Waiting for peer to connect");var u=s.connect(c.WS_URL);u.setKey(e).then(function(){f("Sent message to signalling server: "+JSON.stringify({type:"set key",key:e}))}).catch(function(t){p('Controller is already online; "set key" message rejected by signalling server: '+t),u.useKey(e).then(function(){f("Sent message to signalling server: "+JSON.stringify({type:"use key",key:e}))}).catch(function(e){l('Failed to send "use key" mesage to signalling server: '+e)})}),u.on("connection",function(e){f("["+e.address+"] Found peer via signalling server"+(i?" (reattempt #"+i++ +")":"")),t(e),e.on("open",function(){f("["+e.address+"] Opened peer connection to controller")}).on("message",function(t){if("object"==typeof t&&t.type)switch(t.type){case"bye":return p("["+e.address+"] Lost peer connection to controller"),void i++;case"state":return f("["+e.address+"] Received new controller state from peer: "+("object"==typeof t?JSON.stringify(t):t)),this._updateState(t.data);default:return p("["+e.address+"] Received peer message of unexpected type ("+(t.type||"")+"): "+("object"==typeof t?JSON.stringify(t):t))}p("["+e.address+"] Received unexpected peer message: "+("object"==typeof t?JSON.stringify(t):t))}.bind(this)).on("error",function(t){l("["+e.address+"] Peer error: "+("object"==typeof t?JSON.stringify(t):t)),r(e)}).on("close",function(){f("["+e.address+"] Peer closed")}),n.addEventListener("beforeunload",function(){e.send({type:"bye"})})}.bind(this)).on("message",function(e){f("Received message from signalling server: "+JSON.stringify(e))}).on("error",function(e){l(": "+JSON.stringify(e)),r(e)}).on("close",function(){p("Connection lost to signalling server")})}.bind(this))},i.prototype.pair=function(e){return new Promise(function(t,n){f("Pairing started");var r=encodeURIComponent(e||"");e||(e=a.getPeerKey(),r=encodeURIComponent(e||""));var i=this._reverse_url("client")+"?"+r,o='<div class="modal-inner modal-pair"><h2>URL</h2><p><a href="'+i+'" class="pair-url" target="_blank">'+i+'</a></p><h2>Code</h2><p class="pair-code">'+r+"</p></div>";return this.modal=new s({id:"pairing-screen",classes:"slim",title:"Pair your mobile phone",content:o},!0),this.modal.open().then(function(){f("Awaiting player to pair device")}).catch(function(){p("Failed to open modal"),n()}),["https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700","/css/modal.css"].forEach(function(e){a.injectCSS({href:e})}),this._pair(e).then(function(e){f("["+e.address+"] Paired to controller")}.bind(this)).then(function(){this.modal.close()}.bind(this)).catch(function(e){console.trace(e.stack?e.stack:e)})}.bind(this))},i.prototype._updateState=function(e){this.state=e,Object.keys(e||{}).forEach(function(t){!this.state[t]&&e[t]?(this._emit("buttondown",t),this._emit("buttondown."+t,t)):this.state[t]&&!e[t]&&(this._emit("buttonup",t),this._emit("buttonup."+t,t))}.bind(this))},i.prototype.hidePairingScreen=function(){this.modal.close()},i.prototype._emit=function(e,t){f('Emit "'+e+'": '+t)},i.prototype._bind=function(e,t){return"undefined"==typeof this.listeners[event]&&(this.listeners[event]=[]),this.listeners[event].push(t),this},i.prototype.unbind=function(e,t){return"undefined"==typeof e?void(this.listeners={}):"undefined"==typeof t?void(this.listeners[e]=[]):"undefined"==typeof this.listeners[e]?!1:(this.listeners[e].forEach(function(n,r){return n===t?(this.listeners[e].splice(r,1),!0):void 0}),!1)},t.exports=m}(window,document)},{"./lib/modal":17,"./lib/routes":18,"./lib/utils":19,"./settings":20,plink:6}],2:[function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(e){return"function"==typeof e}function i(e){return"number"==typeof e}function o(e){return"object"==typeof e&&null!==e}function s(e){return void 0===e}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!i(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,i,c,a,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[e],s(n))return!1;if(r(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:for(i=arguments.length,c=new Array(i-1),a=1;i>a;a++)c[a-1]=arguments[a];n.apply(this,c)}else if(o(n)){for(i=arguments.length,c=new Array(i-1),a=1;i>a;a++)c[a-1]=arguments[a];for(u=n.slice(),i=u.length,a=0;i>a;a++)u[a].apply(this,c)}return!0},n.prototype.addListener=function(e,t){var i;if(!r(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,r(t.listener)?t.listener:t),this._events[e]?o(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,o(this._events[e])&&!this._events[e].warned){var i;i=s(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,i&&i>0&&this._events[e].length>i&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),i||(i=!0,t.apply(this,arguments))}if(!r(t))throw TypeError("listener must be a function");var i=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,i,s,c;if(!r(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],s=n.length,i=-1,n===t||r(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(o(n)){for(c=s;c-->0;)if(n[c]===t||n[c].listener&&n[c].listener===t){i=c;break}if(0>i)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],r(n))this.removeListener(e,n);else for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?r(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.listenerCount=function(e,t){var n;return n=e._events&&e._events[t]?r(e._events[t])?1:e._events[t].length:0}},{}],3:[function(e,t){function n(){}var r=t.exports={};r.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(t){var n=[];return window.addEventListener("message",function(e){var t=e.source;if((t===window||null===t)&&"process-tick"===e.data&&(e.stopPropagation(),n.length>0)){var r=n.shift();r()}},!0),function(e){n.push(e),window.postMessage("process-tick","*")}}return function(e){setTimeout(e,0)}}(),r.title="browser",r.browser=!0,r.env={},r.argv=[],r.on=n,r.addListener=n,r.once=n,r.off=n,r.removeListener=n,r.removeAllListeners=n,r.emit=n,r.binding=function(){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(){throw new Error("process.chdir is not supported")}},{}],4:[function(e,t){t.exports=e("./lib/its.js")},{"./lib/its.js":5}],5:[function(e,t){var n=Array.prototype.slice,r=Object.prototype.toString,i=/%s/,o=function(e,t){for(var n=[],r=e.split(i),o=0,s=r.length;s>o;o++)n.push(r[o]),n.push(t[o]);return n.join("")},s=t.exports=function(e,t){if(e===!1)throw t&&"string"!=typeof t?t(arguments.length>3?o(arguments[2],n.call(arguments,3)):arguments[2]):new Error(arguments.length>2?o(t,n.call(arguments,2)):t);return e};s.type=function(e,t){if(e===!1)throw new TypeError(arguments.length>2?o(t,n.call(arguments,2)):t);return e},s.undefined=function(e){return s.type.apply(null,[void 0===e].concat(n.call(arguments,1)))},s.null=function(e){return s.type.apply(null,[null===e].concat(n.call(arguments,1)))},s.boolean=function(e){return s.type.apply(null,[e===!0||e===!1||"[object Boolean]"===r.call(e)].concat(n.call(arguments,1)))},s.array=function(e){return s.type.apply(null,["[object Array]"===r.call(e)].concat(n.call(arguments,1)))},s.object=function(e){return s.type.apply(null,[e===Object(e)].concat(n.call(arguments,1)))},function(){for(var e=[["args","Arguments"],["func","Function"],["string","String"],["number","Number"],["date","Date"],["regexp","RegExp"]],t=0,i=e.length;i>t;t++)!function(){var i=e[t];s[i[0]]=function(e){return s.type.apply(null,[r.call(e)==="[object "+i[1]+"]"].concat(n.call(arguments,1)))}}()}(),"function"!=typeof/./&&(s.func=function(e){return s.type.apply(null,["function"==typeof e].concat(n.call(arguments,1)))}),s.defined=function(e,t){if(void 0===e)throw new ReferenceError(arguments.length>2?o(t,n.call(arguments,2)):t);return e},s.range=function(e,t){if(e===!1)throw new RangeError(arguments.length>2?o(t,n.call(arguments,2)):t);return e}},{}],6:[function(e,t){t.exports=e("./lib/Plink.js")},{"./lib/Plink.js":7}],7:[function(e,t){function n(e){this.p=r.create(e)}var r=e("internet"),i=e("./PlinkServer.js");n.create=function(e){return new n(e)},t.exports=n,n.prototype.connect=function(e){var t=this.p.connect(e);return i.create(t)}},{"./PlinkServer.js":8,internet:9}],8:[function(e,t){function n(e){this.promises={},this.onramp=e,this.waitForOpenQueue=[],this.onramp.on("message",this.messageHandler.bind(this)),this.onramp.on("open",this.openHandler.bind(this))}var r=e("when");n.create=function(e){return new n(e)},t.exports=n,n.prototype.on=function(){return this.onramp.on.apply(this.onramp,arguments),this},n.prototype.removeListener=function(){return this.onramp.removeListener.apply(this.onramp,arguments),this},n.prototype.openHandler=function(){this.waitForOpenQueue.forEach(function(e){e()}),this.waitForOpenQueue=[]},n.prototype.setKey=function(e,t){var n=this,i=this.promises["set"+e];return i||(i=this.promises["set"+e]=r.defer()),this.onramp.isOpen()?this.onramp.send({type:"set key",key:e,timeout:t}):this.waitForOpenQueue.push(function(){n.onramp.send({type:"set key",key:e,timeout:t})}),i.promise},n.prototype.revokeKey=function(e){var t=this.promises["revoke"+e];return t||(t=this.promises["revoke"+e]=r.defer()),this.onramp.send({type:"revoke key",key:e}),t.promise},n.prototype.useKey=function(e){var t=this,n=this.promises["use"+e];return n||(n=this.promises["use"+e]=r.defer()),this.onramp.isOpen()?this.onramp.send({type:"use key",key:e}):this.waitForOpenQueue.push(function(){t.onramp.send({type:"use key",key:e})}),n.promise},n.prototype.messageHandler=function(e){if(e.type){var t,n=e.key;switch(e.type){case"address":var r=this.onramp.connect(e.address);t=this.promises["use"+n],t.resolve(r),delete this.promises["use"+n];break;case"invalid key":t=this.promises["use"+n],t.reject(new Error("invalid key: "+e.key)),delete this.promises["use"+n];break;case"key set":t=this.promises["set"+n],t.resolve(e.key),delete this.promises["set"+n];break;case"key not set":t=this.promises["set"+n],t.reject(new Error("key not set: "+e.key)),delete this.promises["set"+n];break;case"key revoked":t=this.promises["revoke"+n],t.resolve(e.key),delete this.promises["revoke"+n];break;case"key revoked":t=this.promises["revoke"+n],t.resolve(new Error("key not revoked: "+e.key)),delete this.promises["revoke"+n]}}}},{when:16}],9:[function(e,t){t.exports=e("./lib/P.js")},{"./lib/P.js":13}],10:[function(e,t){function n(){throw new Error("This method is not implemented")}function r(e,t,n){s.string(e),s.defined(t),this.address=e,this.peers=t,n&&(n.emitter&&(this.emitter=n.emitter),n.firewall&&(this.acceptRTCConnection=n.firewall)),this.emitter||(this.emitter=new r.Emitter)}function i(e){return"[object String]"===Object.prototype.toString.call(e)}var o=e("./JSONProtocol.js"),s=e("its"),c=e("events").EventEmitter;r.createWebRTCConnection=null,r.Emitter=c,r.prototype=Object.create(o.prototype),r.prototype.on=function(){return this.emitter.on.apply(this.emitter,arguments),this},r.prototype.removeListener=function(){return this.emitter.removeListener.apply(this.emitter,arguments),this},r.prototype.send=o.prototype.writeMessage,r.prototype.getPeer=function(e){return this.peers.get(e)},r.prototype.addPeer=function(e){return this.peers.add(e)},r.prototype.getPeers=function(){return this.peers.get()},r.prototype.connect=function(e){i(e)&&(e={address:e});var t=this,n=e.firewall||this.firewall,o=r.createWebRTCConnection(e,this.peers,this,{firewall:n});return o.writeOffer(e),this.peers.add(o),o.on("close",function(){t.peers.remove(o),t.emitter.emit("disconnection",o)}),this.emitter.emit("connection",o),o},r.prototype.readMessage=function(e){this.emitter.emit("message",e)},r.prototype.readArrayBuffer=function(e){this.emitter.emit("arraybuffer",e)},r.prototype.acceptRTCConnection=function(){return!0},r.prototype.readRelay=function(e,t){var n=this.getPeer(e);return n?void n.writeRelayedMessage(this.address,t):void this.emitter.emit("error",new Error("Unknown peer at address: "+e))},r.prototype.readRelayedIceCandidate=function(e,t){var n=this.getPeer(e);return n?void n.readIceCandidate(t):void this.emitter.emit("error",new Error("Unknown peer at address: "+e))},r.prototype.readRelayedOffer=function(e,t,n){if(!this.acceptRTCConnection(t,n))return!1;var i=this,o=r.createWebRTCConnection({address:e},this.peers,this,{firewall:this.firewall});this.addPeer(o),o.on("close",function(){i.peers.remove(o),i.emitter.emit("disconnection",o)}),o.readOffer(t),o.writeAnswer(),this.emitter.emit("connection",o)},r.prototype.readRelayedAnswer=function(e,t){var n=this.getPeer(e);return n?void n.readAnswer(t):void this.emitter.emit("error",new Error("Unknown peer at address: "+e))},r.prototype.close=n,r.prototype.getReadyState=n,r.prototype.isOpen=function(){return"open"===this.getReadyState()},t.exports=r},{"./JSONProtocol.js":12,events:2,its:4}],11:[function(e,t){function n(){}function r(){this.connectionMap={},this.connectionList=[]}var i=e("its");r.prototype.get=function(e){return void 0===e?this.connectionList.slice():this.connectionMap[e]},r.prototype.add=function(e){i.defined(e);var t=e.address;return i.string(t),t in this.connectionMap?!1:(this.connectionMap[t]=e,this.connectionList.push(e),this.onAdd(e),!0)},r.prototype.onAdd=n,r.prototype.remove=function(e){i.defined(e);var t=e.address;i.string(t);var n=this.connectionMap[t];if(!n||n!==e)return!1;delete this.connectionMap[t];var r=this.connectionList.indexOf(e);return this.connectionList.splice(r,1),this.onRemove(e),!0},r.prototype.onRemove=n,t.exports=r},{its:4}],12:[function(e,t){function n(){throw new Error("This method is not implemented")}function r(){}r.prototype.PROTOCOL_NAME="p",r.prototype.MESSAGE_TYPE={DIRECT:0,RTC_OFFER:3,RTC_ANSWER:4,RTC_ICE_CANDIDATE:5,RELAY:6,RELAYED:7},r.prototype.readRaw=function(e){e instanceof ArrayBuffer?this.readArrayBuffer(e):this.readProtocolMessage(JSON.parse(e))},r.prototype.readProtocolMessage=function(e){var t=this.MESSAGE_TYPE,n=e[0];switch(n){case t.DIRECT:this.readMessage(e[1]);break;case t.RELAYED:this.readRelayedMessage(e[1],e[2]);break;case t.RELAY:this.readRelay(e[1],e[2]);break;default:throw new Error("Unknown message type: "+n)}},r.prototype.readRelayedMessage=function(e,t){var n=this.MESSAGE_TYPE,r=t[0];switch(r){case n.RTC_OFFER:this.readRelayedOffer(e,t[1],t[2]);break;case n.RTC_ANSWER:this.readRelayedAnswer(e,t[1]);break;case n.RTC_ICE_CANDIDATE:this.readRelayedIceCandidate(e,t[1]);break;default:throw new Error("Unknown message type: "+r)}},r.prototype.readMessage=n,r.prototype.readArrayBuffer=n,r.prototype.readRelay=n,r.prototype.readRelayedOffer=n,r.prototype.readRelayedAnswer=n,r.prototype.readRelayedIceCandidate=n,r.prototype.writeRaw=n,r.prototype.writeProtocolMessage=function(e){var t=JSON.stringify(e);this.writeRaw(t)},r.prototype.writeMessage=function(e){e instanceof ArrayBuffer?this.writeRaw(e):this.writeStringMessage(e)},r.prototype.writeStringMessage=function(e){this.writeProtocolMessage([this.MESSAGE_TYPE.DIRECT,e])},r.prototype.writeRelayedMessage=function(e,t){this.writeProtocolMessage([this.MESSAGE_TYPE.RELAYED,e,t])},r.prototype.writeRelayMessage=function(e,t){this.writeProtocolMessage([this.MESSAGE_TYPE.RELAY,e,t])},r.prototype.writeRelayAnswer=function(e,t){this.writeRelayMessage(e,[this.MESSAGE_TYPE.RTC_ANSWER,t])},r.prototype.writeRelayIceCandidate=function(e,t){this.writeRelayMessage(e,[this.MESSAGE_TYPE.RTC_ICE_CANDIDATE,t])},r.prototype.writeRelayOffer=function(e,t,n){this.writeRelayMessage(e,[this.MESSAGE_TYPE.RTC_OFFER,t,n])},t.exports=r},{}],13:[function(e,t){function n(e,t,n){s.defined(e),s.defined(t),this.emitter=e,this.peers=t,this.peers.onAdd=function(t){e.emit("connection",t)},this.peers.onRemove=function(t){e.emit("disconnection",t)},n&&n.firewall&&(this.firewall=n.firewall)}var r=e("events").EventEmitter,i=e("./ConnectionManager.js"),o=e("./WebSocketConnection.js"),s=(e("./WebRTCConnection.js"),e("its"));n.create=function(e){var t=new r,o=new i;return new n(t,o,e)},n.prototype.getPeers=function(){return this.peers.get()},n.prototype.connect=function(e){s.string(e);var t=this.peers,n=o.create(e,this.peers,{firewall:this.firewall});return t.add(n),n.on("close",function(){t.remove(n)}),n},n.prototype.on=function(){return this.emitter.on.apply(this.emitter,arguments),this},n.prototype.removeListener=function(){return this.emitter.removeListener.apply(this.emitter,arguments),this},t.exports=n},{"./ConnectionManager.js":11,"./WebRTCConnection.js":14,"./WebSocketConnection.js":15,events:2,its:4}],14:[function(e,t){function n(e,t,n,o,s){var c=this;i.string(e),i.defined(t),i.defined(n),i.defined(o),r.call(this,e,t,s),this.signalingChannel=o,this.rtcConnection=n,this.rtcDataChannel=n.createDataChannel(this.PROTOCOL_NAME,{reliable:!1}),this.close=n.close.bind(n),this.rtcConnection.addEventListener("icecandidate",function(t){t.candidate&&c.signalingChannel.writeRelayIceCandidate(e,t.candidate)}),this.rtcDataChannel.addEventListener("message",function(e){c.readRaw(e.data)}),this.rtcDataChannel.addEventListener("open",function(e){c.emitter.emit("open",e)}),this.rtcDataChannel.addEventListener("error",function(e){c.emitter.emit("error",e)}),this.rtcDataChannel.addEventListener("close",function(e){c.emitter.emit("close",e)}),this.rtcDataChannel.addEventListener("removestream",function(e){c.emitter.emit("removestream",e)}),this.rtcDataChannel.addEventListener("icestatechange",function(e){c.emitter.emit("icestatechange",e)}),this.rtcDataChannel.addEventListener("icechange",function(e){c.emitter.emit("icechange",e)})}var r=e("./Connection.js"),i=e("its"),o="undefined"!=typeof RTCPeerConnection?RTCPeerConnection:"undefined"!=typeof webkitRTCPeerConnection?webkitRTCPeerConnection:"undefined"!=typeof mozRTCPeerConnection?mozRTCPeerConnection:void 0,s="undefined"!=typeof RTCSessionDescription?RTCSessionDescription:"undefined"!=typeof mozRTCSessionDescription?mozRTCSessionDescription:void 0,c="undefined"!=typeof RTCIceCandidate?RTCIceCandidate:"undefined"!=typeof mozRTCIceCandidate?mozRTCIceCandidate:void 0,a=null,u={optional:[{RtpDataChannels:!0}],mandatory:{OfferToReceiveAudio:!1,OfferToReceiveVideo:!1}};n.create=function(e,t,r,i){var s=e.rtcConfiguration||a,c=e.mediaConstraints||u,l=new o(s,c);return new n(e.address,t,l,r,i)},n.prototype=Object.create(r.prototype),n.prototype.writeRaw=function(e){switch(this.rtcDataChannel.readyState){case"connecting":throw new Error("Can't send a message while RTCDataChannel connecting");case"open":this.rtcDataChannel.send(e);break;case"closing":case"closed":throw new Error("Can't send a message while RTCDataChannel is closing or closed")}},n.prototype.readAnswer=function(e){var t=new s(e);this.rtcConnection.setRemoteDescription(t)},n.prototype.readOffer=function(e){var t=new s(e);this.rtcConnection.setRemoteDescription(t)},n.prototype.readIceCandidate=function(e){this.emitter,this.rtcConnection.addIceCandidate(new c(e))},n.prototype.writeAnswer=function(){function e(e){t.emit("error",e)}var t=this.emitter,n=this.address,r=this.rtcConnection,i=this.signalingChannel;r.createAnswer(function(t){r.setLocalDescription(t,function(){i.writeRelayAnswer(n,t)},e)},e)},n.prototype.writeOffer=function(e){function t(e){n.emit("error",e)}var n=this.emitter,r=this.address,i=this.rtcConnection,o=this.signalingChannel;i.createOffer(function(n){i.setLocalDescription(n,function(){o.writeRelayOffer(r,n,e.offerData)},t)},t,e.mediaConstraints||u)},n.prototype.getReadyState=function(){return this.rtcDataChannel.readyState},r.createWebRTCConnection=n.create,t.exports=n},{"./Connection.js":10,its:4}],15:[function(e,t){function n(e,t,n,i){var o=this;r.call(this,e,t,i),this.webSocket=n,this.close=n.close.bind(n),this.webSocket.addEventListener("message",function(e){o.readRaw(e.data)}),this.webSocket.addEventListener("open",function(e){o.emitter.emit("open",e)}),this.webSocket.addEventListener("error",function(e){o.emitter.emit("error",e)}),this.webSocket.addEventListener("close",function(e){o.emitter.emit("close",e)})}var r=e("./Connection.js");n.create=function(e,t,r){var i=new WebSocket(e,n.prototype.PROTOCOL_NAME);return new n(e,t,i,r)},n.prototype=Object.create(r.prototype),n.prototype.writeRaw=function(e){switch(this.webSocket.readyState){case WebSocket.CONNECTING:throw new Error("Can't send a message while WebSocket connecting");case WebSocket.OPEN:this.webSocket.send(e);break;case WebSocket.CLOSING:case WebSocket.CLOSED:throw new Error("Can't send a message while WebSocket is closing or closed")}},n.prototype.getReadyState=function(){switch(this.webSocket.readyState){case WebSocket.CONNECTING:return"connecting";case WebSocket.OPEN:return"open";case WebSocket.CLOSING:return"closing";case WebSocket.CLOSED:return"closed"}},t.exports=n},{"./Connection.js":10}],16:[function(t,n){(function(r){!function(e){"use strict";e(function(e){function t(e,t,n,r){return o(e).then(t,n,r)}function n(e){return new i(e,q.PromiseStatus&&q.PromiseStatus())}function i(e,t){function n(){return a?a.inspect():O()}function r(e,t,n,r,i){function o(o){o._when(e,t,n,r,i)}f?f.push(o):L(function(){o(a)})}function i(e){if(f){var n=f;f=K,L(function(){a=l(c,e),t&&m(a,t),u(n,a)})}}function o(e){i(new h(e))}function s(e){if(f){var t=f;L(function(){u(t,new d(e))})}}var c,a,f=[];c=this,this._status=t,this.inspect=n,this._when=r;try{e(i,o,s)}catch(p){o(p)}}function o(e){return e instanceof i?e:s(e)}function s(e){return n(function(t){t(e)})}function c(e){return t(e,function(e){return new h(e)})}function a(){function e(e,n,o){t.resolve=t.resolver.resolve=function(t){return i?s(t):(i=!0,e(t),r)},t.reject=t.resolver.reject=function(e){return i?s(new h(e)):(i=!0,n(e),r)},t.notify=t.resolver.notify=function(e){return o(e),e}}var t,r,i;return t={promise:K,resolve:K,reject:K,notify:K,resolver:{resolve:K,reject:K,notify:K}},t.promise=r=n(e),t}function u(e,t){for(var n=0;n<e.length;n++)e[n](t)}function l(e,t){if(t===e)return new h(new TypeError);if(t instanceof i)return t;try{var n=t===Object(t)&&t.then;return"function"==typeof n?f(n,t):new p(t)}catch(r){return new h(r)}}function f(e,t){return n(function(n,r){N(e,t,n,r)})}function p(e){this.value=e}function h(e){this.value=e}function d(e){this.value=e}function m(e,t){function n(){t.fulfilled()}function r(e){t.rejected(e)}e.then(n,r)}function y(e){return e&&"function"==typeof e.then}function v(e,r,i,o,s){return t(e,function(e){function c(n,i,o){function s(e){h(e)}function c(e){p(e)}var a,u,l,f,p,h,d,m;if(d=e.length>>>0,a=Math.max(0,Math.min(r,d)),l=[],u=d-a+1,f=[],a)for(h=function(e){f.push(e),--u||(p=h=j,i(f))},p=function(e){l.push(e),--a||(p=h=j,n(l))},m=0;d>m;++m)m in e&&t(e[m],c,s,o);else n(l)}return n(c).then(i,o,s)})}function g(e,t,n,r){function i(e){return t?t(e[0]):e[0]}return v(e,1,i,n,r)}function w(e,t,n,r){return k(e,j).then(t,n,r)}function b(){return k(arguments,j)}function E(e){return k(e,_,S)}function C(e,t){return k(e,t)}function k(e,n,r){return t(e,function(e){function o(i,o,s){function c(e,c){t(e,n,r).then(function(e){a[c]=e,--l||i(a)},o,s)}var a,u,l,f;if(l=u=e.length>>>0,a=[],!l)return void i(a);for(f=0;u>f;f++)f in e?c(e[f],f):--l}return new i(o)})}function R(e,n){var r=N(D,arguments,1);return t(e,function(e){var i;return i=e.length,r[0]=function(e,r,o){return t(e,function(e){return t(r,function(t){return n(e,t,o,i)})})},M.apply(e,r)})}function _(e){return{state:"fulfilled",value:e}}function S(e){return{state:"rejected",reason:e}}function O(){return{state:"pending"}}function L(e){1===I.push(e)&&F(T)}function T(){u(I),I=[]}function j(e){return e}function x(e){throw"function"==typeof q.reportUnhandled?q.reportUnhandled():L(function(){throw e}),e}t.promise=n,t.resolve=s,t.reject=c,t.defer=a,t.join=b,t.all=w,t.map=C,t.reduce=R,t.settle=E,t.any=g,t.some=v,t.isPromise=y,t.isPromiseLike=y,A=i.prototype,A.then=function(e,t,n){var r=this;return new i(function(i,o,s){r._when(i,s,e,t,n)},this._status&&this._status.observed())},A["catch"]=A.otherwise=function(e){return this.then(K,e)},A["finally"]=A.ensure=function(e){function t(){return s(e())}return"function"==typeof e?this.then(t,t)["yield"](this):this},A.done=function(e,t){this.then(e,t)["catch"](x)},A["yield"]=function(e){return this.then(function(){return e})},A.tap=function(e){return this.then(e)["yield"](this)},A.spread=function(e){return this.then(function(t){return w(t,function(t){return e.apply(K,t)})})},A.always=function(e,t){return this.then(e,e,t)},P=Object.create||function(e){function t(){}return t.prototype=e,new t},p.prototype=P(A),p.prototype.inspect=function(){return _(this.value)},p.prototype._when=function(e,t,n){try{e("function"==typeof n?n(this.value):this.value)}catch(r){e(new h(r))}},h.prototype=P(A),h.prototype.inspect=function(){return S(this.value)},h.prototype._when=function(e,t,n,r){try{e("function"==typeof r?r(this.value):this)}catch(i){e(new h(i))}},d.prototype=P(A),d.prototype._when=function(e,t,n,r,i){try{t("function"==typeof i?i(this.value):this.value)}catch(o){t(o)}};var A,P,M,D,N,F,I,W,G,U,q,Y,z,J,K;if(z=e,I=[],q="undefined"!=typeof console?console:t,"object"==typeof r&&r.nextTick)F=r.nextTick;else if(J="function"==typeof MutationObserver&&MutationObserver||"function"==typeof WebKitMutationObserver&&WebKitMutationObserver)F=function(e,t,n){var r=e.createElement("div");return new t(n).observe(r,{attributes:!0}),function(){r.setAttribute("x","x")}}(document,J,T);else try{F=z("vertx").runOnLoop||z("vertx").runOnContext}catch(B){Y=setTimeout,F=function(e){Y(e,0)}}return W=Function.prototype,G=W.call,N=W.bind?G.bind(G):function(e,t){return e.apply(t,D.call(arguments,2))},U=[],D=U.slice,M=U.reduce||function(e){var t,n,r,i,o;if(o=0,t=Object(this),i=t.length>>>0,n=arguments,n.length<=1)for(;;){if(o in t){r=t[o++];break}if(++o>=i)throw new TypeError}else r=n[1];for(;i>o;++o)o in t&&(r=e(r,t[o],o,t));return r},t})}("function"==typeof e&&e.amd?e:function(e){n.exports=e(t)})}).call(this,t("_process"))},{_process:3}],17:[function(e,t){t.exports=function(t,n){"use strict";function r(e,t){Object.keys(e).forEach(function(t){this[t]=e[t]}.bind(this)),t&&this.inject()}var i=e("./utils")(t,n);return r.closeAll=r.prototype.close=function(){var e=n.querySelector(".md-show");e&&(e.classList.remove("md-show"),i.trace("Closed modal")),setTimeout(function(){n.body.classList.remove("galaxy-overlayed"),i.trace("Hid overlay")},150)},r.injectOverlay=function(){if(i.trace("Injected overlay"),!n.querySelector(".md-overlay")){var e=n.createElement("div");e.className="md-overlay",n.body.appendChild(e),i.trace("Added overlay")}},r.prototype.html=function(){var e=n.createElement("div");return e.id="modal-"+this.id,e.className="md-modal md-effect-1 "+(this.classes||""),e.style.display="none",e.innerHTML='<div class="md-content"><h3>'+i.escape(this.title)+'</h3> <a class="md-close" title="Close"><span><div>Close</div></span></a><div>'+this.content+"</div></div>",i.trace("Created modal DOM"),e},r.prototype.inject=function(){return r.injectOverlay(),this.el=this.html(),t.setTimeout(function(){this.el.style.display="block"}.bind(this),150),n.body.appendChild(this.el),n.body.classList.add("galaxy-overlayed"),i.trace("Injected modal"),this.el},r.prototype.open=function(){return new Promise(function(){return i.trace("Opened modal"),this.el.classList.add("md-show")}.bind(this))},r}},{"./utils":19}],18:[function(e,t){t.exports={client:"/client.html"}},{}],19:[function(e,t){t.exports=function(e,t){"use strict";function n(t,n){console[n||"log"]((e.performance.now()/1e3).toFixed(3)+": "+t)}function r(e){return n(e,"error")}function i(e){return n(e,"warn")}function o(){"performance"in e||(e.performance={now:function(){return+new Date}}),"origin"in e.location||(e.location.origin=e.location.protocol+"//"+e.location.host)}function s(){return e.location.pathname.indexOf(".html")?e.location.search.substr(1):e.location.pathname.substr(1)}function c(e){return-1!==m.indexOf(e.target.nodeName.toLowerCase())}function a(){return"ontouchstart"in e||e.DocumentTouch&&t instanceof e.DocumentTouch}function u(e){var n=t.createElement("link");n.href=e.href,n.media="all",n.rel="stylesheet",n.type="text/css",Object.keys(e||{}).forEach(function(t){n[t]=e[t]}),t.querySelector("head").appendChild(n)}function l(e){return e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&#39;").replace(/"/g,"&#34;"):e}function f(){return!(t.fullscreenElement||t.mozFullScreenElement||t.webkitFullscreenElement||t.msFullscreenElement)}function p(){f()?(n("Entering full screen"),t.documentElement.requestFullscreen?t.documentElement.requestFullscreen():t.documentElement.mozRequestFullScreen?t.documentElement.mozRequestFullScreen():t.documentElement.webkitRequestFullscreen?t.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT):t.documentElement.msRequestFullscreen&&t.documentElement.msRequestFullscreen()):(n("Exiting full screen"),t.exitFullscreen?t.exitFullscreen():t.mozCancelFullScreen?t.mozCancelFullScreen():t.webkitExitFullscreen?t.webkitExitFullscreen():t.msExitFullscreen&&t.msExitFullscreen())
  }function h(t){return"lockOrientation"in e.screen?e.screen.lockOrientation(t):"mozLockOrientation"in e.screen?e.screen.mozLockOrientation(t):"webkitLockOrientation"in e.screen?e.screen.webkitLockOrientation(t):"msLockOrientation"in e.screen?e.screen.msLockOrientation(t):i("Orientation could not be locked")}function d(n){var r=t.createEvent("HTMLEvents");r.initEvent(n,!0,!0),r.eventName=n,(t.body||e).dispatchEvent(r)}var m=["input","keygen","meter","option","output","progress","select","textarea"];return{trace:n,error:r,warn:i,polyfill:o,getPeerKey:s,fieldFocused:c,hasTouchEvents:a,injectCSS:u,escape:l,isFullScreen:f,toggleFullScreen:p,lockOrientation:h,triggerEvent:d}}},{}],20:[function(e,t){"use strict";var n={};try{n=e("./settings_local.js")}catch(r){}var i=e("./lib/utils")(window,document);i.polyfill();var o={GAMEPAD_ORIGIN:window.location.origin,WS_URL:"ws://"+location.hostname+":20500/",DEBUG:!1,VERSION:"0.0.1"};Object.keys(n).forEach(function(e){o[e]=n[e]}),t.exports=o},{"./lib/utils":19,"./settings_local.js":21}],21:[function(e,t){t.exports={DEBUG:!0}},{}]},{},[1])(1)});