networked-aframe
Version:
A web framework for building multi-user virtual reality experiences.
1 lines • 98.1 kB
JavaScript
(()=>{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,n){if("object"!=t(e)||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var i=o.call(e,"string");if("object"!=t(i))return i;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.0",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,n){if("object"!=t(e)||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var i=o.call(e,"string");if("object"!=t(i))return i;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,n){if("object"!=t(e)||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var i=o.call(e,"string");if("object"!=t(i))return i;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,n){if("object"!=t(e)||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var i=o.call(e,"string");if("object"!=t(i))return i;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,t){if("object"!=o(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,"string");if("object"!=o(i))return i;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,n){if("object"!=t(e)||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var i=o.call(e,"string");if("object"!=t(i))return i;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,t){if("object"!=o(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,"string");if("object"!=o(i))return i;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,t){if("object"!=o(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,"string");if("object"!=o(i))return i;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,this.easyrtc.joinRoom(e,null)}},{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){this.easyrtc.setRoomOccupantListener((function(t,n,o){e(n)}))}},{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._myRoomJoinTime=e._getRoomJoinTime(o),e.connectSuccess(o)})).catch(this.connectFailure)}},{key:"shouldStartConnectionTo",value:function(e){return 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,t){if("object"!=o(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,"string");if("object"!=o(i))return i;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,t){if("object"!=o(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,"string");if("object"!=o(i))return i;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,this.easyrtc.joinRoom(e,null)}},{key:"setWebRtcOptions",value:function(e){}},{key:"setServerConnectListeners",value:function(e,t){this.connectSuccess=e,this.connectFailure=t}},{key:"setRoomOccupantListener",value:function(e){this.easyrtc.setRoomOccupantListener((function(t,n,o){e(n)}))}},{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.connectSuccess(o)})).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,n){if("object"!=t(e)||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var i=o.call(e,"string");if("object"!=t(i))return i;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,n){if("object"!=t(e)||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var i=o.call(e,"string");if("object"!=t(i))return i;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.