kevoree-group-centralizedws
Version:
WebSocket group based on a centralized architecture that only sends partial model to connected clients
1 lines • 35.9 kB
JavaScript
!function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=14)}([function(e,t){e.exports=KevoreeLibrary},function(e,t,n){"use strict";e.exports=function(e){if(e)for(var t=0;t<e.fragmentDictionary.array.length;t++){var n=e.fragmentDictionary.array[t],r=n.findValuesByID("isMaster");if(r&&"true"===r.value)return e.findSubNodesByID(n.name)}return null}},function(e,t,n){"use strict";function r(e){this.model=e}r.prototype={getModel:function(){return this.model},getType:function(){return"push"},toRaw:function(){return"push/"+this.model}},e.exports=r,e.exports.TYPE="push"},function(e,t,n){"use strict";function r(e){this.kevs=e}r.prototype={getKevScript:function(){return this.kevs},getType:function(){return"kevs"},toRaw:function(){return"kevs/"+this.kevs}},e.exports=r,e.exports.TYPE="kevs"},function(e,t,n){"use strict";function r(e,t){this.nodeName=e,this.model=t}var o="register";r.prototype={getNodeName:function(){return this.nodeName},getModel:function(){return this.model},getType:function(){return o},toRaw:function(){return o+"/"+this.nodeName+"/"+this.model}},e.exports=r,e.exports.TYPE=o},function(e,t,n){"use strict";function r(){}var o="registered";r.prototype={getType:function(){return o},toRaw:function(){return o}},e.exports=r,e.exports.TYPE=o},function(e,t,n){"use strict";var r="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";e.exports=function(e){void 0===e&&(e=5);for(var t="",n=0;n<e;n++)t+=r.charAt(Math.floor(Math.random()*r.length));return t}},function(e,t,n){"use strict";function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function o(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"===(void 0===e?"undefined":c(e))&&null!==e}function u(e){return void 0===e}var c="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};e.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,n,r,i,c,a;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var f=new Error('Uncaught, unspecified "error" event. ('+t+")");throw f.context=t,f}if(n=this._events[e],u(n))return!1;if(o(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:i=Array.prototype.slice.call(arguments,1),n.apply(this,i)}else if(s(n))for(i=Array.prototype.slice.call(arguments,1),a=n.slice(),r=a.length,c=0;c<r;c++)a[c].apply(this,i);return!0},r.prototype.addListener=function(e,t){var n;if(!o(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,o(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(n=u(this._maxListeners)?r.defaultMaxListeners:this._maxListeners)&&n>0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!o(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},r.prototype.removeListener=function(e,t){var n,r,i,u;if(!o(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],i=n.length,r=-1,n===t||o(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(n)){for(u=i;u-- >0;)if(n[u]===t||n[u].listener&&n[u].listener===t){r=u;break}if(r<0)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],o(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){return this._events&&this._events[e]?o(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(o(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t,n){"use strict";function r(){throw new Error("WebSocketServer are not supported in browser environment.")}WebSocket.prototype.on=function(e,t){this["on"+e]=t},WebSocket.prototype.off=function(e,t){"function"==typeof t&&this["on"+e]===t&&delete this["on"+e]},e.exports=WebSocket,e.exports.Server=r},function(e,t,n){"use strict";function r(e){var t=void 0;if("object"===(void 0===e?"undefined":o(e))&&(e=e.data),e.startsWith(i.TYPE))return new i;if(e.startsWith(a.TYPE))return new a;if(e.startsWith(s.TYPE+"/"))return t=e.substring(s.TYPE.length+1),new s(t);if(e.startsWith(u.TYPE+"/"))return t=e.substring(u.TYPE.length+1),new u(t);if(e.startsWith(c.TYPE)){for(var n=e.substring(c.TYPE.length+1),r=0,f=n.charAt(r);r<n.length&&"/"!==f;)r++,f=n[r];var l=n.substring(0,r);return new c(l,n.substring(r+1))}return null}var 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},i=n(10),s=n(2),u=n(3),c=n(4),a=n(5);e.exports={parse:r}},function(e,t,n){"use strict";function r(){}r.prototype={getType:function(){return"pull"},toRaw:function(){return"pull"}},e.exports=r,e.exports.TYPE="pull"},function(e,t,n){"use strict";e.exports=function(e,t){return e&&"string"==typeof e?e.length>t?e.substr(0,t-3)+"...":e.substr(0,t):e}},function(e,t,n){"use strict";function r(e,t,n){return!!e&&e.bindings.array.some(function(e){if(e.port&&e.port.eContainer()){var r=e.port.eContainer().eContainer();if(r.name===t||r.name===n)return!0}return!1})}function o(e,t,n){if(e){if(r(e.hub,t,n))return!0;if(e.port&&e.port.eContainer()){var i=e.port.eContainer().eContainer();if(i.name===t||i.name===n)return!0;e.port.bindings.array.some(function(r){return e.path()!==r.path()&&o(r,t,n)})}}}function i(e,t,n){return e.bindings.array.some(function(e){return!!o(e,t,n)})}function s(e,t,n){return!!e.provided.array.some(function(e){return!!i(e,t,n)})||e.required.array.some(function(e){return!!i(e,t,n)})}function u(e){return/^\/packages\[([\w]+)\]/.exec(e.typeDefinition.path())[1]}function c(e){var t=[];return t.push(u(e)),e.components.array.forEach(function(e){t.push(u(e))}),e.hosts.array.forEach(function(e){t.push(u(e))}),e.groups.array.forEach(function(e){t.push(u(e))}),t}function a(e,t,n){e.nodes.array.forEach(function(e){if(e.name!==t&&e.name!==n){e.components.array.some(function(e){return!!s(e,t,n)})||e.delete()}})}function f(e,t,n){e.mBindings.array.forEach(function(e){r(e.hub,t,n)||e.delete()})}function l(e,t,n){e.hubs.array.forEach(function(e){0===e.bindings.array.length?e.delete():r(e,t,n)||e.delete()})}function p(e,t,n){e.groups.array.forEach(function(e){var r=e.findSubNodesByID(t);r||(r=e.findSubNodesByID(n))||e.delete()})}function d(e,t,n){var r=[],o=e.findNodesByID(t),i=e.findNodesByID(n);o&&(r=r.concat(c(o))),i&&(r=r.concat(c(i))),r=g(r),e.packages.array.forEach(function(e){-1===r.indexOf(e.name)&&e.delete()})}function h(e,t,n){var r=new y.factory.DefaultKevoreeFactory,o=r.createModelCloner(),i=o.clone(e);return a(i,t,n),f(i,t,n),l(i,t,n),p(i,t,n),d(i,t,n),i}var y=n(0),g=n(23);e.exports=h},function(e,t,n){"use strict";function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(e){if(l===setTimeout)return setTimeout(e,0);if((l===r||!l)&&setTimeout)return l=setTimeout,setTimeout(e,0);try{return l(e,0)}catch(t){try{return l.call(null,e,0)}catch(t){return l.call(this,e,0)}}}function s(e){if(p===clearTimeout)return clearTimeout(e);if((p===o||!p)&&clearTimeout)return p=clearTimeout,clearTimeout(e);try{return p(e)}catch(t){try{return p.call(null,e)}catch(t){return p.call(this,e)}}}function u(){g&&h&&(g=!1,h.length?y=h.concat(y):m=-1,y.length&&c())}function c(){if(!g){var e=i(u);g=!0;for(var t=y.length;t;){for(h=y,y=[];++m<t;)h&&h[m].run();m=-1,t=y.length}h=null,g=!1,s(e)}}function a(e,t){this.fun=e,this.array=t}function f(){}var l,p,d=e.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:r}catch(e){l=r}try{p="function"==typeof clearTimeout?clearTimeout:o}catch(e){p=o}}();var h,y=[],g=!1,m=-1;d.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];y.push(new a(e,t)),1!==y.length||g||i(c)},a.prototype.run=function(){this.fun.apply(null,this.array)},d.title="browser",d.browser=!0,d.env={},d.argv=[],d.version="",d.versions={},d.on=f,d.addListener=f,d.once=f,d.off=f,d.removeListener=f,d.removeAllListeners=f,d.emit=f,d.prependListener=f,d.prependOnceListener=f,d.listeners=function(e){return[]},d.binding=function(e){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(e){throw new Error("process.chdir is not supported")},d.umask=function(){return 0}},function(e,t,n){"use strict";var r=n(15),o=n(16),i=n(17);r.register(o.name,o.version,i)},function(e,t){e.exports=KevoreeModuleLoader},function(e,t){e.exports={name:"kevoree-group-centralizedws",version:"1.0.24",description:"WebSocket group based on a centralized architecture that only sends partial model to connected clients",main:"lib/CentralizedWSGroup.js",scripts:{prestart:"npm run build",pretest:"npm run build",prepublishOnly:"npm run test",start:"kevoree-scripts start",build:"kevoree-scripts build",test:"mocha test","kev:publish":"kevoree-scripts publish",postpublish:"npm run kev:publish"},kevoree:{namespace:"kevoree",browser:"lib/browser.js"},browser:{ws:"./ws-shim.js"},dependencies:{"kevoree-entities":"^9.2.4","kevoree-library":"^5.0.13",rwebsocket:"^1.0.1",ws:"^1.1.1"},optionalDependencies:{bufferutil:"^1.3.0","utf-8-validate":"^2.0.0"},devDependencies:{"csv-write-stream":"^2.0.0",eslint:"^4.3.0","eslint-config-kevoree":"^1.0.1",expect:"^1.20.2","kevoree-scripts":"^1.1.2",mocha:"^3.4.2"},repository:{type:"git",url:"git+https://github.com/kevoree/kevoree-js-group-centralizedws.git"},keywords:["kevoree","ws","group","centralized","partial","model"],author:"Maxime Tricoire <max.tricoire@gmail.com>",license:"LGPL-3.0",bugs:{url:"https://github.com/kevoree/kevoree-js-group-centralizedws/issues"},homepage:"https://github.com/kevoree/kevoree-js-group-centralizedws#readme"}},function(e,t,n){"use strict";function r(e,t){return{info:function(n){e.info(t+" "+n)},debug:function(n){e.debug(t+" "+n)},warn:function(n){e.warn(t+" "+n)},error:function(n){e.error(t+" "+n)}}}var o=n(18),i=n(22),s=n(34),u=o.extend({toString:"CentralizedWSGroup",tdef_version:2,dic_isMaster:{optional:!1,defaultValue:!1,fragmentDependant:!0},dic_masterNet:{optional:!1,defaultValue:"lo.ipv4",fragmentDependant:!0},dic_port:{optional:!1,defaultValue:9e3},dic_onDisconnect:{defaultValue:""},dic_reduceModel:{optional:!1,defaultValue:!0},start:function(e){var t=this,n=this.dictionary.getBoolean("isMaster",this.dic_isMaster.defaultValue),o=this.dictionary.getString("masterNet",this.dic_masterNet.defaultValue),u=this.dictionary.getNumber("port",this.dic_port.defaultValue),c=o.match(/^([a-z0-9A-Z]+)\.([a-z0-9A-Z]+)$/);if(c&&c.length>0){if(n)this.fragment=i.create(r(this.log,"[master]"),u,this),e();else try{this.fragment=s.create(r(this.log,"[client]"),u,this,c[1],c[2]),e()}catch(t){e(t)}var a=this;this.dictionary.on("port",function(){n&&t.fragment.broadcast(r(t.log,"[master]"),t),t.stop(function(){a.start(function(){})})})}else e(new Error('"masterNet" param must comply with /^[a-z0-9A-Z]+\\.[a-z0-9A-Z]+$/'))},stop:function(e){this.fragment&&this.fragment.close(this),e()}});e.exports=u},function(e,t,n){"use strict";var r=n(19),o=r.extend({toString:"AbstractGroup",updateModel:function(e){this.kCore.deploy(e)}});e.exports=o},function(e,t,n){"use strict";var r=n(20),o=n(21),i=r({toString:"KevoreeEntity",construct:function(e,t,n){this.kCore=e,this.nodeName=n,this.name=t.name,this.path=t.path(),this.started=!1,this.dictionary=new o(this),this.log=this.kCore.getLoggerFactory().create(t.typeDefinition.name,t.name)},start:function(e){e()},stop:function(e){e()},update:function(e){e()},__start__:function(e){this.started=!0,this.start(e)},__stop__:function(e){this.started=!1,this.stop(e)},__update__:function(e){this.update(e)},__destruct__:function(){this.kCore.getLoggerFactory().delete(this.log)},getKevoreeCore:function(){return this.kCore},getDictionary:function(){return this.dictionary},getName:function(){return this.name},getNodeName:function(){return this.nodeName},getPath:function(){return this.path},getModelEntity:function(){var e=this.kCore.getDeployModel();return e||(e=this.kCore.getCurrentModel()),e.findByPath(this.path)},getNetworkInfos:function(e){var t=this.kCore.getDeployModel();t||this.kCore.getCurrentModel();var n=t.findNodesByID(e);return n?n.networkInformation.iterator():null},isStarted:function(){return this.started},submitScript:function(e,t){this.getKevoreeCore().submitScript(e,t)}});i.DIC="dic_",e.exports=i},function(e,t,n){"use strict";!function(t){function n(){var e,t,n,r,o;for(n=arguments,e=0,t=n.length;e<t;e++){r=n[e];for(o in r)this[o]=r[o]}return this}function r(e){return function(){return this[e].apply(this,arguments)}}function o(e,t){var o,i,s,u,c,a;e.properties=t,c={},o=e;do{if(o.properties)for(s in o.properties)a=c[s]||(c[s]=[]),a.unshift(o.properties[s]);o=o.superConstructor}while(o);u={};for(s in c)i=u[s]=n.apply({},c[s]),"string"==typeof i.set&&(i.set=r(i.set)),"string"==typeof i.get&&(i.get=r(i.get));e.properties=u}var i=function(){},s=/xyz/.test(function(){return"xyz"})?/\._super\b/:{test:function(){return!0}},u=function(e,t,n){return function(){var r=this._super;this._super=n[e];var o=t.apply(this,arguments);return this._super=r,o}},c=function(e,t,n){var r=n[e];return function(){return this._super=r,t.apply(this,arguments)}},a=function(e,t){t=t||this.constructor&&this.constructor.prototype;for(var n in e){var r=e[n];if("construct"!==n&&"destruct"!==n){t&&"function"==typeof r&&"function"==typeof t[n]&&s.test(r)?this.hasOwnProperty(n)?this[n]=c(n,r,this):this[n]=u(n,r,t):this[n]=r}}},f=function e(t){return t&&t.extend?t.extend.extend(t):e.extend(t)};f.prototype.mixin=a,f.extend=function e(t){function n(){if(this instanceof n==!1)throw new Error("Cannot create instance without new operator");var e=n.properties;e&&Object.defineProperties(this,e),this.construct.apply(this,arguments),this.init()}var r=this,s=this.prototype;n.superConstructor=r,n.extend=e;var u=n.prototype=Object.create(s);if(u.constructor=n,u.superPrototype=s,t){var c=t.properties;if(delete t.properties,a.call(u,t,s),Array.isArray(t.mixins))for(var f=0,l=t.mixins.length;f<l;f++)a.call(u,t.mixins[f],u);if(o(n,c),t.construct){var p=t.construct;s.construct?u.construct=function(){s.construct.apply(this,arguments),p.apply(this,arguments)}:u.construct=p}if(t.destruct){var d=t.destruct;s.destruct?u.destruct=function(){d.apply(this,arguments),s.destruct.apply(this,arguments)}:u.destruct=d}if("string"==typeof t.toString){var h=t.toString;u.toString=function(){return h}}}return"function"!=typeof u.construct&&(u.construct=i),"function"!=typeof u.init&&(u.init=i),n},void 0!==e&&e.exports?e.exports=f:"function"==typeof t.define?function(e){e(function(){return f})}(t.define):(t.PseudoClass=f,t.Class||(t.Class=f))}(void 0)},function(e,t,n){"use strict";function r(e){this.entity=e,this.emitter=new i.EventEmitter,this.map={}}var o=n(0),i=n(7);r.prototype={on:function(e,t){this.emitter.addListener(e,t.bind(this.entity))},off:function(e,t){this.emitter.removeListener(e,t)},getValue:function(e){return this.map[e]},getBoolean:function(e,t){var n=this.map[e];return"true"===n||"false"===n?"true"===n:(void 0===t&&(t=!1),t)},getString:function(e,t){var n=this.map[e];return"string"==typeof n?n:("string"!=typeof t&&(t=null),t)},getNumber:function(e,t){var n=void 0;return n=this.map[e]&&0===this.map[e].length?null:+this.map[e],isNaN(n)?"number"!=typeof t?null:t:n},setValue:function(e,t){var n=new o.factory.DefaultKevoreeFactory,r=this.entity.getModelEntity();r.dictionary||(r.dictionary=n.createDictionary()),t=r.dictionary.findValuesByID(e),t||(t=n.createDictionaryValue(),t.name=e,r.dictionary.addValues(t)),t.value=t,this.setEntry(e,t)},setEntry:function(e,t){var n=this.map[e];this.map[e]=t,this.entity.isStarted()&&this.emitter.emit(e,t,n)},setMap:function(e){var t=void 0;if(Object.keys(this.map).length>0)for(var n in e){var r=!1;for(t in this.map)if(n===t){var o=this.map[t];o!==e[t]&&(this.map[t]=e[t],this.emitter.emit(t,this.map[t],o)),r=!0}r||(this.map[n]=e[n])}else this.map=e},getMap:function(){return this.map},cloneMap:function(){var e={};for(var t in this.map)e[t]=this.map[t];return e},toString:function(){return"Dictionary"}},e.exports=r},function(e,t,n){"use strict";function r(e){return e&&e.length>0?", status="+e:""}function o(e,t,n,r,o){var i=a.parse(r);if(i)if(n.id)switch(e.debug('received message from node "'+S[n.id]+'" (id='+n.id+",msg="+h(r,20)+")"),i.getType()){case p.TYPE:v(e,S,n,o);break;case d.TYPE:e.debug("submitting kevscript:"),e.debug(i.getKevScript()),o.submitScript(i.getKevScript(),function(){e.debug("script executed")});break;default:e.warn('protocol message type "'+i.getType()+'" send by registered node (ignored)')}else switch(e.debug("received message from unknown client (msg="+h(r,20)+")"),i.getType()){case p.TYPE:v(e,S,n,o);break;case f.TYPE:m(e,S,n,i,o);break;case l.TYPE:b(e,t,S,n,i,o);break;default:e.warn('protocol message type "'+i.getType()+'" send by unknown client (ignored)')}else e.warn("unable to parse msg: "+h(r,20))}function i(e,t,n,o,i){if(t.id)e.info('node "'+S[t.id]+'" disconnected (id='+t.id+",code="+o+r(i)+")"),w(e,S,t,n,1e3===i);else{var s="unknown";t.upgradeReq.headers.origin&&(s=t.upgradeReq.headers.origin),e.debug('client "'+s+'" disconnected')}}function s(e,t,n,r){n.on("message",function(i){o(e,t,n,i,r)}),n.on("close",function(t,o){i(e,n,r,t,o)})}var u=n(8),c=n(0),a=n(9),f=n(4),l=n(2),p=n(10),d=n(3),h=n(11),y=n(12),g=n(1),m=n(24),v=n(30),b=n(31),w=n(32),S={};e.exports={client2name:S,create:function(e,t,n){var r=this;return this.server=new u.Server({port:t},function(){e.info("listening on 0.0.0.0:"+t)}),this.server.on("connection",function(t){s(e,r.server,t,n)}),this.deployHandler=function(){r.server.clients.length>0&&!n.isRegister?(e.debug("=== Broadcast new model to clients ==="),r.broadcast(e,n),e.debug("=== Broadcast done ===")):e.debug("Deployment is issued by a register (ignore broadcast)")},n.getKevoreeCore().on("deployed",this.deployHandler),this},broadcast:function(e,t){var n=new c.factory.DefaultKevoreeFactory,r=n.createJSONSerializer(),o=t.getKevoreeCore().getCurrentModel(),i=o,s=t.getModelEntity(),a=g(s).name,f=t.getDictionary().getBoolean("reduceModel",t.dic_reduceModel.defaultValue);this.server.clients.forEach(function(t){if(t.id){var n=S[t.id];f&&(i=y(o,a,n),e.debug(' ✔ reduced model for "'+n+'"'))}var s=r.serialize(i),c=new l(s).toRaw(),p="unknown";t.upgradeReq.headers.origin&&(p=t.upgradeReq.headers.origin),t.readyState===u.OPEN?(t.send(c),e.debug(' ✔ model pushed to "'+(S[t.id]?S[t.id]:p)+'"')):(e.debug(' ✘ unable to push to "'+(S[t.id]?S[t.id]:p)+'" (connection is closed)'),t.close())})},close:function(e){e.getKevoreeCore().off("deployed",this.deployHandler),this.server.close()}}},function(e,t,n){"use strict";e.exports=function(e){for(var t={},n=[],r=0;r<e.length;r++)t[e[r]]=!0;for(var o in t)n.push(o);return n}},function(e,t,n){"use strict";(function(t){var r=n(0),o=n(5),i=n(6),s=n(12),u=n(25),c=n(1);e.exports=function(e,n,a,f,l){if(n[a.id])e.warn('node "'+n[a.id]+'" is already registered (id='+a.id+")");else{a.id=i(10),n[a.id]=f.getNodeName(),e.info('node "'+f.getNodeName()+'" registered (id='+a.id+")");var p=new r.factory.DefaultKevoreeFactory,d=p.createJSONLoader(),h=p.createModelCloner(),y=null;try{y=d.loadModelFromString(f.getModel()).get(0)}catch(t){e.warn('erroneous model received from "'+f.getNodeName()+'" registration'),e.warn(t.stack)}if(y){var g=l.getModelEntity(),m=c(g);if(!m)throw new Error("Unable to find a master node");var v=m.name;e.debug('reducing register model for master "'+v+'" and client "'+f.getNodeName()+'"...');var b=s(y,v,f.getNodeName()),w=p.createModelCompare(),S=l.getKevoreeCore(),x=h.clone(S.getCurrentModel());w.merge(b,x).applyOn(b),l.isRegister=!0,e.debug("isRegister lock = true");var _=function(){e.debug("isRegister lock = false"),l.isRegister=!1};S.deploy(b).then(_,_)}a.send((new o).toRaw());new u(a,t.env.KEV_CWSG_HB||15e3).start()}}}).call(t,n(13))},function(e,t,n){"use strict";function r(e,t){var n=this;this.hbTimeout=t||c,this.client=e,e.on("pong",function(t){var r=t+"";r===n.pingMsg?(n.stop(),n.emit("pong",r),n.start()):(n.stop(),n.emit("pong-differs",r,n.pingMsg),e.close(4043,"pong answer differs from ping"))}),e.on("close",function(){n.emit("stop"),n.stop()})}var o=n(26),i=n(7),s=n(8),u=n(6),c=15e3;r.prototype={start:function(){var e=this;this.heartBeatTimeout=setTimeout(function(){e.sendHeartBeat()},this.hbTimeout)},stop:function(){clearTimeout(this.heartBeatTimeout),clearTimeout(this.pingTimeout)},sendHeartBeat:function(){var e=this;this.client.readyState===s.OPEN?(this.pingMsg=u(),this.client.ping(this.pingMsg,null,!1),this.emit("ping",this.pingMsg),this.pingTimeout=setTimeout(function(){e.stop(),e.emit("pong-timeout",e.pingMsg),e.client.close(4042,"no pong answer")},5e3)):(this.stop(),this.emit("not-connected"))}},o.inherits(r,i.EventEmitter),e.exports=r},function(e,t,n){"use strict";(function(e,r){function o(e,n){var r={seen:[],stylize:s};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),y(n)?r.showHidden=n:n&&t._extend(r,n),S(r.showHidden)&&(r.showHidden=!1),S(r.depth)&&(r.depth=2),S(r.colors)&&(r.colors=!1),S(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=i),c(r,e,r.depth)}function i(e,t){var n=o.styles[t];return n?"["+o.colors[n][0]+"m"+e+"["+o.colors[n][1]+"m":e}function s(e,t){return e}function u(e){var t={};return e.forEach(function(e,n){t[e]=!0}),t}function c(e,n,r){if(e.customInspect&&n&&T(n.inspect)&&n.inspect!==t.inspect&&(!n.constructor||n.constructor.prototype!==n)){var o=n.inspect(r,e);return b(o)||(o=c(e,o,r)),o}var i=a(e,n);if(i)return i;var s=Object.keys(n),y=u(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(n)),k(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return f(n);if(0===s.length){if(T(n)){var g=n.name?": "+n.name:"";return e.stylize("[Function"+g+"]","special")}if(x(n))return e.stylize(RegExp.prototype.toString.call(n),"regexp");if(E(n))return e.stylize(Date.prototype.toString.call(n),"date");if(k(n))return f(n)}var m="",v=!1,w=["{","}"];if(h(n)&&(v=!0,w=["[","]"]),T(n)){m=" [Function"+(n.name?": "+n.name:"")+"]"}if(x(n)&&(m=" "+RegExp.prototype.toString.call(n)),E(n)&&(m=" "+Date.prototype.toUTCString.call(n)),k(n)&&(m=" "+f(n)),0===s.length&&(!v||0==n.length))return w[0]+m+w[1];if(r<0)return x(n)?e.stylize(RegExp.prototype.toString.call(n),"regexp"):e.stylize("[Object]","special");e.seen.push(n);var S;return S=v?l(e,n,r,y,s):s.map(function(t){return p(e,n,r,y,t,v)}),e.seen.pop(),d(S,m,w)}function a(e,t){if(S(t))return e.stylize("undefined","undefined");if(b(t)){var n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string")}return v(t)?e.stylize(""+t,"number"):y(t)?e.stylize(""+t,"boolean"):g(t)?e.stylize("null","null"):void 0}function f(e){return"["+Error.prototype.toString.call(e)+"]"}function l(e,t,n,r,o){for(var i=[],s=0,u=t.length;s<u;++s)L(t,String(s))?i.push(p(e,t,n,r,String(s),!0)):i.push("");return o.forEach(function(o){o.match(/^\d+$/)||i.push(p(e,t,n,r,o,!0))}),i}function p(e,t,n,r,o,i){var s,u,a;if(a=Object.getOwnPropertyDescriptor(t,o)||{value:t[o]},a.get?u=a.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):a.set&&(u=e.stylize("[Setter]","special")),L(r,o)||(s="["+o+"]"),u||(e.seen.indexOf(a.value)<0?(u=g(n)?c(e,a.value,null):c(e,a.value,n-1),u.indexOf("\n")>-1&&(u=i?u.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+u.split("\n").map(function(e){return" "+e}).join("\n"))):u=e.stylize("[Circular]","special")),S(s)){if(i&&o.match(/^\d+$/))return u;s=JSON.stringify(""+o),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+u}function d(e,t,n){var r=0;return e.reduce(function(e,t){return r++,t.indexOf("\n")>=0&&r++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60?n[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+n[1]:n[0]+t+" "+e.join(", ")+" "+n[1]}function h(e){return Array.isArray(e)}function y(e){return"boolean"==typeof e}function g(e){return null===e}function m(e){return null==e}function v(e){return"number"==typeof e}function b(e){return"string"==typeof e}function w(e){return"symbol"===(void 0===e?"undefined":O(e))}function S(e){return void 0===e}function x(e){return _(e)&&"[object RegExp]"===M(e)}function _(e){return"object"===(void 0===e?"undefined":O(e))&&null!==e}function E(e){return _(e)&&"[object Date]"===M(e)}function k(e){return _(e)&&("[object Error]"===M(e)||e instanceof Error)}function T(e){return"function"==typeof e}function N(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"===(void 0===e?"undefined":O(e))||void 0===e}function M(e){return Object.prototype.toString.call(e)}function D(e){return e<10?"0"+e.toString(10):e.toString(10)}function C(){var e=new Date,t=[D(e.getHours()),D(e.getMinutes()),D(e.getSeconds())].join(":");return[e.getDate(),K[e.getMonth()],t].join(" ")}function L(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var 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},z=/%[sdj%]/g;t.format=function(e){if(!b(e)){for(var t=[],n=0;n<arguments.length;n++)t.push(o(arguments[n]));return t.join(" ")}for(var n=1,r=arguments,i=r.length,s=String(e).replace(z,function(e){if("%%"===e)return"%";if(n>=i)return e;switch(e){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(e){return"[Circular]"}default:return e}}),u=r[n];n<i;u=r[++n])g(u)||!_(u)?s+=" "+u:s+=" "+o(u);return s},t.deprecate=function(n,o){function i(){if(!s){if(r.throwDeprecation)throw new Error(o);r.traceDeprecation?console.trace(o):console.error(o),s=!0}return n.apply(this,arguments)}if(S(e.process))return function(){return t.deprecate(n,o).apply(this,arguments)};if(!0===r.noDeprecation)return n;var s=!1;return i};var j,P={};t.debuglog=function(e){if(S(j)&&(j=r.env.NODE_DEBUG||""),e=e.toUpperCase(),!P[e])if(new RegExp("\\b"+e+"\\b","i").test(j)){var n=r.pid;P[e]=function(){var r=t.format.apply(t,arguments);console.error("%s %d: %s",e,n,r)}}else P[e]=function(){};return P[e]},t.inspect=o,o.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},o.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},t.isArray=h,t.isBoolean=y,t.isNull=g,t.isNullOrUndefined=m,t.isNumber=v,t.isString=b,t.isSymbol=w,t.isUndefined=S,t.isRegExp=x,t.isObject=_,t.isDate=E,t.isError=k,t.isFunction=T,t.isPrimitive=N,t.isBuffer=n(28);var K=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];t.log=function(){console.log("%s - %s",C(),t.format.apply(t,arguments))},t.inherits=n(29),t._extend=function(e,t){if(!t||!_(t))return e;for(var n=Object.keys(t),r=n.length;r--;)e[n[r]]=t[n[r]];return e}}).call(t,n(27),n(13))},function(e,t,n){"use strict";var r,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};r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(e){"object"===("undefined"==typeof window?"undefined":o(window))&&(r=window)}e.exports=r},function(e,t,n){"use strict";var r="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};e.exports=function(e){return e&&"object"===(void 0===e?"undefined":r(e))&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},function(e,t,n){"use strict";"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t,n,o){var i=t[n.id];i?e.info("pull requested: "+i):e.info("pull requested");var s=new r.factory.DefaultKevoreeFactory,u=s.createJSONSerializer(),c=u.serialize(o.getKevoreeCore().getCurrentModel());n.send(c)}},function(e,t,n){"use strict";var r=n(0),o=n(6);e.exports=function(e,t,n,i,s,u){var c=n[i.id];if(c)e.info("push issued by: "+c);else{var a="anonymous";i.upgradeReq.headers.origin&&(a=i.upgradeReq.headers.origin),e.info("push issued by "+a)}var f=new r.factory.DefaultKevoreeFactory,l=f.createJSONLoader();try{var p=l.loadModelFromString(s.getModel()).get(0),d=o(10);p.generated_KMF_ID=d,t.modelId=d,u.getKevoreeCore().deploy(p)}catch(t){e.error("erroneous model received (push ignored)")}}},function(e,t,n){"use strict";var r=n(33);e.exports=function(e,t,n,o,i){var s=t[n.id];if(s&&(delete t[n.id],delete n.id,!i)){var u=o.getDictionary().getString("onDisconnect",o.dic_onDisconnect.defaultValue).trim();if(u.length>0){u=r(u,o.getName(),s),e.debug("submitting onDisconnect KevScript:"),e.debug(u);try{o.getKevoreeCore().submitScript(u)}catch(t){e.warn("onDisconnect KevScript interpretation error: "+o.getName()),e.warn(t.stack)}}}}},function(e,t,n){"use strict";e.exports=function(e,t,n){return e.replace(/{nodeName}/g,n).replace(/{groupName}/g,t)}},function(e,t,n){"use strict";function r(e,t,n,r,o){var i="";i=443===t?"wss://":"ws://";var s=u(n.getModelEntity());if(s){var a=c(n.getModelEntity(),s);if(a[r]){if(a[r][o])return i+a[r][o]+":"+t;throw new Error('Unable to find network value named "'+o+'" for master node "'+s.name+'"')}throw new Error('Unable to find network "'+r+'" for master node "'+s.name+'"')}throw new Error('No master node found. Did you set one node "isMaster" to "true"?')}var 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},i=n(35),s=n(11),u=n(1),c=n(37),a=n(38),f=n(39),l=n(9),p=n(2),d=n(5),h=n(3);e.exports={create:function(e,t,n,u,c){var y=this,g=r(e,t,n,u,c);return this.client=new i(g),this.client.onopen=function(){e.info("connected to "+g),a(e,y.client,n)},this.client.onmessage=function(t){"object"===(void 0===t?"undefined":o(t))&&(t=t.data);var r=l.parse(t);if(r)if(y.client.isRegistered)switch(r.getType()){case p.TYPE:f(e,r,n);break;case h.TYPE:e.debug("kevs push are not handled yet");break;default:e.warn("unknown message type: "+r.getType()+' (msg: "'+s(t,15)+'")')}else switch(r.getType()){case d.TYPE:y.client.isRegistered=!0;break;default:e.warn('ignoring message type "'+r.getType()+'" send by master (state: not yet registered)')}else e.warn("unable to parse message: "+s(t,20))},this.client.onclose=function(t){y.client.isRegistered=!1,1e3!==t.code||e.info("connection closed with "+g+" (code="+t.code+",reason="+t.status+")")},this.client.connect(),this},close:function(){this.client.close()}}},function(e,t,n){"use strict";function r(e,t,n){this.url=e,this.protocols=t,this.retryInterval=n||3e3}var o=n(36);r.prototype={connect:function(){var e=this;this.client=new o(this.url,this.protocols),this.readyState=this.client.readyState,this.protocol=this.client.protocol,this.client.onopen=function(){clearTimeout(e.connectTimeout),e.connectTimeout=null,e.onopen()},this.client.onmessage=function(t){e.onmessage(t)},this.client.onclose=function(t){1e3===t.code?(e.onclose(t),e.onterminate()):(e.onclose(t),clearTimeout(e.connectTimeout),e.connectTimeout=setTimeout(function(){e.connect()},e.retryInterval))},this.client.onerror=function(t){e.onerror(t),"ECONNREFUSED"===t.code&&(clearTimeout(e.connectTimeout),e.connectTimeout=setTimeout(function(){e.connect()},e.retryInterval))}},close:function(e,t){this.client&&(1e3===e?(clearTimeout(this.connectTimeout),this.client.close(e,t)):this.client.close(e,t))},terminate:function(e,t){this.client&&(clearTimeout(this.connectTimeout),this.client.close(e||1e3,t))},send:function(e){this.client&&this.client.send(e)},onopen:function(){},onmessage:function(){},onclose:function(){},onerror:function(){},onterminate:function(){}},e.exports=r},function(e,t,n){"use strict";WebSocket.prototype.on=function(e,t){this["on"+e]=t},WebSocket.prototype.off=function(e,t){"function"==typeof t&&this["on"+e]===t&&delete this["on"+e]},e.exports=WebSocket,e.exports.Server=function(){throw new Error("WebSocketServer is not supported in browser environment.")}},function(e,t,n){"use strict";e.exports=function(e,t){var n={};if(e){var r=e.findSubNodesByID(t.name);r&&r.networkInformation.array.forEach(function(e){n[e.name]={},e.values.array.forEach(function(t){n[e.name][t.name]=t.value})})}return n}},function(e,t,n){"use strict";var r=n(0),o=n(4);e.exports=function(e,t,n){var i=new r.factory.DefaultKevoreeFactory,s=i.createJSONSerializer(),u=void 0;try{u=s.serialize(n.getKevoreeCore().getCurrentModel())}catch(t){e.warn("unable to serialize register model")}if(u){var c=new o(n.getNodeName(),u);t.send(c.toRaw())}}},function(e,t,n){"use strict";var r=n(0),o=n(1);e.exports=function(e,t,n){var i=new r.factory.DefaultKevoreeFactory,s=i.createJSONLoader(),u=void 0;try{u=s.loadModelFromString(t.getModel()).get(0)}catch(t){e.warn('unable to parse model pushed from master "'+o(n.getModelEntity()).name+'"')}u&&n.getKevoreeCore().deploy(u)}}]);