From f49ef09c1208b7f0cd3adacd2ed925c8421a0586 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Wed, 25 Sep 2013 10:31:53 -0700 Subject: [PATCH] Bump stanzaio version --- clientapp/libraries/stanza.io.js | 21461 ++++++++++++++++++++++++++++- 1 file changed, 21453 insertions(+), 8 deletions(-) diff --git a/clientapp/libraries/stanza.io.js b/clientapp/libraries/stanza.io.js index 427df4c..b65182b 100644 --- a/clientapp/libraries/stanza.io.js +++ b/clientapp/libraries/stanza.io.js @@ -1,8 +1,21453 @@ -!function(t){if("function"==typeof bootstrap)bootstrap("xmpp",t);else if("object"==typeof exports)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeXMPP=t}else"undefined"!=typeof window?window.XMPP=t():global.XMPP=t()}(function(){var t;return function(t,e,n){function r(n,o){if(!e[n]){if(!t[n]){var a="function"==typeof require&&require;if(!o&&a)return a(n,!0);if(i)return i(n,!0);throw new Error("Cannot find module '"+n+"'")}var s=e[n]={exports:{}};t[n][0].call(s.exports,function(e){var i=t[n][1][e];return r(i?i:e)},s,s.exports)}return e[n].exports}for(var i="function"==typeof require&&require,o=0;o0?this.jid.slice(0,t):this.jid,this.parts.bare},get resource(){if(this.parts.resource)return this.parts.resource;var t=this.jid.indexOf("/");return this.parts.resource=t>0?this.jid.slice(t+1):"",this.parts.resource},get local(){if(this.parts.local)return this.parts.local;var t=this.bare,e=t.indexOf("@");return this.parts.local=e>0?t.slice(0,e):t,this.parts.local},get domain(){if(this.parts.domain)return this.parts.domain;var t=this.bare,e=t.indexOf("@");return this.parts.domain=e>0?t.slice(e+1):t,this.parts.domain}},e.exports=n},{}],4:[function(t,e){e.exports=function(t){t.disco.addFeature("urn:xmpp:attention:0"),t.getAttention=function(e,n){n=n||{},n.to=e,n.type="headline",n.attention=!0,t.sendMessage(n)},t.on("message",function(e){e._extensions._attention&&t.emit("attention",e)})}},{}],5:[function(t,e){t("../stanza/avatar"),e.exports=function(t){t.disco.addFeature("urn:xmpp:avatar:metadata+notify"),t.on("pubsubEvent",function(e){e.event._extensions.updated&&"urn:xmpp:avatar:metadata"===e.event.updated.node&&t.emit("avatar",{jid:e.from,avatars:e.event.updated.published[0].avatars})}),t.publishAvatar=function(e,n,r){t.publish("","urn:xmpp:avatar:data",{id:e,avatarData:n},r)},t.useAvatars=function(e,n){t.publish("","urn:xmpp:avatar:metadata",{id:"current",avatars:e},n)},t.getAvatar=function(e,n,r){t.getItem(e,"urn:xmpp:avatar:data",n,r)}}},{"../stanza/avatar":23}],6:[function(t,e){t("../stanza/bookmarks"),e.exports=function(t){t.getBookmarks=function(t){this.getPrivateData({bookmarks:{}},t)},t.setBookmarks=function(t,e){this.setPrivateData({bookmarks:t},e)}}},{"../stanza/bookmarks":25}],7:[function(t,e){t("../stanza/carbons"),e.exports=function(t){t.disco.addFeature("urn:xmpp:carbons:2"),t.enableCarbons=function(t){this.sendIq({type:"set",enableCarbons:!0},t)},t.disableCarbons=function(t){this.sendIq({type:"set",disableCarbons:!0},t)},t.on("message",function(e){return e._extensions.carbonSent?t.emit("carbon:sent",e):e._extensions.carbonReceived?t.emit("carbon:received",e):void 0})}},{"../stanza/carbons":27}],8:[function(t,e){t("../stanza/chatstates"),e.exports=function(t){t.disco.addFeature("http://jabber.org/protocol/chatstates"),t.on("message",function(e){e.chatState&&t.emit("chatState",{to:e.to,from:e.from,chatState:e.chatState})})}},{"../stanza/chatstates":28}],9:[function(t,e){e.exports=function(t){t.disco.addFeature("urn:xmpp:message-correct:0"),t.on("message",function(e){e.replace&&(t.emit("replace",e),t.emit("replace:"+e.id,e))})}},{}],10:[function(t,e){t("../stanza/delayed"),e.exports=function(t){t.disco.addFeature("urn:xmpp:delay")}},{"../stanza/delayed":30}],11:[function(t,e){function n(t,e,n){"sha-1"===e&&(e="sha1");var i=r(t,e);return i&&i==n}function r(t,e){var n="",r=t.features.sort(),i=[],u={},c=[];o.forEach(t.identities,function(t){i.push([t.category||"",t.type||"",t.lang||"",t.name||""].join("/"))});var f=i.length,l=r.length;if(i=o.unique(i,!0),r=o.unique(r,!0),l!=r.length||f!=i.length)return!1;n+=i.join("<")+"<",n+=r.join("<")+"<";var p=!1;if(o.forEach(t.extensions,function(t){for(var e=t.fields,n=0,r=e.length;r>n;n++)if("FORM_TYPE"==e[n].name&&"hidden"==e[n].type){var i=e[n].value;return u[i]?(p=!0,void 0):(u[i]=t,c.push(i),void 0)}}),p)return!1;c.sort(),o.forEach(c,function(t){var e=u[t],r={},i=[];n+="<"+t,o.forEach(e.fields,function(t){var e=t.name;if("FORM_TYPE"!=e){var n=t.value||"";"object"!=typeof n&&(n=n.split("\n")),r[e]=n.sort(),i.push(e)}}),i.sort(),o.forEach(i,function(t){n+="<"+t,o.forEach(r[t],function(t){n+="<"+t})})}),"sha-1"===e&&(e="sha1");var h=a.createHash(e).update(s.encode(n)).digest("base64"),d=4-h.length%4;4===d&&(d=0);for(var m=0;d>m;m++)h+="=";return h}function i(){this.features={},this.identities={},this.extensions={},this.items={},this.caps={}}var o=t("underscore"),a=t("crypto");t("../stanza/disco"),t("../stanza/caps");var s={encode:function(t){return unescape(encodeURIComponent(t))},decode:function(t){return decodeURIComponent(escape(t))}};i.prototype={constructor:{value:i},addFeature:function(t,e){e=e||"",this.features[e]||(this.features[e]=[]),this.features[e].push(t)},addIdentity:function(t,e){e=e||"",this.identities[e]||(this.identities[e]=[]),this.identities[e].push(t)},addItem:function(t,e){e=e||"",this.items[e]||(this.items[e]=[]),this.items[e].push(t)},addExtension:function(t,e){e=e||"",this.extensions[e]||(this.extensions[e]=[]),this.extensions[e].push(t)}},e.exports=function(t){t.disco=new i(t),t.disco.addFeature("http://jabber.org/protocol/disco#info"),t.disco.addIdentity({category:"client",type:"web"}),t.getDiscoInfo=function(t,e,n){this.sendIq({to:t,type:"get",discoInfo:{node:e}},n)},t.getDiscoItems=function(t,e,n){this.sendIq({to:t,type:"get",discoItems:{node:e}},n)},t.updateCaps=function(){var e=this.config.capsNode||"https://stanza.io",n=JSON.parse(JSON.stringify({identities:this.disco.identities[""],features:this.disco.features[""],extensions:this.disco.extensions[""]})),i=r(n,"sha-1");return this.disco.caps={node:e,hash:"sha-1",ver:i},e=e+"#"+i,this.disco.features[e]=n.features,this.disco.identities[e]=n.identities,this.disco.extensions[e]=n.extensions,t.getCurrentCaps()},t.getCurrentCaps=function(){var e=t.disco.caps;if(!e.ver)return{ver:null,discoInfo:null};var n=e.node+"#"+e.ver;return{ver:e.ver,discoInfo:{identities:t.disco.identities[n],features:t.disco.features[n],extensions:t.disco.extensions[n]}}},t.on("presence",function(e){e._extensions.caps&&t.emit("disco:caps",e)}),t.on("iq:get:discoInfo",function(e){var n=e.discoInfo.node,r=e.discoInfo.node;n===t.disco.caps.node+"#"+t.disco.caps.ver&&(r=n,n=""),t.sendIq(e.resultReply({discoInfo:{node:r,identities:t.disco.identities[n]||[],features:t.disco.features[n]||[],extensions:t.disco.extensions[n]||[]}}))}),t.on("iq:get:discoItems",function(e){var n=e.discoInfo.node;t.sendIq(e.resultReply({discoItems:{node:n,items:t.disco.items[n]||[]}}))}),t.verifyVerString=n,t.generateVerString=r}},{"../stanza/caps":26,"../stanza/disco":31,crypto:63,underscore:96}],12:[function(t,e){t("../stanza/forwarded"),e.exports=function(t){t.disco.addFeature("urn:xmpp:forward:0")}},{"../stanza/forwarded":33}],13:[function(t,e){t("../stanza/idle"),e.exports=function(t){t.disco.addFeature("urn:xmpp:idle:0")}},{"../stanza/idle":34}],14:[function(t,e){t("../stanza/visibility"),e.exports=function(t){t.goInvisible=function(){this.sendIq({type:"set",invisible:!0})},t.goVisible=function(){this.sendIq({type:"set",visible:!0})}}},{"../stanza/visibility":54}],15:[function(t,e){t("../stanza/mam"),e.exports=function(t){t.disco.addFeature("urn:xmpp:mam:tmp"),t.getHistory=function(t,e){var n=this,r=this.nextId();t=t||{},t.queryid=r;var i=[];this.on("mam:"+r,"session",function(t){i.push(t)}),e=e||function(){},this.sendIq({type:"get",id:r,mamQuery:t},function(t,o){t?e(t):(n.off("mam:"+r),o.mamQuery.results=i,e(null,o))})},t.getHistoryPreferences=function(e){t.sendIq({type:"get",mamPrefs:{}},e)},t.setHistoryPreferences=function(e,n){t.sendIq({type:"set",mamPrefs:e},n)},t.on("message",function(e){e._extensions.mam&&t.emit("mam:"+e.mam.queryid,e)})}},{"../stanza/mam":36}],16:[function(t,e){t("../stanza/muc"),e.exports=function(t){t.joinRoom=function(t,e,n){n=n||{},n.to=t+"/"+e,n.caps=this.disco.caps,n.joinMuc=n.joinMuc||{},this.sendPresence(n)},t.leaveRoom=function(t,e,n){n=n||{},n.to=t+"/"+e,n.type="unavailable",this.sendPresence(n)}}},{"../stanza/muc":38}],17:[function(t,e){t("../stanza/private"),e.exports=function(t){t.getPrivateData=function(t,e){this.sendIq({type:"get",privateStorage:t},e)},t.setPrivateData=function(t,e){this.sendIq({type:"set",privateStorage:t},e)}}},{"../stanza/private":40}],18:[function(t,e){t("../stanza/pubsub"),e.exports=function(t){t.on("message",function(e){e._extensions.event&&t.emit("pubsubEvent",e)}),t.subscribeToNode=function(e,n,r){t.sendIq({type:"set",to:e,pubsub:{subscribe:{node:n.node,jid:n.jid||t.jid}}},r)},t.unsubscribeFromNode=function(e,n,r){t.sendIq({type:"set",to:e,pubsub:{unsubscribe:{node:n.node,jid:n.jid||t.jid.split("/")[0]}}},r)},t.publish=function(e,n,r,i){t.sendIq({type:"set",to:e,pubsub:{publish:{node:n,item:r}}},i)},t.getItem=function(e,n,r,i){t.sendIq({type:"get",to:e,pubsub:{retrieve:{node:n,item:r}}},i)},t.getItems=function(e,n,r,i){r=r||{},r.node=n,t.sendIq({type:"get",to:e,pubsub:{retrieve:{node:n,max:r.max},rsm:r.rsm}},i)},t.retract=function(e,n,r,i,o){t.sendIq({type:"set",to:e,pubsub:{retract:{node:n,notify:i,id:r}}},o)},t.purgeNode=function(e,n,r){t.sendIq({type:"set",to:e,pubsubOwner:{purge:n}},r)},t.deleteNode=function(e,n,r){t.sendIq({type:"set",to:e,pubsubOwner:{del:n}},r)},t.createNode=function(e,n,r,i){var o={type:"set",to:e,pubsubOwner:{create:n}};r&&(o.pubsubOwner.config={form:r}),t.sendIq(o,i)}}},{"../stanza/pubsub":41}],19:[function(t,e){t("../stanza/receipts"),e.exports=function(t){t.disco.addFeature("urn:xmpp:receipts"),t.on("message",function(e){var n={normal:!0,chat:!0,headline:!0};n[e.type]&&e.requestReceipt&&!e._extensions.receipt&&t.sendMessage({to:e.from,receipt:{id:e.id},id:e.id}),e._extensions.receipt&&t.emit("receipt:"+e.receipt.id)})}},{"../stanza/receipts":42}],20:[function(t,e){t("../stanza/time"),e.exports=function(t){t.disco.addFeature("urn:xmpp:time"),t.getTime=function(t,e){this.sendIq({to:t,type:"get",time:!0},e)},t.on("iq:get:time",function(e){var n=new Date;t.sendIq(e.resultReply({time:{utc:n,tzo:n.getTimezoneOffset()}}))})}},{"../stanza/time":51}],21:[function(t,e){t("../stanza/version"),e.exports=function(t){t.disco.addFeature("jabber:iq:version"),t.on("iq:get:version",function(e){t.sendIq(e.resultReply({version:t.config.version||{name:"stanza.io"}}))}),t.getSoftwareVersion=function(t,e){this.sendIq({to:t,type:"get",version:{}},e)}}},{"../stanza/version":53}],22:[function(t,e){function n(t,e){return(t%e+e)%e}function r(t){this.conn=t,this.id=!1,this.allowResume=!0,this.started=!1,this.lastAck=0,this.handled=0,this.windowSize=1,this.windowCount=0,this.unacked=[]}var i=t("./stanza/sm"),o=Math.pow(2,32);r.prototype={constructor:{value:r},enable:function(){var t=new i.Enable;t.resume=this.allowResume,this.conn.send(t),this.handled=0,this.started=!0},resume:function(){var t=new i.Resume({h:this.handled,previd:this.id});this.conn.send(t),this.started=!0},enabled:function(t){this.id=t.id},resumed:function(t){this.id=t.id,t.h&&this.process(t,!0)},failed:function(){this.started=!1,this.id=!1,this.lastAck=0,this.handled=0,this.windowCount=0,this.unacked=[]},ack:function(){this.conn.send(new i.Ack({h:this.handled}))},request:function(){this.conn.send(new i.Request)},process:function(t,e){for(var r=this,i=n(t.h-this.lastAck,o),a=0;i>a&&this.unacked.length>0;a++)this.conn.emit("stanza:acked",this.unacked.shift());if(e){var s=this.unacked;this.unacked=[],s.forEach(function(t){r.conn.send(t)})}this.lastAck=t.h},track:function(t){var e=t._name,n={message:!0,presence:!0,iq:!0};this.started&&n[e]&&(this.unacked.push(t),this.windowCount+=1,this.windowCount==this.windowSize&&(this.request(),this.windowCount=0))},handle:function(){this.started&&(this.handled=n(this.handled+1,o))}},e.exports=r},{"./stanza/sm":47}],23:[function(t,e){var n=t("underscore"),r=t("jxt"),i=t("./pubsub").Item,o=t("./pubsub").EventItem,a=e.exports=r.define({name:"avatar",namespace:"urn:xmpp:avatar:metadata",element:"info",fields:{id:r.attribute("id"),bytes:r.attribute("bytes"),height:r.attribute("height"),width:r.attribute("width"),type:r.attribute("type","image/png"),url:r.attribute("url")}}),s={get:function(){var t=r.find(this.xml,"urn:xmpp:avatar:metadata","metadata"),e=[];if(t.length){var i=r.find(t[0],"urn:xmpp:avatar:metadata","info");n.forEach(i,function(t){e.push(new a({},t))})}return e},set:function(t){var e=r.findOrCreate(this.xml,"urn:xmpp:avatar:metadata","metadata");r.setAttribute(e,"xmlns","urn:xmpp:avatar:metadata"),n.forEach(t,function(t){var n=new a(t);e.appendChild(n.xml)})}};r.add(i,"avatars",s),r.add(o,"avatars",s),r.add(i,"avatarData",r.subText("urn:xmpp:avatar:data","data")),r.add(o,"avatarData",r.subText("urn:xmpp:avatar:data","data"))},{"./pubsub":41,jxt:77,underscore:96}],24:[function(t,e){var n=t("jxt"),r=t("./iq"),i=t("./streamFeatures"),o=t("./util"),a="urn:ietf:params:xml:ns:xmpp-bind",s=e.exports=n.define({name:"bind",namespace:a,element:"bind",fields:{resource:n.subText(a,"resource"),jid:o.jidSub(a,"jid")}});n.extend(r,s),n.extend(i,s)},{"./iq":35,"./streamFeatures":50,"./util":52,jxt:77}],25:[function(t,e){var n=t("jxt"),r=t("./util"),i=t("./private"),o=n.define({name:"conference",namespace:"storage:bookmarks",element:"conference",fields:{name:n.attribute("name"),autoJoin:n.boolAttribute("autojoin"),jid:r.jidAttribute("jid"),nick:n.subText("storage:bookmarks","nick")}}),a=e.exports=n.define({name:"bookmarks",namespace:"storage:bookmarks",element:"storage"});n.extend(i,a),n.extend(a,o,"conferences")},{"./private":40,"./util":52,jxt:77}],26:[function(t,e){var n=t("jxt"),r=t("./presence"),i=t("./streamFeatures"),o=e.exports=n.define({name:"caps",namespace:"http://jabber.org/protocol/caps",element:"c",fields:{ver:n.attribute("ver"),node:n.attribute("node"),hash:n.attribute("hash"),ext:n.attribute("ext")}});n.extend(r,o),n.extend(i,o)},{"./presence":39,"./streamFeatures":50,jxt:77}],27:[function(t,e,n){var r=t("jxt"),i=t("./message"),o=t("./iq"),a=t("./forwarded");n.Sent=r.define({name:"carbonSent",eventName:"carbon:sent",namespace:"urn:xmpp:carbons:2",element:"sent"}),n.Received=r.define({name:"carbonReceived",eventName:"carbon:received",namespace:"urn:xmpp:carbons:2",element:"received"}),n.Private=r.define({name:"carbonPrivate",eventName:"carbon:private",namespace:"urn:xmpp:carbons:2",element:"private"}),n.Enable=r.define({name:"enableCarbons",namespace:"urn:xmpp:carbons:2",element:"enable"}),n.Disable=r.define({name:"disableCarbons",namespace:"urn:xmpp:carbons:2",element:"disable"}),r.extend(n.Sent,a),r.extend(n.Received,a),r.extend(i,n.Sent),r.extend(i,n.Received),r.extend(i,n.Private),r.extend(o,n.Enable),r.extend(o,n.Disable)},{"./forwarded":33,"./iq":35,"./message":37,jxt:77}],28:[function(t){var e=t("jxt"),n=t("./message"),r="http://jabber.org/protocol/chatstates",i=e.define({name:"chatStateActive",eventName:"chat:active",namespace:r,element:"active"}),o=e.define({name:"chatStateComposing",eventName:"chat:composing",namespace:r,element:"composing"}),a=e.define({name:"chatStatePaused",eventName:"chat:paused",namespace:r,element:"paused"}),s=e.define({name:"chatStateInactive",eventName:"chat:inactive",namespace:r,element:"inactive"}),u=e.define({name:"chatStateGone",eventName:"chat:gone",namespace:r,element:"gone"});e.extend(n,i),e.extend(n,o),e.extend(n,a),e.extend(n,s),e.extend(n,u),e.add(n,"chatState",{get:function(){for(var t=this,e=["Active","Composing","Paused","Inactive","Gone"],n=0;n1?"text-multi"===this._type?t.join("\n"):t:t[0]},set:function(t){"boolean"===this._type?r.setSubText(this.xml,this._NS,"value",t?"1":"0"):("text-multi"===this._type&&(t=t.split("\n")),r.setMultiSubText(this.xml,this._NS,"value",t))}},options:{get:function(){var t=this;return r.getMultiSubText(this.xml,this._NS,"option",function(e){return r.getSubText(e,t._NS,"value")})},set:function(t){var e=this;r.setMultiSubText(this.xml,this._NS,"option",t,function(t){var n=document.createElementNS(e._NS,"option"),r=document.createElementNS(e._NS,"value");n.appendChild(r),r.textContent=t,e.xml.appendChild(n)})}}}}),r.extend(i,n.DataForm)},{"./message":37,"./util":52,jxt:77,underscore:96}],30:[function(t,e){var n=t("jxt"),r=t("./message"),i=t("./presence"),o=t("./util"),a=e.exports=n.define({name:"delay",namespace:"urn:xmpp:delay",element:"delay",fields:{from:o.jidAttribute("from"),stamp:o.dateAttribute("stamp"),reason:n.text()}});n.extend(r,a),n.extend(i,a)},{"./message":37,"./presence":39,"./util":52,jxt:77}],31:[function(t,e,n){t("underscore");var r=t("jxt"),i=t("../jid"),o=t("./iq"),a=t("./rsm"),s=t("./dataforms").DataForm;n.DiscoInfo=r.define({name:"discoInfo",namespace:"http://jabber.org/protocol/disco#info",element:"query",fields:{node:r.attribute("node"),identities:{get:function(){var t=[],e=r.find(this.xml,this._NS,"identity");return e.forEach(function(e){t.push({category:r.getAttribute(e,"category"),type:r.getAttribute(e,"type"),lang:e.getAttributeNS(r.XML_NS,"lang"),name:r.getAttribute(e,"name")})}),t},set:function(t){var e=this,n=r.find(this.xml,this._NS,"identity");n.forEach(function(t){e.xml.removeChild(t)}),t.forEach(function(t){var n=document.createElementNS(e._NS,"identity");r.setAttribute(n,"category",t.category),r.setAttribute(n,"type",t.type),r.setAttribute(n,"name",t.name),t.lang&&n.setAttributeNS(r.XML_NS,"lang",t.lang),e.xml.appendChild(n)})}},features:{get:function(){var t=[],e=r.find(this.xml,this._NS,"feature");return e.forEach(function(e){t.push(e.getAttribute("var"))}),t},set:function(t){var e=this,n=r.find(this.xml,this._NS,"feature");n.forEach(function(t){e.xml.removeChild(t)}),t.forEach(function(t){var n=document.createElementNS(e._NS,"feature");n.setAttribute("var",t),e.xml.appendChild(n)})}}}}),n.DiscoItems=r.define({name:"discoItems",namespace:"http://jabber.org/protocol/disco#items",element:"query",fields:{node:r.attribute("node"),items:{get:function(){var t=[],e=r.find(this.xml,this._NS,"item");return e.forEach(function(e){t.push({jid:new i(r.getAttribute(e,"jid")),node:r.getAttribute(e,"node"),name:r.getAttribute(e,"name")})}),t},set:function(t){var e=this,n=r.find(this.xml,this._NS,"item");n.forEach(function(t){e.xml.removeChild(t)}),t.forEach(function(t){var n=document.createElementNS(e._NS,"item");r.setAttribute(n,"jid",t.jid.toString()),r.setAttribute(n,"node",t.node),r.setAttribute(n,"name",t.name),e.xml.appendChild(n)})}}}}),r.extend(o,n.DiscoInfo),r.extend(o,n.DiscoItems),r.extend(n.DiscoItems,a),r.extend(n.DiscoInfo,s,"extensions")},{"../jid":3,"./dataforms":29,"./iq":35,"./rsm":44,jxt:77,underscore:96}],32:[function(t,e){t("underscore");var n=t("jxt"),r=t("./util"),i=t("./message"),o=t("./presence"),a=t("./iq"),s="urn:ietf:params:xml:ns:xmpp-stanzas",u=["bad-request","conflict","feature-not-implemented","forbidden","gone","internal-server-error","item-not-found","jid-malformed","not-acceptable","not-allowed","not-authorized","payment-required","recipient-unavailable","redirect","registration-required","remote-server-not-found","remote-server-timeout","resource-constraint","service-unavailable","subscription-required","undefined-condition","unexpected-request"],c=e.exports=n.define({name:"error",namespace:"jabber:client",element:"error",fields:{lang:{get:function(){return(this.parent||{}).lang||""}},condition:{get:function(){var t=this,e=[];return u.forEach(function(r){var i=n.find(t.xml,s,r);i.length&&e.push(i[0].tagName)}),e[0]||""},set:function(t){var e=this;if(u.forEach(function(t){var r=n.find(e.xml,e._ERR_NS,t);r.length&&e.xml.removeChild(r[0])}),t){var r=document.createElementNS(this._ERR_NS,t);r.setAttribute("xmlns",this._ERR_NS),this.xml.appendChild(r)}}},gone:{get:function(){return n.getSubText(this.xml,s,"gone")},set:function(t){this.condition="gone",n.setSubText(this.xml,s,"gone",t)}},redirect:{get:function(){return n.getSubText(this.xml,s,"redirect")},set:function(t){this.condition="redirect",n.setSubText(this.xml,s,"redirect",t)}},code:n.attribute("code"),type:n.attribute("type"),by:r.jidAttribute("by"),$text:{get:function(){return n.getSubLangText(this.xml,s,"text",this.lang)}},text:{get:function(){var t=this.$text;return t[this.lang]||""},set:function(t){n.setSubLangText(this.xml,s,"text",t,this.lang)}}}});n.extend(i,c),n.extend(o,c),n.extend(a,c)},{"./iq":35,"./message":37,"./presence":39,"./util":52,jxt:77,underscore:96}],33:[function(t,e){var n=t("jxt"),r=t("./message"),i=t("./presence"),o=t("./iq"),a=t("./delayed"),s=e.exports=n.define({name:"forwarded",eventName:"forward",namespace:"urn:xmpp:forward:0",element:"forwarded"});n.extend(r,s),n.extend(s,r),n.extend(s,i),n.extend(s,o),n.extend(s,a)},{"./delayed":30,"./iq":35,"./message":37,"./presence":39,jxt:77}],34:[function(t,e){var n=t("jxt"),r=t("./util"),i=t("./presence"),o=e.exports=n.define({name:"idle",namespace:"urn:xmpp:idle:0",element:"idle",fields:{since:r.dateAttribute("since")}});n.extend(i,o)},{"./presence":39,"./util":52,jxt:77}],35:[function(t,e){var n=t("jxt"),r=t("./util"),i=e.exports=n.define({name:"iq",namespace:"jabber:client",element:"iq",topLevel:!0,fields:{lang:r.langAttribute(),id:n.attribute("id"),to:r.jidAttribute("to"),from:r.jidAttribute("from"),type:n.attribute("type")}}); -i.prototype.resultReply=function(t){return t.to=this.from,t.id=this.id,t.type="result",new i(t)},i.prototype.errorReply=function(t){return t.to=this.from,t.id=this.id,t.type="error",new i(t)}},{"./util":52,jxt:77}],36:[function(t,e,n){var r=t("jxt"),i=t("./util"),o=t("./message"),a=t("./iq"),s=t("./forwarded"),u=t("./rsm"),c=t("../jid");n.MAMQuery=r.define({name:"mamQuery",namespace:"urn:xmpp:mam:tmp",element:"query",fields:{queryid:r.attribute("queryid"),start:i.dateSub("urn:xmpp:mam:tmp","start"),end:i.dateSub("urn:xmpp:mam:tmp","end"),"with":i.jidSub("urn:xmpp:mam:tmp","with")}}),n.Result=r.define({name:"mam",eventName:"mam:result",namespace:"urn:xmpp:mam:tmp",element:"result",fields:{queryid:r.attribute("queryid"),id:r.attribute("id")}}),n.Archived=r.define({name:"mamArchived",namespace:"urn:xmpp:mam:tmp",element:"archived",fields:{by:i.jidAttribute("by"),id:r.attribute("id")}}),n.Prefs=r.define({name:"mamPrefs",namespace:"urn:xmpp:mam:tmp",element:"prefs",fields:{defaultCondition:r.attribute("default"),always:{get:function(){var t=[],e=r.find(this.xml,this._NS,"always");if(0===e.length)return t;e=e[0];var n=r.getMultiSubText(e,this._NS,"jid");return n.forEach(function(e){t.push(new c(e.textContent))}),t},set:function(t){if(t.length>0){var e=r.find(this.xml,this._NS,"always");r.setMultiSubText(e,this._NS,"jid",t)}}},never:{get:function(){var t=[],e=r.find(this.xml,this._NS,"always");if(0===e.length)return t;e=e[0];var n=r.getMultiSubText(e,this._NS,"jid");return n.forEach(function(e){t.push(new c(e.textContent))}),t},set:function(t){if(t.length>0){var e=r.find(this.xml,this._NS,"never");r.setMultiSubText(e,this._NS,"jid",t)}}}}}),r.extend(o,n.Archived,"archived"),r.extend(a,n.MAMQuery),r.extend(a,n.Prefs),r.extend(o,n.Result),r.extend(n.Result,s),r.extend(n.MAMQuery,u)},{"../jid":3,"./forwarded":33,"./iq":35,"./message":37,"./rsm":44,"./util":52,jxt:77}],37:[function(t,e){t("underscore");var n=t("jxt"),r=t("./util");e.exports=n.define({name:"message",namespace:"jabber:client",element:"message",topLevel:!0,fields:{lang:r.langAttribute(),id:n.attribute("id"),to:r.jidAttribute("to"),from:r.jidAttribute("from"),type:n.attribute("type","normal"),thread:n.subText("jabber:client","thread"),parentThread:n.subAttribute("jabber:client","thread","parent"),$body:{get:function(){return n.getSubLangText(this.xml,this._NS,"body",this.lang)}},body:{get:function(){var t=this.$body;return t[this.lang]||""},set:function(t){n.setSubLangText(this.xml,this._NS,"body",t,this.lang)}},attention:n.boolSub("urn:xmpp:attention:0","attention"),replace:n.subAttribute("urn:xmpp:message-correct:0","replace","id")}})},{"./util":52,jxt:77,underscore:96}],38:[function(t,e,n){var r=t("jxt");t("./message");var i=t("./presence");t("./iq");var o="http://jabber.org/protocol/muc";n.MUCJoin=r.define({name:"joinMuc",namespace:o,element:"x",fields:{password:r.subText(o,"password"),history:{get:function(){var t={},e=r.find(this.xml,this._NS,"history");if(!e.length)return{};e=e[0];var n=e.getAttribute("maxchars")||"",i=e.getAttribute("maxstanas")||"",o=e.getAttribute("seconds")||"",a=e.getAttribute("since")||"";n&&(t.maxchars=parseInt(n,10)),i&&(t.maxstanzas=parseInt(i,10)),o&&(t.seconds=parseInt(o,10)),a&&(t.since=new Date(a))},set:function(t){var e=r.find(this.xml,this._NS,"history");if(e.length)for(var n=0;nt&&(t=-t,i="+"),e=t/60,r=t%60,i+=(10>e?"0":"")+e+":"+(10>r?"0":"")+r):i=t,n.setSubText(this.xml,this._NS,"tzo",i)}}}});n.extend(i,o)},{"./iq":35,"./util":52,jxt:77}],52:[function(t,e,n){var r=t("jxt"),i=t("../jid"),o="http://www.w3.org/XML/1998/namespace";n.langAttribute=r.field(function(t){return t.getAttributeNS(o,"lang")||""},function(t,e){t.setAttributeNS(o,"lang",e)}),n.jidAttribute=r.field(function(t,e){return new i(r.getAttribute(t,e))},function(t,e,n){r.setAttribute(t,e,(n||"").toString())}),n.jidSub=r.field(function(t,e,n){return new i(r.getSubText(t,e,n))},function(t,e,n,i){r.setSubText(t,e,n,(i||"").toString())}),n.b64Text=r.field(function(t){return t.textContent&&"="!=t.textContent?atob(t.textContent):""},function(t,e){t.textContent=btoa(e)||"="}),n.dateAttribute=r.field(function(t,e){return new Date(r.getAttribute(t,e)||Date.now())},function(t,e,n){n&&r.setAttribute(t,e,n.toISOString())}),n.dateSub=r.field(function(t,e,n){return new Date(r.getSubText(t,e,n)||Date.now())},function(t,e,n,i){i&&r.setSubText(t,e,n,i.toISOString())}),n.numberAttribute=r.field(function(t,e,n){return parseInt(r.getAttribute(t,e,n),10)},function(t,e,n){r.setAttribute(t,e,n.toString())}),n.numberSub=r.field(function(t,e,n,i){return parseInt(r.getSubText(t,e,n,i),10)},function(t,e,n,i){r.setSubText(t,e,n,i.toString())})},{"../jid":3,jxt:77}],53:[function(t,e){var n=t("jxt"),r=t("./iq"),i="jabber:iq:version",o=e.exports=n.define({name:"version",namespace:i,element:"query",fields:{name:n.subText(i,"name"),version:n.subText(i,"version"),os:n.subText(i,"os")}});n.extend(r,o)},{"./iq":35,jxt:77}],54:[function(t){var e=t("jxt"),n=t("./iq");e.add(n,"visible",e.boolSub("urn:xmpp:invisible:0","visible")),e.add(n,"invisible",e.boolSub("urn:xmpp:invisible:0","invisible"))},{"./iq":35,jxt:77}],55:[function(t,e){function n(){function t(t){var e=[n.streamStart,t,n.streamEnd].join("");return e}function e(t){for(var e=n.parser.parseFromString(t,"application/xml").childNodes,r=0;r'].join(" "))}),n.on("raw:incoming",function(i){var o,s;if(i=i.trim(),i=i.replace(/^(\s*<\?.*\?>\s*)*/,""),""!==i){if(i.match(n.streamEnd))return n.disconnect();if(n.hasStream)try{o=new a({},e(t(i)))}catch(u){return n.disconnect()}else{var c=i.match(/^<(\S+:)?(\S+) /);n.streamStart=i,n.streamEnd="",s=!1;try{o=new a({},e(i+n.streamEnd))}catch(u){try{o=new a({},e(i)),s=!0}catch(f){return n.disconnect()}}n.hasStream=!0,n.stream=o,n.emit("stream:start",o)}r.each(o._extensions,function(t){t.lang||(t.lang=n.stream.lang),("message"===t._name||"presence"===t._name||"iq"===t._name)&&(n.sm.handle(t),n.emit("stanza",t)),n.emit(t._eventname||t._name,t),n.emit("stream:data",t),t.id&&n.emit("id:"+t.id,t)}),s&&n.emit("stream:end")}})}var r=t("underscore"),i=t("wildemitter"),o=t("async"),a=t("./stanza/stream");t("./stanza/message"),t("./stanza/presence"),t("./stanza/iq");var s=t("./sm");t("node-uuid"),n.prototype=Object.create(i.prototype,{constructor:{value:n}}),n.prototype.connect=function(t){var e=this;e.config=t,e.hasStream=!1,e.streamStart='',e.streamEnd="",e.parser=new DOMParser,e.serializer=new XMLSerializer,e.conn=new WebSocket(t.wsURL,"xmpp"),e.conn.onerror=function(t){return t.preventDefault(),e.emit("disconnected",e),!1},e.conn.onclose=function(){e.emit("disconnected",e)},e.conn.onopen=function(){e.sm.started=!1,e.emit("connected",e)},e.conn.onmessage=function(t){e.emit("raw:incoming",t.data)}},n.prototype.disconnect=function(){this.conn&&(this.hasStream&&(this.conn.send(""),this.emit("raw:outgoing",""),this.emit("stream:end")),this.hasStream=!1,this.conn.close(),this.stream=void 0,this.conn=void 0,this.sm.failed())},n.prototype.restart=function(){var t=this;t.hasStream=!1,t.send(["'].join(" "))},n.prototype.send=function(t){this.sendQueue.push(t)},e.exports=n},{"./sm":22,"./stanza/iq":35,"./stanza/message":37,"./stanza/presence":39,"./stanza/stream":48,async:56,"node-uuid":82,underscore:96,wildemitter:97}],56:[function(e,n){var r=e("__browserify_process");!function(){function e(t){var e=!1;return function(){if(e)throw new Error("Callback was already called.");e=!0,t.apply(i,arguments)}}var i,o,a={};i=this,null!=i&&(o=i.async),a.noConflict=function(){return i.async=o,a};var s=function(t,e){if(t.forEach)return t.forEach(e);for(var n=0;n=t.length&&r(null))}))})},a.forEach=a.each,a.eachSeries=function(t,e,n){if(n=n||function(){},!t.length)return n();var r=0,i=function(){e(t[r],function(e){e?(n(e),n=function(){}):(r+=1,r>=t.length?n(null):i())})};i()},a.forEachSeries=a.eachSeries,a.eachLimit=function(t,e,n,r){var i=l(e);i.apply(null,[t,n,r])},a.forEachLimit=a.eachLimit;var l=function(t){return function(e,n,r){if(r=r||function(){},!e.length||0>=t)return r();var i=0,o=0,a=0;!function s(){if(i>=e.length)return r();for(;t>a&&o=e.length?r():s())})}()}},p=function(t){return function(){var e=Array.prototype.slice.call(arguments);return t.apply(null,[a.each].concat(e))}},h=function(t,e){return function(){var n=Array.prototype.slice.call(arguments);return e.apply(null,[l(t)].concat(n))}},d=function(t){return function(){var e=Array.prototype.slice.call(arguments);return t.apply(null,[a.eachSeries].concat(e))}},m=function(t,e,n,r){var i=[];e=u(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n,r){i[t.index]=r,e(n)})},function(t){r(t,i)})};a.map=p(m),a.mapSeries=d(m),a.mapLimit=function(t,e,n,r){return g(e)(t,n,r)};var g=function(t){return h(t,m)};a.reduce=function(t,e,n,r){a.eachSeries(t,function(t,r){n(e,t,function(t,n){e=n,r(t)})},function(t){r(t,e)})},a.inject=a.reduce,a.foldl=a.reduce,a.reduceRight=function(t,e,n,r){var i=u(t,function(t){return t}).reverse();a.reduce(i,e,n,r)},a.foldr=a.reduceRight;var v=function(t,e,n,r){var i=[];e=u(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n){n&&i.push(t),e()})},function(){r(u(i.sort(function(t,e){return t.index-e.index}),function(t){return t.value}))})};a.filter=p(v),a.filterSeries=d(v),a.select=a.filter,a.selectSeries=a.filterSeries;var y=function(t,e,n,r){var i=[];e=u(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n){n||i.push(t),e()})},function(){r(u(i.sort(function(t,e){return t.index-e.index}),function(t){return t.value}))})};a.reject=p(y),a.rejectSeries=d(y);var b=function(t,e,n,r){t(e,function(t,e){n(t,function(n){n?(r(t),r=function(){}):e()})},function(){r()})};a.detect=p(b),a.detectSeries=d(b),a.some=function(t,e,n){a.each(t,function(t,r){e(t,function(t){t&&(n(!0),n=function(){}),r()})},function(){n(!1)})},a.any=a.some,a.every=function(t,e,n){a.each(t,function(t,r){e(t,function(t){t||(n(!1),n=function(){}),r()})},function(){n(!0)})},a.all=a.every,a.sortBy=function(t,e,n){a.map(t,function(t,n){e(t,function(e,r){e?n(e):n(null,{value:t,criteria:r})})},function(t,e){if(t)return n(t);var r=function(t,e){var n=t.criteria,r=e.criteria;return r>n?-1:n>r?1:0};n(null,u(e.sort(r),function(t){return t.value}))})},a.auto=function(t,e){e=e||function(){};var n=f(t);if(!n.length)return e(null);var r={},i=[],o=function(t){i.unshift(t)},u=function(t){for(var e=0;ee;e++)t[e].apply(null,arguments)}])))};return i.memo=n,i.unmemoized=t,i},a.unmemoize=function(t){return function(){return(t.unmemoized||t).apply(null,arguments)}},a.times=function(t,e,n){for(var r=[],i=0;t>i;i++)r.push(i);return a.map(r,e,n)},a.timesSeries=function(t,e,n){for(var r=[],i=0;t>i;i++)r.push(i);return a.mapSeries(r,e,n)},a.compose=function(){var t=Array.prototype.reverse.call(arguments);return function(){var e=this,n=Array.prototype.slice.call(arguments),r=n.pop();a.reduce(t,n,function(t,n,r){n.apply(e,t.concat([function(){var t=arguments[0],e=Array.prototype.slice.call(arguments,1);r(t,e)}]))},function(t,n){r.apply(e,[t].concat(n))})}};var E=function(t,e){var n=function(){var n=this,r=Array.prototype.slice.call(arguments),i=r.pop();return t(e,function(t,e){t.apply(n,r.concat([e]))},i)};if(arguments.length>2){var r=Array.prototype.slice.call(arguments,2);return n.apply(this,r)}return n};a.applyEach=p(E),a.applyEachSeries=d(E),a.forever=function(t,e){function n(r){if(r){if(e)return e(r);throw r}t(n)}n()},"undefined"!=typeof t&&t.amd?t([],function(){return a}):"undefined"!=typeof n&&n.exports?n.exports=a:i.async=a}()},{__browserify_process:69}],57:[function(t,e){function n(t){if(Object.keys)return Object.keys(t);var e=[];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.push(n);return e}function r(t,e){return void 0===e?""+e:"number"!=typeof e||!isNaN(e)&&isFinite(e)?"function"==typeof e||e instanceof RegExp?e.toString():e:e.toString()}function i(t,e){return"string"==typeof t?t.length=0;i--)if(o[i]!=a[i])return!1;for(i=o.length-1;i>=0;i--)if(r=o[i],!s(t[r],e[r]))return!1;return!0}function l(t,e){return t&&e?e instanceof RegExp?e.test(t):t instanceof e?!0:e.call({},t)===!0?!0:!1:!1}function p(t,e,n,r){var i;"string"==typeof n&&(r=n,n=null);try{e()}catch(a){i=a}if(r=(n&&n.name?" ("+n.name+").":".")+(r?" "+r:"."),t&&!i&&o("Missing expected exception"+r),!t&&l(i,n)&&o("Got unwanted exception"+r),t&&i&&n&&!l(i,n)||!t&&i)throw i}var h=t("util"),d=t("buffer").Buffer,m=Array.prototype.slice,g=e.exports=a;g.AssertionError=function(t){this.name="AssertionError",this.message=t.message,this.actual=t.actual,this.expected=t.expected,this.operator=t.operator;var e=t.stackStartFunction||o;Error.captureStackTrace&&Error.captureStackTrace(this,e)},h.inherits(g.AssertionError,Error),g.AssertionError.prototype.toString=function(){return this.message?[this.name+":",this.message].join(" "):[this.name+":",i(JSON.stringify(this.actual,r),128),this.operator,i(JSON.stringify(this.expected,r),128)].join(" ")},g.fail=o,g.ok=a,g.equal=function(t,e,n){t!=e&&o(t,e,n,"==",g.equal)},g.notEqual=function(t,e,n){t==e&&o(t,e,n,"!=",g.notEqual)},g.deepEqual=function(t,e,n){s(t,e)||o(t,e,n,"deepEqual",g.deepEqual)},g.notDeepEqual=function(t,e,n){s(t,e)&&o(t,e,n,"notDeepEqual",g.notDeepEqual)},g.strictEqual=function(t,e,n){t!==e&&o(t,e,n,"===",g.strictEqual)},g.notStrictEqual=function(t,e,n){t===e&&o(t,e,n,"!==",g.notStrictEqual)},g.throws=function(){p.apply(this,[!0].concat(m.call(arguments)))},g.doesNotThrow=function(){p.apply(this,[!1].concat(m.call(arguments)))},g.ifError=function(t){if(t)throw t}},{buffer:61,util:59}],58:[function(t,e,n){function r(t,e){if(t.indexOf)return t.indexOf(e);for(var n=0;ni;i++)r[i].apply(this,n);return!0}return!1},o.prototype.addListener=function(t,e){if("function"!=typeof e)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",t,e),this._events[t])if(a(this._events[t])){if(!this._events[t].warned){var n;n=void 0!==this._events.maxListeners?this._events.maxListeners:s,n&&n>0&&this._events[t].length>n&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),console.trace())}this._events[t].push(e)}else this._events[t]=[this._events[t],e];else this._events[t]=e;return this},o.prototype.on=o.prototype.addListener,o.prototype.once=function(t,e){var n=this;return n.on(t,function r(){n.removeListener(t,r),e.apply(this,arguments)}),this},o.prototype.removeListener=function(t,e){if("function"!=typeof e)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[t])return this;var n=this._events[t];if(a(n)){var i=r(n,e);if(0>i)return this;n.splice(i,1),0==n.length&&delete this._events[t]}else this._events[t]===e&&delete this._events[t];return this},o.prototype.removeAllListeners=function(t){return 0===arguments.length?(this._events={},this):(t&&this._events&&this._events[t]&&(this._events[t]=null),this)},o.prototype.listeners=function(t){return this._events||(this._events={}),this._events[t]||(this._events[t]=[]),a(this._events[t])||(this._events[t]=[this._events[t]]),this._events[t]},o.listenerCount=function(t,e){var n;return n=t._events&&t._events[e]?"function"==typeof t._events[e]?1:t._events[e].length:0}},{__browserify_process:69}],59:[function(t,e,n){function r(t){return Array.isArray(t)||"object"==typeof t&&"[object Array]"===Object.prototype.toString.call(t)}function i(t){"object"==typeof t&&"[object RegExp]"===Object.prototype.toString.call(t)}function o(t){return"object"==typeof t&&"[object Date]"===Object.prototype.toString.call(t)}t("events"),n.isArray=r,n.isDate=function(t){return"[object Date]"===Object.prototype.toString.call(t)},n.isRegExp=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},n.print=function(){},n.puts=function(){},n.debug=function(){},n.inspect=function(t,e,u,c){function f(t,u){if(t&&"function"==typeof t.inspect&&t!==n&&(!t.constructor||t.constructor.prototype!==t))return t.inspect(u);switch(typeof t){case"undefined":return p("undefined","undefined");case"string":var c="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return p(c,"string");case"number":return p(""+t,"number");case"boolean":return p(""+t,"boolean")}if(null===t)return p("null","null");var h=a(t),d=e?s(t):h;if("function"==typeof t&&0===d.length){if(i(t))return p(""+t,"regexp");var m=t.name?": "+t.name:"";return p("[Function"+m+"]","special")}if(o(t)&&0===d.length)return p(t.toUTCString(),"date");var g,v,y;if(r(t)?(v="Array",y=["[","]"]):(v="Object",y=["{","}"]),"function"==typeof t){var b=t.name?": "+t.name:"";g=i(t)?" "+t:" [Function"+b+"]"}else g="";if(o(t)&&(g=" "+t.toUTCString()),0===d.length)return y[0]+g+y[1];if(0>u)return i(t)?p(""+t,"regexp"):p("[Object]","special");l.push(t);var x=d.map(function(e){var n,i;if(t.__lookupGetter__&&(t.__lookupGetter__(e)?i=t.__lookupSetter__(e)?p("[Getter/Setter]","special"):p("[Getter]","special"):t.__lookupSetter__(e)&&(i=p("[Setter]","special"))),h.indexOf(e)<0&&(n="["+e+"]"),i||(l.indexOf(t[e])<0?(i=null===u?f(t[e]):f(t[e],u-1),i.indexOf("\n")>-1&&(i=r(t)?i.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+i.split("\n").map(function(t){return" "+t}).join("\n"))):i=p("[Circular]","special")),"undefined"==typeof n){if("Array"===v&&e.match(/^\d+$/))return i;n=JSON.stringify(""+e),n.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(n=n.substr(1,n.length-2),n=p(n,"name")):(n=n.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),n=p(n,"string"))}return n+": "+i});l.pop();var w=0,_=x.reduce(function(t,e){return w++,e.indexOf("\n")>=0&&w++,t+e.length+1},0);return x=_>50?y[0]+(""===g?"":g+"\n ")+" "+x.join(",\n ")+" "+y[1]:y[0]+g+" "+x.join(", ")+" "+y[1]}var l=[],p=function(t,e){var n={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},r={special:"cyan",number:"blue","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"}[e];return r?"["+n[r][0]+"m"+t+"["+n[r][1]+"m":t};return c||(p=function(t){return t}),f(t,"undefined"==typeof u?2:u)},n.log=function(){},n.pump=null;var a=Object.keys||function(t){var e=[];for(var n in t)e.push(n);return e},s=Object.getOwnPropertyNames||function(t){var e=[];for(var n in t)Object.hasOwnProperty.call(t,n)&&e.push(n);return e},u=Object.create||function(t,e){var n;if(null===t)n={__proto__:null};else{if("object"!=typeof t)throw new TypeError("typeof prototype["+typeof t+"] != 'object'");var r=function(){};r.prototype=t,n=new r,n.__proto__=t}return"undefined"!=typeof e&&Object.defineProperties&&Object.defineProperties(n,e),n};n.inherits=function(t,e){t.super_=e,t.prototype=u(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})};var c=/%[sdj%]/g;n.format=function(t){if("string"!=typeof t){for(var e=[],r=0;r=o)return t;switch(t){case"%s":return String(i[r++]);case"%d":return Number(i[r++]);case"%j":return JSON.stringify(i[r++]);default:return t}}),s=i[r];o>r;s=i[++r])a+=null===s||"object"!=typeof s?" "+s:" "+n.inspect(s);return a}},{events:58}],60:[function(t,e,n){n.readIEEE754=function(t,e,n,r,i){var o,a,s=8*i-r-1,u=(1<>1,f=-7,l=n?0:i-1,p=n?1:-1,h=t[e+l];for(l+=p,o=h&(1<<-f)-1,h>>=-f,f+=s;f>0;o=256*o+t[e+l],l+=p,f-=8);for(a=o&(1<<-f)-1,o>>=-f,f+=r;f>0;a=256*a+t[e+l],l+=p,f-=8);if(0===o)o=1-c;else{if(o===u)return a?0/0:1/0*(h?-1:1);a+=Math.pow(2,r),o-=c}return(h?-1:1)*a*Math.pow(2,o-r)},n.writeIEEE754=function(t,e,n,r,i,o){var a,s,u,c=8*o-i-1,f=(1<>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?o-1:0,d=r?-1:1,m=0>e||0===e&&0>1/e?1:0;for(e=Math.abs(e),isNaN(e)||1/0===e?(s=isNaN(e)?1:0,a=f):(a=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-a))<1&&(a--,u*=2),e+=a+l>=1?p/u:p*Math.pow(2,1-l),e*u>=2&&(a++,u/=2),a+l>=f?(s=0,a=f):a+l>=1?(s=(e*u-1)*Math.pow(2,i),a+=l):(s=e*Math.pow(2,l-1)*Math.pow(2,i),a=0));i>=8;t[n+h]=255&s,h+=d,s/=256,i-=8);for(a=a<0;t[n+h]=255&a,h+=d,a/=256,c-=8);t[n+h-d]|=128*m}},{}],61:[function(t,e,n){function r(t,e,n){if(!(this instanceof r))return new r(t,e,n);this.parent=this,this.offset=0;var o;if("number"==typeof n)this.length=i(e),this.offset=n;else{switch(o=typeof t){case"number":this.length=i(t);break;case"string":this.length=r.byteLength(t,e);break;case"object":this.length=i(t.length);break;default:throw new Error("First argument needs to be a number, array or string.")}if(a(t))for(var s=0;st?0:t}function o(t){return(Array.isArray||function(t){return"[object Array]"=={}.toString.apply(t)})(t)}function a(t){return o(t)||r.isBuffer(t)||t&&"object"==typeof t&&"number"==typeof t.length}function s(t){return 16>t?"0"+t.toString(16):t.toString(16)}function u(t){for(var e=[],n=0;ni&&!(i+n>=e.length||i>=t.length);)e[i+n]=t[i],i++;return i}function p(t){try{return decodeURIComponent(t)}catch(e){return String.fromCharCode(65533)}}function h(t,e,n,r){var i=0;return r||(I.ok("boolean"==typeof n,"missing or invalid endian"),I.ok(void 0!==e&&null!==e,"missing offset"),I.ok(e+1=t.length?0:(n?(i=t[e]<<8,e+1=t.length?0:(n?(e+1>>0):(e+2>>0)),i)}function m(t,e,n,r){var i,o;return r||(I.ok("boolean"==typeof n,"missing or invalid endian"),I.ok(void 0!==e&&null!==e,"missing offset"),I.ok(e+1=0,"specified a negative value for writing an unsigned value"),I.ok(e>=t,"value is larger than maximum value for type"),I.ok(Math.floor(t)===t,"value has a fractional component")}function x(t,e,n,r,i){i||(I.ok(void 0!==e&&null!==e,"missing value"),I.ok("boolean"==typeof r,"missing or invalid endian"),I.ok(void 0!==n&&null!==n,"missing offset"),I.ok(n+1>>8*(r?1-o:o)}function w(t,e,n,r,i){i||(I.ok(void 0!==e&&null!==e,"missing value"),I.ok("boolean"==typeof r,"missing or invalid endian"),I.ok(void 0!==n&&null!==n,"missing offset"),I.ok(n+3>>8*(r?3-o:o)}function _(t,e,n){I.ok("number"==typeof t,"cannot write a non-number as a number"),I.ok(e>=t,"value larger than maximum allowed value"),I.ok(t>=n,"value smaller than minimum allowed value"),I.ok(Math.floor(t)===t,"value has a fractional component")}function E(t,e,n){I.ok("number"==typeof t,"cannot write a non-number as a number"),I.ok(e>=t,"value larger than maximum allowed value"),I.ok(t>=n,"value smaller than minimum allowed value")}function S(t,e,n,r,i){i||(I.ok(void 0!==e&&null!==e,"missing value"),I.ok("boolean"==typeof r,"missing or invalid endian"),I.ok(void 0!==n&&null!==n,"missing offset"),I.ok(n+1=0?x(t,e,n,r,i):x(t,65535+e+1,n,r,i)}function j(t,e,n,r,i){i||(I.ok(void 0!==e&&null!==e,"missing value"),I.ok("boolean"==typeof r,"missing or invalid endian"),I.ok(void 0!==n&&null!==n,"missing offset"),I.ok(n+3=0?w(t,e,n,r,i):w(t,4294967295+e+1,n,r,i)}function k(e,n,r,i,o){o||(I.ok(void 0!==n&&null!==n,"missing value"),I.ok("boolean"==typeof i,"missing or invalid endian"),I.ok(void 0!==r&&null!==r,"missing offset"),I.ok(r+3t||t>=this.length)throw new Error("oob");return this[t]},r.prototype.set=function(t,e){if(0>t||t>=this.length)throw new Error("oob");return this[t]=e},r.byteLength=function(t,e){switch(e||"utf8"){case"hex":return t.length/2;case"utf8":case"utf-8":return u(t).length;case"ascii":case"binary":return t.length;case"base64":return f(t).length;default:throw new Error("Unknown encoding")}},r.prototype.utf8Write=function(t,e,n){return r._charsWritten=l(u(t),this,e,n)},r.prototype.asciiWrite=function(t,e,n){return r._charsWritten=l(c(t),this,e,n)},r.prototype.binaryWrite=r.prototype.asciiWrite,r.prototype.base64Write=function(t,e,n){return r._charsWritten=l(f(t),this,e,n)},r.prototype.base64Slice=function(){var e=Array.prototype.slice.apply(this,arguments);return t("base64-js").fromByteArray(e)},r.prototype.utf8Slice=function(){for(var t=Array.prototype.slice.apply(this,arguments),e="",n="",r=0;rr;r++)if(t[r]=s(this[r]),r==n.INSPECT_MAX_BYTES){t[r+1]="...";break}return""},r.prototype.hexSlice=function(t,e){var n=this.length;(!t||0>t)&&(t=0),(!e||0>e||e>n)&&(e=n);for(var r="",i=t;e>i;i++)r+=s(this[i]);return r},r.prototype.toString=function(t,e,n){if(t=String(t||"utf8").toLowerCase(),e=+e||0,"undefined"==typeof n&&(n=this.length),+n==e)return"";switch(t){case"hex":return this.hexSlice(e,n);case"utf8":case"utf-8":return this.utf8Slice(e,n);case"ascii":return this.asciiSlice(e,n);case"binary":return this.binarySlice(e,n);case"base64":return this.base64Slice(e,n);case"ucs2":case"ucs-2":return this.ucs2Slice(e,n);default:throw new Error("Unknown encoding")}},r.prototype.hexWrite=function(t,e,n){e=+e||0;var i=this.length-e;n?(n=+n,n>i&&(n=i)):n=i;var o=t.length;if(o%2)throw new Error("Invalid hex string");n>o/2&&(n=o/2);for(var a=0;n>a;a++){var s=parseInt(t.substr(2*a,2),16);if(isNaN(s))throw new Error("Invalid hex string");this[e+a]=s}return r._charsWritten=2*a,a},r.prototype.write=function(t,e,n,r){if(isFinite(e))isFinite(n)||(r=n,n=void 0);else{var i=r;r=e,e=n,n=i}e=+e||0;var o=this.length-e;switch(n?(n=+n,n>o&&(n=o)):n=o,r=String(r||"utf8").toLowerCase()){case"hex":return this.hexWrite(t,e,n);case"utf8":case"utf-8":return this.utf8Write(t,e,n);case"ascii":return this.asciiWrite(t,e,n);case"binary":return this.binaryWrite(t,e,n);case"base64":return this.base64Write(t,e,n);case"ucs2":case"ucs-2":return this.ucs2Write(t,e,n);default:throw new Error("Unknown encoding")}},r.prototype.slice=function(t,e){if(void 0===e&&(e=this.length),e>this.length)throw new Error("oob");if(t>e)throw new Error("oob");return new r(this,e-t,+t)},r.prototype.copy=function(t,e,n,r){var i=this;if(n||(n=0),(void 0===r||isNaN(r))&&(r=this.length),e||(e=0),n>r)throw new Error("sourceEnd < sourceStart");if(r===n)return 0;if(0==t.length||0==i.length)return 0;if(0>e||e>=t.length)throw new Error("targetStart out of bounds");if(0>n||n>=i.length)throw new Error("sourceStart out of bounds");if(0>r||r>i.length)throw new Error("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-ea;a++)I.ok("undefined"!=typeof this[a],"copying undefined buffer bytes!"),o.push(this[a]);for(var a=e;an)throw new Error("end < start");if(n===e)return 0;if(0==this.length)return 0;if(0>e||e>=this.length)throw new Error("start out of bounds");if(0>n||n>this.length)throw new Error("end out of bounds");for(var r=e;n>r;r++)this[r]=t},r.isBuffer=function(t){return t instanceof r||t instanceof r},r.concat=function(t,e){if(!o(t))throw new Error("Usage: Buffer.concat(list, [totalLength])\n list should be an Array.");if(0===t.length)return new r(0);if(1===t.length)return t[0];if("number"!=typeof e){e=0;for(var n=0;n=n.length?void 0:n[t]},r.prototype.readUInt16LE=function(t,e){return h(this,t,!1,e)},r.prototype.readUInt16BE=function(t,e){return h(this,t,!0,e)},r.prototype.readUInt32LE=function(t,e){return d(this,t,!1,e)},r.prototype.readUInt32BE=function(t,e){return d(this,t,!0,e)},r.prototype.readInt8=function(t,e){var n,r=this;return e||(I.ok(void 0!==t&&null!==t,"missing offset"),I.ok(t=r.length?void 0:(n=128&r[t],n?-1*(255-r[t]+1):r[t])},r.prototype.readInt16LE=function(t,e){return m(this,t,!1,e)},r.prototype.readInt16BE=function(t,e){return m(this,t,!0,e)},r.prototype.readInt32LE=function(t,e){return g(this,t,!1,e)},r.prototype.readInt32BE=function(t,e){return g(this,t,!0,e)},r.prototype.readFloatLE=function(t,e){return v(this,t,!1,e)},r.prototype.readFloatBE=function(t,e){return v(this,t,!0,e)},r.prototype.readDoubleLE=function(t,e){return y(this,t,!1,e)},r.prototype.readDoubleBE=function(t,e){return y(this,t,!0,e)},r.prototype.writeUInt8=function(t,e,n){var r=this;n||(I.ok(void 0!==t&&null!==t,"missing value"),I.ok(void 0!==e&&null!==e,"missing offset"),I.ok(e=0?r.writeUInt8(t,e,n):r.writeUInt8(255+t+1,e,n)},r.prototype.writeInt16LE=function(t,e,n){S(this,t,e,!1,n)},r.prototype.writeInt16BE=function(t,e,n){S(this,t,e,!0,n)},r.prototype.writeInt32LE=function(t,e,n){j(this,t,e,!1,n)},r.prototype.writeInt32BE=function(t,e,n){j(this,t,e,!0,n)},r.prototype.writeFloatLE=function(t,e,n){k(this,t,e,!1,n)},r.prototype.writeFloatBE=function(t,e,n){k(this,t,e,!0,n)},r.prototype.writeDoubleLE=function(t,e,n){A(this,t,e,!1,n)},r.prototype.writeDoubleBE=function(t,e,n){A(this,t,e,!0,n)}},{"./buffer_ieee754":60,assert:57,"base64-js":62}],62:[function(t,e){!function(){"use strict";function t(t){var e,n,i,o,a,s;if(t.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(a=t.indexOf("="),a=a>0?t.length-a:0,s=[],i=a>0?t.length-4:t.length,e=0,n=0;i>e;e+=4,n+=3)o=r.indexOf(t[e])<<18|r.indexOf(t[e+1])<<12|r.indexOf(t[e+2])<<6|r.indexOf(t[e+3]),s.push((16711680&o)>>16),s.push((65280&o)>>8),s.push(255&o);return 2===a?(o=r.indexOf(t[e])<<2|r.indexOf(t[e+1])>>4,s.push(255&o)):1===a&&(o=r.indexOf(t[e])<<10|r.indexOf(t[e+1])<<4|r.indexOf(t[e+2])>>2,s.push(255&o>>8),s.push(255&o)),s}function n(t){function e(t){return r[63&t>>18]+r[63&t>>12]+r[63&t>>6]+r[63&t]}var n,i,o,a=t.length%3,s="";for(n=0,o=t.length-a;o>n;n+=3)i=(t[n]<<16)+(t[n+1]<<8)+t[n+2],s+=e(i);switch(a){case 1:i=t[t.length-1],s+=r[i>>2],s+=r[63&i<<4],s+="==";break;case 2:i=(t[t.length-2]<<8)+t[t.length-1],s+=r[i>>10],s+=r[63&i>>4],s+=r[63&i<<2],s+="="}return s}var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";e.exports.toByteArray=t,e.exports.fromByteArray=n}()},{}],63:[function(t,e,n){function r(){var t=[].slice.call(arguments).join(" ");throw new Error([t,"we accept pull requests","http://github.com/dominictarr/crypto-browserify"].join("\n"))}function i(t,e){for(var n in t)e(t[n],n)}var o=t("buffer").Buffer,a=t("./sha"),s=t("./sha256"),u=t("./rng"),c=t("./md5"),f={sha1:{hex:a.hex_sha1,base64:a.b64_sha1,binary:a.str_sha1},sha256:{hex:s.hex_sha256,base64:s.b64_sha256,binary:s.str_sha256},md5:{hex:c.hex_md5,base64:c.b64_md5,binary:c.bin_md5}},l={sha1:{hex:a.hex_hmac_sha1,base64:a.b64_hmac_sha1,binary:a.str_hmac_sha1},sha256:{hex:s.hex_hmac_sha256,base64:s.b64_hmac_sha256,binary:s.str_hmac_sha256},md5:{hex:c.hex_hmac_md5,base64:c.b64_hmac_md5,binary:c.bin_hmac_md5}};n.createHash=function(t){t=t||"sha1",f[t]||r("algorithm:",t,"is not yet supported");var e="",n=f[t];return{update:function(t){return e+=t,this},digest:function(i){i=i||"binary";var o;(o=n[i])||r("encoding:",i,"is not yet supported for algorithm",t);var a=o(e);return e=null,a}}},n.createHmac=function(t,e){l[t]||r("algorithm:",t,"is not yet supported"),"string"!=typeof e&&(e=e.toString("binary"));var n="",i=l[t];return{update:function(t){return n+=t,this},digest:function(o){o=o||"binary";var a;(a=i[o])||r("encoding:",o,"is not yet support for algorithm",t);var s=a(e,n);return n=null,s}}},n.randomBytes=function(t,e){if(!e||!e.call)return new o(u(t));try{e.call(this,void 0,new o(u(t)))}catch(n){e(n)}},i(["createCredentials","createCipher","createCipheriv","createDecipher","createDecipheriv","createSign","createVerify","createDiffieHellman","pbkdf2"],function(t){n[t]=function(){r("sorry,",t,"is not implemented yet")}})},{"./md5":64,"./rng":65,"./sha":66,"./sha256":67,buffer:61}],64:[function(t,e,n){function r(t){return x(c(y(t),t.length*S))}function i(t){return w(c(y(t),t.length*S))}function o(t){return b(c(y(t),t.length*S))}function a(t,e){return x(m(t,e))}function s(t,e){return w(m(t,e))}function u(t,e){return b(m(t,e))}function c(t,e){t[e>>5]|=128<>>9<<4)+14]=e;for(var n=1732584193,r=-271733879,i=-1732584194,o=271733878,a=0;a16&&(n=c(n,t.length*S));for(var r=Array(16),i=Array(16),o=0;16>o;o++)r[o]=909522486^n[o],i[o]=1549556828^n[o];var a=c(r.concat(y(e)),512+e.length*S);return c(i.concat(a),640)}function g(t,e){var n=(65535&t)+(65535&e),r=(t>>16)+(e>>16)+(n>>16);return r<<16|65535&n}function v(t,e){return t<>>32-e}function y(t){for(var e=Array(),n=(1<>5]|=(t.charCodeAt(r/S)&n)<>5]>>>r%32&n);return e}function x(t){for(var e=_?"0123456789ABCDEF":"0123456789abcdef",n="",r=0;r<4*t.length;r++)n+=e.charAt(15&t[r>>2]>>8*(r%4)+4)+e.charAt(15&t[r>>2]>>8*(r%4));return n}function w(t){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n="",r=0;r<4*t.length;r+=3)for(var i=(255&t[r>>2]>>8*(r%4))<<16|(255&t[r+1>>2]>>8*((r+1)%4))<<8|255&t[r+2>>2]>>8*((r+2)%4),o=0;4>o;o++)n+=8*r+6*o>32*t.length?E:e.charAt(63&i>>6*(3-o));return n}var _=0,E="=",S=8;n.hex_md5=r,n.b64_md5=i,n.bin_md5=o,n.hex_hmac_md5=a,n.b64_hmac_md5=s,n.bin_hmac_md5=u},{}],65:[function(t,e){!function(){var t,n,r=this;if(t=function(t){for(var e,e,n=new Array(t),r=0;t>r;r++)0==(3&r)&&(e=4294967296*Math.random()),n[r]=255&e>>>((3&r)<<3);return n},r.crypto&&crypto.getRandomValues){var i=new Uint32Array(4);n=function(t){var e=new Array(t);crypto.getRandomValues(i);for(var n=0;t>n;n++)e[n]=255&i[n>>2]>>>8*(3&n);return e}}e.exports=n||t}()},{}],66:[function(t,e,n){function r(t){return v(c(m(t),t.length*w))}function i(t){return y(c(m(t),t.length*w))}function o(t){return g(c(m(t),t.length*w))}function a(t,e){return v(p(t,e))}function s(t,e){return y(p(t,e))}function u(t,e){return g(p(t,e))}function c(t,e){t[e>>5]|=128<<24-e%32,t[(e+64>>9<<4)+15]=e;for(var n=Array(80),r=1732584193,i=-271733879,o=-1732584194,a=271733878,s=-1009589776,u=0;uy;y++){n[y]=16>y?t[u+y]:d(n[y-3]^n[y-8]^n[y-14]^n[y-16],1);var b=h(h(d(r,5),f(y,i,o,a)),h(h(s,n[y]),l(y)));s=a,a=o,o=d(i,30),i=r,r=b}r=h(r,c),i=h(i,p),o=h(o,m),a=h(a,g),s=h(s,v)}return Array(r,i,o,a,s)}function f(t,e,n,r){return 20>t?e&n|~e&r:40>t?e^n^r:60>t?e&n|e&r|n&r:e^n^r}function l(t){return 20>t?1518500249:40>t?1859775393:60>t?-1894007588:-899497514}function p(t,e){var n=m(t);n.length>16&&(n=c(n,t.length*w));for(var r=Array(16),i=Array(16),o=0;16>o;o++)r[o]=909522486^n[o],i[o]=1549556828^n[o];var a=c(r.concat(m(e)),512+e.length*w);return c(i.concat(a),672)}function h(t,e){var n=(65535&t)+(65535&e),r=(t>>16)+(e>>16)+(n>>16);return r<<16|65535&n}function d(t,e){return t<>>32-e}function m(t){for(var e=Array(),n=(1<>5]|=(t.charCodeAt(r/w)&n)<<32-w-r%32;return e}function g(t){for(var e="",n=(1<>5]>>>32-w-r%32&n);return e}function v(t){for(var e=b?"0123456789ABCDEF":"0123456789abcdef",n="",r=0;r<4*t.length;r++)n+=e.charAt(15&t[r>>2]>>8*(3-r%4)+4)+e.charAt(15&t[r>>2]>>8*(3-r%4));return n}function y(t){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n="",r=0;r<4*t.length;r+=3)for(var i=(255&t[r>>2]>>8*(3-r%4))<<16|(255&t[r+1>>2]>>8*(3-(r+1)%4))<<8|255&t[r+2>>2]>>8*(3-(r+2)%4),o=0;4>o;o++)n+=8*r+6*o>32*t.length?x:e.charAt(63&i>>6*(3-o));return n}n.hex_sha1=r,n.b64_sha1=i,n.str_sha1=o,n.hex_hmac_sha1=a,n.b64_hmac_sha1=s,n.str_hmac_sha1=u;var b=0,x="=",w=8},{}],67:[function(t,e,n){function r(t){return E(w(_(t),t.length*l))}function i(t){return S(w(_(t),t.length*l))}function o(t){return c(w(_(t),t.length*l))}function a(t,e){return E(j(t,e))}function s(t,e){return S(j(t,e))}function u(t,e){return c(j(t,e))}function c(t){for(var e="",n=(1<>5]>>>32-l-r%32&n);return e}n.hex_sha256=r,n.b64_sha256=i,n.str_sha256=o,n.hex_hmac_sha256=a,n.b64_hmac_sha256=s,n.str_hmac_sha256=u;var f=0,l=8,p=function(t,e){var n=(65535&t)+(65535&e),r=(t>>16)+(e>>16)+(n>>16);return r<<16|65535&n},h=function(t,e){return t>>>e|t<<32-e},d=function(t,e){return t>>>e},m=function(t,e,n){return t&e^~t&n},g=function(t,e,n){return t&e^t&n^e&n},v=function(t){return h(t,2)^h(t,13)^h(t,22)},y=function(t){return h(t,6)^h(t,11)^h(t,25)},b=function(t){return h(t,7)^h(t,18)^d(t,3)},x=function(t){return h(t,17)^h(t,19)^d(t,10)},w=function(t,e){var n,r,i,o,a,s,u,c,f,l,h,d,w=new Array(1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298),_=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),E=new Array(64); -t[e>>5]|=128<<24-e%32,t[(e+64>>9<<4)+15]=e;for(var f=0;fl;l++)E[l]=16>l?t[l+f]:p(p(p(x(E[l-2]),E[l-7]),b(E[l-15])),E[l-16]),h=p(p(p(p(c,y(a)),m(a,s,u)),w[l]),E[l]),d=p(v(n),g(n,r,i)),c=u,u=s,s=a,a=p(o,h),o=i,i=r,r=n,n=p(h,d);_[0]=p(n,_[0]),_[1]=p(r,_[1]),_[2]=p(i,_[2]),_[3]=p(o,_[3]),_[4]=p(a,_[4]),_[5]=p(s,_[5]),_[6]=p(u,_[6]),_[7]=p(c,_[7])}return _},_=function(t){for(var e=Array(),n=(1<>5]|=(t.charCodeAt(r/l)&n)<<24-r%32;return e},E=function(t){for(var e=f?"0123456789ABCDEF":"0123456789abcdef",n="",r=0;r<4*t.length;r++)n+=e.charAt(15&t[r>>2]>>8*(3-r%4)+4)+e.charAt(15&t[r>>2]>>8*(3-r%4));return n},S=function(t){var e,n,r,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o="",a=4*t.length,s="=";for(e=0;a>e;e+=3)for(r=(255&t[e>>2]>>8*(3-e%4))<<16|(255&t[e+1>>2]>>8*(3-(e+1)%4))<<8|255&t[e+2>>2]>>8*(3-(e+2)%4),n=0;4>n;n+=1)o+=8*e+6*n<=32*t.length?i.charAt(63&r>>6*(3-n)):s;return o},j=function(t,e){var n=_(t);n.length>16&&(n=w(n,t.length*l));for(var r=Array(16),i=Array(16),o=0;16>o;o++)r[o]=909522486^n[o],i[o]=1549556828^n[o];var a=w(r.concat(_(e)),512+e.length*l);return w(i.concat(a),768)}},{}],68:[function(t,e){t=function(t,e,n,r){function i(r){if(!n[r]){if(!e[r]){if(t)return t(r);throw new Error("Cannot find module '"+r+"'")}var o=n[r]={exports:{}};e[r][0](function(t){var n=e[r][1][t];return i(n?n:t)},o,o.exports)}return n[r].exports}for(var o=0;o=0;i--)if(o[i]!=a[i])return!1;for(i=o.length-1;i>=0;i--)if(r=o[i],!s(t[r],e[r]))return!1;return!0}function l(t,e){return t&&e?e instanceof RegExp?e.test(t):t instanceof e?!0:e.call({},t)===!0?!0:!1:!1}function p(t,e,n,r){var i;"string"==typeof n&&(r=n,n=null);try{e()}catch(a){i=a}if(r=(n&&n.name?" ("+n.name+").":".")+(r?" "+r:"."),t&&!i&&o("Missing expected exception"+r),!t&&l(i,n)&&o("Got unwanted exception"+r),t&&i&&n&&!l(i,n)||!t&&i)throw i}var h=t("util"),d=t("buffer").Buffer,m=Array.prototype.slice,g=e.exports=a;g.AssertionError=function(t){this.name="AssertionError",this.message=t.message,this.actual=t.actual,this.expected=t.expected,this.operator=t.operator;var e=t.stackStartFunction||o;Error.captureStackTrace&&Error.captureStackTrace(this,e)},h.inherits(g.AssertionError,Error),g.AssertionError.prototype.toString=function(){return this.message?[this.name+":",this.message].join(" "):[this.name+":",i(JSON.stringify(this.actual,r),128),this.operator,i(JSON.stringify(this.expected,r),128)].join(" ")},g.AssertionError.__proto__=Error.prototype,g.fail=o,g.ok=a,g.equal=function(t,e,n){t!=e&&o(t,e,n,"==",g.equal)},g.notEqual=function(t,e,n){t==e&&o(t,e,n,"!=",g.notEqual)},g.deepEqual=function(t,e,n){s(t,e)||o(t,e,n,"deepEqual",g.deepEqual)},g.notDeepEqual=function(t,e,n){s(t,e)&&o(t,e,n,"notDeepEqual",g.notDeepEqual)},g.strictEqual=function(t,e,n){t!==e&&o(t,e,n,"===",g.strictEqual)},g.notStrictEqual=function(t,e,n){t===e&&o(t,e,n,"!==",g.notStrictEqual)},g.throws=function(){p.apply(this,[!0].concat(m.call(arguments)))},g.doesNotThrow=function(){p.apply(this,[!1].concat(m.call(arguments)))},g.ifError=function(t){if(t)throw t}},{util:2,buffer:3}],2:[function(t,e,n){function r(t){return t instanceof Array||Array.isArray(t)||t&&t!==Object.prototype&&r(t.__proto__)}function i(t){return t instanceof RegExp||"object"==typeof t&&"[object RegExp]"===Object.prototype.toString.call(t)}function o(t){if(t instanceof Date)return!0;if("object"!=typeof t)return!1;var e=Date.prototype&&s(Date.prototype),n=t.__proto__&&s(t.__proto__);return JSON.stringify(n)===JSON.stringify(e)}t("events"),n.isArray=r,n.isDate=function(t){return"[object Date]"===Object.prototype.toString.call(t)},n.isRegExp=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},n.print=function(){},n.puts=function(){},n.debug=function(){},n.inspect=function(t,e,u,c){function f(t,u){if(t&&"function"==typeof t.inspect&&t!==n&&(!t.constructor||t.constructor.prototype!==t))return t.inspect(u);switch(typeof t){case"undefined":return p("undefined","undefined");case"string":var c="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return p(c,"string");case"number":return p(""+t,"number");case"boolean":return p(""+t,"boolean")}if(null===t)return p("null","null");var h=a(t),d=e?s(t):h;if("function"==typeof t&&0===d.length){if(i(t))return p(""+t,"regexp");var m=t.name?": "+t.name:"";return p("[Function"+m+"]","special")}if(o(t)&&0===d.length)return p(t.toUTCString(),"date");var g,v,y;if(r(t)?(v="Array",y=["[","]"]):(v="Object",y=["{","}"]),"function"==typeof t){var b=t.name?": "+t.name:"";g=i(t)?" "+t:" [Function"+b+"]"}else g="";if(o(t)&&(g=" "+t.toUTCString()),0===d.length)return y[0]+g+y[1];if(0>u)return i(t)?p(""+t,"regexp"):p("[Object]","special");l.push(t);var x=d.map(function(e){var n,i;if(t.__lookupGetter__&&(t.__lookupGetter__(e)?i=t.__lookupSetter__(e)?p("[Getter/Setter]","special"):p("[Getter]","special"):t.__lookupSetter__(e)&&(i=p("[Setter]","special"))),h.indexOf(e)<0&&(n="["+e+"]"),i||(l.indexOf(t[e])<0?(i=null===u?f(t[e]):f(t[e],u-1),i.indexOf("\n")>-1&&(i=r(t)?i.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+i.split("\n").map(function(t){return" "+t}).join("\n"))):i=p("[Circular]","special")),"undefined"==typeof n){if("Array"===v&&e.match(/^\d+$/))return i;n=JSON.stringify(""+e),n.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(n=n.substr(1,n.length-2),n=p(n,"name")):(n=n.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),n=p(n,"string"))}return n+": "+i});l.pop();var w=0,_=x.reduce(function(t,e){return w++,e.indexOf("\n")>=0&&w++,t+e.length+1},0);return x=_>50?y[0]+(""===g?"":g+"\n ")+" "+x.join(",\n ")+" "+y[1]:y[0]+g+" "+x.join(", ")+" "+y[1]}var l=[],p=function(t,e){var n={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},r={special:"cyan",number:"blue","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"}[e];return r?"["+n[r][0]+"m"+t+"["+n[r][1]+"m":t};return c||(p=function(t){return t}),f(t,"undefined"==typeof u?2:u)},n.log=function(){},n.pump=null;var a=Object.keys||function(t){var e=[];for(var n in t)e.push(n);return e},s=Object.getOwnPropertyNames||function(t){var e=[];for(var n in t)Object.hasOwnProperty.call(t,n)&&e.push(n);return e},u=Object.create||function(t,e){var n;if(null===t)n={__proto__:null};else{if("object"!=typeof t)throw new TypeError("typeof prototype["+typeof t+"] != 'object'");var r=function(){};r.prototype=t,n=new r,n.__proto__=t}return"undefined"!=typeof e&&Object.defineProperties&&Object.defineProperties(n,e),n};n.inherits=function(t,e){t.super_=e,t.prototype=u(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})};var c=/%[sdj%]/g;n.format=function(t){if("string"!=typeof t){for(var e=[],r=0;r=o)return t;switch(t){case"%s":return String(i[r++]);case"%d":return Number(i[r++]);case"%j":return JSON.stringify(i[r++]);default:return t}}),s=i[r];o>r;s=i[++r])a+=null===s||"object"!=typeof s?" "+s:" "+n.inspect(s);return a}},{events:4}],5:[function(t,e,n){n.readIEEE754=function(t,e,n,r,i){var o,a,s=8*i-r-1,u=(1<>1,f=-7,l=n?0:i-1,p=n?1:-1,h=t[e+l];for(l+=p,o=h&(1<<-f)-1,h>>=-f,f+=s;f>0;o=256*o+t[e+l],l+=p,f-=8);for(a=o&(1<<-f)-1,o>>=-f,f+=r;f>0;a=256*a+t[e+l],l+=p,f-=8);if(0===o)o=1-c;else{if(o===u)return a?0/0:1/0*(h?-1:1);a+=Math.pow(2,r),o-=c}return(h?-1:1)*a*Math.pow(2,o-r)},n.writeIEEE754=function(t,e,n,r,i,o){var a,s,u,c=8*o-i-1,f=(1<>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?o-1:0,d=r?-1:1,m=0>e||0===e&&0>1/e?1:0;for(e=Math.abs(e),isNaN(e)||1/0===e?(s=isNaN(e)?1:0,a=f):(a=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-a))<1&&(a--,u*=2),e+=a+l>=1?p/u:p*Math.pow(2,1-l),e*u>=2&&(a++,u/=2),a+l>=f?(s=0,a=f):a+l>=1?(s=(e*u-1)*Math.pow(2,i),a+=l):(s=e*Math.pow(2,l-1)*Math.pow(2,i),a=0));i>=8;t[n+h]=255&s,h+=d,s/=256,i-=8);for(a=a<0;t[n+h]=255&a,h+=d,a/=256,c-=8);t[n+h-d]|=128*m}},{}],6:[function(t,e){var n=e.exports={};n.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var n=[];return window.addEventListener("message",function(t){if(t.source===window&&"process-tick"===t.data&&(t.stopPropagation(),n.length>0)){var e=n.shift();e()}},!0),function(t){n.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.binding=function(){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw new Error("process.chdir is not supported")}},{}],4:[function(t,e,n){!function(t){function e(t,e){if(t.indexOf)return t.indexOf(e);for(var n=0;no;o++)r[o].apply(this,n);return!0}return!1},r.prototype.addListener=function(t,e){if("function"!=typeof e)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",t,e),this._events[t])if(i(this._events[t])){if(!this._events[t].warned){var n;n=void 0!==this._events.maxListeners?this._events.maxListeners:o,n&&n>0&&this._events[t].length>n&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),console.trace())}this._events[t].push(e)}else this._events[t]=[this._events[t],e];else this._events[t]=e;return this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(t,e){var n=this;return n.on(t,function r(){n.removeListener(t,r),e.apply(this,arguments)}),this},r.prototype.removeListener=function(t,n){if("function"!=typeof n)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[t])return this;var r=this._events[t];if(i(r)){var o=e(r,n);if(0>o)return this;r.splice(o,1),0==r.length&&delete this._events[t]}else this._events[t]===n&&delete this._events[t];return this},r.prototype.removeAllListeners=function(t){return 0===arguments.length?(this._events={},this):(t&&this._events&&this._events[t]&&(this._events[t]=null),this)},r.prototype.listeners=function(t){return this._events||(this._events={}),this._events[t]||(this._events[t]=[]),i(this._events[t])||(this._events[t]=[this._events[t]]),this._events[t]}}(t("__browserify_process"))},{__browserify_process:6}],"buffer-browserify":[function(t,e){e.exports=t("q9TxCC")},{}],q9TxCC:[function(t,e,n){function r(t){this.length=t}function i(t){return 16>t?"0"+t.toString(16):t.toString(16)}function o(t){for(var e=[],n=0;ni&&!(i+n>=e.length||i>=t.length);)e[i+n]=t[i],i++;return i}function c(t){try{return decodeURIComponent(t)}catch(e){return String.fromCharCode(65533)}}function f(t){return t=~~Math.ceil(+t),0>t?0:t}function l(t,e,n){if(!(this instanceof l))return new l(t,e,n);var i;if("number"==typeof n)this.length=f(e),this.parent=t,this.offset=n;else{switch(i=typeof t){case"number":this.length=f(t);break;case"string":this.length=l.byteLength(t,e);break;case"object":this.length=f(t.length);break;default:throw new Error("First argument needs to be a number, array or string.")}if(this.length>l.poolSize?(this.parent=new r(this.length),this.offset=0):((!N||N.length-N.used=t.length?0:(n?(i=t.parent[t.offset+e]<<8,e+1=t.length?0:(n?(e+1>>0):(e+2>>0)),i)}function g(t,e,n,r){var i,o;return r||(C.ok("boolean"==typeof n,"missing or invalid endian"),C.ok(void 0!==e&&null!==e,"missing offset"),C.ok(e+1=0,"specified a negative value for writing an unsigned value"),C.ok(e>=t,"value is larger than maximum value for type"),C.ok(Math.floor(t)===t,"value has a fractional component")}function w(t,e,n,r,i){i||(C.ok(void 0!==e&&null!==e,"missing value"),C.ok("boolean"==typeof r,"missing or invalid endian"),C.ok(void 0!==n&&null!==n,"missing offset"),C.ok(n+1>>8*(r?1-o:o)}function _(t,e,n,r,i){i||(C.ok(void 0!==e&&null!==e,"missing value"),C.ok("boolean"==typeof r,"missing or invalid endian"),C.ok(void 0!==n&&null!==n,"missing offset"),C.ok(n+3>>8*(r?3-o:o)}function E(t,e,n){C.ok("number"==typeof t,"cannot write a non-number as a number"),C.ok(e>=t,"value larger than maximum allowed value"),C.ok(t>=n,"value smaller than minimum allowed value"),C.ok(Math.floor(t)===t,"value has a fractional component")}function S(t,e,n){C.ok("number"==typeof t,"cannot write a non-number as a number"),C.ok(e>=t,"value larger than maximum allowed value"),C.ok(t>=n,"value smaller than minimum allowed value")}function j(t,e,n,r,i){i||(C.ok(void 0!==e&&null!==e,"missing value"),C.ok("boolean"==typeof r,"missing or invalid endian"),C.ok(void 0!==n&&null!==n,"missing offset"),C.ok(n+1=0?w(t,e,n,r,i):w(t,65535+e+1,n,r,i)}function k(t,e,n,r,i){i||(C.ok(void 0!==e&&null!==e,"missing value"),C.ok("boolean"==typeof r,"missing or invalid endian"),C.ok(void 0!==n&&null!==n,"missing offset"),C.ok(n+3=0?_(t,e,n,r,i):_(t,4294967295+e+1,n,r,i)}function A(e,n,r,i,o){o||(C.ok(void 0!==n&&null!==n,"missing value"),C.ok("boolean"==typeof i,"missing or invalid endian"),C.ok(void 0!==r&&null!==r,"missing offset"),C.ok(r+3r;r++)if(t[r]=i(this[r]),r==n.INSPECT_MAX_BYTES){t[r+1]="...";break}return""},r.prototype.hexSlice=function(t,e){var n=this.length;(!t||0>t)&&(t=0),(!e||0>e||e>n)&&(e=n);for(var r="",o=t;e>o;o++)r+=i(this[o]);return r},r.prototype.toString=function(t,e,n){if(t=String(t||"utf8").toLowerCase(),e=+e||0,"undefined"==typeof n&&(n=this.length),+n==e)return"";switch(t){case"hex":return this.hexSlice(e,n);case"utf8":case"utf-8":return this.utf8Slice(e,n);case"ascii":return this.asciiSlice(e,n);case"binary":return this.binarySlice(e,n);case"base64":return this.base64Slice(e,n);case"ucs2":case"ucs-2":return this.ucs2Slice(e,n);default:throw new Error("Unknown encoding")}},r.prototype.hexWrite=function(t,e,n){e=+e||0;var i=this.length-e;n?(n=+n,n>i&&(n=i)):n=i;var o=t.length;if(o%2)throw new Error("Invalid hex string");n>o/2&&(n=o/2);for(var a=0;n>a;a++){var s=parseInt(t.substr(2*a,2),16);if(isNaN(s))throw new Error("Invalid hex string");this[e+a]=s}return r._charsWritten=2*a,a},r.prototype.write=function(t,e,n,r){if(isFinite(e))isFinite(n)||(r=n,n=void 0);else{var i=r;r=e,e=n,n=i}e=+e||0;var o=this.length-e;switch(n?(n=+n,n>o&&(n=o)):n=o,r=String(r||"utf8").toLowerCase()){case"hex":return this.hexWrite(t,e,n);case"utf8":case"utf-8":return this.utf8Write(t,e,n);case"ascii":return this.asciiWrite(t,e,n);case"binary":return this.binaryWrite(t,e,n);case"base64":return this.base64Write(t,e,n);case"ucs2":case"ucs-2":return this.ucs2Write(t,e,n);default:throw new Error("Unknown encoding")}},r.prototype.slice=function(t,e){if(void 0===e&&(e=this.length),e>this.length)throw new Error("oob");if(t>e)throw new Error("oob");return new l(this,e-t,+t)},r.prototype.copy=function(t,e,n,r){for(var i=[],o=n;r>o;o++)C.ok("undefined"!=typeof this[o],"copying undefined buffer bytes!"),i.push(this[o]);for(var o=e;othis.length)throw new Error("oob");if(e>n)throw new Error("oob");for(var r=e;n>r;r++)this[r]=t},n.SlowBuffer=r,n.Buffer=l,l.poolSize=8192;var N;l.isBuffer=function(t){return t instanceof l||t instanceof r},l.concat=function(t,e){if(!Array.isArray(t))throw new Error("Usage: Buffer.concat(list, [totalLength])\n list should be an Array.");if(0===t.length)return new l(0);if(1===t.length)return t[0];if("number"!=typeof e){e=0;for(var n=0;nr;r++)if(t[r]=i(this.parent[r+this.offset]),r==n.INSPECT_MAX_BYTES){t[r+1]="...";break}return""},l.prototype.get=function(t){if(0>t||t>=this.length)throw new Error("oob");return this.parent[this.offset+t]},l.prototype.set=function(t,e){if(0>t||t>=this.length)throw new Error("oob");return this.parent[this.offset+t]=e},l.prototype.write=function(t,e,n,i){if(isFinite(e))isFinite(n)||(i=n,n=void 0);else{var o=i;i=e,e=n,n=o}e=+e||0;var a=this.length-e;n?(n=+n,n>a&&(n=a)):n=a,i=String(i||"utf8").toLowerCase();var s;switch(i){case"hex":s=this.parent.hexWrite(t,this.offset+e,n);break;case"utf8":case"utf-8":s=this.parent.utf8Write(t,this.offset+e,n);break;case"ascii":s=this.parent.asciiWrite(t,this.offset+e,n);break;case"binary":s=this.parent.binaryWrite(t,this.offset+e,n);break;case"base64":s=this.parent.base64Write(t,this.offset+e,n);break;case"ucs2":case"ucs-2":s=this.parent.ucs2Write(t,this.offset+e,n);break;default:throw new Error("Unknown encoding")}return l._charsWritten=r._charsWritten,s},l.prototype.toString=function(t,e,n){switch(t=String(t||"utf8").toLowerCase(),"undefined"==typeof e||0>e?e=0:e>this.length&&(e=this.length),"undefined"==typeof n||n>this.length?n=this.length:0>n&&(n=0),e+=this.offset,n+=this.offset,t){case"hex":return this.parent.hexSlice(e,n);case"utf8":case"utf-8":return this.parent.utf8Slice(e,n);case"ascii":return this.parent.asciiSlice(e,n);case"binary":return this.parent.binarySlice(e,n);case"base64":return this.parent.base64Slice(e,n);case"ucs2":case"ucs-2":return this.parent.ucs2Slice(e,n);default:throw new Error("Unknown encoding")}},l.byteLength=r.byteLength,l.prototype.fill=function(t,e,n){if(t||(t=0),e||(e=0),n||(n=this.length),"string"==typeof t&&(t=t.charCodeAt(0)),"number"!=typeof t||isNaN(t))throw new Error("value is not a number");if(e>n)throw new Error("end < start");if(n===e)return 0;if(0==this.length)return 0;if(0>e||e>=this.length)throw new Error("start out of bounds");if(0>n||n>this.length)throw new Error("end out of bounds");return this.parent.fill(t,e+this.offset,n+this.offset)},l.prototype.copy=function(t,e,n,r){var i=this;if(n||(n=0),r||(r=this.length),e||(e=0),n>r)throw new Error("sourceEnd < sourceStart");if(r===n)return 0;if(0==t.length||0==i.length)return 0;if(0>e||e>=t.length)throw new Error("targetStart out of bounds");if(0>n||n>=i.length)throw new Error("sourceStart out of bounds");if(0>r||r>i.length)throw new Error("sourceEnd out of bounds");return r>this.length&&(r=this.length),t.length-ethis.length)throw new Error("oob");if(t>e)throw new Error("oob");return new l(this.parent,e-t,+t+this.offset)},l.prototype.utf8Slice=function(t,e){return this.toString("utf8",t,e)},l.prototype.binarySlice=function(t,e){return this.toString("binary",t,e)},l.prototype.asciiSlice=function(t,e){return this.toString("ascii",t,e)},l.prototype.utf8Write=function(t,e){return this.write(t,e,"utf8")},l.prototype.binaryWrite=function(t,e){return this.write(t,e,"binary")},l.prototype.asciiWrite=function(t,e){return this.write(t,e,"ascii")},l.prototype.readUInt8=function(t,e){var n=this;return e||(C.ok(void 0!==t&&null!==t,"missing offset"),C.ok(t=n.length?void 0:n.parent[n.offset+t]},l.prototype.readUInt16LE=function(t,e){return d(this,t,!1,e)},l.prototype.readUInt16BE=function(t,e){return d(this,t,!0,e)},l.prototype.readUInt32LE=function(t,e){return m(this,t,!1,e)},l.prototype.readUInt32BE=function(t,e){return m(this,t,!0,e)},l.prototype.readInt8=function(t,e){var n,r=this;return e||(C.ok(void 0!==t&&null!==t,"missing offset"),C.ok(t=r.length?void 0:(n=128&r.parent[r.offset+t],n?-1*(255-r.parent[r.offset+t]+1):r.parent[r.offset+t])},l.prototype.readInt16LE=function(t,e){return g(this,t,!1,e)},l.prototype.readInt16BE=function(t,e){return g(this,t,!0,e)},l.prototype.readInt32LE=function(t,e){return v(this,t,!1,e)},l.prototype.readInt32BE=function(t,e){return v(this,t,!0,e)},l.prototype.readFloatLE=function(t,e){return y(this,t,!1,e)},l.prototype.readFloatBE=function(t,e){return y(this,t,!0,e)},l.prototype.readDoubleLE=function(t,e){return b(this,t,!1,e)},l.prototype.readDoubleBE=function(t,e){return b(this,t,!0,e)},l.prototype.writeUInt8=function(t,e,n){var r=this;n||(C.ok(void 0!==t&&null!==t,"missing value"),C.ok(void 0!==e&&null!==e,"missing offset"),C.ok(e=0?r.writeUInt8(t,e,n):r.writeUInt8(255+t+1,e,n)},l.prototype.writeInt16LE=function(t,e,n){j(this,t,e,!1,n)},l.prototype.writeInt16BE=function(t,e,n){j(this,t,e,!0,n)},l.prototype.writeInt32LE=function(t,e,n){k(this,t,e,!1,n)},l.prototype.writeInt32BE=function(t,e,n){k(this,t,e,!0,n)},l.prototype.writeFloatLE=function(t,e,n){A(this,t,e,!1,n)},l.prototype.writeFloatBE=function(t,e,n){A(this,t,e,!0,n)},l.prototype.writeDoubleLE=function(t,e,n){I(this,t,e,!1,n)},l.prototype.writeDoubleBE=function(t,e,n){I(this,t,e,!0,n)},r.prototype.readUInt8=l.prototype.readUInt8,r.prototype.readUInt16LE=l.prototype.readUInt16LE,r.prototype.readUInt16BE=l.prototype.readUInt16BE,r.prototype.readUInt32LE=l.prototype.readUInt32LE,r.prototype.readUInt32BE=l.prototype.readUInt32BE,r.prototype.readInt8=l.prototype.readInt8,r.prototype.readInt16LE=l.prototype.readInt16LE,r.prototype.readInt16BE=l.prototype.readInt16BE,r.prototype.readInt32LE=l.prototype.readInt32LE,r.prototype.readInt32BE=l.prototype.readInt32BE,r.prototype.readFloatLE=l.prototype.readFloatLE,r.prototype.readFloatBE=l.prototype.readFloatBE,r.prototype.readDoubleLE=l.prototype.readDoubleLE,r.prototype.readDoubleBE=l.prototype.readDoubleBE,r.prototype.writeUInt8=l.prototype.writeUInt8,r.prototype.writeUInt16LE=l.prototype.writeUInt16LE,r.prototype.writeUInt16BE=l.prototype.writeUInt16BE,r.prototype.writeUInt32LE=l.prototype.writeUInt32LE,r.prototype.writeUInt32BE=l.prototype.writeUInt32BE,r.prototype.writeInt8=l.prototype.writeInt8,r.prototype.writeInt16LE=l.prototype.writeInt16LE,r.prototype.writeInt16BE=l.prototype.writeInt16BE,r.prototype.writeInt32LE=l.prototype.writeInt32LE,r.prototype.writeInt32BE=l.prototype.writeInt32BE,r.prototype.writeFloatLE=l.prototype.writeFloatLE,r.prototype.writeFloatBE=l.prototype.writeFloatBE,r.prototype.writeDoubleLE=l.prototype.writeDoubleLE,r.prototype.writeDoubleBE=l.prototype.writeDoubleBE},{assert:1,"./buffer_ieee754":5,"base64-js":7}],7:[function(t,e){!function(){"use strict";function t(t){var e,n,i,o,a,s;if(t.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(a=t.indexOf("="),a=a>0?t.length-a:0,s=[],i=a>0?t.length-4:t.length,e=0,n=0;i>e;e+=4,n+=3)o=r.indexOf(t[e])<<18|r.indexOf(t[e+1])<<12|r.indexOf(t[e+2])<<6|r.indexOf(t[e+3]),s.push((16711680&o)>>16),s.push((65280&o)>>8),s.push(255&o);return 2===a?(o=r.indexOf(t[e])<<2|r.indexOf(t[e+1])>>4,s.push(255&o)):1===a&&(o=r.indexOf(t[e])<<10|r.indexOf(t[e+1])<<4|r.indexOf(t[e+2])>>2,s.push(255&o>>8),s.push(255&o)),s}function n(t){function e(t){return r[63&t>>18]+r[63&t>>12]+r[63&t>>6]+r[63&t]}var n,i,o,a=t.length%3,s="";for(n=0,o=t.length-a;o>n;n+=3)i=(t[n]<<16)+(t[n+1]<<8)+t[n+2],s+=e(i);switch(a){case 1:i=t[t.length-1],s+=r[i>>2],s+=r[63&i<<4],s+="==";break;case 2:i=(t[t.length-2]<<8)+t[t.length-1],s+=r[i>>10],s+=r[63&i>>4],s+=r[63&i<<2],s+="="}return s}var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";e.exports.toByteArray=t,e.exports.fromByteArray=n}()},{}],8:[function(t,e,n){n.readIEEE754=function(t,e,n,r,i){var o,a,s=8*i-r-1,u=(1<>1,f=-7,l=n?0:i-1,p=n?1:-1,h=t[e+l];for(l+=p,o=h&(1<<-f)-1,h>>=-f,f+=s;f>0;o=256*o+t[e+l],l+=p,f-=8);for(a=o&(1<<-f)-1,o>>=-f,f+=r;f>0;a=256*a+t[e+l],l+=p,f-=8);if(0===o)o=1-c;else{if(o===u)return a?0/0:1/0*(h?-1:1);a+=Math.pow(2,r),o-=c}return(h?-1:1)*a*Math.pow(2,o-r)},n.writeIEEE754=function(t,e,n,r,i,o){var a,s,u,c=8*o-i-1,f=(1<>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?o-1:0,d=r?-1:1,m=0>e||0===e&&0>1/e?1:0;for(e=Math.abs(e),isNaN(e)||1/0===e?(s=isNaN(e)?1:0,a=f):(a=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-a))<1&&(a--,u*=2),e+=a+l>=1?p/u:p*Math.pow(2,1-l),e*u>=2&&(a++,u/=2),a+l>=f?(s=0,a=f):a+l>=1?(s=(e*u-1)*Math.pow(2,i),a+=l):(s=e*Math.pow(2,l-1)*Math.pow(2,i),a=0));i>=8;t[n+h]=255&s,h+=d,s/=256,i-=8);for(a=a<0;t[n+h]=255&a,h+=d,a/=256,c-=8);t[n+h-d]|=128*m}},{}],3:[function(t,e,n){function r(t){this.length=t}function i(t){return 16>t?"0"+t.toString(16):t.toString(16)}function o(t){for(var e=[],n=0;ni&&!(i+n>=e.length||i>=t.length);)e[i+n]=t[i],i++;return i}function c(t){try{return decodeURIComponent(t)}catch(e){return String.fromCharCode(65533)}}function f(t){return t=~~Math.ceil(+t),0>t?0:t}function l(t,e,n){if(!(this instanceof l))return new l(t,e,n);var i;if("number"==typeof n)this.length=f(e),this.parent=t,this.offset=n;else{switch(i=typeof t){case"number":this.length=f(t);break;case"string":this.length=l.byteLength(t,e);break;case"object":this.length=f(t.length);break;default:throw new Error("First argument needs to be a number, array or string.")}if(this.length>l.poolSize?(this.parent=new r(this.length),this.offset=0):((!N||N.length-N.used>>0):(i=t.parent[t.offset+e+2]<<16,i|=t.parent[t.offset+e+1]<<8,i|=t.parent[t.offset+e],i+=t.parent[t.offset+e+3]<<24>>>0),i}function g(t,e,n,r){var i,o;return r||(C.ok("boolean"==typeof n,"missing or invalid endian"),C.ok(void 0!==e&&null!==e,"missing offset"),C.ok(e+1=0,"specified a negative value for writing an unsigned value"),C.ok(e>=t,"value is larger than maximum value for type"),C.ok(Math.floor(t)===t,"value has a fractional component")}function w(t,e,n,r,i){i||(C.ok(void 0!==e&&null!==e,"missing value"),C.ok("boolean"==typeof r,"missing or invalid endian"),C.ok(void 0!==n&&null!==n,"missing offset"),C.ok(n+1>>8,t.parent[t.offset+n+1]=255&e):(t.parent[t.offset+n+1]=(65280&e)>>>8,t.parent[t.offset+n]=255&e)}function _(t,e,n,r,i){i||(C.ok(void 0!==e&&null!==e,"missing value"),C.ok("boolean"==typeof r,"missing or invalid endian"),C.ok(void 0!==n&&null!==n,"missing offset"),C.ok(n+3>>24,t.parent[t.offset+n+1]=255&e>>>16,t.parent[t.offset+n+2]=255&e>>>8,t.parent[t.offset+n+3]=255&e):(t.parent[t.offset+n+3]=255&e>>>24,t.parent[t.offset+n+2]=255&e>>>16,t.parent[t.offset+n+1]=255&e>>>8,t.parent[t.offset+n]=255&e)}function E(t,e,n){C.ok("number"==typeof t,"cannot write a non-number as a number"),C.ok(e>=t,"value larger than maximum allowed value"),C.ok(t>=n,"value smaller than minimum allowed value"),C.ok(Math.floor(t)===t,"value has a fractional component")}function S(t,e,n){C.ok("number"==typeof t,"cannot write a non-number as a number"),C.ok(e>=t,"value larger than maximum allowed value"),C.ok(t>=n,"value smaller than minimum allowed value")}function j(t,e,n,r,i){i||(C.ok(void 0!==e&&null!==e,"missing value"),C.ok("boolean"==typeof r,"missing or invalid endian"),C.ok(void 0!==n&&null!==n,"missing offset"),C.ok(n+1=0?w(t,e,n,r,i):w(t,65535+e+1,n,r,i)}function k(t,e,n,r,i){i||(C.ok(void 0!==e&&null!==e,"missing value"),C.ok("boolean"==typeof r,"missing or invalid endian"),C.ok(void 0!==n&&null!==n,"missing offset"),C.ok(n+3=0?_(t,e,n,r,i):_(t,4294967295+e+1,n,r,i)}function A(e,n,r,i,o){o||(C.ok(void 0!==n&&null!==n,"missing value"),C.ok("boolean"==typeof i,"missing or invalid endian"),C.ok(void 0!==r&&null!==r,"missing offset"),C.ok(r+3r;r++)if(t[r]=i(this[r]),r==n.INSPECT_MAX_BYTES){t[r+1]="...";break}return""},r.prototype.hexSlice=function(t,e){var n=this.length;(!t||0>t)&&(t=0),(!e||0>e||e>n)&&(e=n);for(var r="",o=t;e>o;o++)r+=i(this[o]);return r},r.prototype.toString=function(t,e,n){if(t=String(t||"utf8").toLowerCase(),e=+e||0,"undefined"==typeof n&&(n=this.length),+n==e)return"";switch(t){case"hex":return this.hexSlice(e,n);case"utf8":case"utf-8":return this.utf8Slice(e,n);case"ascii":return this.asciiSlice(e,n);case"binary":return this.binarySlice(e,n);case"base64":return this.base64Slice(e,n);case"ucs2":case"ucs-2":return this.ucs2Slice(e,n);default:throw new Error("Unknown encoding")}},r.prototype.hexWrite=function(t,e,n){e=+e||0;var i=this.length-e;n?(n=+n,n>i&&(n=i)):n=i;var o=t.length;if(o%2)throw new Error("Invalid hex string");n>o/2&&(n=o/2);for(var a=0;n>a;a++){var s=parseInt(t.substr(2*a,2),16);if(isNaN(s))throw new Error("Invalid hex string");this[e+a]=s}return r._charsWritten=2*a,a},r.prototype.write=function(t,e,n,r){if(isFinite(e))isFinite(n)||(r=n,n=void 0);else{var i=r;r=e,e=n,n=i}e=+e||0;var o=this.length-e;switch(n?(n=+n,n>o&&(n=o)):n=o,r=String(r||"utf8").toLowerCase()){case"hex":return this.hexWrite(t,e,n);case"utf8":case"utf-8":return this.utf8Write(t,e,n);case"ascii":return this.asciiWrite(t,e,n);case"binary":return this.binaryWrite(t,e,n);case"base64":return this.base64Write(t,e,n);case"ucs2":case"ucs-2":return this.ucs2Write(t,e,n);default:throw new Error("Unknown encoding")}},r.prototype.slice=function(t,e){if(void 0===e&&(e=this.length),e>this.length)throw new Error("oob");if(t>e)throw new Error("oob");return new l(this,e-t,+t)},r.prototype.copy=function(t,e,n,r){for(var i=[],o=n;r>o;o++)C.ok("undefined"!=typeof this[o],"copying undefined buffer bytes!"),i.push(this[o]);for(var o=e;or;r++)if(t[r]=i(this.parent[r+this.offset]),r==n.INSPECT_MAX_BYTES){t[r+1]="...";break}return""},l.prototype.get=function(t){if(0>t||t>=this.length)throw new Error("oob");return this.parent[this.offset+t]},l.prototype.set=function(t,e){if(0>t||t>=this.length)throw new Error("oob");return this.parent[this.offset+t]=e},l.prototype.write=function(t,e,n,i){if(isFinite(e))isFinite(n)||(i=n,n=void 0);else{var o=i;i=e,e=n,n=o}e=+e||0;var a=this.length-e;n?(n=+n,n>a&&(n=a)):n=a,i=String(i||"utf8").toLowerCase();var s;switch(i){case"hex":s=this.parent.hexWrite(t,this.offset+e,n);break;case"utf8":case"utf-8":s=this.parent.utf8Write(t,this.offset+e,n);break;case"ascii":s=this.parent.asciiWrite(t,this.offset+e,n);break;case"binary":s=this.parent.binaryWrite(t,this.offset+e,n);break;case"base64":s=this.parent.base64Write(t,this.offset+e,n);break;case"ucs2":case"ucs-2":s=this.parent.ucs2Write(t,this.offset+e,n);break;default:throw new Error("Unknown encoding")}return l._charsWritten=r._charsWritten,s},l.prototype.toString=function(t,e,n){switch(t=String(t||"utf8").toLowerCase(),"undefined"==typeof e||0>e?e=0:e>this.length&&(e=this.length),"undefined"==typeof n||n>this.length?n=this.length:0>n&&(n=0),e+=this.offset,n+=this.offset,t){case"hex":return this.parent.hexSlice(e,n);case"utf8":case"utf-8":return this.parent.utf8Slice(e,n);case"ascii":return this.parent.asciiSlice(e,n);case"binary":return this.parent.binarySlice(e,n);case"base64":return this.parent.base64Slice(e,n);case"ucs2":case"ucs-2":return this.parent.ucs2Slice(e,n);default:throw new Error("Unknown encoding")}},l.byteLength=r.byteLength,l.prototype.fill=function(t,e,n){if(t||(t=0),e||(e=0),n||(n=this.length),"string"==typeof t&&(t=t.charCodeAt(0)),"number"!=typeof t||isNaN(t))throw new Error("value is not a number");if(e>n)throw new Error("end < start");if(n===e)return 0;if(0==this.length)return 0;if(0>e||e>=this.length)throw new Error("start out of bounds");if(0>n||n>this.length)throw new Error("end out of bounds");return this.parent.fill(t,e+this.offset,n+this.offset)},l.prototype.copy=function(t,e,n,r){var i=this;if(n||(n=0),r||(r=this.length),e||(e=0),n>r)throw new Error("sourceEnd < sourceStart");if(r===n)return 0;if(0==t.length||0==i.length)return 0;if(0>e||e>=t.length)throw new Error("targetStart out of bounds");if(0>n||n>=i.length)throw new Error("sourceStart out of bounds");if(0>r||r>i.length)throw new Error("sourceEnd out of bounds");return r>this.length&&(r=this.length),t.length-ethis.length)throw new Error("oob");if(t>e)throw new Error("oob");return new l(this.parent,e-t,+t+this.offset)},l.prototype.utf8Slice=function(t,e){return this.toString("utf8",t,e)},l.prototype.binarySlice=function(t,e){return this.toString("binary",t,e)},l.prototype.asciiSlice=function(t,e){return this.toString("ascii",t,e)},l.prototype.utf8Write=function(t,e){return this.write(t,e,"utf8")},l.prototype.binaryWrite=function(t,e){return this.write(t,e,"binary")},l.prototype.asciiWrite=function(t,e){return this.write(t,e,"ascii")},l.prototype.readUInt8=function(t,e){var n=this;return e||(C.ok(void 0!==t&&null!==t,"missing offset"),C.ok(t=0?r.writeUInt8(t,e,n):r.writeUInt8(255+t+1,e,n)},l.prototype.writeInt16LE=function(t,e,n){j(this,t,e,!1,n)},l.prototype.writeInt16BE=function(t,e,n){j(this,t,e,!0,n)},l.prototype.writeInt32LE=function(t,e,n){k(this,t,e,!1,n)},l.prototype.writeInt32BE=function(t,e,n){k(this,t,e,!0,n)},l.prototype.writeFloatLE=function(t,e,n){A(this,t,e,!1,n)},l.prototype.writeFloatBE=function(t,e,n){A(this,t,e,!0,n)},l.prototype.writeDoubleLE=function(t,e,n){I(this,t,e,!1,n)},l.prototype.writeDoubleBE=function(t,e,n){I(this,t,e,!0,n)},r.prototype.readUInt8=l.prototype.readUInt8,r.prototype.readUInt16LE=l.prototype.readUInt16LE,r.prototype.readUInt16BE=l.prototype.readUInt16BE,r.prototype.readUInt32LE=l.prototype.readUInt32LE,r.prototype.readUInt32BE=l.prototype.readUInt32BE,r.prototype.readInt8=l.prototype.readInt8,r.prototype.readInt16LE=l.prototype.readInt16LE,r.prototype.readInt16BE=l.prototype.readInt16BE,r.prototype.readInt32LE=l.prototype.readInt32LE,r.prototype.readInt32BE=l.prototype.readInt32BE,r.prototype.readFloatLE=l.prototype.readFloatLE,r.prototype.readFloatBE=l.prototype.readFloatBE,r.prototype.readDoubleLE=l.prototype.readDoubleLE,r.prototype.readDoubleBE=l.prototype.readDoubleBE,r.prototype.writeUInt8=l.prototype.writeUInt8,r.prototype.writeUInt16LE=l.prototype.writeUInt16LE,r.prototype.writeUInt16BE=l.prototype.writeUInt16BE,r.prototype.writeUInt32LE=l.prototype.writeUInt32LE,r.prototype.writeUInt32BE=l.prototype.writeUInt32BE,r.prototype.writeInt8=l.prototype.writeInt8,r.prototype.writeInt16LE=l.prototype.writeInt16LE,r.prototype.writeInt16BE=l.prototype.writeInt16BE,r.prototype.writeInt32LE=l.prototype.writeInt32LE,r.prototype.writeInt32BE=l.prototype.writeInt32BE,r.prototype.writeFloatLE=l.prototype.writeFloatLE,r.prototype.writeFloatBE=l.prototype.writeFloatBE,r.prototype.writeDoubleLE=l.prototype.writeDoubleLE,r.prototype.writeDoubleBE=l.prototype.writeDoubleBE},{assert:1,"./buffer_ieee754":8,"base64-js":9}],9:[function(t,e){!function(){"use strict";function t(t){var e,n,i,o,a,s;if(t.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(a=t.indexOf("="),a=a>0?t.length-a:0,s=[],i=a>0?t.length-4:t.length,e=0,n=0;i>e;e+=4,n+=3)o=r.indexOf(t[e])<<18|r.indexOf(t[e+1])<<12|r.indexOf(t[e+2])<<6|r.indexOf(t[e+3]),s.push((16711680&o)>>16),s.push((65280&o)>>8),s.push(255&o);return 2===a?(o=r.indexOf(t[e])<<2|r.indexOf(t[e+1])>>4,s.push(255&o)):1===a&&(o=r.indexOf(t[e])<<10|r.indexOf(t[e+1])<<4|r.indexOf(t[e+2])>>2,s.push(255&o>>8),s.push(255&o)),s}function n(t){function e(t){return r[63&t>>18]+r[63&t>>12]+r[63&t>>6]+r[63&t]}var n,i,o,a=t.length%3,s="";for(n=0,o=t.length-a;o>n;n+=3)i=(t[n]<<16)+(t[n+1]<<8)+t[n+2],s+=e(i);switch(a){case 1:i=t[t.length-1],s+=r[i>>2],s+=r[63&i<<4],s+="==";break;case 2:i=(t[t.length-2]<<8)+t[t.length-1],s+=r[i>>10],s+=r[63&i>>4],s+=r[63&i<<2],s+="="}return s}var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";e.exports.toByteArray=t,e.exports.fromByteArray=n}()},{}]},{},[]),e.exports=t("buffer-browserify")},{}],69:[function(t,e){var n=e.exports={};n.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var n=[];return window.addEventListener("message",function(t){if(t.source===window&&"process-tick"===t.data&&(t.stopPropagation(),n.length>0)){var e=n.shift();e()}},!0),function(t){n.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.binding=function(){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw new Error("process.chdir is not supported")}},{}],70:[function(t,e){function n(t,e){return o.init(this,e,t)}var r=t("./vendor/lodash"),i=t("async"),o=t("jxt"),a=t("xhr"),s=new DOMParser;n.prototype={constructor:{value:n},NS:"http://docs.oasis-open.org/ns/xri/xrd-1.0",EL:"XRD",toString:o.toString,toJSON:o.toJSON,get subject(){return o.getSubText(this.xml,this.NS,"Subject")},get expires(){return new Date(o.getSubText(this.xml,this.NS,"Expires"))},get aliases(){return o.getMultiSubText(this.xml,this.NS,"Alias")},get properties(){var t={},e=o.find(this.xml,this.NS,"Property");return r.each(e,function(e){var n=o.getAttribute(e,"type");t[n]=e.textContent}),t},get links(){var t=[],e=o.find(this.xml,this.NS,"Link");return r.each(e,function(e){var n={rel:o.getAttribute(e,"rel"),href:o.getAttribute(e,"href"),type:o.getAttribute(e,"type"),template:o.getAttribute(e,"template"),titles:o.getSubLangText(e,this.NS,"Title","default"),properties:{}},i=o.find(e,this.NS,"Property");r.each(i,function(t){var e=o.getAttribute(t,"type");n.properties[e]=t.textContent}),t.push(n)}),t}},e.exports=function(t,e){"string"==typeof t&&(t={host:t}),t=r.extend({ssl:!0,json:!0},t);var o=t.ssl?"https://":"http://";i.parallel({json:function(e){return t.json?(a({uri:o+t.host+"/.well-known/host-meta.json"},function(t,n,r){if(t)return e();try{e("completed",JSON.parse(r))}catch(i){e(null,{})}}),void 0):e(null,{})},xrd:function(e){a({uri:o+t.host+"/.well-known/host-meta"},function(t,r){if(t)return e(null,{});try{var i=s.parseFromString(r.body,"application/xml").childNodes[0],o=new n({},i);e("completed",o.toJSON())}catch(a){e(null,{})}})}},function(t,n){if(t){if(Object.keys(n.json).length)return e(!1,n.json);if(Object.keys(n.xrd).length)return e(!1,n.xrd)}e("no-host-meta",{})})}},{"./vendor/lodash":76,async:56,jxt:71,xhr:73}],71:[function(t,e,n){var r=t("./vendor/lodash"),i=new XMLSerializer,o="http://www.w3.org/XML/1998/namespace",a={},s={},u={},c=n.find=function(t,e,n){var i=t.querySelectorAll(n);return r.filter(i,function(n){return n.namespaceURI===e&&n.parentNode==t})};n.findOrCreate=function(t,e,n){var r=c(t,e,n);if(r.length)return r[0];var i=document.createElementNS(e,n);return t.appendChild(i),i},n.init=function(t,e,n){return t.xml=e||document.createElementNS(t.NS,t.EL),t.xml.parentNode&&t.xml.parentNode.namespaceURI===t.NS||t.xml.setAttribute("xmlns",t.NS),t._extensions={},r.each(t.xml.childNodes,function(e){var n=e.namespaceURI+"|"+e.localName,r=s[n];if(void 0!==r){var i=r.prototype._name;t._extensions[i]=new r(null,e),t._extensions[i].parent=t}}),r.extend(t,n),t},n.getSubText=function(t,e,n){var r=c(t,e,n);if(!r)return"";for(var i=0;i=0?Object.keys(r).length>0&&(e[t]=r):i.indexOf("Array")>=0?r.length>0&&(e[t]=r):r&&(e[t]=r)}return e},n.extend=function(t,e){var i=t.prototype.NS+"|"+t.prototype.EL,o=e.prototype._name,a=e.prototype.NS+"|"+e.prototype.EL;s[a]=e,u[a]||(u[a]={}),u[i]||(u[i]={}),u[i][o]=e,t.prototype.__defineGetter__(o,function(){if(!this._extensions[o]){var t=n.find(this.xml,e.prototype.NS,e.prototype.EL);t.length?this._extensions[o]=new e(null,t[0]):(this._extensions[o]=new e,this.xml.appendChild(this._extensions[o].xml)),this._extensions[o].parent=this}return this._extensions[o]}),t.prototype.__defineSetter__(o,function(t){var e=this[o];r.extend(e,t)})},n.topLevel=function(t){var e=t.prototype.NS+"|"+t.prototype.EL;s[e]=t,a[e]=t},n.build=function(t){var e=a[t.namespaceURI+"|"+t.localName];return e?new e(null,t):void 0},n.XML_NS=o,n.TOP_LEVEL_LOOKUP=a,n.LOOKUP_EXT=u,n.LOOKUP=s},{"./vendor/lodash":72}],72:[function(e,n,r){var i=self;!function(e){function o(t){return"function"!=typeof t.toString&&"string"==typeof(t+"")}function a(t){t.length=0,y.lengthk;k++)r+="m='"+t.g[k]+"';if((!(p&&v[m])&&l.call(r,m))",t.i||(r+="||(!v[m]&&r[m]!==y[m])"),r+="){"+t.f+"}";r+="}"}return(t.b||Y.nonEnumArgs)&&(r+="}"),r+=t.c+";return C",e=e("i,j,l,n,o,q,t,u,y,z,w,G,H,J",n+r+"}"),s(t),e(C,U,D,f,Z,d,ee,u,z,q,K,T,R,J)}function f(t){return J.call(t)==S}function l(t,e,n,r,i,s){var c=n===x;if("function"==typeof n&&!c){n=u.createCallback(n,r,2);var h=n(t,e);if("undefined"!=typeof h)return!!h}if(t===e)return 0!==t||1/t==1/e;var d=typeof t,m=typeof e;if(t===t&&(!t||"function"!=d&&"object"!=d)&&(!e||"function"!=m&&"object"!=m))return!1;if(null==t||null==e)return t===e;if(m=J.call(t),d=J.call(e),m==S&&(m=O),d==S&&(d=O),m!=d)return!1;switch(m){case A:case I:return+t==+e;case N:return t!=+t?e!=+e:0==t?1/t==1/e:t==+e;case L:case T:return t==e+""}if(d=m==j,!d){if(D.call(t,"__wrapped__")||D.call(e,"__wrapped__"))return l(t.__wrapped__||t,e.__wrapped__||e,n,r,i,s);if(m!=O||!Y.nodeClass&&(o(t)||o(e)))return!1;var m=!Y.argsObject&&f(t)?Object:t.constructor,g=!Y.argsObject&&f(e)?Object:e.constructor;if(!(m==g||p(m)&&m instanceof m&&p(g)&&g instanceof g))return!1}for(g=!i,i||(i=y.pop()||[]),s||(s=y.pop()||[]),m=i.length;m--;)if(i[m]==t)return s[m]==e;var v=0,h=!0;if(i.push(t),s.push(e),d){if(m=t.length,v=e.length,h=v==t.length,!h&&!c)return h;for(;v--;)if(d=m,g=e[v],c)for(;d--&&!(h=l(t[d],g,n,r,i,s)););else if(!(h=l(t[v],g,n,r,i,s)))break;return h}return re(e,function(e,o,a){return D.call(a,o)?(v++,h=D.call(t,o)&&l(t[o],e,n,r,i,s)):void 0}),h&&!c&&re(t,function(t,e,n){return D.call(n,e)?h=-1<--v:void 0}),g&&(a(i),a(s)),h}function p(t){return"function"==typeof t}function h(t){return!(!t||!q[typeof t])}function d(t){return"string"==typeof t||J.call(t)==T}function m(t,e,n){var r=[];if(e=u.createCallback(e,n),Z(t)){n=-1;for(var i=t.length;++n3&&typeof a[c-2]=='function'){var d=u.createCallback(a[--c-1],a[c--],2)}else if(c>2&&typeof a[c-1]=='function'){d=a[--c]}"),f:"C[m]=d?d(C[m],r[m]):r[m]"}),re=c($,F,{i:!1});p(/x/)&&(p=function(t){return"function"==typeof t&&"[object Function]"==J.call(t)}),u.assign=X,u.createCallback=function(t,e,n){if(null==t)return v;var r=typeof t;if("function"!=r){if("object"!=r)return function(e){return e[t]};var i=ee(t);return function(e){for(var n=i.length,r=!1;n--&&(r=l(e[i[n]],t[i[n]],x)););return r}}return"undefined"==typeof e||_&&!_.test(P.call(t))?t:1===n?function(n){return t.call(e,n)}:2===n?function(n,r){return t.call(e,n,r)}:4===n?function(n,r,i,o){return t.call(e,n,r,i,o)}:function(n,r,i){return t.call(e,n,r,i)}},u.filter=m,u.forEach=g,u.forIn=re,u.keys=ee,u.each=g,u.extend=X,u.select=m,u.identity=v,u.isArguments=f,u.isArray=Z,u.isEqual=l,u.isFunction=p,u.isObject=h,u.isString=d,u.VERSION="1.3.1","function"==typeof t&&"object"==typeof t.amd&&t.amd?(e._=u,t(function(){return u})):B&&!B.nodeType?M?(M.exports=u)._=u:B._=u:e._=u}(this)},{}],73:[function(t,e){function n(t,e){function n(){4===f.readyState&&i()}function i(){var t=null,n=f.statusCode=f.status,r=f.body=f.response||f.responseText||f.responseXML;if(0===n||n>=400&&600>n){var i=f.responseText||a[String(f.status).charAt(0)];t=new Error(i),t.statusCode=f.status}if(m)try{r=f.body=JSON.parse(r)}catch(o){}e(t,f,r)}function c(t){e(t,f)}"string"==typeof t&&(t={uri:t}),t=t||{},e=o(e);var f;t.cors?(f=new u,f.withCredentials=!0):f=new s;var l=f.url=t.uri,p=f.method=t.method||"GET",h=t.body||t.data,d=f.headers=t.headers||{},m=!1;return"json"in t&&(m=!0,d["Content-Type"]="application/json",h=JSON.stringify(t.json)),f.onreadystatechange=n,f.onload=i,f.onerror=c,f.onprogress=function(){},f.ontimeout=r,f.open(p,l),f.timeout="timeout"in t?t.timeout:5e3,f.setRequestHeader&&Object.keys(d).forEach(function(t){f.setRequestHeader(t,d[t])}),f.send(h),f}function r(){}var i=t("global/window"),o=t("once"),a={0:"Internal XMLHttpRequest Error",4:"4xx Client Error",5:"5xx Server Error"},s=i.XMLHttpRequest||r,u="withCredentials"in new s?i.XMLHttpRequest:i.XDomainRequest; -e.exports=n},{"global/window":74,once:75}],74:[function(t,e){var n=self;e.exports="undefined"!=typeof window?window:"undefined"!=typeof n?n:{}},{}],75:[function(t,e){function n(t){var e=!1;return function(){return e?void 0:(e=!0,t.apply(this,arguments))}}e.exports=n,n.proto=n(function(){Object.defineProperty(Function.prototype,"once",{value:function(){return n(this)},configurable:!0})})},{}],76:[function(e,n,r){var i=self;!function(e){function o(t){return"function"!=typeof t.toString&&"string"==typeof(t+"")}function a(t){t.length=0,v.lengthk;k++)r+="m='"+t.g[k]+"';if((!(p&&v[m])&&l.call(r,m))",t.i||(r+="||(!v[m]&&r[m]!==y[m])"),r+="){"+t.f+"}";r+="}"}return(t.b||K.nonEnumArgs)&&(r+="}"),r+=t.c+";return C",e=e("i,j,l,n,o,q,t,u,y,z,w,G,H,J",n+r+"}"),s(t),e(I,F,P,f,Q,d,te,u,U,T,V,L,z,W)}function f(t){return W.call(t)==E}function l(t,e,n,r,i,s){var c=n===b;if("function"==typeof n&&!c){n=u.createCallback(n,r,2);var h=n(t,e);if("undefined"!=typeof h)return!!h}if(t===e)return 0!==t||1/t==1/e;var d=typeof t,m=typeof e;if(t===t&&(!t||"function"!=d&&"object"!=d)&&(!e||"function"!=m&&"object"!=m))return!1;if(null==t||null==e)return t===e;if(m=W.call(t),d=W.call(e),m==E&&(m=N),d==E&&(d=N),m!=d)return!1;switch(m){case j:case A:return+t==+e;case C:return t!=+t?e!=+e:0==t?1/t==1/e:t==+e;case O:case L:return t==e+""}if(d=m==S,!d){if(P.call(t,"__wrapped__")||P.call(e,"__wrapped__"))return l(t.__wrapped__||t,e.__wrapped__||e,n,r,i,s);if(m!=N||!K.nodeClass&&(o(t)||o(e)))return!1;var m=!K.argsObject&&f(t)?Object:t.constructor,g=!K.argsObject&&f(e)?Object:e.constructor;if(!(m==g||p(m)&&m instanceof m&&p(g)&&g instanceof g))return!1}for(g=!i,i||(i=v.pop()||[]),s||(s=v.pop()||[]),m=i.length;m--;)if(i[m]==t)return s[m]==e;var y=0,h=!0;if(i.push(t),s.push(e),d){if(m=t.length,y=e.length,h=y==t.length,!h&&!c)return h;for(;y--;)if(d=m,g=e[y],c)for(;d--&&!(h=l(t[d],g,n,r,i,s)););else if(!(h=l(t[y],g,n,r,i,s)))break;return h}return ne(e,function(e,o,a){return P.call(a,o)?(y++,h=P.call(t,o)&&l(t[o],e,n,r,i,s)):void 0}),h&&!c&&ne(t,function(t,e,n){return P.call(n,e)?h=-1<--y:void 0}),g&&(a(i),a(s)),h}function p(t){return"function"==typeof t}function h(t){return!(!t||!T[typeof t])}function d(t){return"string"==typeof t||W.call(t)==L}function m(t,e,n){if(e&&"undefined"==typeof n&&Q(t)){n=-1;for(var r=t.length;++n3&&typeof a[c-2]=='function'){var d=u.createCallback(a[--c-1],a[c--],2)}else if(c>2&&typeof a[c-1]=='function'){d=a[--c]}"),f:"C[m]=d?d(C[m],r[m]):r[m]"}),ne=c(G,M,{i:!1});p(/x/)&&(p=function(t){return"function"==typeof t&&"[object Function]"==W.call(t)}),u.assign=$,u.createCallback=function(t,e,n){if(null==t)return g;var r=typeof t;if("function"!=r){if("object"!=r)return function(e){return e[t]};var i=te(t);return function(e){for(var n=i.length,r=!1;n--&&(r=l(e[i[n]],t[i[n]],b)););return r}}return"undefined"==typeof e||w&&!w.test(R.call(t))?t:1===n?function(n){return t.call(e,n)}:2===n?function(n,r){return t.call(e,n,r)}:4===n?function(n,r,i,o){return t.call(e,n,r,i,o)}:function(n,r,i){return t.call(e,n,r,i)}},u.forEach=m,u.forIn=ne,u.keys=te,u.each=m,u.extend=$,u.identity=g,u.isArguments=f,u.isArray=Q,u.isEqual=l,u.isFunction=p,u.isObject=h,u.isString=d,u.VERSION="1.3.1","function"==typeof t&&"object"==typeof t.amd&&t.amd?(e._=u,t(function(){return u})):q&&!q.nodeType?B?(B.exports=u)._=u:q._=u:e._=u}(this)},{}],77:[function(t,e){"use strict";var n=t("lodash"),r=t("./lib/core"),i=t("./lib/helpers"),o=t("./lib/types");e.exports=n.extend({},r,i,o)},{"./lib/core":78,"./lib/helpers":79,"./lib/types":80,lodash:81}],78:[function(t,e,n){"use strict";function r(t){var e=t.prototype._NS+"|"+t.prototype._EL;c[e]=t,l[e]=t}function i(t){return u.serializeToString(t)}function o(t){var e,n={},r={constructor:!0,_EL:!0,_NS:!0,_extensions:!0,_name:!0,parent:!0,prototype:!0,toJSON:!0,toString:!0,xml:!0};for(e in t._extensions)t._extensions[e].toJSON&&(n[e]=t._extensions[e].toJSON());for(e in t)if(!r[e]&&!(f[t._NS+"|"+t._EL]||{})[e]&&!t._extensions[e]&&"_"!==e[0]){var i=t[e];if("function"==typeof i)continue;var o=Object.prototype.toString.call(i);o.indexOf("Object")>=0?Object.keys(i).length>0&&(n[e]=i):o.indexOf("Array")>=0?i.length>0&&(n[e]=i):i&&(n[e]=i)}return n}var a=t("underscore");t("./helpers").find;var s=t("./types"),u=new XMLSerializer,c={},f={},l={};n.build=function(t){var e=l[t.namespaceURI+"|"+t.localName];return e?new e(null,t):void 0},n.extend=function(t,e,r){var i=t.prototype._NS+"|"+t.prototype._EL,o=e.prototype._name,a=e.prototype._NS+"|"+e.prototype._EL;c[a]=e,f[a]||(f[a]={}),f[i]||(f[i]={}),f[i][o]=e,n.add(t,o,s.extension(e)),r&&n.add(t,r,s.multiExtension(e))},n.add=function(t,e,n){n.get&&t.prototype.__defineGetter__(e,n.get),n.set&&t.prototype.__defineSetter__(e,n.set)},n.define=function(t){var e=function(e,n){var r=this;return r.xml=n||document.createElementNS(r._NS,r._EL),r.xml.parentNode&&r.xml.parentNode.namespaceURI===r._NS||r.xml.setAttribute("xmlns",r._NS),r._extensions={},a.each(r.xml.childNodes,function(t){var e=t.namespaceURI+"|"+t.localName,n=c[e];if(void 0!==n){var i=n.prototype._name;r._extensions[i]=new n(null,t),r._extensions[i].parent=r}}),a.extend(r,e),t.init&&t.init(e),r};e.prototype={constructor:{value:e},_name:t.name,_eventname:t.eventName,_NS:t.namespace,_EL:t.element,toString:function(){return i(this.xml)},toJSON:function(){return o(this)}};var s=Object.keys(t.fields||{});return s.forEach(function(r){n.add(e,r,t.fields[r])}),t.topLevel&&r(e),e}},{"./helpers":79,"./types":80,underscore:96}],79:[function(t,e,n){"use strict";var r=t("underscore"),i="http://www.w3.org/XML/1998/namespace";n.getParser=function(){return new DOMParser},n.createElement=function(t,e,r){var i=document.createElementNS(t,e);return r&&r!==t&&n.setAttribute(i,"xmlns",t),i};var o=n.find=function(t,e,n){var i=t.querySelectorAll(n);return r.filter(i,function(n){return n.namespaceURI===e&&n.parentNode==t})};n.findOrCreate=function(t,e,r){var i=n.find(t,e,r);if(i.length)return i[0];var o=n.createElement(e,r,t.namespaceURI);return t.appendChild(o),o},n.getAttribute=function(t,e,n){return t.getAttribute(e)||n||""},n.setAttribute=function(t,e,n,r){n||r?t.setAttribute(e,n):t.removeAttribute(e)},n.getBoolAttribute=function(t,e,n){var r=t.getAttribute(e)||n||"";return"true"===r||"1"===r},n.setBoolAttribute=function(t,e,n){n?t.setAttribute(e,"1"):t.removeAttribute(e)},n.getSubAttribute=function(t,e,n,r,i){var a=o(t,e,n);if(!a)return"";for(var s=0;s-1?0:-1:t?0:-1}function a(t){var e=this.cache,n=typeof t;if("boolean"==n||null==t)e[t]=!0;else{"number"!=n&&"string"!=n&&(n="object");var r="number"==n?t:_+t,i=e[n]||(e[n]={});"object"==n?(i[r]||(i[r]=[])).push(t):i[r]=!0}}function s(t){return t.charCodeAt(0)}function u(t,e){var n=t.criteria,r=e.criteria;if(n!==r){if(n>r||"undefined"==typeof n)return 1;if(r>n||"undefined"==typeof r)return-1}return t.index-e.index}function c(t){var e=-1,n=t.length,r=t[0],i=t[0|n/2],o=t[n-1];if(r&&"object"==typeof r&&i&&"object"==typeof i&&o&&"object"==typeof o)return!1;var s=p();s["false"]=s["null"]=s["true"]=s.undefined=!1;var u=p();for(u.array=t,u.cache=s,u.push=a;++ei?0:i);++r-1:void 0}),g&&(d(i),d(o)),a}function S(t,e,n,r,i){(Hr(e)?We:ii)(e,function(e,o){var a,s,u=e,c=t[o];if(e&&((s=Hr(e))||oi(e))){for(var f=r.length;f--;)if(a=r[f]==e){c=i[f];break}if(!a){var l;n&&(u=n(c,e),(l="undefined"!=typeof u)&&(c=u)),l||(c=s?Hr(c)?c:[]:oi(c)?c:{}),r.push(e),i.push(c),l||S(c,e,n,r,i)}}else n&&(u=n(c,e),"undefined"==typeof u&&(u=e)),"undefined"!=typeof u&&(c=u);t[o]=c})}function K(t,n,r){var i=-1,a=ie(),s=t?t.length:0,u=[],f=!n&&s>=E&&a===e,p=r||f?l():u;if(f){var h=c(p);h?(a=o,p=h):(f=!1,p=r?p:(d(p),u))}for(;++i3&&"function"==typeof e[n-2])var r=a(e[--n-1],e[n--],2);else n>2&&"function"==typeof e[n-1]&&(r=e[--n]);for(var i=Dr.call(arguments,1,n),o=-1,s=l(),u=l();++on?Ur(0,o+n):n)||0,Hr(t)?a=i(t,e,n)>-1:"number"==typeof o?a=(Ce(t)?t.indexOf(e,n):i(t,e,n))>-1:ii(t,function(t){return++r>=n?!(a=t===e):void 0}),a}function ze(t,e,r){var i=!0;e=n.createCallback(e,r,3);var o=-1,a=t?t.length:0;if("number"==typeof a)for(;++oo&&(o=c)}else e=!e&&Ce(t)?s:n.createCallback(e,r,3),We(t,function(t,n,r){var a=e(t,n,r);a>i&&(i=a,o=t)});return o}function He(t,e,r){var i=1/0,o=i;if(!e&&Hr(t))for(var a=-1,u=t.length;++ac&&(o=c)}else e=!e&&Ce(t)?s:n.createCallback(e,r,3),We(t,function(t,n,r){var a=e(t,n,r);i>a&&(i=a,o=t)});return o}function Ve(t,e){var n=-1,r=t?t.length:0;if("number"==typeof r)for(var i=ir(r);++n=E&&r===e;if(u){var f=c(a);f?(r=o,a=f):u=!1}for(;++nr?Ur(0,i+r):r||0}else if(r){var o=wn(t,n);return t[o]===n?o:-1}return e(t,n,r)}function hn(t,e,r){var i=0,o=t?t.length:0;if("number"!=typeof e&&null!=e){var a=o;for(e=n.createCallback(e,r,3);a--&&e(t[a],a,t);)i++}else i=null==e||r?1:e||i;return g(t,0,zr(Ur(0,o-i),o))}function dn(t){for(var n=arguments,r=n.length,i=-1,a=l(),s=-1,u=ie(),f=t?t.length:0,p=[],h=l();++i=E&&c(i?n[i]:h)}t:for(;++sn?Ur(0,r+n):zr(n,r-1))+1);r--;)if(t[r]===e)return r;return-1}function vn(t){for(var e=arguments,n=0,r=e.length,i=t?t.length:0;++no;){var s=o+a>>>1;r(t[s])1?arguments:arguments[0],e=-1,n=t?Xe(Ve(t,"length")):0,r=ir(0>n?0:n);++e2?Z(t,17,Dr.call(arguments,2),null,e):Z(t,1,null,null,e)}function Cn(t){for(var e=arguments.length>1?b(arguments,!0,!1,1):de(t),n=-1,r=e.length;++n2?Z(e,19,Dr.call(arguments,2),null,t):Z(e,3,null,null,t)}function On(){for(var t=arguments,e=t.length;e--;)if(!Ee(t[e]))throw new hr;return function(){for(var e=arguments,n=t.length;n--;)e=[t[n].apply(this,e)];return e[0]}}function Ln(t,e,n){var r=typeof t;if(null==t||"function"==r)return a(t,e,n);if("object"!=r)return function(e){return e[t]};var i=Kr(t),o=i[0],s=t[o];return 1!=i.length||s!==s||Se(s)?function(e){for(var n=i.length,r=!1;n--&&(r=x(e[i[n]],t[i[n]],null,!0)););return r}:function(t){var e=t[o];return s===e&&(0!==s||1/s==1/e)}}function Tn(t,e){return e="number"==typeof e?e:+e||t.length,Z(t,4,null,null,null,e)}function qn(t,e,n){var r,i,o,a,s,u,c,f=0,l=!1,p=!0;if(!Ee(t))throw new hr;if(e=Ur(0,e)||0,n===!0){var h=!0;p=!1}else Se(n)&&(h=n.leading,l="maxWait"in n&&(Ur(e,n.maxWait)||0),p="trailing"in n?n.trailing:p);var d=function(){var n=e-(Sr()-a);if(0>=n){i&&br(i);var l=c;i=u=c=y,l&&(f=Sr(),o=t.apply(s,r))}else u=Ar(d,n)},m=function(){u&&br(u),i=u=c=y,(p||l!==e)&&(f=Sr(),o=t.apply(s,r))};return function(){if(r=arguments,a=Sr(),s=this,c=p&&(u||!h),l===!1)var n=h&&!u;else{i||h||(f=a);var g=l-(a-f);0>=g?(i&&(i=br(i)),f=a,o=t.apply(s,r)):i||(i=Ar(m,g))}return u||e===l||(u=Ar(d,e)),n&&(o=t.apply(s,r)),o}}function Bn(t){if(!Ee(t))throw new hr;var e=Dr.call(arguments,1);return Ar(function(){t.apply(y,e)},1)}function Mn(t,e){if(!Ee(t))throw new hr;var n=Dr.call(arguments,2);return Ar(function(){t.apply(y,n)},e)}function Fn(t,e){if(!Ee(t))throw new hr;var n=function(){var r=n.cache,i=e?e.apply(this,arguments):_+arguments[0];return Er.call(r,i)?r[i]:r[i]=t.apply(this,arguments)};return n.cache={},n}function Un(t){var e,n;if(!Ee(t))throw new hr;return function(){return e?n:(e=!0,n=t.apply(this,arguments),t=null,n)}}function zn(t){return Z(t,16,Dr.call(arguments,1))}function Rn(t){return Z(t,32,null,Dr.call(arguments,1))}function Pn(t,e,n){var r=!0,i=!0;if(!Ee(t))throw new hr;n===!1?r=!1:Se(n)&&(r="leading"in n?n.leading:r,i="trailing"in n?n.trailing:i),n=p(),n.leading=r,n.maxWait=e,n.trailing=i;var o=qn(t,e,n);return m(n),o}function Dn(t,e){if(!Ee(e))throw new hr;return function(){var n=[t];return jr.apply(n,arguments),e.apply(this,n) -}}function Wn(t){return null==t?"":pr(t).replace(ti,re)}function Jn(t){return t}function Gn(t,e){var i=t,o=!e||Ee(i);e||(i=r,e=t,t=n),We(de(e),function(n){var r=t[n]=e[n];o&&(i.prototype[n]=function(){var e=this.__wrapped__,n=[e];jr.apply(n,arguments);var o=r.apply(t,n);return e&&"object"==typeof e&&e===o?this:new i(o)})})}function $n(){return t._=gr,this}function Xn(t,e,n){var r=null==t,i=null==e;null==n&&("boolean"==typeof t&&i?(n=t,t=1):i||"boolean"!=typeof e||(n=e,i=!0)),r&&i&&(e=1),t=+t||0,i?(e=t,t=0):e=+e||0;var o=Pr();return n||t%1||e%1?t+zr(o*(e-t+parseFloat("1e-"+((o+"").length-1))),e):t+xr(o*(e-t+1))}function Hn(t,e){if(t){var n=t[e];return Ee(n)?t[e]():n}}function Vn(t,e,r){var i=n.templateSettings;t||(t=""),r=ni({},r,i);var o,a=ni({},r.imports,i.imports),s=Kr(a),u=Me(a),c=0,l=r.interpolate||q,p="__p += '",h=lr((r.escape||q).source+"|"+l.source+"|"+(l===L?C:q).source+"|"+(r.evaluate||q).source+"|$","g");t.replace(h,function(e,n,r,i,a,s){return r||(r=i),p+=t.slice(c,s).replace(M,f),n&&(p+="' +\n__e("+n+") +\n'"),a&&(o=!0,p+="';\n"+a+";\n__p += '"),r&&(p+="' +\n((__t = ("+r+")) == null ? '' : __t) +\n'"),c=s+e.length,e}),p+="';\n";var d=r.variable,m=d;m||(d="obj",p="with ("+d+") {\n"+p+"\n}\n"),p=(o?p.replace(k,""):p).replace(A,"$1").replace(I,"$1;"),p="function("+d+") {\n"+(m?"":d+" || ("+d+" = {});\n")+"var __t, __p = '', __e = _.escape"+(o?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+p+"return __p\n}";var g="\n/*\n//# sourceURL="+(r.sourceURL||"/lodash/template/source["+U++ +"]")+"\n*/";try{var v=sr(s,"return "+p+g).apply(y,u)}catch(b){throw b.source=p,b}return e?v(e):(v.source=p,v)}function Kn(t,e,n){t=(t=+t)>-1?t:0;var r=-1,i=ir(t);for(e=a(e,n,1);++r/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:L,variable:"",imports:{_:n}};var Xr=Or?function(t,e){var n=p();n.value=e,Or(t,"__bindData__",n),m(n)}:h,Hr=qr||function(t){return t&&"object"==typeof t&&"number"==typeof t.length&&Cr.call(t)==R||!1},Vr=function(t){var e,n=t,r=[];if(!n)return r;if(!V[typeof t])return r;for(e in n)Er.call(n,e)&&r.push(e);return r},Kr=Fr?function(t){return Se(t)?Fr(t):[]}:Vr,Yr={"&":"&","<":"<",">":">",'"':""","'":"'"},Qr=ge(Yr),Zr=lr("("+Kr(Qr).join("|")+")","g"),ti=lr("["+Kr(Yr).join("")+"]","g"),ei=function(t,e,n){var r,i=t,o=i;if(!i)return o;var s=arguments,u=0,c="number"==typeof n?2:s.length;if(c>3&&"function"==typeof s[c-2])var f=a(s[--c-1],s[c--],2);else c>2&&"function"==typeof s[c-1]&&(f=s[--c]);for(;++u/g,T=RegExp("^["+j+"]*0+(?=.$)"),q=/($^)/,B=/\bthis\b/,M=/['\n\r\t\u2028\u2029\\]/g,F=["Array","Boolean","Date","Function","Math","Number","Object","RegExp","String","_","attachEvent","clearTimeout","isFinite","isNaN","parseInt","setImmediate","setTimeout"],U=0,z="[object Arguments]",R="[object Array]",P="[object Boolean]",D="[object Date]",W="[object Function]",J="[object Number]",G="[object Object]",$="[object RegExp]",X="[object String]",H={};H[W]=!1,H[z]=H[R]=H[P]=H[D]=H[J]=H[G]=H[$]=H[X]=!0;var V={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},K={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"},Y=V[typeof window]&&window||this,Q=V[typeof r]&&r&&!r.nodeType&&r,Z=V[typeof n]&&n&&!n.nodeType&&n,te=Z&&Z.exports===Q&&Q,ee=V[typeof i]&&i;!ee||ee.global!==ee&&ee.window!==ee||(Y=ee);var ne=v();"function"==typeof t&&"object"==typeof t.amd&&t.amd?(Y._=ne,t(function(){return ne})):Q&&Z?te?(Z.exports=ne)._=ne:Q._=ne:Y._=ne}.call(this)},{}],82:[function(e,n){var r=e("__browserify_Buffer").Buffer;!function(){function i(t,e,n){var r=e&&n||0,i=0;for(e=e||[],t.toLowerCase().replace(/[0-9a-f]{2}/g,function(t){16>i&&(e[r+i++]=g[t])});16>i;)e[r+i++]=0;return e}function o(t,e){var n=e||0,r=m;return r[t[n++]]+r[t[n++]]+r[t[n++]]+r[t[n++]]+"-"+r[t[n++]]+r[t[n++]]+"-"+r[t[n++]]+r[t[n++]]+"-"+r[t[n++]]+r[t[n++]]+"-"+r[t[n++]]+r[t[n++]]+r[t[n++]]+r[t[n++]]+r[t[n++]]+r[t[n++]]}function a(t,e,n){var r=e&&n||0,i=e||[];t=t||{};var a=null!=t.clockseq?t.clockseq:x,s=null!=t.msecs?t.msecs:(new Date).getTime(),u=null!=t.nsecs?t.nsecs:_+1,c=s-w+(u-_)/1e4;if(0>c&&null==t.clockseq&&(a=16383&a+1),(0>c||s>w)&&null==t.nsecs&&(u=0),u>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");w=s,_=u,x=a,s+=122192928e5;var f=(1e4*(268435455&s)+u)%4294967296;i[r++]=255&f>>>24,i[r++]=255&f>>>16,i[r++]=255&f>>>8,i[r++]=255&f;var l=268435455&1e4*(s/4294967296);i[r++]=255&l>>>8,i[r++]=255&l,i[r++]=16|15&l>>>24,i[r++]=255&l>>>16,i[r++]=128|a>>>8,i[r++]=255&a;for(var p=t.node||b,h=0;6>h;h++)i[r+h]=p[h];return e?e:o(i)}function s(t,e,n){var r=e&&n||0;"string"==typeof t&&(e="binary"==t?new d(16):null,t=null),t=t||{};var i=t.random||(t.rng||u)();if(i[6]=64|15&i[6],i[8]=128|63&i[8],e)for(var a=0;16>a;a++)e[r+a]=i[a];return e||o(i)}var u,c=this;if("function"==typeof e)try{var f=e("crypto").randomBytes;u=f&&function(){return f(16)}}catch(l){}if(!u&&c.crypto&&crypto.getRandomValues){var p=new Uint8Array(16);u=function(){return crypto.getRandomValues(p),p}}if(!u){var h=new Array(16);u=function(){for(var t,e=0;16>e;e++)0===(3&e)&&(t=4294967296*Math.random()),h[e]=255&t>>>((3&e)<<3);return h}}for(var d="function"==typeof r?r:Array,m=[],g={},v=0;256>v;v++)m[v]=(v+256).toString(16).substr(1),g[m[v]]=v;var y=u(),b=[1|y[0],y[1],y[2],y[3],y[4],y[5]],x=16383&(y[6]<<8|y[7]),w=0,_=0,E=s;if(E.v1=a,E.v4=s,E.parse=i,E.unparse=o,E.BufferClass=d,c.define&&t.amd)t(function(){return E});else if("undefined"!=typeof n&&n.exports)n.exports=E;else{var S=c.uuid;E.noConflict=function(){return c.uuid=S,E},c.uuid=E}}()},{__browserify_Buffer:68,crypto:63}],83:[function(t,e,n){function r(t){c.call(this),this.registry=new Object,this.insureids=0,this.freq=void 0===t?5:t,this.run=!1,this.start()}function i(t,e,n,r){void 0===r&&(++this.insureids,this.insureids%=65e3,r=this.insureids),expiretime=Date.now()+1e3*e;var i=this,o={paddle:i,error_callback:t,args:n,id:r,timeout:expiretime,done:!1,check_in:function(){return this.paddle.check_in(this.id)}};return this.registry[r]=o,o}function o(t){return void 0!==t.id&&(t=t.id),t in this.registry?(this.emit("check_in",this.registry[t]),this.registry[t].done=!0,delete this.registry[t],!0):!1}function a(){var t=Date.now();for(var e in this.registry)t>this.registry[e].timeout&&(this.registry[e].error_callback.apply(this,this.registry[e].args),this.emit("timeout",this.registry[e]),delete this.registry[e]);this.run&&setTimeout(function(){this.checkEnsures()}.bind(this),1e3*this.freq)}function s(t){return void 0!==t&&(this.freq=t),this.run?!1:(this.run=!0,setTimeout(function(){this.checkEnsures()}.bind(this),1e3*this.freq),!0)}function u(){return this.run?(this.run=!1,!0):!0}var c=t("events").EventEmitter;r.super_=c,r.prototype=Object.create(c.prototype,{constructor:{value:r,enumerable:!1}}),r.prototype.insure=i,r.prototype.check_in=o,r.prototype.checkEnsures=a,r.prototype.start=s,r.prototype.stop=u,n.Paddle=r},{events:58}],84:[function(e,n,r){!function(e,i){"object"==typeof r?i(r,n):"function"==typeof t&&t.amd&&t(["exports","module"],i)}(this,function(t,e){function n(){}n.prototype.name="ANONYMOUS",n.prototype.clientFirst=!0,n.prototype.response=function(t){return t.trace||""},n.prototype.challenge=function(){},t=e.exports=n})},{}],85:[function(e,n,r){!function(i,o){"object"==typeof r?o(r,n,e("./lib/mechanism")):"function"==typeof t&&t.amd&&t(["exports","module","./lib/mechanism"],o)}(this,function(t,e,n){t=e.exports=n,t.Mechanism=n})},{"./lib/mechanism":84}],86:[function(e,n,r){!function(i,o){"object"==typeof r?o(r,n,e("crypto")):"function"==typeof t&&t.amd&&t(["exports","module","crypto"],o)}(this,function(t,e,n){function r(t){t=t||{},this._genNonce=t.genNonce||o(32)}function i(t){for(var e={},n=t.split(/,(?=(?:[^"]|"[^"]*")*$)/),r=0,i=n.length;i>r;r++){var o=/(\w+)=["]?([^"]+)["]?$/.exec(n[r]);o&&(e[o[1]]=o[2])}return e}function o(t){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=e.length;return function(){for(var r=[],i=0;t>i;++i)r.push(e[0|Math.random()*n]);return r.join("")}}function a(t,e){return n.createHash("md5").update(t).digest(e||"hex")}r.prototype.name="DIGEST-MD5",r.prototype.clientFirst=!1,r.prototype.response=function(t){var e=t.serviceType+"/"+t.host;t.serviceName&&t.host!==t.serviceName&&(e+="/"+serviceName);var n,r,i,o=t.realm||this._realm||"",s=this._genNonce(),u="00000001",c="auth",f="";return f+='username="'+t.username+'"',o&&(f+=',realm="'+o+'"'),f+=',nonce="'+this._nonce+'"',f+=',cnonce="'+s+'"',f+=",nc="+u,f+=",qop="+c,f+=',digest-uri="'+e+'"',n=t.authzid?a(a(t.username+":"+o+":"+t.password,"binary")+":"+this._nonce+":"+s+":"+t.authzid):a(a(t.username+":"+o+":"+t.password,"binary")+":"+this._nonce+":"+s),"auth"==c?r=a("AUTHENTICATE:"+e):("auth-int"==c||"auth-conf"==c)&&(r=a("AUTHENTICATE:"+e+":00000000000000000000000000000000")),i=a(n+":"+this._nonce+":"+u+":"+s+":"+c+":"+r),f+=",response="+i,"utf-8"==this._charset&&(f+=",charset=utf-8"),t.authzid&&(f+='authzid="'+t.authzid+'"'),f},r.prototype.challenge=function(t){var e=i(t);return this._realm=e.realm,this._nonce=e.nonce,this._qop=(e.qop||"auth").split(","),this._stale=e.stale,this._maxbuf=parseInt(e.maxbuf)||65536,this._charset=e.charset,this._algo=e.algorithm,this._cipher=e.cipher,this._cipher&&this._cipher.split(","),this},t=e.exports=r})},{crypto:63}],87:[function(e,n,r){!function(i,o){"object"==typeof r?o(r,n,e("./lib/mechanism")):"function"==typeof t&&t.amd&&t(["exports","module","./lib/mechanism"],o)}(this,function(t,e,n){t=e.exports=n,t.Mechanism=n})},{"./lib/mechanism":86}],88:[function(e,n,r){!function(e,i){"object"==typeof r?i(r,n):"function"==typeof t&&t.amd&&t(["exports","module"],i)}(this,function(t,e){function n(){}n.prototype.name="EXTERNAL",n.prototype.clientFirst=!0,n.prototype.response=function(t){return t.authzid||""},n.prototype.challenge=function(){},t=e.exports=n})},{}],89:[function(e,n,r){!function(i,o){"object"==typeof r?o(r,n,e("./lib/mechanism")):"function"==typeof t&&t.amd&&t(["exports","module","./lib/mechanism"],o)}(this,function(t,e,n){t=e.exports=n,t.Mechanism=n})},{"./lib/mechanism":88}],90:[function(e,n,r){!function(e,i){"object"==typeof r?i(r,n):"function"==typeof t&&t.amd&&t(["exports","module"],i)}(this,function(t,e){function n(){}n.prototype.name="PLAIN",n.prototype.clientFirst=!0,n.prototype.response=function(t){var e="";return e+=t.authzid||"",e+="\0",e+=t.username,e+="\0",e+=t.password},n.prototype.challenge=function(){return this},t=e.exports=n})},{}],91:[function(e,n,r){!function(i,o){"object"==typeof r?o(r,n,e("./lib/mechanism")):"function"==typeof t&&t.amd&&t(["exports","module","./lib/mechanism"],o)}(this,function(t,e,n){t=e.exports=n,t.Mechanism=n})},{"./lib/mechanism":90}],92:[function(e,n,r){!function(i,o){"object"==typeof r?o(r,n,e("crypto"),e("buffer")):"function"==typeof t&&t.amd&&t(["exports","module","crypto","buffer"],o)}(this,function(t,e,n,r){function i(t){t=t||{},this._genNonce=t.genNonce||l(32),this._stage=0}function o(t,e){return n.createHmac("sha1",t).update(e).digest("binary")}function a(t,e,n){for(var r=o(t,e+"\0\0\0"),i=r,a=0;n-1>a;a++)r=o(t,r),i=u(i,r);return i}function s(t){return n.createHash("sha1").update(t).digest("binary")}function u(t,e){t=new p(t,"binary"),e=new p(e,"binary");var n=Math.min(t.length,e.length);result=[];for(var r=0;n>r;r++)result.push(t[r]^e[r]);return result=new p(result,"binary"),result.toString("binary")}function c(t){for(var e=[],n="",r=0;rr;r++){var o=/(\w+)=["]?([^"]+)["]?$/.exec(n[r]);o&&(e[o[1]]=o[2])}return e}function l(t){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=e.length;return function(){for(var r=[],i=0;t>i;++i)r.push(e[0|Math.random()*n]);return r.join("")}}var p=r.Buffer;i.prototype.name="SCRAM-SHA-1",i.prototype.clientFirst=!0,i.prototype.response=function(t){return h[this._stage](this,t)},i.prototype.challenge=function(t){var e=f(t);return this._salt=new p(e.s||"","base64").toString("binary"),this._iterationCount=parseInt(e.i,10),this._nonce=e.r,this._verifier=e.v,this._error=e.e,this._challenge=t,this};var h={};h[0]=function(t,e){t._cnonce=t._genNonce();var n="";e.authzid&&(n="a="+c(e.authzid)),t._gs2Header="n,"+n+",";var r="r="+t._cnonce,i="n="+c(e.username);t._clientFirstMessageBare=i+","+r;var o=t._gs2Header+t._clientFirstMessageBare;return t._stage=1,o},h[1]=function(t,e){var n=new p(t._gs2Header).toString("base64");t._clientFinalMessageWithoutProof="c="+n+",r="+t._nonce;var r,i,c;e.clientKey&&e.serverKey?(i=e.clientKey,c=e.serverKey):(r=e.saltedPassword||a(e.password,t._salt,t._iterationCount),i=o(r,"Client Key"),c=o(r,"Server Key"));var f=s(i),l=t._clientFirstMessageBare+","+t._challenge+","+t._clientFinalMessageWithoutProof,h=o(f,l),d=u(i,h),m=new p(d,"binary").toString("base64");t._serverSignature=o(c,l);var g=t._clientFinalMessageWithoutProof+",p="+m;return t._stage=2,t.cache={saltedPassword:r,clientKey:i,serverKey:c},g},h[2]=function(){return""},t=e.exports=i})},{buffer:61,crypto:63}],93:[function(e,n,r){!function(i,o){"object"==typeof r?o(r,n,e("./lib/mechanism")):"function"==typeof t&&t.amd&&t(["exports","module","./lib/mechanism"],o)}(this,function(t,e,n){t=e.exports=n,t.Mechanism=n})},{"./lib/mechanism":92}],94:[function(e,n,r){!function(e,i){"object"==typeof r?i(r,n):"function"==typeof t&&t.amd&&t(["exports","module"],i)}(this,function(t,e){function n(){this._mechs=[]}n.prototype.use=function(t,e){return e||(e=t,t=e.prototype.name),this._mechs.push({name:t,mech:e}),this},n.prototype.create=function(t){for(var e=0,n=this._mechs.length;n>e;e++)for(var r=0,i=t.length;i>r;r++){var o=this._mechs[e];if(o.name==t[r])return new o.mech}return null},t=e.exports=n})},{}],95:[function(e,n,r){!function(i,o){"object"==typeof r?o(r,n,e("./lib/factory")):"function"==typeof t&&t.amd&&t(["exports","module","./lib/factory"],o)}(this,function(t,e,n){t=e.exports=n,t.Factory=n})},{"./lib/factory":94}],96:[function(t,e,n){!function(){var t=this,r=t._,i={},o=Array.prototype,a=Object.prototype,s=Function.prototype,u=o.push,c=o.slice,f=o.concat,l=a.toString,p=a.hasOwnProperty,h=o.forEach,d=o.map,m=o.reduce,g=o.reduceRight,v=o.filter,y=o.every,b=o.some,x=o.indexOf,w=o.lastIndexOf,_=Array.isArray,E=Object.keys,S=s.bind,j=function(t){return t instanceof j?t:this instanceof j?(this._wrapped=t,void 0):new j(t)};"undefined"!=typeof n?("undefined"!=typeof e&&e.exports&&(n=e.exports=j),n._=j):t._=j,j.VERSION="1.5.2";var k=j.each=j.forEach=function(t,e,n){if(null!=t)if(h&&t.forEach===h)t.forEach(e,n);else if(t.length===+t.length){for(var r=0,o=t.length;o>r;r++)if(e.call(n,t[r],r,t)===i)return}else for(var a=j.keys(t),r=0,o=a.length;o>r;r++)if(e.call(n,t[a[r]],a[r],t)===i)return};j.map=j.collect=function(t,e,n){var r=[];return null==t?r:d&&t.map===d?t.map(e,n):(k(t,function(t,i,o){r.push(e.call(n,t,i,o))}),r)};var A="Reduce of empty array with no initial value";j.reduce=j.foldl=j.inject=function(t,e,n,r){var i=arguments.length>2;if(null==t&&(t=[]),m&&t.reduce===m)return r&&(e=j.bind(e,r)),i?t.reduce(e,n):t.reduce(e);if(k(t,function(t,o,a){i?n=e.call(r,n,t,o,a):(n=t,i=!0)}),!i)throw new TypeError(A);return n},j.reduceRight=j.foldr=function(t,e,n,r){var i=arguments.length>2;if(null==t&&(t=[]),g&&t.reduceRight===g)return r&&(e=j.bind(e,r)),i?t.reduceRight(e,n):t.reduceRight(e);var o=t.length;if(o!==+o){var a=j.keys(t);o=a.length}if(k(t,function(s,u,c){u=a?a[--o]:--o,i?n=e.call(r,n,t[u],u,c):(n=t[u],i=!0)}),!i)throw new TypeError(A);return n},j.find=j.detect=function(t,e,n){var r;return I(t,function(t,i,o){return e.call(n,t,i,o)?(r=t,!0):void 0}),r},j.filter=j.select=function(t,e,n){var r=[];return null==t?r:v&&t.filter===v?t.filter(e,n):(k(t,function(t,i,o){e.call(n,t,i,o)&&r.push(t)}),r)},j.reject=function(t,e,n){return j.filter(t,function(t,r,i){return!e.call(n,t,r,i)},n)},j.every=j.all=function(t,e,n){e||(e=j.identity);var r=!0;return null==t?r:y&&t.every===y?t.every(e,n):(k(t,function(t,o,a){return(r=r&&e.call(n,t,o,a))?void 0:i}),!!r)};var I=j.some=j.any=function(t,e,n){e||(e=j.identity);var r=!1;return null==t?r:b&&t.some===b?t.some(e,n):(k(t,function(t,o,a){return r||(r=e.call(n,t,o,a))?i:void 0}),!!r)};j.contains=j.include=function(t,e){return null==t?!1:x&&t.indexOf===x?-1!=t.indexOf(e):I(t,function(t){return t===e})},j.invoke=function(t,e){var n=c.call(arguments,2),r=j.isFunction(e);return j.map(t,function(t){return(r?e:t[e]).apply(t,n)})},j.pluck=function(t,e){return j.map(t,function(t){return t[e]})},j.where=function(t,e,n){return j.isEmpty(e)?n?void 0:[]:j[n?"find":"filter"](t,function(t){for(var n in e)if(e[n]!==t[n])return!1;return!0})},j.findWhere=function(t,e){return j.where(t,e,!0)},j.max=function(t,e,n){if(!e&&j.isArray(t)&&t[0]===+t[0]&&t.length<65535)return Math.max.apply(Math,t);if(!e&&j.isEmpty(t))return-1/0;var r={computed:-1/0,value:-1/0};return k(t,function(t,i,o){var a=e?e.call(n,t,i,o):t;a>r.computed&&(r={value:t,computed:a})}),r.value},j.min=function(t,e,n){if(!e&&j.isArray(t)&&t[0]===+t[0]&&t.length<65535)return Math.min.apply(Math,t);if(!e&&j.isEmpty(t))return 1/0;var r={computed:1/0,value:1/0};return k(t,function(t,i,o){var a=e?e.call(n,t,i,o):t;ar||void 0===n)return 1;if(r>n||void 0===r)return-1}return t.index-e.index}),"value")};var N=function(t){return function(e,n,r){var i={},o=null==n?j.identity:C(n);return k(e,function(n,a){var s=o.call(r,n,a,e);t(i,s,n)}),i}};j.groupBy=N(function(t,e,n){(j.has(t,e)?t[e]:t[e]=[]).push(n)}),j.indexBy=N(function(t,e,n){t[e]=n}),j.countBy=N(function(t,e){j.has(t,e)?t[e]++:t[e]=1}),j.sortedIndex=function(t,e,n,r){n=null==n?j.identity:C(n);for(var i=n.call(r,e),o=0,a=t.length;a>o;){var s=o+a>>>1;n.call(r,t[s])=0})})},j.difference=function(t){var e=f.apply(o,c.call(arguments,1));return j.filter(t,function(t){return!j.contains(e,t)})},j.zip=function(){for(var t=j.max(j.pluck(arguments,"length").concat(0)),e=new Array(t),n=0;t>n;n++)e[n]=j.pluck(arguments,""+n);return e},j.object=function(t,e){if(null==t)return{};for(var n={},r=0,i=t.length;i>r;r++)e?n[t[r]]=e[r]:n[t[r][0]]=t[r][1];return n},j.indexOf=function(t,e,n){if(null==t)return-1;var r=0,i=t.length;if(n){if("number"!=typeof n)return r=j.sortedIndex(t,e),t[r]===e?r:-1;r=0>n?Math.max(0,i+n):n}if(x&&t.indexOf===x)return t.indexOf(e,n);for(;i>r;r++)if(t[r]===e)return r;return-1},j.lastIndexOf=function(t,e,n){if(null==t)return-1;var r=null!=n;if(w&&t.lastIndexOf===w)return r?t.lastIndexOf(e,n):t.lastIndexOf(e);for(var i=r?n:t.length;i--;)if(t[i]===e)return i;return-1},j.range=function(t,e,n){arguments.length<=1&&(e=t||0,t=0),n=arguments[2]||1;for(var r=Math.max(Math.ceil((e-t)/n),0),i=0,o=new Array(r);r>i;)o[i++]=t,t+=n;return o};var L=function(){};j.bind=function(t,e){var n,r;if(S&&t.bind===S)return S.apply(t,c.call(arguments,1));if(!j.isFunction(t))throw new TypeError;return n=c.call(arguments,2),r=function(){if(!(this instanceof r))return t.apply(e,n.concat(c.call(arguments)));L.prototype=t.prototype;var i=new L;L.prototype=null;var o=t.apply(i,n.concat(c.call(arguments)));return Object(o)===o?o:i}},j.partial=function(t){var e=c.call(arguments,1);return function(){return t.apply(this,e.concat(c.call(arguments)))}},j.bindAll=function(t){var e=c.call(arguments,1);if(0===e.length)throw new Error("bindAll must be passed function names");return k(e,function(e){t[e]=j.bind(t[e],t)}),t},j.memoize=function(t,e){var n={};return e||(e=j.identity),function(){var r=e.apply(this,arguments);return j.has(n,r)?n[r]:n[r]=t.apply(this,arguments)}},j.delay=function(t,e){var n=c.call(arguments,2);return setTimeout(function(){return t.apply(null,n)},e)},j.defer=function(t){return j.delay.apply(j,[t,1].concat(c.call(arguments,1)))},j.throttle=function(t,e,n){var r,i,o,a=null,s=0;n||(n={});var u=function(){s=n.leading===!1?0:new Date,a=null,o=t.apply(r,i)};return function(){var c=new Date;s||n.leading!==!1||(s=c);var f=e-(c-s);return r=this,i=arguments,0>=f?(clearTimeout(a),a=null,s=c,o=t.apply(r,i)):a||n.trailing===!1||(a=setTimeout(u,f)),o}},j.debounce=function(t,e,n){var r,i,o,a,s;return function(){o=this,i=arguments,a=new Date;var u=function(){var c=new Date-a;e>c?r=setTimeout(u,e-c):(r=null,n||(s=t.apply(o,i)))},c=n&&!r;return r||(r=setTimeout(u,e)),c&&(s=t.apply(o,i)),s}},j.once=function(t){var e,n=!1;return function(){return n?e:(n=!0,e=t.apply(this,arguments),t=null,e)}},j.wrap=function(t,e){return function(){var n=[t];return u.apply(n,arguments),e.apply(this,n)}},j.compose=function(){var t=arguments;return function(){for(var e=arguments,n=t.length-1;n>=0;n--)e=[t[n].apply(this,e)];return e[0]}},j.after=function(t,e){return function(){return--t<1?e.apply(this,arguments):void 0}},j.keys=E||function(t){if(t!==Object(t))throw new TypeError("Invalid object");var e=[];for(var n in t)j.has(t,n)&&e.push(n);return e},j.values=function(t){for(var e=j.keys(t),n=e.length,r=new Array(n),i=0;n>i;i++)r[i]=t[e[i]];return r},j.pairs=function(t){for(var e=j.keys(t),n=e.length,r=new Array(n),i=0;n>i;i++)r[i]=[e[i],t[e[i]]];return r},j.invert=function(t){for(var e={},n=j.keys(t),r=0,i=n.length;i>r;r++)e[t[n[r]]]=n[r];return e},j.functions=j.methods=function(t){var e=[];for(var n in t)j.isFunction(t[n])&&e.push(n);return e.sort()},j.extend=function(t){return k(c.call(arguments,1),function(e){if(e)for(var n in e)t[n]=e[n]}),t},j.pick=function(t){var e={},n=f.apply(o,c.call(arguments,1));return k(n,function(n){n in t&&(e[n]=t[n])}),e},j.omit=function(t){var e={},n=f.apply(o,c.call(arguments,1));for(var r in t)j.contains(n,r)||(e[r]=t[r]);return e},j.defaults=function(t){return k(c.call(arguments,1),function(e){if(e)for(var n in e)void 0===t[n]&&(t[n]=e[n])}),t},j.clone=function(t){return j.isObject(t)?j.isArray(t)?t.slice():j.extend({},t):t},j.tap=function(t,e){return e(t),t};var T=function(t,e,n,r){if(t===e)return 0!==t||1/t==1/e;if(null==t||null==e)return t===e;t instanceof j&&(t=t._wrapped),e instanceof j&&(e=e._wrapped);var i=l.call(t);if(i!=l.call(e))return!1;switch(i){case"[object String]":return t==String(e);case"[object Number]":return t!=+t?e!=+e:0==t?1/t==1/e:t==+e;case"[object Date]":case"[object Boolean]":return+t==+e;case"[object RegExp]":return t.source==e.source&&t.global==e.global&&t.multiline==e.multiline&&t.ignoreCase==e.ignoreCase}if("object"!=typeof t||"object"!=typeof e)return!1;for(var o=n.length;o--;)if(n[o]==t)return r[o]==e;var a=t.constructor,s=e.constructor;if(a!==s&&!(j.isFunction(a)&&a instanceof a&&j.isFunction(s)&&s instanceof s))return!1;n.push(t),r.push(e);var u=0,c=!0;if("[object Array]"==i){if(u=t.length,c=u==e.length)for(;u--&&(c=T(t[u],e[u],n,r)););}else{for(var f in t)if(j.has(t,f)&&(u++,!(c=j.has(e,f)&&T(t[f],e[f],n,r))))break;if(c){for(f in e)if(j.has(e,f)&&!u--)break;c=!u}}return n.pop(),r.pop(),c};j.isEqual=function(t,e){return T(t,e,[],[])},j.isEmpty=function(t){if(null==t)return!0;if(j.isArray(t)||j.isString(t))return 0===t.length;for(var e in t)if(j.has(t,e))return!1;return!0},j.isElement=function(t){return!(!t||1!==t.nodeType)},j.isArray=_||function(t){return"[object Array]"==l.call(t)},j.isObject=function(t){return t===Object(t)},k(["Arguments","Function","String","Number","Date","RegExp"],function(t){j["is"+t]=function(e){return l.call(e)=="[object "+t+"]"}}),j.isArguments(arguments)||(j.isArguments=function(t){return!(!t||!j.has(t,"callee"))}),"function"!=typeof/./&&(j.isFunction=function(t){return"function"==typeof t}),j.isFinite=function(t){return isFinite(t)&&!isNaN(parseFloat(t))},j.isNaN=function(t){return j.isNumber(t)&&t!=+t},j.isBoolean=function(t){return t===!0||t===!1||"[object Boolean]"==l.call(t)},j.isNull=function(t){return null===t},j.isUndefined=function(t){return void 0===t},j.has=function(t,e){return p.call(t,e)},j.noConflict=function(){return t._=r,this},j.identity=function(t){return t},j.times=function(t,e,n){for(var r=Array(Math.max(0,t)),i=0;t>i;i++)r[i]=e.call(n,i);return r},j.random=function(t,e){return null==e&&(e=t,t=0),t+Math.floor(Math.random()*(e-t+1))};var q={escape:{"&":"&","<":"<",">":">",'"':""","'":"'"}};q.unescape=j.invert(q.escape);var B={escape:new RegExp("["+j.keys(q.escape).join("")+"]","g"),unescape:new RegExp("("+j.keys(q.unescape).join("|")+")","g")};j.each(["escape","unescape"],function(t){j[t]=function(e){return null==e?"":(""+e).replace(B[t],function(e){return q[t][e]})}}),j.result=function(t,e){if(null==t)return void 0;var n=t[e];return j.isFunction(n)?n.call(t):n},j.mixin=function(t){k(j.functions(t),function(e){var n=j[e]=t[e];j.prototype[e]=function(){var t=[this._wrapped]; -return u.apply(t,arguments),R.call(this,n.apply(j,t))}})};var M=0;j.uniqueId=function(t){var e=++M+"";return t?t+e:e},j.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var F=/(.)^/,U={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},z=/\\|'|\r|\n|\t|\u2028|\u2029/g;j.template=function(t,e,n){var r;n=j.defaults({},n,j.templateSettings);var i=new RegExp([(n.escape||F).source,(n.interpolate||F).source,(n.evaluate||F).source].join("|")+"|$","g"),o=0,a="__p+='";t.replace(i,function(e,n,r,i,s){return a+=t.slice(o,s).replace(z,function(t){return"\\"+U[t]}),n&&(a+="'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'"),r&&(a+="'+\n((__t=("+r+"))==null?'':__t)+\n'"),i&&(a+="';\n"+i+"\n__p+='"),o=s+e.length,e}),a+="';\n",n.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{r=new Function(n.variable||"obj","_",a)}catch(s){throw s.source=a,s}if(e)return r(e,j);var u=function(t){return r.call(this,t,j)};return u.source="function("+(n.variable||"obj")+"){\n"+a+"}",u},j.chain=function(t){return j(t).chain()};var R=function(t){return this._chain?j(t).chain():t};j.mixin(j),k(["pop","push","reverse","shift","sort","splice","unshift"],function(t){var e=o[t];j.prototype[t]=function(){var n=this._wrapped;return e.apply(n,arguments),"shift"!=t&&"splice"!=t||0!==n.length||delete n[0],R.call(this,n)}}),k(["concat","join","slice"],function(t){var e=o[t];j.prototype[t]=function(){return R.call(this,e.apply(this._wrapped,arguments))}}),j.extend(j.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}.call(this)},{}],97:[function(t,e){function n(){this.callbacks={}}e.exports=n,n.prototype.on=function(t){var e=3===arguments.length,n=e?arguments[1]:void 0,r=e?arguments[2]:arguments[1];return r._groupName=n,(this.callbacks[t]=this.callbacks[t]||[]).push(r),this},n.prototype.once=function(t){function e(){n.off(t,e),o.apply(this,arguments)}var n=this,r=3===arguments.length,i=r?arguments[1]:void 0,o=r?arguments[2]:arguments[1];return this.on(t,i,e),this},n.prototype.releaseGroup=function(t){var e,n,r,i;for(e in this.callbacks)for(i=this.callbacks[e],n=0,r=i.length;r>n;n++)i[n]._groupName===t&&(i.splice(n,1),n--,r--);return this},n.prototype.off=function(t,e){var n,r=this.callbacks[t];return r?1===arguments.length?(delete this.callbacks[t],this):(n=r.indexOf(e),r.splice(n,1),this):this},n.prototype.emit=function(t){var e,n,r=[].slice.call(arguments,1),i=this.callbacks[t],o=this.getWildcardCallbacks(t);if(i)for(e=0,n=i.length;n>e&&i[e];++e)i[e].apply(this,r);if(o)for(e=0,n=o.length;n>e&&o[e];++e)o[e].apply(this,[t].concat(r));return this},n.prototype.getWildcardCallbacks=function(t){var e,n,r=[];for(e in this.callbacks)n=e.split("*"),("*"===e||2===n.length&&t.slice(0,n[1].length)===n[1])&&(r=r.concat(this.callbacks[e]));return r}},{}]},{},[1])(1)}); \ No newline at end of file +(function(e){if("function"==typeof bootstrap)bootstrap("xmpp",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeXMPP=e}else"undefined"!=typeof window?window.XMPP=e():global.XMPP=e()})(function(){var define,ses,bootstrap,module,exports; +return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s 0) { + this.parts.bare = this.jid.slice(0, split); + } else { + this.parts.bare = this.jid; + } + return this.parts.bare; + }, + get resource() { + if (this.parts.resource) { + return this.parts.resource; + } + + var split = this.jid.indexOf('/'); + if (split > 0) { + this.parts.resource = this.jid.slice(split + 1); + } else { + this.parts.resource = ''; + } + return this.parts.resource; + }, + get local() { + if (this.parts.local) { + return this.parts.local; + } + + var bare = this.bare; + var split = bare.indexOf('@'); + if (split > 0) { + this.parts.local = bare.slice(0, split); + } else { + this.parts.local = bare; + } + + return this.parts.local; + }, + get domain() { + if (this.parts.domain) { + return this.parts.domain; + } + + var bare = this.bare; + var split = bare.indexOf('@'); + if (split > 0) { + this.parts.domain = bare.slice(split + 1); + } else { + this.parts.domain = bare; + } + + return this.parts.domain; + } +}; + + +module.exports = JID; + +},{}],4:[function(require,module,exports){ +module.exports = function (client) { + client.disco.addFeature('urn:xmpp:attention:0'); + + + client.getAttention = function (jid, opts) { + opts = opts || {}; + opts.to = jid; + opts.type = 'headline'; + opts.attention = true; + client.sendMessage(opts); + }; + + client.on('message', function (msg) { + if (msg._extensions._attention) { + client.emit('attention', msg); + } + }); +}; + +},{}],5:[function(require,module,exports){ +var stanzas = require('../stanza/avatar'); + + +module.exports = function (client) { + client.disco.addFeature('urn:xmpp:avatar:metadata+notify'); + + client.on('pubsubEvent', function (msg) { + if (!msg.event._extensions.updated) return; + if (msg.event.updated.node !== 'urn:xmpp:avatar:metadata') return; + + client.emit('avatar', { + jid: msg.from, + avatars: msg.event.updated.published[0].avatars + }); + }); + + client.publishAvatar = function (id, data, cb) { + client.publish('', 'urn:xmpp:avatar:data', { + id: id, + avatarData: data + }, cb); + }; + + client.useAvatars = function (info, cb) { + client.publish('', 'urn:xmpp:avatar:metadata', { + id: 'current', + avatars: info + }, cb); + }; + + client.getAvatar = function (jid, id, cb) { + client.getItem(jid, 'urn:xmpp:avatar:data', id, cb); + }; +}; + +},{"../stanza/avatar":23}],6:[function(require,module,exports){ +var stanzas = require('../stanza/bookmarks'); + + +module.exports = function (client) { + + client.getBookmarks = function (cb) { + this.getPrivateData({bookmarks: {}}, cb); + }; + + client.setBookmarks = function (opts, cb) { + this.setPrivateData({bookmarks: opts}, cb); + }; + +}; + +},{"../stanza/bookmarks":25}],7:[function(require,module,exports){ +var stanzas = require('../stanza/carbons'); + + +module.exports = function (client) { + client.disco.addFeature('urn:xmpp:carbons:2'); + + client.enableCarbons = function (cb) { + this.sendIq({ + type: 'set', + enableCarbons: true + }, cb); + }; + + client.disableCarbons = function (cb) { + this.sendIq({ + type: 'set', + disableCarbons: true + }, cb); + }; + + client.on('message', function (msg) { + if (msg._extensions.carbonSent) { + return client.emit('carbon:sent', msg); + } + if (msg._extensions.carbonReceived) { + return client.emit('carbon:received', msg); + } + }); +}; + +},{"../stanza/carbons":27}],8:[function(require,module,exports){ +var stanzas = require('../stanza/chatstates'); + + +module.exports = function (client) { + client.disco.addFeature('http://jabber.org/protocol/chatstates'); + + client.on('message', function (msg) { + if (msg.chatState) { + client.emit('chatState', { + to: msg.to, + from: msg.from, + chatState: msg.chatState + }); + } + }); +}; + +},{"../stanza/chatstates":28}],9:[function(require,module,exports){ +module.exports = function (client) { + client.disco.addFeature('urn:xmpp:message-correct:0'); + + client.on('message', function (msg) { + if (msg.replace) { + client.emit('replace', msg); + client.emit('replace:' + msg.id, msg); + } + }); +}; + +},{}],10:[function(require,module,exports){ +var stanzas = require('../stanza/delayed'); + + +module.exports = function (client) { + client.disco.addFeature('urn:xmpp:delay'); +}; + +},{"../stanza/delayed":30}],11:[function(require,module,exports){ +/*global unescape, escape */ + +var _ = require('underscore'); +var crypto = require('crypto'); + +require('../stanza/disco'); +require('../stanza/caps'); + + +var UTF8 = { + encode: function (s) { + return unescape(encodeURIComponent(s)); + }, + decode: function (s) { + return decodeURIComponent(escape(s)); + } +}; + + +function verifyVerString(info, hash, check) { + if (hash === 'sha-1') { + hash = 'sha1'; + } + var computed = generateVerString(info, hash); + return computed && computed == check; +} + + +function generateVerString(info, hash) { + var S = ''; + var features = info.features.sort(); + var identities = []; + var formTypes = {}; + var formOrder = []; + + + _.forEach(info.identities, function (identity) { + identities.push([ + identity.category || '', + identity.type || '', + identity.lang || '', + identity.name || '' + ].join('/')); + }); + + var idLen = identities.length; + var featureLen = features.length; + + identities = _.unique(identities, true); + features = _.unique(features, true); + + if (featureLen != features.length || idLen != identities.length) { + return false; + } + + + S += identities.join('<') + '<'; + S += features.join('<') + '<'; + + + var illFormed = false; + _.forEach(info.extensions, function (ext) { + var fields = ext.fields; + for (var i = 0, len = fields.length; i < len; i++) { + if (fields[i].name == 'FORM_TYPE' && fields[i].type == 'hidden') { + var name = fields[i].value; + if (formTypes[name]) { + illFormed = true; + return; + } + formTypes[name] = ext; + formOrder.push(name); + return; + } + } + }); + if (illFormed) { + return false; + } + + formOrder.sort(); + + _.forEach(formOrder, function (name) { + var ext = formTypes[name]; + var fields = {}; + var fieldOrder = []; + + S += '<' + name; + + _.forEach(ext.fields, function (field) { + var fieldName = field.name; + if (fieldName != 'FORM_TYPE') { + var values = field.value || ''; + if (typeof values != 'object') { + values = values.split('\n'); + } + fields[fieldName] = values.sort(); + fieldOrder.push(fieldName); + } + }); + + fieldOrder.sort(); + + _.forEach(fieldOrder, function (fieldName) { + S += '<' + fieldName; + _.forEach(fields[fieldName], function (val) { + S += '<' + val; + }); + }); + }); + + if (hash === 'sha-1') { + hash = 'sha1'; + } + + var ver = crypto.createHash(hash).update(UTF8.encode(S)).digest('base64'); + var padding = 4 - ver.length % 4; + if (padding === 4) { + padding = 0; + } + + for (var i = 0; i < padding; i++) { + ver += '='; + } + return ver; +} + + +function Disco(client) { + this.features = {}; + this.identities = {}; + this.extensions = {}; + this.items = {}; + this.caps = {}; +} + +Disco.prototype = { + constructor: { + value: Disco + }, + addFeature: function (feature, node) { + node = node || ''; + if (!this.features[node]) { + this.features[node] = []; + } + this.features[node].push(feature); + }, + addIdentity: function (identity, node) { + node = node || ''; + if (!this.identities[node]) { + this.identities[node] = []; + } + this.identities[node].push(identity); + }, + addItem: function (item, node) { + node = node || ''; + if (!this.items[node]) { + this.items[node] = []; + } + this.items[node].push(item); + }, + addExtension: function (form, node) { + node = node || ''; + if (!this.extensions[node]) { + this.extensions[node] = []; + } + this.extensions[node].push(form); + } +}; + +module.exports = function (client) { + client.disco = new Disco(client); + + client.disco.addFeature('http://jabber.org/protocol/disco#info'); + client.disco.addIdentity({ + category: 'client', + type: 'web' + }); + + client.getDiscoInfo = function (jid, node, cb) { + this.sendIq({ + to: jid, + type: 'get', + discoInfo: { + node: node + } + }, cb); + }; + + client.getDiscoItems = function (jid, node, cb) { + this.sendIq({ + to: jid, + type: 'get', + discoItems: { + node: node + } + }, cb); + }; + + client.updateCaps = function () { + var node = this.config.capsNode || 'https://stanza.io'; + var data = JSON.parse(JSON.stringify({ + identities: this.disco.identities[''], + features: this.disco.features[''], + extensions: this.disco.extensions[''] + })); + + var ver = generateVerString(data, 'sha-1'); + + this.disco.caps = { + node: node, + hash: 'sha-1', + ver: ver + }; + + node = node + '#' + ver; + this.disco.features[node] = data.features; + this.disco.identities[node] = data.identities; + this.disco.extensions[node] = data.extensions; + + return client.getCurrentCaps(); + }; + + client.getCurrentCaps = function () { + var caps = client.disco.caps; + if (!caps.ver) { + return {ver: null, discoInfo: null}; + } + + var node = caps.node + '#' + caps.ver; + return { + ver: caps.ver, + discoInfo: { + identities: client.disco.identities[node], + features: client.disco.features[node], + extensions: client.disco.extensions[node] + } + }; + }; + + client.on('presence', function (pres) { + if (pres._extensions.caps) { + client.emit('disco:caps', pres); + } + }); + + client.on('iq:get:discoInfo', function (iq) { + var node = iq.discoInfo.node; + var reportedNode = iq.discoInfo.node; + + if (node === client.disco.caps.node + '#' + client.disco.caps.ver) { + reportedNode = node; + node = ''; + } + var res = iq.resultReply({ + discoInfo: { + node: reportedNode, + identities: client.disco.identities[node] || [], + features: client.disco.features[node] || [], + extensions: client.disco.extensions[node] || [] + } + }); + debugger; + client.sendIq(res); + }); + + client.on('iq:get:discoItems', function (iq) { + var node = iq.discoInfo.node; + client.sendIq(iq.resultReply({ + discoItems: { + node: node, + items: client.disco.items[node] || [] + } + })); + }); + + client.verifyVerString = verifyVerString; + client.generateVerString = generateVerString; +}; + +},{"../stanza/caps":26,"../stanza/disco":31,"crypto":63,"underscore":96}],12:[function(require,module,exports){ +var stanzas = require('../stanza/forwarded'); + + +module.exports = function (client) { + client.disco.addFeature('urn:xmpp:forward:0'); +}; + +},{"../stanza/forwarded":33}],13:[function(require,module,exports){ +var stanzas = require('../stanza/idle'); + + +module.exports = function (client) { + client.disco.addFeature('urn:xmpp:idle:0'); +}; + +},{"../stanza/idle":34}],14:[function(require,module,exports){ +require('../stanza/visibility'); + + +module.exports = function (client) { + client.goInvisible = function (cb) { + this.sendIq({ + type: 'set', + invisible: true + }); + }; + + client.goVisible = function (cb) { + this.sendIq({ + type: 'set', + visible: true + }); + }; +}; + +},{"../stanza/visibility":54}],15:[function(require,module,exports){ +var stanzas = require('../stanza/mam'); + + +module.exports = function (client) { + client.disco.addFeature('urn:xmpp:mam:tmp'); + + client.getHistory = function (opts, cb) { + var self = this; + var queryid = this.nextId(); + + opts = opts || {}; + opts.queryid = queryid; + + var mamResults = []; + this.on('mam:' + queryid, 'session', function (msg) { + mamResults.push(msg); + }); + + cb = cb || function () {}; + + this.sendIq({ + type: 'get', + id: queryid, + mamQuery: opts + }, function (err, resp) { + if (err) { + cb(err); + } else { + self.off('mam:' + queryid); + resp.mamQuery.results = mamResults; + cb(null, resp); + } + }); + }; + + client.getHistoryPreferences = function (cb) { + client.sendIq({ + type: 'get', + mamPrefs: {} + }, cb); + }; + + client.setHistoryPreferences = function (opts, cb) { + client.sendIq({ + type: 'set', + mamPrefs: opts + }, cb); + }; + + client.on('message', function (msg) { + if (msg._extensions.mam) { + client.emit('mam:' + msg.mam.queryid, msg); + } + }); +}; + +},{"../stanza/mam":36}],16:[function(require,module,exports){ +require('../stanza/muc'); + + +module.exports = function (client) { + client.joinRoom = function (room, nick, opts) { + opts = opts || {}; + opts.to = room + '/' + nick; + opts.caps = this.disco.caps; + opts.joinMuc = opts.joinMuc || {}; + + this.sendPresence(opts); + }; + + client.leaveRoom = function (room, nick, opts) { + opts = opts || {}; + opts.to = room + '/' + nick; + opts.type = 'unavailable'; + this.sendPresence(opts); + }; +}; + +},{"../stanza/muc":38}],17:[function(require,module,exports){ +var stanzas = require('../stanza/private'); + + +module.exports = function (client) { + + client.getPrivateData = function (opts, cb) { + this.sendIq({ + type: 'get', + privateStorage: opts + }, cb); + }; + + client.setPrivateData = function (opts, cb) { + this.sendIq({ + type: 'set', + privateStorage: opts + }, cb); + }; + +}; + +},{"../stanza/private":40}],18:[function(require,module,exports){ +var stanzas = require('../stanza/pubsub'); + + +module.exports = function (client) { + + client.on('message', function (msg) { + if (msg._extensions.event) { + client.emit('pubsubEvent', msg); + } + }); + + client.subscribeToNode = function (jid, opts, cb) { + client.sendIq({ + type: 'set', + to: jid, + pubsub: { + subscribe: { + node: opts.node, + jid: opts.jid || client.jid + } + } + }, cb); + }; + + client.unsubscribeFromNode = function (jid, opts, cb) { + client.sendIq({ + type: 'set', + to: jid, + pubsub: { + unsubscribe: { + node: opts.node, + jid: opts.jid || client.jid.split('/')[0] + } + } + }, cb); + }; + + client.publish = function (jid, node, item, cb) { + client.sendIq({ + type: 'set', + to: jid, + pubsub: { + publish: { + node: node, + item: item + } + } + }, cb); + }; + + client.getItem = function (jid, node, id, cb) { + client.sendIq({ + type: 'get', + to: jid, + pubsub: { + retrieve: { + node: node, + item: id + } + } + }, cb); + }; + + client.getItems = function (jid, node, opts, cb) { + opts = opts || {}; + opts.node = node; + client.sendIq({ + type: 'get', + to: jid, + pubsub: { + retrieve: { + node: node, + max: opts.max + }, + rsm: opts.rsm + } + }, cb); + }; + + client.retract = function (jid, node, id, notify, cb) { + client.sendIq({ + type: 'set', + to: jid, + pubsub: { + retract: { + node: node, + notify: notify, + id: id + } + } + }, cb); + }; + + client.purgeNode = function (jid, node, cb) { + client.sendIq({ + type: 'set', + to: jid, + pubsubOwner: { + purge: node + } + }, cb); + }; + + client.deleteNode = function (jid, node, cb) { + client.sendIq({ + type: 'set', + to: jid, + pubsubOwner: { + del: node + } + }, cb); + }; + + client.createNode = function (jid, node, config, cb) { + var cmd = { + type: 'set', + to: jid, + pubsubOwner: { + create: node + } + }; + + if (config) { + cmd.pubsubOwner.config = {form: config}; + } + + client.sendIq(cmd, cb); + }; +}; + +},{"../stanza/pubsub":41}],19:[function(require,module,exports){ +var stanzas = require('../stanza/receipts'); + + +module.exports = function (client) { + client.disco.addFeature('urn:xmpp:receipts'); + + client.on('message', function (msg) { + var ackTypes = { + normal: true, + chat: true, + headline: true + }; + if (ackTypes[msg.type] && msg.requestReceipt && !msg._extensions.receipt) { + client.sendMessage({ + to: msg.from, + receipt: { + id: msg.id + }, + id: msg.id + }); + } + if (msg._extensions.receipt) { + client.emit('receipt:' + msg.receipt.id); + } + }); +}; + +},{"../stanza/receipts":42}],20:[function(require,module,exports){ +var stanzas = require('../stanza/time'); + + +module.exports = function (client) { + client.disco.addFeature('urn:xmpp:time'); + + client.getTime = function (jid, cb) { + this.sendIq({ + to: jid, + type: 'get', + time: true + }, cb); + }; + + client.on('iq:get:time', function (iq) { + var time = new Date(); + client.sendIq(iq.resultReply({ + time: { + utc: time, + tzo: time.getTimezoneOffset() + } + })); + }); +}; + +},{"../stanza/time":51}],21:[function(require,module,exports){ +require('../stanza/version'); + + +module.exports = function (client) { + client.disco.addFeature('jabber:iq:version'); + + client.on('iq:get:version', function (iq) { + client.sendIq(iq.resultReply({ + version: client.config.version || { + name: 'stanza.io' + } + })); + }); + + client.getSoftwareVersion = function (jid, cb) { + this.sendIq({ + to: jid, + type: 'get', + version: {} + }, cb); + }; +}; + +},{"../stanza/version":53}],22:[function(require,module,exports){ +var SM = require('./stanza/sm'); +var MAX_SEQ = Math.pow(2, 32); + + +function mod(v, n) { + return ((v % n) + n) % n; +} + + +function StreamManagement(conn) { + this.conn = conn; + this.id = false; + this.allowResume = true; + this.started = false; + this.lastAck = 0; + this.handled = 0; + this.windowSize = 1; + this.windowCount = 0; + this.unacked = []; +} + +StreamManagement.prototype = { + constructor: { + value: StreamManagement + }, + enable: function () { + var enable = new SM.Enable(); + enable.resume = this.allowResume; + this.conn.send(enable); + this.handled = 0; + this.started = true; + }, + resume: function () { + var resume = new SM.Resume({ + h: this.handled, + previd: this.id + }); + this.conn.send(resume); + this.started = true; + }, + enabled: function (resp) { + this.id = resp.id; + }, + resumed: function (resp) { + this.id = resp.id; + if (resp.h) { + this.process(resp, true); + } + }, + failed: function (resp) { + this.started = false; + this.id = false; + this.lastAck = 0; + this.handled = 0; + this.windowCount = 0; + this.unacked = []; + }, + ack: function () { + this.conn.send(new SM.Ack({ + h: this.handled + })); + }, + request: function () { + this.conn.send(new SM.Request()); + }, + process: function (ack, resend) { + var self = this; + var numAcked = mod(ack.h - this.lastAck, MAX_SEQ); + + for (var i = 0; i < numAcked && this.unacked.length > 0; i++) { + this.conn.emit('stanza:acked', this.unacked.shift()); + } + if (resend) { + var resendUnacked = this.unacked; + this.unacked = []; + resendUnacked.forEach(function (stanza) { + self.conn.send(stanza); + }); + } + this.lastAck = ack.h; + }, + track: function (stanza) { + var name = stanza._name; + var acceptable = { + message: true, + presence: true, + iq: true + }; + + if (this.started && acceptable[name]) { + this.unacked.push(stanza); + this.windowCount += 1; + if (this.windowCount == this.windowSize) { + this.request(); + this.windowCount = 0; + } + } + }, + handle: function (stanza) { + if (this.started) { + this.handled = mod(this.handled + 1, MAX_SEQ); + } + } +}; + +module.exports = StreamManagement; + +},{"./stanza/sm":47}],23:[function(require,module,exports){ +var _ = require('underscore'); +var stanza = require('jxt'); +var Item = require('./pubsub').Item; +var EventItem = require('./pubsub').EventItem; + +var Avatar = module.exports = stanza.define({ + name: 'avatar', + namespace: 'urn:xmpp:avatar:metadata', + element: 'info', + fields: { + id: stanza.attribute('id'), + bytes: stanza.attribute('bytes'), + height: stanza.attribute('height'), + width: stanza.attribute('width'), + type: stanza.attribute('type', 'image/png'), + url: stanza.attribute('url') + } +}); + + +var avatars = { + get: function () { + var metadata = stanza.find(this.xml, 'urn:xmpp:avatar:metadata', 'metadata'); + var results = []; + if (metadata.length) { + var avatars = stanza.find(metadata[0], 'urn:xmpp:avatar:metadata', 'info'); + _.forEach(avatars, function (info) { + results.push(new Avatar({}, info)); + }); + } + return results; + }, + set: function (value) { + var metadata = stanza.findOrCreate(this.xml, 'urn:xmpp:avatar:metadata', 'metadata'); + stanza.setAttribute(metadata, 'xmlns', 'urn:xmpp:avatar:metadata'); + _.forEach(value, function (info) { + var avatar = new Avatar(info); + metadata.appendChild(avatar.xml); + }); + } +}; + +stanza.add(Item, 'avatars', avatars); +stanza.add(EventItem, 'avatars', avatars); +stanza.add(Item, 'avatarData', stanza.subText('urn:xmpp:avatar:data', 'data')); +stanza.add(EventItem, 'avatarData', stanza.subText('urn:xmpp:avatar:data', 'data')); + +},{"./pubsub":41,"jxt":77,"underscore":96}],24:[function(require,module,exports){ +var stanza = require('jxt'); +var Iq = require('./iq'); +var StreamFeatures = require('./streamFeatures'); +var util = require('./util'); + +var NS = 'urn:ietf:params:xml:ns:xmpp-bind'; + +var Bind = module.exports = stanza.define({ + name: 'bind', + namespace: NS, + element: 'bind', + fields: { + resource: stanza.subText(NS, 'resource'), + jid: util.jidSub(NS, 'jid') + } +}); + +stanza.extend(Iq, Bind); +stanza.extend(StreamFeatures, Bind); + +},{"./iq":35,"./streamFeatures":50,"./util":52,"jxt":77}],25:[function(require,module,exports){ +var stanza = require('jxt'); +var util = require('./util'); +var PrivateStorage = require('./private'); + + +var Conference = stanza.define({ + name: 'conference', + namespace: 'storage:bookmarks', + element: 'conference', + fields: { + name: stanza.attribute('name'), + autoJoin: stanza.boolAttribute('autojoin'), + jid: util.jidAttribute('jid'), + nick: stanza.subText('storage:bookmarks', 'nick') + } +}); + +var Bookmarks = module.exports = stanza.define({ + name: 'bookmarks', + namespace: 'storage:bookmarks', + element: 'storage' +}); + + +stanza.extend(PrivateStorage, Bookmarks); +stanza.extend(Bookmarks, Conference, 'conferences'); + +},{"./private":40,"./util":52,"jxt":77}],26:[function(require,module,exports){ +var stanza = require('jxt'); +var Presence = require('./presence'); +var StreamFeatures = require('./streamFeatures'); + + +var Caps = module.exports = stanza.define({ + name: 'caps', + namespace: 'http://jabber.org/protocol/caps', + element: 'c', + fields: { + ver: stanza.attribute('ver'), + node: stanza.attribute('node'), + hash: stanza.attribute('hash'), + ext: stanza.attribute('ext') + } +}); + +stanza.extend(Presence, Caps); +stanza.extend(StreamFeatures, Caps); + +},{"./presence":39,"./streamFeatures":50,"jxt":77}],27:[function(require,module,exports){ +var stanza = require('jxt'); +var Message = require('./message'); +var Iq = require('./iq'); +var Forwarded = require('./forwarded'); + + +exports.Sent = stanza.define({ + name: 'carbonSent', + eventName: 'carbon:sent', + namespace: 'urn:xmpp:carbons:2', + element: 'sent' +}); + +exports.Received = stanza.define({ + name: 'carbonReceived', + eventName: 'carbon:received', + namespace: 'urn:xmpp:carbons:2', + element: 'received' +}); + +exports.Private = stanza.define({ + name: 'carbonPrivate', + eventName: 'carbon:private', + namespace: 'urn:xmpp:carbons:2', + element: 'private' +}); + +exports.Enable = stanza.define({ + name: 'enableCarbons', + namespace: 'urn:xmpp:carbons:2', + element: 'enable' +}); + +exports.Disable = stanza.define({ + name: 'disableCarbons', + namespace: 'urn:xmpp:carbons:2', + element: 'disable' +}); + + +stanza.extend(exports.Sent, Forwarded); +stanza.extend(exports.Received, Forwarded); +stanza.extend(Message, exports.Sent); +stanza.extend(Message, exports.Received); +stanza.extend(Message, exports.Private); +stanza.extend(Iq, exports.Enable); +stanza.extend(Iq, exports.Disable); + +},{"./forwarded":33,"./iq":35,"./message":37,"jxt":77}],28:[function(require,module,exports){ +var stanza = require('jxt'); +var Message = require('./message'); + +var NS = 'http://jabber.org/protocol/chatstates'; + +var Active = stanza.define({ + name: 'chatStateActive', + eventName: 'chat:active', + namespace: NS, + element: 'active' +}); + +var Composing = stanza.define({ + name: 'chatStateComposing', + eventName: 'chat:composing', + namespace: NS, + element: 'composing' +}); + +var Paused = stanza.define({ + name: 'chatStatePaused', + eventName: 'chat:paused', + namespace: NS, + element: 'paused' +}); + +var Inactive = stanza.define({ + name: 'chatStateInactive', + eventName: 'chat:inactive', + namespace: NS, + element: 'inactive' +}); + +var Gone = stanza.define({ + name: 'chatStateGone', + eventName: 'chat:gone', + namespace: NS, + element: 'gone' +}); + +stanza.extend(Message, Active); +stanza.extend(Message, Composing); +stanza.extend(Message, Paused); +stanza.extend(Message, Inactive); +stanza.extend(Message, Gone); + +stanza.add(Message, 'chatState', { + get: function () { + var self = this; + var states = ['Active', 'Composing', 'Paused', 'Inactive', 'Gone']; + + for (var i = 0; i < states.length; i++) { + if (self._extensions['chatState' + states[i]]) { + return states[i].toLowerCase(); + } + } + return ''; + }, + set: function (value) { + var self = this; + var states = ['Active', 'Composing', 'Paused', 'Inactive', 'Gone']; + + states.forEach(function (state) { + if (self._extensions['chatState' + state]) { + self.xml.removeChild(self._extensions['chatState' + state].xml); + delete self._extensions['chatState' + state]; + } + }); + if (value) { + this['chatState' + value.charAt(0).toUpperCase() + value.slice(1)]; + } + } +}); + +},{"./message":37,"jxt":77}],29:[function(require,module,exports){ +var _ = require('underscore'); +var stanza = require('jxt'); +var util = require('./util'); +var Message = require('./message'); + + +exports.DataForm = stanza.define({ + name: 'form', + namespace: 'jabber:x:data', + element: 'x', + fields: { + title: stanza.subText('jabber:x:data', 'title'), + instructions: stanza.multiSubText('jabber:x:data', 'instructions'), + type: stanza.attribute('type', 'form') + } +}); + +exports.Field = stanza.define({ + name: 'field', + namespace: 'jabber:x:data', + element: 'field', + init: function (data) { + this._type = data.type || this.type; + }, + fields: { + type: { + get: function () { + return stanza.getAttribute(this.xml, 'type', 'text-single'); + }, + set: function (value) { + this._type = value; + stanza.setAttribute(this.xml, 'type', value); + } + }, + name: stanza.attribute('var'), + desc: stanza.subText('desc'), + required: stanza.boolSub('jabber:x:data', 'required'), + label: stanza.attribute('label'), + value: { + get: function () { + var vals = stanza.getMultiSubText(this.xml, this._NS, 'value'); + if (this._type === 'boolean') { + return vals[0] === '1' || vals[0] === 'true'; + } + if (vals.length > 1) { + if (this._type === 'text-multi') { + return vals.join('\n'); + } + return vals; + } + return vals[0]; + }, + set: function (value) { + if (this._type === 'boolean') { + stanza.setSubText(this.xml, this._NS, 'value', value ? '1' : '0'); + } else { + if (this._type === 'text-multi') { + value = value.split('\n'); + } + stanza.setMultiSubText(this.xml, this._NS, 'value', value); + } + } + }, + options: { + get: function () { + var self = this; + return stanza.getMultiSubText(this.xml, this._NS, 'option', function (sub) { + return stanza.getSubText(sub, self._NS, 'value'); + }); + }, + set: function (value) { + var self = this; + stanza.setMultiSubText(this.xml, this._NS, 'option', value, function (val) { + var opt = document.createElementNS(self._NS, 'option'); + var value = document.createElementNS(self._NS, 'value'); + + opt.appendChild(value); + value.textContent = val; + self.xml.appendChild(opt); + }); + } + } + } +}); + + +stanza.extend(Message, exports.DataForm); + +},{"./message":37,"./util":52,"jxt":77,"underscore":96}],30:[function(require,module,exports){ +var stanza = require('jxt'); +var Message = require('./message'); +var Presence = require('./presence'); +var util = require('./util'); + +var DelayedDelivery = module.exports = stanza.define({ + name: 'delay', + namespace: 'urn:xmpp:delay', + element: 'delay', + fields: { + from: util.jidAttribute('from'), + stamp: util.dateAttribute('stamp'), + reason: stanza.text() + } +}); + +stanza.extend(Message, DelayedDelivery); +stanza.extend(Presence, DelayedDelivery); + +},{"./message":37,"./presence":39,"./util":52,"jxt":77}],31:[function(require,module,exports){ +var _ = require('underscore'); +var stanza = require('jxt'); +var JID = require('../jid'); +var Iq = require('./iq'); +var RSM = require('./rsm'); +var DataForm = require('./dataforms').DataForm; + + +exports.DiscoInfo = stanza.define({ + name: 'discoInfo', + namespace: 'http://jabber.org/protocol/disco#info', + element: 'query', + fields: { + node: stanza.attribute('node'), + identities: { + get: function () { + var result = []; + var identities = stanza.find(this.xml, this._NS, 'identity'); + identities.forEach(function (identity) { + result.push({ + category: stanza.getAttribute(identity, 'category'), + type: stanza.getAttribute(identity, 'type'), + lang: identity.getAttributeNS(stanza.XML_NS, 'lang'), + name: stanza.getAttribute(identity, 'name') + }); + }); + return result; + }, + set: function (values) { + var self = this; + + var existing = stanza.find(this.xml, this._NS, 'identity'); + existing.forEach(function (item) { + self.xml.removeChild(item); + }); + values.forEach(function (value) { + var identity = document.createElementNS(self._NS, 'identity'); + stanza.setAttribute(identity, 'category', value.category); + stanza.setAttribute(identity, 'type', value.type); + stanza.setAttribute(identity, 'name', value.name); + if (value.lang) { + identity.setAttributeNS(stanza.XML_NS, 'lang', value.lang); + } + self.xml.appendChild(identity); + }); + } + }, + features: { + get: function () { + var result = []; + var features = stanza.find(this.xml, this._NS, 'feature'); + features.forEach(function (feature) { + result.push(feature.getAttribute('var')); + }); + return result; + }, + set: function (values) { + var self = this; + + var existing = stanza.find(this.xml, this._NS, 'feature'); + existing.forEach(function (item) { + self.xml.removeChild(item); + }); + values.forEach(function (value) { + var feature = document.createElementNS(self._NS, 'feature'); + feature.setAttribute('var', value); + self.xml.appendChild(feature); + }); + } + } + } +}); + + +exports.DiscoItems = stanza.define({ + name: 'discoItems', + namespace: 'http://jabber.org/protocol/disco#items', + element: 'query', + fields: { + node: stanza.attribute('node'), + items: { + get: function () { + var result = []; + var items = stanza.find(this.xml, this._NS, 'item'); + items.forEach(function (item) { + result.push({ + jid: new JID(stanza.getAttribute(item, 'jid')), + node: stanza.getAttribute(item, 'node'), + name: stanza.getAttribute(item, 'name') + }); + }); + return result; + }, + set: function (values) { + var self = this; + var existing = stanza.find(this.xml, this._NS, 'item'); + + existing.forEach(function (item) { + self.xml.removeChild(item); + }); + values.forEach(function (value) { + var item = document.createElementNS(self._NS, 'item'); + stanza.setAttribute(item, 'jid', value.jid.toString()); + stanza.setAttribute(item, 'node', value.node); + stanza.setAttribute(item, 'name', value.name); + self.xml.appendChild(item); + }); + } + } + } +}); + + +stanza.extend(Iq, exports.DiscoInfo); +stanza.extend(Iq, exports.DiscoItems); +stanza.extend(exports.DiscoItems, RSM); +stanza.extend(exports.DiscoInfo, DataForm, 'extensions'); + +},{"../jid":3,"./dataforms":29,"./iq":35,"./rsm":44,"jxt":77,"underscore":96}],32:[function(require,module,exports){ +var _ = require('underscore'); +var stanza = require('jxt'); +var util = require('./util'); +var Message = require('./message'); +var Presence = require('./presence'); +var Iq = require('./iq'); + + +var ERR_NS = 'urn:ietf:params:xml:ns:xmpp-stanzas'; +var CONDITIONS = [ + 'bad-request', 'conflict', 'feature-not-implemented', + 'forbidden', 'gone', 'internal-server-error', + 'item-not-found', 'jid-malformed', 'not-acceptable', + 'not-allowed', 'not-authorized', 'payment-required', + 'recipient-unavailable', 'redirect', + 'registration-required', 'remote-server-not-found', + 'remote-server-timeout', 'resource-constraint', + 'service-unavailable', 'subscription-required', + 'undefined-condition', 'unexpected-request' +]; + + +var ErrorStanza = module.exports = stanza.define({ + name: 'error', + namespace: 'jabber:client', + element: 'error', + fields: { + lang: { + get: function () { + return (this.parent || {}).lang || ''; + } + }, + condition: { + get: function () { + var self = this; + var result = []; + CONDITIONS.forEach(function (condition) { + var exists = stanza.find(self.xml, ERR_NS, condition); + if (exists.length) { + result.push(exists[0].tagName); + } + }); + return result[0] || ''; + }, + set: function (value) { + var self = this; + CONDITIONS.forEach(function (condition) { + var exists = stanza.find(self.xml, ERR_NS, condition); + if (exists.length) { + self.xml.removeChild(exists[0]); + } + }); + + if (value) { + var condition = document.createElementNS(ERR_NS, value); + condition.setAttribute('xmlns', ERR_NS); + this.xml.appendChild(condition); + } + } + }, + gone: { + get: function () { + return stanza.getSubText(this.xml, ERR_NS, 'gone'); + }, + set: function (value) { + this.condition = 'gone'; + stanza.setSubText(this.xml, ERR_NS, 'gone', value); + } + }, + redirect: { + get: function () { + return stanza.getSubText(this.xml, ERR_NS, 'redirect'); + }, + set: function (value) { + this.condition = 'redirect'; + stanza.setSubText(this.xml, ERR_NS, 'redirect', value); + } + }, + code: stanza.attribute('code'), + type: stanza.attribute('type'), + by: util.jidAttribute('by'), + $text: { + get: function () { + return stanza.getSubLangText(this.xml, ERR_NS, 'text', this.lang); + } + }, + text: { + get: function () { + var text = this.$text; + return text[this.lang] || ''; + }, + set: function (value) { + stanza.setSubLangText(this.xml, ERR_NS, 'text', value, this.lang); + } + } + } +}); + + +stanza.extend(Message, ErrorStanza); +stanza.extend(Presence, ErrorStanza); +stanza.extend(Iq, ErrorStanza); + +},{"./iq":35,"./message":37,"./presence":39,"./util":52,"jxt":77,"underscore":96}],33:[function(require,module,exports){ +var stanza = require('jxt'); +var Message = require('./message'); +var Presence = require('./presence'); +var Iq = require('./iq'); +var DelayedDelivery = require('./delayed'); + + +var Forwarded = module.exports = stanza.define({ + name: 'forwarded', + eventName: 'forward', + namespace: 'urn:xmpp:forward:0', + element: 'forwarded' +}); + + +stanza.extend(Message, Forwarded); +stanza.extend(Forwarded, Message); +stanza.extend(Forwarded, Presence); +stanza.extend(Forwarded, Iq); +stanza.extend(Forwarded, DelayedDelivery); + +},{"./delayed":30,"./iq":35,"./message":37,"./presence":39,"jxt":77}],34:[function(require,module,exports){ +var stanza = require('jxt'); +var util = require('./util'); +var Presence = require('./presence'); + +var Idle = module.exports = stanza.define({ + name: 'idle', + namespace: 'urn:xmpp:idle:0', + element: 'idle', + fields: { + since: util.dateAttribute('since') + } +}); + +stanza.extend(Presence, Idle); + +},{"./presence":39,"./util":52,"jxt":77}],35:[function(require,module,exports){ +var stanza = require('jxt'); +var util = require('./util'); + + +var Iq = module.exports = stanza.define({ + name: 'iq', + namespace: 'jabber:client', + element: 'iq', + topLevel: true, + fields: { + lang: util.langAttribute(), + id: stanza.attribute('id'), + to: util.jidAttribute('to'), + from: util.jidAttribute('from'), + type: stanza.attribute('type') + } +}); + +Iq.prototype.resultReply = function (data) { + data.to = this.from; + data.id = this.id; + data.type = 'result'; + return new Iq(data); +}; + +Iq.prototype.errorReply = function (data) { + data.to = this.from; + data.id = this.id; + data.type = 'error'; + return new Iq(data); +}; + +},{"./util":52,"jxt":77}],36:[function(require,module,exports){ +var stanza = require('jxt'); +var util = require('./util'); +var Message = require('./message'); +var Iq = require('./iq'); +var Forwarded = require('./forwarded'); +var RSM = require('./rsm'); +var JID = require('../jid'); + + +exports.MAMQuery = stanza.define({ + name: 'mamQuery', + namespace: 'urn:xmpp:mam:tmp', + element: 'query', + fields: { + queryid: stanza.attribute('queryid'), + start: util.dateSub('urn:xmpp:mam:tmp', 'start'), + end: util.dateSub('urn:xmpp:mam:tmp', 'end'), + 'with': util.jidSub('urn:xmpp:mam:tmp', 'with') + } +}); + +exports.Result = stanza.define({ + name: 'mam', + eventName: 'mam:result', + namespace: 'urn:xmpp:mam:tmp', + element: 'result', + fields: { + queryid: stanza.attribute('queryid'), + id: stanza.attribute('id') + } +}); + +exports.Archived = stanza.define({ + name: 'mamArchived', + namespace: 'urn:xmpp:mam:tmp', + element: 'archived', + fields: { + by: util.jidAttribute('by'), + id: stanza.attribute('id') + } +}); + +exports.Prefs = stanza.define({ + name: 'mamPrefs', + namespace: 'urn:xmpp:mam:tmp', + element: 'prefs', + fields: { + defaultCondition: stanza.attribute('default'), + always: { + get: function () { + var results = []; + var container = stanza.find(this.xml, this._NS, 'always'); + if (container.length === 0) { + return results; + } + container = container[0]; + var jids = stanza.getMultiSubText(container, this._NS, 'jid'); + jids.forEach(function (jid) { + results.push(new JID(jid.textContent)); + }); + return results; + }, + set: function (value) { + if (value.length > 0) { + var container = stanza.find(this.xml, this._NS, 'always'); + stanza.setMultiSubText(container, this._NS, 'jid', value); + } + } + }, + never: { + get: function () { + var results = []; + var container = stanza.find(this.xml, this._NS, 'always'); + if (container.length === 0) { + return results; + } + container = container[0]; + var jids = stanza.getMultiSubText(container, this._NS, 'jid'); + jids.forEach(function (jid) { + results.push(new JID(jid.textContent)); + }); + return results; + }, + set: function (value) { + if (value.length > 0) { + var container = stanza.find(this.xml, this._NS, 'never'); + stanza.setMultiSubText(container, this._NS, 'jid', value); + } + } + } + } +}); + +stanza.extend(Message, exports.Archived, 'archived'); +stanza.extend(Iq, exports.MAMQuery); +stanza.extend(Iq, exports.Prefs); +stanza.extend(Message, exports.Result); +stanza.extend(exports.Result, Forwarded); +stanza.extend(exports.MAMQuery, RSM); + +},{"../jid":3,"./forwarded":33,"./iq":35,"./message":37,"./rsm":44,"./util":52,"jxt":77}],37:[function(require,module,exports){ +var _ = require('underscore'); +var stanza = require('jxt'); +var util = require('./util'); + + +module.exports = stanza.define({ + name: 'message', + namespace: 'jabber:client', + element: 'message', + topLevel: true, + fields: { + lang: util.langAttribute(), + id: stanza.attribute('id'), + to: util.jidAttribute('to'), + from: util.jidAttribute('from'), + type: stanza.attribute('type', 'normal'), + thread: stanza.subText('jabber:client', 'thread'), + parentThread: stanza.subAttribute('jabber:client', 'thread', 'parent'), + $body: { + get: function () { + return stanza.getSubLangText(this.xml, this._NS, 'body', this.lang); + } + }, + body: { + get: function () { + var bodies = this.$body; + return bodies[this.lang] || ''; + }, + set: function (value) { + stanza.setSubLangText(this.xml, this._NS, 'body', value, this.lang); + } + }, + attention: stanza.boolSub('urn:xmpp:attention:0', 'attention'), + replace: stanza.subAttribute('urn:xmpp:message-correct:0', 'replace', 'id') + } +}); + +},{"./util":52,"jxt":77,"underscore":96}],38:[function(require,module,exports){ +var stanza = require('jxt'); +var Message = require('./message'); +var Presence = require('./presence'); +var Iq = require('./iq'); + + +var NS = 'http://jabber.org/protocol/muc'; + + +exports.MUCJoin = stanza.define({ + name: 'joinMuc', + namespace: NS, + element: 'x', + fields: { + password: stanza.subText(NS, 'password'), + history: { + get: function () { + var result = {}; + var hist = stanza.find(this.xml, this._NS, 'history'); + + if (!hist.length) { + return {}; + } + hist = hist[0]; + + var maxchars = hist.getAttribute('maxchars') || ''; + var maxstanzas = hist.getAttribute('maxstanas') || ''; + var seconds = hist.getAttribute('seconds') || ''; + var since = hist.getAttribute('since') || ''; + + + if (maxchars) { + result.maxchars = parseInt(maxchars, 10); + } + if (maxstanzas) { + result.maxstanzas = parseInt(maxstanzas, 10); + } + if (seconds) { + result.seconds = parseInt(seconds, 10); + } + if (since) { + result.since = new Date(since); + } + }, + set: function (opts) { + var existing = stanza.find(this.xml, this._NS, 'history'); + if (existing.length) { + for (var i = 0; i < existing.length; i++) { + this.xml.removeChild(existing[i]); + } + } + + var hist = document.createElementNS(this._NS, 'history'); + this.xml.appendChild(hist); + + if (opts.maxchars) { + hist.setAttribute('' + opts.maxchars); + } + if (opts.maxstanzas) { + hist.setAttribute('' + opts.maxstanzas); + } + if (opts.seconds) { + hist.setAttribute('' + opts.seconds); + } + if (opts.since) { + hist.setAttribute(opts.since.toISOString()); + } + } + } + } +}); + + +stanza.extend(Presence, exports.MUCJoin); + +},{"./iq":35,"./message":37,"./presence":39,"jxt":77}],39:[function(require,module,exports){ +var _ = require('underscore'); +var stanza = require('jxt'); +var util = require('./util'); + + +module.exports = stanza.define({ + name: 'presence', + namespace: 'jabber:client', + element: 'presence', + topLevel: true, + fields: { + lang: util.langAttribute(), + id: stanza.attribute('id'), + to: util.jidAttribute('to'), + from: util.jidAttribute('from'), + priority: stanza.subText('jabber:client', 'priority', '0'), + show: stanza.subText('jabber:client', 'show'), + type: { + get: function () { + return stanza.getAttribute(this.xml, 'type', 'available'); + }, + set: function (value) { + if (value === 'available') { + value = false; + } + stanza.setAttribute(this.xml, 'type', value); + } + }, + $status: { + get: function () { + return stanza.getSubLangText(this.xml, this._NS, 'status', this.lang); + } + }, + status: { + get: function () { + var statuses = this.$status; + return statuses[this.lang] || ''; + }, + set: function (value) { + stanza.setSubLangText(this.xml, this._NS, 'status', value, this.lang); + } + } + } +}); + +},{"./util":52,"jxt":77,"underscore":96}],40:[function(require,module,exports){ +var stanza = require('jxt'); +var Iq = require('./iq'); + + +var PrivateStorage = module.exports = stanza.define({ + name: 'privateStorage', + namespace: 'jabber:iq:private', + element: 'query' +}); + +stanza.extend(Iq, PrivateStorage); + +},{"./iq":35,"jxt":77}],41:[function(require,module,exports){ +var _ = require('underscore'); +var stanza = require('jxt'); +var util = require('./util'); +var Iq = require('./iq'); +var Message = require('./message'); +var Form = require('./dataforms').DataForm; +var RSM = require('./rsm'); +var JID = require('../jid'); + + +var NS = 'http://jabber.org/protocol/pubsub'; +var OwnerNS = 'http://jabber.org/protocol/pubsub#owner'; +var EventNS = 'http://jabber.org/protocol/pubsub#event'; + + +exports.Pubsub = stanza.define({ + name: 'pubsub', + namespace: 'http://jabber.org/protocol/pubsub', + element: 'pubsub', + fields: { + publishOptions: { + get: function () { + var conf = stanza.find(this.xml, this._NS, 'publish-options'); + if (conf.length && conf[0].childNodes.length) { + return new Form({}, conf[0].childNodes[0]); + } + }, + set: function (value) { + var conf = stanza.findOrCreate(this.xml, this._NS, 'publish-options'); + if (value) { + var form = new Form(value); + conf.appendChild(form.xml); + } + } + } + } +}); + +exports.PubsubOwner = stanza.define({ + name: 'pubsubOwner', + namespace: OwnerNS, + element: 'pubsub', + fields: { + create: stanza.subAttribute(OwnerNS, 'create', 'node'), + purge: stanza.subAttribute(OwnerNS, 'purge', 'node'), + del: stanza.subAttribute(OwnerNS, 'delete', 'node'), + redirect: { + get: function () { + var del = stanza.find(this.xml, this._NS, 'delete'); + if (del.length) { + return stanza.getSubAttribute(del[0], this._NS, 'redirect', 'uri'); + } + return ''; + }, + set: function (value) { + var del = stanza.findOrCreate(this.xml, this._NS, 'delete'); + stanza.setSubAttribute(del, this._NS, 'redirect', 'uri', value); + } + } + } +}); + +exports.Configure = stanza.define({ + name: 'config', + namespace: OwnerNS, + element: 'configure', + fields: { + node: stanza.attribute('node') + } +}); + +exports.Event = stanza.define({ + name: 'event', + namespace: EventNS, + element: 'event' +}); + +exports.Subscribe = stanza.define({ + name: 'subscribe', + namespace: NS, + element: 'subscribe', + fields: { + node: stanza.attribute('node'), + jid: util.jidAttribute('jid') + } +}); + +exports.Subscription = stanza.define({ + name: 'subscription', + namespace: NS, + element: 'subscription', + fields: { + node: stanza.attribute('node'), + jid: util.jidAttribute('jid'), + subid: stanza.attribute('subid'), + type: stanza.attribute('subscription') + } +}); + +exports.Unsubscribe = stanza.define({ + name: 'unsubscribe', + namespace: NS, + element: 'unsubscribe', + fields: { + node: stanza.attribute('node'), + jid: util.jidAttribute('jid') + } +}); + +exports.Publish = stanza.define({ + name: 'publish', + namespace: NS, + element: 'publish', + fields: { + node: stanza.attribute('node'), + } +}); + +exports.Retract = stanza.define({ + name: 'retract', + namespace: NS, + element: 'retract', + fields: { + node: stanza.attribute('node'), + notify: stanza.boolAttribute('notify'), + id: stanza.subAttribute(NS, 'item', 'id') + } +}); + +exports.Retrieve = stanza.define({ + name: 'retrieve', + namespace: NS, + element: 'items', + fields: { + node: stanza.attribute('node'), + max: stanza.attribute('max_items') + } +}); + +exports.Item = stanza.define({ + name: 'item', + namespace: NS, + element: 'item', + fields: { + id: stanza.attribute('id') + } +}); + +exports.EventItems = stanza.define({ + name: 'updated', + namespace: EventNS, + element: 'items', + fields: { + node: stanza.attribute('node'), + retracted: { + get: function () { + var results = []; + var retracted = stanza.find(this.xml, this._NS, 'retract'); + + _.forEach(retracted, function (xml) { + results.push(xml.getAttribute('id')); + }); + return results; + }, + set: function (value) { + var self = this; + _.forEach(value, function (id) { + var retracted = document.createElementNS(self._NS, 'retract'); + retracted.setAttribute('id', id); + this.xml.appendChild(retracted); + }); + } + } + } +}); + +exports.EventItem = stanza.define({ + name: 'eventItem', + namespace: EventNS, + element: 'item', + fields: { + id: stanza.attribute('id'), + node: stanza.attribute('node'), + publisher: util.jidAttribute('publisher') + } +}); + + +stanza.extend(exports.Pubsub, exports.Subscribe); +stanza.extend(exports.Pubsub, exports.Unsubscribe); +stanza.extend(exports.Pubsub, exports.Publish); +stanza.extend(exports.Pubsub, exports.Retrieve); +stanza.extend(exports.Pubsub, exports.Subscription); +stanza.extend(exports.PubsubOwner, exports.Configure); +stanza.extend(exports.Publish, exports.Item, 'items'); +stanza.extend(exports.Retrieve, exports.Item, 'items'); +stanza.extend(exports.Configure, Form); +stanza.extend(exports.Pubsub, RSM); +stanza.extend(exports.Event, exports.EventItems); +stanza.extend(exports.EventItems, exports.EventItem, 'published'); +stanza.extend(Message, exports.Event); +stanza.extend(Iq, exports.Pubsub); +stanza.extend(Iq, exports.PubsubOwner); + +},{"../jid":3,"./dataforms":29,"./iq":35,"./message":37,"./rsm":44,"./util":52,"jxt":77,"underscore":96}],42:[function(require,module,exports){ +var stanza = require('jxt'); +var Message = require('./message'); + + +stanza.add(Message, 'requestReceipt', stanza.boolSub('urn:xmpp:receipts', 'request')); + +var Received = module.exports = stanza.define({ + name: 'receipt', + namespace: 'urn:xmpp:receipts', + element: 'receipt', + fields: { + id: stanza.attribute('id') + } +}); + +stanza.extend(Message, Received); + +},{"./message":37,"jxt":77}],43:[function(require,module,exports){ +var _ = require('underscore'); +var stanza = require('jxt'); +var Iq = require('./iq'); +var JID = require('../jid'); + + +var Roster = module.exports = stanza.define({ + name: 'roster', + namespace: 'jabber:iq:roster', + element: 'query', + fields: { + ver: { + get: function () { + return stanza.getAttribute(this.xml, 'ver'); + }, + set: function (value) { + var force = (value === ''); + stanza.setAttribute(this.xml, 'ver', value, force); + } + }, + items: { + get: function () { + var self = this; + + var items = stanza.find(this.xml, this._NS, 'item'); + if (!items.length) { + return []; + } + var results = []; + items.forEach(function (item) { + var data = { + jid: new JID(stanza.getAttribute(item, 'jid', '')), + name: stanza.getAttribute(item, 'name', undefined), + subscription: stanza.getAttribute(item, 'subscription', 'none'), + ask: stanza.getAttribute(item, 'ask', undefined), + groups: [] + }; + var groups = stanza.find(item, self._NS, 'group'); + groups.forEach(function (group) { + data.groups.push(group.textContent); + }); + results.push(data); + }); + return results; + }, + set: function (values) { + var self = this; + values.forEach(function (value) { + var item = document.createElementNS(self._NS, 'item'); + stanza.setAttribute(item, 'jid', value.jid.toString()); + stanza.setAttribute(item, 'name', value.name); + stanza.setAttribute(item, 'subscription', value.subscription); + stanza.setAttribute(item, 'ask', value.ask); + (value.groups || []).forEach(function (name) { + var group = document.createElementNS(self._NS, 'group'); + group.textContent = name; + item.appendChild(group); + }); + self.xml.appendChild(item); + }); + } + } + } +}); + +stanza.extend(Iq, Roster); + +},{"../jid":3,"./iq":35,"jxt":77,"underscore":96}],44:[function(require,module,exports){ +var stanza = require('jxt'); +var util = require('./util'); + + +var NS = 'http://jabber.org/protocol/rsm'; + + +module.exports = stanza.define({ + name: 'rsm', + namespace: NS, + element: 'set', + fields: { + after: stanza.subText(NS, 'after'), + before: { + get: function () { + return stanza.getSubText(this.xml, this._NS, 'before'); + }, + set: function (value) { + if (value === true) { + stanza.findOrCreate(this.xml, this._NS, 'before'); + } else { + stanza.setSubText(this.xml, this._NS, 'before', value); + } + } + }, + count: util.numberSub(NS, 'count'), + first: stanza.subText(NS, 'first'), + firstIndex: stanza.subAttribute(NS, 'first', 'index'), + index: stanza.subText(NS, 'index'), + last: stanza.subText(NS, 'last'), + max: stanza.subText(NS, 'max') + } +}); + +},{"./util":52,"jxt":77}],45:[function(require,module,exports){ +var _ = require('underscore'); +var stanza = require('jxt'); +var util = require('./util'); +var StreamFeatures = require('./streamFeatures'); + +var NS = 'urn:ietf:params:xml:ns:xmpp-sasl'; +var CONDITIONS = [ + 'aborted', 'account-disabled', 'credentials-expired', + 'encryption-required', 'incorrect-encoding', 'invalid-authzid', + 'invalid-mechanism', 'malformed-request', 'mechanism-too-weak', + 'not-authorized', 'temporary-auth-failure' +]; + +exports.Mechanisms = stanza.define({ + name: 'sasl', + namespace: NS, + element: 'mechanisms', + fields: { + mechanisms: stanza.multiSubText(NS, 'mechanism') + } +}); + +exports.Auth = stanza.define({ + name: 'saslAuth', + eventName: 'sasl:auth', + namespace: NS, + element: 'auth', + topLevel: true, + fields: { + value: util.b64Text(), + mechanism: stanza.attribute('mechanism') + } +}); + +exports.Challenge = stanza.define({ + name: 'saslChallenge', + eventName: 'sasl:challenge', + namespace: NS, + element: 'challenge', + topLevel: true, + fields: { + value: util.b64Text() + } +}); + +exports.Response = stanza.define({ + name: 'saslResponse', + eventName: 'sasl:response', + namespace: NS, + element: 'response', + topLevel: true, + fields: { + value: util.b64Text() + } +}); + +exports.Abort = stanza.define({ + name: 'saslAbort', + eventName: 'sasl:abort', + namespace: NS, + element: 'abort', + topLevel: true +}); + +exports.Success = stanza.define({ + name: 'saslSuccess', + eventName: 'sasl:success', + namespace: NS, + element: 'success', + topLevel: true, + fields: { + value: util.b64Text() + } +}); + +exports.Failure = stanza.define({ + name: 'saslFailure', + eventName: 'sasl:failure', + namespace: NS, + element: 'failure', + topLevel: true, + fields: { + lang: { + get: function () { + return this._lang || ''; + }, + set: function (value) { + this._lang = value; + } + }, + condition: { + get: function () { + var self = this; + var result = []; + CONDITIONS.forEach(function (condition) { + var exists = stanza.find(self.xml, NS, condition); + if (exists.length) { + result.push(exists[0].tagName); + } + }); + return result[0] || ''; + }, + set: function (value) { + var self = this; + this._CONDITIONS.forEach(function (condition) { + var exists = stanza.find(self.xml, NS, condition); + if (exists.length) { + self.xml.removeChild(exists[0]); + } + }); + if (value) { + var condition = stanza.createElementNS(NS, value); + condition.setAttribute('xmlns', NS); + this.xml.appendChild(condition); + } + } + }, + $text: { + get: function () { + return stanza.getSubLangText(this.xml, NS, 'text', this.lang); + } + }, + text: { + get: function () { + var text = this.$text; + return text[this.lang] || ''; + }, + set: function (value) { + stanza.setSubLangText(this.xml, NS, 'text', value, this.lang); + } + } + } +}); + + +stanza.extend(StreamFeatures, exports.Mechanisms); + +},{"./streamFeatures":50,"./util":52,"jxt":77,"underscore":96}],46:[function(require,module,exports){ +var stanza = require('jxt'); +var Iq = require('./iq'); +var StreamFeatures = require('./streamFeatures'); + +var Session = module.exports = stanza.define({ + name: 'session', + namespace: 'urn:ietf:params:xml:ns:xmpp-session', + element: 'session' +}); + +stanza.extend(StreamFeatures, Session); +stanza.extend(Iq, Session); + +},{"./iq":35,"./streamFeatures":50,"jxt":77}],47:[function(require,module,exports){ +var stanza = require('jxt'); +var util = require('./util'); +var StreamFeatures = require('./streamFeatures'); + + +var NS = 'urn:xmpp:sm:3'; + + +exports.SMFeature = stanza.define({ + name: 'streamManagement', + namespace: NS, + element: 'sm' +}); + +exports.Enable = stanza.define({ + name: 'smEnable', + eventName: 'stream:management:enable', + namespace: NS, + element: 'enable', + topLevel: true, + fields: { + resume: stanza.boolAttribute('resume') + } +}); + +exports.Enabled = stanza.define({ + name: 'smEnabled', + eventName: 'stream:management:enabled', + namespace: NS, + element: 'enabled', + topLevel: true, + fields: { + id: stanza.attribute('id'), + resume: stanza.boolAttribute('resume') + } +}); + +exports.Resume = stanza.define({ + name: 'smResume', + eventName: 'stream:management:resume', + namespace: NS, + element: 'resume', + topLevel: true, + fields: { + h: util.numberAttribute('h', '0'), + previd: stanza.attribute('previd') + } +}); + +exports.Resumed = stanza.define({ + name: 'smResumed', + eventName: 'stream:management:resumed', + namespace: NS, + element: 'resumed', + topLevel: true, + fields: { + h: util.numberAttribute('h', '0'), + previd: stanza.attribute('previd') + } +}); + +exports.Failed = stanza.define({ + name: 'smFailed', + eventName: 'stream:management:failed', + namespace: NS, + element: 'failed', + topLevel: true +}); + +exports.Ack = stanza.define({ + name: 'smAck', + eventName: 'stream:management:ack', + namespace: NS, + element: 'a', + topLevel: true, + fields: { + h: util.numberAttribute('h', '0') + } +}); + +exports.Request = stanza.define({ + name: 'smRequest', + eventName: 'stream:management:request', + namespace: NS, + element: 'r', + topLevel: true +}); + + +stanza.extend(StreamFeatures, exports.SMFeature); + +},{"./streamFeatures":50,"./util":52,"jxt":77}],48:[function(require,module,exports){ +var stanza = require('jxt'); +var util = require('./util'); + + +module.exports = stanza.define({ + name: 'stream', + namespace: 'http://etherx.jabber.org/streams', + element: 'stream', + fields: { + lang: { + get: function () { + return this.xml.getAttributeNS(stanza.XML_NS, 'lang') || ''; + }, + set: function (value) { + this.xml.setAttributeNS(stanza.XML_NS, 'lang', value); + } + }, + id: stanza.attribute('id'), + version: stanza.attribute('version', '1.0'), + to: util.jidAttribute('to'), + from: util.jidAttribute('from') + } +}); + +},{"./util":52,"jxt":77}],49:[function(require,module,exports){ +var _ = require('underscore'); +var stanza = require('jxt'); + + +var ERR_NS = 'urn:ietf:params:xml:ns:xmpp-streams'; +var CONDITIONS = [ + 'bad-format', 'bad-namespace-prefix', 'conflict', + 'connection-timeout', 'host-gone', 'host-unknown', + 'improper-addressing', 'internal-server-error', 'invalid-from', + 'invalid-namespace', 'invalid-xml', 'not-authorized', + 'not-well-formed', 'policy-violation', 'remote-connection-failed', + 'reset', 'resource-constraint', 'restricted-xml', 'see-other-host', + 'system-shutdown', 'undefined-condition', 'unsupported-encoding', + 'unsupported-feature', 'unsupported-stanza-type', + 'unsupported-version' +]; + +module.exports = stanza.define({ + name: 'streamError', + namespace: 'http://etherx.jabber.org/streams', + element: 'error', + topLevel: true, + fields: { + lang: { + get: function () { + return this._lang || ''; + }, + set: function (value) { + this._lang = value; + } + }, + condition: { + get: function () { + var self = this; + var result = []; + CONDITIONS.forEach(function (condition) { + var exists = stanza.find(self.xml, ERR_NS, condition); + if (exists.length) { + result.push(exists[0].tagName); + } + }); + return result[0] || ''; + }, + set: function (value) { + var self = this; + this._CONDITIONS.forEach(function (condition) { + var exists = stanza.find(self.xml, ERR_NS, condition); + if (exists.length) { + self.xml.removeChild(exists[0]); + } + }); + if (value) { + var condition = stanza.createElementNS(ERR_NS, value); + condition.setAttribute('xmlns', ERR_NS); + this.xml.appendChild(condition); + } + } + }, + seeOtherHost: { + get: function () { + return stanza.getSubText(this.xml, ERR_NS, 'see-other-host'); + }, + set: function (value) { + this.condition = 'see-other-host'; + stanza.setSubText(this.xml, ERR_NS, 'see-other-host', value); + } + }, + $text: { + get: function () { + return stanza.getSubLangText(this.xml, ERR_NS, 'text', this.lang); + } + }, + text: { + get: function () { + var text = this.$text; + return text[this.lang] || ''; + }, + set: function (value) { + stanza.setSubLangText(this.xml, ERR_NS, 'text', value, this.lang); + } + } + } +}); + +},{"jxt":77,"underscore":96}],50:[function(require,module,exports){ +var stanza = require('jxt'); + +var StreamFeatures = module.exports = stanza.define({ + name: 'streamFeatures', + namespace: 'http://etherx.jabber.org/streams', + element: 'features', + topLevel: true, + fields: { + features: { + get: function () { + return this._extensions; + } + } + } +}); + +var RosterVerFeature = stanza.define({ + name: 'rosterVersioning', + namespace: 'urn:xmpp:features:rosterver', + element: 'ver' +}); + +var SubscriptionPreApprovalFeature = stanza.define({ + name: 'subscriptionPreApproval', + namespace: 'urn:xmpp:features:pre-approval', + element: 'sub' +}); + + +stanza.extend(StreamFeatures, RosterVerFeature); +stanza.extend(StreamFeatures, SubscriptionPreApprovalFeature); + +},{"jxt":77}],51:[function(require,module,exports){ +var stanza = require('jxt'); +var util = require('./util'); +var Iq = require('./iq'); + +var EntityTime = module.exports = stanza.define({ + name: 'time', + namespace: 'urn:xmpp:time', + element: 'time', + fields: { + utc: util.dateSub('urn:xmpp:time', 'utc'), + tzo: { + get: function () { + var split, hrs, min; + var sign = -1; + var formatted = stanza.getSubText(this.xml, this._NS, 'tzo'); + + if (!formatted) { + return 0; + } + if (formatted.charAt(0) === '-') { + sign = 1; + formatted = formatted.slice(1); + } + split = formatted.split(':'); + hrs = parseInt(split[0], 10); + min = parseInt(split[1], 10); + return (hrs * 60 + min) * sign; + }, + set: function (value) { + var hrs, min; + var formatted = '-'; + if (typeof value === 'number') { + if (value < 0) { + value = -value; + formatted = '+'; + } + hrs = value / 60; + min = value % 60; + formatted += (hrs < 10 ? '0' : '') + hrs + ':' + (min < 10 ? '0' : '') + min; + } else { + formatted = value; + } + stanza.setSubText(this.xml, this._NS, 'tzo', formatted); + } + } + } +}); + + +stanza.extend(Iq, EntityTime); + +},{"./iq":35,"./util":52,"jxt":77}],52:[function(require,module,exports){ +var stanza = require('jxt'); +var JID = require('../jid'); +var XML_NS = 'http://www.w3.org/XML/1998/namespace'; + + +exports.langAttribute = stanza.field( + function (xml) { + return xml.getAttributeNS(XML_NS, 'lang') || ''; + }, + function (xml, value) { + xml.setAttributeNS(XML_NS, 'lang', value); + } +); + +exports.jidAttribute = stanza.field( + function (xml, attr) { + return new JID(stanza.getAttribute(xml, attr)); + }, + function (xml, attr, value) { + stanza.setAttribute(xml, attr, (value || '').toString()); + } +); + +exports.jidSub = stanza.field( + function (xml, NS, sub) { + return new JID(stanza.getSubText(xml, NS, sub)); + }, + function (xml, NS, sub, value) { + stanza.setSubText(xml, NS, sub, (value || '').toString()); + } +); + +exports.b64Text = stanza.field( + function (xml) { + if (xml.textContent && xml.textContent != '=') { + return atob(xml.textContent); + } + return ''; + }, + function (xml, value) { + xml.textContent = btoa(value) || '='; + } +); + +exports.dateAttribute = stanza.field( + function (xml, attr) { + return new Date(stanza.getAttribute(xml, attr) || Date.now()); + }, + function (xml, attr, value) { + if (!value) return; + stanza.setAttribute(xml, attr, value.toISOString()); + } +); + +exports.dateSub = stanza.field( + function (xml, NS, sub) { + return new Date(stanza.getSubText(xml, NS, sub) || Date.now()); + }, + function (xml, NS, sub, value) { + if (!value) return; + stanza.setSubText(xml, NS, sub, value.toISOString()); + } +); + +exports.numberAttribute = stanza.field( + function (xml, attr, defaultVal) { + return parseInt(stanza.getAttribute(xml, attr, defaultVal), 10); + }, + function (xml, attr, value) { + stanza.setAttribute(xml, attr, value.toString()); + } +); + +exports.numberSub = stanza.field( + function (xml, NS, sub, defaultVal) { + return parseInt(stanza.getSubText(xml, NS, sub, defaultVal), 10); + }, + function (xml, NS, sub, value) { + stanza.setSubText(xml, NS, sub, value.toString()); + } +); + +},{"../jid":3,"jxt":77}],53:[function(require,module,exports){ +var stanza = require('jxt'); +var Iq = require('./iq'); + +var NS = 'jabber:iq:version'; + +var Version = module.exports = stanza.define({ + name: 'version', + namespace: NS, + element: 'query', + fields: { + name: stanza.subText(NS, 'name'), + version: stanza.subText(NS, 'version'), + os: stanza.subText(NS, 'os') + } +}); + +stanza.extend(Iq, Version); + +},{"./iq":35,"jxt":77}],54:[function(require,module,exports){ +var stanza = require('jxt'); +var Iq = require('./iq'); + + +stanza.add(Iq, 'visible', stanza.boolSub('urn:xmpp:invisible:0', 'visible')); +stanza.add(Iq, 'invisible', stanza.boolSub('urn:xmpp:invisible:0', 'invisible')); + +},{"./iq":35,"jxt":77}],55:[function(require,module,exports){ +var _ = require('underscore'); +var WildEmitter = require('wildemitter'); +var async = require('async'); +var Stream = require('./stanza/stream'); +var Message = require('./stanza/message'); +var Presence = require('./stanza/presence'); +var Iq = require('./stanza/iq'); +var StreamManagement = require('./sm'); +var uuid = require('node-uuid'); + + +function WSConnection() { + var self = this; + + WildEmitter.call(this); + + self.sm = new StreamManagement(self); + + self.sendQueue = async.queue(function (data, cb) { + if (self.conn) { + self.emit('raw:outgoing', data); + + self.sm.track(data); + + if (typeof data !== 'string') { + data = data.toString(); + } + + self.conn.send(data); + } + cb(); + }, 1); + + function wrap(data) { + var result = [self.streamStart, data, self.streamEnd].join(''); + return result; + } + + function parse(data) { + var nodes = (self.parser.parseFromString(data, 'application/xml')).childNodes; + for (var i = 0; i < nodes.length; i++) { + if (nodes[i].nodeType === 1) { + return nodes[i]; + } + } + } + + self.on('connected', function () { + self.send([ + '' + ].join(' ')); + }); + + self.on('raw:incoming', function (data) { + var streamData, ended; + + data = data.trim(); + data = data.replace(/^(\s*<\?.*\?>\s*)*/, ''); + if (data === '') { + return; + } + + if (data.match(self.streamEnd)) { + return self.disconnect(); + } else if (self.hasStream) { + try { + streamData = new Stream({}, parse(wrap(data))); + } catch (e) { + return self.disconnect(); + } + } else { + // Inspect start of stream element to get NS prefix name + var parts = data.match(/^<(\S+:)?(\S+) /); + self.streamStart = data; + self.streamEnd = ''; + + ended = false; + try { + streamData = new Stream({}, parse(data + self.streamEnd)); + } catch (e) { + try { + streamData = new Stream({}, parse(data)); + ended = true; + } catch (e2) { + return self.disconnect(); + } + } + + self.hasStream = true; + self.stream = streamData; + self.emit('stream:start', streamData); + } + + _.each(streamData._extensions, function (stanzaObj) { + if (!stanzaObj.lang) { + stanzaObj.lang = self.stream.lang; + } + + if (stanzaObj._name === 'message' || stanzaObj._name === 'presence' || stanzaObj._name === 'iq') { + self.sm.handle(stanzaObj); + self.emit('stanza', stanzaObj); + } + self.emit(stanzaObj._eventname || stanzaObj._name, stanzaObj); + self.emit('stream:data', stanzaObj); + + if (stanzaObj.id) { + self.emit('id:' + stanzaObj.id, stanzaObj); + } + }); + + if (ended) { + self.emit('stream:end'); + } + }); +} + +WSConnection.prototype = Object.create(WildEmitter.prototype, { + constructor: { + value: WSConnection + } +}); + +WSConnection.prototype.connect = function (opts) { + var self = this; + + self.config = opts; + + self.hasStream = false; + self.streamStart = ''; + self.streamEnd = ''; + self.parser = new DOMParser(); + self.serializer = new XMLSerializer(); + + self.conn = new WebSocket(opts.wsURL, 'xmpp'); + self.conn.onerror = function (e) { + e.preventDefault(); + self.emit('disconnected', self); + return false; + }; + + self.conn.onclose = function () { + self.emit('disconnected', self); + }; + + self.conn.onopen = function () { + self.sm.started = false; + self.emit('connected', self); + }; + + self.conn.onmessage = function (wsMsg) { + self.emit('raw:incoming', wsMsg.data); + }; +}; + +WSConnection.prototype.disconnect = function () { + if (this.conn) { + if (this.hasStream) { + this.conn.send(''); + this.emit('raw:outgoing', ''); + this.emit('stream:end'); + } + this.hasStream = false; + this.conn.close(); + this.stream = undefined; + this.conn = undefined; + this.sm.failed(); + } +}; + +WSConnection.prototype.restart = function () { + var self = this; + self.hasStream = false; + self.send([ + '' + ].join(' ')); +}; + +WSConnection.prototype.send = function (data) { + this.sendQueue.push(data); +}; + + +module.exports = WSConnection; + +},{"./sm":22,"./stanza/iq":35,"./stanza/message":37,"./stanza/presence":39,"./stanza/stream":48,"async":56,"node-uuid":82,"underscore":96,"wildemitter":97}],56:[function(require,module,exports){ +var process=require("__browserify_process");/*global setImmediate: false, setTimeout: false, console: false */ +(function () { + + var async = {}; + + // global on the server, window in the browser + var root, previous_async; + + root = this; + if (root != null) { + previous_async = root.async; + } + + async.noConflict = function () { + root.async = previous_async; + return async; + }; + + function only_once(fn) { + var called = false; + return function() { + if (called) throw new Error("Callback was already called."); + called = true; + fn.apply(root, arguments); + } + } + + //// cross-browser compatiblity functions //// + + var _each = function (arr, iterator) { + if (arr.forEach) { + return arr.forEach(iterator); + } + for (var i = 0; i < arr.length; i += 1) { + iterator(arr[i], i, arr); + } + }; + + var _map = function (arr, iterator) { + if (arr.map) { + return arr.map(iterator); + } + var results = []; + _each(arr, function (x, i, a) { + results.push(iterator(x, i, a)); + }); + return results; + }; + + var _reduce = function (arr, iterator, memo) { + if (arr.reduce) { + return arr.reduce(iterator, memo); + } + _each(arr, function (x, i, a) { + memo = iterator(memo, x, i, a); + }); + return memo; + }; + + var _keys = function (obj) { + if (Object.keys) { + return Object.keys(obj); + } + var keys = []; + for (var k in obj) { + if (obj.hasOwnProperty(k)) { + keys.push(k); + } + } + return keys; + }; + + //// exported async module functions //// + + //// nextTick implementation with browser-compatible fallback //// + if (typeof process === 'undefined' || !(process.nextTick)) { + if (typeof setImmediate === 'function') { + async.nextTick = function (fn) { + // not a direct alias for IE10 compatibility + setImmediate(fn); + }; + async.setImmediate = async.nextTick; + } + else { + async.nextTick = function (fn) { + setTimeout(fn, 0); + }; + async.setImmediate = async.nextTick; + } + } + else { + async.nextTick = process.nextTick; + if (typeof setImmediate !== 'undefined') { + async.setImmediate = setImmediate; + } + else { + async.setImmediate = async.nextTick; + } + } + + async.each = function (arr, iterator, callback) { + callback = callback || function () {}; + if (!arr.length) { + return callback(); + } + var completed = 0; + _each(arr, function (x) { + iterator(x, only_once(function (err) { + if (err) { + callback(err); + callback = function () {}; + } + else { + completed += 1; + if (completed >= arr.length) { + callback(null); + } + } + })); + }); + }; + async.forEach = async.each; + + async.eachSeries = function (arr, iterator, callback) { + callback = callback || function () {}; + if (!arr.length) { + return callback(); + } + var completed = 0; + var iterate = function () { + iterator(arr[completed], function (err) { + if (err) { + callback(err); + callback = function () {}; + } + else { + completed += 1; + if (completed >= arr.length) { + callback(null); + } + else { + iterate(); + } + } + }); + }; + iterate(); + }; + async.forEachSeries = async.eachSeries; + + async.eachLimit = function (arr, limit, iterator, callback) { + var fn = _eachLimit(limit); + fn.apply(null, [arr, iterator, callback]); + }; + async.forEachLimit = async.eachLimit; + + var _eachLimit = function (limit) { + + return function (arr, iterator, callback) { + callback = callback || function () {}; + if (!arr.length || limit <= 0) { + return callback(); + } + var completed = 0; + var started = 0; + var running = 0; + + (function replenish () { + if (completed >= arr.length) { + return callback(); + } + + while (running < limit && started < arr.length) { + started += 1; + running += 1; + iterator(arr[started - 1], function (err) { + if (err) { + callback(err); + callback = function () {}; + } + else { + completed += 1; + running -= 1; + if (completed >= arr.length) { + callback(); + } + else { + replenish(); + } + } + }); + } + })(); + }; + }; + + + var doParallel = function (fn) { + return function () { + var args = Array.prototype.slice.call(arguments); + return fn.apply(null, [async.each].concat(args)); + }; + }; + var doParallelLimit = function(limit, fn) { + return function () { + var args = Array.prototype.slice.call(arguments); + return fn.apply(null, [_eachLimit(limit)].concat(args)); + }; + }; + var doSeries = function (fn) { + return function () { + var args = Array.prototype.slice.call(arguments); + return fn.apply(null, [async.eachSeries].concat(args)); + }; + }; + + + var _asyncMap = function (eachfn, arr, iterator, callback) { + var results = []; + arr = _map(arr, function (x, i) { + return {index: i, value: x}; + }); + eachfn(arr, function (x, callback) { + iterator(x.value, function (err, v) { + results[x.index] = v; + callback(err); + }); + }, function (err) { + callback(err, results); + }); + }; + async.map = doParallel(_asyncMap); + async.mapSeries = doSeries(_asyncMap); + async.mapLimit = function (arr, limit, iterator, callback) { + return _mapLimit(limit)(arr, iterator, callback); + }; + + var _mapLimit = function(limit) { + return doParallelLimit(limit, _asyncMap); + }; + + // reduce only has a series version, as doing reduce in parallel won't + // work in many situations. + async.reduce = function (arr, memo, iterator, callback) { + async.eachSeries(arr, function (x, callback) { + iterator(memo, x, function (err, v) { + memo = v; + callback(err); + }); + }, function (err) { + callback(err, memo); + }); + }; + // inject alias + async.inject = async.reduce; + // foldl alias + async.foldl = async.reduce; + + async.reduceRight = function (arr, memo, iterator, callback) { + var reversed = _map(arr, function (x) { + return x; + }).reverse(); + async.reduce(reversed, memo, iterator, callback); + }; + // foldr alias + async.foldr = async.reduceRight; + + var _filter = function (eachfn, arr, iterator, callback) { + var results = []; + arr = _map(arr, function (x, i) { + return {index: i, value: x}; + }); + eachfn(arr, function (x, callback) { + iterator(x.value, function (v) { + if (v) { + results.push(x); + } + callback(); + }); + }, function (err) { + callback(_map(results.sort(function (a, b) { + return a.index - b.index; + }), function (x) { + return x.value; + })); + }); + }; + async.filter = doParallel(_filter); + async.filterSeries = doSeries(_filter); + // select alias + async.select = async.filter; + async.selectSeries = async.filterSeries; + + var _reject = function (eachfn, arr, iterator, callback) { + var results = []; + arr = _map(arr, function (x, i) { + return {index: i, value: x}; + }); + eachfn(arr, function (x, callback) { + iterator(x.value, function (v) { + if (!v) { + results.push(x); + } + callback(); + }); + }, function (err) { + callback(_map(results.sort(function (a, b) { + return a.index - b.index; + }), function (x) { + return x.value; + })); + }); + }; + async.reject = doParallel(_reject); + async.rejectSeries = doSeries(_reject); + + var _detect = function (eachfn, arr, iterator, main_callback) { + eachfn(arr, function (x, callback) { + iterator(x, function (result) { + if (result) { + main_callback(x); + main_callback = function () {}; + } + else { + callback(); + } + }); + }, function (err) { + main_callback(); + }); + }; + async.detect = doParallel(_detect); + async.detectSeries = doSeries(_detect); + + async.some = function (arr, iterator, main_callback) { + async.each(arr, function (x, callback) { + iterator(x, function (v) { + if (v) { + main_callback(true); + main_callback = function () {}; + } + callback(); + }); + }, function (err) { + main_callback(false); + }); + }; + // any alias + async.any = async.some; + + async.every = function (arr, iterator, main_callback) { + async.each(arr, function (x, callback) { + iterator(x, function (v) { + if (!v) { + main_callback(false); + main_callback = function () {}; + } + callback(); + }); + }, function (err) { + main_callback(true); + }); + }; + // all alias + async.all = async.every; + + async.sortBy = function (arr, iterator, callback) { + async.map(arr, function (x, callback) { + iterator(x, function (err, criteria) { + if (err) { + callback(err); + } + else { + callback(null, {value: x, criteria: criteria}); + } + }); + }, function (err, results) { + if (err) { + return callback(err); + } + else { + var fn = function (left, right) { + var a = left.criteria, b = right.criteria; + return a < b ? -1 : a > b ? 1 : 0; + }; + callback(null, _map(results.sort(fn), function (x) { + return x.value; + })); + } + }); + }; + + async.auto = function (tasks, callback) { + callback = callback || function () {}; + var keys = _keys(tasks); + if (!keys.length) { + return callback(null); + } + + var results = {}; + + var listeners = []; + var addListener = function (fn) { + listeners.unshift(fn); + }; + var removeListener = function (fn) { + for (var i = 0; i < listeners.length; i += 1) { + if (listeners[i] === fn) { + listeners.splice(i, 1); + return; + } + } + }; + var taskComplete = function () { + _each(listeners.slice(0), function (fn) { + fn(); + }); + }; + + addListener(function () { + if (_keys(results).length === keys.length) { + callback(null, results); + callback = function () {}; + } + }); + + _each(keys, function (k) { + var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k]; + var taskCallback = function (err) { + var args = Array.prototype.slice.call(arguments, 1); + if (args.length <= 1) { + args = args[0]; + } + if (err) { + var safeResults = {}; + _each(_keys(results), function(rkey) { + safeResults[rkey] = results[rkey]; + }); + safeResults[k] = args; + callback(err, safeResults); + // stop subsequent errors hitting callback multiple times + callback = function () {}; + } + else { + results[k] = args; + async.setImmediate(taskComplete); + } + }; + var requires = task.slice(0, Math.abs(task.length - 1)) || []; + var ready = function () { + return _reduce(requires, function (a, x) { + return (a && results.hasOwnProperty(x)); + }, true) && !results.hasOwnProperty(k); + }; + if (ready()) { + task[task.length - 1](taskCallback, results); + } + else { + var listener = function () { + if (ready()) { + removeListener(listener); + task[task.length - 1](taskCallback, results); + } + }; + addListener(listener); + } + }); + }; + + async.waterfall = function (tasks, callback) { + callback = callback || function () {}; + if (tasks.constructor !== Array) { + var err = new Error('First argument to waterfall must be an array of functions'); + return callback(err); + } + if (!tasks.length) { + return callback(); + } + var wrapIterator = function (iterator) { + return function (err) { + if (err) { + callback.apply(null, arguments); + callback = function () {}; + } + else { + var args = Array.prototype.slice.call(arguments, 1); + var next = iterator.next(); + if (next) { + args.push(wrapIterator(next)); + } + else { + args.push(callback); + } + async.setImmediate(function () { + iterator.apply(null, args); + }); + } + }; + }; + wrapIterator(async.iterator(tasks))(); + }; + + var _parallel = function(eachfn, tasks, callback) { + callback = callback || function () {}; + if (tasks.constructor === Array) { + eachfn.map(tasks, function (fn, callback) { + if (fn) { + fn(function (err) { + var args = Array.prototype.slice.call(arguments, 1); + if (args.length <= 1) { + args = args[0]; + } + callback.call(null, err, args); + }); + } + }, callback); + } + else { + var results = {}; + eachfn.each(_keys(tasks), function (k, callback) { + tasks[k](function (err) { + var args = Array.prototype.slice.call(arguments, 1); + if (args.length <= 1) { + args = args[0]; + } + results[k] = args; + callback(err); + }); + }, function (err) { + callback(err, results); + }); + } + }; + + async.parallel = function (tasks, callback) { + _parallel({ map: async.map, each: async.each }, tasks, callback); + }; + + async.parallelLimit = function(tasks, limit, callback) { + _parallel({ map: _mapLimit(limit), each: _eachLimit(limit) }, tasks, callback); + }; + + async.series = function (tasks, callback) { + callback = callback || function () {}; + if (tasks.constructor === Array) { + async.mapSeries(tasks, function (fn, callback) { + if (fn) { + fn(function (err) { + var args = Array.prototype.slice.call(arguments, 1); + if (args.length <= 1) { + args = args[0]; + } + callback.call(null, err, args); + }); + } + }, callback); + } + else { + var results = {}; + async.eachSeries(_keys(tasks), function (k, callback) { + tasks[k](function (err) { + var args = Array.prototype.slice.call(arguments, 1); + if (args.length <= 1) { + args = args[0]; + } + results[k] = args; + callback(err); + }); + }, function (err) { + callback(err, results); + }); + } + }; + + async.iterator = function (tasks) { + var makeCallback = function (index) { + var fn = function () { + if (tasks.length) { + tasks[index].apply(null, arguments); + } + return fn.next(); + }; + fn.next = function () { + return (index < tasks.length - 1) ? makeCallback(index + 1): null; + }; + return fn; + }; + return makeCallback(0); + }; + + async.apply = function (fn) { + var args = Array.prototype.slice.call(arguments, 1); + return function () { + return fn.apply( + null, args.concat(Array.prototype.slice.call(arguments)) + ); + }; + }; + + var _concat = function (eachfn, arr, fn, callback) { + var r = []; + eachfn(arr, function (x, cb) { + fn(x, function (err, y) { + r = r.concat(y || []); + cb(err); + }); + }, function (err) { + callback(err, r); + }); + }; + async.concat = doParallel(_concat); + async.concatSeries = doSeries(_concat); + + async.whilst = function (test, iterator, callback) { + if (test()) { + iterator(function (err) { + if (err) { + return callback(err); + } + async.whilst(test, iterator, callback); + }); + } + else { + callback(); + } + }; + + async.doWhilst = function (iterator, test, callback) { + iterator(function (err) { + if (err) { + return callback(err); + } + if (test()) { + async.doWhilst(iterator, test, callback); + } + else { + callback(); + } + }); + }; + + async.until = function (test, iterator, callback) { + if (!test()) { + iterator(function (err) { + if (err) { + return callback(err); + } + async.until(test, iterator, callback); + }); + } + else { + callback(); + } + }; + + async.doUntil = function (iterator, test, callback) { + iterator(function (err) { + if (err) { + return callback(err); + } + if (!test()) { + async.doUntil(iterator, test, callback); + } + else { + callback(); + } + }); + }; + + async.queue = function (worker, concurrency) { + if (concurrency === undefined) { + concurrency = 1; + } + function _insert(q, data, pos, callback) { + if(data.constructor !== Array) { + data = [data]; + } + _each(data, function(task) { + var item = { + data: task, + callback: typeof callback === 'function' ? callback : null + }; + + if (pos) { + q.tasks.unshift(item); + } else { + q.tasks.push(item); + } + + if (q.saturated && q.tasks.length === concurrency) { + q.saturated(); + } + async.setImmediate(q.process); + }); + } + + var workers = 0; + var q = { + tasks: [], + concurrency: concurrency, + saturated: null, + empty: null, + drain: null, + push: function (data, callback) { + _insert(q, data, false, callback); + }, + unshift: function (data, callback) { + _insert(q, data, true, callback); + }, + process: function () { + if (workers < q.concurrency && q.tasks.length) { + var task = q.tasks.shift(); + if (q.empty && q.tasks.length === 0) { + q.empty(); + } + workers += 1; + var next = function () { + workers -= 1; + if (task.callback) { + task.callback.apply(task, arguments); + } + if (q.drain && q.tasks.length + workers === 0) { + q.drain(); + } + q.process(); + }; + var cb = only_once(next); + worker(task.data, cb); + } + }, + length: function () { + return q.tasks.length; + }, + running: function () { + return workers; + } + }; + return q; + }; + + async.cargo = function (worker, payload) { + var working = false, + tasks = []; + + var cargo = { + tasks: tasks, + payload: payload, + saturated: null, + empty: null, + drain: null, + push: function (data, callback) { + if(data.constructor !== Array) { + data = [data]; + } + _each(data, function(task) { + tasks.push({ + data: task, + callback: typeof callback === 'function' ? callback : null + }); + if (cargo.saturated && tasks.length === payload) { + cargo.saturated(); + } + }); + async.setImmediate(cargo.process); + }, + process: function process() { + if (working) return; + if (tasks.length === 0) { + if(cargo.drain) cargo.drain(); + return; + } + + var ts = typeof payload === 'number' + ? tasks.splice(0, payload) + : tasks.splice(0); + + var ds = _map(ts, function (task) { + return task.data; + }); + + if(cargo.empty) cargo.empty(); + working = true; + worker(ds, function () { + working = false; + + var args = arguments; + _each(ts, function (data) { + if (data.callback) { + data.callback.apply(null, args); + } + }); + + process(); + }); + }, + length: function () { + return tasks.length; + }, + running: function () { + return working; + } + }; + return cargo; + }; + + var _console_fn = function (name) { + return function (fn) { + var args = Array.prototype.slice.call(arguments, 1); + fn.apply(null, args.concat([function (err) { + var args = Array.prototype.slice.call(arguments, 1); + if (typeof console !== 'undefined') { + if (err) { + if (console.error) { + console.error(err); + } + } + else if (console[name]) { + _each(args, function (x) { + console[name](x); + }); + } + } + }])); + }; + }; + async.log = _console_fn('log'); + async.dir = _console_fn('dir'); + /*async.info = _console_fn('info'); + async.warn = _console_fn('warn'); + async.error = _console_fn('error');*/ + + async.memoize = function (fn, hasher) { + var memo = {}; + var queues = {}; + hasher = hasher || function (x) { + return x; + }; + var memoized = function () { + var args = Array.prototype.slice.call(arguments); + var callback = args.pop(); + var key = hasher.apply(null, args); + if (key in memo) { + callback.apply(null, memo[key]); + } + else if (key in queues) { + queues[key].push(callback); + } + else { + queues[key] = [callback]; + fn.apply(null, args.concat([function () { + memo[key] = arguments; + var q = queues[key]; + delete queues[key]; + for (var i = 0, l = q.length; i < l; i++) { + q[i].apply(null, arguments); + } + }])); + } + }; + memoized.memo = memo; + memoized.unmemoized = fn; + return memoized; + }; + + async.unmemoize = function (fn) { + return function () { + return (fn.unmemoized || fn).apply(null, arguments); + }; + }; + + async.times = function (count, iterator, callback) { + var counter = []; + for (var i = 0; i < count; i++) { + counter.push(i); + } + return async.map(counter, iterator, callback); + }; + + async.timesSeries = function (count, iterator, callback) { + var counter = []; + for (var i = 0; i < count; i++) { + counter.push(i); + } + return async.mapSeries(counter, iterator, callback); + }; + + async.compose = function (/* functions... */) { + var fns = Array.prototype.reverse.call(arguments); + return function () { + var that = this; + var args = Array.prototype.slice.call(arguments); + var callback = args.pop(); + async.reduce(fns, args, function (newargs, fn, cb) { + fn.apply(that, newargs.concat([function () { + var err = arguments[0]; + var nextargs = Array.prototype.slice.call(arguments, 1); + cb(err, nextargs); + }])) + }, + function (err, results) { + callback.apply(that, [err].concat(results)); + }); + }; + }; + + var _applyEach = function (eachfn, fns /*args...*/) { + var go = function () { + var that = this; + var args = Array.prototype.slice.call(arguments); + var callback = args.pop(); + return eachfn(fns, function (fn, cb) { + fn.apply(that, args.concat([cb])); + }, + callback); + }; + if (arguments.length > 2) { + var args = Array.prototype.slice.call(arguments, 2); + return go.apply(this, args); + } + else { + return go; + } + }; + async.applyEach = doParallel(_applyEach); + async.applyEachSeries = doSeries(_applyEach); + + async.forever = function (fn, callback) { + function next(err) { + if (err) { + if (callback) { + return callback(err); + } + throw err; + } + fn(next); + } + next(); + }; + + // AMD / RequireJS + if (typeof define !== 'undefined' && define.amd) { + define([], function () { + return async; + }); + } + // Node.js + else if (typeof module !== 'undefined' && module.exports) { + module.exports = async; + } + // included directly via