blob: f61579a429b0bf8f7e41f73287dc7ef4eaf5449b [file] [log] [blame]
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (process,Buffer){
"use strict";function get_socket_id(t){return t.get_id_string?t.get_id_string():t.localAddress+":"+t.localPort+" -> "+t.remoteAddress+":"+t.remotePort}function session_per_connection(t){var e=null;return{get_session:function(){return e||(e=t.create_session(),e.begin()),e}}}function restrict(t,e){if(t){var o,n=t;return function(i){return o!==i&&(n=t,o=i),n--?e(i):-1}}return e}function backoff(t,e){var o,n=t;return function(i){o!==i&&(n=t,o=i);var s=n,r=2*n;return n=e>r?r:e,s}}function get_connect_fn(t){if(void 0===t.transport||"tcp"===t.transport)return net.connect;if("tls"===t.transport||"ssl"===t.transport)return tls.connect;throw Error("Unrecognised transport: "+t.transport)}function connection_details(t){var e={};return e.connect=t.connect?t.connect:get_connect_fn(t),e.host=t.host?t.host:"localhost",e.port=t.port?t.port:5672,e.options=t,e}function delegate_to_session(t){Connection.prototype["on_"+t]=function(e){var o=this.remote_channel_map[e.channel];if(!o)throw Error(t+" received on invalid channel "+e.channel);o["on_"+t](e)}}var frames=require("./frames.js"),log=require("./log.js"),sasl=require("./sasl.js"),types=require("./types.js"),util=require("./util.js"),EndpointState=require("./endpoint.js"),Session=require("./session.js"),Transport=require("./transport.js"),net=require("net"),tls=require("tls"),EventEmitter=require("events").EventEmitter,AMQP_PROTOCOL_ID=0,TLS_PROTOCOL_ID=2,conn_counter=1,Connection=function(t,e){if(this.options={},t)for(var o in t)this.options[o]=t[o];if(this.container=e,this.options.id||(this.options.id="connection-"+conn_counter++),this.options.container_id||(this.options.container_id=e?e.id:util.generate_uuid()),!this.options.connection_details){var n=this;this.options.connection_details=function(){return connection_details(n.options)}}var i=this.get_option("reconnect",!0);if("boolean"==typeof i&&i){var s=this.get_option("initial_reconnect_delay",100),r=this.get_option("max_reconnect_delay",6e4);this.options.reconnect=restrict(this.get_option("reconnect_limit"),backoff(s,r))}else if("number"==typeof i){var c=this.options.reconnect;this.options.reconnect=restrict(this.get_option("reconnect_limit"),function(){return c})}this.registered=!1,this.state=new EndpointState,this.local_channel_map={},this.remote_channel_map={},this.local={},this.remote={},this.local.open=frames.open(this.options),this.local.close=frames.close({}),this.session_policy=session_per_connection(this),this.amqp_transport=new Transport(this.options.id,AMQP_PROTOCOL_ID,frames.TYPE_AMQP,this),this.sasl_transport=void 0,this.transport=this.amqp_transport,this.conn_established_counter=0,this.heartbeat_out=void 0,this.heartbeat_in=void 0,this.abort_idle=!1,this.socket_ready=!1,this.scheduled_reconnect=void 0};Connection.prototype=Object.create(EventEmitter.prototype),Connection.prototype.constructor=Connection,Connection.prototype.dispatch=function(t,e){return log.events("Connection got event: "+t),this.listeners(t).length?(EventEmitter.prototype.emit.apply(this,arguments),!0):this.container?this.container.dispatch.apply(this.container,arguments):void 0},Connection.prototype.reset=function(){this.abort_idle&&(this.abort_idle=!1,this.local.close.error=void 0,this.state=new EndpointState,this.state.open()),this.amqp_transport=new Transport(this.options.id,AMQP_PROTOCOL_ID,frames.TYPE_AMQP,this),this.sasl_transport=void 0,this.transport=this.amqp_transport,this.state.disconnected(),this.remote={},this.remote_channel_map={};for(var t in this.local_channel_map)this.local_channel_map[t].reset();this.socket_ready=!1},Connection.prototype.connect=function(){return this.is_server=!1,this._connect(this.options.connection_details(this.conn_established_counter)),this.open(),this},Connection.prototype.reconnect=function(){return this.scheduled_reconnect=void 0,log.reconnect("reconnecting..."),this.reset(),this._connect(this.options.connection_details(this.conn_established_counter)),process.nextTick(this._process.bind(this)),this},Connection.prototype._connect=function(t){return t.connect?this.init(t.connect(t.port,t.host,t.options,this.connected.bind(this))):this.init(get_connect_fn(t)(t.port,t.host,t.options,this.connected.bind(this))),this},Connection.prototype.accept=function(t){return this.is_server=!0,log.io("["+this.id+"] client accepted: "+get_socket_id(t)),this.socket_ready=!0,this.init(t)},Connection.prototype.init=function(t){if(this.socket=t,this.socket.on("data",this.input.bind(this)),this.socket.on("error",this.error.bind(this)),this.socket.on("end",this.eof.bind(this)),this.is_server){var e;this.container&&Object.getOwnPropertyNames(this.container.sasl_server_mechanisms).length&&(e=this.container.sasl_server_mechanisms),this.socket.encrypted&&this.socket.authorized&&this.get_option("enable_sasl_external",!1)&&(e=sasl.server_add_external(e?util.clone(e):{})),e&&(this.sasl_transport=new sasl.Server(this,e))}else{var o=this.get_option("sasl_mechanisms");if(!o){var n=this.get_option("username"),i=this.get_option("password");n&&(o=sasl.client_mechanisms(),i?o.enable_plain(n,i):o.enable_anonymous(n))}this.socket.encrypted&&this.options.cert&&this.get_option("enable_sasl_external",!1)&&(o||(o=sasl.client_mechanisms()),o.enable_external()),o&&(this.sasl_transport=new sasl.Client(this,o))}return this.transport=this.sasl_transport?this.sasl_transport:this.amqp_transport,this},Connection.prototype.attach_sender=function(t){return this.session_policy.get_session().attach_sender(t)},Connection.prototype.open_sender=Connection.prototype.attach_sender,Connection.prototype.attach_receiver=function(t){return this.session_policy.get_session().attach_receiver(t)},Connection.prototype.open_receiver=Connection.prototype.attach_receiver,Connection.prototype.get_option=function(t,e){return void 0!==this.options[t]?this.options[t]:this.container?this.container.get_option(t,e):e},Connection.prototype.connected=function(){this.socket_ready=!0,this.conn_established_counter++,log.io("["+this.options.id+"] connected "+get_socket_id(this.socket)),this.output()},Connection.prototype.sasl_failed=function(t){this.transport_error={condition:"amqp:unauthorized-access",description:t},this._handle_error()},Connection.prototype._handle_error=function(){var t=this.get_error();return t?(this.dispatch("connection_error",this._context())||this.dispatch("connection_close",this._context())||console.log("error: "+JSON.stringify(t)),!0):!1},Connection.prototype.get_error=function(){return this.transport_error?this.transport_error:this.remote.close&&this.remote.close.error?this.remote.close.error:void 0},Connection.prototype.output=function(){this.socket&&this.socket_ready&&(this.heartbeat_out&&clearTimeout(this.heartbeat_out),this.transport.write(this.socket),(this.is_closed()&&this.state.has_settled()||this.abort_idle||this.transport_error)&&!this.transport.has_writes_pending()?this.socket.end():this.is_open()&&this.remote.open.idle_time_out&&(this.heartbeat_out=setTimeout(this._write_frame.bind(this),this.remote.open.idle_time_out/2)))},Connection.prototype.input=function(t){this.heartbeat_in&&clearTimeout(this.heartbeat_in),log.io("["+this.options.id+"] read "+t.length+" bytes");var e;this.previous_input?(e=Buffer.concat([this.previous_input,t],this.previous_input.length+t.length),this.previous_input=null):e=t;var o=this.transport.read(e,this);o<e.length&&(this.previous_input=e.slice(o)),this.local.open.idle_time_out&&(this.heartbeat_in=setTimeout(this.idle.bind(this),this.local.open.idle_time_out)),this.transport.has_writes_pending()&&this.output()},Connection.prototype.idle=function(){this.is_open()&&(this.abort_idle=!0,this.local.close.error={condition:"amqp:resource-limit-exceeded",description:"max idle time exceeded"},this.close())},Connection.prototype.error=function(t){console.log("["+this.options.id+"] error: "+t),this._disconnected()},Connection.prototype.eof=function(t){this._disconnected()},Connection.prototype._disconnected=function(){if(!this.is_closed()&&void 0==this.scheduled_reconnect&&(this.dispatch("disconnected",this._context())||console.log("["+this.options.id+"] disconnected"),!this.is_server&&!this.transport_error&&this.options.reconnect)){var t=this.options.reconnect(this.conn_established_counter);t>=0&&(log.reconnect("Scheduled reconnect in "+t+"ms"),this.scheduled_reconnect=setTimeout(this.reconnect.bind(this),t))}},Connection.prototype.open=function(){this.state.open()&&this._register()},Connection.prototype.close=function(){this.state.close()&&this._register()},Connection.prototype.is_open=function(){return this.state.is_open()},Connection.prototype.is_closed=function(){return this.state.is_closed()},Connection.prototype.create_session=function(){for(var t=0;this.local_channel_map[t];)t++;var e=new Session(this,t);return this.local_channel_map[t]=e,e},Connection.prototype.on_open=function(t){if(!this.state.remote_opened())throw Error("Open already received");this.remote.open=t.performative,this.open(),this.dispatch("connection_open",this._context())},Connection.prototype.on_close=function(t){if(!this.state.remote_closed())throw Error("Close already received");this.remote.close=t.performative,this.close(),this.remote.close.error?this._handle_error():this.dispatch("connection_close",this._context()),this.heartbeat_out&&clearTimeout(this.heartbeat_out)},Connection.prototype._register=function(){this.registered||(this.registered=!0,process.nextTick(this._process.bind(this)))},Connection.prototype._process=function(){this.registered=!1;do{this.state.need_open()&&this._write_open();for(var t in this.local_channel_map)this.local_channel_map[t]._process();this.state.need_close()&&this._write_close()}while(!this.state.has_settled())},Connection.prototype._write_frame=function(t,e,o){this.amqp_transport.encode(frames.amqp_frame(t,e,o)),this.output()},Connection.prototype._write_open=function(){this._write_frame(0,this.local.open.described())},Connection.prototype._write_close=function(){this._write_frame(0,this.local.close.described())},Connection.prototype.on_begin=function(t){var e;if(null===t.performative.remote_channel||void 0===t.performative.remote_channel)e=this.create_session(),e.local.begin.remote_channel=t.channel;else if(e=this.local_channel_map[t.performative.remote_channel],!e)throw Error("Invalid value for remote channel "+t.performative.remote_channel);e.on_begin(t),this.remote_channel_map[t.channel]=e},Connection.prototype.get_peer_certificate=function(){return this.socket&&this.socket.getPeerCertificate?this.socket.getPeerCertificate():void 0},Connection.prototype._context=function(t){var e=t?t:{};return e.connection=this,this.container&&(e.container=this.container),e},delegate_to_session("end"),delegate_to_session("attach"),delegate_to_session("detach"),delegate_to_session("transfer"),delegate_to_session("disposition"),delegate_to_session("flow"),module.exports=Connection;
}).call(this,require('_process'),require("buffer").Buffer)
},{"./endpoint.js":2,"./frames.js":3,"./log.js":5,"./sasl.js":8,"./session.js":9,"./transport.js":11,"./types.js":12,"./util.js":13,"_process":24,"buffer":19,"events":23,"net":18,"tls":18}],2:[function(require,module,exports){
"use strict";var EndpointState=function(){this.init()};EndpointState.prototype.init=function(){this.local_open=!1,this.remote_open=!1,this.open_requests=0,this.close_requests=0,this.initialised=!1},EndpointState.prototype.open=function(){return this.initialised=!0,this.local_open?!1:(this.local_open=!0,this.open_requests++,!0)},EndpointState.prototype.close=function(){return this.local_open?(this.local_open=!1,this.close_requests++,!0):!1},EndpointState.prototype.disconnected=function(){var t=this.local_open;this.init(),t?this.open():this.close()},EndpointState.prototype.remote_opened=function(t){return this.remote_open?!1:(this.remote_open=!0,!0)},EndpointState.prototype.remote_closed=function(t){return this.remote_open?(this.remote_open=!1,!0):!1},EndpointState.prototype.is_open=function(){return this.local_open&&this.remote_open},EndpointState.prototype.is_closed=function(){return this.initialised&&!this.local_open&&!this.remote_open},EndpointState.prototype.has_settled=function(){return 0==this.open_requests&&0==this.close_requests},EndpointState.prototype.need_open=function(){return this.open_requests>0?(this.open_requests--,!0):!1},EndpointState.prototype.need_close=function(){return this.close_requests>0?(this.close_requests--,!0):!1},module.exports=EndpointState;
},{}],3:[function(require,module,exports){
"use strict";function define_frame(e,a){var t=types.define_composite(a);frames[a.name]=t.create,by_descriptor[Number(t.descriptor.numeric).toString(10)]=t,by_descriptor[t.descriptor.symbolic]=t}var types=require("./types.js"),frames={},by_descriptor={};frames.read_header=function(e){var a=4,t={},n=e.toString("ascii",0,a);if("AMQP"!==n)throw Error("Invalid protocol header for AMQP "+n);if(t.protocol_id=e.readUInt8(a++),t.major=e.readUInt8(a++),t.minor=e.readUInt8(a++),t.revision=e.readUInt8(a++),1!==t.major||0!==t.minor)throw Error("Unsupported AMQP version: "+JSON.stringify(t));return t},frames.write_header=function(e,a){var t=4;return e.write("AMQP",0,t,"ascii"),e.writeUInt8(a.protocol_id,t++),e.writeUInt8(a.major,t++),e.writeUInt8(a.minor,t++),e.writeUInt8(a.revision,t++),8},frames.TYPE_AMQP=0,frames.TYPE_SASL=1,frames.read_frame=function(e){var a=new types.Reader(e),t={};if(t.size=a.read_uint(4),a.remaining<t.size)return null;var n=a.read_uint(1);if(2>n)throw Error("Invalid data offset, must be at least 2 was "+n);if(t.type=a.read_uint(1),t.type===frames.TYPE_AMQP)t.channel=a.read_uint(2);else{if(t.type!==frames.TYPE_SASL)throw Error("Unknown frame type "+t.type);a.skip(2)}if(n>1&&a.skip(4*n-8),a.remaining()){t.performative=a.read();var r=by_descriptor[t.performative.descriptor.value];r&&(t.performative=new r(t.performative.value)),a.remaining()&&(t.payload=a.read_bytes(a.remaining()))}return t},frames.write_frame=function(e){var a=new types.Writer;if(a.skip(4),a.write_uint(2,1),a.write_uint(e.type,1),e.type===frames.TYPE_AMQP)a.write_uint(e.channel,2);else{if(e.type!==frames.TYPE_SASL)throw Error("Unknown frame type "+e.type);a.write_uint(0,2)}e.performative&&(a.write(e.performative),e.payload&&a.write_bytes(e.payload));var t=a.toBuffer();return t.writeUInt32BE(t.length,0),t},frames.amqp_frame=function(e,a,t){return{channel:e||0,type:frames.TYPE_AMQP,performative:a,payload:t}},frames.sasl_frame=function(e){return{channel:0,type:frames.TYPE_SASL,performative:e}};var open={name:"open",code:16,fields:[{name:"container_id",type:"string",mandatory:!0},{name:"hostname",type:"string"},{name:"max_frame_size",type:"uint",default_value:4294967295},{name:"channel_max",type:"ushort",default_value:65535},{name:"idle_time_out",type:"uint"},{name:"outgoing_locales",type:"symbol",multiple:!0},{name:"incoming_locales",type:"symbol",multiple:!0},{name:"offered_capabilities",type:"symbol",multiple:!0},{name:"desired_capabilities",type:"symbol",multiple:!0},{name:"properties",type:"symbolic_map"}]},begin={name:"begin",code:17,fields:[{name:"remote_channel",type:"ushort"},{name:"next_outgoing_id",type:"uint",mandatory:!0},{name:"incoming_window",type:"uint",mandatory:!0},{name:"outgoing_window",type:"uint",mandatory:!0},{name:"handle_max",type:"uint",default_value:"4294967295"},{name:"offered_capabilities",type:"symbol",multiple:!0},{name:"desired_capabilities",type:"symbol",multiple:!0},{name:"properties",type:"symbolic_map"}]},attach={name:"attach",code:18,fields:[{name:"name",type:"string",mandatory:!0},{name:"handle",type:"uint",mandatory:!0},{name:"role",type:"boolean",mandatory:!0},{name:"snd_settle_mode",type:"ubyte",default_value:2},{name:"rcv_settle_mode",type:"ubyte",default_value:0},{name:"source",type:"*"},{name:"target",type:"*"},{name:"unsettled",type:"map"},{name:"incomplete_unsettled",type:"boolean",default_value:!1},{name:"initial_delivery_count",type:"uint"},{name:"max_message_size",type:"ulong"},{name:"offered_capabilities",type:"symbol",multiple:!0},{name:"desired_capabilities",type:"symbol",multiple:!0},{name:"properties",type:"symbolic_map"}]},flow={name:"flow",code:19,fields:[{name:"next_incoming_id",type:"uint"},{name:"incoming_window",type:"uint",mandatory:!0},{name:"next_outgoing_id",type:"uint",mandatory:!0},{name:"outgoing_window",type:"uint",mandatory:!0},{name:"handle",type:"uint"},{name:"delivery_count",type:"uint"},{name:"link_credit",type:"uint"},{name:"available",type:"uint"},{name:"drain",type:"boolean",default_value:!1},{name:"echo",type:"boolean",default_value:!1},{name:"properties",type:"symbolic_map"}]},transfer={name:"transfer",code:20,fields:[{name:"handle",type:"uint",mandatory:!0},{name:"delivery_id",type:"uint"},{name:"delivery_tag",type:"binary"},{name:"message_format",type:"uint"},{name:"settled",type:"boolean"},{name:"more",type:"boolean",default_value:!1},{name:"rcv_settle_mode",type:"ubyte"},{name:"state",type:"delivery_state"},{name:"resume",type:"boolean",default_value:!1},{name:"aborted",type:"boolean",default_value:!1},{name:"batchable",type:"boolean",default_value:!1}]},disposition={name:"disposition",code:21,fields:[{name:"role",type:"boolean",mandatory:!0},{name:"first",type:"uint",mandatory:!0},{name:"last",type:"uint"},{name:"settled",type:"boolean",default_value:!1},{name:"state",type:"*"},{name:"batchable",type:"boolean",default_value:!1}]},detach={name:"detach",code:22,fields:[{name:"handle",type:"uint",mandatory:!0},{name:"closed",type:"boolean",default_value:!1},{name:"error",type:"error"}]},end={name:"end",code:23,fields:[{name:"error",type:"error"}]},close={name:"close",code:24,fields:[{name:"error",type:"error"}]};define_frame(frames.TYPE_AMQP,open),define_frame(frames.TYPE_AMQP,begin),define_frame(frames.TYPE_AMQP,attach),define_frame(frames.TYPE_AMQP,flow),define_frame(frames.TYPE_AMQP,transfer),define_frame(frames.TYPE_AMQP,disposition),define_frame(frames.TYPE_AMQP,detach),define_frame(frames.TYPE_AMQP,end),define_frame(frames.TYPE_AMQP,close);var sasl_mechanisms={name:"sasl_mechanisms",code:64,fields:[{name:"sasl_server_mechanisms",type:"symbol",multiple:!0,mandatory:!0}]},sasl_init={name:"sasl_init",code:65,fields:[{name:"mechanism",type:"symbol",mandatory:!0},{name:"initial_response",type:"binary"},{name:"hostname",type:"string"}]},sasl_challenge={name:"sasl_challenge",code:66,fields:[{name:"challenge",type:"binary",mandatory:!0}]},sasl_response={name:"sasl_response",code:67,fields:[{name:"response",type:"binary",mandatory:!0}]},sasl_outcome={name:"sasl_outcome",code:68,fields:[{name:"code",type:"ubyte",mandatory:!0},{name:"additional_data",type:"binary"}]};define_frame(frames.TYPE_SASL,sasl_mechanisms),define_frame(frames.TYPE_SASL,sasl_init),define_frame(frames.TYPE_SASL,sasl_challenge),define_frame(frames.TYPE_SASL,sasl_response),define_frame(frames.TYPE_SASL,sasl_outcome),module.exports=frames;
},{"./types.js":12}],4:[function(require,module,exports){
"use strict";function auto_settle(e){e.delivery.settled=!0}function auto_accept(e){e.delivery.update(!0,message.accepted().described())}function is_internal(e){switch(e){case"handle":case"role":case"initial_delivery_count":return!0;default:return!1}}var frames=require("./frames.js"),log=require("./log.js"),message=require("./message.js"),terminus=require("./terminus.js"),types=require("./types.js"),EndpointState=require("./endpoint.js"),FlowController=function(e){this.window=e};FlowController.prototype.update=function(e){var t=this.window-e.receiver.credit;e.receiver.flow(t)};var EventEmitter=require("events").EventEmitter,link=Object.create(EventEmitter.prototype);link.dispatch=function(e,t){log.events("Link got event: "+e),EventEmitter.prototype.emit.apply(this.observers,arguments),this.listeners(e).length?EventEmitter.prototype.emit.apply(this,arguments):this.session.dispatch.apply(this.session,arguments)},link.set_source=function(e){this.local.attach.source=terminus.source(e).described()},link.set_target=function(e){this.local.attach.target=terminus.target(e).described()},link.attach=function(){this.state.open()&&this.connection._register()},link.open=link.attach,link.detach=function(){this.local.detach.closed=!1,this.state.close()&&this.connection._register()},link.close=function(){this.local.detach.closed=!0,this.state.close()&&this.connection._register()},link.is_open=function(){return this.session.is_open()&&this.state.is_open()},link.is_closed=function(){return this.session.is_closed()||this.state.is_closed()},link._process=function(){do this.state.need_open()&&this.session.output(this.local.attach.described()),this.issue_flow&&(this.session._write_flow(this),this.issue_flow=!1),this.state.need_close()&&this.session.output(this.local.detach.described());while(!this.state.has_settled())},link.on_attach=function(e){if(!this.state.remote_opened())throw Error("Attach already received");this.remote.handle||(this.remote.handle=e.handle),e.performative.source=terminus.unwrap(e.performative.source),e.performative.target=terminus.unwrap(e.performative.target),this.remote.attach=e.performative,this.open(),this.dispatch(this.is_receiver()?"receiver_open":"sender_open",this._context())},link.on_detach=function(e){if(!this.state.remote_closed())throw Error("Detach already received");this.remote.detach=e.performative,this.close(),this.dispatch(this.local.attach.role?"receiver_close":"sender_close",this._context())},link.init=function(e,t,i,s,n){this.session=e,this.connection=e.connection,this.name=t,this.options=void 0===s?{}:s,this.state=new EndpointState,this.issue_flow=!1,this.local={handle:i},this.local.attach=frames.attach({handle:i,name:t,role:n});for(var o in this.local.attach)is_internal(o)||void 0===this.options[o]||(this.local.attach[o]=this.options[o]);this.local.detach=frames.detach({handle:i,closed:!0}),this.remote={handle:void 0},this.delivery_count=0,this.credit=0,this.observers=new EventEmitter},link.reset=function(){this.state.disconnected(),this.remote={handle:void 0},this.delivery_count=0,this.credit=0},link.has_credit=function(){return this.credit>0},link.is_receiver=function(){return this.local.attach.role},link._context=function(e){var t=e?e:{};return this.is_receiver()?t.receiver=this:t.sender=this,this.session._context(t)},link.get_option=function(e,t){return void 0!==this.options[e]?this.options[e]:this.session.get_option(e,t)};var Sender=function(e,t,i,s){this.init(e,t,i,s,!1),this.local.attach.initial_delivery_count=0,this.tag=0,this.get_option("autosettle",!0)&&this.observers.on("settled",auto_settle)};Sender.prototype=Object.create(link),Sender.prototype.constructor=Sender,Sender.prototype.next_tag=function(){return new String(this.tag++)},Sender.prototype.sendable=function(e){return this.credit&&this.session.outgoing.available()},Sender.prototype.on_flow=function(e){var t=e.performative;this.credit=t.delivery_count+t.link_credit-this.delivery_count,this.is_open()&&(this.dispatch("sender_flow",this._context()),this.sendable()&&this.dispatch("sendable",this._context()))},Sender.prototype.on_transfer=function(e){throw Error("got transfer on sending link")},Sender.prototype.send=function(e,t){return this.session.send(this,t?t:this.next_tag(),message.encode(e),0)};var Receiver=function(e,t,i,s){this.init(e,t,i,s,!0),this.set_prefetch(this.get_option("prefetch",100)),this.get_option("autoaccept",!0)&&this.observers.on("message",auto_accept)};Receiver.prototype=Object.create(link),Receiver.prototype.constructor=Receiver,Receiver.prototype.on_flow=function(e){this.dispatch("receiver_flow",this._context())},Receiver.prototype.flow=function(e){e>0&&(this.credit+=e,this.issue_flow=!0,this.connection._register())},Receiver.prototype.set_prefetch=function(e){if(e>0){var t=new FlowController(e),i=t.update.bind(t);this.observers.on("message",i),this.observers.on("receiver_open",i)}},module.exports={Sender:Sender,Receiver:Receiver};
},{"./endpoint.js":2,"./frames.js":3,"./log.js":5,"./message.js":6,"./terminus.js":10,"./types.js":12,"events":23}],5:[function(require,module,exports){
"use strict";var debug=require("debug");module.exports={frames:debug("rhea:frames"),raw:debug("rhea:raw"),reconnect:debug("rhea:reconnect"),events:debug("rhea:events"),message:debug("rhea:message"),flow:debug("rhea:flow"),io:debug("rhea:io")};
},{"debug":15}],6:[function(require,module,exports){
"use strict";function define_section(e,n,t){n.descriptor=e,unwrappers[e.symbolic]=n,unwrappers[Number(e.numeric).toString(10)]=n,t&&wrappers.push(t)}function define_composite_section(e){var n=types.define_composite(e);message[e.name]=n.create,by_descriptor[Number(n.descriptor.numeric).toString(10)]=n,by_descriptor[n.descriptor.symbolic]=n;var t=function(t,o){t[e.name]=new n(o.value)},o=function(t,o){o[e.name]&&(o[e.name].described?t.push(o[e.name].described()):t.push(n.create(o[e.name]).described()))};define_section(n.descriptor,t,o)}function define_map_section(e){var n={numeric:e.code};n.symbolic="amqp:"+e.name.replace(/_/g,"-")+":map";var t=function(n,t){n[e.name]=types.unwrap(t)},o=function(t,o){o[e.name]&&t.push(types.described(types.wrap_ulong(n.numeric),types.wrap_map(o[e.name])))};define_section(n,t,o)}function define_outcome(e){var n=types.define_composite(e);n.composite_type=e.name,message[e.name]=n.create,outcomes[Number(n.descriptor.numeric).toString(10)]=n,outcomes[n.descriptor.symbolic]=n,message["is_"+e.name]=function(n){if(n&&n.descriptor){var t=outcomes[n.descriptor.value];if(t)return t.descriptor.numeric==e.code}return!1}}var log=require("./log.js"),types=require("./types.js"),by_descriptor={},unwrappers={},wrappers=[],message={};define_composite_section({name:"header",code:112,fields:[{name:"durable",type:"boolean",default_value:!1},{name:"priority",type:"ubyte",default_value:4},{name:"ttl",type:"uint"},{name:"first_acquirer",type:"boolean",default_value:!1},{name:"delivery_count",type:"uint",default_value:0}]}),define_map_section({name:"delivery_annotations",code:113}),define_map_section({name:"message_annotations",code:114}),define_composite_section({name:"properties",code:115,fields:[{name:"message_id",type:"message_id"},{name:"user_id",type:"binary"},{name:"to",type:"string"},{name:"subject",type:"string"},{name:"reply_to",type:"string"},{name:"correlation_id",type:"message_id"},{name:"content_type",type:"symbol"},{name:"content_encoding",type:"symbol"},{name:"absolute_expiry_time",type:"timestamp"},{name:"creation_time",type:"timestamp"},{name:"group_id",type:"string"},{name:"group_sequence",type:"uint"},{name:"reply_to_group_id",type:"string"}]}),define_map_section({name:"application_properties",code:116}),define_section({numeric:119,symbolic:"amqp:value:*"},function(e,n){e.body=types.unwrap(n)},function(e,n){e.push(types.described(types.wrap_ulong(119),types.wrap(n.body)))}),define_map_section({name:"footer",code:120}),message.encode=function(e){var n=[];wrappers.forEach(function(t){t(n,e)});for(var t=new types.Writer,o=0;o<n.length;o++)log.message("Encoding section "+(o+1)+" of "+n.length+": "+n[o]),t.write(n[o]);var i=t.toBuffer();return log.message("encoded "+i.length+" bytes"),i},message.decode=function(e){for(var n={},t=new types.Reader(e);t.remaining();){var o=t.read();if(log.message("decoding section: "+JSON.stringify(o)+" of type: "+JSON.stringify(o.descriptor)),o.descriptor){var i=unwrappers[o.descriptor.value];i?i(n,o):console.log("WARNING: did not recognise message section with descriptor "+o.descriptor)}else console.log("WARNING: expected described message section got "+JSON.stringify(o))}return n};var outcomes={};message.unwrap_outcome=function(e){if(e&&e.descriptor){var n=outcomes[e.descriptor.value];if(n)return new n(e)}return console.log("unrecognised outcome"),e},message.are_outcomes_equivalent=function(e,n){return void 0===e&&void 0===n?!0:void 0===e||void 0===n?!1:e.descriptor.value==n.descriptor.value&&JSON.stringify(e)==JSON.stringify(n)},define_outcome({name:"received",code:35,fields:[{name:"section-number",type:"uint",mandatory:!0},{name:"section-offset",type:"ulong",mandatory:!0}]}),define_outcome({name:"accepted",code:36,fields:[]}),define_outcome({name:"rejected",code:37,fields:[{name:"error",type:"error"}]}),define_outcome({name:"released",code:38,fields:[]}),define_outcome({name:"modified",code:39,fields:[{name:"delivery-failed",type:"boolean"},{name:"undeliverable-here",type:"boolean"},{name:"message-annotations",type:"fields"}]}),module.exports=message;
},{"./log.js":5,"./types.js":12}],7:[function(require,module,exports){
"use strict";function match(e,t){return t?Array.isArray(t)?t.indexOf(e)>-1:e===t:!1}var url=require("url"),simple_id_generator={counter:1,next:function(){return this.counter++}},Client=function(e,t){var i=url.parse(t);this.connection=e.connect({host:i.hostname,port:i.port}),this.connection.on("message",this._response.bind(this)),this.connection.on("receiver_open",this._ready.bind(this)),this.sender=this.connection.attach_sender(i.path.substr(1)),this.receiver=this.connection.attach_receiver({source:{dynamic:!0}}),this.id_generator=simple_id_generator,this.pending=[],this.outstanding={}};Client.prototype._request=function(e,t,i,n){var s={properties:{}};s.properties.subject=t,s.body=i,s.properties.message_id=e,s.properties.reply_to=this.receiver.remote.attach.source.address,this.outstanding[e]=n,this.sender.send(s)},Client.prototype._response=function(e){var t=e.message.properties.correlation_id,i=this.outstanding[t];i?"ok"===e.message.properties.subject?i(e.message.body):i(void 0,{name:e.message.properties.subject,description:e.message.body}):console.log("no request pending for "+t+", ignoring response")},Client.prototype._ready=function(e){this._process_pending()},Client.prototype._process_pending=function(){for(var e=0;e<this.pending.length;e++){var t=this.pending[e];this._request(t.id,t.name,t.args,t.callback)}this.pending=[]},Client.prototype.call=function(e,t,i){var n=this.id_generator.next();this.receiver.is_open()&&0===this.pending.length?this._request(n,e,t,i):this.pending.push({name:e,args:t,callback:i,id:n})},Client.prototype.close=function(){this.receiver.close(),this.sender.close(),this.connection.close()},Client.prototype.define=function(e){this[e]=function(t,i){this.call(e,t,i)}};var Cache=function(e,t){this.ttl=e,this.purged=t,this.entries={},this.timeout=void 0};Cache.prototype.clear=function(){this.timeout&&clearTimeout(this.timeout),this.entries={}},Cache.prototype.put=function(e,t){this.entries[e]={value:t,last_accessed:Date.now()},this.timeout||(this.timeout=setTimeout(this.purge.bind(this),this.ttl))},Cache.prototype.get=function(e){var t=this.entries[e];return t?(t.last_accessed=Date.now(),t.value):void 0},Cache.prototype.purge=function(){var e=Date.now(),t=[],i=0;for(var n in this.entries)e-this.entries[n].last_accessed>=this.ttl?t.push(n):i++;for(var s=0;s<t.length;s++){var o=this.entries[t[s]];delete this.entries[t[s]],this.purged(o.value)}i&&!this.timeout&&(this.timeout=setTimeout(this.purge.bind(this),this.ttl))};var LinkCache=function(e,t){this.factory=e,this.cache=new Cache(t,function(e){e.close()})};LinkCache.prototype.clear=function(){this.cache.clear()},LinkCache.prototype.get=function(e){var t=this.cache.get(e);return void 0===t&&(t=this.factory(e),this.cache.put(e,t)),t};var Server=function(e,t,i){this.options=i||{};var n=url.parse(t);this.connection=e.connect({host:n.hostname,port:n.port}),this.connection.on("connection_open",this._connection_open.bind(this)),this.connection.on("message",this._request.bind(this)),this.receiver=this.connection.attach_receiver(n.path.substr(1)),this.callbacks={},this._send=void 0,this._clear=void 0};Server.prototype._connection_open=function(e){if(match("ANONYMOUS-RELAY",this.connection.remote.open.offered_capabilities)){var t=this.connection.attach_sender({target:{}});this._send=function(e){t.send(e)}}else{var i=new LinkCache(this.connection.attach_sender.bind(this.connection),this.options.cache_ttl||6e4);this._send=function(e){var t=i.get(e.properties.to);t&&t.send(e)},this._clear=function(){i.clear()}}},Server.prototype._respond=function(e){var t=this;return function(i,n){n?(e.properties.subject=n.name||"error",e.body=n.description||n):(e.properties.subject="ok",e.body=i),t._send(e)}},Server.prototype._request=function(e){var t=e.message,i={properties:{}};i.properties.to=t.properties.reply_to,i.properties.correlation_id=t.properties.message_id;var n=this.callbacks[t.properties.subject];n?n(t.body,this._respond(i)):(i.properties.subject="bad-method",i.body="Unrecognised method "+t.properties.subject,this._send(i))},Server.prototype.bind_sync=function(e,t){this.callbacks[t||e.name]=function(t,i){var n=e(t);i(n)}},Server.prototype.bind=function(e,t){this.callbacks[t||e.name]=e},Server.prototype.close=function(){this._clear&&this._clear(),this.receiver.close(),this.connection.close()},module.exports={server:function(e,t,i){return new Server(e,t,i)},client:function(e,t){return new Client(e,t)}};
},{"url":29}],8:[function(require,module,exports){
(function (Buffer){
"use strict";function intersection(e,t){return e.filter(function(e){return t.indexOf(e)>=0})}function extract(e){for(var t=[],s=0,n=0;n<e.length;)0===e[n]?(n>s?t.push(e.toString("utf8",s,n)):t.push(null),s=++n):++n;return n>s?t.push(e.toString("utf8",s,n)):t.push(null),t}var frames=require("./frames.js"),log=require("./log.js"),Transport=require("./transport.js"),sasl_codes={OK:0,AUTH:1,SYS:2,SYS_PERM:3,SYS_TEMP:4},SASL_PROTOCOL_ID=3,PlainServer=function(e){this.callback=e,this.outcome=void 0,this.username=void 0};PlainServer.prototype.start=function(e){var t=extract(e);3!==t.length&&this.connection.sasl_failed("Unexpected response in PLAIN, got "+t.length+" fields, expected 3"),this.callback(t[1],t[2])?(this.outcome=!0,this.username=t[1]):this.outcome=!1};var PlainClient=function(e,t){this.username=e,this.password=t};PlainClient.prototype.start=function(){var e=new Buffer(1+this.username.length+1+this.password.length);return e.writeUInt8(0,0),e.write(this.username,1),e.writeUInt8(0,1+this.username.length),e.write(this.password,1+this.username.length+1),e};var AnonymousServer=function(){this.outcome=void 0,this.username=void 0};AnonymousServer.prototype.start=function(e){this.outcome=!0,this.username=e?e.toString("utf8"):"anonymous"};var AnonymousClient=function(e){this.username=e?e:"anonymous"};AnonymousClient.prototype.start=function(){var e=new Buffer(1+this.username.length);return e.writeUInt8(0,0),e.write(this.username,1),e};var ExternalServer=function(){this.outcome=void 0,this.username=void 0};ExternalServer.prototype.start=function(e){this.outcome=!0};var ExternalClient=function(){this.username=void 0};ExternalClient.prototype.start=function(){return null};var SaslServer=function(e,t){this.connection=e,this.transport=new Transport(e.amqp_transport.identifier,SASL_PROTOCOL_ID,frames.TYPE_SASL,this),this.next=e.amqp_transport,this.mechanisms=t,this.mechanism=void 0,this.outcome=void 0,this.username=void 0;var s=Object.getOwnPropertyNames(t);this.transport.encode(frames.sasl_frame(frames.sasl_mechanisms({sasl_server_mechanisms:s}).described()))};SaslServer.prototype.do_step=function(e){void 0===this.mechanism.outcome?this.transport.encode(frames.sasl_frame(frames.sasl_challenge({challenge:e}).described())):(this.outcome=this.mechanism.outcome?sasl_codes.OK:sasl_codes.AUTH,this.transport.encode(frames.sasl_frame(frames.sasl_outcome({code:this.outcome}).described())),this.outcome===sasl_codes.OK&&(this.username=this.mechanism.username,this.transport.write_complete=!0,this.transport.read_complete=!0))},SaslServer.prototype.on_sasl_init=function(e){var t=this.mechanisms[e.performative.mechanism];if(t){this.mechanism=t();var s=this.mechanism.start(e.performative.initial_response);this.do_step(s)}else this.outcome=sasl_codes.AUTH,this.transport.encode(frames.sasl_frame(frames.sasl_outcome({code:this.outcome}).described()))},SaslServer.prototype.on_sasl_response=function(e){this.do_step(this.mechanism.step(e.performative.response))},SaslServer.prototype.has_writes_pending=function(){return this.transport.has_writes_pending()||this.next.has_writes_pending()},SaslServer.prototype.write=function(e){return this.transport.write_complete&&0===this.transport.pending.length?this.next.write(e):this.transport.write(e)},SaslServer.prototype.read=function(e){return this.transport.read_complete?this.next.read(e):this.transport.read(e)};var SaslClient=function(e,t){this.connection=e,this.transport=new Transport(e.amqp_transport.identifier,SASL_PROTOCOL_ID,frames.TYPE_SASL,this),this.next=e.amqp_transport,this.mechanisms=t,this.mechanism=void 0,this.mechanism_name=void 0,this.failed=!1};SaslClient.prototype.on_sasl_mechanisms=function(e){for(var t=0;void 0===this.mechanism&&t<e.performative.sasl_server_mechanisms.length;t++){var s=e.performative.sasl_server_mechanisms[t],n=this.mechanisms[s];n&&(this.mechanism=n(),this.mechanism_name=s)}if(this.mechanism){var r=this.mechanism.start();this.transport.encode(frames.sasl_frame(frames.sasl_init({mechanism:this.mechanism_name,initial_response:r}).described()))}else this.failed=!0,this.connection.sasl_failed("No suitable mechanism; server supports "+e.performative.sasl_server_mechanisms)},SaslClient.prototype.on_sasl_challenge=function(e){var t=this.mechanism.step(e.performative.challenge);this.transport.encode(frames.sasl_frame(frames.sasl_response({response:t}).described()))},SaslClient.prototype.on_sasl_outcome=function(e){switch(e.performative.code){case sasl_codes.OK:this.transport.read_complete=!0,this.transport.write_complete=!0;break;default:this.transport.write_complete=!0,this.connection.sasl_failed("Failed to authenticate: "+e.performative.code)}},SaslClient.prototype.has_writes_pending=function(){return this.transport.has_writes_pending()||this.next.has_writes_pending()},SaslClient.prototype.write=function(e){return this.transport.write_complete?this.next.write(e):this.transport.write(e)},SaslClient.prototype.read=function(e){return this.transport.read_complete?this.next.read(e):this.transport.read(e)};var default_server_mechanisms={enable_anonymous:function(){this.ANONYMOUS=function(){return new AnonymousServer}},enable_plain:function(e){this.PLAIN=function(){return new PlainServer(e)}}},default_client_mechanisms={enable_anonymous:function(e){this.ANONYMOUS=function(){return new AnonymousClient(e)}},enable_plain:function(e,t){this.PLAIN=function(){return new PlainClient(e,t)}},enable_external:function(){this.EXTERNAL=function(){return new ExternalClient}}};module.exports={Client:SaslClient,Server:SaslServer,server_mechanisms:function(){return Object.create(default_server_mechanisms)},client_mechanisms:function(){return Object.create(default_client_mechanisms)},server_add_external:function(e){return e.EXTERNAL=function(){return new ExternalServer},e}};
}).call(this,require("buffer").Buffer)
},{"./frames.js":3,"./log.js":5,"./transport.js":11,"buffer":19}],9:[function(require,module,exports){
(function (Buffer){
"use strict";function attach(e,t,i){var o=t?t:{};"string"==typeof t&&(o={},o[i]=t),o.name||(o.name=util.generate_uuid());var n=e(o.name,o);for(var s in{source:0,target:0})o[s]&&("string"==typeof o[s]&&(o[s]={address:o[s]}),n["set_"+s](o[s]));return n.attach(),n}var frames=require("./frames.js"),link=require("./link.js"),log=require("./log.js"),message=require("./message.js"),types=require("./types.js"),util=require("./util.js"),EndpointState=require("./endpoint.js"),EventEmitter=require("events").EventEmitter,CircularBuffer=function(e){this.capacity=e,this.size=0,this.head=0,this.tail=0,this.entries=[]};CircularBuffer.prototype.available=function(){return this.capacity-this.size},CircularBuffer.prototype.push=function(e){if(!(this.size<this.capacity))throw Error("circular buffer overflow: head="+this.head+" tail="+this.tail+" size="+this.size+" capacity="+this.capacity);this.entries[this.tail]=e,this.tail=(this.tail+1)%this.capacity,this.size++},CircularBuffer.prototype.pop_if=function(e){for(var t=0;this.size&&e(this.entries[this.head]);)this.entries[this.head]=void 0,this.head=(this.head+1)%this.capacity,this.size--,t++;return t},CircularBuffer.prototype.by_id=function(e){if(this.size>0){var t=e-this.entries[this.head].id;if(t<this.size)return this.entries[(this.head+t)%this.capacity]}},CircularBuffer.prototype.get_head=function(e){return this.size>0?this.entries[this.head]:void 0};var Outgoing=function(){this.deliveries=new CircularBuffer(2048),this.updated=[],this.next_delivery_id=0,this.next_pending_delivery=0,this.next_transfer_id=0,this.window=types.MAX_UINT,this.remote_next_transfer_id=void 0,this.remote_window=void 0};Outgoing.prototype.available=function(){return this.deliveries.available()},Outgoing.prototype.send=function(e,t,i,o){var n={id:this.next_delivery_id++,tag:t,link:e,data:i,format:o?o:0,sent:!1,settled:!1,state:void 0,remote_settled:!1,remote_state:void 0};return this.deliveries.push(n),n},Outgoing.prototype.on_begin=function(e){this.remote_window=e.incoming_window},Outgoing.prototype.on_flow=function(e){this.remote_next_transfer_id=e.next_incoming_id,this.remote_window=e.incoming_window},Outgoing.prototype.on_disposition=function(e){for(var t=e.last?e.last:e.first,i=e.first;t>=i;i++){var o=this.deliveries.by_id(i);if(o||console.log("Could not find delivery for "+i+" ["+JSON.stringify(e)+"]"),o&&!o.remote_settled){var n=!1;e.settled&&(o.remote_settled=e.settled,n=!0),e.state&&e.state!==o.remote_state&&(o.remote_state=e.state,n=!0),n&&this.updated.push(o)}}},Outgoing.prototype.transfer_window=function(){return this.remote_window?this.remote_window-(this.next_transfer_id-this.remote_next_transfer_id):void 0},Outgoing.prototype.process=function(){for(;this.next_pending_delivery<this.next_delivery_id;){var e=this.deliveries.by_id(this.next_pending_delivery);if(!e){console.log("ERROR: Next pending delivery not found: "+this.next_pending_delivery);break}if(!e.link.has_credit()){log.flow("Link has no credit");break}if(e.link.delivery_count++,e.transfers_required=1,!(this.transfer_window()>=e.transfers_required)){log.flow("Incoming window of peer preventing sending further transfers: remote_window="+this.remote_window+", remote_next_transfer_id="+this.remote_next_transfer_id+", next_transfer_id="+this.next_transfer_id);break}this.next_transfer_id+=e.transfers_required,this.window-=e.transfers_required,e.link.session.output(frames.transfer({handle:e.link.local.handle,message_format:e.format,delivery_id:e.id,delivery_tag:e.tag}).described(),e.data),e.link.credit--,this.next_pending_delivery++}for(var t=0;t<this.updated.length;t++){var e=this.updated[t];e.remote_state&&(e.remote_state=message.unwrap_outcome(e.remote_state),e.remote_state&&e.remote_state.constructor.composite_type&&e.link.dispatch(e.remote_state.constructor.composite_type,e.link._context({delivery:e}))),e.remote_settled&&e.link.dispatch("settled",e.link._context({delivery:e}))}this.updated=[],this.deliveries.pop_if(function(e){return e.settled&&e.remote_settled})};var Incoming=function(){this.deliveries=new CircularBuffer(2048),this.updated=[],this.next_transfer_id=0,this.next_delivery_id=void 0,this.window=2048,this.remote_next_transfer_id=void 0,this.remote_window=void 0};Incoming.prototype.update=function(e,t,i){e&&(e.settled=t,void 0!==i&&(e.state=i),e.remote_settled||this.updated.push(e),e.link.connection._register())},Incoming.prototype.on_transfer=function(e,t){if(this.next_transfer_id++,t.is_open()){void 0===this.next_delivery_id&&(this.next_delivery_id=e.performative.delivery_id);var i,o,n=this.deliveries.get_head();if(n&&n.incomplete){if(void 0!==e.performative.delivery_id&&this.next_delivery_id!=e.performative.delivery_id)throw Error("frame sequence error: delivery "+this.next_delivery_id+" not complete, got "+e.performative.delivery_id);i=n,o=Buffer.concat([i.data,e.payload],i.data.size()+e.payload.size())}else{if(this.next_delivery_id!==e.performative.delivery_id)throw Error("frame sequence error: expected "+this.next_delivery_id+", got "+e.performative.delivery_id);i={id:e.performative.delivery_id,tag:e.performative.delivery_tag,link:t,settled:!1,state:void 0,remote_settled:e.performative.settled,remote_state:void 0};var s=this;i.update=function(e,t){s.update(i,e,t)},this.deliveries.push(i),o=e.payload}i.incomplete=e.performative.more,i.incomplete?i.data=o:(t.credit--,t.delivery_count++,this.next_delivery_id++,t.dispatch("message",t._context({message:message.decode(o),delivery:i})))}},Incoming.prototype.process=function(){if(this.updated.length>0){for(var e,t,i,o=0;o<this.updated.length;o++){var n=this.updated[o];void 0===e&&(e=n,t=n,i=n.id),message.are_outcomes_equivalent(t.state,n.state)&&t.settled===n.settled&&i===n.id?(t.id!==n.id&&(t=n),i++):(e.link.session.output(frames.disposition({role:!0,first:e.id,last:t.id,state:e.state,settled:e.settled}).described()),e=n,t=n,i=n.id)}void 0!==e&&void 0!==t&&e.link.session.output(frames.disposition({role:!0,first:e.id,last:t.id,state:e.state,settled:e.settled}).described()),this.updated=[]}this.deliveries.pop_if(function(e){return e.settled})},Incoming.prototype.on_begin=function(e){this.remote_window=e.outgoing_window},Incoming.prototype.on_flow=function(e){this.remote_next_transfer_id=e.next_outgoing_id,this.remote_window=e.outgoing_window},Incoming.prototype.on_disposition=function(e){for(var t=e.last?e.last:e.first,i=e.first;t>=i;i++){var o=this.deliveries.by_id(i);if(o||console.log("Could not find delivery for "+i),o&&!o.remote_settled){var n=!1;e.settled&&(o.remote_settled=e.settled,n=!0),e.state&&e.state!==o.remote_state&&(o.remote_state=e.state,n=!0),n&&(console.log(o.link.connection.options.id+" added delivery to updated list following receipt of disposition for incoming deliveries"),this.updated.push(o))}}};var Session=function(e,t){this.connection=e,this.outgoing=new Outgoing,this.incoming=new Incoming,this.state=new EndpointState,this.local={channel:t,handles:{}},this.local.begin=frames.begin({next_outgoing_id:this.outgoing.next_transfer_id,incoming_window:this.incoming.window,outgoing_window:this.outgoing.window}),this.local.end=frames.end(),this.remote={handles:{}},this.links={},this.options={}};Session.prototype=Object.create(EventEmitter.prototype),Session.prototype.constructor=Session,Session.prototype.reset=function(){this.state.disconnected(),this.outgoing=new Outgoing,this.incoming=new Incoming,this.remote={handles:{}};for(var e in this.links)this.links[e].reset()},Session.prototype.dispatch=function(e,t){log.events("Session got event: "+e),this.listeners(e).length?EventEmitter.prototype.emit.apply(this,arguments):this.connection.dispatch.apply(this.connection,arguments)},Session.prototype.output=function(e,t){this.connection._write_frame(this.local.channel,e,t)},Session.prototype.create_sender=function(e,t){return this.create_link(e,link.Sender,t)},Session.prototype.create_receiver=function(e,t){return this.create_link(e,link.Receiver,t)},Session.prototype.get_option=function(e,t){return void 0!==this.options[e]?this.options[e]:this.connection.get_option(e,t)},Session.prototype.attach_sender=function(e){return attach(this.create_sender.bind(this),e,"target")},Session.prototype.open_sender=Session.prototype.attach_sender,Session.prototype.attach_receiver=function(e){return attach(this.create_receiver.bind(this),e,"source")},Session.prototype.open_receiver=Session.prototype.attach_receiver,Session.prototype.create_link=function(e,t,i){for(var o=0;this.local.handles[o];)o++;var n=new t(this,e,o,i);return this.links[e]=n,this.local.handles[o]=n,n},Session.prototype.begin=function(){this.state.open()&&this.connection._register()},Session.prototype.open=Session.prototype.begin,Session.prototype.end=function(){this.state.close()&&this.connection._register()},Session.prototype.close=Session.prototype.end,Session.prototype.is_open=function(){return this.connection.is_open()&&this.state.is_open()},Session.prototype.is_closed=function(){return this.connection.is_closed()||this.state.is_closed()},Session.prototype._process=function(){do{this.state.need_open()&&this.output(this.local.begin.described()),this.outgoing.process(),this.incoming.process();for(var e in this.links)this.links[e]._process();this.state.need_close()&&this.output(this.local.end.described())}while(!this.state.has_settled())},Session.prototype.send=function(e,t,i,o){var n=this.outgoing.send(e,t,i,o);return this.connection._register(),n},Session.prototype._write_flow=function(e){var t={next_incoming_id:this.incoming.next_transfer_id,incoming_window:this.incoming.window,next_outgoing_id:this.outgoing.next_transfer_id,outgoing_window:this.outgoing.window};e&&(t.delivery_count=e.delivery_count,t.handle=e.local.handle,t.link_credit=e.credit),this.output(frames.flow(t).described())},Session.prototype.on_begin=function(e){if(!this.state.remote_opened())throw Error("Begin already received");this.remote.channel||(this.remote.channel=e.channel),this.remote.begin=e.performative,this.outgoing.on_begin(e.performative),this.incoming.on_begin(e.performative),this.open(),this.dispatch("session_open",this._context())},Session.prototype.on_end=function(e){if(!this.state.remote_closed())throw Error("End already received");this.remote.end=e.performative,this.close(),this.dispatch("session_close",this._context())},Session.prototype.on_attach=function(e){var t=e.performative.name,i=this.links[t];i||(i=e.performative.role?this.create_sender(t):this.create_receiver(t)),this.remote.handles[e.performative.handle]=i,i.on_attach(e),i.remote.attach=e.performative},Session.prototype.on_disposition=function(e){e.performative.role?(log.events("Received disposition for outgoing transfers"),this.outgoing.on_disposition(e.performative)):(log.events("Received disposition for incoming transfers"),this.incoming.on_disposition(e.performative)),this.connection._register()},Session.prototype.on_flow=function(e){this.outgoing.on_flow(e.performative),this.incoming.on_flow(e.performative),void 0!==e.performative.handle&&this._get_link(e).on_flow(e),this.connection._register()},Session.prototype._context=function(e){var t=e?e:{};return t.session=this,this.connection._context(t)},Session.prototype._get_link=function(e){var t=e.performative.handle,i=this.remote.handles[t];if(!i)throw Error("Invalid handle "+t);return i},Session.prototype.on_detach=function(e){this._get_link(e).on_detach(e);var t=e.performative.handle,i=this.remote.handles[t];delete this.remote.handles[t],delete this.local.handles[i.local.handle],delete this.links[i.name]},Session.prototype.on_transfer=function(e){this.incoming.on_transfer(e,this._get_link(e))},module.exports=Session;
}).call(this,require("buffer").Buffer)
},{"./endpoint.js":2,"./frames.js":3,"./link.js":4,"./log.js":5,"./message.js":6,"./types.js":12,"./util.js":13,"buffer":19,"events":23}],10:[function(require,module,exports){
"use strict";function define_terminus(e){var t=types.define_composite(e);terminus[e.name]=t.create,by_descriptor[Number(t.descriptor.numeric).toString(10)]=t,by_descriptor[t.descriptor.symbolic]=t}var types=require("./types.js"),terminus={},by_descriptor={};terminus.unwrap=function(e){if(e&&e.descriptor){var t=by_descriptor[e.descriptor.value];if(t)return new t(e.value);console.log("Unknown terminus: "+e.descriptor)}return null},define_terminus({name:"source",code:40,fields:[{name:"address",type:"string"},{name:"durable",type:"uint",default_value:0},{name:"expiry_policy",type:"symbol",default_value:"session-end"},{name:"timeout",type:"uint",default_value:0},{name:"dynamic",type:"boolean",default_value:!1},{name:"dynamic_node_properties",type:"symbolic_map"},{name:"distribution_mode",type:"symbol"},{name:"filter",type:"symbolic_map"},{name:"default_outcome",type:"*"},{name:"outcomes",type:"symbol",multiple:!0},{name:"capabilities",type:"symbol",multiple:!0}]}),define_terminus({name:"target",code:41,fields:[{name:"address",type:"string"},{name:"durable",type:"uint",default_value:0},{name:"expiry_policy",type:"symbol",default_value:"session-end"},{name:"timeout",type:"uint",default_value:0},{name:"dynamic",type:"boolean",default_value:!1},{name:"dynamic_node_properties",type:"symbolic_map"},{name:"capabilities",type:"symbol",multiple:!0}]}),module.exports=terminus;
},{"./types.js":12}],11:[function(require,module,exports){
(function (Buffer){
"use strict";var frames=require("./frames.js"),log=require("./log.js"),Transport=function(e,i,r,t){this.identifier=e,this.protocol_id=i,this.frame_type=r,this.handler=t,this.pending=[],this.header_sent=void 0,this.header_received=void 0,this.write_complete=!1,this.read_complete=!1};Transport.prototype.has_writes_pending=function(){return this.pending.length>0},Transport.prototype.encode=function(e){var i=frames.write_frame(e);log.frames("["+this.identifier+"] PENDING: "+JSON.stringify(e)),this.pending.push(i)},Transport.prototype.write=function(e){if(!this.header_sent){var i=new Buffer(8),r={protocol_id:this.protocol_id,major:1,minor:0,revision:0};frames.write_header(i,r),e.write(i),this.header_sent=r}for(var t=0;t<this.pending.length;t++)e.write(this.pending[t]),log.raw("["+this.identifier+"] SENT: "+JSON.stringify(this.pending[t]));this.pending=[]},Transport.prototype.read=function(e){var i=0;if(!this.header_received){if(e.length<8)return i;if(this.header_received=frames.read_header(e),log.frames("["+this.identifier+"] RECV: "+JSON.stringify(this.header_received)),this.header_received.protocol_id!==this.protocol_id)throw Error("Invalid AMQP protocol id "+this.header_received.protocol_id+" expecting: "+this.protocol_id);i=8}for(;i<e.length&&!this.read_complete;){var r=e.readUInt32BE(i);if(log.io("["+this.identifier+"] got frame of size "+r),e.length<i+r){log.io("["+this.identifier+"] incomplete frame; have only "+(e.length-i)+" of "+r);break}var t=frames.read_frame(e.slice(i,i+r));if(log.frames("["+this.identifier+"] RECV: "+JSON.stringify(t)),t.type!==this.frame_type)throw Error("Invalid frame type: "+t.type);i+=r,t.performative&&t.performative.dispatch(this.handler,t)}return i},module.exports=Transport;
}).call(this,require("buffer").Buffer)
},{"./frames.js":3,"./log.js":5,"buffer":19}],12:[function(require,module,exports){
(function (Buffer){
"use strict";function Typed(t,e){this.type=t,this.value=e}function hex(t){return Number(t).toString(16)}function define_type(t,e,r,i){var n,o=e>>>4;switch(n=4===o?function(){this.type=n,this.value=i}:14===o||15===o?function(t,e,r){this.type=n,this.value=t,this.array_constructor={typecode:e},r&&(this.array_constructor.descriptor=r)}:function(t){this.type=n,this.value=t},n.typecode=e,n.prototype=Object.create(Typed.prototype),n.toString=function(){return t+"#"+hex(e)},o){case 4:n.width=0,n.category="fixed";break;case 5:n.width=1,n.category="fixed";break;case 6:n.width=2,n.category="fixed";break;case 7:n.width=4,n.category="fixed";break;case 8:n.width=8,n.category="fixed";break;case 9:n.width=16,n.category="fixed";break;case 10:n.width=1,n.category="variable";break;case 11:n.width=4,n.category="variable";break;case 12:n.width=1,n.category="compound";break;case 13:n.width=4,n.category="compound";break;case 14:n.width=1,n.category="array";break;case 15:n.width=4,n.category="array"}if(r)for(var s in r)n[s]=r[s];return types.by_code[n.typecode]=n,types[t]=n,n}function buffer_ops(t){return{read:function(e,r){return e["read"+t](r)},write:function(e,r,i){e["write"+t](r,i)}}}function write_ulong(t,e,r){if("number"==typeof e||e instanceof Number){var i=e/MAX_UINT,n=e%MAX_UINT;t.writeUInt32BE(i,r),t.writeUInt32BE(n,r+4)}else e.copy(t,r)}function read_ulong(t,e){var r=t.readUInt32BE(e),i=t.readUInt32BE(e+4);return 2097153>r?r*MAX_UINT+i:t.slice(e,e+8)}function write_long(t,e,r){if("number"==typeof e||e instanceof Number){var i=Math.abs(e),n=i/MAX_UINT,o=i%MAX_UINT;if(t.writeInt32BE(n,r),t.writeUInt32BE(o,r+4),0>e)for(var s=1,p=0;8>p;p++){var a=r+(7-p),e=(255^t[a])+s;t[a]=255&e,s=e>>8}}else e.copy(t,r)}function read_long(t,e){var r=t.readInt32BE(e),i=t.readUInt32BE(e+4);return 2097153>r&&r>-2097153?r*MAX_UINT+i:t.slice(e,e+8)}function is_one_of(t,e){for(var r=0;r<e.length;r++)if(t.type.typecode===e[r].typecode)return!0;return!1}function mapify(t){for(var e={},r=0;r+1<t.length;)e[t[r++]]=t[r++];return e}function get_type(t){var e=types.by_code[t];if(!e)throw Error("Unrecognised typecode: "+hex(t));return e}function max(t,e){return t>e?t:e}function get_constructor(t){if("symbol"===t)return{typecode:types.Sym8.typecode};throw Error("TODO: Array of type "+t+" not yet supported")}function wrap_field(t,e){if(void 0!==e&&null!==e){if(Array.isArray(e)){if(!t.multiple)throw Error("Field "+t.name+" does not support multiple values, got "+JSON.stringify(e));var r=get_constructor(t.type);return types.wrap_array(e,r.typecode,r.descriptor)}if("*"===t.type)return e;var i=types["wrap_"+t.type];if(i)return i(e);throw Error("No wrapper for field "+t.name+" of type "+t.type)}if(t.mandatory)throw Error("Field "+t.name+" is mandatory");return new types.Null}function get_accessors(t,e){var r=function(){return"*"===e.type?this.value[t]:types.unwrap(this.value[t])},i=function(r){this.value[t]=wrap_field(e,r)};return{get:r,set:i,enumerable:!0,configurable:!1}}function add_type(t){var e=types.define_composite(t);types["wrap_"+t.name]=function(t){return e.create(t).described()},by_descriptor[Number(e.descriptor.numeric).toString(10)]=e,by_descriptor[e.descriptor.symbolic]=e}Typed.prototype.toString=function(){return this.value?this.value.toString():null},Typed.prototype.toLocaleString=function(){return this.value?this.value.toLocaleString():null},Typed.prototype.valueOf=function(){return this.value},Typed.prototype.toJSON=function(){return this.value&&this.value.toJSON?this.value.toJSON():this.value};var types={by_code:{}};Object.defineProperty(types,"MAX_UINT",{value:4294967295,writable:!1,configurable:!1}),Object.defineProperty(types,"MAX_USHORT",{value:65535,writable:!1,configurable:!1});var MAX_UINT=4294967296;define_type("Null",64,void 0,null),define_type("Boolean",86,buffer_ops("UInt8")),define_type("True",65,void 0,!0),define_type("False",66,void 0,!1),define_type("Ubyte",80,buffer_ops("UInt8")),define_type("Ushort",96,buffer_ops("UInt16BE")),define_type("Uint",112,buffer_ops("UInt32BE")),define_type("SmallUint",82,buffer_ops("UInt8")),define_type("Uint0",67,void 0,0),define_type("Ulong",128,{write:write_ulong,read:read_ulong}),define_type("SmallUlong",83,buffer_ops("UInt8")),define_type("Ulong0",68,void 0,0),define_type("Byte",81,buffer_ops("Int8")),define_type("Short",97,buffer_ops("Int16BE")),define_type("Int",113,buffer_ops("Int32BE")),define_type("SmallInt",84,buffer_ops("Int8")),define_type("Long",129,{write:write_long,read:read_long}),define_type("SmallLong",85,buffer_ops("Int8")),define_type("Float",114,buffer_ops("Float")),define_type("Double",130,buffer_ops("Double")),define_type("Decimal32",116),define_type("Decimal64",132),define_type("Decimal128",148),define_type("CharUTF32",115),define_type("Timestamp",131),define_type("Uuid",152),define_type("Vbin8",160),define_type("Vbin32",176),define_type("Str8",161,{encoding:"utf8"}),define_type("Str32",177,{encoding:"utf8"}),define_type("Sym8",163,{encoding:"ascii"}),define_type("Sym32",179,{encoding:"ascii"}),define_type("List0",69,void 0,[]),define_type("List8",192),define_type("List32",208),define_type("Map8",193),define_type("Map32",209),define_type("Array8",224),define_type("Array32",240),types.is_ulong=function(t){return is_one_of(t,[types.Ulong,types.Ulong0,types.SmallUlong])},types.is_string=function(t){return is_one_of(t,[types.Str8,types.Str32])},types.is_symbol=function(t){return is_one_of(t,[types.Sym8,types.Sym32])},types.is_list=function(t){return is_one_of(t,[types.List0,types.List8,types.List32])},types.is_map=function(t){return is_one_of(t,[types.Map8,types.Map32])},types.wrap_boolean=function(t){return new types.Boolean(t)},types.wrap_ulong=function(t){return 0===t?new types.Ulong0:t>255?new types.Ulong(t):new types.SmallUlong(t)},types.wrap_uint=function(t){return 0===t?new types.Uint0:t>255?new types.Uint(t):new types.SmallUint(t)},types.wrap_ushort=function(t){return new types.Ushort(t)},types.wrap_ubyte=function(t){return new types.Ubyte(t)},types.wrap_long=function(t){return t>127||-128>t?new types.Long(t):new types.SmallLong(t)},types.wrap_int=function(t){return t>127||-128>t?new types.Int(t):new types.SmallInt(t)},types.wrap_short=function(t){return new types.Short(t)},types.wrap_byte=function(t){return new types.Byte(t)},types.wrap_float=function(t){return new types.Float(t)},types.wrap_double=function(t){return new types.Double(t)},types.wrap_timestamp=function(t){return new types.Timestamp(t)},types.wrap_binary=function(t){return t.length>255?new types.Vbin32(t):new types.Vbin8(t)},types.wrap_string=function(t){return t.length>255?new types.Str32(t):new types.Str8(t)},types.wrap_symbol=function(t){return t.length>255?new types.Sym32(t):new types.Sym8(t)},types.wrap_list=function(t){if(0===t.length)return new types.List0;var e=t.map(types.wrap);return new types.List32(e)},types.wrap_map=function(t,e){var r=[];for(var i in t)r.push(e?e(i):types.wrap(i)),r.push(types.wrap(t[i]));return new types.Map32(r)},types.wrap_symbolic_map=function(t){return types.wrap_map(t,types.wrap_symbol)},types.wrap_array=function(t,e,r){if(e)return new types.Array32(t,e,r);throw Error("An array must specify a type for its elements")},types.wrap=function(t){var e=typeof t;if("string"===e)return types.wrap_string(t);if("boolean"==e)return t?new types.True:new types.False;if("number"==e||t instanceof Number){if(isNaN(t))throw Error("Cannot wrap NaN! "+t);return Math.floor(t)-t!==0?new types.Double(t):t>0?types.wrap_uint(t):types.wrap_int(t)}return t instanceof Date?void 0:t instanceof Typed?t:"undefined"==e||null===t?new types.Null:Array.isArray(t)?types.wrap_list(t):types.wrap_map(t)},types.wrap_described=function(t,e){var r=types.wrap(t);return e&&("string"==typeof e?r=types.described(types.wrap_string(e),r):("number"==typeof e||e instanceof Number)&&(r=types.described(types.wrap_ulong(e),r))),r},types.wrap_message_id=function(t){var e=typeof t;if("string"===e)return types.wrap_string(t);if("number"==e||t instanceof Number)return types.wrap_ulong(t);throw Error("invalid message id:"+t)},types.wrap_delivery_state=function(t){return new Null};var by_descriptor={};types.unwrap=function(t,e){if(t instanceof Typed){if(t.descriptor){var r=by_descriptor[t.descriptor.value];if(r)return new r(t.value);if(e)return t}var i=types.unwrap(t.value,!0);return types.is_map(t)?mapify(i):i}return Array.isArray(t)?t.map(function(t){return types.unwrap(t,!0)}):t},types.described=function(t,e){var r=Object.create(e);return t.length?(r.descriptor=t.shift(),described(t,r)):(r.descriptor=t,r)},types.Reader=function(t){this.buffer=t,this.position=0},types.Reader.prototype.read_typecode=function(){return this.read_uint(1)},types.Reader.prototype.read_uint=function(t){var e=this.position;this.position+=t;var r=t>1?"readUInt"+8*t+"BE":"readUInt8";return this.buffer[r](e)},types.Reader.prototype.read_fixed_width=function(t){var e=this.position;return this.position+=t.width,t.read?t.read(this.buffer,e):this.buffer.slice(e,this.position)},types.Reader.prototype.read_variable_width=function(t){var e=this.read_uint(t.width),r=this.read_bytes(e);return t.encoding?r.toString(t.encoding):r},types.Reader.prototype.read=function(){var t=this.read_constructor(),e=this.read_value(get_type(t.typecode));return t.descriptor?types.described(t.descriptor,e):e},types.Reader.prototype.read_constructor=function(){var t=this.read_typecode();if(0===t){var e=[];e.push(this.read());for(var r=this.read_constructor();r.descriptor;)e.push(r.descriptor),r=this.read_constructor();return{typecode:r.typecode,descriptor:1==e.length?e[0]:e}}return{typecode:t}},types.Reader.prototype.read_value=function(t){if(0===t.width)return new t;if("fixed"===t.category)return new t(this.read_fixed_width(t));if("variable"===t.category)return new t(this.read_variable_width(t));if("compound"===t.category)return this.read_compound(t);if("array"===t.category)return this.read_array(t);throw Error("Invalid category for type: "+t)},types.Reader.prototype.read_multiple=function(t,e){for(var r=e?e:this.read.bind(this),i=[];i.length<t;)i.push(r.apply(this));return i},types.Reader.prototype.read_size_count=function(t){return{size:this.read_uint(t),count:this.read_uint(t)}},types.Reader.prototype.read_compound=function(t){var e=this.read_size_count(t.width);return new t(this.read_multiple(e.count))},types.Reader.prototype.read_array=function(t){var e=this.read_size_count(t.width),r=this.read_constructor(),i=new t(this.read_multiple(e.count,this.read_value.bind(this,get_type(r.typecode))),r.typecode,r.descriptor);return i},types.Reader.prototype.toString=function(){var t="buffer@"+this.position;this.position&&(t+=": ");for(var e=this.position;e<this.buffer.length;e++)e>0&&(t+=","),t+="0x"+Number(this.buffer[e]).toString(16);return t},types.Reader.prototype.reset=function(){this.position=0},types.Reader.prototype.skip=function(t){this.position+=t},types.Reader.prototype.read_bytes=function(t){var e=this.position;return this.position+=t,this.buffer.slice(e,this.position)},types.Reader.prototype.remaining=function(){return this.buffer.length-this.position},types.Writer=function(t){this.buffer=t?t:new Buffer(1024),this.position=0},types.Writer.prototype.toBuffer=function(){return this.buffer.slice(0,this.position)},types.Writer.prototype.ensure=function(t){if(this.buffer.length<t){var e=new Buffer(max(2*this.buffer.length,t));this.buffer.copy(e),this.buffer=e}},types.Writer.prototype.write_typecode=function(t){this.write_uint(t,1)},types.Writer.prototype.write_uint=function(t,e){var r=this.position;this.ensure(this.position+e),this.position+=e;var i=e>1?"writeUInt"+8*e+"BE":"writeUInt8";if(!this.buffer[i])throw Error("Buffer doesn't define "+i);return this.buffer[i](t,r)},types.Writer.prototype.write_fixed_width=function(t,e){var r=this.position;if(this.ensure(this.position+t.width),this.position+=t.width,t.write)t.write(this.buffer,e,r);else{if(!e.copy)throw Error("Can't handle write for "+t);e.copy(this.buffer,r)}},types.Writer.prototype.write_variable_width=function(t,e){var r=t.encoding?new Buffer(e,t.encoding):new Buffer(e);this.write_uint(r.length,t.width),this.write_bytes(r)},types.Writer.prototype.write_bytes=function(t){var e=this.position;this.ensure(this.position+t.length),this.position+=t.length,t.copy(this.buffer,e)},types.Writer.prototype.write_constructor=function(t,e){e&&(this.write_typecode(0),this.write(e)),this.write_typecode(t)},types.Writer.prototype.write=function(t){if(!(t instanceof Typed))throw Error("Can't write "+JSON.stringify(t));this.write_constructor(t.type.typecode,t.descriptor),this.write_value(t.type,t.value,t.array_constructor)},types.Writer.prototype.write_value=function(t,e,r){if(0!==t.width)if("fixed"===t.category)this.write_fixed_width(t,e);else if("variable"===t.category)this.write_variable_width(t,e);else if("compound"===t.category)this.write_compound(t,e);else{if("array"!==t.category)throw Error("Invalid category "+t.category+" for type: "+t);this.write_array(t,e,r)}},types.Writer.prototype.backfill_size=function(t,e){var r=this.position-e;this.position=e,this.write_uint(r-t,t),this.position+=r-t},types.Writer.prototype.write_compound=function(t,e){var r=this.position;this.position+=t.width,this.write_uint(e.length,t.width);for(var i=0;i<e.length;i++)void 0===e[i]||null===e[i]?this.write(new types.Null):this.write(e[i]);this.backfill_size(t.width,r)},types.Writer.prototype.write_array=function(t,e,r){var i=this.position;this.position+=t.width,this.write_uint(e.length,t.width),this.write_constructor(r.typecode,r.descriptor);for(var t=get_type(r.typecode),n=0;n<e.length;n++)this.write_value(t,e[n]);this.backfill_size(t.width,i)},types.Writer.prototype.toString=function(){var t="buffer@"+this.position;this.position&&(t+=": ");for(var e=0;e<this.position;e++)e>0&&(t+=","),t+=("00"+Number(this.buffer[e]).toString(16)).slice(-2);return t},types.Writer.prototype.skip=function(t){this.ensure(this.position+t),this.position+=t},types.Writer.prototype.clear=function(){this.buffer.fill(0),this.position=0},types.Writer.prototype.remaining=function(){return this.buffer.length-this.position},types.define_composite=function(t){var e=function(t){this.value=t?t:[]};e.descriptor={numeric:t.code,symbolic:"amqp:"+t.name+":list"},e.prototype.dispatch=function(e,r){e["on_"+t.name](r)};for(var r=0;r<t.fields.length;r++){var i=t.fields[r];Object.defineProperty(e.prototype,i.name,get_accessors(r,i))}return e.toString=function(){return t.name+"#"+Number(t.code).toString(16)},e.prototype.toJSON=function(){var t={};for(var e in this)"value"!==e&&this[e]&&(t[e]=this[e]);return t},e.create=function(t){var r=new e;for(var i in t)r[i]=t[i];return r},e.prototype.described=function(t){return types.described(types.wrap_ulong(e.descriptor.numeric),types.wrap_list(this.value))},e},add_type({name:"error",code:29,fields:[{name:"condition",type:"symbol",mandatory:!0},{name:"description",type:"string"},{name:"info",type:"map"}]}),module.exports=types;
}).call(this,require("buffer").Buffer)
},{"buffer":19}],13:[function(require,module,exports){
"use strict";var util={};util.generate_uuid=function(){var x="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(x){var t=16*Math.random()|0,r="x"==x?t:3&t|8;return r.toString(16)});return x},util.clone=function(x){for(var t=Object.create(x.prototype||{}),r=Object.getOwnPropertyNames(x),e=0;e<r.length;e++){var n=r[e];t[n]=x[n]}return t},module.exports=util;
},{}],14:[function(require,module,exports){
(function (Buffer){
"use strict";function nulltransform(n){return n}function from_arraybuffer(n){return n instanceof ArrayBuffer?new Buffer(new Uint8Array(n)):new Buffer(n)}function to_typedarray(n){return new Uint8Array(n)}function wrap(n){var r=nulltransform,e=nulltransform;return n.binaryType&&(n.binaryType="arraybuffer",r=from_arraybuffer,e=to_typedarray),{end:function(){n.close()},write:function(r){n.send(e(r),{binary:!0})},on:function(e,t){"data"===e?n.onmessage=function(n){t(r(n.data))}:"end"===e?n.onclose=t:"error"===e?n.onerror=t:console.log("ERROR: Attempt to set unrecognised handler on websocket wrapper: "+e)},get_id_string:function(){return n.url}}}module.exports={connect:function(n){return function(r,e){return function(){return{connect:function(t,o,u,a){var f=new n(r,e);return f.onopen=a,wrap(f)}}}}},wrap:wrap};
}).call(this,require("buffer").Buffer)
},{"buffer":19}],15:[function(require,module,exports){
function useColors(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}function formatArgs(){var o=arguments,e=this.useColors;if(o[0]=(e?"%c":"")+this.namespace+(e?" %c":" ")+o[0]+(e?"%c ":" ")+"+"+exports.humanize(this.diff),!e)return o;var r="color: "+this.color;o=[o[0],r,"color: inherit"].concat(Array.prototype.slice.call(o,1));var t=0,s=0;return o[0].replace(/%[a-z%]/g,function(o){"%%"!==o&&(t++,"%c"===o&&(s=t))}),o.splice(s,0,r),o}function log(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function save(o){try{null==o?exports.storage.removeItem("debug"):exports.storage.debug=o}catch(e){}}function load(){var o;try{o=exports.storage.debug}catch(e){}return o}function localstorage(){try{return window.localStorage}catch(o){}}exports=module.exports=require("./debug"),exports.log=log,exports.formatArgs=formatArgs,exports.save=save,exports.load=load,exports.useColors=useColors,exports.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:localstorage(),exports.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],exports.formatters.j=function(o){return JSON.stringify(o)},exports.enable(load());
},{"./debug":16}],16:[function(require,module,exports){
function selectColor(){return exports.colors[prevColor++%exports.colors.length]}function debug(e){function r(){}function o(){var e=o,r=+new Date,s=r-(prevTime||r);e.diff=s,e.prev=prevTime,e.curr=r,prevTime=r,null==e.useColors&&(e.useColors=exports.useColors()),null==e.color&&e.useColors&&(e.color=selectColor());var t=Array.prototype.slice.call(arguments);t[0]=exports.coerce(t[0]),"string"!=typeof t[0]&&(t=["%o"].concat(t));var n=0;t[0]=t[0].replace(/%([a-z%])/g,function(r,o){if("%%"===r)return r;n++;var s=exports.formatters[o];if("function"==typeof s){var p=t[n];r=s.call(e,p),t.splice(n,1),n--}return r}),"function"==typeof exports.formatArgs&&(t=exports.formatArgs.apply(e,t));var p=o.log||exports.log||console.log.bind(console);p.apply(e,t)}r.enabled=!1,o.enabled=!0;var s=exports.enabled(e)?o:r;return s.namespace=e,s}function enable(e){exports.save(e);for(var r=(e||"").split(/[\s,]+/),o=r.length,s=0;o>s;s++)r[s]&&(e=r[s].replace(/\*/g,".*?"),"-"===e[0]?exports.skips.push(new RegExp("^"+e.substr(1)+"$")):exports.names.push(new RegExp("^"+e+"$")))}function disable(){exports.enable("")}function enabled(e){var r,o;for(r=0,o=exports.skips.length;o>r;r++)if(exports.skips[r].test(e))return!1;for(r=0,o=exports.names.length;o>r;r++)if(exports.names[r].test(e))return!0;return!1}function coerce(e){return e instanceof Error?e.stack||e.message:e}exports=module.exports=debug,exports.coerce=coerce,exports.disable=disable,exports.enable=enable,exports.enabled=enabled,exports.humanize=require("ms"),exports.names=[],exports.skips=[],exports.formatters={};var prevColor=0,prevTime;
},{"ms":17}],17:[function(require,module,exports){
function parse(e){if(e=""+e,!(e.length>1e4)){var a=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(a){var r=parseFloat(a[1]),c=(a[2]||"ms").toLowerCase();switch(c){case"years":case"year":case"yrs":case"yr":case"y":return r*y;case"days":case"day":case"d":return r*d;case"hours":case"hour":case"hrs":case"hr":case"h":return r*h;case"minutes":case"minute":case"mins":case"min":case"m":return r*m;case"seconds":case"second":case"secs":case"sec":case"s":return r*s;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r}}}}function short(e){return e>=d?Math.round(e/d)+"d":e>=h?Math.round(e/h)+"h":e>=m?Math.round(e/m)+"m":e>=s?Math.round(e/s)+"s":e+"ms"}function long(e){return plural(e,d,"day")||plural(e,h,"hour")||plural(e,m,"minute")||plural(e,s,"second")||e+" ms"}function plural(s,e,a){return e>s?void 0:1.5*e>s?Math.floor(s/e)+" "+a:Math.ceil(s/e)+" "+a+"s"}var s=1e3,m=60*s,h=60*m,d=24*h,y=365.25*d;module.exports=function(s,e){return e=e||{},"string"==typeof s?parse(s):e["long"]?long(s):short(s)};
},{}],18:[function(require,module,exports){
},{}],19:[function(require,module,exports){
(function (global){
"use strict";function typedArraySupport(){try{var t=new Uint8Array(1);return t.foo=function(){return 42},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(e){return!1}}function kMaxLength(){return Buffer.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Buffer(t){return this instanceof Buffer?(Buffer.TYPED_ARRAY_SUPPORT||(this.length=0,this.parent=void 0),"number"==typeof t?fromNumber(this,t):"string"==typeof t?fromString(this,t,arguments.length>1?arguments[1]:"utf8"):fromObject(this,t)):arguments.length>1?new Buffer(t,arguments[1]):new Buffer(t)}function fromNumber(t,e){if(t=allocate(t,0>e?0:0|checked(e)),!Buffer.TYPED_ARRAY_SUPPORT)for(var r=0;e>r;r++)t[r]=0;return t}function fromString(t,e,r){("string"!=typeof r||""===r)&&(r="utf8");var n=0|byteLength(e,r);return t=allocate(t,n),t.write(e,r),t}function fromObject(t,e){if(Buffer.isBuffer(e))return fromBuffer(t,e);if(isArray(e))return fromArray(t,e);if(null==e)throw new TypeError("must start with number, buffer, array or string");if("undefined"!=typeof ArrayBuffer){if(e.buffer instanceof ArrayBuffer)return fromTypedArray(t,e);if(e instanceof ArrayBuffer)return fromArrayBuffer(t,e)}return e.length?fromArrayLike(t,e):fromJsonObject(t,e)}function fromBuffer(t,e){var r=0|checked(e.length);return t=allocate(t,r),e.copy(t,0,0,r),t}function fromArray(t,e){var r=0|checked(e.length);t=allocate(t,r);for(var n=0;r>n;n+=1)t[n]=255&e[n];return t}function fromTypedArray(t,e){var r=0|checked(e.length);t=allocate(t,r);for(var n=0;r>n;n+=1)t[n]=255&e[n];return t}function fromArrayBuffer(t,e){return e.byteLength,Buffer.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e),t.__proto__=Buffer.prototype):t=fromTypedArray(t,new Uint8Array(e)),t}function fromArrayLike(t,e){var r=0|checked(e.length);t=allocate(t,r);for(var n=0;r>n;n+=1)t[n]=255&e[n];return t}function fromJsonObject(t,e){var r,n=0;"Buffer"===e.type&&isArray(e.data)&&(r=e.data,n=0|checked(r.length)),t=allocate(t,n);for(var f=0;n>f;f+=1)t[f]=255&r[f];return t}function allocate(t,e){Buffer.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e),t.__proto__=Buffer.prototype):t.length=e;var r=0!==e&&e<=Buffer.poolSize>>>1;return r&&(t.parent=rootParent),t}function checked(t){if(t>=kMaxLength())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+kMaxLength().toString(16)+" bytes");return 0|t}function SlowBuffer(t,e){if(!(this instanceof SlowBuffer))return new SlowBuffer(t,e);var r=new Buffer(t,e);return delete r.parent,r}function byteLength(t,e){"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"binary":case"raw":case"raws":return r;case"utf8":case"utf-8":return utf8ToBytes(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return base64ToBytes(t).length;default:if(n)return utf8ToBytes(t).length;e=(""+e).toLowerCase(),n=!0}}function slowToString(t,e,r){var n=!1;if(e=0|e,r=void 0===r||r===1/0?this.length:0|r,t||(t="utf8"),0>e&&(e=0),r>this.length&&(r=this.length),e>=r)return"";for(;;)switch(t){case"hex":return hexSlice(this,e,r);case"utf8":case"utf-8":return utf8Slice(this,e,r);case"ascii":return asciiSlice(this,e,r);case"binary":return binarySlice(this,e,r);case"base64":return base64Slice(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function hexWrite(t,e,r,n){r=Number(r)||0;var f=t.length-r;n?(n=Number(n),n>f&&(n=f)):n=f;var i=e.length;if(i%2!==0)throw new Error("Invalid hex string");n>i/2&&(n=i/2);for(var o=0;n>o;o++){var u=parseInt(e.substr(2*o,2),16);if(isNaN(u))throw new Error("Invalid hex string");t[r+o]=u}return o}function utf8Write(t,e,r,n){return blitBuffer(utf8ToBytes(e,t.length-r),t,r,n)}function asciiWrite(t,e,r,n){return blitBuffer(asciiToBytes(e),t,r,n)}function binaryWrite(t,e,r,n){return asciiWrite(t,e,r,n)}function base64Write(t,e,r,n){return blitBuffer(base64ToBytes(e),t,r,n)}function ucs2Write(t,e,r,n){return blitBuffer(utf16leToBytes(e,t.length-r),t,r,n)}function base64Slice(t,e,r){return 0===e&&r===t.length?base64.fromByteArray(t):base64.fromByteArray(t.slice(e,r))}function utf8Slice(t,e,r){r=Math.min(t.length,r);for(var n=[],f=e;r>f;){var i=t[f],o=null,u=i>239?4:i>223?3:i>191?2:1;if(r>=f+u){var s,h,a,c;switch(u){case 1:128>i&&(o=i);break;case 2:s=t[f+1],128===(192&s)&&(c=(31&i)<<6|63&s,c>127&&(o=c));break;case 3:s=t[f+1],h=t[f+2],128===(192&s)&&128===(192&h)&&(c=(15&i)<<12|(63&s)<<6|63&h,c>2047&&(55296>c||c>57343)&&(o=c));break;case 4:s=t[f+1],h=t[f+2],a=t[f+3],128===(192&s)&&128===(192&h)&&128===(192&a)&&(c=(15&i)<<18|(63&s)<<12|(63&h)<<6|63&a,c>65535&&1114112>c&&(o=c))}}null===o?(o=65533,u=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),f+=u}return decodeCodePointsArray(n)}function decodeCodePointsArray(t){var e=t.length;if(MAX_ARGUMENTS_LENGTH>=e)return String.fromCharCode.apply(String,t);for(var r="",n=0;e>n;)r+=String.fromCharCode.apply(String,t.slice(n,n+=MAX_ARGUMENTS_LENGTH));return r}function asciiSlice(t,e,r){var n="";r=Math.min(t.length,r);for(var f=e;r>f;f++)n+=String.fromCharCode(127&t[f]);return n}function binarySlice(t,e,r){var n="";r=Math.min(t.length,r);for(var f=e;r>f;f++)n+=String.fromCharCode(t[f]);return n}function hexSlice(t,e,r){var n=t.length;(!e||0>e)&&(e=0),(!r||0>r||r>n)&&(r=n);for(var f="",i=e;r>i;i++)f+=toHex(t[i]);return f}function utf16leSlice(t,e,r){for(var n=t.slice(e,r),f="",i=0;i<n.length;i+=2)f+=String.fromCharCode(n[i]+256*n[i+1]);return f}function checkOffset(t,e,r){if(t%1!==0||0>t)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function checkInt(t,e,r,n,f,i){if(!Buffer.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");if(e>f||i>e)throw new RangeError("value is out of bounds");if(r+n>t.length)throw new RangeError("index out of range")}function objectWriteUInt16(t,e,r,n){0>e&&(e=65535+e+1);for(var f=0,i=Math.min(t.length-r,2);i>f;f++)t[r+f]=(e&255<<8*(n?f:1-f))>>>8*(n?f:1-f)}function objectWriteUInt32(t,e,r,n){0>e&&(e=4294967295+e+1);for(var f=0,i=Math.min(t.length-r,4);i>f;f++)t[r+f]=e>>>8*(n?f:3-f)&255}function checkIEEE754(t,e,r,n,f,i){if(e>f||i>e)throw new RangeError("value is out of bounds");if(r+n>t.length)throw new RangeError("index out of range");if(0>r)throw new RangeError("index out of range")}function writeFloat(t,e,r,n,f){return f||checkIEEE754(t,e,r,4,3.4028234663852886e38,-3.4028234663852886e38),ieee754.write(t,e,r,n,23,4),r+4}function writeDouble(t,e,r,n,f){return f||checkIEEE754(t,e,r,8,1.7976931348623157e308,-1.7976931348623157e308),ieee754.write(t,e,r,n,52,8),r+8}function base64clean(t){if(t=stringtrim(t).replace(INVALID_BASE64_RE,""),t.length<2)return"";for(;t.length%4!==0;)t+="=";return t}function stringtrim(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function toHex(t){return 16>t?"0"+t.toString(16):t.toString(16)}function utf8ToBytes(t,e){e=e||1/0;for(var r,n=t.length,f=null,i=[],o=0;n>o;o++){if(r=t.charCodeAt(o),r>55295&&57344>r){if(!f){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(o+1===n){(e-=3)>-1&&i.push(239,191,189);continue}f=r;continue}if(56320>r){(e-=3)>-1&&i.push(239,191,189),f=r;continue}r=(f-55296<<10|r-56320)+65536}else f&&(e-=3)>-1&&i.push(239,191,189);if(f=null,128>r){if((e-=1)<0)break;i.push(r)}else if(2048>r){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(65536>r){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(1114112>r))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function asciiToBytes(t){for(var e=[],r=0;r<t.length;r++)e.push(255&t.charCodeAt(r));return e}function utf16leToBytes(t,e){for(var r,n,f,i=[],o=0;o<t.length&&!((e-=2)<0);o++)r=t.charCodeAt(o),n=r>>8,f=r%256,i.push(f),i.push(n);return i}function base64ToBytes(t){return base64.toByteArray(base64clean(t))}function blitBuffer(t,e,r,n){for(var f=0;n>f&&!(f+r>=e.length||f>=t.length);f++)e[f+r]=t[f];return f}var base64=require("base64-js"),ieee754=require("ieee754"),isArray=require("isarray");exports.Buffer=Buffer,exports.SlowBuffer=SlowBuffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var rootParent={};Buffer.TYPED_ARRAY_SUPPORT=void 0!==global.TYPED_ARRAY_SUPPORT?global.TYPED_ARRAY_SUPPORT:typedArraySupport(),Buffer.TYPED_ARRAY_SUPPORT?(Buffer.prototype.__proto__=Uint8Array.prototype,Buffer.__proto__=Uint8Array):(Buffer.prototype.length=void 0,Buffer.prototype.parent=void 0),Buffer.isBuffer=function(t){return!(null==t||!t._isBuffer)},Buffer.compare=function(t,e){if(!Buffer.isBuffer(t)||!Buffer.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,f=0,i=Math.min(r,n);i>f&&t[f]===e[f];)++f;return f!==i&&(r=t[f],n=e[f]),n>r?-1:r>n?1:0},Buffer.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.concat=function(t,e){if(!isArray(t))throw new TypeError("list argument must be an Array of Buffers.");if(0===t.length)return new Buffer(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;r++)e+=t[r].length;var n=new Buffer(e),f=0;for(r=0;r<t.length;r++){var i=t[r];i.copy(n,f),f+=i.length}return n},Buffer.byteLength=byteLength,Buffer.prototype._isBuffer=!0,Buffer.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?utf8Slice(this,0,t):slowToString.apply(this,arguments)},Buffer.prototype.equals=function(t){if(!Buffer.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:0===Buffer.compare(this,t)},Buffer.prototype.inspect=function(){var t="",e=exports.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),"<Buffer "+t+">"},Buffer.prototype.compare=function(t){if(!Buffer.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?0:Buffer.compare(this,t)},Buffer.prototype.indexOf=function(t,e){function r(t,e,r){for(var n=-1,f=0;r+f<t.length;f++)if(t[r+f]===e[-1===n?0:f-n]){if(-1===n&&(n=f),f-n+1===e.length)return r+n}else n=-1;return-1}if(e>2147483647?e=2147483647:-2147483648>e&&(e=-2147483648),e>>=0,0===this.length)return-1;if(e>=this.length)return-1;if(0>e&&(e=Math.max(this.length+e,0)),"string"==typeof t)return 0===t.length?-1:String.prototype.indexOf.call(this,t,e);if(Buffer.isBuffer(t))return r(this,t,e);if("number"==typeof t)return Buffer.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,t,e):r(this,[t],e);throw new TypeError("val must be string, number or Buffer")},Buffer.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else if(isFinite(e))e=0|e,isFinite(r)?(r=0|r,void 0===n&&(n="utf8")):(n=r,r=void 0);else{var f=n;n=e,e=0|r,r=f}var i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(0>r||0>e)||e>this.length)throw new RangeError("attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return hexWrite(this,t,e,r);case"utf8":case"utf-8":return utf8Write(this,t,e,r);case"ascii":return asciiWrite(this,t,e,r);case"binary":return binaryWrite(this,t,e,r);case"base64":return base64Write(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ucs2Write(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var MAX_ARGUMENTS_LENGTH=4096;Buffer.prototype.slice=function(t,e){var r=this.length;t=~~t,e=void 0===e?r:~~e,0>t?(t+=r,0>t&&(t=0)):t>r&&(t=r),0>e?(e+=r,0>e&&(e=0)):e>r&&(e=r),t>e&&(e=t);var n;if(Buffer.TYPED_ARRAY_SUPPORT)n=this.subarray(t,e),n.__proto__=Buffer.prototype;else{var f=e-t;n=new Buffer(f,void 0);for(var i=0;f>i;i++)n[i]=this[i+t]}return n.length&&(n.parent=this.parent||this),n},Buffer.prototype.readUIntLE=function(t,e,r){t=0|t,e=0|e,r||checkOffset(t,e,this.length);for(var n=this[t],f=1,i=0;++i<e&&(f*=256);)n+=this[t+i]*f;return n},Buffer.prototype.readUIntBE=function(t,e,r){t=0|t,e=0|e,r||checkOffset(t,e,this.length);for(var n=this[t+--e],f=1;e>0&&(f*=256);)n+=this[t+--e]*f;return n},Buffer.prototype.readUInt8=function(t,e){return e||checkOffset(t,1,this.length),this[t]},Buffer.prototype.readUInt16LE=function(t,e){return e||checkOffset(t,2,this.length),this[t]|this[t+1]<<8},Buffer.prototype.readUInt16BE=function(t,e){return e||checkOffset(t,2,this.length),this[t]<<8|this[t+1]},Buffer.prototype.readUInt32LE=function(t,e){return e||checkOffset(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},Buffer.prototype.readUInt32BE=function(t,e){return e||checkOffset(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},Buffer.prototype.readIntLE=function(t,e,r){t=0|t,e=0|e,r||checkOffset(t,e,this.length);for(var n=this[t],f=1,i=0;++i<e&&(f*=256);)n+=this[t+i]*f;return f*=128,n>=f&&(n-=Math.pow(2,8*e)),n},Buffer.prototype.readIntBE=function(t,e,r){t=0|t,e=0|e,r||checkOffset(t,e,this.length);for(var n=e,f=1,i=this[t+--n];n>0&&(f*=256);)i+=this[t+--n]*f;return f*=128,i>=f&&(i-=Math.pow(2,8*e)),i},Buffer.prototype.readInt8=function(t,e){return e||checkOffset(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},Buffer.prototype.readInt16LE=function(t,e){e||checkOffset(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},Buffer.prototype.readInt16BE=function(t,e){e||checkOffset(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},Buffer.prototype.readInt32LE=function(t,e){return e||checkOffset(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},Buffer.prototype.readInt32BE=function(t,e){return e||checkOffset(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},Buffer.prototype.readFloatLE=function(t,e){return e||checkOffset(t,4,this.length),ieee754.read(this,t,!0,23,4)},Buffer.prototype.readFloatBE=function(t,e){return e||checkOffset(t,4,this.length),ieee754.read(this,t,!1,23,4)},Buffer.prototype.readDoubleLE=function(t,e){return e||checkOffset(t,8,this.length),ieee754.read(this,t,!0,52,8)},Buffer.prototype.readDoubleBE=function(t,e){return e||checkOffset(t,8,this.length),ieee754.read(this,t,!1,52,8)},Buffer.prototype.writeUIntLE=function(t,e,r,n){t=+t,e=0|e,r=0|r,n||checkInt(this,t,e,r,Math.pow(2,8*r),0);var f=1,i=0;for(this[e]=255&t;++i<r&&(f*=256);)this[e+i]=t/f&255;return e+r},Buffer.prototype.writeUIntBE=function(t,e,r,n){t=+t,e=0|e,r=0|r,n||checkInt(this,t,e,r,Math.pow(2,8*r),0);var f=r-1,i=1;for(this[e+f]=255&t;--f>=0&&(i*=256);)this[e+f]=t/i&255;return e+r},Buffer.prototype.writeUInt8=function(t,e,r){return t=+t,e=0|e,r||checkInt(this,t,e,1,255,0),Buffer.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},Buffer.prototype.writeUInt16LE=function(t,e,r){return t=+t,e=0|e,r||checkInt(this,t,e,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):objectWriteUInt16(this,t,e,!0),e+2},Buffer.prototype.writeUInt16BE=function(t,e,r){return t=+t,e=0|e,r||checkInt(this,t,e,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):objectWriteUInt16(this,t,e,!1),e+2},Buffer.prototype.writeUInt32LE=function(t,e,r){return t=+t,e=0|e,r||checkInt(this,t,e,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):objectWriteUInt32(this,t,e,!0),e+4},Buffer.prototype.writeUInt32BE=function(t,e,r){return t=+t,e=0|e,r||checkInt(this,t,e,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):objectWriteUInt32(this,t,e,!1),e+4},Buffer.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e=0|e,!n){var f=Math.pow(2,8*r-1);checkInt(this,t,e,r,f-1,-f)}var i=0,o=1,u=0>t?1:0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=(t/o>>0)-u&255;return e+r},Buffer.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e=0|e,!n){var f=Math.pow(2,8*r-1);checkInt(this,t,e,r,f-1,-f)}var i=r-1,o=1,u=0>t?1:0;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=(t/o>>0)-u&255;return e+r},Buffer.prototype.writeInt8=function(t,e,r){return t=+t,e=0|e,r||checkInt(this,t,e,1,127,-128),Buffer.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),0>t&&(t=255+t+1),this[e]=255&t,e+1},Buffer.prototype.writeInt16LE=function(t,e,r){return t=+t,e=0|e,r||checkInt(this,t,e,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):objectWriteUInt16(this,t,e,!0),e+2},Buffer.prototype.writeInt16BE=function(t,e,r){return t=+t,e=0|e,r||checkInt(this,t,e,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):objectWriteUInt16(this,t,e,!1),e+2},Buffer.prototype.writeInt32LE=function(t,e,r){return t=+t,e=0|e,r||checkInt(this,t,e,4,2147483647,-2147483648),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):objectWriteUInt32(this,t,e,!0),e+4},Buffer.prototype.writeInt32BE=function(t,e,r){return t=+t,e=0|e,r||checkInt(this,t,e,4,2147483647,-2147483648),0>t&&(t=4294967295+t+1),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):objectWriteUInt32(this,t,e,!1),e+4},Buffer.prototype.writeFloatLE=function(t,e,r){return writeFloat(this,t,e,!0,r)},Buffer.prototype.writeFloatBE=function(t,e,r){return writeFloat(this,t,e,!1,r)},Buffer.prototype.writeDoubleLE=function(t,e,r){return writeDouble(this,t,e,!0,r)},Buffer.prototype.writeDoubleBE=function(t,e,r){return writeDouble(this,t,e,!1,r)},Buffer.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&r>n&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(0>e)throw new RangeError("targetStart out of bounds");if(0>r||r>=this.length)throw new RangeError("sourceStart out of bounds");if(0>n)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var f,i=n-r;if(this===t&&e>r&&n>e)for(f=i-1;f>=0;f--)t[f+e]=this[f+r];else if(1e3>i||!Buffer.TYPED_ARRAY_SUPPORT)for(f=0;i>f;f++)t[f+e]=this[f+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+i),e);return i},Buffer.prototype.fill=function(t,e,r){if(t||(t=0),e||(e=0),r||(r=this.length),e>r)throw new RangeError("end < start");if(r!==e&&0!==this.length){if(0>e||e>=this.length)throw new RangeError("start out of bounds");if(0>r||r>this.length)throw new RangeError("end out of bounds");var n;if("number"==typeof t)for(n=e;r>n;n++)this[n]=t;else{var f=utf8ToBytes(t.toString()),i=f.length;for(n=e;r>n;n++)this[n]=f[n%i]}return this}};var INVALID_BASE64_RE=/[^+\/0-9A-Za-z-_]/g;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"base64-js":20,"ieee754":21,"isarray":22}],20:[function(require,module,exports){
!function(t){"use strict";function r(t){var r=t.charCodeAt(0);return r===c||r===f?62:r===o||r===d?63:A>r?-1:A+10>r?r-A+26+26:u+26>r?r-u:i+26>r?r-i+26:void 0}function e(t){function e(t){i[f++]=t}var n,a,c,o,A,i;if(t.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var u=t.length;A="="===t.charAt(u-2)?2:"="===t.charAt(u-1)?1:0,i=new h(3*t.length/4-A),c=A>0?t.length-4:t.length;var f=0;for(n=0,a=0;c>n;n+=4,a+=3)o=r(t.charAt(n))<<18|r(t.charAt(n+1))<<12|r(t.charAt(n+2))<<6|r(t.charAt(n+3)),e((16711680&o)>>16),e((65280&o)>>8),e(255&o);return 2===A?(o=r(t.charAt(n))<<2|r(t.charAt(n+1))>>4,e(255&o)):1===A&&(o=r(t.charAt(n))<<10|r(t.charAt(n+1))<<4|r(t.charAt(n+2))>>2,e(o>>8&255),e(255&o)),i}function n(t){function r(t){return a.charAt(t)}function e(t){return r(t>>18&63)+r(t>>12&63)+r(t>>6&63)+r(63&t)}var n,h,c,o=t.length%3,A="";for(n=0,c=t.length-o;c>n;n+=3)h=(t[n]<<16)+(t[n+1]<<8)+t[n+2],A+=e(h);switch(o){case 1:h=t[t.length-1],A+=r(h>>2),A+=r(h<<4&63),A+="==";break;case 2:h=(t[t.length-2]<<8)+t[t.length-1],A+=r(h>>10),A+=r(h>>4&63),A+=r(h<<2&63),A+="="}return A}var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h="undefined"!=typeof Uint8Array?Uint8Array:Array,c="+".charCodeAt(0),o="/".charCodeAt(0),A="0".charCodeAt(0),i="a".charCodeAt(0),u="A".charCodeAt(0),f="-".charCodeAt(0),d="_".charCodeAt(0);t.toByteArray=e,t.fromByteArray=n}("undefined"==typeof exports?this.base64js={}:exports);
},{}],21:[function(require,module,exports){
exports.read=function(a,o,t,r,h){var M,p,w=8*h-r-1,f=(1<<w)-1,e=f>>1,i=-7,N=t?h-1:0,n=t?-1:1,s=a[o+N];for(N+=n,M=s&(1<<-i)-1,s>>=-i,i+=w;i>0;M=256*M+a[o+N],N+=n,i-=8);for(p=M&(1<<-i)-1,M>>=-i,i+=r;i>0;p=256*p+a[o+N],N+=n,i-=8);if(0===M)M=1-e;else{if(M===f)return p?NaN:(s?-1:1)*(1/0);p+=Math.pow(2,r),M-=e}return(s?-1:1)*p*Math.pow(2,M-r)},exports.write=function(a,o,t,r,h,M){var p,w,f,e=8*M-h-1,i=(1<<e)-1,N=i>>1,n=23===h?Math.pow(2,-24)-Math.pow(2,-77):0,s=r?0:M-1,u=r?1:-1,l=0>o||0===o&&0>1/o?1:0;for(o=Math.abs(o),isNaN(o)||o===1/0?(w=isNaN(o)?1:0,p=i):(p=Math.floor(Math.log(o)/Math.LN2),o*(f=Math.pow(2,-p))<1&&(p--,f*=2),o+=p+N>=1?n/f:n*Math.pow(2,1-N),o*f>=2&&(p++,f/=2),p+N>=i?(w=0,p=i):p+N>=1?(w=(o*f-1)*Math.pow(2,h),p+=N):(w=o*Math.pow(2,N-1)*Math.pow(2,h),p=0));h>=8;a[t+s]=255&w,s+=u,w/=256,h-=8);for(p=p<<h|w,e+=h;e>0;a[t+s]=255&p,s+=u,p/=256,e-=8);a[t+s-u]|=128*l};
},{}],22:[function(require,module,exports){
var toString={}.toString;module.exports=Array.isArray||function(r){return"[object Array]"==toString.call(r)};
},{}],23:[function(require,module,exports){
function EventEmitter(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function isFunction(e){return"function"==typeof e}function isNumber(e){return"number"==typeof e}function isObject(e){return"object"==typeof e&&null!==e}function isUndefined(e){return void 0===e}module.exports=EventEmitter,EventEmitter.EventEmitter=EventEmitter,EventEmitter.prototype._events=void 0,EventEmitter.prototype._maxListeners=void 0,EventEmitter.defaultMaxListeners=10,EventEmitter.prototype.setMaxListeners=function(e){if(!isNumber(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},EventEmitter.prototype.emit=function(e){var t,n,i,s,r,o;if(this._events||(this._events={}),"error"===e&&(!this._events.error||isObject(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[e],isUndefined(n))return!1;if(isFunction(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:s=Array.prototype.slice.call(arguments,1),n.apply(this,s)}else if(isObject(n))for(s=Array.prototype.slice.call(arguments,1),o=n.slice(),i=o.length,r=0;i>r;r++)o[r].apply(this,s);return!0},EventEmitter.prototype.addListener=function(e,t){var n;if(!isFunction(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,isFunction(t.listener)?t.listener:t),this._events[e]?isObject(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,isObject(this._events[e])&&!this._events[e].warned&&(n=isUndefined(this._maxListeners)?EventEmitter.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},EventEmitter.prototype.on=EventEmitter.prototype.addListener,EventEmitter.prototype.once=function(e,t){function n(){this.removeListener(e,n),i||(i=!0,t.apply(this,arguments))}if(!isFunction(t))throw TypeError("listener must be a function");var i=!1;return n.listener=t,this.on(e,n),this},EventEmitter.prototype.removeListener=function(e,t){var n,i,s,r;if(!isFunction(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],s=n.length,i=-1,n===t||isFunction(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(isObject(n)){for(r=s;r-- >0;)if(n[r]===t||n[r].listener&&n[r].listener===t){i=r;break}if(0>i)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},EventEmitter.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],isFunction(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},EventEmitter.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?isFunction(this._events[e])?[this._events[e]]:this._events[e].slice():[]},EventEmitter.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(isFunction(t))return 1;if(t)return t.length}return 0},EventEmitter.listenerCount=function(e,t){return e.listenerCount(t)};
},{}],24:[function(require,module,exports){
function cleanUpNextTick(){draining=!1,currentQueue.length?queue=currentQueue.concat(queue):queueIndex=-1,queue.length&&drainQueue()}function drainQueue(){if(!draining){var e=setTimeout(cleanUpNextTick);draining=!0;for(var n=queue.length;n;){for(currentQueue=queue,queue=[];++queueIndex<n;)currentQueue&&currentQueue[queueIndex].run();queueIndex=-1,n=queue.length}currentQueue=null,draining=!1,clearTimeout(e)}}function Item(e,n){this.fun=e,this.array=n}function noop(){}var process=module.exports={},queue=[],draining=!1,currentQueue,queueIndex=-1;process.nextTick=function(e){var n=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)n[r-1]=arguments[r];queue.push(new Item(e,n)),1!==queue.length||draining||setTimeout(drainQueue,0)},Item.prototype.run=function(){this.fun.apply(null,this.array)},process.title="browser",process.browser=!0,process.env={},process.argv=[],process.version="",process.versions={},process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.binding=function(e){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(e){throw new Error("process.chdir is not supported")},process.umask=function(){return 0};
},{}],25:[function(require,module,exports){
(function (global){
!function(e){function o(e){throw new RangeError(T[e])}function n(e,o){for(var n=e.length,r=[];n--;)r[n]=o(e[n]);return r}function r(e,o){var r=e.split("@"),t="";r.length>1&&(t=r[0]+"@",e=r[1]),e=e.replace(S,".");var u=e.split("."),i=n(u,o).join(".");return t+i}function t(e){for(var o,n,r=[],t=0,u=e.length;u>t;)o=e.charCodeAt(t++),o>=55296&&56319>=o&&u>t?(n=e.charCodeAt(t++),56320==(64512&n)?r.push(((1023&o)<<10)+(1023&n)+65536):(r.push(o),t--)):r.push(o);return r}function u(e){return n(e,function(e){var o="";return e>65535&&(e-=65536,o+=P(e>>>10&1023|55296),e=56320|1023&e),o+=P(e)}).join("")}function i(e){return 10>e-48?e-22:26>e-65?e-65:26>e-97?e-97:b}function f(e,o){return e+22+75*(26>e)-((0!=o)<<5)}function c(e,o,n){var r=0;for(e=n?M(e/j):e>>1,e+=M(e/o);e>L*C>>1;r+=b)e=M(e/L);return M(r+(L+1)*e/(e+m))}function l(e){var n,r,t,f,l,s,d,a,p,h,v=[],g=e.length,w=0,m=I,j=A;for(r=e.lastIndexOf(E),0>r&&(r=0),t=0;r>t;++t)e.charCodeAt(t)>=128&&o("not-basic"),v.push(e.charCodeAt(t));for(f=r>0?r+1:0;g>f;){for(l=w,s=1,d=b;f>=g&&o("invalid-input"),a=i(e.charCodeAt(f++)),(a>=b||a>M((x-w)/s))&&o("overflow"),w+=a*s,p=j>=d?y:d>=j+C?C:d-j,!(p>a);d+=b)h=b-p,s>M(x/h)&&o("overflow"),s*=h;n=v.length+1,j=c(w-l,n,0==l),M(w/n)>x-m&&o("overflow"),m+=M(w/n),w%=n,v.splice(w++,0,m)}return u(v)}function s(e){var n,r,u,i,l,s,d,a,p,h,v,g,w,m,j,F=[];for(e=t(e),g=e.length,n=I,r=0,l=A,s=0;g>s;++s)v=e[s],128>v&&F.push(P(v));for(u=i=F.length,i&&F.push(E);g>u;){for(d=x,s=0;g>s;++s)v=e[s],v>=n&&d>v&&(d=v);for(w=u+1,d-n>M((x-r)/w)&&o("overflow"),r+=(d-n)*w,n=d,s=0;g>s;++s)if(v=e[s],n>v&&++r>x&&o("overflow"),v==n){for(a=r,p=b;h=l>=p?y:p>=l+C?C:p-l,!(h>a);p+=b)j=a-h,m=b-h,F.push(P(f(h+j%m,0))),a=M(j/m);F.push(P(f(a,0))),l=c(r,w,u==i),r=0,++u}++r,++n}return F.join("")}function d(e){return r(e,function(e){return F.test(e)?l(e.slice(4).toLowerCase()):e})}function a(e){return r(e,function(e){return O.test(e)?"xn--"+s(e):e})}var p="object"==typeof exports&&exports&&!exports.nodeType&&exports,h="object"==typeof module&&module&&!module.nodeType&&module,v="object"==typeof global&&global;(v.global===v||v.window===v||v.self===v)&&(e=v);var g,w,x=2147483647,b=36,y=1,C=26,m=38,j=700,A=72,I=128,E="-",F=/^xn--/,O=/[^\x20-\x7E]/,S=/[\x2E\u3002\uFF0E\uFF61]/g,T={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},L=b-y,M=Math.floor,P=String.fromCharCode;if(g={version:"1.3.2",ucs2:{decode:t,encode:u},decode:l,encode:s,toASCII:a,toUnicode:d},"function"==typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return g});else if(p&&h)if(module.exports==p)h.exports=g;else for(w in g)g.hasOwnProperty(w)&&(p[w]=g[w]);else e.punycode=g}(this);
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],26:[function(require,module,exports){
"use strict";function hasOwnProperty(r,e){return Object.prototype.hasOwnProperty.call(r,e)}module.exports=function(r,e,t,n){e=e||"&",t=t||"=";var o={};if("string"!=typeof r||0===r.length)return o;var a=/\+/g;r=r.split(e);var s=1e3;n&&"number"==typeof n.maxKeys&&(s=n.maxKeys);var p=r.length;s>0&&p>s&&(p=s);for(var y=0;p>y;++y){var u,c,i,l,f=r[y].replace(a,"%20"),v=f.indexOf(t);v>=0?(u=f.substr(0,v),c=f.substr(v+1)):(u=f,c=""),i=decodeURIComponent(u),l=decodeURIComponent(c),hasOwnProperty(o,i)?isArray(o[i])?o[i].push(l):o[i]=[o[i],l]:o[i]=l}return o};var isArray=Array.isArray||function(r){return"[object Array]"===Object.prototype.toString.call(r)};
},{}],27:[function(require,module,exports){
"use strict";function map(r,e){if(r.map)return r.map(e);for(var t=[],n=0;n<r.length;n++)t.push(e(r[n],n));return t}var stringifyPrimitive=function(r){switch(typeof r){case"string":return r;case"boolean":return r?"true":"false";case"number":return isFinite(r)?r:"";default:return""}};module.exports=function(r,e,t,n){return e=e||"&",t=t||"=",null===r&&(r=void 0),"object"==typeof r?map(objectKeys(r),function(n){var i=encodeURIComponent(stringifyPrimitive(n))+t;return isArray(r[n])?map(r[n],function(r){return i+encodeURIComponent(stringifyPrimitive(r))}).join(e):i+encodeURIComponent(stringifyPrimitive(r[n]))}).join(e):n?encodeURIComponent(stringifyPrimitive(n))+t+encodeURIComponent(stringifyPrimitive(r)):""};var isArray=Array.isArray||function(r){return"[object Array]"===Object.prototype.toString.call(r)},objectKeys=Object.keys||function(r){var e=[];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&e.push(t);return e};
},{}],28:[function(require,module,exports){
"use strict";exports.decode=exports.parse=require("./decode"),exports.encode=exports.stringify=require("./encode");
},{"./decode":26,"./encode":27}],29:[function(require,module,exports){
"use strict";function Url(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}function urlParse(t,s,e){if(t&&util.isObject(t)&&t instanceof Url)return t;var h=new Url;return h.parse(t,s,e),h}function urlFormat(t){return util.isString(t)&&(t=urlParse(t)),t instanceof Url?t.format():Url.prototype.format.call(t)}function urlResolve(t,s){return urlParse(t,!1,!0).resolve(s)}function urlResolveObject(t,s){return t?urlParse(t,!1,!0).resolveObject(s):s}var punycode=require("punycode"),util=require("./util");exports.parse=urlParse,exports.resolve=urlResolve,exports.resolveObject=urlResolveObject,exports.format=urlFormat,exports.Url=Url;var protocolPattern=/^([a-z0-9.+-]+:)/i,portPattern=/:[0-9]*$/,simplePathPattern=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,delims=["<",">",'"',"`"," ","\r","\n"," "],unwise=["{","}","|","\\","^","`"].concat(delims),autoEscape=["'"].concat(unwise),nonHostChars=["%","/","?",";","#"].concat(autoEscape),hostEndingChars=["/","?","#"],hostnameMaxLen=255,hostnamePartPattern=/^[+a-z0-9A-Z_-]{0,63}$/,hostnamePartStart=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,unsafeProtocol={javascript:!0,"javascript:":!0},hostlessProtocol={javascript:!0,"javascript:":!0},slashedProtocol={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},querystring=require("querystring");Url.prototype.parse=function(t,s,e){if(!util.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var h=t.indexOf("?"),r=-1!==h&&h<t.indexOf("#")?"?":"#",a=t.split(r),o=/\\/g;a[0]=a[0].replace(o,"/"),t=a.join(r);var n=t;if(n=n.trim(),!e&&1===t.split("#").length){var i=simplePathPattern.exec(n);if(i)return this.path=n,this.href=n,this.pathname=i[1],i[2]?(this.search=i[2],s?this.query=querystring.parse(this.search.substr(1)):this.query=this.search.substr(1)):s&&(this.search="",this.query={}),this}var l=protocolPattern.exec(n);if(l){l=l[0];var u=l.toLowerCase();this.protocol=u,n=n.substr(l.length)}if(e||l||n.match(/^\/\/[^@\/]+@[^@\/]+/)){var p="//"===n.substr(0,2);!p||l&&hostlessProtocol[l]||(n=n.substr(2),this.slashes=!0)}if(!hostlessProtocol[l]&&(p||l&&!slashedProtocol[l])){for(var c=-1,f=0;f<hostEndingChars.length;f++){var m=n.indexOf(hostEndingChars[f]);-1!==m&&(-1===c||c>m)&&(c=m)}var v,g;g=-1===c?n.lastIndexOf("@"):n.lastIndexOf("@",c),-1!==g&&(v=n.slice(0,g),n=n.slice(g+1),this.auth=decodeURIComponent(v)),c=-1;for(var f=0;f<nonHostChars.length;f++){var m=n.indexOf(nonHostChars[f]);-1!==m&&(-1===c||c>m)&&(c=m)}-1===c&&(c=n.length),this.host=n.slice(0,c),n=n.slice(c),this.parseHost(),this.hostname=this.hostname||"";var y="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!y)for(var P=this.hostname.split(/\./),f=0,d=P.length;d>f;f++){var q=P[f];if(q&&!q.match(hostnamePartPattern)){for(var b="",O=0,j=q.length;j>O;O++)b+=q.charCodeAt(O)>127?"x":q[O];if(!b.match(hostnamePartPattern)){var x=P.slice(0,f),U=P.slice(f+1),C=q.match(hostnamePartStart);C&&(x.push(C[1]),U.unshift(C[2])),U.length&&(n="/"+U.join(".")+n),this.hostname=x.join(".");break}}}this.hostname.length>hostnameMaxLen?this.hostname="":this.hostname=this.hostname.toLowerCase(),y||(this.hostname=punycode.toASCII(this.hostname));var A=this.port?":"+this.port:"",w=this.hostname||"";this.host=w+A,this.href+=this.host,y&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==n[0]&&(n="/"+n))}if(!unsafeProtocol[u])for(var f=0,d=autoEscape.length;d>f;f++){var E=autoEscape[f];if(-1!==n.indexOf(E)){var I=encodeURIComponent(E);I===E&&(I=escape(E)),n=n.split(E).join(I)}}var R=n.indexOf("#");-1!==R&&(this.hash=n.substr(R),n=n.slice(0,R));var S=n.indexOf("?");if(-1!==S?(this.search=n.substr(S),this.query=n.substr(S+1),s&&(this.query=querystring.parse(this.query)),n=n.slice(0,S)):s&&(this.search="",this.query={}),n&&(this.pathname=n),slashedProtocol[u]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var A=this.pathname||"",k=this.search||"";this.path=A+k}return this.href=this.format(),this},Url.prototype.format=function(){var t=this.auth||"";t&&(t=encodeURIComponent(t),t=t.replace(/%3A/i,":"),t+="@");var s=this.protocol||"",e=this.pathname||"",h=this.hash||"",r=!1,a="";this.host?r=t+this.host:this.hostname&&(r=t+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(r+=":"+this.port)),this.query&&util.isObject(this.query)&&Object.keys(this.query).length&&(a=querystring.stringify(this.query));var o=this.search||a&&"?"+a||"";return s&&":"!==s.substr(-1)&&(s+=":"),this.slashes||(!s||slashedProtocol[s])&&r!==!1?(r="//"+(r||""),e&&"/"!==e.charAt(0)&&(e="/"+e)):r||(r=""),h&&"#"!==h.charAt(0)&&(h="#"+h),o&&"?"!==o.charAt(0)&&(o="?"+o),e=e.replace(/[?#]/g,function(t){return encodeURIComponent(t)}),o=o.replace("#","%23"),s+r+e+o+h},Url.prototype.resolve=function(t){return this.resolveObject(urlParse(t,!1,!0)).format()},Url.prototype.resolveObject=function(t){if(util.isString(t)){var s=new Url;s.parse(t,!1,!0),t=s}for(var e=new Url,h=Object.keys(this),r=0;r<h.length;r++){var a=h[r];e[a]=this[a]}if(e.hash=t.hash,""===t.href)return e.href=e.format(),e;if(t.slashes&&!t.protocol){for(var o=Object.keys(t),n=0;n<o.length;n++){var i=o[n];"protocol"!==i&&(e[i]=t[i])}return slashedProtocol[e.protocol]&&e.hostname&&!e.pathname&&(e.path=e.pathname="/"),e.href=e.format(),e}if(t.protocol&&t.protocol!==e.protocol){if(!slashedProtocol[t.protocol]){for(var l=Object.keys(t),u=0;u<l.length;u++){var p=l[u];e[p]=t[p]}return e.href=e.format(),e}if(e.protocol=t.protocol,t.host||hostlessProtocol[t.protocol])e.pathname=t.pathname;else{for(var c=(t.pathname||"").split("/");c.length&&!(t.host=c.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==c[0]&&c.unshift(""),c.length<2&&c.unshift(""),e.pathname=c.join("/")}if(e.search=t.search,e.query=t.query,e.host=t.host||"",e.auth=t.auth,e.hostname=t.hostname||t.host,e.port=t.port,e.pathname||e.search){var f=e.pathname||"",m=e.search||"";e.path=f+m}return e.slashes=e.slashes||t.slashes,e.href=e.format(),e}var v=e.pathname&&"/"===e.pathname.charAt(0),g=t.host||t.pathname&&"/"===t.pathname.charAt(0),y=g||v||e.host&&t.pathname,P=y,d=e.pathname&&e.pathname.split("/")||[],c=t.pathname&&t.pathname.split("/")||[],q=e.protocol&&!slashedProtocol[e.protocol];if(q&&(e.hostname="",e.port=null,e.host&&(""===d[0]?d[0]=e.host:d.unshift(e.host)),e.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===c[0]?c[0]=t.host:c.unshift(t.host)),t.host=null),y=y&&(""===c[0]||""===d[0])),g)e.host=t.host||""===t.host?t.host:e.host,e.hostname=t.hostname||""===t.hostname?t.hostname:e.hostname,e.search=t.search,e.query=t.query,d=c;else if(c.length)d||(d=[]),d.pop(),d=d.concat(c),e.search=t.search,e.query=t.query;else if(!util.isNullOrUndefined(t.search)){if(q){e.hostname=e.host=d.shift();var b=e.host&&e.host.indexOf("@")>0?e.host.split("@"):!1;b&&(e.auth=b.shift(),e.host=e.hostname=b.shift())}return e.search=t.search,e.query=t.query,util.isNull(e.pathname)&&util.isNull(e.search)||(e.path=(e.pathname?e.pathname:"")+(e.search?e.search:"")),e.href=e.format(),e}if(!d.length)return e.pathname=null,e.search?e.path="/"+e.search:e.path=null,e.href=e.format(),e;for(var O=d.slice(-1)[0],j=(e.host||t.host||d.length>1)&&("."===O||".."===O)||""===O,x=0,U=d.length;U>=0;U--)O=d[U],"."===O?d.splice(U,1):".."===O?(d.splice(U,1),x++):x&&(d.splice(U,1),x--);if(!y&&!P)for(;x--;x)d.unshift("..");!y||""===d[0]||d[0]&&"/"===d[0].charAt(0)||d.unshift(""),j&&"/"!==d.join("/").substr(-1)&&d.push("");var C=""===d[0]||d[0]&&"/"===d[0].charAt(0);if(q){e.hostname=e.host=C?"":d.length?d.shift():"";var b=e.host&&e.host.indexOf("@")>0?e.host.split("@"):!1;b&&(e.auth=b.shift(),e.host=e.hostname=b.shift())}return y=y||e.host&&d.length,y&&!C&&d.unshift(""),d.length?e.pathname=d.join("/"):(e.pathname=null,e.path=null),util.isNull(e.pathname)&&util.isNull(e.search)||(e.path=(e.pathname?e.pathname:"")+(e.search?e.search:"")),e.auth=t.auth||e.auth,e.slashes=e.slashes||t.slashes,e.href=e.format(),e},Url.prototype.parseHost=function(){var t=this.host,s=portPattern.exec(t);s&&(s=s[0],":"!==s&&(this.port=s.substr(1)),t=t.substr(0,t.length-s.length)),t&&(this.hostname=t)};
},{"./util":30,"punycode":25,"querystring":28}],30:[function(require,module,exports){
"use strict";module.exports={isString:function(n){return"string"==typeof n},isObject:function(n){return"object"==typeof n&&null!==n},isNull:function(n){return null===n},isNullOrUndefined:function(n){return null==n}};
},{}],"rhea":[function(require,module,exports){
(function (process){
"use strict";var Connection=require("./connection.js"),log=require("./log.js"),rpc=require("./rpc.js"),sasl=require("./sasl.js"),util=require("./util.js"),net=require("net"),tls=require("tls"),url=require("url"),EventEmitter=require("events").EventEmitter,Container=function(t){this.options=t?Object.create(t):{},this.options.id||(this.options.id=util.generate_uuid()),this.id=this.options.id,this.sasl_server_mechanisms=sasl.server_mechanisms()};Container.prototype=Object.create(EventEmitter.prototype),Container.prototype.constructor=Container,Container.prototype.dispatch=function(t,e){return log.events("Container got event: "+t),this.listeners(t).length?(EventEmitter.prototype.emit.apply(this,arguments),!0):!1},Container.prototype.connect=function(t){return new Connection(t,this).connect()},Container.prototype.listen=function(t){var e,n=this;if(void 0===t.transport||"tcp"===t.transport)e=net.createServer(),e.on("connection",function(e){new Connection(t,n).accept(e)});else{if("tls"!==t.transport&&"ssl"!==t.transport)throw Error("Unrecognised transport: "+t.transport);e=tls.createServer(t),e.on("secureConnection",function(e){new Connection(t,n).accept(e)})}return process.version.match(/v0\.10\.\d+/)?e.listen(t.port,t.host):e.listen(t),e},Container.prototype.create_container=function(t){return new Container(t)},Container.prototype.get_option=function(t,e){return void 0!==this.options[t]?this.options[t]:e},Container.prototype.generate_uuid=util.generate_uuid,Container.prototype.rpc_server=function(t,e){return rpc.server(this,t,e)},Container.prototype.rpc_client=function(t){return rpc.client(this,t)};var ws=require("./ws.js");Container.prototype.websocket_accept=function(t,e){new Connection(e,this).accept(ws.wrap(t))},Container.prototype.websocket_connect=ws.connect,module.exports=new Container;
}).call(this,require('_process'))
},{"./connection.js":1,"./log.js":5,"./rpc.js":7,"./sasl.js":8,"./util.js":13,"./ws.js":14,"_process":24,"events":23,"net":18,"tls":18,"url":29}]},{},[])
//# sourceMappingURL=rhea.map.json