1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00
Files
matrix-js-sdk/dist/0.1.1/browser-matrix-0.1.1.min.js
2015-06-23 15:42:08 +01:00

2 lines
54 KiB
JavaScript

!function e(t,n,r){function o(s,u){if(!n[s]){if(!t[s]){var a="function"==typeof require&&require;if(!u&&a)return a(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var p=n[s]={exports:{}};t[s][0].call(p.exports,function(e){var n=t[s][1][e];return o(n?n:e)},p,p.exports,e,t,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(e,t){"use strict";function n(e){if(T.checkObjectHasKeys(e,["baseUrl","request"]),T.checkObjectHasNoAdditionalKeys(e,["baseUrl","request","accessToken","userId","store","scheduler"]),this.store=e.store||new _,this.scheduler=e.scheduler,this.scheduler){var t=this;this.scheduler.setProcessFunction(function(e){return o(t,e)})}this.fromToken=void 0,this.clientRunning=!1;var n={baseUrl:e.baseUrl,accessToken:e.accessToken,request:e.request,prefix:g.PREFIX_V1,onlyData:!0};this.credentials={userId:e.userId||null},this._http=new g.MatrixHttpApi(n),this._syncingRooms={}}function r(e,t,n,r){var i,s=y.defer();return e.scheduler&&(i=e.scheduler.queueEvent(n)),i||(i=o(e,n)),i.done(function(e){if(t){var o=e.event_id,i=T.findElement(t.timeline,function(e){return e.getId()===o},!0);i?T.removeElement(t.timeline,function(e){return e.getId()===n.getId()},!0):(n.event.event_id=e.event_id,n.status=null)}d(r,s,e)},function(e){n.status=w.NOT_SENT,l(r,s,e)}),s.promise}function o(e,t){var n,r={$roomId:t.getRoomId(),$eventType:t.getType(),$stateKey:t.getStateKey(),$txnId:t._txnId?t._txnId:(new Date).getTime()};if(t.isState()){var o="/rooms/$roomId/state/$eventType";t.getStateKey()&&t.getStateKey().length>0&&(o="/rooms/$roomId/state/$eventType/$stateKey"),n=T.encodeUri(o,r)}else n=T.encodeUri("/rooms/$roomId/send/$eventType/$txnId",r);return e._http.authedRequest(void 0,"PUT",n,void 0,t.getContent())}function i(e,t,n,r,o,i){T.isFunction(o)&&(i=o,o=void 0);var s=T.encodeUri("/rooms/$roomId/state/m.room.member/$userId",{$roomId:t,$userId:n});return e._http.authedRequest(i,"PUT",s,void 0,{membership:r,reason:o})}function s(e,t,n,r,o,i){T.isFunction(o)&&(i=o,o=void 0);var s=T.encodeUri("/rooms/$room_id/$membership",{$room_id:t,$membership:r});return e._http.authedRequest(i,"POST",s,void 0,{user_id:n,reason:o})}function u(e){var t=e;if(e.clientRunning){var n=!1,r=setTimeout(function(){n=!0,u(e)},4e4);e._http.authedRequest(void 0,"GET","/events",{from:e.fromToken,timeout:3e4}).done(function(e){if(!n){clearTimeout(r);var o=[];if(e&&(o=T.map(e.chunk,function(e){return new b(e)})),!(t.store instanceof _)){var i=0,s={};for(i=0;i<o.length;i++){var c=o[i].getRoomId();c&&(s[c]||(s[c]=[]),s[c].push(o[i]))}var p=T.keys(s);T.forEach(p,function(e){var n=t.store.getRoom(e),r=!1;n||(n=h(t,e),r=!0);var o=n.hasMembershipState(t.credentials.userId,"join");n.addEvents(s[e],"replace"),n.recalculate(t.credentials.userId),r&&(t.store.storeRoom(n),t.emit("Room",n));var i=n.hasMembershipState(t.credentials.userId,"join");!o&&i&&a(t,n)})}e&&(t.fromToken=e.end,T.forEach(o,function(e){t.emit("event",e)})),u(t)}},function(e){n||(clearTimeout(r),t.emit("syncError",e),setTimeout(function(){u(t)},2e3))})}}function a(e,t){if(e._syncingRooms[t.roomId])return e._syncingRooms[t.roomId];var n=y.defer();return e._syncingRooms[t.roomId]=n.promise,e.roomInitialSync(t.roomId,8).done(function(r){t.timeline=[],c(t,r.state,r.messages),t.recalculate(e.credentials.userId),e.store.storeRoom(t),e.emit("Room",t),n.resolve(t),e._syncingRooms[t.roomId]=void 0},function(r){n.reject(r),e._syncingRooms[t.roomId]=void 0}),n.promise}function c(e,t,n){var r=T.map(T.deepCopy(t),m),o=T.map(t,m);e.oldState.setStateEvents(r),e.currentState.setStateEvents(o),e.addEventsToTimeline(T.map(n?n.chunk:[],m).reverse(),!0),n&&(e.oldState.paginationToken=n.start)}function p(e,t,n){T.forEach(n,function(n){t.on(n,function(){for(var t=[n],r=0;r<arguments.length;r++)t.push(arguments[r]);e.emit.apply(e,t)})})}function f(e,t){var n=new x(t);return p(e,n,["User.avatarUrl","User.displayName","User.presence"]),n}function h(e,t){var n=new E(t);return p(e,n,["Room.name","Room.timeline"]),p(e,n.currentState,["RoomState.events","RoomState.members","RoomState.newMember"]),n.currentState.on("RoomState.newMember",function(t,n,r){p(e,r,["RoomMember.name","RoomMember.typing","RoomMember.powerLevel","RoomMember.membership"])}),n}function l(e,t,n){e&&e(n),t.reject(n)}function d(e,t,n){e&&e(null,n),t.resolve(n)}function m(e){return new b(e)}var v=e("events").EventEmitter,y=e("q"),g=e("./http-api"),b=e("./models/event").MatrixEvent,w=e("./models/event").EventStatus,_=e("./store/stub"),E=e("./models/room"),x=e("./models/user"),T=e("./utils");T.inherits(n,v),n.prototype.getRoom=function(e){return this.store.getRoom(e)},n.prototype.getRooms=function(){return this.store.getRooms()},n.prototype.createRoom=function(e,t){return this._http.authedRequest(t,"POST","/createRoom",void 0,e)},n.prototype.joinRoom=function(e,t){var n=T.encodeUri("/join/$roomid",{$roomid:e}),r=y.defer(),o=this;return this._http.authedRequest(void 0,"POST",n,void 0,{}).then(function(e){var t=e.room_id,n=h(o,t);return a(o,n)},function(e){l(t,r,e)}).done(function(e){d(t,r,e)},function(e){l(t,r,e)}),r.promise},n.prototype.resendEvent=function(e,t){return e.status=w.SENDING,r(this,t,e)},n.prototype.setRoomName=function(e,t,n){return this.sendStateEvent(e,"m.room.name",{name:t},void 0,n)},n.prototype.setRoomTopic=function(e,t,n){return this.sendStateEvent(e,"m.room.topic",{topic:t},void 0,n)},n.prototype.setPowerLevel=function(e,t,n,r,o){var i={users:{}};r&&"m.room.power_levels"===r.type&&(i=r.content),i.users[t]=n;var s=T.encodeUri("/rooms/$roomId/state/m.room.power_levels",{$roomId:e});return this._http.authedRequest(o,"PUT",s,void 0,i)},n.prototype.getStateEvent=function(e,t,n,r){var o={$roomId:e,$eventType:t,$stateKey:n},i=T.encodeUri("/rooms/$roomId/state/$eventType",o);return void 0!==n&&(i=T.encodeUri(i+"/$stateKey",o)),this._http.authedRequest(r,"GET",i)},n.prototype.sendStateEvent=function(e,t,n,r,o){var i={$roomId:e,$eventType:t,$stateKey:r},s=T.encodeUri("/rooms/$roomId/state/$eventType",i);return void 0!==r&&(s=T.encodeUri(s+"/$stateKey",i)),this._http.authedRequest(o,"PUT",s,void 0,n)},n.prototype.sendEvent=function(e,t,n,o,i){T.isFunction(o)&&(i=o,o=void 0),o||(o="m"+(new Date).getTime());var s=this.getRoom(e),u=new b({event_id:"~"+e+":"+o,user_id:this.credentials.userId,room_id:e,type:t,origin_server_ts:(new Date).getTime(),content:n});return u._txnId=o,s&&(u.status=w.SENDING,s.addEventsToTimeline([u])),r(this,s,u,i)},n.prototype.sendMessage=function(e,t,n,r){return T.isFunction(n)&&(r=n,n=void 0),this.sendEvent(e,"m.room.message",t,n,r)},n.prototype.sendTextMessage=function(e,t,n,r){var o={msgtype:"m.text",body:t};return this.sendMessage(e,o,n,r)},n.prototype.sendEmoteMessage=function(e,t,n,r){var o={msgtype:"m.emote",body:t};return this.sendMessage(e,o,n,r)},n.prototype.sendImageMessage=function(e,t,n,r,o){T.isFunction(r)&&(o=r,r=void 0),r||(r="Image");var i={msgtype:"m.image",url:t,info:n,body:r};return this.sendMessage(e,i,o)},n.prototype.sendHtmlMessage=function(e,t,n,r){var o={msgtype:"m.text",format:"org.matrix.custom.html",body:t,formatted_body:n};return this.sendMessage(e,o,r)},n.prototype.sendTyping=function(e,t,n,r){var o=T.encodeUri("/rooms/$roomId/typing/$userId",{$roomId:e,$userId:this.credentials.userId}),i={typing:t};return t&&(i.timeout=n?n:2e4),this._http.authedRequest(r,"PUT",o,void 0,i)},n.prototype.redactEvent=function(e,t,n){var r=T.encodeUri("/rooms/$roomId/redact/$eventId",{$roomId:e,$eventId:t});return this._http.authedRequest(n,"POST",r,void 0,{})},n.prototype.invite=function(e,t,n){return s(this,e,t,"invite",void 0,n)},n.prototype.leave=function(e,t){return s(this,e,void 0,"leave",void 0,t)},n.prototype.ban=function(e,t,n,r){return s(this,e,t,"ban",n,r)},n.prototype.unban=function(e,t,n){return i(this,e,t,"leave",void 0,n)},n.prototype.kick=function(e,t,n,r){return i(this,e,t,"leave",n,r)},n.prototype.getProfileInfo=function(e,t,n){T.isFunction(t)&&(n=t,t=void 0);var r=t?T.encodeUri("/profile/$userId/$info",{$userId:e,$info:t}):T.encodeUri("/profile/$userId",{$userId:e});return this._http.authedRequest(n,"GET",r)},n.prototype.setProfileInfo=function(e,t,n){var r=T.encodeUri("/profile/$userId/$info",{$userId:this.credentials.userId,$info:e});return this._http.authedRequest(n,"PUT",r,void 0,t)},n.prototype.setDisplayName=function(e,t){return this.setProfileInfo("displayname",{displayname:e},t)},n.prototype.setAvatarUrl=function(e,t){return this.setProfileInfo("avatar_url",{avatar_url:e},t)},n.prototype.getThreePids=function(e){var t="/account/3pid";return this._http.authedRequestWithPrefix(e,"GET",t,void 0,void 0,g.PREFIX_V2_ALPHA)},n.prototype.addThreePid=function(e,t,n){var r="/account/3pid",o={threePidCreds:e,bind:t};return this._http.authedRequestWithPrefix(n,"POST",r,null,o,g.PREFIX_V2_ALPHA)},n.prototype.setPresence=function(e,t){var n=T.encodeUri("/presence/$userId/status",{$userId:this.credentials.userId}),r=["offline","online","unavailable"];if(-1==r.indexOf(e))throw new Error("Bad presence value: "+e);var o={presence:e};return this._http.authedRequest(t,"PUT",n,void 0,o)},n.prototype.publicRooms=function(e){return this._http.request(e,"GET","/publicRooms")},n.prototype.registerFlows=function(e){return this._http.request(e,"GET","/register")},n.prototype.loginFlows=function(e){return this._http.request(e,"GET","/login")},n.prototype.resolveRoomAlias=function(e,t){var n=T.encodeUri("/directory/room/$alias",{$alias:e});return this._http.request(t,"GET",n)},n.prototype.roomInitialSync=function(e,t,n){T.isFunction(t)&&(n=t,t=void 0);var r=T.encodeUri("/rooms/$roomId/initialSync",{$roomId:e});return t||(t=30),this._http.authedRequest(n,"GET",r,{limit:t})},n.prototype.roomState=function(e,t){var n=T.encodeUri("/rooms/$roomId/state",{$roomId:e});return this._http.authedRequest(t,"GET",n)},n.prototype.scrollback=function(e,t,n){T.isFunction(t)&&(n=t,t=void 0);var r=T.encodeUri("/rooms/$roomId/messages",{$roomId:e.roomId}),o={from:e.oldState.paginationToken,limit:t||30,dir:"b"},i=y.defer();return this._http.authedRequest(n,"GET",r,o).done(function(t){e.addEventsToTimeline(T.map(t.chunk,m),!0),e.oldState.paginationToken=t.end,d(n,i,e)},function(e){l(n,i,e)}),i.promise},n.prototype.login=function(e,t,n){return t.type=e,this._http.authedRequest(n,"POST","/login",void 0,t)},n.prototype.register=function(e,t,n){return t.type=e,this._http.authedRequest(n,"POST","/register",void 0,t)},n.prototype.loginWithPassword=function(e,t,n){return this.login("m.login.password",{user:e,password:t},n)},n.prototype.pushRules=function(e){return this._http.authedRequest(e,"GET","/pushrules/")},n.prototype.addPushRule=function(e,t,n,r,o){var i=T.encodeUri("/pushrules/"+e+"/$kind/$ruleId",{$kind:t,$ruleId:n});return this._http.authedRequest(o,"PUT",i,void 0,r)},n.prototype.deletePushRule=function(e,t,n,r){var o=T.encodeUri("/pushrules/"+e+"/$kind/$ruleId",{$kind:t,$ruleId:n});return this._http.authedRequest(r,"DELETE",o)},n.prototype.turnServer=function(e){return this._http.authedRequest(e,"GET","/voip/turnServer")},n.prototype.isLoggedIn=function(){return void 0!==this._http.opts.accessToken},n.prototype.startClient=function(e){if(!this.clientRunning){if(this.fromToken)return void u(this);var t=this;this._http.authedRequest(void 0,"GET","/initialSync",{limit:e||12}).done(function(e){var n,r;if(!(t.store instanceof _))for(T.forEach(T.map(e.presence,m),function(e){var n=f(t,e.getContent().user_id);n.setPresenceEvent(e),t.store.storeUser(n)}),n=0;n<e.rooms.length;n++){var o=h(t,e.rooms[n].room_id);e.rooms[n].state||(e.rooms[n].state=[]),"invite"===e.rooms[n].membership&&e.rooms[n].state.push({event_id:"$fake_"+o.roomId,content:{membership:"invite"},state_key:t.credentials.userId,user_id:e.rooms[n].inviter,room_id:o.roomId,type:"m.room.member"}),c(o,e.rooms[n].state,e.rooms[n].messages),o.recalculate(t.credentials.userId),t.store.storeRoom(o),t.emit("Room",o)}if(e){t.fromToken=e.end;var i=[];for(n=0;n<e.presence.length;n++)i.push(new b(e.presence[n]));for(n=0;n<e.rooms.length;n++){if(e.rooms[n].state)for(r=0;r<e.rooms[n].state.length;r++)i.push(new b(e.rooms[n].state[r]));if(e.rooms[n].messages)for(r=0;r<e.rooms[n].messages.chunk.length;r++)i.push(new b(e.rooms[n].messages.chunk[r]))}T.forEach(i,function(e){t.emit("event",e)})}t.clientRunning=!0,t.emit("syncComplete"),u(t)},function(e){t.emit("syncError",e)})}},n.prototype.stopClient=function(){this.clientRunning=!1},t.exports.MatrixClient=n},{"./http-api":2,"./models/event":4,"./models/room":8,"./models/user":9,"./store/stub":12,"./utils":13,events:15,q:17}],2:[function(e,t){"use strict";var n=e("q"),r=e("./utils");t.exports.PREFIX_V1="/_matrix/client/api/v1",t.exports.PREFIX_V2_ALPHA_PREFIX="/_matrix/client/v2_alpha",t.exports.MatrixHttpApi=function(e){r.checkObjectHasKeys(e,["baseUrl","request","prefix"]),e.onlyData=e.onlyData||!1,this.opts=e},t.exports.MatrixHttpApi.prototype={getHttpUriForMxc:function(e,t,n,o){if("string"!=typeof e||!e)return e;if(0!==e.indexOf("mxc://"))return e;var i=e.slice(6),s="/_matrix/media/v1/download/",u={};t&&(u.width=t),n&&(u.height=n),o&&(u.method=o),r.keys(u).length>0&&(s="/_matrix/media/v1/thumbnail/");var a=i.indexOf("#"),c="";return a>=0&&(c=i.substr(a),i=i.substr(0,a)),this.credentials.baseUrl+s+i+(0===r.keys(u).length?"":"?"+r.encodeParams(u))+c},getIdenticonUri:function(e,t,n){if(e){t||(t=96),n||(n=96);var o={width:t,height:n},i=r.encodeUri("/_matrix/media/v1/identicon/$ident",{$ident:e});return this.credentials.baseUrl+i+(0===r.keys(o).length?"":"?"+r.encodeParams(o))}},getContentUri:function(){var e={access_token:this.credentials.accessToken};return{base:this.credentials.baseUrl,path:"/_matrix/media/v1/upload",params:e}},authedRequest:function(e,t,n,r,o){return r||(r={}),r.access_token=this.opts.accessToken,this.request(e,t,n,r,o)},request:function(e,t,n,r,o){return this.requestWithPrefix(e,t,n,r,o,this.opts.prefix)},authedRequestWithPrefix:function(e,t,n,r,o,i){var s=this.opts.baseUrl+i+n;return r||(r={}),r.access_token=this.opts.accessToken,this._request(e,t,s,r,o)},requestWithPrefix:function(e,t,n,r,o,i){var s=this.opts.baseUrl+i+n;return r||(r={}),this._request(e,t,s,r,o)},_request:function(e,t,i,s,u){if(void 0!==e&&!r.isFunction(e))throw Error("Expected callback to be a function but got "+typeof e);var a=n.defer();return this.opts.request({uri:i,method:t,withCredentials:!1,qs:s,body:u,json:!0,_matrix_opts:this.opts},o(a,e,this.opts.onlyData)),a.promise}};var o=function(e,n,r){return n=n||function(){},function(o,i,s){if(!o&&i.statusCode>=400&&(o=new t.exports.MatrixError(s)),o)e.reject(o),n(o);else{var u={code:i.statusCode,headers:i.headers,data:s};e.resolve(r?s:u),n(null,r?s:u)}}};t.exports.MatrixError=function(e){this.name=e.errcode||"Unknown error code",this.message=e.error||"Unknown message",this.data=e},t.exports.MatrixError.prototype=Object.create(Error.prototype),t.exports.MatrixError.prototype.constructor=t.exports.MatrixError},{"./utils":13,q:17}],3:[function(e,t){"use strict";t.exports.MatrixEvent=e("./models/event").MatrixEvent,t.exports.EventStatus=e("./models/event").EventStatus,t.exports.MatrixInMemoryStore=e("./store/memory").MatrixInMemoryStore,t.exports.MatrixHttpApi=e("./http-api").MatrixHttpApi,t.exports.MatrixError=e("./http-api").MatrixError,t.exports.MatrixClient=e("./client").MatrixClient,t.exports.Room=e("./models/room"),t.exports.RoomMember=e("./models/room-member"),t.exports.RoomState=e("./models/room-state"),t.exports.User=e("./models/user"),t.exports.MatrixScheduler=e("./scheduler");var n;t.exports.request=function(e){n=e},t.exports.createClient=function(e){return"string"==typeof e&&(e={baseUrl:e}),e.request=n,e.store=new t.exports.MatrixInMemoryStore,e.scheduler=new t.exports.MatrixScheduler,new t.exports.MatrixClient(e)}},{"./client":1,"./http-api":2,"./models/event":4,"./models/room":8,"./models/room-member":5,"./models/room-state":6,"./models/user":9,"./scheduler":10,"./store/memory":11}],4:[function(e,t){"use strict";t.exports.EventStatus={NOT_SENT:"not_sent",SENDING:"sending"},t.exports.MatrixEvent=function(e){this.event=e||{},this.sender=null,this.target=null,this.status=null,this.forwardLooking=!0},t.exports.MatrixEvent.prototype={getId:function(){return this.event.event_id},getSender:function(){return this.event.user_id},getType:function(){return this.event.type},getRoomId:function(){return this.event.room_id},getTs:function(){return this.event.origin_server_ts},getContent:function(){return this.event.content||{}},getPrevContent:function(){return this.event.prev_content||{}},getDirectionalContent:function(){return this.forwardLooking?this.getContent():this.getPrevContent()},getAge:function(){return this.event.age},getStateKey:function(){return this.event.state_key},isState:function(){return void 0!==this.event.state_key}}},{}],5:[function(e,t){"use strict";function n(e,t){this.roomId=e,this.userId=t,this.typing=!1,this.name=t,this.powerLevel=0,this.powerLevelNorm=0,this.user=null,this.membership=null,this.events={member:null}}function r(e,t,n){var r=t.getDirectionalContent().displayname,o=e.userId;if(!r)return o;if(!n)return r;var s=i.filter(n.getStateEvents("m.room.member"),function(e){return e.getContent().displayname===r&&e.getSender()!==o});return s.length>1?r+" ("+o+")":r}var o=e("events").EventEmitter,i=e("../utils");i.inherits(n,o),n.prototype.setMembershipEvent=function(e,t){if("m.room.member"===e.getType()){this.events.member=e;var n=this.membership;this.membership=e.getDirectionalContent().membership;var o=this.name;this.name=r(this,e,t),n!==this.membership&&this.emit("RoomMember.membership",e,this),o!==this.name&&this.emit("RoomMember.name",e,this)}},n.prototype.setPowerLevelEvent=function(e){if("m.room.power_levels"===e.getType()){var t=e.getContent().users_default||0;i.forEach(i.values(e.getContent().users),function(e){t=Math.max(t,e)});var n=this.powerLevel,r=this.powerLevelNorm;this.powerLevel=e.getContent().users[this.userId]||e.getContent().users_default||0,this.powerLevelNorm=0,t>0&&(this.powerLevelNorm=100*this.powerLevel/t),(n!==this.powerLevel||r!==this.powerLevelNorm)&&this.emit("RoomMember.powerLevel",e,this)}},n.prototype.setTypingEvent=function(e){if("m.typing"===e.getType()){var t=this.typing;this.typing=!1;var n=e.getContent().user_ids;i.isArray(n)&&(-1!==n.indexOf(this.userId)&&(this.typing=!0),t!==this.typing&&this.emit("RoomMember.typing",e,this))}},t.exports=n},{"../utils":13,events:15}],6:[function(e,t){"use strict";function n(e){this.roomId=e,this.members={},this.events={},this.paginationToken=null,this._sentinels={}}var r=e("events").EventEmitter,o=e("../utils"),i=e("./room-member");o.inherits(n,r),n.prototype.getMembers=function(){return o.values(this.members)},n.prototype.getMember=function(e){return this.members[e]||null},n.prototype.getSentinelMember=function(e){return this._sentinels[e]||null},n.prototype.getStateEvents=function(e,t){if(!this.events[e])return void 0===t?[]:null;if(void 0===t)return o.values(this.events[e]);var n=this.events[e][t];return n?n:null},n.prototype.setStateEvents=function(e){var t=this;o.forEach(e,function(e){if(e.getRoomId()===t.roomId&&e.isState())if(void 0===t.events[e.getType()]&&(t.events[e.getType()]={}),t.events[e.getType()][e.getStateKey()]=e,t.emit("RoomState.events",e,t),"m.room.member"===e.getType()){var n=e.getStateKey(),r=t.members[n];r||(r=new i(e.getRoomId(),n),t.emit("RoomState.newMember",e,t,r));var s=new i(e.getRoomId(),n);o.forEach([r,s],function(n){n.setMembershipEvent(e,t);var r=t.getStateEvents("m.room.power_levels","");r&&n.setPowerLevelEvent(r)}),t._sentinels[n]=s,t.members[n]=r,t.emit("RoomState.members",e,t,r)}else if("m.room.power_levels"===e.getType()){var u=o.values(t.members);o.forEach(u,function(t){t.setPowerLevelEvent(e)})}})},n.prototype.setTypingEvent=function(e){o.forEach(o.values(this.members),function(t){t.setTypingEvent(e)})},t.exports=n},{"../utils":13,"./room-member":5,events:15}],7:[function(e,t){"use strict";function n(e,t){this.roomId=e,this.info=t}t.exports=n},{}],8:[function(e,t){"use strict";function n(e){this.roomId=e,this.name=e,this.timeline=[],this.oldState=new i(e),this.currentState=new i(e),this.summary=null}function r(e,t){var n,r=e.currentState.getStateEvents("m.room.aliases")[0];r&&u.isArray(r.getContent().aliases)&&(n=r.getContent().aliases[0]);var o=e.currentState.getStateEvents("m.room.name","");if(o)return o.getContent().name+(n?" ("+n+")":"");if(n)return n;var i=u.filter(e.currentState.getMembers(),function(e){return e.userId!==t});if(0===i.length){var s=e.currentState.getMembers();return 1===s.length?"invite"===s[0].membership?"Room Invite":t:"?"}return 1===i.length?i[0].name:2===i.length?i[0].name+" and "+i[1].name:i[0].name+" and "+(i.length-1)+" others"}var o=e("events").EventEmitter,i=e("./room-state"),s=e("./room-summary"),u=e("../utils");u.inherits(n,o),n.prototype.getMember=function(e){var t=this.currentState.members[e];return t?t:null},n.prototype.getJoinedMembers=function(){return u.filter(this.currentState.getMembers(),function(e){return"join"===e.membership})},n.prototype.hasMembershipState=function(e,t){return u.filter(this.currentState.getMembers(),function(n){return n.membership===t&&n.userId===e}).length>0},n.prototype.addEventsToTimeline=function(e,t){for(var n=t?this.oldState:this.currentState,r=0;r<e.length;r++)e[r].sender=n.getSentinelMember(e[r].getSender()),"m.room.member"===e[r].getType()&&(e[r].target=n.getSentinelMember(e[r].getStateKey())),e[r].isState()&&(t&&(e[r].forwardLooking=!1),n.setStateEvents([e[r]],t)),t?this.timeline.unshift(e[r]):this.timeline.push(e[r]),this.emit("Room.timeline",e[r],this,t)},n.prototype.addEvents=function(e,t){if(t&&-1===["replace","ignore"].indexOf(t))throw new Error("duplicateStrategy MUST be either 'replace' or 'ignore'");for(var n=0;n<e.length;n++)if("m.typing"===e[n].getType())this.currentState.setTypingEvent(e[n]);else{if(t){for(var r=!1,o=0;o<this.timeline.length;o++)if(this.timeline[o].getId()===e[n].getId())if("replace"===t)this.timeline[o]=e[n],r=!0;else if("ignore"===t){r=!0;break}if(r)continue}this.addEventsToTimeline([e[n]])}},n.prototype.recalculate=function(e){var t=this.name;this.name=r(this,e),this.summary=new s(this.roomId,{title:this.name}),t!==this.name&&this.emit("Room.name",this)},t.exports=n},{"../utils":13,"./room-state":6,"./room-summary":7,events:15}],9:[function(e,t){"use strict";function n(e){this.userId=e,this.presence="offline",this.displayName=e,this.avatarUrl=null,this.lastActiveAgo=0,this.events={presence:null,profile:null}}var r=e("events").EventEmitter,o=e("../utils");o.inherits(n,r),n.prototype.setPresenceEvent=function(e){if("m.presence"===e.getType()){this.events.presence=e;var t=[];e.getContent().presence!==this.presence&&t.push("User.presence"),e.getContent().avatar_url!==this.avatarUrl&&t.push("User.avatarUrl"),e.getContent().displayname!==this.displayName&&t.push("User.displayName"),this.presence=e.getContent().presence,this.displayName=e.getContent().displayname,this.avatarUrl=e.getContent().avatar_url,this.lastActiveAgo=e.getContent().last_active_ago;for(var n=0;n<t.length;n++)this.emit(t[n],e,this)}},t.exports=n},{"../utils":13,events:15}],10:[function(e,t){"use strict";function n(e,t){this.retryAlgorithm=e||n.RETRY_BACKOFF_RATELIMIT,this.queueAlgorithm=t||n.QUEUE_MESSAGES,this._queues={},this._activeQueues=[],this._procFn=null}function r(e){e._procFn&&a.forEach(a.filter(a.keys(e._queues),function(t){return-1===e._activeQueues.indexOf(t)&&e._queues[t].length>0}),function(t){e._activeQueues.push(t),u("Spinning up queue: '%s'",t),o(e,t)})}function o(e,t){var n=i(e,t);if(!n){var r=e._activeQueues.indexOf(t);return r>=0&&e._activeQueues.splice(r,1),void u("Stopping queue '%s' as it is now empty",t)}u("Queue '%s' has %s pending events",t,e._queues[t].length),e._procFn(n.event).done(function(r){s(e,t),u("Queue '%s' sent event %s",t,n.event.getId()),n.defer.resolve(r),o(e,t)},function(r){n.attempts+=1;var i=e.retryAlgorithm(n.event,n.attempts,r);u("retry(%s) err=%s event_id=%s waitTime=%s",n.attempts,r,n.event.getId(),i),-1===i?(u("Queue '%s' giving up on event %s",t,n.event.getId()),s(e,t),n.defer.reject(r),o(e,t)):setTimeout(function(){o(e,t)},i)})}function i(e,t){var n=e._queues[t];return a.isArray(n)?n[0]:null}function s(e,t){var n=e._queues[t];return a.isArray(n)?n.shift():null}function u(){p&&console.log.apply(console,arguments)}var a=e("./utils"),c=e("q"),p=!1;n.prototype.setProcessFunction=function(e){this._procFn=e,r(this)},n.prototype.queueEvent=function(e){var t=this.queueAlgorithm(e);if(!t)return null;this._queues[t]||(this._queues[t]=[]);var n=c.defer();return this._queues[t].push({event:e,defer:n,attempts:0}),u("Queue algorithm dumped event %s into queue '%s'",e.getId(),t),r(this),n.promise},n.RETRY_BACKOFF_RATELIMIT=function(e,t,n){if("M_LIMIT_EXCEEDED"===n.name){var r=n.data.retry_after_ms;if(r)return r}return t>4?-1:1e3*Math.pow(2,t)},n.QUEUE_MESSAGES=function(e){return"m.room.message"===e.getType()?"message":null},t.exports=n},{"./utils":13,q:17}],11:[function(e,t){"use strict";var n=e("../utils");t.exports.MatrixInMemoryStore=function(){this.rooms={},this.users={}},t.exports.MatrixInMemoryStore.prototype={storeRoom:function(e){this.rooms[e.roomId]=e},getRoom:function(e){return this.rooms[e]||null},getRooms:function(){return n.values(this.rooms)},getRoomSummaries:function(){return n.map(n.values(this.rooms),function(e){return e.summary})},storeUser:function(e){this.users[e.userId]=e},getUser:function(e){return this.users[e]||null}}},{"../utils":13}],12:[function(e,t){"use strict";function n(){}n.prototype={storeRoom:function(){},getRoom:function(){return null},getRooms:function(){return[]},getRoomSummaries:function(){return[]},storeUser:function(){},getUser:function(){return null}},t.exports=n},{}],13:[function(e,t){"use strict";t.exports.encodeParams=function(e){var t="";for(var n in e)e.hasOwnProperty(n)&&(t+="&"+encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t.substring(1)},t.exports.encodeUri=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e=e.replace(n,encodeURIComponent(t[n])));return e},t.exports.map=function(e,t){for(var n=new Array(e.length),r=0;r<e.length;r++)n[r]=t(e[r]);return n},t.exports.filter=function(e,t){for(var n=[],r=0;r<e.length;r++)t(e[r],r,e)&&n.push(e[r]);return n},t.exports.keys=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t},t.exports.values=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(e[n]);return t},t.exports.forEach=function(e,t){for(var n=0;n<e.length;n++)t(e[n],n)},t.exports.findElement=function(e,t,n){var r;if(n){for(r=e.length-1;r>=0;r--)if(t(e[r],r,e))return e[r]}else for(r=0;r<e.length;r++)if(t(e[r],r,e))return e[r]},t.exports.removeElement=function(e,t,n){var r;if(n){for(r=e.length-1;r>=0;r--)if(t(e[r],r,e))return void e.splice(r,1)}else for(r=0;r<e.length;r++)if(t(e[r],r,e))return void e.splice(r,1)},t.exports.isFunction=function(e){return"[object Function]"==Object.prototype.toString.call(e)},t.exports.isArray=function(e){return Boolean(e&&e.constructor===Array)},t.exports.checkObjectHasKeys=function(e,t){for(var n=0;n<t.length;n++)if(!e.hasOwnProperty(t[n]))throw new Error("Missing required key: "+t[n])},t.exports.checkObjectHasNoAdditionalKeys=function(e,t){for(var n in e)if(e.hasOwnProperty(n)&&-1===t.indexOf(n))throw new Error("Unknown key: "+n)},t.exports.shallowCopy=function(e,t){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},t.exports.deepCopy=function(e){return JSON.parse(JSON.stringify(e))},t.exports.inherits=function(e,t){"function"!=typeof Object.create&&(Object.create=function(){function e(){}var t=Object.prototype.hasOwnProperty;return function(n){if("object"!=typeof n)throw new TypeError("Object prototype may only be an Object or null");e.prototype=n;var r=new e;if(e.prototype=null,arguments.length>1){var o=Object(arguments[1]);for(var i in o)t.call(o,i)&&(r[i]=o[i])}return r}}()),e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}},{}],14:[function(e,t,n){!function(e,r){"function"==typeof define&&define.amd?define([],r):"object"==typeof n?t.exports=r():e.returnExports=r()}(this,function(){function e(o,i){if("function"!=typeof i)throw new Error("Bad callback given: "+i);if(!o)throw new Error("No options given");var u=o.onResponse;if(o="string"==typeof o?{uri:o}:JSON.parse(JSON.stringify(o)),o.onResponse=u,o.verbose&&(e.log=r()),o.url&&(o.uri=o.url,delete o.url),!o.uri&&""!==o.uri)throw new Error("options.uri is a required argument");if("string"!=typeof o.uri)throw new Error("options.uri must be a string");for(var a=["proxy","_redirectsFollowed","maxRedirects","followRedirect"],c=0;c<a.length;c++)if(o[a[c]])throw new Error("options."+a[c]+" is not supported");if(o.callback=i,o.method=o.method||"GET",o.headers=o.headers||{},o.body=o.body||null,o.timeout=o.timeout||e.DEFAULT_TIMEOUT,o.headers.host)throw new Error("Options.headers.host is not supported");o.json&&(o.headers.accept=o.headers.accept||"application/json","GET"!==o.method&&(o.headers["content-type"]="application/json"),"boolean"!=typeof o.json?o.body=JSON.stringify(o.json):"string"!=typeof o.body&&(o.body=JSON.stringify(o.body)));var p=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t.join("&")};if(o.qs){var f="string"==typeof o.qs?o.qs:p(o.qs);o.uri=-1!==o.uri.indexOf("?")?o.uri+"&"+f:o.uri+"?"+f}var h=function(e){var t={};t.boundry="-------------------------------"+Math.floor(1e9*Math.random());var n=[];for(var r in e)e.hasOwnProperty(r)&&n.push("--"+t.boundry+'\nContent-Disposition: form-data; name="'+r+'"\n\n'+e[r]+"\n");return n.push("--"+t.boundry+"--"),t.body=n.join(""),t.length=t.body.length,t.type="multipart/form-data; boundary="+t.boundry,t};if(o.form){if("string"==typeof o.form)throw"form name unsupported";if("POST"===o.method){var l=(o.encoding||"application/x-www-form-urlencoded").toLowerCase();switch(o.headers["content-type"]=l,l){case"application/x-www-form-urlencoded":o.body=p(o.form).replace(/%20/g,"+");break;case"multipart/form-data":var d=h(o.form);o.body=d.body,o.headers["content-type"]=d.type;break;default:throw new Error("unsupported encoding:"+l)}}}return o.onResponse=o.onResponse||n,o.onResponse===!0&&(o.onResponse=i,o.callback=n),!o.headers.authorization&&o.auth&&(o.headers.authorization="Basic "+s(o.auth.username+":"+o.auth.password)),t(o)}function t(t){function n(){f=!0;var n=new Error("ETIMEDOUT");return n.code="ETIMEDOUT",n.duration=t.timeout,e.log.error("Timeout",{id:p._id,milliseconds:t.timeout}),t.callback(n,p)}function r(){if(f)return e.log.debug("Ignoring timed out state change",{state:p.readyState,id:p.id});if(e.log.debug("State change",{state:p.readyState,id:p.id,timed_out:f}),p.readyState===u.OPENED){e.log.debug("Request started",{id:p.id});for(var n in t.headers)p.setRequestHeader(n,t.headers[n])}else p.readyState===u.HEADERS_RECEIVED?o():p.readyState===u.LOADING?(o(),s()):p.readyState===u.DONE&&(o(),s(),a())}function o(){if(!m.response){if(m.response=!0,e.log.debug("Got response",{id:p.id,status:p.status}),clearTimeout(p.timeoutTimer),p.statusCode=p.status,h&&0==p.statusCode){var n=new Error("CORS request rejected: "+t.uri);return n.cors="rejected",m.loading=!0,m.end=!0,t.callback(n,p)}t.onResponse(null,p)}}function s(){m.loading||(m.loading=!0,e.log.debug("Response body loading",{id:p.id}))}function a(){if(!m.end){if(m.end=!0,e.log.debug("Request done",{id:p.id}),p.body=p.responseText,t.json)try{p.body=JSON.parse(p.responseText)}catch(n){return t.callback(n,p)}t.callback(null,p,p.body)}}var p=new u,f=!1,h=i(t.uri),l="withCredentials"in p;if(c+=1,p.seq_id=c,p.id=c+": "+t.method+" "+t.uri,p._id=p.id,h&&!l){var d=new Error("Browser does not support cross-origin request: "+t.uri);return d.cors="unsupported",t.callback(d,p)}p.timeoutTimer=setTimeout(n,t.timeout);var m={response:!1,
loading:!1,end:!1};return p.onreadystatechange=r,p.open(t.method,t.uri,!0),h&&(p.withCredentials=!!t.withCredentials),p.send(t.body),p}function n(){}function r(){var e,t,r={},i=["trace","debug","info","warn","error"];for(t=0;t<i.length;t++)e=i[t],r[e]=n,"undefined"!=typeof console&&console&&console[e]&&(r[e]=o(console,e));return r}function o(e,t){function n(n,r){return"object"==typeof r&&(n+=" "+JSON.stringify(r)),e[t].call(e,n)}return n}function i(e){var t,n=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/;try{t=location.href}catch(r){t=document.createElement("a"),t.href="",t=t.href}var o=n.exec(t.toLowerCase())||[],i=n.exec(e.toLowerCase()),s=!(!i||i[1]==o[1]&&i[2]==o[2]&&(i[3]||("http:"===i[1]?80:443))==(o[3]||("http:"===o[1]?80:443)));return s}function s(e){var t,n,r,o,i,s,u,a,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",p=0,f=0,h="",l=[];if(!e)return e;do t=e.charCodeAt(p++),n=e.charCodeAt(p++),r=e.charCodeAt(p++),a=t<<16|n<<8|r,o=a>>18&63,i=a>>12&63,s=a>>6&63,u=63&a,l[f++]=c.charAt(o)+c.charAt(i)+c.charAt(s)+c.charAt(u);while(p<e.length);switch(h=l.join(""),e.length%3){case 1:h=h.slice(0,-2)+"==";break;case 2:h=h.slice(0,-1)+"="}return h}var u=XMLHttpRequest;if(!u)throw new Error("missing XMLHttpRequest");e.log={trace:n,debug:n,info:n,warn:n,error:n};var a=18e4,c=0;e.withCredentials=!1,e.DEFAULT_TIMEOUT=a,e.defaults=function(t){var n=function(e){var n=function(n,r){n="string"==typeof n?{uri:n}:JSON.parse(JSON.stringify(n));for(var o in t)void 0===n[o]&&(n[o]=t[o]);return e(n,r)};return n},r=n(e);return r.get=n(e.get),r.post=n(e.post),r.put=n(e.put),r.head=n(e.head),r};var p=["get","put","post","head"];return p.forEach(function(t){var n=t.toUpperCase(),r=t.toLowerCase();e[r]=function(t){"string"==typeof t?t={method:n,uri:t}:(t=JSON.parse(JSON.stringify(t)),t.method=n);var r=[t].concat(Array.prototype.slice.apply(arguments,[1]));return e.apply(this,r)}}),e.couch=function(t,r){function o(e,t,n){if(e)return r(e,t,n);if((t.statusCode<200||t.statusCode>299)&&n.error){e=new Error("CouchDB error: "+(n.error.reason||n.error.error));for(var o in n)e[o]=n[o];return r(e,t,n)}return r(e,t,n)}"string"==typeof t&&(t={uri:t}),t.json=!0,t.body&&(t.json=t.body),delete t.body,r=r||n;var i=e(t,o);return i},e})},{}],15:[function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(e){return"function"==typeof e}function o(e){return"number"==typeof e}function i(e){return"object"==typeof e&&null!==e}function s(e){return void 0===e}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!o(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,o,u,a,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[e],s(n))return!1;if(r(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:for(o=arguments.length,u=new Array(o-1),a=1;o>a;a++)u[a-1]=arguments[a];n.apply(this,u)}else if(i(n)){for(o=arguments.length,u=new Array(o-1),a=1;o>a;a++)u[a-1]=arguments[a];for(c=n.slice(),o=c.length,a=0;o>a;a++)c[a].apply(this,u)}return!0},n.prototype.addListener=function(e,t){var o;if(!r(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,r(t.listener)?t.listener:t),this._events[e]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned){var o;o=s(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,o&&o>0&&this._events[e].length>o&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),o||(o=!0,t.apply(this,arguments))}if(!r(t))throw TypeError("listener must be a function");var o=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,o,s,u;if(!r(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],s=n.length,o=-1,n===t||r(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(n)){for(u=s;u-->0;)if(n[u]===t||n[u].listener&&n[u].listener===t){o=u;break}if(0>o)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],r(n))this.removeListener(e,n);else for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?r(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.listenerCount=function(e,t){var n;return n=e._events&&e._events[t]?r(e._events[t])?1:e._events[t].length:0}},{}],16:[function(e,t){function n(){c=!1,s.length?a=s.concat(a):p=-1,a.length&&r()}function r(){if(!c){var e=setTimeout(n);c=!0;for(var t=a.length;t;){for(s=a,a=[];++p<t;)s[p].run();p=-1,t=a.length}s=null,c=!1,clearTimeout(e)}}function o(e,t){this.fun=e,this.array=t}function i(){}var s,u=t.exports={},a=[],c=!1,p=-1;u.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];a.push(new o(e,t)),1!==a.length||c||setTimeout(r,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},u.title="browser",u.browser=!0,u.env={},u.argv=[],u.version="",u.versions={},u.on=i,u.addListener=i,u.once=i,u.off=i,u.removeListener=i,u.removeAllListeners=i,u.emit=i,u.binding=function(){throw new Error("process.binding is not supported")},u.cwd=function(){return"/"},u.chdir=function(){throw new Error("process.chdir is not supported")},u.umask=function(){return 0}},{}],17:[function(e,t,n){(function(e){!function(e){"use strict";if("function"==typeof bootstrap)bootstrap("promise",e);else if("object"==typeof n&&"object"==typeof t)t.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeQ=e}else{if("undefined"==typeof window&&"undefined"==typeof self)throw new Error("This environment was not anticipated by Q. Please file a bug.");var r="undefined"!=typeof window?window:self,o=r.Q;r.Q=e(),r.Q.noConflict=function(){return r.Q=o,this}}}(function(){"use strict";function t(e){return function(){return V.apply(e,arguments)}}function n(e){return e===Object(e)}function r(e){return"[object StopIteration]"===re(e)||e instanceof Q}function o(e,t){if(G&&t.stack&&"object"==typeof e&&null!==e&&e.stack&&-1===e.stack.indexOf(oe)){for(var n=[],r=t;r;r=r.source)r.stack&&n.unshift(r.stack);n.unshift(e.stack);var o=n.join("\n"+oe+"\n");e.stack=i(o)}}function i(e){for(var t=e.split("\n"),n=[],r=0;r<t.length;++r){var o=t[r];a(o)||s(o)||!o||n.push(o)}return n.join("\n")}function s(e){return-1!==e.indexOf("(module.js:")||-1!==e.indexOf("(node.js:")}function u(e){var t=/at .+ \((.+):(\d+):(?:\d+)\)$/.exec(e);if(t)return[t[1],Number(t[2])];var n=/at ([^ ]+):(\d+):(?:\d+)$/.exec(e);if(n)return[n[1],Number(n[2])];var r=/.*@(.+):(\d+)$/.exec(e);return r?[r[1],Number(r[2])]:void 0}function a(e){var t=u(e);if(!t)return!1;var n=t[0],r=t[1];return n===K&&r>=J&&ce>=r}function c(){if(G)try{throw new Error}catch(e){var t=e.stack.split("\n"),n=t[0].indexOf("@")>0?t[1]:t[2],r=u(n);if(!r)return;return K=r[0],r[1]}}function p(e,t,n){return function(){return"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn(t+" is deprecated, use "+n+" instead.",new Error("").stack),e.apply(e,arguments)}}function f(e){return e instanceof m?e:b(e)?k(e):S(e)}function h(){function e(e){t=e,i.source=e,z(n,function(t,n){f.nextTick(function(){e.promiseDispatch.apply(e,n)})},void 0),n=void 0,r=void 0}var t,n=[],r=[],o=ee(h.prototype),i=ee(m.prototype);if(i.promiseDispatch=function(e,o,i){var s=W(arguments);n?(n.push(s),"when"===o&&i[1]&&r.push(i[1])):f.nextTick(function(){t.promiseDispatch.apply(t,s)})},i.valueOf=function(){if(n)return i;var e=y(t);return g(e)&&(t=e),e},i.inspect=function(){return t?t.inspect():{state:"pending"}},f.longStackSupport&&G)try{throw new Error}catch(s){i.stack=s.stack.substring(s.stack.indexOf("\n")+1)}return o.promise=i,o.resolve=function(n){t||e(f(n))},o.fulfill=function(n){t||e(S(n))},o.reject=function(n){t||e(I(n))},o.notify=function(e){t||z(r,function(t,n){f.nextTick(function(){n(e)})},void 0)},o}function l(e){if("function"!=typeof e)throw new TypeError("resolver must be a function.");var t=h();try{e(t.resolve,t.reject,t.notify)}catch(n){t.reject(n)}return t.promise}function d(e){return l(function(t,n){for(var r=0,o=e.length;o>r;r++)f(e[r]).then(t,n)})}function m(e,t,n){void 0===t&&(t=function(e){return I(new Error("Promise does not support operation: "+e))}),void 0===n&&(n=function(){return{state:"unknown"}});var r=ee(m.prototype);if(r.promiseDispatch=function(n,o,i){var s;try{s=e[o]?e[o].apply(r,i):t.call(r,o,i)}catch(u){s=I(u)}n&&n(s)},r.inspect=n,n){var o=n();"rejected"===o.state&&(r.exception=o.reason),r.valueOf=function(){var e=n();return"pending"===e.state||"rejected"===e.state?r:e.value}}return r}function v(e,t,n,r){return f(e).then(t,n,r)}function y(e){if(g(e)){var t=e.inspect();if("fulfilled"===t.state)return t.value}return e}function g(e){return e instanceof m}function b(e){return n(e)&&"function"==typeof e.then}function w(e){return g(e)&&"pending"===e.inspect().state}function _(e){return!g(e)||"fulfilled"===e.inspect().state}function E(e){return g(e)&&"rejected"===e.inspect().state}function x(){ie.length=0,se.length=0,ae||(ae=!0)}function T(t,n){ae&&("object"==typeof e&&"function"==typeof e.emit&&f.nextTick.runAfter(function(){-1!==Y(se,t)&&(e.emit("unhandledRejection",n,t),ue.push(t))}),se.push(t),ie.push(n&&"undefined"!=typeof n.stack?n.stack:"(no stack) "+n))}function R(t){if(ae){var n=Y(se,t);-1!==n&&("object"==typeof e&&"function"==typeof e.emit&&f.nextTick.runAfter(function(){var r=Y(ue,t);-1!==r&&(e.emit("rejectionHandled",ie[n],t),ue.splice(r,1))}),se.splice(n,1),ie.splice(n,1))}}function I(e){var t=m({when:function(t){return t&&R(this),t?t(e):this}},function(){return this},function(){return{state:"rejected",reason:e}});return T(t,e),t}function S(e){return m({when:function(){return e},get:function(t){return e[t]},set:function(t,n){e[t]=n},"delete":function(t){delete e[t]},post:function(t,n){return null===t||void 0===t?e.apply(void 0,n):e[t].apply(e,n)},apply:function(t,n){return e.apply(t,n)},keys:function(){return ne(e)}},void 0,function(){return{state:"fulfilled",value:e}})}function k(e){var t=h();return f.nextTick(function(){try{e.then(t.resolve,t.reject,t.notify)}catch(n){t.reject(n)}}),t.promise}function j(e){return m({isDef:function(){}},function(t,n){return $(e,t,n)},function(){return f(e).inspect()})}function M(e,t,n){return f(e).spread(t,n)}function U(e){return function(){function t(e,t){var s;if("undefined"==typeof StopIteration){try{s=n[e](t)}catch(u){return I(u)}return s.done?f(s.value):v(s.value,o,i)}try{s=n[e](t)}catch(u){return r(u)?f(u.value):I(u)}return v(s,o,i)}var n=e.apply(this,arguments),o=t.bind(t,"next"),i=t.bind(t,"throw");return o()}}function q(e){f.done(f.async(e)())}function O(e){throw new Q(e)}function C(e){return function(){return M([this,P(arguments)],function(t,n){return e.apply(t,n)})}}function $(e,t,n){return f(e).dispatch(t,n)}function P(e){return v(e,function(e){var t=0,n=h();return z(e,function(r,o,i){var s;g(o)&&"fulfilled"===(s=o.inspect()).state?e[i]=s.value:(++t,v(o,function(r){e[i]=r,0===--t&&n.resolve(e)},n.reject,function(e){n.notify({index:i,value:e})}))},void 0),0===t&&n.resolve(e),n.promise})}function L(e){if(0===e.length)return f.resolve();var t=f.defer(),n=0;return z(e,function(r,o,i){function s(e){t.resolve(e)}function u(){n--,0===n&&t.reject(new Error("Can't get fulfillment value from any promise, all promises were rejected."))}function a(e){t.notify({index:i,value:e})}var c=e[i];n++,v(c,s,u,a)},void 0),t.promise}function A(e){return v(e,function(e){return e=Z(e,f),v(P(Z(e,function(e){return v(e,B,B)})),function(){return e})})}function N(e){return f(e).allSettled()}function D(e,t){return f(e).then(void 0,void 0,t)}function F(e,t){return f(e).nodeify(t)}var G=!1;try{throw new Error}catch(H){G=!!H.stack}var K,Q,J=c(),B=function(){},X=function(){function t(){for(var e,t;r.next;)r=r.next,e=r.task,r.task=void 0,t=r.domain,t&&(r.domain=void 0,t.enter()),n(e,t);for(;a.length;)e=a.pop(),n(e);i=!1}function n(e,n){try{e()}catch(r){if(u)throw n&&n.exit(),setTimeout(t,0),n&&n.enter(),r;setTimeout(function(){throw r},0)}n&&n.exit()}var r={task:void 0,next:null},o=r,i=!1,s=void 0,u=!1,a=[];if(X=function(t){o=o.next={task:t,domain:u&&e.domain,next:null},i||(i=!0,s())},"object"==typeof e&&"[object process]"===e.toString()&&e.nextTick)u=!0,s=function(){e.nextTick(t)};else if("function"==typeof setImmediate)s="undefined"!=typeof window?setImmediate.bind(window,t):function(){setImmediate(t)};else if("undefined"!=typeof MessageChannel){var c=new MessageChannel;c.port1.onmessage=function(){s=p,c.port1.onmessage=t,t()};var p=function(){c.port2.postMessage(0)};s=function(){setTimeout(t,0),p()}}else s=function(){setTimeout(t,0)};return X.runAfter=function(e){a.push(e),i||(i=!0,s())},X}(),V=Function.call,W=t(Array.prototype.slice),z=t(Array.prototype.reduce||function(e,t){var n=0,r=this.length;if(1===arguments.length)for(;;){if(n in this){t=this[n++];break}if(++n>=r)throw new TypeError}for(;r>n;n++)n in this&&(t=e(t,this[n],n));return t}),Y=t(Array.prototype.indexOf||function(e){for(var t=0;t<this.length;t++)if(this[t]===e)return t;return-1}),Z=t(Array.prototype.map||function(e,t){var n=this,r=[];return z(n,function(o,i,s){r.push(e.call(t,i,s,n))},void 0),r}),ee=Object.create||function(e){function t(){}return t.prototype=e,new t},te=t(Object.prototype.hasOwnProperty),ne=Object.keys||function(e){var t=[];for(var n in e)te(e,n)&&t.push(n);return t},re=t(Object.prototype.toString);Q="undefined"!=typeof ReturnValue?ReturnValue:function(e){this.value=e};var oe="From previous event:";f.resolve=f,f.nextTick=X,f.longStackSupport=!1,"object"==typeof e&&e&&e.env&&e.env.Q_DEBUG&&(f.longStackSupport=!0),f.defer=h,h.prototype.makeNodeResolver=function(){var e=this;return function(t,n){t?e.reject(t):e.resolve(arguments.length>2?W(arguments,1):n)}},f.Promise=l,f.promise=l,l.race=d,l.all=P,l.reject=I,l.resolve=f,f.passByCopy=function(e){return e},m.prototype.passByCopy=function(){return this},f.join=function(e,t){return f(e).join(t)},m.prototype.join=function(e){return f([this,e]).spread(function(e,t){if(e===t)return e;throw new Error("Can't join: not the same: "+e+" "+t)})},f.race=d,m.prototype.race=function(){return this.then(f.race)},f.makePromise=m,m.prototype.toString=function(){return"[object Promise]"},m.prototype.then=function(e,t,n){function r(t){try{return"function"==typeof e?e(t):t}catch(n){return I(n)}}function i(e){if("function"==typeof t){o(e,u);try{return t(e)}catch(n){return I(n)}}return I(e)}function s(e){return"function"==typeof n?n(e):e}var u=this,a=h(),c=!1;return f.nextTick(function(){u.promiseDispatch(function(e){c||(c=!0,a.resolve(r(e)))},"when",[function(e){c||(c=!0,a.resolve(i(e)))}])}),u.promiseDispatch(void 0,"when",[void 0,function(e){var t,n=!1;try{t=s(e)}catch(r){if(n=!0,!f.onerror)throw r;f.onerror(r)}n||a.notify(t)}]),a.promise},f.tap=function(e,t){return f(e).tap(t)},m.prototype.tap=function(e){return e=f(e),this.then(function(t){return e.fcall(t).thenResolve(t)})},f.when=v,m.prototype.thenResolve=function(e){return this.then(function(){return e})},f.thenResolve=function(e,t){return f(e).thenResolve(t)},m.prototype.thenReject=function(e){return this.then(function(){throw e})},f.thenReject=function(e,t){return f(e).thenReject(t)},f.nearer=y,f.isPromise=g,f.isPromiseAlike=b,f.isPending=w,m.prototype.isPending=function(){return"pending"===this.inspect().state},f.isFulfilled=_,m.prototype.isFulfilled=function(){return"fulfilled"===this.inspect().state},f.isRejected=E,m.prototype.isRejected=function(){return"rejected"===this.inspect().state};var ie=[],se=[],ue=[],ae=!0;f.resetUnhandledRejections=x,f.getUnhandledReasons=function(){return ie.slice()},f.stopUnhandledRejectionTracking=function(){x(),ae=!1},x(),f.reject=I,f.fulfill=S,f.master=j,f.spread=M,m.prototype.spread=function(e,t){return this.all().then(function(t){return e.apply(void 0,t)},t)},f.async=U,f.spawn=q,f["return"]=O,f.promised=C,f.dispatch=$,m.prototype.dispatch=function(e,t){var n=this,r=h();return f.nextTick(function(){n.promiseDispatch(r.resolve,e,t)}),r.promise},f.get=function(e,t){return f(e).dispatch("get",[t])},m.prototype.get=function(e){return this.dispatch("get",[e])},f.set=function(e,t,n){return f(e).dispatch("set",[t,n])},m.prototype.set=function(e,t){return this.dispatch("set",[e,t])},f.del=f["delete"]=function(e,t){return f(e).dispatch("delete",[t])},m.prototype.del=m.prototype["delete"]=function(e){return this.dispatch("delete",[e])},f.mapply=f.post=function(e,t,n){return f(e).dispatch("post",[t,n])},m.prototype.mapply=m.prototype.post=function(e,t){return this.dispatch("post",[e,t])},f.send=f.mcall=f.invoke=function(e,t){return f(e).dispatch("post",[t,W(arguments,2)])},m.prototype.send=m.prototype.mcall=m.prototype.invoke=function(e){return this.dispatch("post",[e,W(arguments,1)])},f.fapply=function(e,t){return f(e).dispatch("apply",[void 0,t])},m.prototype.fapply=function(e){return this.dispatch("apply",[void 0,e])},f["try"]=f.fcall=function(e){return f(e).dispatch("apply",[void 0,W(arguments,1)])},m.prototype.fcall=function(){return this.dispatch("apply",[void 0,W(arguments)])},f.fbind=function(e){var t=f(e),n=W(arguments,1);return function(){return t.dispatch("apply",[this,n.concat(W(arguments))])}},m.prototype.fbind=function(){var e=this,t=W(arguments);return function(){return e.dispatch("apply",[this,t.concat(W(arguments))])}},f.keys=function(e){return f(e).dispatch("keys",[])},m.prototype.keys=function(){return this.dispatch("keys",[])},f.all=P,m.prototype.all=function(){return P(this)},f.any=L,m.prototype.any=function(){return L(this)},f.allResolved=p(A,"allResolved","allSettled"),m.prototype.allResolved=function(){return A(this)},f.allSettled=N,m.prototype.allSettled=function(){return this.then(function(e){return P(Z(e,function(e){function t(){return e.inspect()}return e=f(e),e.then(t,t)}))})},f.fail=f["catch"]=function(e,t){return f(e).then(void 0,t)},m.prototype.fail=m.prototype["catch"]=function(e){return this.then(void 0,e)},f.progress=D,m.prototype.progress=function(e){return this.then(void 0,void 0,e)},f.fin=f["finally"]=function(e,t){return f(e)["finally"](t)},m.prototype.fin=m.prototype["finally"]=function(e){return e=f(e),this.then(function(t){return e.fcall().then(function(){return t})},function(t){return e.fcall().then(function(){throw t})})},f.done=function(e,t,n,r){return f(e).done(t,n,r)},m.prototype.done=function(t,n,r){var i=function(e){f.nextTick(function(){if(o(e,s),!f.onerror)throw e;f.onerror(e)})},s=t||n||r?this.then(t,n,r):this;"object"==typeof e&&e&&e.domain&&(i=e.domain.bind(i)),s.then(void 0,i)},f.timeout=function(e,t,n){return f(e).timeout(t,n)},m.prototype.timeout=function(e,t){var n=h(),r=setTimeout(function(){t&&"string"!=typeof t||(t=new Error(t||"Timed out after "+e+" ms"),t.code="ETIMEDOUT"),n.reject(t)},e);return this.then(function(e){clearTimeout(r),n.resolve(e)},function(e){clearTimeout(r),n.reject(e)},n.notify),n.promise},f.delay=function(e,t){return void 0===t&&(t=e,e=void 0),f(e).delay(t)},m.prototype.delay=function(e){return this.then(function(t){var n=h();return setTimeout(function(){n.resolve(t)},e),n.promise})},f.nfapply=function(e,t){return f(e).nfapply(t)},m.prototype.nfapply=function(e){var t=h(),n=W(e);return n.push(t.makeNodeResolver()),this.fapply(n).fail(t.reject),t.promise},f.nfcall=function(e){var t=W(arguments,1);return f(e).nfapply(t)},m.prototype.nfcall=function(){var e=W(arguments),t=h();return e.push(t.makeNodeResolver()),this.fapply(e).fail(t.reject),t.promise},f.nfbind=f.denodeify=function(e){var t=W(arguments,1);return function(){var n=t.concat(W(arguments)),r=h();return n.push(r.makeNodeResolver()),f(e).fapply(n).fail(r.reject),r.promise}},m.prototype.nfbind=m.prototype.denodeify=function(){var e=W(arguments);return e.unshift(this),f.denodeify.apply(void 0,e)},f.nbind=function(e,t){var n=W(arguments,2);return function(){function r(){return e.apply(t,arguments)}var o=n.concat(W(arguments)),i=h();return o.push(i.makeNodeResolver()),f(r).fapply(o).fail(i.reject),i.promise}},m.prototype.nbind=function(){var e=W(arguments,0);return e.unshift(this),f.nbind.apply(void 0,e)},f.nmapply=f.npost=function(e,t,n){return f(e).npost(t,n)},m.prototype.nmapply=m.prototype.npost=function(e,t){var n=W(t||[]),r=h();return n.push(r.makeNodeResolver()),this.dispatch("post",[e,n]).fail(r.reject),r.promise},f.nsend=f.nmcall=f.ninvoke=function(e,t){var n=W(arguments,2),r=h();return n.push(r.makeNodeResolver()),f(e).dispatch("post",[t,n]).fail(r.reject),r.promise},m.prototype.nsend=m.prototype.nmcall=m.prototype.ninvoke=function(e){var t=W(arguments,1),n=h();return t.push(n.makeNodeResolver()),this.dispatch("post",[e,t]).fail(n.reject),n.promise},f.nodeify=F,m.prototype.nodeify=function(e){return e?void this.then(function(t){f.nextTick(function(){e(null,t)})},function(t){f.nextTick(function(){e(t)})}):this},f.noConflict=function(){throw new Error("Q.noConflict only works when Q is used as a global")};var ce=c();return f})}).call(this,e("_process"))},{_process:16}],18:[function(e,t){(function(n){var r=e("./lib/matrix");r.request(e("browser-request")),t.exports=r,n.matrixcs=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./lib/matrix":3,"browser-request":14}]},{},[18]);