Comparing version 0.3.1 to 0.4.0
@@ -1,3 +0,3 @@ | ||
!function(t){if("object"==typeof exports)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.babble=t()}}(function(){var t;return function n(t,e,r){function i(a,u){if(!e[a]){if(!t[a]){var f="function"==typeof require&&require;if(!u&&f)return f(a,!0);if(o)return o(a,!0);throw new Error("Cannot find module '"+a+"'")}var s=e[a]={exports:{}};t[a][0].call(s.exports,function(n){var e=t[a][1][n];return i(e?e:n)},s,s.exports,n,t,e,r)}return e[a].exports}for(var o="function"==typeof require&&require,a=0;a<r.length;a++)i(r[a]);return i}({1:[function(t,n){n.exports=t("./lib/babble")},{"./lib/babble":3}],2:[function(t,n){function e(t){if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if(!t)throw new Error("id required");this.id=t,this.triggers={},this.conversations={}}var r=t("node-uuid"),i=t("./pubsub"),o=t("./block/Block"),a=t("./block/Reply"),u=t("./block/Trigger");e.prototype.subscribe=function(t,n){if("function"==typeof t&&(n=t,t=null),t||(t=i["default"]()),"function"!=typeof t.subscribe)throw new Error("pubsub must contain a function subscribe(params: {id: string, callback: function}) : function");if("function"!=typeof t.publish)throw new Error("pubsub must contain a function publish(params: {id: string, message: *})");var e=this,r=t.subscribe({id:this.id,message:function(t){var n,r;n=e.conversations[t.id],n?e._run(n,t.message):(r=e.triggers[t.message],r&&(n={id:t.id,peer:t.from,next:r,context:{from:t.from}},e._run(n,t.data)))},connect:n});if("function"!=typeof r)throw new Error("pubsub.subscribe must return a function to unsubscribe");return this.unsubscribe=r,this.publish=t.publish,this},e.prototype.unsubscribe=function(){throw new Error("Cannot unsubscribe: not subscribed")},e.prototype.publish=function(){throw new Error("Cannot publish: not subscribed")},e.prototype.listen=function(t,n){if("string"!=typeof t)throw new TypeError("Parameter message must be a string");if(!(n instanceof o))throw new TypeError("Parameter next must be a Block");this.triggers[t]=new u(n)},e.prototype.tell=function(t,n,e){this.publish(t,{from:this.id,to:t,message:n,data:e})},e.prototype.ask=function(t,n,e,i){var o=r.v4();arguments.length<4&&(i=e,e=void 0),this.conversations[o]={id:o,peer:t,next:i,context:{from:t}},this.publish(t,{id:o,from:this.id,to:t,message:n,data:e})},e.prototype._run=function(t,n){var e=t.next,r=e.run(t.context,n),i=r.result;t.next=r.block,void 0!==t.next?this.conversations[t.id]=t:delete this.conversations[t.id],e instanceof a?this.publish(t.peer,{id:t.id,from:this.id,to:t.peer,message:i}):t.next&&this._run(t,n)},n.exports=e},{"./block/Block":5,"./block/Reply":7,"./block/Trigger":8,"./pubsub":10,"node-uuid":21}],3:[function(t,n,e){var r=t("./Babbler"),i=t("./block/Reply"),o=t("./block/Action"),a=t("./block/Decision");e.babbler=function(t){return new r(t)},e.reply=function(t,n){return new i(t,n)},e.decide=function(t){return new a(t)},e.run=function(t,n){return new o(t,n)},e.Babbler=r,e.block=t("./block/index"),e.pubsub=t("./pubsub")},{"./Babbler":2,"./block/Action":4,"./block/Decision":6,"./block/Reply":7,"./block/index":9,"./pubsub":10}],4:[function(t,n){function e(t,n){if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if("function"!=typeof t)throw new TypeError("Parameter callback must be a Function");if(n&&!(n instanceof r))throw new TypeError("Parameter next must be a Block");this.callback=t,this.next=n}var r=t("./Block");e.prototype=Object.create(r.prototype),e.prototype.run=function(t,n){var e=this.callback(n,t);if(void 0!==e)throw new Error("Callback of Action must return undefined");return{result:void 0,block:this.next}},n.exports=e},{"./Block":5}],5:[function(t,n){function e(){}e.prototype.run=function(){throw new Error("Cannot run an abstract Block")},n.exports=e},{}],6:[function(t,n){function e(t){if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if("function"==typeof t);else{if(!t)throw new TypeError("Function or Object expected as first parameter");Object.keys(t).forEach(function(n){if(!(t[n]instanceof r))throw new TypeError("Decision map must contain Blocks")})}if(arguments[1]instanceof r)throw new SyntaxError("Decision doesn't accept a second parameter");this.decision=t}var r=t("./Block");e.prototype=Object.create(r.prototype),e.prototype.run=function(t,n){var e;if("function"==typeof this.decision){if(e=this.decision(n,t),e&&!(e instanceof r))throw new TypeError("Decision function must return a Block")}else e=this.decision[n];return{result:void 0,block:e}},n.exports=e},{"./Block":5}],7:[function(t,n){function e(t,n){if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if("function"!=typeof t)throw new TypeError("Parameter callback must be a Function");if(n&&!(n instanceof r))throw new TypeError("Parameter next must be a Block");this.callback=t,this.next=n}var r=t("./Block");e.prototype=Object.create(r.prototype),e.prototype.run=function(t,n){var e=this.callback(n,t);if(void 0===e)throw new Error("Callback of Reply returned undefined");return{result:e,block:this.next}},n.exports=e},{"./Block":5}],8:[function(t,n){function e(t){if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if(!(t instanceof r))throw new TypeError("Parameter next must be a Block");this.next=t}var r=t("./Block");e.prototype=Object.create(r.prototype),e.prototype.run=function(){return{result:void 0,block:this.next}},n.exports=e},{"./Block":5}],9:[function(t,n,e){e.Block=t("./Block"),e.Action=t("./Action"),e.Decision=t("./Decision"),e.Reply=t("./Reply"),e.Trigger=t("./Trigger")},{"./Action":4,"./Block":5,"./Decision":6,"./Reply":7,"./Trigger":8}],10:[function(t,n,e){e["pubsub-js"]=function(){var n=t("pubsub-js");return{subscribe:function(t){var e=n.subscribe(t.id,function(n,e){t.message(e)});return"function"==typeof t.connect&&t.connect(),function(){n.unsubscribe(e)}},publish:function(t,e){n.publish(t,e)}}},e.pubnub=function(n){var e;if("undefined"!=typeof window){if("undefined"==typeof window.PUBNUB)throw new Error("Please load pubnub first in the browser");e=window.PUBNUB}else e=t("pubnub");var r=e.init(n);return{subscribe:function(t){return r.subscribe({channel:t.id,message:t.message,connect:t.connect}),function(){r.unsubscribe(t.id)}},publish:function(t,n){r.publish({channel:t,message:n})}}},e["default"]=e["pubsub-js"]},{pubnub:"NaMlu/","pubsub-js":22}],11:[function(t,n){function e(t,n){if(t.length%a!==0){var e=t.length+(a-t.length%a);t=o.concat([t,u],e)}for(var r=[],i=n?t.readInt32BE:t.readInt32LE,f=0;f<t.length;f+=a)r.push(i.call(t,f));return r}function r(t,n,e){for(var r=new o(n),i=e?r.writeInt32BE:r.writeInt32LE,a=0;a<t.length;a++)i.call(r,t[a],4*a,!0);return r}function i(t,n,i,a){o.isBuffer(t)||(t=new o(t));var u=n(e(t,a),t.length*f);return r(u,i,a)}var o=t("buffer").Buffer,a=4,u=new o(a);u.fill(0);var f=8;n.exports={hash:i}},{buffer:18}],12:[function(t,n,e){function r(t,n,e){u.isBuffer(n)||(n=new u(n)),u.isBuffer(e)||(e=new u(e)),n.length>p?n=t(n):n.length<p&&(n=u.concat([n,d],p));for(var r=new u(p),i=new u(p),o=0;p>o;o++)r[o]=54^n[o],i[o]=92^n[o];var a=t(u.concat([r,e]));return t(u.concat([i,a]))}function i(t,n){t=t||"sha1";var e=h[t],i=[],a=0;return e||o("algorithm:",t,"is not yet supported"),{update:function(t){return u.isBuffer(t)||(t=new u(t)),i.push(t),a+=t.length,this},digest:function(t){var o=u.concat(i),a=n?r(e,n,o):e(o);return i=null,t?a.toString(t):a}}}function o(){var t=[].slice.call(arguments).join(" ");throw new Error([t,"we accept pull requests","http://github.com/dominictarr/crypto-browserify"].join("\n"))}function a(t,n){for(var e in t)n(t[e],e)}var u=t("buffer").Buffer,f=t("./sha"),s=t("./sha256"),c=t("./rng"),l=t("./md5"),h={sha1:f,sha256:s,md5:l},p=64,d=new u(p);d.fill(0),e.createHash=function(t){return i(t)},e.createHmac=function(t,n){return i(t,n)},e.randomBytes=function(t,n){if(!n||!n.call)return new u(c(t));try{n.call(this,void 0,new u(c(t)))}catch(e){n(e)}},a(["createCredentials","createCipher","createCipheriv","createDecipher","createDecipheriv","createSign","createVerify","createDiffieHellman","pbkdf2"],function(t){e[t]=function(){o("sorry,",t,"is not implemented yet")}})},{"./md5":13,"./rng":14,"./sha":15,"./sha256":16,buffer:18}],13:[function(t,n){function e(t,n){t[n>>5]|=128<<n%32,t[(n+64>>>9<<4)+14]=n;for(var e=1732584193,r=-271733879,s=-1732584194,c=271733878,l=0;l<t.length;l+=16){var h=e,p=r,d=s,g=c;e=i(e,r,s,c,t[l+0],7,-680876936),c=i(c,e,r,s,t[l+1],12,-389564586),s=i(s,c,e,r,t[l+2],17,606105819),r=i(r,s,c,e,t[l+3],22,-1044525330),e=i(e,r,s,c,t[l+4],7,-176418897),c=i(c,e,r,s,t[l+5],12,1200080426),s=i(s,c,e,r,t[l+6],17,-1473231341),r=i(r,s,c,e,t[l+7],22,-45705983),e=i(e,r,s,c,t[l+8],7,1770035416),c=i(c,e,r,s,t[l+9],12,-1958414417),s=i(s,c,e,r,t[l+10],17,-42063),r=i(r,s,c,e,t[l+11],22,-1990404162),e=i(e,r,s,c,t[l+12],7,1804603682),c=i(c,e,r,s,t[l+13],12,-40341101),s=i(s,c,e,r,t[l+14],17,-1502002290),r=i(r,s,c,e,t[l+15],22,1236535329),e=o(e,r,s,c,t[l+1],5,-165796510),c=o(c,e,r,s,t[l+6],9,-1069501632),s=o(s,c,e,r,t[l+11],14,643717713),r=o(r,s,c,e,t[l+0],20,-373897302),e=o(e,r,s,c,t[l+5],5,-701558691),c=o(c,e,r,s,t[l+10],9,38016083),s=o(s,c,e,r,t[l+15],14,-660478335),r=o(r,s,c,e,t[l+4],20,-405537848),e=o(e,r,s,c,t[l+9],5,568446438),c=o(c,e,r,s,t[l+14],9,-1019803690),s=o(s,c,e,r,t[l+3],14,-187363961),r=o(r,s,c,e,t[l+8],20,1163531501),e=o(e,r,s,c,t[l+13],5,-1444681467),c=o(c,e,r,s,t[l+2],9,-51403784),s=o(s,c,e,r,t[l+7],14,1735328473),r=o(r,s,c,e,t[l+12],20,-1926607734),e=a(e,r,s,c,t[l+5],4,-378558),c=a(c,e,r,s,t[l+8],11,-2022574463),s=a(s,c,e,r,t[l+11],16,1839030562),r=a(r,s,c,e,t[l+14],23,-35309556),e=a(e,r,s,c,t[l+1],4,-1530992060),c=a(c,e,r,s,t[l+4],11,1272893353),s=a(s,c,e,r,t[l+7],16,-155497632),r=a(r,s,c,e,t[l+10],23,-1094730640),e=a(e,r,s,c,t[l+13],4,681279174),c=a(c,e,r,s,t[l+0],11,-358537222),s=a(s,c,e,r,t[l+3],16,-722521979),r=a(r,s,c,e,t[l+6],23,76029189),e=a(e,r,s,c,t[l+9],4,-640364487),c=a(c,e,r,s,t[l+12],11,-421815835),s=a(s,c,e,r,t[l+15],16,530742520),r=a(r,s,c,e,t[l+2],23,-995338651),e=u(e,r,s,c,t[l+0],6,-198630844),c=u(c,e,r,s,t[l+7],10,1126891415),s=u(s,c,e,r,t[l+14],15,-1416354905),r=u(r,s,c,e,t[l+5],21,-57434055),e=u(e,r,s,c,t[l+12],6,1700485571),c=u(c,e,r,s,t[l+3],10,-1894986606),s=u(s,c,e,r,t[l+10],15,-1051523),r=u(r,s,c,e,t[l+1],21,-2054922799),e=u(e,r,s,c,t[l+8],6,1873313359),c=u(c,e,r,s,t[l+15],10,-30611744),s=u(s,c,e,r,t[l+6],15,-1560198380),r=u(r,s,c,e,t[l+13],21,1309151649),e=u(e,r,s,c,t[l+4],6,-145523070),c=u(c,e,r,s,t[l+11],10,-1120210379),s=u(s,c,e,r,t[l+2],15,718787259),r=u(r,s,c,e,t[l+9],21,-343485551),e=f(e,h),r=f(r,p),s=f(s,d),c=f(c,g)}return Array(e,r,s,c)}function r(t,n,e,r,i,o){return f(s(f(f(n,t),f(r,o)),i),e)}function i(t,n,e,i,o,a,u){return r(n&e|~n&i,t,n,o,a,u)}function o(t,n,e,i,o,a,u){return r(n&i|e&~i,t,n,o,a,u)}function a(t,n,e,i,o,a,u){return r(n^e^i,t,n,o,a,u)}function u(t,n,e,i,o,a,u){return r(e^(n|~i),t,n,o,a,u)}function f(t,n){var e=(65535&t)+(65535&n),r=(t>>16)+(n>>16)+(e>>16);return r<<16|65535&e}function s(t,n){return t<<n|t>>>32-n}var c=t("./helpers");n.exports=function(t){return c.hash(t,e,16)}},{"./helpers":11}],14:[function(t,n){!function(){var t,e,r=this;t=function(t){for(var n,n,e=new Array(t),r=0;t>r;r++)0==(3&r)&&(n=4294967296*Math.random()),e[r]=n>>>((3&r)<<3)&255;return e},r.crypto&&crypto.getRandomValues&&(e=function(t){var n=new Uint8Array(t);return crypto.getRandomValues(n),n}),n.exports=e||t}()},{}],15:[function(t,n){function e(t,n){t[n>>5]|=128<<24-n%32,t[(n+64>>9<<4)+15]=n;for(var e=Array(80),u=1732584193,f=-271733879,s=-1732584194,c=271733878,l=-1009589776,h=0;h<t.length;h+=16){for(var p=u,d=f,g=s,w=c,y=l,b=0;80>b;b++){e[b]=16>b?t[h+b]:a(e[b-3]^e[b-8]^e[b-14]^e[b-16],1);var v=o(o(a(u,5),r(b,f,s,c)),o(o(l,e[b]),i(b)));l=c,c=s,s=a(f,30),f=u,u=v}u=o(u,p),f=o(f,d),s=o(s,g),c=o(c,w),l=o(l,y)}return Array(u,f,s,c,l)}function r(t,n,e,r){return 20>t?n&e|~n&r:40>t?n^e^r:60>t?n&e|n&r|e&r:n^e^r}function i(t){return 20>t?1518500249:40>t?1859775393:60>t?-1894007588:-899497514}function o(t,n){var e=(65535&t)+(65535&n),r=(t>>16)+(n>>16)+(e>>16);return r<<16|65535&e}function a(t,n){return t<<n|t>>>32-n}var u=t("./helpers");n.exports=function(t){return u.hash(t,e,20,!0)}},{"./helpers":11}],16:[function(t,n){var e=t("./helpers"),r=function(t,n){var e=(65535&t)+(65535&n),r=(t>>16)+(n>>16)+(e>>16);return r<<16|65535&e},i=function(t,n){return t>>>n|t<<32-n},o=function(t,n){return t>>>n},a=function(t,n,e){return t&n^~t&e},u=function(t,n,e){return t&n^t&e^n&e},f=function(t){return i(t,2)^i(t,13)^i(t,22)},s=function(t){return i(t,6)^i(t,11)^i(t,25)},c=function(t){return i(t,7)^i(t,18)^o(t,3)},l=function(t){return i(t,17)^i(t,19)^o(t,10)},h=function(t,n){var e,i,o,h,p,d,g,w,y,b,v,m,E=new Array(1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298),B=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),I=new Array(64);t[n>>5]|=128<<24-n%32,t[(n+64>>9<<4)+15]=n;for(var y=0;y<t.length;y+=16){e=B[0],i=B[1],o=B[2],h=B[3],p=B[4],d=B[5],g=B[6],w=B[7];for(var b=0;64>b;b++)I[b]=16>b?t[b+y]:r(r(r(l(I[b-2]),I[b-7]),c(I[b-15])),I[b-16]),v=r(r(r(r(w,s(p)),a(p,d,g)),E[b]),I[b]),m=r(f(e),u(e,i,o)),w=g,g=d,d=p,p=r(h,v),h=o,o=i,i=e,e=r(v,m);B[0]=r(e,B[0]),B[1]=r(i,B[1]),B[2]=r(o,B[2]),B[3]=r(h,B[3]),B[4]=r(p,B[4]),B[5]=r(d,B[5]),B[6]=r(g,B[6]),B[7]=r(w,B[7])}return B};n.exports=function(t){return e.hash(t,h,32,!0)}},{"./helpers":11}],17:[function(t,n){t=function e(n,r,i){function o(u,f){if(!r[u]){if(!n[u]){var s="function"==typeof t&&t;if(!f&&s)return s(u,!0);if(a)return a(u,!0);throw new Error("Cannot find module '"+u+"'")}var c=r[u]={exports:{}};n[u][0].call(c.exports,function(t){var e=n[u][1][t];return o(e?e:t)},c,c.exports,e,n,r,i)}return r[u].exports}for(var a="function"==typeof t&&t,u=0;u<i.length;u++)o(i[u]);return o}({PcZj9L:[function(t,n,e){function r(t,n,e){if(!(this instanceof r))return new r(t,n,e);var i=typeof t;if("base64"===n&&"string"===i)for(t=x(t);t.length%4!==0;)t+="=";var o;if("number"===i)o=C(t);else if("string"===i)o=r.byteLength(t,n);else{if("object"!==i)throw new Error("First argument needs to be a number, array or string.");o=C(t.length)}var a;Y?a=S(new Uint8Array(o)):(a=this,a.length=o);var u;if(r.isBuffer(t))a.set(t);else if(M(t))for(u=0;o>u;u++)a[u]=r.isBuffer(t)?t.readUInt8(u):t[u];else if("string"===i)a.write(t,0,n);else if("number"===i&&!Y&&!e)for(u=0;o>u;u++)a[u]=0;return a}function i(t,n,e,i){e=Number(e)||0;var o=t.length-e;i?(i=Number(i),i>o&&(i=o)):i=o;var a=n.length;if(a%2!==0)throw new Error("Invalid hex string");i>a/2&&(i=a/2);for(var u=0;i>u;u++){var f=parseInt(n.substr(2*u,2),16);if(isNaN(f))throw new Error("Invalid hex string");t[e+u]=f}return r._charsWritten=2*u,u}function o(t,n,e,i){return r._charsWritten=O(D(n),t,e,i)}function a(t,n,e,i){return r._charsWritten=O(N(n),t,e,i)}function u(t,n,e,r){return a(t,n,e,r)}function f(t,n,e,i){return r._charsWritten=O(F(n),t,e,i)}function s(t,n,e){return 0===n&&e===t.length?J.fromByteArray(t):J.fromByteArray(t.slice(n,e))}function c(t,n,e){var r="",i="";e=Math.min(t.length,e);for(var o=n;e>o;o++)t[o]<=127?(r+=P(i)+String.fromCharCode(t[o]),i=""):i+="%"+t[o].toString(16);return r+P(i)}function l(t,n,e){var r="";e=Math.min(t.length,e);for(var i=n;e>i;i++)r+=String.fromCharCode(t[i]);return r}function h(t,n,e){return l(t,n,e)}function p(t,n,e){var r=t.length;(!n||0>n)&&(n=0),(!e||0>e||e>r)&&(e=r);for(var i="",o=n;e>o;o++)i+=_(t[o]);return i}function d(t,n,e,r){r||(W("boolean"==typeof e,"missing or invalid endian"),W(void 0!==n&&null!==n,"missing offset"),W(n+1<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){if(Y){if(i>n+1)return t._dataview.getUint16(n,e);var o=new DataView(new ArrayBuffer(2));return o.setUint8(0,t[i-1]),o.getUint16(0,e)}var a;return e?(a=t[n],i>n+1&&(a|=t[n+1]<<8)):(a=t[n]<<8,i>n+1&&(a|=t[n+1])),a}}function g(t,n,e,r){r||(W("boolean"==typeof e,"missing or invalid endian"),W(void 0!==n&&null!==n,"missing offset"),W(n+3<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){if(Y){if(i>n+3)return t._dataview.getUint32(n,e);for(var o=new DataView(new ArrayBuffer(4)),a=0;i>a+n;a++)o.setUint8(a,t[a+n]);return o.getUint32(0,e)}var u;return e?(i>n+2&&(u=t[n+2]<<16),i>n+1&&(u|=t[n+1]<<8),u|=t[n],i>n+3&&(u+=t[n+3]<<24>>>0)):(i>n+1&&(u=t[n+1]<<16),i>n+2&&(u|=t[n+2]<<8),i>n+3&&(u|=t[n+3]),u+=t[n]<<24>>>0),u}}function w(t,n,e,r){r||(W("boolean"==typeof e,"missing or invalid endian"),W(void 0!==n&&null!==n,"missing offset"),W(n+1<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){if(Y){if(n+1===i){var o=new DataView(new ArrayBuffer(2));return o.setUint8(0,t[i-1]),o.getInt16(0,e)}return t._dataview.getInt16(n,e)}var a=d(t,n,e,!0),u=32768&a;return u?-1*(65535-a+1):a}}function y(t,n,e,r){r||(W("boolean"==typeof e,"missing or invalid endian"),W(void 0!==n&&null!==n,"missing offset"),W(n+3<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){if(Y){if(n+3>=i){for(var o=new DataView(new ArrayBuffer(4)),a=0;i>a+n;a++)o.setUint8(a,t[a+n]);return o.getInt32(0,e)}return t._dataview.getInt32(n,e)}var u=g(t,n,e,!0),f=2147483648&u;return f?-1*(4294967295-u+1):u}}function b(t,n,e,r){return r||(W("boolean"==typeof e,"missing or invalid endian"),W(n+3<t.length,"Trying to read beyond buffer length")),Y?t._dataview.getFloat32(n,e):X.read(t,n,e,23,4)}function v(t,n,e,r){return r||(W("boolean"==typeof e,"missing or invalid endian"),W(n+7<t.length,"Trying to read beyond buffer length")),Y?t._dataview.getFloat64(n,e):X.read(t,n,e,52,8)}function m(t,n,e,r,i){i||(W(void 0!==n&&null!==n,"missing value"),W("boolean"==typeof r,"missing or invalid endian"),W(void 0!==e&&null!==e,"missing offset"),W(e+1<t.length,"trying to write beyond buffer length"),V(n,65535));var o=t.length;if(!(e>=o))if(Y)if(e+1===o){var a=new DataView(new ArrayBuffer(2));a.setUint16(0,n,r),t[e]=a.getUint8(0)}else t._dataview.setUint16(e,n,r);else for(var u=0,f=Math.min(o-e,2);f>u;u++)t[e+u]=(n&255<<8*(r?u:1-u))>>>8*(r?u:1-u)}function E(t,n,e,r,i){i||(W(void 0!==n&&null!==n,"missing value"),W("boolean"==typeof r,"missing or invalid endian"),W(void 0!==e&&null!==e,"missing offset"),W(e+3<t.length,"trying to write beyond buffer length"),V(n,4294967295));var o=t.length;if(!(e>=o)){var a;if(Y)if(e+3>=o){var u=new DataView(new ArrayBuffer(4));for(u.setUint32(0,n,r),a=0;o>a+e;a++)t[a+e]=u.getUint8(a)}else t._dataview.setUint32(e,n,r);else for(a=0,j=Math.min(o-e,4);j>a;a++)t[e+a]=n>>>8*(r?a:3-a)&255}}function B(t,n,e,r,i){i||(W(void 0!==n&&null!==n,"missing value"),W("boolean"==typeof r,"missing or invalid endian"),W(void 0!==e&&null!==e,"missing offset"),W(e+1<t.length,"Trying to write beyond buffer length"),R(n,32767,-32768));var o=t.length;if(!(e>=o))if(Y)if(e+1===o){var a=new DataView(new ArrayBuffer(2));a.setInt16(0,n,r),t[e]=a.getUint8(0)}else t._dataview.setInt16(e,n,r);else n>=0?m(t,n,e,r,i):m(t,65535+n+1,e,r,i)}function I(t,n,e,r,i){i||(W(void 0!==n&&null!==n,"missing value"),W("boolean"==typeof r,"missing or invalid endian"),W(void 0!==e&&null!==e,"missing offset"),W(e+3<t.length,"Trying to write beyond buffer length"),R(n,2147483647,-2147483648));var o=t.length;if(!(e>=o))if(Y)if(e+3>=o){var a=new DataView(new ArrayBuffer(4));a.setInt32(0,n,r);for(var u=0;o>u+e;u++)t[u+e]=a.getUint8(u)}else t._dataview.setInt32(e,n,r);else n>=0?E(t,n,e,r,i):E(t,4294967295+n+1,e,r,i)}function A(t,n,e,r,i){i||(W(void 0!==n&&null!==n,"missing value"),W("boolean"==typeof r,"missing or invalid endian"),W(void 0!==e&&null!==e,"missing offset"),W(e+3<t.length,"Trying to write beyond buffer length"),q(n,3.4028234663852886e38,-3.4028234663852886e38));var o=t.length;if(!(e>=o))if(Y)if(e+3>=o){var a=new DataView(new ArrayBuffer(4));a.setFloat32(0,n,r);for(var u=0;o>u+e;u++)t[u+e]=a.getUint8(u)}else t._dataview.setFloat32(e,n,r);else X.write(t,n,e,r,23,4)}function U(t,n,e,r,i){i||(W(void 0!==n&&null!==n,"missing value"),W("boolean"==typeof r,"missing or invalid endian"),W(void 0!==e&&null!==e,"missing offset"),W(e+7<t.length,"Trying to write beyond buffer length"),q(n,1.7976931348623157e308,-1.7976931348623157e308));var o=t.length;if(!(e>=o))if(Y)if(e+7>=o){var a=new DataView(new ArrayBuffer(8));a.setFloat64(0,n,r);for(var u=0;o>u+e;u++)t[u+e]=a.getUint8(u)}else t._dataview.setFloat64(e,n,r);else X.write(t,n,e,r,52,8)}function L(){return new r(this).buffer}function x(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function S(t){return t._isBuffer=!0,t.write=H.write,t.toString=H.toString,t.toLocaleString=H.toString,t.toJSON=H.toJSON,t.copy=H.copy,t.slice=H.slice,t.readUInt8=H.readUInt8,t.readUInt16LE=H.readUInt16LE,t.readUInt16BE=H.readUInt16BE,t.readUInt32LE=H.readUInt32LE,t.readUInt32BE=H.readUInt32BE,t.readInt8=H.readInt8,t.readInt16LE=H.readInt16LE,t.readInt16BE=H.readInt16BE,t.readInt32LE=H.readInt32LE,t.readInt32BE=H.readInt32BE,t.readFloatLE=H.readFloatLE,t.readFloatBE=H.readFloatBE,t.readDoubleLE=H.readDoubleLE,t.readDoubleBE=H.readDoubleBE,t.writeUInt8=H.writeUInt8,t.writeUInt16LE=H.writeUInt16LE,t.writeUInt16BE=H.writeUInt16BE,t.writeUInt32LE=H.writeUInt32LE,t.writeUInt32BE=H.writeUInt32BE,t.writeInt8=H.writeInt8,t.writeInt16LE=H.writeInt16LE,t.writeInt16BE=H.writeInt16BE,t.writeInt32LE=H.writeInt32LE,t.writeInt32BE=H.writeInt32BE,t.writeFloatLE=H.writeFloatLE,t.writeFloatBE=H.writeFloatBE,t.writeDoubleLE=H.writeDoubleLE,t.writeDoubleBE=H.writeDoubleBE,t.fill=H.fill,t.inspect=H.inspect,t.toArrayBuffer=L,0!==t.byteLength&&(t._dataview=new DataView(t.buffer,t.byteOffset,t.byteLength)),t}function k(t,n,e){return"number"!=typeof t?e:(t=~~t,t>=n?n:t>=0?t:(t+=n,t>=0?t:0))}function C(t){return t=~~Math.ceil(+t),0>t?0:t}function T(t){return(Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)})(t)}function M(t){return T(t)||r.isBuffer(t)||t&&"object"==typeof t&&"number"==typeof t.length}function _(t){return 16>t?"0"+t.toString(16):t.toString(16)}function D(t){for(var n=[],e=0;e<t.length;e++)if(t.charCodeAt(e)<=127)n.push(t.charCodeAt(e));else for(var r=encodeURIComponent(t.charAt(e)).substr(1).split("%"),i=0;i<r.length;i++)n.push(parseInt(r[i],16));return n}function N(t){for(var n=[],e=0;e<t.length;e++)n.push(255&t.charCodeAt(e));return n}function F(t){return J.toByteArray(t)}function O(t,n,e,r){for(var i=0;r>i&&!(i+e>=n.length||i>=t.length);i++)n[i+e]=t[i];return i}function P(t){try{return decodeURIComponent(t)}catch(n){return String.fromCharCode(65533)}}function V(t,n){W("number"==typeof t,"cannot write a non-number as a number"),W(t>=0,"specified a negative value for writing an unsigned value"),W(n>=t,"value is larger than maximum value for type"),W(Math.floor(t)===t,"value has a fractional component")}function R(t,n,e){W("number"==typeof t,"cannot write a non-number as a number"),W(n>=t,"value larger than maximum allowed value"),W(t>=e,"value smaller than minimum allowed value"),W(Math.floor(t)===t,"value has a fractional component")}function q(t,n,e){W("number"==typeof t,"cannot write a non-number as a number"),W(n>=t,"value larger than maximum allowed value"),W(t>=e,"value smaller than minimum allowed value")}function W(t,n){if(!t)throw new Error(n||"Failed assertion")}var J=t("base64-js"),X=t("ieee754");e.Buffer=r,e.SlowBuffer=r,e.INSPECT_MAX_BYTES=50,r.poolSize=8192;var Y=function(){if("undefined"==typeof Uint8Array||"undefined"==typeof ArrayBuffer||"undefined"==typeof DataView)return!1;try{var t=new Uint8Array(0);return t.foo=function(){return 42},42===t.foo()}catch(n){return!1}}();r.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":return!0;default:return!1}},r.isBuffer=function(t){return t&&t._isBuffer},r.byteLength=function(t,n){switch(n||"utf8"){case"hex":return t.length/2;case"utf8":case"utf-8":return D(t).length;case"ascii":case"binary":return t.length;case"base64":return F(t).length;default:throw new Error("Unknown encoding")}},r.concat=function(t,n){if(!T(t))throw new Error("Usage: Buffer.concat(list, [totalLength])\nlist should be an Array.");if(0===t.length)return new r(0);if(1===t.length)return t[0];var e;if("number"!=typeof n)for(n=0,e=0;e<t.length;e++)n+=t[e].length;var i=new r(n),o=0;for(e=0;e<t.length;e++){var a=t[e];a.copy(i,o),o+=a.length}return i},r.prototype.write=function(t,n,e,r){if(isFinite(n))isFinite(e)||(r=e,e=void 0);else{var s=r;r=n,n=e,e=s}n=Number(n)||0;var c=this.length-n;switch(e?(e=Number(e),e>c&&(e=c)):e=c,r=String(r||"utf8").toLowerCase()){case"hex":return i(this,t,n,e);case"utf8":case"utf-8":return o(this,t,n,e);case"ascii":return a(this,t,n,e);case"binary":return u(this,t,n,e);case"base64":return f(this,t,n,e);default:throw new Error("Unknown encoding")}},r.prototype.toString=function(t,n,e){var r=this;if(t=String(t||"utf8").toLowerCase(),n=Number(n)||0,e=void 0!==e?Number(e):e=r.length,e===n)return"";switch(t){case"hex":return p(r,n,e);case"utf8":case"utf-8":return c(r,n,e);case"ascii":return l(r,n,e);case"binary":return h(r,n,e);case"base64":return s(r,n,e);default:throw new Error("Unknown encoding")}},r.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},r.prototype.copy=function(t,n,e,r){var i=this;if(e||(e=0),r||0===r||(r=this.length),n||(n=0),r!==e&&0!==t.length&&0!==i.length){if(e>r)throw new Error("sourceEnd < sourceStart");if(0>n||n>=t.length)throw new Error("targetStart out of bounds");if(0>e||e>=i.length)throw new Error("sourceStart out of bounds");if(0>r||r>i.length)throw new Error("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-n<r-e&&(r=t.length-n+e);for(var o=0;r-e>o;o++)t[o+n]=this[o+e]}},r.prototype.slice=function(t,n){var e=this.length;if(t=k(t,e,0),n=k(n,e,e),Y)return S(this.subarray(t,n));for(var i=n-t,o=new r(i,void 0,!0),a=0;i>a;a++)o[a]=this[a+t];return o},r.prototype.readUInt8=function(t,n){var e=this;return n||(W(void 0!==t&&null!==t,"missing offset"),W(t<e.length,"Trying to read beyond buffer length")),t>=e.length?void 0:e[t]},r.prototype.readUInt16LE=function(t,n){return d(this,t,!0,n)},r.prototype.readUInt16BE=function(t,n){return d(this,t,!1,n)},r.prototype.readUInt32LE=function(t,n){return g(this,t,!0,n)},r.prototype.readUInt32BE=function(t,n){return g(this,t,!1,n)},r.prototype.readInt8=function(t,n){var e=this;if(n||(W(void 0!==t&&null!==t,"missing offset"),W(t<e.length,"Trying to read beyond buffer length")),!(t>=e.length)){if(Y)return e._dataview.getInt8(t);var r=128&e[t];return r?-1*(255-e[t]+1):e[t]}},r.prototype.readInt16LE=function(t,n){return w(this,t,!0,n)},r.prototype.readInt16BE=function(t,n){return w(this,t,!1,n)},r.prototype.readInt32LE=function(t,n){return y(this,t,!0,n)},r.prototype.readInt32BE=function(t,n){return y(this,t,!1,n)},r.prototype.readFloatLE=function(t,n){return b(this,t,!0,n)},r.prototype.readFloatBE=function(t,n){return b(this,t,!1,n)},r.prototype.readDoubleLE=function(t,n){return v(this,t,!0,n)},r.prototype.readDoubleBE=function(t,n){return v(this,t,!1,n)},r.prototype.writeUInt8=function(t,n,e){var r=this;e||(W(void 0!==t&&null!==t,"missing value"),W(void 0!==n&&null!==n,"missing offset"),W(n<r.length,"trying to write beyond buffer length"),V(t,255)),n>=r.length||(r[n]=t)},r.prototype.writeUInt16LE=function(t,n,e){m(this,t,n,!0,e)},r.prototype.writeUInt16BE=function(t,n,e){m(this,t,n,!1,e)},r.prototype.writeUInt32LE=function(t,n,e){E(this,t,n,!0,e)},r.prototype.writeUInt32BE=function(t,n,e){E(this,t,n,!1,e)},r.prototype.writeInt8=function(t,n,e){var r=this;e||(W(void 0!==t&&null!==t,"missing value"),W(void 0!==n&&null!==n,"missing offset"),W(n<r.length,"Trying to write beyond buffer length"),R(t,127,-128)),n>=r.length||(Y?r._dataview.setInt8(n,t):t>=0?r.writeUInt8(t,n,e):r.writeUInt8(255+t+1,n,e))},r.prototype.writeInt16LE=function(t,n,e){B(this,t,n,!0,e)},r.prototype.writeInt16BE=function(t,n,e){B(this,t,n,!1,e)},r.prototype.writeInt32LE=function(t,n,e){I(this,t,n,!0,e)},r.prototype.writeInt32BE=function(t,n,e){I(this,t,n,!1,e)},r.prototype.writeFloatLE=function(t,n,e){A(this,t,n,!0,e)},r.prototype.writeFloatBE=function(t,n,e){A(this,t,n,!1,e)},r.prototype.writeDoubleLE=function(t,n,e){U(this,t,n,!0,e)},r.prototype.writeDoubleBE=function(t,n,e){U(this,t,n,!1,e)},r.prototype.fill=function(t,n,e){if(t||(t=0),n||(n=0),e||(e=this.length),"string"==typeof t&&(t=t.charCodeAt(0)),"number"!=typeof t||isNaN(t))throw new Error("value is not a number");if(n>e)throw new Error("end < start");if(e!==n&&0!==this.length){if(0>n||n>=this.length)throw new Error("start out of bounds");if(0>e||e>this.length)throw new Error("end out of bounds");for(var r=n;e>r;r++)this[r]=t}},r.prototype.inspect=function(){for(var t=[],n=this.length,r=0;n>r;r++)if(t[r]=_(this[r]),r===e.INSPECT_MAX_BYTES){t[r+1]="...";break}return"<Buffer "+t.join(" ")+">"};var H=r.prototype},{"base64-js":3,ieee754:4}],"native-buffer-browserify":[function(t,n){n.exports=t("PcZj9L")},{}],3:[function(t,n){function e(t,n){var e=t.length,r=Number(arguments[1])||0;for(r=0>r?Math.ceil(r):Math.floor(r),0>r&&(r+=e);e>r;r++)if("string"==typeof t&&t.charAt(r)===n||"string"!=typeof t&&t[r]===n)return r;return-1}!function(){"use strict";function t(t){var n,r,o,a,u,f;if(t.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(u=e(t,"="),u=u>0?t.length-u:0,f=[],o=u>0?t.length-4:t.length,n=0,r=0;o>n;n+=4,r+=3)a=e(i,t.charAt(n))<<18|e(i,t.charAt(n+1))<<12|e(i,t.charAt(n+2))<<6|e(i,t.charAt(n+3)),f.push((16711680&a)>>16),f.push((65280&a)>>8),f.push(255&a);return 2===u?(a=e(i,t.charAt(n))<<2|e(i,t.charAt(n+1))>>4,f.push(255&a)):1===u&&(a=e(i,t.charAt(n))<<10|e(i,t.charAt(n+1))<<4|e(i,t.charAt(n+2))>>2,f.push(a>>8&255),f.push(255&a)),f}function r(t){function n(t){return i.charAt(t>>18&63)+i.charAt(t>>12&63)+i.charAt(t>>6&63)+i.charAt(63&t)}var e,r,o,a=t.length%3,u="";for(e=0,o=t.length-a;o>e;e+=3)r=(t[e]<<16)+(t[e+1]<<8)+t[e+2],u+=n(r);switch(a){case 1:r=t[t.length-1],u+=i.charAt(r>>2),u+=i.charAt(r<<4&63),u+="==";break;case 2:r=(t[t.length-2]<<8)+t[t.length-1],u+=i.charAt(r>>10),u+=i.charAt(r>>4&63),u+=i.charAt(r<<2&63),u+="="}return u}var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";n.exports.toByteArray=t,n.exports.fromByteArray=r}()},{}],4:[function(t,n,e){e.read=function(t,n,e,r,i){var o,a,u=8*i-r-1,f=(1<<u)-1,s=f>>1,c=-7,l=e?i-1:0,h=e?-1:1,p=t[n+l];for(l+=h,o=p&(1<<-c)-1,p>>=-c,c+=u;c>0;o=256*o+t[n+l],l+=h,c-=8);for(a=o&(1<<-c)-1,o>>=-c,c+=r;c>0;a=256*a+t[n+l],l+=h,c-=8);if(0===o)o=1-s;else{if(o===f)return a?0/0:1/0*(p?-1:1);a+=Math.pow(2,r),o-=s}return(p?-1:1)*a*Math.pow(2,o-r)},e.write=function(t,n,e,r,i,o){var a,u,f,s=8*o-i-1,c=(1<<s)-1,l=c>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:o-1,d=r?1:-1,g=0>n||0===n&&0>1/n?1:0;for(n=Math.abs(n),isNaN(n)||1/0===n?(u=isNaN(n)?1:0,a=c):(a=Math.floor(Math.log(n)/Math.LN2),n*(f=Math.pow(2,-a))<1&&(a--,f*=2),n+=a+l>=1?h/f:h*Math.pow(2,1-l),n*f>=2&&(a++,f/=2),a+l>=c?(u=0,a=c):a+l>=1?(u=(n*f-1)*Math.pow(2,i),a+=l):(u=n*Math.pow(2,l-1)*Math.pow(2,i),a=0));i>=8;t[e+p]=255&u,p+=d,u/=256,i-=8);for(a=a<<i|u,s+=i;s>0;t[e+p]=255&a,p+=d,a/=256,s-=8);t[e+p-d]|=128*g}},{}]},{},[]),n.exports=t("native-buffer-browserify").Buffer | ||
},{}],18:[function(t,n,e){function r(t,n,e){if(!(this instanceof r))return new r(t,n,e);var i=typeof t;if("base64"===n&&"string"===i)for(t=x(t);t.length%4!==0;)t+="=";var o;if("number"===i)o=C(t);else if("string"===i)o=r.byteLength(t,n);else{if("object"!==i)throw new Error("First argument needs to be a number, array or string.");o=C(t.length)}var a;r._useTypedArrays?a=S(new Uint8Array(o)):(a=this,a.length=o);var u;if(r.isBuffer(t))a.set(t);else if(M(t))for(u=0;o>u;u++)a[u]=r.isBuffer(t)?t.readUInt8(u):t[u];else if("string"===i)a.write(t,0,n);else if("number"===i&&!r._useTypedArrays&&!e)for(u=0;o>u;u++)a[u]=0;return a}function i(t,n,e,i){e=Number(e)||0;var o=t.length-e;i?(i=Number(i),i>o&&(i=o)):i=o;var a=n.length;q(a%2===0,"Invalid hex string"),i>a/2&&(i=a/2);for(var u=0;i>u;u++){var f=parseInt(n.substr(2*u,2),16);q(!isNaN(f),"Invalid hex string"),t[e+u]=f}return r._charsWritten=2*u,u}function o(t,n,e,i){return r._charsWritten=j(D(n),t,e,i)}function a(t,n,e,i){return r._charsWritten=j(N(n),t,e,i)}function u(t,n,e,r){return a(t,n,e,r)}function f(t,n,e,i){return r._charsWritten=j(F(n),t,e,i)}function s(t,n,e){return 0===n&&e===t.length?W.fromByteArray(t):W.fromByteArray(t.slice(n,e))}function c(t,n,e){var r="",i="";e=Math.min(t.length,e);for(var o=n;e>o;o++)t[o]<=127?(r+=O(i)+String.fromCharCode(t[o]),i=""):i+="%"+t[o].toString(16);return r+O(i)}function l(t,n,e){var r="";e=Math.min(t.length,e);for(var i=n;e>i;i++)r+=String.fromCharCode(t[i]);return r}function h(t,n,e){return l(t,n,e)}function p(t,n,e){var r=t.length;(!n||0>n)&&(n=0),(!e||0>e||e>r)&&(e=r);for(var i="",o=n;e>o;o++)i+=_(t[o]);return i}function d(t,n,e,r){r||(q("boolean"==typeof e,"missing or invalid endian"),q(void 0!==n&&null!==n,"missing offset"),q(n+1<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){var o;return e?(o=t[n],i>n+1&&(o|=t[n+1]<<8)):(o=t[n]<<8,i>n+1&&(o|=t[n+1])),o}}function g(t,n,e,r){r||(q("boolean"==typeof e,"missing or invalid endian"),q(void 0!==n&&null!==n,"missing offset"),q(n+3<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){var o;return e?(i>n+2&&(o=t[n+2]<<16),i>n+1&&(o|=t[n+1]<<8),o|=t[n],i>n+3&&(o+=t[n+3]<<24>>>0)):(i>n+1&&(o=t[n+1]<<16),i>n+2&&(o|=t[n+2]<<8),i>n+3&&(o|=t[n+3]),o+=t[n]<<24>>>0),o}}function w(t,n,e,r){r||(q("boolean"==typeof e,"missing or invalid endian"),q(void 0!==n&&null!==n,"missing offset"),q(n+1<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){var o=d(t,n,e,!0),a=32768&o;return a?-1*(65535-o+1):o}}function y(t,n,e,r){r||(q("boolean"==typeof e,"missing or invalid endian"),q(void 0!==n&&null!==n,"missing offset"),q(n+3<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){var o=g(t,n,e,!0),a=2147483648&o;return a?-1*(4294967295-o+1):o}}function b(t,n,e,r){return r||(q("boolean"==typeof e,"missing or invalid endian"),q(n+3<t.length,"Trying to read beyond buffer length")),J.read(t,n,e,23,4)}function v(t,n,e,r){return r||(q("boolean"==typeof e,"missing or invalid endian"),q(n+7<t.length,"Trying to read beyond buffer length")),J.read(t,n,e,52,8)}function m(t,n,e,r,i){i||(q(void 0!==n&&null!==n,"missing value"),q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+1<t.length,"trying to write beyond buffer length"),P(n,65535));var o=t.length;if(!(e>=o))for(var a=0,u=Math.min(o-e,2);u>a;a++)t[e+a]=(n&255<<8*(r?a:1-a))>>>8*(r?a:1-a)}function E(t,n,e,r,i){i||(q(void 0!==n&&null!==n,"missing value"),q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+3<t.length,"trying to write beyond buffer length"),P(n,4294967295));var o=t.length;if(!(e>=o))for(var a=0,u=Math.min(o-e,4);u>a;a++)t[e+a]=n>>>8*(r?a:3-a)&255}function B(t,n,e,r,i){i||(q(void 0!==n&&null!==n,"missing value"),q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+1<t.length,"Trying to write beyond buffer length"),V(n,32767,-32768));var o=t.length;e>=o||(n>=0?m(t,n,e,r,i):m(t,65535+n+1,e,r,i))}function I(t,n,e,r,i){i||(q(void 0!==n&&null!==n,"missing value"),q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+3<t.length,"Trying to write beyond buffer length"),V(n,2147483647,-2147483648));var o=t.length;e>=o||(n>=0?E(t,n,e,r,i):E(t,4294967295+n+1,e,r,i))}function A(t,n,e,r,i){i||(q(void 0!==n&&null!==n,"missing value"),q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+3<t.length,"Trying to write beyond buffer length"),R(n,3.4028234663852886e38,-3.4028234663852886e38));var o=t.length;e>=o||J.write(t,n,e,r,23,4)}function U(t,n,e,r,i){i||(q(void 0!==n&&null!==n,"missing value"),q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+7<t.length,"Trying to write beyond buffer length"),R(n,1.7976931348623157e308,-1.7976931348623157e308));var o=t.length;e>=o||J.write(t,n,e,r,52,8)}function L(){return new r(this).buffer}function x(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function S(t){return t._isBuffer=!0,t.write=X.write,t.toString=X.toString,t.toLocaleString=X.toString,t.toJSON=X.toJSON,t.copy=X.copy,t.slice=X.slice,t.readUInt8=X.readUInt8,t.readUInt16LE=X.readUInt16LE,t.readUInt16BE=X.readUInt16BE,t.readUInt32LE=X.readUInt32LE,t.readUInt32BE=X.readUInt32BE,t.readInt8=X.readInt8,t.readInt16LE=X.readInt16LE,t.readInt16BE=X.readInt16BE,t.readInt32LE=X.readInt32LE,t.readInt32BE=X.readInt32BE,t.readFloatLE=X.readFloatLE,t.readFloatBE=X.readFloatBE,t.readDoubleLE=X.readDoubleLE,t.readDoubleBE=X.readDoubleBE,t.writeUInt8=X.writeUInt8,t.writeUInt16LE=X.writeUInt16LE,t.writeUInt16BE=X.writeUInt16BE,t.writeUInt32LE=X.writeUInt32LE,t.writeUInt32BE=X.writeUInt32BE,t.writeInt8=X.writeInt8,t.writeInt16LE=X.writeInt16LE,t.writeInt16BE=X.writeInt16BE,t.writeInt32LE=X.writeInt32LE,t.writeInt32BE=X.writeInt32BE,t.writeFloatLE=X.writeFloatLE,t.writeFloatBE=X.writeFloatBE,t.writeDoubleLE=X.writeDoubleLE,t.writeDoubleBE=X.writeDoubleBE,t.fill=X.fill,t.inspect=X.inspect,t.toArrayBuffer=L,t}function k(t,n,e){return"number"!=typeof t?e:(t=~~t,t>=n?n:t>=0?t:(t+=n,t>=0?t:0))}function C(t){return t=~~Math.ceil(+t),0>t?0:t}function T(t){return(Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)})(t)}function M(t){return T(t)||r.isBuffer(t)||t&&"object"==typeof t&&"number"==typeof t.length}function _(t){return 16>t?"0"+t.toString(16):t.toString(16)}function D(t){for(var n=[],e=0;e<t.length;e++)if(t.charCodeAt(e)<=127)n.push(t.charCodeAt(e));else for(var r=encodeURIComponent(t.charAt(e)).substr(1).split("%"),i=0;i<r.length;i++)n.push(parseInt(r[i],16));return n}function N(t){for(var n=[],e=0;e<t.length;e++)n.push(255&t.charCodeAt(e));return n}function F(t){return W.toByteArray(t)}function j(t,n,e,r){for(var i=0;r>i&&!(i+e>=n.length||i>=t.length);i++)n[i+e]=t[i];return i}function O(t){try{return decodeURIComponent(t)}catch(n){return String.fromCharCode(65533)}}function P(t,n){q("number"==typeof t,"cannot write a non-number as a number"),q(t>=0,"specified a negative value for writing an unsigned value"),q(n>=t,"value is larger than maximum value for type"),q(Math.floor(t)===t,"value has a fractional component")}function V(t,n,e){q("number"==typeof t,"cannot write a non-number as a number"),q(n>=t,"value larger than maximum allowed value"),q(t>=e,"value smaller than minimum allowed value"),q(Math.floor(t)===t,"value has a fractional component")}function R(t,n,e){q("number"==typeof t,"cannot write a non-number as a number"),q(n>=t,"value larger than maximum allowed value"),q(t>=e,"value smaller than minimum allowed value")}function q(t,n){if(!t)throw new Error(n||"Failed assertion")}var W=t("base64-js"),J=t("ieee754");e.Buffer=r,e.SlowBuffer=r,e.INSPECT_MAX_BYTES=50,r.poolSize=8192,r._useTypedArrays=function(){if("undefined"==typeof Uint8Array||"undefined"==typeof ArrayBuffer)return!1;try{var t=new Uint8Array(0);return t.foo=function(){return 42},42===t.foo()&&"function"==typeof t.subarray}catch(n){return!1}}(),r.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":return!0;default:return!1}},r.isBuffer=function(t){return t&&t._isBuffer},r.byteLength=function(t,n){switch(n||"utf8"){case"hex":return t.length/2;case"utf8":case"utf-8":return D(t).length;case"ascii":case"binary":return t.length;case"base64":return F(t).length;default:throw new Error("Unknown encoding")}},r.concat=function(t,n){if(q(T(t),"Usage: Buffer.concat(list, [totalLength])\nlist should be an Array."),0===t.length)return new r(0);if(1===t.length)return t[0];var e;if("number"!=typeof n)for(n=0,e=0;e<t.length;e++)n+=t[e].length;var i=new r(n),o=0;for(e=0;e<t.length;e++){var a=t[e];a.copy(i,o),o+=a.length}return i},r.prototype.write=function(t,n,e,r){if(isFinite(n))isFinite(e)||(r=e,e=void 0);else{var s=r;r=n,n=e,e=s}n=Number(n)||0;var c=this.length-n;switch(e?(e=Number(e),e>c&&(e=c)):e=c,r=String(r||"utf8").toLowerCase()){case"hex":return i(this,t,n,e);case"utf8":case"utf-8":return o(this,t,n,e);case"ascii":return a(this,t,n,e);case"binary":return u(this,t,n,e);case"base64":return f(this,t,n,e);default:throw new Error("Unknown encoding")}},r.prototype.toString=function(t,n,e){var r=this;if(t=String(t||"utf8").toLowerCase(),n=Number(n)||0,e=void 0!==e?Number(e):e=r.length,e===n)return"";switch(t){case"hex":return p(r,n,e);case"utf8":case"utf-8":return c(r,n,e);case"ascii":return l(r,n,e);case"binary":return h(r,n,e);case"base64":return s(r,n,e);default:throw new Error("Unknown encoding")}},r.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},r.prototype.copy=function(t,n,e,r){var i=this;if(e||(e=0),r||0===r||(r=this.length),n||(n=0),r!==e&&0!==t.length&&0!==i.length){q(r>=e,"sourceEnd < sourceStart"),q(n>=0&&n<t.length,"targetStart out of bounds"),q(e>=0&&e<i.length,"sourceStart out of bounds"),q(r>=0&&r<=i.length,"sourceEnd out of bounds"),r>this.length&&(r=this.length),t.length-n<r-e&&(r=t.length-n+e);for(var o=0;r-e>o;o++)t[o+n]=this[o+e]}},r.prototype.slice=function(t,n){var e=this.length;if(t=k(t,e,0),n=k(n,e,e),r._useTypedArrays)return S(this.subarray(t,n));for(var i=n-t,o=new r(i,void 0,!0),a=0;i>a;a++)o[a]=this[a+t];return o},r.prototype.readUInt8=function(t,n){var e=this;return n||(q(void 0!==t&&null!==t,"missing offset"),q(t<e.length,"Trying to read beyond buffer length")),t>=e.length?void 0:e[t]},r.prototype.readUInt16LE=function(t,n){return d(this,t,!0,n)},r.prototype.readUInt16BE=function(t,n){return d(this,t,!1,n)},r.prototype.readUInt32LE=function(t,n){return g(this,t,!0,n)},r.prototype.readUInt32BE=function(t,n){return g(this,t,!1,n)},r.prototype.readInt8=function(t,n){var e=this;if(n||(q(void 0!==t&&null!==t,"missing offset"),q(t<e.length,"Trying to read beyond buffer length")),!(t>=e.length)){var r=128&e[t];return r?-1*(255-e[t]+1):e[t]}},r.prototype.readInt16LE=function(t,n){return w(this,t,!0,n)},r.prototype.readInt16BE=function(t,n){return w(this,t,!1,n)},r.prototype.readInt32LE=function(t,n){return y(this,t,!0,n)},r.prototype.readInt32BE=function(t,n){return y(this,t,!1,n)},r.prototype.readFloatLE=function(t,n){return b(this,t,!0,n)},r.prototype.readFloatBE=function(t,n){return b(this,t,!1,n)},r.prototype.readDoubleLE=function(t,n){return v(this,t,!0,n)},r.prototype.readDoubleBE=function(t,n){return v(this,t,!1,n)},r.prototype.writeUInt8=function(t,n,e){var r=this;e||(q(void 0!==t&&null!==t,"missing value"),q(void 0!==n&&null!==n,"missing offset"),q(n<r.length,"trying to write beyond buffer length"),P(t,255)),n>=r.length||(r[n]=t)},r.prototype.writeUInt16LE=function(t,n,e){m(this,t,n,!0,e)},r.prototype.writeUInt16BE=function(t,n,e){m(this,t,n,!1,e)},r.prototype.writeUInt32LE=function(t,n,e){E(this,t,n,!0,e)},r.prototype.writeUInt32BE=function(t,n,e){E(this,t,n,!1,e)},r.prototype.writeInt8=function(t,n,e){var r=this;e||(q(void 0!==t&&null!==t,"missing value"),q(void 0!==n&&null!==n,"missing offset"),q(n<r.length,"Trying to write beyond buffer length"),V(t,127,-128)),n>=r.length||(t>=0?r.writeUInt8(t,n,e):r.writeUInt8(255+t+1,n,e))},r.prototype.writeInt16LE=function(t,n,e){B(this,t,n,!0,e)},r.prototype.writeInt16BE=function(t,n,e){B(this,t,n,!1,e)},r.prototype.writeInt32LE=function(t,n,e){I(this,t,n,!0,e)},r.prototype.writeInt32BE=function(t,n,e){I(this,t,n,!1,e)},r.prototype.writeFloatLE=function(t,n,e){A(this,t,n,!0,e)},r.prototype.writeFloatBE=function(t,n,e){A(this,t,n,!1,e)},r.prototype.writeDoubleLE=function(t,n,e){U(this,t,n,!0,e)},r.prototype.writeDoubleBE=function(t,n,e){U(this,t,n,!1,e)},r.prototype.fill=function(t,n,e){if(t||(t=0),n||(n=0),e||(e=this.length),"string"==typeof t&&(t=t.charCodeAt(0)),q("number"==typeof t&&!isNaN(t),"value is not a number"),q(e>=n,"end < start"),e!==n&&0!==this.length){q(n>=0&&n<this.length,"start out of bounds"),q(e>=0&&e<=this.length,"end out of bounds");for(var r=n;e>r;r++)this[r]=t}},r.prototype.inspect=function(){for(var t=[],n=this.length,r=0;n>r;r++)if(t[r]=_(this[r]),r===e.INSPECT_MAX_BYTES){t[r+1]="...";break}return"<Buffer "+t.join(" ")+">"};var X=r.prototype},{"base64-js":19,ieee754:20}],19:[function(t,n){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(){"use strict";function t(t){var n=t.charCodeAt(0);return n===a?62:n===u?63:f>n?-1:f+10>n?n-f+26+26:c+26>n?n-c:s+26>n?n-s+26:void 0}function r(n){function e(t){s[l++]=t}var r,i,a,u,f,s;if(n.length%4>0)throw"Invalid string. Length must be a multiple of 4";var c=n.length;f="="===n.charAt(c-2)?2:"="===n.charAt(c-1)?1:0,s=new o(3*n.length/4-f),a=f>0?n.length-4:n.length;var l=0;for(r=0,i=0;a>r;r+=4,i+=3)u=t(n.charAt(r))<<18|t(n.charAt(r+1))<<12|t(n.charAt(r+2))<<6|t(n.charAt(r+3)),e((16711680&u)>>16),e((65280&u)>>8),e(255&u);return 2===f?(u=t(n.charAt(r))<<2|t(n.charAt(r+1))>>4,e(255&u)):1===f&&(u=t(n.charAt(r))<<10|t(n.charAt(r+1))<<4|t(n.charAt(r+2))>>2,e(u>>8&255),e(255&u)),s}function i(t){function n(t){return e.charAt(t)}function r(t){return n(t>>18&63)+n(t>>12&63)+n(t>>6&63)+n(63&t)}var i,o,a,u=t.length%3,f="";for(i=0,a=t.length-u;a>i;i+=3)o=(t[i]<<16)+(t[i+1]<<8)+t[i+2],f+=r(o);switch(u){case 1:o=t[t.length-1],f+=n(o>>2),f+=n(o<<4&63),f+="==";break;case 2:o=(t[t.length-2]<<8)+t[t.length-1],f+=n(o>>10),f+=n(o>>4&63),f+=n(o<<2&63),f+="="}return f}var o="undefined"!=typeof Uint8Array?Uint8Array:Array,a=("0".charCodeAt(0),"+".charCodeAt(0)),u="/".charCodeAt(0),f="0".charCodeAt(0),s="a".charCodeAt(0),c="A".charCodeAt(0);n.exports.toByteArray=r,n.exports.fromByteArray=i}()},{}],20:[function(t,n,e){e.read=function(t,n,e,r,i){var o,a,u=8*i-r-1,f=(1<<u)-1,s=f>>1,c=-7,l=e?i-1:0,h=e?-1:1,p=t[n+l];for(l+=h,o=p&(1<<-c)-1,p>>=-c,c+=u;c>0;o=256*o+t[n+l],l+=h,c-=8);for(a=o&(1<<-c)-1,o>>=-c,c+=r;c>0;a=256*a+t[n+l],l+=h,c-=8);if(0===o)o=1-s;else{if(o===f)return a?0/0:1/0*(p?-1:1);a+=Math.pow(2,r),o-=s}return(p?-1:1)*a*Math.pow(2,o-r)},e.write=function(t,n,e,r,i,o){var a,u,f,s=8*o-i-1,c=(1<<s)-1,l=c>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:o-1,d=r?1:-1,g=0>n||0===n&&0>1/n?1:0;for(n=Math.abs(n),isNaN(n)||1/0===n?(u=isNaN(n)?1:0,a=c):(a=Math.floor(Math.log(n)/Math.LN2),n*(f=Math.pow(2,-a))<1&&(a--,f*=2),n+=a+l>=1?h/f:h*Math.pow(2,1-l),n*f>=2&&(a++,f/=2),a+l>=c?(u=0,a=c):a+l>=1?(u=(n*f-1)*Math.pow(2,i),a+=l):(u=n*Math.pow(2,l-1)*Math.pow(2,i),a=0));i>=8;t[e+p]=255&u,p+=d,u/=256,i-=8);for(a=a<<i|u,s+=i;s>0;t[e+p]=255&a,p+=d,a/=256,s-=8);t[e+p-d]|=128*g}},{}],21:[function(n,e){var r=n("__browserify_Buffer");(function(){function i(t,n,e){var r=n&&e||0,i=0;for(n=n||[],t.toLowerCase().replace(/[0-9a-f]{2}/g,function(t){16>i&&(n[r+i++]=w[t])});16>i;)n[r+i++]=0;return n}function o(t,n){var e=n||0,r=g;return r[t[e++]]+r[t[e++]]+r[t[e++]]+r[t[e++]]+"-"+r[t[e++]]+r[t[e++]]+"-"+r[t[e++]]+r[t[e++]]+"-"+r[t[e++]]+r[t[e++]]+"-"+r[t[e++]]+r[t[e++]]+r[t[e++]]+r[t[e++]]+r[t[e++]]+r[t[e++]]}function a(t,n,e){var r=n&&e||0,i=n||[];t=t||{};var a=null!=t.clockseq?t.clockseq:m,u=null!=t.msecs?t.msecs:(new Date).getTime(),f=null!=t.nsecs?t.nsecs:B+1,s=u-E+(f-B)/1e4;if(0>s&&null==t.clockseq&&(a=a+1&16383),(0>s||u>E)&&null==t.nsecs&&(f=0),f>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");E=u,B=f,m=a,u+=122192928e5;var c=(1e4*(268435455&u)+f)%4294967296;i[r++]=c>>>24&255,i[r++]=c>>>16&255,i[r++]=c>>>8&255,i[r++]=255&c;var l=u/4294967296*1e4&268435455;i[r++]=l>>>8&255,i[r++]=255&l,i[r++]=l>>>24&15|16,i[r++]=l>>>16&255,i[r++]=a>>>8|128,i[r++]=255&a;for(var h=t.node||v,p=0;6>p;p++)i[r+p]=h[p];return n?n:o(i)}function u(t,n,e){var r=n&&e||0;"string"==typeof t&&(n="binary"==t?new d(16):null,t=null),t=t||{};var i=t.random||(t.rng||f)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,n)for(var a=0;16>a;a++)n[r+a]=i[a];return n||o(i)}var f,s=this;if("function"==typeof n)try{var c=n("crypto").randomBytes;f=c&&function(){return c(16)}}catch(l){}if(!f&&s.crypto&&crypto.getRandomValues){var h=new Uint8Array(16);f=function(){return crypto.getRandomValues(h),h}}if(!f){var p=new Array(16);f=function(){for(var t,n=0;16>n;n++)0===(3&n)&&(t=4294967296*Math.random()),p[n]=t>>>((3&n)<<3)&255;return p}}for(var d="function"==typeof r?r:Array,g=[],w={},y=0;256>y;y++)g[y]=(y+256).toString(16).substr(1),w[g[y]]=y;var b=f(),v=[1|b[0],b[1],b[2],b[3],b[4],b[5]],m=16383&(b[6]<<8|b[7]),E=0,B=0,I=u;if(I.v1=a,I.v4=u,I.parse=i,I.unparse=o,I.BufferClass=d,"function"==typeof t&&t.amd)t(function(){return I});else if("undefined"!=typeof e&&e.exports)e.exports=I;else{var A=s.uuid;I.noConflict=function(){return s.uuid=A,I},s.uuid=I}}).call(this)},{__browserify_Buffer:17,crypto:12}],22:[function(n,e,r){!function(n,i){"use strict";"object"==typeof r&&e?e.exports=i():"function"==typeof t&&t.amd?t(i):n.PubSub=i()}("object"==typeof window&&window||this,function(){"use strict";function t(t){return function(){throw t}}function n(n,e,r){try{n(e,r)}catch(i){setTimeout(t(i),0)}}function e(t,n,e){t(n,e)}function r(t,r,i,o){var a,u=f[r],s=o?e:n;if(f.hasOwnProperty(r))for(a=0;a<u.length;a++)s(u[a].func,t,i)}function i(t,n,e){return function(){var i=String(t),o=i.lastIndexOf(".");for(r(t,t,n,e);-1!==o;)i=i.substr(0,o),o=i.lastIndexOf("."),r(t,i,n)}}function o(t){for(var n=String(t),e=f.hasOwnProperty(n),r=n.lastIndexOf(".");!e&&-1!==r;)n=n.substr(0,r),r=n.lastIndexOf("."),e=f.hasOwnProperty(n);return e&&f[n].length>0}function a(t,n,e,r){var a=i(t,n,r),u=o(t);return u?(e===!0?a():setTimeout(a,0),!0):!1}var u={},f={},s=-1;return u.publish=function(t,n){return a(t,n,!1,u.immediateExceptions)},u.publishSync=function(t,n){return a(t,n,!0,u.immediateExceptions)},u.subscribe=function(t,n){if("function"!=typeof n)return!1;f.hasOwnProperty(t)||(f[t]=[]);var e=String(++s);return f[t].push({token:e,func:n}),e},u.unsubscribe=function(t){var n,e,r="string"==typeof t,i=r?"token":"func",o=r?t:!0,a=!1;for(n in f)if(f.hasOwnProperty(n))for(e=f[n].length-1;e>=0;e--)if(f[n][e][i]===t&&(f[n].splice(e,1),a=o,r))return a;return a},u})},{}]},{},[1])(1)}); | ||
!function(t){if("object"==typeof exports)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.babble=t()}}(function(){var t;return function n(t,e,r){function i(a,u){if(!e[a]){if(!t[a]){var f="function"==typeof require&&require;if(!u&&f)return f(a,!0);if(o)return o(a,!0);throw new Error("Cannot find module '"+a+"'")}var s=e[a]={exports:{}};t[a][0].call(s.exports,function(n){var e=t[a][1][n];return i(e?e:n)},s,s.exports,n,t,e,r)}return e[a].exports}for(var o="function"==typeof require&&require,a=0;a<r.length;a++)i(r[a]);return i}({1:[function(t,n){n.exports=t("./lib/babble")},{"./lib/babble":3}],2:[function(t,n){function e(t){if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if(!t)throw new Error("id required");this.id=t,this.listeners={},this.conversations={}}var r=t("node-uuid"),i=t("./pubsub"),o=(t("./block/Block"),t("./block/Action"),t("./block/Reply")),a=t("./block/Listen");e.prototype.subscribe=function(t,n){if("function"==typeof t&&(n=t,t=null),t||(t=i["default"]()),"function"!=typeof t.subscribe)throw new Error("pubsub must contain a function subscribe(params: {id: string, callback: function}) : function");if("function"!=typeof t.publish)throw new Error("pubsub must contain a function publish(params: {id: string, message: *})");var e=this,r=t.subscribe({id:this.id,message:function(t){var n,r;n=e.conversations[t.id],n?e._run(n,t.message):(r=e.listeners[t.message],r&&(n={id:t.id,peer:t.from,next:r,context:{from:t.from}},e._run(n,t.data)))},connect:n});if("function"!=typeof r)throw new Error("pubsub.subscribe must return a function to unsubscribe");return this.unsubscribe=r,this.publish=t.publish,this},e.prototype.unsubscribe=function(){throw new Error("Cannot unsubscribe: not subscribed")},e.prototype.publish=function(){throw new Error("Cannot publish: not subscribed")},e.prototype.listen=function u(t,n){if("string"!=typeof t)throw new TypeError("Parameter message must be a string");var u=new a(n);return this.listeners[t]=u,u},e.prototype.tell=function(t,n,e){this.publish(t,{from:this.id,to:t,message:n,data:e})},e.prototype.ask=function(t,n,e,i){var o=r.v4();"function"==typeof e&&(i=e,e=void 0);var u=new a(i);return this.conversations[o]={id:o,peer:t,next:u,context:{from:t}},this.publish(t,{id:o,from:this.id,to:t,message:n,data:e}),u},e.prototype._run=function(t,n){delete this.conversations[t.id];var e=t.next;do{var r=e.execute(n,t.context);e instanceof o&&this.publish(t.peer,{id:t.id,from:this.id,to:t.peer,message:r.result}),n=r.result,e=r.block,e instanceof a&&(t.next=e,this.conversations[t.id]=t)}while(e&&!(e instanceof a))},n.exports=e},{"./block/Action":4,"./block/Block":5,"./block/Listen":7,"./block/Reply":8,"./pubsub":9,"node-uuid":20}],3:[function(t,n,e){var r=t("./Babbler"),i=t("./block/Reply"),o=t("./block/Action"),a=t("./block/Decision");e.babbler=function(t){return new r(t)},e.reply=function(t){return new i(t)},e.decide=function(t,n){return new a(t,n)},e.run=function(t){return new o(t)},e.Babbler=r,e.block={Block:t("./block/Block"),Action:t("./block/Action"),Decision:t("./block/Decision"),Listen:t("./block/Listen"),Reply:t("./block/Reply")},e.pubsub=t("./pubsub")},{"./Babbler":2,"./block/Action":4,"./block/Block":5,"./block/Decision":6,"./block/Listen":7,"./block/Reply":8,"./pubsub":9}],4:[function(t,n){function e(t){if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if("function"!=typeof t)throw new TypeError("Parameter callback must be a Function");this.callback=t}var r=t("./Block");e.prototype=Object.create(r.prototype),e.prototype.execute=function(t,n){var e=this.callback(t,n);return{result:e,block:this.next}},r.prototype.run=function(t){var n=new e(t);return this.then(n)},n.exports=e},{"./Block":5}],5:[function(t,n){function e(){this.next=null,this.previous=null}e.prototype.execute=function(){throw new Error("Cannot run an abstract Block")},e.prototype.then=function(t){if(!(t instanceof e))throw new TypeError("Parameter next must be a Block");for(var n=this;n.next;)n=n.next;for(var r=this;r.previous;)r=r.previous;return t.previous=this,n.next=t,r},n.exports=e},{}],6:[function(t,n){function e(t,n){var r,i;if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if("function"==typeof t?(r=t,i=n):(r=null,i=t),r){if("function"!=typeof r)throw new TypeError("Parameter decision must be a function")}else r=function(t){return t};if(i&&i instanceof Function)throw new TypeError("Parameter choices must be an object");if(this.decision=r,this.choices={},i){var o=this;Object.keys(i).forEach(function(t){o.addChoice(t,i[t])})}}var r=t("./Block");e.prototype=Object.create(r.prototype),e.prototype.execute=function(t,n){var e=this.decision(t,n);if("string"!=typeof e)throw new TypeError("Decision function must return a string containing the id of the next block");var r=this.choices[e];if(!r)throw new Error('Block with id "'+e+'" not found');return{result:t,block:r}},e.prototype.addChoice=function(t,n){if("string"!=typeof t)throw new TypeError("String expected as choice id");if(!(n instanceof r))throw new TypeError("Block expected as choice");if(t in this.choices)throw new Error('Choice with id "'+t+'" already exists');return this.choices[t]=n,this},r.prototype.decide=function(t,n){var r=new e(t,n);return this.then(r)},n.exports=e},{"./Block":5}],7:[function(t,n){function e(t){if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if(t&&"function"!=typeof t)throw new TypeError("Parameter callback must be a Function");this.callback=t||function(t){return t}}var r=t("./Block");e.prototype=Object.create(r.prototype),e.prototype.execute=function(t,n){var e=this.callback(t,n);return{result:e,block:this.next}},r.prototype.listen=function(t){var n=new e(t);return this.then(n)},n.exports=e},{"./Block":5}],8:[function(t,n){function e(t){if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if("function"!=typeof t)throw new TypeError("Parameter callback must be a Function");this.callback=t}var r=t("./Block");e.prototype=Object.create(r.prototype),e.prototype.execute=function(t,n){var e=this.callback(t,n);return{result:e,block:this.next}},r.prototype.reply=function(t){var n=new e(t);return this.then(n)},n.exports=e},{"./Block":5}],9:[function(t,n,e){e["pubsub-js"]=function(){var n=t("pubsub-js");return{subscribe:function(t){var e=n.subscribe(t.id,function(n,e){t.message(e)});return"function"==typeof t.connect&&t.connect(),function(){n.unsubscribe(e)}},publish:function(t,e){n.publish(t,e)}}},e.pubnub=function(n){var e;if("undefined"!=typeof window){if("undefined"==typeof window.PUBNUB)throw new Error("Please load pubnub first in the browser");e=window.PUBNUB}else e=t("pubnub");var r=e.init(n);return{subscribe:function(t){return r.subscribe({channel:t.id,message:t.message,connect:t.connect}),function(){r.unsubscribe(t.id)}},publish:function(t,n){r.publish({channel:t,message:n})}}},e["default"]=e["pubsub-js"]},{pubnub:"NaMlu/","pubsub-js":21}],10:[function(t,n){function e(t,n){if(t.length%a!==0){var e=t.length+(a-t.length%a);t=o.concat([t,u],e)}for(var r=[],i=n?t.readInt32BE:t.readInt32LE,f=0;f<t.length;f+=a)r.push(i.call(t,f));return r}function r(t,n,e){for(var r=new o(n),i=e?r.writeInt32BE:r.writeInt32LE,a=0;a<t.length;a++)i.call(r,t[a],4*a,!0);return r}function i(t,n,i,a){o.isBuffer(t)||(t=new o(t));var u=n(e(t,a),t.length*f);return r(u,i,a)}var o=t("buffer").Buffer,a=4,u=new o(a);u.fill(0);var f=8;n.exports={hash:i}},{buffer:17}],11:[function(t,n,e){function r(t,n,e){u.isBuffer(n)||(n=new u(n)),u.isBuffer(e)||(e=new u(e)),n.length>p?n=t(n):n.length<p&&(n=u.concat([n,d],p));for(var r=new u(p),i=new u(p),o=0;p>o;o++)r[o]=54^n[o],i[o]=92^n[o];var a=t(u.concat([r,e]));return t(u.concat([i,a]))}function i(t,n){t=t||"sha1";var e=h[t],i=[],a=0;return e||o("algorithm:",t,"is not yet supported"),{update:function(t){return u.isBuffer(t)||(t=new u(t)),i.push(t),a+=t.length,this},digest:function(t){var o=u.concat(i),a=n?r(e,n,o):e(o);return i=null,t?a.toString(t):a}}}function o(){var t=[].slice.call(arguments).join(" ");throw new Error([t,"we accept pull requests","http://github.com/dominictarr/crypto-browserify"].join("\n"))}function a(t,n){for(var e in t)n(t[e],e)}var u=t("buffer").Buffer,f=t("./sha"),s=t("./sha256"),c=t("./rng"),l=t("./md5"),h={sha1:f,sha256:s,md5:l},p=64,d=new u(p);d.fill(0),e.createHash=function(t){return i(t)},e.createHmac=function(t,n){return i(t,n)},e.randomBytes=function(t,n){if(!n||!n.call)return new u(c(t));try{n.call(this,void 0,new u(c(t)))}catch(e){n(e)}},a(["createCredentials","createCipher","createCipheriv","createDecipher","createDecipheriv","createSign","createVerify","createDiffieHellman","pbkdf2"],function(t){e[t]=function(){o("sorry,",t,"is not implemented yet")}})},{"./md5":12,"./rng":13,"./sha":14,"./sha256":15,buffer:17}],12:[function(t,n){function e(t,n){t[n>>5]|=128<<n%32,t[(n+64>>>9<<4)+14]=n;for(var e=1732584193,r=-271733879,s=-1732584194,c=271733878,l=0;l<t.length;l+=16){var h=e,p=r,d=s,g=c;e=i(e,r,s,c,t[l+0],7,-680876936),c=i(c,e,r,s,t[l+1],12,-389564586),s=i(s,c,e,r,t[l+2],17,606105819),r=i(r,s,c,e,t[l+3],22,-1044525330),e=i(e,r,s,c,t[l+4],7,-176418897),c=i(c,e,r,s,t[l+5],12,1200080426),s=i(s,c,e,r,t[l+6],17,-1473231341),r=i(r,s,c,e,t[l+7],22,-45705983),e=i(e,r,s,c,t[l+8],7,1770035416),c=i(c,e,r,s,t[l+9],12,-1958414417),s=i(s,c,e,r,t[l+10],17,-42063),r=i(r,s,c,e,t[l+11],22,-1990404162),e=i(e,r,s,c,t[l+12],7,1804603682),c=i(c,e,r,s,t[l+13],12,-40341101),s=i(s,c,e,r,t[l+14],17,-1502002290),r=i(r,s,c,e,t[l+15],22,1236535329),e=o(e,r,s,c,t[l+1],5,-165796510),c=o(c,e,r,s,t[l+6],9,-1069501632),s=o(s,c,e,r,t[l+11],14,643717713),r=o(r,s,c,e,t[l+0],20,-373897302),e=o(e,r,s,c,t[l+5],5,-701558691),c=o(c,e,r,s,t[l+10],9,38016083),s=o(s,c,e,r,t[l+15],14,-660478335),r=o(r,s,c,e,t[l+4],20,-405537848),e=o(e,r,s,c,t[l+9],5,568446438),c=o(c,e,r,s,t[l+14],9,-1019803690),s=o(s,c,e,r,t[l+3],14,-187363961),r=o(r,s,c,e,t[l+8],20,1163531501),e=o(e,r,s,c,t[l+13],5,-1444681467),c=o(c,e,r,s,t[l+2],9,-51403784),s=o(s,c,e,r,t[l+7],14,1735328473),r=o(r,s,c,e,t[l+12],20,-1926607734),e=a(e,r,s,c,t[l+5],4,-378558),c=a(c,e,r,s,t[l+8],11,-2022574463),s=a(s,c,e,r,t[l+11],16,1839030562),r=a(r,s,c,e,t[l+14],23,-35309556),e=a(e,r,s,c,t[l+1],4,-1530992060),c=a(c,e,r,s,t[l+4],11,1272893353),s=a(s,c,e,r,t[l+7],16,-155497632),r=a(r,s,c,e,t[l+10],23,-1094730640),e=a(e,r,s,c,t[l+13],4,681279174),c=a(c,e,r,s,t[l+0],11,-358537222),s=a(s,c,e,r,t[l+3],16,-722521979),r=a(r,s,c,e,t[l+6],23,76029189),e=a(e,r,s,c,t[l+9],4,-640364487),c=a(c,e,r,s,t[l+12],11,-421815835),s=a(s,c,e,r,t[l+15],16,530742520),r=a(r,s,c,e,t[l+2],23,-995338651),e=u(e,r,s,c,t[l+0],6,-198630844),c=u(c,e,r,s,t[l+7],10,1126891415),s=u(s,c,e,r,t[l+14],15,-1416354905),r=u(r,s,c,e,t[l+5],21,-57434055),e=u(e,r,s,c,t[l+12],6,1700485571),c=u(c,e,r,s,t[l+3],10,-1894986606),s=u(s,c,e,r,t[l+10],15,-1051523),r=u(r,s,c,e,t[l+1],21,-2054922799),e=u(e,r,s,c,t[l+8],6,1873313359),c=u(c,e,r,s,t[l+15],10,-30611744),s=u(s,c,e,r,t[l+6],15,-1560198380),r=u(r,s,c,e,t[l+13],21,1309151649),e=u(e,r,s,c,t[l+4],6,-145523070),c=u(c,e,r,s,t[l+11],10,-1120210379),s=u(s,c,e,r,t[l+2],15,718787259),r=u(r,s,c,e,t[l+9],21,-343485551),e=f(e,h),r=f(r,p),s=f(s,d),c=f(c,g)}return Array(e,r,s,c)}function r(t,n,e,r,i,o){return f(s(f(f(n,t),f(r,o)),i),e)}function i(t,n,e,i,o,a,u){return r(n&e|~n&i,t,n,o,a,u)}function o(t,n,e,i,o,a,u){return r(n&i|e&~i,t,n,o,a,u)}function a(t,n,e,i,o,a,u){return r(n^e^i,t,n,o,a,u)}function u(t,n,e,i,o,a,u){return r(e^(n|~i),t,n,o,a,u)}function f(t,n){var e=(65535&t)+(65535&n),r=(t>>16)+(n>>16)+(e>>16);return r<<16|65535&e}function s(t,n){return t<<n|t>>>32-n}var c=t("./helpers");n.exports=function(t){return c.hash(t,e,16)}},{"./helpers":10}],13:[function(t,n){!function(){var t,e,r=this;t=function(t){for(var n,n,e=new Array(t),r=0;t>r;r++)0==(3&r)&&(n=4294967296*Math.random()),e[r]=n>>>((3&r)<<3)&255;return e},r.crypto&&crypto.getRandomValues&&(e=function(t){var n=new Uint8Array(t);return crypto.getRandomValues(n),n}),n.exports=e||t}()},{}],14:[function(t,n){function e(t,n){t[n>>5]|=128<<24-n%32,t[(n+64>>9<<4)+15]=n;for(var e=Array(80),u=1732584193,f=-271733879,s=-1732584194,c=271733878,l=-1009589776,h=0;h<t.length;h+=16){for(var p=u,d=f,g=s,y=c,w=l,b=0;80>b;b++){e[b]=16>b?t[h+b]:a(e[b-3]^e[b-8]^e[b-14]^e[b-16],1);var v=o(o(a(u,5),r(b,f,s,c)),o(o(l,e[b]),i(b)));l=c,c=s,s=a(f,30),f=u,u=v}u=o(u,p),f=o(f,d),s=o(s,g),c=o(c,y),l=o(l,w)}return Array(u,f,s,c,l)}function r(t,n,e,r){return 20>t?n&e|~n&r:40>t?n^e^r:60>t?n&e|n&r|e&r:n^e^r}function i(t){return 20>t?1518500249:40>t?1859775393:60>t?-1894007588:-899497514}function o(t,n){var e=(65535&t)+(65535&n),r=(t>>16)+(n>>16)+(e>>16);return r<<16|65535&e}function a(t,n){return t<<n|t>>>32-n}var u=t("./helpers");n.exports=function(t){return u.hash(t,e,20,!0)}},{"./helpers":10}],15:[function(t,n){var e=t("./helpers"),r=function(t,n){var e=(65535&t)+(65535&n),r=(t>>16)+(n>>16)+(e>>16);return r<<16|65535&e},i=function(t,n){return t>>>n|t<<32-n},o=function(t,n){return t>>>n},a=function(t,n,e){return t&n^~t&e},u=function(t,n,e){return t&n^t&e^n&e},f=function(t){return i(t,2)^i(t,13)^i(t,22)},s=function(t){return i(t,6)^i(t,11)^i(t,25)},c=function(t){return i(t,7)^i(t,18)^o(t,3)},l=function(t){return i(t,17)^i(t,19)^o(t,10)},h=function(t,n){var e,i,o,h,p,d,g,y,w,b,v,m,E=new Array(1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298),I=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),B=new Array(64);t[n>>5]|=128<<24-n%32,t[(n+64>>9<<4)+15]=n;for(var w=0;w<t.length;w+=16){e=I[0],i=I[1],o=I[2],h=I[3],p=I[4],d=I[5],g=I[6],y=I[7];for(var b=0;64>b;b++)B[b]=16>b?t[b+w]:r(r(r(l(B[b-2]),B[b-7]),c(B[b-15])),B[b-16]),v=r(r(r(r(y,s(p)),a(p,d,g)),E[b]),B[b]),m=r(f(e),u(e,i,o)),y=g,g=d,d=p,p=r(h,v),h=o,o=i,i=e,e=r(v,m);I[0]=r(e,I[0]),I[1]=r(i,I[1]),I[2]=r(o,I[2]),I[3]=r(h,I[3]),I[4]=r(p,I[4]),I[5]=r(d,I[5]),I[6]=r(g,I[6]),I[7]=r(y,I[7])}return I};n.exports=function(t){return e.hash(t,h,32,!0)}},{"./helpers":10}],16:[function(t,n){t=function e(n,r,i){function o(u,f){if(!r[u]){if(!n[u]){var s="function"==typeof t&&t;if(!f&&s)return s(u,!0);if(a)return a(u,!0);throw new Error("Cannot find module '"+u+"'")}var c=r[u]={exports:{}};n[u][0].call(c.exports,function(t){var e=n[u][1][t];return o(e?e:t)},c,c.exports,e,n,r,i)}return r[u].exports}for(var a="function"==typeof t&&t,u=0;u<i.length;u++)o(i[u]);return o}({PcZj9L:[function(t,n,e){function r(t,n,e){if(!(this instanceof r))return new r(t,n,e);var i=typeof t;if("base64"===n&&"string"===i)for(t=x(t);t.length%4!==0;)t+="=";var o;if("number"===i)o=C(t);else if("string"===i)o=r.byteLength(t,n);else{if("object"!==i)throw new Error("First argument needs to be a number, array or string.");o=C(t.length)}var a;Y?a=k(new Uint8Array(o)):(a=this,a.length=o);var u;if(r.isBuffer(t))a.set(t);else if(M(t))for(u=0;o>u;u++)a[u]=r.isBuffer(t)?t.readUInt8(u):t[u];else if("string"===i)a.write(t,0,n);else if("number"===i&&!Y&&!e)for(u=0;o>u;u++)a[u]=0;return a}function i(t,n,e,i){e=Number(e)||0;var o=t.length-e;i?(i=Number(i),i>o&&(i=o)):i=o;var a=n.length;if(a%2!==0)throw new Error("Invalid hex string");i>a/2&&(i=a/2);for(var u=0;i>u;u++){var f=parseInt(n.substr(2*u,2),16);if(isNaN(f))throw new Error("Invalid hex string");t[e+u]=f}return r._charsWritten=2*u,u}function o(t,n,e,i){return r._charsWritten=O(D(n),t,e,i)}function a(t,n,e,i){return r._charsWritten=O(N(n),t,e,i)}function u(t,n,e,r){return a(t,n,e,r)}function f(t,n,e,i){return r._charsWritten=O(F(n),t,e,i)}function s(t,n,e){return 0===n&&e===t.length?J.fromByteArray(t):J.fromByteArray(t.slice(n,e))}function c(t,n,e){var r="",i="";e=Math.min(t.length,e);for(var o=n;e>o;o++)t[o]<=127?(r+=P(i)+String.fromCharCode(t[o]),i=""):i+="%"+t[o].toString(16);return r+P(i)}function l(t,n,e){var r="";e=Math.min(t.length,e);for(var i=n;e>i;i++)r+=String.fromCharCode(t[i]);return r}function h(t,n,e){return l(t,n,e)}function p(t,n,e){var r=t.length;(!n||0>n)&&(n=0),(!e||0>e||e>r)&&(e=r);for(var i="",o=n;e>o;o++)i+=_(t[o]);return i}function d(t,n,e,r){r||(W("boolean"==typeof e,"missing or invalid endian"),W(void 0!==n&&null!==n,"missing offset"),W(n+1<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){if(Y){if(i>n+1)return t._dataview.getUint16(n,e);var o=new DataView(new ArrayBuffer(2));return o.setUint8(0,t[i-1]),o.getUint16(0,e)}var a;return e?(a=t[n],i>n+1&&(a|=t[n+1]<<8)):(a=t[n]<<8,i>n+1&&(a|=t[n+1])),a}}function g(t,n,e,r){r||(W("boolean"==typeof e,"missing or invalid endian"),W(void 0!==n&&null!==n,"missing offset"),W(n+3<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){if(Y){if(i>n+3)return t._dataview.getUint32(n,e);for(var o=new DataView(new ArrayBuffer(4)),a=0;i>a+n;a++)o.setUint8(a,t[a+n]);return o.getUint32(0,e)}var u;return e?(i>n+2&&(u=t[n+2]<<16),i>n+1&&(u|=t[n+1]<<8),u|=t[n],i>n+3&&(u+=t[n+3]<<24>>>0)):(i>n+1&&(u=t[n+1]<<16),i>n+2&&(u|=t[n+2]<<8),i>n+3&&(u|=t[n+3]),u+=t[n]<<24>>>0),u}}function y(t,n,e,r){r||(W("boolean"==typeof e,"missing or invalid endian"),W(void 0!==n&&null!==n,"missing offset"),W(n+1<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){if(Y){if(n+1===i){var o=new DataView(new ArrayBuffer(2));return o.setUint8(0,t[i-1]),o.getInt16(0,e)}return t._dataview.getInt16(n,e)}var a=d(t,n,e,!0),u=32768&a;return u?-1*(65535-a+1):a}}function w(t,n,e,r){r||(W("boolean"==typeof e,"missing or invalid endian"),W(void 0!==n&&null!==n,"missing offset"),W(n+3<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){if(Y){if(n+3>=i){for(var o=new DataView(new ArrayBuffer(4)),a=0;i>a+n;a++)o.setUint8(a,t[a+n]);return o.getInt32(0,e)}return t._dataview.getInt32(n,e)}var u=g(t,n,e,!0),f=2147483648&u;return f?-1*(4294967295-u+1):u}}function b(t,n,e,r){return r||(W("boolean"==typeof e,"missing or invalid endian"),W(n+3<t.length,"Trying to read beyond buffer length")),Y?t._dataview.getFloat32(n,e):X.read(t,n,e,23,4)}function v(t,n,e,r){return r||(W("boolean"==typeof e,"missing or invalid endian"),W(n+7<t.length,"Trying to read beyond buffer length")),Y?t._dataview.getFloat64(n,e):X.read(t,n,e,52,8)}function m(t,n,e,r,i){i||(W(void 0!==n&&null!==n,"missing value"),W("boolean"==typeof r,"missing or invalid endian"),W(void 0!==e&&null!==e,"missing offset"),W(e+1<t.length,"trying to write beyond buffer length"),V(n,65535));var o=t.length;if(!(e>=o))if(Y)if(e+1===o){var a=new DataView(new ArrayBuffer(2));a.setUint16(0,n,r),t[e]=a.getUint8(0)}else t._dataview.setUint16(e,n,r);else for(var u=0,f=Math.min(o-e,2);f>u;u++)t[e+u]=(n&255<<8*(r?u:1-u))>>>8*(r?u:1-u)}function E(t,n,e,r,i){i||(W(void 0!==n&&null!==n,"missing value"),W("boolean"==typeof r,"missing or invalid endian"),W(void 0!==e&&null!==e,"missing offset"),W(e+3<t.length,"trying to write beyond buffer length"),V(n,4294967295));var o=t.length;if(!(e>=o)){var a;if(Y)if(e+3>=o){var u=new DataView(new ArrayBuffer(4));for(u.setUint32(0,n,r),a=0;o>a+e;a++)t[a+e]=u.getUint8(a)}else t._dataview.setUint32(e,n,r);else for(a=0,j=Math.min(o-e,4);j>a;a++)t[e+a]=n>>>8*(r?a:3-a)&255}}function I(t,n,e,r,i){i||(W(void 0!==n&&null!==n,"missing value"),W("boolean"==typeof r,"missing or invalid endian"),W(void 0!==e&&null!==e,"missing offset"),W(e+1<t.length,"Trying to write beyond buffer length"),R(n,32767,-32768));var o=t.length;if(!(e>=o))if(Y)if(e+1===o){var a=new DataView(new ArrayBuffer(2));a.setInt16(0,n,r),t[e]=a.getUint8(0)}else t._dataview.setInt16(e,n,r);else n>=0?m(t,n,e,r,i):m(t,65535+n+1,e,r,i)}function B(t,n,e,r,i){i||(W(void 0!==n&&null!==n,"missing value"),W("boolean"==typeof r,"missing or invalid endian"),W(void 0!==e&&null!==e,"missing offset"),W(e+3<t.length,"Trying to write beyond buffer length"),R(n,2147483647,-2147483648));var o=t.length;if(!(e>=o))if(Y)if(e+3>=o){var a=new DataView(new ArrayBuffer(4));a.setInt32(0,n,r);for(var u=0;o>u+e;u++)t[u+e]=a.getUint8(u)}else t._dataview.setInt32(e,n,r);else n>=0?E(t,n,e,r,i):E(t,4294967295+n+1,e,r,i)}function A(t,n,e,r,i){i||(W(void 0!==n&&null!==n,"missing value"),W("boolean"==typeof r,"missing or invalid endian"),W(void 0!==e&&null!==e,"missing offset"),W(e+3<t.length,"Trying to write beyond buffer length"),q(n,3.4028234663852886e38,-3.4028234663852886e38));var o=t.length;if(!(e>=o))if(Y)if(e+3>=o){var a=new DataView(new ArrayBuffer(4));a.setFloat32(0,n,r);for(var u=0;o>u+e;u++)t[u+e]=a.getUint8(u)}else t._dataview.setFloat32(e,n,r);else X.write(t,n,e,r,23,4)}function U(t,n,e,r,i){i||(W(void 0!==n&&null!==n,"missing value"),W("boolean"==typeof r,"missing or invalid endian"),W(void 0!==e&&null!==e,"missing offset"),W(e+7<t.length,"Trying to write beyond buffer length"),q(n,1.7976931348623157e308,-1.7976931348623157e308));var o=t.length;if(!(e>=o))if(Y)if(e+7>=o){var a=new DataView(new ArrayBuffer(8));a.setFloat64(0,n,r);for(var u=0;o>u+e;u++)t[u+e]=a.getUint8(u)}else t._dataview.setFloat64(e,n,r);else X.write(t,n,e,r,52,8)}function L(){return new r(this).buffer}function x(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function k(t){return t._isBuffer=!0,t.write=H.write,t.toString=H.toString,t.toLocaleString=H.toString,t.toJSON=H.toJSON,t.copy=H.copy,t.slice=H.slice,t.readUInt8=H.readUInt8,t.readUInt16LE=H.readUInt16LE,t.readUInt16BE=H.readUInt16BE,t.readUInt32LE=H.readUInt32LE,t.readUInt32BE=H.readUInt32BE,t.readInt8=H.readInt8,t.readInt16LE=H.readInt16LE,t.readInt16BE=H.readInt16BE,t.readInt32LE=H.readInt32LE,t.readInt32BE=H.readInt32BE,t.readFloatLE=H.readFloatLE,t.readFloatBE=H.readFloatBE,t.readDoubleLE=H.readDoubleLE,t.readDoubleBE=H.readDoubleBE,t.writeUInt8=H.writeUInt8,t.writeUInt16LE=H.writeUInt16LE,t.writeUInt16BE=H.writeUInt16BE,t.writeUInt32LE=H.writeUInt32LE,t.writeUInt32BE=H.writeUInt32BE,t.writeInt8=H.writeInt8,t.writeInt16LE=H.writeInt16LE,t.writeInt16BE=H.writeInt16BE,t.writeInt32LE=H.writeInt32LE,t.writeInt32BE=H.writeInt32BE,t.writeFloatLE=H.writeFloatLE,t.writeFloatBE=H.writeFloatBE,t.writeDoubleLE=H.writeDoubleLE,t.writeDoubleBE=H.writeDoubleBE,t.fill=H.fill,t.inspect=H.inspect,t.toArrayBuffer=L,0!==t.byteLength&&(t._dataview=new DataView(t.buffer,t.byteOffset,t.byteLength)),t}function S(t,n,e){return"number"!=typeof t?e:(t=~~t,t>=n?n:t>=0?t:(t+=n,t>=0?t:0))}function C(t){return t=~~Math.ceil(+t),0>t?0:t}function T(t){return(Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)})(t)}function M(t){return T(t)||r.isBuffer(t)||t&&"object"==typeof t&&"number"==typeof t.length}function _(t){return 16>t?"0"+t.toString(16):t.toString(16)}function D(t){for(var n=[],e=0;e<t.length;e++)if(t.charCodeAt(e)<=127)n.push(t.charCodeAt(e));else for(var r=encodeURIComponent(t.charAt(e)).substr(1).split("%"),i=0;i<r.length;i++)n.push(parseInt(r[i],16));return n}function N(t){for(var n=[],e=0;e<t.length;e++)n.push(255&t.charCodeAt(e));return n}function F(t){return J.toByteArray(t)}function O(t,n,e,r){for(var i=0;r>i&&!(i+e>=n.length||i>=t.length);i++)n[i+e]=t[i];return i}function P(t){try{return decodeURIComponent(t)}catch(n){return String.fromCharCode(65533)}}function V(t,n){W("number"==typeof t,"cannot write a non-number as a number"),W(t>=0,"specified a negative value for writing an unsigned value"),W(n>=t,"value is larger than maximum value for type"),W(Math.floor(t)===t,"value has a fractional component")}function R(t,n,e){W("number"==typeof t,"cannot write a non-number as a number"),W(n>=t,"value larger than maximum allowed value"),W(t>=e,"value smaller than minimum allowed value"),W(Math.floor(t)===t,"value has a fractional component")}function q(t,n,e){W("number"==typeof t,"cannot write a non-number as a number"),W(n>=t,"value larger than maximum allowed value"),W(t>=e,"value smaller than minimum allowed value")}function W(t,n){if(!t)throw new Error(n||"Failed assertion")}var J=t("base64-js"),X=t("ieee754");e.Buffer=r,e.SlowBuffer=r,e.INSPECT_MAX_BYTES=50,r.poolSize=8192;var Y=function(){if("undefined"==typeof Uint8Array||"undefined"==typeof ArrayBuffer||"undefined"==typeof DataView)return!1;try{var t=new Uint8Array(0);return t.foo=function(){return 42},42===t.foo()}catch(n){return!1}}();r.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":return!0;default:return!1}},r.isBuffer=function(t){return t&&t._isBuffer},r.byteLength=function(t,n){switch(n||"utf8"){case"hex":return t.length/2;case"utf8":case"utf-8":return D(t).length;case"ascii":case"binary":return t.length;case"base64":return F(t).length;default:throw new Error("Unknown encoding")}},r.concat=function(t,n){if(!T(t))throw new Error("Usage: Buffer.concat(list, [totalLength])\nlist should be an Array.");if(0===t.length)return new r(0);if(1===t.length)return t[0];var e;if("number"!=typeof n)for(n=0,e=0;e<t.length;e++)n+=t[e].length;var i=new r(n),o=0;for(e=0;e<t.length;e++){var a=t[e];a.copy(i,o),o+=a.length}return i},r.prototype.write=function(t,n,e,r){if(isFinite(n))isFinite(e)||(r=e,e=void 0);else{var s=r;r=n,n=e,e=s}n=Number(n)||0;var c=this.length-n;switch(e?(e=Number(e),e>c&&(e=c)):e=c,r=String(r||"utf8").toLowerCase()){case"hex":return i(this,t,n,e);case"utf8":case"utf-8":return o(this,t,n,e);case"ascii":return a(this,t,n,e);case"binary":return u(this,t,n,e);case"base64":return f(this,t,n,e);default:throw new Error("Unknown encoding")}},r.prototype.toString=function(t,n,e){var r=this;if(t=String(t||"utf8").toLowerCase(),n=Number(n)||0,e=void 0!==e?Number(e):e=r.length,e===n)return"";switch(t){case"hex":return p(r,n,e);case"utf8":case"utf-8":return c(r,n,e);case"ascii":return l(r,n,e);case"binary":return h(r,n,e);case"base64":return s(r,n,e);default:throw new Error("Unknown encoding")}},r.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},r.prototype.copy=function(t,n,e,r){var i=this;if(e||(e=0),r||0===r||(r=this.length),n||(n=0),r!==e&&0!==t.length&&0!==i.length){if(e>r)throw new Error("sourceEnd < sourceStart");if(0>n||n>=t.length)throw new Error("targetStart out of bounds");if(0>e||e>=i.length)throw new Error("sourceStart out of bounds");if(0>r||r>i.length)throw new Error("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-n<r-e&&(r=t.length-n+e);for(var o=0;r-e>o;o++)t[o+n]=this[o+e]}},r.prototype.slice=function(t,n){var e=this.length;if(t=S(t,e,0),n=S(n,e,e),Y)return k(this.subarray(t,n));for(var i=n-t,o=new r(i,void 0,!0),a=0;i>a;a++)o[a]=this[a+t];return o},r.prototype.readUInt8=function(t,n){var e=this;return n||(W(void 0!==t&&null!==t,"missing offset"),W(t<e.length,"Trying to read beyond buffer length")),t>=e.length?void 0:e[t]},r.prototype.readUInt16LE=function(t,n){return d(this,t,!0,n)},r.prototype.readUInt16BE=function(t,n){return d(this,t,!1,n)},r.prototype.readUInt32LE=function(t,n){return g(this,t,!0,n)},r.prototype.readUInt32BE=function(t,n){return g(this,t,!1,n)},r.prototype.readInt8=function(t,n){var e=this;if(n||(W(void 0!==t&&null!==t,"missing offset"),W(t<e.length,"Trying to read beyond buffer length")),!(t>=e.length)){if(Y)return e._dataview.getInt8(t);var r=128&e[t];return r?-1*(255-e[t]+1):e[t]}},r.prototype.readInt16LE=function(t,n){return y(this,t,!0,n)},r.prototype.readInt16BE=function(t,n){return y(this,t,!1,n)},r.prototype.readInt32LE=function(t,n){return w(this,t,!0,n)},r.prototype.readInt32BE=function(t,n){return w(this,t,!1,n)},r.prototype.readFloatLE=function(t,n){return b(this,t,!0,n)},r.prototype.readFloatBE=function(t,n){return b(this,t,!1,n)},r.prototype.readDoubleLE=function(t,n){return v(this,t,!0,n)},r.prototype.readDoubleBE=function(t,n){return v(this,t,!1,n)},r.prototype.writeUInt8=function(t,n,e){var r=this;e||(W(void 0!==t&&null!==t,"missing value"),W(void 0!==n&&null!==n,"missing offset"),W(n<r.length,"trying to write beyond buffer length"),V(t,255)),n>=r.length||(r[n]=t)},r.prototype.writeUInt16LE=function(t,n,e){m(this,t,n,!0,e)},r.prototype.writeUInt16BE=function(t,n,e){m(this,t,n,!1,e)},r.prototype.writeUInt32LE=function(t,n,e){E(this,t,n,!0,e)},r.prototype.writeUInt32BE=function(t,n,e){E(this,t,n,!1,e)},r.prototype.writeInt8=function(t,n,e){var r=this;e||(W(void 0!==t&&null!==t,"missing value"),W(void 0!==n&&null!==n,"missing offset"),W(n<r.length,"Trying to write beyond buffer length"),R(t,127,-128)),n>=r.length||(Y?r._dataview.setInt8(n,t):t>=0?r.writeUInt8(t,n,e):r.writeUInt8(255+t+1,n,e))},r.prototype.writeInt16LE=function(t,n,e){I(this,t,n,!0,e)},r.prototype.writeInt16BE=function(t,n,e){I(this,t,n,!1,e)},r.prototype.writeInt32LE=function(t,n,e){B(this,t,n,!0,e)},r.prototype.writeInt32BE=function(t,n,e){B(this,t,n,!1,e)},r.prototype.writeFloatLE=function(t,n,e){A(this,t,n,!0,e)},r.prototype.writeFloatBE=function(t,n,e){A(this,t,n,!1,e)},r.prototype.writeDoubleLE=function(t,n,e){U(this,t,n,!0,e)},r.prototype.writeDoubleBE=function(t,n,e){U(this,t,n,!1,e)},r.prototype.fill=function(t,n,e){if(t||(t=0),n||(n=0),e||(e=this.length),"string"==typeof t&&(t=t.charCodeAt(0)),"number"!=typeof t||isNaN(t))throw new Error("value is not a number");if(n>e)throw new Error("end < start");if(e!==n&&0!==this.length){if(0>n||n>=this.length)throw new Error("start out of bounds");if(0>e||e>this.length)throw new Error("end out of bounds");for(var r=n;e>r;r++)this[r]=t}},r.prototype.inspect=function(){for(var t=[],n=this.length,r=0;n>r;r++)if(t[r]=_(this[r]),r===e.INSPECT_MAX_BYTES){t[r+1]="...";break}return"<Buffer "+t.join(" ")+">"};var H=r.prototype},{"base64-js":3,ieee754:4}],"native-buffer-browserify":[function(t,n){n.exports=t("PcZj9L")},{}],3:[function(t,n){function e(t,n){var e=t.length,r=Number(arguments[1])||0;for(r=0>r?Math.ceil(r):Math.floor(r),0>r&&(r+=e);e>r;r++)if("string"==typeof t&&t.charAt(r)===n||"string"!=typeof t&&t[r]===n)return r;return-1}!function(){"use strict";function t(t){var n,r,o,a,u,f;if(t.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(u=e(t,"="),u=u>0?t.length-u:0,f=[],o=u>0?t.length-4:t.length,n=0,r=0;o>n;n+=4,r+=3)a=e(i,t.charAt(n))<<18|e(i,t.charAt(n+1))<<12|e(i,t.charAt(n+2))<<6|e(i,t.charAt(n+3)),f.push((16711680&a)>>16),f.push((65280&a)>>8),f.push(255&a);return 2===u?(a=e(i,t.charAt(n))<<2|e(i,t.charAt(n+1))>>4,f.push(255&a)):1===u&&(a=e(i,t.charAt(n))<<10|e(i,t.charAt(n+1))<<4|e(i,t.charAt(n+2))>>2,f.push(a>>8&255),f.push(255&a)),f}function r(t){function n(t){return i.charAt(t>>18&63)+i.charAt(t>>12&63)+i.charAt(t>>6&63)+i.charAt(63&t)}var e,r,o,a=t.length%3,u="";for(e=0,o=t.length-a;o>e;e+=3)r=(t[e]<<16)+(t[e+1]<<8)+t[e+2],u+=n(r);switch(a){case 1:r=t[t.length-1],u+=i.charAt(r>>2),u+=i.charAt(r<<4&63),u+="==";break;case 2:r=(t[t.length-2]<<8)+t[t.length-1],u+=i.charAt(r>>10),u+=i.charAt(r>>4&63),u+=i.charAt(r<<2&63),u+="="}return u}var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";n.exports.toByteArray=t,n.exports.fromByteArray=r}()},{}],4:[function(t,n,e){e.read=function(t,n,e,r,i){var o,a,u=8*i-r-1,f=(1<<u)-1,s=f>>1,c=-7,l=e?i-1:0,h=e?-1:1,p=t[n+l];for(l+=h,o=p&(1<<-c)-1,p>>=-c,c+=u;c>0;o=256*o+t[n+l],l+=h,c-=8);for(a=o&(1<<-c)-1,o>>=-c,c+=r;c>0;a=256*a+t[n+l],l+=h,c-=8);if(0===o)o=1-s;else{if(o===f)return a?0/0:1/0*(p?-1:1);a+=Math.pow(2,r),o-=s}return(p?-1:1)*a*Math.pow(2,o-r) | ||
},e.write=function(t,n,e,r,i,o){var a,u,f,s=8*o-i-1,c=(1<<s)-1,l=c>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:o-1,d=r?1:-1,g=0>n||0===n&&0>1/n?1:0;for(n=Math.abs(n),isNaN(n)||1/0===n?(u=isNaN(n)?1:0,a=c):(a=Math.floor(Math.log(n)/Math.LN2),n*(f=Math.pow(2,-a))<1&&(a--,f*=2),n+=a+l>=1?h/f:h*Math.pow(2,1-l),n*f>=2&&(a++,f/=2),a+l>=c?(u=0,a=c):a+l>=1?(u=(n*f-1)*Math.pow(2,i),a+=l):(u=n*Math.pow(2,l-1)*Math.pow(2,i),a=0));i>=8;t[e+p]=255&u,p+=d,u/=256,i-=8);for(a=a<<i|u,s+=i;s>0;t[e+p]=255&a,p+=d,a/=256,s-=8);t[e+p-d]|=128*g}},{}]},{},[]),n.exports=t("native-buffer-browserify").Buffer},{}],17:[function(t,n,e){function r(t,n,e){if(!(this instanceof r))return new r(t,n,e);var i=typeof t;if("base64"===n&&"string"===i)for(t=x(t);t.length%4!==0;)t+="=";var o;if("number"===i)o=C(t);else if("string"===i)o=r.byteLength(t,n);else{if("object"!==i)throw new Error("First argument needs to be a number, array or string.");o=C(t.length)}var a;r._useTypedArrays?a=k(new Uint8Array(o)):(a=this,a.length=o);var u;if(r.isBuffer(t))a.set(t);else if(M(t))for(u=0;o>u;u++)a[u]=r.isBuffer(t)?t.readUInt8(u):t[u];else if("string"===i)a.write(t,0,n);else if("number"===i&&!r._useTypedArrays&&!e)for(u=0;o>u;u++)a[u]=0;return a}function i(t,n,e,i){e=Number(e)||0;var o=t.length-e;i?(i=Number(i),i>o&&(i=o)):i=o;var a=n.length;q(a%2===0,"Invalid hex string"),i>a/2&&(i=a/2);for(var u=0;i>u;u++){var f=parseInt(n.substr(2*u,2),16);q(!isNaN(f),"Invalid hex string"),t[e+u]=f}return r._charsWritten=2*u,u}function o(t,n,e,i){return r._charsWritten=j(D(n),t,e,i)}function a(t,n,e,i){return r._charsWritten=j(N(n),t,e,i)}function u(t,n,e,r){return a(t,n,e,r)}function f(t,n,e,i){return r._charsWritten=j(F(n),t,e,i)}function s(t,n,e){return 0===n&&e===t.length?W.fromByteArray(t):W.fromByteArray(t.slice(n,e))}function c(t,n,e){var r="",i="";e=Math.min(t.length,e);for(var o=n;e>o;o++)t[o]<=127?(r+=O(i)+String.fromCharCode(t[o]),i=""):i+="%"+t[o].toString(16);return r+O(i)}function l(t,n,e){var r="";e=Math.min(t.length,e);for(var i=n;e>i;i++)r+=String.fromCharCode(t[i]);return r}function h(t,n,e){return l(t,n,e)}function p(t,n,e){var r=t.length;(!n||0>n)&&(n=0),(!e||0>e||e>r)&&(e=r);for(var i="",o=n;e>o;o++)i+=_(t[o]);return i}function d(t,n,e,r){r||(q("boolean"==typeof e,"missing or invalid endian"),q(void 0!==n&&null!==n,"missing offset"),q(n+1<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){var o;return e?(o=t[n],i>n+1&&(o|=t[n+1]<<8)):(o=t[n]<<8,i>n+1&&(o|=t[n+1])),o}}function g(t,n,e,r){r||(q("boolean"==typeof e,"missing or invalid endian"),q(void 0!==n&&null!==n,"missing offset"),q(n+3<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){var o;return e?(i>n+2&&(o=t[n+2]<<16),i>n+1&&(o|=t[n+1]<<8),o|=t[n],i>n+3&&(o+=t[n+3]<<24>>>0)):(i>n+1&&(o=t[n+1]<<16),i>n+2&&(o|=t[n+2]<<8),i>n+3&&(o|=t[n+3]),o+=t[n]<<24>>>0),o}}function y(t,n,e,r){r||(q("boolean"==typeof e,"missing or invalid endian"),q(void 0!==n&&null!==n,"missing offset"),q(n+1<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){var o=d(t,n,e,!0),a=32768&o;return a?-1*(65535-o+1):o}}function w(t,n,e,r){r||(q("boolean"==typeof e,"missing or invalid endian"),q(void 0!==n&&null!==n,"missing offset"),q(n+3<t.length,"Trying to read beyond buffer length"));var i=t.length;if(!(n>=i)){var o=g(t,n,e,!0),a=2147483648&o;return a?-1*(4294967295-o+1):o}}function b(t,n,e,r){return r||(q("boolean"==typeof e,"missing or invalid endian"),q(n+3<t.length,"Trying to read beyond buffer length")),J.read(t,n,e,23,4)}function v(t,n,e,r){return r||(q("boolean"==typeof e,"missing or invalid endian"),q(n+7<t.length,"Trying to read beyond buffer length")),J.read(t,n,e,52,8)}function m(t,n,e,r,i){i||(q(void 0!==n&&null!==n,"missing value"),q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+1<t.length,"trying to write beyond buffer length"),P(n,65535));var o=t.length;if(!(e>=o))for(var a=0,u=Math.min(o-e,2);u>a;a++)t[e+a]=(n&255<<8*(r?a:1-a))>>>8*(r?a:1-a)}function E(t,n,e,r,i){i||(q(void 0!==n&&null!==n,"missing value"),q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+3<t.length,"trying to write beyond buffer length"),P(n,4294967295));var o=t.length;if(!(e>=o))for(var a=0,u=Math.min(o-e,4);u>a;a++)t[e+a]=n>>>8*(r?a:3-a)&255}function I(t,n,e,r,i){i||(q(void 0!==n&&null!==n,"missing value"),q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+1<t.length,"Trying to write beyond buffer length"),V(n,32767,-32768));var o=t.length;e>=o||(n>=0?m(t,n,e,r,i):m(t,65535+n+1,e,r,i))}function B(t,n,e,r,i){i||(q(void 0!==n&&null!==n,"missing value"),q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+3<t.length,"Trying to write beyond buffer length"),V(n,2147483647,-2147483648));var o=t.length;e>=o||(n>=0?E(t,n,e,r,i):E(t,4294967295+n+1,e,r,i))}function A(t,n,e,r,i){i||(q(void 0!==n&&null!==n,"missing value"),q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+3<t.length,"Trying to write beyond buffer length"),R(n,3.4028234663852886e38,-3.4028234663852886e38));var o=t.length;e>=o||J.write(t,n,e,r,23,4)}function U(t,n,e,r,i){i||(q(void 0!==n&&null!==n,"missing value"),q("boolean"==typeof r,"missing or invalid endian"),q(void 0!==e&&null!==e,"missing offset"),q(e+7<t.length,"Trying to write beyond buffer length"),R(n,1.7976931348623157e308,-1.7976931348623157e308));var o=t.length;e>=o||J.write(t,n,e,r,52,8)}function L(){return new r(this).buffer}function x(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function k(t){return t._isBuffer=!0,t.write=X.write,t.toString=X.toString,t.toLocaleString=X.toString,t.toJSON=X.toJSON,t.copy=X.copy,t.slice=X.slice,t.readUInt8=X.readUInt8,t.readUInt16LE=X.readUInt16LE,t.readUInt16BE=X.readUInt16BE,t.readUInt32LE=X.readUInt32LE,t.readUInt32BE=X.readUInt32BE,t.readInt8=X.readInt8,t.readInt16LE=X.readInt16LE,t.readInt16BE=X.readInt16BE,t.readInt32LE=X.readInt32LE,t.readInt32BE=X.readInt32BE,t.readFloatLE=X.readFloatLE,t.readFloatBE=X.readFloatBE,t.readDoubleLE=X.readDoubleLE,t.readDoubleBE=X.readDoubleBE,t.writeUInt8=X.writeUInt8,t.writeUInt16LE=X.writeUInt16LE,t.writeUInt16BE=X.writeUInt16BE,t.writeUInt32LE=X.writeUInt32LE,t.writeUInt32BE=X.writeUInt32BE,t.writeInt8=X.writeInt8,t.writeInt16LE=X.writeInt16LE,t.writeInt16BE=X.writeInt16BE,t.writeInt32LE=X.writeInt32LE,t.writeInt32BE=X.writeInt32BE,t.writeFloatLE=X.writeFloatLE,t.writeFloatBE=X.writeFloatBE,t.writeDoubleLE=X.writeDoubleLE,t.writeDoubleBE=X.writeDoubleBE,t.fill=X.fill,t.inspect=X.inspect,t.toArrayBuffer=L,t}function S(t,n,e){return"number"!=typeof t?e:(t=~~t,t>=n?n:t>=0?t:(t+=n,t>=0?t:0))}function C(t){return t=~~Math.ceil(+t),0>t?0:t}function T(t){return(Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)})(t)}function M(t){return T(t)||r.isBuffer(t)||t&&"object"==typeof t&&"number"==typeof t.length}function _(t){return 16>t?"0"+t.toString(16):t.toString(16)}function D(t){for(var n=[],e=0;e<t.length;e++)if(t.charCodeAt(e)<=127)n.push(t.charCodeAt(e));else for(var r=encodeURIComponent(t.charAt(e)).substr(1).split("%"),i=0;i<r.length;i++)n.push(parseInt(r[i],16));return n}function N(t){for(var n=[],e=0;e<t.length;e++)n.push(255&t.charCodeAt(e));return n}function F(t){return W.toByteArray(t)}function j(t,n,e,r){for(var i=0;r>i&&!(i+e>=n.length||i>=t.length);i++)n[i+e]=t[i];return i}function O(t){try{return decodeURIComponent(t)}catch(n){return String.fromCharCode(65533)}}function P(t,n){q("number"==typeof t,"cannot write a non-number as a number"),q(t>=0,"specified a negative value for writing an unsigned value"),q(n>=t,"value is larger than maximum value for type"),q(Math.floor(t)===t,"value has a fractional component")}function V(t,n,e){q("number"==typeof t,"cannot write a non-number as a number"),q(n>=t,"value larger than maximum allowed value"),q(t>=e,"value smaller than minimum allowed value"),q(Math.floor(t)===t,"value has a fractional component")}function R(t,n,e){q("number"==typeof t,"cannot write a non-number as a number"),q(n>=t,"value larger than maximum allowed value"),q(t>=e,"value smaller than minimum allowed value")}function q(t,n){if(!t)throw new Error(n||"Failed assertion")}var W=t("base64-js"),J=t("ieee754");e.Buffer=r,e.SlowBuffer=r,e.INSPECT_MAX_BYTES=50,r.poolSize=8192,r._useTypedArrays=function(){if("undefined"==typeof Uint8Array||"undefined"==typeof ArrayBuffer)return!1;try{var t=new Uint8Array(0);return t.foo=function(){return 42},42===t.foo()&&"function"==typeof t.subarray}catch(n){return!1}}(),r.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":return!0;default:return!1}},r.isBuffer=function(t){return t&&t._isBuffer},r.byteLength=function(t,n){switch(n||"utf8"){case"hex":return t.length/2;case"utf8":case"utf-8":return D(t).length;case"ascii":case"binary":return t.length;case"base64":return F(t).length;default:throw new Error("Unknown encoding")}},r.concat=function(t,n){if(q(T(t),"Usage: Buffer.concat(list, [totalLength])\nlist should be an Array."),0===t.length)return new r(0);if(1===t.length)return t[0];var e;if("number"!=typeof n)for(n=0,e=0;e<t.length;e++)n+=t[e].length;var i=new r(n),o=0;for(e=0;e<t.length;e++){var a=t[e];a.copy(i,o),o+=a.length}return i},r.prototype.write=function(t,n,e,r){if(isFinite(n))isFinite(e)||(r=e,e=void 0);else{var s=r;r=n,n=e,e=s}n=Number(n)||0;var c=this.length-n;switch(e?(e=Number(e),e>c&&(e=c)):e=c,r=String(r||"utf8").toLowerCase()){case"hex":return i(this,t,n,e);case"utf8":case"utf-8":return o(this,t,n,e);case"ascii":return a(this,t,n,e);case"binary":return u(this,t,n,e);case"base64":return f(this,t,n,e);default:throw new Error("Unknown encoding")}},r.prototype.toString=function(t,n,e){var r=this;if(t=String(t||"utf8").toLowerCase(),n=Number(n)||0,e=void 0!==e?Number(e):e=r.length,e===n)return"";switch(t){case"hex":return p(r,n,e);case"utf8":case"utf-8":return c(r,n,e);case"ascii":return l(r,n,e);case"binary":return h(r,n,e);case"base64":return s(r,n,e);default:throw new Error("Unknown encoding")}},r.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},r.prototype.copy=function(t,n,e,r){var i=this;if(e||(e=0),r||0===r||(r=this.length),n||(n=0),r!==e&&0!==t.length&&0!==i.length){q(r>=e,"sourceEnd < sourceStart"),q(n>=0&&n<t.length,"targetStart out of bounds"),q(e>=0&&e<i.length,"sourceStart out of bounds"),q(r>=0&&r<=i.length,"sourceEnd out of bounds"),r>this.length&&(r=this.length),t.length-n<r-e&&(r=t.length-n+e);for(var o=0;r-e>o;o++)t[o+n]=this[o+e]}},r.prototype.slice=function(t,n){var e=this.length;if(t=S(t,e,0),n=S(n,e,e),r._useTypedArrays)return k(this.subarray(t,n));for(var i=n-t,o=new r(i,void 0,!0),a=0;i>a;a++)o[a]=this[a+t];return o},r.prototype.readUInt8=function(t,n){var e=this;return n||(q(void 0!==t&&null!==t,"missing offset"),q(t<e.length,"Trying to read beyond buffer length")),t>=e.length?void 0:e[t]},r.prototype.readUInt16LE=function(t,n){return d(this,t,!0,n)},r.prototype.readUInt16BE=function(t,n){return d(this,t,!1,n)},r.prototype.readUInt32LE=function(t,n){return g(this,t,!0,n)},r.prototype.readUInt32BE=function(t,n){return g(this,t,!1,n)},r.prototype.readInt8=function(t,n){var e=this;if(n||(q(void 0!==t&&null!==t,"missing offset"),q(t<e.length,"Trying to read beyond buffer length")),!(t>=e.length)){var r=128&e[t];return r?-1*(255-e[t]+1):e[t]}},r.prototype.readInt16LE=function(t,n){return y(this,t,!0,n)},r.prototype.readInt16BE=function(t,n){return y(this,t,!1,n)},r.prototype.readInt32LE=function(t,n){return w(this,t,!0,n)},r.prototype.readInt32BE=function(t,n){return w(this,t,!1,n)},r.prototype.readFloatLE=function(t,n){return b(this,t,!0,n)},r.prototype.readFloatBE=function(t,n){return b(this,t,!1,n)},r.prototype.readDoubleLE=function(t,n){return v(this,t,!0,n)},r.prototype.readDoubleBE=function(t,n){return v(this,t,!1,n)},r.prototype.writeUInt8=function(t,n,e){var r=this;e||(q(void 0!==t&&null!==t,"missing value"),q(void 0!==n&&null!==n,"missing offset"),q(n<r.length,"trying to write beyond buffer length"),P(t,255)),n>=r.length||(r[n]=t)},r.prototype.writeUInt16LE=function(t,n,e){m(this,t,n,!0,e)},r.prototype.writeUInt16BE=function(t,n,e){m(this,t,n,!1,e)},r.prototype.writeUInt32LE=function(t,n,e){E(this,t,n,!0,e)},r.prototype.writeUInt32BE=function(t,n,e){E(this,t,n,!1,e)},r.prototype.writeInt8=function(t,n,e){var r=this;e||(q(void 0!==t&&null!==t,"missing value"),q(void 0!==n&&null!==n,"missing offset"),q(n<r.length,"Trying to write beyond buffer length"),V(t,127,-128)),n>=r.length||(t>=0?r.writeUInt8(t,n,e):r.writeUInt8(255+t+1,n,e))},r.prototype.writeInt16LE=function(t,n,e){I(this,t,n,!0,e)},r.prototype.writeInt16BE=function(t,n,e){I(this,t,n,!1,e)},r.prototype.writeInt32LE=function(t,n,e){B(this,t,n,!0,e)},r.prototype.writeInt32BE=function(t,n,e){B(this,t,n,!1,e)},r.prototype.writeFloatLE=function(t,n,e){A(this,t,n,!0,e)},r.prototype.writeFloatBE=function(t,n,e){A(this,t,n,!1,e)},r.prototype.writeDoubleLE=function(t,n,e){U(this,t,n,!0,e)},r.prototype.writeDoubleBE=function(t,n,e){U(this,t,n,!1,e)},r.prototype.fill=function(t,n,e){if(t||(t=0),n||(n=0),e||(e=this.length),"string"==typeof t&&(t=t.charCodeAt(0)),q("number"==typeof t&&!isNaN(t),"value is not a number"),q(e>=n,"end < start"),e!==n&&0!==this.length){q(n>=0&&n<this.length,"start out of bounds"),q(e>=0&&e<=this.length,"end out of bounds");for(var r=n;e>r;r++)this[r]=t}},r.prototype.inspect=function(){for(var t=[],n=this.length,r=0;n>r;r++)if(t[r]=_(this[r]),r===e.INSPECT_MAX_BYTES){t[r+1]="...";break}return"<Buffer "+t.join(" ")+">"};var X=r.prototype},{"base64-js":18,ieee754:19}],18:[function(t,n){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(){"use strict";function t(t){var n=t.charCodeAt(0);return n===a?62:n===u?63:f>n?-1:f+10>n?n-f+26+26:c+26>n?n-c:s+26>n?n-s+26:void 0}function r(n){function e(t){s[l++]=t}var r,i,a,u,f,s;if(n.length%4>0)throw"Invalid string. Length must be a multiple of 4";var c=n.length;f="="===n.charAt(c-2)?2:"="===n.charAt(c-1)?1:0,s=new o(3*n.length/4-f),a=f>0?n.length-4:n.length;var l=0;for(r=0,i=0;a>r;r+=4,i+=3)u=t(n.charAt(r))<<18|t(n.charAt(r+1))<<12|t(n.charAt(r+2))<<6|t(n.charAt(r+3)),e((16711680&u)>>16),e((65280&u)>>8),e(255&u);return 2===f?(u=t(n.charAt(r))<<2|t(n.charAt(r+1))>>4,e(255&u)):1===f&&(u=t(n.charAt(r))<<10|t(n.charAt(r+1))<<4|t(n.charAt(r+2))>>2,e(u>>8&255),e(255&u)),s}function i(t){function n(t){return e.charAt(t)}function r(t){return n(t>>18&63)+n(t>>12&63)+n(t>>6&63)+n(63&t)}var i,o,a,u=t.length%3,f="";for(i=0,a=t.length-u;a>i;i+=3)o=(t[i]<<16)+(t[i+1]<<8)+t[i+2],f+=r(o);switch(u){case 1:o=t[t.length-1],f+=n(o>>2),f+=n(o<<4&63),f+="==";break;case 2:o=(t[t.length-2]<<8)+t[t.length-1],f+=n(o>>10),f+=n(o>>4&63),f+=n(o<<2&63),f+="="}return f}var o="undefined"!=typeof Uint8Array?Uint8Array:Array,a=("0".charCodeAt(0),"+".charCodeAt(0)),u="/".charCodeAt(0),f="0".charCodeAt(0),s="a".charCodeAt(0),c="A".charCodeAt(0);n.exports.toByteArray=r,n.exports.fromByteArray=i}()},{}],19:[function(t,n,e){e.read=function(t,n,e,r,i){var o,a,u=8*i-r-1,f=(1<<u)-1,s=f>>1,c=-7,l=e?i-1:0,h=e?-1:1,p=t[n+l];for(l+=h,o=p&(1<<-c)-1,p>>=-c,c+=u;c>0;o=256*o+t[n+l],l+=h,c-=8);for(a=o&(1<<-c)-1,o>>=-c,c+=r;c>0;a=256*a+t[n+l],l+=h,c-=8);if(0===o)o=1-s;else{if(o===f)return a?0/0:1/0*(p?-1:1);a+=Math.pow(2,r),o-=s}return(p?-1:1)*a*Math.pow(2,o-r)},e.write=function(t,n,e,r,i,o){var a,u,f,s=8*o-i-1,c=(1<<s)-1,l=c>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:o-1,d=r?1:-1,g=0>n||0===n&&0>1/n?1:0;for(n=Math.abs(n),isNaN(n)||1/0===n?(u=isNaN(n)?1:0,a=c):(a=Math.floor(Math.log(n)/Math.LN2),n*(f=Math.pow(2,-a))<1&&(a--,f*=2),n+=a+l>=1?h/f:h*Math.pow(2,1-l),n*f>=2&&(a++,f/=2),a+l>=c?(u=0,a=c):a+l>=1?(u=(n*f-1)*Math.pow(2,i),a+=l):(u=n*Math.pow(2,l-1)*Math.pow(2,i),a=0));i>=8;t[e+p]=255&u,p+=d,u/=256,i-=8);for(a=a<<i|u,s+=i;s>0;t[e+p]=255&a,p+=d,a/=256,s-=8);t[e+p-d]|=128*g}},{}],20:[function(n,e){var r=n("__browserify_Buffer");(function(){function i(t,n,e){var r=n&&e||0,i=0;for(n=n||[],t.toLowerCase().replace(/[0-9a-f]{2}/g,function(t){16>i&&(n[r+i++]=y[t])});16>i;)n[r+i++]=0;return n}function o(t,n){var e=n||0,r=g;return r[t[e++]]+r[t[e++]]+r[t[e++]]+r[t[e++]]+"-"+r[t[e++]]+r[t[e++]]+"-"+r[t[e++]]+r[t[e++]]+"-"+r[t[e++]]+r[t[e++]]+"-"+r[t[e++]]+r[t[e++]]+r[t[e++]]+r[t[e++]]+r[t[e++]]+r[t[e++]]}function a(t,n,e){var r=n&&e||0,i=n||[];t=t||{};var a=null!=t.clockseq?t.clockseq:m,u=null!=t.msecs?t.msecs:(new Date).getTime(),f=null!=t.nsecs?t.nsecs:I+1,s=u-E+(f-I)/1e4;if(0>s&&null==t.clockseq&&(a=a+1&16383),(0>s||u>E)&&null==t.nsecs&&(f=0),f>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");E=u,I=f,m=a,u+=122192928e5;var c=(1e4*(268435455&u)+f)%4294967296;i[r++]=c>>>24&255,i[r++]=c>>>16&255,i[r++]=c>>>8&255,i[r++]=255&c;var l=u/4294967296*1e4&268435455;i[r++]=l>>>8&255,i[r++]=255&l,i[r++]=l>>>24&15|16,i[r++]=l>>>16&255,i[r++]=a>>>8|128,i[r++]=255&a;for(var h=t.node||v,p=0;6>p;p++)i[r+p]=h[p];return n?n:o(i)}function u(t,n,e){var r=n&&e||0;"string"==typeof t&&(n="binary"==t?new d(16):null,t=null),t=t||{};var i=t.random||(t.rng||f)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,n)for(var a=0;16>a;a++)n[r+a]=i[a];return n||o(i)}var f,s=this;if("function"==typeof n)try{var c=n("crypto").randomBytes;f=c&&function(){return c(16)}}catch(l){}if(!f&&s.crypto&&crypto.getRandomValues){var h=new Uint8Array(16);f=function(){return crypto.getRandomValues(h),h}}if(!f){var p=new Array(16);f=function(){for(var t,n=0;16>n;n++)0===(3&n)&&(t=4294967296*Math.random()),p[n]=t>>>((3&n)<<3)&255;return p}}for(var d="function"==typeof r?r:Array,g=[],y={},w=0;256>w;w++)g[w]=(w+256).toString(16).substr(1),y[g[w]]=w;var b=f(),v=[1|b[0],b[1],b[2],b[3],b[4],b[5]],m=16383&(b[6]<<8|b[7]),E=0,I=0,B=u;if(B.v1=a,B.v4=u,B.parse=i,B.unparse=o,B.BufferClass=d,"function"==typeof t&&t.amd)t(function(){return B});else if("undefined"!=typeof e&&e.exports)e.exports=B;else{var A=s.uuid;B.noConflict=function(){return s.uuid=A,B},s.uuid=B}}).call(this)},{__browserify_Buffer:16,crypto:11}],21:[function(n,e,r){!function(n,i){"use strict";"object"==typeof r&&e?e.exports=i():"function"==typeof t&&t.amd?t(i):n.PubSub=i()}("object"==typeof window&&window||this,function(){"use strict";function t(t){return function(){throw t}}function n(n,e,r){try{n(e,r)}catch(i){setTimeout(t(i),0)}}function e(t,n,e){t(n,e)}function r(t,r,i,o){var a,u=f[r],s=o?e:n;if(f.hasOwnProperty(r))for(a=0;a<u.length;a++)s(u[a].func,t,i)}function i(t,n,e){return function(){var i=String(t),o=i.lastIndexOf(".");for(r(t,t,n,e);-1!==o;)i=i.substr(0,o),o=i.lastIndexOf("."),r(t,i,n)}}function o(t){for(var n=String(t),e=f.hasOwnProperty(n),r=n.lastIndexOf(".");!e&&-1!==r;)n=n.substr(0,r),r=n.lastIndexOf("."),e=f.hasOwnProperty(n);return e&&f[n].length>0}function a(t,n,e,r){var a=i(t,n,r),u=o(t);return u?(e===!0?a():setTimeout(a,0),!0):!1}var u={},f={},s=-1;return u.publish=function(t,n){return a(t,n,!1,u.immediateExceptions)},u.publishSync=function(t,n){return a(t,n,!0,u.immediateExceptions)},u.subscribe=function(t,n){if("function"!=typeof n)return!1;f.hasOwnProperty(t)||(f[t]=[]);var e=String(++s);return f[t].push({token:e,func:n}),e},u.unsubscribe=function(t){var n,e,r="string"==typeof t,i=r?"token":"func",o=r?t:!0,a=!1;for(n in f)if(f.hasOwnProperty(n))for(e=f[n].length-1;e>=0;e--)if(f[n][e][i]===t&&(f[n].splice(e,1),a=o,r))return a;return a},u})},{}]},{},[1])(1)}); | ||
//# sourceMappingURL=./babble.min.map |
@@ -6,14 +6,17 @@ var babble = require('../index'); | ||
emma.listen('ask age', babble.reply(function () { | ||
return 25; | ||
})); | ||
emma.listen('ask age') | ||
.reply(function () { | ||
return 25; | ||
}); | ||
emma.listen('tell age', babble.run(function (age, context) { | ||
console.log(context.from + ' is ' + age + ' years old'); | ||
})); | ||
emma.listen('tell age') | ||
.run(function (age, context) { | ||
console.log(context.from + ' is ' + age + ' years old'); | ||
}); | ||
jack.tell('emma', 'tell age', 27); | ||
jack.ask('emma', 'ask age', babble.run(function (age, context) { | ||
console.log(context.from + ' is ' + age + ' years old'); | ||
})); | ||
jack.ask('emma', 'ask age') | ||
.run(function (age, context) { | ||
console.log(context.from + ' is ' + age + ' years old'); | ||
}); |
@@ -1,6 +0,2 @@ | ||
var babble = require('../index'), | ||
babbler = babble.babbler, | ||
decide = babble.decide, | ||
reply = babble.reply, | ||
run = babble.run; | ||
var babble = require('../index'); | ||
@@ -12,101 +8,114 @@ var MIN = 0, | ||
var emma = babbler('emma').subscribe(); | ||
(function () { | ||
var emma = babble.babbler('emma').subscribe(); | ||
var checkGuess = decide(function (guess, context) { | ||
if (guess < context.number) { | ||
return reply(function () { | ||
console.log('emma: higher'); | ||
function decideToPlay () { | ||
return (Math.random() > 0.2) ? 'start': 'deny'; | ||
} | ||
function decideIfCorrect (guess, context) { | ||
if (guess < context.number) { | ||
return 'higher'; | ||
}, checkGuess) | ||
} | ||
else if (guess > context.number) { | ||
return reply(function () { | ||
console.log('emma: lower'); | ||
} | ||
else if (guess > context.number) { | ||
return 'lower'; | ||
}, checkGuess) | ||
} | ||
else { | ||
return reply(function () { | ||
console.log('emma: right!'); | ||
} | ||
else { | ||
return 'right'; | ||
}); | ||
} | ||
} | ||
}); | ||
var startGame = reply(function (response, context) { | ||
// choose a random value | ||
context.number = randomInt(MIN, MAX); | ||
var start = function (response, context) { | ||
// choose a random value | ||
context.number = randomInt(MIN, MAX); | ||
console.log('emma: ok I have a number in mind between ' + MIN + ' and ' + MAX); | ||
return 'ok'; | ||
}, checkGuess); | ||
console.log('emma: ok I have a number in mind between ' + MIN + ' and ' + MAX); | ||
return 'ok'; | ||
}; | ||
var denyGame = reply(function () { | ||
return 'no thanks'; | ||
}); | ||
var deny = function () { | ||
return 'no thanks'; | ||
}; | ||
emma.listen('lets play guess the number', decide(function () { | ||
if (Math.random() > 0.2) { | ||
return startGame; | ||
function higher () { | ||
console.log('emma: higher'); | ||
return 'higher'; | ||
} | ||
else { | ||
return denyGame; | ||
function lower () { | ||
console.log('emma: lower'); | ||
return 'lower'; | ||
} | ||
})); | ||
/* -------------------------------------------------------------------------- */ | ||
function right () { | ||
console.log('emma: right!'); | ||
return 'right'; | ||
} | ||
var jack = babbler('jack').subscribe(); | ||
var check = babble.decide(decideIfCorrect); | ||
check.addChoice('higher', babble.reply(higher).listen().then(check)); | ||
check.addChoice('lower', babble.reply(lower).listen().then(check)); | ||
check.addChoice('right', babble.reply(right)); | ||
var triumph = function (response, context) { | ||
console.log('jack: I found it! The correct number is: ' + context.number); | ||
}; | ||
emma.listen('lets play guess the number') | ||
.decide(decideToPlay, { | ||
start: babble.reply(start).listen().then(check), | ||
deny: babble.reply(deny) | ||
}); | ||
var guess = function (response, context) { | ||
if (response == 'higher') { | ||
context.lower = context.number + 1; | ||
} | ||
else if (response == 'lower') { | ||
context.upper = context.number - 1; | ||
} | ||
})(); | ||
context.number = randomInt(context.lower, context.upper); | ||
console.log('jack: guessing ' + context.number + '...'); | ||
return context.number; | ||
}; | ||
/* -------------------------------------------------------------------------- */ | ||
var initialize = function (response, context) { | ||
context.lower = MIN; | ||
context.upper = MAX; | ||
(function () { | ||
var jack = babble.babbler('jack').subscribe(); | ||
context.number = randomInt(context.lower, context.upper); | ||
console.log('jack: guessing ' + context.number + '...'); | ||
return context.number; | ||
}; | ||
function decideToStart (response) { | ||
return (response == 'ok') ? 'start': 'cancel'; | ||
} | ||
var whine = function () { | ||
console.log('emma doesn\'t want to play guess the number :('); | ||
}; | ||
function decideIfCorrect (response) { | ||
return (response == 'right') ? 'right': 'wrong'; | ||
} | ||
var validateGuess = decide(function (response) { | ||
if (response == 'right') { | ||
return run(triumph); | ||
function start(response, context) { | ||
context.lower = MIN; | ||
context.upper = MAX; | ||
} | ||
else { | ||
return reply(guess, validateGuess); | ||
function whine() { | ||
console.log('emma doesn\'t want to play guess the number :('); | ||
} | ||
}); | ||
jack.ask('emma', 'lets play guess the number', decide(function (response) { | ||
if (response == 'ok') { | ||
return reply(initialize, validateGuess); | ||
function triumph (response, context) { | ||
console.log('jack: I found it! The correct number is: ' + context.number); | ||
} | ||
else { | ||
return run(whine); | ||
function guess (response, context) { | ||
if (response == 'higher') { | ||
context.lower = context.number + 1; | ||
} | ||
else if (response == 'lower') { | ||
context.upper = context.number - 1; | ||
} | ||
context.number = randomInt(context.lower, context.upper); | ||
console.log('jack: guessing ' + context.number + '...'); | ||
return context.number; | ||
} | ||
})); | ||
var checkGuess = babble.decide(decideIfCorrect); | ||
checkGuess.addChoice('right', babble.run(triumph)); | ||
checkGuess.addChoice('wrong', babble.reply(guess).listen().then(checkGuess)); | ||
jack.ask('emma', 'lets play guess the number') | ||
.decide(decideToStart, { | ||
start: babble.run(start).reply(guess).listen().then(checkGuess), | ||
cancel: babble.run(whine) | ||
}); | ||
})(); | ||
function randomInt(min, max) { | ||
return Math.floor(min + Math.random() * (max - min)); | ||
} |
@@ -1,56 +0,69 @@ | ||
var babble = require('../index'), | ||
babbler = babble.babbler, | ||
reply = babble.reply, | ||
run = babble.run, | ||
decide = babble.decide; | ||
var babble = require('../index'); | ||
var emma = babbler('emma').subscribe(), | ||
jack = babbler('jack').subscribe(); | ||
var emma = babble.babbler('emma').subscribe(), | ||
jack = babble.babbler('jack').subscribe(); | ||
emma.listen('do you have time today?', decide(function (response) { | ||
if (Math.random() > 0.4) { | ||
return reply(function () { | ||
return 'yes'; | ||
}, decide(function (response) { | ||
if (response == 'can we meet at 15:00?' && Math.random() > 0.5) { | ||
return reply(function () { | ||
return 'ok'; | ||
}); | ||
} | ||
else { | ||
return reply(function () { | ||
return 'no'; | ||
}) | ||
} | ||
})); | ||
function decideIfAvailable () { | ||
return (Math.random() > 0.4) ? 'yes' : 'no'; | ||
} | ||
function decideToAgree (response) { | ||
if (response == 'can we meet at 15:00?' && Math.random() > 0.5) { | ||
return 'ok'; | ||
} | ||
else { | ||
return reply(function () { | ||
return 'no'; | ||
}); | ||
return 'no'; | ||
} | ||
})); | ||
} | ||
jack.ask('emma', 'do you have time today?', decide(function (response) { | ||
if (response == 'yes') { | ||
return reply(function () { | ||
return 'can we meet at 15:00?'; | ||
}, decide(function (response) { | ||
if (response == 'ok') { | ||
return run(function () { | ||
console.log('emma agreed'); | ||
}); | ||
} | ||
else { | ||
return run(function () { | ||
console.log('emma didn\'t agree'); | ||
}); | ||
} | ||
})); | ||
} | ||
else { | ||
return run(function () { | ||
console.log('emma has no time'); | ||
function yes() { | ||
return 'yes'; | ||
} | ||
function ok () { | ||
return 'ok'; | ||
} | ||
function no () { | ||
return 'no'; | ||
} | ||
emma.listen('do you have time today?') | ||
.decide(decideIfAvailable, { | ||
yes: babble.reply(yes) | ||
.decide(decideToAgree, { | ||
ok: babble.reply(ok), | ||
no: babble.reply(no) | ||
}), | ||
no: babble.reply(no) | ||
}); | ||
} | ||
})); | ||
function askToMeet () { | ||
return 'can we meet at 15:00?'; | ||
} | ||
function noTime () { | ||
console.log('emma has no time'); | ||
} | ||
function agreesToMeet (response) { | ||
return (response == 'ok') ? 'ok': 'notOk'; | ||
} | ||
function agreement () { | ||
console.log('emma agreed'); | ||
} | ||
function noAgreement () { | ||
console.log('emma didn\'t agree'); | ||
} | ||
jack.ask('emma', 'do you have time today?') | ||
.decide({ | ||
yes: babble.reply(askToMeet) | ||
.decide(agreesToMeet, { | ||
ok: babble.run(agreement), | ||
notOk: babble.run(noAgreement) | ||
}), | ||
no: babble.run(noTime) | ||
}); |
@@ -25,15 +25,18 @@ var babble = require('../index'), | ||
function (err, babblers) { | ||
babblers.emma.listen('ask age', babble.reply(function (response) { | ||
return 25; | ||
})); | ||
babblers.emma.listen('ask age') | ||
.reply(function (response) { | ||
return 25; | ||
}); | ||
babblers.emma.listen('tell age', babble.run (function (age) { | ||
console.log(this.from + ' is ' + age + ' years old'); | ||
})); | ||
babblers.emma.listen('tell age') | ||
.run (function (age, context) { | ||
console.log(context.from + ' is ' + age + ' years old'); | ||
}); | ||
babblers.jack.tell('emma', 'tell age', 27); | ||
babblers.jack.ask('emma', 'ask age', babble.run (function (age) { | ||
console.log(this.from + ' is ' + age + ' years old'); | ||
})); | ||
babblers.jack.ask('emma', 'ask age') | ||
.run (function (age, context) { | ||
console.log(context.from + ' is ' + age + ' years old'); | ||
}); | ||
}); |
@@ -17,31 +17,61 @@ var Babbler = require('./Babbler'), | ||
/** | ||
* Create a reply block | ||
* @param {Function} callback Invoked as fn(response), | ||
* where response is the incoming message. | ||
* The return value of fn is send back to the | ||
* sender | ||
* @param {Block} next The next block | ||
* Create a control flow starting with a reply block | ||
* @param {Function} callback Invoked as callback(message, context), | ||
* where `message` is the output from the previous | ||
* block in the chain, and `context` is an object | ||
* where state can be stored during a conversation. | ||
* The result returned by the function will be | ||
* send back to the sender. | ||
* @return {Reply} reply | ||
*/ | ||
exports.reply = function reply(callback, next) { | ||
return new Reply(callback, next); | ||
exports.reply = function reply(callback) { | ||
return new Reply(callback); | ||
}; | ||
/** | ||
* Create a decision block | ||
* @param {Function} callback Invoked as fn(response), | ||
* where response is the latest message received. | ||
* Must return a Block element. | ||
* Create a decision block and chain it to the current block. | ||
* Returns the first block in the chain. | ||
* | ||
* Syntax: | ||
* | ||
* decide(choices) | ||
* decide(decision, choices) | ||
* | ||
* Where: | ||
* | ||
* {Function | Object} [decision] | ||
* When a `decision` function is provided, the | ||
* function is invoked as decision(message, context), | ||
* where `message` is the output from the previous | ||
* block in the chain, and `context` is an object | ||
* where state can be stored during a conversation. | ||
* The function must return the id for the next | ||
* block in the control flow, which must be | ||
* available in the provided `choices`. | ||
* If `decision` is not provided, the next block | ||
* will be mapped directly from the message. | ||
* {Object.<String, Block>} choices | ||
* A map with the possible next blocks in the flow | ||
* The next block is selected by the id returned | ||
* by the decision function. | ||
* | ||
* @param {Function | Object} arg1 Can be {function} decision or {Object} choices | ||
* @param {Object} [arg2] choices | ||
* @return {Block} decision The created decision block | ||
*/ | ||
exports.decide = function decide(callback) { | ||
return new Decision(callback); | ||
exports.decide = function decide(arg1, arg2) { | ||
// TODO: test arguments.length > 2 | ||
return new Decision(arg1, arg2); | ||
}; | ||
/** | ||
* Create an action block | ||
* @param {Function} callback Invoked as fn(response), | ||
* where response is the latest message received. | ||
* @param {Block} next The next block | ||
* Create a control flow starting with an action block | ||
* @param {Function} callback Invoked as callback(message, context), | ||
* where `message` is the output from the previous | ||
* block in the chain, and `context` is an object | ||
* where state can be stored during a conversation. | ||
* @return {Action} action | ||
*/ | ||
exports.run = function run (callback, next) { | ||
return new Action(callback, next); | ||
exports.run = function run (callback) { | ||
return new Action(callback); | ||
}; | ||
@@ -53,5 +83,11 @@ | ||
// export all flow blocks | ||
exports.block = require('./block/index'); | ||
exports.block = { | ||
Block: require('./block/Block'), | ||
Action: require('./block/Action'), | ||
Decision: require('./block/Decision'), | ||
Listen: require('./block/Listen'), | ||
Reply: require('./block/Reply') | ||
}; | ||
// export pubsub interfaces | ||
exports.pubsub = require('./pubsub'); |
var uuid = require('node-uuid'), | ||
pubsubInterfaces = require('./pubsub'), | ||
Block = require('./block/Block'), | ||
Action = require('./block/Action'), | ||
Reply = require('./block/Reply'), | ||
Trigger = require('./block/Trigger'); | ||
Listen = require('./block/Listen'); | ||
@@ -23,3 +25,3 @@ /** | ||
this.id = id; | ||
this.triggers = {}; | ||
this.listeners = {}; | ||
this.conversations = {}; | ||
@@ -78,4 +80,4 @@ } | ||
else { | ||
// check the triggers to start a new conversation | ||
trigger = me.triggers[message.message]; | ||
// check the listeners to start a new conversation | ||
trigger = me.listeners[message.message]; | ||
if (trigger) { | ||
@@ -133,5 +135,9 @@ //console.log('message create a new conversation', trigger, trigger.callback); // TODO: cleanup | ||
* @param {String} message | ||
* @param {Block} next An Action or Decision block | ||
* @param {Function} [callback] Invoked as callback(message, context), | ||
* where `message` is the just received message, | ||
* and `context` is an object where state can be | ||
* stored during a conversation. | ||
* @return {Block} block Start block of a control flow. | ||
*/ | ||
Babbler.prototype.listen = function listen (message, next) { | ||
Babbler.prototype.listen = function listen (message, callback) { | ||
if (typeof message !== 'string') { | ||
@@ -141,8 +147,9 @@ throw new TypeError('Parameter message must be a string'); | ||
if (!(next instanceof Block)) { | ||
throw new TypeError('Parameter next must be a Block'); | ||
} | ||
// TODO: add support for a string as callback | ||
// TODO: add support for a string as callback | ||
this.triggers[message] = new Trigger(next); | ||
var listen = new Listen(callback); | ||
this.listeners[message] = listen; | ||
return listen; | ||
}; | ||
@@ -166,17 +173,19 @@ | ||
/** | ||
* Send a question, await a response. | ||
* @param {String} id Babbler id | ||
* Send a question, listen for a response | ||
* @param {String} id Babbler id | ||
* @param {String} message | ||
* @param {JSON} [data] Data must be serializable | ||
* @param {Block} next An Action or Decision block | ||
* @param {JSON} [data] Data must be serializable | ||
* @param {Function} [callback] Callback called | ||
* @return {Block} block Start block for the control flow | ||
*/ | ||
Babbler.prototype.ask = function ask (id, message, data, next) { | ||
Babbler.prototype.ask = function ask (id, message, data, callback) { | ||
var cid = uuid.v4(); // create an id for this conversation | ||
// handle optional parameter data | ||
if (arguments.length < 4) { | ||
next = data; | ||
if (typeof data === 'function') { | ||
callback = data; | ||
data = undefined; | ||
} | ||
var block = new Listen(callback); | ||
// create a new conversation | ||
@@ -186,3 +195,3 @@ this.conversations[cid] = { | ||
peer: id, | ||
next: next, | ||
next: block, | ||
context: { | ||
@@ -200,2 +209,4 @@ from: id | ||
}); | ||
return block; | ||
}; | ||
@@ -211,35 +222,34 @@ | ||
//console.log('_run', conversation, message); // TODO: cleanup | ||
// remove the conversation from the queue | ||
delete this.conversations[conversation.id]; | ||
var block = conversation.next; | ||
var next = block.run(conversation.context, message); | ||
var result = next.result; | ||
conversation.next = next.block; | ||
do { | ||
//console.log('execute', block, message); // TODO: cleanup | ||
var next = block.execute(message, conversation.context); | ||
//console.log('_run next ', next); // TODO: cleanup | ||
if (block instanceof Reply) { | ||
// send a response back to the other peer | ||
this.publish(conversation.peer, { | ||
id: conversation.id, | ||
from: this.id, | ||
to: conversation.peer, | ||
message: next.result | ||
}); | ||
} | ||
if (conversation.next !== undefined) { | ||
// store the conversation | ||
this.conversations[conversation.id] = conversation; | ||
} | ||
else { | ||
// end of the conversation, there is no next block | ||
delete this.conversations[conversation.id]; | ||
} | ||
message = next.result; | ||
block = next.block; | ||
//console.log('message', message); // TODO: cleanup | ||
if (block instanceof Reply) { | ||
// send a response back to the other peer | ||
this.publish(conversation.peer, { | ||
id: conversation.id, | ||
from: this.id, | ||
to: conversation.peer, | ||
message: result | ||
}); | ||
} | ||
else { // Decision, Trigger, Action | ||
if (conversation.next) { | ||
// immediately run the next block (with the same message) | ||
this._run(conversation, message); | ||
if (block instanceof Listen) { | ||
// wait for a next incoming message | ||
conversation.next = block; | ||
this.conversations[conversation.id] = conversation; | ||
} | ||
} | ||
while (block && !(block instanceof Listen)); | ||
}; | ||
module.exports = Babbler; |
@@ -6,12 +6,10 @@ var Block = require('./Block'); | ||
* Execute an action. | ||
* @param {Function} callback Invoked as callback(response, context), | ||
* where `response` is the last received message, | ||
* and `context` is an object where state can | ||
* be stored during a conversation. | ||
* The callback should return nothing. | ||
* @param {Block} [next] The next block in the control flow | ||
* @param {Function} callback Invoked as callback(message, context), | ||
* where `message` is the output from the previous | ||
* block in the chain, and `context` is an object | ||
* where state can be stored during a conversation. | ||
* @constructor | ||
* @extends {Block} | ||
*/ | ||
function Action (callback, next) { | ||
function Action (callback) { | ||
if (!(this instanceof Action)) { | ||
@@ -25,8 +23,3 @@ throw new SyntaxError('Constructor must be called with the new operator'); | ||
if (next && !(next instanceof Block)) { | ||
throw new TypeError('Parameter next must be a Block'); | ||
} | ||
this.callback = callback; | ||
this.next = next; | ||
} | ||
@@ -37,16 +30,12 @@ | ||
/** | ||
* Run the block | ||
* Execute the block | ||
* @param {*} message | ||
* @param {Object} context | ||
* @param {String} [arg=undefined] | ||
* @return {{result: *, block: Block}} next | ||
*/ | ||
Action.prototype.run = function run (context, arg) { | ||
var result = this.callback(arg, context); | ||
Action.prototype.execute = function execute (message, context) { | ||
var result = this.callback(message, context); | ||
if (result !== undefined) { | ||
throw new Error('Callback of Action must return undefined'); | ||
} | ||
return { | ||
result: undefined, | ||
result: result, | ||
block: this.next | ||
@@ -56,2 +45,17 @@ }; | ||
/** | ||
* Create an action block and chain it to the current block. | ||
* Returns the first block in the chain. | ||
* @param {Function} callback Invoked as callback(message, context), | ||
* where `message` is the output from the previous | ||
* block in the chain, and `context` is an object | ||
* where state can be stored during a conversation. | ||
* @return {Block} first First block in the chain | ||
*/ | ||
Block.prototype.run = function run (callback) { | ||
var action = new Action(callback); | ||
return this.then(action); | ||
}; | ||
module.exports = Action; |
@@ -5,14 +5,48 @@ /** | ||
*/ | ||
function Block() {} | ||
function Block() { | ||
this.next = null; | ||
this.previous = null; | ||
} | ||
/** | ||
* Run the block | ||
* Execute the block | ||
* @param {*} message | ||
* @param {Object} context | ||
* @param {String} [arg] | ||
* @return {{result: *, block: Block}} next | ||
*/ | ||
Block.prototype.run = function run (context, arg) { | ||
Block.prototype.execute = function execute (message, context) { | ||
throw new Error('Cannot run an abstract Block'); | ||
}; | ||
/** | ||
* Chain a block to the current block. The new block is appended to the *last* | ||
* block in the chain, and the function returns the *first* block in the chain. | ||
* @param {Block} next | ||
* @return {Block} first First block in the chain | ||
*/ | ||
Block.prototype.then = function then (next) { | ||
if (!(next instanceof Block)) { | ||
throw new TypeError('Parameter next must be a Block'); | ||
} | ||
// find the last block in the chain | ||
var last = this; | ||
while (last.next) { | ||
last = last.next; | ||
} | ||
// find the first block in the chain. | ||
var first = this; | ||
while (first.previous) { | ||
first = first.previous; | ||
} | ||
// append after the last block | ||
next.previous = this; | ||
last.next = next; | ||
// return the first block | ||
return first; | ||
}; | ||
module.exports = Block; |
@@ -6,17 +6,35 @@ var Block = require('./Block'); | ||
* A decision is made by executing the provided callback function, which returns | ||
* a next Action. | ||
* @param {Function | Object} decision | ||
* When `decision` is a function, the function is | ||
* invoked as decision(response, context), | ||
* where `response` is the last received message, | ||
* and `context` is an object where state can be | ||
* stored during a conversation. The function must | ||
* return a Block element. | ||
* When `decision` is an object, it must contain | ||
* a map with response:String as keys and | ||
* next:Block as next control flow block. | ||
* a next control flow block. | ||
* | ||
* Syntax: | ||
* | ||
* new Decision(choices) | ||
* new Decision(decision, choices) | ||
* | ||
* Where: | ||
* | ||
* {Function | Object} [decision] | ||
* When a `decision` function is provided, the | ||
* function is invoked as decision(message, context), | ||
* where `message` is the output from the previous | ||
* block in the chain, and `context` is an object | ||
* where state can be stored during a conversation. | ||
* The function must return the id for the next | ||
* block in the control flow, which must be | ||
* available in the provided `choices`. | ||
* If `decision` is not provided, the next block | ||
* will be mapped directly from the message. | ||
* {Object.<String, Block>} choices | ||
* A map with the possible next blocks in the flow | ||
* The next block is selected by the id returned | ||
* by the decision function. | ||
* | ||
* @param arg1 Can be {function} decision or {Object} choices | ||
* @param [arg2] {Object} choices | ||
* @constructor | ||
* @extends {Block} | ||
*/ | ||
function Decision (decision) { | ||
function Decision (arg1, arg2) { | ||
var decision, choices; | ||
if (!(this instanceof Decision)) { | ||
@@ -26,23 +44,36 @@ throw new SyntaxError('Constructor must be called with the new operator'); | ||
if ((typeof decision === 'function')) { | ||
// great, a function (should return a Block). | ||
if (typeof arg1 === 'function') { | ||
decision = arg1; | ||
choices = arg2; | ||
} | ||
else if (decision) { | ||
// a map with properties. Test whether all property values are blocks | ||
Object.keys(decision).forEach(function (key) { | ||
if (!(decision[key] instanceof Block)) { | ||
throw new TypeError('Decision map must contain Blocks'); | ||
} | ||
}); | ||
else { | ||
decision = null; | ||
choices = arg1; | ||
} | ||
if (decision) { | ||
if (typeof decision !== 'function') { | ||
throw new TypeError('Parameter decision must be a function'); | ||
} | ||
} | ||
else { | ||
throw new TypeError('Function or Object expected as first parameter'); | ||
decision = function (message) { | ||
return message; | ||
} | ||
} | ||
// other Blocks do have a second argument `next` so that is an easy pitfall... | ||
if (arguments[1] instanceof Block) { | ||
throw new SyntaxError('Decision doesn\'t accept a second parameter'); | ||
if (choices && (choices instanceof Function)) { | ||
throw new TypeError('Parameter choices must be an object'); | ||
} | ||
this.decision = decision; | ||
this.choices = {}; | ||
// append all choices | ||
if (choices) { | ||
var me = this; | ||
Object.keys(choices).forEach(function (id) { | ||
me.addChoice(id, choices[id]); | ||
}); | ||
} | ||
} | ||
@@ -53,22 +84,22 @@ | ||
/** | ||
* Run the block | ||
* Execute the block | ||
* @param {*} message | ||
* @param {Object} context | ||
* @param {String} [arg] | ||
* @return {{result: *, block: Block}} next | ||
*/ | ||
Decision.prototype.run = function run (context, arg) { | ||
var next; | ||
if (typeof this.decision === 'function') { | ||
next = this.decision(arg, context); | ||
Decision.prototype.execute = function execute (message, context) { | ||
var id = this.decision(message, context); | ||
if (next && !(next instanceof Block)) { | ||
throw new TypeError('Decision function must return a Block'); | ||
} | ||
if (typeof id !== 'string') { | ||
throw new TypeError('Decision function must return a string containing ' + | ||
'the id of the next block'); | ||
} | ||
else { | ||
next = this.decision[arg]; | ||
var next = this.choices[id]; | ||
if (!next) { | ||
throw new Error('Block with id "' + id + '" not found'); | ||
} | ||
return { | ||
result: undefined, | ||
result: message, | ||
block: next | ||
@@ -78,2 +109,64 @@ }; | ||
/** | ||
* Add a choice to the decision block | ||
* @param {String} id | ||
* @param {Block} block | ||
* @return {Decision} self | ||
*/ | ||
Decision.prototype.addChoice = function addChoice (id, block) { | ||
if (typeof id !== 'string') { | ||
throw new TypeError('String expected as choice id'); | ||
} | ||
if (!(block instanceof Block)) { | ||
throw new TypeError('Block expected as choice'); | ||
} | ||
if (id in this.choices) { | ||
throw new Error('Choice with id "' + id + '" already exists'); | ||
} | ||
this.choices[id] = block; | ||
return this; | ||
}; | ||
/** | ||
* Create a decision block and chain it to the current block. | ||
* Returns the first block in the chain. | ||
* | ||
* Syntax: | ||
* | ||
* decide(choices) | ||
* decide(decision, choices) | ||
* | ||
* Where: | ||
* | ||
* {Function | Object} [decision] | ||
* When a `decision` function is provided, the | ||
* function is invoked as decision(message, context), | ||
* where `message` is the output from the previous | ||
* block in the chain, and `context` is an object | ||
* where state can be stored during a conversation. | ||
* The function must return the id for the next | ||
* block in the control flow, which must be | ||
* available in the provided `choices`. | ||
* If `decision` is not provided, the next block | ||
* will be mapped directly from the message. | ||
* {Object.<String, Block>} choices | ||
* A map with the possible next blocks in the flow | ||
* The next block is selected by the id returned | ||
* by the decision function. | ||
* | ||
* @param {Function | Object} arg1 Can be {function} decision or {Object} choices | ||
* @param {Object} [arg2] choices | ||
* @return {Block} first First block in the chain | ||
*/ | ||
Block.prototype.decide = function decide (arg1, arg2) { | ||
// TODO: test arguments.length > 2 | ||
var decision = new Decision(arg1, arg2); | ||
return this.then(decision); | ||
}; | ||
module.exports = Decision; |
@@ -5,14 +5,13 @@ var Block = require('./Block'); | ||
* Reply | ||
* Handle a reply to a message. | ||
* @param {Function} callback Invoked as callback(response, context), | ||
* where `response` is the last received message, | ||
* and `context` is an object where state can | ||
* be stored during a conversation. | ||
* The function must return something, the | ||
* returned result will be send back to the sender. | ||
* @param {Block} [next] The next block in the control flow | ||
* Send a message to the other peer. | ||
* @param {Function} callback Invoked as callback(message, context), | ||
* where `message` is the output from the previous | ||
* block in the chain, and `context` is an object | ||
* where state can be stored during a conversation. | ||
* The result returned by the function will be | ||
* send back to the sender. | ||
* @constructor | ||
* @extends {Block} | ||
*/ | ||
function Reply (callback, next) { | ||
function Reply (callback) { | ||
if (!(this instanceof Reply)) { | ||
@@ -26,8 +25,3 @@ throw new SyntaxError('Constructor must be called with the new operator'); | ||
if (next && !(next instanceof Block)) { | ||
throw new TypeError('Parameter next must be a Block'); | ||
} | ||
this.callback = callback; | ||
this.next = next; | ||
} | ||
@@ -38,14 +32,10 @@ | ||
/** | ||
* Run the block | ||
* Execute the block | ||
* @param {*} message | ||
* @param {Object} context | ||
* @param {String} [arg] | ||
* @return {{result: *, block: Block}} next | ||
*/ | ||
Reply.prototype.run = function run (context, arg) { | ||
var result = this.callback(arg, context); | ||
Reply.prototype.execute = function execute (message, context) { | ||
var result = this.callback(message, context); | ||
if (result === undefined) { | ||
throw new Error('Callback of Reply returned undefined'); | ||
} | ||
return { | ||
@@ -57,2 +47,19 @@ result: result, | ||
/** | ||
* Create a Reply block and chain it to the current block | ||
* Returns the first block in the chain. | ||
* @param {Function} callback Invoked as callback(message, context), | ||
* where `message` is the output from the previous | ||
* block in the chain, and `context` is an object | ||
* where state can be stored during a conversation. | ||
* The result returned by the function will be | ||
* send back to the sender. | ||
* @return {Block} first First block in the chain | ||
*/ | ||
Block.prototype.reply = function reply (callback) { | ||
var block = new Reply(callback); | ||
return this.then(block); | ||
}; | ||
module.exports = Reply; |
{ | ||
"name": "babble", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Dynamic communication flows between message based actors.", | ||
@@ -5,0 +5,0 @@ "author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)", |
228
README.md
@@ -59,12 +59,18 @@ # Babble | ||
emma.listen('ask age', babble.reply(function () { | ||
return 25; | ||
})); | ||
emma.listen('ask age') | ||
.reply(function () { | ||
return 25; | ||
})); | ||
jack.ask('emma', 'ask age', babble.run(function (age, context) { | ||
console.log(context.from + ' is ' + age + ' years old'); | ||
})); | ||
jack.ask('emma', 'ask age') | ||
.run(function (age, context) { | ||
console.log(context.from + ' is ' + age + ' years old'); | ||
})); | ||
``` | ||
## Control flow | ||
TODO: describe control flow blocks | ||
## Examples | ||
@@ -87,23 +93,23 @@ | ||
```js | ||
var babble = require('babble'), | ||
babbler = babble.babbler, | ||
reply = babble.reply, | ||
run = babble.run; | ||
var babble = require('babble'); | ||
var emma = babbler('emma').subscribe(), | ||
jack = babbler('jack').subscribe(); | ||
var emma = babble.babbler('emma').subscribe(), | ||
jack = babble.babbler('jack').subscribe(); | ||
emma.listen('ask age', reply(function () { | ||
return 25; | ||
})); | ||
emma.listen('ask age') | ||
.reply(function () { | ||
return 25; | ||
}); | ||
emma.listen('tell age', run(function (age, context) { | ||
console.log(context.from + ' is ' + age + ' years old'); | ||
})); | ||
emma.listen('tell age') | ||
.run(function (age, context) { | ||
console.log(context.from + ' is ' + age + ' years old'); | ||
}); | ||
jack.tell('emma', 'tell age', 27); | ||
jack.ask('emma', 'ask age', run(function (age, context) { | ||
console.log(context.from + ' is ' + age + ' years old'); | ||
})); | ||
jack.ask('emma', 'ask age') | ||
.run(function (age, context) { | ||
console.log(context.from + ' is ' + age + ' years old'); | ||
}); | ||
``` | ||
@@ -121,61 +127,75 @@ | ||
The scenario is coded as: | ||
The scenario can be coded as follows. Note that the implementations of the | ||
control flow blocks are separated from the flow itself. | ||
```js | ||
var babble = require('babble'), | ||
babbler = babble.babbler, | ||
reply = babble.reply, | ||
run = babble.run, | ||
decide = babble.decide; | ||
var babble = require('babble'); | ||
var emma = babbler('emma').subscribe(), | ||
jack = babbler('jack').subscribe(); | ||
var emma = babble.babbler('emma').subscribe(), | ||
jack = babble.babbler('jack').subscribe(); | ||
emma.listen('do you have time today?', decide(function (response) { | ||
if (Math.random() > 0.4) { | ||
return reply(function () { | ||
return 'yes'; | ||
}, decide(function (response) { | ||
if (response == 'can we meet at 15:00?' && Math.random() > 0.5) { | ||
return reply(function () { | ||
return 'ok'; | ||
}); | ||
} | ||
else { | ||
return reply(function () { | ||
return 'no'; | ||
}) | ||
} | ||
})); | ||
function decideIfAvailable () { | ||
return (Math.random() > 0.4) ? 'yes' : 'no'; | ||
} | ||
function decideToAgree (response) { | ||
if (response == 'can we meet at 15:00?' && Math.random() > 0.5) { | ||
return 'ok'; | ||
} | ||
else { | ||
return reply(function () { | ||
return 'no'; | ||
}); | ||
return 'no'; | ||
} | ||
})); | ||
} | ||
jack.ask('emma', 'do you have time today?', decide(function (response) { | ||
if (response == 'yes') { | ||
return reply(function () { | ||
return 'can we meet at 15:00?'; | ||
}, decide(function (response) { | ||
if (response == 'ok') { | ||
return run(function () { | ||
console.log('emma agreed'); | ||
}); | ||
} | ||
else { | ||
return run(function () { | ||
console.log('emma didn\'t agree'); | ||
}); | ||
} | ||
})); | ||
} | ||
else { | ||
return run(function () { | ||
console.log('emma has no time'); | ||
function yes() { | ||
return 'yes'; | ||
} | ||
function ok () { | ||
return 'ok'; | ||
} | ||
function no () { | ||
return 'no'; | ||
} | ||
emma.listen('do you have time today?') | ||
.decide(decideIfAvailable, { | ||
yes: babble.reply(yes) | ||
.decide(decideToAgree, { | ||
ok: babble.reply(ok), | ||
no: babble.reply(no) | ||
}), | ||
no: babble.reply(no) | ||
}); | ||
} | ||
})); | ||
function askToMeet () { | ||
return 'can we meet at 15:00?'; | ||
} | ||
function noTime () { | ||
console.log('emma has no time'); | ||
} | ||
function agreesToMeet (response) { | ||
return (response == 'ok') ? 'ok': 'notOk'; | ||
} | ||
function agreement () { | ||
console.log('emma agreed'); | ||
} | ||
function noAgreement () { | ||
console.log('emma didn\'t agree'); | ||
} | ||
jack.ask('emma', 'do you have time today?') | ||
.decide({ | ||
yes: babble.reply(askToMeet) | ||
.decide(agreesToMeet, { | ||
ok: babble.run(agreement), | ||
notOk: babble.run(noAgreement) | ||
}), | ||
no: babble.run(noTime) | ||
}); | ||
``` | ||
@@ -190,15 +210,24 @@ | ||
Factory function to create a new Babbler. | ||
- `babble.run(callback: Function [, next: Block]) : Action` | ||
Factory function to create an Action block. The provided callback function | ||
- `babble.run(callback: Function) : Block` | ||
Create a flow starting with an Action block. The provided callback function | ||
is called as `callback(response, context)` and should not return a result. | ||
- `babble.decide(callback: Function) : Decision` | ||
Factory function to create a Decision block. The callback function is called | ||
as `callback(response, context) : Block`, and must return an instance of | ||
`Block` (an Action, Reply, or Decision). The returned block is used as next | ||
block in the control flow. | ||
- `babble.reply(callback: Function [, next: Block]) : Reply` | ||
Factory function to create a Reply block. The provided callback function | ||
- `babble.decide([decision: Function, ] choices: Object<String, Block>) : Block` | ||
Create a flow starting with a Decision block. | ||
When a `decision` function is provided, the function is invoked as | ||
`decision(response, context)`. The function must return the id for the next | ||
block in the control flow, which must be available in the provided `options`. | ||
If `decision` is not provided, the next block will be mapped directly from the | ||
`response`. Parameter `choices` is a map with the possible next blocks in the | ||
flow. The next block is selected by the id returned by the `decision` function. | ||
The returned block is used as next block in the control flow. | ||
- `babble.reply(callback: Function) : Block` | ||
Create a flow starting with a Reply block. The provided callback function | ||
is called as `callback(response, context)`, where `response` is the latest | ||
received message, and must return a result. The returned result is send to the | ||
connected peer. | ||
- `babble.then(block: Block) : Block` | ||
Create a flow starting with given block. The provided callback function | ||
is called as `callback(response, context)`, where `response` is the latest | ||
received message, and must return a result. The returned result is send to the | ||
connected peer. | ||
@@ -213,3 +242,3 @@ Babble contains the following prototypes. These prototypes are normally | ||
- `babble.block.Reply` | ||
- `babble.block.Trigger` | ||
- `babble.block.Start` | ||
@@ -240,5 +269,5 @@ ### Babbler | ||
- `listen(message: String, next: Block)` | ||
Listen for incoming messages. If there is a match, the provided | ||
control flow block `next` will be executed. | ||
- `listen(message: String [, callback: Function]) : Block` | ||
Listen for incoming messages. If there is a match, the returned control flow | ||
block will be executed. Other blocks can be chained to the returned block. | ||
@@ -248,7 +277,32 @@ - `tell(id: String, message: String [, data: JSON])` | ||
- `ask(id: String, message: String [,data: JSON], next: Block)` | ||
Send a question to another peer. When the reply comes in, | ||
the provided control flow block `next` is executed. | ||
- `ask(id: String, message: String [,data: JSON] [, callback: Function]) : Block` | ||
Send a question to another peer. Returns a `start` Block which is executed | ||
When the reply comes in. Other blocks can be chained to the returned block. | ||
### Block | ||
Blocks can be created via the factory functions available in `babble` | ||
(`reply`, `decide`, `run`, `then`, `listen`), or in a Babbler (`listen`, `ask`). | ||
Blocks can be chained together, resulting in a control flow. The results | ||
returned by blocks are used as input argument for the next block in the chain. | ||
A Block has the following functions: | ||
- `decide([decision: function, ] choices: Object<String, Block>) : Block` | ||
Append a decision block to the control flow. Returns the first block in the | ||
chain. | ||
- `reply(callback: Function) : Block` | ||
Append a Reply block to the control flow. Returns the first block in the | ||
chain. | ||
- `listen([callback: Function]) : Block` | ||
Append a Listen block to the control flow. Returns the first block in the | ||
chain. | ||
- `run(callback: Function) : Block` | ||
Append an Action block to the control flow. Returns the first block in the | ||
chain. | ||
- `then(block : Block) : Block` | ||
Append an arbitrary block to the control flow. Returns the first block in the | ||
chain. | ||
## Build | ||
@@ -255,0 +309,0 @@ |
var assert = require('assert'), | ||
babble = require('../index'), | ||
Babbler = require('../lib/Babbler'); | ||
Babbler = require('../lib/Babbler'), | ||
Reply = require('../lib/block/Reply'), | ||
Decision = require('../lib/block/Decision'), | ||
Action = require('../lib/block/Action'); | ||
describe('babbler', function() { | ||
@@ -16,3 +20,18 @@ | ||
it('should create a flow starting with a reply block', function() { | ||
var block = babble.reply(function () {}); | ||
assert.ok(block instanceof Reply); | ||
}); | ||
it('should create a flow starting with a decision block', function() { | ||
var block = babble.decide(function () {}, {}); | ||
assert.ok(block instanceof Decision); | ||
}); | ||
it('should create a flow starting with an action block', function() { | ||
var block = babble.run(function () {}); | ||
assert.ok(block instanceof Action); | ||
}); | ||
// TODO: test reply, decide, run | ||
}); |
var assert = require('assert'), | ||
Babbler = require('../lib/Babbler'), | ||
Block = require('../lib/block/Block'), | ||
Reply = require('../lib/block/Reply'), | ||
@@ -27,3 +28,3 @@ Action = require('../lib/block/Action'), | ||
it('should create and destroy a babbler', function() { | ||
it.skip('should create and destroy a babbler', function() { | ||
var susan = new Babbler('susan').subscribe(); | ||
@@ -34,3 +35,3 @@ assert.ok(susan instanceof Babbler); | ||
it('should throw an error when creating a babbler with wrong syntax', function() { | ||
it.skip('should throw an error when creating a babbler with wrong syntax', function() { | ||
assert.throws (function () {new Babbler(); }); | ||
@@ -40,13 +41,13 @@ assert.throws (function () {Babbler('whoops'); }); | ||
describe ('listen', function () { | ||
describe.skip ('listen', function () { | ||
it ('should listen to a message', function () { | ||
emma.listen('test', new Reply(function () {})); | ||
emma.listen('test', new Block()); | ||
assert.equal(Object.keys(emma.triggers).length, 1); | ||
assert.equal(Object.keys(emma.listeners).length, 1); | ||
}); | ||
it ('should throw an error when calling listen wrongly', function () { | ||
assert.throws(function () {emma.listen({'a': 'not a string'}, new Reply(function () {}))}); | ||
assert.throws(function () {emma.listen('test', function () {})}); | ||
assert.throws(function () {emma.listen({'a': 'not a string'})}); | ||
assert.throws(function () {emma.listen()}); | ||
}); | ||
@@ -56,9 +57,10 @@ | ||
describe ('tell', function () { | ||
describe.skip ('tell', function () { | ||
it('should tell a message', function(done) { | ||
emma.listen('test', new Action(function (data) { | ||
assert.equal(data, null); | ||
done(); | ||
})); | ||
emma.listen('test') | ||
.run(function (data) { | ||
assert.equal(data, null); | ||
done(); | ||
}); | ||
@@ -69,6 +71,7 @@ jack.tell('emma', 'test'); | ||
it('should tell a message with data', function(done) { | ||
emma.listen('test', new Action(function (data) { | ||
assert.deepEqual(data, {a:2, b:3}); | ||
done(); | ||
})); | ||
emma.listen('test') | ||
.run(function (data) { | ||
assert.deepEqual(data, {a:2, b:3}); | ||
done(); | ||
}); | ||
@@ -83,41 +86,79 @@ jack.tell('emma', 'test', {a:2, b:3}); | ||
it('should ask a question and reply', function(done) { | ||
emma.listen('add', new Reply(function (data) { | ||
return data.a + data.b; | ||
})); | ||
emma.listen('add') | ||
.reply(function (data) { | ||
return data.a + data.b; | ||
}); | ||
jack.ask('emma', 'add', {a:2, b:3}, new Action(function (result) { | ||
assert.equal(result, 5); | ||
jack.ask('emma', 'add', {a:2, b:3}, function (result) { | ||
assert.equal(result, 5); | ||
done(); | ||
}); | ||
}); | ||
it ('should ask a question, reply, and reply on the reply', function(done) { | ||
emma.listen('count') | ||
.reply(function (count) { | ||
return count + 1; | ||
}) | ||
.listen(function (count) { | ||
assert.equal(count, 3); | ||
done(); | ||
}); | ||
jack.ask('emma', 'count', 0) | ||
.reply(function (count) { | ||
return count + 2; | ||
}); | ||
}); | ||
it ('should invoke the callback provided with listen', function(done) { | ||
emma.listen('age', function (response) { | ||
assert.equal(response, 32); | ||
done(); | ||
})); | ||
}); | ||
jack.tell('emma', 'age', 32); | ||
}); | ||
it('should ask a question, reply, and reply on the reply', function(done) { | ||
emma.listen('count', new Reply(function (count) { | ||
return count + 1; | ||
}, new Action(function (count) { | ||
assert.equal(count, 3); | ||
it ('should invoke the callback provided with ask', function(done) { | ||
emma.listen('age') | ||
.reply(function () { | ||
return 32; | ||
}); | ||
jack.ask('emma', 'age', function (response) { | ||
assert.equal(response, 32); | ||
done(); | ||
}))); | ||
}); | ||
}); | ||
jack.ask('emma', 'count', 0, new Reply(function (count) { | ||
assert.equal(count, 1); | ||
return count + 2; | ||
})); | ||
it ('should invoke the callback provided with an ask with data', function(done) { | ||
emma.listen('double') | ||
.reply(function (value) { | ||
return value * 2; | ||
}); | ||
jack.ask('emma', 'double', 2, function (response) { | ||
assert.equal(response, 4); | ||
done(); | ||
}); | ||
}); | ||
it('should make a decision during a conversation', function(done) { | ||
emma.listen('are you available?', new Reply(function (data ) { | ||
assert.strictEqual(data, undefined); | ||
return 'yes'; | ||
})); | ||
emma.listen('are you available?') | ||
.reply(function (data) { | ||
assert.strictEqual(data, undefined); | ||
return 'yes'; | ||
}); | ||
jack.ask('emma', 'are you available?', new Decision(function (response) { | ||
assert.equal(response, 'yes'); | ||
if (response == 'yes') { | ||
return new Action(function (response) { | ||
jack.ask('emma', 'are you available?') | ||
.decide(function (response) { | ||
assert.equal(response, 'yes'); | ||
done(); | ||
return response; | ||
}, { | ||
yes: new Action(function (response) { | ||
assert.equal(response, 'yes'); | ||
done(); | ||
}) | ||
}); | ||
} | ||
})); | ||
}); | ||
@@ -128,53 +169,65 @@ | ||
emma.listen('are you available?', new Action(function (response) { | ||
logs.push('log 1'); | ||
}, new Reply(function (response) { | ||
logs.push('log 2'); | ||
assert.strictEqual(response, undefined); | ||
return 'yes'; | ||
}))); | ||
emma.listen('are you available?') | ||
.run(function (response) { | ||
logs.push('log 1'); | ||
}) | ||
.reply(function (response) { | ||
logs.push('log 2'); | ||
assert.strictEqual(response, undefined); | ||
return 'yes'; | ||
}); | ||
jack.ask('emma', 'are you available?', new Action(function (response) { | ||
assert.equal(response, 'yes'); | ||
logs.push('log 3'); | ||
}, new Action(function () { | ||
logs.push('log 4'); | ||
jack.ask('emma', 'are you available?', function (response) { | ||
assert.equal(response, 'yes'); | ||
logs.push('log 3'); | ||
}) | ||
.run(function () { | ||
logs.push('log 4'); | ||
assert.deepEqual(logs, ['log 1', 'log 2', 'log 3', 'log 4']); | ||
assert.deepEqual(logs, ['log 1', 'log 2', 'log 3', 'log 4']); | ||
done(); | ||
}))); | ||
done(); | ||
}); | ||
}); | ||
it('should keep state in the context during the conversation', function(done) { | ||
emma.listen('question', new Action (function (response, context) { | ||
context.a = 1; | ||
}, new Decision (function (response, context) { | ||
context.b = 2; | ||
assert.equal(context.a, 1); | ||
it ('should keep state in the context during the conversation', function(done) { | ||
emma.listen('question') | ||
.run(function (response, context) { | ||
context.a = 1; | ||
return response; | ||
}) | ||
.decide(function (response, context) { | ||
context.b = 2; | ||
assert.equal(context.a, 1); | ||
return new Reply(function (response, context) { | ||
assert.equal(response, 'a'); | ||
assert.equal(context.a, 1); | ||
assert.equal(context.b, 2); | ||
context.c = 3; | ||
return 'first'; | ||
}, { | ||
first: new Reply(function (response, context) { | ||
assert.equal(response, 'a'); | ||
assert.equal(context.a, 1); | ||
assert.equal(context.b, 2); | ||
context.c = 3; | ||
return 'b'; | ||
}, new Action (function (response, context) { | ||
assert.equal(response, 'c'); | ||
assert.equal(context.a, 1); | ||
assert.equal(context.b, 2); | ||
assert.equal(context.c, 3); | ||
done(); | ||
})); | ||
}))); | ||
return 'b'; | ||
}) | ||
.listen(function (response, context) { | ||
assert.equal(response, 'c'); | ||
assert.equal(context.a, 1); | ||
assert.equal(context.b, 2); | ||
assert.equal(context.c, 3); | ||
done(); | ||
}) | ||
}); | ||
jack.ask('emma', 'question', 'a', new Action(function (response, context) { | ||
context.a = 1; | ||
}, new Reply(function (response, context) { | ||
assert.equal(response, 'b'); | ||
assert.equal(context.a, 1); | ||
jack.ask('emma', 'question', 'a') | ||
.run(function (response, context) { | ||
context.a = 1; | ||
return response; | ||
}) | ||
.reply(function (response, context) { | ||
assert.equal(response, 'b'); | ||
assert.equal(context.a, 1); | ||
return 'c'; | ||
}))); | ||
return 'c'; | ||
}); | ||
}); | ||
@@ -181,0 +234,0 @@ |
@@ -9,5 +9,2 @@ var assert = require('assert'), | ||
assert.ok(action1 instanceof Action); | ||
var action2 = new Action(function () {}, new Action(function () {})); | ||
assert.ok(action2 instanceof Action); | ||
}); | ||
@@ -19,6 +16,5 @@ | ||
assert.throws(function () { new Action('bla')}, TypeError); | ||
assert.throws(function () { new Action(function () {}, 'bla')}, TypeError); | ||
}); | ||
it('should run an action without arguments', function () { | ||
it('should execute an action without arguments', function () { | ||
var action = new Action(function (response, context) { | ||
@@ -29,3 +25,3 @@ assert.strictEqual(response, undefined); | ||
var next = action.run(); | ||
var next = action.execute(); | ||
assert.deepEqual(next, { | ||
@@ -37,3 +33,3 @@ result: undefined, | ||
it('should run an action with context', function () { | ||
it('should execute an action with context', function () { | ||
var context = {a: 2}; | ||
@@ -45,3 +41,3 @@ var action = new Action(function (response, context) { | ||
var next = action.run(context); | ||
var next = action.execute(undefined, context); | ||
assert.deepEqual(next, { | ||
@@ -53,3 +49,3 @@ result: undefined, | ||
it('should run an action with context and argument', function () { | ||
it('should execute an action with context and argument', function () { | ||
var context = {a: 2}; | ||
@@ -61,3 +57,3 @@ var action = new Action(function (response, context) { | ||
var next = action.run(context, 'hello world'); | ||
var next = action.execute('hello world', context); | ||
assert.deepEqual(next, { | ||
@@ -69,7 +65,8 @@ result: undefined, | ||
it('should run an action with next block', function () { | ||
it('should execute an action with next block', function () { | ||
var action = new Action(function () {}); | ||
var nextAction = new Action (function () {}); | ||
var action = new Action(function () {}, nextAction); | ||
action.then(nextAction); | ||
var next = action.run(); | ||
var next = action.execute(); | ||
assert.strictEqual(next.result, undefined); | ||
@@ -79,10 +76,13 @@ assert.strictEqual(next.block, nextAction); | ||
it('should throw an error when callback returns a result', function () { | ||
it('should pass the result from and to callback when executing', function () { | ||
var action = new Action(function (response, context) { | ||
return 'oops'; | ||
assert.equal(response, 'in'); | ||
return 'out'; | ||
}); | ||
assert.throws(function () {action.run();}); | ||
var next = action.execute('in'); | ||
assert.strictEqual(next.result, 'out'); | ||
assert.strictEqual(next.block, undefined); | ||
}); | ||
}); |
@@ -13,5 +13,5 @@ var assert = require('assert'), | ||
var block = new Block(); | ||
assert.throws(function () {block.run()}); | ||
assert.throws(function () {block.execute()}); | ||
}); | ||
}); |
var assert = require('assert'), | ||
Block = require('../../lib/block/Block'), | ||
Decision = require('../../lib/block/Decision'); | ||
@@ -7,41 +8,126 @@ | ||
it('should create a decision', function () { | ||
var decision1 = new Decision(function () {}); | ||
var decision1 = new Decision(function () {}, {}); | ||
assert.ok(decision1 instanceof Decision); | ||
var decision2 = new Decision({ | ||
yes: new Block(), | ||
no: new Block() | ||
}); | ||
assert.ok(decision2 instanceof Decision); | ||
assert.deepEqual(decision2.choices, { | ||
yes: new Block(), | ||
no: new Block() | ||
}); | ||
}); | ||
it('should add choices to a decision', function () { | ||
var decision = new Decision(); | ||
assert.deepEqual(decision.choices, {}); | ||
decision.addChoice('yes', new Block()); | ||
decision.addChoice('no', new Block()); | ||
assert.deepEqual(decision.choices, { | ||
yes: new Block(), | ||
no: new Block() | ||
}); | ||
}); | ||
it('should throw an error when adding invalid choices to a decision', function () { | ||
var decision = new Decision(); | ||
assert.deepEqual(decision.choices, {}); | ||
assert.throws(function () { | ||
decision.addChoice(); | ||
}); | ||
assert.throws(function () { | ||
decision.addChoice(123, new Block()); | ||
}); | ||
assert.throws(function () { | ||
decision.addChoice('id', function() {}); | ||
}); | ||
}); | ||
it('should throw an error when wrongly creating a decision', function () { | ||
assert.throws(function () { Decision(function () {}) }, SyntaxError); | ||
assert.throws(function () { Decision(function () {}, new Decision(function() {})) }, SyntaxError); | ||
assert.throws(function () { new Decision()}, TypeError); | ||
assert.throws(function () { new Decision('bla')}, TypeError); | ||
assert.throws(function () { Decision({ | ||
yes: new Block(), | ||
no: 'no block' | ||
})}, SyntaxError); | ||
assert.throws(function () { Decision('no function', {}) }, SyntaxError); | ||
}); | ||
it('should run a decision without arguments', function () { | ||
it('should throw an error when decision function returns a non existing id', function () { | ||
assert.throws(function () { | ||
Decision(function () { | ||
return 'non existing id' | ||
}, { | ||
yes: new Block(), | ||
no: new Block() | ||
}) | ||
}, Error); | ||
}); | ||
it('should throw an error when decision function doesn\'t return a string', function () { | ||
assert.throws(function () { | ||
var decision = new Decision(function () { | ||
return 123 | ||
}, {}); | ||
decision.execute(); | ||
}, TypeError); | ||
}); | ||
it('should execute a decision without decision function', function () { | ||
var yes = new Block(); | ||
var no = new Block(); | ||
var decision = new Decision({ | ||
yes: yes, | ||
no: no | ||
}); | ||
var context = {}; | ||
var next = decision.execute('yes', context); | ||
assert.deepEqual(next, { | ||
result: 'yes', | ||
block: yes | ||
}) | ||
}); | ||
it('should execute a decision without arguments', function () { | ||
var yes = new Block(); | ||
var no = new Block(); | ||
var decision = new Decision(function (response, context) { | ||
assert.strictEqual(response, undefined); | ||
assert.strictEqual(response, 'message'); | ||
assert.strictEqual(context, undefined); | ||
return 'yes'; | ||
}, { | ||
yes: yes, | ||
no: no | ||
}); | ||
var next = decision.run(); | ||
var next = decision.execute('message'); | ||
assert.deepEqual(next, { | ||
result: undefined, | ||
block: undefined | ||
result: 'message', | ||
block: yes | ||
}) | ||
}); | ||
it('should run a decision with context', function () { | ||
it('should execute a decision with context', function () { | ||
var yes = new Block(); | ||
var context = {a: 2}; | ||
var decision = new Decision(function (response, context) { | ||
assert.strictEqual(response, undefined); | ||
assert.strictEqual(response, 'message'); | ||
assert.deepEqual(context, {a: 2}); | ||
return 'yes'; | ||
}, { | ||
yes: yes | ||
}); | ||
var next = decision.run(context); | ||
var next = decision.execute('message', context); | ||
assert.deepEqual(next, { | ||
result: undefined, | ||
block: undefined | ||
result: 'message', | ||
block: yes | ||
}) | ||
}); | ||
it('should run a decision with context and argument', function () { | ||
it('should execute a decision with context and argument', function () { | ||
var yes = new Block(); | ||
var context = {a: 2}; | ||
@@ -51,30 +137,14 @@ var decision = new Decision(function (response, context) { | ||
assert.deepEqual(context, {a: 2}); | ||
return 'yes'; | ||
}, { | ||
yes: yes | ||
}); | ||
var next = decision.run(context, 'hello world'); | ||
var next = decision.execute('hello world', context); | ||
assert.deepEqual(next, { | ||
result: undefined, | ||
block: undefined | ||
result: 'hello world', | ||
block: yes | ||
}) | ||
}); | ||
it('should run a decision with next block', function () { | ||
var decision2 = new Decision (function () {}); | ||
var decision1 = new Decision(function () { | ||
return decision2; | ||
}); | ||
var next = decision1.run(); | ||
assert.strictEqual(next.result, undefined); | ||
assert.strictEqual(next.block, decision2); | ||
}); | ||
it('should throw an error when callback doesn\'t return a Block', function () { | ||
var decision = new Decision(function (response, context) { | ||
return 'oops'; | ||
}); | ||
assert.throws(function () {decision.run();}, TypeError); | ||
}); | ||
}); |
@@ -7,6 +7,3 @@ var assert = require('assert'), | ||
it('should create a reply', function () { | ||
var reply1 = new Reply(function () {}); | ||
assert.ok(reply1 instanceof Reply); | ||
var reply2 = new Reply(function () {}, new Reply(function () {})); | ||
var reply2 = new Reply(function () {}); | ||
assert.ok(reply2 instanceof Reply); | ||
@@ -19,6 +16,5 @@ }); | ||
assert.throws(function () { new Reply('bla')}, TypeError); | ||
assert.throws(function () { new Reply(function () {}, 'bla')}, TypeError); | ||
}); | ||
it('should run a reply without arguments', function () { | ||
it('should execute a reply without arguments', function () { | ||
var reply = new Reply(function (response, context) { | ||
@@ -30,3 +26,3 @@ assert.strictEqual(response, undefined); | ||
var next = reply.run(); | ||
var next = reply.execute(); | ||
assert.deepEqual(next, { | ||
@@ -38,3 +34,3 @@ result: 'foo', | ||
it('should run a reply with context', function () { | ||
it('should execute a reply with context', function () { | ||
var context = {a: 2}; | ||
@@ -47,3 +43,3 @@ var reply = new Reply(function (response, context) { | ||
var next = reply.run(context); | ||
var next = reply.execute(undefined, context); | ||
assert.deepEqual(next, { | ||
@@ -55,3 +51,3 @@ result: 'foo', | ||
it('should run a reply with context and argument', function () { | ||
it('should execute a reply with context and argument', function () { | ||
var context = {a: 2}; | ||
@@ -64,3 +60,3 @@ var reply = new Reply(function (response, context) { | ||
var next = reply.run(context, 'hello world'); | ||
var next = reply.execute('hello world', context); | ||
assert.deepEqual(next, { | ||
@@ -72,19 +68,23 @@ result: 'foo', | ||
it('should run a reply with next block', function () { | ||
var nextAction = new Reply (function () {return 'foo'}); | ||
var reply = new Reply(function () {return 'foo'}, nextAction); | ||
it('should execute a reply with next block', function () { | ||
var reply = new Reply(function () {return 'foo'}); | ||
var nextReply = new Reply (function () {return 'foo'}); | ||
reply.then(nextReply); | ||
var next = reply.run(); | ||
var next = reply.execute(); | ||
assert.strictEqual(next.result, 'foo'); | ||
assert.strictEqual(next.block, nextAction); | ||
assert.strictEqual(next.block, nextReply); | ||
}); | ||
it('should throw an error when callback does not return a result', function () { | ||
var reply = new Reply(function (response, context) { | ||
return undefined; | ||
it('should pass the result from and to callback when executing', function () { | ||
var action = new Reply(function (response, context) { | ||
assert.equal(response, 'in'); | ||
return 'out'; | ||
}); | ||
assert.throws(function () {reply.run();}); | ||
var next = action.execute('in'); | ||
assert.strictEqual(next.result, 'out'); | ||
assert.strictEqual(next.block, undefined); | ||
}); | ||
}); |
# TO DO | ||
- Implement support for a static map with blocks for `Decision` block. | ||
- Introduce flow blocks Listen and Send? | ||
- Implement error handling | ||
- Implement support for promises to allow async callback functions | ||
- Provide the context as function argument instead of as `this`? | ||
- Store message history in context. | ||
- What to do with initial message and data, whilst subsequent calls only have | ||
message? -> rename this stuff? an initial `event` with optional `message`, | ||
and only subsequal `message`. | ||
- Change to JSON-RPC under the hood? | ||
and sequential only a `message`. | ||
- implement conversations with multiple peers at the same time. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
483358
5375
326
38