swim-client-js
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -1,3 +0,3 @@ | ||
// Swim Client v0.5.1. Copyright 2015-2016, Swim.it Inc. | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("recon-js")):"function"==typeof define&&define.amd?define(["exports","recon-js"],e):e(t.Swim=t.Swim||{},t.Recon)}(this,function(t,e){"use strict";function i(){}function o(){i.call(this)}function n(){i.call(this)}function s(){i.call(this)}function r(t,e,i){s.call(this),this.node=t,this.lane=e,this.body=i}function h(t,e,i){s.call(this),this.node=t,this.lane=e,this.body=i}function p(t,e,i,n,s){o.call(this),this.node=t,this.lane=e,this.prio=i,this.rate=n,this.body=s}function l(t,e,i,o,s){n.call(this),this.node=t,this.lane=e,this.prio=i,this.rate=o,this.body=s}function d(t,e,i,n,s){o.call(this),this.node=t,this.lane=e,this.prio=i,this.rate=n,this.body=s}function a(t,e,i){n.call(this),this.node=t,this.lane=e,this.body=i}function c(t,e,i){o.call(this),this.node=t,this.lane=e,this.body=i}function u(t,e,i){n.call(this),this.node=t,this.lane=e,this.body=i}function f(t){o.call(this),this.body=t}function y(t){n.call(this),this.body=t}function v(t){o.call(this),this.body=t}function g(t){n.call(this),this.body=t}function w(t,e,i,o,n,s,r){Object.defineProperty(this,"context",{value:t}),Object.defineProperty(this,"hostUri",{value:e,enumerable:!0}),Object.defineProperty(this,"nodeUri",{value:i,enumerable:!0}),Object.defineProperty(this,"laneUri",{value:o,enumerable:!0}),Object.defineProperty(this,"prio",{value:n||0,enumerable:!0}),Object.defineProperty(this,"rate",{value:s||0,enumerable:!0}),Object.defineProperty(this,"body",{value:r,enumerable:!0}),Object.defineProperty(this,"views",{value:[],configurable:!0})}function m(t,e,i,o,n){Object.defineProperty(this,"context",{value:t}),Object.defineProperty(this,"scope",{value:e}),Object.defineProperty(this,"props",{value:Object.freeze(i||{})}),this.options=o||{},this.delegate=n||{},this.model=null}function b(t,e,i,o,n,s,r){w.call(this,t,e,i,o,n,s,r)}function k(t,e,i,o,n){m.call(this,t,e,i,o,n)}function U(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t}function O(t,e,i,o,n,s,r,h,p,l){w.call(this,t,e,i,o,n,s,r),this.setRefs(h||[]),this.setState(p||[]),l&&(this.makeRef=l)}function D(t,e,i){m.call(this,t,e,i)}function R(t,e,i,o,n,s,r,h){w.call(this,t,e,i,o,n,s,r),this.setState(h||{})}function j(t,e,i,o,n){m.call(this,t,e,i,o,n)}function C(t,e,i,o,n,s,r,h){w.call(this,t,e,i,o,n,s,r),this.setState(h)}function S(t,e,i,o,n){m.call(this,t,e,i,o,n)}function P(t){Object.defineProperty(this,"context",{value:t}),Object.defineProperty(this,"downlinks",{value:{},configurable:!0}),Object.defineProperty(this,"downlinkCount",{value:0,writable:!0}),this.delegate=this}function x(t,e){P.call(this,t),Object.defineProperty(this,"hostUri",{value:e,enumerable:!0}),Object.defineProperty(this,"props",{value:Object.freeze({hostUri:e})})}function E(t,e,i){P.call(this,t),Object.defineProperty(this,"hostUri",{value:e,enumerable:!0}),Object.defineProperty(this,"nodeUri",{value:i,enumerable:!0}),Object.defineProperty(this,"props",{value:Object.freeze({hostUri:e,nodeUri:i})})}function M(t,e,i,o){P.call(this,t),Object.defineProperty(this,"hostUri",{value:e,enumerable:!0}),Object.defineProperty(this,"nodeUri",{value:i,enumerable:!0}),Object.defineProperty(this,"laneUri",{value:o,enumerable:!0}),Object.defineProperty(this,"props",{value:Object.freeze({hostUri:e,nodeUri:i,laneUri:o})})}function W(t,i,o){Object.defineProperty(this,"context",{value:t}),Object.defineProperty(this,"hostUri",{value:i,enumerable:!0}),Object.defineProperty(this,"options",{value:o||{},enumerable:!0}),Object.defineProperty(this,"downlinks",{value:{},configurable:!0}),Object.defineProperty(this,"downlinkCount",{value:0,writable:!0}),Object.defineProperty(this,"authenticated",{value:!1,enumerable:!0,configurable:!0}),Object.defineProperty(this,"authentication",{value:null,enumerable:!0,configurable:!0}),Object.defineProperty(this,"uriCache",{value:new e.UriCache(i),configurable:!0}),Object.defineProperty(this,"sendBuffer",{value:[],configurable:!0}),Object.defineProperty(this,"reconnectTimer",{value:null,writable:!0}),Object.defineProperty(this,"reconnectTimeout",{value:0,writable:!0}),Object.defineProperty(this,"idleTimer",{value:null,writable:!0})}function I(t,e,i){W.call(this,t,e,i)}function q(t){Object.defineProperty(this,"options",{value:t||{},enumerable:!0}),Object.defineProperty(this,"scopes",{value:[],configurable:!0}),Object.defineProperty(this,"hosts",{value:{},configurable:!0}),Object.defineProperty(this,"downlinks",{value:{},configurable:!0}),Object.defineProperty(this,"downlinkCount",{value:0,writable:!0}),Object.defineProperty(this,"online",{value:!0,configurable:!0}),this.delegate={},this.onOnline=this.onOnline.bind(this),this.onOffline=this.onOffline.bind(this),this.watchOnline(this.keepOnline)}function L(){return J.isOnline.apply(J,arguments)}function A(){return J.keepOnline.apply(J,arguments)}function T(){return J.host.apply(J,arguments)}function F(){return J.node.apply(J,arguments)}function H(){return J.lane.apply(J,arguments)}function z(){return J.downlink.apply(J,arguments)}function B(){return J.downlinkList.apply(J,arguments)}function V(){return J.downlinkMap.apply(J,arguments)}function _(){return J.downlinkValue.apply(J,arguments)}function N(){J.command.apply(J,arguments)}function G(){J.authenticate.apply(J,arguments)}Object.defineProperty(i.prototype,"isRequest",{value:!1}),Object.defineProperty(i.prototype,"isResponse",{value:!1}),Object.defineProperty(i.prototype,"isMessage",{value:!1}),Object.defineProperty(i.prototype,"isEventMessage",{value:!1}),Object.defineProperty(i.prototype,"isCommandMessage",{value:!1}),Object.defineProperty(i.prototype,"isLinkRequest",{value:!1}),Object.defineProperty(i.prototype,"isLinkedResponse",{value:!1}),Object.defineProperty(i.prototype,"isSyncRequest",{value:!1}),Object.defineProperty(i.prototype,"isSyncedResponse",{value:!1}),Object.defineProperty(i.prototype,"isUnlinkRequest",{value:!1}),Object.defineProperty(i.prototype,"isUnlinkedResponse",{value:!1}),Object.defineProperty(i.prototype,"isAuthRequest",{value:!1}),Object.defineProperty(i.prototype,"isAuthedResponse",{value:!1}),Object.defineProperty(i.prototype,"isDeauthRequest",{value:!1}),Object.defineProperty(i.prototype,"isDeauthedResponse",{value:!1}),i.prototype.toRecon=function(){return e.stringify(this.encode())},i.decode=function(t){switch(e.tag(t)){case"@event":return r.decode(t);case"@command":return h.decode(t);case"@link":return p.decode(t);case"@linked":return l.decode(t);case"@sync":return d.decode(t);case"@synced":return a.decode(t);case"@unlink":return c.decode(t);case"@unlinked":return u.decode(t);case"@auth":return f.decode(t);case"@authed":return y.decode(t);case"@deauth":return v.decode(t);case"@deauthed":return g.decode(t)}},i.parse=function(t){return i.decode(e.parse(t))},o.prototype=Object.create(i.prototype),o.prototype.constructor=o,Object.defineProperty(o.prototype,"isRequest",{value:!0}),n.prototype=Object.create(i.prototype),n.prototype.constructor=n,Object.defineProperty(n.prototype,"isResponse",{value:!0}),s.prototype=Object.create(i.prototype),s.prototype.constructor=s,Object.defineProperty(s.prototype,"isMessage",{value:!0}),r.prototype=Object.create(s.prototype),r.prototype.constructor=r,Object.defineProperty(r.prototype,"isEventMessage",{value:!0}),r.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new r(t,e,this.body)},r.prototype.encode=function(){var t={node:this.node,lane:this.lane};return e.concat({"@event":t},this.body)},r.decode=function(t){var i,o,n=e.headers(t,"@event");if(e.forEach(n,function(t,e,n){"node"===e?i=t:"lane"===e?o=t:0===n?i=t:1===n&&(o=t)}),void 0!==i&&void 0!==o){var s=e.body(t);return new r(i,o,s)}},h.prototype=Object.create(s.prototype),h.prototype.constructor=h,Object.defineProperty(h.prototype,"isCommandMessage",{value:!0}),h.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new h(t,e,this.body)},h.prototype.encode=function(){var t={node:this.node,lane:this.lane};return e.concat({"@command":t},this.body)},h.decode=function(t){var i,o,n=e.headers(t,"@command");if(e.forEach(n,function(t,e,n){"node"===e?i=t:"lane"===e?o=t:0===n?i=t:1===n&&(o=t)}),void 0!==i&&void 0!==o){var s=e.body(t);return new h(i,o,s)}},p.prototype=Object.create(o.prototype),p.prototype.constructor=p,Object.defineProperty(p.prototype,"isLinkRequest",{value:!0}),p.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new p(t,e,this.prio,this.rate,this.body)},p.prototype.encode=function(){var t={node:this.node,lane:this.lane};return void 0!==this.prio&&0!==this.prio&&(t.prio=this.prio),void 0!==this.rate&&0!==this.rate&&(t.rate=this.rate),e.concat({"@link":t},this.body)},p.decode=function(t){var i,o,n,s,r=e.headers(t,"@link");if(e.forEach(r,function(t,e,r){"node"===e?i=t:"lane"===e?o=t:"prio"===e?n=t:"rate"===e?s=t:0===r?i=t:1===r&&(o=t)}),void 0!==i&&void 0!==o){var h=e.body(t);return new p(i,o,n,s,h)}},l.prototype=Object.create(n.prototype),l.prototype.constructor=l,Object.defineProperty(l.prototype,"isLinkedResponse",{value:!0}),l.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new l(t,e,this.prio,this.rate,this.body)},l.prototype.encode=function(){var t={node:this.node,lane:this.lane};return void 0!==this.prio&&0!==this.prio&&(t.prio=this.prio),void 0!==this.rate&&0!==this.rate&&(t.rate=this.rate),e.concat({"@linked":t},this.body)},l.decode=function(t){var i,o,n,s,r=e.headers(t,"@linked");if(e.forEach(r,function(t,e,r){"node"===e?i=t:"lane"===e?o=t:"prio"===e?n=t:"rate"===e?s=t:0===r?i=t:1===r&&(o=t)}),void 0!==i&&void 0!==o){var h=e.body(t);return new l(i,o,n,s,h)}},d.prototype=Object.create(o.prototype),d.prototype.constructor=d,Object.defineProperty(d.prototype,"isSyncRequest",{value:!0}),d.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new d(t,e,this.prio,this.rate,this.body)},d.prototype.encode=function(){var t={node:this.node,lane:this.lane};return void 0!==this.prio&&0!==this.prio&&(t.prio=this.prio),void 0!==this.rate&&0!==this.rate&&(t.rate=this.rate),e.concat({"@sync":t},this.body)},d.decode=function(t){var i,o,n,s,r=e.headers(t,"@sync");if(e.forEach(r,function(t,e,r){"node"===e?i=t:"lane"===e?o=t:"prio"===e?n=t:"rate"===e?s=t:0===r?i=t:1===r&&(o=t)}),void 0!==i&&void 0!==o){var h=e.body(t);return new d(i,o,n,s,h)}},a.prototype=Object.create(n.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"isSyncedResponse",{value:!0}),a.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new a(t,e,this.body)},a.prototype.encode=function(){var t={node:this.node,lane:this.lane};return e.concat({"@synced":t},this.body)},a.decode=function(t){var i,o,n=e.headers(t,"@synced");if(e.forEach(n,function(t,e,n){"node"===e?i=t:"lane"===e?o=t:0===n?i=t:1===n&&(o=t)}),void 0!==i&&void 0!==o){var s=e.body(t);return new a(i,o,s)}},c.prototype=Object.create(o.prototype),c.prototype.constructor=c,Object.defineProperty(c.prototype,"isUnlinkRequest",{value:!0}),c.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new c(t,e,this.body)},c.prototype.encode=function(){var t={node:this.node,lane:this.lane};return e.concat({"@unlink":t},this.body)},c.decode=function(t){var i,o,n=e.headers(t,"@unlink");if(e.forEach(n,function(t,e,n){"node"===e?i=t:"lane"===e?o=t:0===n?i=t:1===n&&(o=t)}),void 0!==i&&void 0!==o){var s=e.body(t);return new c(i,o,s)}},u.prototype=Object.create(n.prototype),u.prototype.constructor=u,Object.defineProperty(u.prototype,"isUnlinkedResponse",{value:!0}),u.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new u(t,e,this.body)},u.prototype.encode=function(){var t={node:this.node,lane:this.lane};return e.concat({"@unlinked":t},this.body)},u.decode=function(t){var i,o,n=e.headers(t,"@unlinked");if(e.forEach(n,function(t,e,n){"node"===e?i=t:"lane"===e?o=t:0===n?i=t:1===n&&(o=t)}),void 0!==i&&void 0!==o){var s=e.body(t);return new u(i,o,s)}},f.prototype=Object.create(o.prototype),f.prototype.constructor=f,Object.defineProperty(f.prototype,"isAuthRequest",{value:!0}),f.prototype.encode=function(){return e.concat({"@auth":null},this.body)},f.decode=function(t){if(e.headers(t,"@auth"))return new f(e.body(t))},y.prototype=Object.create(n.prototype),y.prototype.constructor=y,Object.defineProperty(y.prototype,"isAuthedResponse",{value:!0}),y.prototype.encode=function(){return e.concat({"@authed":null},this.body)},y.decode=function(t){if(e.headers(t,"@authed"))return new y(e.body(t))},v.prototype=Object.create(o.prototype),v.prototype.constructor=v,Object.defineProperty(v.prototype,"isDeauthRequest",{value:!0}),v.prototype.encode=function(){return e.concat({"@deauth":null},this.body)},v.decode=function(t){if(e.headers(t,"@deauth"))return new v(e.body(t))},g.prototype=Object.create(n.prototype),g.prototype.constructor=g,Object.defineProperty(g.prototype,"isDeauthedResponse",{value:!0}),g.prototype.encode=function(){return e.concat({"@deauthed":null},this.body)},g.decode=function(t){if(e.headers(t,"@deauthed"))return new g(e.body(t))},w.prototype.keepLinked=function(){for(var t=0,e=this.views.length;t<e;t+=1)if(this.views[t].keepLinked())return!0;return!1},w.prototype.keepSynced=function(){for(var t=0,e=this.views.length;t<e;t+=1)if(this.views[t].keepSynced())return!0;return!1},w.prototype.isConnected=function(){return this.context.isConnected()},w.prototype.isAuthenticated=function(){return this.context.isAuthenticated()},w.prototype.session=function(){return this.context.session()},w.prototype.addDownlink=function(t){this.views.push(t)},w.prototype.removeDownlink=function(t){for(var e=0;e<this.views.length;e+=1)this.views[e]===t&&(this.views.splice(e,1),t.closeUp());0===this.views.length&&this.context.close()},w.prototype.onEventMessage=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onEventMessage(t)},w.prototype.onCommandMessage=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onCommandMessage(t)},w.prototype.onLinkRequest=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onLinkRequest(t)},w.prototype.onLinkedResponse=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onLinkedResponse(t)},w.prototype.onSyncRequest=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onSyncRequest(t)},w.prototype.onSyncedResponse=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onSyncedResponse(t)},w.prototype.onUnlinkRequest=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onUnlinkRequest(t)},w.prototype.onUnlinkedResponse=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onUnlinkedResponse(t)},w.prototype.hostDidConnect=function(t){Object.defineProperty(this,"host",{value:t,configurable:!0});for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].hostDidConnect();var o,n=this.host.unresolve(this.nodeUri);this.keepSynced()?(o=new d(n,this.laneUri,this.prio,this.rate,this.body),this.onSyncRequest(o)):(o=new p(n,this.laneUri,this.prio,this.rate,this.body),this.onLinkRequest(o)),this.host.push(o)},w.prototype.hostDidDisconnect=function(t){Object.defineProperty(this,"host",{value:null,configurable:!0});for(var e=!1,i=0,o=this.views.length;i<o;i+=1){var n=this.views[i];n.hostDidDisconnect(),e=e||n.keepLinked()}e||this.close()},w.prototype.hostDidFail=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)this.views[i].hostDidFail(t)},w.prototype.command=function(t){this.onCommandMessage(t),this.context.command(this.hostUri,this.nodeUri,this.laneUri,t)},w.prototype.close=function(){this.context.closeDownlink(this)},w.prototype.closeUp=function(){var t=this.views;Object.defineProperty(this,"views",{value:[],configurable:!0});for(var e=0;e<t.length;e+=1)t[e].closeUp()},m.prototype.copy=function(t,e,i){var o,n={};for(o in this.props)n[o]=this.props[o];for(o in t)n[o]=t[o];var s={};for(o in this.options)s[o]=this.options[o];for(o in e)s[o]=e[o];var r={};for(o in this.delegate)r[o]=this.delegate[o];for(o in i)r[o]=i[o];return new this.constructor(this.context,this.scope,n,s,r)},m.prototype.host=function(t){if(!arguments.length)return this.props.hostUri;if(this.props.nodeUri){var i=e.Uri.resolveUri(t,this.props.nodeUri);return this.copy({hostUri:t,nodeUri:i})}return this.copy({hostUri:t})},m.prototype.node=function(t){return arguments.length?(this.props.hostUri&&(t=e.Uri.resolveUri(this.props.hostUri,t)),this.copy({nodeUri:t})):this.props.nodeUri},m.prototype.lane=function(t){return arguments.length?this.copy({laneUri:t}):this.props.laneUri},m.prototype.prio=function(t){return arguments.length?this.copy({prio:t}):this.props.prio},m.prototype.rate=function(t){return arguments.length?this.copy({rate:t}):this.props.rate},m.prototype.body=function(t){return arguments.length?this.copy({body:t}):this.props.body},m.prototype.keepLinked=function(t){return arguments.length?(this.options.keepLinked=t,this):void 0===this.options.keepLinked||this.options.keepLinked},m.prototype.keepSynced=function(t){return arguments.length?(this.options.keepSynced=t,this):void 0===this.options.keepSynced||this.options.keepSynced},m.prototype.onEvent=function(t){return arguments.length?(this.delegate.onEvent=t,this):this.delegate.onEvent},m.prototype.onCommand=function(t){return arguments.length?(this.delegate.onCommand=t,this):this.delegate.onCommand},m.prototype.willLink=function(t){return arguments.length?(this.delegate.willLink=t,this):this.delegate.willLink},m.prototype.didLink=function(t){return arguments.length?(this.delegate.didLink=t,this):this.delegate.didLink},m.prototype.willSync=function(t){return arguments.length?(this.delegate.willSync=t,this):this.delegate.willSync},m.prototype.didSync=function(t){return arguments.length?(this.delegate.didSync=t,this):this.delegate.didSync},m.prototype.willUnlink=function(t){return arguments.length?(this.delegate.willUnlink=t,this):this.delegate.willUnlink},m.prototype.didUnlink=function(t){return arguments.length?(this.delegate.didUnlink=t,this):this.delegate.didUnlink},m.prototype.didConnect=function(t){return arguments.length?(this.delegate.didConnect=t,this):this.delegate.didConnect},m.prototype.didDisconnect=function(t){return arguments.length?(this.delegate.didDisconnect=t,this):this.delegate.didDisconnect},m.prototype.didClose=function(t){return arguments.length?(this.delegate.didClose=t,this):this.delegate.didClose},m.prototype.didFail=function(t){return arguments.length?(this.delegate.didFail=t,this):this.delegate.didFail},m.prototype.isConnected=function(){return this.model&&this.model.isConnected()},m.prototype.isAuthenticated=function(){return this.model&&this.model.isAuthenticated()},m.prototype.session=function(){return this.model&&this.model.session()},m.prototype.onEventMessage=function(t){this.delegate&&"function"==typeof this.delegate.onEvent&&this.delegate.onEvent(t.body,this)},m.prototype.onCommandMessage=function(t){this.delegate&&"function"==typeof this.delegate.onCommand&&this.delegate.onCommand(t.body,this)},m.prototype.onLinkRequest=function(t){this.delegate&&"function"==typeof this.delegate.willLink&&this.delegate.willLink(this)},m.prototype.onLinkedResponse=function(t){this.delegate&&"function"==typeof this.delegate.didLink&&this.delegate.didLink(this)},m.prototype.onSyncRequest=function(t){this.delegate&&"function"==typeof this.delegate.willSync&&this.delegate.willSync(this)},m.prototype.onSyncedResponse=function(t){this.delegate&&"function"==typeof this.delegate.didSync&&this.delegate.didSync(this)},m.prototype.onUnlinkRequest=function(t){this.delegate&&"function"==typeof this.delegate.willUnlink&&this.delegate.willUnlink(this)},m.prototype.onUnlinkedResponse=function(t){this.delegate&&"function"==typeof this.delegate.didUnlink&&this.delegate.didUnlink(this)},m.prototype.hostDidConnect=function(){this.delegate&&"function"==typeof this.delegate.didConnect&&this.delegate.didConnect(this)},m.prototype.hostDidDisconnect=function(){this.delegate&&"function"==typeof this.delegate.didDisconnect&&this.delegate.didDisconnect(this)},m.prototype.hostDidFail=function(){this.delegate&&"function"==typeof this.delegate.didFail&&this.delegate.didFail(this)},m.prototype.command=function(t){this.model.command(t)},m.prototype.open=null,m.prototype.close=function(){this.scope&&this.scope.removeDownlink(this),this.model&&this.model.removeDownlink(this)},m.prototype.closeUp=function(){this.delegate&&"function"==typeof this.delegate.didClose&&this.delegate.didClose(this)},b.prototype=Object.create(w.prototype),b.prototype.constructor=b,k.prototype=Object.create(m.prototype),k.prototype.constructor=k,k.prototype.keepSynced=function(t){return arguments.length?(this.options.keepSynced=t,this):void 0!==this.options.keepSynced&&this.options.keepSynced},k.prototype.open=function(){var t=this.props,e=this.context.getDownlink(t.hostUri,t.nodeUri,t.laneUri);if(e){if(!(e instanceof b))throw"downlink type mismatch";e.addDownlink(this)}else e=new b(this.context,t.hostUri,t.nodeUri,t.laneUri,t.prio,t.rate,t.body),e.addDownlink(this),this.context.openDownlink(e);return this.model=e,this.scope&&this.scope.addDownlink(this),this},O.prototype=Object.create(w.prototype),O.prototype.constructor=O,Object.defineProperty(O.prototype,"length",{get:function(){return this.state.length},configurable:!0,enumerable:!0}),O.prototype.get=function(t){return this.state[t]},O.prototype.set=function(t,i){if(!U(t))throw new TypeError("index");if(t<0&&(t=this.state.length+t),t>=0&&t<this.state.length){i=this.listWillUpdate(t,i);var o=this.refs[t],n=this.state[t];this.state[t]=i,this.listDidUpdate(t,i,n),this.command(e.concat({"@update":{id:o.id,index:t}},i))}else t=Math.max(0,t),this.insert(t,i);return this},O.prototype.insert=function(){var t=arguments[0];if(!U(t))throw new TypeError("start");t<0&&(t=this.state.length+t),t=Math.min(Math.max(0,t),this.state.length);for(var i=1,o=arguments.length;i<o;i+=1){var n=t+i-1,s=arguments[i];s=this.listWillInsert(n,s);var r=this.makeRef(s);this.refs.splice(n,0,r),this.state.splice(n,0,s),this.listDidInsert(n,s),this.command(e.concat({"@insert":{id:r.id,index:n}},s))}return this},O.prototype.push=function(){for(var t=0,i=arguments.length;t<i;t+=1){var o=this.state.length,n=arguments[t];n=this.listWillInsert(o,n);var s=this.makeRef(n);this.refs.push(s),this.state.push(n),this.listDidInsert(o,n),this.command(e.concat({"@insert":{id:s.id,index:o}},n))}return this.state.length},O.prototype.pop=function(){var t=this.state.length-1;if(!(t<0)){this.listWillRemove(t);var e=this.refs.pop(),i=this.state.pop();return this.listDidRemove(t,i),this.command({"@remove":{id:e.id,index:t}}),i}},O.prototype.unshift=function(){for(var t=arguments.length-1;t>=0;t-=1){var i=arguments[t];i=this.listWillInsert(0,i);var o=this.makeRef(i);this.refs.unshift(o),this.state.unshift(i),this.listDidInsert(0,i),this.command(e.concat({"@insert":{id:o.id,index:0}},i))}return this.state.length},O.prototype.shift=function(){if(0!==this.state.length){this.listWillRemove(0);var t=this.refs.shift(),e=this.state.shift();return this.listDidRemove(0,e),this.command({"@remove":{id:t.id,index:0}}),e}},O.prototype.move=function(t,e){if(t<0||t>=this.state.length)throw new RangeError("fromIndex");if(e<0||e>=this.state.length)throw new RangeError("toIndex");if(t===e)return this;var i=this.refs[t],o=this.state[t];return this.listWillMove(t,e,o),this.refs.splice(t,1),this.state.splice(t,1),this.refs.splice(e,0,i),this.state.splice(e,0,o),this.listDidMove(t,e,o),this.command({"@move":{id:i.id,from:t,to:e}}),this},O.prototype.splice=function(){var t=arguments[0];if(!U(t))throw new TypeError("start");t<0&&(t=this.state.length+t),t=Math.min(Math.max(0,t),this.state.length);var i;if(arguments.length>1){if(i=arguments[1],!U(i))throw new TypeError("deleteCount")}else i=this.state.length-t;var o,n,s,r=[];for(o=t,n=t+i;o<n;o+=1){this.listWillRemove(t),s=this.refs[t];var h=this.state[t];r.push(h),this.refs.splice(t,1),this.state.splice(t,1),this.listDidRemove(t,h),this.command({"@remove":{id:s.id,index:t}})}for(o=2,n=arguments.length;o<n;o+=1){var p=t+o-2,l=arguments[o];l=this.listWillInsert(p,l),s=this.makeRef(l),this.refs.splice(p,0,s),this.state.splice(p,0,l),this.listDidInsert(p,l),this.command(e.concat({"@insert":{id:s.id,index:p}},l))}return r},O.prototype.clear=function(){this.listWillClear(),this.refs.length=0,this.state.length=0,this.listDidClear(),this.command({"@clear":null})},O.prototype.forEach=function(t,e){for(var i=0,o=this.state.length;i<o;i+=1)t.call(e,this.state[i],i,this)},O.prototype.makeRef=function(t){var e=16777215*Math.random()|0,i=new Uint8Array(3);return i[0]=e>>16&255,i[1]=e>>8&255,i[2]=255&e,{id:i}},O.prototype.getRef=function(t){return this.refs[t]},O.prototype.setRefs=function(t){Object.defineProperty(this,"refs",{value:t,configurable:!0,enumerable:!0})},O.prototype.setState=function(t){Object.defineProperty(this,"state",{value:t,configurable:!0,enumerable:!0})},O.prototype.onEventMessage=function(t){w.prototype.onEventMessage.call(this,t);var i,o,n=t.body,s=e.tag(n);"@update"===s?(i=n[s],o=this.resolveIndex(i.id,i.index),o>=0?this.onUpdateEvent(i.id,o,e.body(n)):this.onInsertEvent(i.id,i.index,e.body(n))):"@insert"===s?(i=n[s],o=this.resolveIndex(i.id,i.index),o<0?this.onInsertEvent(i.id,i.index,e.body(n)):this.onUpdateEvent(i.id,o,e.body(n))):"@move"===s?(i=n[s],(o=this.resolveIndex(i.id,i.from))>=0&&this.onMoveEvent(i.id,o,i.to)):"@remove"===s?(i=n[s],(o=this.resolveIndex(i.id,i.index))>=0&&this.onRemoveEvent(i.id,o)):"@clear"===s&&this.onClearEvent()},O.prototype.onUpdateEvent=function(t,e,i){i=this.listWillUpdate(e,i);var o=this.state[e];this.state[e]=i,this.listDidUpdate(e,i,o)},O.prototype.onInsertEvent=function(t,e,i){i=this.listWillInsert(e,i);var o={id:t};this.refs.splice(e,0,o),this.state.splice(e,0,i),this.listDidInsert(e,i)},O.prototype.onMoveEvent=function(t,e,i){if(i=Math.min(Math.max(0,i),this.state.length),e!==i){var o=this.refs[e],n=this.state[e];this.listWillMove(e,i,n),this.refs.splice(e,1),this.state.splice(e,1),this.refs.splice(i,0,o),this.state.splice(i,0,n),this.listDidMove(e,i,n)}},O.prototype.onRemoveEvent=function(t,e){this.listWillRemove(e);var i=this.state[e];this.refs.splice(e,1),this.state.splice(e,1),this.listDidRemove(e,i)},O.prototype.onClearEvent=function(){this.listWillClear(),this.refs.length=0,this.state.length=0,this.listDidClear()},O.prototype.listWillInsert=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)e=this.views[i].listWillInsert(t,e);return e},O.prototype.listDidInsert=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)this.views[i].listDidInsert(t,e)},O.prototype.listWillUpdate=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)e=this.views[i].listWillUpdate(t,e);return e},O.prototype.listDidUpdate=function(t,e,i){for(var o=0,n=this.views.length;o<n;o+=1)this.views[o].listDidUpdate(t,e,i)},O.prototype.listWillMove=function(t,e,i){for(var o=0,n=this.views.length;o<n;o+=1)this.views[o].listWillMove(t,e,i)},O.prototype.listDidMove=function(t,e,i){for(var o=0,n=this.views.length;o<n;o+=1)this.views[o].listDidMove(t,e,i)},O.prototype.listWillRemove=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].listWillRemove(t)},O.prototype.listDidRemove=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)this.views[i].listDidRemove(t,e)},O.prototype.listWillClear=function(){for(var t=0,e=this.views.length;t<e;t+=1)this.views[t].listWillClear()},O.prototype.listDidClear=function(){for(var t=0,e=this.views.length;t<e;t+=1)this.views[t].listDidClear()},O.prototype.resolveIndex=function(t,i){var o=this.refs[i];if(o&&e.equal(o.id,t))return i;for(var n=0,s=this.refs.length;n<s;n+=1)if((o=this.refs[n])&&e.equal(o.id,t))return n;return-1},D.prototype=Object.create(m.prototype),D.prototype.constructor=D,D.prototype.getRef=function(t){return this.model.getRef(t)},Object.defineProperty(D.prototype,"length",{get:function(){return this.model.length},configurable:!0,enumerable:!0});D.prototype.get=function(t){return this.model.get(t)},D.prototype.set=function(t,e){return this.model.set(t,e),this},D.prototype.push=function(){return this.model.push.apply(this.model,arguments)},D.prototype.pop=function(){return this.model.pop()},D.prototype.unshift=function(){return this.model.unshift.apply(this.model,arguments)},D.prototype.shift=function(){return this.model.shift()},D.prototype.move=function(t,e){return this.model.move(t,e)},D.prototype.splice=function(){return this.model.splice.apply(this.model,arguments)},D.prototype.clear=function(){this.model.clear()},D.prototype.forEach=function(t,e){this.model.forEach(t,e)},D.prototype.willInsert=function(t){return arguments.length?(this.delegate.willInsert=t,this):this.delegate.willInsert},D.prototype.didInsert=function(t){return arguments.length?(this.delegate.didInsert=t,this):this.delegate.didInsert},D.prototype.willUpdate=function(t){return arguments.length?(this.delegate.willUpdate=t,this):this.delegate.willUpdate},D.prototype.didUpdate=function(t){return arguments.length?(this.delegate.didUpdate=t,this):this.delegate.didUpdate},D.prototype.willMove=function(t){return arguments.length?(this.delegate.willMove=t,this):this.delegate.willMove},D.prototype.didMove=function(t){return arguments.length?(this.delegate.didMove=t,this):this.delegate.didMove},D.prototype.willRemove=function(t){return arguments.length?(this.delegate.willRemove=t,this):this.delegate.willRemove},D.prototype.didRemove=function(t){return arguments.length?(this.delegate.didRemove=t,this):this.delegate.didRemove},D.prototype.willClear=function(t){return arguments.length?(this.delegate.willClear=t,this):this.delegate.willClear},D.prototype.didClear=function(t){return arguments.length?(this.delegate.didClear=t,this):this.delegate.didClear},D.prototype.listWillInsert=function(t,e){if(this.delegate&&"function"==typeof this.delegate.willInsert){var i=this.delegate.willInsert(t,e,this);void 0!==i&&(e=i)}return e},D.prototype.listDidInsert=function(t,e){this.delegate&&"function"==typeof this.delegate.didInsert&&this.delegate.didInsert(t,e,this)},D.prototype.listWillUpdate=function(t,e){if(this.delegate&&"function"==typeof this.delegate.willUpdate){var i=this.delegate.willUpdate(t,e,this);void 0!==i&&(e=i)}return e},D.prototype.listDidUpdate=function(t,e,i){this.delegate&&"function"==typeof this.delegate.didUpdate&&this.delegate.didUpdate(t,e,i,this)},D.prototype.listWillMove=function(t,e,i){this.delegate&&"function"==typeof this.delegate.willMove&&this.delegate.willMove(t,e,i,this)},D.prototype.listDidMove=function(t,e,i){this.delegate&&"function"==typeof this.delegate.didMove&&this.delegate.didMove(t,e,i,this)},D.prototype.listWillRemove=function(t){this.delegate&&"function"==typeof this.delegate.willRemove&&this.delegate.willRemove(t,this)},D.prototype.listDidRemove=function(t,e){this.delegate&&"function"==typeof this.delegate.didRemove&&this.delegate.didRemove(t,e,this)},D.prototype.listWillClear=function(){this.delegate&&"function"==typeof this.delegate.willClear&&this.delegate.willClear(this)},D.prototype.listDidClear=function(){this.delegate&&"function"==typeof this.delegate.didClear&&this.delegate.didClear(this)},D.prototype.makeRef=function(t){return arguments.length?(this.options.makeRef=t,this):this.options.makeRef},D.prototype.initialRefs=function(t){return arguments.length?(this.options.initialRefs=t,this):this.options.initialRefs},D.prototype.initialState=function(t){return arguments.length?(this.options.initialState=t,this):this.options.initialState},D.prototype.open=function(){var t=this.props,e=this.context.getDownlink(t.hostUri,t.nodeUri,t.laneUri);if(e){if(!(e instanceof O))throw"downlink type mismatch";e.addDownlink(this) | ||
}else e=new O(this.context,t.hostUri,t.nodeUri,t.laneUri,t.prio,t.rate,t.body,this.options.initialRefs,this.options.initialState,this.options.makeRef),e.addDownlink(this),this.context.openDownlink(e);return this.model=e,this.scope&&this.scope.addDownlink(this),this},R.prototype=Object.create(w.prototype),R.prototype.constructor=R,Object.defineProperty(R.prototype,"size",{get:function(){return e.length(this.state)},configurable:!0,enumerable:!0}),R.prototype.has=function(t){return e.has(this.state,t)},R.prototype.get=function(t){return e.get(this.state,t)},R.prototype.set=function(t,i){i=this.mapWillUpdate(t,i);var o=this.state,n=e.get(o,t),s=e.set(o,t,i);return this.setState(s),this.mapDidUpdate(t,i,n),this.command(e.concat({"@update":{key:t}},i)),this},R.prototype.delete=function(t){this.mapWillRemove(t);var i=this.state,o=e.get(i,t),n=e.remove(i,t);return this.setState(n),this.mapDidRemove(t,o),void 0!==o&&(this.command({"@remove":{key:t}}),!0)},R.prototype.clear=function(){this.mapWillClear(),this.setState({}),this.mapDidClear(),this.command({"@clear":null})},R.prototype.keys=function(){return e.keys(this.state)},R.prototype.values=function(){return e.values(this.state)},R.prototype.forEach=function(t,i){e.forEach(this.state,t,i)},R.prototype.setState=function(t){Object.defineProperty(this,"state",{value:t,configurable:!0,enumerable:!0})},R.prototype.onEventMessage=function(t){w.prototype.onEventMessage.call(this,t);var i,o=t.body,n=e.tag(o);"@update"===n?(i=o[n],this.onUpdateEvent(i.key,e.body(o))):"@remove"===n?(i=o[n],this.onRemoveEvent(i.key)):"@clear"===n&&this.onClearEvent()},R.prototype.onUpdateEvent=function(t,i){i=this.mapWillUpdate(t,i);var o=this.state,n=e.get(o,t),s=e.set(o,t,i);this.setState(s),this.mapDidUpdate(t,i,n)},R.prototype.onRemoveEvent=function(t){this.mapWillRemove(t);var i=this.state,o=e.get(i,t),n=e.remove(i,t);this.setState(n),this.mapDidRemove(t,o)},R.prototype.onClearEvent=function(){this.mapWillClear(),this.setState({}),this.mapDidClear()},R.prototype.mapWillUpdate=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)e=this.views[i].mapWillUpdate(t,e);return e},R.prototype.mapDidUpdate=function(t,e,i){for(var o=0,n=this.views.length;o<n;o+=1)this.views[o].mapDidUpdate(t,e,i)},R.prototype.mapWillRemove=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].mapWillRemove(t)},R.prototype.mapDidRemove=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)this.views[i].mapDidRemove(t,e)},R.prototype.mapWillClear=function(){for(var t=0,e=this.views.length;t<e;t+=1)this.views[t].mapWillClear()},R.prototype.mapDidClear=function(){for(var t=0,e=this.views.length;t<e;t+=1)this.views[t].mapDidClear()},j.prototype=Object.create(m.prototype),j.prototype.constructor=j,Object.defineProperty(j.prototype,"state",{get:function(){return this.model.state},configurable:!0,enumerable:!0}),Object.defineProperty(j.prototype,"size",{get:function(){return this.model.size},configurable:!0,enumerable:!0}),j.prototype.has=function(t){return this.model.has(t)},j.prototype.get=function(t){return this.model.get(t)},j.prototype.set=function(t,e){return this.model.set(t,e),this},j.prototype.delete=function(t){return this.model.delete(t)},j.prototype.clear=function(){this.model.clear()},j.prototype.keys=function(){return this.model.keys()},j.prototype.values=function(){return this.model.values()},j.prototype.forEach=function(t,e){this.model.forEach(t,e)},j.prototype.willUpdate=function(t){return arguments.length?(this.delegate.willUpdate=t,this):this.delegate.willUpdate},j.prototype.didUpdate=function(t){return arguments.length?(this.delegate.didUpdate=t,this):this.delegate.didUpdate},j.prototype.willRemove=function(t){return arguments.length?(this.delegate.willRemove=t,this):this.delegate.willRemove},j.prototype.didRemove=function(t){return arguments.length?(this.delegate.didRemove=t,this):this.delegate.didRemove},j.prototype.willClear=function(t){return arguments.length?(this.delegate.willClear=t,this):this.delegate.willClear},j.prototype.didClear=function(t){return arguments.length?(this.delegate.didClear=t,this):this.delegate.didClear},j.prototype.mapWillUpdate=function(t,e){if(this.delegate&&"function"==typeof this.delegate.willUpdate){var i=this.delegate.willUpdate(t,e,this);void 0!==i&&(e=i)}return e},j.prototype.mapDidUpdate=function(t,e,i){this.delegate&&"function"==typeof this.delegate.didUpdate&&this.delegate.didUpdate(t,e,i,this)},j.prototype.mapWillRemove=function(t){this.delegate&&"function"==typeof this.delegate.willRemove&&this.delegate.willRemove(t,this)},j.prototype.mapDidRemove=function(t,e){this.delegate&&"function"==typeof this.delegate.didRemove&&this.delegate.didRemove(t,e,this)},j.prototype.mapWillClear=function(){this.delegate&&"function"==typeof this.delegate.willClear&&this.delegate.willClear(this)},j.prototype.mapDidClear=function(){this.delegate&&"function"==typeof this.delegate.didClear&&this.delegate.didClear(this)},j.prototype.initialState=function(t){return arguments.length?(this.options.initialState=t,this):this.options.initialState},j.prototype.open=function(){var t=this.props,e=this.context.getDownlink(t.hostUri,t.nodeUri,t.laneUri);if(e){if(!(e instanceof R))throw"downlink type mismatch";e.addDownlink(this)}else e=new R(this.context,t.hostUri,t.nodeUri,t.laneUri,t.prio,t.rate,t.body,this.options.initialState),e.addDownlink(this),this.context.openDownlink(e);return this.model=e,this.scope&&this.scope.addDownlink(this),this},C.prototype=Object.create(w.prototype),C.prototype.constructor=C,C.prototype.get=function(){return this.state},C.prototype.set=function(t){t=this.valueWillSet(t);var e=this.state;this.setState(t),this.valueDidSet(t,e),this.command(t)},C.prototype.setState=function(t){Object.defineProperty(this,"state",{value:t,configurable:!0,enumerable:!0})},C.prototype.onEventMessage=function(t){w.prototype.onEventMessage.call(this,t),this.onSetEvent(t.body)},C.prototype.onSetEvent=function(t){t=this.valueWillSet(t);var e=this.state;this.setState(t),this.valueDidSet(t,e)},C.prototype.valueWillSet=function(t){for(var e=0,i=this.views.length;e<i;e+=1)t=this.views[e].valueWillSet(t);return t},C.prototype.valueDidSet=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)this.views[i].valueDidSet(t,e)},S.prototype=Object.create(m.prototype),S.prototype.constructor=S,S.prototype.get=function(){return this.model.get()},S.prototype.set=function(t){this.model.set(t)},S.prototype.setState=function(t){this.model.setState(t)},S.prototype.willSet=function(t){return arguments.length?(this.delegate.willSet=t,this):this.delegate.willSet},S.prototype.didSet=function(t){return arguments.length?(this.delegate.didSet=t,this):this.delegate.didSet},S.prototype.valueWillSet=function(t){if(this.delegate&&"function"==typeof this.delegate.willSet){var e=this.delegate.willSet(t,this);void 0!==e&&(t=e)}return t},S.prototype.valueDidSet=function(t,e){this.delegate&&"function"==typeof this.delegate.didSet&&this.delegate.didSet(t,e,this)},S.prototype.initialState=function(t){return arguments.length?(this.options.initialState=t,this):this.options.initialState},S.prototype.open=function(){var t=this.props,e=this.context.getDownlink(t.hostUri,t.nodeUri,t.laneUri);if(e){if(!(e instanceof C))throw"downlink type mismatch";e.addDownlink(this)}else e=new C(this.context,t.hostUri,t.nodeUri,t.laneUri,t.prio,t.rate,t.body,this.options.initialState),e.addDownlink(this),this.context.openDownlink(e);return this.model=e,this.scope&&this.scope.addDownlink(this),this},P.prototype.isConnected=function(){return this.host&&this.host.isConnected()},P.prototype.isAuthenticated=function(){return this.host&&this.host.isAuthenticated()},P.prototype.session=function(){return this.host&&this.host.session()},P.prototype.addDownlink=function(t){var e=t.hostUri,i=t.nodeUri,o=t.laneUri;0===this.downlinkCount&&this.open();var n=this.downlinks[e];n||(n={},this.downlinks[e]=n);var s=n[i];s||(s={},n[i]=s);var r=s[o];r||(r=[],s[o]=r),r.push(t),this.downlinkCount+=1},P.prototype.removeDownlink=function(t){var e=t.hostUri,i=t.nodeUri,o=t.laneUri,n=this.downlinks[e];if(n){var s=n[i];if(s){var r=s[o];if(r)for(var h=0;h<r.length;h+=1)if(r[h]===t){this.downlinkCount-=1,r.splice(h,1),0===r.length&&(delete s[o],0===Object.keys(s).length&&(delete n[i],0===Object.keys(n).length&&delete this.downlinks[e])),0===this.downlinkCount&&this.close();break}}}},P.prototype.hostDidConnect=function(t){Object.defineProperty(this,"host",{value:t,configurable:!0}),this.delegate&&"function"==typeof this.delegate.didConnect&&this.delegate.didConnect()},P.prototype.hostDidAuthenticate=function(t,e){this.delegate&&"function"==typeof this.delegate.didAuthenticate&&this.delegate.didAuthenticate(t.body)},P.prototype.hostDidDeauthenticate=function(t,e){this.delegate&&"function"==typeof this.delegate.didDeauthenticate&&this.delegate.didDeauthenticate(t.body)},P.prototype.hostDidDisconnect=function(t){Object.defineProperty(this,"host",{value:null,configurable:!0}),this.delegate&&"function"==typeof this.delegate.didDisconnect&&this.delegate.didDisconnect()},P.prototype.hostDidFail=function(t,e){this.delegate&&"function"==typeof this.delegate.didFail&&this.delegate.didFail(t)},P.prototype.open=function(){this.context.openScope(this)},P.prototype.close=function(){this.context.closeScope(this)},P.prototype.closeUp=function(){this.downlinkCount=0;var t=this.downlinks;Object.defineProperty(this,"downlinks",{value:{},configurable:!0});for(var e in t){var i=t[e];for(var o in i){var n=i[o];for(var s in n)for(var r=n[s],h=0;h<r.length;h+=1)r[h].close()}}},x.prototype=Object.create(P.prototype),x.prototype.constructor=x,x.prototype.host=function(){return this.hostUri},x.prototype.node=function(t){return new E(this.context,this.hostUri,e.Uri.resolveUri(this.hostUri,t))},x.prototype.lane=function(t,i){return new M(this.context,this.hostUri,e.Uri.resolveUri(this.hostUri,t),i)},x.prototype.downlink=function(){return new k(this.context,this,this.props)},x.prototype.downlinkList=function(){return new D(this.context,this,this.props)},x.prototype.downlinkMap=function(){return new j(this.context,this,this.props)},x.prototype.downlinkValue=function(){return new S(this.context,this,this.props)},x.prototype.command=function(t,i,o){this.context.command(e.Uri.resolveUri(this.hostUri,t),i,o)},x.prototype.authenticate=function(t){this.context.authenticate(this.hostUri,t)},E.prototype=Object.create(P.prototype),E.prototype.constructor=E,E.prototype.host=function(){return this.hostUri},E.prototype.node=function(){return this.nodeUri},E.prototype.lane=function(t){return new M(this.context,this.hostUri,this.nodeUri,t)},E.prototype.downlink=function(){return new k(this.context,this,this.props)},E.prototype.downlinkList=function(){return new D(this.context,this,this.props)},E.prototype.downlinkMap=function(){return new j(this.context,this,this.props)},E.prototype.downlinkValue=function(){return new S(this.context,this,this.props)},E.prototype.command=function(t,e){this.context.command(this.nodeUri,t,e)},E.prototype.authenticate=function(t){this.context.authenticate(this.hostUri,t)},M.prototype=Object.create(P.prototype),M.prototype.constructor=M,M.prototype.host=function(){return this.hostUri},M.prototype.node=function(){return this.nodeUri},M.prototype.lane=function(){return this.laneUri},M.prototype.downlink=function(){return new k(this.context,this,this.props)},M.prototype.downlinkList=function(){return new D(this.context,this,this.props)},M.prototype.downlinkMap=function(){return new j(this.context,this,this.props)},M.prototype.downlinkValue=function(){return new S(this.context,this,this.props)},M.prototype.command=function(t){this.context.command(this.nodeUri,this.laneUri,t)},M.prototype.authenticate=function(t){this.context.authenticate(this.hostUri,t)},Object.defineProperty(W.prototype,"credentials",{get:function(){return this.options.credentials}}),Object.defineProperty(W.prototype,"maxReconnectTimeout",{get:function(){return this.options.maxReconnectTimeout||3e4}}),Object.defineProperty(W.prototype,"idleTimeout",{get:function(){return this.options.idleTimeout||1e3}}),Object.defineProperty(W.prototype,"sendBufferSize",{get:function(){return this.options.sendBufferSize||1024}}),W.prototype.isAuthenticated=function(){return this.authenticated},W.prototype.session=function(){return this.authentication},W.prototype.isIdle=function(){return 0===this.sendBuffer.length&&0===this.downlinkCount},W.prototype.resolve=function(t){return this.uriCache.resolve(t)},W.prototype.unresolve=function(t){return this.uriCache.unresolve(t)},W.prototype.authenticate=function(t){if(!e.equal(this.options.credentials,t))if(this.options.credentials=t,this.isConnected()){var i=new f(t);this.push(i)}else this.open()},W.prototype.openDownlink=function(t){this.clearIdle();var e=t.nodeUri,i=t.laneUri;0===this.downlinkCount&&this.open();var o=this.downlinks[e];if(o||(o={},this.downlinks[e]=o),o[i])throw"duplicate downlink";o[i]=t,this.downlinkCount+=1,this.isConnected()&&t.hostDidConnect(this)},W.prototype.closeDownlink=function(t){var e=t.nodeUri,i=t.laneUri,o=this.downlinks[e];if(o&&o[i]){if(this.downlinkCount-=1,delete o[i],0===Object.keys(o).length&&delete this.downlinks[e],this.isConnected()){var n=new c(this.unresolve(e),i);t.onUnlinkRequest(n),this.push(n)}0===this.downlinkCount&&this.watchIdle(),t.closeUp()}},W.prototype.command=function(t,e,i){var o=new h(this.unresolve(t),e,i);this.push(o)},W.prototype.onEnvelope=function(t){t instanceof r?this.onEventMessage(t):t instanceof h?this.onCommandMessage(t):t instanceof p?this.onLinkRequest(t):t instanceof l?this.onLinkedResponse(t):t instanceof d?this.onSyncRequest(t):t instanceof a?this.onSyncedResponse(t):t instanceof c?this.onUnlinkRequest(t):t instanceof u?this.onUnlinkedResponse(t):t instanceof f?this.onAuthRequest(t):t instanceof y?this.onAuthedResponse(t):t instanceof v?this.onDeauthRequest(t):t instanceof g?this.onDeauthedResponse(t):this.onUnknownEnvelope(t)},W.prototype.onEventMessage=function(t){var e=this.resolve(t.node),i=t.lane,o=this.downlinks[e];if(o){var n=o[i];if(n){var s=t.withAddress(e);n.onEventMessage(s)}}},W.prototype.onCommandMessage=function(t){},W.prototype.onLinkRequest=function(t){},W.prototype.onLinkedResponse=function(t){var e=this.resolve(t.node),i=t.lane,o=this.downlinks[e];if(o){var n=o[i];if(n){var s=t.withAddress(e);n.onLinkedResponse(s)}}},W.prototype.onSyncRequest=function(t){},W.prototype.onSyncedResponse=function(t){var e=this.resolve(t.node),i=t.lane,o=this.downlinks[e];if(o){var n=o[i];if(n){var s=t.withAddress(e);n.onSyncedResponse(s)}}},W.prototype.onUnlinkRequest=function(t){},W.prototype.onUnlinkedResponse=function(t){var e=this.resolve(t.node),i=t.lane,o=this.downlinks[e];if(o){var n=o[i];if(n){delete o[i],0===Object.keys(o).length&&delete this.downlinks[e];var s=t.withAddress(e);n.onUnlinkedResponse(s),n.closeUp()}}},W.prototype.onAuthRequest=function(t){},W.prototype.onAuthedResponse=function(t){Object.defineProperty(this,"authenticated",{value:!0,enumerable:!0,configurable:!0}),Object.defineProperty(this,"authentication",{value:t.body,enumerable:!0,configurable:!0}),this.context.hostDidAuthenticate(t,this)},W.prototype.onDeauthRequest=function(t){},W.prototype.onDeauthedResponse=function(t){Object.defineProperty(this,"authenticated",{value:!1,enumerable:!0,configurable:!0}),Object.defineProperty(this,"authentication",{value:null,enumerable:!0,configurable:!0}),this.context.hostDidDeauthenticate(t,this)},W.prototype.onConnect=function(){this.reconnectTimeout=0,this.context.hostDidConnect(this);for(var t in this.downlinks){var e=this.downlinks[t];for(var i in e){e[i].hostDidConnect(this)}}},W.prototype.onDisconnect=function(){Object.defineProperty(this,"authenticated",{value:!1,enumerable:!0,configurable:!0}),Object.defineProperty(this,"authentication",{value:null,enumerable:!0,configurable:!0}),this.context.hostDidDisconnect(this);for(var t in this.downlinks){var e=this.downlinks[t];for(var i in e){e[i].hostDidDisconnect(this)}}},W.prototype.onError=function(t){this.context.hostDidFail(t,this);for(var e in this.downlinks){var i=this.downlinks[e];for(var o in i){i[o].hostDidFail(t,this)}}},W.prototype.reconnect=function(){this.reconnectTimer||(this.reconnectTimeout?this.reconnectTimeout=Math.min(Math.floor(1.8*this.reconnectTimeout),this.maxReconnectTimeout):this.reconnectTimeout=Math.floor(500+1e3*Math.random()),this.reconnectTimer=setTimeout(this.open.bind(this),this.reconnectTimeout))},W.prototype.clearReconnect=function(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)},W.prototype.clearIdle=function(){this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null)},W.prototype.watchIdle=function(){!this.idleTimer&&this.isConnected()&&this.isIdle()&&(this.idleTimer=setTimeout(this.checkIdle.bind(this),this.idleTimeout))},W.prototype.checkIdle=function(){this.isConnected()&&this.isIdle()&&this.close()},W.prototype.close=function(){this.context.closeHost(this)},W.prototype.closeUp=function(){for(var t in this.downlinks){var e=this.downlinks[t];for(var i in e){e[i].closeUp(this)}}},I.prototype=Object.create(W.prototype),I.prototype.constructor=I,Object.defineProperty(I.prototype,"WebSocket",{get:function(){return this.options.WebSocket||"undefined"!=typeof WebSocket&&WebSocket||"function"==typeof require&&require("ws")}}),I.prototype.isConnected=function(){return this.socket&&this.socket.readyState===this.socket.OPEN},I.prototype.open=function(){this.clearReconnect(),this.socket||(this.options.protocols?this.socket=new this.WebSocket(this.hostUri,this.options.protocols):this.socket=new this.WebSocket(this.hostUri),this.socket.onopen=this.onWebSocketOpen.bind(this),this.socket.onmessage=this.onWebSocketMessage.bind(this),this.socket.onclose=this.onWebSocketClose.bind(this),this.socket.onerror=this.onWebSocketError.bind(this))},I.prototype.close=function(){this.clearReconnect(),this.clearIdle(),this.socket?(this.socket.close(),this.context.online||this.onWebSocketClose()):W.prototype.close.call(this)},I.prototype.push=function(t){if(this.isConnected()){this.clearIdle();var e=t.toRecon();this.socket.send(e),this.watchIdle()}else if(t instanceof h){if(!(this.sendBuffer.length<this.sendBufferSize))throw"send buffer overflow";this.sendBuffer.push(t),this.open()}},I.prototype.onWebSocketOpen=function(){if(this.isConnected()){var t=this.credentials;if(t){var e=new f(t);this.push(e)}this.onConnect();for(var i;(i=this.sendBuffer.shift())&&this.isConnected();)this.push(i);this.watchIdle()}else this.close()},I.prototype.onWebSocketMessage=function(t){var e=t.data;if("string"==typeof e){var o=i.parse(e);o?this.onEnvelope(o):this.onUnknownEnvelope(e)}},I.prototype.onWebSocketClose=function(){this.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onclose=null,this.socket.onerror=null,this.socket=null),this.onDisconnect(),this.clearIdle(),this.isIdle()?this.close():this.context.online&&this.reconnect()},I.prototype.onWebSocketError=function(){this.onError(),this.socket&&this.socket.close()},q.prototype.isOnline=function(t){if(!arguments.length)return this.online;if(this.online!==t){Object.defineProperty(this,"online",{value:t,configurable:!0});for(var e in this.hosts){var i=this.hosts[e];t?i.open():i.close()}}return this},q.prototype.keepOnline=function(t){return arguments.length?(this.options.keepOnline!==t&&(this.options.keepOnline=t,this.watchOnline(t)),this):void 0===this.options.keepOnline||this.options.keepOnline},q.prototype.watchOnline=function(t){"object"==typeof window&&(t?(window.addEventListener("online",this.onOnline,!1),window.addEventListener("offline",this.onOffline,!1)):(window.removeEventListener("online",this.onOnline,!1),window.removeEventListener("offline",this.onOffline,!1)))},q.prototype.onOnline=function(){this.isOnline(!0)},q.prototype.onOffline=function(){this.isOnline(!1)};q.prototype.openScope=function(t){this.scopes.push(t)},q.prototype.closeScope=function(t){for(var e=0;e<this.scopes.length;e+=1)if(this.scopes[e]===t){this.scopes.splice(e,1),t.closeUp();break}},q.prototype.getHost=function(t){return this.hosts[t]},q.prototype.openHost=function(t){var e=this.hosts[t];return e||(e=new I(this,t,this.options),this.hosts[t]=e),e},q.prototype.closeHost=function(t){this.hosts[t.hostUri]&&(delete this.hosts[t.hostUri],t.closeUp())},q.prototype.getDownlink=function(t,e,i){var o=this.downlinks[t];if(o){var n=o[e];if(n)return n[i]}},q.prototype.openDownlink=function(t){var e=t.hostUri,i=t.nodeUri,o=t.laneUri,n=this.downlinks[e];n||(n={},this.downlinks[e]=n);var s=n[i];if(s||(s={},n[i]=s),s[o])throw"duplicate downlink";s[o]=t,this.downlinkCount+=1,this.openHost(e).openDownlink(t)},q.prototype.closeDownlink=function(t){var e=t.hostUri,i=t.nodeUri,o=t.laneUri,n=this.downlinks[e];if(n){var s=n[i];if(s&&s[o]){this.downlinkCount-=1,delete s[o],0===Object.keys(s).length&&(delete n[i],0===Object.keys(n).length&&delete this.downlinks[e]);var r=this.getHost(e);r&&r.closeDownlink(t)}}},q.prototype.host=function(t){return new x(this,t)},q.prototype.node=function(){var t,i;return 1===arguments.length?(i=arguments[0],t=e.Uri.getHostUri(i)):(t=arguments[0],i=e.Uri.resolveUri(t,arguments[1])),new E(this,t,i)},q.prototype.lane=function(){var t,i,o;return 2===arguments.length?(o=arguments[1],i=arguments[0],t=e.Uri.getHostUri(i)):(t=arguments[0],i=e.Uri.resolveUri(t,arguments[1]),o=arguments[2]),new M(this,t,i,o)},q.prototype.downlink=function(){return new k(this)},q.prototype.downlinkList=function(){return new D(this)},q.prototype.downlinkMap=function(){return new j(this)},q.prototype.downlinkValue=function(){return new S(this)},q.prototype.command=function(){var t,i,o,n;3===arguments.length?(n=arguments[2],o=arguments[1],i=arguments[0],t=e.Uri.getHostUri(i)):(t=arguments[0],i=e.Uri.resolveUri(t,arguments[1]),o=arguments[2],n=arguments[3]),this.openHost(t).command(i,o,n)},q.prototype.authenticate=function(t,e){this.openHost(t).authenticate(e)},q.prototype.didAuthenticate=function(t){return arguments.length?(this.delegate.didAuthenticate=t,this):this.delegate.didAuthenticate},q.prototype.didDeauthenticate=function(t){return arguments.length?(this.delegate.didDeauthenticate=t,this):this.delegate.didDeauthenticate},q.prototype.didConnect=function(t){return arguments.length?(this.delegate.didConnect=t,this):this.delegate.didConnect},q.prototype.didDisconnect=function(t){return arguments.length?(this.delegate.didDisconnect=t,this):this.delegate.didDisconnect},q.prototype.didFail=function(t){return arguments.length?(this.delegate.didFail=t,this):this.delegate.didFail},q.prototype.hostDidAuthenticate=function(t,e){this.delegate&&"function"==typeof this.delegate.didAuthenticate&&this.delegate.didAuthenticate(t.body,e);for(var i=0,o=this.scopes.length;i<o;i+=1){var n=this.scopes[i];n.hostUri===e.hostUri&&n.hostDidAuthenticate(t,e)}},q.prototype.hostDidDeauthenticate=function(t,e){this.delegate&&"function"==typeof this.delegate.didDeauthenticate&&this.delegate.didDeauthenticate(t.body,e);for(var i=0,o=this.scopes.length;i<o;i+=1){var n=this.scopes[i];n.hostUri===e.hostUri&&n.hostDidDeauthenticate(t,e)}},q.prototype.hostDidConnect=function(t){this.delegate&&"function"==typeof this.delegate.didConnect&&this.delegate.didConnect(t);for(var e=0,i=this.scopes.length;e<i;e+=1){var o=this.scopes[e];o.hostUri===t.hostUri&&o.hostDidConnect(t)}},q.prototype.hostDidDisconnect=function(t){this.delegate&&"function"==typeof this.delegate.didDisconnect&&this.delegate.didDisconnect(t);for(var e=0,i=this.scopes.length;e<i;e+=1){var o=this.scopes[e];o.hostUri===t.hostUri&&o.hostDidDisconnect(t)}},q.prototype.hostDidFail=function(t,e){this.delegate&&"function"==typeof this.delegate.didFail&&this.delegate.didFail(t,e);for(var i=0,o=this.scopes.length;i<o;i+=1){var n=this.scopes[i];n.hostUri===e.hostUri&&n.hostDidFail(t,e)}},q.prototype.close=function(){var t,e=this.scopes;Object.defineProperty(this,"scopes",{value:[],configurable:!0});for(var i=0;i<e.length;i+=1)e[i].closeUp();this.downlinkCount=0;var o=this.downlinks;Object.defineProperty(this,"downlinks",{value:{},configurable:!0});for(t in o){var n=o[t];for(var s in n){var r=n[s];for(var h in r)r[h].closeUp()}}var p=this.hosts;Object.defineProperty(this,"hosts",{value:{},configurable:!0});for(t in p)p[t].closeUp()};var J=new q;t.client=J,t.isOnline=L,t.keepOnline=A,t.host=T,t.node=F,t.lane=H,t.downlink=z,t.downlinkList=B,t.downlinkMap=V,t.downlinkValue=_,t.command=N,t.authenticate=G,t.Envelope=i,t.RequestEnvelope=o,t.ResponseEnvelope=n,t.MessageEnvelope=s,t.EventMessage=r,t.CommandMessage=h,t.LinkRequest=p,t.LinkedResponse=l,t.SyncRequest=d,t.SyncedResponse=a,t.UnlinkRequest=c,t.UnlinkedResponse=u,t.AuthRequest=f,t.AuthedResponse=y,t.DeauthRequest=v,t.DeauthedResponse=g,t.Client=q,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
// Swim client v0.5.2. Copyright 2015-2017, Swim.it Inc. | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("recon-js")):"function"==typeof define&&define.amd?define(["exports","recon-js"],e):e(t.Swim=t.Swim||{},t.Recon)}(this,function(t,e){"use strict";function i(){}function o(){i.call(this)}function n(){i.call(this)}function s(){i.call(this)}function r(t,e,i){s.call(this),this.node=t,this.lane=e,this.body=i}function h(t,e,i){s.call(this),this.node=t,this.lane=e,this.body=i}function p(t,e,i,n,s){o.call(this),this.node=t,this.lane=e,this.prio=i,this.rate=n,this.body=s}function l(t,e,i,o,s){n.call(this),this.node=t,this.lane=e,this.prio=i,this.rate=o,this.body=s}function d(t,e,i,n,s){o.call(this),this.node=t,this.lane=e,this.prio=i,this.rate=n,this.body=s}function c(t,e,i){n.call(this),this.node=t,this.lane=e,this.body=i}function a(t,e,i){o.call(this),this.node=t,this.lane=e,this.body=i}function u(t,e,i){n.call(this),this.node=t,this.lane=e,this.body=i}function f(t){o.call(this),this.body=t}function y(t){n.call(this),this.body=t}function v(t){o.call(this),this.body=t}function g(t){n.call(this),this.body=t}function w(t,i,o){this.context=t,this.hostUri=i,this.options=o||{},this.downlinks={},this.downlinkCount=0,this.authenticated=!1,this.authentication=null,this.uriCache=new e.UriCache(i),this.sendBuffer=[],this.reconnectTimer=null,this.reconnectTimeout=0,this.idleTimer=null}function m(t,e,i,o,n,s,r){this.context=t,this.hostUri=e,this.nodeUri=i,this.laneUri=o,this.prio=n,this.rate=s,this.body=r,this.views=[],this.host=null,this.linked=!1,this.synced=!1}function k(t,e,i,o,n){this.context=t,this.scope=e,this.props=i||{},this.options=o||{},this.delegate=n||{},this.model=null}function U(t,e,i,o,n,s,r){m.call(this,t,e,i,o,n,s,r)}function D(t,e,i,o,n){k.call(this,t,e,i,o,n)}function R(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t}function b(t,e,i,o,n,s,r,h,p,l){m.call(this,t,e,i,o,n,s,r),this.refs=h||[],this.state=p||[],l&&(this.makeRef=l)}function C(t,e,i,o,n){k.call(this,t,e,i,o,n)}function S(t,e,i,o,n,s,r,h){m.call(this,t,e,i,o,n,s,r),this.state=h||{}}function E(t,e,i,o,n){k.call(this,t,e,i,o,n)}function x(t,e,i,o,n,s,r,h){m.call(this,t,e,i,o,n,s,r),this.state=h}function M(t,e,i,o,n){k.call(this,t,e,i,o,n)}function O(t){this.context=t,this.downlinks={},this.downlinkCount=0,this.delegate=this}function W(t,e){O.call(this,t),this.hostUri=e,this.props={hostUri:e}}function I(t,e,i){O.call(this,t),this.hostUri=e,this.nodeUri=i,this.props={hostUri:e,nodeUri:i}}function L(t,e,i,o){O.call(this,t),this.hostUri=e,this.nodeUri=i,this.laneUri=o,this.props={hostUri:e,nodeUri:i,laneUri:o}}function A(t,e,i){w.call(this,t,e,i)}function q(t){this.options=t||{},this.scopes=[],this.hosts={},this.downlinks={},this.downlinkCount=0,this.online=!0,this.delegate={},this.onOnline=this.onOnline.bind(this),this.onOffline=this.onOffline.bind(this),this.watchOnline(this.options.keepOnline)}function j(){return Q.isOnline.apply(Q,arguments)}function T(){return Q.keepOnline.apply(Q,arguments)}function F(){return Q.host.apply(Q,arguments)}function H(){return Q.node.apply(Q,arguments)}function V(){return Q.lane.apply(Q,arguments)}function B(){return Q.downlink.apply(Q,arguments)}function P(){return Q.downlinkList.apply(Q,arguments)}function z(){return Q.downlinkMap.apply(Q,arguments)}function N(){return Q.downlinkValue.apply(Q,arguments)}function _(){Q.command.apply(Q,arguments)}function G(){Q.authenticate.apply(Q,arguments)}i.prototype.isRequest=!1,i.prototype.isResponse=!1,i.prototype.isMessage=!1,i.prototype.isEventMessage=!1,i.prototype.isCommandMessage=!1,i.prototype.isLinkRequest=!1,i.prototype.isLinkedResponse=!1,i.prototype.isSyncRequest=!1,i.prototype.isSyncedResponse=!1,i.prototype.isUnlinkRequest=!1,i.prototype.isUnlinkedResponse=!1,i.prototype.isAuthRequest=!1,i.prototype.isAuthedResponse=!1,i.prototype.isDeauthRequest=!1,i.prototype.isDeauthedResponse=!1,i.prototype.encode=function(){},i.prototype.toRecon=function(){return e.stringify(this.encode())},i.decode=function(t){switch(e.tag(t)){case"@event":return r.decode(t);case"@command":return h.decode(t);case"@link":return p.decode(t);case"@linked":return l.decode(t);case"@sync":return d.decode(t);case"@synced":return c.decode(t);case"@unlink":return a.decode(t);case"@unlinked":return u.decode(t);case"@auth":return f.decode(t);case"@authed":return y.decode(t);case"@deauth":return v.decode(t);case"@deauthed":return g.decode(t);default:return null}},i.parse=function(t){return i.decode(e.parse(t))},o.prototype=Object.create(i.prototype),o.prototype.constructor=o,o.prototype.isRequest=!0,n.prototype=Object.create(i.prototype),n.prototype.constructor=n,n.prototype.isResponse=!0,s.prototype=Object.create(i.prototype),s.prototype.constructor=s,s.prototype.isMessage=!0,r.prototype=Object.create(s.prototype),r.prototype.constructor=r,r.prototype.isEventMessage=!0,r.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new r(t,e,this.body)},r.prototype.encode=function(){var t={};return t.node=this.node,t.lane=this.lane,e.concat({"@event":t},this.body)},r.decode=function(t){var i,o,n=e.headers(t,"@event");if(e.forEach(n,function(t,e,n){"node"===e?i=t:"lane"===e?o=t:0===n?i=t:1===n&&(o=t)}),void 0!==i&&void 0!==o){var s=e.body(t);return new r(i,o,s)}return null},h.prototype=Object.create(s.prototype),h.prototype.constructor=h,h.prototype.isCommandMessage=!0,h.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new h(t,e,this.body)},h.prototype.encode=function(){var t={};return t.node=this.node,t.lane=this.lane,e.concat({"@command":t},this.body)},h.decode=function(t){var i,o,n=e.headers(t,"@command");if(e.forEach(n,function(t,e,n){"node"===e?i=t:"lane"===e?o=t:0===n?i=t:1===n&&(o=t)}),void 0!==i&&void 0!==o){var s=e.body(t);return new h(i,o,s)}return null},p.prototype=Object.create(o.prototype),p.prototype.constructor=p,p.prototype.isLinkRequest=!0,p.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new p(t,e,this.prio,this.rate,this.body)},p.prototype.encode=function(){var t={};return t.node=this.node,t.lane=this.lane,void 0!==this.prio&&0!==this.prio&&(t.prio=this.prio),void 0!==this.rate&&0!==this.rate&&(t.rate=this.rate),e.concat({"@link":t},this.body)},p.decode=function(t){var i,o,n,s,r=e.headers(t,"@link");if(e.forEach(r,function(t,e,r){"node"===e?i=t:"lane"===e?o=t:"prio"===e?n=t:"rate"===e?s=t:0===r?i=t:1===r&&(o=t)}),void 0!==i&&void 0!==o){var h=e.body(t);return new p(i,o,n,s,h)}return null},l.prototype=Object.create(n.prototype),l.prototype.constructor=l,l.prototype.isLinkedResponse=!0,l.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new l(t,e,this.prio,this.rate,this.body)},l.prototype.encode=function(){var t={};return t.node=this.node,t.lane=this.lane,void 0!==this.prio&&0!==this.prio&&(t.prio=this.prio),void 0!==this.rate&&0!==this.rate&&(t.rate=this.rate),e.concat({"@linked":t},this.body)},l.decode=function(t){var i,o,n,s,r=e.headers(t,"@linked");if(e.forEach(r,function(t,e,r){"node"===e?i=t:"lane"===e?o=t:"prio"===e?n=t:"rate"===e?s=t:0===r?i=t:1===r&&(o=t)}),void 0!==i&&void 0!==o){var h=e.body(t);return new l(i,o,n,s,h)}return null},d.prototype=Object.create(o.prototype),d.prototype.constructor=d,d.prototype.isSyncRequest=!0,d.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new d(t,e,this.prio,this.rate,this.body)},d.prototype.encode=function(){var t={};return t.node=this.node,t.lane=this.lane,void 0!==this.prio&&0!==this.prio&&(t.prio=this.prio),void 0!==this.rate&&0!==this.rate&&(t.rate=this.rate),e.concat({"@sync":t},this.body)},d.decode=function(t){var i,o,n,s,r=e.headers(t,"@sync");if(e.forEach(r,function(t,e,r){"node"===e?i=t:"lane"===e?o=t:"prio"===e?n=t:"rate"===e?s=t:0===r?i=t:1===r&&(o=t)}),void 0!==i&&void 0!==o){var h=e.body(t);return new d(i,o,n,s,h)}return null},c.prototype=Object.create(n.prototype),c.prototype.constructor=c,c.prototype.isSyncedResponse=!0,c.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new c(t,e,this.body)},c.prototype.encode=function(){var t={};return t.node=this.node,t.lane=this.lane,e.concat({"@synced":t},this.body)},c.decode=function(t){var i,o,n=e.headers(t,"@synced");if(e.forEach(n,function(t,e,n){"node"===e?i=t:"lane"===e?o=t:0===n?i=t:1===n&&(o=t)}),void 0!==i&&void 0!==o){var s=e.body(t);return new c(i,o,s)}return null},a.prototype=Object.create(o.prototype),a.prototype.constructor=a,a.prototype.isUnlinkRequest=!0,a.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new a(t,e,this.body)},a.prototype.encode=function(){var t={};return t.node=this.node,t.lane=this.lane,e.concat({"@unlink":t},this.body)},a.decode=function(t){var i,o,n=e.headers(t,"@unlink");if(e.forEach(n,function(t,e,n){"node"===e?i=t:"lane"===e?o=t:0===n?i=t:1===n&&(o=t)}),void 0!==i&&void 0!==o){var s=e.body(t);return new a(i,o,s)}return null},u.prototype=Object.create(n.prototype),u.prototype.constructor=u,u.prototype.isUnlinkedResponse=!0,u.prototype.withAddress=function(t,e){return void 0===t&&(t=this.node),void 0===e&&(e=this.lane),new u(t,e,this.body)},u.prototype.encode=function(){var t={};return t.node=this.node,t.lane=this.lane,e.concat({"@unlinked":t},this.body)},u.decode=function(t){var i,o,n=e.headers(t,"@unlinked");if(e.forEach(n,function(t,e,n){"node"===e?i=t:"lane"===e?o=t:0===n?i=t:1===n&&(o=t)}),void 0!==i&&void 0!==o){var s=e.body(t);return new u(i,o,s)}return null},f.prototype=Object.create(o.prototype),f.prototype.constructor=f,f.prototype.isAuthRequest=!0,f.prototype.encode=function(){return e.concat({"@auth":null},this.body)},f.decode=function(t){if(e.headers(t,"@auth"))return new f(e.body(t));return null},y.prototype=Object.create(n.prototype),y.prototype.constructor=y,y.prototype.isAuthedResponse=!0,y.prototype.encode=function(){return e.concat({"@authed":null},this.body)},y.decode=function(t){if(e.headers(t,"@authed"))return new y(e.body(t));return null},v.prototype=Object.create(o.prototype),v.prototype.constructor=v,v.prototype.isDeauthRequest=!0,v.prototype.encode=function(){return e.concat({"@deauth":null},this.body)},v.decode=function(t){if(e.headers(t,"@deauth"))return new v(e.body(t));return null},g.prototype=Object.create(n.prototype),g.prototype.constructor=g,g.prototype.isDeauthedResponse=!0,g.prototype.encode=function(){return e.concat({"@deauthed":null},this.body)},g.decode=function(t){if(e.headers(t,"@deauthed"))return new g(e.body(t));return null},w.prototype.credentials=function(){return this.options.credentials},w.prototype.maxReconnectTimeout=function(){return this.options.maxReconnectTimeout||3e4},w.prototype.idleTimeout=function(){return this.options.idleTimeout||1e3},w.prototype.sendBufferSize=function(){return this.options.sendBufferSize||1024},w.prototype.isConnected=function(){},w.prototype.isAuthenticated=function(){return this.authenticated},w.prototype.session=function(){return this.authentication},w.prototype.isIdle=function(){return 0===this.sendBuffer.length&&0===this.downlinkCount},w.prototype.resolve=function(t){return this.uriCache.resolve(t)},w.prototype.unresolve=function(t){return this.uriCache.unresolve(t)},w.prototype.authenticate=function(t){if(!e.equal(this.options.credentials,t))if(this.options.credentials=t,this.isConnected()){var i=new f(t);this.push(i)}else this.open()},w.prototype.openDownlink=function(t){this.clearIdle();var e=this.resolve(t.nodeUri),i=t.laneUri;0===this.downlinkCount&&this.open();var o=this.downlinks[e];if(o||(o={},this.downlinks[e]=o),o[i])throw"duplicate downlink";o[i]=t,this.downlinkCount+=1,t.openUp(this),this.isConnected()&&t.hostDidConnect(this)},w.prototype.closeDownlink=function(t){var e=this.resolve(t.nodeUri),i=t.laneUri,o=this.downlinks[e];if(o&&o[i]){if(this.downlinkCount-=1,delete o[i],0===Object.keys(o).length&&delete this.downlinks[e],this.isConnected()){var n=new a(this.unresolve(e),i);t.onUnlinkRequest(n),this.push(n)}0===this.downlinkCount&&this.watchIdle(),t.closeUp()}},w.prototype.command=function(t,e,i){var o=new h(this.unresolve(t),e,i);this.push(o)},w.prototype.onEnvelope=function(t){t instanceof r?this.onEventMessage(t):t instanceof h?this.onCommandMessage(t):t instanceof p?this.onLinkRequest(t):t instanceof l?this.onLinkedResponse(t):t instanceof d?this.onSyncRequest(t):t instanceof c?this.onSyncedResponse(t):t instanceof a?this.onUnlinkRequest(t):t instanceof u?this.onUnlinkedResponse(t):t instanceof f?this.onAuthRequest(t):t instanceof y?this.onAuthedResponse(t):t instanceof v?this.onDeauthRequest(t):t instanceof g?this.onDeauthedResponse(t):this.onUnknownEnvelope(t)},w.prototype.onEventMessage=function(t){var e=this.resolve(t.node),i=t.lane,o=this.downlinks[e];if(o){var n=o[i];if(n){var s=t.withAddress(e);n.onEventMessage(s)}}},w.prototype.onCommandMessage=function(t){},w.prototype.onLinkRequest=function(t){},w.prototype.onLinkedResponse=function(t){var e=this.resolve(t.node),i=t.lane,o=this.downlinks[e];if(o){var n=o[i];if(n){var s=t.withAddress(e);n.onLinkedResponse(s)}}},w.prototype.onSyncRequest=function(t){},w.prototype.onSyncedResponse=function(t){var e=this.resolve(t.node),i=t.lane,o=this.downlinks[e];if(o){var n=o[i];if(n){var s=t.withAddress(e);n.onSyncedResponse(s)}}},w.prototype.onUnlinkRequest=function(t){},w.prototype.onUnlinkedResponse=function(t){var e=this.resolve(t.node),i=t.lane,o=this.downlinks[e];if(o){var n=o[i];if(n){delete o[i],0===Object.keys(o).length&&delete this.downlinks[e];var s=t.withAddress(e);n.onUnlinkedResponse(s),n.closeUp()}}},w.prototype.onAuthRequest=function(t){},w.prototype.onAuthedResponse=function(t){this.authenticated=!0,this.authentication=t.body,this.context.hostDidAuthenticate(t,this)},w.prototype.onDeauthRequest=function(t){},w.prototype.onDeauthedResponse=function(t){this.authenticated=!1,this.authentication=null,this.context.hostDidDeauthenticate(t,this)},w.prototype.onUnknownEnvelope=function(t){},w.prototype.onConnect=function(){this.reconnectTimeout=0,this.context.hostDidConnect(this);for(var t in this.downlinks){var e=this.downlinks[t];for(var i in e){e[i].hostDidConnect(this)}}},w.prototype.onDisconnect=function(){this.authenticated=!1,this.authentication=null,this.context.hostDidDisconnect(this);for(var t in this.downlinks){var e=this.downlinks[t];for(var i in e){e[i].hostDidDisconnect(this)}}},w.prototype.onError=function(t){this.context.hostDidFail(t,this);for(var e in this.downlinks){var i=this.downlinks[e];for(var o in i){i[o].hostDidFail(t,this)}}},w.prototype.reconnect=function(){this.reconnectTimer||(this.reconnectTimeout?this.reconnectTimeout=Math.min(Math.floor(1.8*this.reconnectTimeout),this.maxReconnectTimeout()):this.reconnectTimeout=Math.floor(500+1e3*Math.random()),this.reconnectTimer=setTimeout(this.open.bind(this),this.reconnectTimeout))},w.prototype.clearReconnect=function(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)},w.prototype.clearIdle=function(){this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null)},w.prototype.watchIdle=function(){!this.idleTimer&&this.isConnected()&&this.isIdle()&&(this.idleTimer=setTimeout(this.checkIdle.bind(this),this.idleTimeout()))},w.prototype.checkIdle=function(){this.isConnected()&&this.isIdle()&&this.close()},w.prototype.open=function(){},w.prototype.close=function(){this.context.closeHost(this)},w.prototype.closeUp=function(){for(var t in this.downlinks){var e=this.downlinks[t];for(var i in e){e[i].closeUp(this)}}},w.prototype.push=function(t){},m.prototype.keepLinked=function(){for(var t=0,e=this.views.length;t<e;t+=1)if(this.views[t].keepLinked())return!0;return!1},m.prototype.keepSynced=function(){for(var t=0,e=this.views.length;t<e;t+=1)if(this.views[t].keepSynced())return!0;return!1},m.prototype.isConnected=function(){return!(!this.host||!this.host.isConnected())},m.prototype.isAuthenticated=function(){return!(!this.host||!this.host.isAuthenticated())},m.prototype.isLinked=function(){return this.linked},m.prototype.isSynced=function(){return this.synced},m.prototype.session=function(){return this.host&&this.host.session()},m.prototype.addDownlink=function(t){this.views.push(t)},m.prototype.removeDownlink=function(t){for(var e=0;e<this.views.length;e+=1)this.views[e]===t&&(this.views.splice(e,1),t.closeUp());0===this.views.length&&this.close()},m.prototype.onEventMessage=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onEventMessage(t)},m.prototype.onCommandMessage=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onCommandMessage(t)},m.prototype.onLinkRequest=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onLinkRequest(t)},m.prototype.onLinkedResponse=function(t){this.linked=!0;for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onLinkedResponse(t)},m.prototype.onSyncRequest=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onSyncRequest(t)},m.prototype.onSyncedResponse=function(t){this.synced=!0;for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onSyncedResponse(t)},m.prototype.onUnlinkRequest=function(t){this.synced=!1,this.linked=!1;for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onUnlinkRequest(t)},m.prototype.onUnlinkedResponse=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].onUnlinkedResponse(t)},m.prototype.hostDidConnect=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].hostDidConnect();var o,n=this.host.unresolve(this.nodeUri);this.keepSynced()?(o=new d(n,this.laneUri,this.prio,this.rate,this.body),this.onSyncRequest(o)):(o=new p(n,this.laneUri,this.prio,this.rate,this.body),this.onLinkRequest(o)),this.host.push(o)},m.prototype.hostDidDisconnect=function(t){this.synced=!1,this.linked=!1;for(var e=!1,i=0,o=this.views.length;i<o;i+=1){var n=this.views[i];n.hostDidDisconnect(),e=e||n.keepLinked()}e||this.close()},m.prototype.hostDidFail=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)this.views[i].hostDidFail(t)},m.prototype.command=function(t){this.onCommandMessage(t),this.host.command(this.nodeUri,this.laneUri,t)},m.prototype.close=function(){this.context.closeDownlink(this)},m.prototype.openUp=function(t){this.host=t;for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].openUp(t)},m.prototype.closeUp=function(){var t=this.views;this.views=[];for(var e=0;e<t.length;e+=1)t[e].closeUp()},k.prototype.copy=function(t,e,i){var o,n={};for(o in this.props)n[o]=this.props[o];for(o in t)n[o]=t[o];var s={};for(o in this.options)s[o]=this.options[o];for(o in e)s[o]=e[o];var r={};for(o in this.delegate)r[o]=this.delegate[o];for(o in i)r[o]=i[o];return new this.constructor(this.context,this.scope,n,s,r)},k.prototype.host=function(t){return arguments.length?this.copy({hostUri:t}):this.props.hostUri},k.prototype.node=function(t){return arguments.length?this.copy({nodeUri:t}):this.props.nodeUri},k.prototype.lane=function(t){return arguments.length?this.copy({laneUri:t}):this.props.laneUri},k.prototype.prio=function(t){return arguments.length?this.copy({prio:t}):this.props.prio},k.prototype.rate=function(t){return arguments.length?this.copy({rate:t}):this.props.rate},k.prototype.body=function(t){return arguments.length?this.copy({body:t}):this.props.body},k.prototype.keepLinked=function(t){return arguments.length?(this.options.keepLinked=t,this):void 0===this.options.keepLinked||this.options.keepLinked},k.prototype.keepSynced=function(t){return arguments.length?(this.options.keepSynced=t,this):void 0===this.options.keepSynced||this.options.keepSynced},k.prototype.onEvent=function(t){return arguments.length?(this.delegate.onEvent=t,this):this.delegate.onEvent},k.prototype.onCommand=function(t){return arguments.length?(this.delegate.onCommand=t,this):this.delegate.onCommand},k.prototype.willLink=function(t){return arguments.length?(this.delegate.willLink=t,this):this.delegate.willLink},k.prototype.didLink=function(t){return arguments.length?(this.delegate.didLink=t,this):this.delegate.didLink},k.prototype.willSync=function(t){return arguments.length?(this.delegate.willSync=t,this):this.delegate.willSync},k.prototype.didSync=function(t){return arguments.length?(this.delegate.didSync=t,this):this.delegate.didSync},k.prototype.willUnlink=function(t){return arguments.length?(this.delegate.willUnlink=t,this):this.delegate.willUnlink},k.prototype.didUnlink=function(t){return arguments.length?(this.delegate.didUnlink=t,this):this.delegate.didUnlink},k.prototype.didConnect=function(t){return arguments.length?(this.delegate.didConnect=t,this):this.delegate.didConnect},k.prototype.didDisconnect=function(t){return arguments.length?(this.delegate.didDisconnect=t,this):this.delegate.didDisconnect},k.prototype.didClose=function(t){return arguments.length?(this.delegate.didClose=t,this):this.delegate.didClose},k.prototype.didFail=function(t){return arguments.length?(this.delegate.didFail=t,this):this.delegate.didFail},k.prototype.isConnected=function(){return!(!this.model||!this.model.isConnected())},k.prototype.isAuthenticated=function(){return!(!this.model||!this.model.isAuthenticated())},k.prototype.isLinked=function(){return!(!this.model||!this.model.isLinked())},k.prototype.isSynced=function(){return!(!this.model||!this.model.isSynced())},k.prototype.session=function(){return this.model&&this.model.session()},k.prototype.onEventMessage=function(t){this.delegate&&"function"==typeof this.delegate.onEvent&&this.delegate.onEvent(t.body,this)},k.prototype.onCommandMessage=function(t){this.delegate&&"function"==typeof this.delegate.onCommand&&this.delegate.onCommand(t,this)},k.prototype.onLinkRequest=function(){this.delegate&&"function"==typeof this.delegate.willLink&&this.delegate.willLink(this)},k.prototype.onLinkedResponse=function(t){this.delegate&&"function"==typeof this.delegate.didLink&&this.delegate.didLink(this)},k.prototype.onSyncRequest=function(){this.delegate&&"function"==typeof this.delegate.willSync&&this.delegate.willSync(this)},k.prototype.onSyncedResponse=function(t){this.delegate&&"function"==typeof this.delegate.didSync&&this.delegate.didSync(this)},k.prototype.onUnlinkRequest=function(){this.delegate&&"function"==typeof this.delegate.willUnlink&&this.delegate.willUnlink(this)},k.prototype.onUnlinkedResponse=function(t){this.delegate&&"function"==typeof this.delegate.didUnlink&&this.delegate.didUnlink(this)},k.prototype.hostDidConnect=function(){this.delegate&&"function"==typeof this.delegate.didConnect&&this.delegate.didConnect(this)},k.prototype.hostDidDisconnect=function(){this.delegate&&"function"==typeof this.delegate.didDisconnect&&this.delegate.didDisconnect(this)},k.prototype.hostDidFail=function(){this.delegate&&"function"==typeof this.delegate.didFail&&this.delegate.didFail(this)},k.prototype.command=function(t){this.model.command(t)},k.prototype.open=function(){},k.prototype.close=function(){this.scope&&this.scope.removeDownlink(this),this.model&&this.model.removeDownlink(this)};k.prototype.openUp=function(t){},k.prototype.closeUp=function(){this.delegate&&"function"==typeof this.delegate.didClose&&this.delegate.didClose(this)},U.prototype=Object.create(m.prototype),U.prototype.constructor=U,D.prototype=Object.create(k.prototype),D.prototype.constructor=D,D.prototype.keepSynced=function(t){return arguments.length?(this.options.keepSynced=t,this):void 0!==this.options.keepSynced&&this.options.keepSynced},D.prototype.open=function(){var t=this.props,e=this.context.getDownlink(t.hostUri,t.nodeUri,t.laneUri);if(e){if(!(e instanceof U))throw"downlink type mismatch";e.addDownlink(this)}else e=new U(this.context,t.hostUri,t.nodeUri,t.laneUri,t.prio,t.rate,t.body),e.addDownlink(this),this.context.openDownlink(e);return this.model=e,this.scope&&this.scope.addDownlink(this),this},b.prototype=Object.create(m.prototype),b.prototype.constructor=b,Object.defineProperty(b.prototype,"length",{get:function(){return this.state.length},configurable:!0,enumerable:!0}),b.prototype.get=function(t){return this.state[t]},b.prototype.set=function(t,i){if(!R(t))throw new TypeError("index");if(t<0&&(t=this.state.length+t),t>=0&&t<this.state.length){i=this.listWillUpdate(t,i);var o=this.refs[t],n=this.state[t];this.state[t]=i,this.listDidUpdate(t,i,n),this.command(e.concat({"@update":{id:o.id,index:t}},i))}else t=Math.max(0,t),this.insert(t,i);return this},b.prototype.insert=function(t,i){if(!R(t))throw new TypeError("start");t<0&&(t=this.state.length+t),t=Math.min(Math.max(0,t),this.state.length);for(var o=1,n=arguments.length;o<n;o+=1){var s=t+o-1,r=arguments[o];r=this.listWillInsert(s,r);var h=this.makeRef(r);this.refs.splice(s,0,h),this.state.splice(s,0,r),this.listDidInsert(s,r),this.command(e.concat({"@insert":{id:h.id,index:s}},r))}return this},b.prototype.push=function(t){for(var i=0,o=arguments.length;i<o;i+=1){var n=this.state.length,s=arguments[i];s=this.listWillInsert(n,s);var r=this.makeRef(s);this.refs.push(r),this.state.push(s),this.listDidInsert(n,s),this.command(e.concat({"@insert":{id:r.id,index:n}},s))}return this.state.length},b.prototype.pop=function(){var t=this.state.length-1;if(!(t<0)){this.listWillRemove(t);var e=this.refs.pop(),i=this.state.pop();return this.listDidRemove(t,i),this.command({"@remove":{id:e.id,index:t}}),i}},b.prototype.unshift=function(t){for(var i=arguments.length-1;i>=0;i-=1){var o=arguments[i];o=this.listWillInsert(0,o);var n=this.makeRef(o);this.refs.unshift(n),this.state.unshift(o),this.listDidInsert(0,o),this.command(e.concat({"@insert":{id:n.id,index:0}},o))}return this.state.length},b.prototype.shift=function(){if(0!==this.state.length){this.listWillRemove(0);var t=this.refs.shift(),e=this.state.shift();return this.listDidRemove(0,e),this.command({"@remove":{id:t.id,index:0}}),e}},b.prototype.move=function(t,e){if(t<0||t>=this.state.length)throw new RangeError("fromIndex");if(e<0||e>=this.state.length)throw new RangeError("toIndex");if(t===e)return this;var i=this.refs[t],o=this.state[t];return this.listWillMove(t,e,o),this.refs.splice(t,1),this.state.splice(t,1),this.refs.splice(e,0,i),this.state.splice(e,0,o),this.listDidMove(t,e,o),this.command({"@move":{id:i.id,from:t,to:e}}),this},b.prototype.splice=function(t){var i=arguments[0];if(!R(i))throw new TypeError("start");i<0&&(i=this.state.length+i),i=Math.min(Math.max(0,i),this.state.length);var o;if(arguments.length>1){if(o=arguments[1],!R(o))throw new TypeError("deleteCount")}else o=this.state.length-i;var n,s,r,h=[];for(n=i,s=i+o;n<s;n+=1){this.listWillRemove(i),r=this.refs[i];var p=this.state[i];h.push(p),this.refs.splice(i,1),this.state.splice(i,1),this.listDidRemove(i,p),this.command({"@remove":{id:r.id,index:i}})}for(n=2,s=arguments.length;n<s;n+=1){var l=i+n-2,d=arguments[n];d=this.listWillInsert(l,d),r=this.makeRef(d),this.refs.splice(l,0,r),this.state.splice(l,0,d),this.listDidInsert(l,d),this.command(e.concat({"@insert":{id:r.id,index:l}},d))}return h},b.prototype.clear=function(){this.listWillClear(),this.refs.length=0,this.state.length=0,this.listDidClear(),this.command({"@clear":null})},b.prototype.forEach=function(t,e){for(var i=0,o=this.state.length;i<o;i+=1)t.call(e,this.state[i],i,this)},b.prototype.makeRef=function(t){var e=16777215*Math.random()|0,i=new Uint8Array(3);return i[0]=e>>16&255,i[1]=e>>8&255,i[2]=255&e,{id:i}},b.prototype.getRef=function(t){return this.refs[t]},b.prototype.setRefs=function(t){this.refs=t},b.prototype.setState=function(t){this.state=t},b.prototype.onEventMessage=function(t){m.prototype.onEventMessage.call(this,t);var i,o,n=t.body,s=e.tag(n);"@update"===s?(i=n[s],o=this.resolveIndex(i.id,i.index),o>=0?this.onUpdateEvent(i.id,o,e.body(n)):this.onInsertEvent(i.id,i.index,e.body(n))):"@insert"===s?(i=n[s],o=this.resolveIndex(i.id,i.index),o<0?this.onInsertEvent(i.id,i.index,e.body(n)):this.onUpdateEvent(i.id,o,e.body(n))):"@move"===s?(i=n[s],(o=this.resolveIndex(i.id,i.from))>=0&&this.onMoveEvent(i.id,o,i.to)):"@remove"===s?(i=n[s],(o=this.resolveIndex(i.id,i.index))>=0&&this.onRemoveEvent(i.id,o)):"@clear"===s&&this.onClearEvent()},b.prototype.onUpdateEvent=function(t,e,i){i=this.listWillUpdate(e,i);var o=this.state[e];this.state[e]=i,this.listDidUpdate(e,i,o)},b.prototype.onInsertEvent=function(t,e,i){i=this.listWillInsert(e,i);var o={id:t};this.refs.splice(e,0,o),this.state.splice(e,0,i),this.listDidInsert(e,i)},b.prototype.onMoveEvent=function(t,e,i){if(i=Math.min(Math.max(0,i),this.state.length),e!==i){var o=this.refs[e],n=this.state[e];this.listWillMove(e,i,n),this.refs.splice(e,1),this.state.splice(e,1),this.refs.splice(i,0,o),this.state.splice(i,0,n),this.listDidMove(e,i,n)}},b.prototype.onRemoveEvent=function(t,e){this.listWillRemove(e);var i=this.state[e];this.refs.splice(e,1),this.state.splice(e,1),this.listDidRemove(e,i)},b.prototype.onClearEvent=function(){this.listWillClear(),this.refs.length=0,this.state.length=0,this.listDidClear()},b.prototype.listWillInsert=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)e=this.views[i].listWillInsert(t,e);return e},b.prototype.listDidInsert=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)this.views[i].listDidInsert(t,e)},b.prototype.listWillUpdate=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)e=this.views[i].listWillUpdate(t,e);return e},b.prototype.listDidUpdate=function(t,e,i){for(var o=0,n=this.views.length;o<n;o+=1)this.views[o].listDidUpdate(t,e,i)},b.prototype.listWillMove=function(t,e,i){for(var o=0,n=this.views.length;o<n;o+=1)this.views[o].listWillMove(t,e,i)},b.prototype.listDidMove=function(t,e,i){for(var o=0,n=this.views.length;o<n;o+=1)this.views[o].listDidMove(t,e,i)},b.prototype.listWillRemove=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].listWillRemove(t)},b.prototype.listDidRemove=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)this.views[i].listDidRemove(t,e)},b.prototype.listWillClear=function(){for(var t=0,e=this.views.length;t<e;t+=1)this.views[t].listWillClear()},b.prototype.listDidClear=function(){for(var t=0,e=this.views.length;t<e;t+=1)this.views[t].listDidClear()},b.prototype.resolveIndex=function(t,i){var o=this.refs[i];if(o&&e.equal(o.id,t))return i;for(var n=0,s=this.refs.length;n<s;n+=1)if((o=this.refs[n])&&e.equal(o.id,t))return n;return-1},C.prototype=Object.create(k.prototype),C.prototype.constructor=C,C.prototype.getRef=function(t){return this.model.getRef(t)},Object.defineProperty(C.prototype,"state",{get:function(){return this.model.state},configurable:!0,enumerable:!0}),Object.defineProperty(C.prototype,"length",{get:function(){return this.model.length},configurable:!0,enumerable:!0}),C.prototype.get=function(t){return this.model.get(t)},C.prototype.set=function(t,e){return this.model.set(t,e),this},C.prototype.push=function(t){return this.model.push.apply(this.model,arguments)},C.prototype.pop=function(){return this.model.pop()},C.prototype.unshift=function(t){return this.model.unshift.apply(this.model,arguments)},C.prototype.shift=function(){return this.model.shift()},C.prototype.move=function(t,e){return this.model.move(t,e),this},C.prototype.splice=function(t){return this.model.splice.apply(this.model,arguments)},C.prototype.clear=function(){this.model.clear()},C.prototype.forEach=function(t,e){for(var i=this.model.state,o=0,n=i.length;o<n;o+=1)t.call(e,i[o],o,this)},C.prototype.willInsert=function(t){return arguments.length?(this.delegate.willInsert=t,this):this.delegate.willInsert},C.prototype.didInsert=function(t){return arguments.length?(this.delegate.didInsert=t,this):this.delegate.didInsert},C.prototype.willUpdate=function(t){return arguments.length?(this.delegate.willUpdate=t,this):this.delegate.willUpdate},C.prototype.didUpdate=function(t){return arguments.length?(this.delegate.didUpdate=t,this):this.delegate.didUpdate},C.prototype.willMove=function(t){return arguments.length?(this.delegate.willMove=t,this):this.delegate.willMove},C.prototype.didMove=function(t){ | ||
return arguments.length?(this.delegate.didMove=t,this):this.delegate.didMove},C.prototype.willRemove=function(t){return arguments.length?(this.delegate.willRemove=t,this):this.delegate.willRemove},C.prototype.didRemove=function(t){return arguments.length?(this.delegate.didRemove=t,this):this.delegate.didRemove},C.prototype.willClear=function(t){return arguments.length?(this.delegate.willClear=t,this):this.delegate.willClear},C.prototype.didClear=function(t){return arguments.length?(this.delegate.didClear=t,this):this.delegate.didClear},C.prototype.listWillInsert=function(t,e){if(this.delegate&&"function"==typeof this.delegate.willInsert){var i=this.delegate.willInsert(t,e,this);void 0!==i&&(e=i)}return e},C.prototype.listDidInsert=function(t,e){this.delegate&&"function"==typeof this.delegate.didInsert&&this.delegate.didInsert(t,e,this)},C.prototype.listWillUpdate=function(t,e){if(this.delegate&&"function"==typeof this.delegate.willUpdate){var i=this.delegate.willUpdate(t,e,this);void 0!==i&&(e=i)}return e},C.prototype.listDidUpdate=function(t,e,i){this.delegate&&"function"==typeof this.delegate.didUpdate&&this.delegate.didUpdate(t,e,i,this)},C.prototype.listWillMove=function(t,e,i){this.delegate&&"function"==typeof this.delegate.willMove&&this.delegate.willMove(t,e,i,this)},C.prototype.listDidMove=function(t,e,i){this.delegate&&"function"==typeof this.delegate.didMove&&this.delegate.didMove(t,e,i,this)},C.prototype.listWillRemove=function(t){this.delegate&&"function"==typeof this.delegate.willRemove&&this.delegate.willRemove(t,this)},C.prototype.listDidRemove=function(t,e){this.delegate&&"function"==typeof this.delegate.didRemove&&this.delegate.didRemove(t,e,this)},C.prototype.listWillClear=function(){this.delegate&&"function"==typeof this.delegate.willClear&&this.delegate.willClear(this)},C.prototype.listDidClear=function(){this.delegate&&"function"==typeof this.delegate.didClear&&this.delegate.didClear(this)},C.prototype.makeRef=function(t){return arguments.length?(this.options.makeRef=t,this):this.options.makeRef},C.prototype.initialRefs=function(t){return arguments.length?(this.options.initialRefs=t,this):this.options.initialRefs},C.prototype.initialState=function(t){return arguments.length?(this.options.initialState=t,this):this.options.initialState},C.prototype.didAliasModel=function(){this.forEach(function(t,e){this.listDidInsert(e,t)},this)},C.prototype.open=function(){var t=this.props,e=this.context.getDownlink(t.hostUri,t.nodeUri,t.laneUri);if(e){if(!(e instanceof b))throw"downlink type mismatch";e.addDownlink(this),this.model=e,this.didAliasModel()}else e=new b(this.context,t.hostUri,t.nodeUri,t.laneUri,t.prio,t.rate,t.body,this.options.initialRefs,this.options.initialState,this.options.makeRef),e.addDownlink(this),this.context.openDownlink(e),this.model=e;return this.scope&&this.scope.addDownlink(this),this},S.prototype=Object.create(m.prototype),S.prototype.constructor=S,Object.defineProperty(S.prototype,"size",{get:function(){return e.length(this.state)},configurable:!0,enumerable:!0}),S.prototype.has=function(t){return e.has(this.state,t)},S.prototype.get=function(t){return e.get(this.state,t)},S.prototype.set=function(t,i){i=this.mapWillUpdate(t,i);var o=this.state,n=e.get(o,t),s=e.set(o,t,i);return this.setState(s),this.mapDidUpdate(t,i,n),this.command(e.concat({"@update":{key:t}},i)),this},S.prototype.delete=function(t){this.mapWillRemove(t);var i=this.state,o=e.get(i,t),n=e.remove(i,t);return this.setState(n),this.mapDidRemove(t,o),void 0!==o&&(this.command({"@remove":{key:t}}),!0)},S.prototype.clear=function(){this.mapWillClear(),this.setState({}),this.mapDidClear(),this.command({"@clear":null})},S.prototype.keys=function(){return e.keys(this.state)},S.prototype.values=function(){return e.values(this.state)},S.prototype.forEach=function(t,i){e.forEach(this.state,t,i)},S.prototype.setState=function(t){this.state=t},S.prototype.onEventMessage=function(t){m.prototype.onEventMessage.call(this,t);var i,o=t.body,n=e.tag(o);"@update"===n?(i=o[n],this.onUpdateEvent(i.key,e.body(o))):"@remove"===n?(i=o[n],this.onRemoveEvent(i.key)):"@clear"===n&&this.onClearEvent()},S.prototype.onUpdateEvent=function(t,i){i=this.mapWillUpdate(t,i);var o=this.state,n=e.get(o,t),s=e.set(o,t,i);this.setState(s),this.mapDidUpdate(t,i,n)},S.prototype.onRemoveEvent=function(t){this.mapWillRemove(t);var i=this.state,o=e.get(i,t),n=e.remove(i,t);this.setState(n),this.mapDidRemove(t,o)},S.prototype.onClearEvent=function(){this.mapWillClear(),this.setState({}),this.mapDidClear()},S.prototype.mapWillUpdate=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)e=this.views[i].mapWillUpdate(t,e);return e},S.prototype.mapDidUpdate=function(t,e,i){for(var o=0,n=this.views.length;o<n;o+=1)this.views[o].mapDidUpdate(t,e,i)},S.prototype.mapWillRemove=function(t){for(var e=0,i=this.views.length;e<i;e+=1)this.views[e].mapWillRemove(t)},S.prototype.mapDidRemove=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)this.views[i].mapDidRemove(t,e)},S.prototype.mapWillClear=function(){for(var t=0,e=this.views.length;t<e;t+=1)this.views[t].mapWillClear()},S.prototype.mapDidClear=function(){for(var t=0,e=this.views.length;t<e;t+=1)this.views[t].mapDidClear()},E.prototype=Object.create(k.prototype),E.prototype.constructor=E,Object.defineProperty(E.prototype,"state",{get:function(){return this.model.state},configurable:!0,enumerable:!0}),Object.defineProperty(E.prototype,"size",{get:function(){return this.model.size},configurable:!0,enumerable:!0}),E.prototype.has=function(t){return this.model.has(t)},E.prototype.get=function(t){return this.model.get(t)},E.prototype.set=function(t,e){return this.model.set(t,e),this},E.prototype.delete=function(t){return this.model.delete(t)},E.prototype.clear=function(){this.model.clear()},E.prototype.keys=function(){return this.model.keys()},E.prototype.values=function(){return this.model.values()},E.prototype.forEach=function(t,e){this.model.forEach(t,e)},E.prototype.willUpdate=function(t){return arguments.length?(this.delegate.willUpdate=t,this):this.delegate.willUpdate},E.prototype.didUpdate=function(t){return arguments.length?(this.delegate.didUpdate=t,this):this.delegate.didUpdate},E.prototype.willRemove=function(t){return arguments.length?(this.delegate.willRemove=t,this):this.delegate.willRemove},E.prototype.didRemove=function(t){return arguments.length?(this.delegate.didRemove=t,this):this.delegate.didRemove},E.prototype.willClear=function(t){return arguments.length?(this.delegate.willClear=t,this):this.delegate.willClear},E.prototype.didClear=function(t){return arguments.length?(this.delegate.didClear=t,this):this.delegate.didClear},E.prototype.mapWillUpdate=function(t,e){if(this.delegate&&"function"==typeof this.delegate.willUpdate){var i=this.delegate.willUpdate(t,e,this);void 0!==i&&(e=i)}return e},E.prototype.mapDidUpdate=function(t,e,i){this.delegate&&"function"==typeof this.delegate.didUpdate&&this.delegate.didUpdate(t,e,i,this)},E.prototype.mapWillRemove=function(t){this.delegate&&"function"==typeof this.delegate.willRemove&&this.delegate.willRemove(t,this)},E.prototype.mapDidRemove=function(t,e){this.delegate&&"function"==typeof this.delegate.didRemove&&this.delegate.didRemove(t,e,this)},E.prototype.mapWillClear=function(){this.delegate&&"function"==typeof this.delegate.willClear&&this.delegate.willClear(this)},E.prototype.mapDidClear=function(){this.delegate&&"function"==typeof this.delegate.didClear&&this.delegate.didClear(this)},E.prototype.initialState=function(t){return arguments.length?(this.options.initialState=t,this):this.options.initialState},E.prototype.didAliasModel=function(){this.forEach(function(t,e){this.mapDidUpdate(t,e,void 0)},this)},E.prototype.open=function(){var t=this.props,e=this.context.getDownlink(t.hostUri,t.nodeUri,t.laneUri);if(e){if(!(e instanceof S))throw"downlink type mismatch";e.addDownlink(this),this.model=e,this.didAliasModel()}else e=new S(this.context,t.hostUri,t.nodeUri,t.laneUri,t.prio,t.rate,t.body,this.options.initialState),e.addDownlink(this),this.context.openDownlink(e),this.model=e;return this.scope&&this.scope.addDownlink(this),this},x.prototype=Object.create(m.prototype),x.prototype.constructor=x,x.prototype.get=function(){return this.state},x.prototype.set=function(t){t=this.valueWillSet(t);var e=this.state;this.setState(t),this.valueDidSet(t,e),this.command(t)},x.prototype.setState=function(t){this.state=t},x.prototype.onEventMessage=function(t){m.prototype.onEventMessage.call(this,t),this.onSetEvent(t.body)},x.prototype.onSetEvent=function(t){t=this.valueWillSet(t);var e=this.state;this.setState(t),this.valueDidSet(t,e)},x.prototype.valueWillSet=function(t){for(var e=0,i=this.views.length;e<i;e+=1)t=this.views[e].valueWillSet(t);return t},x.prototype.valueDidSet=function(t,e){for(var i=0,o=this.views.length;i<o;i+=1)this.views[i].valueDidSet(t,e)},M.prototype=Object.create(k.prototype),M.prototype.constructor=M,M.prototype.get=function(){return this.model.get()},M.prototype.set=function(t){this.model.set(t)},M.prototype.setState=function(t){this.model.setState(t)},M.prototype.willSet=function(t){return arguments.length?(this.delegate.willSet=t,this):this.delegate.willSet},M.prototype.didSet=function(t){return arguments.length?(this.delegate.didSet=t,this):this.delegate.didSet},M.prototype.valueWillSet=function(t){if(this.delegate&&"function"==typeof this.delegate.willSet){var e=this.delegate.willSet(t,this);void 0!==e&&(t=e)}return t},M.prototype.valueDidSet=function(t,e){this.delegate&&"function"==typeof this.delegate.didSet&&this.delegate.didSet(t,e,this)},M.prototype.initialState=function(t){return arguments.length?(this.options.initialState=t,this):this.options.initialState},M.prototype.didAliasModel=function(){this.valueDidSet(this.get(),void 0)},M.prototype.open=function(){var t=this.props,e=this.context.getDownlink(t.hostUri,t.nodeUri,t.laneUri);if(e){if(!(e instanceof x))throw"downlink type mismatch";e.addDownlink(this),this.model=e,this.didAliasModel()}else e=new x(this.context,t.hostUri,t.nodeUri,t.laneUri,t.prio,t.rate,t.body,this.options.initialState),e.addDownlink(this),this.context.openDownlink(e),this.model=e;return this.scope&&this.scope.addDownlink(this),this},O.prototype.isConnected=function(){return!(!this.host||!this.host.isConnected())},O.prototype.isAuthenticated=function(){return!(!this.host||!this.host.isAuthenticated())},O.prototype.session=function(){return this.host&&this.host.session()},O.prototype.addDownlink=function(t){var e=t.host(),i=t.node(),o=t.lane();0===this.downlinkCount&&this.open();var n=this.downlinks[e];n||(n={},this.downlinks[e]=n);var s=n[i];s||(s={},n[i]=s);var r=s[o];r||(r=[],s[o]=r),r.push(t),this.downlinkCount+=1},O.prototype.removeDownlink=function(t){var e=t.host(),i=t.node(),o=t.lane(),n=this.downlinks[e];if(n){var s=n[i];if(s){var r=s[o];if(r)for(var h=0;h<r.length;h+=1)if(r[h]===t){this.downlinkCount-=1,r.splice(h,1),0===r.length&&(delete s[o],0===Object.keys(s).length&&(delete n[i],0===Object.keys(n).length&&delete this.downlinks[e])),0===this.downlinkCount&&this.close();break}}}},O.prototype.downlink=function(){},O.prototype.downlinkList=function(){},O.prototype.downlinkMap=function(){},O.prototype.downlinkValue=function(){},O.prototype.authenticate=function(t){},O.prototype.hostDidConnect=function(t){this.host=t,this.delegate&&"function"==typeof this.delegate.didConnect&&this.delegate.didConnect()},O.prototype.hostDidAuthenticate=function(t,e){this.delegate&&"function"==typeof this.delegate.didAuthenticate&&this.delegate.didAuthenticate(t.body)},O.prototype.hostDidDeauthenticate=function(t,e){this.delegate&&"function"==typeof this.delegate.didDeauthenticate&&this.delegate.didDeauthenticate(t.body)},O.prototype.hostDidDisconnect=function(t){this.host=null,this.delegate&&"function"==typeof this.delegate.didDisconnect&&this.delegate.didDisconnect()},O.prototype.hostDidFail=function(t,e){this.delegate&&"function"==typeof this.delegate.didFail&&this.delegate.didFail(t)},O.prototype.open=function(){this.context.openScope(this)},O.prototype.close=function(){this.context.closeScope(this)},O.prototype.closeUp=function(){this.downlinkCount=0;var t=this.downlinks;this.downlinks={};for(var e in t){var i=t[e];for(var o in i){var n=i[o];for(var s in n)for(var r=n[s],h=0;h<r.length;h+=1)r[h].close()}}},W.prototype=Object.create(O.prototype),W.prototype.constructor=W,W.prototype.host=function(){return this.hostUri},W.prototype.node=function(t){return new I(this.context,this.hostUri,e.Uri.resolveUri(this.hostUri,t))},W.prototype.lane=function(t,i){return new L(this.context,this.hostUri,e.Uri.resolveUri(this.hostUri,t),i)},W.prototype.downlink=function(){return new D(this.context,this,this.props)},W.prototype.downlinkList=function(){return new C(this.context,this,this.props)},W.prototype.downlinkMap=function(){return new E(this.context,this,this.props)},W.prototype.downlinkValue=function(){return new M(this.context,this,this.props)},W.prototype.command=function(t,i,o){this.context.command(e.Uri.resolveUri(this.hostUri,t),i,o)},W.prototype.authenticate=function(t){this.context.authenticate(this.hostUri,t)},I.prototype=Object.create(O.prototype),I.prototype.constructor=I,I.prototype.host=function(){return this.hostUri},I.prototype.node=function(){return this.nodeUri},I.prototype.lane=function(t){return new L(this.context,this.hostUri,this.nodeUri,t)},I.prototype.downlink=function(){return new D(this.context,this,this.props)},I.prototype.downlinkList=function(){return new C(this.context,this,this.props)},I.prototype.downlinkMap=function(){return new E(this.context,this,this.props)},I.prototype.downlinkValue=function(){return new M(this.context,this,this.props)},I.prototype.command=function(t,e){this.context.command(this.nodeUri,t,e)},I.prototype.authenticate=function(t){this.context.authenticate(this.hostUri,t)},L.prototype=Object.create(O.prototype),L.prototype.constructor=L,L.prototype.host=function(){return this.hostUri},L.prototype.node=function(){return this.nodeUri},L.prototype.lane=function(){return this.laneUri},L.prototype.downlink=function(){return new D(this.context,this,this.props)},L.prototype.downlinkList=function(){return new C(this.context,this,this.props)};L.prototype.downlinkMap=function(){return new E(this.context,this,this.props)},L.prototype.downlinkValue=function(){return new M(this.context,this,this.props)},L.prototype.command=function(t){this.context.command(this.nodeUri,this.laneUri,t)},L.prototype.authenticate=function(t){this.context.authenticate(this.hostUri,t)},A.prototype=Object.create(w.prototype),A.prototype.constructor=A,A.prototype.WebSocket=function(){return this.options.WebSocket||"undefined"!=typeof WebSocket&&WebSocket||"function"==typeof require&&require("ws")},A.prototype.isConnected=function(){return!(!this.socket||this.socket.readyState!==this.socket.OPEN)},A.prototype.open=function(){if(this.clearReconnect(),!this.socket){var t=this.WebSocket();this.options.protocols?this.socket=new t(this.hostUri,this.options.protocols):this.socket=new t(this.hostUri),this.socket.onopen=this.onWebSocketOpen.bind(this),this.socket.onmessage=this.onWebSocketMessage.bind(this),this.socket.onclose=this.onWebSocketClose.bind(this),this.socket.onerror=this.onWebSocketError.bind(this)}},A.prototype.close=function(){this.clearReconnect(),this.clearIdle(),this.socket?(this.socket.close(),this.context.online||this.onWebSocketClose()):w.prototype.close.call(this)},A.prototype.push=function(t){if(this.isConnected()){this.clearIdle();var e=t.toRecon();this.socket.send(e),this.watchIdle()}else if(t instanceof h){if(!(this.sendBuffer.length<this.sendBufferSize()))throw"send buffer overflow";this.sendBuffer.push(t),this.open()}},A.prototype.onWebSocketOpen=function(){if(this.isConnected()){var t=this.credentials();if(t){var e=new f(t);this.push(e)}this.onConnect();for(var i;(i=this.sendBuffer.shift())&&this.isConnected();)this.push(i);this.watchIdle()}else this.close()},A.prototype.onWebSocketMessage=function(t){var e=t.data;if("string"==typeof e){var o=i.parse(e);o?this.onEnvelope(o):this.onUnknownEnvelope(e)}},A.prototype.onWebSocketClose=function(){this.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onclose=null,this.socket.onerror=null,this.socket=null),this.onDisconnect(),this.clearIdle(),this.isIdle()?this.close():this.context.online&&this.reconnect()},A.prototype.onWebSocketError=function(){this.onError(),this.socket&&this.socket.close()},q.prototype.isOnline=function(t){if(!arguments.length)return this.online;if(this.online!==t){this.online=t;for(var e in this.hosts){var i=this.hosts[e];t?i.open():i.close()}}return this},q.prototype.keepOnline=function(t){return arguments.length?(this.options.keepOnline!==t&&(this.options.keepOnline=t,this.watchOnline(t)),this):void 0===this.options.keepOnline||this.options.keepOnline},q.prototype.watchOnline=function(t){"object"==typeof window&&(t?(window.addEventListener("online",this.onOnline,!1),window.addEventListener("offline",this.onOffline,!1)):(window.removeEventListener("online",this.onOnline,!1),window.removeEventListener("offline",this.onOffline,!1)))},q.prototype.onOnline=function(t){this.isOnline(!0)},q.prototype.onOffline=function(t){this.isOnline(!1)},q.prototype.openScope=function(t){this.scopes.push(t)},q.prototype.closeScope=function(t){for(var e=0;e<this.scopes.length;e+=1)if(this.scopes[e]===t){this.scopes.splice(e,1),t.closeUp();break}},q.prototype.getHost=function(t){return this.hosts[t]},q.prototype.openHost=function(t){var e=this.hosts[t];return e||(e=new A(this,t,this.options),this.hosts[t]=e),e},q.prototype.closeHost=function(t){this.hosts[t.hostUri]&&(delete this.hosts[t.hostUri],t.closeUp())},q.prototype.getDownlink=function(t,e,i){var o=this.downlinks[t];if(o){var n=o[e];if(n)return n[i]}return null},q.prototype.openDownlink=function(t){var e=t.hostUri,i=t.nodeUri,o=t.laneUri,n=this.downlinks[e];n||(n={},this.downlinks[e]=n);var s=n[i];if(s||(s={},n[i]=s),s[o])throw"duplicate downlink";s[o]=t,this.downlinkCount+=1,this.openHost(e).openDownlink(t)},q.prototype.closeDownlink=function(t){var e=t.hostUri,i=t.nodeUri,o=t.laneUri,n=this.downlinks[e];if(n){var s=n[i];if(s&&s[o]){this.downlinkCount-=1,delete s[o],0===Object.keys(s).length&&(delete n[i],0===Object.keys(n).length&&delete this.downlinks[e]);var r=this.getHost(e);r&&r.closeDownlink(t)}}},q.prototype.host=function(t){return new W(this,t)},q.prototype.node=function(t,i){var o,n;return 1===arguments.length?(n=arguments[0],o=e.Uri.getHostUri(n)):(o=arguments[0],n=e.Uri.resolveUri(o,arguments[1])),new I(this,o,n)},q.prototype.lane=function(t,i,o){var n,s,r;return 2===arguments.length?(r=arguments[1],s=arguments[0],n=e.Uri.getHostUri(s)):(n=arguments[0],s=e.Uri.resolveUri(n,arguments[1]),r=arguments[2]),new L(this,n,s,r)},q.prototype.downlink=function(){return new D(this)},q.prototype.downlinkList=function(){return new C(this)},q.prototype.downlinkMap=function(){return new E(this)},q.prototype.downlinkValue=function(){return new M(this)},q.prototype.command=function(t,i,o,n){var s,r,h,p;3===arguments.length?(p=arguments[2],h=arguments[1],r=arguments[0],s=e.Uri.getHostUri(r)):(s=arguments[0],r=e.Uri.resolveUri(s,arguments[1]),h=arguments[2],p=arguments[3]),this.openHost(s).command(r,h,p)},q.prototype.authenticate=function(t,e){this.openHost(t).authenticate(e)},q.prototype.didAuthenticate=function(t){return arguments.length?(this.delegate.didAuthenticate=t,this):this.delegate.didAuthenticate},q.prototype.didDeauthenticate=function(t){return arguments.length?(this.delegate.didDeauthenticate=t,this):this.delegate.didDeauthenticate},q.prototype.didConnect=function(t){return arguments.length?(this.delegate.didConnect=t,this):this.delegate.didConnect},q.prototype.didDisconnect=function(t){return arguments.length?(this.delegate.didDisconnect=t,this):this.delegate.didDisconnect},q.prototype.didFail=function(t){return arguments.length?(this.delegate.didFail=t,this):this.delegate.didFail},q.prototype.hostDidAuthenticate=function(t,e){this.delegate&&"function"==typeof this.delegate.didAuthenticate&&this.delegate.didAuthenticate(t.body,e);for(var i=0,o=this.scopes.length;i<o;i+=1){var n=this.scopes[i];n.hostUri===e.hostUri&&n.hostDidAuthenticate(t,e)}},q.prototype.hostDidDeauthenticate=function(t,e){this.delegate&&"function"==typeof this.delegate.didDeauthenticate&&this.delegate.didDeauthenticate(t.body,e);for(var i=0,o=this.scopes.length;i<o;i+=1){var n=this.scopes[i];n.hostUri===e.hostUri&&n.hostDidDeauthenticate(t,e)}},q.prototype.hostDidConnect=function(t){this.delegate&&"function"==typeof this.delegate.didConnect&&this.delegate.didConnect(t);for(var e=0,i=this.scopes.length;e<i;e+=1){var o=this.scopes[e];o.hostUri===t.hostUri&&o.hostDidConnect(t)}},q.prototype.hostDidDisconnect=function(t){this.delegate&&"function"==typeof this.delegate.didDisconnect&&this.delegate.didDisconnect(t);for(var e=0,i=this.scopes.length;e<i;e+=1){var o=this.scopes[e];o.hostUri===t.hostUri&&o.hostDidDisconnect(t)}},q.prototype.hostDidFail=function(t,e){this.delegate&&"function"==typeof this.delegate.didFail&&this.delegate.didFail(t,e);for(var i=0,o=this.scopes.length;i<o;i+=1){var n=this.scopes[i];n.hostUri===e.hostUri&&n.hostDidFail(t,e)}},q.prototype.close=function(){var t,e=this.scopes;this.scopes=[];for(var i=0;i<e.length;i+=1)e[i].closeUp();this.downlinkCount=0;var o=this.downlinks;this.downlinks={};for(t in o){var n=o[t];for(var s in n){var r=n[s];for(var h in r)r[h].closeUp()}}var p=this.hosts;this.hosts={};for(t in p)p[t].closeUp()};var J=i.decode,K=i.parse,Q=new q;t.decodeEnvelope=J,t.parseEnvelope=K,t.client=Q,t.isOnline=j,t.keepOnline=T,t.host=F,t.node=H,t.lane=V,t.downlink=B,t.downlinkList=P,t.downlinkMap=z,t.downlinkValue=N,t.command=_,t.authenticate=G,t.Envelope=i,t.RequestEnvelope=o,t.ResponseEnvelope=n,t.MessageEnvelope=s,t.EventMessage=r,t.CommandMessage=h,t.LinkRequest=p,t.LinkedResponse=l,t.SyncRequest=d,t.SyncedResponse=c,t.UnlinkRequest=a,t.UnlinkedResponse=u,t.AuthRequest=f,t.AuthedResponse=y,t.DeauthRequest=v,t.DeauthedResponse=g,t.RemoteHost=w,t.Scope=O,t.HostScope=W,t.NodeScope=I,t.LaneScope=L,t.DownlinkView=k,t.EventDownlinkView=D,t.ListDownlinkView=C,t.MapDownlinkView=E,t.ValueDownlinkView=M,t.Client=q,Object.defineProperty(t,"__esModule",{value:!0})}); |
19
index.js
@@ -20,2 +20,21 @@ export { | ||
import {Envelope} from './src/envelope'; | ||
export var decodeEnvelope = Envelope.decode; | ||
export var parseEnvelope = Envelope.parse; | ||
export {RemoteHost} from './src/remote-host'; | ||
export { | ||
Scope, | ||
HostScope, | ||
NodeScope, | ||
LaneScope | ||
} from './src/scope'; | ||
export {DownlinkView} from './src/downlink'; | ||
export {EventDownlinkView} from './src/event-downlink'; | ||
export {ListDownlinkView} from './src/list-downlink'; | ||
export {MapDownlinkView} from './src/map-downlink'; | ||
export {ValueDownlinkView} from './src/value-downlink'; | ||
export {Client} from './src/client'; | ||
@@ -22,0 +41,0 @@ |
@@ -1,2 +0,2 @@ | ||
Copyright 2015-2016 Swim.it Inc. | ||
Copyright 2015-2017 Swim.it Inc. | ||
@@ -3,0 +3,0 @@ Licensed under the Apache License, Version 2.0 (the "License"); |
{ | ||
"name": "swim-client-js", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Swim JavaScript Client", | ||
"homepage": "https://github.com/swimit/swim-client-js", | ||
"author": "Chris Sachs <chris@swim.it>", | ||
"copyright": "Copyright 2015-2017, Swim.it Inc.", | ||
"license": "Apache-2.0", | ||
@@ -41,2 +42,3 @@ "main": "dist/swim-client.js", | ||
"eslint": "3", | ||
"google-closure-compiler": "20170521", | ||
"rollup": "0.41", | ||
@@ -49,8 +51,13 @@ "tape": "4", | ||
"clean": "rm -rf dist", | ||
"preamble": "node -e 'var pkg = require(\"./package.json\"); console.log(\"// Swim Client v\" + pkg.version + \". Copyright 2015-2016, Swim.it Inc.\");'", | ||
"pretest": "rm -rf dist && mkdir dist && rollup --banner \"$(npm run -s preamble)\" -f umd -g recon-js:Recon,ws:WebSocket -n Swim -o dist/swim-client.js -- index.js", | ||
"test": "eslint index.js src && tape 'test/**/*-spec.js'", | ||
"prepublish": "npm run test && uglifyjs --preamble \"$(npm run -s preamble)\" dist/swim-client.js -c -m -o dist/swim-client.min.js", | ||
"doc": "esdoc -c .esdocrc" | ||
"preamble": "node -e \"var pkg = require('./package.json'); console.log('// Swim client v' + pkg.version + '. ' + pkg.copyright);\"", | ||
"module": "node -e \"var pkg = require('./package.json'); console.log('// Swim client v' + pkg.version + '. ' + pkg.copyright + '\\n(function(global,factory){\\'object\\'===typeof exports&&\\'undefined\\'!==typeof module?factory(exports,require(\\'recon-js\\')):\\'function\\'===typeof define&&define.amd?define([\\'exports\\',\\'recon-js\\'],factory):(factory((global.Swim=global.Swim||{}),global.Recon));}(this,(function(exports,Recon){\\'use strict\\';\\n%output%\\nObject.defineProperty(exports,\\'__esModule\\',{value:true});})));');\"", | ||
"rollup": "rollup --banner \"$(npm run -s preamble)\" -f umd -g recon-js:Recon,ws:WebSocket -n Swim -o dist/swim-client.js index.js", | ||
"uglify": "uglifyjs --preamble \"$(npm run -s preamble)\" --source-map -c -m -o dist/swim-client.min.js dist/swim-client.js", | ||
"compile": "java -jar node_modules/google-closure-compiler/compiler.jar --compilation_level=ADVANCED --new_type_inf --assume_function_wrapper --create_source_map=dist/swim-client.all.js.map --source_map_include_content --output_wrapper \"$(npm run -s module)\" --dependency_mode=STRICT --module_resolution=NODE --externs=externs.js --externs=api.js --externs=node_modules/recon-js/api.js --entry_point=exports exports.js index.js src/*.js node_modules/recon-js/{index.js,src/*.js} > dist/swim-client.all.js", | ||
"build": "rm -rf dist && mkdir dist && npm run rollup && npm run uglify && (command -v java >/dev/null 2>&1 && npm run compile || :)", | ||
"lint": "eslint index.js src", | ||
"test": "tape 'test/**/*-spec.js'", | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm run test" | ||
} | ||
} |
import {Uri} from 'recon-js'; | ||
import {HostScope, NodeScope, LaneScope} from './scope'; | ||
import {HostContext} from './remote-host'; // eslint-disable-line no-unused-vars | ||
import {WebSocketHost} from './websocket-host'; | ||
import {DownlinkContext} from './downlink'; // eslint-disable-line no-unused-vars | ||
import {EventDownlinkView} from './event-downlink'; | ||
@@ -9,14 +11,32 @@ import {ListDownlinkView} from './list-downlink'; | ||
/** | ||
* @constructor | ||
* @implements {DownlinkContext} | ||
* @implements {HostContext} | ||
* @param {{keepOnline: (boolean|undefined)}=} options | ||
*/ | ||
export function Client(options) { | ||
Object.defineProperty(this, 'options', {value: options || {}, enumerable: true}); | ||
Object.defineProperty(this, 'scopes', {value: [], configurable: true}); | ||
Object.defineProperty(this, 'hosts', {value: {}, configurable: true}); | ||
Object.defineProperty(this, 'downlinks', {value: {}, configurable: true}); | ||
Object.defineProperty(this, 'downlinkCount', {value: 0, writable: true}); | ||
Object.defineProperty(this, 'online', {value: true, configurable: true}); | ||
this.options = options || {}; | ||
/** @private */ | ||
this.scopes = []; | ||
/** @private */ | ||
this.hosts = {}; | ||
/** @private */ | ||
this.downlinks = {}; | ||
/** @private */ | ||
this.downlinkCount = 0; | ||
/** @private */ | ||
this.online = true; | ||
/** @private */ | ||
this.delegate = {}; | ||
/** @private */ | ||
this.onOnline = this.onOnline.bind(this); | ||
/** @private */ | ||
this.onOffline = this.onOffline.bind(this); | ||
this.watchOnline(this.keepOnline); | ||
this.watchOnline(this.options.keepOnline); | ||
} | ||
/** | ||
* @param {boolean} isOnline | ||
* @return {this} | ||
*/ | ||
Client.prototype.isOnline = function (isOnline) { | ||
@@ -27,3 +47,3 @@ if (!arguments.length) { | ||
if (this.online !== isOnline) { | ||
Object.defineProperty(this, 'online', {value: isOnline, configurable: true}); | ||
this.online = isOnline; | ||
for (var hostUri in this.hosts) { | ||
@@ -40,2 +60,6 @@ var host = this.hosts[hostUri]; | ||
}; | ||
/** | ||
* @param {boolean} keepOnline | ||
* @return {this} | ||
*/ | ||
Client.prototype.keepOnline = function (keepOnline) { | ||
@@ -51,2 +75,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @private | ||
* @param {boolean} keepOnline | ||
*/ | ||
Client.prototype.watchOnline = function (keepOnline) { | ||
@@ -58,18 +86,32 @@ /* global window */ | ||
if (keepOnline) { | ||
window.addEventListener('online', this.onOnline, false); | ||
window.addEventListener('offline', this.onOffline, false); | ||
window.addEventListener('online', /** @type {function (Event)} */ (this.onOnline), false); | ||
window.addEventListener('offline', /** @type {function (Event)} */ (this.onOffline), false); | ||
} else { | ||
window.removeEventListener('online', this.onOnline, false); | ||
window.removeEventListener('offline', this.onOffline, false); | ||
window.removeEventListener('online', /** @type {function (Event)} */ (this.onOnline), false); | ||
window.removeEventListener('offline', /** @type {function (Event)} */ (this.onOffline), false); | ||
} | ||
}; | ||
Client.prototype.onOnline = function () { | ||
/** | ||
* @private | ||
* @param {!Event} event | ||
*/ | ||
Client.prototype.onOnline = function (event) { | ||
this.isOnline(true); | ||
}; | ||
Client.prototype.onOffline = function () { | ||
/** | ||
* @private | ||
* @param {!Event} event | ||
*/ | ||
Client.prototype.onOffline = function (event) { | ||
this.isOnline(false); | ||
}; | ||
/** | ||
* @param {!./scope.Scope} scope; | ||
*/ | ||
Client.prototype.openScope = function (scope) { | ||
this.scopes.push(scope); | ||
}; | ||
/** | ||
* @param {!./scope.Scope} scope; | ||
*/ | ||
Client.prototype.closeScope = function (scope) { | ||
@@ -84,5 +126,13 @@ for (var i = 0; i < this.scopes.length; i += 1) { | ||
}; | ||
/** | ||
* @param {string} hostUri | ||
* @return {./remote-host.RemoteHost} | ||
*/ | ||
Client.prototype.getHost = function (hostUri) { | ||
return this.hosts[hostUri]; | ||
}; | ||
/** | ||
* @param {string} hostUri | ||
* @return {!./remote-host.RemoteHost} | ||
*/ | ||
Client.prototype.openHost = function (hostUri) { | ||
@@ -96,2 +146,5 @@ var host = this.hosts[hostUri]; | ||
}; | ||
/** | ||
* @param {!./remote-host.RemoteHost} host | ||
*/ | ||
Client.prototype.closeHost = function (host) { | ||
@@ -103,2 +156,8 @@ if (this.hosts[host.hostUri]) { | ||
}; | ||
/** | ||
* @param {string} hostUri | ||
* @param {string} nodeUri | ||
* @param {string} laneUri | ||
* @return {./downlink.DownlinkModel} | ||
*/ | ||
Client.prototype.getDownlink = function (hostUri, nodeUri, laneUri) { | ||
@@ -112,3 +171,7 @@ var hostDownlinks = this.downlinks[hostUri]; | ||
} | ||
return null; | ||
}; | ||
/** | ||
* @param {!./downlink.DownlinkModel} downlink | ||
*/ | ||
Client.prototype.openDownlink = function (downlink) { | ||
@@ -136,2 +199,5 @@ var hostUri = downlink.hostUri; | ||
}; | ||
/** | ||
* @param {!./downlink.DownlinkModel} downlink | ||
*/ | ||
Client.prototype.closeDownlink = function (downlink) { | ||
@@ -162,6 +228,15 @@ var hostUri = downlink.hostUri; | ||
}; | ||
/** | ||
* @param {string} hostUri | ||
* @return {!HostScope} | ||
*/ | ||
Client.prototype.host = function (hostUri) { | ||
return new HostScope(this, hostUri); | ||
}; | ||
Client.prototype.node = function () { | ||
/** | ||
* @param {string} _hostUri | ||
* @param {string=} _nodeUri | ||
* @return {!NodeScope} | ||
*/ | ||
Client.prototype.node = function (_hostUri, _nodeUri) { | ||
var hostUri, nodeUri; | ||
@@ -177,3 +252,9 @@ if (arguments.length === 1) { | ||
}; | ||
Client.prototype.lane = function () { | ||
/** | ||
* @param {string} _hostUri | ||
* @param {string} _nodeUri | ||
* @param {string=} _laneUri | ||
* @return {LaneScope} | ||
*/ | ||
Client.prototype.lane = function (_hostUri, _nodeUri, _laneUri) { | ||
var hostUri, nodeUri, laneUri; | ||
@@ -191,15 +272,33 @@ if (arguments.length === 2) { | ||
}; | ||
/** | ||
* @return {!EventDownlinkView} | ||
*/ | ||
Client.prototype.downlink = function () { | ||
return new EventDownlinkView(this); | ||
}; | ||
/** | ||
* @return {!ListDownlinkView} | ||
*/ | ||
Client.prototype.downlinkList = function () { | ||
return new ListDownlinkView(this); | ||
}; | ||
/** | ||
* @return {!MapDownlinkView} | ||
*/ | ||
Client.prototype.downlinkMap = function () { | ||
return new MapDownlinkView(this); | ||
}; | ||
/** | ||
* @return {!ValueDownlinkView} | ||
*/ | ||
Client.prototype.downlinkValue = function () { | ||
return new ValueDownlinkView(this); | ||
}; | ||
Client.prototype.command = function () { | ||
/** | ||
* @param {string} _hostUri | ||
* @param {string} _nodeUri | ||
* @param {*} _laneUri | ||
* @param {*=} _body | ||
*/ | ||
Client.prototype.command = function (_hostUri, _nodeUri, _laneUri, _body) { | ||
var hostUri, nodeUri, laneUri, body; | ||
@@ -220,2 +319,6 @@ if (arguments.length === 3) { | ||
}; | ||
/** | ||
* @param {string} hostUri | ||
* @param {*} credentials | ||
*/ | ||
Client.prototype.authenticate = function (hostUri, credentials) { | ||
@@ -225,2 +328,6 @@ var host = this.openHost(hostUri); | ||
}; | ||
/** | ||
* @param {function (*=, ./remote-host.RemoteHost=)} didAuthenticate | ||
* @return {this} | ||
*/ | ||
Client.prototype.didAuthenticate = function (didAuthenticate) { | ||
@@ -233,2 +340,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (*=, ./remote-host.RemoteHost=)} didDeauthenticate | ||
* @return {this} | ||
*/ | ||
Client.prototype.didDeauthenticate = function (didDeauthenticate) { | ||
@@ -241,2 +352,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (./remote-host.RemoteHost=)} didConnect | ||
* @return {this} | ||
*/ | ||
Client.prototype.didConnect = function (didConnect) { | ||
@@ -249,2 +364,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (./remote-host.RemoteHost=)} didDisconnect | ||
* @return {this} | ||
*/ | ||
Client.prototype.didDisconnect = function (didDisconnect) { | ||
@@ -257,2 +376,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (*=, ./remote-host.RemoteHost=)} didFail | ||
* @return {this} | ||
*/ | ||
Client.prototype.didFail = function (didFail) { | ||
@@ -265,5 +388,5 @@ if (!arguments.length) { | ||
}; | ||
Client.prototype.hostDidAuthenticate = function (message, host) { | ||
Client.prototype.hostDidAuthenticate = function (response, host) { | ||
if (this.delegate && typeof this.delegate.didAuthenticate === 'function') { | ||
this.delegate.didAuthenticate(message.body, host); | ||
this.delegate.didAuthenticate(response.body, host); | ||
} | ||
@@ -273,9 +396,9 @@ for (var i = 0, n = this.scopes.length; i < n; i += 1) { | ||
if (scope.hostUri === host.hostUri) { | ||
scope.hostDidAuthenticate(message, host); | ||
scope.hostDidAuthenticate(response, host); | ||
} | ||
} | ||
}; | ||
Client.prototype.hostDidDeauthenticate = function (message, host) { | ||
Client.prototype.hostDidDeauthenticate = function (response, host) { | ||
if (this.delegate && typeof this.delegate.didDeauthenticate === 'function') { | ||
this.delegate.didDeauthenticate(message.body, host); | ||
this.delegate.didDeauthenticate(response.body, host); | ||
} | ||
@@ -285,3 +408,3 @@ for (var i = 0, n = this.scopes.length; i < n; i += 1) { | ||
if (scope.hostUri === host.hostUri) { | ||
scope.hostDidDeauthenticate(message, host); | ||
scope.hostDidDeauthenticate(response, host); | ||
} | ||
@@ -326,3 +449,3 @@ } | ||
var scopes = this.scopes; | ||
Object.defineProperty(this, 'scopes', {value: [], configurable: true}); | ||
this.scopes = []; | ||
for (var i = 0; i < scopes.length; i += 1) { | ||
@@ -333,3 +456,3 @@ scopes[i].closeUp(); | ||
var downlinks = this.downlinks; | ||
Object.defineProperty(this, 'downlinks', {value: {}, configurable: true}); | ||
this.downlinks = {}; | ||
for (hostUri in downlinks) { | ||
@@ -345,3 +468,3 @@ var hostDownlinks = downlinks[hostUri]; | ||
var hosts = this.hosts; | ||
Object.defineProperty(this, 'hosts', {value: {}, configurable: true}); | ||
this.hosts = {}; | ||
for (hostUri in hosts) { | ||
@@ -348,0 +471,0 @@ hosts[hostUri].closeUp(); |
@@ -1,14 +0,50 @@ | ||
import {Uri} from 'recon-js'; | ||
import {LinkRequest, SyncRequest} from './envelope'; | ||
import {HostDownlink, RemoteHost} from './remote-host'; // eslint-disable-line no-unused-vars | ||
/** | ||
* @interface | ||
*/ | ||
export function DownlinkContext() {} | ||
/** | ||
* @param {!DownlinkModel} downlink | ||
*/ | ||
DownlinkContext.prototype.closeDownlink = function (downlink) {}; | ||
/** | ||
* @interface | ||
*/ | ||
export function DownlinkScope() {} | ||
/** | ||
* @param {!DownlinkView} view | ||
*/ | ||
DownlinkScope.prototype.removeDownlink = function (view) {}; | ||
/** | ||
* @abstract @constructor | ||
* @implements {HostDownlink} | ||
* @param {!DownlinkContext} context | ||
* @param {string} hostUri | ||
* @param {string} nodeUri | ||
* @param {string} laneUri | ||
* @param {number} prio | ||
* @param {number} rate | ||
* @paran {*} body | ||
*/ | ||
export function DownlinkModel(context, hostUri, nodeUri, laneUri, prio, rate, body) { | ||
Object.defineProperty(this, 'context', {value: context}); | ||
Object.defineProperty(this, 'hostUri', {value: hostUri, enumerable: true}); | ||
Object.defineProperty(this, 'nodeUri', {value: nodeUri, enumerable: true}); | ||
Object.defineProperty(this, 'laneUri', {value: laneUri, enumerable: true}); | ||
Object.defineProperty(this, 'prio', {value: prio || 0, enumerable: true}); | ||
Object.defineProperty(this, 'rate', {value: rate || 0, enumerable: true}); | ||
Object.defineProperty(this, 'body', {value: body, enumerable: true}); | ||
Object.defineProperty(this, 'views', {value: [], configurable: true}); | ||
this.context = context; | ||
this.hostUri = hostUri; | ||
this.nodeUri = nodeUri; | ||
this.laneUri = laneUri; | ||
this.prio = prio; | ||
this.rate = rate; | ||
this.body = body; | ||
this.views = []; | ||
/** @type {RemoteHost} **/ | ||
this.host = null; | ||
this.linked = false; | ||
this.synced = false; | ||
} | ||
/** | ||
* @return {boolean} | ||
*/ | ||
DownlinkModel.prototype.keepLinked = function () { | ||
@@ -22,2 +58,5 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
DownlinkModel.prototype.keepSynced = function () { | ||
@@ -31,14 +70,41 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
DownlinkModel.prototype.isConnected = function () { | ||
return this.context.isConnected(); | ||
return !!(this.host && this.host.isConnected()); | ||
}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
DownlinkModel.prototype.isAuthenticated = function () { | ||
return this.context.isAuthenticated(); | ||
return !!(this.host && this.host.isAuthenticated()); | ||
}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
DownlinkModel.prototype.isLinked = function () { | ||
return this.linked; | ||
}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
DownlinkModel.prototype.isSynced = function () { | ||
return this.synced; | ||
}; | ||
/** | ||
* @return {*} | ||
*/ | ||
DownlinkModel.prototype.session = function () { | ||
return this.context.session(); | ||
return this.host && this.host.session(); | ||
}; | ||
/** | ||
* @param {!DownlinkView} view | ||
*/ | ||
DownlinkModel.prototype.addDownlink = function (view) { | ||
this.views.push(view); | ||
}; | ||
/** | ||
* @param {!DownlinkView} view | ||
*/ | ||
DownlinkModel.prototype.removeDownlink = function (view) { | ||
@@ -52,3 +118,3 @@ for (var i = 0; i < this.views.length; i += 1) { | ||
if (this.views.length === 0) { | ||
this.context.close(); | ||
this.close(); | ||
} | ||
@@ -61,7 +127,13 @@ }; | ||
}; | ||
DownlinkModel.prototype.onCommandMessage = function (message) { | ||
/** | ||
* @param {*} body | ||
*/ | ||
DownlinkModel.prototype.onCommandMessage = function (body) { | ||
for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
this.views[i].onCommandMessage(message); | ||
this.views[i].onCommandMessage(body); | ||
} | ||
}; | ||
/** | ||
* @param {!LinkRequest} request | ||
*/ | ||
DownlinkModel.prototype.onLinkRequest = function (request) { | ||
@@ -73,2 +145,3 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
DownlinkModel.prototype.onLinkedResponse = function (response) { | ||
this.linked = true; | ||
for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
@@ -78,2 +151,5 @@ this.views[i].onLinkedResponse(response); | ||
}; | ||
/** | ||
* @param {!SyncRequest} request | ||
*/ | ||
DownlinkModel.prototype.onSyncRequest = function (request) { | ||
@@ -85,2 +161,3 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
DownlinkModel.prototype.onSyncedResponse = function (response) { | ||
this.synced = true; | ||
for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
@@ -90,3 +167,8 @@ this.views[i].onSyncedResponse(response); | ||
}; | ||
/** | ||
* @param {!./envelope.UnlinkRequest} request | ||
*/ | ||
DownlinkModel.prototype.onUnlinkRequest = function (request) { | ||
this.synced = false; | ||
this.linked = false; | ||
for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
@@ -101,4 +183,6 @@ this.views[i].onUnlinkRequest(request); | ||
}; | ||
/** | ||
* @param {!RemoteHost} host | ||
*/ | ||
DownlinkModel.prototype.hostDidConnect = function (host) { | ||
Object.defineProperty(this, 'host', {value: host, configurable: true}); | ||
for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
@@ -118,4 +202,8 @@ this.views[i].hostDidConnect(); | ||
}; | ||
/** | ||
* @param {!RemoteHost} host | ||
*/ | ||
DownlinkModel.prototype.hostDidDisconnect = function (host) { | ||
Object.defineProperty(this, 'host', {value: null, configurable: true}); | ||
this.synced = false; | ||
this.linked = false; | ||
var keepLinked = false; | ||
@@ -131,2 +219,6 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {*} error | ||
* @param {!RemoteHost} host | ||
*/ | ||
DownlinkModel.prototype.hostDidFail = function (error, host) { | ||
@@ -137,5 +229,8 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {*=} body | ||
*/ | ||
DownlinkModel.prototype.command = function (body) { | ||
this.onCommandMessage(body); | ||
this.context.command(this.hostUri, this.nodeUri, this.laneUri, body); | ||
this.host.command(this.nodeUri, this.laneUri, body); | ||
}; | ||
@@ -145,5 +240,14 @@ DownlinkModel.prototype.close = function () { | ||
}; | ||
/** | ||
* @param {!RemoteHost} host | ||
*/ | ||
DownlinkModel.prototype.openUp = function (host) { | ||
this.host = host; | ||
for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
this.views[i].openUp(host); | ||
} | ||
}; | ||
DownlinkModel.prototype.closeUp = function () { | ||
var views = this.views; | ||
Object.defineProperty(this, 'views', {value: [], configurable: true}); | ||
this.views = []; | ||
for (var i = 0; i < views.length; i += 1) { | ||
@@ -154,6 +258,14 @@ views[i].closeUp(); | ||
/** | ||
* @abstract @constructor | ||
* @param {!DownlinkContext} context | ||
* @param {DownlinkScope} scope | ||
* @param {Object} props | ||
* @param {{keepSynced: (boolean|undefined)}} options | ||
* @param {Object} delegate | ||
*/ | ||
export function DownlinkView(context, scope, props, options, delegate) { | ||
Object.defineProperty(this, 'context', {value: context}); | ||
Object.defineProperty(this, 'scope', {value: scope}); | ||
Object.defineProperty(this, 'props', {value: Object.freeze(props || {})}); | ||
this.context = context; | ||
this.scope = scope; | ||
this.props = props || {}; | ||
this.options = options || {}; | ||
@@ -163,2 +275,8 @@ this.delegate = delegate || {}; | ||
} | ||
/** | ||
* @param {!Object} props | ||
* @param {!{keepSynced: (boolean|undefined)}=} options | ||
* @param {!Object=} delegate | ||
* @return {this} | ||
*/ | ||
DownlinkView.prototype.copy = function (props, options, delegate) { | ||
@@ -191,5 +309,8 @@ var key; | ||
return new this.constructor(this.context, this.scope, newProps, | ||
newOptions, newDelegate); | ||
return new this.constructor(this.context, this.scope, newProps, newOptions, newDelegate); | ||
}; | ||
/** | ||
* @param {string=} hostUri | ||
* @return {string|this} | ||
*/ | ||
DownlinkView.prototype.host = function (hostUri) { | ||
@@ -199,9 +320,8 @@ if (!arguments.length) { | ||
} | ||
if (this.props.nodeUri) { | ||
var nodeUri = Uri.resolveUri(hostUri, this.props.nodeUri); | ||
return this.copy({hostUri: hostUri, nodeUri: nodeUri}); | ||
} else { | ||
return this.copy({hostUri: hostUri}); | ||
} | ||
return this.copy({hostUri: hostUri}); | ||
}; | ||
/** | ||
* @param {string=} nodeUri | ||
* @return {string|this} | ||
*/ | ||
DownlinkView.prototype.node = function (nodeUri) { | ||
@@ -211,7 +331,8 @@ if (!arguments.length) { | ||
} | ||
if (this.props.hostUri) { | ||
nodeUri = Uri.resolveUri(this.props.hostUri, nodeUri); | ||
} | ||
return this.copy({nodeUri: nodeUri}); | ||
}; | ||
/** | ||
* @param {string=} laneUri | ||
* @return {string|this} | ||
*/ | ||
DownlinkView.prototype.lane = function (laneUri) { | ||
@@ -223,2 +344,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {number=} prio | ||
* @return {number|this} | ||
*/ | ||
DownlinkView.prototype.prio = function (prio) { | ||
@@ -230,2 +355,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {number=} rate | ||
* @return {number|this} | ||
*/ | ||
DownlinkView.prototype.rate = function (rate) { | ||
@@ -237,2 +366,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {*=} body | ||
* @return {*|this} | ||
*/ | ||
DownlinkView.prototype.body = function (body) { | ||
@@ -244,2 +377,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {boolean=} keepLinked | ||
* @return {boolean|this} | ||
*/ | ||
DownlinkView.prototype.keepLinked = function (keepLinked) { | ||
@@ -252,2 +389,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {boolean=} keepSynced | ||
* @return {boolean|this} | ||
*/ | ||
DownlinkView.prototype.keepSynced = function (keepSynced) { | ||
@@ -260,2 +401,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (*=, !DownlinkView=)=} onEvent | ||
* @return {function (*=, !DownlinkView=)|this} | ||
*/ | ||
DownlinkView.prototype.onEvent = function (onEvent) { | ||
@@ -268,2 +413,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (*=, !DownlinkView=)=} onCommand | ||
* @return {function (*=, !DownlinkView=)|this} | ||
*/ | ||
DownlinkView.prototype.onCommand = function (onCommand) { | ||
@@ -276,2 +425,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!DownlinkView=)=} willLink | ||
* @return {function (!DownlinkView=)|this} | ||
*/ | ||
DownlinkView.prototype.willLink = function (willLink) { | ||
@@ -284,2 +437,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!DownlinkView=)=} didLink | ||
* @return {function (!DownlinkView=)|this} | ||
*/ | ||
DownlinkView.prototype.didLink = function (didLink) { | ||
@@ -292,2 +449,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!DownlinkView=)=} willSync | ||
* @return {function (!DownlinkView=)|this} | ||
*/ | ||
DownlinkView.prototype.willSync = function (willSync) { | ||
@@ -300,2 +461,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!DownlinkView=)=} didSync | ||
* @return {function (!DownlinkView=)|this} | ||
*/ | ||
DownlinkView.prototype.didSync = function (didSync) { | ||
@@ -308,2 +473,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!DownlinkView=)=} willUnlink | ||
* @return {function (!DownlinkView=)|this} | ||
*/ | ||
DownlinkView.prototype.willUnlink = function (willUnlink) { | ||
@@ -316,2 +485,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!DownlinkView=)=} didUnlink | ||
* @return {function (!DownlinkView=)|this} | ||
*/ | ||
DownlinkView.prototype.didUnlink = function (didUnlink) { | ||
@@ -324,2 +497,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!DownlinkView=)=} didConnect | ||
* @return {function (!DownlinkView=)|this} | ||
*/ | ||
DownlinkView.prototype.didConnect = function (didConnect) { | ||
@@ -332,2 +509,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!DownlinkView=)=} didDisconnect | ||
* @return {function (!DownlinkView=)|this} | ||
*/ | ||
DownlinkView.prototype.didDisconnect = function (didDisconnect) { | ||
@@ -340,2 +521,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!DownlinkView=)=} didClose | ||
* @return {function (!DownlinkView=)|this} | ||
*/ | ||
DownlinkView.prototype.didClose = function (didClose) { | ||
@@ -348,2 +533,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!DownlinkView=)=} didFail | ||
* @return {function (!DownlinkView=)|this} | ||
*/ | ||
DownlinkView.prototype.didFail = function (didFail) { | ||
@@ -356,11 +545,35 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
DownlinkView.prototype.isConnected = function () { | ||
return this.model && this.model.isConnected(); | ||
return !!(this.model && this.model.isConnected()); | ||
}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
DownlinkView.prototype.isAuthenticated = function () { | ||
return this.model && this.model.isAuthenticated(); | ||
return !!(this.model && this.model.isAuthenticated()); | ||
}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
DownlinkView.prototype.isLinked = function () { | ||
return !!(this.model && this.model.isLinked()); | ||
}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
DownlinkView.prototype.isSynced = function () { | ||
return !!(this.model && this.model.isSynced()); | ||
}; | ||
/** | ||
* @return {*} | ||
*/ | ||
DownlinkView.prototype.session = function () { | ||
return this.model && this.model.session(); | ||
}; | ||
/** | ||
* @param {!./envelope.EventMessage} message | ||
*/ | ||
DownlinkView.prototype.onEventMessage = function (message) { | ||
@@ -371,8 +584,11 @@ if (this.delegate && typeof this.delegate.onEvent === 'function') { | ||
}; | ||
DownlinkView.prototype.onCommandMessage = function (message) { | ||
/** | ||
* @param {*} body | ||
*/ | ||
DownlinkView.prototype.onCommandMessage = function (body) { | ||
if (this.delegate && typeof this.delegate.onCommand === 'function') { | ||
this.delegate.onCommand(message.body, this); | ||
this.delegate.onCommand(body, this); | ||
} | ||
}; | ||
DownlinkView.prototype.onLinkRequest = function (request) { | ||
DownlinkView.prototype.onLinkRequest = function () { | ||
if (this.delegate && typeof this.delegate.willLink === 'function') { | ||
@@ -382,2 +598,5 @@ this.delegate.willLink(this); | ||
}; | ||
/** | ||
* @param {!./envelope.LinkedResponse} response | ||
*/ | ||
DownlinkView.prototype.onLinkedResponse = function (response) { | ||
@@ -388,3 +607,3 @@ if (this.delegate && typeof this.delegate.didLink === 'function') { | ||
}; | ||
DownlinkView.prototype.onSyncRequest = function (request) { | ||
DownlinkView.prototype.onSyncRequest = function () { | ||
if (this.delegate && typeof this.delegate.willSync === 'function') { | ||
@@ -394,2 +613,5 @@ this.delegate.willSync(this); | ||
}; | ||
/** | ||
* @param {!./envelope.SyncedResponse} response | ||
*/ | ||
DownlinkView.prototype.onSyncedResponse = function (response) { | ||
@@ -400,3 +622,3 @@ if (this.delegate && typeof this.delegate.didSync === 'function') { | ||
}; | ||
DownlinkView.prototype.onUnlinkRequest = function (request) { | ||
DownlinkView.prototype.onUnlinkRequest = function () { | ||
if (this.delegate && typeof this.delegate.willUnlink === 'function') { | ||
@@ -406,2 +628,5 @@ this.delegate.willUnlink(this); | ||
}; | ||
/** | ||
* @param {!./envelope.UnlinkedResponse} response | ||
*/ | ||
DownlinkView.prototype.onUnlinkedResponse = function (response) { | ||
@@ -427,6 +652,13 @@ if (this.delegate && typeof this.delegate.didUnlink === 'function') { | ||
}; | ||
/** | ||
* @param {*=} body | ||
*/ | ||
DownlinkView.prototype.command = function (body) { | ||
this.model.command(body); | ||
}; | ||
DownlinkView.prototype.open = null; | ||
/** | ||
* @abstract | ||
* @return {this} | ||
*/ | ||
DownlinkView.prototype.open = function () {}; | ||
DownlinkView.prototype.close = function () { | ||
@@ -440,2 +672,6 @@ if (this.scope) { | ||
}; | ||
/** | ||
* @param {!RemoteHost} host | ||
*/ | ||
DownlinkView.prototype.openUp = function (host) {}; | ||
DownlinkView.prototype.closeUp = function () { | ||
@@ -442,0 +678,0 @@ if (this.delegate && typeof this.delegate.didClose === 'function') { |
import * as Recon from 'recon-js'; | ||
/** | ||
* @abstract @constructor | ||
*/ | ||
export function Envelope() {} | ||
Object.defineProperty(Envelope.prototype, 'isRequest', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isResponse', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isMessage', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isEventMessage', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isCommandMessage', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isLinkRequest', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isLinkedResponse', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isSyncRequest', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isSyncedResponse', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isUnlinkRequest', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isUnlinkedResponse', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isAuthRequest', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isAuthedResponse', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isDeauthRequest', {value: false}); | ||
Object.defineProperty(Envelope.prototype, 'isDeauthedResponse', {value: false}); | ||
Envelope.prototype.isRequest = false; | ||
Envelope.prototype.isResponse = false; | ||
Envelope.prototype.isMessage = false; | ||
Envelope.prototype.isEventMessage = false; | ||
Envelope.prototype.isCommandMessage = false; | ||
Envelope.prototype.isLinkRequest = false; | ||
Envelope.prototype.isLinkedResponse = false; | ||
Envelope.prototype.isSyncRequest = false; | ||
Envelope.prototype.isSyncedResponse = false; | ||
Envelope.prototype.isUnlinkRequest = false; | ||
Envelope.prototype.isUnlinkedResponse = false; | ||
Envelope.prototype.isAuthRequest = false; | ||
Envelope.prototype.isAuthedResponse = false; | ||
Envelope.prototype.isDeauthRequest = false; | ||
Envelope.prototype.isDeauthedResponse = false; | ||
/** | ||
* @abstract | ||
* @return {*} | ||
*/ | ||
Envelope.prototype.encode = function () {} | ||
/** | ||
* @return {string} | ||
*/ | ||
Envelope.prototype.toRecon = function () { | ||
return Recon.stringify(this.encode()); | ||
}; | ||
/** | ||
* @param {*} record | ||
* @return {Envelope} | ||
*/ | ||
Envelope.decode = function (record) { | ||
switch (Recon.tag(record)) { | ||
case '@event': | ||
return EventMessage.decode(record); | ||
return /** @type (Envelope) */ (EventMessage.decode(record)); | ||
case '@command': | ||
return CommandMessage.decode(record); | ||
return /** @type (Envelope) */ (CommandMessage.decode(record)); | ||
case '@link': | ||
return LinkRequest.decode(record); | ||
return /** @type (Envelope) */ (LinkRequest.decode(record)); | ||
case '@linked': | ||
return LinkedResponse.decode(record); | ||
return /** @type (Envelope) */ (LinkedResponse.decode(record)); | ||
case '@sync': | ||
return SyncRequest.decode(record); | ||
return /** @type (Envelope) */ (SyncRequest.decode(record)); | ||
case '@synced': | ||
return SyncedResponse.decode(record); | ||
return /** @type (Envelope) */ (SyncedResponse.decode(record)); | ||
case '@unlink': | ||
return UnlinkRequest.decode(record); | ||
return /** @type (Envelope) */ (UnlinkRequest.decode(record)); | ||
case '@unlinked': | ||
return UnlinkedResponse.decode(record); | ||
return /** @type (Envelope) */ (UnlinkedResponse.decode(record)); | ||
case '@auth': | ||
return AuthRequest.decode(record); | ||
return /** @type (Envelope) */ (AuthRequest.decode(record)); | ||
case '@authed': | ||
return AuthedResponse.decode(record); | ||
return /** @type (Envelope) */ (AuthedResponse.decode(record)); | ||
case '@deauth': | ||
return DeauthRequest.decode(record); | ||
return /** @type (Envelope) */ (DeauthRequest.decode(record)); | ||
case '@deauthed': | ||
return DeauthedResponse.decode(record); | ||
return /** @type (Envelope) */ (DeauthedResponse.decode(record)); | ||
default: | ||
return null; | ||
} | ||
}; | ||
/** | ||
* @param {string} string | ||
* @return {Envelope} | ||
*/ | ||
Envelope.parse = function (string) { | ||
@@ -54,2 +75,6 @@ return Envelope.decode(Recon.parse(string)); | ||
/** | ||
* @abstract @constructor | ||
* @extends {Envelope} | ||
*/ | ||
export function RequestEnvelope() { | ||
@@ -60,4 +85,8 @@ Envelope.call(this); | ||
RequestEnvelope.prototype.constructor = RequestEnvelope; | ||
Object.defineProperty(RequestEnvelope.prototype, 'isRequest', {value: true}); | ||
RequestEnvelope.prototype.isRequest = true; | ||
/** | ||
* @abstract @constructor | ||
* @extends {Envelope} | ||
*/ | ||
export function ResponseEnvelope() { | ||
@@ -68,4 +97,8 @@ Envelope.call(this); | ||
ResponseEnvelope.prototype.constructor = ResponseEnvelope; | ||
Object.defineProperty(ResponseEnvelope.prototype, 'isResponse', {value: true}); | ||
ResponseEnvelope.prototype.isResponse = true; | ||
/** | ||
* @abstract @constructor | ||
* @extends {Envelope} | ||
*/ | ||
export function MessageEnvelope() { | ||
@@ -76,4 +109,11 @@ Envelope.call(this); | ||
MessageEnvelope.prototype.constructor = MessageEnvelope; | ||
Object.defineProperty(MessageEnvelope.prototype, 'isMessage', {value: true}); | ||
MessageEnvelope.prototype.isMessage = true; | ||
/** | ||
* @constructor | ||
* @extends {MessageEnvelope} | ||
* @param {*} node | ||
* @param {*} lane | ||
* @param {*=} body | ||
*/ | ||
export function EventMessage(node, lane, body) { | ||
@@ -87,3 +127,8 @@ MessageEnvelope.call(this); | ||
EventMessage.prototype.constructor = EventMessage; | ||
Object.defineProperty(EventMessage.prototype, 'isEventMessage', {value: true}); | ||
EventMessage.prototype.isEventMessage = true; | ||
/** | ||
* @param {*=} node | ||
* @param {*=} lane | ||
* @return {!EventMessage} | ||
*/ | ||
EventMessage.prototype.withAddress = function (node, lane) { | ||
@@ -99,5 +144,10 @@ if (node === undefined) { | ||
EventMessage.prototype.encode = function () { | ||
var headers = {node: this.node, lane: this.lane}; | ||
var headers = {}; | ||
headers['node'] = this.node; | ||
headers['lane'] = this.lane; | ||
return Recon.concat({'@event': headers}, this.body); | ||
}; | ||
/** | ||
* @return {EventMessage} | ||
*/ | ||
EventMessage.decode = function (record) { | ||
@@ -121,4 +171,12 @@ var node, lane; | ||
} | ||
return null; | ||
}; | ||
/** | ||
* @constructor | ||
* @extends {MessageEnvelope} | ||
* @param {*} node | ||
* @param {*} lane | ||
* @param {*=} body | ||
*/ | ||
export function CommandMessage(node, lane, body) { | ||
@@ -132,3 +190,8 @@ MessageEnvelope.call(this); | ||
CommandMessage.prototype.constructor = CommandMessage; | ||
Object.defineProperty(CommandMessage.prototype, 'isCommandMessage', {value: true}); | ||
CommandMessage.prototype.isCommandMessage = true; | ||
/** | ||
* @param {*=} node | ||
* @param {*=} lane | ||
* @return {!CommandMessage} | ||
*/ | ||
CommandMessage.prototype.withAddress = function (node, lane) { | ||
@@ -144,5 +207,10 @@ if (node === undefined) { | ||
CommandMessage.prototype.encode = function () { | ||
var headers = {node: this.node, lane: this.lane}; | ||
var headers = {}; | ||
headers['node'] = this.node; | ||
headers['lane'] = this.lane; | ||
return Recon.concat({'@command': headers}, this.body); | ||
}; | ||
/** | ||
* @return {CommandMessage} | ||
*/ | ||
CommandMessage.decode = function (record) { | ||
@@ -166,4 +234,14 @@ var node, lane; | ||
} | ||
return null; | ||
}; | ||
/** | ||
* @constructor | ||
* @extends {RequestEnvelope} | ||
* @param {*} node | ||
* @param {*} lane | ||
* @param {number=} prio | ||
* @param {number=} rate | ||
* @param {*=} body | ||
*/ | ||
export function LinkRequest(node, lane, prio, rate, body) { | ||
@@ -179,3 +257,8 @@ RequestEnvelope.call(this); | ||
LinkRequest.prototype.constructor = LinkRequest; | ||
Object.defineProperty(LinkRequest.prototype, 'isLinkRequest', {value: true}); | ||
LinkRequest.prototype.isLinkRequest = true; | ||
/** | ||
* @param {*=} node | ||
* @param {*=} lane | ||
* @return {!LinkRequest} | ||
*/ | ||
LinkRequest.prototype.withAddress = function (node, lane) { | ||
@@ -191,11 +274,16 @@ if (node === undefined) { | ||
LinkRequest.prototype.encode = function () { | ||
var headers = {node: this.node, lane: this.lane}; | ||
var headers = {}; | ||
headers['node'] = this.node; | ||
headers['lane'] = this.lane; | ||
if (this.prio !== undefined && this.prio !== 0) { | ||
headers.prio = this.prio; | ||
headers['prio'] = this.prio; | ||
} | ||
if (this.rate !== undefined && this.rate !== 0) { | ||
headers.rate = this.rate; | ||
headers['rate'] = this.rate; | ||
} | ||
return Recon.concat({'@link': headers}, this.body); | ||
}; | ||
/** | ||
* @return {LinkRequest} | ||
*/ | ||
LinkRequest.decode = function (record) { | ||
@@ -223,4 +311,14 @@ var node, lane, prio, rate; | ||
} | ||
return null; | ||
}; | ||
/** | ||
* @constructor | ||
* @extends {ResponseEnvelope} | ||
* @param {*} node | ||
* @param {*} lane | ||
* @param {number=} prio | ||
* @param {number=} rate | ||
* @param {*=} body | ||
*/ | ||
export function LinkedResponse(node, lane, prio, rate, body) { | ||
@@ -236,3 +334,8 @@ ResponseEnvelope.call(this); | ||
LinkedResponse.prototype.constructor = LinkedResponse; | ||
Object.defineProperty(LinkedResponse.prototype, 'isLinkedResponse', {value: true}); | ||
LinkedResponse.prototype.isLinkedResponse = true; | ||
/** | ||
* @param {*=} node | ||
* @param {*=} lane | ||
* @return {!LinkedResponse} | ||
*/ | ||
LinkedResponse.prototype.withAddress = function (node, lane) { | ||
@@ -248,11 +351,16 @@ if (node === undefined) { | ||
LinkedResponse.prototype.encode = function () { | ||
var headers = {node: this.node, lane: this.lane}; | ||
var headers = {}; | ||
headers['node'] = this.node; | ||
headers['lane'] = this.lane; | ||
if (this.prio !== undefined && this.prio !== 0) { | ||
headers.prio = this.prio; | ||
headers['prio'] = this.prio; | ||
} | ||
if (this.rate !== undefined && this.rate !== 0) { | ||
headers.rate = this.rate; | ||
headers['rate'] = this.rate; | ||
} | ||
return Recon.concat({'@linked': headers}, this.body); | ||
}; | ||
/** | ||
* @return {LinkedResponse} | ||
*/ | ||
LinkedResponse.decode = function (record) { | ||
@@ -280,4 +388,14 @@ var node, lane, prio, rate; | ||
} | ||
return null; | ||
}; | ||
/** | ||
* @constructor | ||
* @extends {RequestEnvelope} | ||
* @param {*} node | ||
* @param {*} lane | ||
* @param {number=} prio | ||
* @param {number=} rate | ||
* @param {*=} body | ||
*/ | ||
export function SyncRequest(node, lane, prio, rate, body) { | ||
@@ -293,3 +411,8 @@ RequestEnvelope.call(this); | ||
SyncRequest.prototype.constructor = SyncRequest; | ||
Object.defineProperty(SyncRequest.prototype, 'isSyncRequest', {value: true}); | ||
SyncRequest.prototype.isSyncRequest = true; | ||
/** | ||
* @param {*=} node | ||
* @param {*=} lane | ||
* @return {!SyncRequest} | ||
*/ | ||
SyncRequest.prototype.withAddress = function (node, lane) { | ||
@@ -305,11 +428,16 @@ if (node === undefined) { | ||
SyncRequest.prototype.encode = function () { | ||
var headers = {node: this.node, lane: this.lane}; | ||
var headers = {}; | ||
headers['node'] = this.node; | ||
headers['lane'] = this.lane; | ||
if (this.prio !== undefined && this.prio !== 0) { | ||
headers.prio = this.prio; | ||
headers['prio'] = this.prio; | ||
} | ||
if (this.rate !== undefined && this.rate !== 0) { | ||
headers.rate = this.rate; | ||
headers['rate'] = this.rate; | ||
} | ||
return Recon.concat({'@sync': headers}, this.body); | ||
}; | ||
/** | ||
* @return {SyncRequest} | ||
*/ | ||
SyncRequest.decode = function (record) { | ||
@@ -337,4 +465,12 @@ var node, lane, prio, rate; | ||
} | ||
return null; | ||
}; | ||
/** | ||
* @constructor | ||
* @extends {ResponseEnvelope} | ||
* @param {*} node | ||
* @param {*} lane | ||
* @param {*=} body | ||
*/ | ||
export function SyncedResponse(node, lane, body) { | ||
@@ -348,3 +484,8 @@ ResponseEnvelope.call(this); | ||
SyncedResponse.prototype.constructor = SyncedResponse; | ||
Object.defineProperty(SyncedResponse.prototype, 'isSyncedResponse', {value: true}); | ||
SyncedResponse.prototype.isSyncedResponse = true; | ||
/** | ||
* @param {*=} node | ||
* @param {*=} lane | ||
* @return {!SyncedResponse} | ||
*/ | ||
SyncedResponse.prototype.withAddress = function (node, lane) { | ||
@@ -360,5 +501,10 @@ if (node === undefined) { | ||
SyncedResponse.prototype.encode = function () { | ||
var headers = {node: this.node, lane: this.lane}; | ||
var headers = {}; | ||
headers['node'] = this.node; | ||
headers['lane'] = this.lane; | ||
return Recon.concat({'@synced': headers}, this.body); | ||
}; | ||
/** | ||
* @return {SyncedResponse} | ||
*/ | ||
SyncedResponse.decode = function (record) { | ||
@@ -382,4 +528,12 @@ var node, lane; | ||
} | ||
return null; | ||
}; | ||
/** | ||
* @constructor | ||
* @extends {RequestEnvelope} | ||
* @param {*} node | ||
* @param {*} lane | ||
* @param {*=} body | ||
*/ | ||
export function UnlinkRequest(node, lane, body) { | ||
@@ -393,3 +547,8 @@ RequestEnvelope.call(this); | ||
UnlinkRequest.prototype.constructor = UnlinkRequest; | ||
Object.defineProperty(UnlinkRequest.prototype, 'isUnlinkRequest', {value: true}); | ||
UnlinkRequest.prototype.isUnlinkRequest = true; | ||
/** | ||
* @param {*=} node | ||
* @param {*=} lane | ||
* @return {!UnlinkRequest} | ||
*/ | ||
UnlinkRequest.prototype.withAddress = function (node, lane) { | ||
@@ -405,5 +564,10 @@ if (node === undefined) { | ||
UnlinkRequest.prototype.encode = function () { | ||
var headers = {node: this.node, lane: this.lane}; | ||
var headers = {}; | ||
headers['node'] = this.node; | ||
headers['lane'] = this.lane; | ||
return Recon.concat({'@unlink': headers}, this.body); | ||
}; | ||
/** | ||
* @return {UnlinkRequest} | ||
*/ | ||
UnlinkRequest.decode = function (record) { | ||
@@ -427,5 +591,12 @@ var node, lane; | ||
} | ||
return null; | ||
}; | ||
/** | ||
* @constructor | ||
* @extends {ResponseEnvelope} | ||
* @param {*} node | ||
* @param {*} lane | ||
* @param {*=} body | ||
*/ | ||
export function UnlinkedResponse(node, lane, body) { | ||
@@ -439,3 +610,8 @@ ResponseEnvelope.call(this); | ||
UnlinkedResponse.prototype.constructor = UnlinkedResponse; | ||
Object.defineProperty(UnlinkedResponse.prototype, 'isUnlinkedResponse', {value: true}); | ||
UnlinkedResponse.prototype.isUnlinkedResponse = true; | ||
/** | ||
* @param {*=} node | ||
* @param {*=} lane | ||
* @return {!UnlinkedResponse} | ||
*/ | ||
UnlinkedResponse.prototype.withAddress = function (node, lane) { | ||
@@ -451,5 +627,10 @@ if (node === undefined) { | ||
UnlinkedResponse.prototype.encode = function () { | ||
var headers = {node: this.node, lane: this.lane}; | ||
var headers = {}; | ||
headers['node'] = this.node; | ||
headers['lane'] = this.lane; | ||
return Recon.concat({'@unlinked': headers}, this.body); | ||
}; | ||
/** | ||
* @return {UnlinkedResponse} | ||
*/ | ||
UnlinkedResponse.decode = function (record) { | ||
@@ -473,4 +654,10 @@ var node, lane; | ||
} | ||
return null; | ||
}; | ||
/** | ||
* @constructor | ||
* @extends {RequestEnvelope} | ||
* @param {*=} body | ||
*/ | ||
export function AuthRequest(body) { | ||
@@ -482,6 +669,9 @@ RequestEnvelope.call(this); | ||
AuthRequest.prototype.constructor = AuthRequest; | ||
Object.defineProperty(AuthRequest.prototype, 'isAuthRequest', {value: true}); | ||
AuthRequest.prototype.isAuthRequest = true; | ||
AuthRequest.prototype.encode = function () { | ||
return Recon.concat({'@auth': null}, this.body); | ||
}; | ||
/** | ||
* @return {AuthRequest} | ||
*/ | ||
AuthRequest.decode = function (record) { | ||
@@ -493,4 +683,10 @@ var headers = Recon.headers(record, '@auth'); | ||
} | ||
return null; | ||
}; | ||
/** | ||
* @constructor | ||
* @extends {ResponseEnvelope} | ||
* @param {*=} body | ||
*/ | ||
export function AuthedResponse(body) { | ||
@@ -502,6 +698,9 @@ ResponseEnvelope.call(this); | ||
AuthedResponse.prototype.constructor = AuthedResponse; | ||
Object.defineProperty(AuthedResponse.prototype, 'isAuthedResponse', {value: true}); | ||
AuthedResponse.prototype.isAuthedResponse = true; | ||
AuthedResponse.prototype.encode = function () { | ||
return Recon.concat({'@authed': null}, this.body); | ||
}; | ||
/** | ||
* @return {AuthedResponse} | ||
*/ | ||
AuthedResponse.decode = function (record) { | ||
@@ -513,4 +712,10 @@ var headers = Recon.headers(record, '@authed'); | ||
} | ||
return null; | ||
}; | ||
/** | ||
* @constructor | ||
* @extends {RequestEnvelope} | ||
* @param {*=} body | ||
*/ | ||
export function DeauthRequest(body) { | ||
@@ -522,6 +727,9 @@ RequestEnvelope.call(this); | ||
DeauthRequest.prototype.constructor = DeauthRequest; | ||
Object.defineProperty(DeauthRequest.prototype, 'isDeauthRequest', {value: true}); | ||
DeauthRequest.prototype.isDeauthRequest = true; | ||
DeauthRequest.prototype.encode = function () { | ||
return Recon.concat({'@deauth': null}, this.body); | ||
}; | ||
/** | ||
* @return {DeauthRequest} | ||
*/ | ||
DeauthRequest.decode = function (record) { | ||
@@ -533,4 +741,10 @@ var headers = Recon.headers(record, '@deauth'); | ||
} | ||
return null; | ||
}; | ||
/** | ||
* @constructor | ||
* @extends {ResponseEnvelope} | ||
* @param {*=} body | ||
*/ | ||
export function DeauthedResponse(body) { | ||
@@ -542,6 +756,9 @@ ResponseEnvelope.call(this); | ||
DeauthedResponse.prototype.constructor = DeauthedResponse; | ||
Object.defineProperty(DeauthedResponse.prototype, 'isDeauthedResponse', {value: true}); | ||
DeauthedResponse.prototype.isDeauthedResponse = true; | ||
DeauthedResponse.prototype.encode = function () { | ||
return Recon.concat({'@deauthed': null}, this.body); | ||
}; | ||
/** | ||
* @return {DeauthedResponse} | ||
*/ | ||
DeauthedResponse.decode = function (record) { | ||
@@ -553,2 +770,3 @@ var headers = Recon.headers(record, '@deauthed'); | ||
} | ||
return null; | ||
}; |
import {DownlinkModel, DownlinkView} from './downlink'; | ||
/** | ||
* @constructor | ||
* @extends {DownlinkModel} | ||
* @param {!./downlink.DownlinkContext} context | ||
* @param {string} hostUri | ||
* @param {string} nodeUri | ||
* @param {string} laneUri | ||
* @param {number} prio | ||
* @param {number} rate | ||
* @paran {*} body | ||
*/ | ||
export function EventDownlinkModel(context, hostUri, nodeUri, laneUri, prio, rate, body) { | ||
@@ -9,2 +20,11 @@ DownlinkModel.call(this, context, hostUri, nodeUri, laneUri, prio, rate, body); | ||
/** | ||
* @constructor | ||
* @extends {DownlinkView} | ||
* @param {!./downlink.DownlinkContext} context | ||
* @param {./downlink.DownlinkScope} scope | ||
* @param {Object} props | ||
* @param {{keepSynced: (boolean|undefined)}} options | ||
* @param {Object} delegate | ||
*/ | ||
export function EventDownlinkView(context, scope, props, options, delegate) { | ||
@@ -11,0 +31,0 @@ DownlinkView.call(this, context, scope, props, options, delegate); |
import * as Recon from 'recon-js'; | ||
import {DownlinkModel, DownlinkView} from './downlink'; | ||
/** | ||
* @param {*} value | ||
* @return {boolean} | ||
*/ | ||
function isInteger(value) { | ||
@@ -8,6 +12,20 @@ return typeof value === 'number' && isFinite(value) && Math.floor(value) === value; | ||
/** | ||
* @constructor | ||
* @extends {DownlinkModel} | ||
* @param {!./downlink.DownlinkContext} context | ||
* @param {string} hostUri | ||
* @param {string} nodeUri | ||
* @param {string} laneUri | ||
* @param {number} prio | ||
* @param {number} rate | ||
* @paran {*= body | ||
* @param {Array<{id: *}>} initialRefs | ||
* @param {Array<*>} initialState | ||
* @param {function(*):!{id: *}} makeRef | ||
*/ | ||
export function ListDownlinkModel(context, hostUri, nodeUri, laneUri, prio, rate, body, initialRefs, initialState, makeRef) { | ||
DownlinkModel.call(this, context, hostUri, nodeUri, laneUri, prio, rate, body); | ||
this.setRefs(initialRefs || []); | ||
this.setState(initialState || []); | ||
this.refs = initialRefs || []; | ||
this.state = initialState || []; | ||
if (makeRef) { | ||
@@ -20,3 +38,3 @@ this.makeRef = makeRef; | ||
Object.defineProperty(ListDownlinkModel.prototype, 'length', { | ||
get: function () { | ||
get: /** @this {ListDownlinkModel} */ function () { | ||
return this.state.length; | ||
@@ -27,5 +45,14 @@ }, | ||
}); | ||
/** | ||
* @param {number} index | ||
* @return {*} | ||
*/ | ||
ListDownlinkModel.prototype.get = function (index) { | ||
return this.state[index]; | ||
}; | ||
/** | ||
* @param {number} index | ||
* @param {*} newValue | ||
* @return {this} | ||
*/ | ||
ListDownlinkModel.prototype.set = function (index, newValue) { | ||
@@ -51,4 +78,8 @@ if (!isInteger(index)) { | ||
}; | ||
ListDownlinkModel.prototype.insert = function () { | ||
var start = arguments[0]; | ||
/** | ||
* @param {number} start | ||
* @param {...*} var_args | ||
* @return {this} | ||
*/ | ||
ListDownlinkModel.prototype.insert = function (start, var_args) { | ||
if (!isInteger(start)) { | ||
@@ -73,3 +104,7 @@ throw new TypeError('start'); | ||
}; | ||
ListDownlinkModel.prototype.push = function () { | ||
/** | ||
* @param {...*} var_args | ||
* @return {number} | ||
*/ | ||
ListDownlinkModel.prototype.push = function (var_args) { | ||
for (var i = 0, n = arguments.length; i < n; i += 1) { | ||
@@ -87,2 +122,5 @@ var index = this.state.length; | ||
}; | ||
/** | ||
* @return {*} | ||
*/ | ||
ListDownlinkModel.prototype.pop = function () { | ||
@@ -100,3 +138,7 @@ var index = this.state.length - 1; | ||
}; | ||
ListDownlinkModel.prototype.unshift = function () { | ||
/** | ||
* @param {...*} var_args | ||
* @return {number} | ||
*/ | ||
ListDownlinkModel.prototype.unshift = function (var_args) { | ||
for (var i = arguments.length - 1; i >= 0; i -= 1) { | ||
@@ -113,2 +155,5 @@ var newValue = arguments[i]; | ||
}; | ||
/** | ||
* @return {*} | ||
*/ | ||
ListDownlinkModel.prototype.shift = function () { | ||
@@ -125,2 +170,7 @@ if (this.state.length === 0) { | ||
}; | ||
/** | ||
* @param {number} fromIndex | ||
* @param {number} toIndex | ||
* @return {this} | ||
*/ | ||
ListDownlinkModel.prototype.move = function (fromIndex, toIndex) { | ||
@@ -144,6 +194,10 @@ if (fromIndex < 0 || fromIndex >= this.state.length) { | ||
this.listDidMove(fromIndex, toIndex, value); | ||
this.command({'@move': {id: ref.id, from: fromIndex, to: toIndex}}); | ||
this.command({'@move': {'id': ref.id, 'from': fromIndex, 'to': toIndex}}); | ||
return this; | ||
}; | ||
ListDownlinkModel.prototype.splice = function () { | ||
/** | ||
* @param {...*} var_args | ||
* @return {*} | ||
*/ | ||
ListDownlinkModel.prototype.splice = function (var_args) { | ||
var start = arguments[0]; | ||
@@ -197,2 +251,6 @@ if (!isInteger(start)) { | ||
}; | ||
/** | ||
* @param {function (*, number=, !ListDownlinkModel=)} callback | ||
* @param {*=} thisArg | ||
*/ | ||
ListDownlinkModel.prototype.forEach = function (callback, thisArg) { | ||
@@ -203,2 +261,6 @@ for (var i = 0, n = this.state.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {*} newValue | ||
* @return {!{id: *}} | ||
*/ | ||
ListDownlinkModel.prototype.makeRef = function (newValue) { | ||
@@ -213,10 +275,20 @@ // Randomly generate a 24-bit item ID | ||
}; | ||
/** | ||
* @param {number} index | ||
* @return {{id: *}} | ||
*/ | ||
ListDownlinkModel.prototype.getRef = function (index) { | ||
return this.refs[index]; | ||
}; | ||
/** | ||
* @param {!Array<!{id: *}>} refs | ||
*/ | ||
ListDownlinkModel.prototype.setRefs = function (refs) { | ||
Object.defineProperty(this, 'refs', {value: refs, configurable: true, enumerable: true}); | ||
this.refs = refs; | ||
}; | ||
/** | ||
* @param {!Array<*>} state | ||
*/ | ||
ListDownlinkModel.prototype.setState = function (state) { | ||
Object.defineProperty(this, 'state', {value: state, configurable: true, enumerable: true}); | ||
this.state = state; | ||
}; | ||
@@ -260,2 +332,7 @@ ListDownlinkModel.prototype.onEventMessage = function (message) { | ||
}; | ||
/** | ||
* @param {*} id | ||
* @param {number} index | ||
* @param {*} newValue | ||
*/ | ||
ListDownlinkModel.prototype.onUpdateEvent = function (id, index, newValue) { | ||
@@ -267,2 +344,7 @@ newValue = this.listWillUpdate(index, newValue); | ||
}; | ||
/** | ||
* @param {*} id | ||
* @param {number} index | ||
* @param {*} newValue | ||
*/ | ||
ListDownlinkModel.prototype.onInsertEvent = function (id, index, newValue) { | ||
@@ -275,2 +357,7 @@ newValue = this.listWillInsert(index, newValue); | ||
}; | ||
/** | ||
* @param {*} id | ||
* @param {number} fromIndex | ||
* @param {number} toIndex | ||
*/ | ||
ListDownlinkModel.prototype.onMoveEvent = function (id, fromIndex, toIndex) { | ||
@@ -290,2 +377,6 @@ toIndex = Math.min(Math.max(0, toIndex), this.state.length); | ||
}; | ||
/** | ||
* @param {*} id | ||
* @param {number} index | ||
*/ | ||
ListDownlinkModel.prototype.onRemoveEvent = function (id, index) { | ||
@@ -304,2 +395,6 @@ this.listWillRemove(index); | ||
}; | ||
/** | ||
* @param {number} index | ||
* @param {*} newValue | ||
*/ | ||
ListDownlinkModel.prototype.listWillInsert = function (index, newValue) { | ||
@@ -311,2 +406,6 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {number} index | ||
* @param {*} newValue | ||
*/ | ||
ListDownlinkModel.prototype.listDidInsert = function (index, newValue) { | ||
@@ -317,2 +416,6 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {number} index | ||
* @param {*} newValue | ||
*/ | ||
ListDownlinkModel.prototype.listWillUpdate = function (index, newValue) { | ||
@@ -324,2 +427,7 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {number} index | ||
* @param {*} newValue | ||
* @param {*} oldValue | ||
*/ | ||
ListDownlinkModel.prototype.listDidUpdate = function (index, newValue, oldValue) { | ||
@@ -330,2 +438,7 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {number} fromIndex | ||
* @param {number} toIndex | ||
* @param {*} value | ||
*/ | ||
ListDownlinkModel.prototype.listWillMove = function (fromIndex, toIndex, value) { | ||
@@ -336,2 +449,7 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {number} fromIndex | ||
* @param {number} toIndex | ||
* @param {*} value | ||
*/ | ||
ListDownlinkModel.prototype.listDidMove = function (fromIndex, toIndex, value) { | ||
@@ -342,2 +460,5 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {number} index | ||
*/ | ||
ListDownlinkModel.prototype.listWillRemove = function (index) { | ||
@@ -348,2 +469,6 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {number} index | ||
* @param {*} oldValue | ||
*/ | ||
ListDownlinkModel.prototype.listDidRemove = function (index, oldValue) { | ||
@@ -364,2 +489,6 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {*} id | ||
* @param {number} index | ||
*/ | ||
ListDownlinkModel.prototype.resolveIndex = function (id, index) { | ||
@@ -379,12 +508,32 @@ var ref = this.refs[index]; | ||
export function ListDownlinkView(context, model, options) { | ||
DownlinkView.call(this, context, model, options); | ||
/** | ||
* @constructor | ||
* @extends {DownlinkView} | ||
* @param {!./downlink.DownlinkContext} context | ||
* @param {./downlink.DownlinkScope} scope | ||
* @param {Object} props | ||
* @param {{keepSynced: (boolean|undefined)}} options | ||
* @param {Object} delegate | ||
*/ | ||
export function ListDownlinkView(context, scope, props, options, delegate) { | ||
DownlinkView.call(this, context, scope, props, options, delegate); | ||
} | ||
ListDownlinkView.prototype = Object.create(DownlinkView.prototype); | ||
ListDownlinkView.prototype.constructor = ListDownlinkView; | ||
/** | ||
* @param {number} index | ||
* @return {{id: *}} | ||
*/ | ||
ListDownlinkView.prototype.getRef = function (index) { | ||
return this.model.getRef(index); | ||
}; | ||
Object.defineProperty(ListDownlinkView.prototype, 'state', { | ||
get: /** @this {ListDownlinkView} */ function () { | ||
return this.model.state; | ||
}, | ||
configurable: true, | ||
enumerable: true | ||
}); | ||
Object.defineProperty(ListDownlinkView.prototype, 'length', { | ||
get: function () { | ||
get: /** @this {ListDownlinkView} */ function () { | ||
return this.model.length; | ||
@@ -395,5 +544,14 @@ }, | ||
}); | ||
/** | ||
* @param {number} index | ||
* @return {*} | ||
*/ | ||
ListDownlinkView.prototype.get = function (index) { | ||
return this.model.get(index); | ||
}; | ||
/** | ||
* @param {number} index | ||
* @param {*} newValue | ||
* @return {this} | ||
*/ | ||
ListDownlinkView.prototype.set = function (index, newValue) { | ||
@@ -403,18 +561,42 @@ this.model.set(index, newValue); | ||
}; | ||
ListDownlinkView.prototype.push = function () { | ||
/** | ||
* @param {...*} var_args | ||
* @return {number} | ||
*/ | ||
ListDownlinkView.prototype.push = function (var_args) { | ||
return this.model.push.apply(this.model, arguments); | ||
}; | ||
/** | ||
* @return {*} | ||
*/ | ||
ListDownlinkView.prototype.pop = function () { | ||
return this.model.pop(); | ||
}; | ||
ListDownlinkView.prototype.unshift = function () { | ||
/** | ||
* @param {...*} var_args | ||
* @return {number} | ||
*/ | ||
ListDownlinkView.prototype.unshift = function (var_args) { | ||
return this.model.unshift.apply(this.model, arguments); | ||
}; | ||
/** | ||
* @return {*} | ||
*/ | ||
ListDownlinkView.prototype.shift = function () { | ||
return this.model.shift(); | ||
}; | ||
/** | ||
* @param {number} fromIndex | ||
* @param {number} toIndex | ||
* @return {this} | ||
*/ | ||
ListDownlinkView.prototype.move = function (fromIndex, toIndex) { | ||
return this.model.move(fromIndex, toIndex); | ||
this.model.move(fromIndex, toIndex); | ||
return this; | ||
}; | ||
ListDownlinkView.prototype.splice = function () { | ||
/** | ||
* @param {...*} var_args | ||
* @return {*} | ||
*/ | ||
ListDownlinkView.prototype.splice = function (var_args) { | ||
return this.model.splice.apply(this.model, arguments); | ||
@@ -425,5 +607,16 @@ }; | ||
}; | ||
/** | ||
* @param {function (*, number=, !ListDownlinkView=)} callback | ||
* @param {*=} thisArg | ||
*/ | ||
ListDownlinkView.prototype.forEach = function (callback, thisArg) { | ||
this.model.forEach(callback, thisArg); | ||
var state = this.model.state; | ||
for (var i = 0, n = state.length; i < n; i += 1) { | ||
callback.call(thisArg, state[i], i, this); | ||
} | ||
}; | ||
/** | ||
* @param {function (number, *, !ListDownlinkView=):*=} willInsert | ||
* @return {function (number, *, !ListDownlinkView=):*|this} | ||
*/ | ||
ListDownlinkView.prototype.willInsert = function (willInsert) { | ||
@@ -436,2 +629,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (number, *, !ListDownlinkView=)=} didInsert | ||
* @return {function (number, *, !ListDownlinkView=)|this} | ||
*/ | ||
ListDownlinkView.prototype.didInsert = function (didInsert) { | ||
@@ -444,2 +641,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (number, *, !ListDownlinkView=):*=} willUpdate | ||
* @return {function (number, *, !ListDownlinkView=):*|this} | ||
*/ | ||
ListDownlinkView.prototype.willUpdate = function (willUpdate) { | ||
@@ -452,2 +653,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (number, *, *=, !ListDownlinkView=)=} didUpdate | ||
* @return {function (number, *, *=, !ListDownlinkView=)|this} | ||
*/ | ||
ListDownlinkView.prototype.didUpdate = function (didUpdate) { | ||
@@ -460,2 +665,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (number, number, *=, !ListDownlinkView=)=} willMove | ||
* @return {function (number, number, *=, !ListDownlinkView=)|this} | ||
*/ | ||
ListDownlinkView.prototype.willMove = function (willMove) { | ||
@@ -468,2 +677,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (number, number, *=, !ListDownlinkView=)=} didMove | ||
* @return {function (number, number, *=, !ListDownlinkView=)|this} | ||
*/ | ||
ListDownlinkView.prototype.didMove = function (didMove) { | ||
@@ -476,2 +689,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (number, !ListDownlinkView=)=} willRemove | ||
* @return {function (number, !ListDownlinkView=)|this} | ||
*/ | ||
ListDownlinkView.prototype.willRemove = function (willRemove) { | ||
@@ -484,2 +701,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (number, *=, !ListDownlinkView=)=} didRemove | ||
* @return {function (number, *=, !ListDownlinkView=)|this} | ||
*/ | ||
ListDownlinkView.prototype.didRemove = function (didRemove) { | ||
@@ -492,2 +713,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!ListDownlinkView=)=} willClear | ||
* @return {function (!ListDownlinkView=)|this} | ||
*/ | ||
ListDownlinkView.prototype.willClear = function (willClear) { | ||
@@ -500,2 +725,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!ListDownlinkView=)=} didClear | ||
* @return {function (!ListDownlinkView=)|this} | ||
*/ | ||
ListDownlinkView.prototype.didClear = function (didClear) { | ||
@@ -508,2 +737,7 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {number} index | ||
* @param {*} newValue | ||
* @return {*} | ||
*/ | ||
ListDownlinkView.prototype.listWillInsert = function (index, newValue) { | ||
@@ -518,2 +752,6 @@ if (this.delegate && typeof this.delegate.willInsert === 'function') { | ||
}; | ||
/** | ||
* @param {number} index | ||
* @param {*} newValue | ||
*/ | ||
ListDownlinkView.prototype.listDidInsert = function (index, newValue) { | ||
@@ -524,2 +762,7 @@ if (this.delegate && typeof this.delegate.didInsert === 'function') { | ||
}; | ||
/** | ||
* @param {number} index | ||
* @param {*} newValue | ||
* @return {*} | ||
*/ | ||
ListDownlinkView.prototype.listWillUpdate = function (index, newValue) { | ||
@@ -534,2 +777,7 @@ if (this.delegate && typeof this.delegate.willUpdate === 'function') { | ||
}; | ||
/** | ||
* @param {number} index | ||
* @param {*} newValue | ||
* @param {*} oldValue | ||
*/ | ||
ListDownlinkView.prototype.listDidUpdate = function (index, newValue, oldValue) { | ||
@@ -540,2 +788,7 @@ if (this.delegate && typeof this.delegate.didUpdate === 'function') { | ||
}; | ||
/** | ||
* @param {number} fromIndex | ||
* @param {number} toIndex | ||
* @param {*} value | ||
*/ | ||
ListDownlinkView.prototype.listWillMove = function (fromIndex, toIndex, value) { | ||
@@ -546,2 +799,7 @@ if (this.delegate && typeof this.delegate.willMove === 'function') { | ||
}; | ||
/** | ||
* @param {number} fromIndex | ||
* @param {number} toIndex | ||
* @param {*} value | ||
*/ | ||
ListDownlinkView.prototype.listDidMove = function (fromIndex, toIndex, value) { | ||
@@ -552,2 +810,5 @@ if (this.delegate && typeof this.delegate.didMove === 'function') { | ||
}; | ||
/** | ||
* @param {number} index | ||
*/ | ||
ListDownlinkView.prototype.listWillRemove = function (index) { | ||
@@ -558,2 +819,6 @@ if (this.delegate && typeof this.delegate.willRemove === 'function') { | ||
}; | ||
/** | ||
* @param {number} index | ||
* @param {*} oldValue | ||
*/ | ||
ListDownlinkView.prototype.listDidRemove = function (index, oldValue) { | ||
@@ -574,2 +839,6 @@ if (this.delegate && typeof this.delegate.didRemove === 'function') { | ||
}; | ||
/** | ||
* @param {function (*):!{id: *}=} makeRef | ||
* @return {function (*):!{id: *}|this} | ||
*/ | ||
ListDownlinkView.prototype.makeRef = function (makeRef) { | ||
@@ -582,2 +851,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {Array<!{id: *}>=} initialRefs | ||
* @return {Array<!{id: *}>|this} | ||
*/ | ||
ListDownlinkView.prototype.initialRefs = function (initialRefs) { | ||
@@ -590,2 +863,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {Array<*>=} initialState | ||
* @return {Array<*>|this} | ||
*/ | ||
ListDownlinkView.prototype.initialState = function (initialState) { | ||
@@ -598,2 +875,10 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @return {void} | ||
*/ | ||
ListDownlinkView.prototype.didAliasModel = function () { | ||
this.forEach(function (value, index) { | ||
this.listDidInsert(index, value); | ||
}, this); | ||
}; | ||
ListDownlinkView.prototype.open = function () { | ||
@@ -607,2 +892,4 @@ var props = this.props; | ||
model.addDownlink(this); | ||
this.model = model; | ||
this.didAliasModel(); | ||
} else { | ||
@@ -614,4 +901,4 @@ model = new ListDownlinkModel(this.context, props.hostUri, props.nodeUri, | ||
this.context.openDownlink(model); | ||
this.model = model; | ||
} | ||
this.model = model; | ||
if (this.scope) { | ||
@@ -618,0 +905,0 @@ this.scope.addDownlink(this); |
import * as Recon from 'recon-js'; | ||
import {DownlinkModel, DownlinkView} from './downlink'; | ||
/** | ||
* @constructor | ||
* @extends {DownlinkModel} | ||
* @param {!./downlink.DownlinkContext} context | ||
* @param {string} hostUri | ||
* @param {string} nodeUri | ||
* @param {string} laneUri | ||
* @param {number} prio | ||
* @param {number} rate | ||
* @paran {*} body | ||
* @param {!Object} initialState | ||
*/ | ||
export function MapDownlinkModel(context, hostUri, nodeUri, laneUri, prio, rate, body, initialState) { | ||
DownlinkModel.call(this, context, hostUri, nodeUri, laneUri, prio, rate, body); | ||
this.setState(initialState || {}); | ||
this.state = initialState || {}; | ||
} | ||
@@ -11,3 +23,3 @@ MapDownlinkModel.prototype = Object.create(DownlinkModel.prototype); | ||
Object.defineProperty(MapDownlinkModel.prototype, 'size', { | ||
get: function () { | ||
get: /** @this {MapDownlinkModel} */ function () { | ||
return Recon.length(this.state); | ||
@@ -18,8 +30,21 @@ }, | ||
}); | ||
/** | ||
* @param {*} key | ||
* @return {boolean} | ||
*/ | ||
MapDownlinkModel.prototype.has = function (key) { | ||
return Recon.has(this.state, key); | ||
}; | ||
/** | ||
* @param {*} key | ||
* @return {*} | ||
*/ | ||
MapDownlinkModel.prototype.get = function (key) { | ||
return Recon.get(this.state, key); | ||
}; | ||
/** | ||
* @param {*} key | ||
* @param {*} newValue | ||
* @return {this} | ||
*/ | ||
MapDownlinkModel.prototype.set = function (key, newValue) { | ||
@@ -35,2 +60,6 @@ newValue = this.mapWillUpdate(key, newValue); | ||
}; | ||
/** | ||
* @param {*} key | ||
* @return {boolean} | ||
*/ | ||
MapDownlinkModel.prototype.delete = function (key) { | ||
@@ -56,13 +85,26 @@ this.mapWillRemove(key); | ||
}; | ||
/** | ||
* @return {!Array<*>} | ||
*/ | ||
MapDownlinkModel.prototype.keys = function () { | ||
return Recon.keys(this.state); | ||
}; | ||
/** | ||
* @return {!Array<*>} | ||
*/ | ||
MapDownlinkModel.prototype.values = function () { | ||
return Recon.values(this.state); | ||
}; | ||
/** | ||
* @param {function(*, *, number, *)} callback | ||
* @param {*=} thisArg | ||
*/ | ||
MapDownlinkModel.prototype.forEach = function (callback, thisArg) { | ||
Recon.forEach(this.state, callback, thisArg); | ||
}; | ||
/** | ||
* @param {!Object} state | ||
*/ | ||
MapDownlinkModel.prototype.setState = function (state) { | ||
Object.defineProperty(this, 'state', {value: state, configurable: true, enumerable: true}); | ||
this.state = state; | ||
}; | ||
@@ -84,2 +126,6 @@ MapDownlinkModel.prototype.onEventMessage = function (message) { | ||
}; | ||
/** | ||
* @param {*} key | ||
* @param {*} newValue | ||
*/ | ||
MapDownlinkModel.prototype.onUpdateEvent = function (key, newValue) { | ||
@@ -93,2 +139,5 @@ newValue = this.mapWillUpdate(key, newValue); | ||
}; | ||
/** | ||
* @param {*} key | ||
*/ | ||
MapDownlinkModel.prototype.onRemoveEvent = function (key) { | ||
@@ -107,2 +156,7 @@ this.mapWillRemove(key); | ||
}; | ||
/** | ||
* @param {*} key | ||
* @param {*} newValue | ||
* @return {*} | ||
*/ | ||
MapDownlinkModel.prototype.mapWillUpdate = function (key, newValue) { | ||
@@ -114,2 +168,7 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {*} key | ||
* @param {*} newValue | ||
* @param {*} oldValue | ||
*/ | ||
MapDownlinkModel.prototype.mapDidUpdate = function (key, newValue, oldValue) { | ||
@@ -120,2 +179,5 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {*} key | ||
*/ | ||
MapDownlinkModel.prototype.mapWillRemove = function (key) { | ||
@@ -126,2 +188,6 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {*} key | ||
* @param {*} oldValue | ||
*/ | ||
MapDownlinkModel.prototype.mapDidRemove = function (key, oldValue) { | ||
@@ -143,2 +209,11 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
/** | ||
* @constructor | ||
* @extends {DownlinkView} | ||
* @param {!./downlink.DownlinkContext} context | ||
* @param {./downlink.DownlinkScope} scope | ||
* @param {Object} props | ||
* @param {{keepSynced: (boolean|undefined)}} options | ||
* @param {Object} delegate | ||
*/ | ||
export function MapDownlinkView(context, scope, props, options, delegate) { | ||
@@ -150,3 +225,3 @@ DownlinkView.call(this, context, scope, props, options, delegate); | ||
Object.defineProperty(MapDownlinkView.prototype, 'state', { | ||
get: function () { | ||
get: /** @this {MapDownlinkView} */ function () { | ||
return this.model.state; | ||
@@ -158,3 +233,3 @@ }, | ||
Object.defineProperty(MapDownlinkView.prototype, 'size', { | ||
get: function () { | ||
get: /** @this {MapDownlinkView} */ function () { | ||
return this.model.size; | ||
@@ -165,8 +240,21 @@ }, | ||
}); | ||
/** | ||
* @param {*} key | ||
* @return {boolean} | ||
*/ | ||
MapDownlinkView.prototype.has = function (key) { | ||
return this.model.has(key); | ||
}; | ||
/** | ||
* @param {*} key | ||
* @return {*} | ||
*/ | ||
MapDownlinkView.prototype.get = function (key) { | ||
return this.model.get(key); | ||
}; | ||
/** | ||
* @param {*} key | ||
* @param {*} newValue | ||
* @return {this} | ||
*/ | ||
MapDownlinkView.prototype.set = function (key, newValue) { | ||
@@ -176,2 +264,6 @@ this.model.set(key, newValue); | ||
}; | ||
/** | ||
* @param {*} key | ||
* @return {boolean} | ||
*/ | ||
MapDownlinkView.prototype.delete = function (key) { | ||
@@ -183,11 +275,25 @@ return this.model.delete(key); | ||
}; | ||
/** | ||
* @return {!Array<*>} | ||
*/ | ||
MapDownlinkView.prototype.keys = function () { | ||
return this.model.keys(); | ||
}; | ||
/** | ||
* @return {!Array<*>} | ||
*/ | ||
MapDownlinkView.prototype.values = function () { | ||
return this.model.values(); | ||
}; | ||
/** | ||
* @param {function(*, *, number, *)} callback | ||
* @param {*=} thisArg | ||
*/ | ||
MapDownlinkView.prototype.forEach = function (callback, thisArg) { | ||
this.model.forEach(callback, thisArg); | ||
}; | ||
/** | ||
* @param {function (*, *, !MapDownlinkView=):*=} willUpdate | ||
* @return {function (*, *, !MapDownlinkView=):*|this} | ||
*/ | ||
MapDownlinkView.prototype.willUpdate = function (willUpdate) { | ||
@@ -200,2 +306,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (*, *, *=, !MapDownlinkView=)=} didUpdate | ||
* @return {function (*, *, *=, !MapDownlinkView=)|this} | ||
*/ | ||
MapDownlinkView.prototype.didUpdate = function (didUpdate) { | ||
@@ -208,2 +318,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (*, !MapDownlinkView=)=} willRemove | ||
* @return {function (*, !MapDownlinkView=)|this} | ||
*/ | ||
MapDownlinkView.prototype.willRemove = function (willRemove) { | ||
@@ -216,2 +330,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (*, *=, !MapDownlinkView=)=} didRemove | ||
* @return {function (*, *=, !MapDownlinkView=)|this} | ||
*/ | ||
MapDownlinkView.prototype.didRemove = function (didRemove) { | ||
@@ -224,2 +342,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!MapDownlinkView=)=} willClear | ||
* @return {function (!MapDownlinkView=)|this} | ||
*/ | ||
MapDownlinkView.prototype.willClear = function (willClear) { | ||
@@ -232,2 +354,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (!MapDownlinkView=)=} didClear | ||
* @return {function (!MapDownlinkView=)|this} | ||
*/ | ||
MapDownlinkView.prototype.didClear = function (didClear) { | ||
@@ -240,2 +366,7 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {*} key | ||
* @param {*} newValue | ||
* @return {*} | ||
*/ | ||
MapDownlinkView.prototype.mapWillUpdate = function (key, newValue) { | ||
@@ -250,2 +381,7 @@ if (this.delegate && typeof this.delegate.willUpdate === 'function') { | ||
}; | ||
/** | ||
* @param {*} key | ||
* @param {*} newValue | ||
* @param {*} oldValue | ||
*/ | ||
MapDownlinkView.prototype.mapDidUpdate = function (key, newValue, oldValue) { | ||
@@ -256,2 +392,5 @@ if (this.delegate && typeof this.delegate.didUpdate === 'function') { | ||
}; | ||
/** | ||
* @param {*} key | ||
*/ | ||
MapDownlinkView.prototype.mapWillRemove = function (key) { | ||
@@ -262,2 +401,6 @@ if (this.delegate && typeof this.delegate.willRemove === 'function') { | ||
}; | ||
/** | ||
* @param {*} key | ||
* @param {*} oldValue | ||
*/ | ||
MapDownlinkView.prototype.mapDidRemove = function (key, oldValue) { | ||
@@ -278,2 +421,6 @@ if (this.delegate && typeof this.delegate.didRemove === 'function') { | ||
}; | ||
/** | ||
* @param {!Object=} initialState | ||
* @return {Object|undefined} | ||
*/ | ||
MapDownlinkView.prototype.initialState = function (initialState) { | ||
@@ -286,2 +433,10 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @return {void} | ||
*/ | ||
MapDownlinkView.prototype.didAliasModel = function () { | ||
this.forEach(function (key, value) { | ||
this.mapDidUpdate(key, value, undefined); | ||
}, this); | ||
}; | ||
MapDownlinkView.prototype.open = function () { | ||
@@ -295,2 +450,4 @@ var props = this.props; | ||
model.addDownlink(this); | ||
this.model = model; | ||
this.didAliasModel(); | ||
} else { | ||
@@ -301,4 +458,4 @@ model = new MapDownlinkModel(this.context, props.hostUri, props.nodeUri, | ||
this.context.openDownlink(model); | ||
this.model = model; | ||
} | ||
this.model = model; | ||
if (this.scope) { | ||
@@ -305,0 +462,0 @@ this.scope.addDownlink(this); |
@@ -17,51 +17,161 @@ import * as Recon from 'recon-js'; | ||
/** | ||
* @interface | ||
*/ | ||
export function HostContext() {} | ||
/** | ||
* @param {!AuthedResponse} response | ||
* @param {!RemoteHost} host | ||
*/ | ||
HostContext.prototype.hostDidAuthenticate = function (response, host) {}; | ||
/** | ||
* @param {!DeauthedResponse} response | ||
* @param {!RemoteHost} host | ||
*/ | ||
HostContext.prototype.hostDidDeauthenticate = function (response, host) {}; | ||
/** | ||
* @param {!RemoteHost} host | ||
*/ | ||
HostContext.prototype.hostDidConnect = function (host) {}; | ||
/** | ||
* @param {!RemoteHost} host | ||
*/ | ||
HostContext.prototype.hostDidDisconnect = function (host) {}; | ||
/** | ||
* @param {*} error | ||
* @param {!RemoteHost} host | ||
*/ | ||
HostContext.prototype.hostDidFail = function (error, host) {}; | ||
/** | ||
* @interface | ||
*/ | ||
export function HostDownlink() {} | ||
/** | ||
* @type {string} | ||
*/ | ||
HostDownlink.prototype.nodeUri; | ||
/** | ||
* @type {string} | ||
*/ | ||
HostDownlink.prototype.laneUri; | ||
/** | ||
* @param {!EventMessage} message | ||
*/ | ||
HostDownlink.prototype.onEventMessage = function (message) {}; | ||
/** | ||
* @param {!LinkedResponse} response | ||
*/ | ||
HostDownlink.prototype.onLinkedResponse = function (response) {}; | ||
/** | ||
* @param {!SyncedResponse} response | ||
*/ | ||
HostDownlink.prototype.onSyncedResponse = function (response) {}; | ||
/** | ||
* @param {!UnlinkedResponse} response | ||
*/ | ||
HostDownlink.prototype.onUnlinkedResponse = function (response) {}; | ||
/** | ||
* @param {!RemoteHost} host | ||
*/ | ||
HostDownlink.prototype.hostDidConnect = function (host) {}; | ||
/** | ||
* @param {!RemoteHost} host | ||
*/ | ||
HostDownlink.prototype.hostDidDisconnect = function (host) {}; | ||
/** | ||
* @param {*} error | ||
* @param {!RemoteHost} host | ||
*/ | ||
HostDownlink.prototype.hostDidFail = function (error, host) {}; | ||
/** | ||
* @param {!RemoteHost} host | ||
*/ | ||
HostDownlink.prototype.openUp = function (host) {}; | ||
HostDownlink.prototype.closeUp = function () {}; | ||
/** | ||
* @abstract @constructor | ||
* @param {!HostContext} context | ||
* @param {string} hostUri | ||
* @param {!Object=} options | ||
*/ | ||
export function RemoteHost(context, hostUri, options) { | ||
Object.defineProperty(this, 'context', {value: context}); | ||
Object.defineProperty(this, 'hostUri', {value: hostUri, enumerable: true}); | ||
Object.defineProperty(this, 'options', {value: options || {}, enumerable: true}); | ||
Object.defineProperty(this, 'downlinks', {value: {}, configurable: true}); | ||
Object.defineProperty(this, 'downlinkCount', {value: 0, writable: true}); | ||
Object.defineProperty(this, 'authenticated', {value: false, enumerable: true, configurable: true}); | ||
Object.defineProperty(this, 'authentication', {value: null, enumerable: true, configurable: true}); | ||
Object.defineProperty(this, 'uriCache', {value: new Recon.UriCache(hostUri), configurable: true}); | ||
Object.defineProperty(this, 'sendBuffer', {value: [], configurable: true}); | ||
Object.defineProperty(this, 'reconnectTimer', {value: null, writable: true}); | ||
Object.defineProperty(this, 'reconnectTimeout', {value: 0, writable: true}); | ||
Object.defineProperty(this, 'idleTimer', {value: null, writable: true}); | ||
this.context = context; | ||
this.hostUri = hostUri; | ||
this.options = options || {}; | ||
this.downlinks = {}; | ||
this.downlinkCount = 0; | ||
this.authenticated = false; | ||
this.authentication = null; | ||
this.uriCache = new Recon.UriCache(hostUri); | ||
this.sendBuffer = []; | ||
this.reconnectTimer = null; | ||
this.reconnectTimeout = 0; | ||
this.idleTimer = null; | ||
} | ||
Object.defineProperty(RemoteHost.prototype, 'credentials', { | ||
get: function () { | ||
return this.options.credentials; | ||
} | ||
}); | ||
Object.defineProperty(RemoteHost.prototype, 'maxReconnectTimeout', { | ||
get: function () { | ||
return this.options.maxReconnectTimeout || 30000; | ||
} | ||
}); | ||
Object.defineProperty(RemoteHost.prototype, 'idleTimeout', { | ||
get: function () { | ||
return this.options.idleTimeout || 1000; | ||
} | ||
}); | ||
Object.defineProperty(RemoteHost.prototype, 'sendBufferSize', { | ||
get: function () { | ||
return this.options.sendBufferSize || 1024; | ||
} | ||
}); | ||
/** | ||
* @return {*} | ||
*/ | ||
RemoteHost.prototype.credentials = function () { | ||
return this.options.credentials; | ||
}; | ||
/** | ||
* @return {number} | ||
*/ | ||
RemoteHost.prototype.maxReconnectTimeout = function () { | ||
return this.options.maxReconnectTimeout || 30000; | ||
}; | ||
/** | ||
* @return {number} | ||
*/ | ||
RemoteHost.prototype.idleTimeout = function () { | ||
return this.options.idleTimeout || 1000; | ||
}; | ||
/** | ||
* @return {number} | ||
*/ | ||
RemoteHost.prototype.sendBufferSize = function () { | ||
return this.options.sendBufferSize || 1024; | ||
}; | ||
/** | ||
* @abstract | ||
* @return {boolean} | ||
*/ | ||
RemoteHost.prototype.isConnected = function () {}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
RemoteHost.prototype.isAuthenticated = function () { | ||
return this.authenticated; | ||
}; | ||
/** | ||
* @return {*} | ||
*/ | ||
RemoteHost.prototype.session = function () { | ||
return this.authentication; | ||
}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
RemoteHost.prototype.isIdle = function () { | ||
return this.sendBuffer.length === 0 && this.downlinkCount === 0; | ||
}; | ||
/** | ||
* @param {string} unresolvedUri | ||
* @return {string} | ||
*/ | ||
RemoteHost.prototype.resolve = function (unresolvedUri) { | ||
return this.uriCache.resolve(unresolvedUri); | ||
}; | ||
/** | ||
* @param {string} resolvedUri | ||
* @return {string} | ||
*/ | ||
RemoteHost.prototype.unresolve = function (resolvedUri) { | ||
return this.uriCache.unresolve(resolvedUri); | ||
}; | ||
/** | ||
* @param {*} credentials | ||
*/ | ||
RemoteHost.prototype.authenticate = function (credentials) { | ||
@@ -78,5 +188,8 @@ if (!Recon.equal(this.options.credentials, credentials)) { | ||
}; | ||
/** | ||
* @param {!HostDownlink} downlink | ||
*/ | ||
RemoteHost.prototype.openDownlink = function (downlink) { | ||
this.clearIdle(); | ||
var nodeUri = downlink.nodeUri; | ||
var nodeUri = this.resolve(downlink.nodeUri); | ||
var laneUri = downlink.laneUri; | ||
@@ -96,2 +209,3 @@ if (this.downlinkCount === 0) { | ||
this.downlinkCount += 1; | ||
downlink.openUp(this); | ||
if (this.isConnected()) { | ||
@@ -101,4 +215,7 @@ downlink.hostDidConnect(this); | ||
}; | ||
/** | ||
* #@param {!HostDownlink} downlink | ||
*/ | ||
RemoteHost.prototype.closeDownlink = function (downlink) { | ||
var nodeUri = downlink.nodeUri; | ||
var nodeUri = this.resolve(downlink.nodeUri); | ||
var laneUri = downlink.laneUri; | ||
@@ -125,2 +242,7 @@ var nodeDownlinks = this.downlinks[nodeUri]; | ||
}; | ||
/** | ||
* @param {string} nodeUri | ||
* @param {string} laneUri | ||
* @param {*} body | ||
*/ | ||
RemoteHost.prototype.command = function (nodeUri, laneUri, body) { | ||
@@ -130,2 +252,5 @@ var message = new CommandMessage(this.unresolve(nodeUri), laneUri, body); | ||
}; | ||
/** | ||
* #@param {!./envelope.Envelope} envelope | ||
*/ | ||
RemoteHost.prototype.onEnvelope = function (envelope) { | ||
@@ -160,2 +285,5 @@ if (envelope instanceof EventMessage) { | ||
}; | ||
/** | ||
* @param {!EventMessage} message | ||
*/ | ||
RemoteHost.prototype.onEventMessage = function (message) { | ||
@@ -173,8 +301,17 @@ var nodeUri = this.resolve(message.node); | ||
}; | ||
/** | ||
* @param {!CommandMessage} message | ||
*/ | ||
RemoteHost.prototype.onCommandMessage = function (message) { | ||
// TODO: client services | ||
}; | ||
/** | ||
* @param {!LinkRequest} request | ||
*/ | ||
RemoteHost.prototype.onLinkRequest = function (request) { | ||
// TODO: client services | ||
}; | ||
/** | ||
* @param {!LinkedResponse} response | ||
*/ | ||
RemoteHost.prototype.onLinkedResponse = function (response) { | ||
@@ -192,5 +329,11 @@ var nodeUri = this.resolve(response.node); | ||
}; | ||
/** | ||
* @param {!SyncRequest} request | ||
*/ | ||
RemoteHost.prototype.onSyncRequest = function (request) { | ||
// TODO: client services | ||
}; | ||
/** | ||
* @param {!SyncedResponse} response | ||
*/ | ||
RemoteHost.prototype.onSyncedResponse = function (response) { | ||
@@ -208,5 +351,11 @@ var nodeUri = this.resolve(response.node); | ||
}; | ||
/** | ||
* @param {!UnlinkRequest} request | ||
*/ | ||
RemoteHost.prototype.onUnlinkRequest = function (request) { | ||
// TODO: client services | ||
}; | ||
/** | ||
* @param {!UnlinkedResponse} response | ||
*/ | ||
RemoteHost.prototype.onUnlinkedResponse = function (response) { | ||
@@ -229,18 +378,34 @@ var nodeUri = this.resolve(response.node); | ||
}; | ||
/** | ||
* @param {!AuthRequest} request | ||
*/ | ||
RemoteHost.prototype.onAuthRequest = function (request) { | ||
// TODO: client services | ||
}; | ||
/** | ||
* @param {!AuthedResponse} response | ||
*/ | ||
RemoteHost.prototype.onAuthedResponse = function (response) { | ||
Object.defineProperty(this, 'authenticated', {value: true, enumerable: true, configurable: true}); | ||
Object.defineProperty(this, 'authentication', {value: response.body, enumerable: true, configurable: true}); | ||
this.authenticated = true; | ||
this.authentication = response.body; | ||
this.context.hostDidAuthenticate(response, this); | ||
}; | ||
/** | ||
* @param {!DeauthRequest} request | ||
*/ | ||
RemoteHost.prototype.onDeauthRequest = function (request) { | ||
// TODO: client services | ||
}; | ||
/** | ||
* @param {!DeauthedResponse} response | ||
*/ | ||
RemoteHost.prototype.onDeauthedResponse = function (response) { | ||
Object.defineProperty(this, 'authenticated', {value: false, enumerable: true, configurable: true}); | ||
Object.defineProperty(this, 'authentication', {value: null, enumerable: true, configurable: true}); | ||
this.authenticated = false; | ||
this.authentication = null; | ||
this.context.hostDidDeauthenticate(response, this); | ||
}; | ||
/** | ||
* @param {!./envelope.Envelope} envelope | ||
*/ | ||
RemoteHost.prototype.onUnknownEnvelope = function (envelope) {}; | ||
RemoteHost.prototype.onConnect = function () { | ||
@@ -258,4 +423,4 @@ this.reconnectTimeout = 0; | ||
RemoteHost.prototype.onDisconnect = function () { | ||
Object.defineProperty(this, 'authenticated', {value: false, enumerable: true, configurable: true}); | ||
Object.defineProperty(this, 'authentication', {value: null, enumerable: true, configurable: true}); | ||
this.authenticated = false; | ||
this.authentication = null; | ||
this.context.hostDidDisconnect(this); | ||
@@ -270,2 +435,5 @@ for (var nodeUri in this.downlinks) { | ||
}; | ||
/** | ||
* @param {*=} error | ||
*/ | ||
RemoteHost.prototype.onError = function (error) { | ||
@@ -286,3 +454,3 @@ this.context.hostDidFail(error, this); | ||
} else { | ||
this.reconnectTimeout = Math.min(Math.floor(1.8 * this.reconnectTimeout), this.maxReconnectTimeout); | ||
this.reconnectTimeout = Math.min(Math.floor(1.8 * this.reconnectTimeout), this.maxReconnectTimeout()); | ||
} | ||
@@ -306,3 +474,3 @@ this.reconnectTimer = setTimeout(this.open.bind(this), this.reconnectTimeout); | ||
if (!this.idleTimer && this.isConnected() && this.isIdle()) { | ||
this.idleTimer = setTimeout(this.checkIdle.bind(this), this.idleTimeout); | ||
this.idleTimer = setTimeout(this.checkIdle.bind(this), this.idleTimeout()); | ||
} | ||
@@ -315,2 +483,6 @@ }; | ||
}; | ||
/** | ||
* @abstract | ||
*/ | ||
RemoteHost.prototype.open = function () {}; | ||
RemoteHost.prototype.close = function () { | ||
@@ -328,1 +500,5 @@ this.context.closeHost(this); | ||
}; | ||
/** | ||
* @param {!./envelope.Envelope} envelope | ||
*/ | ||
RemoteHost.prototype.push = function (envelope) {}; |
180
src/scope.js
import {Uri} from 'recon-js'; | ||
import {DownlinkScope} from './downlink'; // eslint-disable-line no-unused-vars | ||
import {EventDownlinkView} from './event-downlink'; | ||
@@ -7,21 +8,37 @@ import {ListDownlinkView} from './list-downlink'; | ||
/** | ||
* @abstract @constructor | ||
* @implements {DownlinkScope} | ||
*/ | ||
export function Scope(context) { | ||
Object.defineProperty(this, 'context', {value: context}); | ||
Object.defineProperty(this, 'downlinks', {value: {}, configurable: true}); | ||
Object.defineProperty(this, 'downlinkCount', {value: 0, writable: true}); | ||
this.context = context; | ||
this.downlinks = {}; | ||
this.downlinkCount = 0; | ||
this.delegate = this; | ||
} | ||
/** | ||
* @return {boolean} | ||
*/ | ||
Scope.prototype.isConnected = function () { | ||
return this.host && this.host.isConnected(); | ||
return !!(this.host && this.host.isConnected()); | ||
}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
Scope.prototype.isAuthenticated = function () { | ||
return this.host && this.host.isAuthenticated(); | ||
return !!(this.host && this.host.isAuthenticated()); | ||
}; | ||
/** | ||
* @return {*} | ||
*/ | ||
Scope.prototype.session = function () { | ||
return this.host && this.host.session(); | ||
}; | ||
Scope.prototype.addDownlink = function (downlink) { | ||
var hostUri = downlink.hostUri; | ||
var nodeUri = downlink.nodeUri; | ||
var laneUri = downlink.laneUri; | ||
/** | ||
* @param {!./downlink.DownlinkView} view | ||
*/ | ||
Scope.prototype.addDownlink = function (view) { | ||
var hostUri = view.host(); | ||
var nodeUri = view.node(); | ||
var laneUri = view.lane(); | ||
if (this.downlinkCount === 0) { | ||
@@ -45,9 +62,12 @@ this.open(); | ||
} | ||
laneDownlinks.push(downlink); | ||
laneDownlinks.push(view); | ||
this.downlinkCount += 1; | ||
}; | ||
Scope.prototype.removeDownlink = function (downlink) { | ||
var hostUri = downlink.hostUri; | ||
var nodeUri = downlink.nodeUri; | ||
var laneUri = downlink.laneUri; | ||
/** | ||
* @param {!./downlink.DownlinkView} view | ||
*/ | ||
Scope.prototype.removeDownlink = function (view) { | ||
var hostUri = view.host(); | ||
var nodeUri = view.node(); | ||
var laneUri = view.lane(); | ||
var hostDownlinks = this.downlinks[hostUri]; | ||
@@ -60,3 +80,3 @@ if (hostDownlinks) { | ||
for (var i = 0; i < laneDownlinks.length; i += 1) { | ||
if (laneDownlinks[i] === downlink) { | ||
if (laneDownlinks[i] === view) { | ||
this.downlinkCount -= 1; | ||
@@ -83,4 +103,32 @@ laneDownlinks.splice(i, 1); | ||
}; | ||
/** | ||
* @abstract | ||
* @return {!EventDownlinkView} | ||
*/ | ||
Scope.prototype.downlink = function () {}; | ||
/** | ||
* @abstract | ||
* @return {!ListDownlinkView} | ||
*/ | ||
Scope.prototype.downlinkList = function () {}; | ||
/** | ||
* @abstract | ||
* @return {!MapDownlinkView} | ||
*/ | ||
Scope.prototype.downlinkMap = function () {}; | ||
/** | ||
* @abstract | ||
* @return {!ValueDownlinkView} | ||
*/ | ||
Scope.prototype.downlinkValue = function () {}; | ||
/** | ||
* @abstract | ||
* @param {*} credentials | ||
*/ | ||
Scope.prototype.authenticate = function (credentials) {}; | ||
/** | ||
* @param {!./remote-host.RemoteHost} host | ||
*/ | ||
Scope.prototype.hostDidConnect = function (host) { | ||
Object.defineProperty(this, 'host', {value: host, configurable: true}); | ||
this.host = host; | ||
if (this.delegate && typeof this.delegate.didConnect === 'function') { | ||
@@ -90,14 +138,25 @@ this.delegate.didConnect(); | ||
}; | ||
Scope.prototype.hostDidAuthenticate = function (message, host) { | ||
/** | ||
* @param {!./envelope.AuthedResponse} response | ||
* @param {!./remote-host.RemoteHost} host | ||
*/ | ||
Scope.prototype.hostDidAuthenticate = function (response, host) { | ||
if (this.delegate && typeof this.delegate.didAuthenticate === 'function') { | ||
this.delegate.didAuthenticate(message.body); | ||
this.delegate.didAuthenticate(response.body); | ||
} | ||
}; | ||
Scope.prototype.hostDidDeauthenticate = function (message, host) { | ||
/** | ||
* @param {!./envelope.DeauthedResponse} response | ||
* @param {!./remote-host.RemoteHost} host | ||
*/ | ||
Scope.prototype.hostDidDeauthenticate = function (response, host) { | ||
if (this.delegate && typeof this.delegate.didDeauthenticate === 'function') { | ||
this.delegate.didDeauthenticate(message.body); | ||
this.delegate.didDeauthenticate(response.body); | ||
} | ||
}; | ||
/** | ||
* @param {!./remote-host.RemoteHost} host | ||
*/ | ||
Scope.prototype.hostDidDisconnect = function (host) { | ||
Object.defineProperty(this, 'host', {value: null, configurable: true}); | ||
this.host = null; | ||
if (this.delegate && typeof this.delegate.didDisconnect === 'function') { | ||
@@ -107,2 +166,6 @@ this.delegate.didDisconnect(); | ||
}; | ||
/** | ||
* @param {*} error | ||
* @param {!./remote-host.RemoteHost} host | ||
*/ | ||
Scope.prototype.hostDidFail = function (error, host) { | ||
@@ -122,3 +185,3 @@ if (this.delegate && typeof this.delegate.didFail === 'function') { | ||
var downlinks = this.downlinks; | ||
Object.defineProperty(this, 'downlinks', {value: {}, configurable: true}); | ||
this.downlinks = {}; | ||
for (var hostUri in downlinks) { | ||
@@ -138,15 +201,31 @@ var hostDownlinks = downlinks[hostUri]; | ||
/** | ||
* @constructor | ||
* @extends {Scope} | ||
*/ | ||
export function HostScope(context, hostUri) { | ||
Scope.call(this, context); | ||
Object.defineProperty(this, 'hostUri', {value: hostUri, enumerable: true}); | ||
Object.defineProperty(this, 'props', {value: Object.freeze({hostUri: hostUri})}); | ||
this.hostUri = hostUri; | ||
this.props = {hostUri: hostUri}; | ||
} | ||
HostScope.prototype = Object.create(Scope.prototype); | ||
HostScope.prototype.constructor = HostScope; | ||
/** | ||
* @return {string} | ||
*/ | ||
HostScope.prototype.host = function () { | ||
return this.hostUri; | ||
}; | ||
/** | ||
* @param {string} nodeUri | ||
* @return {!NodeScope} | ||
*/ | ||
HostScope.prototype.node = function (nodeUri) { | ||
return new NodeScope(this.context, this.hostUri, Uri.resolveUri(this.hostUri, nodeUri)); | ||
}; | ||
/** | ||
* @param {string} nodeUri | ||
* @param {string} laneUri | ||
* @return {!LaneScope} | ||
*/ | ||
HostScope.prototype.lane = function (nodeUri, laneUri) { | ||
@@ -167,2 +246,7 @@ return new LaneScope(this.context, this.hostUri, Uri.resolveUri(this.hostUri, nodeUri), laneUri); | ||
}; | ||
/** | ||
* @param {string} nodeUri | ||
* @param {string} laneUri | ||
* @param {*=} body | ||
*/ | ||
HostScope.prototype.command = function (nodeUri, laneUri, body) { | ||
@@ -175,16 +259,30 @@ this.context.command(Uri.resolveUri(this.hostUri, nodeUri), laneUri, body); | ||
/** | ||
* @constructor | ||
* @extends {Scope} | ||
*/ | ||
export function NodeScope(context, hostUri, nodeUri) { | ||
Scope.call(this, context); | ||
Object.defineProperty(this, 'hostUri', {value: hostUri, enumerable: true}); | ||
Object.defineProperty(this, 'nodeUri', {value: nodeUri, enumerable: true}); | ||
Object.defineProperty(this, 'props', {value: Object.freeze({hostUri: hostUri, nodeUri: nodeUri})}); | ||
this.hostUri = hostUri; | ||
this.nodeUri = nodeUri; | ||
this.props = {hostUri: hostUri, nodeUri: nodeUri}; | ||
} | ||
NodeScope.prototype = Object.create(Scope.prototype); | ||
NodeScope.prototype.constructor = NodeScope; | ||
/** | ||
* @return {string} | ||
*/ | ||
NodeScope.prototype.host = function () { | ||
return this.hostUri; | ||
}; | ||
/** | ||
* @return {string} | ||
*/ | ||
NodeScope.prototype.node = function () { | ||
return this.nodeUri; | ||
}; | ||
/** | ||
* @param {string} laneUri | ||
* @return {!LaneScope} | ||
*/ | ||
NodeScope.prototype.lane = function (laneUri) { | ||
@@ -205,2 +303,6 @@ return new LaneScope(this.context, this.hostUri, this.nodeUri, laneUri); | ||
}; | ||
/** | ||
* @param {string} laneUri | ||
* @param {*=} body | ||
*/ | ||
NodeScope.prototype.command = function (laneUri, body) { | ||
@@ -213,17 +315,30 @@ this.context.command(this.nodeUri, laneUri, body); | ||
/** | ||
* @constructor | ||
* @extends {Scope} | ||
*/ | ||
export function LaneScope(context, hostUri, nodeUri, laneUri) { | ||
Scope.call(this, context); | ||
Object.defineProperty(this, 'hostUri', {value: hostUri, enumerable: true}); | ||
Object.defineProperty(this, 'nodeUri', {value: nodeUri, enumerable: true}); | ||
Object.defineProperty(this, 'laneUri', {value: laneUri, enumerable: true}); | ||
Object.defineProperty(this, 'props', {value: Object.freeze({hostUri: hostUri, nodeUri: nodeUri, laneUri: laneUri})}); | ||
this.hostUri = hostUri; | ||
this.nodeUri = nodeUri; | ||
this.laneUri = laneUri; | ||
this.props = {hostUri: hostUri, nodeUri: nodeUri, laneUri: laneUri}; | ||
} | ||
LaneScope.prototype = Object.create(Scope.prototype); | ||
LaneScope.prototype.constructor = LaneScope; | ||
/** | ||
* @return {string} | ||
*/ | ||
LaneScope.prototype.host = function () { | ||
return this.hostUri; | ||
}; | ||
/** | ||
* @return {string} | ||
*/ | ||
LaneScope.prototype.node = function () { | ||
return this.nodeUri; | ||
}; | ||
/** | ||
* @return {string} | ||
*/ | ||
LaneScope.prototype.lane = function () { | ||
@@ -244,2 +359,5 @@ return this.laneUri; | ||
}; | ||
/** | ||
* @param {*=} body | ||
*/ | ||
LaneScope.prototype.command = function (body) { | ||
@@ -246,0 +364,0 @@ this.context.command(this.nodeUri, this.laneUri, body); |
import {DownlinkModel, DownlinkView} from './downlink'; | ||
/** | ||
* @constructor | ||
* @extends {DownlinkModel} | ||
* @param {!./downlink.DownlinkContext} context | ||
* @param {string} hostUri | ||
* @param {string} nodeUri | ||
* @param {string} laneUri | ||
* @param {number} prio | ||
* @param {number} rate | ||
* @paran {*} body | ||
* @param {*} initialState | ||
*/ | ||
export function ValueDownlinkModel(context, hostUri, nodeUri, laneUri, prio, rate, body, initialState) { | ||
DownlinkModel.call(this, context, hostUri, nodeUri, laneUri, prio, rate, body); | ||
this.setState(initialState); | ||
this.state = initialState; | ||
} | ||
ValueDownlinkModel.prototype = Object.create(DownlinkModel.prototype); | ||
ValueDownlinkModel.prototype.constructor = ValueDownlinkModel; | ||
/** | ||
* @return {*} | ||
*/ | ||
ValueDownlinkModel.prototype.get = function () { | ||
return this.state; | ||
}; | ||
/** | ||
* @param {*} newValue | ||
*/ | ||
ValueDownlinkModel.prototype.set = function (newValue) { | ||
@@ -19,4 +37,7 @@ newValue = this.valueWillSet(newValue); | ||
}; | ||
/** | ||
* @param {*} state | ||
*/ | ||
ValueDownlinkModel.prototype.setState = function (state) { | ||
Object.defineProperty(this, 'state', {value: state, configurable: true, enumerable: true}); | ||
this.state = state; | ||
}; | ||
@@ -27,2 +48,5 @@ ValueDownlinkModel.prototype.onEventMessage = function (message) { | ||
}; | ||
/** | ||
* @param {*} newValue | ||
*/ | ||
ValueDownlinkModel.prototype.onSetEvent = function (newValue) { | ||
@@ -34,2 +58,5 @@ newValue = this.valueWillSet(newValue); | ||
}; | ||
/** | ||
* @param {*} newValue | ||
*/ | ||
ValueDownlinkModel.prototype.valueWillSet = function (newValue) { | ||
@@ -41,2 +68,6 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
}; | ||
/** | ||
* @param {*} newValue | ||
* @param {*} oldValue | ||
*/ | ||
ValueDownlinkModel.prototype.valueDidSet = function (newValue, oldValue) { | ||
@@ -48,2 +79,11 @@ for (var i = 0, n = this.views.length; i < n; i += 1) { | ||
/** | ||
* @constructor | ||
* @extends {DownlinkView} | ||
* @param {!./downlink.DownlinkContext} context | ||
* @param {./downlink.DownlinkScope} scope | ||
* @param {Object} props | ||
* @param {{keepSynced: (boolean|undefined)}} options | ||
* @param {Object} delegate | ||
*/ | ||
export function ValueDownlinkView(context, scope, props, options, delegate) { | ||
@@ -54,11 +94,24 @@ DownlinkView.call(this, context, scope, props, options, delegate); | ||
ValueDownlinkView.prototype.constructor = ValueDownlinkView; | ||
/** | ||
* @return {*} | ||
*/ | ||
ValueDownlinkView.prototype.get = function () { | ||
return this.model.get(); | ||
}; | ||
/** | ||
* @param {*} newValue | ||
*/ | ||
ValueDownlinkView.prototype.set = function (newValue) { | ||
this.model.set(newValue); | ||
}; | ||
/** | ||
* @param {*} state | ||
*/ | ||
ValueDownlinkView.prototype.setState = function (state) { | ||
this.model.setState(state); | ||
}; | ||
/** | ||
* @param {function (*, !ValueDownlinkView=):*=} willSet | ||
* @return {function (*, !ValueDownlinkView=):*|this} | ||
*/ | ||
ValueDownlinkView.prototype.willSet = function (willSet) { | ||
@@ -71,2 +124,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {function (*, *=, !ValueDownlinkView=)=} didSet | ||
* @return {function (*, *=, !ValueDownlinkView=)|this} | ||
*/ | ||
ValueDownlinkView.prototype.didSet = function (didSet) { | ||
@@ -79,2 +136,6 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @param {*} newValue | ||
* @return {*} | ||
*/ | ||
ValueDownlinkView.prototype.valueWillSet = function (newValue) { | ||
@@ -89,2 +150,6 @@ if (this.delegate && typeof this.delegate.willSet === 'function') { | ||
}; | ||
/** | ||
* @param {*} newValue | ||
* @param {*} oldValue | ||
*/ | ||
ValueDownlinkView.prototype.valueDidSet = function (newValue, oldValue) { | ||
@@ -95,2 +160,6 @@ if (this.delegate && typeof this.delegate.didSet === 'function') { | ||
}; | ||
/** | ||
* @param {*=} initialState | ||
* @return {*|this} | ||
*/ | ||
ValueDownlinkView.prototype.initialState = function (initialState) { | ||
@@ -103,2 +172,8 @@ if (!arguments.length) { | ||
}; | ||
/** | ||
* @return {void} | ||
*/ | ||
ValueDownlinkView.prototype.didAliasModel = function () { | ||
this.valueDidSet(this.get(), undefined); | ||
}; | ||
ValueDownlinkView.prototype.open = function () { | ||
@@ -112,2 +187,4 @@ var props = this.props; | ||
model.addDownlink(this); | ||
this.model = model; | ||
this.didAliasModel(); | ||
} else { | ||
@@ -118,4 +195,4 @@ model = new ValueDownlinkModel(this.context, props.hostUri, props.nodeUri, | ||
this.context.openDownlink(model); | ||
this.model = model; | ||
} | ||
this.model = model; | ||
if (this.scope) { | ||
@@ -122,0 +199,0 @@ this.scope.addDownlink(this); |
@@ -1,2 +0,2 @@ | ||
import {RemoteHost} from './remote-host'; | ||
import {HostContext, RemoteHost} from './remote-host'; // eslint-disable-line no-unused-vars | ||
import { | ||
@@ -8,2 +8,9 @@ Envelope, | ||
/** | ||
* @constructor | ||
* @extends {RemoteHost} | ||
* @param {!HostContext} context | ||
* @param {string} hostUri | ||
* @param {!Object=} options | ||
*/ | ||
export function WebSocketHost(context, hostUri, options) { | ||
@@ -14,12 +21,16 @@ RemoteHost.call(this, context, hostUri, options); | ||
WebSocketHost.prototype.constructor = WebSocketHost; | ||
Object.defineProperty(WebSocketHost.prototype, 'WebSocket', { | ||
get: function () { | ||
/* global WebSocket, require */ | ||
return this.options.WebSocket || | ||
typeof WebSocket !== 'undefined' && WebSocket || | ||
typeof require === 'function' && require('ws'); | ||
} | ||
}); | ||
/** | ||
* @return {!function (new: WebSocket, string, *=)} | ||
*/ | ||
WebSocketHost.prototype.WebSocket = function () { | ||
/* global WebSocket, require */ | ||
return this.options.WebSocket || | ||
typeof WebSocket !== 'undefined' && WebSocket || | ||
typeof require === 'function' && require('ws'); | ||
}; | ||
/** | ||
* @return {boolean} | ||
*/ | ||
WebSocketHost.prototype.isConnected = function () { | ||
return this.socket && this.socket.readyState === this.socket.OPEN; | ||
return !!(this.socket && this.socket.readyState === this.socket.OPEN); | ||
}; | ||
@@ -29,6 +40,7 @@ WebSocketHost.prototype.open = function () { | ||
if (!this.socket) { | ||
var WebSocket = this.WebSocket(); | ||
if (this.options.protocols) { | ||
this.socket = new this.WebSocket(this.hostUri, this.options.protocols); | ||
this.socket = new WebSocket(this.hostUri, this.options.protocols); | ||
} else { | ||
this.socket = new this.WebSocket(this.hostUri); | ||
this.socket = new WebSocket(this.hostUri); | ||
} | ||
@@ -53,2 +65,5 @@ this.socket.onopen = this.onWebSocketOpen.bind(this); | ||
}; | ||
/** | ||
* @param {!Envelope} envelope | ||
*/ | ||
WebSocketHost.prototype.push = function (envelope) { | ||
@@ -61,3 +76,3 @@ if (this.isConnected()) { | ||
} else if (envelope instanceof CommandMessage) { | ||
if (this.sendBuffer.length < this.sendBufferSize) { | ||
if (this.sendBuffer.length < this.sendBufferSize()) { | ||
this.sendBuffer.push(envelope); | ||
@@ -72,3 +87,3 @@ } else { | ||
if (this.isConnected()) { | ||
var credentials = this.credentials; | ||
var credentials = this.credentials(); | ||
if (credentials) { | ||
@@ -88,2 +103,5 @@ var request = new AuthRequest(credentials); | ||
}; | ||
/** | ||
* @param {{data: *}} message | ||
*/ | ||
WebSocketHost.prototype.onWebSocketMessage = function (message) { | ||
@@ -90,0 +108,0 @@ var data = message.data; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1117496
1
23
9497
6
4