diff --git a/dist/networked-aframe.js b/dist/networked-aframe.js index 75099012..a4ee9f4b 100644 --- a/dist/networked-aframe.js +++ b/dist/networked-aframe.js @@ -47,7 +47,7 @@ eval("// Patched version of fast-deep-equal which does not\n// allocate memory v \*************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { -eval("var options = __webpack_require__(/*! ./options */ \"./src/options.js\");\nvar utils = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\nvar NafLogger = __webpack_require__(/*! ./NafLogger */ \"./src/NafLogger.js\");\nvar Schemas = __webpack_require__(/*! ./Schemas */ \"./src/Schemas.js\");\nvar NetworkEntities = __webpack_require__(/*! ./NetworkEntities */ \"./src/NetworkEntities.js\");\nvar NetworkConnection = __webpack_require__(/*! ./NetworkConnection */ \"./src/NetworkConnection.js\");\nvar AdapterFactory = __webpack_require__(/*! ./adapters/AdapterFactory */ \"./src/adapters/AdapterFactory.js\");\nvar naf = {};\nnaf.app = '';\nnaf.room = '';\nnaf.clientId = '';\nnaf.options = options;\nnaf.utils = utils;\nnaf.log = new NafLogger();\nnaf.schemas = new Schemas();\nnaf.version = \"0.12.1\";\nnaf.adapters = new AdapterFactory();\nvar entities = new NetworkEntities();\nvar connection = new NetworkConnection(entities);\nnaf.connection = connection;\nnaf.entities = entities;\nmodule.exports = window.NAF = naf;\n\n//# sourceURL=webpack://networked-aframe/./src/NafIndex.js?"); +eval("var options = __webpack_require__(/*! ./options */ \"./src/options.js\");\nvar utils = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\nvar NafLogger = __webpack_require__(/*! ./NafLogger */ \"./src/NafLogger.js\");\nvar Schemas = __webpack_require__(/*! ./Schemas */ \"./src/Schemas.js\");\nvar NetworkEntities = __webpack_require__(/*! ./NetworkEntities */ \"./src/NetworkEntities.js\");\nvar NetworkConnection = __webpack_require__(/*! ./NetworkConnection */ \"./src/NetworkConnection.js\");\nvar AdapterFactory = __webpack_require__(/*! ./adapters/AdapterFactory */ \"./src/adapters/AdapterFactory.js\");\nvar naf = {};\nnaf.app = '';\nnaf.room = '';\nnaf.clientId = '';\nnaf.options = options;\nnaf.utils = utils;\nnaf.log = new NafLogger();\nnaf.schemas = new Schemas();\nnaf.version = \"0.12.2\";\nnaf.adapters = new AdapterFactory();\nvar entities = new NetworkEntities();\nvar connection = new NetworkConnection(entities);\nnaf.connection = connection;\nnaf.entities = entities;\nmodule.exports = window.NAF = naf;\n\n//# sourceURL=webpack://networked-aframe/./src/NafIndex.js?"); /***/ }), diff --git a/dist/networked-aframe.min.js b/dist/networked-aframe.min.js index 823f2dbb..e275aa78 100644 --- a/dist/networked-aframe.min.js +++ b/dist/networked-aframe.min.js @@ -1 +1 @@ -(()=>{var t={934:t=>{"use strict";var e=function(){function t(t,e){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:0,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.15;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.state=0,this.buffer=[],this.bufferTime=1e3*n,this.time=0,this.mode=e,this.originFrame=i(),this.position=new THREE.Vector3,this.quaternion=new THREE.Quaternion,this.scale=new THREE.Vector3(1,1,1)}return e(t,[{key:"hermite",value:function(t,e,n,i,o,r){var s=e*e,a=e*e*e,c=2*a-3*s+1,u=-2*a+3*s,l=a-2*s+e,h=a-s;t.copy(n.multiplyScalar(c)),t.add(i.multiplyScalar(u)),t.add(o.multiplyScalar(l)),t.add(r.multiplyScalar(h))}},{key:"lerp",value:function(t,e,n,i){t.lerpVectors(e,n,i)}},{key:"slerp",value:function(t,e,n,i){t.slerpQuaternions(e,n,i)}},{key:"updateOriginFrameToBufferTail",value:function(){var t;t=this.originFrame,n.push(t),this.originFrame=this.buffer.shift()}},{key:"appendBuffer",value:function(t,e,n,o){var r=this.buffer.length>0?this.buffer[this.buffer.length-1]:null;if(r&&r.time===this.time)t&&r.position.copy(t),e&&r.velocity.copy(e),n&&r.quaternion.copy(n),o&&r.scale.copy(o);else{var s=r||this.originFrame,a=i();a.position.copy(t||s.position),a.velocity.copy(e||s.velocity),a.quaternion.copy(n||s.quaternion),a.scale.copy(o||s.scale),a.time=this.time,this.buffer.push(a)}}},{key:"setTarget",value:function(t,e,n,i){this.appendBuffer(t,e,n,i)}},{key:"setPosition",value:function(t,e){this.appendBuffer(t,e,null,null)}},{key:"setQuaternion",value:function(t){this.appendBuffer(null,null,t,null)}},{key:"setScale",value:function(t){this.appendBuffer(null,null,null,t)}},{key:"update",value:function(t){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 e=this.time-this.bufferTime;this.buffer.length>0&&e>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+t);if(this.buffer.length>0&&this.buffer[0].time>0){var n=this.buffer[0],i=n.time-this.originFrame.time,o=(e-this.originFrame.time)/i;0===this.mode?this.lerp(this.position,this.originFrame.position,n.position,o):1===this.mode&&this.hermite(this.position,o,this.originFrame.position,n.position,this.originFrame.velocity.multiplyScalar(i),n.velocity.multiplyScalar(i)),this.slerp(this.quaternion,this.originFrame.quaternion,n.quaternion,o),this.lerp(this.scale,this.originFrame.scale,n.scale,o)}}0!==this.state&&(this.time+=t)}},{key:"getPosition",value:function(){return this.position}},{key:"getQuaternion",value:function(){return this.quaternion}},{key:"getScale",value:function(){return this.scale}}]),t}();t.exports=o},737:t=>{function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,e){for(var n=0;n{"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}var n=Array.isArray,i=Object.keys,o=Object.prototype.hasOwnProperty;t.exports=function t(r,s){if(r===s)return!0;if(r&&s&&"object"==e(r)&&"object"==e(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(!t(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=i(r);if((c=v.length)!==i(s).length)return!1;for(a=c;0!=a--;)if(!o.call(s,v[a]))return!1;for(a=c;0!=a--;)if(!t(r[u=v[a]],s[u]))return!1;return!0}return r!=r&&s!=s}},199:(t,e,n)=>{var i=n(172),o=n(347),r=n(759),s=n(758),a=n(815),c=n(192),u=n(724),l={app:"",room:"",clientId:""};l.options=i,l.utils=o,l.log=new r,l.schemas=new s,l.version="0.12.1",l.adapters=new u;var h=new a,d=new c(h);l.connection=d,l.entities=h,t.exports=window.NAF=l},564:t=>{function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,e){for(var n=0;n{function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,e){for(var n=0;n{function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,e){for(var n=0;n3&&void 0!==arguments[3]&&arguments[3],o=arguments.length>4&&void 0!==arguments[4]&&arguments[4];NAF.app=e,NAF.room=n,this.adapter.setServerUrl(t),this.adapter.setApp(e),this.adapter.setRoom(n);var r={audio:i,video:o,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(t){this.onConnectCallback=t,this.isConnected()?t():document.body.addEventListener("connected",t,!1)}},{key:"connectSuccess",value:function(t){NAF.log.write("Networked-Aframe Client ID:",t),NAF.clientId=t;var e=new CustomEvent("connected",{detail:{clientId:t}});document.body.dispatchEvent(e)}},{key:"connectFailure",value:function(t,e){NAF.log.error(t,"failure to connect")}},{key:"occupantsReceived",value:function(t){var e=Object.assign({},this.connectedClients);this.connectedClients=t,this.checkForDisconnectingClients(e,t),this.checkForConnectingClients(t)}},{key:"checkForDisconnectingClients",value:function(t,e){for(var n in t)e[n]||(NAF.log.write("Closing stream to",n),this.adapter.closeStreamConnection(n))}},{key:"checkForConnectingClients",value:function(t){for(var e in t)this.isNewClient(e)&&this.adapter.shouldStartConnectionTo(t[e])&&(NAF.log.write("Opening datachannel to",e),this.adapter.startStreamConnection(e))}},{key:"getConnectedClients",value:function(){return this.connectedClients}},{key:"isConnected",value:function(){return!!NAF.clientId}},{key:"isMineAndConnected",value:function(t){return this.isConnected()&&NAF.clientId===t}},{key:"isNewClient",value:function(t){return!this.isConnectedTo(t)}},{key:"isConnectedTo",value:function(t){return this.adapter.getConnectStatus(t)===NAF.adapters.IS_CONNECTED}},{key:"dataChannelOpen",value:function(t){NAF.log.write("Opened data channel from "+t),this.activeDataChannels[t]=!0,this.entities.completeSync(t,!0);var e=new CustomEvent("clientConnected",{detail:{clientId:t}});document.body.dispatchEvent(e)}},{key:"dataChannelClosed",value:function(t){NAF.log.write("Closed data channel from "+t),this.activeDataChannels[t]=!1,this.entities.removeEntitiesOfClient(t);var e=new CustomEvent("clientDisconnected",{detail:{clientId:t}});document.body.dispatchEvent(e)}},{key:"hasActiveDataChannel",value:function(t){return!!this.activeDataChannels[t]}},{key:"broadcastData",value:function(t,e){this.adapter.broadcastData(t,e)}},{key:"broadcastDataGuaranteed",value:function(t,e){this.adapter.broadcastDataGuaranteed(t,e)}},{key:"sendData",value:function(t,e,n,i){this.hasActiveDataChannel(t)&&(i?this.adapter.sendDataGuaranteed(t,e,n):this.adapter.sendData(t,e,n))}},{key:"sendDataGuaranteed",value:function(t,e,n){this.sendData(t,e,n,!0)}},{key:"subscribeToDataChannel",value:function(t,e){this.isReservedDataType(t)?NAF.log.error("NetworkConnection@subscribeToDataChannel: "+t+" is a reserved dataType. Choose another"):this.dataChannelSubs[t]=e}},{key:"unsubscribeToDataChannel",value:function(t){this.isReservedDataType(t)?NAF.log.error("NetworkConnection@unsubscribeToDataChannel: "+t+" is a reserved dataType. Choose another"):delete this.dataChannelSubs[t]}},{key:"isReservedDataType",value:function(t){return"u"==t||"r"==t}},{key:"receivedData",value:function(t,e,n,i){this.dataChannelSubs[e]?this.dataChannelSubs[e](t,e,n,i):NAF.log.write("NetworkConnection@receivedData: "+e+" 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)}}],i&&n(e.prototype,i),Object.defineProperty(e,"prototype",{writable:!1}),t}();t.exports=o},815:(t,e,n)=>{function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function o(t,e){for(var n=0;n{function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,e){for(var n=0;n is defined."));if(!this.validateTemplate(t,e))return;this.templateCache[t.template]=document.importNode(e.content,!0)}else NAF.log.error("Schema not valid: ",t),NAF.log.error("See https://github.com/networked-aframe/networked-aframe#syncing-custom-components")}},{key:"getCachedTemplate",value:function(t){return this.templateIsCached(t)||(this.templateExistsInScene(t)?this.add(this.createDefaultSchema(t)):NAF.log.error("Template el for ".concat(t," is not in the scene, add the template to and register with NAF.schemas.add."))),this.templateCache[t].firstElementChild.cloneNode(!0)}},{key:"templateIsCached",value:function(t){return!!this.templateCache[t]}},{key:"getComponents",value:function(t){var e=["position","rotation"];return this.hasTemplate(t)&&(e=this.schemaDict[t].components),e}},{key:"hasTemplate",value:function(t){return!!this.schemaDict[t]}},{key:"templateExistsInScene",value:function(t){var e=document.querySelector(t);return e&&this.isTemplateTag(e)}},{key:"validateSchema",value:function(t){return!(!t.template||!t.components)}},{key:"validateTemplate",value:function(t,e){return this.isTemplateTag(e)?!!this.templateHasOneOrZeroChildren(e)||(NAF.log.error("Template for ".concat(t.template," has more than one child. Templates must have one direct child element, no more. Template found:"),e),!1):(NAF.log.error("Template for ".concat(t.template," is not a