endpointjs
Version:
Endpoint.js enables modules within a web application to discover and use each other, whether that be on the same web page, other browser windows and tabs, iframes, servers and web workers in a reactive way by providing robust discovery, execution and stre
9 lines • 200 kB
JavaScript
/**
* endpointjs - v0.4.1
* Built 2016-04-26
* Created in collaboration with Booz Allen Hamilton (www.boozallen.com)
* (C) 2016 Booz Allen Hamilton, All rights reserved
* Powered by InnoVision, created by the GIAT
*/
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){(function(c){"use strict";function d(a,b){if(!(this instanceof d))return new d(a,b);if(d.super_.call(this,a,{type:j.EndpointType.ADAPTER,id:i(),identification:h("[name: %s] [version: %s]",b.name,b.version)}),this._name=b.name,this._version=""+b.version,this._object=b.object||{},this._resolver=b.resolver||m({instanceId:a.getInstanceId(),id:this.getId()}),this._metadata=b.metadata||{},this._neighborhood=n.getNeighborhood(b.neighborhood,"group"),this._neighborhood===j.Neighborhood.GLOBAL)throw this.close(),new Error("Cannot use GLOBAL neighborhood for adapter. Must use UNIVERSAL");var c="adapter|"+this.getName()+"|"+this.getVersion();if(f.listenerCount(this.getBus(),c)>0)throw this.close(),new Error("That adapter is already registered: "+c);this._maxAdapterInstances=a.getConfiguration().get("maxAdapterInstances"),this._maxHops=a.getConfiguration().get("maxHops"),this._clientInstances={},this._clientInstancesCount=0,this._currentContext=null,this._facadeEvents=null,this.registerBusEvent(c,this._handleRegistryRequest.bind(this)),this.registerDefaultMessengerListener(),o.log(o.DEBUG,"Created %s",this);var e=this.getBus(),g="register|"+this.getName()+"|"+this.getVersion();n.nextTick(function(){o.log(o.DEBUG2,"Sending register event for %s",this),e.emit(j.Neighborhood.LOCAL,g)}.bind(this))}var e=a("../../endpoint/endpoint"),f=a("events").EventEmitter,g=a("util").inherits,h=a("util").format,i=a("node-uuid"),j=a("../../util/constants"),k=a("../../routing/address"),l=a("./client-instance"),m=a("./resolver"),n=a("../../util/appUtils"),o=n.getLogger(c);g(d,e),b.exports=d,d.prototype.getName=function(){return this._name},d.prototype.getVersion=function(){return this._version},d.prototype.getObject=function(){return this._object},d.prototype.getEvents=function(){if(null===this._facadeEvents){var a=this;this._facadeEvents={emit:function(){for(var b in a._clientInstances)a._clientInstances[b].getEvents().emit.apply(a._clientInstances[b],arguments)}}}return this._facadeEvents},d.prototype.getMetadata=function(){return this._metadata},d.prototype.setMetadata=function(a){this._metadata=a||{}},d.prototype.setCurrentContext=function(a){this._currentContext=a},d.prototype.getCurrentContext=function(){return this._currentContext},d.prototype._handleRegistryRequest=function(a,b,c){return b>this._neighborhood?void 0:(o.log(o.TRACE,"Adapter request: %s",this),this._clientInstancesCount>=this._maxAdapterInstances?void o.log(o.WARN,"Max client instance count reached [%s], ignoring adapter request",this._clientInstancesCount):void(this._resolver.resolve(c.criteria,this._metadata,a)&&(o.log(o.DEBUG3,"Responding to adapter request [for: %s]: %s",c.id,this),this.getMessenger().sendMessage(a,c.id,{type:"api",id:this.getId(),address:a.getPathVector()}))))},d.prototype._handleMessage=function(a,b){if(!(b>this._neighborhood||this._clientInstancesCount>=this._maxAdapterInstances)){var c=k(a.address),d=!n.isUuid(a.id)||!c.isValid(this._maxHops)||null!==a.hostAffinityId&&!n.isUuid(a.hostAffinityId);if(d)return void o.log(o.WARN,"Invalid adapter request: %j",a);var e=l(this.getEndpointManager(),{remoteAddress:c,remoteId:a.id,hostAffinityId:a.hostAffinityId,neighborhood:this._neighborhood,facadeId:a.facadeId,adapter:this});this._clientInstances[e.getId()]=e,this._clientInstancesCount+=1,e.on("closed",function(){delete this._clientInstances[e.getId()],this._clientInstancesCount-=1}.bind(this)),this.emit("client-instance",e)}},d.prototype._handleClose=function(){if(this._clientInstances){var a=Object.keys(this._clientInstances);for(var b in a)this._clientInstances[b].close()}}}).call(this,"/js\\app\\api\\adapter\\adapter.js")},{"../../endpoint/endpoint":26,"../../routing/address":36,"../../util/appUtils":54,"../../util/constants":55,"./client-instance":2,"./resolver":5,events:64,"node-uuid":69,util:92}],2:[function(a,b,c){(function(c){"use strict";function d(a,b){if(!(this instanceof d))return new d(a,b);d.super_.call(this,a,{type:j.EndpointType.CLIENT_INSTANCE,id:i(),identification:g("[name: %s] [version: %s]",b.adapter.getName(),b.adapter.getVersion())}),this.registerDefaultMessengerListener(),this._maxClientObjects=a.getConfiguration().get("maxClientObjects"),this._facadeEvents=null,this._adapter=b.adapter,this._remoteAddress=b.remoteAddress,this._remoteId=b.remoteId,this._hostAffinityId=b.hostAffinityId,this._neighborhood=b.neighborhood,this._remoteConnected=!0,this._objects={},this._totalObjects=0;var c=this.createObjectInstance(this._adapter.getName(),this._adapter.getObject(),b.facadeId);c.attachEndpoint(this),this.getMessenger().sendMessage(this._remoteAddress,this._remoteId,{type:"connect",id:this.getId(),object:c.getApi()}),this.trackEndpointAffinity(this._hostAffinityId),l.log(l.DEBUG,"Created %s",this)}var e=a("../../endpoint/endpoint"),f=a("util").inherits,g=a("util").format,h=a("./object-instance"),i=a("node-uuid"),j=a("../../util/constants"),k=a("../../util/appUtils"),l=k.getLogger(c);f(d,e),b.exports=d,d.prototype.getAdapter=function(){return this._adapter},d.prototype.getObjectInstance=function(a){return this._objects[a]},d.prototype.getRemoteAddress=function(){return this._remoteAddress},d.prototype.getRemoteId=function(){return this._remoteId},d.prototype.getHostAffinityId=function(){return this._hostAffinityId},d.prototype.getEvents=function(){if(null===this._facadeEvents){var a=this;this._facadeEvents={emit:function(){for(var b=[],c=0;c<arguments.length;c++)b.push(arguments[c]);a.getMessenger().sendMessage(a._remoteAddress,a._remoteId,{type:"event",event:b})}}}return this._facadeEvents},d.prototype.createObjectInstance=function(a,b,c,d){if(this._totalObjects>this._maxClientObjects)return l.log(l.WARN,"Max client objects exceeded [total: %s] for %s",this._maxClientObjects,this),null;var e=h(this.getEndpointManager(),{name:a,object:b,remoteId:c,clientInstance:this});return this._objects[e.getId()]=e,this._totalObjects+=1,e.on("closed",function(){delete this._objects[e.getId()],this._totalObjects-=1}.bind(this)),d=d||this,d.attachEndpoint(e),e},d.prototype._handleMessage=function(a,b){if(!(b>this._neighborhood)){var c=a.type;if(c)switch(c){case"disconnect":return this._remoteConnected=!1,void this.close()}l.log(l.ERROR,"Malformed message: %j for %s",a,this)}},d.prototype._handleClose=function(a){this._remoteConnected&&!a&&this.getMessenger().sendMessage(this._remoteAddress,this._remoteId,{id:this.getId(),type:"disconnect"})}}).call(this,"/js\\app\\api\\adapter\\client-instance.js")},{"../../endpoint/endpoint":26,"../../util/appUtils":54,"../../util/constants":55,"./object-instance":4,"node-uuid":69,util:92}],3:[function(a,b,c){(function(c){"use strict";function d(a){return this instanceof d?(this._objectInstance=a,this._inputStream=null,this._outputStream=null,this._cb=null,this._asyncMode=!1,this._buffered=!1,void(this._periodicCounter=0)):new d(a)}var e=a("through2"),f=a("../../util/appUtils"),g=f.getLogger(c);b.exports=d,d.prototype.incrementPeriodic=function(){this._periodicCounter+=1},d.prototype.getPeriodic=function(){return this._periodicCounter},d.prototype.getClientInstance=function(){return this._objectInstance.getClientInstance()},d.prototype.getObjectInstance=function(){return this._objectInstance},d.prototype.isBuffered=function(){return this._buffered},d.prototype.setBuffered=function(a){this._buffered=a},d.prototype.setAsyncMode=function(){this._asyncMode=!0},d.prototype.isAsync=function(){return this._asyncMode},d.prototype.setAsyncResult=function(a){this._cb("result",a)},d.prototype.setAsyncError=function(a){this._cb("error",a)},d.prototype.hasInputStream=function(){return null!==this._inputStream},d.prototype.hasOutputStream=function(){return null!==this._outputStream},d.prototype.getInputStream=function(){return this._inputStream},d.prototype.setInputStream=function(a){this._inputStream=a},d.prototype.getOutputStream=function(){return this._outputStream},d.prototype.setOutputStream=function(a){this._outputStream=a},d.prototype.execute=function(a,b,c){var d=this.getObjectInstance(),e=this.getClientInstance().getAdapter();g.log(g.DEBUG3,"Executing %s on %s",a,d),this._cb=c;var f;try{e.setCurrentContext(this);var h=d.getObject();if(!h[a])throw new Error("Unknown function name");f=h[a].apply(h,b),this.hasInputStream()&&this.hasOutputStream()&&(this.getInputStream().on("end",function(){this.getOutputStream().end()}.bind(this)),this.getOutputStream().on("end",function(){this.getInputStream().end()}.bind(this))),e.setCurrentContext(null),this.isAsync()||c("result",f)}catch(i){e.setCurrentContext(null),g.log(g.WARN,"Issue executing API call [func: %s] [args: %j] [exception: %s] [trace: %s]",a,b,i.toString(),i.stack),c("error",i)}},d.prototype.cancel=function(){this.hasInputStream()&&this.getInputStream().end(),this.hasOutputStream()&&this.getOutputStream().end()},d.prototype.transformDuplexStream=function(a,b){var c=e.obj;this._buffered&&(c=e),this._inputStream.pipe(c(a)).pipe(this._outputStream),this._outputStream.pipe(c(b)).pipe(this._inputStream)},d.prototype.transformStream=function(a){var b=e.obj;this._buffered&&(b=e),this._inputStream.pipe(b(a)).pipe(this._outputStream)}}).call(this,"/js\\app\\api\\adapter\\context.js")},{"../../util/appUtils":54,through2:89}],4:[function(a,b,c){(function(c){"use strict";function d(a,b){if(!(this instanceof d))return new d(a,b);var c=b.clientInstance.getAdapter();d.super_.call(this,a,{type:k.EndpointType.OBJECT_INSTANCE,id:h(),identification:g("[name: %s] [version: %s]",b.name,c.getVersion())}),this.registerDefaultStreamerListener(),this.registerDefaultMessengerListener(),this._name=b.name,this._object=b.object,this._clientInstance=b.clientInstance,this._remoteId=b.remoteId,this._contexts={},this._contextsCount=0,this._remoteConnected=!0,this._methodIndex=this._createMethodIndex(),m.log(m.DEBUG,"Created %s",this)}var e=a("../../endpoint/endpoint"),f=a("util").inherits,g=a("util").format,h=a("node-uuid"),i=a("./context"),j=a("../../routing/address"),k=a("../../util/constants"),l=a("../../util/appUtils"),m=l.getLogger(c);f(d,e),b.exports=d,d.prototype.getName=function(){return this._name},d.prototype.getObject=function(){return this._object},d.prototype.getClientInstance=function(){return this._clientInstance},d.prototype.getRemoteAddress=function(){return this.getClientInstance().getRemoteAddress()},d.prototype.getRemoteId=function(){return this._remoteId},d.prototype.getContext=function(a,b){if(this.hasContext(a))return this._contexts[a];if(b){if(!l.isUuid(a))throw new Error("invalid context id");var c=this._contexts[a]=i(this,a);return this._contextsCount+=1,1==this._contextsCount&&this.getEndpointManager().registerPeriodic(this),c}return null},d.prototype.getApi=function(){return{id:this.getId(),methods:this.getMethodNames()}},d.prototype.getMethodNames=function(){return Object.keys(this._methodIndex)},d.prototype.hasContext=function(a){return!!this._contexts[a]},d.prototype._handleStream=function(a,b){var c=a.meta.type,d=a.meta.id;if(this.attachStream(a),d){var e;switch(c){case"input":e=this.getContext(d,!0),e.setInputStream(a),e.setBuffered(!b.objectMode);break;case"output":e=this.getContext(d,!0),e.setOutputStream(a);break;default:return m.log(m.ERROR,"Malformed stream: %j for %s",a.meta,this),void a.end()}this.getMessenger().sendMessage(this.getRemoteAddress(),d,{type:"stream-connected"})}},d.prototype._handleMessage=function(a,b){if(!(b>this._neighborhood)){var c=a.id,d=a.type;if(c&&d)switch(d){case"close":return this._remoteConnected=!1,void this.close();case"remote-stream":return void this._establishRemoteStream(c,a);case"call-facade":case"call-ignore":case"call":return void this._callMethod(c,d,a);case"cancel":return void this.cancel(c)}m.log(m.ERROR,"Malformed message: %j for %s",a,this)}},d.prototype._callMethod=function(a,b,c){var d=this.getContext(a,!0);if(c.xargs&&c.xargs.length>0)for(var e=0;e<c.xargs.length;e++){var f=c.xargs[e],h=c.args[f],i=this.getClientInstance().getObjectInstance(h);i?c.args[f]=i.getObject():m.log(m.WARN,"Unknown object id: %s",h)}var j,k=function(d,e){if(this.removeContext(a),"result"==d){if(j={type:"result"},"call"==b)j.value=e;else if("call-facade"==b){var f=g("%s.%s",this.getName(),c.func),h=this.getClientInstance().createObjectInstance(f,e,c.facadeId,this);h?j.value=h.getApi():j={type:"error",message:"Could not create the object instance",name:"Error"}}}else j={type:"error",message:e.message,name:e.name};this.getMessenger().sendMessage(this.getRemoteAddress(),a,j)}.bind(this);this.hasMethod(c.func)?d.execute(c.func,c.args,k):(m.log(m.ERROR,"Method does not exist: %s for %s",c.func,this),k("error",new Error("Method not found")))},d.prototype._establishRemoteStream=function(a,b){var c=this.getContext(a,!0),d=b.remoteAddress,e=b.remoteId,f=this.getRemoteAddress().routeThrough(j(d,!0)),g=this.getStreamer().createStream(e,f,{id:b.callId,type:"input"},{objectMode:!b.buffered});this.attachStream(g),this.getMessenger().sendMessage(this.getRemoteAddress(),a,{type:"stream-connected"}),c.setOutputStream(g)},d.prototype.hasMethod=function(a){return!!this._methodIndex[a]},d.prototype._createMethodIndex=function(){var a={},b=this._object,c=0;for(var d in b)"function"==typeof b[d]&&"_"!==d.charAt(0)&&(a[d]=!0,c+=1);return m.log(m.DEBUG2,"Counted %s functions in object for %s",c,this),a},d.prototype.performPeriodic=function(){for(var a=Object.keys(this._contexts),b=0;b<a.length;b++){var c=a[b],d=this._contexts[c];d.incrementPeriodic(),d.getPeriodic()>2&&(m.log(m.DEBUG,"Context is stale [ctx: %s] for %s",c,this),this.cancel(c))}},d.prototype.cancel=function(a){this.hasContext(a)&&(this._contexts[a].cancel(),this.removeContext(a))},d.prototype.removeContext=function(a){this.hasContext(a)&&(delete this._contexts[a],this._contextsCount-=1,0===this._contextsCount&&this.getEndpointManager().unregisterPeriodic(this))},d.prototype._handleClose=function(a){this._remoteConnected&&!a&&this.getMessenger().sendMessage(this.getRemoteAddress(),this._remoteId,{id:this.getId(),type:"close"});var b=Object.keys(this._contexts);for(var c in b)this.cancel(c)}}).call(this,"/js\\app\\api\\adapter\\object-instance.js")},{"../../endpoint/endpoint":26,"../../routing/address":36,"../../util/appUtils":54,"../../util/constants":55,"./context":3,"node-uuid":69,util:92}],5:[function(a,b,c){"use strict";function d(a){return this instanceof d?(this._id=a.id,void(this._instanceId=a.instanceId)):new d(a)}b.exports=d,d.prototype.resolve=function(a,b,c){return a?a.hasOwnProperty("instanceId")&&a.instanceId!==this._instanceId?!1:!a.hasOwnProperty("id")||a.id===this._id:!0}},{}],6:[function(a,b,c){(function(c){"use strict";function d(a,b){return this instanceof d?(this._id=b.get("instanceId"),this._endpointManager=a,void j.log(j.DEBUG,"API Layer initialized")):new d(a,b)}var e=a("./adapter/adapter"),f=a("./facade/client"),g=a("./facade/query"),h=a("./facade-manager"),i=a("../util/appUtils"),j=i.getLogger(c);b.exports=d,d.prototype.getInstanceId=function(){return this._id},d.prototype.getEndpointManager=function(){return this._endpointManager},d.prototype.getConfiguration=function(){return this._endpointManager.getConfiguration()},d.prototype.createQuery=function(a,b,c){return c=c||{},g(this._endpointManager,{name:a,version:b,criteria:c.criteria||{},neighborhood:c.neighborhood||"local",tryForever:c.hasOwnProperty("tryForever")?c.tryForever:!0,bridgeId:c.bridgeId,hostId:c.hostId})},d.prototype.createFacade=function(a,b,c){function d(a){e.connect(a.address,a.id,a.neighborhood,g.getId())}c=c||{};var e=f(this._endpointManager,{name:a,version:b}),g=e.createFacadeInstance(a);if(g.attachEndpoint(e,!1),c.api)d(c.api);else{var h=this.createQuery(a,b,c);h.on("api",function(a){h.close(),d(a)}),h.on("timeout",function(){j.log(j.WARN,"A facade timed out for %s",this),g.emit("timeout"),g.close()}),g.attachEndpoint(h)}return g},d.prototype.manageFacades=function(){var a=h(this);try{for(var b=0;b<arguments.length;b++){var c=arguments[b];if(c.length<2)throw a.close(),new Error("Input error, invalid number of arguments for facade manager");h.prototype.addFacade.apply(a,c)}}catch(d){throw j.log(j.ERROR,"Could not create facade manager: %s, stack = %s",d.message,d.stack),a.close(),d}return a},d.prototype.registerAdapter=function(a,b,c,d){return d=d||{},e(this._endpointManager,{name:a,version:b,object:c,neighborhood:d.neighborhood||"group",resolver:d.resolver,metadata:d.metadata||{}})}}).call(this,"/js\\app\\api\\api.js")},{"../util/appUtils":54,"./adapter/adapter":1,"./facade-manager":7,"./facade/client":14,"./facade/query":16}],7:[function(a,b,c){(function(c){"use strict";function d(a){return this instanceof d?(e.call(this),this._facades={},this._api=a,this._ready=!1,this._closed=!1,this._totalFacades=0,void(this._facadesReady=0)):new d(a)}var e=a("events").EventEmitter,f=a("util").inherits,g=a("../util/appUtils"),h=g.getLogger(c);f(d,e),b.exports=d,d.prototype.getFacade=function(a){if(!this._facades[a])throw new Error("Do not know of that facade");return this._facades[a]},d.prototype.getApi=function(a){if(!this._ready)throw new Error("Facade Manager isn't ready");return this.getFacade(a).getApi()},d.prototype.getEvents=function(a){if(!this._ready)throw new Error("Facade Manager isn't ready");return this.getFacade(a).getEvents()},d.prototype.addFacade=function(a,b,c){if(this._facades[a])throw new Error("Can only managed one facade of a specific type");var d=this._api.createFacade(a,b,c);this._totalFacades+=1,this._facades[d.getName()]=d,d.on("closed",function(){h.log(h.DEBUG2,"Facade was closed for %s",d.getId()),delete this._facades[d.getName()],this._totalFacades-=1,d.isReady()&&(this._facadesReady-=1),this._closed||(h.log(h.WARN,"Facade was closed. Re-creating for %s",d.getId()),this.addFacade(a,b,c))}.bind(this)),d.on("ready",function(){if(this._facadesReady+=1,this._facadesReady===this._totalFacades){var a=!0;this._ready||(a=!1,this._ready=!0),this.emit("reconnect"),a||this.emit("ready")}}.bind(this))},d.prototype.close=function(){this._closed=!0;var a=Object.keys(this._facades);a.forEach(function(a){this._facades[a].close()},this)}}).call(this,"/js\\app\\api\\facade-manager.js")},{"../util/appUtils":54,events:64,util:92}],8:[function(a,b,c){(function(c){"use strict";function d(a,b){return this instanceof d?(d.super_.call(this,a,{type:h.EndpointType.CALL,id:g()}),this.getEndpointManager().registerPeriodic(this),this._readyToExecute=!1,this._forwardStream=null,this._reverseStream=null,this._buffered=!1,this._result=null,void(this._periodicCounter=0)):new d(a,b)}var e=a("../../endpoint/endpoint"),f=a("util").inherits,g=a("node-uuid"),h=a("../../util/constants"),i=a("../../util/appUtils"),j=i.getLogger(c);f(d,e),b.exports=d,d.prototype.performPeriodic=function(){this._periodicCounter++,6==this._periodicCounter&&(j.log(j.WARN,"A call timed out for %s",this),this.emit("call-error","Call timed out"))},d.prototype.isFacadeCall=function(){return!1},d.prototype.isStreamCall=function(){return!1},d.prototype.isCallbackCall=function(){return!1},d.prototype.connectForwardStream=function(a){this._forwardStream=a},d.prototype.getForwardStream=function(){return this._forwardStream},d.prototype.connectReverseStream=function(a){this._reverseStream=a},d.prototype.getReverseStream=function(){return this._reverseStream},d.prototype.isBuffered=function(){return this._buffered},d.prototype.setBuffered=function(a){this._buffered=a},d.prototype.setResult=function(a){this._result=a},d.prototype.getResult=function(){return this._result},d.prototype.pipe=function(a){if(a.setBuffered(this.isBuffered()),a.isFacadeCall()){var b=a.establishInputStream(this.isBuffered());a.connectForwardStream(b),a.connectReverseStream(b),this.getForwardStream().pipe(b),b.pipe(this.getReverseStream())}else if(a.isStreamCall()||a.isCallbackCall()&&a.wantsStreams())a.connectForwardStream(this.getForwardStream()),a.connectReverseStream(this.getReverseStream());else if(!a.isCallbackCall())throw new Error("Unknown call type")},d.prototype.execute=function(){j.log(j.DEBUG2,"Complete for %s",this),this.emit("complete")}}).call(this,"/js\\app\\api\\facade\\call.js")},{"../../endpoint/endpoint":26,"../../util/appUtils":54,"../../util/constants":55,"node-uuid":69,util:92}],9:[function(a,b,c){"use strict";function d(a,b){return this instanceof d?void e.call(this,a,b):new d(a,b)}var e=a("./facade-call"),f=a("util").inherits;f(d,e),b.exports=d,d.prototype.isBaseCall=function(){return!0},d.prototype.connectInputStream=function(){var a=this.establishInputStream(this.isBuffered());return this.connectForwardStream(a),this.connectReverseStream(a),a},d.prototype._setResultValue=function(a){this.setResult(a)}},{"./facade-call":11,util:92}],10:[function(a,b,c){(function(c){"use strict";function d(a,b){return this instanceof d?(e.call(this,a,b),this._func=b.func,void(this._wantsStreams=b.func.length>1)):new d(a,b)}var e=a("../call"),f=a("util").inherits,g=a("../../../util/appUtils"),h=g.getLogger(c);f(d,e),b.exports=d,d.prototype.getFunc=function(){return this._func},d.prototype.wantsStreams=function(){return this._wantsStreams},d.prototype.isCallbackCall=function(){return!0},d.prototype.execute=function(){try{var a=this._func(this.getResult(),this.getForwardStream(),this.getReverseStream());this.setResult(a),h.log(h.DEBUG2,"Complete for callback %s",this),this.emit("complete")}catch(b){h.log(h.WARN,"Issue executing Callback call [exception: %s] [trace: %s]",b.toString(),b.stack),this.emit("call-error",b.message)}}}).call(this,"/js\\app\\api\\facade\\calls\\callback-call.js")},{"../../../util/appUtils":54,"../call":8,util:92}],11:[function(a,b,c){(function(c){"use strict";function d(b,c){return this instanceof d?(e||(e=a("../facade")),f.call(this,b,c),this.registerDefaultMessengerListener(),this._pendingStreamsCount=0,this._func=c.func,this._args=c.args,this._facade=this._func.getFacade(),this._complete=!1,this._executing=!1,this._returnResult=!1,this._returnFacade=!1,void(this._facadeResult=null)):new d(b,c)}var e,f=a("../call"),g=a("util").inherits,h=a("util").format,i=a("../../../util/appUtils"),j=i.getLogger(c);g(d,f),b.exports=d,d.prototype.getFunction=function(){return this._func},d.prototype.getArguments=function(){return this._args},d.prototype.isFacadeCall=function(){return!0},d.prototype.isBaseCall=function(){return!1},d.prototype.setReturnFacade=function(a){this._returnFacade=a},d.prototype.setReturnResult=function(a){this._returnResult=a},d.prototype.establishRemoteStream=function(a,b,c,d){this._pendingStreamsCount+=1,this._sendMessage({type:"remote-stream",callId:a,remoteAddress:b.getPathVector(),remoteId:c,buffered:d})},d.prototype.incrementExpectedStreamCount=function(){this._pendingStreamsCount+=1},d.prototype.getRemoteAddress=function(){return this._facade.getRemoteAddress()},d.prototype.getRemoteId=function(){return this._facade.getRemoteId()},d.prototype.establishInputStream=function(a){this._pendingStreamsCount+=1;var b=this.establishStream("input",a);return this._facade.attachStream(b),b},d.prototype.establishOutputStream=function(a){this._pendingStreamsCount+=1;var b=this.establishStream("output",a);return this._facade.attachStream(b),b},d.prototype._handleMessage=function(a){switch(a.type){case"stream-connected":j.log(j.TRACE,"Received stream connected message for %s",this),this._pendingStreamsCount-=1,0===this._pendingStreamsCount&&this._readyToExecute&&this.execute();break;case"result":this._complete=!0,this._handleResult(a);break;case"error":this._complete=!0,j.log(j.ERROR,"Error [%s] type [%s] for call %s",a.message,a.name,this),this.emit("call-error",a.message,a.name);break;default:j.log(j.WARN,"Unknown message: %j for %s",a,this)}},d.prototype._handleResult=function(a){if(this._returnFacade){try{this._facadeResult.assignObject(a.value)}catch(b){return j.log(j.ERROR,"Object Error [%s] for call %s",b.message,this),void this.emit("call-error",b.message,"facade-object")}a.value=this._facadeResult,this._facadeResult=null}this._setResultValue(a.value),j.log(j.DEBUG2,"Call complete for %s",this),this.emit("complete")},d.prototype._setResultValue=function(a){},d.prototype.establishStream=function(a,b){var c=this.getStreamer().createStream(this.getRemoteId(),this.getRemoteAddress(),{id:this.getId(),type:a},{objectMode:!b});return c},d.prototype.pipe=function(a){if(a.setBuffered(this.isBuffered()),a.isFacadeCall())a.incrementExpectedStreamCount(),this.establishRemoteStream(a.getId(),a.getRemoteAddress(),a.getRemoteId(),this.isBuffered());else if(a.isStreamCall()||a.isCallbackCall()&&a.wantsStreams()){var b=this.establishOutputStream(this.isBuffered());a.connectForwardStream(b),a.connectReverseStream(b)}else if(!a.isCallbackCall())throw new Error("Unknown call type")},d.prototype.execute=function(){if(this._pendingStreamsCount>0)this._readyToExecute=!0;else{for(var a=[],b=[],c=0;c<this._args.length;c++){var d=this._args[c];d instanceof e?(a.push(c),b.push(d.getRemoteId())):d._facade&&d._facade instanceof e?(a.push(c),b.push(d._facade.getRemoteId())):b.push(this._args[c])}j.log(j.DEBUG2,"Sent call for %s",this),this._executing=!0;var f={type:"call",func:this._func.getFacadeFunctionName(),args:b,xargs:a};if(this._returnResult){if(this._returnFacade){var g=h("%s.%s",this._facade.getName(),f.func);this._facadeResult=this._facade.getClient().createFacadeInstance(g,this._facade),f.type="call-facade",f.facadeId=this._facadeResult.getId()}}else f.type="call-ignore";this._sendMessage(f)}},d.prototype._sendMessage=function(a){a.id=this.getId(),this.getMessenger().sendMessage(this.getRemoteAddress(),this.getRemoteId(),a)},d.prototype._handleClose=function(){!this._complete&&this._executing&&this._sendMessage({type:"cancel"}),this._facadeResult&&this._facadeResult.close()}}).call(this,"/js\\app\\api\\facade\\calls\\facade-call.js")},{"../../../util/appUtils":54,"../call":8,"../facade":15,util:92}],12:[function(a,b,c){"use strict";function d(a,b){return this instanceof d?(e.call(this,a,b),this._forwardStream=b.forwardStream||g.obj(),void(this._reverseStream=b.reverseStream||g.obj())):new d(a,b)}var e=a("../call"),f=a("util").inherits,g=a("through2");f(d,e),b.exports=d,d.prototype.isStreamCall=function(){return!0},d.prototype.setForwardStream=function(a){this._forwardStream=a},d.prototype.setReverseStream=function(a){this._reverseStream=a},d.prototype.connectForwardStream=function(a){a.pipe(this._forwardStream),e.prototype.connectForwardStream.call(this,this._forwardStream)},d.prototype.connectReverseStream=function(a){this._reverseStream.pipe(a),e.prototype.connectReverseStream.call(this,this._reverseStream)}},{"../call":8,through2:89,util:92}],13:[function(a,b,c){"use strict";function d(a,b){if(!(this instanceof d))return new d(a,b);e.call(this,a,b),this._inputFunc=b.inputFunc,this._outputFunc=null,b.hasOwnProperty("outputFunc")&&(this._outputFunc=b.outputFunc);var c=this._setupTransform(this._inputFunc);this.setForwardStream(c),null!==this._outputFunc&&(c=this._setupTransform(this._outputFunc),this.setReverseStream(c))}var e=a("./stream-call"),f=a("util").inherits,g=a("through2");f(d,e),b.exports=d,d.prototype._setupTransform=function(a){return this.isBuffered()?g(a):g.obj(a)}},{"./stream-call":12,through2:89,util:92}],14:[function(a,b,c){(function(c){"use strict";function d(a,b){return this instanceof d?(d.super_.call(this,a,{type:k.EndpointType.CLIENT,id:i(),identification:j("[name: %s] [version: %s]",b.name,b.version)}),this.registerDefaultMessengerListener(),this._eventEmitter=new h,this._name=b.name,this._version=b.version,this._remoteConnected=!1,this._facades={},this._remoteAddress=null,this._remoteId=null,this._hostAffinityId=null,this._neighborhood=0,this._facadeId=null,void m.log(m.DEBUG,"Created %s",this)):new d(a,b)}var e=a("../../endpoint/endpoint"),f=a("util").inherits,g=a("./facade"),h=a("events").EventEmitter,i=a("node-uuid"),j=a("util").format,k=a("../../util/constants"),l=a("../../util/appUtils"),m=l.getLogger(c);f(d,e),b.exports=d,d.prototype.getName=function(){return this._name},d.prototype.getVersion=function(){return this._version},d.prototype.getRemoteAddress=function(){return this._remoteAddress},d.prototype.getNeighborhood=function(){return this._neighborhood},d.prototype.getRemoteId=function(){return this._remoteId},d.prototype.getHostAffinityId=function(){return this._hostAffinityId},d.prototype.getEvents=function(){return this._eventEmitter},d.prototype.connect=function(a,b,c,d){this._remoteAddress=a,this._neighborhood=c,this._facadeId=d,this._hostAffinityId=this.getHostAffinity().establishHostAffinity(a),this.trackEndpointAffinity(this._hostAffinityId),this.getMessenger().sendMessage(a,b,{id:this.getId(),address:a.getPathVector(),hostAffinityId:this._hostAffinityId,facadeId:d})},d.prototype._handleMessage=function(a,b){if(!(b>this._neighborhood))switch(a.type){case"connect":l.isUuid(a.id)&&(this._remoteConnected=!0,this._handleConnection(a));break;case"disconnect":this._remoteConnected=!1,this.close();break;case"event":this._eventEmitter.emit.apply(this._eventEmitter,a.event)}},d.prototype._handleConnection=function(a){this._remoteId=a.id;var b=a.object,c=this._facades[this._facadeId];if(!c){var d="Could not locate facade to assign API to for ";throw m.log(m.ERROR,d+this),new Error(d+this)}c.assignObject(b),this.emit("ready")},d.prototype.createFacadeInstance=function(a,b){var c=g(this.getEndpointManager(),{name:a,version:this.getVersion(),client:this});return this._facades[c.getId()]=c,c.on("closed",function(){delete this._facades[c.getId()]}.bind(this)),b=b||this,b.attachEndpoint(c),c},d.prototype._handleClose=function(a){this._remoteConnected&&!a&&this.getMessenger().sendMessage(this._remoteAddress,this._remoteId,{id:this.getId(),type:"disconnect"}),this._remoteAddress&&this.getHostAffinity().removeHostAffinity(this._remoteAddress,this._hostAffinityId)}}).call(this,"/js\\app\\api\\facade\\client.js")},{"../../endpoint/endpoint":26,"../../util/appUtils":54,"../../util/constants":55,"./facade":15,events:64,"node-uuid":69,util:92}],15:[function(a,b,c){(function(c){"use strict";function d(a,b){return this instanceof d?(d.super_.call(this,a,{type:k.EndpointType.FACADE,id:h(),identification:i("[name: %s] [version: %s]",b.name,b.client.getVersion())}),this.registerDefaultMessengerListener(),this._strategies={},this._name=b.name,this._client=b.client,this._remoteConnected=!1,this._api=null,this._remoteId=null,this._ready=!1,void m.log(m.DEBUG,"Created %s",this)):new d(a,b)}var e=a("../../endpoint/endpoint"),f=a("util").inherits,g=a("util").isArray,h=a("node-uuid"),i=a("util").format,j=a("./strategy"),k=a("../../util/constants"),l=a("../../util/appUtils"),m=l.getLogger(c);f(d,e),b.exports=d,d.prototype.getName=function(){return this._name},d.prototype.getVersion=function(){return this.getClient().getVersion()},d.prototype.getClient=function(){return this._client},d.prototype.getEvents=function(){return this.getClient().getEvents()},d.prototype.getRemoteAddress=function(){return this.getClient().getRemoteAddress()},d.prototype.getRemoteId=function(){return this._remoteId},d.prototype.isReady=function(){return this._ready},d.prototype.assignObject=function(a){if(!a||!g(a.methods)||!l.isUuid(a.id))throw this.close(),new Error("Invalid API response for Facade "+this);if(null===this._api){this._remoteConnected=!0,this._remoteId=a.id,m.log(m.DEBUG,"Assigning API [id = %s] for %s",this._remoteId,this);var b=this,c=this._api={};a.methods.forEach(function(a){c[a]=function(){var d=j(b.getEndpointManager());return d.call(c[a],arguments),b._strategies[d.getId()]=d,d.on("complete",function(){
delete b._strategies[d.getId()]}),l.nextTick(function(){d.execute()}),d},c[a].isFacadeFunction=function(){return!0},c[a].getFacadeFunctionName=function(){return a},c[a].getFacade=function(){return b}}),c._facade=this,this._ready=!0,this.emit("ready")}else m.log(m.DEBUG,"Already established API for %s",this)},d.prototype._handleMessage=function(a,b){if(!(b>this.getClient().getNeighborhood()))switch(a.type){case"close":this._remoteConnected=!1,this.close()}},d.prototype.getApi=function(){if(!this.isReady()){var a=new Error("Tried to get API but not ready for "+this);throw m.log(m.ERROR,a),a}return this._api},d.prototype._handleClose=function(a){this._remoteConnected&&!a&&this.getMessenger().sendMessage(this.getRemoteAddress(),this._remoteId,{id:this.getId(),type:"close"});var b=Object.keys(this._strategies);b.forEach(function(a){this._strategies[a].cancel()},this)}}).call(this,"/js\\app\\api\\facade\\facade.js")},{"../../endpoint/endpoint":26,"../../util/appUtils":54,"../../util/constants":55,"./strategy":17,"node-uuid":69,util:92}],16:[function(a,b,c){(function(c){"use strict";function d(a,b){if(!(this instanceof d))return new d(a,b);d.super_.call(this,a,{type:j.EndpointType.QUERY,id:i()}),this.registerDefaultMessengerListener(),this.getEndpointManager().registerPeriodic(this);var c=this.getEndpointManager().getService("router");this.registerObjectEvent(c,"route-available",this._routeAvailable.bind(this)),this.registerObjectEvent(c,"route-unavailable",this._routeLost.bind(this)),this._periodicCounter=0,this._name=b.name,this._version=b.version,this._criteria=b.criteria,this._bridgeId=b.bridgeId,this._hostId=b.hostId,this._tryForever=b.tryForever,this._maxHops=a.getConfiguration().get("maxHops"),this._queryNeighborhood=k.getNeighborhood(b.neighborhood,"local"),this._foundApis={},this._foundApisCount=0,this._searchQueued=!1,this._acceptNeighborhood=this._queryNeighborhood==j.Neighborhood.GLOBAL?j.Neighborhood.UNIVERSAL:this._queryNeighborhood;var e="register|"+this.getName()+"|"+this.getVersion();this.registerBusEvent(e,this._adapterRegistered.bind(this)),this.searchAdapter(this._queryNeighborhood,this._bridgeId,this._hostId,this._criteria)}var e=a("../../endpoint/endpoint"),f=a("util").inherits,g=a("../../routing/address"),h=a("xtend"),i=a("node-uuid"),j=a("../../util/constants"),k=a("../../util/appUtils"),l=k.getLogger(c);f(d,e),b.exports=d,d.prototype.getName=function(){return this._name},d.prototype.getVersion=function(){return this._version},d.prototype.getFoundApis=function(){return this._foundApis},d.prototype.getFoundApisCount=function(){return this._foundApisCount},d.prototype._routeAvailable=function(a,b){if(b.adjacent){if(this._hostId)return;this.searchAdapter(this._queryNeighborhood,this._bridgeId,a,this._criteria)}},d.prototype._routeLost=function(a){this._hostId==a&&(this.emit("timeout"),this.close())},d.prototype._adapterRegistered=function(a,b){b>j.Neighborhood.LOCAL||this.searchAdapter(j.Neighborhood.LOCAL,null,null,this._criteria)},d.prototype.performPeriodic=function(a){a||(this._periodicCounter++,this._periodicCounter%2===0&&(this._tryForever?0===this._foundApisCount&&l.log(l.WARN,"Could not find a suitable Adapter. Check the 'neighborhood' settings on both the Facade and Adapter to ensure they are high enough."):(0===this._foundApisCount&&this.emit("timeout"),this.close()),this.searchAdapter(this._queryNeighborhood,this._bridgeId,this._hostId,this._criteria)))},d.prototype.searchAdapter=function(a,b,c,d){this._searchQueued||(l.log(l.DEBUG3,"Queuing search request for %s",this),k.nextTick(function(){this._searchQueued=!1,l.log(l.DEBUG2,"Sending a search request [Name: %s] [Bridge: %s] [Host: %s]",this.getName(),b,c);var e={id:this.getId(),criteria:{}};d&&(e.criteria=h(d));var f="adapter|"+this.getName()+"|"+this.getVersion();b||c?this.getBus().emitDirect(b,c,a,f,e):this.getBus().emit(a,f,e)}.bind(this)),this._searchQueued=!0)},d.prototype._handleMessage=function(a,b){if(!(b>this._acceptNeighborhood))switch(a.type){case"api":this._foundApis[a.id]||(a.address=g(a.address),a.neighborhood=b,a.address.isValid(this._maxHops)&&(this._foundApis[a.id]=a,this._foundApisCount+=1,this.emit("api",a)))}}}).call(this,"/js\\app\\api\\facade\\query.js")},{"../../endpoint/endpoint":26,"../../routing/address":36,"../../util/appUtils":54,"../../util/constants":55,"node-uuid":69,util:92,xtend:93}],17:[function(a,b,c){(function(c){"use strict";function d(a){return this instanceof d?(e.call(this),this._route=[],this._id=g(),this._catch=null,this._executing=!1,this._endpointManager=a,void(this._currentCall=null)):new d(a)}var e=a("events").EventEmitter,f=a("util").inherits,g=a("node-uuid"),h=a("./calls/base-call"),i=a("./calls/callback-call"),j=a("./calls/facade-call"),k=a("./calls/stream-call"),l=a("./calls/transform-call"),m=a("../../util/appUtils"),n=m.getLogger(c);f(d,e),b.exports=d,d.prototype.getId=function(){return this._id},d.prototype.getRoute=function(){return this._route.slice(0)},d.prototype.clearRoute=function(){this._route=[]},d.prototype.isExecuting=function(){return this._executing},d.prototype.getCatch=function(){return this._catch},d.prototype.call=function(a,b){if(this._executing)throw this.cancel(),new Error("Cannot add to an executing strategy");if(this._route.length>0)throw this.cancel(),new Error("Can only make one base call per strategy");if(!a.hasOwnProperty("isFacadeFunction")||!a.isFacadeFunction())throw this.cancel(),new Error("Must use a facade function");var c={func:a,args:this._cacheArguments(b,0),instanceId:this._endpointManager.getInstanceId()};return this._route.push(h(this._endpointManager,c)),this},d.prototype.pipe=function(a){if(this._executing)throw this.cancel(),new Error("Cannot add to an executing strategy");var b;if(a.hasOwnProperty("isFacadeFunction")&&a.isFacadeFunction())b={func:a,args:this._cacheArguments(arguments,1),instanceId:this._endpointManager.getInstanceId()},this._route.push(j(this._endpointManager,b));else if(a instanceof d){n.log(n.DEBUG2,"Concatenating passed strategy with this strategy [passed: %s] [this: %s]",a.getId(),this.getId());var c=a.getRoute();if(c.length>0){var e=c.shift();if(e.isFacadeCall()&&e.isBaseCall()){b={func:e.getFunction(),args:e.getArguments()};var f=j(this._endpointManager,b);this._route.push(f),e.close()}else this._route.push(e);this._route=this._route.concat(c),a.clearRoute()}}else if(a.pipe&&"function"==typeof a.pipe)b={forwardStream:a},arguments.length>=2&&arguments[1].pipe&&"function"==typeof arguments[1].pipe&&(b.reverseStream=arguments[1]),this._route.push(k(this._endpointManager,b));else{if("function"!=typeof a)throw this.cancel(),new Error("Must use a stream, facade function, or callback for pipe");b={inputFunc:a},arguments.length>=2&&"function"==typeof arguments[1]&&(b.outputFunc=arguments[1]),this._route.push(l(this._endpointManager,b))}return this},d.prototype.then=function(a){if(this._executing)throw this.cancel(),new Error("Cannot add to an executing strategy");if(a.hasOwnProperty("isFacadeFunction")&&a.isFacadeFunction())throw this.cancel(),new Error("Cannot use a facade function on then, use pipe");if("function"!=typeof a)throw this.cancel(),new Error("Must use a callback for then");var b={func:a};return this._route.push(i(this._endpointManager,b)),arguments.length>=2&&"function"==typeof arguments[1]&&this["catch"](arguments[1]),this},d.prototype["catch"]=function(a){if(null!==this._catch)throw this.cancel(),new Error("Cannot catch a Strategy twice");return this._catch=a,this},d.prototype.stream=function(){if(this._executing)throw this.cancel(),new Error("Cannot add to an executing strategy");var a=this._route[0],b=a.connectInputStream();return this.execute(),b},d.prototype.facade=function(){var a=this._route[0];return a.setReturnFacade(!0),this},d.prototype.buffered=function(){if(this._executing)throw this.cancel(),new Error("Cannot add to an executing strategy");var a=this._route[0],b=!0;return arguments.length>=1&&arguments[0]===!1&&(b=!1),a.setBuffered(b),this},d.prototype.execute=function(){if(!this._executing){this._executing=!0;for(var a=this._route[0],b=null,c=0;c<this._route.length;c++){var e=this._route[c];if(null!==b&&b.pipe(e),b=e,e.isCallbackCall()){e.getFunc().length>0&&a.setReturnResult(!0);break}}var f=this,g=null,h=function(){if(f._route.length>0){var a=f._currentCall=f._route.shift();a.setResult(g),a.on("call-error",function(b,c){a.close(),f._callCatch(b,c),f.cancel()}),a.on("complete",function(){a.close(),g=a.getResult(),a.isCallbackCall()&&(g instanceof d?g.pipe(f):f._route.length>0&&(n.log(n.ERROR,"Additional items after then(), but strategy not returned"),f.cancel())),h()}),a.execute()}else n.log(n.DEBUG2,"Strategy Complete for %s",f.getId()),f.emit("complete")};n.log(n.DEBUG2,"Executing Strategy for %s",this.getId()),h()}},d.prototype._cacheArguments=function(a,b){for(var c=[],d=b;d<a.length;d++)c.push(a[d]);return c},d.prototype.cancel=function(){null!==this._currentCall&&this._currentCall.close(),this._route.forEach(function(a){a.close()}),this._route=[],this.emit("complete")},d.prototype._callCatch=function(a,b){try{null!==this._catch&&this._catch(a,b)}catch(c){n.log(n.WARN,"Issue executing catch method [exception: %s] [trace: %s]",c.toString(),c.stack)}}}).call(this,"/js\\app\\api\\facade\\strategy.js")},{"../../util/appUtils":54,"./calls/base-call":9,"./calls/callback-call":10,"./calls/facade-call":11,"./calls/stream-call":12,"./calls/transform-call":13,events:64,"node-uuid":69,util:92}],18:[function(a,b,c){(function(b){"use strict";a("./util/polyfills");var c=a("./util/appUtils"),d=a("./util/logger"),e=a("./loader"),f=a("./switching/link-directory"),g=a("./config/configuration-factory"),h=c.getLogger(b);if(c.getGlobalObject().endpointLogLevel&&(d.logLevel=c.getGlobalObject().endpointLogLevel),c.initScriptName(),c.getGlobalObject().endpoint)h.log(h.INFO,"Endpoint.js Already Initialized");else{var i=f(),j={};c.getGlobalObject().endpointConfig&&(j=c.getGlobalObject().endpointConfig||{});var k=g(i).createDefaultBrowserConfiguration(j),l=e(i,k);c.getGlobalObject().endpoint=l,h.log(h.INFO,"Endpoint.js Initialized [Instance ID: %s]",l.getInstanceId())}}).call(this,"/js\\app\\browser.js")},{"./config/configuration-factory":19,"./loader":35,"./switching/link-directory":46,"./util/appUtils":54,"./util/logger":57,"./util/polyfills":59}],19:[function(a,b,c){(function(c){"use strict";function d(a){return this instanceof d?void(this._linkDirectory=a):new d(a)}var e=a("./link-support"),f=a("./configuration"),g=a("../util/appUtils"),h=g.getLogger(c);b.exports=d,d.prototype.createDefaultBrowserConfiguration=function(a){var b=g.getGlobalObject();if(e.isWorkerHub(b)||e.isWorker(b))return h.log(h.DEBUG,"Creating default web worker configuration"),this.createWebWorkerConfiguration(a);h.log(h.DEBUG,"Creating default browser configuration");var c=f(this._linkDirectory,a);if(!a.links){var d=[],i={linkId:"default-window",type:"window",settings:{origin:b.location.origin,external:!1}};d.push(i);var j={linkId:"default-worker",type:"worker",settings:{}};d.push(j);var k=e.supportsSharedWorker();if(!k&&e.supportsLocalStorage()){h.log(h.DEBUG,"Adding tab link to configuration");var l={linkId:"default-tab",type:"tab",settings:{channel:"endpointjs-default"}};d.push(l)}if(h.log(h.DEBUG,"Adding %s links to configuration",d.length),c.addLinks(d),c.get("createSharedWorker")&&k){var m=this._createSharedWorker(c.get("sharedWorkerUrl")),n=this._linkDirectory.getLink("default-worker");n.addWorker(m)}var o=b.parent;if(o&&o!==b){var p=!0;if(b.document&&"string"==typeof b.document.referrer&&-1==b.document.referrer.indexOf(b.location.origin)&&(p=!1),p){var q=this._linkDirectory.getLink("default-window");q.announceWindow(o)}}}var r=this;return g.addEventListener(b,"beforeunload",function(){r._linkDirectory.close()}),c},d.prototype.createDefaultServerConfiguration=function(a){if(h.log(h.DEBUG,"Creating default server configuration"),!a.links){var b={linkId:"default-server",type:"server",settings:{channel:"endpointjs-default"}};a.links=[b]}return f(this._linkDirectory,a)},d.prototype.createWebWorkerConfiguration=function(a){var b=f(this._linkDirectory,a);if(!a.links){var c={linkId:"default-worker",type:"worker",settings:{channel:"endpointjs-default"}};b.addLinks([c]);var d=this._linkDirectory.getLink("default-worker");d.addHub(g.getGlobalObject())}return b},d.prototype._createSharedWorker=function(a){a||(a=g.getScriptName()),h.log(h.DEBUG,"Creating shared worker hub: [URL: %s]",a);try{return new SharedWorker(a)}catch(b){h.log(h.WARN,"Issue creating shared worker [message: %s]",b.message)}}}).call(this,"/js\\app\\config\\configuration-factory.js")},{"../util/appUtils":54,"./configuration":20,"./link-support":23}],20:[function(a,b,c){(function(c){"use strict";function d(a,b){if(!(this instanceof d))return new d(a,b);var c=[["instanceId",f()],["maxHops",10],["maxHostAffinities",25],["maxAdapterInstances",1e3],["maxClientObjects",100],["createSharedWorker",!0],["sharedWorkerUrl",null]];this._options={},c.forEach(function(a){this._options[a[0]]=b&&b.hasOwnProperty(a[0])?b[a[0]]:a[1]},this),this._linkDirectory=a,this._linkAssociation=m(),this._customLinkTypes={},this._linkCounter=1,b.links&&this.addLinks(b.links)}var e=a("../util/appUtils"),f=a("node-uuid"),g=a("util").isArray,h=a("../link/worker"),i=a("../link/tab"),j=a("../link/window"),k=a("../link/server"),l=a("../util/constants"),m=a("./link-association"),n=e.getLogger(c);b.exports=d,d.prototype.addLinks=function(a){a&&a.length>0&&(n.log(n.DEBUG2,"Adding: %s default links",a.length),a.forEach(function(a){this.addLink(a)},this))},d.prototype.get=function(a){return this._options[a]},d.prototype.addCustomLinkType=function(a,b){this._customLinkTypes[a]=b},d.prototype.addLink=function(a){var b;if(!a.type)throw b="No link type specified",n.log(n.ERROR,b),new Error(b);var c,d=a.linkId||this._linkCounter++,e=this.get("instanceId"),f=a.settings||{};switch(a.type){case l.LinkType.SERVER:c=k(e,d,f);break;case l.LinkType.WORKER:c=h(e,d,f);break;case l.LinkType.WINDOW:c=j(e,d,f);break;case l.LinkType.TAB:c=i(e,d,f);break;default:if(!this._customLinkTypes[a.type])throw b="Link type unknown: "+a.type,n.log(n.ERROR,b),new Error(b);c=this._customLinkTypes[a.type](e,d,f)}return this._linkDirectory.addLink(c),c},d.prototype.getLink=function(a){return this._linkDirectory.getLink(a)},d.prototype.removeLink=function(a){this._linkDirectory.removeLink(this.getLink(a))},d.prototype.getLinkAssociation=function(){return this._linkAssociation},d.prototype.createBridge=function(a,b){g(a)||(a="undefined"!=typeof a?[a]:[]);var c=this._linkAssociation.createBridge(!!b);return a.forEach(function(a){c.addLinkId(a)}),c}}).call(this,"/js\\app\\config\\configuration.js")},{"../link/server":31,"../link/tab":32,"../link/window":33,"../link/worker":34,"../util/appUtils":54,"../util/constants":55,"./link-association":21,"node-uuid":69,util:92}],21:[function(a,b,c){"use strict";function d(){return this instanceof d?(this._linkBridges={},this._linkAssociations={},this._addLinkAssociationPtr=this._addLinkAssociation.bind(this),this._removeLinkAssociationPtr=this._removeLinkAssociation.bind(this),void(this._removeBridgePtr=this._removeBridge.bind(this))):new d}var e=a("./link-bridge");b.exports=d,d.prototype._addLinkAssociation=function(a,b){var c=this._linkAssociations[a];c||(c=this._linkAssociations[a]={_assoc:{},_count:0});var d=c._assoc[b];d||(c._count+=1,c._assoc[b]=0),c._assoc[b]+=1},d.prototype._removeLinkAssociation=function(a,b){var c=this._linkAssociations[a];if(c){var d=c._assoc[b];d&&(c._assoc[b]-=1,0===c._assoc[b]&&(delete c._assoc[b],c._count-=1),0===c._count&&delete this._linkAssociations[a])}},d.prototype.getBridge=function(a){return this._linkBridges[a]},d.prototype.createBridge=function(a){var b=e(a);return this._linkBridges[b.getId()]=b,b.on("add-association",this._addLinkAssociationPtr),b.on("remove-association",this._removeLinkAssociationPtr),b.on("closed",this._removeBridgePtr),b},d.prototype._removeBridge=function(a){var b=this._linkBridges[a];b&&(delete this._linkBridges[a],b.removeListener("add-association",this._addLinkAssociationPtr),b.removeListener("remove-association",this._removeLinkAssociationPtr),b.removeListener("closed",this._removeBridgePtr))},d.prototype.isAssociated=function(a,b){var c=this._linkAssociations[a];return!(!c||!c._assoc[b])}},{"./link-bridge":22}],22:[function(a,b,c){(function(c){"use strict";function d(a){return this instanceof d?(e.call(this),this._id=g(),this._selfRelay=!!a,void(this._links={})):new d(a)}var e=a("events").EventEmitter,f=a("util").inherits,g=a("node-uuid"),h=a("../util/appUtils"),i=h.getLogger(c);f(d,e),b.exports=d,d.prototype.getId=function(){return this._id},d.prototype.hasLinkId=function(a){return!!this._links[a]},d.prototype.addLinkId=function(a){var b=this._links[a];b||(this._event("add-association",a),this._links[a]=!0)},d.prototype.removeLinkId=function(a){var b=this._links[a];b&&(delete this._links[a],this._event("remove-association",a))},d.prototype._event=function(a,b){this._selfRelay&&(i.log(i.DEBUG3,"Emitting self relay %s for %s",a,b),this.emit(a,b,b)),Object.keys(this._links).forEach(function(c){i.log(i.DEBUG3,"Emitting %s for %s <-> %s",a,b,c),this.emit(a,c,b),this.emit(a,b,c)},this)},d.prototype.close=function(){Object.keys(this._links).forEach(function(a){this._event("remove-association",a)},this),this.emit("closed",this.getId())}}).call(this,"/js\\app\\config\\link-bridge.js")},{"../util/appUtils":54,events:64,"node-uuid":69,util:92}],23:[function(a,b,c){(function(c){"use strict";var d=a("../util/appUtils"),e=d.getLogger(c);b.exports={isWorkerHub:function(a){return"onconnect"in a},isWorker:function(a){return"undefined"!=typeof WorkerGlobalScope&&a instanceof Work