diff options
Diffstat (limited to 'public/vendor/networked-aframe-0.14.3.min.js')
| -rw-r--r-- | public/vendor/networked-aframe-0.14.3.min.js | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/public/vendor/networked-aframe-0.14.3.min.js b/public/vendor/networked-aframe-0.14.3.min.js new file mode 100644 index 0000000..0f512c9 --- /dev/null +++ b/public/vendor/networked-aframe-0.14.3.min.js @@ -0,0 +1 @@ +(()=>{var e={934(e){"use strict";var t=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),n=[],o=function(){var e=n.pop();return e||(e={position:new THREE.Vector3,velocity:new THREE.Vector3,scale:new THREE.Vector3,quaternion:new THREE.Quaternion,time:0}),e},i=function(){function e(){var t=arguments.length>0&&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;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,o(i.key),i)}}function o(e){var n=function(e){if("object"!=t(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,"string");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(n)?n:n+""}var i=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.dict={}},(t=[{key:"addChild",value:function(e,t){this.hasParent(e)||(this.dict[e]=[]),this.dict[e].push(t)}},{key:"getChildren",value:function(e){if(!this.hasParent(e))return[];var t=this.dict[e];return delete this.dict[e],t}},{key:"hasParent",value:function(e){return!!this.dict[e]}}])&&n(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();e.exports=i},451(e){"use strict";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)}var n=Array.isArray,o=Object.keys,i=Object.prototype.hasOwnProperty;e.exports=function e(r,s){if(r===s)return!0;if(r&&s&&"object"==t(r)&&"object"==t(s)){var a,c,u,l=n(r),h=n(s);if(l&&h){if((c=r.length)!=s.length)return!1;for(a=c;0!==a--;)if(!e(r[a],s[a]))return!1;return!0}if(l!=h)return!1;var d=r instanceof Date,f=s instanceof Date;if(d!=f)return!1;if(d&&f)return r.getTime()==s.getTime();var p=r instanceof RegExp,m=s instanceof RegExp;if(p!=m)return!1;if(p&&m)return r.toString()==s.toString();var v=o(r);if((c=v.length)!==o(s).length)return!1;for(a=c;0!==a--;)if(!i.call(s,v[a]))return!1;for(a=c;0!==a--;)if(!e(r[u=v[a]],s[u]))return!1;return!0}return r!=r&&s!=s}},199(e,t,n){var o=n(172),i=n(347),r=n(759),s=n(758),a=n(815),c=n(192),u=n(724),l={app:"",room:"",clientId:""};l.options=o,l.utils=i,l.log=new r,l.schemas=new s,l.version="0.14.3",l.adapters=new u;var h=new a,d=new c(h);l.connection=d,l.entities=h,e.exports=window.NAF=l},564(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;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,o(i.key),i)}}function o(e){var n=function(e){if("object"!=t(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,"string");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(n)?n:n+""}var i=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)},(t=[{key:"notImplemented",value:function(e){NAF.log.error("Interface method not implemented:",e)}}])&&n(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();e.exports=i},759(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;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,o(i.key),i)}}function o(e){var n=function(e){if("object"!=t(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,"string");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(n)?n:n+""}var i=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.debug=!1},t=[{key:"setDebug",value:function(e){this.debug=e}},{key:"write",value:function(){this.debug&&console.log.apply(this,arguments)}},{key:"warn",value:function(){console.warn.apply(this,arguments)}},{key:"error",value:function(){console.error.apply(this,arguments)}}],t&&n(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();e.exports=i},192(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;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,o(i.key),i)}}function o(e){var n=function(e){if("object"!=t(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,"string");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(n)?n:n+""}var i=function(){return e=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.entities=t,this.setupDefaultDataSubscriptions(),this.connectedClients={},this.activeDataChannels={}},t=[{key:"setNetworkAdapter",value:function(e){this.adapter=e}},{key:"setupDefaultDataSubscriptions",value:function(){this.dataChannelSubs={},this.dataChannelSubs.u=this.entities.updateEntity.bind(this.entities),this.dataChannelSubs.um=this.entities.updateEntityMulti.bind(this.entities),this.dataChannelSubs.r=this.entities.removeRemoteEntity.bind(this.entities)}},{key:"connect",value:function(e,t,n){var o=arguments.length>3&&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<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,r(o.key),o)}}function r(e){var t=function(e){if("object"!=o(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=o(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==o(t)?t:t+""}var s=n(737),a=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.entities={},this.childCache=new s,this.onRemoteEntityCreatedEvent=new Event("remoteEntityCreated"),this._persistentFirstSyncs={}},(t=[{key:"registerEntity",value:function(e,t){this.entities[e]=t}},{key:"createRemoteEntity",value:function(e){NAF.log.write("Creating remote entity",e);var t=e.networkId,n=NAF.schemas.getCachedTemplate(e.template);return this.initPosition(n,e.components),this.initRotation(n,e.components),this.addNetworkComponent(n,e),this.registerEntity(t,n),n}},{key:"initPosition",value:function(e,t){if(t.position){var n=t.position;e.setAttribute("position",n)}}},{key:"initRotation",value:function(e,t){if(t.rotation){var n=t.rotation;e.setAttribute("rotation",n)}}},{key:"addNetworkComponent",value:function(e,t){var n={template:t.template,creator:t.creator,owner:t.owner,networkId:t.networkId,persistent:t.persistent};e.setAttribute("networked",n),e.firstUpdateData=t}},{key:"updateEntityMulti",value:function(e,t,n,o){if(!NAF.options.syncSource||o===NAF.options.syncSource)for(var i=0,r=n.d.length;i<r;i++)this.updateEntity(e,"u",n.d[i],o)}},{key:"updateEntity",value:function(e,t,n,o){if(!NAF.options.syncSource||o===NAF.options.syncSource){var i=n.networkId;this.hasEntity(i)?this.entities[i].components.networked.networkUpdate(n):n.isFirstSync&&!1!==NAF.connection.activeDataChannels[n.owner]&&(NAF.options.firstSyncSource&&o!==NAF.options.firstSyncSource?NAF.log.write("Ignoring first sync from disallowed source",o):n.persistent?this._persistentFirstSyncs[i]=n:this.receiveFirstUpdateFromEntity(n))}}},{key:"receiveFirstUpdateFromEntity",value:function(e){var t=e.parent,n=e.networkId;if(t&&!this.hasEntity(t))this.childCache.addChild(t,e);else{var o=this.createRemoteEntity(e);this.createAndAppendChildren(n,o),this.addEntityToPage(o,t)}}},{key:"createAndAppendChildren",value:function(e,t){for(var n=this.childCache.getChildren(e),o=0;o<n.length;o++){var i=n[o],r=i.networkId;if(this.hasEntity(r))NAF.log.warn("Tried to instantiate entity multiple times",r,i,"Existing entity:",this.getEntity(r));else{var s=this.createRemoteEntity(i);this.createAndAppendChildren(r,s),t.appendChild(s)}}}},{key:"addEntityToPage",value:function(e,t){this.hasEntity(t)?this.addEntityToParent(e,t):this.addEntityToSceneRoot(e)}},{key:"addEntityToParent",value:function(e,t){this.entities[t].appendChild(e)}},{key:"addEntityToSceneRoot",value:function(e){document.querySelector("a-scene").appendChild(e)}},{key:"completeSync",value:function(e,t){for(var n in this.entities)this.entities[n]&&this.entities[n].components.networked.syncAll(e,t)}},{key:"removeRemoteEntity",value:function(e,t,n,o){if(!NAF.options.syncSource||o===NAF.options.syncSource){var i=n.networkId;return this.removeEntity(i)}}},{key:"removeEntitiesOfClient",value:function(e){var t=[];for(var n in this.entities){var o=this.entities[n],i=NAF.utils.getCreator(o),r=NAF.utils.getNetworkOwner(o);if(i===e||!i&&r===e){var s=this.entities[n].getAttribute("networked");s&&s.persistent?NAF.utils.takeOwnership(o):t.push(this.removeEntity(n))}}return t}},{key:"removeEntity",value:function(e){if(this.forgetPersistentFirstSync(e),this.hasEntity(e)){var t=this.entities[e];return this.forgetEntity(e),t.parentNode.removeChild(t),t}return NAF.log.error("Tried to remove entity I don't have."),null}},{key:"forgetEntity",value:function(e){delete this.entities[e],this.forgetPersistentFirstSync(e)}},{key:"getPersistentFirstSync",value:function(e){return this._persistentFirstSyncs[e]}},{key:"forgetPersistentFirstSync",value:function(e){delete this._persistentFirstSyncs[e]}},{key:"getEntity",value:function(e){return this.entities[e]?this.entities[e]:null}},{key:"hasEntity",value:function(e){return!!this.entities[e]}},{key:"removeRemoteEntities",value:function(){for(var e in this.childCache=new s,this.entities)this.entities[e].getAttribute("networked").owner!=NAF.clientId&&this.removeEntity(e)}}])&&i(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();e.exports=a},758(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;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,o(i.key),i)}}function o(e){var n=function(e){if("object"!=t(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,"string");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(n)?n:n+""}var i=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.schemaDict={},this.templateCache={}},(t=[{key:"createDefaultSchema",value:function(e){return{template:e,components:["position","rotation"]}}},{key:"add",value:function(e){if(this.validateSchema(e)){this.schemaDict[e.template]=e;var t=document.querySelector(e.template);if(!t)return void NAF.log.error("Template el not found for ".concat(e.template,", make sure NAF.schemas.add is called after <a-scene> 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 <a-assets> 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 <template> tag. Instead found: ").concat(t.tagName)),!1)}},{key:"isTemplateTag",value:function(e){return"template"===e.tagName.toLowerCase()}},{key:"templateHasOneOrZeroChildren",value:function(e){return e.content.childElementCount<2}},{key:"remove",value:function(e){delete this.schemaDict[e]}},{key:"clear",value:function(){this.schemaDict={}}}])&&n(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();e.exports=i},724(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<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,r(o.key),o)}}function r(e){var t=function(e){if("object"!=o(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=o(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==o(t)?t:t+""}var s=n(689),a=n(115),c=n(692),u=n(672),l=n(844),h=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.adapters={wseasyrtc:s,easyrtc:a,socketio:u,webrtc:c,uws:l},this.IS_CONNECTED=e.IS_CONNECTED,this.CONNECTING=e.CONNECTING,this.NOT_CONNECTED=e.NOT_CONNECTED},(t=[{key:"register",value:function(e,t){this.adapters[e]=t}},{key:"make",value:function(e){var t=e.toLowerCase();if(this.adapters[t])return new(0,this.adapters[t]);throw new Error("Adapter: "+e+" not registered. Please use NAF.adapters.register() to register this adapter.")}}])&&i(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();h.IS_CONNECTED="IS_CONNECTED",h.CONNECTING="CONNECTING",h.NOT_CONNECTED="NOT_CONNECTED",e.exports=h},115(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){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function r(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,s(o.key),o)}}function s(e){var t=function(e){if("object"!=o(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=o(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==o(t)?t:t+""}function a(e,t,n){return t=u(t),function(e,t){if(t&&("object"==o(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,c()?Reflect.construct(t,n||[],u(e).constructor):t.apply(e,n))}function c(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(c=function(){return!!e})()}function u(e){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},u(e)}function l(e,t){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},l(e,t)}var h=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=a(this,t)).easyrtc=e||window.easyrtc,n.app="default",n.room="default",n.destination={targetRoom:n.room},n.mediaStreams={},n.remoteClients={},n.pendingMediaRequests=new Map,n.serverTimeRequests=0,n.timeOffsets=[],n.avgTimeOffset=0,n.easyrtc.setPeerOpenListener(function(e){var t=n.easyrtc.getPeerConnectionByUserId(e);n.remoteClients[e]=t}),n.easyrtc.setPeerClosedListener(function(e){delete n.remoteClients[e];var t=n.pendingMediaRequests.get(e);t&&(Object.keys(t).forEach(function(e){t[e].reject("The user disconnected before the media stream was resolved.")}),n.pendingMediaRequests.delete(e))}),n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&l(e,t)}(t,e),n=t,o=[{key:"setServerUrl",value:function(e){this.easyrtc.setSocketUrl(e)}},{key:"setApp",value:function(e){this.app=e}},{key:"setRoom",value:function(e){this.room=e,this.destination.targetRoom=this.room}},{key:"setWebRtcOptions",value:function(e){this.easyrtc.enableDataChannels(e.datachannel),this.easyrtc.enableVideo(e.video),this.easyrtc.enableAudio(e.audio),this.easyrtc.enableVideoReceive(!0),this.easyrtc.enableAudioReceive(!0)}},{key:"setServerConnectListeners",value:function(e,t){this.connectSuccess=e,this.connectFailure=t}},{key:"setRoomOccupantListener",value:function(e){var t=this;this.easyrtc.setRoomOccupantListener(function(n,o,i){n===t.room&&e(o)})}},{key:"setDataChannelListeners",value:function(e,t,n){this.easyrtc.setDataChannelOpenListener(e),this.easyrtc.setDataChannelCloseListener(t),this.easyrtc.setPeerListener(n)}},{key:"updateTimeOffset",value:function(){var e=this,t=Date.now()+this.avgTimeOffset;return fetch(document.location.href,{method:"HEAD",cache:"no-cache"}).then(function(n){var o=new Date(n.headers.get("Date")).getTime()+500,i=Date.now(),r=o+(i-t)/2-i;e.serverTimeRequests++,e.serverTimeRequests<=10?e.timeOffsets.push(r):e.timeOffsets[e.serverTimeRequests%10]=r,e.avgTimeOffset=e.timeOffsets.reduce(function(e,t){return e+t},0)/e.timeOffsets.length,e.serverTimeRequests>10?setTimeout(function(){return e.updateTimeOffset()},3e5):e.updateTimeOffset()})}},{key:"connect",value:function(){var e=this;Promise.all([this.updateTimeOffset(),new Promise(function(t,n){e._connect(t,n)})]).then(function(t){var n=function(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,i,r,s,a=[],c=!0,u=!1;try{if(r=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(o=r.call(n)).done)&&(a.push(o.value),a.length!==t);c=!0);}catch(e){u=!0,i=e}finally{try{if(!c&&null!=n.return&&(s=n.return(),Object(s)!==s))return}finally{if(u)throw i}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(t,2),o=(n[0],n[1]);e.easyrtc.joinRoom(e.room,null,function(){e.connectSuccess(o)},function(t,n){e.connectFailure(t,n)})}).catch(this.connectFailure)}},{key:"shouldStartConnectionTo",value:function(e){return void 0===this._myRoomJoinTime&&(this._myRoomJoinTime=this._getRoomJoinTime(this.easyrtc.myEasyrtcid)),this._myRoomJoinTime<=e.roomJoinTime}},{key:"startStreamConnection",value:function(e){this.easyrtc.call(e,function(e,t){"datachannel"===t&&NAF.log.write("Successfully started datachannel to ",e)},function(e,t){NAF.log.error(e,t)},function(e){})}},{key:"closeStreamConnection",value:function(e){this.easyrtc.hangup(e)}},{key:"sendData",value:function(e,t,n){this.easyrtc.sendData(e,t,n)}},{key:"sendDataGuaranteed",value:function(e,t,n){this.easyrtc.sendDataWS(e,t,n)}},{key:"broadcastData",value:function(e,t){var n=this.easyrtc.getRoomOccupantsAsMap(this.room);for(var o in n)n[o]&&o!==this.easyrtc.myEasyrtcid&&this.easyrtc.sendData(o,e,t)}},{key:"broadcastDataGuaranteed",value:function(e,t){this.easyrtc.sendDataWS(this.destination,e,t)}},{key:"getConnectStatus",value:function(e){var t=this.easyrtc.getConnectStatus(e);return t==this.easyrtc.IS_CONNECTED?NAF.adapters.IS_CONNECTED:t==this.easyrtc.NOT_CONNECTED?NAF.adapters.NOT_CONNECTED:NAF.adapters.CONNECTING}},{key:"getMediaStream",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"audio";if(this.mediaStreams[e]&&this.mediaStreams[e][t])return NAF.log.write("Already had ".concat(t," for ").concat(e)),Promise.resolve(this.mediaStreams[e][t]);if(NAF.log.write("Waiting on ".concat(t," for ").concat(e)),!this.pendingMediaRequests.has(e)){var n={},o=new Promise(function(e,t){n.audio={resolve:e,reject:t}}).catch(function(t){return NAF.log.warn("".concat(e," getMediaStream Audio Error"),t)});n.audio.promise=o;var i=new Promise(function(e,t){n.video={resolve:e,reject:t}}).catch(function(t){return NAF.log.warn("".concat(e," getMediaStream Video Error"),t)});n.video.promise=i,this.pendingMediaRequests.set(e,n)}var r=this.pendingMediaRequests.get(e);if(!r[t]){var s=new Promise(function(e,n){r[t]={resolve:e,reject:n}}).catch(function(n){return NAF.log.warn("".concat(e,' getMediaStream "').concat(t,'" Error'),n)});r[t].promise=s}return this.pendingMediaRequests.get(e)[t].promise}},{key:"setMediaStream",value:function(e,t,n){var o=this.pendingMediaRequests.get(e),i=this.mediaStreams[e]=this.mediaStreams[e]||{};if("default"===n){var r=t.getAudioTracks();if(r.length>0){var s=new MediaStream;try{r.forEach(function(e){return s.addTrack(e)}),i.audio=s}catch(t){NAF.log.warn("".concat(e,' setMediaStream "audio" alias Error'),t)}o&&o.audio.resolve(s)}var a=t.getVideoTracks();if(a.length>0){var c=new MediaStream;try{a.forEach(function(e){return c.addTrack(e)}),i.video=c}catch(t){NAF.log.warn("".concat(e,' setMediaStream "video" alias Error'),t)}o&&o.video.resolve(c)}}else i[n]=t,o&&o[n]&&(o[n].resolve(t),delete o[n])}},{key:"addLocalMediaStream",value:function(e,t){var n=this.easyrtc;t=t||e.id,this.setMediaStream("local",e,t),n.register3rdPartyLocalMediaStream(e,t),Object.keys(this.remoteClients).forEach(function(e){n.getConnectStatus(e)!==n.NOT_CONNECTED&&n.addStreamToCall(e,t)})}},{key:"removeLocalMediaStream",value:function(e){this.easyrtc.closeLocalMediaStream(e),delete this.mediaStreams.local[e]}},{key:"enableMicrophone",value:function(e){this.easyrtc.enableMicrophone(e)}},{key:"enableCamera",value:function(e){this.easyrtc.enableCamera(e)}},{key:"disconnect",value:function(){this.easyrtc.disconnect()}},{key:"_connect",value:function(e,t){var n=this;this.easyrtc.setStreamAcceptor(this.setMediaStream.bind(this)),this.easyrtc.setOnStreamClosed(function(e,t,o){"default"===o?(delete n.mediaStreams[e].audio,delete n.mediaStreams[e].video):delete n.mediaStreams[e][o],0===Object.keys(n.mediaStreams[e]).length&&delete n.mediaStreams[e]}),n.easyrtc.audioEnabled||n.easyrtc.videoEnabled?navigator.mediaDevices.getUserMedia({video:n.easyrtc.videoEnabled,audio:n.easyrtc.audioEnabled}).then(function(o){n.addLocalMediaStream(o,"default"),n.easyrtc.connect(n.app,e,t)},function(e,t){NAF.log.error(e,t)}):n.easyrtc.connect(n.app,e,t)}},{key:"_getRoomJoinTime",value:function(e){var t=NAF.room;return this.easyrtc.getRoomOccupantsAsMap(t)[e].roomJoinTime}},{key:"getServerTime",value:function(){return Date.now()+this.avgTimeOffset}}],o&&r(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o}(n(632));e.exports=h},632(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<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,r(o.key),o)}}function r(e){var t=function(e){if("object"!=o(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=o(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==o(t)?t:t+""}function s(e,t,n){return t=c(t),function(e,t){if(t&&("object"==o(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,a()?Reflect.construct(t,n||[],c(e).constructor):t.apply(e,n))}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},c(e)}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}var l=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),s(this,t,arguments)}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&u(e,t)}(t,e),n=t,(o=[{key:"setServerUrl",value:function(e){this.notImplemented("setServerUrl")}},{key:"setApp",value:function(e){this.notImplemented("setApp")}},{key:"setRoom",value:function(e){this.notImplemented("setRoom")}},{key:"setWebRtcOptions",value:function(e){this.notImplemented("setWebRtcOptions")}},{key:"setServerConnectListeners",value:function(e,t){this.notImplemented("setServerConnectListeners")}},{key:"setRoomOccupantListener",value:function(e){this.notImplemented("setRoomOccupantListener")}},{key:"setDataChannelListeners",value:function(e,t,n){this.notImplemented("setDataChannelListeners")}},{key:"connect",value:function(){this.notImplemented("connect")}},{key:"shouldStartConnectionTo",value:function(e){this.notImplemented("shouldStartConnectionTo")}},{key:"startStreamConnection",value:function(e){this.notImplemented("startStreamConnection")}},{key:"closeStreamConnection",value:function(e){this.notImplemented("closeStreamConnection")}},{key:"getConnectStatus",value:function(e){this.notImplemented("getConnectStatus")}},{key:"getMediaStream",value:function(e){return Promise.reject("Interface method not implemented: getMediaStream")}},{key:"getServerTime",value:function(){this.notImplemented("getServerTime")}},{key:"sendData",value:function(e,t,n){this.notImplemented("sendData")}},{key:"sendDataGuaranteed",value:function(e,t,n){this.notImplemented("sendDataGuaranteed")}},{key:"broadcastData",value:function(e,t){this.notImplemented("broadcastData")}},{key:"broadcastDataGuaranteed",value:function(e,t){this.notImplemented("broadcastDataGuaranteed")}},{key:"disconnect",value:function(){this.notImplemented("disconnect")}}])&&i(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o}(n(564));e.exports=l},689(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){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function r(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,s(o.key),o)}}function s(e){var t=function(e){if("object"!=o(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=o(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==o(t)?t:t+""}function a(e,t,n){return t=u(t),function(e,t){if(t&&("object"==o(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,c()?Reflect.construct(t,n||[],u(e).constructor):t.apply(e,n))}function c(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(c=function(){return!!e})()}function u(e){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},u(e)}function l(e,t){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},l(e,t)}var h=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=a(this,t)).easyrtc=e||window.easyrtc,n.app="default",n.room="default",n.destination={targetRoom:n.room},n.connectedClients=[],n.serverTimeRequests=0,n.timeOffsets=[],n.avgTimeOffset=0,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&l(e,t)}(t,e),n=t,(o=[{key:"setServerUrl",value:function(e){this.serverUrl=e,this.easyrtc.setSocketUrl(e)}},{key:"setApp",value:function(e){this.app=e}},{key:"setRoom",value:function(e){this.room=e,this.destination.targetRoom=this.room}},{key:"setWebRtcOptions",value:function(e){}},{key:"setServerConnectListeners",value:function(e,t){this.connectSuccess=e,this.connectFailure=t}},{key:"setRoomOccupantListener",value:function(e){var t=this;this.easyrtc.setRoomOccupantListener(function(n,o,i){n===t.room&&e(o)})}},{key:"setDataChannelListeners",value:function(e,t,n){this.openListener=e,this.closedListener=t,this.easyrtc.setPeerListener(n)}},{key:"updateTimeOffset",value:function(){var e=this,t=Date.now()+this.avgTimeOffset;return fetch(document.location.href,{method:"HEAD",cache:"no-cache"}).then(function(n){var o=new Date(n.headers.get("Date")).getTime()+500,i=Date.now(),r=o+(i-t)/2-i;e.serverTimeRequests++,e.serverTimeRequests<=10?e.timeOffsets.push(r):e.timeOffsets[e.serverTimeRequests%10]=r,e.avgTimeOffset=e.timeOffsets.reduce(function(e,t){return e+t},0)/e.timeOffsets.length,e.serverTimeRequests>10?setTimeout(function(){return e.updateTimeOffset()},3e5):e.updateTimeOffset()})}},{key:"connect",value:function(){var e=this;Promise.all([this.updateTimeOffset(),new Promise(function(t,n){e.easyrtc.connect(e.app,t,n)})]).then(function(t){var n=function(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,i,r,s,a=[],c=!0,u=!1;try{if(r=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(o=r.call(n)).done)&&(a.push(o.value),a.length!==t);c=!0);}catch(e){u=!0,i=e}finally{try{if(!c&&null!=n.return&&(s=n.return(),Object(s)!==s))return}finally{if(u)throw i}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(t,2),o=(n[0],n[1]);e.easyrtc.joinRoom(e.room,null,function(){e.connectSuccess(o)},function(t,n){e.connectFailure(t,n)})}).catch(this.connectFailure)}},{key:"shouldStartConnectionTo",value:function(e){return!0}},{key:"startStreamConnection",value:function(e){this.connectedClients.push(e),this.openListener(e)}},{key:"closeStreamConnection",value:function(e){var t=this.connectedClients.indexOf(e);t>-1&&this.connectedClients.splice(t,1),this.closedListener(e)}},{key:"sendData",value:function(e,t,n){this.easyrtc.sendDataWS(e,t,n)}},{key:"sendDataGuaranteed",value:function(e,t,n){this.sendData(e,t,n)}},{key:"broadcastData",value:function(e,t){this.easyrtc.sendDataWS(this.destination,e,t)}},{key:"broadcastDataGuaranteed",value:function(e,t){this.broadcastData(e,t)}},{key:"getConnectStatus",value:function(e){return-1!=this.connectedClients.indexOf(e)?NAF.adapters.IS_CONNECTED:NAF.adapters.NOT_CONNECTED}},{key:"getServerTime",value:function(){return Date.now()+this.avgTimeOffset}},{key:"disconnect",value:function(){this.easyrtc.disconnect()}}])&&r(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o}(n(632));e.exports=h},672(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;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,o(i.key),i)}}function o(e){var n=function(e){if("object"!=t(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,"string");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(n)?n:n+""}var i=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),void 0===io&&console.warn("It looks like socket.io has not been loaded before SocketioAdapter. Please do that."),this.app="default",this.room="default",this.occupantListener=null,this.myRoomJoinTime=null,this.myId=null,this.packet={from:void 0,to:void 0,type:void 0,data:void 0},this.occupants={},this.connectedClients=[],this.serverTimeRequests=0,this.timeOffsets=[],this.avgTimeOffset=0},(t=[{key:"setServerUrl",value:function(e){this.wsUrl=e}},{key:"setApp",value:function(e){this.app=e}},{key:"setRoom",value:function(e){this.room=e}},{key:"setWebRtcOptions",value:function(e){}},{key:"setServerConnectListeners",value:function(e,t){this.connectSuccess=e,this.connectFailure=t}},{key:"setRoomOccupantListener",value:function(e){this.occupantListener=e}},{key:"setDataChannelListeners",value:function(e,t,n){this.openListener=e,this.closedListener=t,this.messageListener=n}},{key:"connect",value:function(){var e=this,t=this;this.updateTimeOffset().then(function(){t.wsUrl&&"/"!==t.wsUrl||("https:"===location.protocol?t.wsUrl="wss://"+location.host:t.wsUrl="ws://"+location.host),NAF.log.write("Attempting to connect to socket.io");var n=t.socket=io(t.wsUrl);function o(e){var n=e.from,o=e.type,i=e.data;t.messageListener(n,o,i)}n.on("connect",function(){NAF.clientId&&t.onDisconnect(),NAF.log.write("User connected",n.id),t.myId=n.id,t.joinRoom()}),n.on("connectSuccess",function(e){var n=e.joinedTime;t.myRoomJoinTime=n,NAF.log.write("Successfully joined room",t.room,"at server time",n),t.connectSuccess(t.myId)}),n.io.on("error",function(t){console.error("Socket connection failure",t),e.onDisconnect()}),n.on("occupantsChanged",function(e){var n=e.occupants;NAF.log.write("occupants changed",e),t.receivedOccupants(n)}),n.on("send",o),n.on("broadcast",o)})}},{key:"joinRoom",value:function(){NAF.log.write("Joining room",this.room),this.socket.emit("joinRoom",{room:this.room})}},{key:"receivedOccupants",value:function(e){delete e[this.myId],this.occupants=e,this.occupantListener(e)}},{key:"shouldStartConnectionTo",value:function(e){return!0}},{key:"startStreamConnection",value:function(e){this.connectedClients.push(e),this.openListener(e)}},{key:"closeStreamConnection",value:function(e){this.connectedClients=this.connectedClients.filter(function(t){return t!==e}),this.closedListener(e)}},{key:"getConnectStatus",value:function(e){return-1!==this.connectedClients.indexOf(e)?NAF.adapters.IS_CONNECTED:NAF.adapters.NOT_CONNECTED}},{key:"sendData",value:function(e,t,n){this.sendDataGuaranteed(e,t,n)}},{key:"sendDataGuaranteed",value:function(e,t,n){this.packet.from=this.myId,this.packet.to=e,this.packet.type=t,this.packet.data=n,this.socket?this.socket.emit("send",this.packet):NAF.log.warn("SocketIO socket not created yet")}},{key:"broadcastData",value:function(e,t){this.broadcastDataGuaranteed(e,t)}},{key:"broadcastDataGuaranteed",value:function(e,t){this.packet.from=this.myId,this.packet.to=void 0,this.packet.type=e,this.packet.data=t,this.socket?this.socket.emit("broadcast",this.packet):NAF.log.warn("SocketIO socket not created yet")}},{key:"getMediaStream",value:function(e){return Promise.reject("Interface method not implemented: getMediaStream")}},{key:"updateTimeOffset",value:function(){var e=this,t=Date.now()+this.avgTimeOffset;return fetch(document.location.href,{method:"HEAD",cache:"no-cache"}).then(function(n){var o=new Date(n.headers.get("Date")).getTime()+500,i=Date.now(),r=o+(i-t)/2-i;e.serverTimeRequests++,e.serverTimeRequests<=10?e.timeOffsets.push(r):e.timeOffsets[e.serverTimeRequests%10]=r,e.avgTimeOffset=e.timeOffsets.reduce(function(e,t){return e+t},0)/e.timeOffsets.length,e.serverTimeRequests>10?setTimeout(function(){return e.updateTimeOffset()},3e5):e.updateTimeOffset()})}},{key:"getServerTime",value:function(){return Date.now()+this.avgTimeOffset}},{key:"onDisconnect",value:function(){if(""!==NAF.clientId){this.receivedOccupants({});for(var e=0,t=Object.values(NAF.entities.entities);e<t.length;e++){var n=t[e];n.components.networked.data.creator===NAF.clientId&&(n.setAttribute("networked",{owner:"",creator:""}),document.body.addEventListener("connected",n.components.networked.onConnected,!1))}NAF.clientId=""}}},{key:"disconnect",value:function(){this.socket.disconnect(),this.onDisconnect()}}])&&n(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();e.exports=i},844(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;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,o(i.key),i)}}function o(e){var n=function(e){if("object"!=t(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,"string");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(n)?n:n+""}var i=function(){return e=function e(){var t=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.app="default",this.room="default",this.occupantListener=null,this.myRoomJoinTime=null,this.myId=null,this.packet={from:void 0,to:void 0,type:void 0,data:void 0},this.occupants={},this.connectedClients=[],this.serverTimeRequests=0,this.timeOffsets=[],this.avgTimeOffset=0,this.ws=null,this.onWebsocketOpen=this.onWebsocketOpen.bind(this),this.onWebsocketClose=this.onWebsocketClose.bind(this),this.onWebsocketMessage=this.onWebsocketMessage.bind(this),this.initialReconnectionDelay=1e3*Math.random(),this.reconnectionDelay=this.initialReconnectionDelay,this.reconnectionTimeout=null,this.maxReconnectionAttempts=10,this.reconnectionAttempts=0,this.isReconnecting=!1,window.addEventListener("offline",function(){console.log("Browser went offline - closing WebSocket"),t.reconnect()})},(t=[{key:"setServerUrl",value:function(e){this.wsUrl=e}},{key:"setApp",value:function(e){this.app=e}},{key:"setRoom",value:function(e){this.room=e}},{key:"setWebRtcOptions",value:function(e){}},{key:"setServerConnectListeners",value:function(e,t){this.connectSuccess=e,this.connectFailure=t}},{key:"setRoomOccupantListener",value:function(e){this.occupantListener=e}},{key:"setDataChannelListeners",value:function(e,t,n){this.openListener=e,this.closedListener=t,this.messageListener=n}},{key:"connect",value:function(){return Promise.all([this.connectToServer(),this.updateTimeOffset()])}},{key:"connectToServer",value:function(){var e=this;return this.wsUrl&&"/"!==this.wsUrl||("https:"===location.protocol?this.wsUrl="wss://"+location.host:this.wsUrl="ws://"+location.host),NAF.log.write("Connecting to WebSocket",this.wsUrl),new Promise(function(t,n){e.ws=new WebSocket(e.wsUrl),e.websocketConnectionPromise={},e.websocketConnectionPromise.resolve=t,e.websocketConnectionPromise.reject=n,e.ws.addEventListener("open",e.onWebsocketOpen),e.ws.addEventListener("close",e.onWebsocketClose),e.ws.addEventListener("message",e.onWebsocketMessage)})}},{key:"onWebsocketOpen",value:function(){console.log("WebSocket connected"),this.joinRoom()}},{key:"onWebsocketClose",value:function(e){var t=this;1e3!==e.code&&1005!==e.code&&(this.websocketConnectionPromise.reject(e),this.isReconnecting||(this.isReconnecting=!0,console.warn("WebSocket closed unexpectedly."),this.onReconnecting&&this.onReconnecting(this.reconnectionDelay),this.reconnectionTimeout=setTimeout(function(){return t.reconnect()},this.reconnectionDelay)))}},{key:"reconnect",value:function(){var e=this;this.disconnect(),this.connectToServer().then(function(){e.reconnectionDelay=e.initialReconnectionDelay,e.reconnectionAttempts=0,e.isReconnecting=!1,e.onReconnected&&e.onReconnected()}).catch(function(t){if(e.reconnectionDelay+=1e3,e.reconnectionAttempts++,e.reconnectionAttempts>e.maxReconnectionAttempts){var n=new Error("Connection could not be reestablished, exceeded maximum number of reconnection attempts.");return e.onReconnectionError?e.onReconnectionError(n):void console.warn(n)}console.warn("Error during reconnect, retrying."),console.warn(t),e.onReconnecting&&e.onReconnecting(e.reconnectionDelay),e.reconnectionTimeout=setTimeout(function(){return e.reconnect()},e.reconnectionDelay)})}},{key:"onWebsocketMessage",value:function(e){var t=JSON.parse(e.data),n=t.event,o=t.data;switch(n){case"connectSuccess":var i=o.joinedTime,r=o.socketId;this.myRoomJoinTime=i,this.myId=r,this.websocketConnectionPromise.resolve(),this.connectSuccess(this.myId);break;case"occupantsChanged":var s=o.occupants;this.receivedOccupants(s);break;case"send":case"broadcast":var a=o.from,c=o.type,u=o.data;this.messageListener(a,c,u)}}},{key:"joinRoom",value:function(){NAF.log.write("Joining room",this.room),this.send("joinRoom",{room:this.room})}},{key:"receivedOccupants",value:function(e){delete e[this.myId],this.occupants=e,this.occupantListener(e)}},{key:"shouldStartConnectionTo",value:function(e){return!0}},{key:"startStreamConnection",value:function(e){this.connectedClients.push(e),this.openListener(e)}},{key:"closeStreamConnection",value:function(e){this.connectedClients=this.connectedClients.filter(function(t){return t!==e}),this.closedListener(e)}},{key:"getConnectStatus",value:function(e){return-1!==this.connectedClients.indexOf(e)?NAF.adapters.IS_CONNECTED:NAF.adapters.NOT_CONNECTED}},{key:"send",value:function(e,t){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({event:e,data:t}))}},{key:"sendData",value:function(e,t,n){this.sendDataGuaranteed(e,t,n)}},{key:"sendDataGuaranteed",value:function(e,t,n){this.packet.from=this.myId,this.packet.to=e,this.packet.type=t,this.packet.data=n,this.send("send",this.packet)}},{key:"broadcastData",value:function(e,t){this.broadcastDataGuaranteed(e,t)}},{key:"broadcastDataGuaranteed",value:function(e,t){this.packet.from=this.myId,this.packet.to=void 0,this.packet.type=e,this.packet.data=t,this.send("broadcast",this.packet)}},{key:"getMediaStream",value:function(e){return Promise.reject("Interface method not implemented: getMediaStream")}},{key:"updateTimeOffset",value:function(){var e=this,t=Date.now()+this.avgTimeOffset;return fetch(document.location.href,{method:"HEAD",cache:"no-cache"}).then(function(n){var o=new Date(n.headers.get("Date")).getTime()+500,i=Date.now(),r=o+(i-t)/2-i;e.serverTimeRequests++,e.serverTimeRequests<=10?e.timeOffsets.push(r):e.timeOffsets[e.serverTimeRequests%10]=r,e.avgTimeOffset=e.timeOffsets.reduce(function(e,t){return e+t},0)/e.timeOffsets.length,e.serverTimeRequests>10?setTimeout(function(){return e.updateTimeOffset()},3e5):e.updateTimeOffset()})}},{key:"getServerTime",value:function(){return Date.now()+this.avgTimeOffset}},{key:"onDisconnect",value:function(){if(""!==NAF.clientId){this.receivedOccupants({});for(var e=0,t=Object.values(NAF.entities.entities);e<t.length;e++){var n=t[e];n.components.networked.data.creator===NAF.clientId&&(n.setAttribute("networked",{owner:"",creator:""}),document.body.addEventListener("connected",n.components.networked.onConnected,!1))}NAF.clientId=""}}},{key:"disconnect",value:function(){clearTimeout(this.reconnectionTimeout),this.onDisconnect(),this.ws&&(this.ws.removeEventListener("open",this.onWebsocketOpen),this.ws.removeEventListener("close",this.onWebsocketClose),this.ws.removeEventListener("message",this.onWebsocketMessage),this.ws.close(),this.ws=null)}}])&&n(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();e.exports=i},692(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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,r(o.key),o)}}function i(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function r(e){var n=function(e){if("object"!=t(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,"string");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(n)?n:n+""}var s=function(){function e(t,o,i){n(this,e),this.localId=t,this.remoteId=o,this.sendSignalFunc=i,this.open=!1,this.channelLabel="networked-aframe-channel",this.pc=this.createPeerConnection(),this.channel=null}return i(e,[{key:"setDatachannelListeners",value:function(e,t,n,o){this.openListener=e,this.closedListener=t,this.messageListener=n,this.trackListener=o}},{key:"offer",value:function(e){var t=this;this.setupChannel(this.pc.createDataChannel(this.channelLabel,{reliable:!1})),e.sendAudio&&e.localAudioStream.getTracks().forEach(function(n){return t.pc.addTrack(n,e.localAudioStream)}),this.pc.createOffer(function(e){t.handleSessionDescription(e)},function(e){NAF.log.error("WebRtcPeer.offer: "+e)},{offerToReceiveAudio:!0,offerToReceiveVideo:!1})}},{key:"handleSignal",value:function(e){if(this.localId===e.to&&this.remoteId===e.from)switch(e.type){case"offer":this.handleOffer(e);break;case"answer":this.handleAnswer(e);break;case"candidate":this.handleCandidate(e);break;default:NAF.log.error("WebRtcPeer.handleSignal: Unknown signal type "+e.type)}}},{key:"send",value:function(e,t){null!==this.channel&&"open"===this.channel.readyState&&this.channel.send(JSON.stringify({type:e,data:t}))}},{key:"getStatus",value:function(){if(null===this.channel)return e.NOT_CONNECTED;switch(this.channel.readyState){case"open":return e.IS_CONNECTED;case"connecting":return e.CONNECTING;default:return e.NOT_CONNECTED}}},{key:"createPeerConnection",value:function(){var t=this,n=window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection||window.msRTCPeerConnection;if(void 0===n)throw new Error("WebRtcPeer.createPeerConnection: This browser does not seem to support WebRTC.");var o=new n({iceServers:e.ICE_SERVERS});return o.onicecandidate=function(e){e.candidate&&t.sendSignalFunc({from:t.localId,to:t.remoteId,type:"candidate",sdpMLineIndex:e.candidate.sdpMLineIndex,candidate:e.candidate.candidate})},o.oniceconnectionstatechange=function(){t.open&&"disconnected"===o.iceConnectionState&&(t.open=!1,t.closedListener(t.remoteId))},o.ontrack=function(e){t.trackListener(t.remoteId,e.streams[0])},o}},{key:"setupChannel",value:function(e){var t=this;this.channel=e,this.channel.onmessage=function(e){var n=JSON.parse(e.data);t.messageListener(t.remoteId,n.type,n.data)},this.channel.onopen=function(e){t.open=!0,t.openListener(t.remoteId)},this.channel.onclose=function(e){t.open&&(t.open=!1,t.closedListener(t.remoteId))},this.channel.onerror=function(e){NAF.log.error("WebRtcPeer.channel.onerror: "+e)}}},{key:"handleOffer",value:function(e){var t=this;this.pc.ondatachannel=function(e){t.setupChannel(e.channel)},this.setRemoteDescription(e),this.pc.createAnswer(function(e){t.handleSessionDescription(e)},function(e){NAF.log.error("WebRtcPeer.handleOffer: "+e)})}},{key:"handleAnswer",value:function(e){this.setRemoteDescription(e)}},{key:"handleCandidate",value:function(e){var t=window.RTCIceCandidate||window.webkitRTCIceCandidate||window.mozRTCIceCandidate;this.pc.addIceCandidate(new t(e),function(){},function(e){NAF.log.error("WebRtcPeer.handleCandidate: "+e)})}},{key:"handleSessionDescription",value:function(e){this.pc.setLocalDescription(e,function(){},function(e){NAF.log.error("WebRtcPeer.handleSessionDescription: "+e)}),this.sendSignalFunc({from:this.localId,to:this.remoteId,type:e.type,sdp:e.sdp})}},{key:"setRemoteDescription",value:function(e){var t=window.RTCSessionDescription||window.webkitRTCSessionDescription||window.mozRTCSessionDescription||window.msRTCSessionDescription;this.pc.setRemoteDescription(new t(e),function(){},function(e){NAF.log.error("WebRtcPeer.setRemoteDescription: "+e)})}},{key:"close",value:function(){this.pc&&this.pc.close()}}])}();s.IS_CONNECTED="IS_CONNECTED",s.CONNECTING="CONNECTING",s.NOT_CONNECTED="NOT_CONNECTED",s.ICE_SERVERS=[{urls:"stun:stun1.l.google.com:19302"},{urls:"stun:stun2.l.google.com:19302"},{urls:"stun:stun3.l.google.com:19302"},{urls:"stun:stun4.l.google.com:19302"}];var a=function(){return i(function e(){n(this,e),void 0===io&&console.warn("It looks like socket.io has not been loaded before WebrtcAdapter. Please do that."),this.app="default",this.room="default",this.occupantListener=null,this.myRoomJoinTime=null,this.myId=null,this.packet={from:void 0,to:void 0,type:void 0,data:void 0},this.peers={},this.occupants={},this.audioStreams={},this.pendingAudioRequest={},this.serverTimeRequests=0,this.timeOffsets=[],this.avgTimeOffset=0},[{key:"setServerUrl",value:function(e){this.wsUrl=e}},{key:"setApp",value:function(e){this.app=e}},{key:"setRoom",value:function(e){this.room=e}},{key:"setWebRtcOptions",value:function(e){!1===e.datachannel&&NAF.log.error("WebrtcAdapter.setWebRtcOptions: datachannel must be true."),!0===e.audio&&(this.sendAudio=!0),!0===e.video&&NAF.log.warn("WebrtcAdapter does not support video yet.")}},{key:"setServerConnectListeners",value:function(e,t){this.connectSuccess=e,this.connectFailure=t}},{key:"setRoomOccupantListener",value:function(e){this.occupantListener=e}},{key:"setDataChannelListeners",value:function(e,t,n){this.openListener=e,this.closedListener=t,this.messageListener=n}},{key:"connect",value:function(){var e=this,t=this;this.updateTimeOffset().then(function(){t.wsUrl&&"/"!==t.wsUrl||("https:"===location.protocol?t.wsUrl="wss://"+location.host:t.wsUrl="ws://"+location.host),NAF.log.write("Attempting to connect to socket.io");var n=t.socket=io(t.wsUrl);function o(e){var n=e.from,o=e.type,i=e.data;"ice-candidate"!==o?t.messageListener(n,o,i):t.peers[n].handleSignal(i)}n.on("connect",function(){NAF.clientId&&t.onDisconnect(),NAF.log.write("User connected",n.id),t.myId=n.id,t.joinRoom()}),n.on("connectSuccess",function(e){var n=e.joinedTime;t.myRoomJoinTime=n,NAF.log.write("Successfully joined room",t.room,"at server time",n),t.sendAudio?navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then(function(e){t.storeAudioStream(t.myId,e),t.connectSuccess(t.myId),e.getTracks().forEach(function(n){Object.keys(t.peers).forEach(function(o){t.peers[o].pc.addTrack(n,e)})})}).catch(function(e){NAF.log.error(e),console.error("Microphone is disabled due to lack of permissions"),t.sendAudio=!1,t.connectSuccess(t.myId)}):t.connectSuccess(t.myId)}),n.io.on("error",function(t){console.error("Socket connection failure",t),e.onDisconnect()}),n.on("occupantsChanged",function(e){var n=e.occupants;NAF.log.write("occupants changed",e),t.receivedOccupants(n)}),n.on("send",o),n.on("broadcast",o)})}},{key:"joinRoom",value:function(){NAF.log.write("Joining room",this.room),this.socket.emit("joinRoom",{room:this.room})}},{key:"receivedOccupants",value:function(e){var t=this;delete e[this.myId],this.occupants=e;var n=this,o=this.myId,i=function(){var e=r;if(t.peers[e])return 1;var i=new s(o,e,function(t){n.socket.emit("send",{from:o,to:e,type:"ice-candidate",data:t})});i.setDatachannelListeners(n.openListener,n.closedListener,n.messageListener,n.trackListener.bind(n)),n.peers[e]=i};for(var r in e)i();this.occupantListener(e)}},{key:"shouldStartConnectionTo",value:function(e){return(this.myRoomJoinTime||0)<=(e||0)}},{key:"startStreamConnection",value:function(e){var t=this;NAF.log.write("starting offer process"),this.sendAudio?this.getMediaStream(this.myId).then(function(n){var o={sendAudio:!0,localAudioStream:n};t.peers[e].offer(o)}):this.peers[e].offer({})}},{key:"closeStreamConnection",value:function(e){NAF.log.write("closeStreamConnection",e,this.peers),this.peers[e].close(),delete this.peers[e],delete this.occupants[e],this.closedListener(e)}},{key:"getConnectStatus",value:function(e){var t=this.peers[e];if(void 0===t)return NAF.adapters.NOT_CONNECTED;switch(t.getStatus()){case s.IS_CONNECTED:return NAF.adapters.IS_CONNECTED;case s.CONNECTING:return NAF.adapters.CONNECTING;case s.NOT_CONNECTED:default:return NAF.adapters.NOT_CONNECTED}}},{key:"sendData",value:function(e,t,n){this.peers[e].send(t,n)}},{key:"sendDataGuaranteed",value:function(e,t,n){this.packet.from=this.myId,this.packet.to=e,this.packet.type=t,this.packet.data=n,this.socket?this.socket.emit("send",this.packet):NAF.log.warn("SocketIO socket not created yet")}},{key:"broadcastData",value:function(e,t){for(var n in this.peers)this.sendData(n,e,t)}},{key:"broadcastDataGuaranteed",value:function(e,t){this.packet.from=this.myId,this.packet.to=void 0,this.packet.type=e,this.packet.data=t,this.socket?this.socket.emit("broadcast",this.packet):NAF.log.warn("SocketIO socket not created yet")}},{key:"storeAudioStream",value:function(e,t){this.audioStreams[e]=t,this.pendingAudioRequest[e]&&(NAF.log.write("Received pending audio for "+e),this.pendingAudioRequest[e](t),this.pendingAudioRequest[e](t))}},{key:"trackListener",value:function(e,t){this.storeAudioStream(e,t)}},{key:"getMediaStream",value:function(e){var t=this;return this.audioStreams[e]?(NAF.log.write("Already had audio for "+e),Promise.resolve(this.audioStreams[e])):(NAF.log.write("Waiting on audio for "+e),new Promise(function(n){t.pendingAudioRequest[e]=n}))}},{key:"updateTimeOffset",value:function(){var e=this,t=Date.now()+this.avgTimeOffset;return fetch(document.location.href,{method:"HEAD",cache:"no-cache"}).then(function(n){var o=new Date(n.headers.get("Date")).getTime()+500,i=Date.now(),r=o+(i-t)/2-i;e.serverTimeRequests++,e.serverTimeRequests<=10?e.timeOffsets.push(r):e.timeOffsets[e.serverTimeRequests%10]=r,e.avgTimeOffset=e.timeOffsets.reduce(function(e,t){return e+t},0)/e.timeOffsets.length,e.serverTimeRequests>10?setTimeout(function(){return e.updateTimeOffset()},3e5):e.updateTimeOffset()})}},{key:"getServerTime",value:function(){return Date.now()+this.avgTimeOffset}},{key:"onDisconnect",value:function(){if(""!==NAF.clientId){this.receivedOccupants({});for(var e=0,t=Object.values(NAF.entities.entities);e<t.length;e++){var n=t[e];n.components.networked.data.creator===NAF.clientId&&(n.setAttribute("networked",{owner:"",creator:""}),document.body.addEventListener("connected",n.components.networked.onConnected,!1))}NAF.clientId=""}}},{key:"disconnect",value:function(){this.socket.disconnect(),this.onDisconnect()}}])}();e.exports=a},909(e,t,n){var o=n(199);AFRAME.registerComponent("networked-audio-source",{schema:{streamName:{default:"audio"},positional:{default:!0},distanceModel:{default:"inverse",oneOf:["linear","inverse","exponential"]},maxDistance:{default:1e4},refDistance:{default:1},rolloffFactor:{default:1},createSoundOnInit:{default:!0}},init:function(){this.stream=null,this.sound=null,this.audioEl=null,this._setupSound=this._setupSound.bind(this),this.data.createSoundOnInit&&this.createSound()},update:function(e){this.sound&&(e.positional!==this.data.positional?(this.destroySound(),this._setupSound(this.stream)):this.data.positional&&this._setPannerProperties())},_setPannerProperties:function(){this.sound.setDistanceModel(this.data.distanceModel),this.sound.setMaxDistance(this.data.maxDistance),this.sound.setRefDistance(this.data.refDistance),this.sound.setRolloffFactor(this.data.rolloffFactor)},remove:function(){this.destroySound()},destroySound:function(){this.sound&&(this.el.emit("sound-source-removed",{soundSource:this.soundSource}),this.sound.disconnect(),this.el.removeObject3D(this.attrName),this.sound=null),this.audioEl&&(this.audioEl.pause(),this.audioEl.srcObject=null,this.audioEl.load(),this.audioEl=null)},createSound:function(){var e=this;NAF.utils.getNetworkedEntity(this.el).then(function(t){var n=t.components.networked.data.owner;n&&NAF.connection.adapter.getMediaStream(n,e.data.streamName).then(e._setupSound).catch(function(e){return o.log.error("Error getting media stream for ".concat(n),e)})})},_setupSound:function(e){if(e&&this.el.parentNode){var t=this.el,n=t.sceneEl;n.audioListener||(n.audioListener=new THREE.AudioListener,n.camera&&n.camera.add(n.audioListener),n.addEventListener("camera-set-active",function(e){e.detail.cameraEl.getObject3D("camera").add(n.audioListener)})),this.sound=this.data.positional?new THREE.PositionalAudio(n.audioListener):new THREE.Audio(n.audioListener),t.setObject3D(this.attrName,this.sound),this.data.positional&&this._setPannerProperties(),/chrome/i.test(navigator.userAgent)&&(this.audioEl=new Audio,this.audioEl.setAttribute("autoplay","autoplay"),this.audioEl.setAttribute("playsinline","playsinline"),this.audioEl.srcObject=e,this.audioEl.volume=0),this.soundSource=this.sound.context.createMediaStreamSource(e),this.sound.setNodeSource(this.soundSource),this.el.emit("sound-source-set",{soundSource:this.soundSource}),this.stream=e}}})},435(){function e(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,n){if(e){if("string"==typeof e)return t(e,n);var o={}.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?t(e,n):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}["left","right"].forEach(function(e){var t=document.createElement("template"),n=document.createElement("a-entity");t.id="".concat(e,"-hand-default-template"),n.setAttribute("rotation","0 0 0"),n.setAttribute("networked-hand-controls","hand: ".concat(e)),t.appendChild(n);var o="#".concat(t.id);NAF.schemas.schemaDict[o]={template:o,components:[{component:"position",requiresNetworkUpdate:NAF.utils.vectorRequiresUpdate(.001)},{component:"rotation",requiresNetworkUpdate:NAF.utils.vectorRequiresUpdate(.5)},"networked-hand-controls"]},NAF.schemas.templateCache[o]=t}),AFRAME.registerComponent("networked-hand-controls",{schema:{color:{default:"white",type:"color"},hand:{type:"string",default:"left",oneOf:["right","left"]},handModelStyle:{type:"string",default:"highPoly",oneOf:["lowPoly","highPoly","toon","controller"]},controllerComponent:{type:"string",default:""},webxrControllerProfiles:{type:"string",default:""},controllerEvent:{default:JSON.stringify({}),type:"string"},controllerModelUpdate:{default:[],type:"array"},customHandModelURL:{type:"string",default:""},gesture:{type:"string",default:"open"},visible:{type:"bool",default:!1}},init:function(){var t=this;this.setup(),this.rendererSystem=this.el.sceneEl.systems.renderer,"controller"!==this.data.handModelStyle&&this.addHandModel(),NAF.utils.getNetworkedEntity(this.el).then(function(e){t.local=e.components.networked.createdByMe()}).catch(function(){t.local=!0}).then(function(){if(t.local){for(var n in t.addControllerComponents("controller"===t.data.handModelStyle),t.buttonEventMap){var o;t.eventFunctionMap[t.data.hand][n]=(o=t.handleButton).bind.apply(o,[t].concat(e(t.buttonEventMap[n])))}for(var i in t.visibleListeners)t.eventFunctionMap[t.data.hand][i]=t.visibleListeners[i].bind(t)}else t.el.classList.add("naf-remote-hand")})},play:function(){this.local&&this.addEventListeners()},pause:function(){this.local&&this.removeEventListeners()},tick:function(e,t){var n;null!==(n=this.getMesh())&&void 0!==n&&n.mixer&&this.getMesh().mixer.update(t/1e3)},update:function(t){var n=this;if(t.visible!=this.data.visible&&(this.el.object3D.visible=this.data.visible),t.handModelStyle&&t.handModelStyle!==this.data.handModelStyle&&(this.getMesh()&&this.el.removeObject3D(this.str.mesh),["gltf-model","obj-model"].forEach(function(e){n.el.components[e]&&n.el.removeAttribute(e)}),"controller"!==this.data.handModelStyle?this.addHandModel():(this.data.controllerComponent&&this.el.components[this.data.controllerComponent]&&this.el.removeAttribute(this.data.controllerComponent),this.local?(this.addControllerComponents(!0),this.el.components[this.data.controllerComponent].injectTrackedControls({profiles:JSON.parse(this.data.webxrControllerProfiles)})):!this.injectedController&&this.data.controllerComponent&&this.data.webxrControllerProfiles[0]&&this.injectRemoteControllerModel())),t.color&&this.data.handModelStyle!==this.str.controller&&t.color!==this.data.color&&this.updateHandMeshColor(),!this.local)if(this.data.handModelStyle!==this.str.controller&&this.data.gesture!==t.gesture)this.handleGesture(this.data.gesture,t.gesture);else if(this.data.handModelStyle===this.str.controller){if(!this.injectedController&&this.data.controllerComponent&&this.data.webxrControllerProfiles[0]&&this.injectRemoteControllerModel(),t.controllerEvent&&t.controllerEvent!==this.data.controllerEvent){var o=JSON.parse(this.data.controllerEvent);this.el.components[this.data.controllerComponent]["thumbstickmoved"===o.type?"onThumbstickMoved":"onButtonChanged"](o)}var i;!t.controllerModelUpdate||t.controllerModelUpdate[0]===this.data.controllerModelUpdate[0]&&t.controllerModelUpdate[1]===this.data.controllerModelUpdate[1]||(i=this.el.components[this.data.controllerComponent]).updateModel.apply(i,e(this.data.controllerModelUpdate))}},remove:function(){this.el.removeObject3D(this.str.mesh)},addHandModel:function(){var e=this;this.loader=new THREE.GLTFLoader,this.loader.setCrossOrigin("anonymous");var t=this.MODEL_BASE+this.MODEL_NAMES[this.data.handModelStyle+this.data.hand.charAt(0).toUpperCase()+this.data.hand.slice(1)];this.loader.load(this.data.customHandModelURL||t,function(t){var n=t.scene.children[0],o="left"===e.data.hand?Math.PI/2:-Math.PI/2;n.mixer=new THREE.AnimationMixer(n),e.clips=t.animations,e.clips.forEach(function(t){e.clipNameToClip[t.name]=t}),e.el.setObject3D(e.str.mesh,n);var i=e.data.color;n.traverse(function(e){e.isMesh&&(e.material.color=new THREE.Color(i))}),n.position.set(0,0,0),n.rotation.set(0,0,o)})},updateHandMeshColor:function(){var e=this.getMesh();if(e){var t=this.data.color;e.traverse(function(e){e.isMesh&&e.material.color.set(t)})}},controllerComponents:["magicleap-controls","vive-controls","oculus-touch-controls","windows-motion-controls","hp-mixed-reality-controls","valve-index-controls","oculus-go-controls","vive-focus-controls"],addControllerComponents:function(e){var t=this;this.controllerComponents.forEach(function(n){t.data.controllerComponent&&t.data.controllerComponent!==n||(t.el.setAttribute(n,{hand:t.data.hand,model:e}),t.el.components[n].injectTrackedControls=t.injectControlsWrapper.bind(t,t.el.components[n].injectTrackedControls.bind(t.el.components[n]),n))}),this.isViveController()},injectControlsWrapper:function(e,t,n){this.el.setAttribute("networked-hand-controls",{controllerComponent:t,webxrControllerProfiles:JSON.stringify(n.profiles)}),e(n),this.el.components[t].updateModel=this.updateModelWrapper.bind(this,this.el.components[t].updateModel.bind(this.el.components[t])),this.el.components[t].onButtonChanged=this.onButtonChangedWrapper.bind(this,this.el.components[t].onButtonChanged),this.el.components[t].onThumbstickMoved=this.onThumbstickMovedWrapper.bind(this,this.el.components[t].onThumbstickMoved),this.el.components[t].removeEventListeners(),this.el.components[t].addEventListeners()},onButtonChangedWrapper:function(e,t){this.el.setAttribute("networked-hand-controls",this.str.controllerEvent,JSON.stringify({detail:t.detail,type:t.type})),e(t)},onThumbstickMovedWrapper:function(e,t){this.el.setAttribute("networked-hand-controls",this.str.controllerEvent,JSON.stringify({detail:t.detail,type:t.type})),e(t)},updateModelWrapper:function(e,t,n){this.btnEvtMap[t]||(this.btnEvtMap[t]={}),this.btnEvtMap[t][n]||(this.btnEvtMap[t][n]="".concat(t,",").concat(n)),this.el.setAttribute("networked-hand-controls","controllerModelUpdate",this.btnEvtMap[t][n]),e(t,n)},catchPoseTrackingInitialization:function(){this.catchAndRemoveWebXRTracking=function(e){"tracked-controls-webxr"===e.detail.name&&(this.el.removeEventListener("componentinitialized",this.catchAndRemoveWebXRTracking),this.el.removeAttribute("tracked-controls-webxr"))}.bind(this),this.el.addEventListener("componentinitialized",this.catchAndRemoveWebXRTracking)},injectRemoteControllerModel:function(){this.el.pause(),this.el.setAttribute(this.data.controllerComponent,{hand:this.data.hand,model:!0}),this.el.components[this.data.controllerComponent].removeControllersUpdateListener(),this.el.components[this.data.controllerComponent].checkIfControllerPresent&&this.el.components[this.data.controllerComponent].loadModel?(this.el.components[this.data.controllerComponent].checkIfControllerPresent=function(e){return e},this.el.components[this.data.controllerComponent].injectTrackedControls=function(e){return e},this.el.addEventListener("model-loaded",this.el.components[this.data.controllerComponent].onModelLoaded),this.el.components[this.data.controllerComponent].loadModel({profiles:JSON.parse(this.data.webxrControllerProfiles)})):(console.warn("fallback path: will add and then disable pose tracking",this.data.controllerComponent,this.el,this.el.components),this.el.addEventListener("model-loaded",this.el.components[this.data.controllerComponent].onModelLoaded),this.catchPoseTrackingInitialization(),this.el.components[this.data.controllerComponent].injectTrackedControls({profiles:JSON.parse(this.data.webxrControllerProfiles)})),this.el.play(),this.injectedController=!0},getMesh:function(){return this.el.getObject3D(this.str.mesh)},local:!1,eventFunctionMap:{left:{},right:{}},buttonEventMap:{gripdown:["grip","down"],gripup:["grip","up"],trackpaddown:["trackpad","down"],trackpadup:["trackpad","up"],trackpadtouchstart:["trackpad","touchstart"],trackpadtouchend:["trackpad","touchend"],triggerdown:["trigger","down"],triggerup:["trigger","up"],triggertouchstart:["trigger","touchstart"],triggertouchend:["trigger","touchend"],griptouchstart:["grip","touchstart"],griptouchend:["grip","touchend"],abuttontouchstart:["AorX","touchstart"],abuttontouchend:["AorX","touchend"],bbuttontouchstart:["BorY","touchstart"],bbuttontouchend:["BorY","touchend"],xbuttontouchstart:["AorX","touchstart"],xbuttontouchend:["AorX","touchend"],ybuttontouchstart:["BorY","touchstart"],ybuttontouchend:["BorY","touchend"],surfacetouchstart:["surface","touchstart"],surfacetouchend:["surface","touchend"]},visibleListeners:{controllerconnected:function(){this.el.setAttribute("networked-hand-controls","visible",!0)},controllerdisconnected:function(){this.el.setAttribute("networked-hand-controls","visible",!1)}},addEventListeners:function(){for(var e in this.buttonEventMap)this.el.addEventListener(e,this.eventFunctionMap[this.data.hand][e]);for(var t in this.visibleListeners)this.el.addEventListener(t,this.eventFunctionMap[this.data.hand][t])},removeEventListeners:function(){for(var e in this.buttonEventMap)this.el.removeEventListener(e,this.eventFunctionMap[this.data.hand][e]);for(var t in this.visibleListeners)this.el.removeEventListener(t,this.eventFunctionMap[this.data.hand][t])},str:{nafHandControls:"networked-hand-controls",mesh:"mesh",gesture:"gesture",down:"down",touchstart:"touchstart",fist:"fist",point:"point",thumbUp:"thumbUp",pistol:"pistol",hold:"hold",open:"open",controller:"controller",controllerEvent:"controllerEvent"},handleButton:function(e,t){"controller"!==this.data.handModelStyle&&(this.isContact=t===this.str.down||t===this.str.touchstart,this.isContact!==this.contact[e]&&(this.contact[e]=this.isContact,this.lastGesture=this.data.gesture,this.determineGesture(),this.gesture!==this.lastGesture&&(this.el.setAttribute(this.str.nafHandControls,this.str.gesture,this.gesture),this.handleGesture())))},handleGesture:function(){this.data.gesture!==this.lastGesture&&(this.playAnimation(),this.emitGestureEvents())},determineGesture:function(){this.gripIsActive=this.contact.grip,this.triggerIsActive=this.contact.trigger,this.thumbIsActive=this.contact.trackpad||this.contact.surface,this.contact.AorX||this.contact.BorY,this.isVive?this.gesture=this.gripIsActive||this.triggerIsActive?this.str.fist:this.contact.trackpad?this.str.point:this.str.open:this.gesture=this.gripIsActive&&this.thumbIsActive&&this.triggerIsActive?this.str.fist:this.gripIsActive&&this.thumbIsActive&&!this.triggerIsActive?this.str.point:this.gripIsActive&&!this.thumbIsActive&&this.triggerIsActive?this.str.thumbUp:!this.gripIsActive||this.thumbIsActive||this.triggerIsActive?this.triggerIsActive?this.str.hold:this.str.open:this.str.pistol},emitGestureEvents:function(){var e,t;this.el.emit(null===(e=this.eventNames[this.lastGesture])||void 0===e?void 0:e.inactive),this.el.emit(null===(t=this.eventNames[this.data.gesture])||void 0===t?void 0:t.active)},eventNames:{fist:{active:"fiststart",inactive:"fistend"},thumbUp:{active:"thumbupstart",inactive:"thumbupend"},point:{active:"pointstart",inactive:"pointend"},hold:{active:"holdstart",inactive:"holdend"},open:{active:"openstart",inactive:"openend"},pistol:{active:"pistolstart",inactive:"pistolend"}},playAnimation:function(){if(this.getMesh()){if(this.getMesh().mixer.stopAllAction(),this.clip=this.clipNameToClip[this.ANIMATIONS[this.data.gesture]],this.toAction=this.getMesh().mixer.clipAction(this.clip),this.toAction.clampWhenFinished=!0,this.toAction.loop=THREE.LoopRepeat,this.toAction.repetitions=0,this.toAction.timeScale=this.reverse?-1:1,this.toAction.time=this.reverse?this.clip.duration:0,this.toAction.weight=1,!this.lastGesture||this.data.gesture===this.lastGesture)return this.getMesh().mixer.stopAllAction(),void this.toAction.play();this.clip=this.clipNameToClip[this.ANIMATIONS[this.lastGesture]],this.fromAction=this.getMesh().mixer.clipAction(this.clip),this.fromAction.weight=.15,this.fromAction.play(),this.toAction.play(),this.fromAction.crossFadeTo(this.toAction,.15,!0)}},MODEL_BASE:"https://cdn.aframe.io/controllers/hands/",MODEL_NAMES:{toonLeft:"leftHand.glb",toonRight:"rightHand.glb",lowPolyLeft:"leftHandLow.glb",lowPolyRight:"rightHandLow.glb",highPolyLeft:"leftHandHigh.glb",highPolyRight:"rightHandHigh.glb"},clipNameToClip:{},ANIMATIONS:{open:"Open",point:"Point",pistol:"Point + Thumb",fist:"Fist",hold:"Hold",thumbUp:"Thumb Up"},isVive:!1,isViveController:function(){var e=this.el.components["tracked-controls"]&&this.el.components["tracked-controls"].controller;this.isVive=e&&(e.id&&0===e.id.indexOf("OpenVR ")||e.profiles&&e.profiles[0]&&"htc-vive"===e.profiles[0])},btnEvtMap:{},setup:function(){this.contact={grip:!1,trigger:!1,surface:!1,trackpad:!1,AorX:!1,BorY:!1},this.reverse=!1,this.isContact=!1,this.injectedController=!1,this.lastGesture="",this.gesture="",this.gripIsActive=!1,this.triggerIsActive=!1,this.thumbIsActive=!1,this.clip=null,this.toAction=null,this.fromAction=null}})},673(){AFRAME.registerComponent("networked-scene",{schema:{serverURL:{default:"/"},app:{default:"default"},room:{default:"default"},connectOnLoad:{default:!0},onConnect:{default:"onConnect"},adapter:{default:"wseasyrtc"},audio:{default:!1},video:{default:!1},debug:{default:!1}},init:function(){var e=this.el;this.connect=this.connect.bind(this),e.addEventListener("connect",this.connect),this.data.connectOnLoad&&e.emit("connect",null,!1)},connect:function(){return NAF.log.setDebug(this.data.debug),NAF.log.write("Networked-Aframe Connecting..."),this.checkDeprecatedProperties(),this.setupNetworkAdapter(),this.hasOnConnectFunction()&&this.callOnConnect(),NAF.connection.connect(this.data.serverURL,this.data.app,this.data.room,this.data.audio,this.data.video)},checkDeprecatedProperties:function(){},setupNetworkAdapter:function(){var e=this.data.adapter,t=NAF.adapters.make(e);NAF.connection.setNetworkAdapter(t),this.el.emit("adapter-ready",t,!1)},hasOnConnectFunction:function(){return""!=this.data.onConnect&&window[this.data.onConnect]},callOnConnect:function(){NAF.connection.onConnect(window[this.data.onConnect])},remove:function(){NAF.log.write("networked-scene disconnected"),this.el.removeEventListener("connect",this.connect),NAF.connection.disconnect()}})},126(e,t,n){var o=n(199);AFRAME.registerComponent("networked-video-source",{schema:{streamName:{default:"video"}},dependencies:["material"],init:function(){this.videoTexture=null,this.video=null,this.stream=null,this._setMediaStream=this._setMediaStream.bind(this),this._waitForMediaStream=this._waitForMediaStream.bind(this),this._waitForMediaStream()},_waitForMediaStream:function(){var e=this;NAF.utils.getNetworkedEntity(this.el).then(function(t){var n=t.components.networked.data.owner;n&&NAF.connection.adapter.getMediaStream(n,e.data.streamName).then(e._setMediaStream).catch(function(e){return o.log.error("Error getting media stream for ".concat(n),e)})})},_setMediaStream:function(e){var t=this;if(this.video||this.setupVideo(),e!==this.stream){if(this.stream&&this._clearMediaStream(),e){this.video.srcObject=e;var n=this.video.play();n instanceof Promise&&n.catch(function(e){return o.log.error("Error play video stream",e)}),this.videoTexture&&this.videoTexture.dispose(),this.videoTexture=new THREE.VideoTexture(this.video);var i=this.el.getObject3D("mesh");i.material.map=this.videoTexture,i.material.map.colorSpace=THREE.SRGBColorSpace,i.material.needsUpdate=!0,e.addEventListener("removetrack",function(){t._clearMediaStream(),t._waitForMediaStream()})}this.stream=e}},_clearMediaStream:function(){if(this.stream=null,this.videoTexture){if(this.videoTexture.image instanceof HTMLVideoElement){var e=this.videoTexture.image;e.pause(),e.srcObject=null,e.load()}this.videoTexture.dispose(),this.videoTexture=null;var t=this.el.getObject3D("mesh");t.material.map=null,t.material.needsUpdate=!0}},remove:function(){this._clearMediaStream()},setupVideo:function(){if(!this.video){var e=document.createElement("video");e.setAttribute("autoplay",!0),e.setAttribute("playsinline",!0),e.setAttribute("muted",!0),this.video=e}}})},924(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){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function r(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach(function(t){s(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function s(e,t,n){return(t=function(e){var t=function(e){if("object"!=o(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=o(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==o(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a=n(451),c=n(934),u=THREE.MathUtils.DEG2RAD,l=["position","rotation","scale"];function h(e){return!(!e.isVector3||isNaN(e.x)||isNaN(e.y)||isNaN(e.z)||null===e.x||null===e.y||null===e.z)}function d(e){return!(!e.isQuaternion||isNaN(e.x)||isNaN(e.y)||isNaN(e.z)||isNaN(e.w)||null===e.x||null===e.y||null===e.z||null===e.w)}NAF.InterpolationBuffer=c;var f,p,m=(f=0,function(e,t){var n=Date.now();n-f>t&&(f=n,e())});function v(){NAF.log.warn("Received invalid network update.")}function y(e){for(var t in e)delete e[t];return e}AFRAME.registerSystem("networked",{init:function(){this.components=[],this.nextSyncTime=0},register:function(e){this.components.push(e)},deregister:function(e){var t=this.components.indexOf(e);t>-1&&this.components.splice(t,1)},tick:(p={d:[]},function(e){if(NAF.connection.adapter&&!(e<this.nextSyncTime)){p.d.length=0;for(var t=0,n=this.components.length;t<n;t++){var o=this.components[t];if(o.isMine()){if(!o.el.parentElement)return void NAF.log.error("entity registered with system despite being removed");var i=this.components[t].syncDirty();i&&p.d.push(i)}}p.d.length>0&&NAF.connection.broadcastData("um",p),this.updateNextSyncTime(e)}}),updateNextSyncTime:function(e){this.nextSyncTime=e+1e3/NAF.options.updateRate}}),AFRAME.registerComponent("networked",{schema:{template:{default:""},attachTemplateToLocal:{default:!0},persistent:{default:!1},networkId:{default:""},owner:{default:""},creator:{default:""}},init:function(){this.OWNERSHIP_GAINED="ownership-gained",this.OWNERSHIP_CHANGED="ownership-changed",this.OWNERSHIP_LOST="ownership-lost",this.onOwnershipGainedEvent={el:this.el},this.onOwnershipChangedEvent={el:this.el},this.onOwnershipLostEvent={el:this.el},this.conversionEuler=new THREE.Euler,this.conversionEuler.order="YXZ",this.bufferInfos=[],this.bufferPosition=new THREE.Vector3,this.bufferQuaternion=new THREE.Quaternion,this.bufferScale=new THREE.Vector3;var e,t=!!this.el.firstUpdateData;this.onConnected=this.onConnected.bind(this),this.syncData={},this.componentsData={},this.componentSchemas=NAF.schemas.getComponents(this.data.template),this.cachedElements=new Array(this.componentSchemas.length),this.networkUpdatePredicates=this.componentSchemas.map(function(e){return e.requiresNetworkUpdate&&e.requiresNetworkUpdate()||(t=null,function(e){return!(null!==t&&a(t,e)||(t=AFRAME.utils.clone(e),0))});var t}),this.invalidateCachedElements(),this.initNetworkParent(),""===this.data.networkId?(e=NAF.utils.createNetworkId(),this.el.setAttribute(this.name,{networkId:e})):e=this.data.networkId,this.el.id||this.el.setAttribute("id","naf-"+e),t?this.firstUpdate():(this.data.attachTemplateToLocal&&this.attachTemplateToLocal(),this.registerEntity(this.data.networkId)),this.lastOwnerTime=-1,NAF.clientId?this.onConnected():document.body.addEventListener("connected",this.onConnected,!1),document.body.dispatchEvent(this.entityCreatedEvent()),this.el.dispatchEvent(new CustomEvent("instantiated",{detail:{el:this.el}})),this.el.sceneEl.systems.networked.register(this)},attachTemplateToLocal:function(){for(var e=NAF.schemas.getCachedTemplate(this.data.template),t=e.attributes,n=0;n<t.length;n++)this.el.setAttribute(t[n].name,t[n].value);for(;e.firstElementChild;)this.el.appendChild(e.firstElementChild)},takeOwnership:function(){var e=this.data.owner,t=this.lastOwnerTime,n=NAF.connection.getServerTime();return!!(e&&!this.isMine()&&t<n)&&(this.lastOwnerTime=n,this.removeLerp(),this.el.setAttribute("networked",{owner:NAF.clientId}),this.syncAll(),this.onOwnershipGainedEvent.oldOwner=e,this.el.emit(this.OWNERSHIP_GAINED,this.onOwnershipGainedEvent),this.onOwnershipChangedEvent.oldOwner=e,this.onOwnershipChangedEvent.newOwner=NAF.clientId,this.el.emit(this.OWNERSHIP_CHANGED,this.onOwnershipChangedEvent),!0)},initNetworkParent:function(){var e=this.el.parentElement;e.components&&e.components.networked?this.parent=e:this.parent=null},registerEntity:function(e){NAF.entities.registerEntity(e,this.el)},applyPersistentFirstSync:function(){var e=this.data.networkId,t=NAF.entities.getPersistentFirstSync(e);t&&(this.networkUpdate(t),NAF.entities.forgetPersistentFirstSync(e))},firstUpdate:function(){var e=this.el.firstUpdateData;this.networkUpdate(e),this.el.firstUpdateData=void 0},onConnected:function(){var e=this;""===this.data.owner&&(this.lastOwnerTime=NAF.connection.getServerTime(),this.el.setAttribute(this.name,{owner:NAF.clientId,creator:NAF.clientId}),setTimeout(function(){e.el.parentNode?e.syncAll(void 0,!0):NAF.log.warn("Networked element was removed before ever getting the chance to syncAll")},0)),document.body.removeEventListener("connected",this.onConnected,!1)},isMine:function(){return this.data.owner===NAF.clientId},createdByMe:function(){return this.data.creator===NAF.clientId},tick:function(e,t){if(!this.isMine()&&NAF.options.useLerp)for(var n=0;n<this.bufferInfos.length;n++){var o=this.bufferInfos[n],i=o.buffer,r=o.object3D,s=o.componentNames;if(i.update(t),s.includes("position")){var a=i.getPosition();h(a)?r.position.copy(a):m(v,5e3)}if(s.includes("rotation")){var c=i.getQuaternion();d(c)?r.quaternion.copy(c):m(v,5e3)}if(s.includes("scale")){var u=i.getScale();h(u)?r.scale.copy(u):m(v,5e3)}}},syncAll:function(e,t){if(this.canSync()){var n=this.gatherComponentsData(!0),o=this.createSyncData(n,t);e?NAF.connection.sendDataGuaranteed(e,"u",o):NAF.connection.broadcastDataGuaranteed("u",o)}},syncDirty:function(){if(this.canSync()){var e=this.gatherComponentsData(!1);if(null!==e)return this.createSyncData(e)}},getCachedElement:function(e){var t=this.cachedElements[e];if(t)return t;var n=this.componentSchemas[e];return n.selector?this.cachedElements[e]=this.el.querySelector(n.selector):this.cachedElements[e]=this.el},invalidateCachedElements:function(){for(var e=0;e<this.cachedElements.length;e++)this.cachedElements[e]=null},gatherComponentsData:function(e){for(var t=null,n=0;n<this.componentSchemas.length;n++){var o=this.componentSchemas[n],i=this.getCachedElement(n);if(i){var r=o.component?o.component:o,s=i.getAttribute(r);if(null!==s){var a=o.property?s[o.property]:s;(this.networkUpdatePredicates[n](a)||e)&&((t=t||y(this.componentsData))[n]=a)}else e&&((t=t||y(this.componentsData))[n]=null)}else e&&((t=t||y(this.componentsData))[n]=null)}return t},createSyncData:function(e,t){var n=this.syncData,o=this.data;return n.networkId=o.networkId,n.owner=o.owner,n.creator=o.creator,n.lastOwnerTime=this.lastOwnerTime,n.template=o.template,n.persistent=o.persistent,n.parent=this.getParentId(),n.components=e,n.isFirstSync=!!t,n},canSync:function(){if(this.data.owner&&this.isMine())return!0;if(!this.createdByMe())return!1;var e=NAF.connection.getConnectedClients();for(var t in e)if(t===this.data.owner)return!1;return!0},getParentId:function(){return this.initNetworkParent(),this.parent?this.parent.getAttribute("networked").networkId:null},networkUpdate:function(e){if(void 0!==this.componentSchemas){if(!(e.lastOwnerTime<this.lastOwnerTime||this.lastOwnerTime===e.lastOwnerTime&&this.data.owner>e.owner)){if(this.data.owner!==e.owner){var t=this.isMine();this.lastOwnerTime=e.lastOwnerTime;var n=this.data.owner,o=e.owner;this.el.setAttribute("networked",{owner:e.owner}),t&&(this.onOwnershipLostEvent.newOwner=o,this.el.emit(this.OWNERSHIP_LOST,this.onOwnershipLostEvent)),this.onOwnershipChangedEvent.oldOwner=n,this.onOwnershipChangedEvent.newOwner=o,this.el.emit(this.OWNERSHIP_CHANGED,this.onOwnershipChangedEvent)}this.data.persistent!==e.persistent&&this.el.setAttribute("networked",{persistent:e.persistent}),this.updateNetworkedComponents(e.components)}}else this.el.firstUpdateData&&this.el.firstUpdateData!==e&&(this.el.firstUpdateData.components=r(r({},this.el.firstUpdateData.components),e.components))},updateNetworkedComponents:function(e){for(var t=0,n=this.componentSchemas.length;t<n;t++){var o=e[t],i=this.componentSchemas[t],r=this.getCachedElement(t);null!==r&&null!=o&&(i.component?i.property?this.updateNetworkedComponent(r,i.component,i.property,o):this.updateNetworkedComponent(r,i.component,o):this.updateNetworkedComponent(r,i,o))}},updateNetworkedComponent:function(e,t,n,o){if(NAF.options.useLerp&&l.includes(t)){for(var i,r=0,s=this.bufferInfos.length;r<s;r++){var a=this.bufferInfos[r];if(a.object3D===e.object3D){i=a;break}}if(i){var h=i.componentNames;h.includes(t)||h.push(t)}else i={buffer:new c(0,.1),object3D:e.object3D,componentNames:[t]},this.bufferInfos.push(i);var d=i.buffer;switch(t){case"position":return void d.setPosition(this.bufferPosition.set(n.x,n.y,n.z));case"rotation":return this.conversionEuler.set(u*n.x,u*n.y,u*n.z),void d.setQuaternion(this.bufferQuaternion.setFromEuler(this.conversionEuler));case"scale":return void d.setScale(this.bufferScale.set(n.x,n.y,n.z))}NAF.log.error("Could not set value in interpolation buffer.",e,t,n,i)}else void 0===o?e.setAttribute(t,n):e.setAttribute(t,n,o)},removeLerp:function(){this.bufferInfos=[]},remove:function(){if(document.body.removeEventListener("connected",this.onConnected,!1),this.isMine()&&NAF.connection.isConnected()){var e={networkId:this.data.networkId};NAF.entities.hasEntity(this.data.networkId)?NAF.connection.broadcastDataGuaranteed("r",e):this.data.creator&&!1===NAF.connection.activeDataChannels[this.data.creator]||NAF.log.error("Removing networked entity that is not in entities array.")}NAF.entities.forgetEntity(this.data.networkId),document.body.dispatchEvent(this.entityRemovedEvent(this.data.networkId)),this.el.sceneEl.systems.networked.deregister(this)},entityCreatedEvent:function(){return new CustomEvent("entityCreated",{detail:{el:this.el}})},entityRemovedEvent:function(e){return new CustomEvent("entityRemoved",{detail:{networkId:e}})}})},172(e){e.exports={debug:!1,updateRate:15,useLerp:!0,firstSyncSource:null,syncSource:null}},347(e){e.exports.whenEntityLoaded=function(e,t){e.hasLoaded&&t(),e.addEventListener("loaded",function(){t()})},e.exports.createHtmlNodeFromString=function(e){var t=document.createElement("div");return t.innerHTML=e,t.firstChild},e.exports.getCreator=function(e){var t=e.components;return t.networked?t.networked.data.creator:null},e.exports.getNetworkOwner=function(e){var t=e.components;return t.networked?t.networked.data.owner:null},e.exports.getNetworkId=function(e){var t=e.components;return t.networked?t.networked.data.networkId:null},e.exports.now=function(){return Date.now()},e.exports.createNetworkId=function(){return Math.random().toString(36).substring(2,9)},e.exports.getNetworkedEntity=function(e){return new Promise(function(t,n){for(var o=e;o&&o.components&&!o.components.networked;)o=o.parentNode;if(!o||!o.components||!o.components.networked)return n("Entity does not have and is not a child of an entity with the [networked] component ");o.hasLoaded?t(o):o.addEventListener("instantiated",function(){t(o)},{once:!0})})},e.exports.takeOwnership=function(e){for(var t=e;t&&t.components&&!t.components.networked;)t=t.parentNode;if(!t||!t.components||!t.components.networked)throw new Error("Entity does not have and is not a child of an entity with the [networked] component ");return t.components.networked.takeOwnership()},e.exports.isMine=function(e){for(var t=e;t&&t.components&&!t.components.networked;)t=t.parentNode;if(!t||!t.components||!t.components.networked)throw new Error("Entity does not have and is not a child of an entity with the [networked] component ");return!!t.components.networked.data&&t.components.networked.data.owner===NAF.clientId},e.exports.almostEqualVec3=function(e,t,n){return Math.abs(e.x-t.x)<n&&Math.abs(e.y-t.y)<n&&Math.abs(e.z-t.z)<n},e.exports.vectorRequiresUpdate=function(e){return function(){var t=null;return function(n){return null===t?(t=new THREE.Vector3(n.x,n.y,n.z),!0):!NAF.utils.almostEqualVec3(t,n,e)&&(t.copy(n),!0)}}}}},t={};function n(o){var i=t[o];if(void 0!==i)return i.exports;var r=t[o]={exports:{}};return e[o](r,r.exports,n),r.exports}n(199),n(673),n(924),n(909),n(126),n(435)})();
\ No newline at end of file |