(()=>{var e={934(e){"use strict";var t=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:0,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.15;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.state=0,this.buffer=[],this.bufferTime=1e3*n,this.time=0,this.mode=t,this.originFrame=o(),this.position=new THREE.Vector3,this.quaternion=new THREE.Quaternion,this.scale=new THREE.Vector3(1,1,1)}return t(e,[{key:"hermite",value:function(e,t,n,o,i,r){var s=t*t,a=t*t*t,c=2*a-3*s+1,u=-2*a+3*s,l=a-2*s+t,h=a-s;e.copy(n.multiplyScalar(c)),e.add(o.multiplyScalar(u)),e.add(i.multiplyScalar(l)),e.add(r.multiplyScalar(h))}},{key:"lerp",value:function(e,t,n,o){e.lerpVectors(t,n,o)}},{key:"slerp",value:function(e,t,n,o){e.slerpQuaternions(t,n,o)}},{key:"updateOriginFrameToBufferTail",value:function(){var e;e=this.originFrame,n.push(e),this.originFrame=this.buffer.shift()}},{key:"appendBuffer",value:function(e,t,n,i){var r=this.buffer.length>0?this.buffer[this.buffer.length-1]:null;if(r&&r.time===this.time)e&&r.position.copy(e),t&&r.velocity.copy(t),n&&r.quaternion.copy(n),i&&r.scale.copy(i);else{var s=r||this.originFrame,a=o();a.position.copy(e||s.position),a.velocity.copy(t||s.velocity),a.quaternion.copy(n||s.quaternion),a.scale.copy(i||s.scale),a.time=this.time,this.buffer.push(a)}}},{key:"setTarget",value:function(e,t,n,o){this.appendBuffer(e,t,n,o)}},{key:"setPosition",value:function(e,t){this.appendBuffer(e,t,null,null)}},{key:"setQuaternion",value:function(e){this.appendBuffer(null,null,e,null)}},{key:"setScale",value:function(e){this.appendBuffer(null,null,null,e)}},{key:"update",value:function(e){if(0===this.state&&this.buffer.length>0&&(this.updateOriginFrameToBufferTail(),this.position.copy(this.originFrame.position),this.quaternion.copy(this.originFrame.quaternion),this.scale.copy(this.originFrame.scale),this.state=1),1===this.state&&this.buffer.length>0&&this.time>this.bufferTime&&(this.state=2),2===this.state){for(var t=this.time-this.bufferTime;this.buffer.length>0&&t>this.buffer[0].time;)this.buffer.length>1?this.updateOriginFrameToBufferTail():(this.originFrame.position.copy(this.buffer[0].position),this.originFrame.velocity.copy(this.buffer[0].velocity),this.originFrame.quaternion.copy(this.buffer[0].quaternion),this.originFrame.scale.copy(this.buffer[0].scale),this.originFrame.time=this.buffer[0].time,this.buffer[0].time=this.time+e);if(this.buffer.length>0&&this.buffer[0].time>0){var n=this.buffer[0],o=n.time-this.originFrame.time,i=(t-this.originFrame.time)/o;0===this.mode?this.lerp(this.position,this.originFrame.position,n.position,i):1===this.mode&&this.hermite(this.position,i,this.originFrame.position,n.position,this.originFrame.velocity.multiplyScalar(o),n.velocity.multiplyScalar(o)),this.slerp(this.quaternion,this.originFrame.quaternion,n.quaternion,i),this.lerp(this.scale,this.originFrame.scale,n.scale,i)}}0!==this.state&&(this.time+=e)}},{key:"getPosition",value:function(){return this.position}},{key:"getQuaternion",value:function(){return this.quaternion}},{key:"getScale",value:function(){return this.scale}}]),e}();e.exports=i},737(e){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function n(e,t){for(var n=0;n3&&void 0!==arguments[3]&&arguments[3],i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];NAF.app=t,NAF.room=n,this.adapter.setServerUrl(e),this.adapter.setApp(t),this.adapter.setRoom(n);var r={audio:o,video:i,datachannel:!0};return this.adapter.setWebRtcOptions(r),this.adapter.setServerConnectListeners(this.connectSuccess.bind(this),this.connectFailure.bind(this)),this.adapter.setDataChannelListeners(this.dataChannelOpen.bind(this),this.dataChannelClosed.bind(this),this.receivedData.bind(this)),this.adapter.setRoomOccupantListener(this.occupantsReceived.bind(this)),this.adapter.connect()}},{key:"onConnect",value:function(e){this.onConnectCallback=e,this.isConnected()?e():document.body.addEventListener("connected",e,!1)}},{key:"connectSuccess",value:function(e){NAF.log.write("Networked-Aframe Client ID:",e),NAF.clientId=e;var t=new CustomEvent("connected",{detail:{clientId:e}});document.body.dispatchEvent(t)}},{key:"connectFailure",value:function(e,t){NAF.log.error(e,"failure to connect")}},{key:"occupantsReceived",value:function(e){var t=Object.assign({},this.connectedClients);this.connectedClients=e,this.checkForDisconnectingClients(t,e),this.checkForConnectingClients(e)}},{key:"checkForDisconnectingClients",value:function(e,t){for(var n in e)t[n]||(NAF.log.write("Closing stream to",n),this.adapter.closeStreamConnection(n))}},{key:"checkForConnectingClients",value:function(e){for(var t in e)this.isNewClient(t)&&this.adapter.shouldStartConnectionTo(e[t])&&(NAF.log.write("Opening datachannel to",t),this.adapter.startStreamConnection(t))}},{key:"getConnectedClients",value:function(){return this.connectedClients}},{key:"isConnected",value:function(){return!!NAF.clientId}},{key:"isMineAndConnected",value:function(e){return this.isConnected()&&NAF.clientId===e}},{key:"isNewClient",value:function(e){return!this.isConnectedTo(e)}},{key:"isConnectedTo",value:function(e){return this.adapter.getConnectStatus(e)===NAF.adapters.IS_CONNECTED}},{key:"dataChannelOpen",value:function(e){NAF.log.write("Opened data channel from "+e),this.activeDataChannels[e]=!0,this.entities.completeSync(e,!0);var t=new CustomEvent("clientConnected",{detail:{clientId:e}});document.body.dispatchEvent(t)}},{key:"dataChannelClosed",value:function(e){NAF.log.write("Closed data channel from "+e),this.activeDataChannels[e]=!1,this.entities.removeEntitiesOfClient(e);var t=new CustomEvent("clientDisconnected",{detail:{clientId:e}});document.body.dispatchEvent(t)}},{key:"hasActiveDataChannel",value:function(e){return!!this.activeDataChannels[e]}},{key:"broadcastData",value:function(e,t){this.adapter.broadcastData(e,t)}},{key:"broadcastDataGuaranteed",value:function(e,t){this.adapter.broadcastDataGuaranteed(e,t)}},{key:"sendData",value:function(e,t,n,o){this.hasActiveDataChannel(e)&&(o?this.adapter.sendDataGuaranteed(e,t,n):this.adapter.sendData(e,t,n))}},{key:"sendDataGuaranteed",value:function(e,t,n){this.sendData(e,t,n,!0)}},{key:"subscribeToDataChannel",value:function(e,t){this.isReservedDataType(e)?NAF.log.error("NetworkConnection@subscribeToDataChannel: "+e+" is a reserved dataType. Choose another"):this.dataChannelSubs[e]=t}},{key:"unsubscribeToDataChannel",value:function(e){this.isReservedDataType(e)?NAF.log.error("NetworkConnection@unsubscribeToDataChannel: "+e+" is a reserved dataType. Choose another"):delete this.dataChannelSubs[e]}},{key:"isReservedDataType",value:function(e){return"u"==e||"r"==e}},{key:"receivedData",value:function(e,t,n,o){this.dataChannelSubs[t]?this.dataChannelSubs[t](e,t,n,o):NAF.log.write("NetworkConnection@receivedData: "+t+" has not been subscribed to yet. Call subscribeToDataChannel()")}},{key:"getServerTime",value:function(){return this.adapter.getServerTime()}},{key:"disconnect",value:function(){this.entities.removeRemoteEntities(),this.adapter&&this.adapter.disconnect(),NAF.app="",NAF.room="",NAF.clientId="",this.connectedClients={},this.activeDataChannels={},this.adapter=null,this.setupDefaultDataSubscriptions(),document.body.removeEventListener("connected",this.onConnectCallback)}}],t&&n(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();e.exports=i},815(e,t,n){function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function i(e,t){for(var n=0;n is defined."));if(!this.validateTemplate(e,t))return;this.templateCache[e.template]=document.importNode(t.content,!0)}else NAF.log.error("Schema not valid: ",e),NAF.log.error("See https://github.com/networked-aframe/networked-aframe#syncing-custom-components")}},{key:"getCachedTemplate",value:function(e){return this.templateIsCached(e)||(this.templateExistsInScene(e)?this.add(this.createDefaultSchema(e)):NAF.log.error("Template el for ".concat(e," is not in the scene, add the template to and register with NAF.schemas.add."))),this.templateCache[e].firstElementChild.cloneNode(!0)}},{key:"templateIsCached",value:function(e){return!!this.templateCache[e]}},{key:"getComponents",value:function(e){var t=["position","rotation"];return this.hasTemplate(e)&&(t=this.schemaDict[e].components),t}},{key:"hasTemplate",value:function(e){return!!this.schemaDict[e]}},{key:"templateExistsInScene",value:function(e){var t=document.querySelector(e);return t&&this.isTemplateTag(t)}},{key:"validateSchema",value:function(e){return!(!e.template||!e.components)}},{key:"validateTemplate",value:function(e,t){return this.isTemplateTag(t)?!!this.templateHasOneOrZeroChildren(t)||(NAF.log.error("Template for ".concat(e.template," has more than one child. Templates must have one direct child element, no more. Template found:"),t),!1):(NAF.log.error("Template for ".concat(e.template," is not a