schildi-web/origin_migrator/dest/browser-matrix.min.js
David Baker 751a1dc543 Add tool to migrate logins between origins
App checks at startup for an existing session, if there isn't one,
it will start the tool to check for a login in the file:// origin.
If there is one, it will copy the login over to the vector://vector
origin.

In principle this could also be used to migrate logins between
other origins on the web if this were ever required.

This includes a minified copy of the browserified js-sdk with
a getAllEndToEndSessions() function added to the crypto store
(https://github.com/matrix-org/matrix-js-sdk/pull/812). This is
not great, but for a short-lived tool this seems better than
introducing more entry points into webpack only used for the
electron app.
2018-12-21 19:14:25 +00:00

19 lines
540 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

!function(){function e(t,r,n){function o(s,a){if(!r[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=r[s]={exports:{}};t[s][0].call(l.exports,function(e){return o(t[s][1][e]||e)},l,l.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}return e}()({1:[function(e,t,r){(function(r){var n=e("./lib/matrix");const o=e("browser-request"),i=e("qs");n.request(function(e,t){return e.qs=i.stringify(e.qs||{},e.qsStringifyOptions),o(e,t)});var s;try{s=r.indexedDB}catch(e){}s&&n.setCryptoStoreFactory(function(){return new n.IndexedDBCryptoStore(s,"matrix-js-sdk:crypto")}),t.exports=n,r.matrixcs=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./lib/matrix":30,"browser-request":90,qs:239}],2:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=e("babel-runtime/core-js/get-iterator"),i=n(o),s=e("babel-runtime/helpers/classCallCheck"),a=n(s),u=e("babel-runtime/helpers/createClass"),c=n(u),l=function(){function e(t){(0,a.default)(this,e),this.target=t,this.boundHandlers={}}return(0,c.default)(e,[{key:"_handleEvent",value:function(e){for(var t,r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];(t=this.target).emit.apply(t,[e].concat(n))}},{key:"reEmit",value:function(e,t){var r=!0,n=!1,o=void 0;try{for(var s,a=(0,i.default)(t);!(r=(s=a.next()).done);r=!0){var u=s.value;void 0===this.boundHandlers[u]&&(this.boundHandlers[u]=this._handleEvent.bind(this,u));var c=this.boundHandlers[u];e.on(u,c)}}catch(e){n=!0,o=e}finally{try{!r&&a.return&&a.return()}finally{if(n)throw o}}}}]),e}();r.default=l},{"babel-runtime/core-js/get-iterator":58,"babel-runtime/helpers/classCallCheck":79,"babel-runtime/helpers/createClass":80}],3:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){l.checkObjectHasKeys(e,["baseUrl","request"]),this.baseUrl=e.baseUrl,this.idBaseUrl=e.idBaseUrl;var t={baseUrl:e.baseUrl,idBaseUrl:e.idBaseUrl,accessToken:e.accessToken,request:e.request,prefix:c.PREFIX_R0,onlyData:!0,extraParams:e.queryParams,localTimeoutMs:e.localTimeoutMs,useAuthorizationHeader:e.useAuthorizationHeader};this._http=new c.MatrixHttpApi(this,t),this._txnCtr=0}var i=e("babel-runtime/helpers/typeof"),s=n(i),a=e("babel-runtime/core-js/object/keys"),u=n(a),c=e("./http-api"),l=e("./utils");o.prototype.getHomeserverUrl=function(){return this.baseUrl},o.prototype.getIdentityServerUrl=function(){return arguments.length>0&&void 0!==arguments[0]&&arguments[0]&&(this.idBaseUrl.startsWith("http://")||this.idBaseUrl.startsWith("https://"))?this.idBaseUrl.split("://")[1]:this.idBaseUrl},o.prototype.getAccessToken=function(){return this._http.opts.accessToken||null},o.prototype.isLoggedIn=function(){return void 0!==this._http.opts.accessToken},o.prototype.makeTxnId=function(){return"m"+(new Date).getTime()+"."+this._txnCtr++},o.prototype.isUsernameAvailable=function(e){return this._http.authedRequest(void 0,"GET","/register/available",{username:e}).then(function(e){return e.available})},o.prototype.register=function(e,t,r,n,o,i,s){!0===o?o={email:!0}:null!==o&&void 0!==o||(o={}),void 0!==n&&null!==n||(n={}),r&&(n.session=r);var a={auth:n};return void 0!==e&&null!==e&&(a.username=e),void 0!==t&&null!==t&&(a.password=t),o.email&&(a.bind_email=!0),o.msisdn&&(a.bind_msisdn=!0),void 0!==i&&null!==i&&(a.guest_access_token=i),void 0!==t&&null!==t&&(a.x_show_msisdn=!0),this.registerRequest(a,void 0,s)},o.prototype.registerGuest=function(e,t){return e=e||{},e.body=e.body||{},this.registerRequest(e.body,"guest",t)},o.prototype.registerRequest=function(e,t,r){var n={};return t&&(n.kind=t),this._http.request(r,"POST","/register",n,e)},o.prototype.loginFlows=function(e){return this._http.request(e,"GET","/login")},o.prototype.login=function(e,t,r){var n=this,o={type:e};return l.extend(o,t),this._http.authedRequest(function(t,o){"m.login.password"===e&&o&&o.access_token&&o.user_id&&(n._http.opts.accessToken=o.access_token,n.credentials={userId:o.user_id}),r&&r(t,o)},"POST","/login",void 0,o)},o.prototype.loginWithPassword=function(e,t,r){return this.login("m.login.password",{user:e,password:t},r)},o.prototype.loginWithSAML2=function(e,t){return this.login("m.login.saml2",{relay_state:e},t)},o.prototype.getCasLoginUrl=function(e){return this.getSsoLoginUrl(e,"cas")},o.prototype.getSsoLoginUrl=function(e,t){return void 0===t&&(t="sso"),this._http.getUrl("/login/"+t+"/redirect",{redirectUrl:e},c.PREFIX_R0)},o.prototype.loginWithToken=function(e,t){return this.login("m.login.token",{token:e},t)},o.prototype.logout=function(e){return this._http.authedRequest(e,"POST","/logout")},o.prototype.deactivateAccount=function(e,t){if("function"==typeof t)throw new Error("deactivateAccount no longer accepts a callback parameter");var r={};return e&&(r.auth=e),void 0!==t&&(r.erase=t),this._http.authedRequestWithPrefix(void 0,"POST","/account/deactivate",void 0,r,c.PREFIX_R0)},o.prototype.getFallbackAuthUrl=function(e,t){var r=l.encodeUri("/auth/$loginType/fallback/web",{$loginType:e});return this._http.getUrl(r,{session:t},c.PREFIX_R0)},o.prototype.createRoom=function(e,t){return this._http.authedRequest(t,"POST","/createRoom",void 0,e)},o.prototype.roomState=function(e,t){var r=l.encodeUri("/rooms/$roomId/state",{$roomId:e});return this._http.authedRequest(t,"GET",r)},o.prototype.fetchRoomEvent=function(e,t,r){var n=l.encodeUri("/rooms/$roomId/event/$eventId",{$roomId:e,$eventId:t});return this._http.authedRequest(r,"GET",n)},o.prototype.members=function(e,t,r,n,o){var i={};t&&(i.membership=t),r&&(i.not_membership=r),n&&(i.at=n);var s=l.encodeParams(i),a=l.encodeUri("/rooms/$roomId/members?"+s,{$roomId:e});return this._http.authedRequest(o,"GET",a)},o.prototype.upgradeRoom=function(e,t){var r=l.encodeUri("/rooms/$roomId/upgrade",{$roomId:e});return this._http.authedRequest(void 0,"POST",r,void 0,{new_version:t})},o.prototype.getGroupSummary=function(e){var t=l.encodeUri("/groups/$groupId/summary",{$groupId:e});return this._http.authedRequest(void 0,"GET",t)},o.prototype.getGroupProfile=function(e){var t=l.encodeUri("/groups/$groupId/profile",{$groupId:e});return this._http.authedRequest(void 0,"GET",t)},o.prototype.setGroupProfile=function(e,t){var r=l.encodeUri("/groups/$groupId/profile",{$groupId:e});return this._http.authedRequest(void 0,"POST",r,void 0,t)},o.prototype.setGroupJoinPolicy=function(e,t){var r=l.encodeUri("/groups/$groupId/settings/m.join_policy",{$groupId:e});return this._http.authedRequest(void 0,"PUT",r,void 0,{"m.join_policy":t})},o.prototype.getGroupUsers=function(e){var t=l.encodeUri("/groups/$groupId/users",{$groupId:e});return this._http.authedRequest(void 0,"GET",t)},o.prototype.getGroupInvitedUsers=function(e){var t=l.encodeUri("/groups/$groupId/invited_users",{$groupId:e});return this._http.authedRequest(void 0,"GET",t)},o.prototype.getGroupRooms=function(e){var t=l.encodeUri("/groups/$groupId/rooms",{$groupId:e});return this._http.authedRequest(void 0,"GET",t)},o.prototype.inviteUserToGroup=function(e,t){var r=l.encodeUri("/groups/$groupId/admin/users/invite/$userId",{$groupId:e,$userId:t});return this._http.authedRequest(void 0,"PUT",r,void 0,{})},o.prototype.removeUserFromGroup=function(e,t){var r=l.encodeUri("/groups/$groupId/admin/users/remove/$userId",{$groupId:e,$userId:t});return this._http.authedRequest(void 0,"PUT",r,void 0,{})},o.prototype.addUserToGroupSummary=function(e,t,r){var n=l.encodeUri(r?"/groups/$groupId/summary/$roleId/users/$userId":"/groups/$groupId/summary/users/$userId",{$groupId:e,$roleId:r,$userId:t});return this._http.authedRequest(void 0,"PUT",n,void 0,{})},o.prototype.removeUserFromGroupSummary=function(e,t){var r=l.encodeUri("/groups/$groupId/summary/users/$userId",{$groupId:e,$userId:t});return this._http.authedRequest(void 0,"DELETE",r,void 0,{})},o.prototype.addRoomToGroupSummary=function(e,t,r){var n=l.encodeUri(r?"/groups/$groupId/summary/$categoryId/rooms/$roomId":"/groups/$groupId/summary/rooms/$roomId",{$groupId:e,$categoryId:r,$roomId:t});return this._http.authedRequest(void 0,"PUT",n,void 0,{})},o.prototype.removeRoomFromGroupSummary=function(e,t){var r=l.encodeUri("/groups/$groupId/summary/rooms/$roomId",{$groupId:e,$roomId:t});return this._http.authedRequest(void 0,"DELETE",r,void 0,{})},o.prototype.addRoomToGroup=function(e,t,r){void 0===r&&(r=!0);var n=l.encodeUri("/groups/$groupId/admin/rooms/$roomId",{$groupId:e,$roomId:t});return this._http.authedRequest(void 0,"PUT",n,void 0,{"m.visibility":{type:r?"public":"private"}})},o.prototype.updateGroupRoomVisibility=function(e,t,r){var n=l.encodeUri("/groups/$groupId/admin/rooms/$roomId/config/m.visibility",{$groupId:e,$roomId:t});return this._http.authedRequest(void 0,"PUT",n,void 0,{type:r?"public":"private"})},o.prototype.removeRoomFromGroup=function(e,t){var r=l.encodeUri("/groups/$groupId/admin/rooms/$roomId",{$groupId:e,$roomId:t});return this._http.authedRequest(void 0,"DELETE",r,void 0,{})},o.prototype.acceptGroupInvite=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=l.encodeUri("/groups/$groupId/self/accept_invite",{$groupId:e});return this._http.authedRequest(void 0,"PUT",r,void 0,t||{})},o.prototype.joinGroup=function(e){var t=l.encodeUri("/groups/$groupId/self/join",{$groupId:e});return this._http.authedRequest(void 0,"PUT",t,void 0,{})},o.prototype.leaveGroup=function(e){var t=l.encodeUri("/groups/$groupId/self/leave",{$groupId:e});return this._http.authedRequest(void 0,"PUT",t,void 0,{})},o.prototype.getJoinedGroups=function(){var e=l.encodeUri("/joined_groups");return this._http.authedRequest(void 0,"GET",e)},o.prototype.createGroup=function(e){var t=l.encodeUri("/create_group");return this._http.authedRequest(void 0,"POST",t,void 0,e)},o.prototype.getPublicisedGroups=function(e){var t=l.encodeUri("/publicised_groups");return this._http.authedRequest(void 0,"POST",t,void 0,{user_ids:e})},o.prototype.setGroupPublicity=function(e,t){var r=l.encodeUri("/groups/$groupId/self/update_publicity",{$groupId:e});return this._http.authedRequest(void 0,"PUT",r,void 0,{publicise:t})},o.prototype.getStateEvent=function(e,t,r,n){var o={$roomId:e,$eventType:t,$stateKey:r},i=l.encodeUri("/rooms/$roomId/state/$eventType",o);return void 0!==r&&(i=l.encodeUri(i+"/$stateKey",o)),this._http.authedRequest(n,"GET",i)},o.prototype.sendStateEvent=function(e,t,r,n,o){var i={$roomId:e,$eventType:t,$stateKey:n},s=l.encodeUri("/rooms/$roomId/state/$eventType",i);return void 0!==n&&(s=l.encodeUri(s+"/$stateKey",i)),this._http.authedRequest(o,"PUT",s,void 0,r)},o.prototype.redactEvent=function(e,t,r){var n=l.encodeUri("/rooms/$roomId/redact/$eventId",{$roomId:e,$eventId:t});return this._http.authedRequest(r,"POST",n,void 0,{})},o.prototype.roomInitialSync=function(e,t,r){l.isFunction(t)&&(r=t,t=void 0);var n=l.encodeUri("/rooms/$roomId/initialSync",{$roomId:e});return t||(t=30),this._http.authedRequest(r,"GET",n,{limit:t})},o.prototype.setRoomReadMarkersHttpRequest=function(e,t,r){var n=l.encodeUri("/rooms/$roomId/read_markers",{$roomId:e}),o={"m.fully_read":t,"m.read":r};return this._http.authedRequest(void 0,"POST",n,void 0,o)},o.prototype.getJoinedRooms=function(){var e=l.encodeUri("/joined_rooms");return this._http.authedRequest(void 0,"GET",e)},o.prototype.getJoinedRoomMembers=function(e){var t=l.encodeUri("/rooms/$roomId/joined_members",{$roomId:e});return this._http.authedRequest(void 0,"GET",t)},o.prototype.publicRooms=function(e,t){"function"==typeof e&&(t=e,e={}),void 0===e&&(e={});var r={};return e.server&&(r.server=e.server,delete e.server),0===(0,u.default)(e).length&&0===(0,u.default)(r).length?this._http.authedRequest(t,"GET","/publicRooms"):this._http.authedRequest(t,"POST","/publicRooms",r,e)},o.prototype.createAlias=function(e,t,r){var n=l.encodeUri("/directory/room/$alias",{$alias:e}),o={room_id:t};return this._http.authedRequest(r,"PUT",n,void 0,o)},o.prototype.deleteAlias=function(e,t){var r=l.encodeUri("/directory/room/$alias",{$alias:e});return this._http.authedRequest(t,"DELETE",r,void 0,void 0)},o.prototype.getRoomIdForAlias=function(e,t){var r=l.encodeUri("/directory/room/$alias",{$alias:e});return this._http.authedRequest(t,"GET",r)},o.prototype.resolveRoomAlias=function(e,t){var r=l.encodeUri("/directory/room/$alias",{$alias:e});return this._http.request(t,"GET",r)},o.prototype.getRoomDirectoryVisibility=function(e,t){var r=l.encodeUri("/directory/list/room/$roomId",{$roomId:e});return this._http.authedRequest(t,"GET",r)},o.prototype.setRoomDirectoryVisibility=function(e,t,r){var n=l.encodeUri("/directory/list/room/$roomId",{$roomId:e});return this._http.authedRequest(r,"PUT",n,void 0,{visibility:t})},o.prototype.setRoomDirectoryVisibilityAppService=function(e,t,r,n){var o=l.encodeUri("/directory/list/appservice/$networkId/$roomId",{$networkId:e,$roomId:t});return this._http.authedRequest(n,"PUT",o,void 0,{visibility:r})},o.prototype.searchUserDirectory=function(e){var t={search_term:e.term};return void 0!==e.limit&&(t.limit=e.limit),this._http.authedRequest(void 0,"POST","/user_directory/search",void 0,t)},o.prototype.uploadContent=function(e,t){return this._http.uploadContent(e,t)},o.prototype.cancelUpload=function(e){return this._http.cancelUpload(e)},o.prototype.getCurrentUploads=function(){return this._http.getCurrentUploads()},o.prototype.getProfileInfo=function(e,t,r){l.isFunction(t)&&(r=t,t=void 0);var n=t?l.encodeUri("/profile/$userId/$info",{$userId:e,$info:t}):l.encodeUri("/profile/$userId",{$userId:e});return this._http.authedRequest(r,"GET",n)},o.prototype.getThreePids=function(e){return this._http.authedRequest(e,"GET","/account/3pid",void 0,void 0)},o.prototype.addThreePid=function(e,t,r){var n={threePidCreds:e,bind:t};return this._http.authedRequest(r,"POST","/account/3pid",null,n)},o.prototype.deleteThreePid=function(e,t){var r={medium:e,address:t};return this._http.authedRequestWithPrefix(void 0,"POST","/account/3pid/delete",null,r,c.PREFIX_UNSTABLE)},o.prototype.setPassword=function(e,t,r){var n={auth:e,new_password:t};return this._http.authedRequest(r,"POST","/account/password",null,n)},o.prototype.getDevices=function(){return this._http.authedRequestWithPrefix(void 0,"GET","/devices",void 0,void 0,c.PREFIX_UNSTABLE)},o.prototype.setDeviceDetails=function(e,t){var r=l.encodeUri("/devices/$device_id",{$device_id:e});return this._http.authedRequestWithPrefix(void 0,"PUT",r,void 0,t,c.PREFIX_UNSTABLE)},o.prototype.deleteDevice=function(e,t){var r=l.encodeUri("/devices/$device_id",{$device_id:e}),n={};return t&&(n.auth=t),this._http.authedRequestWithPrefix(void 0,"DELETE",r,void 0,n,c.PREFIX_UNSTABLE)},o.prototype.deleteMultipleDevices=function(e,t){var r={devices:e};return t&&(r.auth=t),this._http.authedRequestWithPrefix(void 0,"POST","/delete_devices",void 0,r,c.PREFIX_UNSTABLE)},o.prototype.getPushers=function(e){return this._http.authedRequest(e,"GET","/pushers",void 0,void 0)},o.prototype.setPusher=function(e,t){return this._http.authedRequest(t,"POST","/pushers/set",null,e)},o.prototype.getPushRules=function(e){return this._http.authedRequest(e,"GET","/pushrules/")},o.prototype.addPushRule=function(e,t,r,n,o){var i=l.encodeUri("/pushrules/"+e+"/$kind/$ruleId",{$kind:t,$ruleId:r});return this._http.authedRequest(o,"PUT",i,void 0,n)},o.prototype.deletePushRule=function(e,t,r,n){var o=l.encodeUri("/pushrules/"+e+"/$kind/$ruleId",{$kind:t,$ruleId:r});return this._http.authedRequest(n,"DELETE",o)},o.prototype.setPushRuleEnabled=function(e,t,r,n,o){var i=l.encodeUri("/pushrules/"+e+"/$kind/$ruleId/enabled",{$kind:t,$ruleId:r});return this._http.authedRequest(o,"PUT",i,void 0,{enabled:n})},o.prototype.setPushRuleActions=function(e,t,r,n,o){var i=l.encodeUri("/pushrules/"+e+"/$kind/$ruleId/actions",{$kind:t,$ruleId:r});return this._http.authedRequest(o,"PUT",i,void 0,{actions:n})},o.prototype.search=function(e,t){var r={};return e.next_batch&&(r.next_batch=e.next_batch),this._http.authedRequest(t,"POST","/search",r,e.body)},o.prototype.uploadKeysRequest=function(e,t,r){t=t||{};var n=t.device_id,o=void 0;return o=n?l.encodeUri("/keys/upload/$deviceId",{$deviceId:n}):"/keys/upload",this._http.authedRequestWithPrefix(r,"POST",o,void 0,e,c.PREFIX_UNSTABLE)},o.prototype.downloadKeysForUsers=function(e,t){if(l.isFunction(t))throw new Error("downloadKeysForUsers no longer accepts a callback parameter");t=t||{};var r={device_keys:{}};return"token"in t&&(r.token=t.token),e.forEach(function(e){r.device_keys[e]={}}),this._http.authedRequestWithPrefix(void 0,"POST","/keys/query",void 0,r,c.PREFIX_UNSTABLE)},o.prototype.claimOneTimeKeys=function(e,t){var r={};void 0===t&&(t="signed_curve25519");for(var n=0;n<e.length;++n){var o=e[n][0],i=e[n][1],s=r[o]||{};r[o]=s,s[i]=t}var a={one_time_keys:r};return this._http.authedRequestWithPrefix(void 0,"POST","/keys/claim",void 0,a,c.PREFIX_UNSTABLE)},o.prototype.getKeyChanges=function(e,t){var r={from:e,to:t};return this._http.authedRequestWithPrefix(void 0,"GET","/keys/changes",r,void 0,c.PREFIX_UNSTABLE)},o.prototype.requestEmailToken=function(e,t,r,n,o){var i={client_secret:t,email:e,send_attempt:r,next_link:n};return this._http.idServerRequest(o,"POST","/validate/email/requestToken",i,c.PREFIX_IDENTITY_V1)},o.prototype.submitMsisdnToken=function(e,t,r){var n={sid:e,client_secret:t,token:r};return this._http.idServerRequest(void 0,"POST","/validate/msisdn/submitToken",n,c.PREFIX_IDENTITY_V1)},o.prototype.lookupThreePid=function(e,t,r){var n={medium:e,address:t};return this._http.idServerRequest(r,"GET","/lookup",n,c.PREFIX_IDENTITY_V1)},o.prototype.sendToDevice=function(e,t,r){var n=l.encodeUri("/sendToDevice/$eventType/$txnId",{$eventType:e,$txnId:r||this.makeTxnId()}),o={messages:t};return this._http.authedRequestWithPrefix(void 0,"PUT",n,void 0,o,c.PREFIX_UNSTABLE)},o.prototype.getThirdpartyProtocols=function(){return this._http.authedRequestWithPrefix(void 0,"GET","/thirdparty/protocols",void 0,void 0,c.PREFIX_UNSTABLE).then(function(e){if(!e||"object"!==(void 0===e?"undefined":(0,s.default)(e)))throw new Error("/thirdparty/protocols did not return an object: "+e);return e})},o.prototype.getThirdpartyLocation=function(e,t){var r=l.encodeUri("/thirdparty/location/$protocol",{$protocol:e});return this._http.authedRequestWithPrefix(void 0,"GET",r,t,void 0,c.PREFIX_UNSTABLE)},t.exports=o},{"./http-api":27,"./utils":55,"babel-runtime/core-js/object/keys":69,"babel-runtime/helpers/typeof":85}],4:[function(e,t,r){(function(r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t,r){var n=[],o=!0,s=!1,a=void 0;try{for(var u,c=(0,N.default)((0,L.default)(e));!(o=(u=c.next()).done);o=!0){var l=(0,M.default)(u.value,2),d=l[0],f=l[1];try{var p=i(f,t);p.session_id=d,p.room_id=r,n.push(p)}catch(e){console.log("Failed to decrypt session from backup")}}}catch(e){s=!0,a=e}finally{try{!o&&c.return&&c.return()}finally{if(s)throw a}}return n}function i(e,t){return JSON.parse(t.decrypt(e.session_data.ephemeral,e.session_data.mac,e.session_data.ciphertext))}function s(e){e.baseUrl&&e.baseUrl.endsWith("/")&&(e.baseUrl=e.baseUrl.substr(0,e.baseUrl.length-1)),e.idBaseUrl&&e.idBaseUrl.endsWith("/")&&(e.idBaseUrl=e.idBaseUrl.substr(0,e.idBaseUrl.length-1)),ce.call(this,e),this.olmVersion=null,this.reEmitter=new B.default(this),this.store=e.store||new ne,this.deviceId=e.deviceId||null;var t=e.userId||null;if(this.credentials={userId:t},this.scheduler=e.scheduler,this.scheduler){var r=this;this.scheduler.setProcessFunction(function(e){var t=r.getRoom(e.getRoomId());return e.status!==ee.SENDING&&c(t,e,ee.SENDING),l(r,e)})}this.clientRunning=!1,this.callList={};var n=oe.createNewMatrixCall(this);this._supportsVoip=!1,n&&(h(this),this._supportsVoip=!0),this._syncingRetry=null,this._syncApi=null,this._peekSync=null,this._isGuest=!1,this._ongoingScrollbacks={},this.timelineSupport=Boolean(e.timelineSupport),this.urlPreviewCache={},this._notifTimelineSet=null,this._crypto=null,this._cryptoStore=e.cryptoStore,this._sessionStore=e.sessionStore,this._forceTURN=e.forceTURN||!1,this._roomList=new G.default(this._cryptoStore,this._sessionStore),this._pushProcessor=new Q(this),this._serverSupportsLazyLoading=null}function a(e,t,r,n){return j.default.resolve().then(function(){var n=u(e,r,t);return n?(c(t,r,ee.ENCRYPTING),n.then(function(){c(t,r,ee.SENDING)})):null}).then(function(){var n=void 0;return e.scheduler&&(n=e.scheduler.queueEvent(r))&&e.scheduler.getQueueForEvent(r).length>1&&c(t,r,ee.QUEUED),n||(n=l(e,r)),n}).then(function(e){return t&&t.updatePendingEvent(r,ee.SENT,e.event_id),n&&n(null,e),e},function(e){console.error("Error sending event",e.stack||e);try{r.error=e,c(t,r,ee.NOT_SENT),e.event=r,n&&n(e)}catch(t){console.error("Exception in error handler!",t.stack||e)}throw e})}function u(e,t,r){if(t.isEncrypted())return null;if(!e.isRoomEncrypted(t.getRoomId()))return null;if(!e._crypto)throw new Error("This room is configured to use encryption, but your client does not support encryption.");return e._crypto.encryptEvent(t,r)}function c(e,t,r){e?e.updatePendingEvent(t,r):t.status=r}function l(e,t){var r=t._txnId?t._txnId:e.makeTxnId(),n={$roomId:t.getRoomId(),$eventType:t.getWireType(),$stateKey:t.getStateKey(),$txnId:r},o=void 0;if(t.isState()){var i="/rooms/$roomId/state/$eventType";t.getStateKey()&&t.getStateKey().length>0&&(i="/rooms/$roomId/state/$eventType/$stateKey"),o=ie.encodeUri(i,n)}else o=ie.encodeUri("/rooms/$roomId/send/$eventType/$txnId",n);return e._http.authedRequest(void 0,"PUT",o,void 0,t.getWireContent()).then(function(e){return console.log("Event sent to "+t.getRoomId()+" with event id "+e.event_id),e})}function d(e,t,r,n,o,i){ie.isFunction(o)&&(i=o,o=void 0);var s=ie.encodeUri("/rooms/$roomId/state/m.room.member/$userId",{$roomId:t,$userId:r});return e._http.authedRequest(i,"PUT",s,void 0,{membership:n,reason:o})}function f(e,t,r,n,o,i){ie.isFunction(o)&&(i=o,o=void 0);var s=ie.encodeUri("/rooms/$room_id/$membership",{$room_id:t,$membership:n});return e._http.authedRequest(i,"POST",s,void 0,{user_id:r,reason:o})}function p(e,t,r,n){var o=ie.encodeUri("/presence/list/$userId",{$userId:t.credentials.userId});return t._http.authedRequest(e,n,o,void 0,r)}function h(e){function t(e){return 0!==e.getType().indexOf("m.call.")?void((e.isBeingDecrypted()||e.isDecryptionFailure())&&e.once("Event.decrypted",t)):i?void r(e):void o.push(e)}function r(t){var r=t.getContent(),o=r.call_id?e.callList[r.call_id]:void 0,i=void 0;if("m.call.invite"===t.getType()){if(t.getSender()===e.credentials.userId)return;if(t.getAge()>r.lifetime)return;if(o&&"ended"===o.state)return;if(o&&console.log("WARN: Already have a MatrixCall with id %s but got an invite. Clobbering.",r.call_id),!(o=oe.createNewMatrixCall(e,t.getRoomId(),{forceTURN:e._forceTURN})))return void console.log("Incoming call ID "+r.call_id+" but this client doesn't support WebRTC");if(o.callId=r.call_id,o._initWithInvite(t),e.callList[o.callId]=o,n[o.callId])for(i=0;i<n[o.callId].length;i++)o._gotRemoteIceCandidate(n[o.callId][i]);var s=void 0,a=ie.values(e.callList);for(i=0;i<a.length;++i){var u=a[i];if(o.roomId===u.roomId&&"outbound"===u.direction&&-1!==["wait_local_media","create_offer","invite_sent"].indexOf(u.state)){s=u;break}}s?"wait_local_media"===s.state||"create_offer"===s.state||s.callId>o.callId?(console.log("Glare detected: answering incoming call "+o.callId+" and canceling outgoing call "+s.callId),s._replacedBy(o),o.answer()):(console.log("Glare detected: rejecting incoming call "+o.callId+" and keeping outgoing call "+s.callId),o.hangup()):e.emit("Call.incoming",o)}else if("m.call.answer"===t.getType()){if(!o)return;t.getSender()===e.credentials.userId?"ringing"===o.state&&o._onAnsweredElsewhere(r):o._receivedAnswer(r)}else if("m.call.candidates"===t.getType()){if(t.getSender()===e.credentials.userId)return;if(o)for(i=0;i<r.candidates.length;i++)o._gotRemoteIceCandidate(r.candidates[i]);else n[r.call_id]||(n[r.call_id]=[]),n[r.call_id]=n[r.call_id].concat(r.candidates)}else"m.call.hangup"===t.getType()&&(o?"ended"!==o.state&&(o._onHangupReceived(r),delete e.callList[r.call_id]):(o=oe.createNewMatrixCall(e,t.getRoomId()))&&(o.callId=r.call_id,o._initWithHangup(t),e.callList[r.call_id]=o))}var n={},o=[],i=!1;e.on("sync",function(e){if("PREPARED"===e){i=!0;for(var t={},n=o.length-1;n>=0;n--){var s=o[n];"m.call.answer"!==s.getType()&&"m.call.hangup"!==s.getType()||(t[s.getContent().call_id]="yep")}o.forEach(function(e){t[e.getContent().call_id]||r(e)}),o=[]}}),e.on("event",t)}function v(e){e._supportsVoip&&(e.isGuest()||e.turnServer().done(function(t){if(t.uris){console.log("Got TURN URIs: "+t.uris+" refresh in "+t.ttl+" secs");var r={urls:t.uris,username:t.username,credential:t.password};e._turnServers=[r],e._checkTurnServersTimeoutID=setTimeout(function(){v(e)},1e3*(t.ttl||3600)*.9)}},function(t){console.error("Failed to get TURN URIs"),e._checkTurnServersTimeoutID=setTimeout(function(){v(e)},6e4)}))}function m(e,t,r){e&&e(r),t.reject(r)}function y(e,t,r){e&&e(null,r),t.resolve(r)}function _(e){function t(t){var r=new Z(t);return r.isEncrypted()&&(e.reEmitter.reEmit(r,["Event.decrypted"]),r.attemptDecryption(e._crypto)),r}return t}var g=e("babel-runtime/core-js/object/assign"),b=n(g),E=e("babel-runtime/core-js/json/stringify"),w=n(E),S=e("babel-runtime/core-js/set"),k=n(S),T=e("babel-runtime/core-js/object/keys"),x=n(T),R=e("babel-runtime/helpers/typeof"),I=n(R),C=e("bluebird"),j=n(C),O=e("babel-runtime/regenerator"),A=n(O),D=e("babel-runtime/helpers/slicedToArray"),M=n(D),P=e("babel-runtime/core-js/object/entries"),L=n(P),U=e("babel-runtime/core-js/get-iterator"),N=n(U),F=function(){var e=(0,C.coroutine)(A.default.mark(function e(t,r,n,o,i,s){var a;return A.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t._crypto){e.next=2;break}throw new Error("End-to-End encryption disabled");case 2:return e.next=4,(0,C.resolve)(t._crypto.setDeviceVerification(r,n,o,i,s));case 4:a=e.sent,t.emit("deviceVerificationChanged",r,n,a);case 6:case"end":return e.stop()}},e,this)}));return function(t,r,n,o,i,s){return e.apply(this,arguments)}}(),q=e("./ReEmitter"),B=n(q),K=e("./crypto/RoomList"),G=n(K),$=e("./crypto"),V=n($),W=e("./crypto/recoverykey"),H=e("./crypto/backup_password"),z=e("./randomstring"),Q=e("./pushprocessor"),J=e("events").EventEmitter,Y=e("url"),X=e("./http-api"),Z=e("./models/event").MatrixEvent,ee=e("./models/event").EventStatus,te=e("./models/event-timeline"),re=e("./models/search-result"),ne=e("./store/stub"),oe=e("./webrtc/call"),ie=e("./utils"),se=e("./content-repo"),ae=e("./filter"),ue=e("./sync"),ce=e("./base-apis"),le=X.MatrixError,de=e("./content-helpers"),fe=e("./crypto/olmlib");j.default.config({warnings:!1});var pe=(0,$.isCryptoAvailable)();ie.inherits(s,J),ie.extend(s.prototype,ce.prototype),s.prototype.clearStores=function(){if(this._clientRunning)throw new Error("Cannot clear stores while client is running");var e=[];return e.push(this.store.deleteAllData()),this._cryptoStore&&e.push(this._cryptoStore.deleteAllData()),j.default.all(e)},s.prototype.getUserId=function(){return this.credentials&&this.credentials.userId?this.credentials.userId:null},s.prototype.getDomain=function(){return this.credentials&&this.credentials.userId?this.credentials.userId.replace(/^.*?:/,""):null},s.prototype.getUserIdLocalpart=function(){return this.credentials&&this.credentials.userId?this.credentials.userId.split(":")[0].substring(1):null},s.prototype.getDeviceId=function(){return this.deviceId},s.prototype.supportsVoip=function(){return this._supportsVoip},s.prototype.setForceTURN=function(e){this._forceTURN=e},s.prototype.getSyncState=function(){return this._syncApi?this._syncApi.getSyncState():null},s.prototype.getSyncStateData=function(){return this._syncApi?this._syncApi.getSyncStateData():null},s.prototype.isGuest=function(){return this._isGuest},s.prototype.getScheduler=function(){return this.scheduler},s.prototype.setGuest=function(e){this._isGuest=e},s.prototype.retryImmediately=function(){return this._syncApi.retryImmediately()},s.prototype.getNotifTimelineSet=function(){return this._notifTimelineSet},s.prototype.setNotifTimelineSet=function(e){this._notifTimelineSet=e},s.prototype.initCrypto=(0,C.coroutine)(A.default.mark(function e(){var t,r;return A.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if((0,$.isCryptoAvailable)()){e.next=2;break}throw new Error("End-to-end encryption not supported in this js-sdk build: did you remember to load the olm library?");case 2:if(!this._crypto){e.next=5;break}return console.warn("Attempt to re-initialise e2e encryption on MatrixClient"),e.abrupt("return");case 5:if(this._sessionStore){e.next=7;break}throw new Error("Cannot enable encryption: no sessionStore provided");case 7:if(this._cryptoStore){e.next=9;break}throw new Error("Cannot enable encryption: no cryptoStore provided");case 9:return e.next=11,(0,C.resolve)(this._roomList.init());case 11:if(null!==(t=this.getUserId())){e.next=14;break}throw new Error("Cannot enable encryption on MatrixClient with unknown userId: ensure userId is passed in createClient().");case 14:if(null!==this.deviceId){e.next=16;break}throw new Error("Cannot enable encryption on MatrixClient with unknown deviceId: ensure deviceId is passed in createClient().");case 16:return r=new V.default(this,this._sessionStore,t,this.deviceId,this.store,this._cryptoStore,this._roomList),this.reEmitter.reEmit(r,["crypto.roomKeyRequest","crypto.roomKeyRequestCancellation","crypto.warning"]),e.next=20,(0,C.resolve)(r.init());case 20:this.olmVersion=V.default.getOlmVersion(),r.registerEventHandlers(this),this._crypto=r;case 23:case"end":return e.stop()}},e,this)})),s.prototype.isCryptoEnabled=function(){return null!==this._crypto},s.prototype.getDeviceEd25519Key=function(){return this._crypto?this._crypto.getDeviceEd25519Key():null},s.prototype.uploadKeys=function(){if(null===this._crypto)throw new Error("End-to-end encryption disabled");return this._crypto.uploadDeviceKeys()},s.prototype.downloadKeys=function(e,t){return null===this._crypto?j.default.reject(new Error("End-to-end encryption disabled")):this._crypto.downloadKeys(e,t)},s.prototype.getStoredDevicesForUser=function(){var e=(0,C.method)(function(e){if(null===this._crypto)throw new Error("End-to-end encryption disabled");return this._crypto.getStoredDevicesForUser(e)||[]});return function(t){return e.apply(this,arguments)}}(),s.prototype.getStoredDevice=function(){var e=(0,C.method)(function(e,t){if(null===this._crypto)throw new Error("End-to-end encryption disabled");return this._crypto.getStoredDevice(e,t)||null});return function(t,r){return e.apply(this,arguments)}}(),s.prototype.setDeviceVerified=function(e,t,r){void 0===r&&(r=!0);var n=F(this,e,t,r,null);return e==this.credentials.userId&&this._crypto.checkKeyBackup(),n},s.prototype.setDeviceBlocked=function(e,t,r){return void 0===r&&(r=!0),F(this,e,t,null,r)},s.prototype.setDeviceKnown=function(e,t,r){return void 0===r&&(r=!0),F(this,e,t,null,null,r)},s.prototype.setGlobalBlacklistUnverifiedDevices=function(e){if(null===this._crypto)throw new Error("End-to-end encryption disabled");this._crypto.setGlobalBlacklistUnverifiedDevices(e)},s.prototype.getGlobalBlacklistUnverifiedDevices=function(){if(null===this._crypto)throw new Error("End-to-end encryption disabled");return this._crypto.getGlobalBlacklistUnverifiedDevices()},s.prototype.getEventSenderDeviceInfo=function(){var e=(0,C.method)(function(e){return this._crypto?this._crypto.getEventSenderDeviceInfo(e):null});return function(t){return e.apply(this,arguments)}}(),s.prototype.isEventSenderVerified=function(){var e=(0,C.coroutine)(A.default.mark(function e(t){var r;return A.default.wrap(function(e){
for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,C.resolve)(this.getEventSenderDeviceInfo(t));case 2:if(r=e.sent){e.next=5;break}return e.abrupt("return",!1);case 5:return e.abrupt("return",r.isVerified());case 6:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),s.prototype.cancelAndResendEventRoomKeyRequest=function(e){e.cancelAndResendKeyRequest(this._crypto)},s.prototype.setRoomEncryption=function(e,t){if(!this._crypto)throw new Error("End-to-End encryption disabled");return this._crypto.setRoomEncryption(e,t)},s.prototype.isRoomEncrypted=function(e){var t=this.getRoom(e);return!!t&&(!!t.currentState.getStateEvents("m.room.encryption","")||this._roomList.isRoomEncrypted(e))},s.prototype.forceDiscardSession=function(e){if(!this._crypto)throw new Error("End-to-End encryption disabled");this._crypto.forceDiscardSession(e)},s.prototype.exportRoomKeys=function(){return this._crypto?this._crypto.exportRoomKeys():j.default.reject(new Error("End-to-end encryption disabled"))},s.prototype.importRoomKeys=function(e){if(!this._crypto)throw new Error("End-to-end encryption disabled");return this._crypto.importRoomKeys(e)},s.prototype.getKeyBackupVersion=function(){return this._http.authedRequest(void 0,"GET","/room_keys/version").then(function(e){if(e.algorithm!==fe.MEGOLM_BACKUP_ALGORITHM){var t="Unknown backup algorithm: "+e.algorithm;return j.default.reject(t)}if("object"===(0,I.default)(e.auth_data)&&e.auth_data.public_key)return e;return j.default.reject("Invalid backup data returned")}).catch(function(e){if("M_NOT_FOUND"===e.errcode)return null;throw e})},s.prototype.isKeyBackupTrusted=function(e){return this._crypto.isKeyBackupTrusted(e)},s.prototype.getKeyBackupEnabled=function(){if(null===this._crypto)throw new Error("End-to-end encryption disabled");return Boolean(this._crypto.backupKey)},s.prototype.enableKeyBackup=function(e){if(null===this._crypto)throw new Error("End-to-end encryption disabled");this._crypto.backupInfo=e,this._crypto.backupKey&&this._crypto.backupKey.free(),this._crypto.backupKey=new r.Olm.PkEncryption,this._crypto.backupKey.set_recipient_key(e.auth_data.public_key),this.emit("crypto.keyBackupStatus",!0)},s.prototype.disableKeyBackup=function(){if(null===this._crypto)throw new Error("End-to-end encryption disabled");this._crypto.backupInfo=null,this._crypto.backupKey&&this._crypto.backupKey.free(),this._crypto.backupKey=null,this.emit("crypto.keyBackupStatus",!1)},s.prototype.prepareKeyBackupVersion=function(){var e=(0,C.coroutine)(A.default.mark(function e(t){var n,o,i,s;return A.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==this._crypto){e.next=2;break}throw new Error("End-to-end encryption disabled");case 2:if(n=new r.Olm.PkDecryption,e.prev=3,o=void 0,i={},!t){e.next=15;break}return e.next=9,(0,C.resolve)((0,H.keyForNewBackup)(t));case 9:s=e.sent,o=n.init_with_private_key(s.key),i.private_key_salt=s.salt,i.private_key_iterations=s.iterations,e.next=16;break;case 15:o=n.generate_key();case 16:return i.public_key=o,e.abrupt("return",{algorithm:fe.MEGOLM_BACKUP_ALGORITHM,auth_data:i,recovery_key:(0,W.encodeRecoveryKey)(n.get_private_key())});case 18:return e.prev=18,n.free(),e.finish(18);case 21:case"end":return e.stop()}},e,this,[[3,,18,21]])}));return function(t){return e.apply(this,arguments)}}(),s.prototype.createKeyBackupVersion=function(e){var t=this;if(null===this._crypto)throw new Error("End-to-end encryption disabled");var r={algorithm:e.algorithm,auth_data:e.auth_data};return this._crypto._signObject(r.auth_data).then(function(){return t._http.authedRequest(void 0,"POST","/room_keys/version",void 0,r)}).then(function(r){return t.enableKeyBackup({algorithm:e.algorithm,auth_data:e.auth_data,version:r.version}),r})},s.prototype.deleteKeyBackupVersion=function(e){if(null===this._crypto)throw new Error("End-to-end encryption disabled");this._crypto.backupInfo&&this._crypto.backupInfo.version===e&&this.disableKeyBackup();var t=ie.encodeUri("/room_keys/version/$version",{$version:e});return this._http.authedRequest(void 0,"DELETE",t,void 0,void 0)},s.prototype._makeKeyBackupPath=function(e,t,r){var n=void 0;return n=void 0!==t?ie.encodeUri("/room_keys/keys/$roomId/$sessionId",{$roomId:e,$sessionId:t}):void 0!==e?ie.encodeUri("/room_keys/keys/$roomId",{$roomId:e}):"/room_keys/keys",{path:n,queryData:void 0===r?void 0:{version:r}}},s.prototype.sendKeyBackup=function(e,t,r,n){if(null===this._crypto)throw new Error("End-to-end encryption disabled");var o=this._makeKeyBackupPath(e,t,r);return this._http.authedRequest(void 0,"PUT",o.path,o.queryData,n)},s.prototype.backupAllGroupSessions=function(e){if(null===this._crypto)throw new Error("End-to-end encryption disabled");return this._crypto.backupAllGroupSessions(e)},s.prototype.isValidRecoveryKey=function(e){try{return(0,W.decodeRecoveryKey)(e),!0}catch(e){return!1}},s.prototype.restoreKeyBackupWithPassword=function(){var e=(0,C.coroutine)(A.default.mark(function e(t,r,n,o){var i,s;return A.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,C.resolve)(this.getKeyBackupVersion());case 2:return i=e.sent,e.next=5,(0,C.resolve)((0,H.keyForExistingBackup)(i,t));case 5:return s=e.sent,e.abrupt("return",this._restoreKeyBackup(s,r,n,o));case 7:case"end":return e.stop()}},e,this)}));return function(t,r,n,o){return e.apply(this,arguments)}}(),s.prototype.restoreKeyBackupWithRecoveryKey=function(e,t,r,n){var o=(0,W.decodeRecoveryKey)(e);return this._restoreKeyBackup(o,t,r,n)},s.prototype._restoreKeyBackup=function(e,t,n,s){var a=this;if(null===this._crypto)throw new Error("End-to-end encryption disabled");var u=0,c=[],l=this._makeKeyBackupPath(t,n,s),d=new r.Olm.PkDecryption;try{d.init_with_private_key(e)}catch(e){throw d.free(),e}return this._http.authedRequest(void 0,"GET",l.path,l.queryData).then(function(e){if(e.rooms){var r=!0,s=!1,l=void 0;try{for(var f,p=(0,N.default)((0,L.default)(e.rooms));!(r=(f=p.next()).done);r=!0){var h=(0,M.default)(f.value,2),v=h[0],m=h[1];if(m.sessions){u+=(0,x.default)(m.sessions).length;var y=o(m.sessions,d,v),_=!0,g=!1,b=void 0;try{for(var E,w=(0,N.default)(y);!(_=(E=w.next()).done);_=!0){var S=E.value;S.room_id=v,c.push(S)}}catch(e){g=!0,b=e}finally{try{!_&&w.return&&w.return()}finally{if(g)throw b}}}}}catch(e){s=!0,l=e}finally{try{!r&&p.return&&p.return()}finally{if(s)throw l}}}else if(e.sessions)u=(0,x.default)(e.sessions).length,c=o(e.sessions,d,t);else{u=1;try{var k=i(e,d);k.room_id=t,k.session_id=n,c.push(k)}catch(e){console.log("Failed to decrypt session from backup")}}return a.importRoomKeys(c)}).then(function(){return{total:u,imported:c.length}}).finally(function(){d.free()})},s.prototype.deleteKeysFromBackup=function(e,t,r){if(null===this._crypto)throw new Error("End-to-end encryption disabled");var n=this._makeKeyBackupPath(e,t,r);return this._http.authedRequest(void 0,"DELETE",n.path,n.queryData)},s.prototype.getGroup=function(e){return this.store.getGroup(e)},s.prototype.getGroups=function(){return this.store.getGroups()},s.prototype.getMediaConfig=function(e){return this._http.authedRequestWithPrefix(e,"GET","/config",void 0,void 0,X.PREFIX_MEDIA_R0)},s.prototype.getRoom=function(e){return this.store.getRoom(e)},s.prototype.getRooms=function(){return this.store.getRooms()},s.prototype.getVisibleRooms=function(){var e=this.store.getRooms(),t=new k.default,r=!0,n=!1,o=void 0;try{for(var i,s=(0,N.default)(e);!(r=(i=s.next()).done);r=!0){var a=i.value,u=a.currentState.getStateEvents("m.room.create","");if(u){var c=u.getContent().predecessor;c&&c.room_id&&t.add(c.room_id)}}}catch(e){n=!0,o=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw o}}return e.filter(function(e){return!e.currentState.getStateEvents("m.room.tombstone","")||!t.has(e.roomId)})},s.prototype.getUser=function(e){return this.store.getUser(e)},s.prototype.getUsers=function(){return this.store.getUsers()},s.prototype.setAccountData=function(e,t,r){var n=ie.encodeUri("/user/$userId/account_data/$type",{$userId:this.credentials.userId,$type:e});return this._http.authedRequest(r,"PUT",n,void 0,t)},s.prototype.getAccountData=function(e){return this.store.getAccountData(e)},s.prototype.getIgnoredUsers=function(){var e=this.getAccountData("m.ignored_user_list");return e&&e.getContent()&&e.getContent().ignored_users?(0,x.default)(e.getContent().ignored_users):[]},s.prototype.setIgnoredUsers=function(e,t){var r={ignored_users:{}};return e.map(function(e){return r.ignored_users[e]={}}),this.setAccountData("m.ignored_user_list",r,t)},s.prototype.isUserIgnored=function(e){return-1!==this.getIgnoredUsers().indexOf(e)},s.prototype.joinRoom=function(e,t,r){if(ie.isFunction(t))throw new Error("Expected 'opts' object, got function.");t=t||{},void 0===t.syncRoom&&(t.syncRoom=!0);var n=this.getRoom(e);if(n&&n.hasMembershipState(this.credentials.userId,"join"))return j.default.resolve(n);var o=j.default.resolve();t.inviteSignUrl&&(o=this._http.requestOtherUrl(void 0,"POST",t.inviteSignUrl,{mxid:this.credentials.userId}));var i={};t.viaServers&&(i.server_name=t.viaServers);var s={qsStringifyOptions:{arrayFormat:"repeat"}},a=j.default.defer(),u=this;return o.then(function(t){var r={};t&&(r.third_party_signed=t);var n=ie.encodeUri("/join/$roomid",{$roomid:e});return u._http.authedRequest(void 0,"POST",n,i,r,s)}).then(function(e){var r=e.room_id,n=new ue(u,u._clientOpts),o=n.createRoom(r);return t.syncRoom,j.default.resolve(o)}).done(function(e){y(r,a,e)},function(e){m(r,a,e)}),a.promise},s.prototype.resendEvent=function(e,t){return c(t,e,ee.SENDING),a(this,t,e)},s.prototype.cancelPendingEvent=function(e){if([ee.QUEUED,ee.NOT_SENT].indexOf(e.status)<0)throw new Error("cannot cancel an event with status "+e.status);this.scheduler&&this.scheduler.removeEventFromQueue(e),c(this.getRoom(e.getRoomId()),e,ee.CANCELLED)},s.prototype.setRoomName=function(e,t,r){return this.sendStateEvent(e,"m.room.name",{name:t},void 0,r)},s.prototype.setRoomTopic=function(e,t,r){return this.sendStateEvent(e,"m.room.topic",{topic:t},void 0,r)},s.prototype.getRoomTags=function(e,t){var r=ie.encodeUri("/user/$userId/rooms/$roomId/tags/",{$userId:this.credentials.userId,$roomId:e});return this._http.authedRequest(t,"GET",r,void 0)},s.prototype.setRoomTag=function(e,t,r,n){var o=ie.encodeUri("/user/$userId/rooms/$roomId/tags/$tag",{$userId:this.credentials.userId,$roomId:e,$tag:t});return this._http.authedRequest(n,"PUT",o,void 0,r)},s.prototype.deleteRoomTag=function(e,t,r){var n=ie.encodeUri("/user/$userId/rooms/$roomId/tags/$tag",{$userId:this.credentials.userId,$roomId:e,$tag:t});return this._http.authedRequest(r,"DELETE",n,void 0,void 0)},s.prototype.setRoomAccountData=function(e,t,r,n){var o=ie.encodeUri("/user/$userId/rooms/$roomId/account_data/$type",{$userId:this.credentials.userId,$roomId:e,$type:t});return this._http.authedRequest(n,"PUT",o,void 0,r)},s.prototype.setPowerLevel=function(e,t,r,n,o){var i={users:{}};n&&"m.room.power_levels"===n.getType()&&(i=ie.deepCopy(n.getContent())),i.users[t]=r;var s=ie.encodeUri("/rooms/$roomId/state/m.room.power_levels",{$roomId:e});return this._http.authedRequest(o,"PUT",s,void 0,i)},s.prototype.sendEvent=function(e,t,r,n,o){ie.isFunction(n)&&(o=n,n=void 0),n||(n=this.makeTxnId()),console.log("sendEvent of type "+t+" in "+e+" with txnId "+n);var i=this.getRoom(e),s=new Z({event_id:"~"+e+":"+n,user_id:this.credentials.userId,room_id:e,type:t,origin_server_ts:(new Date).getTime(),content:r});return s._txnId=n,s.status=ee.SENDING,i&&i.addPendingEvent(s,n),s.status===ee.NOT_SENT?j.default.reject(new Error("Event blocked by other events not yet sent")):a(this,i,s,o)},s.prototype.sendMessage=function(e,t,r,n){return ie.isFunction(r)&&(n=r,r=void 0),this.sendEvent(e,"m.room.message",t,r,n)},s.prototype.sendTextMessage=function(e,t,r,n){var o=de.makeTextMessage(t);return this.sendMessage(e,o,r,n)},s.prototype.sendNotice=function(e,t,r,n){var o=de.makeNotice(t);return this.sendMessage(e,o,r,n)},s.prototype.sendEmoteMessage=function(e,t,r,n){var o=de.makeEmoteMessage(t);return this.sendMessage(e,o,r,n)},s.prototype.sendImageMessage=function(e,t,r,n,o){ie.isFunction(n)&&(o=n,n=void 0),n||(n="Image");var i={msgtype:"m.image",url:t,info:r,body:n};return this.sendMessage(e,i,o)},s.prototype.sendStickerMessage=function(e,t,r,n,o){ie.isFunction(n)&&(o=n,n=void 0),n||(n="Sticker");var i={url:t,info:r,body:n};return this.sendEvent(e,"m.sticker",i,o,void 0)},s.prototype.sendHtmlMessage=function(e,t,r,n){var o=de.makeHtmlMessage(t,r);return this.sendMessage(e,o,n)},s.prototype.sendHtmlNotice=function(e,t,r,n){var o=de.makeHtmlNotice(t,r);return this.sendMessage(e,o,n)},s.prototype.sendHtmlEmote=function(e,t,r,n){var o=de.makeHtmlEmote(t,r);return this.sendMessage(e,o,n)},s.prototype.sendReceipt=function(e,t,r){if(this.isGuest())return j.default.resolve({});var n=ie.encodeUri("/rooms/$roomId/receipt/$receiptType/$eventId",{$roomId:e.getRoomId(),$receiptType:t,$eventId:e.getId()}),o=this._http.authedRequest(r,"POST",n,void 0,{}),i=this.getRoom(e.getRoomId());return i&&i._addLocalEchoReceipt(this.credentials.userId,e,t),o},s.prototype.sendReadReceipt=function(e,t){return this.sendReceipt(e,"m.read",t)},s.prototype.setRoomReadMarkers=function(e,t,r){var n=t,o=void 0;if(r){o=r.getId();var i=this.getRoom(e);i&&i._addLocalEchoReceipt(this.credentials.userId,r,"m.read")}return this.setRoomReadMarkersHttpRequest(e,n,o)},s.prototype.getUrlPreview=function(e,t,r){var n=t+"_"+e,o=this.urlPreviewCache[n];if(o)return j.default.resolve(o);var i=this;return this._http.authedRequestWithPrefix(r,"GET","/preview_url",{url:e,ts:t},void 0,X.PREFIX_MEDIA_R0).then(function(e){return i.urlPreviewCache[n]=e,e})},s.prototype.sendTyping=function(e,t,r,n){if(this.isGuest())return j.default.resolve({});var o=ie.encodeUri("/rooms/$roomId/typing/$userId",{$roomId:e,$userId:this.credentials.userId}),i={typing:t};return t&&(i.timeout=r||2e4),this._http.authedRequest(n,"PUT",o,void 0,i)},s.prototype.invite=function(e,t,r){return f(this,e,t,"invite",void 0,r)},s.prototype.inviteByEmail=function(e,t,r){return this.inviteByThreePid(e,"email",t,r)},s.prototype.inviteByThreePid=function(e,t,r,n){var o=ie.encodeUri("/rooms/$roomId/invite",{$roomId:e}),i=this.getIdentityServerUrl(!0);return i?this._http.authedRequest(n,"POST",o,void 0,{id_server:i,medium:t,address:r}):j.default.reject(new le({error:"No supplied identity server URL",errcode:"ORG.MATRIX.JSSDK_MISSING_PARAM"}))},s.prototype.leave=function(e,t){return f(this,e,void 0,"leave",void 0,t)},s.prototype.ban=function(e,t,r,n){return f(this,e,t,"ban",r,n)},s.prototype.forget=function(e,t,r){void 0===t&&(t=!0);var n=f(this,e,void 0,"forget",void 0,r);if(!t)return n;var o=this;return n.then(function(t){return o.store.removeRoom(e),o.emit("deleteRoom",e),t})},s.prototype.unban=function(e,t,r){var n=ie.encodeUri("/rooms/$roomId/unban",{$roomId:e}),o={user_id:t};return this._http.authedRequest(r,"POST",n,void 0,o)},s.prototype.kick=function(e,t,r,n){return d(this,e,t,"leave",r,n)},s.prototype.getPushActionsForEvent=function(e){return e.getPushActions()||e.setPushActions(this._pushProcessor.actionsForEvent(e)),e.getPushActions()},s.prototype.setProfileInfo=function(e,t,r){var n=ie.encodeUri("/profile/$userId/$info",{$userId:this.credentials.userId,$info:e});return this._http.authedRequest(r,"PUT",n,void 0,t)},s.prototype.setDisplayName=function(e,t){return this.setProfileInfo("displayname",{displayname:e},t)},s.prototype.setAvatarUrl=function(e,t){return this.setProfileInfo("avatar_url",{avatar_url:e},t)},s.prototype.mxcUrlToHttp=function(e,t,r,n,o){return se.getHttpUriForMxc(this.baseUrl,e,t,r,n,o)},s.prototype.setPresence=function(e,t){var r=ie.encodeUri("/presence/$userId/status",{$userId:this.credentials.userId});if("string"==typeof e&&(e={presence:e}),-1==["offline","online","unavailable"].indexOf(e.presence))throw new Error("Bad presence value: "+e.presence);return this._http.authedRequest(t,"PUT",r,void 0,e)},s.prototype.getPresenceList=function(e){return p(e,this,void 0,"GET")},s.prototype.inviteToPresenceList=function(e,t){return p(e,this,{invite:t},"POST")},s.prototype.dropFromPresenceList=function(e,t){return p(e,this,{drop:t},"POST")},s.prototype.scrollback=function(e,t,r){ie.isFunction(t)&&(r=t,t=void 0),t=t||30;var n=0,o=this._ongoingScrollbacks[e.roomId]||{};if(o.promise)return o.promise;if(o.errorTs){var i=Date.now()-o.errorTs;n=Math.max(3e3-i,0)}if(null===e.oldState.paginationToken)return j.default.resolve(e);var s=this.store.scrollback(e,t).length;if(s===t)return j.default.resolve(e);t-=s;var a=j.default.defer();o={promise:a.promise,errorTs:null};var u=this;return j.default.delay(n).then(function(){return u._createMessagesRequest(e.roomId,e.oldState.paginationToken,t,"b")}).done(function(t){var n=ie.map(t.chunk,_(u));if(t.state){var o=ie.map(t.state,_(u));e.currentState.setUnknownStateEvents(o)}e.addEventsToTimeline(n,!0,e.getLiveTimeline()),e.oldState.paginationToken=t.end,0===t.chunk.length&&(e.oldState.paginationToken=null),u.store.storeEvents(e,n,t.end,!0),u._ongoingScrollbacks[e.roomId]=null,y(r,a,e)},function(t){u._ongoingScrollbacks[e.roomId]={errorTs:Date.now()},m(r,a,t)}),this._ongoingScrollbacks[e.roomId]=o,a.promise},s.prototype.getEventTimeline=function(e,t){if(!this.timelineSupport)throw new Error("timeline support is disabled. Set the 'timelineSupport' parameter to true when creating MatrixClient to enable it.");if(e.getTimelineForEvent(t))return j.default.resolve(e.getTimelineForEvent(t));var r=ie.encodeUri("/rooms/$roomId/context/$eventId",{$roomId:e.room.roomId,$eventId:t}),n=void 0;this._clientOpts.lazyLoadMembers&&(n={filter:(0,w.default)(ae.LAZY_LOADING_MESSAGES_FILTER)});var o=this;return o._http.authedRequest(void 0,"GET",r,n).then(function(r){if(!r.event)throw new Error("'event' not in '/context' result - homeserver too old?");if(e.getTimelineForEvent(t))return e.getTimelineForEvent(t);r.events_after.reverse();var n=r.events_after.concat([r.event]).concat(r.events_before),i=ie.map(n,o.getEventMapper()),s=e.getTimelineForEvent(i[0].getId());if(s){var a=ie.map(r.state,o.getEventMapper());s.getState(te.BACKWARDS).setUnknownStateEvents(a)}else s=e.addTimeline(),s.initialiseState(ie.map(r.state,o.getEventMapper())),s.getState(te.FORWARDS).paginationToken=r.end;return e.addEventsToTimeline(i,!0,s,r.start),e.getTimelineForEvent(t)||s})},s.prototype._createMessagesRequest=function(e,t,r,n){var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,i=ie.encodeUri("/rooms/$roomId/messages",{$roomId:e});void 0===r&&(r=30);var s={from:t,limit:r,dir:n},a=null;return this._clientOpts.lazyLoadMembers&&(a=(0,b.default)({},ae.LAZY_LOADING_MESSAGES_FILTER)),o&&(a=a||{},(0,b.default)(a,o.getRoomTimelineFilterComponent())),a&&(s.filter=(0,w.default)(a)),this._http.authedRequest(void 0,"GET",i,s)},s.prototype.paginateEventTimeline=function(e,t){var r=e.getTimelineSet()===this._notifTimelineSet;t=t||{};var n=t.backwards||!1;if(r&&!n)throw new Error("paginateNotifTimeline can only paginate backwards");var o=n?te.BACKWARDS:te.FORWARDS,i=e.getPaginationToken(o);if(!i)return j.default.resolve(!1);var s=e._paginationRequests[o];if(s)return s;var a=void 0,u=void 0,c=void 0,l=this;if(r)a="/notifications",u={limit:"limit"in t?t.limit:30,only:"highlight"},i&&"end"!==i&&(u.from=i),c=this._http.authedRequestWithPrefix(void 0,"GET",a,u,void 0,X.PREFIX_UNSTABLE).then(function(t){for(var r=t.next_token,i=[],s=0;s<t.notifications.length;s++){var a=t.notifications[s],u=l.getEventMapper()(a.event);u.setPushActions(Q.actionListToActionsObject(a.actions)),u.event.room_id=a.room_id,i[s]=u}return e.getTimelineSet().addEventsToTimeline(i,n,e,r),n&&!t.next_token&&e.setPaginationToken(null,o),!!t.next_token}).finally(function(){e._paginationRequests[o]=null}),e._paginationRequests[o]=c;else{if(!this.getRoom(e.getRoomId()))throw new Error("Unknown room "+e.getRoomId());c=this._createMessagesRequest(e.getRoomId(),i,t.limit,o,e.getFilter()),c.then(function(t){if(t.state){var r=e.getState(o),i=ie.map(t.state,l.getEventMapper());r.setUnknownStateEvents(i)}var s=t.end,a=ie.map(t.chunk,l.getEventMapper());return e.getTimelineSet().addEventsToTimeline(a,n,e,s),n&&t.end==t.start&&e.setPaginationToken(null,o),t.end!=t.start}).finally(function(){e._paginationRequests[o]=null}),e._paginationRequests[o]=c}return c},s.prototype.resetNotifTimelineSet=function(){this._notifTimelineSet&&this._notifTimelineSet.resetLiveTimeline("end",null)},s.prototype.peekInRoom=function(e){return this._peekSync&&this._peekSync.stopPeeking(),this._peekSync=new ue(this,this._clientOpts),this._peekSync.peek(e)},s.prototype.stopPeeking=function(){this._peekSync&&(this._peekSync.stopPeeking(),this._peekSync=null)},s.prototype.setGuestAccess=function(e,t){var r=this.sendStateEvent(e,"m.room.guest_access",{guest_access:t.allowJoin?"can_join":"forbidden"}),n=j.default.resolve();return t.allowRead&&(n=this.sendStateEvent(e,"m.room.history_visibility",{history_visibility:"world_readable"})),j.default.all([n,r])},s.prototype.requestRegisterEmailToken=function(e,t,r,n){return this._requestTokenFromEndpoint("/register/email/requestToken",{email:e,client_secret:t,send_attempt:r,next_link:n})},s.prototype.requestRegisterMsisdnToken=function(e,t,r,n,o){return this._requestTokenFromEndpoint("/register/msisdn/requestToken",{country:e,phone_number:t,client_secret:r,send_attempt:n,next_link:o})},s.prototype.requestAdd3pidEmailToken=function(e,t,r,n){return this._requestTokenFromEndpoint("/account/3pid/email/requestToken",{email:e,client_secret:t,send_attempt:r,next_link:n})},s.prototype.requestAdd3pidMsisdnToken=function(e,t,r,n,o){return this._requestTokenFromEndpoint("/account/3pid/msisdn/requestToken",{country:e,phone_number:t,client_secret:r,send_attempt:n,next_link:o})},s.prototype.requestPasswordEmailToken=function(e,t,r,n){return this._requestTokenFromEndpoint("/account/password/email/requestToken",{email:e,client_secret:t,send_attempt:r,next_link:n})},s.prototype.requestPasswordMsisdnToken=function(e,t,r,n,o){return this._requestTokenFromEndpoint("/account/password/msisdn/requestToken",{country:e,phone_number:t,client_secret:r,send_attempt:n,next_link:o})},s.prototype._requestTokenFromEndpoint=function(e,t){var r=Y.parse(this.idBaseUrl);if(null===r.host)throw new Error("Invalid ID server URL: "+this.idBaseUrl);var n=(0,b.default)({},t,{id_server:r.host});return this._http.request(void 0,"POST",e,void 0,n)},s.prototype.getRoomPushRule=function(e,t){if(!this.pushRules)throw new Error("SyncApi.sync() must be done before accessing to push rules.");for(var r=0;r<this.pushRules[e].room.length;r++){var n=this.pushRules[e].room[r];if(n.rule_id===t)return n}},s.prototype.setRoomMutePushRule=function(e,t,r){var n=this,o=void 0,i=void 0,s=this.getRoomPushRule(e,t);if(s&&0<=s.actions.indexOf("dont_notify")&&(i=!0),r?s?i||(o=j.default.defer(),this.deletePushRule(e,"room",s.rule_id).done(function(){n.addPushRule(e,"room",t,{actions:["dont_notify"]}).done(function(){o.resolve()},function(e){o.reject(e)})},function(e){o.reject(e)}),o=o.promise):o=this.addPushRule(e,"room",t,{actions:["dont_notify"]}):i&&(o=this.deletePushRule(e,"room",s.rule_id)),o){var a=j.default.defer();return o.done(function(){n.getPushRules().done(function(e){n.pushRules=e,a.resolve()},function(e){a.reject(e)})},function(e){n.getPushRules().done(function(t){n.pushRules=t,a.reject(e)},function(t){a.reject(e)})}),a.promise}},s.prototype.searchMessageText=function(e,t){var r={search_term:e.query};return"keys"in e&&(r.keys=e.keys),this.search({body:{search_categories:{room_events:r}}},t)},s.prototype.searchRoomEvents=function(e){var t={search_categories:{room_events:{search_term:e.term,filter:e.filter,order_by:"recent",event_context:{before_limit:1,after_limit:1,include_profile:!0}}}},r={_query:t,results:[],highlights:[]};return this.search({body:t}).then(this._processRoomEventsSearch.bind(this,r))},s.prototype.backPaginateRoomEventsSearch=function(e){if(!e.next_batch)return j.default.reject(new Error("Cannot backpaginate event search any further"));if(e.pendingRequest)return e.pendingRequest;var t={body:e._query,next_batch:e.next_batch},r=this.search(t).then(this._processRoomEventsSearch.bind(this,e)).finally(function(){e.pendingRequest=null});return e.pendingRequest=r,r},s.prototype._processRoomEventsSearch=function(e,t){var r=t.search_categories.room_events;e.count=r.count,e.next_batch=r.next_batch;var n={};r.highlights.forEach(function(e){n[e]=1}),e.highlights.forEach(function(e){n[e]=1}),e.highlights=(0,x.default)(n);for(var o=0;o<r.results.length;o++){var i=re.fromJson(r.results[o],this.getEventMapper());e.results.push(i)}return e},s.prototype.syncLeftRooms=function(){if(this._syncedLeftRooms)return j.default.resolve([]);if(this._syncLeftRoomsPromise)return this._syncLeftRoomsPromise;var e=this,t=new ue(this,this._clientOpts);return this._syncLeftRoomsPromise=t.syncLeftRooms(),this._syncLeftRoomsPromise.then(function(t){console.log("Marking success of sync left room request"),e._syncedLeftRooms=!0}).finally(function(){e._syncLeftRoomsPromise=null}),this._syncLeftRoomsPromise},s.prototype.createFilter=function(e){var t=this,r=ie.encodeUri("/user/$userId/filter",{$userId:this.credentials.userId});return this._http.authedRequest(void 0,"POST",r,void 0,e).then(function(r){var n=ae.fromJson(t.credentials.userId,r.filter_id,e);return t.store.storeFilter(n),n})},s.prototype.getFilter=function(e,t,r){if(r){var n=this.store.getFilter(e,t);if(n)return j.default.resolve(n)}var o=this,i=ie.encodeUri("/user/$userId/filter/$filterId",{$userId:e,$filterId:t});return this._http.authedRequest(void 0,"GET",i,void 0,void 0).then(function(r){var n=ae.fromJson(e,t,r);return o.store.storeFilter(n),n})},s.prototype.getOrCreateFilter=function(e,t){var r=this.store.getFilterIdByName(e),n=j.default.resolve(),o=this;return r&&(n=o.getFilter(o.credentials.userId,r,!0).then(function(n){var i=n.getDefinition(),s=t.getDefinition();if(ie.deepCompare(i,s))return j.default.resolve(r);o.store.setFilterIdByName(e,void 0)},function(t){if(404!==t.httpStatus||"M_UNKNOWN"!==t.errcode&&"M_NOT_FOUND"!==t.errcode)throw t;return void o.store.setFilterIdByName(e,void 0)})),n.then(function(r){return r||o.createFilter(t.getDefinition()).then(function(t){return o.store.setFilterIdByName(e,t.filterId),t.filterId})})},s.prototype.getOpenIdToken=function(){var e=ie.encodeUri("/user/$userId/openid/request_token",{$userId:this.credentials.userId});return this._http.authedRequest(void 0,"POST",e,void 0,{})},s.prototype.turnServer=function(e){return this._http.authedRequest(e,"GET","/voip/turnServer")},s.prototype.getTurnServers=function(){return this._turnServers||[]},s.prototype.startClient=function(){var e=(0,C.method)(function(e){var t=this;this.clientRunning||(this.clientRunning=!0,"number"==typeof e&&(e={initialSyncLimit:e}),this._crypto&&(this._crypto.uploadDeviceKeys().done(),this._crypto.start()),v(this),this._syncApi&&(console.error("Still have sync object whilst not running: stopping old one"),this._syncApi.stop()),e=(0,b.default)({},e),e.crypto=this._crypto,e.canResetEntireTimeline=function(e){return!!t._canResetTimelineCallback&&t._canResetTimelineCallback(e)},this._clientOpts=e,this._syncApi=new ue(this,e),this._syncApi.sync())});return function(t){return e.apply(this,arguments)}}(),s.prototype._storeClientOptions=function(){var e=["boolean","string","number"],t=(0,L.default)(this._clientOpts).filter(function(t){var r=(0,M.default)(t,2),n=(r[0],r[1]);return e.includes(void 0===n?"undefined":(0,I.default)(n))}).reduce(function(e,t){var r=(0,M.default)(t,2),n=r[0],o=r[1];return e[n]=o,e},{});return this.store.storeClientOptions(t)},s.prototype.stopClient=function(){console.log("stopping MatrixClient"),this.clientRunning=!1,this._syncApi&&(this._syncApi.stop(),this._syncApi=null),this._crypto&&this._crypto.stop(),this._peekSync&&this._peekSync.stopPeeking(),r.clearTimeout(this._checkTurnServersTimeoutID)},s.prototype.doesServerSupportLazyLoading=(0,C.coroutine)(A.default.mark(function e(){var t,r;return A.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==this._serverSupportsLazyLoading){e.next=6;break}return e.next=3,(0,C.resolve)(this._http.request(void 0,"GET","/_matrix/client/versions",void 0,void 0,{prefix:""}));case 3:t=e.sent,r=t.unstable_features,this._serverSupportsLazyLoading=r&&r["m.lazy_load_members"];case 6:return e.abrupt("return",this._serverSupportsLazyLoading);case 7:case"end":return e.stop()}},e,this)})),s.prototype.hasLazyLoadMembersEnabled=function(){return!!this._clientOpts.lazyLoadMembers},s.prototype.setCanResetTimelineCallback=function(e){this._canResetTimelineCallback=e},s.prototype.getCanResetTimelineCallback=function(){return this._canResetTimelineCallback},s.prototype.getEventMapper=function(){return _(this)},s.prototype.generateClientSecret=function(){return(0,z.randomString)(32)},t.exports.MatrixClient=s,t.exports.CRYPTO_ENABLED=pe}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./ReEmitter":2,"./base-apis":3,"./content-helpers":5,"./content-repo":6,"./crypto":17,"./crypto/RoomList":10,"./crypto/backup_password":15,"./crypto/olmlib":18,"./crypto/recoverykey":19,"./filter":26,"./http-api":27,"./models/event":34,"./models/event-timeline":33,"./models/search-result":40,"./pushprocessor":42,"./randomstring":43,"./store/stub":51,"./sync":53,"./utils":55,"./webrtc/call":56,"babel-runtime/core-js/get-iterator":58,"babel-runtime/core-js/json/stringify":60,"babel-runtime/core-js/object/assign":63,"babel-runtime/core-js/object/entries":66,"babel-runtime/core-js/object/keys":69,"babel-runtime/core-js/set":76,"babel-runtime/helpers/slicedToArray":84,"babel-runtime/helpers/typeof":85,"babel-runtime/regenerator":86,bluebird:89,events:234,url:250}],5:[function(e,t,r){"use strict";t.exports={makeHtmlMessage:function(e,t){return{msgtype:"m.text",format:"org.matrix.custom.html",body:e,formatted_body:t}},makeHtmlNotice:function(e,t){return{msgtype:"m.notice",format:"org.matrix.custom.html",body:e,formatted_body:t}},makeHtmlEmote:function(e,t){return{msgtype:"m.emote",format:"org.matrix.custom.html",body:e,formatted_body:t}},makeTextMessage:function(e){return{msgtype:"m.text",body:e}},makeNotice:function(e){return{msgtype:"m.notice",body:e}},makeEmoteMessage:function(e){return{msgtype:"m.emote",body:e}}}},{}],6:[function(e,t,r){"use strict";var n=e("./utils");t.exports={getHttpUriForMxc:function(e,t,r,o,i,s){if("string"!=typeof t||!t)return"";if(0!==t.indexOf("mxc://"))return s?t:"";var a=t.slice(6),u="/_matrix/media/v1/download/",c={};r&&(c.width=r),o&&(c.height=o),i&&(c.method=i),n.keys(c).length>0&&(u="/_matrix/media/v1/thumbnail/");var l=a.indexOf("#"),d="";return l>=0&&(d=a.substr(l),a=a.substr(0,l)),e+u+a+(0===n.keys(c).length?"":"?"+n.encodeParams(c))+d},getIdenticonUri:function(e,t,r,o){if(!t)return null;r||(r=96),o||(o=96);var i={width:r,height:o};return e+n.encodeUri("/_matrix/media/v1/identicon/$ident",{$ident:t})+(0===n.keys(i).length?"":"?"+n.encodeParams(i))}}},{"./utils":55}],7:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=e("babel-runtime/helpers/slicedToArray"),i=n(o),s=e("babel-runtime/core-js/object/entries"),a=n(s),u=e("bluebird"),c=n(u),l=e("babel-runtime/regenerator"),d=n(l),f=e("babel-runtime/core-js/object/keys"),p=n(f),h=e("babel-runtime/core-js/get-iterator"),v=n(h),m=e("babel-runtime/helpers/classCallCheck"),y=n(m),_=e("babel-runtime/helpers/createClass"),g=n(_),b=function(){var e=(0,u.coroutine)(d.default.mark(function e(t,r,n,o){var i,s,a,c;return d.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:i=!1,e.t0=d.default.keys(n);case 2:if((e.t1=e.t0()).done){e.next=9;break}if(s=e.t1.value,n.hasOwnProperty(s)){e.next=6;break}return e.abrupt("continue",2);case 6:
s in o||(S.default.log("Device "+r+":"+s+" has been removed"),delete n[s],i=!0),e.next=2;break;case 9:e.t2=d.default.keys(o);case 10:if((e.t3=e.t2()).done){e.next=27;break}if(a=e.t3.value,o.hasOwnProperty(a)){e.next=14;break}return e.abrupt("continue",10);case 14:if(c=o[a],c.user_id===r){e.next=18;break}return S.default.warn("Mismatched user_id "+c.user_id+" in keys from "+r+":"+a),e.abrupt("continue",10);case 18:if(c.device_id===a){e.next=21;break}return S.default.warn("Mismatched device_id "+c.device_id+" in keys from "+r+":"+a),e.abrupt("continue",10);case 21:return e.next=23,(0,u.resolve)(E(t,n,c));case 23:if(!e.sent){e.next=25;break}i=!0;case 25:e.next=10;break;case 27:return e.abrupt("return",i);case 28:case"end":return e.stop()}},e,this)}));return function(t,r,n,o){return e.apply(this,arguments)}}(),E=function(){var e=(0,u.coroutine)(d.default.mark(function e(t,r,n){var o,i,s,a,c,l;return d.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n.keys){e.next=2;break}return e.abrupt("return",!1);case 2:if(o=n.device_id,i=n.user_id,s="ed25519:"+o,a=n.keys[s]){e.next=9;break}return S.default.warn("Device "+i+":"+o+" has no ed25519 key"),e.abrupt("return",!1);case 9:return c=n.unsigned||{},e.prev=10,e.next=13,(0,u.resolve)(R.default.verifySignature(t,n,i,o,a));case 13:e.next=19;break;case 15:return e.prev=15,e.t0=e.catch(10),S.default.warn("Unable to verify signature on device "+i+":"+o+":"+e.t0),e.abrupt("return",!1);case 19:if(l=void 0,!(o in r)){e.next=27;break}if(l=r[o],l.getFingerprint()==a){e.next=25;break}return S.default.warn("Ed25519 key for device "+i+":"+o+" has changed"),e.abrupt("return",!1);case 25:e.next=28;break;case 27:r[o]=l=new T.default(o);case 28:return l.keys=n.keys||{},l.algorithms=n.algorithms||[],l.unsigned=c,e.abrupt("return",!0);case 32:case"end":return e.stop()}},e,this,[[10,15]])}));return function(t,r,n){return e.apply(this,arguments)}}(),w=e("../logger"),S=n(w),k=e("./deviceinfo"),T=n(k),x=e("./olmlib"),R=n(x),I=e("./store/indexeddb-crypto-store"),C=n(I),j=function(){function e(t,r,n,o){(0,y.default)(this,e),this._cryptoStore=r,this._sessionStore=n,this._devices={},this._userByIdentityKey={},this._deviceTrackingStatus={},this._syncToken=null,this._serialiser=new O(t,o,this),this._keyDownloadsInProgressByUser={},this._dirty=!1,this._savePromise=null,this._resolveSavePromise=null,this._savePromiseTime=null,this._saveTimer=null}return(0,g.default)(e,[{key:"load",value:function(){function e(){return t.apply(this,arguments)}var t=(0,u.coroutine)(d.default.mark(function e(){var t,r,n,o,i,s,a,c=this;return d.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=!1,e.next=3,(0,u.resolve)(this._cryptoStore.doTxn("readwrite",[C.default.STORE_DEVICE_DATA],function(e){c._cryptoStore.getEndToEndDeviceData(e,function(r){null===r?(S.default.log("Migrating e2e device data..."),c._devices=c._sessionStore.getAllEndToEndDevices()||{},c._deviceTrackingStatus=c._sessionStore.getEndToEndDeviceTrackingStatus()||{},c._syncToken=c._sessionStore.getEndToEndDeviceSyncToken(),c._cryptoStore.storeEndToEndDeviceData({devices:c._devices,trackingStatus:c._deviceTrackingStatus,syncToken:c._syncToken},e),t=!0):(c._devices=r?r.devices:{},c._deviceTrackingStatus=r?r.trackingStatus:{},c._syncToken=r?r.syncToken:null),c._userByIdentityKey={};var n=!0,o=!1,i=void 0;try{for(var s,a=(0,v.default)((0,p.default)(c._devices));!(n=(s=a.next()).done);n=!0){var u=s.value,l=c._devices[u],d=!0,f=!1,h=void 0;try{for(var m,y=(0,v.default)((0,p.default)(l));!(d=(m=y.next()).done);d=!0){var _=m.value,g=l[_].keys["curve25519:"+_];void 0!==g&&(c._userByIdentityKey[g]=u)}}catch(e){f=!0,h=e}finally{try{!d&&y.return&&y.return()}finally{if(f)throw h}}}}catch(e){o=!0,i=e}finally{try{!n&&a.return&&a.return()}finally{if(o)throw i}}})}));case 3:for(t&&this._sessionStore.removeEndToEndDeviceData(),r=!0,n=!1,o=void 0,e.prev=7,i=(0,v.default)((0,p.default)(this._deviceTrackingStatus));!(r=(s=i.next()).done);r=!0)a=s.value,2==this._deviceTrackingStatus[a]&&(this._deviceTrackingStatus[a]=1);e.next=15;break;case 11:e.prev=11,e.t0=e.catch(7),n=!0,o=e.t0;case 15:e.prev=15,e.prev=16,!r&&i.return&&i.return();case 18:if(e.prev=18,!n){e.next=21;break}throw o;case 21:return e.finish(18);case 22:return e.finish(15);case 23:case"end":return e.stop()}},e,this,[[7,11,15,23],[16,,18,22]])}));return e}()},{key:"stop",value:function(){null!==this._saveTimer&&clearTimeout(this._saveTimer)}},{key:"saveIfDirty",value:function(){function e(e){return t.apply(this,arguments)}var t=(0,u.method)(function(e){var t=this;if(!this._dirty)return c.default.resolve(!1);void 0===e&&(e=500);var r=Date.now+e;this._savePromiseTime&&r<this._savePromiseTime&&(clearTimeout(this._saveTimer),this._saveTimer=null,this._savePromiseTime=null);var n=this._savePromise;if(null===n&&(n=new c.default(function(e,r){t._resolveSavePromise=e}),this._savePromise=n),null===this._saveTimer){var o=this._resolveSavePromise;this._savePromiseTime=r,this._saveTimer=setTimeout(function(){S.default.log("Saving device tracking data at token "+t._syncToken),t._savePromiseTime=null,t._saveTimer=null,t._savePromise=null,t._resolveSavePromise=null,t._dirty=!1,t._cryptoStore.doTxn("readwrite",[C.default.STORE_DEVICE_DATA],function(e){t._cryptoStore.storeEndToEndDeviceData({devices:t._devices,trackingStatus:t._deviceTrackingStatus,syncToken:t._syncToken},e)}).then(function(){o()})},e)}return n});return e}()},{key:"getSyncToken",value:function(){return this._syncToken}},{key:"setSyncToken",value:function(e){this._syncToken=e}},{key:"downloadKeys",value:function(e,t){var r=this,n=[],o=[];if(e.forEach(function(e){var i=r._deviceTrackingStatus[e];r._keyDownloadsInProgressByUser[e]?(S.default.log("downloadKeys: already have a download in progress for "+e+": awaiting its result"),o.push(r._keyDownloadsInProgressByUser[e])):(t||3!=i)&&n.push(e)}),0!=n.length){S.default.log("downloadKeys: downloading for",n);var i=this._doKeyDownload(n);o.push(i)}return 0===o.length&&S.default.log("downloadKeys: already have all necessary keys"),c.default.all(o).then(function(){return r._getDevicesFromStore(e)})}},{key:"_getDevicesFromStore",value:function(e){var t={},r=this;return e.map(function(e){t[e]={},(r.getStoredDevicesForUser(e)||[]).map(function(r){t[e][r.deviceId]=r})}),t}},{key:"getStoredDevicesForUser",value:function(e){var t=this._devices[e];if(!t)return null;var r=[];for(var n in t)t.hasOwnProperty(n)&&r.push(T.default.fromStorage(t[n],n));return r}},{key:"getRawStoredDevicesForUser",value:function(e){return this._devices[e]}},{key:"getStoredDevice",value:function(e,t){var r=this._devices[e];if(r&&r[t])return T.default.fromStorage(r[t],t)}},{key:"getDeviceByIdentityKey",value:function(e,t){var r=this._userByIdentityKey[t];if(!r)return null;if(e!==R.default.OLM_ALGORITHM&&e!==R.default.MEGOLM_ALGORITHM)return null;var n=this._devices[r];if(!n)return null;for(var o in n)if(n.hasOwnProperty(o)){var i=n[o];for(var s in i.keys)if(i.keys.hasOwnProperty(s)&&0===s.indexOf("curve25519:")){var a=i.keys[s];if(a==t)return T.default.fromStorage(i,o)}}return null}},{key:"storeDevicesForUser",value:function(e,t){if(void 0!==this._devices[e]){var r=!0,n=!1,o=void 0;try{for(var s,u=(0,v.default)((0,a.default)(this._devices[e]));!(r=(s=u.next()).done);r=!0){var c=(0,i.default)(s.value,2),l=c[0],d=c[1],f=d.keys["curve25519:"+l];delete this._userByIdentityKey[f]}}catch(e){n=!0,o=e}finally{try{!r&&u.return&&u.return()}finally{if(n)throw o}}}this._devices[e]=t;var p=!0,h=!1,m=void 0;try{for(var y,_=(0,v.default)((0,a.default)(t));!(p=(y=_.next()).done);p=!0){var g=(0,i.default)(y.value,2),l=g[0],d=g[1],b=d.keys["curve25519:"+l];this._userByIdentityKey[b]=e}}catch(e){h=!0,m=e}finally{try{!p&&_.return&&_.return()}finally{if(h)throw m}}this._dirty=!0}},{key:"startTrackingDeviceList",value:function(e){if("string"!=typeof e)throw new Error("userId must be a string; was "+e);this._deviceTrackingStatus[e]||(S.default.log("Now tracking device list for "+e),this._deviceTrackingStatus[e]=1),this._dirty=!0}},{key:"stopTrackingDeviceList",value:function(e){this._deviceTrackingStatus[e]&&(S.default.log("No longer tracking device list for "+e),this._deviceTrackingStatus[e]=0,this._dirty=!0)}},{key:"stopTrackingAllDeviceLists",value:function(){var e=!0,t=!1,r=void 0;try{for(var n,o=(0,v.default)((0,p.default)(this._deviceTrackingStatus));!(e=(n=o.next()).done);e=!0){var i=n.value;this._deviceTrackingStatus[i]=0}}catch(e){t=!0,r=e}finally{try{!e&&o.return&&o.return()}finally{if(t)throw r}}this._dirty=!0}},{key:"invalidateUserDeviceList",value:function(e){this._deviceTrackingStatus[e]&&(S.default.log("Marking device list outdated for",e),this._deviceTrackingStatus[e]=1,this._dirty=!0)}},{key:"refreshOutdatedDeviceLists",value:function(){this.saveIfDirty();var e=[],t=!0,r=!1,n=void 0;try{for(var o,i=(0,v.default)((0,p.default)(this._deviceTrackingStatus));!(t=(o=i.next()).done);t=!0){var s=o.value;1==this._deviceTrackingStatus[s]&&e.push(s)}}catch(e){r=!0,n=e}finally{try{!t&&i.return&&i.return()}finally{if(r)throw n}}return this._doKeyDownload(e)}},{key:"_setRawStoredDevicesForUser",value:function(e,t){if(void 0!==this._devices[e]){var r=!0,n=!1,o=void 0;try{for(var s,u=(0,v.default)((0,a.default)(this._devices[e]));!(r=(s=u.next()).done);r=!0){var c=(0,i.default)(s.value,2),l=c[0],d=c[1],f=d.keys["curve25519:"+l];delete this._userByIdentityKey[f]}}catch(e){n=!0,o=e}finally{try{!r&&u.return&&u.return()}finally{if(n)throw o}}}this._devices[e]=t;var p=!0,h=!1,m=void 0;try{for(var y,_=(0,v.default)((0,a.default)(t));!(p=(y=_.next()).done);p=!0){var g=(0,i.default)(y.value,2),l=g[0],d=g[1],b=d.keys["curve25519:"+l];this._userByIdentityKey[b]=e}}catch(e){h=!0,m=e}finally{try{!p&&_.return&&_.return()}finally{if(h)throw m}}}},{key:"_doKeyDownload",value:function(e){var t=this;if(0===e.length)return c.default.resolve();var r=this._serialiser.updateDevicesForUsers(e,this._syncToken).then(function(){n(!0)},function(t){throw S.default.error("Error downloading keys for "+e+":",t),n(!1),t});e.forEach(function(e){t._keyDownloadsInProgressByUser[e]=r,1==t._deviceTrackingStatus[e]&&(t._deviceTrackingStatus[e]=2)});var n=function(n){e.forEach(function(e){if(t._dirty=!0,t._keyDownloadsInProgressByUser[e]!==r)return void S.default.log("Another update in the queue for",e,"- not marking up-to-date");delete t._keyDownloadsInProgressByUser[e],2==t._deviceTrackingStatus[e]&&(n?(t._deviceTrackingStatus[e]=3,S.default.log("Device list for",e,"now up to date")):t._deviceTrackingStatus[e]=1)}),t.saveIfDirty()};return r}}]),e}();r.default=j;var O=function(){function e(t,r,n){(0,y.default)(this,e),this._baseApis=t,this._olmDevice=r,this._deviceList=n,this._downloadInProgress=!1,this._keyDownloadsQueuedByUser={},this._queuedQueryDeferred=null,this._syncToken=null}return(0,g.default)(e,[{key:"updateDevicesForUsers",value:function(e,t){var r=this;return e.forEach(function(e){r._keyDownloadsQueuedByUser[e]=!0}),this._queuedQueryDeferred||(this._queuedQueryDeferred=c.default.defer()),this._syncToken=t,this._downloadInProgress?(S.default.log("Queued key download for",e),this._queuedQueryDeferred.promise):this._doQueuedQueries()}},{key:"_doQueuedQueries",value:function(){var e=this;if(this._downloadInProgress)throw new Error("DeviceListUpdateSerialiser._doQueuedQueries called with request active");var t=(0,p.default)(this._keyDownloadsQueuedByUser);this._keyDownloadsQueuedByUser={};var r=this._queuedQueryDeferred;this._queuedQueryDeferred=null,S.default.log("Starting key download for",t),this._downloadInProgress=!0;var n={};return this._syncToken&&(n.token=this._syncToken),this._baseApis.downloadKeysForUsers(t,n).then(function(r){var n=r.device_keys||{},o=c.default.resolve(),i=!0,s=!1,a=void 0;try{for(var u,l=(0,v.default)(t);!(i=(u=l.next()).done);i=!0)!function(){var t=u.value;o=o.delay(5).then(function(){return e._processQueryResponseForUser(t,n[t])})}()}catch(e){s=!0,a=e}finally{try{!i&&l.return&&l.return()}finally{if(s)throw a}}return o}).done(function(){S.default.log("Completed key download for "+t),e._downloadInProgress=!1,r.resolve(),e._queuedQueryDeferred&&e._doQueuedQueries()},function(n){S.default.warn("Error downloading keys for "+t+":",n),e._downloadInProgress=!1,r.reject(n)}),r.promise}},{key:"_processQueryResponseForUser",value:function(){function e(e,r){return t.apply(this,arguments)}var t=(0,u.coroutine)(d.default.mark(function e(t,r){var n,o,i;return d.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return S.default.log("got keys for "+t+":",r),n={},o=this._deviceList.getRawStoredDevicesForUser(t),o&&(0,p.default)(o).forEach(function(e){var t=T.default.fromStorage(o[e],e);n[e]=t}),e.next=6,(0,u.resolve)(b(this._olmDevice,t,n,r||{}));case 6:i={},(0,p.default)(n).forEach(function(e){i[e]=n[e].toStorage()}),this._deviceList._setRawStoredDevicesForUser(t,i);case 9:case"end":return e.stop()}},e,this)}));return e}()}]),e}()},{"../logger":29,"./deviceinfo":16,"./olmlib":18,"./store/indexeddb-crypto-store":21,"babel-runtime/core-js/get-iterator":58,"babel-runtime/core-js/object/entries":66,"babel-runtime/core-js/object/keys":69,"babel-runtime/helpers/classCallCheck":79,"babel-runtime/helpers/createClass":80,"babel-runtime/helpers/slicedToArray":84,"babel-runtime/regenerator":86,bluebird:89}],8:[function(e,t,r){(function(r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){if(void 0===e)throw new Error("payloadString undefined");if(e.length>b)throw new Error("Message too long ("+e.length+" bytes). The maximum for an encrypted message is "+b+" bytes.")}function i(e,t){this._sessionStore=e,this._cryptoStore=t,this._pickleKey="DEFAULT_KEY",this.deviceCurve25519Key=null,this.deviceEd25519Key=null,this._maxOneTimeKeys=null,this._outboundGroupSessionStore={},this._inboundGroupSessionMessageIndexes={}}var s=e("babel-runtime/core-js/object/assign"),a=n(s),u=e("babel-runtime/core-js/get-iterator"),c=n(u),l=e("babel-runtime/core-js/object/keys"),d=n(l),f=e("babel-runtime/regenerator"),p=n(f),h=e("bluebird"),v=function(){var e=(0,h.coroutine)(p.default.mark(function e(t,r,n,o){return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,h.resolve)(r.doTxn("readwrite",[g.default.STORE_ACCOUNT],function(e){r.getAccount(e,function(t){null!==t?o.unpickle(n,t):(o.create(),t=o.pickle(n),r.storeAccount(e,t))})}));case 2:case"end":return e.stop()}},e,this)}));return function(t,r,n,o){return e.apply(this,arguments)}}(),m=e("../logger"),y=n(m),_=e("./store/indexeddb-crypto-store"),g=n(_),b=49152;i.prototype.init=(0,h.coroutine)(p.default.mark(function e(){var t,n;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,h.resolve)(this._migrateFromSessionStore());case 2:return t=void 0,n=new r.Olm.Account,e.prev=4,e.next=7,(0,h.resolve)(v(this._sessionStore,this._cryptoStore,this._pickleKey,n));case 7:t=JSON.parse(n.identity_keys()),this._maxOneTimeKeys=n.max_number_of_one_time_keys();case 9:return e.prev=9,n.free(),e.finish(9);case 12:this.deviceCurve25519Key=t.curve25519,this.deviceEd25519Key=t.ed25519;case 14:case"end":return e.stop()}},e,this,[[4,,9,12]])})),i.getOlmVersion=function(){return r.Olm.get_library_version()},i.prototype._migrateFromSessionStore=(0,h.coroutine)(p.default.mark(function e(){var t,r,n,o=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,h.resolve)(this._cryptoStore.doTxn("readwrite",[g.default.STORE_ACCOUNT],function(e){o._cryptoStore.getAccount(e,function(t){null===t&&null!==(t=o._sessionStore.getEndToEndAccount())&&(y.default.log("Migrating account from session store"),o._cryptoStore.storeAccount(e,t))})}));case 2:if(this._sessionStore.removeEndToEndAccount(),t=this._sessionStore.getAllEndToEndSessions(),!((0,d.default)(t).length>0)){e.next=8;break}return e.next=7,(0,h.resolve)(this._cryptoStore.doTxn("readwrite",[g.default.STORE_SESSIONS],function(e){o._cryptoStore.countEndToEndSessions(e,function(r){if(r)return void y.default.log("Crypto store already has sessions: not migrating");var n=0,i=!0,s=!1,a=void 0;try{for(var u,l=(0,c.default)((0,d.default)(t));!(i=(u=l.next()).done);i=!0){var f=u.value,p=!0,h=!1,v=void 0;try{for(var m,_=(0,c.default)((0,d.default)(t[f]));!(p=(m=_.next()).done);p=!0){var g=m.value;n++,o._cryptoStore.storeEndToEndSession(f,g,t[f][g],e)}}catch(e){h=!0,v=e}finally{try{!p&&_.return&&_.return()}finally{if(h)throw v}}}}catch(e){s=!0,a=e}finally{try{!i&&l.return&&l.return()}finally{if(s)throw a}}y.default.log("Migrating "+n+" sessions from session store")})}));case 7:this._sessionStore.removeAllEndToEndSessions();case 8:if(r=this._sessionStore.getAllEndToEndInboundGroupSessionKeys(),!((0,d.default)(r).length>0)){e.next=14;break}return n=0,e.next=13,(0,h.resolve)(this._cryptoStore.doTxn("readwrite",[g.default.STORE_INBOUND_GROUP_SESSIONS],function(e){var t=!0,i=!1,s=void 0;try{for(var a,u=(0,c.default)(r);!(t=(a=u.next()).done);t=!0){var l=a.value;try{o._cryptoStore.addEndToEndInboundGroupSession(l.senderKey,l.sessionId,JSON.parse(o._sessionStore.getEndToEndInboundGroupSession(l.senderKey,l.sessionId)),e)}catch(e){y.default.warn("Failed to migrate session "+l.senderKey+"/"+l.sessionId+": "+e.stack||e)}++n}}catch(e){i=!0,s=e}finally{try{!t&&u.return&&u.return()}finally{if(i)throw s}}y.default.log("Migrated "+n+" inbound group sessions from session store")}));case 13:this._sessionStore.removeAllEndToEndInboundGroupSessions();case 14:case"end":return e.stop()}},e,this)})),i.prototype._getAccount=function(e,t){var n=this;this._cryptoStore.getAccount(e,function(e){var o=new r.Olm.Account;try{o.unpickle(n._pickleKey,e),t(o)}finally{o.free()}})},i.prototype._storeAccount=function(e,t){this._cryptoStore.storeAccount(e,t.pickle(this._pickleKey))},i.prototype._getSession=function(e,t,r,n){var o=this;this._cryptoStore.getEndToEndSession(e,t,r,function(e){o._unpickleSession(e,n)})},i.prototype._unpickleSession=function(e,t){var n=new r.Olm.Session;try{n.unpickle(this._pickleKey,e.session);t((0,a.default)({},e,{session:n}))}finally{n.free()}},i.prototype._saveSession=function(e,t,r){var n=t.session.session_id(),o=(0,a.default)(t,{session:t.session.pickle(this._pickleKey)});this._cryptoStore.storeEndToEndSession(e,n,o,r)},i.prototype._getUtility=function(e){var t=new r.Olm.Utility;try{return e(t)}finally{t.free()}},i.prototype.sign=function(){var e=(0,h.coroutine)(p.default.mark(function e(t){var r,n=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=void 0,e.next=3,(0,h.resolve)(this._cryptoStore.doTxn("readonly",[g.default.STORE_ACCOUNT],function(e){n._getAccount(e,function(e){r=e.sign(t)})}));case 3:return e.abrupt("return",r);case 4:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),i.prototype.getOneTimeKeys=(0,h.coroutine)(p.default.mark(function e(){var t,r=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=void 0,e.next=3,(0,h.resolve)(this._cryptoStore.doTxn("readonly",[g.default.STORE_ACCOUNT],function(e){r._getAccount(e,function(e){t=JSON.parse(e.one_time_keys())})}));case 3:return e.abrupt("return",t);case 4:case"end":return e.stop()}},e,this)})),i.prototype.maxNumberOfOneTimeKeys=function(){return this._maxOneTimeKeys},i.prototype.markKeysAsPublished=(0,h.coroutine)(p.default.mark(function e(){var t=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,h.resolve)(this._cryptoStore.doTxn("readwrite",[g.default.STORE_ACCOUNT],function(e){t._getAccount(e,function(r){r.mark_keys_as_published(),t._storeAccount(e,r)})}));case 2:case"end":return e.stop()}},e,this)})),i.prototype.generateOneTimeKeys=function(e){var t=this;return this._cryptoStore.doTxn("readwrite",[g.default.STORE_ACCOUNT],function(r){t._getAccount(r,function(n){n.generate_one_time_keys(e),t._storeAccount(r,n)})})},i.prototype.createOutboundSession=function(){var e=(0,h.coroutine)(p.default.mark(function e(t,n){var o,i=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return o=void 0,e.next=3,(0,h.resolve)(this._cryptoStore.doTxn("readwrite",[g.default.STORE_ACCOUNT,g.default.STORE_SESSIONS],function(e){i._getAccount(e,function(s){var a=new r.Olm.Session;try{a.create_outbound(s,t,n),o=a.session_id(),i._storeAccount(e,s);var u={session:a,lastReceivedMessageTs:Date.now()};i._saveSession(t,u,e)}finally{a.free()}})}));case 3:return e.abrupt("return",o);case 4:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}(),i.prototype.createInboundSession=function(){var e=(0,h.coroutine)(p.default.mark(function e(t,n,o){var i,s=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(0===n){e.next=2;break}throw new Error("Need messageType == 0 to create inbound session");case 2:return i=void 0,e.next=5,(0,h.resolve)(this._cryptoStore.doTxn("readwrite",[g.default.STORE_ACCOUNT,g.default.STORE_SESSIONS],function(e){s._getAccount(e,function(a){var u=new r.Olm.Session;try{u.create_inbound_from(a,t,o),a.remove_one_time_keys(u),s._storeAccount(e,a);var c=u.decrypt(n,o),l={session:u,lastReceivedMessageTs:Date.now()};s._saveSession(t,l,e),i={payload:c,session_id:u.session_id()}}finally{u.free()}})}));case 5:return e.abrupt("return",i);case 6:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}(),i.prototype.getSessionIdsForDevice=function(){var e=(0,h.coroutine)(p.default.mark(function e(t){var r,n=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=void 0,e.next=3,(0,h.resolve)(this._cryptoStore.doTxn("readonly",[g.default.STORE_SESSIONS],function(e){n._cryptoStore.getEndToEndSessions(t,e,function(e){r=(0,d.default)(e)})}));case 3:return e.abrupt("return",r);case 4:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),i.prototype.getSessionIdForDevice=function(){var e=(0,h.coroutine)(p.default.mark(function e(t){var r,n,o,i,s,a,u;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,h.resolve)(this.getSessionInfoForDevice(t));case 2:if(r=e.sent,0!==r.length){e.next=5;break}return e.abrupt("return",null);case 5:for(n=0,o=1;o<r.length;o++)i=r[o],s=void 0===i.lastReceivedMessageTs?0:i.lastReceivedMessageTs,a=r[n],u=void 0===a.lastReceivedMessageTs?0:a.lastReceivedMessageTs,(s>u||s===u&&i.sessionId<a.sessionId)&&(n=o);return e.abrupt("return",r[n].sessionId);case 8:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),i.prototype.getSessionInfoForDevice=function(){var e=(0,h.coroutine)(p.default.mark(function e(t){var r,n=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=[],e.next=3,(0,h.resolve)(this._cryptoStore.doTxn("readonly",[g.default.STORE_SESSIONS],function(e){n._cryptoStore.getEndToEndSessions(t,e,function(e){var t=(0,d.default)(e).sort(),o=!0,i=!1,s=void 0;try{for(var a,u=(0,c.default)(t);!(o=(a=u.next()).done);o=!0)!function(){var t=a.value;n._unpickleSession(e[t],function(e){r.push({lastReceivedMessageTs:e.lastReceivedMessageTs,hasReceivedMessage:e.session.has_received_message(),sessionId:t})})}()}catch(e){i=!0,s=e}finally{try{!o&&u.return&&u.return()}finally{if(i)throw s}}})}));case 3:return e.abrupt("return",r);case 4:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),i.prototype.encryptMessage=function(){var e=(0,h.coroutine)(p.default.mark(function e(t,r,n){var i,s=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return o(n),i=void 0,e.next=4,(0,h.resolve)(this._cryptoStore.doTxn("readwrite",[g.default.STORE_SESSIONS],function(e){s._getSession(t,r,e,function(r){i=r.session.encrypt(n),s._saveSession(t,r,e)})}));case 4:return e.abrupt("return",i);case 5:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}(),i.prototype.decryptMessage=function(){var e=(0,h.coroutine)(p.default.mark(function e(t,r,n,o){var i,s=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return i=void 0,e.next=3,(0,h.resolve)(this._cryptoStore.doTxn("readwrite",[g.default.STORE_SESSIONS],function(e){s._getSession(t,r,e,function(r){i=r.session.decrypt(n,o),r.lastReceivedMessageTs=Date.now(),s._saveSession(t,r,e)})}));case 3:return e.abrupt("return",i);case 4:case"end":return e.stop()}},e,this)}));return function(t,r,n,o){return e.apply(this,arguments)}}(),i.prototype.matchesSession=function(){var e=(0,h.coroutine)(p.default.mark(function e(t,r,n,o){var i,s=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(0===n){e.next=2;break}return e.abrupt("return",!1);case 2:return i=void 0,e.next=5,(0,h.resolve)(this._cryptoStore.doTxn("readonly",[g.default.STORE_SESSIONS],function(e){s._getSession(t,r,e,function(e){i=e.session.matches_inbound(o)})}));case 5:return e.abrupt("return",i);case 6:case"end":return e.stop()}},e,this)}));return function(t,r,n,o){return e.apply(this,arguments)}}(),i.prototype._saveOutboundGroupSession=function(e){var t=e.pickle(this._pickleKey);this._outboundGroupSessionStore[e.session_id()]=t},i.prototype._getOutboundGroupSession=function(e,t){var n=this._outboundGroupSessionStore[e];if(void 0===n)throw new Error("Unknown outbound group session "+e);var o=new r.Olm.OutboundGroupSession;try{return o.unpickle(this._pickleKey,n),t(o)}finally{o.free()}},i.prototype.createOutboundGroupSession=function(){var e=new r.Olm.OutboundGroupSession;try{return e.create(),this._saveOutboundGroupSession(e),e.session_id()}finally{e.free()}},i.prototype.encryptGroupMessage=function(e,t){var r=this;return o(t),this._getOutboundGroupSession(e,function(e){var n=e.encrypt(t);return r._saveOutboundGroupSession(e),n})},i.prototype.getOutboundGroupSessionKey=function(e){return this._getOutboundGroupSession(e,function(e){return{chain_index:e.message_index(),key:e.session_key()}})},i.prototype._unpickleInboundGroupSession=function(e,t){var n=new r.Olm.InboundGroupSession;try{return n.unpickle(this._pickleKey,e.session),t(n)}finally{n.free()}},i.prototype._getInboundGroupSession=function(e,t,r,n,o){var i=this;this._cryptoStore.getEndToEndInboundGroupSession(t,r,n,function(t){if(null===t)return void o(null);if(null!==e&&e!==t.room_id)throw new Error("Mismatched room_id for inbound group session (expected "+t.room_id+", was "+e+")");i._unpickleInboundGroupSession(t,function(e){o(e,t)})})},i.prototype.addInboundGroupSession=function(){var e=(0,h.coroutine)(p.default.mark(function e(t,n,o,i,s,a,u){var c=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,h.resolve)(this._cryptoStore.doTxn("readwrite",[g.default.STORE_INBOUND_GROUP_SESSIONS],function(e){c._getInboundGroupSession(t,n,i,e,function(l,d){if(l)return void y.default.log("Update for megolm session "+n+"/"+i);var f=new r.Olm.InboundGroupSession;try{if(u?f.import_session(s):f.create(s),i!=f.session_id())throw new Error("Mismatched group session ID from senderKey: "+n);var p={room_id:t,session:f.pickle(c._pickleKey),keysClaimed:a,forwardingCurve25519KeyChain:o};c._cryptoStore.addEndToEndInboundGroupSession(n,i,p,e)}finally{f.free()}})}));case 2:case"end":return e.stop()}},e,this)}));return function(t,r,n,o,i,s,a){return e.apply(this,arguments)}}(),i.prototype.decryptGroupMessage=function(){var e=(0,h.coroutine)(p.default.mark(function e(t,r,n,o,i,s){var a,u=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return a=void 0,e.next=3,(0,h.resolve)(this._cryptoStore.doTxn("readwrite",[g.default.STORE_INBOUND_GROUP_SESSIONS],function(e){u._getInboundGroupSession(t,r,n,e,function(t,c){if(null===t)return void(a=null);var l=t.decrypt(o),d=l.plaintext;if(void 0===d)d=l;else{var f=r+"|"+n+"|"+l.message_index;if(f in u._inboundGroupSessionMessageIndexes){var p=u._inboundGroupSessionMessageIndexes[f];if(p.id!==i||p.timestamp!==s)throw new Error("Duplicate message index, possible replay attack: "+f)}u._inboundGroupSessionMessageIndexes[f]={id:i,timestamp:s}}c.session=t.pickle(u._pickleKey),u._cryptoStore.storeEndToEndInboundGroupSession(r,n,c,e),a={result:d,keysClaimed:c.keysClaimed||{},senderKey:r,forwardingCurve25519KeyChain:c.forwardingCurve25519KeyChain||[]}})}));case 3:return e.abrupt("return",a);case 4:case"end":return e.stop()}},e,this)}));return function(t,r,n,o,i,s){return e.apply(this,arguments)}}(),i.prototype.hasInboundSessionKeys=function(){var e=(0,h.coroutine)(p.default.mark(function e(t,r,n){var o,i=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return o=void 0,e.next=3,(0,h.resolve)(this._cryptoStore.doTxn("readonly",[g.default.STORE_INBOUND_GROUP_SESSIONS],function(e){i._cryptoStore.getEndToEndInboundGroupSession(r,n,e,function(e){if(null===e)return void(o=!1);t!==e.room_id?(y.default.warn("requested keys for inbound group session "+r+"|"+n+", with incorrect room_id (expected "+e.room_id+", was "+t+")"),o=!1):o=!0})}));case 3:return e.abrupt("return",o);case 4:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}(),i.prototype.getInboundGroupSessionKey=function(){var e=(0,h.coroutine)(p.default.mark(function e(t,r,n,o){var i,s=this;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return i=void 0,e.next=3,(0,h.resolve)(this._cryptoStore.doTxn("readonly",[g.default.STORE_INBOUND_GROUP_SESSIONS],function(e){s._getInboundGroupSession(t,r,n,e,function(e,t){if(null===e)return void(i=null);void 0===o&&(o=e.first_known_index());var r=e.export_session(o),n=t.keysClaimed||{},s=n.ed25519||null;i={chain_index:o,key:r,forwarding_curve25519_key_chain:t.forwardingCurve25519KeyChain||[],sender_claimed_ed25519_key:s}})}));case 3:return e.abrupt("return",i);case 4:case"end":return e.stop()}},e,this)}));return function(t,r,n,o){return e.apply(this,arguments)}}(),i.prototype.exportInboundGroupSession=function(e,t,r){return this._unpickleInboundGroupSession(r,function(n){var o=n.first_known_index();return{sender_key:e,sender_claimed_keys:r.keysClaimed,room_id:r.room_id,session_id:t,session_key:n.export_session(o),forwarding_curve25519_key_chain:n.forwardingCurve25519KeyChain||[],first_known_index:n.first_known_index()}})},i.prototype.verifySignature=function(e,t,r){this._getUtility(function(n){n.ed25519_verify(e,t,r)})},t.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../logger":29,"./store/indexeddb-crypto-store":21,"babel-runtime/core-js/get-iterator":58,"babel-runtime/core-js/object/assign":63,"babel-runtime/core-js/object/keys":69,"babel-runtime/regenerator":86,bluebird:89}],9:[function(e,t,r){(function(t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){return e.room_id+" / "+e.session_id}function i(e){return"["+y.default.map(e,function(e){return e.userId+":"+e.deviceId}).join(",")+"]"}Object.defineProperty(r,"__esModule",{value:!0});var s=e("babel-runtime/core-js/get-iterator"),a=n(s),u=e("babel-runtime/helpers/classCallCheck"),c=n(u),l=e("babel-runtime/helpers/createClass"),d=n(l),f=e("bluebird"),p=n(f),h=e("../logger"),v=n(h),m=e("../utils"),y=n(m),_={UNSENT:0,SENT:1,CANCELLATION_PENDING:2,CANCELLATION_PENDING_AND_WILL_RESEND:3},g=function(){function e(t,r,n){(0,c.default)(this,e),this._baseApis=t,this._deviceId=r,this._cryptoStore=n,this._sendOutgoingRoomKeyRequestsTimer=null,this._sendOutgoingRoomKeyRequestsRunning=!1,this._clientRunning=!1}return(0,d.default)(e,[{key:"start",value:function(){this._clientRunning=!0,this._startTimer()}},{key:"stop",value:function(){v.default.log("stopping OutgoingRoomKeyRequestManager"),this._clientRunning=!1}},{key:"sendRoomKeyRequest",value:function(e,t){var r=this;return this._cryptoStore.getOrAddOutgoingRoomKeyRequest({requestBody:e,recipients:t,requestId:this._baseApis.makeTxnId(),state:_.UNSENT
}).then(function(e){e.state===_.UNSENT&&r._startTimer()})}},{key:"cancelRoomKeyRequest",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this._cryptoStore.getOutgoingRoomKeyRequest(e).then(function(n){if(n)switch(n.state){case _.CANCELLATION_PENDING:case _.CANCELLATION_PENDING_AND_WILL_RESEND:return;case _.UNSENT:return v.default.log("deleting unnecessary room key request for "+o(e)),t._cryptoStore.deleteOutgoingRoomKeyRequest(n.requestId,_.UNSENT);case _.SENT:var i=r?_.CANCELLATION_PENDING_AND_WILL_RESEND:_.CANCELLATION_PENDING;return t._cryptoStore.updateOutgoingRoomKeyRequest(n.requestId,_.SENT,{state:i,cancellationTxnId:t._baseApis.makeTxnId()}).then(function(n){if(!n)return void v.default.log("Tried to cancel room key request for "+o(e)+" but it was already cancelled in another tab");t._sendOutgoingRoomKeyRequestCancellation(n,r).catch(function(e){v.default.error("Error sending room key request cancellation; will retry later.",e),t._startTimer()}).then(function(){r&&t._startTimer()})});default:throw new Error("unhandled state: "+n.state)}})}},{key:"getOutgoingSentRoomKeyRequest",value:function(e,t){return this._cryptoStore.getOutgoingRoomKeyRequestsByTarget(e,t,[_.SENT])}},{key:"_startTimer",value:function(){var e=this;if(!this._sendOutgoingRoomKeyRequestsTimer){var r=function(){if(e._sendOutgoingRoomKeyRequestsRunning)throw new Error("RoomKeyRequestSend already in progress!");e._sendOutgoingRoomKeyRequestsRunning=!0,e._sendOutgoingRoomKeyRequests().finally(function(){e._sendOutgoingRoomKeyRequestsRunning=!1}).catch(function(e){v.default.warn("error in OutgoingRoomKeyRequestManager: "+e)}).done()};this._sendOutgoingRoomKeyRequestsTimer=t.setTimeout(r,500)}}},{key:"_sendOutgoingRoomKeyRequests",value:function(){var e=this;return this._clientRunning?(v.default.log("Looking for queued outgoing room key requests"),this._cryptoStore.getOutgoingRoomKeyRequestByState([_.CANCELLATION_PENDING,_.CANCELLATION_PENDING_AND_WILL_RESEND,_.UNSENT]).then(function(t){if(!t)return v.default.log("No more outgoing room key requests"),void(e._sendOutgoingRoomKeyRequestsTimer=null);var r=void 0;switch(t.state){case _.UNSENT:r=e._sendOutgoingRoomKeyRequest(t);break;case _.CANCELLATION_PENDING:r=e._sendOutgoingRoomKeyRequestCancellation(t);break;case _.CANCELLATION_PENDING_AND_WILL_RESEND:r=e._sendOutgoingRoomKeyRequestCancellation(t,!0)}return r.then(function(){return e._sendOutgoingRoomKeyRequests()}).catch(function(t){v.default.error("Error sending room key request; will retry later.",t),e._sendOutgoingRoomKeyRequestsTimer=null,e._startTimer()}).done()})):(this._sendOutgoingRoomKeyRequestsTimer=null,p.default.resolve())}},{key:"_sendOutgoingRoomKeyRequest",value:function(e){var t=this;v.default.log("Requesting keys for "+o(e.requestBody)+" from "+i(e.recipients)+"(id "+e.requestId+")");var r={action:"request",requesting_device_id:this._deviceId,request_id:e.requestId,body:e.requestBody};return this._sendMessageToDevices(r,e.recipients,e.requestId).then(function(){return t._cryptoStore.updateOutgoingRoomKeyRequest(e.requestId,_.UNSENT,{state:_.SENT})})}},{key:"_sendOutgoingRoomKeyRequestCancellation",value:function(e,t){var r=this;v.default.log("Sending cancellation for key request for "+o(e.requestBody)+" to "+i(e.recipients)+" (cancellation id "+e.cancellationTxnId+")");var n={action:"request_cancellation",requesting_device_id:this._deviceId,request_id:e.requestId};return this._sendMessageToDevices(n,e.recipients,e.cancellationTxnId).then(function(){return t?r._cryptoStore.updateOutgoingRoomKeyRequest(e.requestId,_.CANCELLATION_PENDING_AND_WILL_RESEND,{state:_.UNSENT}):r._cryptoStore.deleteOutgoingRoomKeyRequest(e.requestId,_.CANCELLATION_PENDING)})}},{key:"_sendMessageToDevices",value:function(e,t,r){var n={},o=!0,i=!1,s=void 0;try{for(var u,c=(0,a.default)(t);!(o=(u=c.next()).done);o=!0){var l=u.value;n[l.userId]||(n[l.userId]={}),n[l.userId][l.deviceId]=e}}catch(e){i=!0,s=e}finally{try{!o&&c.return&&c.return()}finally{if(i)throw s}}return this._baseApis.sendToDevice("m.room_key_request",n,r)}}]),e}();r.default=g}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../logger":29,"../utils":55,"babel-runtime/core-js/get-iterator":58,"babel-runtime/helpers/classCallCheck":79,"babel-runtime/helpers/createClass":80,bluebird:89}],10:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=e("babel-runtime/regenerator"),i=n(o),s=e("babel-runtime/core-js/get-iterator"),a=n(s),u=e("babel-runtime/core-js/object/keys"),c=n(u),l=e("bluebird"),d=e("babel-runtime/helpers/classCallCheck"),f=n(d),p=e("babel-runtime/helpers/createClass"),h=n(p),v=e("./store/indexeddb-crypto-store"),m=n(v),y=function(){function e(t,r){(0,f.default)(this,e),this._cryptoStore=t,this._sessionStore=r,this._roomEncryption={}}return(0,h.default)(e,[{key:"init",value:function(){function e(){return t.apply(this,arguments)}var t=(0,l.coroutine)(i.default.mark(function e(){var t,r=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=!1,e.next=3,(0,l.resolve)(this._cryptoStore.doTxn("readwrite",[m.default.STORE_ROOMS],function(e){r._cryptoStore.getEndToEndRooms(e,function(n){if(null===n||0===(0,c.default)(n).length){var o=r._sessionStore.getAllEndToEndRooms();if(null!==o){var i=!0,s=!1,u=void 0;try{for(var l,d=(0,a.default)((0,c.default)(o));!(i=(l=d.next()).done);i=!0){var f=l.value;r._cryptoStore.storeEndToEndRoom(f,o[f],e)}}catch(e){s=!0,u=e}finally{try{!i&&d.return&&d.return()}finally{if(s)throw u}}}r._roomEncryption=o,t=!0}else r._roomEncryption=n})}));case 3:t&&this._sessionStore.removeAllEndToEndRooms();case 4:case"end":return e.stop()}},e,this)}));return e}()},{key:"getRoomEncryption",value:function(e){return this._roomEncryption[e]||null}},{key:"isRoomEncrypted",value:function(e){return Boolean(this.getRoomEncryption(e))}},{key:"setRoomEncryption",value:function(){function e(e,r){return t.apply(this,arguments)}var t=(0,l.coroutine)(i.default.mark(function e(t,r){var n=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this._roomEncryption[t]=r,e.next=3,(0,l.resolve)(this._cryptoStore.doTxn("readwrite",[m.default.STORE_ROOMS],function(e){n._cryptoStore.storeEndToEndRoom(t,r,e)}));case 3:case"end":return e.stop()}},e,this)}));return e}()}]),e}();r.default=y},{"./store/indexeddb-crypto-store":21,"babel-runtime/core-js/get-iterator":58,"babel-runtime/core-js/object/keys":69,"babel-runtime/helpers/classCallCheck":79,"babel-runtime/helpers/createClass":80,"babel-runtime/regenerator":86,bluebird:89}],11:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var r=e.name+"[msg: "+e.message;return t&&(r+=", "+(0,a.default)(t).map(function(e){return e+": "+t[e]}).join(", ")),r+="]"}function i(e,t,r){b[e]=t,E[e]=r}Object.defineProperty(r,"__esModule",{value:!0}),r.UnknownDeviceError=r.DecryptionError=r.DecryptionAlgorithm=r.EncryptionAlgorithm=r.DECRYPTION_CLASSES=r.ENCRYPTION_CLASSES=void 0;var s=e("babel-runtime/core-js/object/keys"),a=n(s),u=e("babel-runtime/core-js/object/get-prototype-of"),c=n(u),l=e("babel-runtime/helpers/possibleConstructorReturn"),d=n(l),f=e("babel-runtime/helpers/inherits"),p=n(f),h=e("babel-runtime/helpers/classCallCheck"),v=n(h),m=e("babel-runtime/helpers/createClass"),y=n(m);r.registerAlgorithm=i;var _=e("bluebird"),g=n(_),b=r.ENCRYPTION_CLASSES={},E=r.DECRYPTION_CLASSES={},w=function(){function e(t){(0,v.default)(this,e),this._userId=t.userId,this._deviceId=t.deviceId,this._crypto=t.crypto,this._olmDevice=t.olmDevice,this._baseApis=t.baseApis,this._roomId=t.roomId}return(0,y.default)(e,[{key:"onRoomMembership",value:function(e,t,r){}}]),e}();r.EncryptionAlgorithm=w;var S=function(){function e(t){(0,v.default)(this,e),this._userId=t.userId,this._crypto=t.crypto,this._olmDevice=t.olmDevice,this._baseApis=t.baseApis,this._roomId=t.roomId}return(0,y.default)(e,[{key:"onRoomKeyEvent",value:function(e){}},{key:"importRoomKey",value:function(e){}},{key:"hasKeysForKeyRequest",value:function(e){return g.default.resolve(!1)}},{key:"shareKeysWithDevice",value:function(e){throw new Error("shareKeysWithDevice not supported for this DecryptionAlgorithm")}}]),e}();r.DecryptionAlgorithm=S;var k=function(e){function t(e,r,n){(0,v.default)(this,t);var i=(0,d.default)(this,(t.__proto__||(0,c.default)(t)).call(this,r));return i.code=e,i.name="DecryptionError",i.detailedString=o(i,n),i}return(0,p.default)(t,e),t}(Error);r.DecryptionError=k;r.UnknownDeviceError=function(e){function t(e,r){(0,v.default)(this,t);var n=(0,d.default)(this,(t.__proto__||(0,c.default)(t)).call(this,e));return n.name="UnknownDeviceError",n.devices=r,n}return(0,p.default)(t,e),t}(Error)},{"babel-runtime/core-js/object/get-prototype-of":68,"babel-runtime/core-js/object/keys":69,"babel-runtime/helpers/classCallCheck":79,"babel-runtime/helpers/createClass":80,"babel-runtime/helpers/inherits":82,"babel-runtime/helpers/possibleConstructorReturn":83,bluebird:89}],12:[function(e,t,r){"use strict";var n=e("./base");e("./olm"),e("./megolm"),t.exports.ENCRYPTION_CLASSES=n.ENCRYPTION_CLASSES,t.exports.DECRYPTION_CLASSES=n.DECRYPTION_CLASSES,t.exports.DecryptionError=n.DecryptionError},{"./base":11,"./megolm":13,"./olm":14}],13:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){this.sessionId=e,this.useCount=0,this.creationTime=(new Date).getTime(),this.sharedWithDevices={}}function i(e){k.EncryptionAlgorithm.call(this,e),this._setupPromise=b.default.resolve(),this._outboundSessions={},this._sessionRotationPeriodMsgs=100,this._sessionRotationPeriodMs=6048e5,void 0!==e.config.rotation_period_ms&&(this._sessionRotationPeriodMs=e.config.rotation_period_ms),void 0!==e.config.rotation_period_msgs&&(this._sessionRotationPeriodMsgs=e.config.rotation_period_msgs)}function s(e){k.DecryptionAlgorithm.call(this,e),this._pendingEvents={},this.olmlib=S}var a=e("babel-runtime/core-js/set"),u=n(a),c=e("babel-runtime/core-js/json/stringify"),l=n(c),d=e("babel-runtime/helpers/defineProperty"),f=n(d),p=e("babel-runtime/core-js/object/keys"),h=n(p),v=e("babel-runtime/core-js/get-iterator"),m=n(v),y=e("babel-runtime/regenerator"),_=n(y),g=e("bluebird"),b=n(g),E=e("../../logger"),w=e("../../utils"),S=e("../olmlib"),k=e("./base");o.prototype.needsRotation=function(e,t){var r=(new Date).getTime()-this.creationTime;return(this.useCount>=e||r>=t)&&(E.log("Rotating megolm session after "+this.useCount+" messages, "+r+"ms"),!0)},o.prototype.markSharedWithDevice=function(e,t,r){this.sharedWithDevices[e]||(this.sharedWithDevices[e]={}),this.sharedWithDevices[e][t]=r},o.prototype.sharedWithTooManyDevices=function(e){for(var t in this.sharedWithDevices)if(this.sharedWithDevices.hasOwnProperty(t)){if(!e.hasOwnProperty(t))return E.log("Starting new session because we shared with "+t),!0;for(var r in this.sharedWithDevices[t])if(this.sharedWithDevices[t].hasOwnProperty(r)&&!e[t].hasOwnProperty(r))return E.log("Starting new session because we shared with "+t+":"+r),!0}},w.inherits(i,k.EncryptionAlgorithm),i.prototype._ensureOutboundSession=function(e){function t(){return o}var r=function(){var t=(0,g.coroutine)(_.default.mark(function t(r){var i,s,a,u,c,l;return _.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(o=r,o&&o.needsRotation(n._sessionRotationPeriodMsgs,n._sessionRotationPeriodMs)&&(E.log("Starting new megolm session because we need to rotate."),o=null),o&&o.sharedWithTooManyDevices(e)&&(o=null),o){t.next=9;break}return E.log("Starting new megolm session for room "+n._roomId),t.next=7,(0,g.resolve)(n._prepareNewSession());case 7:o=t.sent,n._outboundSessions[o.sessionId]=o;case 9:i={},t.t0=_.default.keys(e);case 11:if((t.t1=t.t0()).done){t.next=30;break}if(s=t.t1.value,e.hasOwnProperty(s)){t.next=15;break}return t.abrupt("continue",11);case 15:a=e[s],t.t2=_.default.keys(a);case 17:if((t.t3=t.t2()).done){t.next=28;break}if(u=t.t3.value,a.hasOwnProperty(u)){t.next=21;break}return t.abrupt("continue",17);case 21:if(c=a[u],(l=c.getIdentityKey())!=n._olmDevice.deviceCurve25519Key){t.next=25;break}return t.abrupt("continue",17);case 25:o.sharedWithDevices[s]&&void 0!==o.sharedWithDevices[s][u]||(i[s]=i[s]||[],i[s].push(c)),t.next=17;break;case 28:t.next=11;break;case 30:return t.abrupt("return",n._shareKeyWithDevices(o,i));case 31:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}(),n=this,o=void 0,i=this._setupPromise.then(r);return this._setupPromise=i.then(t,t),i.then(t)},i.prototype._prepareNewSession=(0,g.coroutine)(_.default.mark(function e(){var t,r;return _.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=this._olmDevice.createOutboundGroupSession(),r=this._olmDevice.getOutboundGroupSessionKey(t),e.next=4,(0,g.resolve)(this._olmDevice.addInboundGroupSession(this._roomId,this._olmDevice.deviceCurve25519Key,[],t,r.key,{ed25519:this._olmDevice.deviceEd25519Key}));case 4:return this._crypto.backupInfo&&this._crypto.backupGroupSession(this._roomId,this._olmDevice.deviceCurve25519Key,[],t,r.key).catch(function(e){console.log("Failed to back up group session",e)}),e.abrupt("return",new o(t));case 6:case"end":return e.stop()}},e,this)})),i.prototype._splitUserDeviceMap=function(e,t,r,n){var o=[],i=0,s=0,a=!0,u=!1,c=void 0;try{for(var l,d=(0,m.default)((0,h.default)(n));!(a=(l=d.next()).done);a=!0)for(var f=l.value,p=n[f],v=r[f],y=0;y<p.length;y++){var _=p[y],g=_.deviceId,b=v[g];b.sessionId?(E.log("share keys with device "+f+":"+g),s>20&&(s=0,i++),o[i]||(o[i]=[]),o[i].push({userId:f,deviceInfo:_}),s++):e.markSharedWithDevice(f,g,t)}}catch(e){u=!0,c=e}finally{try{!a&&d.return&&d.return()}finally{if(u)throw c}}return o},i.prototype._encryptAndSendKeysToDevices=function(e,t,r,n){for(var o=this,i={algorithm:S.OLM_ALGORITHM,sender_key:this._olmDevice.deviceCurve25519Key,ciphertext:{}},s={},a=[],u=0;u<r.length;u++){var c=r[u],l=c.userId,d=c.deviceInfo,f=d.deviceId;s[l]||(s[l]={}),s[l][f]=i,a.push(S.encryptMessageForDevice(i.ciphertext,this._userId,this._deviceId,this._olmDevice,l,d,n))}return b.default.all(a).then(function(){return o._baseApis.sendToDevice("m.room.encrypted",s).then(function(){var r=!0,n=!1,o=void 0;try{for(var i,a=(0,m.default)((0,h.default)(s));!(r=(i=a.next()).done);r=!0){var u=i.value,c=!0,l=!1,d=void 0;try{for(var f,p=(0,m.default)((0,h.default)(s[u]));!(c=(f=p.next()).done);c=!0){var v=f.value;e.markSharedWithDevice(u,v,t)}}catch(e){l=!0,d=e}finally{try{!c&&p.return&&p.return()}finally{if(l)throw d}}}}catch(e){n=!0,o=e}finally{try{!r&&a.return&&a.return()}finally{if(n)throw o}}})})},i.prototype.reshareKeyWithDevice=function(){var e=(0,g.coroutine)(_.default.mark(function e(t,r,n,o){var i,s,a,u,c;return _.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(i=this._outboundSessions[r]){e.next=4;break}return E.debug("Session ID "+r+" not found: not re-sharing keys"),e.abrupt("return");case 4:if(void 0!==i.sharedWithDevices[n]){e.next=7;break}return E.debug("Session ID "+r+" never shared with user "+n),e.abrupt("return");case 7:if(void 0!==(s=i.sharedWithDevices[n][o.deviceId])){e.next=11;break}return E.debug("Session ID "+r+" never shared with device "+n+":"+o.deviceId),e.abrupt("return");case 11:return e.next=13,(0,g.resolve)(this._olmDevice.getInboundGroupSessionKey(this._roomId,t,r,s));case 13:if(a=e.sent){e.next=17;break}return E.warn("No outbound session key found for "+r+": not re-sharing keys"),e.abrupt("return");case 17:return e.next=19,(0,g.resolve)(S.ensureOlmSessionsForDevices(this._olmDevice,this._baseApis,(0,f.default)({},n,(0,f.default)({},o.deviceId,o))));case 19:return u={type:"m.forwarded_room_key",content:{algorithm:S.MEGOLM_ALGORITHM,room_id:this._roomId,session_id:r,session_key:a.key,chain_index:a.chain_index,sender_key:t,sender_claimed_ed25519_key:a.sender_claimed_ed25519_key,forwarding_curve25519_key_chain:a.forwarding_curve25519_key_chain}},c={algorithm:S.OLM_ALGORITHM,sender_key:this._olmDevice.deviceCurve25519Key,ciphertext:{}},e.next=23,(0,g.resolve)(S.encryptMessageForDevice(c.ciphertext,this._userId,this._deviceId,this._olmDevice,n,o,u));case 23:return e.next=25,(0,g.resolve)(this._baseApis.sendToDevice("m.room.encrypted",(0,f.default)({},n,(0,f.default)({},o.deviceId,c))));case 25:E.debug("Re-shared key for session "+r+" with "+n+":"+o.deviceId);case 26:case"end":return e.stop()}},e,this)}));return function(t,r,n,o){return e.apply(this,arguments)}}(),i.prototype._shareKeyWithDevices=function(){var e=(0,g.coroutine)(_.default.mark(function e(t,r){var n,o,i,s,a;return _.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=this._olmDevice.getOutboundGroupSessionKey(t.sessionId),o={type:"m.room_key",content:{algorithm:S.MEGOLM_ALGORITHM,room_id:this._roomId,session_id:t.sessionId,session_key:n.key,chain_index:n.chain_index}},e.next=4,(0,g.resolve)(S.ensureOlmSessionsForDevices(this._olmDevice,this._baseApis,r));case 4:i=e.sent,s=this._splitUserDeviceMap(t,n.chain_index,i,r),a=0;case 7:if(!(a<s.length)){e.next=21;break}return e.prev=8,e.next=11,(0,g.resolve)(this._encryptAndSendKeysToDevices(t,n.chain_index,s[a],o));case 11:E.log("Completed megolm keyshare in "+this._roomId+" (slice "+(a+1)+"/"+s.length+")"),e.next=18;break;case 14:throw e.prev=14,e.t0=e.catch(8),E.log("megolm keyshare in "+this._roomId+" (slice "+(a+1)+"/"+s.length+") failed"),e.t0;case 18:a++,e.next=7;break;case 21:case"end":return e.stop()}},e,this,[[8,14]])}));return function(t,r){return e.apply(this,arguments)}}(),i.prototype.encryptMessage=function(e,t,r){var n=this;return E.log("Starting to encrypt event for "+this._roomId),this._getDevicesInRoom(e).then(function(e){return n._checkForUnknownDevices(e),n._ensureOutboundSession(e)}).then(function(e){var o={room_id:n._roomId,type:t,content:r},i=n._olmDevice.encryptGroupMessage(e.sessionId,(0,l.default)(o)),s={algorithm:S.MEGOLM_ALGORITHM,sender_key:n._olmDevice.deviceCurve25519Key,ciphertext:i,session_id:e.sessionId,device_id:n._deviceId};return e.useCount++,s})},i.prototype.forceDiscardSession=function(){this._setupPromise=this._setupPromise.then(function(){return null})},i.prototype._checkForUnknownDevices=function(e){var t={};if((0,h.default)(e).forEach(function(r){(0,h.default)(e[r]).forEach(function(n){var o=e[r][n];o.isUnverified()&&!o.isKnown()&&(t[r]||(t[r]={}),t[r][n]=o)})}),(0,h.default)(t).length)throw new k.UnknownDeviceError("This room contains unknown devices which have not been verified. We strongly recommend you verify them before continuing.",t)},i.prototype._getDevicesInRoom=function(){var e=(0,g.coroutine)(_.default.mark(function e(t){var r,n,o,i,s,a,u;return _.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,g.resolve)(t.getEncryptionTargetMembers());case 2:return r=e.sent,n=w.map(r,function(e){return e.userId}),o=this._crypto.getGlobalBlacklistUnverifiedDevices(),"boolean"==typeof t.getBlacklistUnverifiedDevices()&&(o=t.getBlacklistUnverifiedDevices()),e.next=8,(0,g.resolve)(this._crypto.downloadKeys(n,!1));case 8:i=e.sent,e.t0=_.default.keys(i);case 10:if((e.t1=e.t0()).done){e.next=25;break}if(s=e.t1.value,i.hasOwnProperty(s)){e.next=14;break}return e.abrupt("continue",10);case 14:a=i[s],e.t2=_.default.keys(a);case 16:if((e.t3=e.t2()).done){e.next=23;break}if(u=e.t3.value,a.hasOwnProperty(u)){e.next=20;break}return e.abrupt("continue",16);case 20:(a[u].isBlocked()||a[u].isUnverified()&&o)&&delete a[u],e.next=16;break;case 23:e.next=10;break;case 25:return e.abrupt("return",i);case 26:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),w.inherits(s,k.DecryptionAlgorithm),s.prototype.decryptEvent=function(){var e=(0,g.coroutine)(_.default.mark(function e(t){var r,n,o,i;return _.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.getWireContent(),r.sender_key&&r.session_id&&r.ciphertext){e.next=3;break}throw new k.DecryptionError("MEGOLM_MISSING_FIELDS","Missing fields in input");case 3:return this._addEventToPendingList(t),n=void 0,e.prev=5,e.next=8,(0,g.resolve)(this._olmDevice.decryptGroupMessage(t.getRoomId(),r.sender_key,r.session_id,r.ciphertext,t.getId(),t.getTs()));case 8:n=e.sent,e.next=16;break;case 11:throw e.prev=11,e.t0=e.catch(5),o="OLM_DECRYPT_GROUP_MESSAGE_ERROR","OLM.UNKNOWN_MESSAGE_INDEX"===e.t0.message&&(this._requestKeysForEvent(t),o="OLM_UNKNOWN_MESSAGE_INDEX"),new k.DecryptionError(o,e.t0.toString(),{session:r.sender_key+"|"+r.session_id});case 16:if(null!==n){e.next=19;break}throw this._requestKeysForEvent(t),new k.DecryptionError("MEGOLM_UNKNOWN_INBOUND_SESSION_ID","The sender's device has not sent us the keys for this message.",{session:r.sender_key+"|"+r.session_id});case 19:if(this._removeEventFromPendingList(t),i=JSON.parse(n.result),i.room_id===t.getRoomId()){e.next=23;break}throw new k.DecryptionError("MEGOLM_BAD_ROOM","Message intended for room "+i.room_id);case 23:return e.abrupt("return",{clearEvent:i,senderCurve25519Key:n.senderKey,claimedEd25519Key:n.keysClaimed.ed25519,forwardingCurve25519KeyChain:n.forwardingCurve25519KeyChain});case 24:case"end":return e.stop()}},e,this,[[5,11]])}));return function(t){return e.apply(this,arguments)}}(),s.prototype._requestKeysForEvent=function(e){var t=e.getSender(),r=e.getWireContent(),n=[{userId:this._userId,deviceId:"*"}];t!=this._userId&&n.push({userId:t,deviceId:r.device_id}),this._crypto.requestRoomKey({room_id:e.getRoomId(),algorithm:r.algorithm,sender_key:r.sender_key,session_id:r.session_id},n)},s.prototype._addEventToPendingList=function(e){var t=e.getWireContent(),r=t.sender_key+"|"+t.session_id;this._pendingEvents[r]||(this._pendingEvents[r]=new u.default),this._pendingEvents[r].add(e)},s.prototype._removeEventFromPendingList=function(e){var t=e.getWireContent(),r=t.sender_key+"|"+t.session_id;this._pendingEvents[r]&&(this._pendingEvents[r].delete(e),0===this._pendingEvents[r].size&&delete this._pendingEvents[r])},s.prototype.onRoomKeyEvent=function(e){var t=this,r=e.getContent(),n=r.session_id,o=e.getSenderKey(),i=[],s=!1,a=void 0;if(!r.room_id||!n||!r.session_key)return void E.error("key event is missing fields");if(!o)return void E.error("key event has no sender key (not encrypted?)");if("m.forwarded_room_key"==e.getType()){if(s=!0,i=r.forwarding_curve25519_key_chain,w.isArray(i)||(i=[]),i=i.slice(),i.push(o),!(o=r.sender_key))return void E.error("forwarded_room_key event is missing sender_key field");var u=r.sender_claimed_ed25519_key;if(!u)return void E.error("forwarded_room_key_event is missing sender_claimed_ed25519_key field");a={ed25519:u}}else a=e.getKeysClaimed();return E.log("Adding key for megolm session "+o+"|"+n),this._olmDevice.addInboundGroupSession(r.room_id,o,i,n,r.session_key,a,s).then(function(){t._crypto.cancelRoomKeyRequest({algorithm:r.algorithm,room_id:r.room_id,session_id:r.session_id,sender_key:o}),t._retryDecryption(o,n)}).then(function(){t._crypto.backupInfo&&t._crypto.backupGroupSession(r.room_id,o,i,r.session_id,r.session_key,a,s).catch(function(e){console.log("Failed to back up group session",e)})}).catch(function(e){E.error("Error handling m.room_key_event: "+e)})},s.prototype.hasKeysForKeyRequest=function(e){var t=e.requestBody;return this._olmDevice.hasInboundSessionKeys(t.room_id,t.sender_key,t.session_id)},s.prototype.shareKeysWithDevice=function(e){var t=this,r=e.userId,n=e.deviceId,o=this._crypto.getStoredDevice(r,n),i=e.requestBody;this.olmlib.ensureOlmSessionsForDevices(this._olmDevice,this._baseApis,(0,f.default)({},r,[o])).then(function(e){return e[r][n].sessionId?(E.log("sharing keys for session "+i.sender_key+"|"+i.session_id+" with device "+r+":"+n),t._buildKeyForwardingMessage(i.room_id,i.sender_key,i.session_id)):null}).then(function(e){var i={algorithm:S.OLM_ALGORITHM,sender_key:t._olmDevice.deviceCurve25519Key,ciphertext:{}};return t.olmlib.encryptMessageForDevice(i.ciphertext,t._userId,t._deviceId,t._olmDevice,r,o,e).then(function(){var e=(0,f.default)({},r,(0,f.default)({},n,i));return t._baseApis.sendToDevice("m.room.encrypted",e)})}).done()},s.prototype._buildKeyForwardingMessage=function(){var e=(0,g.coroutine)(_.default.mark(function e(t,r,n){var o;return _.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,g.resolve)(this._olmDevice.getInboundGroupSessionKey(t,r,n));case 2:return o=e.sent,e.abrupt("return",{type:"m.forwarded_room_key",content:{algorithm:S.MEGOLM_ALGORITHM,room_id:t,sender_key:r,sender_claimed_ed25519_key:o.sender_claimed_ed25519_key,session_id:n,session_key:o.key,chain_index:o.chain_index,forwarding_curve25519_key_chain:o.forwarding_curve25519_key_chain}});case 4:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}(),s.prototype.importRoomKey=function(e){var t=this;return this._olmDevice.addInboundGroupSession(e.room_id,e.sender_key,e.forwarding_curve25519_key_chain,e.session_id,e.session_key,e.sender_claimed_keys,!0).then(function(){t._crypto.backupInfo&&t._crypto.backupGroupSession(e.room_id,e.sender_key,e.forwarding_curve25519_key_chain,e.session_id,e.session_key,e.sender_claimed_keys,!0).catch(function(e){console.log("Failed to back up group session",e)}),t._retryDecryption(e.sender_key,e.session_id)})},s.prototype._retryDecryption=function(e,t){var r=e+"|"+t,n=this._pendingEvents[r];if(n){delete this._pendingEvents[r];var o=!0,i=!1,s=void 0;try{for(var a,u=(0,m.default)(n);!(o=(a=u.next()).done);o=!0){a.value.attemptDecryption(this._crypto)}}catch(e){i=!0,s=e}finally{try{!o&&u.return&&u.return()}finally{if(i)throw s}}}},k.registerAlgorithm(S.MEGOLM_ALGORITHM,i,s)},{"../../logger":29,"../../utils":55,"../olmlib":18,"./base":11,"babel-runtime/core-js/get-iterator":58,"babel-runtime/core-js/json/stringify":60,"babel-runtime/core-js/object/keys":69,"babel-runtime/core-js/set":76,"babel-runtime/helpers/defineProperty":81,"babel-runtime/regenerator":86,bluebird:89}],14:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){y.EncryptionAlgorithm.call(this,e),this._sessionPrepared=!1,this._prepPromise=null}function i(e){y.DecryptionAlgorithm.call(this,e)}var s=e("babel-runtime/core-js/json/stringify"),a=n(s),u=e("babel-runtime/regenerator"),c=n(u),l=e("bluebird"),d=n(l),f=e("../../logger"),p=e("../../utils"),h=e("../olmlib"),v=e("../deviceinfo"),m=v.DeviceVerification,y=e("./base");p.inherits(o,y.EncryptionAlgorithm),o.prototype._ensureSession=function(e){if(this._prepPromise)return this._prepPromise;if(this._sessionPrepared)return d.default.resolve();var t=this;return this._prepPromise=t._crypto.downloadKeys(e).then(function(r){return t._crypto.ensureOlmSessionsForUsers(e)}).then(function(){t._sessionPrepared=!0}).finally(function(){t._prepPromise=null}),this._prepPromise},o.prototype.encryptMessage=function(){var e=(0,l.coroutine)(c.default.mark(function e(t,r,n){var o,i,s,a,u,f,v,y,_,g,b,E;return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,l.resolve)(t.getEncryptionTargetMembers());case 2:return o=e.sent,i=p.map(o,function(e){return e.userId}),s=this,e.next=7,(0,l.resolve)(this._ensureSession(i));case 7:a={room_id:t.roomId,type:r,content:n},u={algorithm:h.OLM_ALGORITHM,sender_key:s._olmDevice.deviceCurve25519Key,ciphertext:{}},f=[],v=0;case 11:if(!(v<i.length)){e.next=29;break}y=i[v],_=s._crypto.getStoredDevicesForUser(y),g=0;case 15:if(!(g<_.length)){e.next=26;break}if(b=_[g],(E=b.getIdentityKey())!=s._olmDevice.deviceCurve25519Key){e.next=20;break}return e.abrupt("continue",23);case 20:if(b.verified!=m.BLOCKED){e.next=22;break}return e.abrupt("continue",23);case 22:f.push(h.encryptMessageForDevice(u.ciphertext,s._userId,s._deviceId,s._olmDevice,y,b,a));case 23:++g,e.next=15;break;case 26:++v,e.next=11;break;case 29:return e.next=31,(0,l.resolve)(d.default.all(f).return(u));case 31:return e.abrupt("return",e.sent);case 32:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}(),p.inherits(i,y.DecryptionAlgorithm),i.prototype.decryptEvent=function(){var e=(0,l.coroutine)(c.default.mark(function e(t){var r,n,o,i,s,a,u;return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.getWireContent(),n=r.sender_key,o=r.ciphertext){e.next=5;break}throw new y.DecryptionError("OLM_MISSING_CIPHERTEXT","Missing ciphertext");case 5:if(this._olmDevice.deviceCurve25519Key in o){e.next=7;break}throw new y.DecryptionError("OLM_NOT_INCLUDED_IN_RECIPIENTS","Not included in recipients");case 7:return i=o[this._olmDevice.deviceCurve25519Key],s=void 0,e.prev=9,e.next=12,(0,l.resolve)(this._decryptMessage(n,i));case 12:s=e.sent,e.next=18;break;case 15:throw e.prev=15,e.t0=e.catch(9),new y.DecryptionError("OLM_BAD_ENCRYPTED_MESSAGE","Bad Encrypted Message",{sender:n,err:e.t0});case 18:if(a=JSON.parse(s),a.recipient==this._userId){e.next=21;break}throw new y.DecryptionError("OLM_BAD_RECIPIENT","Message was intented for "+a.recipient);case 21:if(a.recipient_keys.ed25519==this._olmDevice.deviceEd25519Key){e.next=23;break}throw new y.DecryptionError("OLM_BAD_RECIPIENT_KEY","Message not intended for this device",{intended:a.recipient_keys.ed25519,our_key:this._olmDevice.deviceEd25519Key});case 23:if(a.sender==t.getSender()){e.next=25;break}throw new y.DecryptionError("OLM_FORWARDED_MESSAGE","Message forwarded from "+a.sender,{reported_sender:t.getSender()});case 25:if(a.room_id===t.getRoomId()){e.next=27;break}throw new y.DecryptionError("OLM_BAD_ROOM","Message intended for room "+a.room_id,{reported_room:t.room_id});case 27:return u=a.keys||{},e.abrupt("return",{clearEvent:a,senderCurve25519Key:n,claimedEd25519Key:u.ed25519||null});case 29:case"end":return e.stop()}},e,this,[[9,15]])}));return function(t){return e.apply(this,arguments)}}(),i.prototype._decryptMessage=function(){var e=(0,l.coroutine)(c.default.mark(function e(t,r){var n,o,i,s,u,d,p;return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,l.resolve)(this._olmDevice.getSessionIdsForDevice(t));case 2:n=e.sent,o={},i=0;case 5:if(!(i<n.length)){e.next=26;break}return s=n[i],e.prev=7,e.next=10,(0,l.resolve)(this._olmDevice.decryptMessage(t,s,r.type,r.body));case 10:return u=e.sent,f.log("Decrypted Olm message from "+t+" with session "+s),e.abrupt("return",u);case 15:return e.prev=15,e.t0=e.catch(7),e.next=19,(0,l.resolve)(this._olmDevice.matchesSession(t,s,r.type,r.body));case 19:if(!(d=e.sent)){e.next=22;break}throw new Error("Error decrypting prekey message with existing session id "+s+": "+e.t0.message);case 22:o[s]=e.t0.message;case 23:i++,e.next=5;break;case 26:if(0===r.type){e.next=30;break}if(0!==n.length){e.next=29;break}throw new Error("No existing sessions");case 29:throw new Error("Error decrypting non-prekey message with existing sessions: "+(0,a.default)(o));case 30:return p=void 0,e.prev=31,e.next=34,(0,l.resolve)(this._olmDevice.createInboundSession(t,r.type,r.body));case 34:p=e.sent,e.next=41;break;case 37:throw e.prev=37,e.t1=e.catch(31),o["(new)"]=e.t1.message,new Error("Error decrypting prekey message: "+(0,a.default)(o));case 41:return f.log("created new inbound Olm session ID "+p.session_id+" with "+t),e.abrupt("return",p.payload);case 43:case"end":return e.stop()}},e,this,[[7,15],[31,37]])}));return function(t,r){return e.apply(this,arguments)}}(),y.registerAlgorithm(h.OLM_ALGORITHM,o,i)},{"../../logger":29,"../../utils":55,"../deviceinfo":16,"../olmlib":18,"./base":11,"babel-runtime/core-js/json/stringify":60,"babel-runtime/regenerator":86,bluebird:89}],15:[function(e,t,r){(function(t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.keyForNewBackup=r.keyForExistingBackup=void 0;var n=e("babel-runtime/regenerator"),o=function(e){return e&&e.__esModule?e:{default:e}}(n),i=e("bluebird"),s=(r.keyForExistingBackup=function(){var e=(0,
i.coroutine)(o.default.mark(function e(r,n){var a;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t.Olm){e.next=2;break}throw new Error("Olm is not available");case 2:if(a=r.auth_data,a.private_key_salt&&a.private_key_iterations){e.next=5;break}throw new Error("Salt and/or iterations not found: this backup cannot be restored with a passphrase");case 5:return e.next=7,(0,i.resolve)(s(n,r.auth_data.private_key_salt,r.auth_data.private_key_iterations));case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}(),r.keyForNewBackup=function(){var e=(0,i.coroutine)(o.default.mark(function e(r){var n,c;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t.Olm){e.next=2;break}throw new Error("Olm is not available");case 2:return n=(0,a.randomString)(32),e.next=5,(0,i.resolve)(s(r,n,u));case 5:return c=e.sent,e.abrupt("return",{key:c,salt:n,iterations:u});case 7:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),function(){var e=(0,i.coroutine)(o.default.mark(function e(r,n,s){var a,u,c,l;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(a=t.crypto.subtle,u=t.TextEncoder,a&&u){e.next=4;break}throw new Error("Password-based backup is not avaiable on this platform");case 4:return e.next=6,(0,i.resolve)(a.importKey("raw",(new u).encode(r),{name:"PBKDF2"},!1,["deriveBits"]));case 6:return c=e.sent,e.next=9,(0,i.resolve)(a.deriveBits({name:"PBKDF2",salt:(new u).encode(n),iterations:s,hash:"SHA-512"},c,8*t.Olm.PRIVATE_KEY_LENGTH));case 9:return l=e.sent,e.abrupt("return",new Uint8Array(l));case 11:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()),a=e("../randomstring"),u=5e5}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../randomstring":43,"babel-runtime/regenerator":86,bluebird:89}],16:[function(e,t,r){"use strict";function n(e){Object.defineProperty(this,"deviceId",{enumerable:!0,value:e}),this.algorithms=[],this.keys={},this.verified=o.UNVERIFIED,this.known=!1,this.unsigned={}}n.fromStorage=function(e,t){var r=new n(t);for(var o in e)e.hasOwnProperty(o)&&(r[o]=e[o]);return r},n.prototype.toStorage=function(){return{algorithms:this.algorithms,keys:this.keys,verified:this.verified,known:this.known,unsigned:this.unsigned}},n.prototype.getFingerprint=function(){return this.keys["ed25519:"+this.deviceId]},n.prototype.getIdentityKey=function(){return this.keys["curve25519:"+this.deviceId]},n.prototype.getDisplayName=function(){return this.unsigned.device_display_name||null},n.prototype.isBlocked=function(){return this.verified==o.BLOCKED},n.prototype.isVerified=function(){return this.verified==o.VERIFIED},n.prototype.isUnverified=function(){return this.verified==o.UNVERIFIED},n.prototype.isKnown=function(){return 1==this.known},n.DeviceVerification={VERIFIED:1,UNVERIFIED:0,BLOCKED:-1};var o=n.DeviceVerification;t.exports=n},{}],17:[function(e,t,r){(function(t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(){return Boolean(t.Olm)}function i(e,t,r,n,o,i,s){this._baseApis=e,this._sessionStore=t,this._userId=r,this._deviceId=n,this._clientStore=o,this._cryptoStore=i,this._roomList=s,this.backupInfo=null,this.backupKey=null,this._checkedForBackup=!1,this._sendingBackups=!1,this._olmDevice=new L(t,i),this._deviceList=new B(e,i,t,this._olmDevice),this._lastOneTimeKeyCheck=null,this._oneTimeKeyCheckInProgress=!1,this._roomEncryptors={},this._roomDecryptors={},this._supportedAlgorithms=P.keys(N.DECRYPTION_CLASSES),this._deviceKeys={},this._globalBlacklistUnverifiedDevices=!1,this._outgoingRoomKeyRequestManager=new j.default(e,this._deviceId,this._cryptoStore),this._receivedRoomKeyRequests=[],this._receivedRoomKeyRequestCancellations=[],this._processingRoomKeyRequests=!1,this._lazyLoadMembers=!1,this._roomDeviceTrackingState={},this._lastNewSessionForced={}}function s(e){function t(n){if(i<=n)return b.default.resolve();var o=Math.min(i-n,r);return e._olmDevice.generateOneTimeKeys(o).then(function(){return R(e)}).then(function(e){if(e.one_time_key_counts&&e.one_time_key_counts.signed_curve25519)return t(e.one_time_key_counts.signed_curve25519);throw new Error("response for uploading keys does not contain one_time_key_counts.signed_curve25519")})}var r=5;if(!e._oneTimeKeyCheckInProgress){var n=Date.now();if(!(null!==e._lastOneTimeKeyCheck&&n-e._lastOneTimeKeyCheck<6e4)){e._lastOneTimeKeyCheck=n;var o=e._olmDevice.maxNumberOfOneTimeKeys(),i=Math.floor(o/2);e._oneTimeKeyCheckInProgress=!0,b.default.resolve().then(function(){return void 0!==e._oneTimeKeyCount?b.default.resolve(e._oneTimeKeyCount):e._baseApis.uploadKeysRequest({},{device_id:e._deviceId}).then(function(e){return e.one_time_key_counts.signed_curve25519||0})}).then(function(e){return t(e)}).catch(function(e){M.error("Error uploading one-time keys",e.stack||e)}).finally(function(){e._oneTimeKeyCount=void 0,e._oneTimeKeyCheckInProgress=!1}).done()}}}Object.defineProperty(r,"__esModule",{value:!0});var a=e("babel-runtime/helpers/classCallCheck"),u=n(a),c=e("babel-runtime/helpers/defineProperty"),l=n(c),d=e("babel-runtime/core-js/set"),f=n(d),p=e("babel-runtime/core-js/object/assign"),h=n(p),v=e("babel-runtime/helpers/typeof"),m=n(v),y=e("babel-runtime/core-js/json/stringify"),_=n(y),g=e("bluebird"),b=n(g),E=e("babel-runtime/core-js/object/keys"),w=n(E),S=e("babel-runtime/core-js/get-iterator"),k=n(S),T=e("babel-runtime/regenerator"),x=n(T),R=function(){var e=(0,g.coroutine)(x.default.mark(function e(t){var r,n,o,i,s,a;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,g.resolve)(t._olmDevice.getOneTimeKeys());case 2:r=e.sent,n={},o=[];for(i in r.curve25519)r.curve25519.hasOwnProperty(i)&&(s={key:r.curve25519[i]},n["signed_curve25519:"+i]=s,o.push(t._signObject(s)));return e.next=8,(0,g.resolve)(b.default.all(o));case 8:return e.next=10,(0,g.resolve)(t._baseApis.uploadKeysRequest({one_time_keys:n},{device_id:t._deviceId}));case 10:return a=e.sent,e.next=13,(0,g.resolve)(t._olmDevice.markKeysAsPublished());case 13:return e.abrupt("return",a);case 14:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}();r.isCryptoAvailable=o,r.default=i;var I=e("events"),C=e("./OutgoingRoomKeyRequestManager"),j=n(C),O=e("./store/indexeddb-crypto-store"),A=n(O),D=e("another-json"),M=e("../logger"),P=e("../utils"),L=e("./OlmDevice"),U=e("./olmlib"),N=e("./algorithms"),F=e("./deviceinfo"),q=F.DeviceVerification,B=e("./DeviceList").default;P.inherits(i,I.EventEmitter),i.prototype.init=(0,g.coroutine)(x.default.mark(function e(){var r,n,o,i,s=this;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,g.resolve)(t.Olm.init());case 2:return r=Boolean(this._sessionStore.getEndToEndAccount()),n=void 0,e.next=6,(0,g.resolve)(this._cryptoStore.doTxn("readonly",[A.default.STORE_ACCOUNT],function(e){s._cryptoStore.getAccount(e,function(e){n=Boolean(e)})}));case 6:return r&&!n?this.emit("crypto.warning","CRYPTO_WARNING_ACCOUNT_MIGRATED"):r&&n&&this.emit("crypto.warning","CRYPTO_WARNING_OLD_VERSION_DETECTED"),e.next=9,(0,g.resolve)(this._olmDevice.init());case 9:return e.next=11,(0,g.resolve)(this._deviceList.load());case 11:this._deviceKeys["ed25519:"+this._deviceId]=this._olmDevice.deviceEd25519Key,this._deviceKeys["curve25519:"+this._deviceId]=this._olmDevice.deviceCurve25519Key,o=this._deviceList.getRawStoredDevicesForUser(this._userId),o||(o={}),o[this._deviceId]||(i={keys:this._deviceKeys,algorithms:this._supportedAlgorithms,verified:q.VERIFIED,known:!0},o[this._deviceId]=i,this._deviceList.storeDevicesForUser(this._userId,o),this._deviceList.saveIfDirty()),this._checkAndStartKeyBackup();case 17:case"end":return e.stop()}},e,this)})),i.prototype._checkAndStartKeyBackup=(0,g.coroutine)(x.default.mark(function e(){var t,r;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("Checking key backup status..."),t=void 0,e.prev=2,e.next=5,(0,g.resolve)(this._baseApis.getKeyBackupVersion());case 5:t=e.sent,e.next=13;break;case 8:return e.prev=8,e.t0=e.catch(2),console.log("Error checking for active key backup",e.t0),e.t0.httpStatus/100==4&&(this._checkedForBackup=!0),e.abrupt("return");case 13:return this._checkedForBackup=!0,e.next=16,(0,g.resolve)(this.isKeyBackupTrusted(t));case 16:r=e.sent,r.usable&&!this.backupInfo?(console.log("Found usable key backup: enabling key backups"),this._baseApis.enableKeyBackup(t)):!r.usable&&this.backupInfo?(console.log("No usable key backup: disabling key backup"),this._baseApis.disableKeyBackup()):r.usable||this.backupInfo||console.log("No usable key backup: not enabling key backup");case 18:case"end":return e.stop()}},e,this,[[2,8]])})),i.prototype.checkKeyBackup=function(){var e=(0,g.coroutine)(x.default.mark(function e(t){return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this._checkedForBackup=!1,e.next=3,(0,g.resolve)(this._checkAndStartKeyBackup());case 3:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),i.prototype.isKeyBackupTrusted=function(){var e=(0,g.coroutine)(x.default.mark(function e(t){var r,n,o,i,s,a,u,c,l,d;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r={usable:!1,sigs:[]},t&&t.algorithm&&t.auth_data&&t.auth_data.public_key&&t.auth_data.signatures){e.next=4;break}return console.log("Key backup is absent or missing required data"),e.abrupt("return",r);case 4:if((n=t.auth_data.signatures[this._userId])&&0!==n.length){e.next=8;break}return console.log("Ignoring key backup because it lacks any signatures from this user"),e.abrupt("return",r);case 8:o=!0,i=!1,s=void 0,e.prev=11,a=(0,k.default)((0,w.default)(n));case 13:if(o=(u=a.next()).done){e.next=34;break}if(c=u.value,l=this._deviceList.getStoredDevice(this._userId,c.split(":")[1])){e.next=19;break}return console.log("Ignoring signature from unknown key "+c),e.abrupt("continue",31);case 19:return d={device:l},e.prev=20,e.next=23,(0,g.resolve)(U.verifySignature(this._olmDevice,t.auth_data,this._userId,l.deviceId,l.getFingerprint()));case 23:d.valid=!0,e.next=30;break;case 26:e.prev=26,e.t0=e.catch(20),console.log("Bad signature from device "+l.deviceId,e.t0),d.valid=!1;case 30:r.sigs.push(d);case 31:o=!0,e.next=13;break;case 34:e.next=40;break;case 36:e.prev=36,e.t1=e.catch(11),i=!0,s=e.t1;case 40:e.prev=40,e.prev=41,!o&&a.return&&a.return();case 43:if(e.prev=43,!i){e.next=46;break}throw s;case 46:return e.finish(43);case 47:return e.finish(40);case 48:return r.usable=r.sigs.some(function(e){return e.valid&&e.device.isVerified()}),e.abrupt("return",r);case 50:case"end":return e.stop()}},e,this,[[11,36,40,48],[20,26],[41,,43,47]])}));return function(t){return e.apply(this,arguments)}}(),i.prototype.enableLazyLoading=function(){this._lazyLoadMembers=!0},i.prototype.registerEventHandlers=function(e){var t=this;e.on("RoomMember.membership",function(e,r,n){try{t._onRoomMembership(e,r,n)}catch(e){M.error("Error handling membership change:",e)}}),e.on("toDeviceEvent",function(e){t._onToDeviceEvent(e)})},i.prototype.start=function(){this._outgoingRoomKeyRequestManager.start()},i.prototype.stop=function(){this._outgoingRoomKeyRequestManager.stop(),this._deviceList.stop()},i.getOlmVersion=function(){return L.getOlmVersion()},i.prototype.getDeviceEd25519Key=function(){return this._olmDevice.deviceEd25519Key},i.prototype.setGlobalBlacklistUnverifiedDevices=function(e){this._globalBlacklistUnverifiedDevices=e},i.prototype.getGlobalBlacklistUnverifiedDevices=function(){return this._globalBlacklistUnverifiedDevices},i.prototype.uploadDeviceKeys=function(){var e=this,t=e._userId,r=e._deviceId,n={algorithms:e._supportedAlgorithms,device_id:r,keys:e._deviceKeys,user_id:t};return e._signObject(n).then(function(){e._baseApis.uploadKeysRequest({device_keys:n},{device_id:r})})},i.prototype.updateOneTimeKeyCount=function(e){if(!isFinite(e))throw new TypeError("Parameter for updateOneTimeKeyCount has to be a number");this._oneTimeKeyCount=e},i.prototype.downloadKeys=function(e,t){return this._deviceList.downloadKeys(e,t)},i.prototype.getStoredDevicesForUser=function(e){return this._deviceList.getStoredDevicesForUser(e)},i.prototype.getStoredDevice=function(e,t){return this._deviceList.getStoredDevice(e,t)},i.prototype.saveDeviceList=function(e){return this._deviceList.saveIfDirty(e)},i.prototype.setDeviceVerification=function(){var e=(0,g.method)(function(e,t,r,n,o){var i=this._deviceList.getRawStoredDevicesForUser(e);if(!i||!i[t])throw new Error("Unknown device "+e+":"+t);var s=i[t],a=s.verified;r?a=q.VERIFIED:null!==r&&a==q.VERIFIED&&(a=q.UNVERIFIED),n?a=q.BLOCKED:null!==n&&a==q.BLOCKED&&(a=q.UNVERIFIED);var u=s.known;return null!==o&&void 0!==o&&(u=o),s.verified===a&&s.known===u||(s.verified=a,s.known=u,this._deviceList.storeDevicesForUser(e,i),this._deviceList.saveIfDirty()),F.fromStorage(s,t)});return function(t,r,n,o,i){return e.apply(this,arguments)}}(),i.prototype.getOlmSessionsForUser=function(){var e=(0,g.coroutine)(x.default.mark(function e(t){var r,n,o,i,s,a;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:r=this.getStoredDevicesForUser(t)||[],n={},o=0;case 3:if(!(o<r.length)){e.next=13;break}return i=r[o],s=i.getIdentityKey(),e.next=8,(0,g.resolve)(this._olmDevice.getSessionInfoForDevice(s));case 8:a=e.sent,n[i.deviceId]={deviceIdKey:s,sessions:a};case 10:++o,e.next=3;break;case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),i.prototype.getEventSenderDeviceInfo=function(e){var t=e.getSenderKey(),r=e.getWireContent().algorithm;if(!t||!r)return null;if(e.getForwardingCurve25519KeyChain().length>0)return null;var n=this._deviceList.getDeviceByIdentityKey(r,t);if(null===n)return null;var o=e.getClaimedEd25519Key();return o?o!==n.getFingerprint()?(M.warn("Event "+e.getId()+" claims ed25519 key "+o+"but sender device has key "+n.getFingerprint()),null):n:(M.warn("Event "+e.getId()+" claims no ed25519 key: cannot verify sending device"),null)},i.prototype.forceDiscardSession=function(e){var t=this._roomEncryptors[e];if(void 0===t)throw new Error("Room not encrypted");if(void 0===t.forceDiscardSession)throw new Error("Room encryption algorithm doesn't support session discarding");t.forceDiscardSession()},i.prototype.setRoomEncryption=function(){var e=(0,g.coroutine)(x.default.mark(function e(t,r,n){var o,i,s,a,u;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(o=this._roomList.getRoomEncryption(t))){e.next=5;break}if((0,_.default)(o)==(0,_.default)(r)){e.next=5;break}return M.error("Ignoring m.room.encryption event which requests a change of config in "+t),e.abrupt("return");case 5:if(!(i=this._roomEncryptors[t])){e.next=8;break}return e.abrupt("return");case 8:if(s=null,o||(s=this._roomList.setRoomEncryption(t,r)),a=N.ENCRYPTION_CLASSES[r.algorithm]){e.next=13;break}throw new Error("Unable to encrypt with "+r.algorithm);case 13:if(u=new a({userId:this._userId,deviceId:this._deviceId,crypto:this,olmDevice:this._olmDevice,baseApis:this._baseApis,roomId:t,config:r}),this._roomEncryptors[t]=u,!s){e.next=18;break}return e.next=18,(0,g.resolve)(s);case 18:if(this._lazyLoadMembers){e.next=25;break}return M.log("Enabling encryption in "+t+"; starting to track device lists for all users therein"),e.next=22,(0,g.resolve)(this.trackRoomDevices(t));case 22:this.inhibitDeviceQuery||this._deviceList.refreshOutdatedDeviceLists(),e.next=26;break;case 25:M.log("Enabling encryption in "+t);case 26:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}(),i.prototype.trackRoomDevices=function(e){var t=this,r=function(){var r=(0,g.coroutine)(x.default.mark(function r(){var n,o;return x.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(t._roomEncryptors[e]){r.next=2;break}return r.abrupt("return");case 2:if(n=t._clientStore.getRoom(e)){r.next=5;break}throw new Error("Unable to start tracking devices in unknown room "+e);case 5:return M.log("Starting to track devices for room "+e+" ..."),r.next=8,(0,g.resolve)(n.getEncryptionTargetMembers());case 8:o=r.sent,o.forEach(function(e){t._deviceList.startTrackingDeviceList(e.userId)});case 10:case"end":return r.stop()}},r,t)}));return function(){return r.apply(this,arguments)}}(),n=this._roomDeviceTrackingState[e];return n||(n=r(),this._roomDeviceTrackingState[e]=n),n},i.prototype.ensureOlmSessionsForUsers=function(e){for(var t={},r=0;r<e.length;++r){var n=e[r];t[n]=[];for(var o=this.getStoredDevicesForUser(n)||[],i=0;i<o.length;++i){var s=o[i];s.getIdentityKey()!=this._olmDevice.deviceCurve25519Key&&(s.verified!=q.BLOCKED&&t[n].push(s))}}return U.ensureOlmSessionsForDevices(this._olmDevice,this._baseApis,t)},i.prototype.exportRoomKeys=(0,g.coroutine)(x.default.mark(function e(){var t,r=this;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=[],e.next=3,(0,g.resolve)(this._cryptoStore.doTxn("readonly",[A.default.STORE_INBOUND_GROUP_SESSIONS],function(e){r._cryptoStore.getAllEndToEndInboundGroupSessions(e,function(e){if(null!==e){var n=r._olmDevice.exportInboundGroupSession(e.senderKey,e.sessionId,e.sessionData);delete n.first_known_index,n.algorithm=U.MEGOLM_ALGORITHM,t.push(n)}})}));case 3:return e.abrupt("return",t);case 4:case"end":return e.stop()}},e,this)})),i.prototype.importRoomKeys=function(e){var t=this;return b.default.map(e,function(e){return e.room_id&&e.algorithm?t._getRoomDecryptor(e.room_id,e.algorithm).importRoomKey(e):(M.warn("ignoring room key entry with missing fields",e),null)})},i.prototype._maybeSendKeyBackup=function(){var e=(0,g.coroutine)(x.default.mark(function e(t,r){var n,o=this;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===r&&(r=!0),this._sendingBackups){e.next=11;break}return this._sendingBackups=!0,e.prev=3,e.delegateYield(x.default.mark(function e(){var n,i,s,a,u,c,l,d,f,p,h,v,m,y,E;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===t&&(t=1e4*Math.random()),e.next=3,(0,g.resolve)(b.default.delay(t));case 3:n=0;case 4:if(o.backupKey){e.next=7;break}return e.abrupt("return",{v:void 0});case 7:return e.next=9,(0,g.resolve)(o._cryptoStore.getSessionsNeedingBackup(10));case 9:if(i=e.sent,i.length){e.next=12;break}return e.abrupt("return",{v:void 0});case 12:s={},a=!0,u=!1,c=void 0,e.prev=16,l=(0,k.default)(i);case 18:if(a=(d=l.next()).done){e.next=37;break}return f=d.value,p=f.sessionData.room_id,void 0===s[p]&&(s[p]={sessions:{}}),e.next=24,(0,g.resolve)(o._olmDevice.exportInboundGroupSession(f.senderKey,f.sessionId,f.sessionData));case 24:h=e.sent,h.algorithm=U.MEGOLM_ALGORITHM,delete h.session_id,delete h.room_id,v=h.first_known_index,delete h.first_known_index,m=o.backupKey.encrypt((0,_.default)(h)),y=(h.forwarding_curve25519_key_chain||[]).length,E=o._deviceList.getDeviceByIdentityKey(U.MEGOLM_ALGORITHM,f.senderKey),s[p].sessions[f.sessionId]={first_message_index:v,forwarded_count:y,is_verified:!(!E||!E.isVerified()),session_data:m};case 34:a=!0,e.next=18;break;case 37:e.next=43;break;case 39:e.prev=39,e.t0=e.catch(16),u=!0,c=e.t0;case 43:e.prev=43,e.prev=44,!a&&l.return&&l.return();case 46:if(e.prev=46,!u){e.next=49;break}throw c;case 49:return e.finish(46);case 50:return e.finish(43);case 51:return e.prev=51,e.next=54,(0,g.resolve)(o._baseApis.sendKeyBackup(void 0,void 0,o.backupInfo.version,{rooms:s}));case 54:return n=0,e.next=57,(0,g.resolve)(o._cryptoStore.unmarkSessionsNeedingBackup(i));case 57:e.next=65;break;case 59:if(e.prev=59,e.t1=e.catch(51),n++,console.log("send failed",e.t1),400!==e.t1.httpStatus&&403!==e.t1.httpStatus&&401!==e.t1.httpStatus&&r){e.next=65;break}throw e.t1;case 65:if(!n){e.next=68;break}return e.next=68,(0,g.resolve)(new b.default(function(e,t){setTimeout(e,1e3*Math.pow(2,Math.min(n-1,4)))}));case 68:e.next=4;break;case 70:case"end":return e.stop()}},e,o,[[16,39,43,51],[44,,46,50],[51,59]])})(),"t0",5);case 5:if(n=e.t0,"object"!==(void 0===n?"undefined":(0,m.default)(n))){e.next=8;break}return e.abrupt("return",n.v);case 8:return e.prev=8,this._sendingBackups=!1,e.finish(8);case 11:case"end":return e.stop()}},e,this,[[3,,8,11]])}));return function(t,r){return e.apply(this,arguments)}}(),i.prototype.backupGroupSession=function(){var e=(0,g.coroutine)(x.default.mark(function e(t,r,n,o,i,s,a){return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.backupInfo){e.next=2;break}throw new Error("Key backups are not enabled");case 2:return e.next=4,(0,g.resolve)(this._cryptoStore.markSessionsNeedingBackup([{senderKey:r,sessionId:o}]));case 4:return e.next=6,(0,g.resolve)(this._maybeSendKeyBackup());case 6:case"end":return e.stop()}},e,this)}));return function(t,r,n,o,i,s,a){return e.apply(this,arguments)}}(),i.prototype.backupAllGroupSessions=function(){var e=(0,g.coroutine)(x.default.mark(function e(t){var r=this;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,g.resolve)(this._cryptoStore.doTxn("readwrite",[A.default.STORE_INBOUND_GROUP_SESSIONS,A.default.STORE_BACKUP],function(e){r._cryptoStore.getAllEndToEndInboundGroupSessions(e,function(t){null!==t&&r._cryptoStore.markSessionsNeedingBackup([t],e)})}));case 2:return e.next=4,(0,g.resolve)(this._maybeSendKeyBackup(0,!1));case 4:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),i.prototype.encryptEvent=function(){var e=(0,g.coroutine)(x.default.mark(function e(t,r){var n,o,i,s,a;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r){e.next=2;break}throw new Error("Cannot send encrypted messages in unknown rooms");case 2:if(n=t.getRoomId(),o=this._roomEncryptors[n]){e.next=6;break}throw new Error("Room was previously configured to use encryption, but is no longer. Perhaps the homeserver is hiding the configuration event.");case 6:return this._roomDeviceTrackingState[n]||this.trackRoomDevices(n),e.next=9,(0,g.resolve)(this._roomDeviceTrackingState[n]);case 9:return i=t.getContent(),s=i["m.relates_to"],s&&(i=(0,h.default)({},i),delete i["m.relates_to"]),e.next=14,(0,g.resolve)(o.encryptMessage(r,t.getType(),i));case 14:a=e.sent,s&&(a["m.relates_to"]=s),t.makeEncrypted("m.room.encrypted",a,this._olmDevice.deviceCurve25519Key,this._olmDevice.deviceEd25519Key);case 17:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}(),i.prototype.decryptEvent=function(e){if(e.isRedacted())return b.default.resolve({clearEvent:{room_id:e.getRoomId(),type:"m.room.message",content:{}}});var t=e.getWireContent();return this._getRoomDecryptor(e.getRoomId(),t.algorithm).decryptEvent(e)},i.prototype.handleDeviceListChanges=function(){var e=(0,g.coroutine)(x.default.mark(function e(t,r){return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t.oldSyncToken){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,(0,g.resolve)(this._evalDeviceListChanges(r));case 4:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}(),i.prototype.requestRoomKey=function(e,t){this._outgoingRoomKeyRequestManager.sendRoomKeyRequest(e,t).catch(function(e){M.error("Error requesting key for event",e)}).done()},i.prototype.cancelRoomKeyRequest=function(e,t){this._outgoingRoomKeyRequestManager.cancelRoomKeyRequest(e,t).catch(function(e){M.warn("Error clearing pending room key requests",e)}).done()},i.prototype.onCryptoEvent=function(){var e=(0,g.coroutine)(x.default.mark(function e(t){var r,n;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.getRoomId(),n=t.getContent(),e.prev=2,e.next=5,(0,g.resolve)(this.setRoomEncryption(r,n,!0));case 5:e.next=10;break;case 7:e.prev=7,e.t0=e.catch(2),M.error("Error configuring encryption in room "+r+":",e.t0);case 10:case"end":return e.stop()}},e,this,[[2,7]])}));return function(t){return e.apply(this,arguments)}}(),i.prototype.onSyncWillProcess=function(){var e=(0,g.method)(function(e){e.oldSyncToken||(M.log("Initial sync performed - resetting device tracking state"),this._deviceList.stopTrackingAllDeviceLists(),this._roomDeviceTrackingState={})});return function(t){return e.apply(this,arguments)}}(),i.prototype.onSyncCompleted=function(){var e=(0,g.method)(function(e){var t=e.nextSyncToken;this._deviceList.setSyncToken(e.nextSyncToken),this._deviceList.saveIfDirty(),this._deviceList.lastKnownSyncToken=t,this._deviceList.refreshOutdatedDeviceLists(),e.catchingUp||(s(this),this._processReceivedRoomKeyRequests())});return function(t){return e.apply(this,arguments)}}(),i.prototype._evalDeviceListChanges=function(){var e=(0,g.coroutine)(x.default.mark(function e(t){var r,n=this;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t.changed&&Array.isArray(t.changed)&&t.changed.forEach(function(e){n._deviceList.invalidateUserDeviceList(e)}),!(t.left&&Array.isArray(t.left)&&t.left.length)){e.next=8;break}return e.t0=f.default,e.next=5,(0,g.resolve)(this._getTrackedE2eUsers());case 5:e.t1=e.sent,r=new e.t0(e.t1),t.left.forEach(function(e){r.has(e)||n._deviceList.stopTrackingDeviceList(e)});case 8:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),i.prototype._getTrackedE2eUsers=(0,g.coroutine)(x.default.mark(function e(){var t,r,n,o,i,s,a,u,c,l,d,f,p,h;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=[],r=!0,n=!1,o=void 0,e.prev=4,i=(0,k.default)(this._getTrackedE2eRooms());case 6:if(r=(s=i.next()).done){e.next=33;break}return a=s.value,e.next=10,(0,g.resolve)(a.getEncryptionTargetMembers());case 10:for(u=e.sent,c=!0,l=!1,d=void 0,e.prev=14,f=(0,k.default)(u);!(c=(p=f.next()).done);c=!0)h=p.value,t.push(h.userId);e.next=22;break;case 18:e.prev=18,e.t0=e.catch(14),l=!0,d=e.t0;case 22:e.prev=22,e.prev=23,!c&&f.return&&f.return();case 25:if(e.prev=25,!l){e.next=28;break}throw d;case 28:return e.finish(25);case 29:return e.finish(22);case 30:r=!0,e.next=6;break;case 33:e.next=39;break;case 35:e.prev=35,e.t1=e.catch(4),n=!0,o=e.t1;case 39:e.prev=39,e.prev=40,!r&&i.return&&i.return();case 42:if(e.prev=42,!n){e.next=45;break}throw o;case 45:return e.finish(42);case 46:return e.finish(39);case 47:return e.abrupt("return",t);case 48:case"end":return e.stop()}},e,this,[[4,35,39,47],[14,18,22,30],[23,,25,29],[40,,42,46]])})),i.prototype._getTrackedE2eRooms=function(){var e=this;return this._clientStore.getRooms().filter(function(t){if(!e._roomEncryptors[t.roomId])return!1;if(!e._roomDeviceTrackingState[t.roomId])return!1;var r=t.getMyMembership();return"join"===r||"invite"===r})},i.prototype._onToDeviceEvent=function(e){var t=this;try{"m.room_key"==e.getType()||"m.forwarded_room_key"==e.getType()?this._onRoomKeyEvent(e):"m.room_key_request"==e.getType()?this._onRoomKeyRequestEvent(e):"m.bad.encrypted"===e.getContent().msgtype?this._onToDeviceBadEncrypted(e):e.isBeingDecrypted()&&e.once("Event.decrypted",function(e){t._onToDeviceEvent(e)})}catch(e){M.error("Error handling toDeviceEvent:",e)}},i.prototype._onRoomKeyEvent=function(e){var t=e.getContent();if(!t.room_id||!t.algorithm)return void M.error("key event is missing fields");this._checkedForBackup||this._checkAndStartKeyBackup(),this._getRoomDecryptor(t.room_id,t.algorithm).onRoomKeyEvent(e)},i.prototype._onToDeviceBadEncrypted=function(){var e=(0,g.coroutine)(x.default.mark(function e(t){var r,n,o,i,s,a,u,c,d,f,p,h,v,m,y;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.getWireContent(),n=t.getSender(),o=r.algorithm,i=r.sender_key,void 0!==n&&void 0!==i&&void 0!==i){e.next=6;break}return e.abrupt("return");case 6:if(this._lastNewSessionForced[n]=this._lastNewSessionForced[n]||{},!((s=this._lastNewSessionForced[n][i]||0)+36e5>Date.now())){e.next=11;break}return M.debug("New session already forced with device "+n+":"+i+" at "+s+": not forcing another"),e.abrupt("return");case 11:if(a=this._deviceList.getDeviceByIdentityKey(o,i)){e.next=15;break}return M.info("Couldn't find device for identity key "+i+": not re-establishing session"),e.abrupt("return");case 15:return u={},u[n]=[a],e.next=19,(0,g.resolve)(U.ensureOlmSessionsForDevices(this._olmDevice,this._baseApis,u,!0));case 19:return this._lastNewSessionForced[n][i]=Date.now(),c={algorithm:U.OLM_ALGORITHM,sender_key:this._olmDevice.deviceCurve25519Key,ciphertext:{}},e.next=23,(0,g.resolve)(U.encryptMessageForDevice(c.ciphertext,this._userId,this._deviceId,this._olmDevice,n,a,{type:"m.dummy"}));case 23:return e.next=25,(0,g.resolve)(this._baseApis.sendToDevice("m.room.encrypted",(0,l.default)({},n,(0,l.default)({},a.deviceId,c))));case 25:return e.next=27,(0,g.resolve)(this._outgoingRoomKeyRequestManager.getOutgoingSentRoomKeyRequest(n,a.deviceId));case 27:for(d=e.sent,f=!0,p=!1,h=void 0,e.prev=31,v=(0,k.default)(d);!(f=(m=v.next()).done);f=!0)y=m.value,this.cancelRoomKeyRequest(y.requestBody,!0);e.next=39;break;case 35:e.prev=35,e.t0=e.catch(31),p=!0,h=e.t0;case 39:e.prev=39,e.prev=40,!f&&v.return&&v.return();case 42:if(e.prev=42,!p){e.next=45;break}throw h;case 45:return e.finish(42);case 46:return e.finish(39);case 47:case"end":return e.stop()}},e,this,[[31,35,39,47],[40,,42,46]])}));return function(t){return e.apply(this,arguments)}}(),i.prototype._onRoomMembership=function(e,t,r){var n=t.roomId,o=this._roomEncryptors[n];o&&(this._roomDeviceTrackingState[n]&&("join"==t.membership?(M.log("Join event for "+t.userId+" in "+n),this._deviceList.startTrackingDeviceList(t.userId)):"invite"==t.membership&&this._clientStore.getRoom(n).shouldEncryptForInvitedMembers()&&(M.log("Invite event for "+t.userId+" in "+n),this._deviceList.startTrackingDeviceList(t.userId))),o.onRoomMembership(e,t,r))},i.prototype._onRoomKeyRequestEvent=function(e){var t=e.getContent();if("request"===t.action){var r=new K(e);this._receivedRoomKeyRequests.push(r)}else if("request_cancellation"===t.action){var n=new G(e);this._receivedRoomKeyRequestCancellations.push(n)}},i.prototype._processReceivedRoomKeyRequests=(0,g.coroutine)(x.default.mark(function e(){var t,r,n=this;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._processingRoomKeyRequests){e.next=2;break}return e.abrupt("return");case 2:return this._processingRoomKeyRequests=!0,e.prev=3,t=this._receivedRoomKeyRequests,this._receivedRoomKeyRequests=[],r=this._receivedRoomKeyRequestCancellations,this._receivedRoomKeyRequestCancellations=[],e.next=10,(0,g.resolve)(b.default.map(t,function(e){return n._processReceivedRoomKeyRequest(e)}));case 10:return e.next=12,(0,g.resolve)(b.default.map(r,function(e){return n._processReceivedRoomKeyRequestCancellation(e)}));case 12:e.next=17;break;case 14:e.prev=14,e.t0=e.catch(3),M.error("Error processing room key requsts: "+e.t0);case 17:return e.prev=17,this._processingRoomKeyRequests=!1,e.finish(17);case 20:case"end":return e.stop()}},e,this,[[3,14,17,20]])})),i.prototype._processReceivedRoomKeyRequest=function(){var e=(0,g.coroutine)(x.default.mark(function e(t){var r,n,o,i,s,a,u,c,l;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.userId,n=t.deviceId,o=t.requestBody,i=o.room_id,s=o.algorithm,M.log("m.room_key_request from "+r+":"+n+" for "+i+" / "+o.session_id+" (id "+t.requestId+")"),r===this._userId){e.next=24;break}if(this._roomEncryptors[i]){e.next=10;break}return M.debug("room key request for unencrypted room "+i),e.abrupt("return");case 10:if(a=this._roomEncryptors[i],u=this._deviceList.getStoredDevice(r,n)){e.next=15;break}return M.debug("Ignoring keyshare for unknown device "+r+":"+n),e.abrupt("return");case 15:return e.prev=15,e.next=18,(0,g.resolve)(a.reshareKeyWithDevice(o.sender_key,o.session_id,r,u));case 18:e.next=23;break;case 20:e.prev=20,
e.t0=e.catch(15),M.warn("Failed to re-share keys for session "+o.session_id+" with device "+r+":"+u.deviceId,e.t0);case 23:return e.abrupt("return");case 24:if(this._roomDecryptors[i]){e.next=27;break}return M.log("room key request for unencrypted room "+i),e.abrupt("return");case 27:if(c=this._roomDecryptors[i][s]){e.next=31;break}return M.log("room key request for unknown alg "+s+" in room "+i),e.abrupt("return");case 31:return e.next=33,(0,g.resolve)(c.hasKeysForKeyRequest(t));case 33:if(e.sent){e.next=36;break}return M.log("room key request for unknown session "+i+" / "+o.session_id),e.abrupt("return");case 36:if(t.share=function(){c.shareKeysWithDevice(t)},!(l=this._deviceList.getStoredDevice(r,n))||!l.isVerified()){e.next=42;break}return M.log("device is already verified: sharing keys"),t.share(),e.abrupt("return");case 42:this.emit("crypto.roomKeyRequest",t);case 43:case"end":return e.stop()}},e,this,[[15,20]])}));return function(t){return e.apply(this,arguments)}}(),i.prototype._processReceivedRoomKeyRequestCancellation=function(){var e=(0,g.method)(function(e){M.log("m.room_key_request cancellation for "+e.userId+":"+e.deviceId+" (id "+e.requestId+")"),this.emit("crypto.roomKeyRequestCancellation",e)});return function(t){return e.apply(this,arguments)}}(),i.prototype._getRoomDecryptor=function(e,t){var r=void 0,n=void 0;if((e=e||null)&&(r=this._roomDecryptors[e],r||(this._roomDecryptors[e]=r={}),n=r[t]))return n;var o=N.DECRYPTION_CLASSES[t];if(!o)throw new N.DecryptionError("UNKNOWN_ENCRYPTION_ALGORITHM",'Unknown encryption algorithm "'+t+'".');return n=new o({userId:this._userId,crypto:this,olmDevice:this._olmDevice,baseApis:this._baseApis,roomId:e}),r&&(r[t]=n),n},i.prototype._signObject=function(){var e=(0,g.coroutine)(x.default.mark(function e(t){var r;return x.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r={},r[this._userId]={},e.next=4,(0,g.resolve)(this._olmDevice.sign(D.stringify(t)));case 4:r[this._userId]["ed25519:"+this._deviceId]=e.sent,t.signatures=r;case 6:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}();var K=function e(t){(0,u.default)(this,e);var r=t.getContent();this.userId=t.getSender(),this.deviceId=r.requesting_device_id,this.requestId=r.request_id,this.requestBody=r.body||{},this.share=function(){throw new Error("don't know how to share keys for this request yet")}},G=function e(t){(0,u.default)(this,e);var r=t.getContent();this.userId=t.getSender(),this.deviceId=r.requesting_device_id,this.requestId=r.request_id}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../logger":29,"../utils":55,"./DeviceList":7,"./OlmDevice":8,"./OutgoingRoomKeyRequestManager":9,"./algorithms":12,"./deviceinfo":16,"./olmlib":18,"./store/indexeddb-crypto-store":21,"another-json":57,"babel-runtime/core-js/get-iterator":58,"babel-runtime/core-js/json/stringify":60,"babel-runtime/core-js/object/assign":63,"babel-runtime/core-js/object/keys":69,"babel-runtime/core-js/set":76,"babel-runtime/helpers/classCallCheck":79,"babel-runtime/helpers/defineProperty":81,"babel-runtime/helpers/typeof":85,"babel-runtime/regenerator":86,bluebird:89,events:234}],18:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}var o=e("bluebird"),i=n(o),s=e("babel-runtime/regenerator"),a=n(s),u=e("babel-runtime/core-js/json/stringify"),c=n(u),l=function(){var e=(0,o.coroutine)(a.default.mark(function e(t,r,n,i){var s,u;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=i.deviceId,e.prev=1,e.next=4,(0,o.resolve)(h(t,r,n,s,i.getFingerprint()));case 4:e.next=10;break;case 6:return e.prev=6,e.t0=e.catch(1),f.error("Unable to verify signature on one-time key for device "+n+":"+s+":",e.t0),e.abrupt("return",null);case 10:return u=void 0,e.prev=11,e.next=14,(0,o.resolve)(t.createOutboundSession(i.getIdentityKey(),r.key));case 14:u=e.sent,e.next=21;break;case 17:return e.prev=17,e.t1=e.catch(11),f.error("Error starting session with device "+n+":"+s+": "+e.t1),e.abrupt("return",null);case 21:return f.log("Started new sessionid "+u+" for device "+n+":"+s),e.abrupt("return",u);case 23:case"end":return e.stop()}},e,this,[[1,6],[11,17]])}));return function(t,r,n,o){return e.apply(this,arguments)}}(),d=e("another-json"),f=e("../logger"),p=e("../utils");t.exports.OLM_ALGORITHM="m.olm.v1.curve25519-aes-sha2",t.exports.MEGOLM_ALGORITHM="m.megolm.v1.aes-sha2",t.exports.MEGOLM_BACKUP_ALGORITHM="m.megolm_backup.v1.curve25519-aes-sha2",t.exports.encryptMessageForDevice=function(){var e=(0,o.coroutine)(a.default.mark(function e(t,r,n,i,s,u,l){var d,h,v;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return d=u.getIdentityKey(),e.next=3,(0,o.resolve)(i.getSessionIdForDevice(d));case 3:if(null!==(h=e.sent)){e.next=6;break}return e.abrupt("return");case 6:return f.log("Using sessionid "+h+" for device "+s+":"+u.deviceId),v={sender:r,sender_device:n,keys:{ed25519:i.deviceEd25519Key},recipient:s,recipient_keys:{ed25519:u.getFingerprint()}},p.extend(v,l),e.next=11,(0,o.resolve)(i.encryptMessage(d,h,(0,c.default)(v)));case 11:t[d]=e.sent;case 12:case"end":return e.stop()}},e,this)}));return function(t,r,n,o,i,s,a){return e.apply(this,arguments)}}(),t.exports.ensureOlmSessionsForDevices=function(){var e=(0,o.coroutine)(a.default.mark(function e(t,r,n,s){var u,c,d,p,h,v,m,y,_,g,b,E,w,S,k,T;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:u=[],c={},e.t0=a.default.keys(n);case 3:if((e.t1=e.t0()).done){e.next=24;break}if(d=e.t1.value,n.hasOwnProperty(d)){e.next=7;break}return e.abrupt("continue",3);case 7:c[d]={},p=n[d],h=0;case 10:if(!(h<p.length)){e.next=22;break}return v=p[h],m=v.deviceId,y=v.getIdentityKey(),e.next=16,(0,o.resolve)(t.getSessionIdForDevice(y));case 16:_=e.sent,(null===_||s)&&u.push([d,m]),c[d][m]={device:v,sessionId:_};case 19:h++,e.next=10;break;case 22:e.next=3;break;case 24:if(0!==u.length){e.next=26;break}return e.abrupt("return",c);case 26:return g="signed_curve25519",e.next=29,(0,o.resolve)(r.claimOneTimeKeys(u,g));case 29:b=e.sent,E=b.one_time_keys||{},w=[],S=function(e){if(!n.hasOwnProperty(e))return"continue";for(var r=E[e]||{},o=n[e],i=0;i<o.length;i++){(function(n){var i=o[n],a=i.deviceId;if(c[e][a].sessionId&&!s)return"continue";var u=r[a]||{},d=null;for(var p in u)0===p.indexOf(g+":")&&(d=u[p]);if(!d)return f.warn("No one-time keys (alg="+g+") for device "+e+":"+a),"continue";w.push(l(t,d,e,i).then(function(t){c[e][a].sessionId=t}))})(i)}},e.t2=a.default.keys(n);case 34:if((e.t3=e.t2()).done){e.next=41;break}if(k=e.t3.value,"continue"!==(T=S(k))){e.next=39;break}return e.abrupt("continue",34);case 39:e.next=34;break;case 41:return e.next=43,(0,o.resolve)(i.default.all(w));case 43:return e.abrupt("return",c);case 44:case"end":return e.stop()}},e,this)}));return function(t,r,n,o){return e.apply(this,arguments)}}();var h=t.exports.verifySignature=function(){var e=(0,o.method)(function(e,t,r,n,o){var i="ed25519:"+n,s=t.signatures||{},a=s[r]||{},u=a[i];if(!u)throw Error("No signature");delete t.unsigned,delete t.signatures;var c=d.stringify(t);e.verifySignature(o,c,u)});return function(t,r,n,o,i){return e.apply(this,arguments)}}()},{"../logger":29,"../utils":55,"another-json":57,"babel-runtime/core-js/json/stringify":60,"babel-runtime/regenerator":86,bluebird:89}],19:[function(e,t,r){(function(t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){var t=new Uint8Array(l.length+e.length+1);t.set(l,0),t.set(e,l.length);for(var r=0,n=0;n<t.length-1;++n)r^=t[n];return t[t.length-1]=r,c.default.encode(t).match(/.{1,4}/g).join(" ")}function i(e){var r=c.default.decode(e.replace(/ /g,"")),n=0,o=!0,i=!1,s=void 0;try{for(var u,d=(0,a.default)(r);!(o=(u=d.next()).done);o=!0){n^=u.value}}catch(e){i=!0,s=e}finally{try{!o&&d.return&&d.return()}finally{if(i)throw s}}if(0!==n)throw new Error("Incorrect parity");for(var f=0;f<l.length;++f)if(r[f]!==l[f])throw new Error("Incorrect prefix");if(r.length!==l.length+t.Olm.PRIVATE_KEY_LENGTH+1)throw new Error("Incorrect length");return r.slice(l.length,l.length+t.Olm.PRIVATE_KEY_LENGTH)}Object.defineProperty(r,"__esModule",{value:!0});var s=e("babel-runtime/core-js/get-iterator"),a=n(s);r.encodeRecoveryKey=o,r.decodeRecoveryKey=i;var u=e("bs58"),c=n(u),l=[139,1]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"babel-runtime/core-js/get-iterator":58,bs58:92}],20:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(y.default.log("Upgrading IndexedDBCryptoStore from version "+t+" to "+b),t<1&&i(e),t<2&&e.createObjectStore("account"),t<3){e.createObjectStore("sessions",{keyPath:["deviceKey","sessionId"]}).createIndex("deviceKey","deviceKey")}t<4&&e.createObjectStore("inbound_group_sessions",{keyPath:["senderCurve25519Key","sessionId"]}),t<5&&e.createObjectStore("device_data"),t<6&&e.createObjectStore("rooms"),t<7&&e.createObjectStore("sessions_needing_backup",{keyPath:["senderCurve25519Key","sessionId"]})}function i(e){var t=e.createObjectStore("outgoingRoomKeyRequests",{keyPath:"requestId"});t.createIndex("session",["requestBody.room_id","requestBody.session_id"]),t.createIndex("state","state")}function s(e,t){e._mx_abortexception=t;try{e.abort()}catch(t){}}function a(e){return new v.default(function(t,r){e.oncomplete=function(){void 0!==e._mx_abortexception&&r(e._mx_abortexception),t()},e.onerror=function(){void 0!==e._mx_abortexception&&r(e._mx_abortexception),r()},e.onabort=function(){return r(e._mx_abortexception)}})}Object.defineProperty(r,"__esModule",{value:!0}),r.Backend=r.VERSION=void 0;var u=e("babel-runtime/core-js/object/assign"),c=n(u),l=e("babel-runtime/helpers/classCallCheck"),d=n(l),f=e("babel-runtime/helpers/createClass"),p=n(f);r.upgradeDatabase=o;var h=e("bluebird"),v=n(h),m=e("../../logger"),y=n(m),_=e("../../utils"),g=n(_),b=r.VERSION=7;r.Backend=function(){function e(t){var r=this;(0,d.default)(this,e),this._db=t,t.onversionchange=function(e){y.default.log("versionchange for indexeddb "+r._dbName+": closing"),t.close()}}return(0,p.default)(e,[{key:"getOrAddOutgoingRoomKeyRequest",value:function(e){var t=e.requestBody,r=v.default.defer(),n=this._db.transaction("outgoingRoomKeyRequests","readwrite");return n.onerror=r.reject,this._getOutgoingRoomKeyRequest(n,t,function(o){if(o)return y.default.log("already have key request outstanding for "+t.room_id+" / "+t.session_id+": not sending another"),void r.resolve(o);y.default.log("enqueueing key request for "+t.room_id+" / "+t.session_id),n.oncomplete=function(){r.resolve(e)},n.objectStore("outgoingRoomKeyRequests").add(e)}),r.promise}},{key:"getOutgoingRoomKeyRequest",value:function(e){var t=v.default.defer(),r=this._db.transaction("outgoingRoomKeyRequests","readonly");return r.onerror=t.reject,this._getOutgoingRoomKeyRequest(r,e,function(e){t.resolve(e)}),t.promise}},{key:"_getOutgoingRoomKeyRequest",value:function(e,t,r){e.objectStore("outgoingRoomKeyRequests").index("session").openCursor([t.room_id,t.session_id]).onsuccess=function(e){var n=e.target.result;if(!n)return void r(null);var o=n.value;if(g.default.deepCompare(o.requestBody,t))return void r(o);n.continue()}}},{key:"getOutgoingRoomKeyRequestByState",value:function(e){function t(o){var i=o.target.result;if(i)return void(n=i.value);if(!(++r>=e.length)){var s=e[r];o.target.source.openCursor(s).onsuccess=t}}if(0===e.length)return v.default.resolve(null);var r=0,n=void 0,o=this._db.transaction("outgoingRoomKeyRequests","readonly"),i=o.objectStore("outgoingRoomKeyRequests"),s=e[r];return i.index("state").openCursor(s).onsuccess=t,a(o).then(function(){return n})}},{key:"getOutgoingRoomKeyRequestsByTarget",value:function(e,t,r){function n(s){var a=s.target.result;if(a){var u=a.value;u.recipients.includes({userId:e,deviceId:t})&&i.push(u),a.continue()}else{if(++o>=r.length)return;var c=r[o];s.target.source.openCursor(c).onsuccess=n}}var o=0,i=[],s=this._db.transaction("outgoingRoomKeyRequests","readonly"),u=s.objectStore("outgoingRoomKeyRequests"),c=r[o];return u.index("state").openCursor(c).onsuccess=n,a(s).then(function(){return i})}},{key:"updateOutgoingRoomKeyRequest",value:function(e,t,r){function n(e){var n=e.target.result;if(n){var i=n.value;if(i.state!=t)return void y.default.warn("Cannot update room key request from "+t+" as it was already updated to "+i.state);(0,c.default)(i,r),n.update(i),o=i}}var o=null,i=this._db.transaction("outgoingRoomKeyRequests","readwrite");return i.objectStore("outgoingRoomKeyRequests").openCursor(e).onsuccess=n,a(i).then(function(){return o})}},{key:"deleteOutgoingRoomKeyRequest",value:function(e,t){var r=this._db.transaction("outgoingRoomKeyRequests","readwrite");return r.objectStore("outgoingRoomKeyRequests").openCursor(e).onsuccess=function(e){var r=e.target.result;if(r){var n=r.value;if(n.state!=t)return void y.default.warn("Cannot delete room key request in state "+n.state+" (expected "+t+")");r.delete()}},a(r)}},{key:"getAccount",value:function(e,t){var r=e.objectStore("account"),n=r.get("-");n.onsuccess=function(){try{t(n.result||null)}catch(t){s(e,t)}}}},{key:"storeAccount",value:function(e,t){e.objectStore("account").put(t,"-")}},{key:"countEndToEndSessions",value:function(e,t){var r=e.objectStore("sessions"),n=r.count();n.onsuccess=function(){t(n.result)}}},{key:"getEndToEndSessions",value:function(e,t,r){var n=t.objectStore("sessions"),o=n.index("deviceKey"),i=o.openCursor(e),a={};i.onsuccess=function(){var e=i.result;if(e)a[e.value.sessionId]={session:e.value.session,lastReceivedMessageTs:e.value.lastReceivedMessageTs},e.continue();else try{r(a)}catch(e){s(t,e)}}}},{key:"getEndToEndSession",value:function(e,t,r,n){var o=r.objectStore("sessions"),i=o.get([e,t]);i.onsuccess=function(){try{n(i.result?{session:i.result.session,lastReceivedMessageTs:i.result.lastReceivedMessageTs}:null)}catch(e){s(r,e)}}}},{key:"getAllEndToEndSessions",value:function(e,t){var r=e.objectStore("sessions"),n=r.openCursor();n.onsuccess=function(){var r=n.result;if(r)t(r.value),r.continue();else try{t(null)}catch(t){s(e,t)}}}},{key:"storeEndToEndSession",value:function(e,t,r,n){n.objectStore("sessions").put({deviceKey:e,sessionId:t,session:r.session,lastReceivedMessageTs:r.lastReceivedMessageTs})}},{key:"getEndToEndInboundGroupSession",value:function(e,t,r,n){var o=r.objectStore("inbound_group_sessions"),i=o.get([e,t]);i.onsuccess=function(){try{n(i.result?i.result.session:null)}catch(e){s(r,e)}}}},{key:"getAllEndToEndInboundGroupSessions",value:function(e,t){var r=e.objectStore("inbound_group_sessions"),n=r.openCursor();n.onsuccess=function(){var r=n.result;if(r){try{t({senderKey:r.value.senderCurve25519Key,sessionId:r.value.sessionId,sessionData:r.value.session})}catch(t){s(e,t)}r.continue()}else try{t(null)}catch(t){s(e,t)}}}},{key:"addEndToEndInboundGroupSession",value:function(e,t,r,n){var o=n.objectStore("inbound_group_sessions"),i=o.add({senderCurve25519Key:e,sessionId:t,session:r});i.onerror=function(r){"ConstraintError"===i.error.name?(r.stopPropagation(),r.preventDefault(),y.default.log("Ignoring duplicate inbound group session: "+e+" / "+t)):s(n,new Error("Failed to add inbound group session: "+i.error))}}},{key:"storeEndToEndInboundGroupSession",value:function(e,t,r,n){n.objectStore("inbound_group_sessions").put({senderCurve25519Key:e,sessionId:t,session:r})}},{key:"getEndToEndDeviceData",value:function(e,t){var r=e.objectStore("device_data"),n=r.get("-");n.onsuccess=function(){try{t(n.result||null)}catch(t){s(e,t)}}}},{key:"storeEndToEndDeviceData",value:function(e,t){t.objectStore("device_data").put(e,"-")}},{key:"storeEndToEndRoom",value:function(e,t,r){r.objectStore("rooms").put(t,e)}},{key:"getEndToEndRooms",value:function(e,t){var r={},n=e.objectStore("rooms"),o=n.openCursor();o.onsuccess=function(){var n=o.result;if(n)r[n.key]=n.value,n.continue();else try{t(r)}catch(t){s(e,t)}}}},{key:"getSessionsNeedingBackup",value:function(e){var t=this;return new v.default(function(r,n){var o=[],i=t._db.transaction(["sessions_needing_backup","inbound_group_sessions"],"readonly");i.onerror=n,i.oncomplete=function(){r(o)};var s=i.objectStore("sessions_needing_backup"),a=i.objectStore("inbound_group_sessions"),u=s.openCursor();u.onsuccess=function(){var t=u.result;if(t){var r=a.get(t.key);r.onsuccess=function(){o.push({senderKey:r.result.senderCurve25519Key,sessionId:r.result.sessionId,sessionData:r.result.session})},(!e||o.length<e)&&t.continue()}}})}},{key:"unmarkSessionsNeedingBackup",value:function(e){var t=this._db.transaction("sessions_needing_backup","readwrite"),r=t.objectStore("sessions_needing_backup");return v.default.all(e.map(function(e){return new v.default(function(t,n){var o=r.delete([e.senderKey,e.sessionId]);o.onsuccess=t,o.onerror=n})}))}},{key:"markSessionsNeedingBackup",value:function(e,t){t||(t=this._db.transaction("sessions_needing_backup","readwrite"));var r=t.objectStore("sessions_needing_backup");return v.default.all(e.map(function(e){return new v.default(function(t,n){var o=r.put({senderCurve25519Key:e.senderKey,sessionId:e.sessionId});o.onsuccess=t,o.onerror=n})}))}},{key:"doTxn",value:function(e,t,r){var n=this._db.transaction(t,e),o=a(n),i=r(n);return o.then(function(){return i})}}]),e}()},{"../../logger":29,"../../utils":55,"babel-runtime/core-js/object/assign":63,"babel-runtime/helpers/classCallCheck":79,"babel-runtime/helpers/createClass":80,bluebird:89}],21:[function(e,t,r){(function(t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=e("babel-runtime/helpers/classCallCheck"),i=n(o),s=e("babel-runtime/helpers/createClass"),a=n(s),u=e("bluebird"),c=n(u),l=e("../../logger"),d=n(l),f=e("./localStorage-crypto-store"),p=n(f),h=e("./memory-crypto-store"),v=n(h),m=e("./indexeddb-crypto-store-backend"),y=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(m),_=e("../../errors"),g=function(){function e(t,r){(0,i.default)(this,e),this._indexedDB=t,this._dbName=r,this._backendPromise=null}return(0,a.default)(e,[{key:"_connect",value:function(){var r=this;return this._backendPromise?this._backendPromise:(this._backendPromise=new c.default(function(e,t){if(!r._indexedDB)return void t(new Error("no indexeddb support available"));d.default.log("connecting to indexeddb "+r._dbName);var n=r._indexedDB.open(r._dbName,y.VERSION);n.onupgradeneeded=function(e){var t=e.target.result,r=e.oldVersion;y.upgradeDatabase(t,r)},n.onblocked=function(){d.default.log("can't yet open IndexedDBCryptoStore because it is open elsewhere")},n.onerror=function(e){t(e.target.error)},n.onsuccess=function(t){var n=t.target.result;d.default.log("connected to indexeddb "+r._dbName),e(new y.Backend(n))}}).then(function(t){return t.doTxn("readonly",[e.STORE_INBOUND_GROUP_SESSIONS],function(e){t.getEndToEndInboundGroupSession("","",e,function(){})}).then(function(){return t})}).catch(function(e){if("VersionError"===e.name)throw d.default.warn("Crypto DB is too new for us to use!",e),new _.InvalidCryptoStoreError(_.InvalidCryptoStoreError.TOO_NEW);d.default.warn("unable to connect to indexeddb "+r._dbName+": falling back to localStorage store: "+e);try{return new p.default(t.localStorage)}catch(e){return d.default.warn("unable to open localStorage: falling back to in-memory store: "+e),new v.default}}),this._backendPromise)}},{key:"deleteAllData",value:function(){var e=this;return new c.default(function(t,r){if(!e._indexedDB)return void r(new Error("no indexeddb support available"));d.default.log("Removing indexeddb instance: "+e._dbName);var n=e._indexedDB.deleteDatabase(e._dbName);n.onblocked=function(){d.default.log("can't yet delete IndexedDBCryptoStore because it is open elsewhere")},n.onerror=function(e){r(e.target.error)},n.onsuccess=function(){d.default.log("Removed indexeddb instance: "+e._dbName),t()}}).catch(function(e){d.default.warn("unable to delete IndexedDBCryptoStore: "+e)})}},{key:"getOrAddOutgoingRoomKeyRequest",value:function(e){return this._connect().then(function(t){return t.getOrAddOutgoingRoomKeyRequest(e)})}},{key:"getOutgoingRoomKeyRequest",value:function(e){return this._connect().then(function(t){return t.getOutgoingRoomKeyRequest(e)})}},{key:"getOutgoingRoomKeyRequestByState",value:function(e){return this._connect().then(function(t){return t.getOutgoingRoomKeyRequestByState(e)})}},{key:"getOutgoingRoomKeyRequestsByTarget",value:function(e,t,r){return this._connect().then(function(n){return n.getOutgoingRoomKeyRequestsByTarget(e,t,r)})}},{key:"updateOutgoingRoomKeyRequest",value:function(e,t,r){return this._connect().then(function(n){return n.updateOutgoingRoomKeyRequest(e,t,r)})}},{key:"deleteOutgoingRoomKeyRequest",value:function(e,t){return this._connect().then(function(r){return r.deleteOutgoingRoomKeyRequest(e,t)})}},{key:"getAccount",value:function(e,t){this._backendPromise.value().getAccount(e,t)}},{key:"storeAccount",value:function(e,t){this._backendPromise.value().storeAccount(e,t)}},{key:"countEndToEndSessions",value:function(e,t){this._backendPromise.value().countEndToEndSessions(e,t)}},{key:"getEndToEndSession",value:function(e,t,r,n){this._backendPromise.value().getEndToEndSession(e,t,r,n)}},{key:"getEndToEndSessions",value:function(e,t,r){this._backendPromise.value().getEndToEndSessions(e,t,r)}},{key:"getAllEndToEndSessions",value:function(e,t){this._backendPromise.value().getAllEndToEndSessions(e,t)}},{key:"storeEndToEndSession",value:function(e,t,r,n){this._backendPromise.value().storeEndToEndSession(e,t,r,n)}},{key:"getEndToEndInboundGroupSession",value:function(e,t,r,n){this._backendPromise.value().getEndToEndInboundGroupSession(e,t,r,n)}},{key:"getAllEndToEndInboundGroupSessions",value:function(e,t){this._backendPromise.value().getAllEndToEndInboundGroupSessions(e,t)}},{key:"addEndToEndInboundGroupSession",value:function(e,t,r,n){this._backendPromise.value().addEndToEndInboundGroupSession(e,t,r,n)}},{key:"storeEndToEndInboundGroupSession",value:function(e,t,r,n){this._backendPromise.value().storeEndToEndInboundGroupSession(e,t,r,n)}},{key:"storeEndToEndDeviceData",value:function(e,t){this._backendPromise.value().storeEndToEndDeviceData(e,t)}},{key:"getEndToEndDeviceData",value:function(e,t){this._backendPromise.value().getEndToEndDeviceData(e,t)}},{key:"storeEndToEndRoom",value:function(e,t,r){this._backendPromise.value().storeEndToEndRoom(e,t,r)}},{key:"getEndToEndRooms",value:function(e,t){this._backendPromise.value().getEndToEndRooms(e,t)}},{key:"getSessionsNeedingBackup",value:function(e){return this._connect().then(function(t){return t.getSessionsNeedingBackup(e)})}},{key:"unmarkSessionsNeedingBackup",value:function(e){return this._connect().then(function(t){return t.unmarkSessionsNeedingBackup(e)})}},{key:"markSessionsNeedingBackup",value:function(e,t){return this._connect().then(function(r){return r.markSessionsNeedingBackup(e,t)})}},{key:"doTxn",value:function(e,t,r){return this._connect().then(function(n){return n.doTxn(e,t,r)})}}]),e}();r.default=g,g.STORE_ACCOUNT="account",g.STORE_SESSIONS="sessions",g.STORE_INBOUND_GROUP_SESSIONS="inbound_group_sessions",g.STORE_DEVICE_DATA="device_data",g.STORE_ROOMS="rooms",g.STORE_BACKUP="sessions_needing_backup"}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../../errors":24,"../../logger":29,"./indexeddb-crypto-store-backend":20,"./localStorage-crypto-store":22,"./memory-crypto-store":23,"babel-runtime/helpers/classCallCheck":79,"babel-runtime/helpers/createClass":80,bluebird:89}],22:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){return D+"sessions/"+e}function i(e,t){return L+e+"/"+t}function s(e){return U+e}function a(e,t){try{return JSON.parse(e.getItem(t))}catch(e){j.default.log("Error: Failed to get key %s: %s",t,e.stack||e),j.default.log(e.stack)}return null}function u(e,t,r){e.setItem(t,(0,l.default)(r))}Object.defineProperty(r,"__esModule",{value:!0});var c=e("babel-runtime/core-js/json/stringify"),l=n(c),d=e("babel-runtime/helpers/slicedToArray"),f=n(d),p=e("babel-runtime/core-js/object/entries"),h=n(p),v=e("babel-runtime/core-js/get-iterator"),m=n(v),y=e("babel-runtime/core-js/object/get-prototype-of"),_=n(y),g=e("babel-runtime/helpers/classCallCheck"),b=n(g),E=e("babel-runtime/helpers/createClass"),w=n(E),S=e("babel-runtime/helpers/possibleConstructorReturn"),k=n(S),T=e("babel-runtime/helpers/inherits"),x=n(T),R=e("bluebird"),I=n(R),C=e("../../logger"),j=n(C),O=e("./memory-crypto-store.js"),A=n(O),D="crypto.",M=D+"account",P=D+"device_data",L=D+"inboundgroupsessions/",U=D+"rooms/",N=D+"sessionsneedingbackup",F=function(e){function t(e){(0,b.default)(this,t);var r=(0,k.default)(this,(t.__proto__||(0,_.default)(t)).call(this));return r.store=e,r}return(0,x.default)(t,e),(0,w.default)(t,[{key:"countEndToEndSessions",value:function(e,t){for(var r=0,n=0;n<this.store.length;++n)this.store.key(n).startsWith(o(""))&&++r;t(r)}},{key:"_getEndToEndSessions",value:function(e,t,r){var n=a(this.store,o(e)),i={},s=!0,u=!1,c=void 0;try{for(var l,d=(0,m.default)((0,h.default)(n||{}));!(s=(l=d.next()).done);s=!0){var p=(0,f.default)(l.value,2),v=p[0],y=p[1];i[v]="string"==typeof y?{session:y}:y}}catch(e){u=!0,c=e}finally{try{!s&&d.return&&d.return()}finally{if(u)throw c}}return i}},{key:"getEndToEndSession",value:function(e,t,r,n){n(this._getEndToEndSessions(e)[t]||{})}},{key:"getEndToEndSessions",value:function(e,t,r){r(this._getEndToEndSessions(e)||{})}},{key:"storeEndToEndSession",value:function(e,t,r,n){var i=this._getEndToEndSessions(e)||{};i[t]=r,u(this.store,o(e),i)}},{key:"getEndToEndInboundGroupSession",value:function(e,t,r,n){n(a(this.store,i(e,t)))}},{key:"getAllEndToEndInboundGroupSessions",value:function(e,t){for(var r=0;r<this.store.length;++r){var n=this.store.key(r);n.startsWith(L)&&t({senderKey:n.substr(L.length,43),sessionId:n.substr(L.length+44),sessionData:a(this.store,n)})}t(null)}},{key:"addEndToEndInboundGroupSession",value:function(e,t,r,n){a(this.store,i(e,t))||this.storeEndToEndInboundGroupSession(e,t,r,n)}},{key:"storeEndToEndInboundGroupSession",value:function(e,t,r,n){u(this.store,i(e,t),r)}},{key:"getEndToEndDeviceData",value:function(e,t){t(a(this.store,P))}},{key:"storeEndToEndDeviceData",value:function(e,t){u(this.store,P,e)}},{key:"storeEndToEndRoom",value:function(e,t,r){u(this.store,s(e),t)}},{key:"getEndToEndRooms",value:function(e,t){for(var r={},n=s(""),o=0;o<this.store.length;++o){var i=this.store.key(o);if(i.startsWith(n)){r[i.substr(n.length)]=a(this.store,i)}}t(r)}},{key:"getSessionsNeedingBackup",value:function(e){var t=this,r=a(this.store,N)||{},n=[];for(var o in r)if(Object.prototype.hasOwnProperty.call(r,o)){var i=function(){var r=o.substr(0,43),i=o.substr(44);if(t.getEndToEndInboundGroupSession(r,i,null,function(e){n.push({senderKey:r,sessionId:i,sessionData:e})}),e&&o.length>=e)return"break"}();if("break"===i)break}return I.default.resolve(n)}},{key:"unmarkSessionsNeedingBackup",value:function(e){var t=a(this.store,N)||{},r=!0,n=!1,o=void 0;try{for(var i,s=(0,m.default)(e);!(r=(i=s.next()).done);r=!0){var c=i.value;delete t[c.senderKey+"/"+c.sessionId]}}catch(e){n=!0,o=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw o}}return u(this.store,N,t),I.default.resolve()}},{key:"markSessionsNeedingBackup",value:function(e){var t=a(this.store,N)||{},r=!0,n=!1,o=void 0;try{for(var i,s=(0,m.default)(e);!(r=(i=s.next()).done);r=!0){var c=i.value;t[c.senderKey+"/"+c.sessionId]=!0}}catch(e){n=!0,o=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw o}}return u(this.store,N,t),I.default.resolve()}},{key:"deleteAllData",value:function(){return this.store.removeItem(M),I.default.resolve()}},{key:"getAccount",value:function(e,t){t(a(this.store,M))}},{key:"storeAccount",value:function(e,t){u(this.store,M,t)}},{key:"doTxn",value:function(e,t,r){return I.default.resolve(r(null))}}]),t}(A.default);r.default=F},{"../../logger":29,"./memory-crypto-store.js":23,"babel-runtime/core-js/get-iterator":58,"babel-runtime/core-js/json/stringify":60,"babel-runtime/core-js/object/entries":66,"babel-runtime/core-js/object/get-prototype-of":68,"babel-runtime/helpers/classCallCheck":79,"babel-runtime/helpers/createClass":80,"babel-runtime/helpers/inherits":82,"babel-runtime/helpers/possibleConstructorReturn":83,"babel-runtime/helpers/slicedToArray":84,bluebird:89}],23:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=e("babel-runtime/core-js/object/keys"),i=n(o),s=e("babel-runtime/core-js/object/assign"),a=n(s),u=e("babel-runtime/core-js/get-iterator"),c=n(u),l=e("babel-runtime/helpers/classCallCheck"),d=n(l),f=e("babel-runtime/helpers/createClass"),p=n(f),h=e("bluebird"),v=n(h),m=e("../../logger"),y=n(m),_=e("../../utils"),g=n(_),b=function(){function e(){(0,d.default)(this,e),this._outgoingRoomKeyRequests=[],this._account=null,this._sessions={},this._inboundGroupSessions={},this._deviceData=null,this._rooms={},this._sessionsNeedingBackup={}}return(0,p.default)(e,[{key:"deleteAllData",value:function(){return v.default.resolve()}},{key:"getOrAddOutgoingRoomKeyRequest",value:function(e){var t=this,r=e.requestBody;return v.default.try(function(){var n=t._getOutgoingRoomKeyRequest(r);return n?(y.default.log("already have key request outstanding for "+r.room_id+" / "+r.session_id+": not sending another"),n):(y.default.log("enqueueing key request for "+r.room_id+" / "+r.session_id),t._outgoingRoomKeyRequests.push(e),e)})}},{key:"getOutgoingRoomKeyRequest",value:function(e){return v.default.resolve(this._getOutgoingRoomKeyRequest(e))}},{key:"_getOutgoingRoomKeyRequest",value:function(e){var t=!0,r=!1,n=void 0;try{for(var o,i=(0,c.default)(this._outgoingRoomKeyRequests);!(t=(o=i.next()).done);t=!0){var s=o.value;if(g.default.deepCompare(s.requestBody,e))return s}}catch(e){r=!0,n=e}finally{try{!t&&i.return&&i.return()}finally{if(r)throw n}}return null}},{key:"getOutgoingRoomKeyRequestByState",value:function(e){var t=!0,r=!1,n=void 0;try{for(var o,i=(0,c.default)(this._outgoingRoomKeyRequests);!(t=(o=i.next()).done);t=!0){var s=o.value,a=!0,u=!1,l=void 0;try{for(var d,f=(0,c.default)(e);!(a=(d=f.next()).done);a=!0){var p=d.value;if(s.state===p)return v.default.resolve(s)}}catch(e){u=!0,l=e}finally{try{!a&&f.return&&f.return()}finally{if(u)throw l}}}}catch(e){r=!0,n=e}finally{try{!t&&i.return&&i.return()}finally{if(r)throw n}}return v.default.resolve(null)}},{key:"getOutgoingRoomKeyRequestsByTarget",value:function(e,t,r){var n=[],o=!0,i=!1,s=void 0;try{for(var a,u=(0,c.default)(this._outgoingRoomKeyRequests);!(o=(a=u.next()).done);o=!0){var l=a.value,d=!0,f=!1,p=void 0;try{for(var h,m=(0,c.default)(r);!(d=(h=m.next()).done);d=!0){var y=h.value;l.state===y&&l.recipients.includes({userId:e,deviceId:t})&&n.push(l)}}catch(e){f=!0,p=e}finally{try{!d&&m.return&&m.return()}finally{if(f)throw p}}}}catch(e){i=!0,s=e}finally{try{!o&&u.return&&u.return()}finally{if(i)throw s}}return v.default.resolve(n)}},{key:"updateOutgoingRoomKeyRequest",value:function(e,t,r){var n=!0,o=!1,i=void 0;try{for(var s,u=(0,c.default)(this._outgoingRoomKeyRequests);!(n=(s=u.next()).done);n=!0){var l=s.value;if(l.requestId===e)return l.state!=t?(y.default.warn("Cannot update room key request from "+t+" as it was already updated to "+l.state),v.default.resolve(null)):((0,a.default)(l,r),v.default.resolve(l))}}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}return v.default.resolve(null)}},{key:"deleteOutgoingRoomKeyRequest",value:function(e,t){for(var r=0;r<this._outgoingRoomKeyRequests.length;r++){var n=this._outgoingRoomKeyRequests[r]
;if(n.requestId===e)return n.state!=t?(y.default.warn("Cannot delete room key request in state "+n.state+" (expected "+t+")"),v.default.resolve(null)):(this._outgoingRoomKeyRequests.splice(r,1),v.default.resolve(n))}return v.default.resolve(null)}},{key:"getAccount",value:function(e,t){t(this._account)}},{key:"storeAccount",value:function(e,t){this._account=t}},{key:"countEndToEndSessions",value:function(e,t){return(0,i.default)(this._sessions).length}},{key:"getEndToEndSession",value:function(e,t,r,n){n((this._sessions[e]||{})[t]||null)}},{key:"getEndToEndSessions",value:function(e,t,r){r(this._sessions[e]||{})}},{key:"storeEndToEndSession",value:function(e,t,r,n){var o=this._sessions[e];void 0===o&&(o={},this._sessions[e]=o),o[t]=r}},{key:"getEndToEndInboundGroupSession",value:function(e,t,r,n){n(this._inboundGroupSessions[e+"/"+t]||null)}},{key:"getAllEndToEndInboundGroupSessions",value:function(e,t){var r=!0,n=!1,o=void 0;try{for(var s,a=(0,c.default)((0,i.default)(this._inboundGroupSessions));!(r=(s=a.next()).done);r=!0){var u=s.value;t({senderKey:u.substr(0,43),sessionId:u.substr(44),sessionData:this._inboundGroupSessions[u]})}}catch(e){n=!0,o=e}finally{try{!r&&a.return&&a.return()}finally{if(n)throw o}}t(null)}},{key:"addEndToEndInboundGroupSession",value:function(e,t,r,n){var o=e+"/"+t;void 0===this._inboundGroupSessions[o]&&(this._inboundGroupSessions[o]=r)}},{key:"storeEndToEndInboundGroupSession",value:function(e,t,r,n){this._inboundGroupSessions[e+"/"+t]=r}},{key:"getEndToEndDeviceData",value:function(e,t){t(this._deviceData)}},{key:"storeEndToEndDeviceData",value:function(e,t){this._deviceData=e}},{key:"storeEndToEndRoom",value:function(e,t,r){this._rooms[e]=t}},{key:"getEndToEndRooms",value:function(e,t){t(this._rooms)}},{key:"getSessionsNeedingBackup",value:function(e){var t=[];for(var r in this._sessionsNeedingBackup)if(this._inboundGroupSessions[r]&&(t.push({senderKey:r.substr(0,43),sessionId:r.substr(44),sessionData:this._inboundGroupSessions[r]}),e&&r.length>=e))break;return v.default.resolve(t)}},{key:"unmarkSessionsNeedingBackup",value:function(e){var t=!0,r=!1,n=void 0;try{for(var o,i=(0,c.default)(e);!(t=(o=i.next()).done);t=!0){var s=o.value,a=s.senderKey+"/"+s.sessionId;delete this._sessionsNeedingBackup[a]}}catch(e){r=!0,n=e}finally{try{!t&&i.return&&i.return()}finally{if(r)throw n}}return v.default.resolve()}},{key:"markSessionsNeedingBackup",value:function(e){var t=!0,r=!1,n=void 0;try{for(var o,i=(0,c.default)(e);!(t=(o=i.next()).done);t=!0){var s=o.value,a=s.senderKey+"/"+s.sessionId;this._sessionsNeedingBackup[a]=!0}}catch(e){r=!0,n=e}finally{try{!t&&i.return&&i.return()}finally{if(r)throw n}}return v.default.resolve()}},{key:"doTxn",value:function(e,t,r){return v.default.resolve(r(null))}}]),e}();r.default=b},{"../../logger":29,"../../utils":55,"babel-runtime/core-js/get-iterator":58,"babel-runtime/core-js/object/assign":63,"babel-runtime/core-js/object/keys":69,"babel-runtime/helpers/classCallCheck":79,"babel-runtime/helpers/createClass":80,bluebird:89}],24:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var r="Store is invalid because "+e+", please stop the client, delete all data and start the client again",n=(0,p.default)(Error,[r]);return(0,d.default)(n,(0,c.default)(this)),n.reason=e,n.value=t,n}function i(e){var t="Crypto store is invalid because "+e+", please stop the client, delete all data and start the client again",r=(0,p.default)(Error,[t]);return(0,d.default)(r,(0,c.default)(this)),r.reason=e,r.name="InvalidCryptoStoreError",r}Object.defineProperty(r,"__esModule",{value:!0});var s=e("babel-runtime/core-js/object/create"),a=n(s),u=e("babel-runtime/core-js/reflect/get-prototype-of"),c=n(u),l=e("babel-runtime/core-js/reflect/set-prototype-of"),d=n(l),f=e("babel-runtime/core-js/reflect/construct"),p=n(f);r.InvalidStoreError=o,r.InvalidCryptoStoreError=i,o.TOGGLED_LAZY_LOADING="TOGGLED_LAZY_LOADING",o.prototype=(0,a.default)(Error.prototype,{constructor:{value:Error,enumerable:!1,writable:!0,configurable:!0}}),(0,d.default)(o,Error),i.TOO_NEW="TOO_NEW",i.prototype=(0,a.default)(Error.prototype,{constructor:{value:Error,enumerable:!1,writable:!0,configurable:!0}}),(0,d.default)(i,Error)},{"babel-runtime/core-js/object/create":64,"babel-runtime/core-js/reflect/construct":73,"babel-runtime/core-js/reflect/get-prototype-of":74,"babel-runtime/core-js/reflect/set-prototype-of":75}],25:[function(e,t,r){"use strict";function n(e,t){if(t.endsWith("*")){var r=t.slice(0,-1);return e.substr(0,r.length)===r}return e===t}function o(e){this.filter_json=e,this.types=e.types||null,this.not_types=e.not_types||[],this.rooms=e.rooms||null,this.not_rooms=e.not_rooms||[],this.senders=e.senders||null,this.not_senders=e.not_senders||[],this.contains_url=e.contains_url||null}var i=e("babel-runtime/core-js/object/keys"),s=function(e){return e&&e.__esModule?e:{default:e}}(i);o.prototype.check=function(e){return this._checkFields(e.getRoomId(),e.getSender(),e.getType(),!!e.getContent()&&void 0!==e.getContent().url)},o.prototype._checkFields=function(e,t,r,o){for(var i={rooms:function(t){return e===t},senders:function(e){return t===e},types:function(e){return n(r,e)}},a=this,u=0;u<(0,s.default)(i).length;u++){var c=(0,s.default)(i)[u],l=i[c];if(a["not_"+c].filter(l).length>0)return!1;var d=a[c];if(d&&!d.map(l))return!1}var f=this.filter_json.contains_url;return void 0===f||f===o},o.prototype.filter=function(e){return e.filter(this.check,this)},o.prototype.limit=function(){return void 0!==this.filter_json.limit?this.filter_json.limit:10},t.exports=o},{"babel-runtime/core-js/object/keys":69}],26:[function(e,t,r){"use strict";function n(e,t,r){for(var n=t.split("."),o=e,i=0;i<n.length-1;i++)o[n[i]]||(o[n[i]]={}),o=o[n[i]];o[n[n.length-1]]=r}function o(e,t){this.userId=e,this.filterId=t,this.definition={}}var i=e("./filter-component");o.LAZY_LOADING_MESSAGES_FILTER={lazy_load_members:!0},o.LAZY_LOADING_SYNC_FILTER={room:{state:o.LAZY_LOADING_MESSAGES_FILTER}},o.prototype.getFilterId=function(){return this.filterId},o.prototype.getDefinition=function(){return this.definition},o.prototype.setDefinition=function(e){this.definition=e;var t=e.room,r={};t&&(t.rooms&&(r.rooms=t.rooms),t.rooms&&(r.not_rooms=t.not_rooms),this._include_leave=t.include_leave||!1),this._room_filter=new i(r),this._room_timeline_filter=new i(t?t.timeline||{}:{})},o.prototype.getRoomTimelineFilterComponent=function(){return this._room_timeline_filter},o.prototype.filterRoomTimeline=function(e){return this._room_timeline_filter.filter(this._room_filter.filter(e))},o.prototype.setTimelineLimit=function(e){n(this.definition,"room.timeline.limit",e)},o.prototype.setIncludeLeaveRooms=function(e){n(this.definition,"room.include_leave",e)},o.fromJson=function(e,t,r){var n=new o(e,t);return n.setDefinition(r),n},t.exports=o},{"./filter-component":25}],27:[function(e,t,r){(function(r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,r){var n=e.statusCode,o=i(e),s=void 0;return o&&("application/json"===o.type?s=new t.exports.MatrixError(JSON.parse(r)):"text/plain"===o.type&&(s=new Error("Server returned "+n+" error: "+r))),s||(s=new Error("Server returned "+n+" error")),s.httpStatus=n,s}function i(e){var t=void 0;if(e.getResponseHeader?t=e.getResponseHeader("Content-Type"):e.headers&&(t=e.headers["content-type"]||null),!t)return null;try{return h(t)}catch(e){throw new Error("Error parsing Content-Type '"+t+"': "+e)}}var s=e("babel-runtime/core-js/object/create"),a=n(s),u=e("babel-runtime/core-js/json/stringify"),c=n(u),l=e("babel-runtime/helpers/typeof"),d=n(l),f=e("bluebird"),p=n(f),h=e("content-type").parse,v=e("./utils"),m=e("./realtime-callbacks");t.exports.PREFIX_R0="/_matrix/client/r0",t.exports.PREFIX_UNSTABLE="/_matrix/client/unstable",t.exports.PREFIX_IDENTITY_V1="/_matrix/identity/api/v1",t.exports.PREFIX_MEDIA_R0="/_matrix/media/r0",t.exports.MatrixHttpApi=function(e,t){v.checkObjectHasKeys(t,["baseUrl","request","prefix"]),t.onlyData=t.onlyData||!1,this.event_emitter=e,this.opts=t,this.useAuthorizationHeader=Boolean(t.useAuthorizationHeader),this.uploads=[]},t.exports.MatrixHttpApi.prototype={getContentUri:function(){var e={access_token:this.opts.accessToken};return{base:this.opts.baseUrl,path:"/_matrix/media/v1/upload",params:e}},uploadContent:function(e,t){v.isFunction(t)?t={callback:t}:void 0===t&&(t={});var n=!1!==t.includeFilename,o=t.type||e.type||"application/octet-stream",i=t.name||e.name,s=e.stream?e.stream:e,a=t.rawResponse;void 0===a&&(r.XMLHttpRequest?a=!1:(console.warn("Returning the raw JSON from uploadContent(). Future versions of the js-sdk will change this default, to return the parsed object. Set opts.rawResponse=false to change this behaviour now."),a=!0));var u=t.onlyContentUri;a||void 0!==u||(r.XMLHttpRequest?(console.warn("Returning only the content-uri from uploadContent(). Future versions of the js-sdk will change this default, to return the whole response object. Set opts.onlyContentUri=false to change this behaviour now."),u=!0):u=!1);var c={loaded:0,total:0},l=void 0,d=null;if(a||(d=function(e){var t=JSON.parse(e);if(u&&void 0===(t=t.content_uri))throw Error("Bad response");return t}),r.XMLHttpRequest){var f=p.default.defer(),h=new r.XMLHttpRequest;c.xhr=h;var _=y(f,t.callback,this.opts.onlyData),g=function(){h.abort(),_(new Error("Timeout"))};h.timeout_timer=m.setTimeout(g,3e4),h.onreadystatechange=function(){switch(h.readyState){case r.XMLHttpRequest.DONE:m.clearTimeout(h.timeout_timer);var e;try{if(!h.responseText)throw new Error("No response body.");e=h.responseText,d&&(e=d(e))}catch(e){return e.http_status=h.status,void _(e)}_(void 0,h,e)}},h.upload.addEventListener("progress",function(e){m.clearTimeout(h.timeout_timer),c.loaded=e.loaded,c.total=e.total,h.timeout_timer=m.setTimeout(g,3e4),t.progressHandler&&t.progressHandler({loaded:e.loaded,total:e.total})});var b=this.opts.baseUrl+"/_matrix/media/v1/upload",E=[];n&&i&&E.push("filename="+encodeURIComponent(i)),this.useAuthorizationHeader||E.push("access_token="+encodeURIComponent(this.opts.accessToken)),E.length>0&&(b+="?"+E.join("&")),h.open("POST",b),this.useAuthorizationHeader&&h.setRequestHeader("Authorization","Bearer "+this.opts.accessToken),h.setRequestHeader("Content-Type",o),h.send(s),l=f.promise,l.abort=h.abort.bind(h)}else{var w={};n&&i&&(w.filename=i),l=this.authedRequest(t.callback,"POST","/upload",w,s,{prefix:"/_matrix/media/v1",headers:{"Content-Type":o},json:!1,bodyParser:d})}var S=this,k=l.finally(function(){for(var e=0;e<S.uploads.length;++e)if(S.uploads[e]===c)return void S.uploads.splice(e,1)});return k.abort=l.abort,c.promise=k,this.uploads.push(c),k},cancelUpload:function(e){return!!e.abort&&(e.abort(),!0)},getCurrentUploads:function(){return this.uploads},idServerRequest:function(e,t,r,n,o){var i=this.opts.idBaseUrl+o+r;if(void 0!==e&&!v.isFunction(e))throw Error("Expected callback to be a function but got "+(void 0===e?"undefined":(0,d.default)(e)));var s={uri:i,method:t,withCredentials:!1,json:!1,_matrix_opts:this.opts};"GET"==t?s.qs=n:s.form=n;var a=p.default.defer();return this.opts.request(s,y(a,e,this.opts.onlyData)),a.promise.then(function(e){return JSON.parse(e)})},authedRequest:function(e,t,r,n,o,i){n||(n={}),this.useAuthorizationHeader?(isFinite(i)&&(i={localTimeoutMs:i}),i||(i={}),i.headers||(i.headers={}),i.headers.Authorization||(i.headers.Authorization="Bearer "+this.opts.accessToken),n.access_token&&delete n.access_token):n.access_token||(n.access_token=this.opts.accessToken);var s=this.request(e,t,r,n,o,i),a=this;return s.catch(function(e){"M_UNKNOWN_TOKEN"==e.errcode?a.event_emitter.emit("Session.logged_out"):"M_CONSENT_NOT_GIVEN"==e.errcode&&a.event_emitter.emit("no_consent",e.message,e.data.consent_uri)}),s},request:function(e,t,r,n,o,i){i=i||{};var s=void 0!==i.prefix?i.prefix:this.opts.prefix,a=this.opts.baseUrl+s+r;return this.requestOtherUrl(e,t,a,n,o,i)},authedRequestWithPrefix:function(e,t,r,n,o,i,s){return this.authedRequest(e,t,r,n,o,{localTimeoutMs:s,prefix:i})},requestWithPrefix:function(e,t,r,n,o,i,s){return this.request(e,t,r,n,o,{localTimeoutMs:s,prefix:i})},requestOtherUrl:function(e,t,r,n,o,i){return void 0===i||null===i?i={}:isFinite(i)&&(i={localTimeoutMs:i}),this._request(e,t,r,n,o,i)},getUrl:function(e,t,r){var n="";return t&&(n="?"+v.encodeParams(t)),this.opts.baseUrl+r+e+n},_request:function(e,r,n,o,i,s){if(void 0!==e&&!v.isFunction(e))throw Error("Expected callback to be a function but got "+(void 0===e?"undefined":(0,d.default)(e)));s=s||{};var a=this;if(this.opts.extraParams)for(var u in this.opts.extraParams)this.opts.extraParams.hasOwnProperty(u)&&(o[u]=this.opts.extraParams[u]);var l=v.extend({},s.headers||{}),f=void 0===s.json||s.json,h=s.bodyParser;f&&(i&&(i=(0,c.default)(i),l["content-type"]="application/json"),l.accept||(l.accept="application/json"),void 0===h&&(h=function(e){return JSON.parse(e)}));var _=p.default.defer(),g=void 0,b=!1,E=void 0,w=s.localTimeoutMs||this.opts.localTimeoutMs,S=function(){w&&(g&&m.clearTimeout(g),g=m.setTimeout(function(){b=!0,E&&E.abort&&E.abort(),_.reject(new t.exports.MatrixError({error:"Locally timed out waiting for a response",errcode:"ORG.MATRIX.JSSDK_TIMEOUT",timeout:w}))},w))};S();var k=_.promise;try{E=this.opts.request({uri:n,method:r,withCredentials:!1,qs:o,qsStringifyOptions:s.qsStringifyOptions,useQuerystring:!0,body:i,json:!1,timeout:w,headers:l||{},_matrix_opts:this.opts},function(t,r,n){if(!w||(m.clearTimeout(g),!b)){y(_,e,a.opts.onlyData,h)(t,r,n)}}),E&&("onprogress"in E&&(E.onprogress=function(e){S()}),E.abort&&(k.abort=E.abort.bind(E)))}catch(t){_.reject(t),e&&e(t)}return k}};var y=function(e,t,r,n){return t=t||function(){},function(i,s,a){if(!i)try{s.statusCode>=400?i=o(s,a):n&&(a=n(a))}catch(e){i=new Error("Error parsing server response: "+e)}if(i)e.reject(i),t(i);else{var u={code:s.statusCode,headers:s.headers,data:a};e.resolve(r?a:u),t(null,r?a:u)}}};t.exports.MatrixError=function(e){e=e||{},this.errcode=e.errcode,this.name=e.errcode||"Unknown error code",this.message=e.error||"Unknown message",this.data=e},t.exports.MatrixError.prototype=(0,a.default)(Error.prototype),t.exports.MatrixError.prototype.constructor=t.exports.MatrixError}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./realtime-callbacks":44,"./utils":55,"babel-runtime/core-js/json/stringify":60,"babel-runtime/core-js/object/create":64,"babel-runtime/helpers/typeof":85,bluebird:89,"content-type":94}],28:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){this._matrixClient=e.matrixClient,this._data=e.authData||{},this._requestCallback=e.doRequest,this._stateUpdatedCallback=e.stateUpdated||e.startAuthStage,this._completionDeferred=null,this._inputs=e.inputs||{},e.sessionId&&(this._data.session=e.sessionId),this._clientSecret=e.clientSecret||this._matrixClient.generateClientSecret(),this._emailSid=e.emailSid,void 0===this._emailSid&&(this._emailSid=null),this._currentStage=null}var i=e("babel-runtime/core-js/get-iterator"),s=n(i),a=e("babel-runtime/core-js/json/stringify"),u=n(a),c=e("bluebird"),l=n(c),d=e("url"),f=e("./utils");o.prototype={attemptAuth:function(){var e=this;return this._completionDeferred=l.default.defer(),l.default.resolve().then(function(){return e._data.flows?e._startNextAuthStage():e._doRequest(e._data),e._completionDeferred.promise})},poll:function(){if(this._data.session){var e={};if("m.login.email.identity"==this._currentStage&&this._emailSid){var t=d.parse(this._matrixClient.getIdentityServerUrl());e={type:"m.login.email.identity",threepid_creds:{sid:this._emailSid,client_secret:this._clientSecret,id_server:t.host}}}this.submitAuthDict(e,!0)}},getSessionId:function(){return this._data?this._data.session:void 0},getClientSecret:function(){return this._clientSecret},getStageParams:function(e){var t={};return this._data&&this._data.params&&(t=this._data.params),t[e]},submitAuthDict:function(e,t){if(!this._completionDeferred)throw new Error("submitAuthDict() called before attemptAuth()");var r={session:this._data.session};f.extend(r,e),this._doRequest(r,t)},getEmailSid:function(){return this._emailSid},setEmailSid:function(e){this._emailSid=e},_doRequest:function(e,t){var r=this,n=this,o=void 0;try{o=this._requestCallback(e,t)}catch(e){o=l.default.reject(e)}o=o.then(function(e){console.log("result from request: ",e),n._completionDeferred.resolve(e)},function(e){var t=e.data?e.data.flows:null,r=Boolean(n._data.flows)||Boolean(t);if(401!==e.httpStatus||!e.data||!r)throw e;e.data.flows||e.data.completed||e.data.session||(e.data.flows=n._data.flows,e.data.completed=n._data.completed,e.data.session=n._data.session),n._data=e.data,n._startNextAuthStage()}),o=t?o.catch(function(e){console.log("Ignoring error from UI auth: "+e)}):o.catch(function(e){r._completionDeferred.reject(e)}),o.done()},_startNextAuthStage:function(){var e=this._chooseStage();if(!e)throw new Error("No incomplete flows from the server");if(this._currentStage=e,"m.login.dummy"==e)return void this.submitAuthDict({type:"m.login.dummy"});if(this._data.errcode||this._data.error)return void this._stateUpdatedCallback(e,{errcode:this._data.errcode||"",error:this._data.error||""});var t={};"m.login.email.identity"==e&&(t.emailSid=this._emailSid),this._stateUpdatedCallback(e,t)},_chooseStage:function(){var e=this._chooseFlow();console.log("Active flow => %s",(0,u.default)(e));var t=this._firstUncompletedStage(e);return console.log("Next stage: %s",t),t},_chooseFlow:function(){var e=this._data.flows||[],t=Boolean(this._inputs.emailAddress)||Boolean(this._emailSid),r=Boolean(this._inputs.phoneCountry)&&Boolean(this._inputs.phoneNumber),n=!0,o=!1,i=void 0;try{for(var a,u=(0,s.default)(e);!(n=(a=u.next()).done);n=!0){var c=a.value,l=!1,d=!1,f=!0,p=!1,h=void 0;try{for(var v,m=(0,s.default)(c.stages);!(f=(v=m.next()).done);f=!0){var y=v.value;"m.login.email.identity"===y?l=!0:"m.login.msisdn"==y&&(d=!0)}}catch(_){p=!0,h=_}finally{try{!f&&m.return&&m.return()}finally{if(p)throw h}}if(l==t&&d==r)return c}}catch(_){o=!0,i=_}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}var _=new Error("No appropriate authentication flow found");throw _.name="NoAuthFlowFoundError",_.required_stages=[],t&&_.required_stages.push("m.login.email.identity"),r&&_.required_stages.push("m.login.msisdn"),_.available_flows=e,_},_firstUncompletedStage:function(e){for(var t=(this._data||{}).completed||[],r=0;r<e.stages.length;++r){var n=e.stages[r];if(-1===t.indexOf(n))return n}}},t.exports=o},{"./utils":55,"babel-runtime/core-js/get-iterator":58,"babel-runtime/core-js/json/stringify":60,bluebird:89,url:250}],29:[function(e,t,r){"use strict";var n=e("loglevel"),o=n.getLogger("matrix");o.setLevel(n.levels.DEBUG),t.exports=o},{loglevel:236}],30:[function(e,t,r){(function(r){"use strict";t.exports.ContentHelpers=e("./content-helpers"),t.exports.MatrixEvent=e("./models/event").MatrixEvent,t.exports.EventStatus=e("./models/event").EventStatus,t.exports.MatrixInMemoryStore=e("./store/memory").MatrixInMemoryStore,t.exports.IndexedDBStore=e("./store/indexeddb").IndexedDBStore,t.exports.IndexedDBStoreBackend=e("./store/indexeddb").IndexedDBStoreBackend,t.exports.SyncAccumulator=e("./sync-accumulator"),t.exports.MatrixHttpApi=e("./http-api").MatrixHttpApi,t.exports.MatrixError=e("./http-api").MatrixError,t.exports.InvalidStoreError=e("./errors").InvalidStoreError,t.exports.MatrixClient=e("./client").MatrixClient,t.exports.Room=e("./models/room"),t.exports.Group=e("./models/group"),t.exports.EventTimeline=e("./models/event-timeline"),t.exports.EventTimelineSet=e("./models/event-timeline-set"),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"),t.exports.WebStorageSessionStore=e("./store/session/webstorage"),t.exports.CRYPTO_ENABLED=e("./client").CRYPTO_ENABLED,t.exports.ContentRepo=e("./content-repo"),t.exports.Filter=e("./filter"),t.exports.TimelineWindow=e("./timeline-window").TimelineWindow,t.exports.InteractiveAuth=e("./interactive-auth"),t.exports.MemoryCryptoStore=e("./crypto/store/memory-crypto-store").default,t.exports.IndexedDBCryptoStore=e("./crypto/store/indexeddb-crypto-store").default,t.exports.createNewMatrixCall=e("./webrtc/call").createNewMatrixCall,t.exports.setMatrixCallAudioOutput=e("./webrtc/call").setAudioOutput,t.exports.setMatrixCallAudioInput=e("./webrtc/call").setAudioInput,t.exports.setMatrixCallVideoInput=e("./webrtc/call").setVideoInput;var n=void 0;t.exports.request=function(e){n=e},t.exports.getRequest=function(){return n},t.exports.wrapRequest=function(e){var t=n;n=function(r,n){return e(t,r,n)}};var o=function(){return new t.exports.MemoryCryptoStore};t.exports.setCryptoStoreFactory=function(e){o=e},t.exports.createClient=function(e){return"string"==typeof e&&(e={baseUrl:e}),e.request=e.request||n,e.store=e.store||new t.exports.MatrixInMemoryStore({localStorage:r.localStorage}),e.scheduler=e.scheduler||new t.exports.MatrixScheduler,e.cryptoStore=e.cryptoStore||o(),new t.exports.MatrixClient(e)}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./client":4,"./content-helpers":5,"./content-repo":6,"./crypto/store/indexeddb-crypto-store":21,"./crypto/store/memory-crypto-store":23,"./errors":24,"./filter":26,"./http-api":27,"./interactive-auth":28,"./models/event":34,"./models/event-timeline":33,"./models/event-timeline-set":32,"./models/group":35,"./models/room":39,"./models/room-member":36,"./models/room-state":37,"./models/user":41,"./scheduler":45,"./store/indexeddb":48,"./store/memory":49,"./store/session/webstorage":50,"./sync-accumulator":52,"./timeline-window":54,"./webrtc/call":56}],31:[function(e,t,r){"use strict";function n(e){this._timeline=[e],this._ourEventIndex=0,this._paginateTokens={b:null,f:null},this._paginateRequests={b:null,f:null}}n.prototype.getEvent=function(){return this._timeline[this._ourEventIndex]},n.prototype.getTimeline=function(){return this._timeline},n.prototype.getOurEventIndex=function(){return this._ourEventIndex},n.prototype.getPaginateToken=function(e){return this._paginateTokens[e?"b":"f"]},n.prototype.setPaginateToken=function(e,t){this._paginateTokens[t?"b":"f"]=e},n.prototype.addEvents=function(e,t){t?(this._timeline=e.concat(this._timeline),this._ourEventIndex+=e.length):this._timeline=this._timeline.concat(e)},t.exports=n},{}],32:[function(e,t,r){"use strict";function n(e,t){this.room=e,this._timelineSupport=Boolean(t.timelineSupport),this._liveTimeline=new s(this),this._timelines=[this._liveTimeline],this._eventIdToTimeline={},this._filter=t.filter||null}var o=e("events").EventEmitter,i=e("../utils"),s=e("./event-timeline"),a=void 0;a=console.log.bind(console),i.inherits(n,o),n.prototype.getFilter=function(){return this._filter},n.prototype.setFilter=function(e){this._filter=e},n.prototype.getPendingEvents=function(){return this.room?this._filter?this._filter.filterRoomTimeline(this.room.getPendingEvents()):this.room.getPendingEvents():[]},n.prototype.getLiveTimeline=function(){return this._liveTimeline},n.prototype.eventIdToTimeline=function(e){return this._eventIdToTimeline[e]},n.prototype.replaceEventId=function(e,t){var r=this._eventIdToTimeline[e];r&&(delete this._eventIdToTimeline[e],this._eventIdToTimeline[t]=r)},n.prototype.resetLiveTimeline=function(e,t){var r=!this._timelineSupport||!t,n=this._liveTimeline,o=r?n.forkLive(s.FORWARDS):n.fork(s.FORWARDS);r?(this._timelines=[o],this._eventIdToTimeline={}):this._timelines.push(o),t&&n.setPaginationToken(t,s.FORWARDS),o.setPaginationToken(e,s.BACKWARDS),this._liveTimeline=o,this.emit("Room.timelineReset",this.room,this,r)},n.prototype.getTimelineForEvent=function(e){var t=this._eventIdToTimeline[e];return void 0===t?null:t},n.prototype.findEventById=function(e){var t=this.getTimelineForEvent(e);if(t)return i.findElement(t.getEvents(),function(t){return t.getId()==e})},n.prototype.addTimeline=function(){if(!this._timelineSupport)throw new Error("timeline support is disabled. Set the 'timelineSupport' parameter to true when creating MatrixClient to enable it.");var e=new s(this);return this._timelines.push(e),e},n.prototype.addEventsToTimeline=function(e,t,r,n){if(!r)throw new Error("'timeline' not specified for EventTimelineSet.addEventsToTimeline");if(!t&&r==this._liveTimeline)throw new Error("EventTimelineSet.addEventsToTimeline cannot be used for adding events to the live timeline - use Room.addLiveEvents instead");if(!this._filter||(e=this._filter.filterRoomTimeline(e),e.length)){for(var o=t?s.BACKWARDS:s.FORWARDS,i=t?s.FORWARDS:s.BACKWARDS,u=!1,c=!1,l=0;l<e.length;l++){var d=e[l],f=d.getId(),p=this._eventIdToTimeline[f];if(p)if(c=!1,p!=r){var h=r.getNeighbouringTimeline(o);h?(a(p==h?"Event "+f+" in neighbouring timeline - switching to "+p:"Event "+f+" already in a different timeline "+p),r=p):(console.info("Already have timeline for "+f+" - joining timeline "+r+" to "+p),r.setNeighbouringTimeline(p,o),p.setNeighbouringTimeline(r,i),r=p,u=!0)}else a("Event "+f+" already in timeline "+r);else this.addEventToTimeline(d,r,t),c=!0,u=!0}!c&&u||r.setPaginationToken(n,o)}},n.prototype.addLiveEvent=function(e,t){if(this._filter){if(!this._filter.filterRoomTimeline([e]).length)return}var r=this._eventIdToTimeline[e.getId()];if(r)if("replace"===t){a("EventTimelineSet.addLiveEvent: replacing duplicate event "+e.getId());for(var n=r.getEvents(),o=0;o<n.length;o++)if(n[o].getId()===e.getId()){s.setEventMetadata(e,r.getState(s.FORWARDS),!1),n[o].encryptedType||(n[o]=e);break}}else a("EventTimelineSet.addLiveEvent: ignoring duplicate event "+e.getId());else this.addEventToTimeline(e,this._liveTimeline,!1)},n.prototype.addEventToTimeline=function(e,t,r){var n=e.getId();t.addEvent(e,r),this._eventIdToTimeline[n]=t;var o={timeline:t,liveEvent:!r&&t==this._liveTimeline};this.emit("Room.timeline",e,this.room,Boolean(r),!1,o)},n.prototype.handleRemoteEcho=function(e,t,r){var n=this._eventIdToTimeline[t];n?(delete this._eventIdToTimeline[t],this._eventIdToTimeline[r]=n):this._filter?this._filter.filterRoomTimeline([e]).length&&this.addEventToTimeline(e,this._liveTimeline,!1):this.addEventToTimeline(e,this._liveTimeline,!1)},n.prototype.removeEvent=function(e){var t=this._eventIdToTimeline[e];if(!t)return null;var r=t.removeEvent(e);if(r){delete this._eventIdToTimeline[e];var n={timeline:t};this.emit("Room.timeline",r,this.room,void 0,!0,n)}return r},n.prototype.compareEventOrdering=function(e,t){if(e==t)return 0;var r=this._eventIdToTimeline[e],n=this._eventIdToTimeline[t];if(void 0===r)return null;if(void 0===n)return null;if(r===n){for(var o=void 0,i=void 0,a=r.getEvents(),u=0;u<a.length&&(void 0===o||void 0===i);u++){var c=a[u].getId();c==e&&(o=u),c==t&&(i=u)}return o-i}for(var l=r;l;){if(l===n)return-1;l=l.getNeighbouringTimeline(s.FORWARDS)}for(l=r;l;){if(l===n)return 1;l=l.getNeighbouringTimeline(s.BACKWARDS)}return null},t.exports=n},{"../utils":55,"./event-timeline":33,events:234}],33:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){this._eventTimelineSet=e,this._roomId=e.room?e.room.roomId:null,this._events=[],this._baseIndex=0,this._startState=new c(this._roomId),this._startState.paginationToken=null,this._endState=new c(this._roomId),this._endState.paginationToken=null,this._prevTimeline=null,this._nextTimeline=null,this._paginationRequests={b:null,f:null},this._name=this._roomId+":"+(new Date).toISOString()}var i=e("babel-runtime/core-js/object/freeze"),s=n(i),a=e("babel-runtime/core-js/get-iterator"),u=n(a),c=e("./room-state");o.BACKWARDS="b",o.FORWARDS="f",o.prototype.initialiseState=function(e){if(this._events.length>0)throw new Error("Cannot initialise state after events are added");var t=!0,r=!1,n=void 0;try{for(var o,i=(0,u.default)(e);!(t=(o=i.next()).done);t=!0){var a=o.value;(0,s.default)(a)}}catch(e){r=!0,n=e}finally{try{!t&&i.return&&i.return()}finally{if(r)throw n}}this._startState.setStateEvents(e),this._endState.setStateEvents(e)},o.prototype.forkLive=function(e){var t=this.getState(e),r=new o(this._eventTimelineSet);return r._startState=t.clone(),r._endState=t,this._endState=t.clone(),r},o.prototype.fork=function(e){var t=this.getState(e),r=new o(this._eventTimelineSet);return r._startState=t.clone(),r._endState=t.clone(),r},o.prototype.getRoomId=function(){return this._roomId},o.prototype.getFilter=function(){return this._eventTimelineSet.getFilter()},o.prototype.getTimelineSet=function(){return this._eventTimelineSet},o.prototype.getBaseIndex=function(){return this._baseIndex},o.prototype.getEvents=function(){return this._events},o.prototype.getState=function(e){if(e==o.BACKWARDS)return this._startState;if(e==o.FORWARDS)return this._endState;throw new Error("Invalid direction '"+e+"'")},o.prototype.getPaginationToken=function(e){return this.getState(e).paginationToken},o.prototype.setPaginationToken=function(e,t){this.getState(t).paginationToken=e},o.prototype.getNeighbouringTimeline=function(e){if(e==o.BACKWARDS)return this._prevTimeline;if(e==o.FORWARDS)return this._nextTimeline;throw new Error("Invalid direction '"+e+"'")},o.prototype.setNeighbouringTimeline=function(e,t){if(this.getNeighbouringTimeline(t))throw new Error("timeline already has a neighbouring timeline - cannot reset neighbour");if(t==o.BACKWARDS)this._prevTimeline=e;else{if(t!=o.FORWARDS)throw new Error("Invalid direction '"+t+"'");this._nextTimeline=e}this.setPaginationToken(null,t)},o.prototype.addEvent=function(e,t){var r=t?this._startState:this._endState,n=this.getTimelineSet();n.room&&n.room.getUnfilteredTimelineSet()===n&&(o.setEventMetadata(e,r,t),e.isState()&&(r.setStateEvents([e]),e.sender&&("m.room.member"!==e.getType()||t)||o.setEventMetadata(e,r,t)));var i=void 0;i=t?0:this._events.length,this._events.splice(i,0,e),t&&this._baseIndex++},o.setEventMetadata=function(e,t,r){e.sender=t.getSentinelMember(e.getSender()),"m.room.member"===e.getType()&&(e.target=t.getSentinelMember(e.getStateKey())),e.isState()&&r&&(e.forwardLooking=!1)},o.prototype.removeEvent=function(e){for(var t=this._events.length-1;t>=0;t--){var r=this._events[t];if(r.getId()==e)return this._events.splice(t,1),t<this._baseIndex&&this._baseIndex--,r}return null},o.prototype.toString=function(){return this._name},t.exports=o},{"./room-state":37,"babel-runtime/core-js/get-iterator":58,"babel-runtime/core-js/object/freeze":67}],34:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}var o=e("babel-runtime/regenerator"),i=n(o),s=e("bluebird"),a=n(s),u=e("events"),c=e("../utils.js"),l=n(c);t.exports.EventStatus={NOT_SENT:"not_sent",ENCRYPTING:"encrypting",SENDING:"sending",QUEUED:"queued",SENT:"sent",CANCELLED:"cancelled"};var d={};t.exports.MatrixEvent=function(e){["state_key","type","sender","room_id","membership"].forEach(function(t){e[t]&&(d[e[t]]||(d[e[t]]=e[t]),e[t]=d[e[t]])}),["membership","avatar_url","displayname"].forEach(function(t){e.content&&e.content[t]&&(d[e.content[t]]||(d[e.content[t]]=e.content[t]),e.content[t]=d[e.content[t]])}),this.event=e||{},this.sender=null,this.target=null,this.status=null,this.error=null,this.forwardLooking=!0,this._pushActions=null,this._clearEvent={},this._senderCurve25519Key=null,this._claimedEd25519Key=null,this._forwardingCurve25519KeyChain=[],this._decryptionPromise=null,this._retryDecryption=!1},l.default.inherits(t.exports.MatrixEvent,u.EventEmitter),l.default.extend(t.exports.MatrixEvent.prototype,{getId:function(){return this.event.event_id},getSender:function(){return this.event.sender||this.event.user_id},getType:function(){return this._clearEvent.type||this.event.type},getWireType:function(){return this.event.type},getRoomId:function(){return this.event.room_id},getTs:function(){return this.event.origin_server_ts},
getDate:function(){return this.event.origin_server_ts?new Date(this.event.origin_server_ts):null},getContent:function(){return this._clearEvent.content||this.event.content||{}},getWireContent:function(){return this.event.content||{}},getPrevContent:function(){return this.getUnsigned().prev_content||this.event.prev_content||{}},getDirectionalContent:function(){return this.forwardLooking?this.getContent():this.getPrevContent()},getAge:function(){return this.getUnsigned().age||this.event.age},getStateKey:function(){return this.event.state_key},isState:function(){return void 0!==this.event.state_key},makeEncrypted:function(e,t,r,n){this._clearEvent={type:this.event.type,content:this.event.content},this.event.type=e,this.event.content=t,this._senderCurve25519Key=r,this._claimedEd25519Key=n},isBeingDecrypted:function(){return null!=this._decryptionPromise},isDecryptionFailure:function(){return this._clearEvent&&this._clearEvent.content&&"m.bad.encrypted"===this._clearEvent.content.msgtype},attemptDecryption:function(){function e(e){return t.apply(this,arguments)}var t=(0,s.method)(function(e){if(!this.isEncrypted())throw new Error("Attempt to decrypt event which isn't encrypted");if(this._clearEvent&&this._clearEvent.content&&"m.bad.encrypted"!==this._clearEvent.content.msgtype)throw new Error("Attempt to decrypt event which has already been encrypted");return this._decryptionPromise?(console.log("Event "+this.getId()+" already being decrypted; queueing a retry"),this._retryDecryption=!0,this._decryptionPromise):(this._decryptionPromise=this._decryptionLoop(e),this._decryptionPromise)});return e}(),cancelAndResendKeyRequest:function(e){var t=this.getWireContent();e.cancelRoomKeyRequest({algorithm:t.algorithm,room_id:this.getRoomId(),session_id:t.session_id,sender_key:t.sender_key},!0)},_decryptionLoop:function(){function e(e){return t.apply(this,arguments)}var t=(0,s.coroutine)(i.default.mark(function e(t){var r,n;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,s.resolve)(a.default.resolve());case 2:if(this._retryDecryption=!1,r=void 0,n=void 0,e.prev=6,t){e.next=11;break}r=this._badEncryptedMessage("Encryption not enabled"),e.next=14;break;case 11:return e.next=13,(0,s.resolve)(t.decryptEvent(this));case 13:r=e.sent;case 14:e.next=29;break;case 16:if(e.prev=16,e.t0=e.catch(6),"DecryptionError"===e.t0.name){e.next=23;break}return console.error("Error decrypting event (id="+this.getId()+"): "+(e.t0.stack||e.t0)),this._decryptionPromise=null,this._retryDecryption=!1,e.abrupt("return");case 23:if(n=e.t0,!this._retryDecryption){e.next=27;break}return console.log("Got error decrypting event (id="+this.getId()+": "+e.t0+"), but retrying"),e.abrupt("continue",2);case 27:console.warn("Error decrypting event (id="+this.getId()+"): "+e.t0.detailedString),r=this._badEncryptedMessage(e.t0.message);case 29:return this._decryptionPromise=null,this._retryDecryption=!1,this._setClearData(r),this.emit("Event.decrypted",this,n),e.abrupt("return");case 36:case"end":return e.stop()}},e,this,[[6,16]])}));return e}(),_badEncryptedMessage:function(e){return{clearEvent:{type:"m.room.message",content:{msgtype:"m.bad.encrypted",body:"** Unable to decrypt: "+e+" **"}}}},_setClearData:function(e){this._clearEvent=e.clearEvent,this._senderCurve25519Key=e.senderCurve25519Key||null,this._claimedEd25519Key=e.claimedEd25519Key||null,this._forwardingCurve25519KeyChain=e.forwardingCurve25519KeyChain||[]},isEncrypted:function(){return"m.room.encrypted"===this.event.type},getSenderKey:function(){return this._senderCurve25519Key},getKeysClaimed:function(){return{ed25519:this._claimedEd25519Key}},getClaimedEd25519Key:function(){return this._claimedEd25519Key},getForwardingCurve25519KeyChain:function(){return this._forwardingCurve25519KeyChain},getUnsigned:function(){return this.event.unsigned||{}},makeRedacted:function(e){if(!e.event)throw new Error("invalid redaction_event in makeRedacted");this.event.unsigned||(this.event.unsigned={}),this.event.unsigned.redacted_because=e.event;var t=void 0;for(t in this.event)this.event.hasOwnProperty(t)&&(f[t]||delete this.event[t]);var r=p[this.getType()]||{},n=this.getContent();for(t in n)n.hasOwnProperty(t)&&(r[t]||delete n[t])},isRedacted:function(){return Boolean(this.getUnsigned().redacted_because)},getPushActions:function(){return this._pushActions},setPushActions:function(e){this._pushActions=e},handleRemoteEcho:function(e){this.event=e,this.status=null}});var f=["event_id","type","room_id","user_id","sender","state_key","prev_state","content","unsigned","origin_server_ts"].reduce(function(e,t){return e[t]=1,e},{}),p={"m.room.member":{membership:1},"m.room.create":{creator:1},"m.room.join_rules":{join_rule:1},"m.room.power_levels":{ban:1,events:1,events_default:1,kick:1,redact:1,state_default:1,users:1,users_default:1},"m.room.aliases":{aliases:1}}},{"../utils.js":55,"babel-runtime/regenerator":86,bluebird:89,events:234}],35:[function(e,t,r){"use strict";function n(e){this.groupId=e,this.name=null,this.avatarUrl=null,this.myMembership=null,this.inviter=null}var o=e("events").EventEmitter;e("../utils").inherits(n,o),n.prototype.setProfile=function(e,t){this.name===e&&this.avatarUrl===t||(this.name=e||this.groupId,this.avatarUrl=t,this.emit("Group.profile",this))},n.prototype.setMyMembership=function(e){this.myMembership!==e&&(this.myMembership=e,this.emit("Group.myMembership",this))},n.prototype.setInviter=function(e){this.inviter=e},t.exports=n},{"../utils":55,events:234}],36:[function(e,t,r){"use strict";function n(e,t){this.roomId=e,this.userId=t,this.typing=!1,this.name=t,this.rawDisplayName=t,this.powerLevel=0,this.powerLevelNorm=0,this.user=null,this.membership=null,this.events={member:null},this._isOutOfBand=!1,this._updateModifiedTime()}function o(e,t,r){if(!t||t===e)return e;if(!r)return t;var n=a.removeHiddenChars(t);if(!n)return e;var o=/@.+:.+/.test(t);if(!o){o=r.getUserIdsWithDisplayName(n).some(function(t){return t!==e})}return o?t+" ("+e+")":t}var i=e("events").EventEmitter,s=e("../content-repo"),a=e("../utils");a.inherits(n,i),n.prototype.markOutOfBand=function(){this._isOutOfBand=!0},n.prototype.isOutOfBand=function(){return this._isOutOfBand},n.prototype.setMembershipEvent=function(e,t){if("m.room.member"===e.getType()){this._isOutOfBand=!1,this.events.member=e;var r=this.membership;this.membership=e.getDirectionalContent().membership;var n=this.name;this.name=o(this.userId,e.getDirectionalContent().displayname,t),this.rawDisplayName=e.getDirectionalContent().displayname||this.userId,r!==this.membership&&(this._updateModifiedTime(),this.emit("RoomMember.membership",e,this,r)),n!==this.name&&(this._updateModifiedTime(),this.emit("RoomMember.name",e,this,n))}},n.prototype.setPowerLevelEvent=function(e){if("m.room.power_levels"===e.getType()){var t=e.getDirectionalContent(),r=t.users_default||0;a.forEach(a.values(t.users),function(e){r=Math.max(r,e)});var n=this.powerLevel,o=this.powerLevelNorm;t.users&&void 0!==t.users[this.userId]?this.powerLevel=t.users[this.userId]:void 0!==t.users_default?this.powerLevel=t.users_default:this.powerLevel=0,this.powerLevelNorm=0,r>0&&(this.powerLevelNorm=100*this.powerLevel/r),n===this.powerLevel&&o===this.powerLevelNorm||(this._updateModifiedTime(),this.emit("RoomMember.powerLevel",e,this))}},n.prototype.setTypingEvent=function(e){if("m.typing"===e.getType()){var t=this.typing;this.typing=!1;var r=e.getContent().user_ids;a.isArray(r)&&(-1!==r.indexOf(this.userId)&&(this.typing=!0),t!==this.typing&&(this._updateModifiedTime(),this.emit("RoomMember.typing",e,this)))}},n.prototype._updateModifiedTime=function(){this._modified=Date.now()},n.prototype.getLastModifiedTime=function(){return this._modified},n.prototype.isKicked=function(){return"leave"===this.membership&&this.events.member.getSender()!==this.events.member.getStateKey()},n.prototype.getDMInviter=function(){if(this.events.member){var e=this.events.member,t=e.getContent(),r=e.getSender();if("join"===t.membership&&(t=e.getPrevContent(),r=e.getUnsigned().prev_sender),"invite"===t.membership&&t.is_direct)return r}},n.prototype.getAvatarUrl=function(e,t,r,n,o,i){void 0===o&&(o=!0);var a=this.getMxcAvatarUrl();if(!a&&!o)return null;var u=s.getHttpUriForMxc(e,a,t,r,n,i);return u||(o?s.getIdenticonUri(e,this.userId,t,r):null)},n.prototype.getMxcAvatarUrl=function(){return this.events.member?this.events.member.getDirectionalContent().avatar_url:this.user?this.user.avatarUrl:null},t.exports=n},{"../content-repo":6,"../utils":55,events:234}],37:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;this.roomId=e,this.members={},this.events={},this.paginationToken=null,this._sentinels={},this._updateModifiedTime(),this._displayNameToUserIds={},this._userIdsToDisplayNames={},this._tokenToInvite={},this._joinedMemberCount=null,this._summaryJoinedMemberCount=null,this._invitedMemberCount=null,this._summaryInvitedMemberCount=null,t||(t={status:m}),this._oobMemberFlags=t}function i(e,t){if(t.getContent().third_party_invite){var r=(t.getContent().third_party_invite.signed||{}).token;if(r){e.getStateEvents("m.room.third_party_invite",r)&&(e._tokenToInvite[r]=t)}}}function s(e,t,r){var n=e._userIdsToDisplayNames[t];if(delete e._userIdsToDisplayNames[t],n){var o=h.removeHiddenChars(n),i=e._displayNameToUserIds[o];if(i){var s=i.filter(function(e){return e!==t});e._displayNameToUserIds[o]=s}}e._userIdsToDisplayNames[t]=r;var a=r&&h.removeHiddenChars(r);a&&(e._displayNameToUserIds[a]||(e._displayNameToUserIds[a]=[]),e._displayNameToUserIds[a].push(t))}var a=e("babel-runtime/core-js/number/is-finite"),u=n(a),c=e("babel-runtime/core-js/object/keys"),l=n(c),d=e("babel-runtime/core-js/object/values"),f=n(d),p=e("events").EventEmitter,h=e("../utils"),v=e("./room-member"),m=1;h.inherits(o,p),o.prototype.getJoinedMemberCount=function(){return null!==this._summaryJoinedMemberCount?this._summaryJoinedMemberCount:(null===this._joinedMemberCount&&(this._joinedMemberCount=this.getMembers().reduce(function(e,t){return"join"===t.membership?e+1:e},0)),this._joinedMemberCount)},o.prototype.setJoinedMemberCount=function(e){this._summaryJoinedMemberCount=e},o.prototype.getInvitedMemberCount=function(){return null!==this._summaryInvitedMemberCount?this._summaryInvitedMemberCount:(null===this._invitedMemberCount&&(this._invitedMemberCount=this.getMembers().reduce(function(e,t){return"invite"===t.membership?e+1:e},0)),this._invitedMemberCount)},o.prototype.setInvitedMemberCount=function(e){this._summaryInvitedMemberCount=e},o.prototype.getMembers=function(){return h.values(this.members)},o.prototype.getMember=function(e){return this.members[e]||null},o.prototype.getSentinelMember=function(e){if(!e)return null;var t=this._sentinels[e];if(void 0===t){t=new v(this.roomId,e);var r=this.members[e];r&&t.setMembershipEvent(r.events.member,this),this._sentinels[e]=t}return t},o.prototype.getStateEvents=function(e,t){if(!this.events[e])return void 0===t?[]:null;if(void 0===t)return h.values(this.events[e]);var r=this.events[e][t];return r||null},o.prototype.clone=function(){var e=new o(this.roomId,this._oobMemberFlags),t=this._oobMemberFlags.status;return this._oobMemberFlags.status=m,(0,f.default)(this.events).forEach(function(t){var r=(0,f.default)(t);e.setStateEvents(r)}),this._oobMemberFlags.status=t,null!==this._summaryInvitedMemberCount&&e.setInvitedMemberCount(this.getInvitedMemberCount()),null!==this._summaryJoinedMemberCount&&e.setJoinedMemberCount(this.getJoinedMemberCount()),3==this._oobMemberFlags.status&&this.getMembers().forEach(function(t){if(t.isOutOfBand()){e.getMember(t.userId).markOutOfBand()}}),e},o.prototype.setUnknownStateEvents=function(e){var t=this,r=e.filter(function(e){return void 0===t.events[e.getType()]||void 0===t.events[e.getType()][e.getStateKey()]});this.setStateEvents(r)},o.prototype.setStateEvents=function(e){var t=this;this._updateModifiedTime(),h.forEach(e,function(e){e.getRoomId()===t.roomId&&e.isState()&&(t._setStateEvent(e),"m.room.member"===e.getType()&&(s(t,e.getStateKey(),e.getContent().displayname),i(t,e)),t.emit("RoomState.events",e,t))}),h.forEach(e,function(e){if(e.getRoomId()===t.roomId&&e.isState())if("m.room.member"===e.getType()){var r=e.getStateKey();"leave"!==e.getContent().membership&&"ban"!==e.getContent().membership||(e.getContent().avatar_url=e.getContent().avatar_url||e.getPrevContent().avatar_url,e.getContent().displayname=e.getContent().displayname||e.getPrevContent().displayname);var n=t._getOrCreateMember(r,e);n.setMembershipEvent(e,t),t._updateMember(n),t.emit("RoomState.members",e,t,n)}else if("m.room.power_levels"===e.getType()){var o=h.values(t.members);h.forEach(o,function(r){r.setPowerLevelEvent(e),t.emit("RoomState.members",e,t,r)}),t._sentinels={}}})},o.prototype._getOrCreateMember=function(e,t){var r=this.members[e];return r||(r=new v(this.roomId,e),this.members[e]=r,this.emit("RoomState.newMember",t,this,r)),r},o.prototype._setStateEvent=function(e){void 0===this.events[e.getType()]&&(this.events[e.getType()]={}),this.events[e.getType()][e.getStateKey()]=e},o.prototype._updateMember=function(e){var t=this.getStateEvents("m.room.power_levels","");t&&e.setPowerLevelEvent(t),delete this._sentinels[e.userId],this.members[e.userId]=e,this._joinedMemberCount=null,this._invitedMemberCount=null},o.prototype.needsOutOfBandMembers=function(){return this._oobMemberFlags.status===m},o.prototype.markOutOfBandMembersStarted=function(){this._oobMemberFlags.status===m&&(this._oobMemberFlags.status=2)},o.prototype.markOutOfBandMembersFailed=function(){2===this._oobMemberFlags.status&&(this._oobMemberFlags.status=m)},o.prototype.clearOutOfBandMembers=function(){var e=this,t=0;(0,l.default)(this.members).forEach(function(r){e.members[r].isOutOfBand()&&(++t,delete e.members[r])}),console.log("LL: RoomState removed "+t+" members..."),this._oobMemberFlags.status=m},o.prototype.setOutOfBandMembers=function(e){var t=this;console.log("LL: RoomState about to set "+e.length+" OOB members ..."),2===this._oobMemberFlags.status&&(console.log("LL: RoomState put in OOB_STATUS_FINISHED state ..."),this._oobMemberFlags.status=3,e.forEach(function(e){return t._setOutOfBandMember(e)}))},o.prototype._setOutOfBandMember=function(e){if("m.room.member"===e.getType()){var t=e.getStateKey(),r=this.getMember(t);if(!r||r.isOutOfBand()){var n=this._getOrCreateMember(t,e);n.setMembershipEvent(e,this),n.markOutOfBand(),s(this,n.userId,n.name),this._setStateEvent(e),this._updateMember(n),this.emit("RoomState.members",e,this,n)}}},o.prototype.setTypingEvent=function(e){h.forEach(h.values(this.members),function(t){t.setTypingEvent(e)})},o.prototype.getInviteForThreePidToken=function(e){return this._tokenToInvite[e]||null},o.prototype._updateModifiedTime=function(){this._modified=Date.now()},o.prototype.getLastModifiedTime=function(){return this._modified},o.prototype.getUserIdsWithDisplayName=function(e){return this._displayNameToUserIds[e]||[]},o.prototype.maySendRedactionForEvent=function(e,t){var r=this.getMember(t);if(!r||"leave"===r.membership)return!1;if(e.status||e.isRedacted())return!1;var n=this.maySendEvent("m.room.redaction",t);return e.getSender()===t?n:this._hasSufficientPowerLevelFor("redact",r.powerLevel)},o.prototype._hasSufficientPowerLevelFor=function(e,t){var r=this.getStateEvents("m.room.power_levels",""),n={};r&&(n=r.getContent());var o=50;return h.isNumber(n[e])&&(o=n[e]),t>=o},o.prototype.maySendMessage=function(e){return this._maySendEventOfType("m.room.message",e,!1)},o.prototype.maySendEvent=function(e,t){return this._maySendEventOfType(e,t,!1)},o.prototype.mayClientSendStateEvent=function(e,t){return!t.isGuest()&&this.maySendStateEvent(e,t.credentials.userId)},o.prototype.maySendStateEvent=function(e,t){return this._maySendEventOfType(e,t,!0)},o.prototype._maySendEventOfType=function(e,t,r){var n=this.getStateEvents("m.room.power_levels",""),o=void 0,i={},s=0,a=0,c=0;if(n){o=n.getContent(),i=o.events||{},s=(0,u.default)(o.state_default)?o.state_default:50;var l=o.users&&o.users[t];(0,u.default)(l)?c=l:(0,u.default)(o.users_default)&&(c=o.users_default),(0,u.default)(o.events_default)&&(a=o.events_default)}var d=r?s:a;return(0,u.default)(i[e])&&(d=i[e]),c>=d},o.prototype.mayTriggerNotifOfType=function(e,t){var r=this.getMember(t);if(!r)return!1;var n=this.getStateEvents("m.room.power_levels",""),o=50;return n&&n.getContent()&&n.getContent().notifications&&h.isNumber(n.getContent().notifications[e])&&(o=n.getContent().notifications[e]),r.powerLevel>=o},t.exports=o},{"../utils":55,"./room-member":36,"babel-runtime/core-js/number/is-finite":61,"babel-runtime/core-js/object/keys":69,"babel-runtime/core-js/object/values":71,events:234}],38:[function(e,t,r){"use strict";function n(e,t){this.roomId=e,this.info=t}t.exports=n},{}],39:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t,r){var n={content:{},type:"m.receipt",room_id:t.getRoomId()};return n.content[t.getId()]={},n.content[t.getId()][r]={},n.content[t.getId()][r][e]={ts:t.getTs()},new S(n)}function i(e,t,r,n){if(n=n||{},n.pendingEventOrdering=n.pendingEventOrdering||"chronological",this.reEmitter=new _.default(this),-1===["chronological","detached"].indexOf(n.pendingEventOrdering))throw new Error("opts.pendingEventOrdering MUST be either 'chronological' or 'detached'. Got: '"+n.pendingEventOrdering+"'");this.myUserId=r,this.roomId=e,this.name=e,this.tags={},this.accountData={},this.summary=null,this.storageToken=n.storageToken,this._opts=n,this._txnToEvent={},this._receipts={},this._receiptCacheByEventId={},this._realReceipts={},this._notificationCounts={},this._timelineSets=[new R(this,n)],this.reEmitter.reEmit(this.getUnfilteredTimelineSet(),["Room.timeline","Room.timelineReset"]),this._fixUpLegacyTimelineFields(),this._filteredTimelineSets={},"detached"==this._opts.pendingEventOrdering&&(this._pendingEventList=[]),this._blacklistUnverifiedDevices=null,this._selfMembership=null,this._summaryHeroes=null,this._client=t,this._opts.lazyLoadMembers?this._membersPromise=null:this._membersPromise=m.default.resolve()}function s(e,t,r){if(!r){var n=e.currentState.getStateEvents("m.room.name","");if(n&&n.getContent()&&n.getContent().name)return n.getContent().name}var o=e.getCanonicalAlias();if(!o){var i=e.getAliases();i.length&&(o=i[0])}if(o)return o;var s=e.currentState.getJoinedMemberCount(),u=e.currentState.getInvitedMemberCount(),c=s+u-1,l=null;if(e._summaryHeroes)l=e._summaryHeroes.map(function(t){var r=e.getMember(t);return r?r.name:t});else{var d=e.currentState.getMembers().filter(function(e){return e.userId!==t&&("invite"===e.membership||"join"===e.membership)});d.sort(function(e,t){return e.userId.localeCompare(t.userId)}),d=d.slice(0,5),l=d.map(function(e){return e.name})}if(c)return a(l,c);if("join"==e.getMyMembership()){var f=e.currentState.getStateEvents("m.room.third_party_invite");if(f&&f.length)return"Inviting "+a(f.map(function(e){return e.getContent().display_name}))}var p=l;return p.length||(p=e.currentState.getMembers().filter(function(e){return e.userId!==t&&"invite"!==e.membership&&"join"!==e.membership}).map(function(e){return e.name})),p.length?"Empty room (was "+a(p)+")":"Empty room"}function a(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.length+1,r=t-1;if(e.length){if(1===e.length&&r<=1)return e[0];if(2===e.length&&r<=2)return e[0]+" and "+e[1];return r>1?e[0]+" and "+r+" others":e[0]+" and 1 other"}return"Empty room"}var u=e("babel-runtime/core-js/object/assign"),c=n(u),l=e("babel-runtime/core-js/number/is-integer"),d=n(l),f=e("babel-runtime/regenerator"),p=n(f),h=e("bluebird"),v=e("babel-runtime/core-js/promise"),m=n(v),y=e("../ReEmitter"),_=n(y),g=e("events").EventEmitter,b=e("./event").EventStatus,E=e("./room-summary"),w=e("./room-member"),S=e("./event").MatrixEvent,k=e("../utils"),T=e("../content-repo"),x=e("./event-timeline"),R=e("./event-timeline-set");k.inherits(i,g),i.prototype.getVersion=function(){var e=this.currentState.getStateEvents("m.room.create","");if(!e)return console.warn("Room "+this.room_id+" does not have an m.room.create event"),"1";var t=e.getContent().room_version;return void 0===t?"1":t},i.prototype.shouldUpgradeToVersion=function(){return"1"===this.getVersion()?null:"1"},i.prototype.userMayUpgradeRoom=function(e){return this.currentState.maySendStateEvent("m.room.tombstone",e)},i.prototype.getPendingEvents=function(){if("detached"!==this._opts.pendingEventOrdering)throw new Error("Cannot call getPendingEventList with pendingEventOrdering == "+this._opts.pendingEventOrdering);return this._pendingEventList},i.prototype.getLiveTimeline=function(){return this.getUnfilteredTimelineSet().getLiveTimeline()},i.prototype.getMyMembership=function(){return this._selfMembership},i.prototype.getDMInviter=function(){if(this.myUserId){var e=this.getMember(this.myUserId);if(e)return e.getDMInviter()}if("invite"===this._selfMembership){if(2==this.getInvitedAndJoinedMemberCount()&&this._summaryHeroes.length)return this._summaryHeroes[0]}},i.prototype.guessDMUserId=function(){var e=this,t=this.getMember(this.myUserId);if(t){var r=t.getDMInviter();if(r)return r}if(Array.isArray(this._summaryHeroes)&&this._summaryHeroes.length)return this._summaryHeroes[0];var n=this.currentState.getMembers(),o=n.find(function(t){return t.userId!==e.myUserId});return o?o.userId:this.myUserId},i.prototype.getAvatarFallbackMember=function(){var e=this;if(!(this.getInvitedAndJoinedMemberCount()>2)){var t=Array.isArray(this._summaryHeroes)&&this._summaryHeroes.length;if(t){var r=this._summaryHeroes.map(function(t){return e.getMember(t)}).find(function(e){return!!e});if(r)return r}var n=this.currentState.getMembers();if(n.length<=2){var o=n.find(function(t){return t.userId!==e.myUserId});if(o)return o}if(t){var i=this._summaryHeroes.map(function(t){return e._client.getUser(t)}).find(function(e){return!!e});if(i){var s=new w(this.roomId,i.userId);return s.user=i,s}}}},i.prototype.updateMyMembership=function(e){var t=this._selfMembership;this._selfMembership=e,t!==e&&("leave"===e&&this._cleanupAfterLeaving(),this.emit("Room.myMembership",this,e,t))},i.prototype._loadMembersFromServer=(0,h.coroutine)(p.default.mark(function e(){var t,r,n,o,i;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=this._client.store.getSyncToken(),r=k.encodeParams({not_membership:"leave",at:t}),n=k.encodeUri("/rooms/$roomId/members?"+r,{$roomId:this.roomId}),o=this._client._http,e.next=6,(0,h.resolve)(o.authedRequest(void 0,"GET",n));case 6:return i=e.sent,e.abrupt("return",i.chunk);case 8:case"end":return e.stop()}},e,this)})),i.prototype._loadMembers=(0,h.coroutine)(p.default.mark(function e(){var t,r,n;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=!1,e.next=3,(0,h.resolve)(this._client.store.getOutOfBandMembers(this.roomId));case 3:if(null!==(r=e.sent)){e.next=10;break}return t=!0,e.next=8,(0,h.resolve)(this._loadMembersFromServer());case 8:r=e.sent,console.log("LL: got "+r.length+" members from server for room "+this.roomId);case 10:return n=r.map(this._client.getEventMapper()),e.abrupt("return",{memberEvents:n,fromServer:t});case 12:case"end":return e.stop()}},e,this)})),i.prototype.loadMembersIfNeeded=function(){var e=this;if(this._membersPromise)return this._membersPromise;this.currentState.markOutOfBandMembersStarted();var t=this._loadMembers().then(function(t){return e.currentState.setOutOfBandMembers(t.memberEvents),e._client.isRoomEncrypted(e.roomId)&&e._client._crypto.trackRoomDevices(e.roomId),t.fromServer}).catch(function(t){throw e._membersPromise=null,e.currentState.markOutOfBandMembersFailed(),t});return t.then(function(t){if(t){var r=e.currentState.getMembers().filter(function(e){return e.isOutOfBand()}).map(function(e){return e.events.member.event});console.log("LL: telling store to write "+r.length+" members for room "+e.roomId);return e._client.store.setOutOfBandMembers(e.roomId,r).catch(function(e){console.log("LL: storing OOB room members failed, oh well",e)})}}).catch(function(e){console.error(e)}),this._membersPromise=t,this._membersPromise},i.prototype.clearLoadedMembersIfNeeded=(0,h.coroutine)(p.default.mark(function e(){return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._opts.lazyLoadMembers||!this._membersPromise){e.next=7;break}return e.next=3,(0,h.resolve)(this.loadMembersIfNeeded());case 3:return e.next=5,(0,h.resolve)(this._client.store.clearOutOfBandMembers(this.roomId));case 5:this.currentState.clearOutOfBandMembers(),this._membersPromise=null;case 7:case"end":return e.stop()}},e,this)})),i.prototype._cleanupAfterLeaving=function(){var e=this;this.clearLoadedMembersIfNeeded().catch(function(t){console.error("error after clearing loaded members from room "+e.roomId+" after leaving"),console.dir(t)})},i.prototype.resetLiveTimeline=function(e,t){for(var r=0;r<this._timelineSets.length;r++)this._timelineSets[r].resetLiveTimeline(e,t);this._fixUpLegacyTimelineFields()},i.prototype._fixUpLegacyTimelineFields=function(){this.timeline=this.getLiveTimeline().getEvents(),this.oldState=this.getLiveTimeline().getState(x.BACKWARDS),this.currentState=this.getLiveTimeline().getState(x.FORWARDS)},i.prototype.getTimelineSets=function(){return this._timelineSets},i.prototype.getUnfilteredTimelineSet=function(){return this._timelineSets[0]},i.prototype.getTimelineForEvent=function(e){return this.getUnfilteredTimelineSet().getTimelineForEvent(e)},i.prototype.addTimeline=function(){return this.getUnfilteredTimelineSet().addTimeline()},i.prototype.findEventById=function(e){return this.getUnfilteredTimelineSet().findEventById(e)},i.prototype.getUnreadNotificationCount=function(e){return e=e||"total",this._notificationCounts[e]},i.prototype.setUnreadNotificationCount=function(e,t){this._notificationCounts[e]=t},i.prototype.setSummary=function(e){var t=this,r=e["m.heroes"],n=e["m.joined_member_count"],o=e["m.invited_member_count"];(0,d.default)(n)&&this.currentState.setJoinedMemberCount(n),(0,d.default)(o)&&this.currentState.setInvitedMemberCount(o),Array.isArray(r)&&(this._summaryHeroes=r.filter(function(e){return e!==t.myUserId}))},i.prototype.setBlacklistUnverifiedDevices=function(e){this._blacklistUnverifiedDevices=e},i.prototype.getBlacklistUnverifiedDevices=function(){return this._blacklistUnverifiedDevices},i.prototype.getAvatarUrl=function(e,t,r,n,o){var i=this.currentState.getStateEvents("m.room.avatar","");if(void 0===o&&(o=!0),!i&&!o)return null;var s=i?i.getContent().url:null;return s?T.getHttpUriForMxc(e,s,t,r,n):o?T.getIdenticonUri(e,this.roomId,t,r):null},i.prototype.getAliases=function(){var e=[],t=this.currentState.getStateEvents("m.room.aliases");if(t)for(var r=0;r<t.length;++r){var n=t[r];k.isArray(n.getContent().aliases)&&Array.prototype.push.apply(e,n.getContent().aliases)}return e},i.prototype.getCanonicalAlias=function(){var e=this.currentState.getStateEvents("m.room.canonical_alias","");return e?e.getContent().alias:null},i.prototype.addEventsToTimeline=function(e,t,r,n){r.getTimelineSet().addEventsToTimeline(e,t,r,n)},i.prototype.getMember=function(e){return this.currentState.getMember(e)},i.prototype.getJoinedMembers=function(){return this.getMembersWithMembership("join")},i.prototype.getJoinedMemberCount=function(){return this.currentState.getJoinedMemberCount()},i.prototype.getInvitedMemberCount=function(){return this.currentState.getInvitedMemberCount()},i.prototype.getInvitedAndJoinedMemberCount=function(){return this.getInvitedMemberCount()+this.getJoinedMemberCount()},i.prototype.getMembersWithMembership=function(e){return k.filter(this.currentState.getMembers(),function(t){return t.membership===e})},i.prototype.getEncryptionTargetMembers=(0,h.coroutine)(p.default.mark(function e(){var t;return p.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,h.resolve)(this.loadMembersIfNeeded());case 2:return t=this.getMembersWithMembership("join"),this.shouldEncryptForInvitedMembers()&&(t=t.concat(this.getMembersWithMembership("invite"))),e.abrupt("return",t);case 5:case"end":return e.stop()}},e,this)})),i.prototype.shouldEncryptForInvitedMembers=function(){var e=this.currentState.getStateEvents("m.room.history_visibility","");return e&&e.getContent()&&"joined"!==e.getContent().history_visibility},i.prototype.getDefaultRoomName=function(e){return s(this,e,!0)},i.prototype.hasMembershipState=function(e,t){var r=this.getMember(e);return!!r&&r.membership===t},i.prototype.getOrCreateFilteredTimelineSet=function(e){if(this._filteredTimelineSets[e.filterId])return this._filteredTimelineSets[e.filterId];var t=(0,c.default)({filter:e},this._opts),r=new R(this,t);this.reEmitter.reEmit(r,["Room.timeline","Room.timelineReset"]),this._filteredTimelineSets[e.filterId]=r,this._timelineSets.push(r);var n=this.getLiveTimeline();n.getEvents().forEach(function(e){r.addLiveEvent(e)});for(var o=n;o.getNeighbouringTimeline(x.BACKWARDS);)o=o.getNeighbouringTimeline(x.BACKWARDS);return r.getLiveTimeline().setPaginationToken(o.getPaginationToken(x.BACKWARDS),x.BACKWARDS),r},i.prototype.removeFilteredTimelineSet=function(e){var t=this._filteredTimelineSets[e.filterId];delete this._filteredTimelineSets[e.filterId];var r=this._timelineSets.indexOf(t);r>-1&&this._timelineSets.splice(r,1)},i.prototype._addLiveEvent=function(e,t){var r=void 0;if("m.room.redaction"===e.getType()){var n=e.event.redacts,i=this.getUnfilteredTimelineSet().findEventById(n);i&&(i.makeRedacted(e),this.emit("Room.redaction",e,this))}if(e.getUnsigned().transaction_id){var s=this._txnToEvent[e.getUnsigned().transaction_id];if(s)return void this._handleRemoteEcho(e,s)}for(r=0;r<this._timelineSets.length;r++)this._timelineSets[r].addLiveEvent(e,t);e.sender&&"m.room.redaction"!==e.getType()&&this.addReceipt(o(e.sender.userId,e,"m.read"),!0)},i.prototype.addPendingEvent=function(e,t){if(e.status!==b.SENDING)throw new Error("addPendingEvent called on an event with status "+e.status);if(this._txnToEvent[t])throw new Error("addPendingEvent called on an event with known txnId "+t);if(x.setEventMetadata(e,this.getLiveTimeline().getState(x.FORWARDS),!1),this._txnToEvent[t]=e,"detached"==this._opts.pendingEventOrdering)this._pendingEventList.some(function(e){return e.status===b.NOT_SENT})&&(console.warn("Setting event as NOT_SENT due to messages in the same state"),e.status=b.NOT_SENT),this._pendingEventList.push(e);else for(var r=0;r<this._timelineSets.length;r++){var n=this._timelineSets[r];n.getFilter()?this._filter.filterRoomTimeline([e]).length&&n.addEventToTimeline(e,n.getLiveTimeline(),!1):n.addEventToTimeline(e,n.getLiveTimeline(),!1)}this.emit("Room.localEchoUpdated",e,this,null,null)},i.prototype._handleRemoteEcho=function(e,t){var r=t.getId(),n=e.getId(),o=t.status;delete this._txnToEvent[e.transaction_id],this._pendingEventList&&k.removeElement(this._pendingEventList,function(e){return e.getId()==r},!1),t.handleRemoteEcho(e.event);for(var i=0;i<this._timelineSets.length;i++){this._timelineSets[i].handleRemoteEcho(t,r,n)}this.emit("Room.localEchoUpdated",t,this,r,o)};var I={};I[b.ENCRYPTING]=[b.SENDING,b.NOT_SENT],I[b.SENDING]=[b.ENCRYPTING,b.QUEUED,b.NOT_SENT,b.SENT],I[b.QUEUED]=[b.SENDING,b.CANCELLED],I[b.SENT]=[],I[b.NOT_SENT]=[b.SENDING,b.QUEUED,b.CANCELLED],I[b.CANCELLED]=[],i.prototype.updatePendingEvent=function(e,t,r){if(console.log("setting pendingEvent status to "+t+" in "+e.getRoomId()),t==b.SENT&&!r)throw new Error("updatePendingEvent called with status=SENT, but no new event id");if(t==b.SENT){if(this.getUnfilteredTimelineSet().eventIdToTimeline(r))return}var n=e.status,o=e.getId();if(!n)throw new Error("updatePendingEventStatus called on an event which is not a local echo.");var i=I[n];if(!i||i.indexOf(t)<0)throw new Error("Invalid EventStatus transition "+n+"->"+t);if(e.status=t,t==b.SENT){e.event.event_id=r
;for(var s=0;s<this._timelineSets.length;s++)this._timelineSets[s].replaceEventId(o,r)}else t==b.CANCELLED&&(this._pendingEventList&&k.removeElement(this._pendingEventList,function(e){return e.getId()==o},!1),this.removeEvent(o));this.emit("Room.localEchoUpdated",e,this,e.getId(),n)},i.prototype.addLiveEvents=function(e,t){var r=void 0;if(t&&-1===["replace","ignore"].indexOf(t))throw new Error("duplicateStrategy MUST be either 'replace' or 'ignore'");for(r=0;r<this._timelineSets.length;r++){var n=this._timelineSets[r].getLiveTimeline();if(n.getPaginationToken(x.FORWARDS))throw new Error("live timeline "+r+" is no longer live - it has a pagination token ("+n.getPaginationToken(x.FORWARDS)+")");if(n.getNeighbouringTimeline(x.FORWARDS))throw new Error("live timeline "+r+" is no longer live - it has a neighbouring timeline")}for(r=0;r<e.length;r++)"m.typing"===e[r].getType()?this.currentState.setTypingEvent(e[r]):"m.receipt"===e[r].getType()?this.addReceipt(e[r]):this._addLiveEvent(e[r],t)},i.prototype.removeEvents=function(e){for(var t=0;t<e.length;++t)this.removeEvent(e[t])},i.prototype.removeEvent=function(e){for(var t=!1,r=0;r<this._timelineSets.length;r++){this._timelineSets[r].removeEvent(e)&&(t=!0)}return t},i.prototype.recalculate=function(){var e=this,t=this.currentState.getStateEvents("m.room.member",this.myUserId);if(t&&"invite"===t.getContent().membership){var r=t.event.invite_room_state||[];k.forEach(r,function(t){e.currentState.getStateEvents(t.type,t.state_key)||e.currentState.setStateEvents([new S({type:t.type,state_key:t.state_key,content:t.content,event_id:"$fake"+Date.now(),room_id:e.roomId,user_id:e.myUserId})])})}var n=this.name;this.name=s(this,this.myUserId),this.summary=new E(this.roomId,{title:this.name}),n!==this.name&&this.emit("Room.name",this)},i.prototype.getUsersReadUpTo=function(e){return this.getReceiptsForEvent(e).filter(function(e){return"m.read"===e.type}).map(function(e){return e.userId})},i.prototype.getEventReadUpTo=function(e,t){var r=this._receipts;return t&&(r=this._realReceipts),void 0===r["m.read"]||void 0===r["m.read"][e]?null:r["m.read"][e].eventId},i.prototype.getReceiptsForEvent=function(e){return this._receiptCacheByEventId[e.getId()]||[]},i.prototype.addReceipt=function(e,t){void 0===t&&(t=!1),t||this._addReceiptsToStructure(e,this._realReceipts),this._addReceiptsToStructure(e,this._receipts),this._receiptCacheByEventId=this._buildReceiptCache(this._receipts),this.emit("Room.receipt",e,this)},i.prototype._addReceiptsToStructure=function(e,t){var r=this;k.keys(e.getContent()).forEach(function(n){k.keys(e.getContent()[n]).forEach(function(o){k.keys(e.getContent()[n][o]).forEach(function(i){var s=e.getContent()[n][o][i];t[o]||(t[o]={});var a=t[o][i];if(a){var u=r.getUnfilteredTimelineSet().compareEventOrdering(a.eventId,n);if(null!==u&&u>=0)return}else t[o][i]={};t[o][i]={eventId:n,data:s}})})})},i.prototype._buildReceiptCache=function(e){var t={};return k.keys(e).forEach(function(r){k.keys(e[r]).forEach(function(n){var o=e[r][n];t[o.eventId]||(t[o.eventId]=[]),t[o.eventId].push({userId:n,type:r,data:o.data})})}),t},i.prototype._addLocalEchoReceipt=function(e,t,r){this.addReceipt(o(e,t,r),!0)},i.prototype.addTags=function(e){this.tags=e.getContent().tags||{},this.emit("Room.tags",e,this)},i.prototype.addAccountData=function(e){for(var t=0;t<e.length;t++){var r=e[t];"m.tag"===r.getType()&&this.addTags(r),this.accountData[r.getType()]=r,this.emit("Room.accountData",r,this)}},i.prototype.getAccountData=function(e){return this.accountData[e]},i.prototype.maySendMessage=function(){return"join"===this.getMyMembership()&&this.currentState.maySendEvent("m.room.message",this.myUserId)},t.exports=i},{"../ReEmitter":2,"../content-repo":6,"../utils":55,"./event":34,"./event-timeline":33,"./event-timeline-set":32,"./room-member":36,"./room-summary":38,"babel-runtime/core-js/number/is-integer":62,"babel-runtime/core-js/object/assign":63,"babel-runtime/core-js/promise":72,"babel-runtime/regenerator":86,bluebird:89,events:234}],40:[function(e,t,r){"use strict";function n(e,t){this.rank=e,this.context=t}var o=e("./event-context"),i=e("../utils");n.fromJson=function(e,t){var r=e.context||{},s=r.events_before||[],a=r.events_after||[],u=new o(t(e.result));return u.setPaginateToken(r.start,!0),u.addEvents(i.map(s,t),!0),u.addEvents(i.map(a,t),!1),u.setPaginateToken(r.end,!1),new n(e.rank,u)},t.exports=n},{"../utils":55,"./event-context":31}],41:[function(e,t,r){"use strict";function n(e){this.userId=e,this.presence="offline",this.presenceStatusMsg=null,this.displayName=e,this.rawDisplayName=e,this.avatarUrl=null,this.lastActiveAgo=0,this.lastPresenceTs=0,this.currentlyActive=!1,this.events={presence:null,profile:null},this._updateModifiedTime()}var o=e("events").EventEmitter;e("../utils").inherits(n,o),n.prototype.setPresenceEvent=function(e){if("m.presence"===e.getType()){var t=null===this.events.presence;this.events.presence=e;var r=[];(e.getContent().presence!==this.presence||t)&&r.push("User.presence"),e.getContent().avatar_url&&e.getContent().avatar_url!==this.avatarUrl&&r.push("User.avatarUrl"),e.getContent().displayname&&e.getContent().displayname!==this.displayName&&r.push("User.displayName"),void 0!==e.getContent().currently_active&&e.getContent().currently_active!==this.currentlyActive&&r.push("User.currentlyActive"),this.presence=e.getContent().presence,r.push("User.lastPresenceTs"),e.getContent().status_msg&&(this.presenceStatusMsg=e.getContent().status_msg),e.getContent().displayname&&(this.displayName=e.getContent().displayname),e.getContent().avatar_url&&(this.avatarUrl=e.getContent().avatar_url),this.lastActiveAgo=e.getContent().last_active_ago,this.lastPresenceTs=Date.now(),this.currentlyActive=e.getContent().currently_active,this._updateModifiedTime();for(var n=0;n<r.length;n++)this.emit(r[n],e,this)}},n.prototype.setDisplayName=function(e){var t=this.displayName;this.displayName=e,e!==t&&this._updateModifiedTime()},n.prototype.setRawDisplayName=function(e){this.rawDisplayName=e},n.prototype.setAvatarUrl=function(e){var t=this.avatarUrl;this.avatarUrl=e,e!==t&&this._updateModifiedTime()},n.prototype._updateModifiedTime=function(){this._modified=Date.now()},n.prototype.getLastModifiedTime=function(){return this._modified},n.prototype.getLastActiveTs=function(){return this.lastPresenceTs-this.lastActiveAgo},t.exports=n},{"../utils":55,events:234}],42:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){var t=this,r={},n=function(e,r,n){for(var o=0;o<f.length;++o)for(var s=f[o],a=r[s],u=0;u<a.length;++u){var c=a[u];if(c.enabled){var l=i(s,c,n);if(l&&t.ruleMatchesEvent(l,e))return c.kind=s,c}}return null},i=function(e,t,r){var n={rule_id:t.rule_id,actions:t.actions,conditions:[]};switch(e){case"underride":case"override":n.conditions=t.conditions;break;case"room":if(!t.rule_id)return null;n.conditions.push({kind:"event_match",key:"room_id",value:t.rule_id});break;case"sender":if(!t.rule_id)return null;n.conditions.push({kind:"event_match",key:"user_id",value:t.rule_id});break;case"content":if(!t.pattern)return null;n.conditions.push({kind:"event_match",key:"content.body",pattern:t.pattern})}return r&&n.conditions.push({kind:"device",profile_tag:r}),n},s=function(e,t){var r={event_match:v,device:h,contains_display_name:p,room_member_count:c,sender_notification_permission:a};return!!r[e.kind]&&r[e.kind](e,t)},a=function(t,r){var n=t.key;if(!n)return!1;var o=e.getRoom(r.getRoomId());return!(!o||!o.currentState)&&o.currentState.mayTriggerNotifOfType(n,r.getSender())},c=function(t,r){if(!t.is)return!1;var n=e.getRoom(r.getRoomId());if(!n||!n.currentState||!n.currentState.members)return!1;var o=n.currentState.getJoinedMemberCount(),i=t.is.match(/^([=<>]*)([0-9]*)$/);if(!i)return!1;var s=i[1],a=parseInt(i[2]);if(isNaN(a))return!1;switch(s){case"":case"==":return o==a;case"<":return o<a;case">":return o>a;case"<=":return o<=a;case">=":return o>=a;default:return!1}},p=function(t,r){var n=r.getContent();if(!n||!n.body||"string"!=typeof n.body)return!1;var o=e.getRoom(r.getRoomId());if(!(o&&o.currentState&&o.currentState.members&&o.currentState.getMember(e.credentials.userId)))return!1;var i=o.currentState.getMember(e.credentials.userId).name,s=new RegExp("(^|\\W)"+(0,d.escapeRegExp)(i)+"(\\W|$)","i");return n.body.search(s)>-1},h=function(e,t){return!1},v=function(e,t){if(!e.key)return!1;var r=y(e.key,t);if(!r||"string"!=typeof r)return!1;if(e.value)return e.value===r;var n=void 0;return n="content.body"==e.key?m("(^|\\W)",e.pattern,"(\\W|$)"):m("^",e.pattern,"$"),!!r.match(n)},m=function(e,t,n){return r[t]?r[t]:(r[t]=new RegExp(e+(0,d.globToRegexp)(t)+n,"i"),r[t])},y=function(e,t){var r=e.split("."),n=void 0,o=r[0];for("content"==o?(n=t.getContent(),r.shift()):"type"==o?(n=t.getType(),r.shift()):n=t.event;r.length>0;){var i=r.shift();if(!n[i])return null;n=n[i]}return n},_=function(t,r){if(!r||!r.device)return null;if(t.getSender()==e.credentials.userId)return null;for(var o=(0,l.default)(r.device),i=0;i<o.length;++i){var s=o[i],a=r.device[s],u=n(a,s);if(u)return u}return n(t,r.global)},g=function(e,t){var r=_(e,t);if(!r)return{};var n=o.actionListToActionsObject(r.actions);return void 0===n.tweaks.highlight&&(n.tweaks.highlight="content"==r.kind),n};this.ruleMatchesEvent=function(e,t){for(var r=!0,n=0;n<e.conditions.length;++n){var o=e.conditions[n];r&=s(o,t)}return r},this.actionsForEvent=function(t){return g(t,e.pushRules)},this.getPushRuleById=function(t){for(var r=["device","global"],n=0;n<r.length;n++){var o=r[n];if(void 0!==e.pushRules[o]){var i=!0,s=!1,a=void 0;try{for(var c,l=(0,u.default)(f);!(i=(c=l.next()).done);i=!0){var d=c.value;if(void 0!==e.pushRules[o][d]){var p=!0,h=!1,v=void 0;try{for(var m,y=(0,u.default)(e.pushRules[o][d]);!(p=(m=y.next()).done);p=!0){var _=m.value;if(_.rule_id===t)return _}}catch(e){h=!0,v=e}finally{try{!p&&y.return&&y.return()}finally{if(h)throw v}}}}}catch(e){s=!0,a=e}finally{try{!i&&l.return&&l.return()}finally{if(s)throw a}}}}return null}}var i=e("babel-runtime/helpers/typeof"),s=n(i),a=e("babel-runtime/core-js/get-iterator"),u=n(a),c=e("babel-runtime/core-js/object/keys"),l=n(c),d=e("./utils"),f=["override","content","room","sender","underride"];o.actionListToActionsObject=function(e){for(var t={notify:!1,tweaks:{}},r=0;r<e.length;++r){var n=e[r];"notify"===n?t.notify=!0:"object"===(void 0===n?"undefined":(0,s.default)(n))&&(void 0===n.value&&(n.value=!0),t.tweaks[n.set_tweak]=n.value)}return t},t.exports=o},{"./utils":55,"babel-runtime/core-js/get-iterator":58,"babel-runtime/core-js/object/keys":69,"babel-runtime/helpers/typeof":85}],43:[function(e,t,r){"use strict";function n(e){for(var t="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=0;n<e;++n)t+=r.charAt(Math.floor(Math.random()*r.length));return t}Object.defineProperty(r,"__esModule",{value:!0}),r.randomString=n},{}],44:[function(e,t,r){(function(e){"use strict";function r(){a&&e.clearTimeout(a);var t=u[0];if(!t)return void c("_scheduleRealCallback: no more callbacks, not rescheduling");var r=l(),o=Math.min(t.runAt-r,i);c("_scheduleRealCallback: now:",r,"delay:",o),a=e.setTimeout(n,o)}function n(){var t=void 0,n=l();c("_runCallbacks: now:",n);for(var o=[];;){var i=u[0];if(!i||i.runAt>n)break;t=u.shift(),c("_runCallbacks: popping",t.key),o.push(t)}r();for(var s=0;s<o.length;s++){t=o[s];try{t.func.apply(e,t.params)}catch(e){console.error("Uncaught exception in callback function",e.stack||e)}}}function o(e,t){for(var r=0,n=e.length;r<n;){var o=r+n>>1;t(e[o])>0?n=o:r=o+1}return r}var i=1e3,s=0,a=void 0,u=[],c=function(){};t.exports.setNow=function(e){l=e||Date.now};var l=Date.now;t.exports.setTimeout=function(e,t){(t=t||0)<0&&(t=0);var n=Array.prototype.slice.call(arguments,2),i=l()+t,a=s++;c("setTimeout: scheduling cb",a,"at",i,"(delay",t,")");var d={runAt:i,func:e,params:n,key:a},f=o(u,function(e){return e.runAt-i});return u.splice(f,0,d),r(),a},t.exports.clearTimeout=function(e){if(0!==u.length){var t=void 0;for(t=0;t<u.length;t++){if(u[t].key==e){u.splice(t,1);break}}0===t&&r()}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],45:[function(e,t,r){"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 o(e){e._procFn&&d.forEach(d.filter(d.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),i(e,t)})}function i(e,t){var r=s(e,t);if(!r){var n=e._activeQueues.indexOf(t);return n>=0&&e._activeQueues.splice(n,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(r.event).done(function(n){a(e,t),u("Queue '%s' sent event %s",t,r.event.getId()),r.defer.resolve(n),i(e,t)},function(n){r.attempts+=1;var o=e.retryAlgorithm(r.event,r.attempts,n);u("retry(%s) err=%s event_id=%s waitTime=%s",r.attempts,n,r.event.getId(),o),-1===o?(u("Queue '%s' giving up on event %s",t,r.event.getId()),a(e,t),r.defer.reject(n),i(e,t)):setTimeout(function(){i(e,t)},o)})}function s(e,t){var r=e._queues[t];return d.isArray(r)?r[0]:null}function a(e,t){var r=e._queues[t];return d.isArray(r)?r.shift():null}function u(){if(f){var e;(e=console).log.apply(e,arguments)}}var c=e("bluebird"),l=function(e){return e&&e.__esModule?e:{default:e}}(c),d=e("./utils"),f=!1;n.prototype.getQueueForEvent=function(e){var t=this.queueAlgorithm(e);return t&&this._queues[t]?d.map(this._queues[t],function(e){return e.event}):null},n.prototype.removeEventFromQueue=function(e){var t=this.queueAlgorithm(e);if(!t||!this._queues[t])return!1;var r=!1;return d.removeElement(this._queues[t],function(t){if(t.event.getId()===e.getId())return r=!0,!0}),r},n.prototype.setProcessFunction=function(e){this._procFn=e,o(this)},n.prototype.queueEvent=function(e){var t=this.queueAlgorithm(e);if(!t)return null;this._queues[t]||(this._queues[t]=[]);var r=l.default.defer();return this._queues[t].push({event:e,defer:r,attempts:0}),u("Queue algorithm dumped event %s into queue '%s'",e.getId(),t),o(this),r.promise},n.RETRY_BACKOFF_RATELIMIT=function(e,t,r){if(400===r.httpStatus||403===r.httpStatus||401===r.httpStatus)return-1;if("rejected"===r.cors)return-1;if("M_LIMIT_EXCEEDED"===r.name){var n=r.data.retry_after_ms;if(n)return n}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":55,bluebird:89}],46:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){e.createObjectStore("users",{keyPath:["userId"]}),e.createObjectStore("accountData",{keyPath:["type"]}),e.createObjectStore("sync",{keyPath:["clobber"]})}function i(e){e.createObjectStore("oob_membership_events",{keyPath:["room_id","state_key"]}).createIndex("room","room_id")}function s(e){e.createObjectStore("client_options",{keyPath:["clobber"]})}function a(e,t,r){var n=e.openCursor(t);return new y.default(function(e,t){var o=[];n.onerror=function(e){t(new Error("Query failed: "+e.target.errorCode))},n.onsuccess=function(t){var n=t.target.result;if(!n)return void e(o);o.push(r(n)),n.continue()}})}function u(e){return new y.default(function(t,r){e.oncomplete=function(e){t(e)},e.onerror=function(e){r(e.target.error)}})}function c(e){return new y.default(function(t,r){e.onsuccess=function(e){t(e)},e.onerror=function(e){r(e.target.error)}})}function l(e){return new y.default(function(t,r){e.onsuccess=function(){return t(e)},e.onerror=function(e){return r(e)}})}function d(e){return c(e).then(function(e){return e.target.result})}Object.defineProperty(r,"__esModule",{value:!0});var f=e("babel-runtime/core-js/get-iterator"),p=n(f),h=e("babel-runtime/regenerator"),v=n(h),m=e("bluebird"),y=n(m),_=e("babel-runtime/helpers/slicedToArray"),g=n(_),b=e("../sync-accumulator"),E=n(b),w=e("../utils"),S=n(w),k=function(e,t){this.indexedDB=e,this._dbName="matrix-js-sdk:"+(t||"default"),this.db=null,this._disconnected=!0,this._syncAccumulator=new E.default,this._isNewlyCreated=!1};k.prototype={connect:function(){var e=this;if(!this._disconnected)return console.log("LocalIndexedDBStoreBackend.connect: already connected or connecting"),y.default.resolve();this._disconnected=!1,console.log("LocalIndexedDBStoreBackend.connect: connecting...");var t=this.indexedDB.open(this._dbName,3);return t.onupgradeneeded=function(t){var r=t.target.result,n=t.oldVersion;console.log("LocalIndexedDBStoreBackend.connect: upgrading from "+n),n<1&&(e._isNewlyCreated=!0,o(r)),n<2&&i(r),n<3&&s(r)},t.onblocked=function(){console.log("can't yet open LocalIndexedDBStoreBackend because it is open elsewhere")},console.log("LocalIndexedDBStoreBackend.connect: awaiting connection..."),c(t).then(function(t){return console.log("LocalIndexedDBStoreBackend.connect: connected"),e.db=t.target.result,e.db.onversionchange=function(){e.db.close()},e._init()})},isNewlyCreated:function(){return y.default.resolve(this._isNewlyCreated)},_init:function(){var e=this;return y.default.all([this._loadAccountData(),this._loadSyncData()]).then(function(t){var r=(0,g.default)(t,2),n=r[0],o=r[1];console.log("LocalIndexedDBStoreBackend: loaded initial data"),e._syncAccumulator.accumulate({next_batch:o.nextBatch,rooms:o.roomsData,groups:o.groupsData,account_data:{events:n}})})},getOutOfBandMembers:function(e){var t=this;return new y.default(function(r,n){var o=t.db.transaction(["oob_membership_events"],"readonly"),i=o.objectStore("oob_membership_events"),s=i.index("room"),a=IDBKeyRange.only(e),u=s.openCursor(a),c=[],l=!1;u.onsuccess=function(e){var t=e.target.result;if(!t)return r(c.length||l?c:null);var n=t.value;n.oob_written?l=!0:c.push(n),t.continue()},u.onerror=function(e){n(e)}}).then(function(t){return console.log("LL: got "+(t&&t.length)+" membershipEvents from storage for room "+e+" ..."),t})},setOutOfBandMembers:function(){function e(e,r){return t.apply(this,arguments)}var t=(0,m.coroutine)(v.default.mark(function e(t,r){var n,o,i;return v.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("LL: backend about to store "+r.length+" members for "+t),n=this.db.transaction(["oob_membership_events"],"readwrite"),o=n.objectStore("oob_membership_events"),r.forEach(function(e){o.put(e)}),i={room_id:t,oob_written:!0,state_key:0},o.put(i),e.next=8,(0,m.resolve)(u(n));case 8:console.log("LL: backend done storing for "+t+"!");case 9:case"end":return e.stop()}},e,this)}));return e}(),clearOutOfBandMembers:function(){function e(e){return t.apply(this,arguments)}var t=(0,m.coroutine)(v.default.mark(function e(t){var r,n,o,i,s,a,u,c,f,p,h,_,b;return v.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=this.db.transaction(["oob_membership_events"],"readonly"),n=r.objectStore("oob_membership_events"),o=n.index("room"),i=IDBKeyRange.only(t),s=d(o.openKeyCursor(i,"next")).then(function(e){return e&&e.primaryKey[1]}),a=d(o.openKeyCursor(i,"prev")).then(function(e){return e&&e.primaryKey[1]}),e.next=8,(0,m.resolve)(y.default.all([s,a]));case 8:return u=e.sent,c=(0,g.default)(u,2),f=c[0],p=c[1],h=this.db.transaction(["oob_membership_events"],"readwrite"),_=h.objectStore("oob_membership_events"),b=IDBKeyRange.bound([t,f],[t,p]),console.log("LL: Deleting all users + marker in storage for room "+t+", with key range:",[t,f],[t,p]),e.next=18,(0,m.resolve)(l(_.delete(b)));case 18:case"end":return e.stop()}},e,this)}));return e}(),clearDatabase:function(){var e=this;return new y.default(function(t,r){console.log("Removing indexeddb instance: "+e._dbName);var n=e.indexedDB.deleteDatabase(e._dbName);n.onblocked=function(){console.log("can't yet delete indexeddb "+e._dbName+" because it is open elsewhere")},n.onerror=function(e){console.warn("unable to delete js-sdk store indexeddb: "+e.target.error),t()},n.onsuccess=function(){console.log("Removed indexeddb instance: "+e._dbName),t()}})},getSavedSync:function(e){void 0===e&&(e=!0);var t=this._syncAccumulator.getJSON();return t.nextBatch?e?y.default.resolve(S.default.deepCopy(t)):y.default.resolve(t):y.default.resolve(null)},getNextBatchToken:function(){return y.default.resolve(this._syncAccumulator.getNextBatchToken())},setSyncData:function(e){var t=this;return y.default.resolve().then(function(){t._syncAccumulator.accumulate(e)})},syncToDatabase:function(e){var t=this._syncAccumulator.getJSON();return y.default.all([this._persistUserPresenceEvents(e),this._persistAccountData(t.accountData),this._persistSyncData(t.nextBatch,t.roomsData,t.groupsData)])},_persistSyncData:function(e,t,r){var n=this;return console.log("Persisting sync data up to ",e),y.default.try(function(){var o=n.db.transaction(["sync"],"readwrite");return o.objectStore("sync").put({clobber:"-",nextBatch:e,roomsData:t,groupsData:r}),u(o)})},_persistAccountData:function(e){var t=this;return y.default.try(function(){for(var r=t.db.transaction(["accountData"],"readwrite"),n=r.objectStore("accountData"),o=0;o<e.length;o++)n.put(e[o]);return u(r)})},_persistUserPresenceEvents:function(e){var t=this;return y.default.try(function(){var r=t.db.transaction(["users"],"readwrite"),n=r.objectStore("users"),o=!0,i=!1,s=void 0;try{for(var a,c=(0,p.default)(e);!(o=(a=c.next()).done);o=!0){var l=a.value;n.put({userId:l[0],event:l[1]})}}catch(e){i=!0,s=e}finally{try{!o&&c.return&&c.return()}finally{if(i)throw s}}return u(r)})},getUserPresenceEvents:function(){var e=this;return y.default.try(function(){return a(e.db.transaction(["users"],"readonly").objectStore("users"),void 0,function(e){return[e.value.userId,e.value.event]})})},_loadAccountData:function(){var e=this;return console.log("LocalIndexedDBStoreBackend: loading account data..."),y.default.try(function(){return a(e.db.transaction(["accountData"],"readonly").objectStore("accountData"),void 0,function(e){return e.value}).then(function(e){return console.log("LocalIndexedDBStoreBackend: loaded account data"),e})})},_loadSyncData:function(){var e=this;return console.log("LocalIndexedDBStoreBackend: loading sync data..."),y.default.try(function(){return a(e.db.transaction(["sync"],"readonly").objectStore("sync"),void 0,function(e){return e.value}).then(function(e){return console.log("LocalIndexedDBStoreBackend: loaded sync data"),e.length>1&&console.warn("loadSyncData: More than 1 sync row found."),e.length>0?e[0]:{}})})},getClientOptions:function(){var e=this;return y.default.resolve().then(function(){return a(e.db.transaction(["client_options"],"readonly").objectStore("client_options"),void 0,function(e){if(e.value&&e.value&&e.value.options)return e.value.options}).then(function(e){return e[0]})})},storeClientOptions:function(){function e(e){return t.apply(this,arguments)}var t=(0,m.coroutine)(v.default.mark(function e(t){var r,n;return v.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=this.db.transaction(["client_options"],"readwrite"),n=r.objectStore("client_options"),n.put({clobber:"-",options:t}),e.next=5,(0,m.resolve)(u(r));case 5:case"end":return e.stop()}},e,this)}));return e}()},r.default=k},{"../sync-accumulator":52,"../utils":55,"babel-runtime/core-js/get-iterator":58,"babel-runtime/helpers/slicedToArray":84,"babel-runtime/regenerator":86,bluebird:89}],47:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e("bluebird"),o=function(e){return e&&e.__esModule?e:{default:e}}(n),i=function(e,t,r){this._workerScript=e,this._dbName=t,this._workerApi=r,this._worker=null,this._nextSeq=0,this._inFlight={},this._startPromise=null};i.prototype={connect:function(){var e=this;return this._ensureStarted().then(function(){return e._doCmd("connect")})},clearDatabase:function(){var e=this;return this._ensureStarted().then(function(){return e._doCmd("clearDatabase")})},isNewlyCreated:function(){return this._doCmd("isNewlyCreated")},getSavedSync:function(){return this._doCmd("getSavedSync")},getNextBatchToken:function(){return this._doCmd("getNextBatchToken")},setSyncData:function(e){return this._doCmd("setSyncData",[e])},syncToDatabase:function(e){return this._doCmd("syncToDatabase",[e])},getOutOfBandMembers:function(e){return this._doCmd("getOutOfBandMembers",[e])},setOutOfBandMembers:function(e,t){return this._doCmd("setOutOfBandMembers",[e,t])},clearOutOfBandMembers:function(e){return this._doCmd("clearOutOfBandMembers",[e])},getClientOptions:function(){return this._doCmd("getClientOptions")},storeClientOptions:function(e){return this._doCmd("storeClientOptions",[e])},getUserPresenceEvents:function(){return this._doCmd("getUserPresenceEvents")},_ensureStarted:function(){return null===this._startPromise&&(this._worker=new this._workerApi(this._workerScript),this._worker.onmessage=this._onWorkerMessage.bind(this),this._startPromise=this._doCmd("_setupWorker",[this._dbName]).then(function(){console.log("IndexedDB worker is ready")})),this._startPromise},_doCmd:function(e,t){var r=this;return o.default.resolve().then(function(){var n=r._nextSeq++,i=o.default.defer();return r._inFlight[n]=i,r._worker.postMessage({command:e,seq:n,args:t}),i.promise})},_onWorkerMessage:function(e){var t=e.data;if("cmd_success"==t.command||"cmd_fail"==t.command){if(void 0===t.seq)return void console.error("Got reply from worker with no seq");var r=this._inFlight[t.seq];if(void 0===r)return void console.error("Got reply for unknown seq "+t.seq);if(delete this._inFlight[t.seq],"cmd_success"==t.command)r.resolve(t.result);else{var n=new Error(t.error.message);n.name=t.error.name,r.reject(n)}}else console.warn("Unrecognised message from worker: "+t)}},r.default=i},{bluebird:89}],48:[function(e,t,r){(function(r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}var o=e("babel-runtime/core-js/get-iterator"),i=n(o),s=e("babel-runtime/helpers/slicedToArray"),a=n(s),u=e("bluebird"),c=n(u),l=e("./memory"),d=e("../utils"),f=n(d),p=e("./indexeddb-local-backend.js"),h=n(p),v=e("./indexeddb-remote-backend.js"),m=n(v),y=e("../models/user"),_=n(y),g=e("../models/event"),b=function(e){if(l.MatrixInMemoryStore.call(this,e),!e.indexedDB)throw new Error("Missing required option: indexedDB");if(e.workerScript){var t=e.workerApi;t||(t=r.Worker),this.backend=new m.default(e.workerScript,e.dbName,t)}else this.backend=new h.default(e.indexedDB,e.dbName);this.startedUp=!1,this._syncTs=0,this._userModifiedMap={}};f.default.inherits(b,l.MatrixInMemoryStore),b.prototype.startup=function(){var e=this;return this.startedUp?(console.log("IndexedDBStore.startup: already started"),c.default.resolve()):(console.log("IndexedDBStore.startup: connecting to backend"),this.backend.connect().then(function(){return console.log("IndexedDBStore.startup: loading presence events"),e.backend.getUserPresenceEvents()}).then(function(t){console.log("IndexedDBStore.startup: processing presence events"),t.forEach(function(t){var r=(0,a.default)(t,2),n=r[0],o=r[1],i=new _.default(n);o&&i.setPresenceEvent(new g.MatrixEvent(o)),e._userModifiedMap[i.userId]=i.getLastModifiedTime(),e.storeUser(i)})}))},b.prototype.getSavedSync=function(){return this.backend.getSavedSync()},b.prototype.isNewlyCreated=function(){return this.backend.isNewlyCreated()},b.prototype.getSavedSyncToken=function(){return this.backend.getNextBatchToken()},b.prototype.deleteAllData=function(){return l.MatrixInMemoryStore.prototype.deleteAllData.call(this),this.backend.clearDatabase().then(function(){console.log("Deleted indexeddb data.")},function(e){throw console.error("Failed to delete indexeddb data: "+e),e})},b.prototype.wantsSave=function(){return Date.now()-this._syncTs>3e5},b.prototype.save=function(){return this.wantsSave()?this._reallySave():c.default.resolve()},b.prototype._reallySave=function(){this._syncTs=Date.now();var e=[],t=!0,r=!1,n=void 0;try{for(var o,s=(0,i.default)(this.getUsers());!(t=(o=s.next()).done);t=!0){var a=o.value;this._userModifiedMap[a.userId]!==a.getLastModifiedTime()&&(a.events.presence&&(e.push([a.userId,a.events.presence.event]),this._userModifiedMap[a.userId]=a.getLastModifiedTime()))}}catch(e){r=!0,n=e}finally{try{!t&&s.return&&s.return()}finally{if(r)throw n}}return this.backend.syncToDatabase(e).catch(function(e){console.error("sync fail:",e)})},b.prototype.setSyncData=function(e){return this.backend.setSyncData(e)},b.prototype.getOutOfBandMembers=function(e){return this.backend.getOutOfBandMembers(e)},b.prototype.setOutOfBandMembers=function(e,t){return this.backend.setOutOfBandMembers(e,t)},b.prototype.clearOutOfBandMembers=function(e){return this.backend.clearOutOfBandMembers(e)},b.prototype.getClientOptions=function(){return this.backend.getClientOptions()},b.prototype.storeClientOptions=function(e){return this.backend.storeClientOptions(e)},t.exports.IndexedDBStore=b}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../models/event":34,"../models/user":41,"../utils":55,"./indexeddb-local-backend.js":46,"./indexeddb-remote-backend.js":47,"./memory":49,"babel-runtime/core-js/get-iterator":58,"babel-runtime/helpers/slicedToArray":84,bluebird:89}],49:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}var o=e("babel-runtime/core-js/object/assign"),i=n(o),s=e("bluebird"),a=n(s),u=e("../utils"),c=e("../models/user");t.exports.MatrixInMemoryStore=function(e){e=e||{},this.rooms={},this.groups={},this.users={},this.syncToken=null,this.filters={},this.accountData={},this.localStorage=e.localStorage,this._oobMembers={},this._clientOptions={}},t.exports.MatrixInMemoryStore.prototype={getSyncToken:function(){return this.syncToken},isNewlyCreated:function(){return a.default.resolve(!0)},setSyncToken:function(e){this.syncToken=e},storeGroup:function(e){this.groups[e.groupId]=e},getGroup:function(e){return this.groups[e]||null},getGroups:function(){return u.values(this.groups)},storeRoom:function(e){this.rooms[e.roomId]=e,e.currentState.on("RoomState.members",this._onRoomMember.bind(this));var t=this;e.currentState.getMembers().forEach(function(r){t._onRoomMember(null,e.currentState,r)})},_onRoomMember:function(e,t,r){if("invite"!==r.membership){var n=this.users[r.userId]||new c(r.userId);r.name&&(n.setDisplayName(r.name),r.events.member&&n.setRawDisplayName(r.events.member.getDirectionalContent().displayname)),r.events.member&&r.events.member.getContent().avatar_url&&n.setAvatarUrl(r.events.member.getContent().avatar_url),this.users[n.userId]=n}},getRoom:function(e){return this.rooms[e]||null},getRooms:function(){return u.values(this.rooms)},removeRoom:function(e){this.rooms[e]&&this.rooms[e].removeListener("RoomState.members",this._onRoomMember),delete this.rooms[e]},getRoomSummaries:function(){return u.map(u.values(this.rooms),function(e){return e.summary})},storeUser:function(e){this.users[e.userId]=e},getUser:function(e){return this.users[e]||null},getUsers:function(){return u.values(this.users)},scrollback:function(e,t){return[]},storeEvents:function(e,t,r,n){},storeFilter:function(e){e&&(this.filters[e.userId]||(this.filters[e.userId]={}),this.filters[e.userId][e.filterId]=e)},getFilter:function(e,t){return this.filters[e]&&this.filters[e][t]?this.filters[e][t]:null},getFilterIdByName:function(e){if(!this.localStorage)return null;try{return this.localStorage.getItem("mxjssdk_memory_filter_"+e)}catch(e){}return null},setFilterIdByName:function(e,t){if(this.localStorage)try{this.localStorage.setItem("mxjssdk_memory_filter_"+e,t)}catch(e){}},storeAccountDataEvents:function(e){var t=this;e.forEach(function(e){t.accountData[e.getType()]=e})},getAccountData:function(e){return this.accountData[e]},setSyncData:function(e){return a.default.resolve()},wantsSave:function(){return!1},save:function(){},startup:function(){return a.default.resolve()},getSavedSync:function(){return a.default.resolve(null)},getSavedSyncToken:function(){
return a.default.resolve(null)},deleteAllData:function(){return this.rooms={},this.users={},this.syncToken=null,this.filters={},this.accountData={},a.default.resolve()},getOutOfBandMembers:function(e){return a.default.resolve(this._oobMembers[e]||null)},setOutOfBandMembers:function(e,t){return this._oobMembers[e]=t,a.default.resolve()},getClientOptions:function(){return a.default.resolve(this._clientOptions)},storeClientOptions:function(e){return this._clientOptions=(0,i.default)({},e),a.default.resolve()}}},{"../models/user":41,"../utils":55,"babel-runtime/core-js/object/assign":63,bluebird:89}],50:[function(e,t,r){"use strict";function n(e){if(this.store=e,!(h.isFunction(e.getItem)&&h.isFunction(e.setItem)&&h.isFunction(e.removeItem)&&h.isFunction(e.key)&&"number"==typeof e.length))throw new Error("Supplied webStore does not meet the WebStorage API interface")}function o(e){return m+"devices/"+e}function i(e){return m+"sessions/"+e}function s(e,t){return m+"inboundgroupsessions/"+e+"/"+t}function a(e){return m+"rooms/"+e}function u(e,t){try{return JSON.parse(e.getItem(t))}catch(e){d("Failed to get key %s: %s",t,e),d(e.stack)}return null}function c(e,t){for(var r=[],n=0;n<e.length;++n){var o=e.key(n);o.startsWith(t)&&r.push(o)}return r}function l(e,t){for(var r=[],n=0;n<e.length;++n){var o=e.key(n);o.startsWith(t)&&r.push(o)}var i=!0,s=!1,a=void 0;try{for(var u,c=(0,p.default)(r);!(i=(u=c.next()).done);i=!0){var l=u.value;e.removeItem(l)}}catch(e){s=!0,a=e}finally{try{!i&&c.return&&c.return()}finally{if(s)throw a}}}function d(){if(v){var e;(e=console).log.apply(e,arguments)}}var f=e("babel-runtime/core-js/get-iterator"),p=function(e){return e&&e.__esModule?e:{default:e}}(f),h=e("../../utils"),v=!1,m="session.e2e.";n.prototype={removeEndToEndAccount:function(){this.store.removeItem(y)},getEndToEndAccount:function(){return this.store.getItem(y)},getAllEndToEndDevices:function(){for(var e=o(""),t={},r=0;r<this.store.length;++r){var n=this.store.key(r),i=n.substr(e.length);n.startsWith(e)&&(t[i]=u(this.store,n))}return t},getEndToEndDeviceTrackingStatus:function(){return u(this.store,g)},getEndToEndDeviceSyncToken:function(){return u(this.store,_)},removeEndToEndDeviceData:function(){l(this.store,o("")),l(this.store,g),l(this.store,_)},getEndToEndSessions:function(e){return u(this.store,i(e))},getAllEndToEndSessions:function(){var e=c(this.store,i("")),t={},r=!0,n=!1,o=void 0;try{for(var s,a=(0,p.default)(e);!(r=(s=a.next()).done);r=!0){var l=s.value;t[l.substr(i("").length)]=u(this.store,l)}}catch(e){n=!0,o=e}finally{try{!r&&a.return&&a.return()}finally{if(n)throw o}}return t},removeAllEndToEndSessions:function(){l(this.store,i(""))},getAllEndToEndInboundGroupSessionKeys:function(){for(var e=m+"inboundgroupsessions/",t=[],r=0;r<this.store.length;r++){var n=this.store.key(r);n.startsWith(e)&&t.push({senderKey:n.substr(e.length,43),sessionId:n.substr(e.length+44)})}return t},getEndToEndInboundGroupSession:function(e,t){var r=s(e,t);return this.store.getItem(r)},removeAllEndToEndInboundGroupSessions:function(){l(this.store,m+"inboundgroupsessions/")},getAllEndToEndRooms:function(){var e=c(this.store,a("")),t={},r=!0,n=!1,o=void 0;try{for(var i,s=(0,p.default)(e);!(r=(i=s.next()).done);r=!0){var l=i.value;t[l.substr(a("").length)]=u(this.store,l)}}catch(e){n=!0,o=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw o}}return t},removeAllEndToEndRooms:function(){l(this.store,a(""))}};var y=m+"account",_=m+"device_sync_token",g=m+"device_tracking";t.exports=n},{"../../utils":55,"babel-runtime/core-js/get-iterator":58}],51:[function(e,t,r){"use strict";function n(){this.fromToken=null}var o=e("bluebird"),i=function(e){return e&&e.__esModule?e:{default:e}}(o);n.prototype={isNewlyCreated:function(){return i.default.resolve(!0)},getSyncToken:function(){return this.fromToken},setSyncToken:function(e){this.fromToken=e},storeGroup:function(e){},getGroup:function(e){return null},getGroups:function(){return[]},storeRoom:function(e){},getRoom:function(e){return null},getRooms:function(){return[]},removeRoom:function(e){},getRoomSummaries:function(){return[]},storeUser:function(e){},getUser:function(e){return null},getUsers:function(){return[]},scrollback:function(e,t){return[]},storeEvents:function(e,t,r,n){},storeFilter:function(e){},getFilter:function(e,t){return null},getFilterIdByName:function(e){return null},setFilterIdByName:function(e,t){},storeAccountDataEvents:function(e){},getAccountData:function(e){},setSyncData:function(e){return i.default.resolve()},wantsSave:function(){return!1},save:function(){},startup:function(){return i.default.resolve()},getSavedSync:function(){return i.default.resolve(null)},getSavedSyncToken:function(){return i.default.resolve(null)},deleteAllData:function(){return i.default.resolve()},getOutOfBandMembers:function(){return i.default.resolve(null)},setOutOfBandMembers:function(){return i.default.resolve()},clearOutOfBandMembers:function(){return i.default.resolve()},getClientOptions:function(){return i.default.resolve()},storeClientOptions:function(){return i.default.resolve()}},t.exports=n},{bluebird:89}],52:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t){null!==t.state_key&&void 0!==t.state_key&&t.type&&(e[t.type]||(e[t.type]=(0,s.default)(null)),e[t.type][t.state_key]=t)}var i=e("babel-runtime/core-js/object/create"),s=n(i),a=e("babel-runtime/core-js/object/keys"),u=n(a),c=e("babel-runtime/helpers/classCallCheck"),l=n(c),d=e("babel-runtime/helpers/createClass"),f=n(d),p=e("./utils"),h=n(p),v=function(){function e(t){(0,l.default)(this,e),t=t||{},t.maxTimelineEntries=t.maxTimelineEntries||50,this.opts=t,this.accountData={},this.inviteRooms={},this.joinRooms={},this.nextBatch=null,this.groups={invite:{},join:{},leave:{}}}return(0,f.default)(e,[{key:"accumulate",value:function(e){this._accumulateRooms(e),this._accumulateGroups(e),this._accumulateAccountData(e),this.nextBatch=e.next_batch}},{key:"_accumulateAccountData",value:function(e){var t=this;e.account_data&&e.account_data.events&&e.account_data.events.forEach(function(e){t.accountData[e.type]=e})}},{key:"_accumulateRooms",value:function(e){var t=this;e.rooms&&(e.rooms.invite&&(0,u.default)(e.rooms.invite).forEach(function(r){t._accumulateRoom(r,"invite",e.rooms.invite[r])}),e.rooms.join&&(0,u.default)(e.rooms.join).forEach(function(r){t._accumulateRoom(r,"join",e.rooms.join[r])}),e.rooms.leave&&(0,u.default)(e.rooms.leave).forEach(function(r){t._accumulateRoom(r,"leave",e.rooms.leave[r])}))}},{key:"_accumulateRoom",value:function(e,t,r){switch(t){case"invite":this._accumulateInviteState(e,r);break;case"join":this.inviteRooms[e]&&delete this.inviteRooms[e],this._accumulateJoinState(e,r);break;case"leave":this.inviteRooms[e]?delete this.inviteRooms[e]:delete this.joinRooms[e];break;default:console.error("Unknown cateogory: ",t)}}},{key:"_accumulateInviteState",value:function(e,t){if(t.invite_state&&t.invite_state.events){if(!this.inviteRooms[e])return void(this.inviteRooms[e]={invite_state:t.invite_state});var r=this.inviteRooms[e];t.invite_state.events.forEach(function(e){for(var t=!1,n=0;n<r.invite_state.events.length;n++){var o=r.invite_state.events[n];o.type===e.type&&o.state_key==e.state_key&&(r.invite_state.events[n]=e,t=!0)}t||r.invite_state.events.push(e)})}}},{key:"_accumulateJoinState",value:function(e,t){this.joinRooms[e]||(this.joinRooms[e]={_currentState:(0,s.default)(null),_timeline:[],_accountData:(0,s.default)(null),_unreadNotifications:{},_summary:{},_readReceipts:{}});var r=this.joinRooms[e];if(t.account_data&&t.account_data.events&&t.account_data.events.forEach(function(e){r._accountData[e.type]=e}),t.unread_notifications&&(r._unreadNotifications=t.unread_notifications),t.summary){var n=r._summary,i=t.summary;n["m.heroes"]=i["m.heroes"]||n["m.heroes"],n["m.joined_member_count"]=i["m.joined_member_count"]||n["m.joined_member_count"],n["m.invited_member_count"]=i["m.invited_member_count"]||n["m.invited_member_count"]}if(t.ephemeral&&t.ephemeral.events&&t.ephemeral.events.forEach(function(e){"m.receipt"===e.type&&e.content&&(0,u.default)(e.content).forEach(function(t){e.content[t]["m.read"]&&(0,u.default)(e.content[t]["m.read"]).forEach(function(n){r._readReceipts[n]={data:e.content[t]["m.read"][n],eventId:t}})})}),t.timeline&&t.timeline.limited&&(r._timeline=[]),t.state&&t.state.events&&t.state.events.forEach(function(e){o(r._currentState,e)}),t.timeline&&t.timeline.events&&t.timeline.events.forEach(function(e,n){o(r._currentState,e),r._timeline.push({event:e,token:0===n?t.timeline.prev_batch:null})}),r._timeline.length>this.opts.maxTimelineEntries)for(var a=r._timeline.length-this.opts.maxTimelineEntries,c=a;c<r._timeline.length;c++)if(r._timeline[c].token){r._timeline=r._timeline.slice(c,r._timeline.length);break}}},{key:"_accumulateGroups",value:function(e){var t=this;e.groups&&(e.groups.invite&&(0,u.default)(e.groups.invite).forEach(function(r){t._accumulateGroup(r,"invite",e.groups.invite[r])}),e.groups.join&&(0,u.default)(e.groups.join).forEach(function(r){t._accumulateGroup(r,"join",e.groups.join[r])}),e.groups.leave&&(0,u.default)(e.groups.leave).forEach(function(r){t._accumulateGroup(r,"leave",e.groups.leave[r])}))}},{key:"_accumulateGroup",value:function(e,t,r){for(var n=["invite","join","leave"],o=0;o<n.length;o++){var i=n[o];delete this.groups[i][e]}this.groups[t][e]=r}},{key:"getJSON",value:function(){var e=this,t={join:{},invite:{},leave:{}};(0,u.default)(this.inviteRooms).forEach(function(r){t.invite[r]=e.inviteRooms[r]}),(0,u.default)(this.joinRooms).forEach(function(r){var n=e.joinRooms[r],i={ephemeral:{events:[]},account_data:{events:[]},state:{events:[]},timeline:{events:[],prev_batch:null},unread_notifications:n._unreadNotifications,summary:n._summary};(0,u.default)(n._accountData).forEach(function(e){i.account_data.events.push(n._accountData[e])});var a={type:"m.receipt",room_id:r,content:{}};(0,u.default)(n._readReceipts).forEach(function(e){var t=n._readReceipts[e];a.content[t.eventId]||(a.content[t.eventId]={"m.read":{}}),a.content[t.eventId]["m.read"][e]=t.data}),(0,u.default)(a.content).length>0&&i.ephemeral.events.push(a),n._timeline.forEach(function(e){if(!i.timeline.prev_batch){if(!e.token)return;i.timeline.prev_batch=e.token}i.timeline.events.push(e.event)});for(var c=(0,s.default)(null),l=i.timeline.events.length-1;l>=0;l--){var d=i.timeline.events[l];if(null!==d.state_key&&void 0!==d.state_key){var f=h.default.deepCopy(d);f.unsigned&&(f.unsigned.prev_content&&(f.content=f.unsigned.prev_content),f.unsigned.prev_sender&&(f.sender=f.unsigned.prev_sender)),o(c,f)}}(0,u.default)(n._currentState).forEach(function(e){(0,u.default)(n._currentState[e]).forEach(function(t){var r=n._currentState[e][t];c[e]&&c[e][t]&&(r=c[e][t]),i.state.events.push(r)})}),t.join[r]=i});var r=[];return(0,u.default)(this.accountData).forEach(function(t){r.push(e.accountData[t])}),{nextBatch:this.nextBatch,roomsData:t,groupsData:this.groups,accountData:r}}},{key:"getNextBatchToken",value:function(){return this.nextBatch}}]),e}();t.exports=v},{"./utils":55,"babel-runtime/core-js/object/create":64,"babel-runtime/core-js/object/keys":69,"babel-runtime/helpers/classCallCheck":79,"babel-runtime/helpers/createClass":80}],53:[function(e,t,r){(function(r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t){return"FILTER_SYNC_"+e+(t?"_"+t:"")}function i(){var e;T&&(e=console).log.apply(e,arguments)}function s(e,t){this.client=e,t=t||{},t.initialSyncLimit=void 0===t.initialSyncLimit?8:t.initialSyncLimit,t.resolveInvitesToProfiles=t.resolveInvitesToProfiles||!1,t.pollTimeout=t.pollTimeout||3e4,t.pendingEventOrdering=t.pendingEventOrdering||"chronological",t.canResetEntireTimeline||(t.canResetEntireTimeline=function(e){return!1}),this.opts=t,this._peekRoomId=null,this._currentSyncRequest=null,this._syncState=null,this._syncStateData=null,this._catchingUp=!1,this._running=!1,this._keepAliveTimer=null,this._connectionReturnedDefer=null,this._notifEvents=[],this._failedSyncCount=0,this._storeIsInvalid=!1,e.getNotifTimelineSet()&&e.reEmitter.reEmit(e.getNotifTimelineSet(),["Room.timeline","Room.timelineReset"])}function a(e,t){var r=new g(t);return e.reEmitter.reEmit(r,["User.avatarUrl","User.displayName","User.presence","User.currentlyActive","User.lastPresenceTs"]),r}var u=e("babel-runtime/core-js/json/stringify"),c=n(u),l=e("babel-runtime/core-js/object/keys"),d=n(l),f=e("babel-runtime/core-js/get-iterator"),p=n(f),h=e("babel-runtime/regenerator"),v=n(h),m=e("bluebird"),y=n(m),_=e("./errors"),g=e("./models/user"),b=e("./models/room"),E=e("./models/group"),w=e("./utils"),S=e("./filter"),k=e("./models/event-timeline"),T=!0;s.prototype.createRoom=function(e){var t=this.client,r=new b(e,t,t.getUserId(),{lazyLoadMembers:this.opts.lazyLoadMembers,pendingEventOrdering:this.opts.pendingEventOrdering,timelineSupport:t.timelineSupport});return t.reEmitter.reEmit(r,["Room.name","Room.timeline","Room.redaction","Room.receipt","Room.tags","Room.timelineReset","Room.localEchoUpdated","Room.accountData","Room.myMembership"]),this._registerStateListeners(r),r},s.prototype.createGroup=function(e){var t=this.client,r=new E(e);return t.reEmitter.reEmit(r,["Group.profile","Group.myMembership"]),t.store.storeGroup(r),r},s.prototype._registerStateListeners=function(e){var t=this.client;t.reEmitter.reEmit(e.currentState,["RoomState.events","RoomState.members","RoomState.newMember"]),e.currentState.on("RoomState.newMember",function(e,r,n){n.user=t.getUser(n.userId),t.reEmitter.reEmit(n,["RoomMember.name","RoomMember.typing","RoomMember.powerLevel","RoomMember.membership"])})},s.prototype._deregisterStateListeners=function(e){e.currentState.removeAllListeners("RoomState.events"),e.currentState.removeAllListeners("RoomState.members"),e.currentState.removeAllListeners("RoomState.newMember")},s.prototype.syncLeftRooms=function(){var e=this.client,t=this,r=new S(this.client.credentials.userId);r.setTimelineLimit(1),r.setIncludeLeaveRooms(!0);var n=this.opts.pollTimeout+8e4,i={timeout:0};return e.getOrCreateFilter(o(e.credentials.userId,"LEFT_ROOMS"),r).then(function(t){return i.filter=t,e._http.authedRequest(void 0,"GET","/sync",i,void 0,n)}).then(function(r){var n=[];r.rooms&&r.rooms.leave&&(n=t._mapSyncResponseToRoomArray(r.rooms.leave));var o=[];return n.forEach(function(r){var n=r.room;if(o.push(n),r.isBrandNewRoom){r.timeline=r.timeline||{};var i=t._mapSyncEventsFormat(r.timeline,n),s=t._mapSyncEventsFormat(r.state,n);n.getLiveTimeline().setPaginationToken(r.timeline.prev_batch,k.BACKWARDS),t._processRoomEvents(n,s,i),n.recalculate(),e.store.storeRoom(n),e.emit("Room",n),t._processEventsForNotifs(n,i)}}),o})},s.prototype.peek=function(e){var t=this,r=this.client;return this._peekRoomId=e,this.client.roomInitialSync(e,20).then(function(n){n.messages=n.messages||{},n.messages.chunk=n.messages.chunk||[],n.state=n.state||[];var o=t.createRoom(e),i=w.map(w.deepCopy(n.state),r.getEventMapper()),s=w.map(n.state,r.getEventMapper()),u=w.map(n.messages.chunk,r.getEventMapper());return n.presence&&w.isArray(n.presence)&&n.presence.map(r.getEventMapper()).forEach(function(e){var t=r.store.getUser(e.getContent().user_id);t?t.setPresenceEvent(e):(t=a(r,e.getContent().user_id),t.setPresenceEvent(e),r.store.storeUser(t)),r.emit("event",e)}),n.messages.start&&(o.oldState.paginationToken=n.messages.start),o.oldState.setStateEvents(i),o.currentState.setStateEvents(s),t._resolveInvites(o),o.recalculate(),o.addEventsToTimeline(u.reverse(),!0,o.getLiveTimeline(),n.messages.start),r.store.storeRoom(o),r.emit("Room",o),t._peekPoll(o),o})},s.prototype.stopPeeking=function(){this._peekRoomId=null},s.prototype._peekPoll=function(e,t){if(this._peekRoomId!==e.roomId)return void i("Stopped peeking in room %s",e.roomId);var r=this;this.client._http.authedRequest(void 0,"GET","/events",{room_id:e.roomId,timeout:3e4,from:t},void 0,5e4).done(function(t){if(r._peekRoomId!==e.roomId)return void i("Stopped peeking in room %s",e.roomId);t.chunk.filter(function(e){return"m.presence"===e.type}).map(r.client.getEventMapper()).forEach(function(e){var t=r.client.store.getUser(e.getContent().user_id);t?t.setPresenceEvent(e):(t=a(r.client,e.getContent().user_id),t.setPresenceEvent(e),r.client.store.storeUser(t)),r.client.emit("event",e)});var n=t.chunk.filter(function(t){return t.room_id===e.roomId}).map(r.client.getEventMapper());e.addLiveEvents(n),r._peekPoll(e,t.end)},function(n){console.error("[%s] Peek poll failed: %s",e.roomId,n),setTimeout(function(){r._peekPoll(e,t)},3e4)})},s.prototype.getSyncState=function(){return this._syncState},s.prototype.getSyncStateData=function(){return this._syncStateData},s.prototype.recoverFromSyncStartupError=function(){var e=(0,m.coroutine)(v.default.mark(function e(t,r){var n;return v.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,m.resolve)(t);case 2:return n=this._startKeepAlives(),this._updateSyncState("ERROR",{error:r}),e.next=6,(0,m.resolve)(n);case 6:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}(),s.prototype._wasLazyLoadingToggled=function(){var e=(0,m.coroutine)(v.default.mark(function e(t){var r,n,o;return v.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=!!t,r=!1,e.next=4,(0,m.resolve)(this.client.store.isNewlyCreated());case 4:if(n=e.sent){e.next=11;break}return e.next=8,(0,m.resolve)(this.client.store.getClientOptions());case 8:return o=e.sent,o&&(r=!!o.lazyLoadMembers),e.abrupt("return",r!==t);case 11:return e.abrupt("return",!1);case 12:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),s.prototype.sync=function(){var e=this,t=function(){var e=(0,m.coroutine)(v.default.mark(function e(){var r;return v.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,(0,m.resolve)(s.getPushRules());case 3:r=e.sent,i("Got push rules"),s.pushRules=r,e.next=14;break;case 8:return e.prev=8,e.t0=e.catch(0),e.next=12,(0,m.resolve)(a.recoverFromSyncStartupError(u,e.t0));case 12:return t(),e.abrupt("return");case 14:l();case 15:case"end":return e.stop()}},e,this,[[0,8]])}));return function(){return e.apply(this,arguments)}}(),n=function(){var e=(0,m.coroutine)(v.default.mark(function e(){var t,r;return v.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=void 0,a.opts.filter?t=a.opts.filter:(t=new S(s.credentials.userId),t.setTimelineLimit(a.opts.initialSyncLimit)),r=void 0,e.prev=3,e.next=6,(0,m.resolve)(s.getOrCreateFilter(o(s.credentials.userId),t));case 6:r=e.sent,e.next=15;break;case 9:return e.prev=9,e.t0=e.catch(3),e.next=13,(0,m.resolve)(a.recoverFromSyncStartupError(u,e.t0));case 13:return n(),e.abrupt("return");case 15:return s.resetNotifTimelineSet(),null===a._currentSyncRequest&&(console.log("Sending first sync request..."),a._currentSyncRequest=a._doSyncRequest({filterId:r},c)),e.next=19,(0,m.resolve)(u);case 19:a._sync({filterId:r});case 20:case"end":return e.stop()}},e,this,[[3,9]])}));return function(){return e.apply(this,arguments)}}(),s=this.client,a=this;this._running=!0,r.document&&(this._onOnlineBound=this._onOnline.bind(this),r.document.addEventListener("online",this._onOnlineBound,!1));var u=y.default.resolve(),c=null,l=function(){var t=(0,m.coroutine)(v.default.mark(function t(){var r,o,i,a;return v.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e.opts.lazyLoadMembers&&s.isGuest()&&(e.opts.lazyLoadMembers=!1),!e.opts.lazyLoadMembers){t.next=13;break}return t.next=4,(0,m.resolve)(s.doesServerSupportLazyLoading());case 4:if(!(r=t.sent)){t.next=11;break}return t.next=8,(0,m.resolve)(s.createFilter(S.LAZY_LOADING_SYNC_FILTER));case 8:e.opts.filter=t.sent,t.next=13;break;case 11:console.log("LL: lazy loading requested but not supported by server, so disabling"),e.opts.lazyLoadMembers=!1;case 13:return t.next=15,(0,m.resolve)(e._wasLazyLoadingToggled(e.opts.lazyLoadMembers));case 15:if(!(o=t.sent)){t.next=23;break}return e._storeIsInvalid=!0,i=_.InvalidStoreError.TOGGLED_LAZY_LOADING,a=new _.InvalidStoreError(i,!!e.opts.lazyLoadMembers),e._updateSyncState("ERROR",{error:a}),console.warn("InvalidStoreError: store is not usable: stopping sync."),t.abrupt("return");case 23:return e.opts.lazyLoadMembers&&e.opts.crypto&&e.opts.crypto.enableLazyLoading(),t.next=26,(0,m.resolve)(e.client._storeClientOptions());case 26:n();case 27:case"end":return t.stop()}},t,e)}));return function(){return t.apply(this,arguments)}}();s.isGuest()?a._sync({}):(u=s.store.getSavedSyncToken().then(function(e){return c=e,s.store.getSavedSync()}).then(function(e){if(e)return a._syncFromCache(e)}),t())},s.prototype.stop=function(){i("SyncApi.stop"),r.document&&(r.document.removeEventListener("online",this._onOnlineBound,!1),this._onOnlineBound=void 0),this._running=!1,this._currentSyncRequest&&this._currentSyncRequest.abort(),this._keepAliveTimer&&(clearTimeout(this._keepAliveTimer),this._keepAliveTimer=null)},s.prototype.retryImmediately=function(){return!!this._connectionReturnedDefer&&(this._startKeepAlives(0),!0)},s.prototype._syncFromCache=function(){var e=(0,m.coroutine)(v.default.mark(function e(t){var r,n,o;return v.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return i("sync(): not doing HTTP hit, instead returning stored /sync data"),r=t.nextBatch,this.client.store.setSyncToken(r),n={oldSyncToken:null,nextSyncToken:r,catchingUp:!1},o={next_batch:r,rooms:t.roomsData,groups:t.groupsData,account_data:{events:t.accountData}},e.prev=5,e.next=8,(0,m.resolve)(this._processSyncResponse(n,o));case 8:e.next=13;break;case 10:e.prev=10,e.t0=e.catch(5),console.error("Error processing cached sync",e.t0.stack||e.t0);case 13:this._storeIsInvalid||this._updateSyncState("PREPARED",n);case 14:case"end":return e.stop()}},e,this,[[5,10]])}));return function(t){return e.apply(this,arguments)}}(),s.prototype._sync=function(){var e=(0,m.coroutine)(v.default.mark(function e(t){var r,n,o,s;return v.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=this.client,this._running){e.next=6;break}return i("Sync no longer running: exiting."),this._connectionReturnedDefer&&(this._connectionReturnedDefer.reject(),this._connectionReturnedDefer=null),this._updateSyncState("STOPPED"),e.abrupt("return");case 6:return n=r.store.getSyncToken(),o=void 0,e.prev=8,null===this._currentSyncRequest&&(this._currentSyncRequest=this._doSyncRequest(t,n)),e.next=12,(0,m.resolve)(this._currentSyncRequest);case 12:o=e.sent,e.next=19;break;case 15:return e.prev=15,e.t0=e.catch(8),this._onSyncError(e.t0,t),e.abrupt("return");case 19:return e.prev=19,this._currentSyncRequest=null,e.finish(19);case 22:return r.store.setSyncToken(o.next_batch),this._failedSyncCount=0,e.next=26,(0,m.resolve)(r.store.setSyncData(o));case 26:if(s={oldSyncToken:n,nextSyncToken:o.next_batch,catchingUp:this._catchingUp},!this.opts.crypto){e.next=30;break}return e.next=30,(0,m.resolve)(this.opts.crypto.onSyncWillProcess(s));case 30:return e.prev=30,e.next=33,(0,m.resolve)(this._processSyncResponse(s,o));case 33:e.next=38;break;case 35:e.prev=35,e.t1=e.catch(30),console.error("Caught /sync error",e.t1.stack||e.t1);case 38:if(s.catchingUp=this._catchingUp,t.hasSyncedBefore||(this._updateSyncState("PREPARED",s),t.hasSyncedBefore=!0),!this.opts.crypto){e.next=43;break}return e.next=43,(0,m.resolve)(this.opts.crypto.onSyncCompleted(s));case 43:if(this._updateSyncState("SYNCING",s),!r.store.wantsSave()){e.next=49;break}if(!this.opts.crypto){e.next=48;break}return e.next=48,(0,m.resolve)(this.opts.crypto.saveDeviceList(0));case 48:r.store.save();case 49:this._sync(t);case 50:case"end":return e.stop()}},e,this,[[8,15,19,22],[30,35]])}));return function(t){return e.apply(this,arguments)}}(),s.prototype._doSyncRequest=function(e,t){var r=this._getSyncParams(e,t);return this.client._http.authedRequest(void 0,"GET","/sync",r,void 0,r.timeout+8e4)},s.prototype._getSyncParams=function(e,t){var r=this.opts.pollTimeout;("SYNCING"!==this.getSyncState()||this._catchingUp)&&(this._catchingUp=!0,r=0);var n=e.filterId;this.client.isGuest()&&!n&&(n=this._getGuestFilter());var o={filter:n,timeout:r};return this.opts.disablePresence&&(o.set_presence="offline"),t?o.since=t:o._cacheBuster=Date.now(),"ERROR"!=this.getSyncState()&&"RECONNECTING"!=this.getSyncState()||(o.timeout=0),o},s.prototype._onSyncError=function(e,t){var r=this;if(!this._running)return i("Sync no longer running: exiting"),this._connectionReturnedDefer&&(this._connectionReturnedDefer.reject(),this._connectionReturnedDefer=null),void this._updateSyncState("STOPPED");console.error("/sync error %s",e),console.error(e),this._failedSyncCount++,console.log("Number of consecutive failed sync requests:",this._failedSyncCount),i("Starting keep-alive"),this._startKeepAlives().then(function(e){e&&"ERROR"===r.getSyncState()&&r._updateSyncState("CATCHUP",{oldSyncToken:null,nextSyncToken:null,catchingUp:!0}),r._sync(t)}),this._currentSyncRequest=null,this._updateSyncState(this._failedSyncCount>=3?"ERROR":"RECONNECTING",{error:e})},s.prototype._processSyncResponse=function(){var e=(0,m.coroutine)(v.default.mark(function e(t,r){var n,o,s,u,c,l,d;return v.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.client,o=this,r.presence&&w.isArray(r.presence.events)&&r.presence.events.map(n.getEventMapper()).forEach(function(e){var t=n.store.getUser(e.getSender());t?t.setPresenceEvent(e):(t=a(n,e.getSender()),t.setPresenceEvent(e),n.store.storeUser(t)),n.emit("event",e)}),r.account_data&&w.isArray(r.account_data.events)&&(s=r.account_data.events.map(n.getEventMapper()),n.store.storeAccountDataEvents(s),s.forEach(function(e){return"m.push_rules"==e.getType()&&(n.pushRules=e.getContent()),n.emit("accountData",e),e})),r.to_device&&w.isArray(r.to_device.events)&&r.to_device.events.length>0?r.to_device.events.map(n.getEventMapper()).forEach(function(e){var t=e.getContent();if("m.room.message"==e.getType()&&"m.bad.encrypted"==t.msgtype)return void console.log("Ignoring undecryptable to-device event from "+e.getSender());n.emit("toDeviceEvent",e)}):this._catchingUp=!1,r.groups&&(r.groups.invite&&this._processGroupSyncEntry(r.groups.invite,"invite"),r.groups.join&&this._processGroupSyncEntry(r.groups.join,"join"),r.groups.leave&&this._processGroupSyncEntry(r.groups.leave,"leave")),u=[],c=[],l=[],r.rooms&&(r.rooms.invite&&(u=this._mapSyncResponseToRoomArray(r.rooms.invite)),r.rooms.join&&(c=this._mapSyncResponseToRoomArray(r.rooms.join)),r.rooms.leave&&(l=this._mapSyncResponseToRoomArray(r.rooms.leave))),this._notifEvents=[],u.forEach(function(e){var t=e.room,r=o._mapSyncEventsFormat(e.invite_state,t);t.updateMyMembership("invite"),o._processRoomEvents(t,r),e.isBrandNewRoom&&(t.recalculate(),n.store.storeRoom(t),n.emit("Room",t)),r.forEach(function(e){n.emit("event",e)})}),e.next=14,(0,m.resolve)(y.default.mapSeries(c,function(){var e=(0,m.coroutine)(v.default.mark(function e(r){var s,a,u,c,l,d,f,p,h=function(){var e=(0,m.coroutine)(v.default.mark(function e(t){return v.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n.emit("event",t),!t.isState()||"m.room.encryption"!=t.getType()||!o.opts.crypto){e.next=4;break}return e.next=4,(0,m.resolve)(o.opts.crypto.onCryptoEvent(t));case 4:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}();return v.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(s=r.room,a=o._mapSyncEventsFormat(r.state,s),u=o._mapSyncEventsFormat(r.timeline,s),c=o._mapSyncEventsFormat(r.ephemeral),l=o._mapSyncEventsFormat(r.account_data),r.unread_notifications&&(s.setUnreadNotificationCount("total",r.unread_notifications.notification_count),s.setUnreadNotificationCount("highlight",r.unread_notifications.highlight_count)),s.updateMyMembership("join"),r.timeline=r.timeline||{},!r.isBrandNewRoom){e.next=12;break}s.getLiveTimeline().setPaginationToken(r.timeline.prev_batch,k.BACKWARDS),e.next=26;break;case 12:if(!r.timeline.limited){e.next=26;break}d=!0,f=u.length-1;case 15:if(!(f>=0)){e.next=25;break}if(p=u[f].getId(),!s.getTimelineForEvent(p)){e.next=22;break}return i("Already have event "+p+" in limited sync - not resetting"),d=!1,u.splice(0,f),e.abrupt("break",25);case 22:f--,e.next=15;break;case 25:d&&(o._deregisterStateListeners(s),s.resetLiveTimeline(r.timeline.prev_batch,o.opts.canResetEntireTimeline(s.roomId)?null:t.oldSyncToken),n.resetNotifTimelineSet(),o._registerStateListeners(s));case 26:return o._processRoomEvents(s,a,u),r.summary&&s.setSummary(r.summary),s.addLiveEvents(c),s.addAccountData(l),s.recalculate(),r.isBrandNewRoom&&(n.store.storeRoom(s),n.emit("Room",s)),o._processEventsForNotifs(s,u),e.next=35,(0,m.resolve)(y.default.mapSeries(a,h));case 35:return e.next=37,(0,m.resolve)(y.default.mapSeries(u,h));case 37:c.forEach(function(e){n.emit("event",e)}),l.forEach(function(e){n.emit("event",e)});case 39:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()));case 14:if(l.forEach(function(e){var t=e.room,r=o._mapSyncEventsFormat(e.state,t),i=o._mapSyncEventsFormat(e.timeline,t),s=o._mapSyncEventsFormat(e.account_data);t.updateMyMembership("leave"),o._processRoomEvents(t,r,i),t.addAccountData(s),t.recalculate(),e.isBrandNewRoom&&(n.store.storeRoom(t),n.emit("Room",t)),o._processEventsForNotifs(t,i),r.forEach(function(e){n.emit("event",e)}),i.forEach(function(e){n.emit("event",e)}),s.forEach(function(e){n.emit("event",e)})}),t.oldSyncToken&&this._notifEvents.length&&(this._notifEvents.sort(function(e,t){return e.getTs()-t.getTs()}),this._notifEvents.forEach(function(e){n.getNotifTimelineSet().addLiveEvent(e)})),!r.device_lists){e.next=22;break}if(!this.opts.crypto){e.next=22;break}return e.next=20,(0,m.resolve)(this.opts.crypto.handleDeviceListChanges(t,r.device_lists));case 20:e.next=22;break;case 22:this.opts.crypto&&r.device_one_time_keys_count&&(d=r.device_one_time_keys_count.signed_curve25519||0,this.opts.crypto.updateOneTimeKeyCount(d));case 23:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}(),s.prototype._startKeepAlives=function(e){void 0===e&&(e=2e3+Math.floor(5e3*Math.random())),null!==this._keepAliveTimer&&clearTimeout(this._keepAliveTimer);var t=this;return e>0?t._keepAliveTimer=setTimeout(t._pokeKeepAlive.bind(t),e):t._pokeKeepAlive(),this._connectionReturnedDefer||(this._connectionReturnedDefer=y.default.defer()),this._connectionReturnedDefer.promise},s.prototype._pokeKeepAlive=function(e){function t(){clearTimeout(r._keepAliveTimer),r._connectionReturnedDefer&&(r._connectionReturnedDefer.resolve(e),r._connectionReturnedDefer=null)}void 0===e&&(e=!1);var r=this;this.client._http.request(void 0,"GET","/_matrix/client/versions",void 0,void 0,{prefix:"",localTimeoutMs:15e3}).done(function(){t()},function(n){400==n.httpStatus||404==n.httpStatus?r._keepAliveTimer=setTimeout(t,2e3):(e=!0,r._keepAliveTimer=setTimeout(r._pokeKeepAlive.bind(r,e),5e3+Math.floor(5e3*Math.random())),r._updateSyncState("ERROR",{error:n}))})},s.prototype._processGroupSyncEntry=function(e,t){var r=!0,n=!1,o=void 0;try{for(var i,s=(0,p.default)((0,d.default)(e));!(r=(i=s.next()).done);r=!0){var a=i.value,u=e[a],c=this.client.store.getGroup(a),l=null===c;null===c&&(c=this.createGroup(a)),u.profile&&c.setProfile(u.profile.name,u.profile.avatar_url),u.inviter&&c.setInviter({userId:u.inviter}),c.setMyMembership(t),l&&this.client.emit("Group",c)}}catch(e){n=!0,o=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw o}}},s.prototype._mapSyncResponseToRoomArray=function(e){var t=this.client,r=this;return w.keys(e).map(function(n){var o=e[n],i=t.store.getRoom(n),s=!1;return i||(i=r.createRoom(n),s=!0),o.room=i,o.isBrandNewRoom=s,o})},s.prototype._mapSyncEventsFormat=function(e,t){if(!e||!w.isArray(e.events))return[];var r=this.client.getEventMapper();return e.events.map(function(e){return t&&(e.room_id=t.roomId),r(e)
})},s.prototype._resolveInvites=function(e){if(e&&this.opts.resolveInvitesToProfiles){var t=this.client;e.getMembersWithMembership("invite").forEach(function(r){if(!r._requestedProfileInfo){r._requestedProfileInfo=!0;var n=t.getUser(r.userId),o=void 0;o=n?y.default.resolve({avatar_url:n.avatarUrl,displayname:n.displayName}):t.getProfileInfo(r.userId),o.done(function(t){var n=r.events.member;"invite"===n.getContent().membership&&(n.getContent().avatar_url=t.avatar_url,n.getContent().displayname=t.displayname,r.setMembershipEvent(n,e.currentState))},function(e){})}})}},s.prototype._processRoomEvents=function(e,t,r){var n=e.getLiveTimeline(),o=0==n.getEvents().length;if(o){var i=!0,s=!1,a=void 0;try{for(var u,c=(0,p.default)(t);!(i=(u=c.next()).done);i=!0){var l=u.value;this.client.getPushActionsForEvent(l)}}catch(e){s=!0,a=e}finally{try{!i&&c.return&&c.return()}finally{if(s)throw a}}n.initialiseState(t)}this._resolveInvites(e),e.recalculate(),o||(e.oldState.setStateEvents(t||[]),e.currentState.setStateEvents(t||[])),e.addLiveEvents(r||[])},s.prototype._processEventsForNotifs=function(e,t){if(this.client.getNotifTimelineSet())for(var r=0;r<t.length;r++){var n=this.client.getPushActionsForEvent(t[r]);n&&n.notify&&n.tweaks&&n.tweaks.highlight&&this._notifEvents.push(t[r])}},s.prototype._getGuestFilter=function(){return this.client._guestRooms?(0,c.default)({room:{timeline:{limit:20}}}):"{}"},s.prototype._updateSyncState=function(e,t){var r=this._syncState;this._syncState=e,this._syncStateData=t,this.client.emit("sync",this._syncState,r,t)},s.prototype._onOnline=function(){i("Browser thinks we are back online"),this._startKeepAlives(0)},t.exports=s}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./errors":24,"./filter":26,"./models/event-timeline":33,"./models/group":35,"./models/room":39,"./models/user":41,"./utils":55,"babel-runtime/core-js/get-iterator":58,"babel-runtime/core-js/json/stringify":60,"babel-runtime/core-js/object/keys":69,"babel-runtime/regenerator":86,bluebird:89}],54:[function(e,t,r){"use strict";function n(e,t,r){r=r||{},this._client=e,this._timelineSet=t,this._start=null,this._end=null,this._eventCount=0,this._windowLimit=r.windowLimit||1e3}function o(e,t){this.timeline=e,this.index=t}var i=e("bluebird"),s=function(e){return e&&e.__esModule?e:{default:e}}(i),a=e("./models/event-timeline"),u=function(){};n.prototype.load=function(e,t){var r=this;t=t||20;var n=function(n){var i=void 0,s=n.getEvents();if(e){for(var a=0;a<s.length;a++)if(s[a].getId()==e){i=a;break}if(void 0===i)throw new Error("getEventTimeline result didn't include requested event")}else i=s.length;var u=Math.min(s.length,i+Math.ceil(t/2)),c=Math.max(0,u-t);r._start=new o(n,c-n.getBaseIndex()),r._end=new o(n,u-n.getBaseIndex()),r._eventCount=u-c};if(e){var i=this._client.getEventTimeline(this._timelineSet,e);return i.isFulfilled()?(n(i.value()),s.default.resolve()):i.then(n)}return n(this._timelineSet.getLiveTimeline()),s.default.resolve()},n.prototype.canPaginate=function(e){var t=void 0;if(e==a.BACKWARDS)t=this._start;else{if(e!=a.FORWARDS)throw new Error("Invalid direction '"+e+"'");t=this._end}if(!t)return u("TimelineWindow: no timeline yet"),!1;if(e==a.BACKWARDS){if(t.index>t.minIndex())return!0}else if(t.index<t.maxIndex())return!0;return Boolean(t.timeline.getNeighbouringTimeline(e)||t.timeline.getPaginationToken(e))},n.prototype.paginate=function(e,t,r,n){void 0===r&&(r=!0),void 0===n&&(n=5);var o=void 0;if(e==a.BACKWARDS)o=this._start;else{if(e!=a.FORWARDS)throw new Error("Invalid direction '"+e+"'");o=this._end}if(!o)return u("TimelineWindow: no timeline yet"),s.default.resolve(!1);if(o.pendingPaginate)return o.pendingPaginate;var i=e==a.BACKWARDS?o.retreat(t):o.advance(t);if(i){this._eventCount+=i,u("TimelineWindow: increased cap by "+i+" (now "+this._eventCount+")");var c=this._eventCount-this._windowLimit;return c>0&&this.unpaginate(c,e!=a.BACKWARDS),s.default.resolve(!0)}if(!r||0===n)return s.default.resolve(!1);if(!o.timeline.getPaginationToken(e))return u("TimelineWindow: no token"),s.default.resolve(!1);u("TimelineWindow: starting request");var l=this,d=this._client.paginateEventTimeline(o.timeline,{backwards:e==a.BACKWARDS,limit:t}).finally(function(){o.pendingPaginate=null}).then(function(r){return u("TimelineWindow: request completed with result "+r),!!r&&l.paginate(e,t,!0,n-1)});return o.pendingPaginate=d,d},n.prototype.unpaginate=function(e,t){var r=t?this._start:this._end;if(e>this._eventCount||e<0)throw new Error("Attemting to unpaginate "+e+" events, but only have "+this._eventCount+" in the timeline");for(;e>0;){var n=t?r.advance(e):r.retreat(e);if(n<=0)throw new Error("Unable to unpaginate any further, but still have "+this._eventCount+" events");e-=n,this._eventCount-=n,u("TimelineWindow.unpaginate: dropped "+n+" (now "+this._eventCount+")")}},n.prototype.getEvents=function(){if(!this._start)return[];for(var e=[],t=this._start.timeline;;){var r=t.getEvents(),n=0,o=r.length;t===this._start.timeline&&(n=this._start.index+t.getBaseIndex()),t===this._end.timeline&&(o=this._end.index+t.getBaseIndex());for(var i=n;i<o;i++)e.push(r[i]);if(t===this._end.timeline)break;t=t.getNeighbouringTimeline(a.FORWARDS)}return e},o.prototype.minIndex=function(){return-1*this.timeline.getBaseIndex()},o.prototype.maxIndex=function(){return this.timeline.getEvents().length-this.timeline.getBaseIndex()},o.prototype.advance=function(e){if(!e)return 0;var t=void 0;if(e<0){if((t=Math.max(e,this.minIndex()-this.index))<0)return this.index+=t,t}else if((t=Math.min(e,this.maxIndex()-this.index))>0)return this.index+=t,t;var r=this.timeline.getNeighbouringTimeline(e<0?a.BACKWARDS:a.FORWARDS);return r?(this.timeline=r,this.index=e<0?this.maxIndex():this.minIndex(),u("paginate: switched to new neighbour"),this.advance(e)):0},o.prototype.retreat=function(e){return-1*this.advance(-1*e)},t.exports.TimelineWindow=n,t.exports.TimelineIndex=o},{"./models/event-timeline":33,bluebird:89}],55:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var i=e("babel-runtime/core-js/object/create"),s=n(i),a=e("babel-runtime/helpers/typeof"),u=n(a),c=e("babel-runtime/core-js/json/stringify"),l=n(c);t.exports.encodeParams=function(e){var t="";for(var r in e)e.hasOwnProperty(r)&&(t+="&"+encodeURIComponent(r)+"="+encodeURIComponent(e[r]));return t.substring(1)},t.exports.encodeUri=function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e=e.replace(r,encodeURIComponent(t[r])));return e},t.exports.map=function(e,t){for(var r=new Array(e.length),n=0;n<e.length;n++)r[n]=t(e[n]);return r},t.exports.filter=function(e,t){for(var r=[],n=0;n<e.length;n++)t(e[n],n,e)&&r.push(e[n]);return r},t.exports.keys=function(e){var t=[];for(var r in e)e.hasOwnProperty(r)&&t.push(r);return t},t.exports.values=function(e){var t=[];for(var r in e)e.hasOwnProperty(r)&&t.push(e[r]);return t},t.exports.forEach=function(e,t){for(var r=0;r<e.length;r++)t(e[r],r)},t.exports.findElement=function(e,t,r){var n=void 0;if(r){for(n=e.length-1;n>=0;n--)if(t(e[n],n,e))return e[n]}else for(n=0;n<e.length;n++)if(t(e[n],n,e))return e[n]},t.exports.removeElement=function(e,t,r){var n=void 0,o=void 0;if(r){for(n=e.length-1;n>=0;n--)if(t(e[n],n,e))return o=e[n],e.splice(n,1),o}else for(n=0;n<e.length;n++)if(t(e[n],n,e))return o=e[n],e.splice(n,1),o;return!1},t.exports.isFunction=function(e){return"[object Function]"==Object.prototype.toString.call(e)},t.exports.isArray=function(e){return Array.isArray?Array.isArray(e):Boolean(e&&e.constructor===Array)},t.exports.checkObjectHasKeys=function(e,t){for(var r=0;r<t.length;r++)if(!e.hasOwnProperty(t[r]))throw new Error("Missing required key: "+t[r])},t.exports.checkObjectHasNoAdditionalKeys=function(e,t){for(var r in e)if(e.hasOwnProperty(r)&&-1===t.indexOf(r))throw new Error("Unknown key: "+r)},t.exports.deepCopy=function(e){return JSON.parse((0,l.default)(e))};var d=t.exports.deepCompare=function(e,t){if(e===t)return!0;if((void 0===e?"undefined":(0,u.default)(e))!==(void 0===t?"undefined":(0,u.default)(t)))return!1;if("number"==typeof e&&isNaN(e)&&isNaN(t))return!0;if(null===e||null===t)return e===t;if(!(e instanceof Object))return!1;if(e.constructor!==t.constructor||e.prototype!==t.prototype)return!1;if(e instanceof RegExp||e instanceof Date)return e.toString()===t.toString();if(e instanceof Array){if(e.length!==t.length)return!1;for(var r=0;r<e.length;r++)if(!d(e[r],t[r]))return!1}else{var n=void 0;for(n in t)if(t.hasOwnProperty(n)!==e.hasOwnProperty(n))return!1;for(n in t){if(t.hasOwnProperty(n)!==e.hasOwnProperty(n))return!1;if(!d(e[n],t[n]))return!1}}return!0};t.exports.extend=function(){for(var e=arguments[0]||{},t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)e[n]=r[n]}return e},t.exports.runPolyfills=function(){Array.prototype.filter||(Array.prototype.filter=function(e){if(void 0===this||null===this)throw new TypeError;var t=Object(this),r=t.length>>>0;if("function"!=typeof e)throw new TypeError;for(var n=[],o=arguments.length>=2?arguments[1]:void 0,i=0;i<r;i++)if(i in t){var s=t[i];e.call(o,s,i,t)&&n.push(s)}return n}),Array.prototype.map||(Array.prototype.map=function(e,t){var r=void 0,n=void 0;if(null===this||void 0===this)throw new TypeError(" this is null or not defined");var o=Object(this),i=o.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");arguments.length>1&&(r=t);var s=new Array(i);for(n=0;n<i;){var a,u;n in o&&(a=o[n],u=e.call(r,a,n,o),s[n]=u),n++}return s}),Array.prototype.forEach||(Array.prototype.forEach=function(e,t){var r=void 0,n=void 0;if(null===this||void 0===this)throw new TypeError(" this is null or not defined");var o=Object(this),i=o.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(arguments.length>1&&(r=t),n=0;n<i;){var s;n in o&&(s=o[n],e.call(r,s,n,o)),n++}})},t.exports.inherits=function(e,t){"function"!=typeof s.default&&(Object.create=function(){function e(){}var t=Object.prototype.hasOwnProperty;return function(r){if("object"!=(void 0===r?"undefined":(0,u.default)(r)))throw new TypeError("Object prototype may only be an Object or null");e.prototype=r;var n=new e;if(e.prototype=null,arguments.length>1){var o=Object(arguments[1]);for(var i in o)t.call(o,i)&&(n[i]=o[i])}return n}}()),e.super_=t,e.prototype=(0,s.default)(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})},t.exports.isNumber=function(e){return"number"==typeof e&&isFinite(e)},t.exports.removeHiddenChars=function(e){return e.normalize("NFD").replace(f,"")};var f=/[\u200B-\u200D\u0300-\u036f\uFEFF\s]/g;t.exports.escapeRegExp=o,t.exports.globToRegexp=function(e,t){t="boolean"!=typeof t||t;var r=o(e);return r=r.replace(/\\\*/g,".*"),r=r.replace(/\?/g,"."),t&&(r=r.replace(/\\\[(!|)(.*)\\]/g,function(e,t,r,n,o){return"["+(t&&"^"||"")+r.replace(/\\\-/,"-")+"]"})),r}},{"babel-runtime/core-js/json/stringify":60,"babel-runtime/core-js/object/create":64,"babel-runtime/helpers/typeof":85}],56:[function(e,t,r){(function(r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e){this.roomId=e.roomId,this.client=e.client,this.webRtc=e.webRtc,this.forceTURN=e.forceTURN,this.URL=e.URL,this.turnServers=e.turnServers||[],0===this.turnServers.length&&this.turnServers.push({urls:[o.FALLBACK_STUN_SERVER]}),l.forEach(this.turnServers,function(e){l.checkObjectHasKeys(e,["urls"])}),this.callId="c"+(new Date).getTime()+Math.random(),this.state="fledgling",this.didConnect=!1,this.candidateSendQueue=[],this.candidateSendTries=0,this.mediaPromises=(0,c.default)(null),this.screenSharingStream=null,this._answerContent=null}var i=e("babel-runtime/regenerator"),s=n(i),a=e("bluebird"),u=e("babel-runtime/core-js/object/create"),c=n(u),l=e("../utils"),d=e("events").EventEmitter;o.CALL_TIMEOUT_MS=6e4,o.FALLBACK_STUN_SERVER="stun:stun.l.google.com:19302",o.ERR_LOCAL_OFFER_FAILED="local_offer_failed",o.ERR_NO_USER_MEDIA="no_user_media",o.ERR_UNKNOWN_DEVICES="unknown_devices",o.ERR_SEND_INVITE="send_invite",o.ERR_SEND_ANSWER="send_answer",l.inherits(o,d),o.prototype.placeVoiceCall=function(){S("placeVoiceCall"),E(this),T(this,I("voice")),this.type="voice"},o.prototype.placeVideoCall=function(e,t){S("placeVideoCall"),E(this),this.localVideoElement=t,this.remoteVideoElement=e,T(this,I("video")),this.type="video",g(this)},o.prototype.placeScreenSharingCall=function(e,t){S("placeScreenSharingCall"),E(this);var r=R(this);if(r){this.localVideoElement=t,this.remoteVideoElement=e;var n=this;this.webRtc.getUserMedia(r,function(e){n.screenSharingStream=e,S("Got screen stream, requesting audio stream...");var t=I("voice");T(n,t)},function(e){n.emit("error",w(o.ERR_NO_USER_MEDIA,"Failed to get screen-sharing stream: "+e))}),this.type="video",g(this)}},o.prototype.playElement=function(e,t){console.log("queuing play on "+t+" and element "+e),this.mediaPromises[t]?this.mediaPromises[t]=this.mediaPromises[t].then(function(){return console.log("previous promise completed for "+t),e.play()},function(){return console.log("previous promise failed for "+t),e.play()}):this.mediaPromises[t]=e.play()},o.prototype.pauseElement=function(e,t){console.log("queuing pause on "+t+" and element "+e),this.mediaPromises[t]?this.mediaPromises[t]=this.mediaPromises[t].then(function(){return console.log("previous promise completed for "+t),e.pause()},function(){return console.log("previous promise failed for "+t),e.pause()}):this.mediaPromises[t]=e.pause()},o.prototype.assignElement=function(e,t,r){console.log("queuing assign on "+r+" element "+e+" for "+t),this.mediaPromises[r]?this.mediaPromises[r]=this.mediaPromises[r].then(function(){console.log("previous promise completed for "+r),e.srcObject=t},function(){console.log("previous promise failed for "+r),e.srcObject=t}):e.srcObject=t},o.prototype.getLocalVideoElement=function(){return this.localVideoElement},o.prototype.getRemoteVideoElement=function(){return this.remoteVideoElement},o.prototype.getRemoteAudioElement=function(){return this.remoteAudioElement},o.prototype.setLocalVideoElement=function(e){if(this.localVideoElement=e,e&&this.localAVStream&&"video"===this.type){e.autoplay=!0,this.assignElement(e,this.localAVStream,"localVideo"),e.muted=!0;var t=this;setTimeout(function(){var e=t.getLocalVideoElement();e.play&&t.playElement(e,"localVideo")},0)}},o.prototype.setRemoteVideoElement=function(e){this.remoteVideoElement=e,g(this)},o.prototype.setRemoteAudioElement=function(e){this.remoteVideoElement.muted=!0,this.remoteAudioElement=e,this.remoteAudioElement.muted=!1,b(this)},o.prototype._initWithInvite=function(e){this.msg=e.getContent(),this.peerConn=x(this);var t=this;this.peerConn&&this.peerConn.setRemoteDescription(new this.webRtc.RtcSessionDescription(this.msg.offer),C(t,t._onSetRemoteDescriptionSuccess),C(t,t._onSetRemoteDescriptionError)),h(this,"ringing"),this.direction="inbound",this.msg.offer&&this.msg.offer.sdp&&this.msg.offer.sdp.indexOf("m=video")>-1?this.type="video":this.type="voice",e.getAge()&&setTimeout(function(){"ringing"==t.state&&(S("Call invite has expired. Hanging up."),t.hangupParty="remote",h(t,"ended"),_(t),"closed"!=t.peerConn.signalingState&&t.peerConn.close(),t.emit("hangup",t))},this.msg.lifetime-e.getAge())},o.prototype._initWithHangup=function(e){this.msg=e.getContent(),h(this,"ended")},o.prototype.answer=function(){S("Answering call %s of type %s",this.callId,this.type);var e=this;if(e._answerContent)return void e._sendAnswer();this.localAVStream||this.waitForLocalAVStream?this.localAVStream?this._maybeGotUserMediaForAnswer(this.localAVStream):this.waitForLocalAVStream&&h(this,"wait_local_media"):(this.webRtc.getUserMedia(I(this.type),C(e,e._maybeGotUserMediaForAnswer),C(e,e._maybeGotUserMediaForAnswer)),h(this,"wait_local_media"))},o.prototype._replacedBy=function(e){S(this.callId+" being replaced by "+e.callId),"wait_local_media"==this.state?(S("Telling new call to wait for local media"),e.waitForLocalAVStream=!0):"create_offer"==this.state?(S("Handing local stream to new call"),e._maybeGotUserMediaForAnswer(this.localAVStream),delete this.localAVStream):"invite_sent"==this.state&&(S("Handing local stream to new call"),e._maybeGotUserMediaForAnswer(this.localAVStream),delete this.localAVStream),e.localVideoElement=this.localVideoElement,e.remoteVideoElement=this.remoteVideoElement,e.remoteAudioElement=this.remoteAudioElement,this.successor=e,this.emit("replaced",e),this.hangup(!0)},o.prototype.hangup=function(e,t){if("ended"!=this.state){S("Ending call "+this.callId),y(this,"local",e,!t);var r={version:0,call_id:this.callId,reason:e};v(this,"m.call.hangup",r)}},o.prototype.setLocalVideoMuted=function(e){this.localAVStream&&f(this.localAVStream.getVideoTracks(),!e)},o.prototype.isLocalVideoMuted=function(){return!!this.localAVStream&&!p(this.localAVStream.getVideoTracks())},o.prototype.setMicrophoneMuted=function(e){this.localAVStream&&f(this.localAVStream.getAudioTracks(),!e)},o.prototype.isMicrophoneMuted=function(){return!!this.localAVStream&&!p(this.localAVStream.getAudioTracks())},o.prototype._maybeGotUserMediaForInvite=function(e){if(this.successor)return void this.successor._maybeGotUserMediaForAnswer(e);if("ended"!=this.state){S("_maybeGotUserMediaForInvite -> "+this.type);var t=this,r=e,n={mandatory:{OfferToReceiveAudio:!0,OfferToReceiveVideo:"video"===t.type}};if(e instanceof MediaStream){var o=this.getLocalVideoElement();o&&"video"==this.type&&(o.autoplay=!0,this.screenSharingStream?(S("Setting screen sharing stream to the local video element"),this.assignElement(o,this.screenSharingStream,"localVideo")):this.assignElement(o,e,"localVideo"),o.muted=!0,setTimeout(function(){var e=t.getLocalVideoElement();e.play&&t.playElement(e,"localVideo")},0)),this.screenSharingStream&&(this.screenSharingStream.addTrack(e.getAudioTracks()[0]),e=this.screenSharingStream),this.localAVStream=e,f(e.getAudioTracks(),!0),this.peerConn=x(this),this.peerConn.addStream(e)}else{if("PermissionDeniedError"!==r.name)return S("Failed to getUserMedia."),void this._getUserMediaFailed(r);S("User denied access to camera/microphone. Or possibly you are using an insecure domain. Receiving only."),this.peerConn=x(this)}this.peerConn.createOffer(C(t,t._gotLocalOffer),C(t,t._getLocalOfferFailed),n),h(t,"create_offer")}},o.prototype._sendAnswer=function(e){var t=this;v(this,"m.call.answer",this._answerContent).then(function(){h(t,"connecting"),k(t)}).catch(function(e){h(t,"ringing"),t.client.cancelPendingEvent(e.event);var r=o.ERR_SEND_ANSWER,n="Failed to send answer";throw"UnknownDeviceError"==e.name&&(r=o.ERR_UNKNOWN_DEVICES,n="Unknown devices present in the room"),t.emit("error",w(r,n)),e})},o.prototype._maybeGotUserMediaForAnswer=function(e){var t=this;if("ended"!=t.state){var r=e;if(e instanceof MediaStream){var n=t.getLocalVideoElement();n&&"video"==t.type&&(n.autoplay=!0,this.assignElement(n,e,"localVideo"),n.muted=!0,setTimeout(function(){var e=t.getLocalVideoElement();e.play&&t.playElement(e,"localVideo")},0)),t.localAVStream=e,f(e.getAudioTracks(),!0),t.peerConn.addStream(e)}else{if("PermissionDeniedError"!==r.name)return S("Failed to getUserMedia."),void this._getUserMediaFailed(r);S("User denied access to camera/microphone. Or possibly you are using an insecure domain. Receiving only.")}var o={mandatory:{OfferToReceiveAudio:!0,OfferToReceiveVideo:"video"===t.type}};t.peerConn.createAnswer(function(e){S("Created answer: "+e),t.peerConn.setLocalDescription(e,function(){t._answerContent={version:0,call_id:t.callId,answer:{sdp:t.peerConn.localDescription.sdp,type:t.peerConn.localDescription.type}},t._sendAnswer()},function(){S("Error setting local description!")},o)},function(e){S("Failed to create answer: "+e)}),h(t,"create_answer")}},o.prototype._gotLocalIceCandidate=function(e){if(e.candidate){if(S("Got local ICE "+e.candidate.sdpMid+" candidate: "+e.candidate.candidate),"ended"==this.state)return;var t={candidate:e.candidate.candidate,sdpMid:e.candidate.sdpMid,sdpMLineIndex:e.candidate.sdpMLineIndex};m(this,t)}},o.prototype._gotRemoteIceCandidate=function(e){"ended"!=this.state&&(S("Got remote ICE "+e.sdpMid+" candidate: "+e.candidate),this.peerConn.addIceCandidate(new this.webRtc.RtcIceCandidate(e),function(){},function(e){}))},o.prototype._receivedAnswer=function(e){if("ended"!=this.state){var t=this;this.peerConn.setRemoteDescription(new this.webRtc.RtcSessionDescription(e.answer),C(t,t._onSetRemoteDescriptionSuccess),C(t,t._onSetRemoteDescriptionError)),h(t,"connecting")}},o.prototype._gotLocalOffer=function(e){var t=this;if(S("Created offer: "+e),"ended"==t.state)return void S("Ignoring newly created offer on call ID "+t.callId+" because the call has ended");t.peerConn.setLocalDescription(e,function(){var e={version:0,call_id:t.callId,offer:{sdp:t.peerConn.localDescription.sdp,type:t.peerConn.localDescription.type},lifetime:o.CALL_TIMEOUT_MS};v(t,"m.call.invite",e).then(function(){h(t,"invite_sent"),setTimeout(function(){"invite_sent"==t.state&&t.hangup("invite_timeout")},o.CALL_TIMEOUT_MS)}).catch(function(e){var r=o.ERR_SEND_INVITE,n="Failed to send invite";throw"UnknownDeviceError"==e.name&&(r=o.ERR_UNKNOWN_DEVICES,n="Unknown devices present in the room"),t.client.cancelPendingEvent(e.event),y(t,"local",r,!1),t.emit("error",w(r,n)),e})},function(){S("Error setting local description!")})},o.prototype._getLocalOfferFailed=function(e){this.emit("error",w(o.ERR_LOCAL_OFFER_FAILED,"Failed to start audio for call!"))},o.prototype._getUserMediaFailed=function(e){y(this,"local","user_media_failed",!1),this.emit("error",w(o.ERR_NO_USER_MEDIA,"Couldn't start capturing media! Is your microphone set up and does this app have permission?"))},o.prototype._onIceConnectionStateChanged=function(){"ended"!=this.state&&(S("Ice connection state changed to: "+this.peerConn.iceConnectionState),"completed"==this.peerConn.iceConnectionState||"connected"==this.peerConn.iceConnectionState?(h(this,"connected"),this.didConnect=!0):"failed"==this.peerConn.iceConnectionState&&this.hangup("ice_failed"))},o.prototype._onSignallingStateChanged=function(){S("call "+this.callId+": Signalling state changed to: "+this.peerConn.signalingState)},o.prototype._onSetRemoteDescriptionSuccess=function(){S("Set remote description")},o.prototype._onSetRemoteDescriptionError=function(e){S("Failed to set remote description"+e)},o.prototype._onAddStream=function(e){S("Stream id "+e.stream.id+" added");var t=e.stream;t.getVideoTracks().length>0?(this.type="video",this.remoteAVStream=t,this.remoteAStream=t):(this.type="voice",this.remoteAStream=t);var r=this;A(t,function(e){S("Track id "+e.id+" added"),e.onstarted=C(r,r._onRemoteStreamTrackStarted)}),void 0!==e.stream.oninactive?e.stream.oninactive=C(r,r._onRemoteStreamEnded):e.stream.onended=C(r,r._onRemoteStreamEnded),e.stream.onstarted=C(r,r._onRemoteStreamStarted),"video"===this.type?(g(this),b(this)):b(this)},o.prototype._onRemoteStreamStarted=function(e){h(this,"connected")},o.prototype._onRemoteStreamEnded=function(e){S("Remote stream ended"),this.hangupParty="remote",h(this,"ended"),_(this),"closed"!=this.peerConn.signalingState&&this.peerConn.close(),this.emit("hangup",this)},o.prototype._onRemoteStreamTrackStarted=function(e){h(this,"connected")},o.prototype._onHangupReceived=function(e){S("Hangup received"),y(this,"remote",e.reason,!0)},o.prototype._onAnsweredElsewhere=function(e){S("Answered elsewhere"),y(this,"remote","answered_elsewhere",!0)};var f=function(e,t){for(var r=0;r<e.length;r++)e[r].enabled=t},p=function(e){for(var t=0;t<e.length;t++)if(e[t].enabled)return!0;return!1},h=function(e,t){var r=e.state;e.state=t,e.emit("state",t,r)},v=function(e,t,r){return e.client.sendEvent(e.roomId,t,r)},m=function(e,t){e.candidateSendQueue.push(t),"ringing"!=e.state&&0===e.candidateSendTries&&setTimeout(function(){k(e)},100)},y=function(e,t,r,n){e.getRemoteVideoElement()&&(e.getRemoteVideoElement().pause&&e.pauseElement(e.getRemoteVideoElement(),"remoteVideo"),e.assignElement(e.getRemoteVideoElement(),null,"remoteVideo")),e.getRemoteAudioElement()&&(e.getRemoteAudioElement().pause&&e.pauseElement(e.getRemoteAudioElement(),"remoteAudio"),e.assignElement(e.getRemoteAudioElement(),null,"remoteAudio")),e.getLocalVideoElement()&&(e.getLocalVideoElement().pause&&e.pauseElement(e.getLocalVideoElement(),"localVideo"),e.assignElement(e.getLocalVideoElement(),null,"localVideo")),e.hangupParty=t,e.hangupReason=r,h(e,"ended"),_(e),e.peerConn&&"closed"!==e.peerConn.signalingState&&e.peerConn.close(),n&&e.emit("hangup",e)},_=function(e){S("stopAllMedia (stream=%s)",e.localAVStream),e.localAVStream&&(A(e.localAVStream,function(e){e.stop&&e.stop()}),e.localAVStream.stop&&e.localAVStream.stop()),e.screenSharingStream&&(A(e.screenSharingStream,function(e){e.stop&&e.stop()}),e.screenSharingStream.stop&&e.screenSharingStream.stop()),e.remoteAVStream&&A(e.remoteAVStream,function(e){e.stop&&e.stop()}),e.remoteAStream&&A(e.remoteAStream,function(e){e.stop&&e.stop()})},g=function(e){if(e.getRemoteVideoElement()&&e.remoteAVStream){var t=e.getRemoteVideoElement();t.autoplay=!0,e.assignElement(t,e.remoteAVStream,"remoteVideo"),setTimeout(function(){var t=e.getRemoteVideoElement();t.play&&e.playElement(t,"remoteVideo"),e.webRtc.isOpenWebRTC()&&h(e,"connected")},0)}},b=function(){var e=(0,a.coroutine)(s.default.mark(function e(t){var r;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.getRemoteAudioElement()||!t.remoteAStream){e.next=8;break}if(r=t.getRemoteAudioElement(),!D){e.next=5;break}return e.next=5,(0,a.resolve)(r.setSinkId(D));case 5:r.autoplay=!0,t.assignElement(r,t.remoteAStream,"remoteAudio"),setTimeout(function(){var e=t.getRemoteAudioElement();e.play&&t.playElement(e,"remoteAudio"),t.webRtc.isOpenWebRTC()&&h(t,"connected")},0);case 8:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}(),E=function(e){if(0===e.listeners("error").length)throw new Error("You MUST attach an error listener using call.on('error', function() {})")},w=function(e,t){var r=new Error(t);return r.code=e,r},S=function(){var e;(e=console).log.apply(e,arguments)},k=function e(t){if(0!==t.candidateSendQueue.length){var r=t.candidateSendQueue;t.candidateSendQueue=[],++t.candidateSendTries;var n={version:0,call_id:t.callId,candidates:r};S("Attempting to send "+r.length+" candidates"),v(t,"m.call.candidates",n).then(function(){t.candidateSendTries=0,e(t)},function(n){for(var o=0;o<r.length;o++)t.candidateSendQueue.push(r[o]);if(t.candidateSendTries>5)return S("Failed to send candidates on attempt %s. Giving up for now.",t.candidateSendTries),void(t.candidateSendTries=0);var i=500*Math.pow(2,t.candidateSendTries);++t.candidateSendTries,S("Failed to send candidates. Retrying in "+i+"ms"),setTimeout(function(){e(t)},i)})}},T=function(e,t){e.client.callList[e.callId]=e,e.webRtc.getUserMedia(t,C(e,e._maybeGotUserMediaForInvite),C(e,e._maybeGotUserMediaForInvite)),h(e,"wait_local_media"),e.direction="outbound",e.config=t},x=function(e){var t=e.turnServers;if("mozilla"===e.webRtc.vendor){t=[];for(var r=0;r<e.turnServers.length;r++)for(var n=0;n<e.turnServers[r].urls.length;n++)t.push({url:e.turnServers[r].urls[n],username:e.turnServers[r].username,credential:e.turnServers[r].credential})}var o=new e.webRtc.RtcPeerConnection({iceTransportPolicy:e.forceTURN?"relay":void 0,iceServers:t});return o.oniceconnectionstatechange=C(e,e._onIceConnectionStateChanged),o.onsignalingstatechange=C(e,e._onSignallingStateChanged),o.onicecandidate=C(e,e._gotLocalIceCandidate),o.onaddstream=C(e,e._onAddStream),o},R=function(e){var t=r.screen;return t?{video:{mediaSource:"screen",mandatory:{chromeMediaSource:"screen",chromeMediaSourceId:""+Date.now(),maxWidth:t.width,maxHeight:t.height,minFrameRate:1,maxFrameRate:10}}}:void e.emit("error",w(o.ERR_NO_USER_MEDIA,"Couldn't determine screen sharing constaints."))},I=function(e){var t=!!r.window.navigator.webkitGetUserMedia;switch(e){case"voice":return{audio:{deviceId:M?{exact:M}:void 0},video:!1};case"video":return{audio:{deviceId:M?{exact:M}:void 0},video:{deviceId:P?{exact:P}:void 0,width:t?{exact:640}:{ideal:640},height:t?{exact:360}:{ideal:360}}}}},C=function(e,t){return function(){return t.apply(e,arguments)}},j=function(e,t){for(var r=e.getVideoTracks(),n=0;n<r.length;n++)t(r[n])},O=function(e,t){for(var r=e.getAudioTracks(),n=0;n<r.length;n++)t(r[n])},A=function(e,t){j(e,t),O(e,t)};t.exports.MatrixCall=o;var D=void 0,M=void 0,P=void 0;t.exports.setAudioOutput=function(e){D=e},t.exports.setAudioInput=function(e){M=e},t.exports.setVideoInput=function(e){P=e},t.exports.createNewMatrixCall=function(e,t,n){var i=r.window,s=r.document;if(!i||!s)return null;var a={};a.isOpenWebRTC=function(){var e=s.getElementById("script");if(!e||!e.length)return!1;for(var t=0;t<e.length;t++)if(e[t].src.indexOf("owr.js")>-1)return!0;return!1};var u=i.navigator.getUserMedia||i.navigator.webkitGetUserMedia||i.navigator.mozGetUserMedia;if(u&&(a.getUserMedia=function(){return u.apply(i.navigator,arguments)}),a.RtcPeerConnection=i.RTCPeerConnection||i.webkitRTCPeerConnection||i.mozRTCPeerConnection,a.RtcSessionDescription=i.RTCSessionDescription||i.webkitRTCSessionDescription||i.mozRTCSessionDescription,a.RtcIceCandidate=i.RTCIceCandidate||i.webkitRTCIceCandidate||i.mozRTCIceCandidate,a.vendor=null,i.mozRTCPeerConnection?a.vendor="mozilla":i.webkitRTCPeerConnection?a.vendor="webkit":i.RTCPeerConnection&&(a.vendor="generic"),!(a.RtcIceCandidate&&a.RtcSessionDescription&&a.RtcPeerConnection&&a.getUserMedia))return null;var c=!!n&&n.forceTURN;return new o({webRtc:a,client:e,URL:i.URL,roomId:t,turnServers:e.getTurnServers(),forceTURN:e._forceTURN||c})}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils":55,"babel-runtime/core-js/object/create":64,"babel-runtime/regenerator":86,bluebird:89,events:234}],57:[function(e,t,r){"use strict";function n(e){return a.lastIndex=0,e.replace(a,function(e){return u[e]})}function o(e){switch(typeof e){case"string":return'"'+n(e)+'"';case"number":return isFinite(e)?e:"null";case"boolean":return e;case"object":return null===e?"null":Array.isArray(e)?i(e):s(e);default:throw new Error("Cannot stringify: "+typeof e)}}function i(e){for(var t="[",r="",n=0;n<e.length;++n)r+=t,t=",",r+=o(e[n]);return","!=t?"[]":r+"]"}function s(e){var t="{",r="",i=Object.keys(e);i.sort();for(var s=0;s<i.length;++s){var a=i[s];r+=t+'"'+n(a)+'":',t=",",r+=o(e[a])}return","!=t?"{}":r+"}"}for(var a=/[\\\"\x00-\x1F]/g,u={},c=0;c<32;++c)u[String.fromCharCode(c)]="\\U"+("0000"+c.toString(16)).slice(-4).toUpperCase();u["\b"]="\\b",u["\t"]="\\t",u["\n"]="\\n",u["\f"]="\\f",u["\r"]="\\r",u['"']='\\"',u["\\"]="\\\\",t.exports={stringify:o}},{}],58:[function(e,t,r){t.exports={default:e("core-js/library/fn/get-iterator"),__esModule:!0}},{"core-js/library/fn/get-iterator":95}],59:[function(e,t,r){t.exports={default:e("core-js/library/fn/is-iterable"),__esModule:!0}},{"core-js/library/fn/is-iterable":96}],60:[function(e,t,r){t.exports={default:e("core-js/library/fn/json/stringify"),__esModule:!0}},{"core-js/library/fn/json/stringify":97}],61:[function(e,t,r){t.exports={default:e("core-js/library/fn/number/is-finite"),__esModule:!0}},{"core-js/library/fn/number/is-finite":98}],62:[function(e,t,r){t.exports={default:e("core-js/library/fn/number/is-integer"),__esModule:!0}},{"core-js/library/fn/number/is-integer":99}],63:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/assign"),__esModule:!0}},{"core-js/library/fn/object/assign":100}],64:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/create"),__esModule:!0}},{"core-js/library/fn/object/create":101}],65:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/define-property"),__esModule:!0}},{"core-js/library/fn/object/define-property":102}],66:[function(e,t,r){
t.exports={default:e("core-js/library/fn/object/entries"),__esModule:!0}},{"core-js/library/fn/object/entries":103}],67:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/freeze"),__esModule:!0}},{"core-js/library/fn/object/freeze":104}],68:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/get-prototype-of"),__esModule:!0}},{"core-js/library/fn/object/get-prototype-of":105}],69:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/keys"),__esModule:!0}},{"core-js/library/fn/object/keys":106}],70:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/set-prototype-of"),__esModule:!0}},{"core-js/library/fn/object/set-prototype-of":107}],71:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/values"),__esModule:!0}},{"core-js/library/fn/object/values":108}],72:[function(e,t,r){t.exports={default:e("core-js/library/fn/promise"),__esModule:!0}},{"core-js/library/fn/promise":109}],73:[function(e,t,r){t.exports={default:e("core-js/library/fn/reflect/construct"),__esModule:!0}},{"core-js/library/fn/reflect/construct":110}],74:[function(e,t,r){t.exports={default:e("core-js/library/fn/reflect/get-prototype-of"),__esModule:!0}},{"core-js/library/fn/reflect/get-prototype-of":111}],75:[function(e,t,r){t.exports={default:e("core-js/library/fn/reflect/set-prototype-of"),__esModule:!0}},{"core-js/library/fn/reflect/set-prototype-of":112}],76:[function(e,t,r){t.exports={default:e("core-js/library/fn/set"),__esModule:!0}},{"core-js/library/fn/set":113}],77:[function(e,t,r){t.exports={default:e("core-js/library/fn/symbol"),__esModule:!0}},{"core-js/library/fn/symbol":114}],78:[function(e,t,r){t.exports={default:e("core-js/library/fn/symbol/iterator"),__esModule:!0}},{"core-js/library/fn/symbol/iterator":115}],79:[function(e,t,r){"use strict";r.__esModule=!0,r.default=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},{}],80:[function(e,t,r){"use strict";r.__esModule=!0;var n=e("../core-js/object/define-property"),o=function(e){return e&&e.__esModule?e:{default:e}}(n);r.default=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),(0,o.default)(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}()},{"../core-js/object/define-property":65}],81:[function(e,t,r){"use strict";r.__esModule=!0;var n=e("../core-js/object/define-property"),o=function(e){return e&&e.__esModule?e:{default:e}}(n);r.default=function(e,t,r){return t in e?(0,o.default)(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}},{"../core-js/object/define-property":65}],82:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}r.__esModule=!0;var o=e("../core-js/object/set-prototype-of"),i=n(o),s=e("../core-js/object/create"),a=n(s),u=e("../helpers/typeof"),c=n(u);r.default=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+(void 0===t?"undefined":(0,c.default)(t)));e.prototype=(0,a.default)(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(i.default?(0,i.default)(e,t):e.__proto__=t)}},{"../core-js/object/create":64,"../core-js/object/set-prototype-of":70,"../helpers/typeof":85}],83:[function(e,t,r){"use strict";r.__esModule=!0;var n=e("../helpers/typeof"),o=function(e){return e&&e.__esModule?e:{default:e}}(n);r.default=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==(void 0===t?"undefined":(0,o.default)(t))&&"function"!=typeof t?e:t}},{"../helpers/typeof":85}],84:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}r.__esModule=!0;var o=e("../core-js/is-iterable"),i=n(o),s=e("../core-js/get-iterator"),a=n(s);r.default=function(){function e(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var s,u=(0,a.default)(e);!(n=(s=u.next()).done)&&(r.push(s.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}return r}return function(t,r){if(Array.isArray(t))return t;if((0,i.default)(Object(t)))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}()},{"../core-js/get-iterator":58,"../core-js/is-iterable":59}],85:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}r.__esModule=!0;var o=e("../core-js/symbol/iterator"),i=n(o),s=e("../core-js/symbol"),a=n(s),u="function"==typeof a.default&&"symbol"==typeof i.default?function(e){return typeof e}:function(e){return e&&"function"==typeof a.default&&e.constructor===a.default&&e!==a.default.prototype?"symbol":typeof e};r.default="function"==typeof a.default&&"symbol"===u(i.default)?function(e){return void 0===e?"undefined":u(e)}:function(e){return e&&"function"==typeof a.default&&e.constructor===a.default&&e!==a.default.prototype?"symbol":void 0===e?"undefined":u(e)}},{"../core-js/symbol":77,"../core-js/symbol/iterator":78}],86:[function(e,t,r){t.exports=e("regenerator-runtime")},{"regenerator-runtime":246}],87:[function(e,t,r){var n=e("safe-buffer").Buffer;t.exports=function(e){function t(t){if(0===t.length)return"";for(var r=[0],n=0;n<t.length;++n){for(var o=0,i=t[n];o<r.length;++o)i+=r[o]<<8,r[o]=i%s,i=i/s|0;for(;i>0;)r.push(i%s),i=i/s|0}for(var u="",c=0;0===t[c]&&c<t.length-1;++c)u+=a;for(var l=r.length-1;l>=0;--l)u+=e[r[l]];return u}function r(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return n.allocUnsafe(0);for(var t=[0],r=0;r<e.length;r++){var o=i[e[r]];if(void 0===o)return;for(var u=0,c=o;u<t.length;++u)c+=t[u]*s,t[u]=255&c,c>>=8;for(;c>0;)t.push(255&c),c>>=8}for(var l=0;e[l]===a&&l<e.length-1;++l)t.push(0);return n.from(t.reverse())}function o(e){var t=r(e);if(t)return t;throw new Error("Non-base"+s+" character")}for(var i={},s=e.length,a=e.charAt(0),u=0;u<e.length;u++){var c=e.charAt(u);if(void 0!==i[c])throw new TypeError(c+" is ambiguous");i[c]=u}return{encode:t,decodeUnsafe:r,decode:o}}},{"safe-buffer":248}],88:[function(e,t,r){"use strict";function n(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function o(e){var t=n(e),r=t[0],o=t[1];return 3*(r+o)/4-o}function i(e,t,r){return 3*(t+r)/4-r}function s(e){for(var t,r=n(e),o=r[0],s=r[1],a=new f(i(e,o,s)),u=0,c=s>0?o-4:o,l=0;l<c;l+=4)t=d[e.charCodeAt(l)]<<18|d[e.charCodeAt(l+1)]<<12|d[e.charCodeAt(l+2)]<<6|d[e.charCodeAt(l+3)],a[u++]=t>>16&255,a[u++]=t>>8&255,a[u++]=255&t;return 2===s&&(t=d[e.charCodeAt(l)]<<2|d[e.charCodeAt(l+1)]>>4,a[u++]=255&t),1===s&&(t=d[e.charCodeAt(l)]<<10|d[e.charCodeAt(l+1)]<<4|d[e.charCodeAt(l+2)]>>2,a[u++]=t>>8&255,a[u++]=255&t),a}function a(e){return l[e>>18&63]+l[e>>12&63]+l[e>>6&63]+l[63&e]}function u(e,t,r){for(var n,o=[],i=t;i<r;i+=3)n=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(a(n));return o.join("")}function c(e){for(var t,r=e.length,n=r%3,o=[],i=0,s=r-n;i<s;i+=16383)o.push(u(e,i,i+16383>s?s:i+16383));return 1===n?(t=e[r-1],o.push(l[t>>2]+l[t<<4&63]+"==")):2===n&&(t=(e[r-2]<<8)+e[r-1],o.push(l[t>>10]+l[t>>4&63]+l[t<<2&63]+"=")),o.join("")}r.byteLength=o,r.toByteArray=s,r.fromByteArray=c;for(var l=[],d=[],f="undefined"!=typeof Uint8Array?Uint8Array:Array,p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=0,v=p.length;h<v;++h)l[h]=p[h],d[p.charCodeAt(h)]=h;d["-".charCodeAt(0)]=62,d["_".charCodeAt(0)]=63},{}],89:[function(e,t,r){(function(e,n,o){!function(e){if("object"==typeof r&&void 0!==t)t.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:void 0!==n?o=n:"undefined"!=typeof self&&(o=self),o.Promise=e()}}(function(){var t,r,i;return function e(t,r,n){function o(s,a){if(!r[s]){if(!t[s]){var u="function"==typeof _dereq_&&_dereq_;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=r[s]={exports:{}};t[s][0].call(l.exports,function(e){var r=t[s][1][e];return o(r||e)},l,l.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof _dereq_&&_dereq_,s=0;s<n.length;s++)o(n[s]);return o}({1:[function(e,t,r){"use strict";t.exports=function(e){function t(e){var t=new r(e),n=t.promise();return t.setHowMany(1),t.setUnwrap(),t.init(),n}var r=e._SomePromiseArray;e.any=function(e){return t(e)},e.prototype.any=function(){return t(this)}}},{}],2:[function(t,r,n){"use strict";function o(){this._customScheduler=!1,this._isTickUsed=!1,this._lateQueue=new f(16),this._normalQueue=new f(16),this._haveDrainedQueues=!1,this._trampolineEnabled=!0;var e=this;this.drainQueues=function(){e._drainQueues()},this._schedule=d}function i(e,t,r){this._lateQueue.push(e,t,r),this._queueTick()}function s(e,t,r){this._normalQueue.push(e,t,r),this._queueTick()}function a(e){this._normalQueue._pushOne(e),this._queueTick()}function u(e){for(;e.length()>0;)c(e)}function c(e){var t=e.shift();if("function"!=typeof t)t._settlePromises();else{var r=e.shift(),n=e.shift();t.call(r,n)}}var l;try{throw new Error}catch(e){l=e}var d=t("./schedule"),f=t("./queue"),p=t("./util");o.prototype.setScheduler=function(e){var t=this._schedule;return this._schedule=e,this._customScheduler=!0,t},o.prototype.hasCustomScheduler=function(){return this._customScheduler},o.prototype.enableTrampoline=function(){this._trampolineEnabled=!0},o.prototype.disableTrampolineIfNecessary=function(){p.hasDevTools&&(this._trampolineEnabled=!1)},o.prototype.haveItemsQueued=function(){return this._isTickUsed||this._haveDrainedQueues},o.prototype.fatalError=function(t,r){r?(e.stderr.write("Fatal "+(t instanceof Error?t.stack:t)+"\n"),e.exit(2)):this.throwLater(t)},o.prototype.throwLater=function(e,t){if(1===arguments.length&&(t=e,e=function(){throw t}),"undefined"!=typeof setTimeout)setTimeout(function(){e(t)},0);else try{this._schedule(function(){e(t)})}catch(e){throw new Error("No async scheduler available\n\n See http://goo.gl/MqrFmX\n")}},p.hasDevTools?(o.prototype.invokeLater=function(e,t,r){this._trampolineEnabled?i.call(this,e,t,r):this._schedule(function(){setTimeout(function(){e.call(t,r)},100)})},o.prototype.invoke=function(e,t,r){this._trampolineEnabled?s.call(this,e,t,r):this._schedule(function(){e.call(t,r)})},o.prototype.settlePromises=function(e){this._trampolineEnabled?a.call(this,e):this._schedule(function(){e._settlePromises()})}):(o.prototype.invokeLater=i,o.prototype.invoke=s,o.prototype.settlePromises=a),o.prototype._drainQueues=function(){u(this._normalQueue),this._reset(),this._haveDrainedQueues=!0,u(this._lateQueue)},o.prototype._queueTick=function(){this._isTickUsed||(this._isTickUsed=!0,this._schedule(this.drainQueues))},o.prototype._reset=function(){this._isTickUsed=!1},r.exports=o,r.exports.firstLineError=l},{"./queue":26,"./schedule":29,"./util":36}],3:[function(e,t,r){"use strict";t.exports=function(e,t,r,n){var o=!1,i=function(e,t){this._reject(t)},s=function(e,t){t.promiseRejectionQueued=!0,t.bindingPromise._then(i,i,null,this,e)},a=function(e,t){0==(50397184&this._bitField)&&this._resolveCallback(t.target)},u=function(e,t){t.promiseRejectionQueued||this._reject(e)};e.prototype.bind=function(i){o||(o=!0,e.prototype._propagateFrom=n.propagateFromFunction(),e.prototype._boundValue=n.boundValueFunction());var c=r(i),l=new e(t);l._propagateFrom(this,1);var d=this._target();if(l._setBoundTo(c),c instanceof e){var f={promiseRejectionQueued:!1,promise:l,target:d,bindingPromise:c};d._then(t,s,void 0,l,f),c._then(a,u,void 0,l,f),l._setOnCancel(c)}else l._resolveCallback(d);return l},e.prototype._setBoundTo=function(e){void 0!==e?(this._bitField=2097152|this._bitField,this._boundTo=e):this._bitField=-2097153&this._bitField},e.prototype._isBound=function(){return 2097152==(2097152&this._bitField)},e.bind=function(t,r){return e.resolve(r).bind(t)}}},{}],4:[function(e,t,r){"use strict";function n(){try{Promise===i&&(Promise=o)}catch(e){}return i}var o;"undefined"!=typeof Promise&&(o=Promise);var i=e("./promise")();i.noConflict=n,t.exports=i},{"./promise":22}],5:[function(e,t,r){"use strict";var n=Object.create;if(n){var o=n(null),i=n(null);o[" size"]=i[" size"]=0}t.exports=function(t){function r(e,r){var n;if(null!=e&&(n=e[r]),"function"!=typeof n){var o="Object "+a.classString(e)+" has no method '"+a.toString(r)+"'";throw new t.TypeError(o)}return n}function n(e){return r(e,this.pop()).apply(e,this)}function o(e){return e[this]}function i(e){var t=+this;return t<0&&(t=Math.max(0,t+e.length)),e[t]}var s,a=e("./util"),u=a.canEvaluate;a.isIdentifier;t.prototype.call=function(e){var t=[].slice.call(arguments,1);return t.push(e),this._then(n,void 0,void 0,t,void 0)},t.prototype.get=function(e){var t,r="number"==typeof e;if(r)t=i;else if(u){var n=s(e);t=null!==n?n:o}else t=o;return this._then(t,void 0,void 0,e,void 0)}}},{"./util":36}],6:[function(e,t,r){"use strict";t.exports=function(t,r,n,o){var i=e("./util"),s=i.tryCatch,a=i.errorObj,u=t._async;t.prototype.break=t.prototype.cancel=function(){if(!o.cancellation())return this._warn("cancellation is disabled");for(var e=this,t=e;e._isCancellable();){if(!e._cancelBy(t)){t._isFollowing()?t._followee().cancel():t._cancelBranched();break}var r=e._cancellationParent;if(null==r||!r._isCancellable()){e._isFollowing()?e._followee().cancel():e._cancelBranched();break}e._isFollowing()&&e._followee().cancel(),e._setWillBeCancelled(),t=e,e=r}},t.prototype._branchHasCancelled=function(){this._branchesRemainingToCancel--},t.prototype._enoughBranchesHaveCancelled=function(){return void 0===this._branchesRemainingToCancel||this._branchesRemainingToCancel<=0},t.prototype._cancelBy=function(e){return e===this?(this._branchesRemainingToCancel=0,this._invokeOnCancel(),!0):(this._branchHasCancelled(),!!this._enoughBranchesHaveCancelled()&&(this._invokeOnCancel(),!0))},t.prototype._cancelBranched=function(){this._enoughBranchesHaveCancelled()&&this._cancel()},t.prototype._cancel=function(){this._isCancellable()&&(this._setCancelled(),u.invoke(this._cancelPromises,this,void 0))},t.prototype._cancelPromises=function(){this._length()>0&&this._settlePromises()},t.prototype._unsetOnCancel=function(){this._onCancelField=void 0},t.prototype._isCancellable=function(){return this.isPending()&&!this._isCancelled()},t.prototype.isCancellable=function(){return this.isPending()&&!this.isCancelled()},t.prototype._doInvokeOnCancel=function(e,t){if(i.isArray(e))for(var r=0;r<e.length;++r)this._doInvokeOnCancel(e[r],t);else if(void 0!==e)if("function"==typeof e){if(!t){var n=s(e).call(this._boundValue());n===a&&(this._attachExtraTrace(n.e),u.throwLater(n.e))}}else e._resultCancelled(this)},t.prototype._invokeOnCancel=function(){var e=this._onCancel();this._unsetOnCancel(),u.invoke(this._doInvokeOnCancel,this,e)},t.prototype._invokeInternalOnCancel=function(){this._isCancellable()&&(this._doInvokeOnCancel(this._onCancel(),!0),this._unsetOnCancel())},t.prototype._resultCancelled=function(){this.cancel()}}},{"./util":36}],7:[function(e,t,r){"use strict";t.exports=function(t){function r(e,r,a){return function(u){var c=a._boundValue();e:for(var l=0;l<e.length;++l){var d=e[l];if(d===Error||null!=d&&d.prototype instanceof Error){if(u instanceof d)return i(r).call(c,u)}else if("function"==typeof d){var f=i(d).call(c,u);if(f===s)return f;if(f)return i(r).call(c,u)}else if(n.isObject(u)){for(var p=o(d),h=0;h<p.length;++h){var v=p[h];if(d[v]!=u[v])continue e}return i(r).call(c,u)}}return t}}var n=e("./util"),o=e("./es5").keys,i=n.tryCatch,s=n.errorObj;return r}},{"./es5":13,"./util":36}],8:[function(e,t,r){"use strict";t.exports=function(e){function t(){this._trace=new t.CapturedTrace(n())}function r(){if(o)return new t}function n(){var e=i.length-1;if(e>=0)return i[e]}var o=!1,i=[];return e.prototype._promiseCreated=function(){},e.prototype._pushContext=function(){},e.prototype._popContext=function(){return null},e._peekContext=e.prototype._peekContext=function(){},t.prototype._pushContext=function(){void 0!==this._trace&&(this._trace._promiseCreated=null,i.push(this._trace))},t.prototype._popContext=function(){if(void 0!==this._trace){var e=i.pop(),t=e._promiseCreated;return e._promiseCreated=null,t}return null},t.CapturedTrace=null,t.create=r,t.deactivateLongStackTraces=function(){},t.activateLongStackTraces=function(){var r=e.prototype._pushContext,i=e.prototype._popContext,s=e._peekContext,a=e.prototype._peekContext,u=e.prototype._promiseCreated;t.deactivateLongStackTraces=function(){e.prototype._pushContext=r,e.prototype._popContext=i,e._peekContext=s,e.prototype._peekContext=a,e.prototype._promiseCreated=u,o=!1},o=!0,e.prototype._pushContext=t.prototype._pushContext,e.prototype._popContext=t.prototype._popContext,e._peekContext=e.prototype._peekContext=n,e.prototype._promiseCreated=function(){var e=this._peekContext();e&&null==e._promiseCreated&&(e._promiseCreated=this)}},t}},{}],9:[function(t,r,n){"use strict";r.exports=function(r,n){function o(e,t){return{promise:t}}function i(){return!1}function s(e,t,r){var n=this;try{e(t,r,function(e){if("function"!=typeof e)throw new TypeError("onCancel must be a function, got: "+q.toString(e));n._attachCancellationCallback(e)})}catch(e){return e}}function a(e){if(!this._isCancellable())return this;var t=this._onCancel();void 0!==t?q.isArray(t)?t.push(e):this._setOnCancel([t,e]):this._setOnCancel(e)}function u(){return this._onCancelField}function c(e){this._onCancelField=e}function l(){this._cancellationParent=void 0,this._onCancelField=void 0}function d(e,t){if(0!=(1&t)){this._cancellationParent=e;var r=e._branchesRemainingToCancel;void 0===r&&(r=0),e._branchesRemainingToCancel=r+1}0!=(2&t)&&e._isBound()&&this._setBoundTo(e._boundTo)}function f(e,t){0!=(2&t)&&e._isBound()&&this._setBoundTo(e._boundTo)}function p(){var e=this._boundTo;return void 0!==e&&e instanceof r?e.isFulfilled()?e.value():void 0:e}function h(){this._trace=new D(this._peekContext())}function v(e,t){if(K(e)){var r=this._trace;if(void 0!==r&&t&&(r=r._parent),void 0!==r)r.attachExtraTrace(e);else if(!e.__stackCleaned__){var n=T(e);q.notEnumerableProp(e,"stack",n.message+"\n"+n.stack.join("\n")),q.notEnumerableProp(e,"__stackCleaned__",!0)}}}function m(){this._trace=void 0}function y(e,t,r,n,o){if(void 0===e&&null!==t&&X){if(void 0!==o&&o._returnedNonUndefined())return;if(0==(65535&n._bitField))return;r&&(r+=" ");var i="",s="";if(t._trace){for(var a=t._trace.stack.split("\n"),u=S(a),c=u.length-1;c>=0;--c){var l=u[c];if(!$.test(l)){var d=l.match(V);d&&(i="at "+d[1]+":"+d[2]+":"+d[3]+" ");break}}if(u.length>0)for(var f=u[0],c=0;c<a.length;++c)if(a[c]===f){c>0&&(s="\n"+a[c-1]);break}}var p="a promise was created in a "+r+"handler "+i+"but was not returned from it, see http://goo.gl/rRqMUw"+s;n._warn(p,!0,t)}}function _(e,t){var r=e+" is deprecated and will be removed in a future version.";return t&&(r+=" Use "+t+" instead."),g(r)}function g(e,t,n){if(ue.warnings){var o,i=new F(e);if(t)n._attachExtraTrace(i);else if(ue.longStackTraces&&(o=r._peekContext()))o.attachExtraTrace(i);else{var s=T(i);i.stack=s.message+"\n"+s.stack.join("\n")}ne("warning",i)||x(i,"",!0)}}function b(e,t){for(var r=0;r<t.length-1;++r)t[r].push("From previous event:"),t[r]=t[r].join("\n");return r<t.length&&(t[r]=t[r].join("\n")),e+"\n"+t.join("\n")}function E(e){for(var t=0;t<e.length;++t)(0===e[t].length||t+1<e.length&&e[t][0]===e[t+1][0])&&(e.splice(t,1),t--)}function w(e){for(var t=e[0],r=1;r<e.length;++r){for(var n=e[r],o=t.length-1,i=t[o],s=-1,a=n.length-1;a>=0;--a)if(n[a]===i){s=a;break}for(var a=s;a>=0;--a){var u=n[a];if(t[o]!==u)break;t.pop(),o--}t=n}}function S(e){for(var t=[],r=0;r<e.length;++r){var n=e[r],o=" (No stack trace)"===n||W.test(n),i=o&&ie(n);o&&!i&&(z&&" "!==n.charAt(0)&&(n=" "+n),t.push(n))}return t}function k(e){for(var t=e.stack.replace(/\s+$/g,"").split("\n"),r=0;r<t.length;++r){var n=t[r];if(" (No stack trace)"===n||W.test(n))break}return r>0&&"SyntaxError"!=e.name&&(t=t.slice(r)),t}function T(e){var t=e.stack,r=e.toString();return t="string"==typeof t&&t.length>0?k(e):[" (No stack trace)"],{message:r,stack:"SyntaxError"==e.name?t:S(t)}}function x(e,t,r){if("undefined"!=typeof console){var n;if(q.isObject(e)){var o=e.stack;n=t+H(o,e)}else n=t+String(e);"function"==typeof L?L(n,r):"function"!=typeof console.log&&"object"!=typeof console.log||console.log(n)}}function R(e,t,r,n){var o=!1;try{"function"==typeof t&&(o=!0,"rejectionHandled"===e?t(n):t(r,n))}catch(e){N.throwLater(e)}"unhandledRejection"===e?ne(e,r,n)||o||x(r,"Unhandled rejection "):ne(e,n)}function I(e){var t;if("function"==typeof e)t="[function "+(e.name||"anonymous")+"]";else{t=e&&"function"==typeof e.toString?e.toString():q.toString(e);if(/\[object [a-zA-Z0-9$_]+\]/.test(t))try{t=JSON.stringify(e)}catch(e){}0===t.length&&(t="(empty array)")}return"(<"+C(t)+">, no stack trace)"}function C(e){return e.length<41?e:e.substr(0,38)+"..."}function j(){return"function"==typeof ae}function O(e){var t=e.match(se);if(t)return{fileName:t[1],line:parseInt(t[2],10)}}function A(e,t){if(j()){for(var r,n,o=e.stack.split("\n"),i=t.stack.split("\n"),s=-1,a=-1,u=0;u<o.length;++u){var c=O(o[u]);if(c){r=c.fileName,s=c.line;break}}for(var u=0;u<i.length;++u){var c=O(i[u]);if(c){n=c.fileName,a=c.line;break}}s<0||a<0||!r||!n||r!==n||s>=a||(ie=function(e){if(G.test(e))return!0;var t=O(e);return!!(t&&t.fileName===r&&s<=t.line&&t.line<=a)})}}function D(e){this._parent=e,this._promisesCreated=0;var t=this._length=1+(void 0===e?0:e._length);ae(this,D),t>32&&this.uncycle()}var M,P,L,U=r._getDomain,N=r._async,F=t("./errors").Warning,q=t("./util"),B=t("./es5"),K=q.canAttachTrace,G=/[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/,$=/\((?:timers\.js):\d+:\d+\)/,V=/[\/<\(](.+?):(\d+):(\d+)\)?\s*$/,W=null,H=null,z=!1,Q=!(0==q.env("BLUEBIRD_DEBUG")),J=!(0==q.env("BLUEBIRD_WARNINGS")||!Q&&!q.env("BLUEBIRD_WARNINGS")),Y=!(0==q.env("BLUEBIRD_LONG_STACK_TRACES")||!Q&&!q.env("BLUEBIRD_LONG_STACK_TRACES")),X=0!=q.env("BLUEBIRD_W_FORGOTTEN_RETURN")&&(J||!!q.env("BLUEBIRD_W_FORGOTTEN_RETURN"));r.prototype.suppressUnhandledRejections=function(){var e=this._target();e._bitField=-1048577&e._bitField|524288},r.prototype._ensurePossibleRejectionHandled=function(){if(0==(524288&this._bitField)){this._setRejectionIsUnhandled();var e=this;setTimeout(function(){e._notifyUnhandledRejection()},1)}},r.prototype._notifyUnhandledRejectionIsHandled=function(){R("rejectionHandled",M,void 0,this)},r.prototype._setReturnedNonUndefined=function(){this._bitField=268435456|this._bitField},r.prototype._returnedNonUndefined=function(){return 0!=(268435456&this._bitField)},r.prototype._notifyUnhandledRejection=function(){if(this._isRejectionUnhandled()){var e=this._settledValue();this._setUnhandledRejectionIsNotified(),R("unhandledRejection",P,e,this)}},r.prototype._setUnhandledRejectionIsNotified=function(){this._bitField=262144|this._bitField},r.prototype._unsetUnhandledRejectionIsNotified=function(){this._bitField=-262145&this._bitField},r.prototype._isUnhandledRejectionNotified=function(){return(262144&this._bitField)>0},r.prototype._setRejectionIsUnhandled=function(){this._bitField=1048576|this._bitField},r.prototype._unsetRejectionIsUnhandled=function(){this._bitField=-1048577&this._bitField,this._isUnhandledRejectionNotified()&&(this._unsetUnhandledRejectionIsNotified(),this._notifyUnhandledRejectionIsHandled())},r.prototype._isRejectionUnhandled=function(){return(1048576&this._bitField)>0},r.prototype._warn=function(e,t,r){return g(e,t,r||this)},r.onPossiblyUnhandledRejection=function(e){var t=U();P="function"==typeof e?null===t?e:q.domainBind(t,e):void 0},r.onUnhandledRejectionHandled=function(e){var t=U();M="function"==typeof e?null===t?e:q.domainBind(t,e):void 0};var Z=function(){};r.longStackTraces=function(){if(N.haveItemsQueued()&&!ue.longStackTraces)throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/MqrFmX\n");if(!ue.longStackTraces&&j()){var e=r.prototype._captureStackTrace,t=r.prototype._attachExtraTrace,o=r.prototype._dereferenceTrace;ue.longStackTraces=!0,Z=function(){if(N.haveItemsQueued()&&!ue.longStackTraces)throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/MqrFmX\n");r.prototype._captureStackTrace=e,r.prototype._attachExtraTrace=t,r.prototype._dereferenceTrace=o,n.deactivateLongStackTraces(),N.enableTrampoline(),ue.longStackTraces=!1},r.prototype._captureStackTrace=h,r.prototype._attachExtraTrace=v,r.prototype._dereferenceTrace=m,n.activateLongStackTraces(),N.disableTrampolineIfNecessary()}},r.hasLongStackTraces=function(){return ue.longStackTraces&&j()};var ee=function(){try{if("function"==typeof CustomEvent){var e=new CustomEvent("CustomEvent");return q.global.dispatchEvent(e),function(e,t){var r={detail:t,cancelable:!0};B.defineProperty(r,"promise",{value:t.promise}),B.defineProperty(r,"reason",{value:t.reason});var n=new CustomEvent(e.toLowerCase(),r);return!q.global.dispatchEvent(n)}}if("function"==typeof Event){var e=new Event("CustomEvent");return q.global.dispatchEvent(e),function(e,t){var r=new Event(e.toLowerCase(),{cancelable:!0});return r.detail=t,B.defineProperty(r,"promise",{value:t.promise}),B.defineProperty(r,"reason",{value:t.reason}),!q.global.dispatchEvent(r)}}var e=document.createEvent("CustomEvent");return e.initCustomEvent("testingtheevent",!1,!0,{}),q.global.dispatchEvent(e),function(e,t){var r=document.createEvent("CustomEvent");return r.initCustomEvent(e.toLowerCase(),!1,!0,t),!q.global.dispatchEvent(r)}}catch(e){}return function(){return!1}}(),te=function(){return q.isNode?function(){return e.emit.apply(e,arguments)}:q.global?function(e){var t="on"+e.toLowerCase(),r=q.global[t];return!!r&&(r.apply(q.global,[].slice.call(arguments,1)),!0)}:function(){return!1}}(),re={promiseCreated:o,promiseFulfilled:o,promiseRejected:o,promiseResolved:o,promiseCancelled:o,promiseChained:function(e,t,r){return{promise:t,child:r}},warning:function(e,t){return{warning:t}},unhandledRejection:function(e,t,r){return{reason:t,promise:r}},rejectionHandled:o},ne=function(e){var t=!1;try{t=te.apply(null,arguments)}catch(e){N.throwLater(e),t=!0}var r=!1;try{r=ee(e,re[e].apply(null,arguments))}catch(e){N.throwLater(e),r=!0}return r||t};r.config=function(e){if(e=Object(e),"longStackTraces"in e&&(e.longStackTraces?r.longStackTraces():!e.longStackTraces&&r.hasLongStackTraces()&&Z()),"warnings"in e){var t=e.warnings;ue.warnings=!!t,X=ue.warnings,q.isObject(t)&&"wForgottenReturn"in t&&(X=!!t.wForgottenReturn)}if("cancellation"in e&&e.cancellation&&!ue.cancellation){if(N.haveItemsQueued())throw new Error("cannot enable cancellation after promises are in use");r.prototype._clearCancellationData=l,r.prototype._propagateFrom=d,r.prototype._onCancel=u,r.prototype._setOnCancel=c,r.prototype._attachCancellationCallback=a,r.prototype._execute=s,oe=d,ue.cancellation=!0}return"monitoring"in e&&(e.monitoring&&!ue.monitoring?(ue.monitoring=!0,r.prototype._fireEvent=ne):!e.monitoring&&ue.monitoring&&(ue.monitoring=!1,r.prototype._fireEvent=i)),r},r.prototype._fireEvent=i,r.prototype._execute=function(e,t,r){try{e(t,r)}catch(e){return e}},r.prototype._onCancel=function(){},r.prototype._setOnCancel=function(e){},r.prototype._attachCancellationCallback=function(e){},r.prototype._captureStackTrace=function(){},r.prototype._attachExtraTrace=function(){},r.prototype._dereferenceTrace=function(){},r.prototype._clearCancellationData=function(){},r.prototype._propagateFrom=function(e,t){};var oe=f,ie=function(){return!1},se=/[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;q.inherits(D,Error),n.CapturedTrace=D,D.prototype.uncycle=function(){var e=this._length;if(!(e<2)){for(var t=[],r={},n=0,o=this;void 0!==o;++n)t.push(o),o=o._parent;e=this._length=n;for(var n=e-1;n>=0;--n){var i=t[n].stack;void 0===r[i]&&(r[i]=n)}for(var n=0;n<e;++n){var s=t[n].stack,a=r[s];if(void 0!==a&&a!==n){a>0&&(t[a-1]._parent=void 0,t[a-1]._length=1),t[n]._parent=void 0,t[n]._length=1;var u=n>0?t[n-1]:this;a<e-1?(u._parent=t[a+1],u._parent.uncycle(),u._length=u._parent._length+1):(u._parent=void 0,u._length=1);for(var c=u._length+1,l=n-2;l>=0;--l)t[l]._length=c,c++;return}}}},D.prototype.attachExtraTrace=function(e){if(!e.__stackCleaned__){this.uncycle();for(var t=T(e),r=t.message,n=[t.stack],o=this;void 0!==o;)n.push(S(o.stack.split("\n"))),o=o._parent;w(n),E(n),q.notEnumerableProp(e,"stack",b(r,n)),q.notEnumerableProp(e,"__stackCleaned__",!0)}};var ae=function(){var e=/^\s*at\s*/,t=function(e,t){return"string"==typeof e?e:void 0!==t.name&&void 0!==t.message?t.toString():I(t)};if("number"==typeof Error.stackTraceLimit&&"function"==typeof Error.captureStackTrace){Error.stackTraceLimit+=6,W=e,H=t;var r=Error.captureStackTrace;return ie=function(e){return G.test(e)},function(e,t){Error.stackTraceLimit+=6,r(e,t),Error.stackTraceLimit-=6}}var n=new Error;if("string"==typeof n.stack&&n.stack.split("\n")[0].indexOf("stackDetection@")>=0)return W=/@/,H=t,z=!0,function(e){e.stack=(new Error).stack};var o;try{throw new Error}catch(e){o="stack"in e}return"stack"in n||!o||"number"!=typeof Error.stackTraceLimit?(H=function(e,t){return"string"==typeof e?e:"object"!=typeof t&&"function"!=typeof t||void 0===t.name||void 0===t.message?I(t):t.toString()},null):(W=e,H=t,function(e){Error.stackTraceLimit+=6;try{throw new Error}catch(t){e.stack=t.stack}Error.stackTraceLimit-=6})}();"undefined"!=typeof console&&void 0!==console.warn&&(L=function(e){console.warn(e)},q.isNode&&e.stderr.isTTY?L=function(e,t){var r=t?"":"";console.warn(r+e+"\n")}:q.isNode||"string"!=typeof(new Error).stack||(L=function(e,t){console.warn("%c"+e,t?"color: darkorange":"color: red")}));var ue={warnings:J,longStackTraces:!1,cancellation:!1,monitoring:!1};return Y&&r.longStackTraces(),{longStackTraces:function(){return ue.longStackTraces},warnings:function(){return ue.warnings},cancellation:function(){return ue.cancellation},monitoring:function(){return ue.monitoring},propagateFromFunction:function(){return oe},boundValueFunction:function(){return p},checkForgottenReturns:y,setBounds:A,warn:g,deprecated:_,CapturedTrace:D,fireDomEvent:ee,fireGlobalEvent:te}}},{"./errors":12,"./es5":13,"./util":36}],10:[function(e,t,r){"use strict";t.exports=function(e){function t(){return this.value}function r(){throw this.reason}e.prototype.return=e.prototype.thenReturn=function(r){return r instanceof e&&r.suppressUnhandledRejections(),this._then(t,void 0,void 0,{value:r},void 0)},e.prototype.throw=e.prototype.thenThrow=function(e){return this._then(r,void 0,void 0,{reason:e},void 0)},e.prototype.catchThrow=function(e){if(arguments.length<=1)return this._then(void 0,r,void 0,{reason:e},void 0);var t=arguments[1],n=function(){throw t};return this.caught(e,n)},e.prototype.catchReturn=function(r){if(arguments.length<=1)return r instanceof e&&r.suppressUnhandledRejections(),this._then(void 0,t,void 0,{value:r},void 0);var n=arguments[1];n instanceof e&&n.suppressUnhandledRejections();var o=function(){return n};return this.caught(r,o)}}},{}],11:[function(e,t,r){"use strict";t.exports=function(e,t){function r(){return i(this)}function n(e,r){return o(e,r,t,t)}var o=e.reduce,i=e.all;e.prototype.each=function(e){return o(this,e,t,0)._then(r,void 0,void 0,this,void 0)},e.prototype.mapSeries=function(e){return o(this,e,t,t)},e.each=function(e,n){return o(e,n,t,0)._then(r,void 0,void 0,e,void 0)},e.mapSeries=n}},{}],12:[function(e,t,r){"use strict";function n(e,t){function r(n){if(!(this instanceof r))return new r(n);d(this,"message","string"==typeof n?n:t),d(this,"name",e),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):Error.call(this)}return l(r,Error),r}function o(e){if(!(this instanceof o))return new o(e);d(this,"name","OperationalError"),d(this,"message",e),this.cause=e,this.isOperational=!0,
e instanceof Error?(d(this,"message",e.message),d(this,"stack",e.stack)):Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}var i,s,a=e("./es5"),u=a.freeze,c=e("./util"),l=c.inherits,d=c.notEnumerableProp,f=n("Warning","warning"),p=n("CancellationError","cancellation error"),h=n("TimeoutError","timeout error"),v=n("AggregateError","aggregate error");try{i=TypeError,s=RangeError}catch(e){i=n("TypeError","type error"),s=n("RangeError","range error")}for(var m="join pop push shift unshift slice filter forEach some every map indexOf lastIndexOf reduce reduceRight sort reverse".split(" "),y=0;y<m.length;++y)"function"==typeof Array.prototype[m[y]]&&(v.prototype[m[y]]=Array.prototype[m[y]]);a.defineProperty(v.prototype,"length",{value:0,configurable:!1,writable:!0,enumerable:!0}),v.prototype.isOperational=!0;var _=0;v.prototype.toString=function(){var e=Array(4*_+1).join(" "),t="\n"+e+"AggregateError of:\n";_++,e=Array(4*_+1).join(" ");for(var r=0;r<this.length;++r){for(var n=this[r]===this?"[Circular AggregateError]":this[r]+"",o=n.split("\n"),i=0;i<o.length;++i)o[i]=e+o[i];n=o.join("\n"),t+=n+"\n"}return _--,t},l(o,Error);var g=Error.__BluebirdErrorTypes__;g||(g=u({CancellationError:p,TimeoutError:h,OperationalError:o,RejectionError:o,AggregateError:v}),a.defineProperty(Error,"__BluebirdErrorTypes__",{value:g,writable:!1,enumerable:!1,configurable:!1})),t.exports={Error:Error,TypeError:i,RangeError:s,CancellationError:g.CancellationError,OperationalError:g.OperationalError,TimeoutError:g.TimeoutError,AggregateError:g.AggregateError,Warning:f}},{"./es5":13,"./util":36}],13:[function(e,t,r){var n=function(){"use strict";return void 0===this}();if(n)t.exports={freeze:Object.freeze,defineProperty:Object.defineProperty,getDescriptor:Object.getOwnPropertyDescriptor,keys:Object.keys,names:Object.getOwnPropertyNames,getPrototypeOf:Object.getPrototypeOf,isArray:Array.isArray,isES5:n,propertyIsWritable:function(e,t){var r=Object.getOwnPropertyDescriptor(e,t);return!(r&&!r.writable&&!r.set)}};else{var o={}.hasOwnProperty,i={}.toString,s={}.constructor.prototype,a=function(e){var t=[];for(var r in e)o.call(e,r)&&t.push(r);return t},u=function(e,t){return{value:e[t]}},c=function(e,t,r){return e[t]=r.value,e},l=function(e){return e},d=function(e){try{return Object(e).constructor.prototype}catch(e){return s}},f=function(e){try{return"[object Array]"===i.call(e)}catch(e){return!1}};t.exports={isArray:f,keys:a,names:a,defineProperty:c,getDescriptor:u,freeze:l,getPrototypeOf:d,isES5:n,propertyIsWritable:function(){return!0}}}},{}],14:[function(e,t,r){"use strict";t.exports=function(e,t){var r=e.map;e.prototype.filter=function(e,n){return r(this,e,n,t)},e.filter=function(e,n,o){return r(e,n,o,t)}}},{}],15:[function(e,t,r){"use strict";t.exports=function(t,r,n){function o(e,t,r){this.promise=e,this.type=t,this.handler=r,this.called=!1,this.cancelPromise=null}function i(e){this.finallyHandler=e}function s(e,t){return null!=e.cancelPromise&&(arguments.length>1?e.cancelPromise._reject(t):e.cancelPromise._cancel(),e.cancelPromise=null,!0)}function a(){return c.call(this,this.promise._target()._settledValue())}function u(e){if(!s(this,e))return f.e=e,f}function c(e){var o=this.promise,c=this.handler;if(!this.called){this.called=!0;var l=this.isFinallyHandler()?c.call(o._boundValue()):c.call(o._boundValue(),e);if(l===n)return l;if(void 0!==l){o._setReturnedNonUndefined();var p=r(l,o);if(p instanceof t){if(null!=this.cancelPromise){if(p._isCancelled()){var h=new d("late cancellation observer");return o._attachExtraTrace(h),f.e=h,f}p.isPending()&&p._attachCancellationCallback(new i(this))}return p._then(a,u,void 0,this,void 0)}}}return o.isRejected()?(s(this),f.e=e,f):(s(this),e)}var l=e("./util"),d=t.CancellationError,f=l.errorObj,p=e("./catch_filter")(n);return o.prototype.isFinallyHandler=function(){return 0===this.type},i.prototype._resultCancelled=function(){s(this.finallyHandler)},t.prototype._passThrough=function(e,t,r,n){return"function"!=typeof e?this.then():this._then(r,n,void 0,new o(this,t,e),void 0)},t.prototype.lastly=t.prototype.finally=function(e){return this._passThrough(e,0,c,c)},t.prototype.tap=function(e){return this._passThrough(e,1,c)},t.prototype.tapCatch=function(e){var r=arguments.length;if(1===r)return this._passThrough(e,1,void 0,c);var n,o=new Array(r-1),i=0;for(n=0;n<r-1;++n){var s=arguments[n];if(!l.isObject(s))return t.reject(new TypeError("tapCatch statement predicate: expecting an object but got "+l.classString(s)));o[i++]=s}o.length=i;var a=arguments[n];return this._passThrough(p(o,a,this),1,void 0,c)},o}},{"./catch_filter":7,"./util":36}],16:[function(e,t,r){"use strict";t.exports=function(t,r,n,o,i,s){function a(e,r,n){for(var i=0;i<r.length;++i){n._pushContext();var s=p(r[i])(e);if(n._popContext(),s===f){n._pushContext();var a=t.reject(f.e);return n._popContext(),a}var u=o(s,n);if(u instanceof t)return u}return null}function u(e,r,o,i){if(s.cancellation()){var a=new t(n),u=this._finallyPromise=new t(n);this._promise=a.lastly(function(){return u}),a._captureStackTrace(),a._setOnCancel(this)}else{(this._promise=new t(n))._captureStackTrace()}this._stack=i,this._generatorFunction=e,this._receiver=r,this._generator=void 0,this._yieldHandlers="function"==typeof o?[o].concat(h):h,this._yieldedPromise=null,this._cancellationPhase=!1}var c=e("./errors"),l=c.TypeError,d=e("./util"),f=d.errorObj,p=d.tryCatch,h=[];d.inherits(u,i),u.prototype._isResolved=function(){return null===this._promise},u.prototype._cleanup=function(){this._promise=this._generator=null,s.cancellation()&&null!==this._finallyPromise&&(this._finallyPromise._fulfill(),this._finallyPromise=null)},u.prototype._promiseCancelled=function(){if(!this._isResolved()){var e,r=void 0!==this._generator.return;if(r)this._promise._pushContext(),e=p(this._generator.return).call(this._generator,void 0),this._promise._popContext();else{var n=new t.CancellationError("generator .return() sentinel");t.coroutine.returnSentinel=n,this._promise._attachExtraTrace(n),this._promise._pushContext(),e=p(this._generator.throw).call(this._generator,n),this._promise._popContext()}this._cancellationPhase=!0,this._yieldedPromise=null,this._continue(e)}},u.prototype._promiseFulfilled=function(e){this._yieldedPromise=null,this._promise._pushContext();var t=p(this._generator.next).call(this._generator,e);this._promise._popContext(),this._continue(t)},u.prototype._promiseRejected=function(e){this._yieldedPromise=null,this._promise._attachExtraTrace(e),this._promise._pushContext();var t=p(this._generator.throw).call(this._generator,e);this._promise._popContext(),this._continue(t)},u.prototype._resultCancelled=function(){if(this._yieldedPromise instanceof t){var e=this._yieldedPromise;this._yieldedPromise=null,e.cancel()}},u.prototype.promise=function(){return this._promise},u.prototype._run=function(){this._generator=this._generatorFunction.call(this._receiver),this._receiver=this._generatorFunction=void 0,this._promiseFulfilled(void 0)},u.prototype._continue=function(e){var r=this._promise;if(e===f)return this._cleanup(),this._cancellationPhase?r.cancel():r._rejectCallback(e.e,!1);var n=e.value;if(!0===e.done)return this._cleanup(),this._cancellationPhase?r.cancel():r._resolveCallback(n);var i=o(n,this._promise);if(!(i instanceof t)&&null===(i=a(i,this._yieldHandlers,this._promise)))return void this._promiseRejected(new l("A value %s was yielded that could not be treated as a promise\n\n See http://goo.gl/MqrFmX\n\n".replace("%s",String(n))+"From coroutine:\n"+this._stack.split("\n").slice(1,-7).join("\n")));i=i._target();var s=i._bitField;0==(50397184&s)?(this._yieldedPromise=i,i._proxy(this,null)):0!=(33554432&s)?t._async.invoke(this._promiseFulfilled,this,i._value()):0!=(16777216&s)?t._async.invoke(this._promiseRejected,this,i._reason()):this._promiseCancelled()},t.coroutine=function(e,t){if("function"!=typeof e)throw new l("generatorFunction must be a function\n\n See http://goo.gl/MqrFmX\n");var r=Object(t).yieldHandler,n=u,o=(new Error).stack;return function(){var t=e.apply(this,arguments),i=new n(void 0,void 0,r,o),s=i.promise();return i._generator=t,i._promiseFulfilled(void 0),s}},t.coroutine.addYieldHandler=function(e){if("function"!=typeof e)throw new l("expecting a function but got "+d.classString(e));h.push(e)},t.spawn=function(e){if(s.deprecated("Promise.spawn()","Promise.coroutine()"),"function"!=typeof e)return r("generatorFunction must be a function\n\n See http://goo.gl/MqrFmX\n");var n=new u(e,this),o=n.promise();return n._run(t.spawn),o}}},{"./errors":12,"./util":36}],17:[function(e,t,r){"use strict";t.exports=function(t,r,n,o,i,s){var a=e("./util");a.canEvaluate,a.tryCatch,a.errorObj;t.join=function(){var e,t=arguments.length-1;if(t>0&&"function"==typeof arguments[t]){e=arguments[t];var n}var o=[].slice.call(arguments);e&&o.pop();var n=new r(o).promise();return void 0!==e?n.spread(e):n}}},{"./util":36}],18:[function(e,t,r){"use strict";t.exports=function(t,r,n,o,i,s){function a(e,t,r,n){this.constructor$(e),this._promise._captureStackTrace();var o=c();this._callback=null===o?t:l.domainBind(o,t),this._preservedValues=n===i?new Array(this.length()):null,this._limit=r,this._inFlight=0,this._queue=[],p.invoke(this._asyncInit,this,void 0)}function u(e,r,o,i){if("function"!=typeof r)return n("expecting a function but got "+l.classString(r));var s=0;if(void 0!==o){if("object"!=typeof o||null===o)return t.reject(new TypeError("options argument must be an object but it is "+l.classString(o)));if("number"!=typeof o.concurrency)return t.reject(new TypeError("'concurrency' must be a number but it is "+l.classString(o.concurrency)));s=o.concurrency}return s="number"==typeof s&&isFinite(s)&&s>=1?s:0,new a(e,r,s,i).promise()}var c=t._getDomain,l=e("./util"),d=l.tryCatch,f=l.errorObj,p=t._async;l.inherits(a,r),a.prototype._asyncInit=function(){this._init$(void 0,-2)},a.prototype._init=function(){},a.prototype._promiseFulfilled=function(e,r){var n=this._values,i=this.length(),a=this._preservedValues,u=this._limit;if(r<0){if(r=-1*r-1,n[r]=e,u>=1&&(this._inFlight--,this._drainQueue(),this._isResolved()))return!0}else{if(u>=1&&this._inFlight>=u)return n[r]=e,this._queue.push(r),!1;null!==a&&(a[r]=e);var c=this._promise,l=this._callback,p=c._boundValue();c._pushContext();var h=d(l).call(p,e,r,i),v=c._popContext();if(s.checkForgottenReturns(h,v,null!==a?"Promise.filter":"Promise.map",c),h===f)return this._reject(h.e),!0;var m=o(h,this._promise);if(m instanceof t){m=m._target();var y=m._bitField;if(0==(50397184&y))return u>=1&&this._inFlight++,n[r]=m,m._proxy(this,-1*(r+1)),!1;if(0==(33554432&y))return 0!=(16777216&y)?(this._reject(m._reason()),!0):(this._cancel(),!0);h=m._value()}n[r]=h}return++this._totalResolved>=i&&(null!==a?this._filter(n,a):this._resolve(n),!0)},a.prototype._drainQueue=function(){for(var e=this._queue,t=this._limit,r=this._values;e.length>0&&this._inFlight<t;){if(this._isResolved())return;var n=e.pop();this._promiseFulfilled(r[n],n)}},a.prototype._filter=function(e,t){for(var r=t.length,n=new Array(r),o=0,i=0;i<r;++i)e[i]&&(n[o++]=t[i]);n.length=o,this._resolve(n)},a.prototype.preservedValues=function(){return this._preservedValues},t.prototype.map=function(e,t){return u(this,e,t,null)},t.map=function(e,t,r,n){return u(e,t,r,n)}}},{"./util":36}],19:[function(e,t,r){"use strict";t.exports=function(t,r,n,o,i){var s=e("./util"),a=s.tryCatch;t.method=function(e){if("function"!=typeof e)throw new t.TypeError("expecting a function but got "+s.classString(e));return function(){var n=new t(r);n._captureStackTrace(),n._pushContext();var o=a(e).apply(this,arguments),s=n._popContext();return i.checkForgottenReturns(o,s,"Promise.method",n),n._resolveFromSyncValue(o),n}},t.attempt=t.try=function(e){if("function"!=typeof e)return o("expecting a function but got "+s.classString(e));var n=new t(r);n._captureStackTrace(),n._pushContext();var u;if(arguments.length>1){i.deprecated("calling Promise.try with more than 1 argument");var c=arguments[1],l=arguments[2];u=s.isArray(c)?a(e).apply(l,c):a(e).call(l,c)}else u=a(e)();var d=n._popContext();return i.checkForgottenReturns(u,d,"Promise.try",n),n._resolveFromSyncValue(u),n},t.prototype._resolveFromSyncValue=function(e){e===s.errorObj?this._rejectCallback(e.e,!1):this._resolveCallback(e,!0)}}},{"./util":36}],20:[function(e,t,r){"use strict";function n(e){return e instanceof Error&&l.getPrototypeOf(e)===Error.prototype}function o(e){var t;if(n(e)){t=new c(e),t.name=e.name,t.message=e.message,t.stack=e.stack;for(var r=l.keys(e),o=0;o<r.length;++o){var i=r[o];d.test(i)||(t[i]=e[i])}return t}return s.markAsOriginatingFromRejection(e),e}function i(e,t){return function(r,n){if(null!==e){if(r){var i=o(a(r));e._attachExtraTrace(i),e._reject(i)}else if(t){var s=[].slice.call(arguments,1);e._fulfill(s)}else e._fulfill(n);e=null}}}var s=e("./util"),a=s.maybeWrapAsError,u=e("./errors"),c=u.OperationalError,l=e("./es5"),d=/^(?:name|message|stack|cause)$/;t.exports=i},{"./errors":12,"./es5":13,"./util":36}],21:[function(e,t,r){"use strict";t.exports=function(t){function r(e,t){var r=this;if(!i.isArray(e))return n.call(r,e,t);var o=a(t).apply(r._boundValue(),[null].concat(e));o===u&&s.throwLater(o.e)}function n(e,t){var r=this,n=r._boundValue(),o=void 0===e?a(t).call(n,null):a(t).call(n,null,e);o===u&&s.throwLater(o.e)}function o(e,t){var r=this;if(!e){var n=new Error(e+"");n.cause=e,e=n}var o=a(t).call(r._boundValue(),e);o===u&&s.throwLater(o.e)}var i=e("./util"),s=t._async,a=i.tryCatch,u=i.errorObj;t.prototype.asCallback=t.prototype.nodeify=function(e,t){if("function"==typeof e){var i=n;void 0!==t&&Object(t).spread&&(i=r),this._then(i,o,void 0,this,e)}return this}}},{"./util":36}],22:[function(t,r,n){"use strict";r.exports=function(){function n(){}function o(e,t){if(null==e||e.constructor!==i)throw new g("the promise constructor cannot be invoked directly\n\n See http://goo.gl/MqrFmX\n");if("function"!=typeof t)throw new g("expecting a function but got "+h.classString(t))}function i(e){e!==E&&o(this,e),this._bitField=0,this._fulfillmentHandler0=void 0,this._rejectionHandler0=void 0,this._promise0=void 0,this._receiver0=void 0,this._resolveFromExecutor(e),this._promiseCreated(),this._fireEvent("promiseCreated",this)}function s(e){this.promise._resolveCallback(e)}function a(e){this.promise._rejectCallback(e,!1)}function u(e){var t=new i(E);t._fulfillmentHandler0=e,t._rejectionHandler0=e,t._promise0=e,t._receiver0=e}var c,l=function(){return new g("circular promise resolution chain\n\n See http://goo.gl/MqrFmX\n")},d=function(){return new i.PromiseInspection(this._target())},f=function(e){return i.reject(new g(e))},p={},h=t("./util");c=h.isNode?function(){var t=e.domain;return void 0===t&&(t=null),t}:function(){return null},h.notEnumerableProp(i,"_getDomain",c);var v=t("./es5"),m=t("./async"),y=new m;v.defineProperty(i,"_async",{value:y});var _=t("./errors"),g=i.TypeError=_.TypeError;i.RangeError=_.RangeError;var b=i.CancellationError=_.CancellationError;i.TimeoutError=_.TimeoutError,i.OperationalError=_.OperationalError,i.RejectionError=_.OperationalError,i.AggregateError=_.AggregateError;var E=function(){},w={},S={},k=t("./thenables")(i,E),T=t("./promise_array")(i,E,k,f,n),x=t("./context")(i),R=x.create,I=t("./debuggability")(i,x),C=(I.CapturedTrace,t("./finally")(i,k,S)),j=t("./catch_filter")(S),O=t("./nodeback"),A=h.errorObj,D=h.tryCatch;return i.prototype.toString=function(){return"[object Promise]"},i.prototype.caught=i.prototype.catch=function(e){var t=arguments.length;if(t>1){var r,n=new Array(t-1),o=0;for(r=0;r<t-1;++r){var i=arguments[r];if(!h.isObject(i))return f("Catch statement predicate: expecting an object but got "+h.classString(i));n[o++]=i}return n.length=o,e=arguments[r],this.then(void 0,j(n,e,this))}return this.then(void 0,e)},i.prototype.reflect=function(){return this._then(d,d,void 0,this,void 0)},i.prototype.then=function(e,t){if(I.warnings()&&arguments.length>0&&"function"!=typeof e&&"function"!=typeof t){var r=".then() only accepts functions but was passed: "+h.classString(e);arguments.length>1&&(r+=", "+h.classString(t)),this._warn(r)}return this._then(e,t,void 0,void 0,void 0)},i.prototype.done=function(e,t){this._then(e,t,void 0,void 0,void 0)._setIsFinal()},i.prototype.spread=function(e){return"function"!=typeof e?f("expecting a function but got "+h.classString(e)):this.all()._then(e,void 0,void 0,w,void 0)},i.prototype.toJSON=function(){var e={isFulfilled:!1,isRejected:!1,fulfillmentValue:void 0,rejectionReason:void 0};return this.isFulfilled()?(e.fulfillmentValue=this.value(),e.isFulfilled=!0):this.isRejected()&&(e.rejectionReason=this.reason(),e.isRejected=!0),e},i.prototype.all=function(){return arguments.length>0&&this._warn(".all() was passed arguments but it does not take any"),new T(this).promise()},i.prototype.error=function(e){return this.caught(h.originatesFromRejection,e)},i.getNewLibraryCopy=r.exports,i.is=function(e){return e instanceof i},i.fromNode=i.fromCallback=function(e){var t=new i(E);t._captureStackTrace();var r=arguments.length>1&&!!Object(arguments[1]).multiArgs,n=D(e)(O(t,r));return n===A&&t._rejectCallback(n.e,!0),t._isFateSealed()||t._setAsyncGuaranteed(),t},i.all=function(e){return new T(e).promise()},i.cast=function(e){var t=k(e);return t instanceof i||(t=new i(E),t._captureStackTrace(),t._setFulfilled(),t._rejectionHandler0=e),t},i.resolve=i.fulfilled=i.cast,i.reject=i.rejected=function(e){var t=new i(E);return t._captureStackTrace(),t._rejectCallback(e,!0),t},i.setScheduler=function(e){if("function"!=typeof e)throw new g("expecting a function but got "+h.classString(e));return y.setScheduler(e)},i.prototype._then=function(e,t,r,n,o){var s=void 0!==o,a=s?o:new i(E),u=this._target(),l=u._bitField;s||(a._propagateFrom(this,3),a._captureStackTrace(),void 0===n&&0!=(2097152&this._bitField)&&(n=0!=(50397184&l)?this._boundValue():u===this?void 0:this._boundTo),this._fireEvent("promiseChained",this,a));var d=c();if(0!=(50397184&l)){var f,p,v=u._settlePromiseCtx;0!=(33554432&l)?(p=u._rejectionHandler0,f=e):0!=(16777216&l)?(p=u._fulfillmentHandler0,f=t,u._unsetRejectionIsUnhandled()):(v=u._settlePromiseLateCancellationObserver,p=new b("late cancellation observer"),u._attachExtraTrace(p),f=t),y.invoke(v,u,{handler:null===d?f:"function"==typeof f&&h.domainBind(d,f),promise:a,receiver:n,value:p})}else u._addCallbacks(e,t,a,n,d);return a},i.prototype._length=function(){return 65535&this._bitField},i.prototype._isFateSealed=function(){return 0!=(117506048&this._bitField)},i.prototype._isFollowing=function(){return 67108864==(67108864&this._bitField)},i.prototype._setLength=function(e){this._bitField=-65536&this._bitField|65535&e},i.prototype._setFulfilled=function(){this._bitField=33554432|this._bitField,this._fireEvent("promiseFulfilled",this)},i.prototype._setRejected=function(){this._bitField=16777216|this._bitField,this._fireEvent("promiseRejected",this)},i.prototype._setFollowing=function(){this._bitField=67108864|this._bitField,this._fireEvent("promiseResolved",this)},i.prototype._setIsFinal=function(){this._bitField=4194304|this._bitField},i.prototype._isFinal=function(){return(4194304&this._bitField)>0},i.prototype._unsetCancelled=function(){this._bitField=-65537&this._bitField},i.prototype._setCancelled=function(){this._bitField=65536|this._bitField,this._fireEvent("promiseCancelled",this)},i.prototype._setWillBeCancelled=function(){this._bitField=8388608|this._bitField},i.prototype._setAsyncGuaranteed=function(){y.hasCustomScheduler()||(this._bitField=134217728|this._bitField)},i.prototype._receiverAt=function(e){var t=0===e?this._receiver0:this[4*e-4+3];if(t!==p)return void 0===t&&this._isBound()?this._boundValue():t},i.prototype._promiseAt=function(e){return this[4*e-4+2]},i.prototype._fulfillmentHandlerAt=function(e){return this[4*e-4+0]},i.prototype._rejectionHandlerAt=function(e){return this[4*e-4+1]},i.prototype._boundValue=function(){},i.prototype._migrateCallback0=function(e){var t=(e._bitField,e._fulfillmentHandler0),r=e._rejectionHandler0,n=e._promise0,o=e._receiverAt(0);void 0===o&&(o=p),this._addCallbacks(t,r,n,o,null)},i.prototype._migrateCallbackAt=function(e,t){var r=e._fulfillmentHandlerAt(t),n=e._rejectionHandlerAt(t),o=e._promiseAt(t),i=e._receiverAt(t);void 0===i&&(i=p),this._addCallbacks(r,n,o,i,null)},i.prototype._addCallbacks=function(e,t,r,n,o){var i=this._length();if(i>=65531&&(i=0,this._setLength(0)),0===i)this._promise0=r,this._receiver0=n,"function"==typeof e&&(this._fulfillmentHandler0=null===o?e:h.domainBind(o,e)),"function"==typeof t&&(this._rejectionHandler0=null===o?t:h.domainBind(o,t));else{var s=4*i-4;this[s+2]=r,this[s+3]=n,"function"==typeof e&&(this[s+0]=null===o?e:h.domainBind(o,e)),"function"==typeof t&&(this[s+1]=null===o?t:h.domainBind(o,t))}return this._setLength(i+1),i},i.prototype._proxy=function(e,t){this._addCallbacks(void 0,void 0,t,e,null)},i.prototype._resolveCallback=function(e,t){if(0==(117506048&this._bitField)){if(e===this)return this._rejectCallback(l(),!1);var r=k(e,this);if(!(r instanceof i))return this._fulfill(e);t&&this._propagateFrom(r,2);var n=r._target();if(n===this)return void this._reject(l());var o=n._bitField;if(0==(50397184&o)){var s=this._length();s>0&&n._migrateCallback0(this);for(var a=1;a<s;++a)n._migrateCallbackAt(this,a);this._setFollowing(),this._setLength(0),this._setFollowee(n)}else if(0!=(33554432&o))this._fulfill(n._value());else if(0!=(16777216&o))this._reject(n._reason());else{var u=new b("late cancellation observer");n._attachExtraTrace(u),this._reject(u)}}},i.prototype._rejectCallback=function(e,t,r){var n=h.ensureErrorObject(e),o=n===e;if(!o&&!r&&I.warnings()){var i="a promise was rejected with a non-error: "+h.classString(e);this._warn(i,!0)}this._attachExtraTrace(n,!!t&&o),this._reject(e)},i.prototype._resolveFromExecutor=function(e){if(e!==E){var t=this;this._captureStackTrace(),this._pushContext();var r=!0,n=this._execute(e,function(e){t._resolveCallback(e)},function(e){t._rejectCallback(e,r)});r=!1,this._popContext(),void 0!==n&&t._rejectCallback(n,!0)}},i.prototype._settlePromiseFromHandler=function(e,t,r,n){var o=n._bitField;if(0==(65536&o)){n._pushContext();var i;t===w?r&&"number"==typeof r.length?i=D(e).apply(this._boundValue(),r):(i=A,i.e=new g("cannot .spread() a non-array: "+h.classString(r))):i=D(e).call(t,r);var s=n._popContext();o=n._bitField,0==(65536&o)&&(i===S?n._reject(r):i===A?n._rejectCallback(i.e,!1):(I.checkForgottenReturns(i,s,"",n,this),n._resolveCallback(i)))}},i.prototype._target=function(){for(var e=this;e._isFollowing();)e=e._followee();return e},i.prototype._followee=function(){return this._rejectionHandler0},i.prototype._setFollowee=function(e){this._rejectionHandler0=e},i.prototype._settlePromise=function(e,t,r,o){var s=e instanceof i,a=this._bitField,u=0!=(134217728&a);0!=(65536&a)?(s&&e._invokeInternalOnCancel(),r instanceof C&&r.isFinallyHandler()?(r.cancelPromise=e,D(t).call(r,o)===A&&e._reject(A.e)):t===d?e._fulfill(d.call(r)):r instanceof n?r._promiseCancelled(e):s||e instanceof T?e._cancel():r.cancel()):"function"==typeof t?s?(u&&e._setAsyncGuaranteed(),this._settlePromiseFromHandler(t,r,o,e)):t.call(r,o,e):r instanceof n?r._isResolved()||(0!=(33554432&a)?r._promiseFulfilled(o,e):r._promiseRejected(o,e)):s&&(u&&e._setAsyncGuaranteed(),0!=(33554432&a)?e._fulfill(o):e._reject(o))},i.prototype._settlePromiseLateCancellationObserver=function(e){var t=e.handler,r=e.promise,n=e.receiver,o=e.value;"function"==typeof t?r instanceof i?this._settlePromiseFromHandler(t,n,o,r):t.call(n,o,r):r instanceof i&&r._reject(o)},i.prototype._settlePromiseCtx=function(e){this._settlePromise(e.promise,e.handler,e.receiver,e.value)},i.prototype._settlePromise0=function(e,t,r){var n=this._promise0,o=this._receiverAt(0);this._promise0=void 0,this._receiver0=void 0,this._settlePromise(n,e,o,t)},i.prototype._clearCallbackDataAtIndex=function(e){var t=4*e-4;this[t+2]=this[t+3]=this[t+0]=this[t+1]=void 0},i.prototype._fulfill=function(e){var t=this._bitField;if(!((117506048&t)>>>16)){if(e===this){var r=l();return this._attachExtraTrace(r),this._reject(r)}this._setFulfilled(),this._rejectionHandler0=e,(65535&t)>0&&(0!=(134217728&t)?this._settlePromises():y.settlePromises(this),this._dereferenceTrace())}},i.prototype._reject=function(e){var t=this._bitField;if(!((117506048&t)>>>16)){if(this._setRejected(),this._fulfillmentHandler0=e,this._isFinal())return y.fatalError(e,h.isNode);(65535&t)>0?y.settlePromises(this):this._ensurePossibleRejectionHandled()}},i.prototype._fulfillPromises=function(e,t){for(var r=1;r<e;r++){var n=this._fulfillmentHandlerAt(r),o=this._promiseAt(r),i=this._receiverAt(r);this._clearCallbackDataAtIndex(r),this._settlePromise(o,n,i,t)}},i.prototype._rejectPromises=function(e,t){for(var r=1;r<e;r++){var n=this._rejectionHandlerAt(r),o=this._promiseAt(r),i=this._receiverAt(r);this._clearCallbackDataAtIndex(r),this._settlePromise(o,n,i,t)}},i.prototype._settlePromises=function(){var e=this._bitField,t=65535&e;if(t>0){if(0!=(16842752&e)){var r=this._fulfillmentHandler0;this._settlePromise0(this._rejectionHandler0,r,e),this._rejectPromises(t,r)}else{var n=this._rejectionHandler0;this._settlePromise0(this._fulfillmentHandler0,n,e),this._fulfillPromises(t,n)}this._setLength(0)}this._clearCancellationData()},i.prototype._settledValue=function(){var e=this._bitField;return 0!=(33554432&e)?this._rejectionHandler0:0!=(16777216&e)?this._fulfillmentHandler0:void 0},i.defer=i.pending=function(){return I.deprecated("Promise.defer","new Promise"),{promise:new i(E),resolve:s,reject:a}},h.notEnumerableProp(i,"_makeSelfResolutionError",l),t("./method")(i,E,k,f,I),t("./bind")(i,E,k,I),t("./cancel")(i,T,f,I),t("./direct_resolve")(i),t("./synchronous_inspection")(i),t("./join")(i,T,k,E,y,c),i.Promise=i,i.version="3.5.3",t("./map.js")(i,T,f,k,E,I),t("./call_get.js")(i),t("./using.js")(i,f,k,R,E,I),t("./timers.js")(i,E,I),t("./generators.js")(i,f,E,k,n,I),t("./nodeify.js")(i),t("./promisify.js")(i,E),t("./props.js")(i,T,k,f),t("./race.js")(i,E,k,f),t("./reduce.js")(i,T,f,k,E,I),t("./settle.js")(i,T,I),t("./some.js")(i,T,f),t("./filter.js")(i,E),t("./each.js")(i,E),t("./any.js")(i),h.toFastProperties(i),h.toFastProperties(i.prototype),u({a:1}),u({b:2}),u({c:3}),u(1),u(function(){}),u(void 0),u(!1),u(new i(E)),I.setBounds(m.firstLineError,h.lastLineError),i}},{"./any.js":1,"./async":2,"./bind":3,"./call_get.js":5,"./cancel":6,"./catch_filter":7,"./context":8,"./debuggability":9,"./direct_resolve":10,"./each.js":11,"./errors":12,"./es5":13,"./filter.js":14,"./finally":15,"./generators.js":16,"./join":17,"./map.js":18,"./method":19,"./nodeback":20,"./nodeify.js":21,"./promise_array":23,"./promisify.js":24,"./props.js":25,"./race.js":27,"./reduce.js":28,"./settle.js":30,"./some.js":31,"./synchronous_inspection":32,"./thenables":33,"./timers.js":34,"./using.js":35,"./util":36}],23:[function(e,t,r){"use strict";t.exports=function(t,r,n,o,i){function s(e){switch(e){case-2:return[];case-3:return{};case-6:return new Map}}function a(e){var n=this._promise=new t(r);e instanceof t&&n._propagateFrom(e,3),n._setOnCancel(this),this._values=e,this._length=0,this._totalResolved=0,this._init(void 0,-2)}var u=e("./util");u.isArray;return u.inherits(a,i),a.prototype.length=function(){return this._length},a.prototype.promise=function(){return this._promise},a.prototype._init=function e(r,i){var a=n(this._values,this._promise);if(a instanceof t){a=a._target();var c=a._bitField;if(this._values=a,0==(50397184&c))return this._promise._setAsyncGuaranteed(),a._then(e,this._reject,void 0,this,i);if(0==(33554432&c))return 0!=(16777216&c)?this._reject(a._reason()):this._cancel();a=a._value()}if(null===(a=u.asArray(a))){var l=o("expecting an array or an iterable object but got "+u.classString(a)).reason();return void this._promise._rejectCallback(l,!1)}if(0===a.length)return void(-5===i?this._resolveEmptyArray():this._resolve(s(i)));this._iterate(a)},a.prototype._iterate=function(e){var r=this.getActualLength(e.length);this._length=r,this._values=this.shouldCopyValues()?new Array(r):this._values;for(var o=this._promise,i=!1,s=null,a=0;a<r;++a){var u=n(e[a],o);u instanceof t?(u=u._target(),s=u._bitField):s=null,i?null!==s&&u.suppressUnhandledRejections():null!==s?0==(50397184&s)?(u._proxy(this,a),this._values[a]=u):i=0!=(33554432&s)?this._promiseFulfilled(u._value(),a):0!=(16777216&s)?this._promiseRejected(u._reason(),a):this._promiseCancelled(a):i=this._promiseFulfilled(u,a)}i||o._setAsyncGuaranteed()},a.prototype._isResolved=function(){return null===this._values},a.prototype._resolve=function(e){this._values=null,this._promise._fulfill(e)},a.prototype._cancel=function(){!this._isResolved()&&this._promise._isCancellable()&&(this._values=null,this._promise._cancel())},a.prototype._reject=function(e){this._values=null,this._promise._rejectCallback(e,!1)},a.prototype._promiseFulfilled=function(e,t){return this._values[t]=e,++this._totalResolved>=this._length&&(this._resolve(this._values),!0)},a.prototype._promiseCancelled=function(){return this._cancel(),!0},a.prototype._promiseRejected=function(e){return this._totalResolved++,this._reject(e),!0},a.prototype._resultCancelled=function(){if(!this._isResolved()){var e=this._values;if(this._cancel(),e instanceof t)e.cancel();else for(var r=0;r<e.length;++r)e[r]instanceof t&&e[r].cancel()}},a.prototype.shouldCopyValues=function(){return!0},a.prototype.getActualLength=function(e){return e},a}},{"./util":36}],24:[function(e,t,r){"use strict";t.exports=function(t,r){function n(e){return!E.test(e)}function o(e){try{return!0===e.__isPromisified__}catch(e){return!1}}function i(e,t,r){var n=p.getDataPropertyOrDefault(e,t+r,g);return!!n&&o(n)}function s(e,t,r){for(var n=0;n<e.length;n+=2){var o=e[n];if(r.test(o))for(var i=o.replace(r,""),s=0;s<e.length;s+=2)if(e[s]===i)throw new _("Cannot promisify an API that has normal methods with '%s'-suffix\n\n See http://goo.gl/MqrFmX\n".replace("%s",t))}}function a(e,t,r,n){for(var a=p.inheritedDataKeys(e),u=[],c=0;c<a.length;++c){var l=a[c],d=e[l],f=n===w||w(l,d,e);"function"!=typeof d||o(d)||i(e,l,t)||!n(l,d,e,f)||u.push(l,d)}return s(u,t,r),u}function u(e,n,o,i,s,a){function u(){var o=n;n===f&&(o=this);var i=new t(r);i._captureStackTrace();var s="string"==typeof l&&this!==c?this[l]:e,u=h(i,a);try{s.apply(o,v(arguments,u))}catch(e){i._rejectCallback(m(e),!0,!0)}return i._isFateSealed()||i._setAsyncGuaranteed(),i}var c=function(){return this}(),l=e;return"string"==typeof l&&(e=i),p.notEnumerableProp(u,"__isPromisified__",!0),u}function c(e,t,r,n,o){for(var i=new RegExp(S(t)+"$"),s=a(e,t,i,r),u=0,c=s.length;u<c;u+=2){var l=s[u],d=s[u+1],h=l+t;if(n===k)e[h]=k(l,f,l,d,t,o);else{var v=n(d,function(){return k(l,f,l,d,t,o)});p.notEnumerableProp(v,"__isPromisified__",!0),e[h]=v}}return p.toFastProperties(e),e}function l(e,t,r){return k(e,t,void 0,e,null,r)}var d,f={},p=e("./util"),h=e("./nodeback"),v=p.withAppended,m=p.maybeWrapAsError,y=p.canEvaluate,_=e("./errors").TypeError,g={__isPromisified__:!0},b=["arity","length","name","arguments","caller","callee","prototype","__isPromisified__"],E=new RegExp("^(?:"+b.join("|")+")$"),w=function(e){return p.isIdentifier(e)&&"_"!==e.charAt(0)&&"constructor"!==e},S=function(e){return e.replace(/([$])/,"\\$")},k=y?d:u;t.promisify=function(e,t){if("function"!=typeof e)throw new _("expecting a function but got "+p.classString(e));if(o(e))return e;t=Object(t);var r=void 0===t.context?f:t.context,i=!!t.multiArgs,s=l(e,r,i);return p.copyDescriptors(e,s,n),s},t.promisifyAll=function(e,t){if("function"!=typeof e&&"object"!=typeof e)throw new _("the target of promisifyAll must be an object or a function\n\n See http://goo.gl/MqrFmX\n");t=Object(t);var r=!!t.multiArgs,n=t.suffix;"string"!=typeof n&&(n="Async");var o=t.filter;"function"!=typeof o&&(o=w);var i=t.promisifier;if("function"!=typeof i&&(i=k),
!p.isIdentifier(n))throw new RangeError("suffix must be a valid identifier\n\n See http://goo.gl/MqrFmX\n");for(var s=p.inheritedDataKeys(e),a=0;a<s.length;++a){var u=e[s[a]];"constructor"!==s[a]&&p.isClass(u)&&(c(u.prototype,n,o,i,r),c(u,n,o,i,r))}return c(e,n,o,i,r)}}},{"./errors":12,"./nodeback":20,"./util":36}],25:[function(e,t,r){"use strict";t.exports=function(t,r,n,o){function i(e){var t,r=!1;if(void 0!==a&&e instanceof a)t=d(e),r=!0;else{var n=l.keys(e),o=n.length;t=new Array(2*o);for(var i=0;i<o;++i){var s=n[i];t[i]=e[s],t[i+o]=s}}this.constructor$(t),this._isMap=r,this._init$(void 0,r?-6:-3)}function s(e){var r,s=n(e);return c(s)?(r=s instanceof t?s._then(t.props,void 0,void 0,void 0,void 0):new i(s).promise(),s instanceof t&&r._propagateFrom(s,2),r):o("cannot await properties of a non-object\n\n See http://goo.gl/MqrFmX\n")}var a,u=e("./util"),c=u.isObject,l=e("./es5");"function"==typeof Map&&(a=Map);var d=function(){function e(e,n){this[t]=e,this[t+r]=n,t++}var t=0,r=0;return function(n){r=n.size,t=0;var o=new Array(2*n.size);return n.forEach(e,o),o}}(),f=function(e){for(var t=new a,r=e.length/2|0,n=0;n<r;++n){var o=e[r+n],i=e[n];t.set(o,i)}return t};u.inherits(i,r),i.prototype._init=function(){},i.prototype._promiseFulfilled=function(e,t){if(this._values[t]=e,++this._totalResolved>=this._length){var r;if(this._isMap)r=f(this._values);else{r={};for(var n=this.length(),o=0,i=this.length();o<i;++o)r[this._values[o+n]]=this._values[o]}return this._resolve(r),!0}return!1},i.prototype.shouldCopyValues=function(){return!1},i.prototype.getActualLength=function(e){return e>>1},t.prototype.props=function(){return s(this)},t.props=function(e){return s(e)}}},{"./es5":13,"./util":36}],26:[function(e,t,r){"use strict";function n(e,t,r,n,o){for(var i=0;i<o;++i)r[i+n]=e[i+t],e[i+t]=void 0}function o(e){this._capacity=e,this._length=0,this._front=0}o.prototype._willBeOverCapacity=function(e){return this._capacity<e},o.prototype._pushOne=function(e){var t=this.length();this._checkCapacity(t+1),this[this._front+t&this._capacity-1]=e,this._length=t+1},o.prototype.push=function(e,t,r){var n=this.length()+3;if(this._willBeOverCapacity(n))return this._pushOne(e),this._pushOne(t),void this._pushOne(r);var o=this._front+n-3;this._checkCapacity(n);var i=this._capacity-1;this[o+0&i]=e,this[o+1&i]=t,this[o+2&i]=r,this._length=n},o.prototype.shift=function(){var e=this._front,t=this[e];return this[e]=void 0,this._front=e+1&this._capacity-1,this._length--,t},o.prototype.length=function(){return this._length},o.prototype._checkCapacity=function(e){this._capacity<e&&this._resizeTo(this._capacity<<1)},o.prototype._resizeTo=function(e){var t=this._capacity;this._capacity=e,n(this,0,this,t,this._front+this._length&t-1)},t.exports=o},{}],27:[function(e,t,r){"use strict";t.exports=function(t,r,n,o){function i(e,i){var u=n(e);if(u instanceof t)return a(u);if(null===(e=s.asArray(e)))return o("expecting an array or an iterable object but got "+s.classString(e));var c=new t(r);void 0!==i&&c._propagateFrom(i,3);for(var l=c._fulfill,d=c._reject,f=0,p=e.length;f<p;++f){var h=e[f];(void 0!==h||f in e)&&t.cast(h)._then(l,d,void 0,c,null)}return c}var s=e("./util"),a=function(e){return e.then(function(t){return i(t,e)})};t.race=function(e){return i(e,void 0)},t.prototype.race=function(){return i(this,void 0)}}},{"./util":36}],28:[function(e,t,r){"use strict";t.exports=function(t,r,n,o,i,s){function a(e,r,n,o){this.constructor$(e);var s=f();this._fn=null===s?r:p.domainBind(s,r),void 0!==n&&(n=t.resolve(n),n._attachCancellationCallback(this)),this._initialValue=n,this._currentCancellable=null,this._eachValues=o===i?Array(this._length):0===o?null:void 0,this._promise._captureStackTrace(),this._init$(void 0,-5)}function u(e,t){this.isFulfilled()?t._resolve(e):t._reject(e)}function c(e,t,r,o){return"function"!=typeof t?n("expecting a function but got "+p.classString(t)):new a(e,t,r,o).promise()}function l(e){this.accum=e,this.array._gotAccum(e);var r=o(this.value,this.array._promise);return r instanceof t?(this.array._currentCancellable=r,r._then(d,void 0,void 0,this,void 0)):d.call(this,r)}function d(e){var r=this.array,n=r._promise,o=h(r._fn);n._pushContext();var i;(i=void 0!==r._eachValues?o.call(n._boundValue(),e,this.index,this.length):o.call(n._boundValue(),this.accum,e,this.index,this.length))instanceof t&&(r._currentCancellable=i);var a=n._popContext();return s.checkForgottenReturns(i,a,void 0!==r._eachValues?"Promise.each":"Promise.reduce",n),i}var f=t._getDomain,p=e("./util"),h=p.tryCatch;p.inherits(a,r),a.prototype._gotAccum=function(e){void 0!==this._eachValues&&null!==this._eachValues&&e!==i&&this._eachValues.push(e)},a.prototype._eachComplete=function(e){return null!==this._eachValues&&this._eachValues.push(e),this._eachValues},a.prototype._init=function(){},a.prototype._resolveEmptyArray=function(){this._resolve(void 0!==this._eachValues?this._eachValues:this._initialValue)},a.prototype.shouldCopyValues=function(){return!1},a.prototype._resolve=function(e){this._promise._resolveCallback(e),this._values=null},a.prototype._resultCancelled=function(e){if(e===this._initialValue)return this._cancel();this._isResolved()||(this._resultCancelled$(),this._currentCancellable instanceof t&&this._currentCancellable.cancel(),this._initialValue instanceof t&&this._initialValue.cancel())},a.prototype._iterate=function(e){this._values=e;var r,n,o=e.length;if(void 0!==this._initialValue?(r=this._initialValue,n=0):(r=t.resolve(e[0]),n=1),this._currentCancellable=r,!r.isRejected())for(;n<o;++n){var i={accum:null,value:e[n],index:n,length:o,array:this};r=r._then(l,void 0,void 0,i,void 0)}void 0!==this._eachValues&&(r=r._then(this._eachComplete,void 0,void 0,this,void 0)),r._then(u,u,void 0,r,this)},t.prototype.reduce=function(e,t){return c(this,e,t,null)},t.reduce=function(e,t,r,n){return c(e,t,r,n)}}},{"./util":36}],29:[function(t,r,i){"use strict";var s,a=t("./util"),u=function(){throw new Error("No async scheduler available\n\n See http://goo.gl/MqrFmX\n")},c=a.getNativePromise();if(a.isNode&&"undefined"==typeof MutationObserver){var l=n.setImmediate,d=e.nextTick;s=a.isRecentNode?function(e){l.call(n,e)}:function(t){d.call(e,t)}}else if("function"==typeof c&&"function"==typeof c.resolve){var f=c.resolve();s=function(e){f.then(e)}}else s="undefined"==typeof MutationObserver||"undefined"!=typeof window&&window.navigator&&(window.navigator.standalone||window.cordova)?void 0!==o?function(e){o(e)}:"undefined"!=typeof setTimeout?function(e){setTimeout(e,0)}:u:function(){var e=document.createElement("div"),t={attributes:!0},r=!1,n=document.createElement("div");new MutationObserver(function(){e.classList.toggle("foo"),r=!1}).observe(n,t);var o=function(){r||(r=!0,n.classList.toggle("foo"))};return function(r){var n=new MutationObserver(function(){n.disconnect(),r()});n.observe(e,t),o()}}();r.exports=s},{"./util":36}],30:[function(e,t,r){"use strict";t.exports=function(t,r,n){function o(e){this.constructor$(e)}var i=t.PromiseInspection;e("./util").inherits(o,r),o.prototype._promiseResolved=function(e,t){return this._values[e]=t,++this._totalResolved>=this._length&&(this._resolve(this._values),!0)},o.prototype._promiseFulfilled=function(e,t){var r=new i;return r._bitField=33554432,r._settledValueField=e,this._promiseResolved(t,r)},o.prototype._promiseRejected=function(e,t){var r=new i;return r._bitField=16777216,r._settledValueField=e,this._promiseResolved(t,r)},t.settle=function(e){return n.deprecated(".settle()",".reflect()"),new o(e).promise()},t.prototype.settle=function(){return t.settle(this)}}},{"./util":36}],31:[function(e,t,r){"use strict";t.exports=function(t,r,n){function o(e){this.constructor$(e),this._howMany=0,this._unwrap=!1,this._initialized=!1}function i(e,t){if((0|t)!==t||t<0)return n("expecting a positive integer\n\n See http://goo.gl/MqrFmX\n");var r=new o(e),i=r.promise();return r.setHowMany(t),r.init(),i}var s=e("./util"),a=e("./errors").RangeError,u=e("./errors").AggregateError,c=s.isArray,l={};s.inherits(o,r),o.prototype._init=function(){if(this._initialized){if(0===this._howMany)return void this._resolve([]);this._init$(void 0,-5);var e=c(this._values);!this._isResolved()&&e&&this._howMany>this._canPossiblyFulfill()&&this._reject(this._getRangeError(this.length()))}},o.prototype.init=function(){this._initialized=!0,this._init()},o.prototype.setUnwrap=function(){this._unwrap=!0},o.prototype.howMany=function(){return this._howMany},o.prototype.setHowMany=function(e){this._howMany=e},o.prototype._promiseFulfilled=function(e){return this._addFulfilled(e),this._fulfilled()===this.howMany()&&(this._values.length=this.howMany(),1===this.howMany()&&this._unwrap?this._resolve(this._values[0]):this._resolve(this._values),!0)},o.prototype._promiseRejected=function(e){return this._addRejected(e),this._checkOutcome()},o.prototype._promiseCancelled=function(){return this._values instanceof t||null==this._values?this._cancel():(this._addRejected(l),this._checkOutcome())},o.prototype._checkOutcome=function(){if(this.howMany()>this._canPossiblyFulfill()){for(var e=new u,t=this.length();t<this._values.length;++t)this._values[t]!==l&&e.push(this._values[t]);return e.length>0?this._reject(e):this._cancel(),!0}return!1},o.prototype._fulfilled=function(){return this._totalResolved},o.prototype._rejected=function(){return this._values.length-this.length()},o.prototype._addRejected=function(e){this._values.push(e)},o.prototype._addFulfilled=function(e){this._values[this._totalResolved++]=e},o.prototype._canPossiblyFulfill=function(){return this.length()-this._rejected()},o.prototype._getRangeError=function(e){var t="Input array must contain at least "+this._howMany+" items but contains only "+e+" items";return new a(t)},o.prototype._resolveEmptyArray=function(){this._reject(this._getRangeError(0))},t.some=function(e,t){return i(e,t)},t.prototype.some=function(e){return i(this,e)},t._SomePromiseArray=o}},{"./errors":12,"./util":36}],32:[function(e,t,r){"use strict";t.exports=function(e){function t(e){void 0!==e?(e=e._target(),this._bitField=e._bitField,this._settledValueField=e._isFateSealed()?e._settledValue():void 0):(this._bitField=0,this._settledValueField=void 0)}t.prototype._settledValue=function(){return this._settledValueField};var r=t.prototype.value=function(){if(!this.isFulfilled())throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\n\n See http://goo.gl/MqrFmX\n");return this._settledValue()},n=t.prototype.error=t.prototype.reason=function(){if(!this.isRejected())throw new TypeError("cannot get rejection reason of a non-rejected promise\n\n See http://goo.gl/MqrFmX\n");return this._settledValue()},o=t.prototype.isFulfilled=function(){return 0!=(33554432&this._bitField)},i=t.prototype.isRejected=function(){return 0!=(16777216&this._bitField)},s=t.prototype.isPending=function(){return 0==(50397184&this._bitField)},a=t.prototype.isResolved=function(){return 0!=(50331648&this._bitField)};t.prototype.isCancelled=function(){return 0!=(8454144&this._bitField)},e.prototype.__isCancelled=function(){return 65536==(65536&this._bitField)},e.prototype._isCancelled=function(){return this._target().__isCancelled()},e.prototype.isCancelled=function(){return 0!=(8454144&this._target()._bitField)},e.prototype.isPending=function(){return s.call(this._target())},e.prototype.isRejected=function(){return i.call(this._target())},e.prototype.isFulfilled=function(){return o.call(this._target())},e.prototype.isResolved=function(){return a.call(this._target())},e.prototype.value=function(){return r.call(this._target())},e.prototype.reason=function(){var e=this._target();return e._unsetRejectionIsUnhandled(),n.call(e)},e.prototype._value=function(){return this._settledValue()},e.prototype._reason=function(){return this._unsetRejectionIsUnhandled(),this._settledValue()},e.PromiseInspection=t}},{}],33:[function(e,t,r){"use strict";t.exports=function(t,r){function n(e,n){if(l(e)){if(e instanceof t)return e;var o=i(e);if(o===c){n&&n._pushContext();var u=t.reject(o.e);return n&&n._popContext(),u}if("function"==typeof o){if(s(e)){var u=new t(r);return e._then(u._fulfill,u._reject,void 0,u,null),u}return a(e,o,n)}}return e}function o(e){return e.then}function i(e){try{return o(e)}catch(e){return c.e=e,c}}function s(e){try{return d.call(e,"_promise0")}catch(e){return!1}}function a(e,n,o){function i(e){a&&(a._resolveCallback(e),a=null)}function s(e){a&&(a._rejectCallback(e,d,!0),a=null)}var a=new t(r),l=a;o&&o._pushContext(),a._captureStackTrace(),o&&o._popContext();var d=!0,f=u.tryCatch(n).call(e,i,s);return d=!1,a&&f===c&&(a._rejectCallback(f.e,!0,!0),a=null),l}var u=e("./util"),c=u.errorObj,l=u.isObject,d={}.hasOwnProperty;return n}},{"./util":36}],34:[function(e,t,r){"use strict";t.exports=function(t,r,n){function o(e){this.handle=e}function i(e){return clearTimeout(this.handle),e}function s(e){throw clearTimeout(this.handle),e}var a=e("./util"),u=t.TimeoutError;o.prototype._resultCancelled=function(){clearTimeout(this.handle)};var c=function(e){return l(+this).thenReturn(e)},l=t.delay=function(e,i){var s,a;return void 0!==i?(s=t.resolve(i)._then(c,null,null,e,void 0),n.cancellation()&&i instanceof t&&s._setOnCancel(i)):(s=new t(r),a=setTimeout(function(){s._fulfill()},+e),n.cancellation()&&s._setOnCancel(new o(a)),s._captureStackTrace()),s._setAsyncGuaranteed(),s};t.prototype.delay=function(e){return l(e,this)};var d=function(e,t,r){var n;n="string"!=typeof t?t instanceof Error?t:new u("operation timed out"):new u(t),a.markAsOriginatingFromRejection(n),e._attachExtraTrace(n),e._reject(n),null!=r&&r.cancel()};t.prototype.timeout=function(e,t){e=+e;var r,a,u=new o(setTimeout(function(){r.isPending()&&d(r,t,a)},e));return n.cancellation()?(a=this.then(),r=a._then(i,s,void 0,u,void 0),r._setOnCancel(u)):r=this._then(i,s,void 0,u,void 0),r}}},{"./util":36}],35:[function(e,t,r){"use strict";t.exports=function(t,r,n,o,i,s){function a(e){setTimeout(function(){throw e},0)}function u(e){var t=n(e);return t!==e&&"function"==typeof e._isDisposable&&"function"==typeof e._getDisposer&&e._isDisposable()&&t._setDisposable(e._getDisposer()),t}function c(e,r){function o(){if(s>=c)return l._fulfill();var i=u(e[s++]);if(i instanceof t&&i._isDisposable()){try{i=n(i._getDisposer().tryDispose(r),e.promise)}catch(e){return a(e)}if(i instanceof t)return i._then(o,a,null,null,null)}o()}var s=0,c=e.length,l=new t(i);return o(),l}function l(e,t,r){this._data=e,this._promise=t,this._context=r}function d(e,t,r){this.constructor$(e,t,r)}function f(e){return l.isDisposer(e)?(this.resources[this.index]._setDisposable(e),e.promise()):e}function p(e){this.length=e,this.promise=null,this[e-1]=null}var h=e("./util"),v=e("./errors").TypeError,m=e("./util").inherits,y=h.errorObj,_=h.tryCatch,g={};l.prototype.data=function(){return this._data},l.prototype.promise=function(){return this._promise},l.prototype.resource=function(){return this.promise().isFulfilled()?this.promise().value():g},l.prototype.tryDispose=function(e){var t=this.resource(),r=this._context;void 0!==r&&r._pushContext();var n=t!==g?this.doDispose(t,e):null;return void 0!==r&&r._popContext(),this._promise._unsetDisposable(),this._data=null,n},l.isDisposer=function(e){return null!=e&&"function"==typeof e.resource&&"function"==typeof e.tryDispose},m(d,l),d.prototype.doDispose=function(e,t){return this.data().call(e,e,t)},p.prototype._resultCancelled=function(){for(var e=this.length,r=0;r<e;++r){var n=this[r];n instanceof t&&n.cancel()}},t.using=function(){var e=arguments.length;if(e<2)return r("you must pass at least 2 arguments to Promise.using");var o=arguments[e-1];if("function"!=typeof o)return r("expecting a function but got "+h.classString(o));var i,a=!0;2===e&&Array.isArray(arguments[0])?(i=arguments[0],e=i.length,a=!1):(i=arguments,e--);for(var u=new p(e),d=0;d<e;++d){var v=i[d];if(l.isDisposer(v)){var m=v;v=v.promise(),v._setDisposable(m)}else{var g=n(v);g instanceof t&&(v=g._then(f,null,null,{resources:u,index:d},void 0))}u[d]=v}for(var b=new Array(u.length),d=0;d<b.length;++d)b[d]=t.resolve(u[d]).reflect();var E=t.all(b).then(function(e){for(var t=0;t<e.length;++t){var r=e[t];if(r.isRejected())return y.e=r.error(),y;if(!r.isFulfilled())return void E.cancel();e[t]=r.value()}w._pushContext(),o=_(o);var n=a?o.apply(void 0,e):o(e),i=w._popContext();return s.checkForgottenReturns(n,i,"Promise.using",w),n}),w=E.lastly(function(){var e=new t.PromiseInspection(E);return c(u,e)});return u.promise=w,w._setOnCancel(u),w},t.prototype._setDisposable=function(e){this._bitField=131072|this._bitField,this._disposer=e},t.prototype._isDisposable=function(){return(131072&this._bitField)>0},t.prototype._getDisposer=function(){return this._disposer},t.prototype._unsetDisposable=function(){this._bitField=-131073&this._bitField,this._disposer=void 0},t.prototype.disposer=function(e){if("function"==typeof e)return new d(e,this,o());throw new v}}},{"./errors":12,"./util":36}],36:[function(t,r,o){"use strict";function i(){try{var e=O;return O=null,e.apply(this,arguments)}catch(e){return j.e=e,j}}function s(e){return O=e,i}function a(e){return null==e||!0===e||!1===e||"string"==typeof e||"number"==typeof e}function u(e){return"function"==typeof e||"object"==typeof e&&null!==e}function c(e){return a(e)?new Error(_(e)):e}function l(e,t){var r,n=e.length,o=new Array(n+1);for(r=0;r<n;++r)o[r]=e[r];return o[r]=t,o}function d(e,t,r){if(!I.isES5)return{}.hasOwnProperty.call(e,t)?e[t]:void 0;var n=Object.getOwnPropertyDescriptor(e,t);return null!=n?null==n.get&&null==n.set?n.value:r:void 0}function f(e,t,r){if(a(e))return e;var n={value:r,configurable:!0,enumerable:!1,writable:!0};return I.defineProperty(e,t,n),e}function p(e){throw e}function h(e){try{if("function"==typeof e){var t=I.names(e.prototype),r=I.isES5&&t.length>1,n=t.length>0&&!(1===t.length&&"constructor"===t[0]),o=P.test(e+"")&&I.names(e).length>0;if(r||n||o)return!0}return!1}catch(e){return!1}}function v(e){function t(){}function r(){return typeof n.foo}t.prototype=e;var n=new t;return r(),r(),e}function m(e){return L.test(e)}function y(e,t,r){for(var n=new Array(e),o=0;o<e;++o)n[o]=t+o+r;return n}function _(e){try{return e+""}catch(e){return"[no string representation]"}}function g(e){return e instanceof Error||null!==e&&"object"==typeof e&&"string"==typeof e.message&&"string"==typeof e.name}function b(e){try{f(e,"isOperational",!0)}catch(e){}}function E(e){return null!=e&&(e instanceof Error.__BluebirdErrorTypes__.OperationalError||!0===e.isOperational)}function w(e){return g(e)&&I.propertyIsWritable(e,"stack")}function S(e){return{}.toString.call(e)}function k(e,t,r){for(var n=I.names(e),o=0;o<n.length;++o){var i=n[o];if(r(i))try{I.defineProperty(t,i,I.getDescriptor(e,i))}catch(e){}}}function T(t){return B?e.env[t]:void 0}function x(){if("function"==typeof Promise)try{var e=new Promise(function(){});if("[object Promise]"==={}.toString.call(e))return Promise}catch(e){}}function R(e,t){return e.bind(t)}var I=t("./es5"),C="undefined"==typeof navigator,j={e:{}},O,A="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==n?n:void 0!==this?this:null,D=function(e,t){function r(){this.constructor=e,this.constructor$=t;for(var r in t.prototype)n.call(t.prototype,r)&&"$"!==r.charAt(r.length-1)&&(this[r+"$"]=t.prototype[r])}var n={}.hasOwnProperty;return r.prototype=t.prototype,e.prototype=new r,e.prototype},M=function(){var e=[Array.prototype,Object.prototype,Function.prototype],t=function(t){for(var r=0;r<e.length;++r)if(e[r]===t)return!0;return!1};if(I.isES5){var r=Object.getOwnPropertyNames;return function(e){for(var n=[],o=Object.create(null);null!=e&&!t(e);){var i;try{i=r(e)}catch(e){return n}for(var s=0;s<i.length;++s){var a=i[s];if(!o[a]){o[a]=!0;var u=Object.getOwnPropertyDescriptor(e,a);null!=u&&null==u.get&&null==u.set&&n.push(a)}}e=I.getPrototypeOf(e)}return n}}var n={}.hasOwnProperty;return function(r){if(t(r))return[];var o=[];e:for(var i in r)if(n.call(r,i))o.push(i);else{for(var s=0;s<e.length;++s)if(n.call(e[s],i))continue e;o.push(i)}return o}}(),P=/this\s*\.\s*\S+\s*=/,L=/^[a-z$_][a-z$_0-9]*$/i,U=function(){return"stack"in new Error?function(e){return w(e)?e:new Error(_(e))}:function(e){if(w(e))return e;try{throw new Error(_(e))}catch(e){return e}}}(),N=function(e){return I.isArray(e)?e:null};if("undefined"!=typeof Symbol&&Symbol.iterator){var F="function"==typeof Array.from?function(e){return Array.from(e)}:function(e){for(var t,r=[],n=e[Symbol.iterator]();!(t=n.next()).done;)r.push(t.value);return r};N=function(e){return I.isArray(e)?e:null!=e&&"function"==typeof e[Symbol.iterator]?F(e):null}}var q=void 0!==e&&"[object process]"===S(e).toLowerCase(),B=void 0!==e&&void 0!==e.env,K={isClass:h,isIdentifier:m,inheritedDataKeys:M,getDataPropertyOrDefault:d,thrower:p,isArray:I.isArray,asArray:N,notEnumerableProp:f,isPrimitive:a,isObject:u,isError:g,canEvaluate:C,errorObj:j,tryCatch:s,inherits:D,withAppended:l,maybeWrapAsError:c,toFastProperties:v,filledRange:y,toString:_,canAttachTrace:w,ensureErrorObject:U,originatesFromRejection:E,markAsOriginatingFromRejection:b,classString:S,copyDescriptors:k,hasDevTools:"undefined"!=typeof chrome&&chrome&&"function"==typeof chrome.loadTimes,isNode:q,hasEnvVariables:B,env:T,global:A,getNativePromise:x,domainBind:R};K.isRecentNode=K.isNode&&function(){var t=e.versions.node.split(".").map(Number);return 0===t[0]&&t[1]>10||t[0]>0}(),K.isNode&&K.toFastProperties(e);try{throw new Error}catch(e){K.lastLineError=e}r.exports=K},{"./es5":13}]},{},[4])(4)}),"undefined"!=typeof window&&null!==window?window.P=window.Promise:"undefined"!=typeof self&&null!==self&&(self.P=self.Promise)}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("timers").setImmediate)},{_process:237,timers:249}],90:[function(e,t,r){!function(e,n){"function"==typeof define&&define.amd?define([],n):"object"==typeof r?t.exports=n():e.returnExports=n()}(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 a=o.onResponse;if(o="string"==typeof o?{uri:o}:JSON.parse(JSON.stringify(o)),o.onResponse=a,o.verbose&&(e.log=n()),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 u=["proxy","_redirectsFollowed","maxRedirects","followRedirect"],c=0;c<u.length;c++)if(o[u[c]])throw new Error("options."+u[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 l=function(e){var t=[];for(var r in e)e.hasOwnProperty(r)&&t.push(encodeURIComponent(r)+"="+encodeURIComponent(e[r]));return t.join("&")};if(o.qs){var d="string"==typeof o.qs?o.qs:l(o.qs);-1!==o.uri.indexOf("?")?o.uri=o.uri+"&"+d:o.uri=o.uri+"?"+d}if(o.form){if("string"==typeof o.form)throw"form name unsupported";if("POST"===o.method){var f=(o.encoding||"application/x-www-form-urlencoded").toLowerCase();switch(o.headers["content-type"]=f,f){case"application/x-www-form-urlencoded":o.body=l(o.form).replace(/%20/g,"+");break;case"multipart/form-data":var p=function(e){var t={};t.boundry="-------------------------------"+Math.floor(1e9*Math.random());var r=[];for(var n in e)e.hasOwnProperty(n)&&r.push("--"+t.boundry+'\nContent-Disposition: form-data; name="'+n+'"\n\n'+e[n]+"\n");return r.push("--"+t.boundry+"--"),t.body=r.join(""),t.length=t.body.length,t.type="multipart/form-data; boundary="+t.boundry,t}(o.form);o.body=p.body,o.headers["content-type"]=p.type;break;default:throw new Error("unsupported encoding:"+f)}}}return o.onResponse=o.onResponse||r,!0===o.onResponse&&(o.onResponse=i,o.callback=r),!o.headers.authorization&&o.auth&&(o.headers.authorization="Basic "+s(o.auth.username+":"+o.auth.password)),t(o)}function t(t){function r(){d=!0;var r=new Error("ETIMEDOUT");return r.code="ETIMEDOUT",r.duration=t.timeout,e.log.error("Timeout",{id:l._id,milliseconds:t.timeout}),t.callback(r,l)}function n(r){if(d)return e.log.debug("Ignoring timed out state change",{state:l.readyState,id:l.id});if(e.log.debug("State change",{state:l.readyState,id:l.id,timed_out:d}),l.readyState===a.OPENED){e.log.debug("Request started",{id:l.id});for(var n in t.headers)l.setRequestHeader(n,t.headers[n])}else l.readyState===a.HEADERS_RECEIVED?o():l.readyState===a.LOADING?(o(),s()):l.readyState===a.DONE&&(o(),s(),c())}function o(){if(!v.response){if(v.response=!0,e.log.debug("Got response",{id:l.id,status:l.status}),clearTimeout(l.timeoutTimer),l.statusCode=l.status,f&&0==l.statusCode){var r=new Error("CORS request rejected: "+t.uri);return r.cors="rejected",v.loading=!0,v.end=!0,t.callback(r,l)}t.onResponse(null,l)}}function s(){v.loading||(v.loading=!0,e.log.debug("Response body loading",{id:l.id}))}function c(){if(!v.end){if(v.end=!0,e.log.debug("Request done",{id:l.id}),l.body=l.responseText,t.json)try{l.body=JSON.parse(l.responseText)}catch(e){return t.callback(e,l)}t.callback(null,l,l.body)}}var l=new a,d=!1,f=i(t.uri),p="withCredentials"in l;if(u+=1,l.seq_id=u,l.id=u+": "+t.method+" "+t.uri,l._id=l.id,f&&!p){var h=new Error("Browser does not support cross-origin request: "+t.uri);return h.cors="unsupported",t.callback(h,l)}l.timeoutTimer=setTimeout(r,t.timeout);var v={response:!1,loading:!1,end:!1};return l.onreadystatechange=n,l.open(t.method,t.uri,!0),f&&(l.withCredentials=!!t.withCredentials),l.send(t.body),l}function r(){}function n(){var e,t,n={},i=["trace","debug","info","warn","error"];for(t=0;t<i.length;t++)e=i[t],n[e]=r,"undefined"!=typeof console&&console&&console[e]&&(n[e]=o(console,e));return n}function o(e,t){function r(r,n){return"object"==typeof n&&(r+=" "+JSON.stringify(n)),e[t].call(e,r)}return r}function i(e){var t,r=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/;try{t=location.href}catch(e){t=document.createElement("a"),t.href="",t=t.href}var n=r.exec(t.toLowerCase())||[],o=r.exec(e.toLowerCase());return!(!o||o[1]==n[1]&&o[2]==n[2]&&(o[3]||("http:"===o[1]?80:443))==(n[3]||("http:"===n[1]?80:443)))}function s(e){var t,r,n,o,i,s,a,u,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",l=0,d=0,f="",p=[];if(!e)return e;do{t=e.charCodeAt(l++),r=e.charCodeAt(l++),n=e.charCodeAt(l++),u=t<<16|r<<8|n,o=u>>18&63,i=u>>12&63,s=u>>6&63,a=63&u,p[d++]=c.charAt(o)+c.charAt(i)+c.charAt(s)+c.charAt(a)}while(l<e.length);switch(f=p.join(""),e.length%3){case 1:f=f.slice(0,-2)+"==";break;case 2:f=f.slice(0,-1)+"="}return f}var a=XMLHttpRequest;if(!a)throw new Error("missing XMLHttpRequest");e.log={trace:r,debug:r,info:r,warn:r,error:r};var u=0;return e.withCredentials=!1,e.DEFAULT_TIMEOUT=18e4,e.defaults=function(t,r){var n=function(e){return function(r,n){r="string"==typeof r?{uri:r}:JSON.parse(JSON.stringify(r));for(var o in t)void 0===r[o]&&(r[o]=t[o]);return e(r,n)}},o=n(e);return o.get=n(e.get),o.post=n(e.post),o.put=n(e.put),o.head=n(e.head),o},["get","put","post","head"].forEach(function(t){var r=t.toUpperCase();e[t.toLowerCase()]=function(t){"string"==typeof t?t={method:r,uri:t}:(t=JSON.parse(JSON.stringify(t)),t.method=r);var n=[t].concat(Array.prototype.slice.apply(arguments,[1]));return e.apply(this,n)}}),e.couch=function(t,n){function o(e,t,r){if(e)return n(e,t,r);if((t.statusCode<200||t.statusCode>299)&&r.error){e=new Error("CouchDB error: "+(r.error.reason||r.error.error));for(var o in r)e[o]=r[o];return n(e,t,r)}return n(e,t,r)}return"string"==typeof t&&(t={uri:t}),t.json=!0,t.body&&(t.json=t.body),delete t.body,n=n||r,e(t,o)},e})},{}],91:[function(e,t,r){(function(e){!function(n){function o(e){throw new RangeError(D[e])}function i(e,t){for(var r=e.length,n=[];r--;)n[r]=t(e[r]);return n}function s(e,t){var r=e.split("@"),n="";return r.length>1&&(n=r[0]+"@",e=r[1]),e=e.replace(A,"."),n+i(e.split("."),t).join(".")}function a(e){for(var t,r,n=[],o=0,i=e.length;o<i;)t=e.charCodeAt(o++),t>=55296&&t<=56319&&o<i?(r=e.charCodeAt(o++),56320==(64512&r)?n.push(((1023&t)<<10)+(1023&r)+65536):(n.push(t),o--)):n.push(t);return n}function u(e){return i(e,function(e){var t="";return e>65535&&(e-=65536,t+=L(e>>>10&1023|55296),e=56320|1023&e),t+=L(e)}).join("")}function c(e){return e-48<10?e-22:e-65<26?e-65:e-97<26?e-97:w}function l(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function d(e,t,r){var n=0;for(e=r?P(e/x):e>>1,e+=P(e/t);e>M*k>>1;n+=w)e=P(e/M);return P(n+(M+1)*e/(e+T))}function f(e){var t,r,n,i,s,a,l,f,p,h,v=[],m=e.length,y=0,_=I,g=R;for(r=e.lastIndexOf(C),r<0&&(r=0),n=0;n<r;++n)e.charCodeAt(n)>=128&&o("not-basic"),v.push(e.charCodeAt(n));for(i=r>0?r+1:0;i<m;){for(s=y,a=1,l=w;i>=m&&o("invalid-input"),f=c(e.charCodeAt(i++)),(f>=w||f>P((E-y)/a))&&o("overflow"),y+=f*a,p=l<=g?S:l>=g+k?k:l-g,!(f<p);l+=w)h=w-p,a>P(E/h)&&o("overflow"),a*=h;t=v.length+1,g=d(y-s,t,0==s),P(y/t)>E-_&&o("overflow"),_+=P(y/t),y%=t,v.splice(y++,0,_)}return u(v)}function p(e){var t,r,n,i,s,u,c,f,p,h,v,m,y,_,g,b=[];for(e=a(e),m=e.length,t=I,r=0,s=R,u=0;u<m;++u)(v=e[u])<128&&b.push(L(v));for(n=i=b.length,i&&b.push(C);n<m;){for(c=E,u=0;u<m;++u)(v=e[u])>=t&&v<c&&(c=v);for(y=n+1,c-t>P((E-r)/y)&&o("overflow"),r+=(c-t)*y,t=c,u=0;u<m;++u)if(v=e[u],v<t&&++r>E&&o("overflow"),v==t){for(f=r,p=w;h=p<=s?S:p>=s+k?k:p-s,!(f<h);p+=w)g=f-h,_=w-h,b.push(L(l(h+g%_,0))),f=P(g/_);b.push(L(l(f,0))),s=d(r,y,n==i),r=0,++n}++r,++t}return b.join("")}function h(e){return s(e,function(e){return j.test(e)?f(e.slice(4).toLowerCase()):e})}function v(e){return s(e,function(e){return O.test(e)?"xn--"+p(e):e})}var m="object"==typeof r&&r&&!r.nodeType&&r,y="object"==typeof t&&t&&!t.nodeType&&t,_="object"==typeof e&&e;_.global!==_&&_.window!==_&&_.self!==_||(n=_);var g,b,E=2147483647,w=36,S=1,k=26,T=38,x=700,R=72,I=128,C="-",j=/^xn--/,O=/[^\x20-\x7E]/,A=/[\x2E\u3002\uFF0E\uFF61]/g,D={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},M=w-S,P=Math.floor,L=String.fromCharCode;if(g={version:"1.4.1",ucs2:{decode:a,encode:u},decode:f,encode:p,toASCII:v,toUnicode:h},"function"==typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return g});else if(m&&y)if(t.exports==m)y.exports=g;else for(b in g)g.hasOwnProperty(b)&&(m[b]=g[b]);else n.punycode=g}(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],92:[function(e,t,r){var n=e("base-x");t.exports=n("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")},{"base-x":87}],93:[function(e,t,r){"use strict";function n(e){if(e>Q)throw new RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return t.__proto__=o.prototype,t}function o(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return u(e)}return i(e,t,r)}function i(e,t,r){if("string"==typeof e)return c(e,t);if(ArrayBuffer.isView(e))return l(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(V(e,ArrayBuffer)||e&&V(e.buffer,ArrayBuffer))return d(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return o.from(n,t,r);var i=f(e);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return o.from(e[Symbol.toPrimitive]("string"),t,r)
;throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function s(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function a(e,t,r){return s(e),e<=0?n(e):void 0!==t?"string"==typeof r?n(e).fill(t,r):n(e).fill(t):n(e)}function u(e){return s(e),n(e<0?0:0|p(e))}function c(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var r=0|v(e,t),i=n(r),s=i.write(e,t);return s!==r&&(i=i.slice(0,s)),i}function l(e){for(var t=e.length<0?0:0|p(e.length),r=n(t),o=0;o<t;o+=1)r[o]=255&e[o];return r}function d(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;return n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r),n.__proto__=o.prototype,n}function f(e){if(o.isBuffer(e)){var t=0|p(e.length),r=n(t);return 0===r.length?r:(e.copy(r,0,0,t),r)}return void 0!==e.length?"number"!=typeof e.length||W(e.length)?n(0):l(e):"Buffer"===e.type&&Array.isArray(e.data)?l(e.data):void 0}function p(e){if(e>=Q)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Q.toString(16)+" bytes");return 0|e}function h(e){return+e!=e&&(e=0),o.alloc(+e)}function v(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||V(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var i=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return q(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return G(e).length;default:if(i)return n?-1:q(e).length;t=(""+t).toLowerCase(),i=!0}}function m(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if(r>>>=0,t>>>=0,r<=t)return"";for(e||(e="utf8");;)switch(e){case"hex":return O(this,t,r);case"utf8":case"utf-8":return R(this,t,r);case"ascii":return C(this,t,r);case"latin1":case"binary":return j(this,t,r);case"base64":return x(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function y(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function _(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,W(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=o.from(t,n)),o.isBuffer(t))return 0===t.length?-1:g(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):g(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function g(e,t,r,n,o){function i(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}var s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}var c;if(o){var l=-1;for(c=r;c<a;c++)if(i(e,c)===i(t,-1===l?0:c-l)){if(-1===l&&(l=c),c-l+1===u)return l*s}else-1!==l&&(c-=c-l),l=-1}else for(r+u>a&&(r=a-u),c=r;c>=0;c--){for(var d=!0,f=0;f<u;f++)if(i(e,c+f)!==i(t,f)){d=!1;break}if(d)return c}return-1}function b(e,t,r,n){r=Number(r)||0;var o=e.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=t.length;n>i/2&&(n=i/2);for(var s=0;s<n;++s){var a=parseInt(t.substr(2*s,2),16);if(W(a))return s;e[r+s]=a}return s}function E(e,t,r,n){return $(q(t,e.length-r),e,r,n)}function w(e,t,r,n){return $(B(t),e,r,n)}function S(e,t,r,n){return w(e,t,r,n)}function k(e,t,r,n){return $(G(t),e,r,n)}function T(e,t,r,n){return $(K(t,e.length-r),e,r,n)}function x(e,t,r){return 0===t&&r===e.length?H.fromByteArray(e):H.fromByteArray(e.slice(t,r))}function R(e,t,r){r=Math.min(e.length,r);for(var n=[],o=t;o<r;){var i=e[o],s=null,a=i>239?4:i>223?3:i>191?2:1;if(o+a<=r){var u,c,l,d;switch(a){case 1:i<128&&(s=i);break;case 2:u=e[o+1],128==(192&u)&&(d=(31&i)<<6|63&u)>127&&(s=d);break;case 3:u=e[o+1],c=e[o+2],128==(192&u)&&128==(192&c)&&(d=(15&i)<<12|(63&u)<<6|63&c)>2047&&(d<55296||d>57343)&&(s=d);break;case 4:u=e[o+1],c=e[o+2],l=e[o+3],128==(192&u)&&128==(192&c)&&128==(192&l)&&(d=(15&i)<<18|(63&u)<<12|(63&c)<<6|63&l)>65535&&d<1114112&&(s=d)}}null===s?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),o+=a}return I(n)}function I(e){var t=e.length;if(t<=J)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=J));return r}function C(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(127&e[o]);return n}function j(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(e[o]);return n}function O(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=t;i<r;++i)o+=F(e[i]);return o}function A(e,t,r){for(var n=e.slice(t,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function D(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function M(e,t,r,n,i,s){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<s)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function P(e,t,r,n,o,i){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(e,t,r,n,o){return t=+t,r>>>=0,o||P(e,t,r,4,3.4028234663852886e38,-3.4028234663852886e38),z.write(e,t,r,n,23,4),r+4}function U(e,t,r,n,o){return t=+t,r>>>=0,o||P(e,t,r,8,1.7976931348623157e308,-1.7976931348623157e308),z.write(e,t,r,n,52,8),r+8}function N(e){if(e=e.split("=")[0],e=e.trim().replace(Y,""),e.length<2)return"";for(;e.length%4!=0;)e+="=";return e}function F(e){return e<16?"0"+e.toString(16):e.toString(16)}function q(e,t){t=t||1/0;for(var r,n=e.length,o=null,i=[],s=0;s<n;++s){if((r=e.charCodeAt(s))>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function B(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}function K(e,t){for(var r,n,o,i=[],s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}function G(e){return H.toByteArray(N(e))}function $(e,t,r,n){for(var o=0;o<n&&!(o+r>=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function V(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function W(e){return e!==e}var H=e("base64-js"),z=e("ieee754");r.Buffer=o,r.SlowBuffer=h,r.INSPECT_MAX_BYTES=50;var Q=2147483647;r.kMaxLength=Q,o.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(e){return!1}}(),o.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&o[Symbol.species]===o&&Object.defineProperty(o,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),o.poolSize=8192,o.from=function(e,t,r){return i(e,t,r)},o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array,o.alloc=function(e,t,r){return a(e,t,r)},o.allocUnsafe=function(e){return u(e)},o.allocUnsafeSlow=function(e){return u(e)},o.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==o.prototype},o.compare=function(e,t){if(V(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),V(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;for(var r=e.length,n=t.length,i=0,s=Math.min(r,n);i<s;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},o.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=o.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var s=e[r];if(V(s,Uint8Array)&&(s=o.from(s)),!o.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,i),i+=s.length}return n},o.byteLength=v,o.prototype._isBuffer=!0,o.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)y(this,t,t+1);return this},o.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)y(this,t,t+3),y(this,t+1,t+2);return this},o.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)y(this,t,t+7),y(this,t+1,t+6),y(this,t+2,t+5),y(this,t+3,t+4);return this},o.prototype.toString=function(){var e=this.length;return 0===e?"":0===arguments.length?R(this,0,e):m.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===o.compare(this,e)},o.prototype.inspect=function(){var e="",t=r.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},o.prototype.compare=function(e,t,r,n,i){if(V(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(t>>>=0,r>>>=0,n>>>=0,i>>>=0,this===e)return 0;for(var s=i-n,a=r-t,u=Math.min(s,a),c=this.slice(n,i),l=e.slice(t,r),d=0;d<u;++d)if(c[d]!==l[d]){s=c[d],a=l[d];break}return s<a?-1:a<s?1:0},o.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},o.prototype.indexOf=function(e,t,r){return _(this,e,t,r,!0)},o.prototype.lastIndexOf=function(e,t,r){return _(this,e,t,r,!1)},o.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return b(this,e,t,r);case"utf8":case"utf-8":return E(this,e,t,r);case"ascii":return w(this,e,t,r);case"latin1":case"binary":return S(this,e,t,r);case"base64":return k(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,e,t,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var J=4096;o.prototype.slice=function(e,t){var r=this.length;e=~~e,t=void 0===t?r:~~t,e<0?(e+=r)<0&&(e=0):e>r&&(e=r),t<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);var n=this.subarray(e,t);return n.__proto__=o.prototype,n},o.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||D(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return n},o.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||D(e,t,this.length);for(var n=this[e+--t],o=1;t>0&&(o*=256);)n+=this[e+--t]*o;return n},o.prototype.readUInt8=function(e,t){return e>>>=0,t||D(e,1,this.length),this[e]},o.prototype.readUInt16LE=function(e,t){return e>>>=0,t||D(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUInt16BE=function(e,t){return e>>>=0,t||D(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUInt32LE=function(e,t){return e>>>=0,t||D(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUInt32BE=function(e,t){return e>>>=0,t||D(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||D(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return o*=128,n>=o&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||D(e,t,this.length);for(var n=t,o=1,i=this[e+--n];n>0&&(o*=256);)i+=this[e+--n]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i},o.prototype.readInt8=function(e,t){return e>>>=0,t||D(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){e>>>=0,t||D(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(e,t){e>>>=0,t||D(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(e,t){return e>>>=0,t||D(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return e>>>=0,t||D(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readFloatLE=function(e,t){return e>>>=0,t||D(e,4,this.length),z.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return e>>>=0,t||D(e,4,this.length),z.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return e>>>=0,t||D(e,8,this.length),z.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return e>>>=0,t||D(e,8,this.length),z.read(this,e,!1,52,8)},o.prototype.writeUIntLE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){M(this,e,t,r,Math.pow(2,8*r)-1,0)}var o=1,i=0;for(this[t]=255&e;++i<r&&(o*=256);)this[t+i]=e/o&255;return t+r},o.prototype.writeUIntBE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){M(this,e,t,r,Math.pow(2,8*r)-1,0)}var o=r-1,i=1;for(this[t+o]=255&e;--o>=0&&(i*=256);)this[t+o]=e/i&255;return t+r},o.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,1,255,0),this[t]=255&e,t+1},o.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},o.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var o=Math.pow(2,8*r-1);M(this,e,t,r,o-1,-o)}var i=0,s=1,a=0;for(this[t]=255&e;++i<r&&(s*=256);)e<0&&0===a&&0!==this[t+i-1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+r},o.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var o=Math.pow(2,8*r-1);M(this,e,t,r,o-1,-o)}var i=r-1,s=1,a=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===a&&0!==this[t+i+1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+r},o.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},o.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeFloatLE=function(e,t,r){return L(this,e,t,!0,r)},o.prototype.writeFloatBE=function(e,t,r){return L(this,e,t,!1,r)},o.prototype.writeDoubleLE=function(e,t,r){return U(this,e,t,!0,r)},o.prototype.writeDoubleBE=function(e,t,r){return U(this,e,t,!1,r)},o.prototype.copy=function(e,t,r,n){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var i=n-r;if(this===e&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(t,r,n);else if(this===e&&r<t&&t<n)for(var s=i-1;s>=0;--s)e[s+t]=this[s+r];else Uint8Array.prototype.set.call(e,this.subarray(r,n),t);return i},o.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!o.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){var i=e.charCodeAt(0);("utf8"===n&&i<128||"latin1"===n)&&(e=i)}}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0);var s;if("number"==typeof e)for(s=t;s<r;++s)this[s]=e;else{var a=o.isBuffer(e)?e:o.from(e,n),u=a.length;if(0===u)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(s=0;s<r-t;++s)this[s+t]=a[s%u]}return this};var Y=/[^+\/0-9A-Za-z-_]/g},{"base64-js":88,ieee754:235}],94:[function(e,t,r){"use strict";function n(e){if(!e||"object"!=typeof e)throw new TypeError("argument obj is required");var t=e.parameters,r=e.type;if(!r||!p.test(r))throw new TypeError("invalid type");var n=r;if(t&&"object"==typeof t)for(var o,i=Object.keys(t).sort(),a=0;a<i.length;a++){if(o=i[a],!l.test(o))throw new TypeError("invalid parameter name");n+="; "+o+"="+s(t[o])}return n}function o(e){if(!e)throw new TypeError("argument string is required");var t="object"==typeof e?i(e):e;if("string"!=typeof t)throw new TypeError("argument string is required to be a string");var r=t.indexOf(";"),n=-1!==r?t.substr(0,r).trim():t.trim();if(!p.test(n))throw new TypeError("invalid media type");var o=new a(n.toLowerCase());if(-1!==r){var s,c,l;for(u.lastIndex=r;c=u.exec(t);){if(c.index!==r)throw new TypeError("invalid parameter format");r+=c[0].length,s=c[1].toLowerCase(),l=c[2],'"'===l[0]&&(l=l.substr(1,l.length-2).replace(d,"$1")),o.parameters[s]=l}if(r!==t.length)throw new TypeError("invalid parameter format")}return o}function i(e){var t;if("function"==typeof e.getHeader?t=e.getHeader("content-type"):"object"==typeof e.headers&&(t=e.headers&&e.headers["content-type"]),"string"!=typeof t)throw new TypeError("content-type header is missing from object");return t}function s(e){var t=String(e);if(l.test(t))return t;if(t.length>0&&!c.test(t))throw new TypeError("invalid parameter value");return'"'+t.replace(f,"\\$1")+'"'}function a(e){this.parameters=Object.create(null),this.type=e}var u=/; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g,c=/^[\u000b\u0020-\u007e\u0080-\u00ff]+$/,l=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,d=/\\([\u000b\u0020-\u00ff])/g,f=/([\\"])/g,p=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;r.format=n,r.parse=o},{}],95:[function(e,t,r){e("../modules/web.dom.iterable"),e("../modules/es6.string.iterator"),t.exports=e("../modules/core.get-iterator")},{"../modules/core.get-iterator":204,"../modules/es6.string.iterator":222,"../modules/web.dom.iterable":233}],96:[function(e,t,r){e("../modules/web.dom.iterable"),e("../modules/es6.string.iterator"),t.exports=e("../modules/core.is-iterable")},{"../modules/core.is-iterable":205,"../modules/es6.string.iterator":222,"../modules/web.dom.iterable":233}],97:[function(e,t,r){var n=e("../../modules/_core"),o=n.JSON||(n.JSON={stringify:JSON.stringify});t.exports=function(e){return o.stringify.apply(o,arguments)}},{"../../modules/_core":131}],98:[function(e,t,r){e("../../modules/es6.number.is-finite"),t.exports=e("../../modules/_core").Number.isFinite},{"../../modules/_core":131,"../../modules/es6.number.is-finite":207}],99:[function(e,t,r){e("../../modules/es6.number.is-integer"),t.exports=e("../../modules/_core").Number.isInteger},{"../../modules/_core":131,"../../modules/es6.number.is-integer":208}],100:[function(e,t,r){e("../../modules/es6.object.assign"),t.exports=e("../../modules/_core").Object.assign},{"../../modules/_core":131,"../../modules/es6.object.assign":209}],101:[function(e,t,r){e("../../modules/es6.object.create");var n=e("../../modules/_core").Object;t.exports=function(e,t){return n.create(e,t)}},{"../../modules/_core":131,"../../modules/es6.object.create":210}],102:[function(e,t,r){e("../../modules/es6.object.define-property");var n=e("../../modules/_core").Object;t.exports=function(e,t,r){return n.defineProperty(e,t,r)}},{"../../modules/_core":131,"../../modules/es6.object.define-property":211}],103:[function(e,t,r){e("../../modules/es7.object.entries"),t.exports=e("../../modules/_core").Object.entries},{"../../modules/_core":131,"../../modules/es7.object.entries":224}],104:[function(e,t,r){e("../../modules/es6.object.freeze"),t.exports=e("../../modules/_core").Object.freeze},{"../../modules/_core":131,"../../modules/es6.object.freeze":212}],105:[function(e,t,r){e("../../modules/es6.object.get-prototype-of"),t.exports=e("../../modules/_core").Object.getPrototypeOf},{"../../modules/_core":131,"../../modules/es6.object.get-prototype-of":213}],106:[function(e,t,r){e("../../modules/es6.object.keys"),t.exports=e("../../modules/_core").Object.keys},{"../../modules/_core":131,"../../modules/es6.object.keys":214}],107:[function(e,t,r){e("../../modules/es6.object.set-prototype-of"),t.exports=e("../../modules/_core").Object.setPrototypeOf},{"../../modules/_core":131,"../../modules/es6.object.set-prototype-of":215}],108:[function(e,t,r){e("../../modules/es7.object.values"),t.exports=e("../../modules/_core").Object.values},{"../../modules/_core":131,"../../modules/es7.object.values":225}],109:[function(e,t,r){e("../modules/es6.object.to-string"),e("../modules/es6.string.iterator"),e("../modules/web.dom.iterable"),e("../modules/es6.promise"),e("../modules/es7.promise.finally"),e("../modules/es7.promise.try"),t.exports=e("../modules/_core").Promise},{"../modules/_core":131,"../modules/es6.object.to-string":216,"../modules/es6.promise":217,"../modules/es6.string.iterator":222,"../modules/es7.promise.finally":226,"../modules/es7.promise.try":227,"../modules/web.dom.iterable":233}],110:[function(e,t,r){e("../../modules/es6.reflect.construct"),t.exports=e("../../modules/_core").Reflect.construct},{"../../modules/_core":131,"../../modules/es6.reflect.construct":218}],111:[function(e,t,r){e("../../modules/es6.reflect.get-prototype-of"),t.exports=e("../../modules/_core").Reflect.getPrototypeOf},{"../../modules/_core":131,"../../modules/es6.reflect.get-prototype-of":219}],112:[function(e,t,r){e("../../modules/es6.reflect.set-prototype-of"),t.exports=e("../../modules/_core").Reflect.setPrototypeOf},{"../../modules/_core":131,"../../modules/es6.reflect.set-prototype-of":220}],113:[function(e,t,r){e("../modules/es6.object.to-string"),e("../modules/es6.string.iterator"),e("../modules/web.dom.iterable"),e("../modules/es6.set"),e("../modules/es7.set.to-json"),e("../modules/es7.set.of"),e("../modules/es7.set.from"),t.exports=e("../modules/_core").Set},{"../modules/_core":131,"../modules/es6.object.to-string":216,"../modules/es6.set":221,"../modules/es6.string.iterator":222,"../modules/es7.set.from":228,"../modules/es7.set.of":229,"../modules/es7.set.to-json":230,"../modules/web.dom.iterable":233}],114:[function(e,t,r){e("../../modules/es6.symbol"),e("../../modules/es6.object.to-string"),e("../../modules/es7.symbol.async-iterator"),e("../../modules/es7.symbol.observable"),t.exports=e("../../modules/_core").Symbol},{"../../modules/_core":131,"../../modules/es6.object.to-string":216,"../../modules/es6.symbol":223,"../../modules/es7.symbol.async-iterator":231,"../../modules/es7.symbol.observable":232}],115:[function(e,t,r){e("../../modules/es6.string.iterator"),e("../../modules/web.dom.iterable"),t.exports=e("../../modules/_wks-ext").f("iterator")},{"../../modules/_wks-ext":201,"../../modules/es6.string.iterator":222,"../../modules/web.dom.iterable":233}],116:[function(e,t,r){t.exports=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e}},{}],117:[function(e,t,r){t.exports=function(){}},{}],118:[function(e,t,r){t.exports=function(e,t,r,n){if(!(e instanceof t)||void 0!==n&&n in e)throw TypeError(r+": incorrect invocation!");return e}},{}],119:[function(e,t,r){var n=e("./_is-object");t.exports=function(e){if(!n(e))throw TypeError(e+" is not an object!");return e}},{"./_is-object":151}],120:[function(e,t,r){var n=e("./_for-of");t.exports=function(e,t){var r=[];return n(e,!1,r.push,r,t),r}},{"./_for-of":140}],121:[function(e,t,r){var n=e("./_to-iobject"),o=e("./_to-length"),i=e("./_to-absolute-index");t.exports=function(e){return function(t,r,s){var a,u=n(t),c=o(u.length),l=i(s,c);if(e&&r!=r){for(;c>l;)if((a=u[l++])!=a)return!0}else for(;c>l;l++)if((e||l in u)&&u[l]===r)return e||l||0;return!e&&-1}}},{"./_to-absolute-index":191,"./_to-iobject":193,"./_to-length":194}],122:[function(e,t,r){var n=e("./_ctx"),o=e("./_iobject"),i=e("./_to-object"),s=e("./_to-length"),a=e("./_array-species-create");t.exports=function(e,t){var r=1==e,u=2==e,c=3==e,l=4==e,d=6==e,f=5==e||d,p=t||a;return function(t,a,h){for(var v,m,y=i(t),_=o(y),g=n(a,h,3),b=s(_.length),E=0,w=r?p(t,b):u?p(t,0):void 0;b>E;E++)if((f||E in _)&&(v=_[E],m=g(v,E,y),e))if(r)w[E]=m;else if(m)switch(e){case 3:return!0;case 5:return v;case 6:return E;case 2:w.push(v)}else if(l)return!1;return d?-1:c||l?l:w}}},{"./_array-species-create":124,"./_ctx":132,"./_iobject":147,"./_to-length":194,"./_to-object":195}],123:[function(e,t,r){var n=e("./_is-object"),o=e("./_is-array"),i=e("./_wks")("species");t.exports=function(e){var t;return o(e)&&(t=e.constructor,"function"!=typeof t||t!==Array&&!o(t.prototype)||(t=void 0),n(t)&&null===(t=t[i])&&(t=void 0)),void 0===t?Array:t}},{"./_is-array":149,"./_is-object":151,"./_wks":202}],124:[function(e,t,r){var n=e("./_array-species-constructor");t.exports=function(e,t){return new(n(e))(t)}},{"./_array-species-constructor":123}],125:[function(e,t,r){"use strict";var n=e("./_a-function"),o=e("./_is-object"),i=e("./_invoke"),s=[].slice,a={},u=function(e,t,r){if(!(t in a)){for(var n=[],o=0;o<t;o++)n[o]="a["+o+"]";a[t]=Function("F,a","return new F("+n.join(",")+")")}return a[t](e,r)};t.exports=Function.bind||function(e){var t=n(this),r=s.call(arguments,1),a=function(){var n=r.concat(s.call(arguments));return this instanceof a?u(t,n.length,n):i(t,n,e)};return o(t.prototype)&&(a.prototype=t.prototype),a}},{"./_a-function":116,"./_invoke":146,"./_is-object":151}],126:[function(e,t,r){var n=e("./_cof"),o=e("./_wks")("toStringTag"),i="Arguments"==n(function(){return arguments}()),s=function(e,t){try{return e[t]}catch(e){}};t.exports=function(e){var t,r,a;return void 0===e?"Undefined":null===e?"Null":"string"==typeof(r=s(t=Object(e),o))?r:i?n(t):"Object"==(a=n(t))&&"function"==typeof t.callee?"Arguments":a}},{"./_cof":127,"./_wks":202}],127:[function(e,t,r){var n={}.toString;t.exports=function(e){return n.call(e).slice(8,-1)}},{}],128:[function(e,t,r){"use strict";var n=e("./_object-dp").f,o=e("./_object-create"),i=e("./_redefine-all"),s=e("./_ctx"),a=e("./_an-instance"),u=e("./_for-of"),c=e("./_iter-define"),l=e("./_iter-step"),d=e("./_set-species"),f=e("./_descriptors"),p=e("./_meta").fastKey,h=e("./_validate-collection"),v=f?"_s":"size",m=function(e,t){var r,n=p(t);if("F"!==n)return e._i[n];for(r=e._f;r;r=r.n)if(r.k==t)return r};t.exports={getConstructor:function(e,t,r,c){var l=e(function(e,n){a(e,l,t,"_i"),e._t=t,e._i=o(null),e._f=void 0,e._l=void 0,e[v]=0,void 0!=n&&u(n,r,e[c],e)});return i(l.prototype,{clear:function(){for(var e=h(this,t),r=e._i,n=e._f;n;n=n.n)n.r=!0,n.p&&(n.p=n.p.n=void 0),delete r[n.i];e._f=e._l=void 0,e[v]=0},delete:function(e){var r=h(this,t),n=m(r,e);if(n){var o=n.n,i=n.p;delete r._i[n.i],n.r=!0,i&&(i.n=o),o&&(o.p=i),r._f==n&&(r._f=o),r._l==n&&(r._l=i),r[v]--}return!!n},forEach:function(e){h(this,t);for(var r,n=s(e,arguments.length>1?arguments[1]:void 0,3);r=r?r.n:this._f;)for(n(r.v,r.k,this);r&&r.r;)r=r.p},has:function(e){return!!m(h(this,t),e)}}),f&&n(l.prototype,"size",{get:function(){return h(this,t)[v]}}),l},def:function(e,t,r){var n,o,i=m(e,t);return i?i.v=r:(e._l=i={i:o=p(t,!0),k:t,v:r,p:n=e._l,n:void 0,r:!1},e._f||(e._f=i),n&&(n.n=i),e[v]++,"F"!==o&&(e._i[o]=i)),e},getEntry:m,setStrong:function(e,t,r){c(e,t,function(e,r){this._t=h(e,t),this._k=r,this._l=void 0},function(){for(var e=this,t=e._k,r=e._l;r&&r.r;)r=r.p;return e._t&&(e._l=r=r?r.n:e._t._f)?"keys"==t?l(0,r.k):"values"==t?l(0,r.v):l(0,[r.k,r.v]):(e._t=void 0,l(1))},r?"entries":"values",!r,!0),d(t)}}},{"./_an-instance":118,"./_ctx":132,"./_descriptors":134,"./_for-of":140,"./_iter-define":154,"./_iter-step":156,"./_meta":159,"./_object-create":163,"./_object-dp":164,"./_redefine-all":179,"./_set-species":184,"./_validate-collection":199}],129:[function(e,t,r){var n=e("./_classof"),o=e("./_array-from-iterable");t.exports=function(e){return function(){if(n(this)!=e)throw TypeError(e+"#toJSON isn't generic");return o(this)}}},{"./_array-from-iterable":120,"./_classof":126}],130:[function(e,t,r){"use strict";var n=e("./_global"),o=e("./_export"),i=e("./_meta"),s=e("./_fails"),a=e("./_hide"),u=e("./_redefine-all"),c=e("./_for-of"),l=e("./_an-instance"),d=e("./_is-object"),f=e("./_set-to-string-tag"),p=e("./_object-dp").f,h=e("./_array-methods")(0),v=e("./_descriptors");t.exports=function(e,t,r,m,y,_){var g=n[e],b=g,E=y?"set":"add",w=b&&b.prototype,S={};return v&&"function"==typeof b&&(_||w.forEach&&!s(function(){(new b).entries().next()}))?(b=t(function(t,r){l(t,b,e,"_c"),t._c=new g,void 0!=r&&c(r,y,t[E],t)}),
h("add,clear,delete,forEach,get,has,set,keys,values,entries,toJSON".split(","),function(e){var t="add"==e||"set"==e;e in w&&(!_||"clear"!=e)&&a(b.prototype,e,function(r,n){if(l(this,b,e),!t&&_&&!d(r))return"get"==e&&void 0;var o=this._c[e](0===r?0:r,n);return t?this:o})}),_||p(b.prototype,"size",{get:function(){return this._c.size}})):(b=m.getConstructor(t,e,y,E),u(b.prototype,r),i.NEED=!0),f(b,e),S[e]=b,o(o.G+o.W+o.F,S),_||m.setStrong(b,e,y),b}},{"./_an-instance":118,"./_array-methods":122,"./_descriptors":134,"./_export":138,"./_fails":139,"./_for-of":140,"./_global":141,"./_hide":143,"./_is-object":151,"./_meta":159,"./_object-dp":164,"./_redefine-all":179,"./_set-to-string-tag":185}],131:[function(e,t,r){var n=t.exports={version:"2.5.7"};"number"==typeof __e&&(__e=n)},{}],132:[function(e,t,r){var n=e("./_a-function");t.exports=function(e,t,r){if(n(e),void 0===t)return e;switch(r){case 1:return function(r){return e.call(t,r)};case 2:return function(r,n){return e.call(t,r,n)};case 3:return function(r,n,o){return e.call(t,r,n,o)}}return function(){return e.apply(t,arguments)}}},{"./_a-function":116}],133:[function(e,t,r){t.exports=function(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e}},{}],134:[function(e,t,r){t.exports=!e("./_fails")(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},{"./_fails":139}],135:[function(e,t,r){var n=e("./_is-object"),o=e("./_global").document,i=n(o)&&n(o.createElement);t.exports=function(e){return i?o.createElement(e):{}}},{"./_global":141,"./_is-object":151}],136:[function(e,t,r){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},{}],137:[function(e,t,r){var n=e("./_object-keys"),o=e("./_object-gops"),i=e("./_object-pie");t.exports=function(e){var t=n(e),r=o.f;if(r)for(var s,a=r(e),u=i.f,c=0;a.length>c;)u.call(e,s=a[c++])&&t.push(s);return t}},{"./_object-gops":169,"./_object-keys":172,"./_object-pie":173}],138:[function(e,t,r){var n=e("./_global"),o=e("./_core"),i=e("./_ctx"),s=e("./_hide"),a=e("./_has"),u=function(e,t,r){var c,l,d,f=e&u.F,p=e&u.G,h=e&u.S,v=e&u.P,m=e&u.B,y=e&u.W,_=p?o:o[t]||(o[t]={}),g=_.prototype,b=p?n:h?n[t]:(n[t]||{}).prototype;p&&(r=t);for(c in r)(l=!f&&b&&void 0!==b[c])&&a(_,c)||(d=l?b[c]:r[c],_[c]=p&&"function"!=typeof b[c]?r[c]:m&&l?i(d,n):y&&b[c]==d?function(e){var t=function(t,r,n){if(this instanceof e){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,r)}return new e(t,r,n)}return e.apply(this,arguments)};return t.prototype=e.prototype,t}(d):v&&"function"==typeof d?i(Function.call,d):d,v&&((_.virtual||(_.virtual={}))[c]=d,e&u.R&&g&&!g[c]&&s(g,c,d)))};u.F=1,u.G=2,u.S=4,u.P=8,u.B=16,u.W=32,u.U=64,u.R=128,t.exports=u},{"./_core":131,"./_ctx":132,"./_global":141,"./_has":142,"./_hide":143}],139:[function(e,t,r){t.exports=function(e){try{return!!e()}catch(e){return!0}}},{}],140:[function(e,t,r){var n=e("./_ctx"),o=e("./_iter-call"),i=e("./_is-array-iter"),s=e("./_an-object"),a=e("./_to-length"),u=e("./core.get-iterator-method"),c={},l={},r=t.exports=function(e,t,r,d,f){var p,h,v,m,y=f?function(){return e}:u(e),_=n(r,d,t?2:1),g=0;if("function"!=typeof y)throw TypeError(e+" is not iterable!");if(i(y)){for(p=a(e.length);p>g;g++)if((m=t?_(s(h=e[g])[0],h[1]):_(e[g]))===c||m===l)return m}else for(v=y.call(e);!(h=v.next()).done;)if((m=o(v,_,h.value,t))===c||m===l)return m};r.BREAK=c,r.RETURN=l},{"./_an-object":119,"./_ctx":132,"./_is-array-iter":148,"./_iter-call":152,"./_to-length":194,"./core.get-iterator-method":203}],141:[function(e,t,r){var n=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},{}],142:[function(e,t,r){var n={}.hasOwnProperty;t.exports=function(e,t){return n.call(e,t)}},{}],143:[function(e,t,r){var n=e("./_object-dp"),o=e("./_property-desc");t.exports=e("./_descriptors")?function(e,t,r){return n.f(e,t,o(1,r))}:function(e,t,r){return e[t]=r,e}},{"./_descriptors":134,"./_object-dp":164,"./_property-desc":178}],144:[function(e,t,r){var n=e("./_global").document;t.exports=n&&n.documentElement},{"./_global":141}],145:[function(e,t,r){t.exports=!e("./_descriptors")&&!e("./_fails")(function(){return 7!=Object.defineProperty(e("./_dom-create")("div"),"a",{get:function(){return 7}}).a})},{"./_descriptors":134,"./_dom-create":135,"./_fails":139}],146:[function(e,t,r){t.exports=function(e,t,r){var n=void 0===r;switch(t.length){case 0:return n?e():e.call(r);case 1:return n?e(t[0]):e.call(r,t[0]);case 2:return n?e(t[0],t[1]):e.call(r,t[0],t[1]);case 3:return n?e(t[0],t[1],t[2]):e.call(r,t[0],t[1],t[2]);case 4:return n?e(t[0],t[1],t[2],t[3]):e.call(r,t[0],t[1],t[2],t[3])}return e.apply(r,t)}},{}],147:[function(e,t,r){var n=e("./_cof");t.exports=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==n(e)?e.split(""):Object(e)}},{"./_cof":127}],148:[function(e,t,r){var n=e("./_iterators"),o=e("./_wks")("iterator"),i=Array.prototype;t.exports=function(e){return void 0!==e&&(n.Array===e||i[o]===e)}},{"./_iterators":157,"./_wks":202}],149:[function(e,t,r){var n=e("./_cof");t.exports=Array.isArray||function(e){return"Array"==n(e)}},{"./_cof":127}],150:[function(e,t,r){var n=e("./_is-object"),o=Math.floor;t.exports=function(e){return!n(e)&&isFinite(e)&&o(e)===e}},{"./_is-object":151}],151:[function(e,t,r){t.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},{}],152:[function(e,t,r){var n=e("./_an-object");t.exports=function(e,t,r,o){try{return o?t(n(r)[0],r[1]):t(r)}catch(t){var i=e.return;throw void 0!==i&&n(i.call(e)),t}}},{"./_an-object":119}],153:[function(e,t,r){"use strict";var n=e("./_object-create"),o=e("./_property-desc"),i=e("./_set-to-string-tag"),s={};e("./_hide")(s,e("./_wks")("iterator"),function(){return this}),t.exports=function(e,t,r){e.prototype=n(s,{next:o(1,r)}),i(e,t+" Iterator")}},{"./_hide":143,"./_object-create":163,"./_property-desc":178,"./_set-to-string-tag":185,"./_wks":202}],154:[function(e,t,r){"use strict";var n=e("./_library"),o=e("./_export"),i=e("./_redefine"),s=e("./_hide"),a=e("./_iterators"),u=e("./_iter-create"),c=e("./_set-to-string-tag"),l=e("./_object-gpo"),d=e("./_wks")("iterator"),f=!([].keys&&"next"in[].keys()),p=function(){return this};t.exports=function(e,t,r,h,v,m,y){u(r,t,h);var _,g,b,E=function(e){if(!f&&e in T)return T[e];switch(e){case"keys":case"values":return function(){return new r(this,e)}}return function(){return new r(this,e)}},w=t+" Iterator",S="values"==v,k=!1,T=e.prototype,x=T[d]||T["@@iterator"]||v&&T[v],R=x||E(v),I=v?S?E("entries"):R:void 0,C="Array"==t?T.entries||x:x;if(C&&(b=l(C.call(new e)))!==Object.prototype&&b.next&&(c(b,w,!0),n||"function"==typeof b[d]||s(b,d,p)),S&&x&&"values"!==x.name&&(k=!0,R=function(){return x.call(this)}),n&&!y||!f&&!k&&T[d]||s(T,d,R),a[t]=R,a[w]=p,v)if(_={values:S?R:E("values"),keys:m?R:E("keys"),entries:I},y)for(g in _)g in T||i(T,g,_[g]);else o(o.P+o.F*(f||k),t,_);return _}},{"./_export":138,"./_hide":143,"./_iter-create":153,"./_iterators":157,"./_library":158,"./_object-gpo":170,"./_redefine":180,"./_set-to-string-tag":185,"./_wks":202}],155:[function(e,t,r){var n=e("./_wks")("iterator"),o=!1;try{var i=[7][n]();i.return=function(){o=!0},Array.from(i,function(){throw 2})}catch(e){}t.exports=function(e,t){if(!t&&!o)return!1;var r=!1;try{var i=[7],s=i[n]();s.next=function(){return{done:r=!0}},i[n]=function(){return s},e(i)}catch(e){}return r}},{"./_wks":202}],156:[function(e,t,r){t.exports=function(e,t){return{value:t,done:!!e}}},{}],157:[function(e,t,r){t.exports={}},{}],158:[function(e,t,r){t.exports=!0},{}],159:[function(e,t,r){var n=e("./_uid")("meta"),o=e("./_is-object"),i=e("./_has"),s=e("./_object-dp").f,a=0,u=Object.isExtensible||function(){return!0},c=!e("./_fails")(function(){return u(Object.preventExtensions({}))}),l=function(e){s(e,n,{value:{i:"O"+ ++a,w:{}}})},d=function(e,t){if(!o(e))return"symbol"==typeof e?e:("string"==typeof e?"S":"P")+e;if(!i(e,n)){if(!u(e))return"F";if(!t)return"E";l(e)}return e[n].i},f=function(e,t){if(!i(e,n)){if(!u(e))return!0;if(!t)return!1;l(e)}return e[n].w},p=function(e){return c&&h.NEED&&u(e)&&!i(e,n)&&l(e),e},h=t.exports={KEY:n,NEED:!1,fastKey:d,getWeak:f,onFreeze:p}},{"./_fails":139,"./_has":142,"./_is-object":151,"./_object-dp":164,"./_uid":197}],160:[function(e,t,r){var n=e("./_global"),o=e("./_task").set,i=n.MutationObserver||n.WebKitMutationObserver,s=n.process,a=n.Promise,u="process"==e("./_cof")(s);t.exports=function(){var e,t,r,c=function(){var n,o;for(u&&(n=s.domain)&&n.exit();e;){o=e.fn,e=e.next;try{o()}catch(n){throw e?r():t=void 0,n}}t=void 0,n&&n.enter()};if(u)r=function(){s.nextTick(c)};else if(!i||n.navigator&&n.navigator.standalone)if(a&&a.resolve){var l=a.resolve(void 0);r=function(){l.then(c)}}else r=function(){o.call(n,c)};else{var d=!0,f=document.createTextNode("");new i(c).observe(f,{characterData:!0}),r=function(){f.data=d=!d}}return function(n){var o={fn:n,next:void 0};t&&(t.next=o),e||(e=o,r()),t=o}}},{"./_cof":127,"./_global":141,"./_task":190}],161:[function(e,t,r){"use strict";function n(e){var t,r;this.promise=new e(function(e,n){if(void 0!==t||void 0!==r)throw TypeError("Bad Promise constructor");t=e,r=n}),this.resolve=o(t),this.reject=o(r)}var o=e("./_a-function");t.exports.f=function(e){return new n(e)}},{"./_a-function":116}],162:[function(e,t,r){"use strict";var n=e("./_object-keys"),o=e("./_object-gops"),i=e("./_object-pie"),s=e("./_to-object"),a=e("./_iobject"),u=Object.assign;t.exports=!u||e("./_fails")(function(){var e={},t={},r=Symbol(),n="abcdefghijklmnopqrst";return e[r]=7,n.split("").forEach(function(e){t[e]=e}),7!=u({},e)[r]||Object.keys(u({},t)).join("")!=n})?function(e,t){for(var r=s(e),u=arguments.length,c=1,l=o.f,d=i.f;u>c;)for(var f,p=a(arguments[c++]),h=l?n(p).concat(l(p)):n(p),v=h.length,m=0;v>m;)d.call(p,f=h[m++])&&(r[f]=p[f]);return r}:u},{"./_fails":139,"./_iobject":147,"./_object-gops":169,"./_object-keys":172,"./_object-pie":173,"./_to-object":195}],163:[function(e,t,r){var n=e("./_an-object"),o=e("./_object-dps"),i=e("./_enum-bug-keys"),s=e("./_shared-key")("IE_PROTO"),a=function(){},u=function(){var t,r=e("./_dom-create")("iframe"),n=i.length;for(r.style.display="none",e("./_html").appendChild(r),r.src="javascript:",t=r.contentWindow.document,t.open(),t.write("<script>document.F=Object<\/script>"),t.close(),u=t.F;n--;)delete u.prototype[i[n]];return u()};t.exports=Object.create||function(e,t){var r;return null!==e?(a.prototype=n(e),r=new a,a.prototype=null,r[s]=e):r=u(),void 0===t?r:o(r,t)}},{"./_an-object":119,"./_dom-create":135,"./_enum-bug-keys":136,"./_html":144,"./_object-dps":165,"./_shared-key":186}],164:[function(e,t,r){var n=e("./_an-object"),o=e("./_ie8-dom-define"),i=e("./_to-primitive"),s=Object.defineProperty;r.f=e("./_descriptors")?Object.defineProperty:function(e,t,r){if(n(e),t=i(t,!0),n(r),o)try{return s(e,t,r)}catch(e){}if("get"in r||"set"in r)throw TypeError("Accessors not supported!");return"value"in r&&(e[t]=r.value),e}},{"./_an-object":119,"./_descriptors":134,"./_ie8-dom-define":145,"./_to-primitive":196}],165:[function(e,t,r){var n=e("./_object-dp"),o=e("./_an-object"),i=e("./_object-keys");t.exports=e("./_descriptors")?Object.defineProperties:function(e,t){o(e);for(var r,s=i(t),a=s.length,u=0;a>u;)n.f(e,r=s[u++],t[r]);return e}},{"./_an-object":119,"./_descriptors":134,"./_object-dp":164,"./_object-keys":172}],166:[function(e,t,r){var n=e("./_object-pie"),o=e("./_property-desc"),i=e("./_to-iobject"),s=e("./_to-primitive"),a=e("./_has"),u=e("./_ie8-dom-define"),c=Object.getOwnPropertyDescriptor;r.f=e("./_descriptors")?c:function(e,t){if(e=i(e),t=s(t,!0),u)try{return c(e,t)}catch(e){}if(a(e,t))return o(!n.f.call(e,t),e[t])}},{"./_descriptors":134,"./_has":142,"./_ie8-dom-define":145,"./_object-pie":173,"./_property-desc":178,"./_to-iobject":193,"./_to-primitive":196}],167:[function(e,t,r){var n=e("./_to-iobject"),o=e("./_object-gopn").f,i={}.toString,s="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[],a=function(e){try{return o(e)}catch(e){return s.slice()}};t.exports.f=function(e){return s&&"[object Window]"==i.call(e)?a(e):o(n(e))}},{"./_object-gopn":168,"./_to-iobject":193}],168:[function(e,t,r){var n=e("./_object-keys-internal"),o=e("./_enum-bug-keys").concat("length","prototype");r.f=Object.getOwnPropertyNames||function(e){return n(e,o)}},{"./_enum-bug-keys":136,"./_object-keys-internal":171}],169:[function(e,t,r){r.f=Object.getOwnPropertySymbols},{}],170:[function(e,t,r){var n=e("./_has"),o=e("./_to-object"),i=e("./_shared-key")("IE_PROTO"),s=Object.prototype;t.exports=Object.getPrototypeOf||function(e){return e=o(e),n(e,i)?e[i]:"function"==typeof e.constructor&&e instanceof e.constructor?e.constructor.prototype:e instanceof Object?s:null}},{"./_has":142,"./_shared-key":186,"./_to-object":195}],171:[function(e,t,r){var n=e("./_has"),o=e("./_to-iobject"),i=e("./_array-includes")(!1),s=e("./_shared-key")("IE_PROTO");t.exports=function(e,t){var r,a=o(e),u=0,c=[];for(r in a)r!=s&&n(a,r)&&c.push(r);for(;t.length>u;)n(a,r=t[u++])&&(~i(c,r)||c.push(r));return c}},{"./_array-includes":121,"./_has":142,"./_shared-key":186,"./_to-iobject":193}],172:[function(e,t,r){var n=e("./_object-keys-internal"),o=e("./_enum-bug-keys");t.exports=Object.keys||function(e){return n(e,o)}},{"./_enum-bug-keys":136,"./_object-keys-internal":171}],173:[function(e,t,r){r.f={}.propertyIsEnumerable},{}],174:[function(e,t,r){var n=e("./_export"),o=e("./_core"),i=e("./_fails");t.exports=function(e,t){var r=(o.Object||{})[e]||Object[e],s={};s[e]=t(r),n(n.S+n.F*i(function(){r(1)}),"Object",s)}},{"./_core":131,"./_export":138,"./_fails":139}],175:[function(e,t,r){var n=e("./_object-keys"),o=e("./_to-iobject"),i=e("./_object-pie").f;t.exports=function(e){return function(t){for(var r,s=o(t),a=n(s),u=a.length,c=0,l=[];u>c;)i.call(s,r=a[c++])&&l.push(e?[r,s[r]]:s[r]);return l}}},{"./_object-keys":172,"./_object-pie":173,"./_to-iobject":193}],176:[function(e,t,r){t.exports=function(e){try{return{e:!1,v:e()}}catch(e){return{e:!0,v:e}}}},{}],177:[function(e,t,r){var n=e("./_an-object"),o=e("./_is-object"),i=e("./_new-promise-capability");t.exports=function(e,t){if(n(e),o(t)&&t.constructor===e)return t;var r=i.f(e);return(0,r.resolve)(t),r.promise}},{"./_an-object":119,"./_is-object":151,"./_new-promise-capability":161}],178:[function(e,t,r){t.exports=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}},{}],179:[function(e,t,r){var n=e("./_hide");t.exports=function(e,t,r){for(var o in t)r&&e[o]?e[o]=t[o]:n(e,o,t[o]);return e}},{"./_hide":143}],180:[function(e,t,r){t.exports=e("./_hide")},{"./_hide":143}],181:[function(e,t,r){"use strict";var n=e("./_export"),o=e("./_a-function"),i=e("./_ctx"),s=e("./_for-of");t.exports=function(e){n(n.S,e,{from:function(e){var t,r,n,a,u=arguments[1];return o(this),t=void 0!==u,t&&o(u),void 0==e?new this:(r=[],t?(n=0,a=i(u,arguments[2],2),s(e,!1,function(e){r.push(a(e,n++))})):s(e,!1,r.push,r),new this(r))}})}},{"./_a-function":116,"./_ctx":132,"./_export":138,"./_for-of":140}],182:[function(e,t,r){"use strict";var n=e("./_export");t.exports=function(e){n(n.S,e,{of:function(){for(var e=arguments.length,t=new Array(e);e--;)t[e]=arguments[e];return new this(t)}})}},{"./_export":138}],183:[function(e,t,r){var n=e("./_is-object"),o=e("./_an-object"),i=function(e,t){if(o(e),!n(t)&&null!==t)throw TypeError(t+": can't set as prototype!")};t.exports={set:Object.setPrototypeOf||("__proto__"in{}?function(t,r,n){try{n=e("./_ctx")(Function.call,e("./_object-gopd").f(Object.prototype,"__proto__").set,2),n(t,[]),r=!(t instanceof Array)}catch(e){r=!0}return function(e,t){return i(e,t),r?e.__proto__=t:n(e,t),e}}({},!1):void 0),check:i}},{"./_an-object":119,"./_ctx":132,"./_is-object":151,"./_object-gopd":166}],184:[function(e,t,r){"use strict";var n=e("./_global"),o=e("./_core"),i=e("./_object-dp"),s=e("./_descriptors"),a=e("./_wks")("species");t.exports=function(e){var t="function"==typeof o[e]?o[e]:n[e];s&&t&&!t[a]&&i.f(t,a,{configurable:!0,get:function(){return this}})}},{"./_core":131,"./_descriptors":134,"./_global":141,"./_object-dp":164,"./_wks":202}],185:[function(e,t,r){var n=e("./_object-dp").f,o=e("./_has"),i=e("./_wks")("toStringTag");t.exports=function(e,t,r){e&&!o(e=r?e:e.prototype,i)&&n(e,i,{configurable:!0,value:t})}},{"./_has":142,"./_object-dp":164,"./_wks":202}],186:[function(e,t,r){var n=e("./_shared")("keys"),o=e("./_uid");t.exports=function(e){return n[e]||(n[e]=o(e))}},{"./_shared":187,"./_uid":197}],187:[function(e,t,r){var n=e("./_core"),o=e("./_global"),i=o["__core-js_shared__"]||(o["__core-js_shared__"]={});(t.exports=function(e,t){return i[e]||(i[e]=void 0!==t?t:{})})("versions",[]).push({version:n.version,mode:e("./_library")?"pure":"global",copyright:"© 2018 Denis Pushkarev (zloirock.ru)"})},{"./_core":131,"./_global":141,"./_library":158}],188:[function(e,t,r){var n=e("./_an-object"),o=e("./_a-function"),i=e("./_wks")("species");t.exports=function(e,t){var r,s=n(e).constructor;return void 0===s||void 0==(r=n(s)[i])?t:o(r)}},{"./_a-function":116,"./_an-object":119,"./_wks":202}],189:[function(e,t,r){var n=e("./_to-integer"),o=e("./_defined");t.exports=function(e){return function(t,r){var i,s,a=String(o(t)),u=n(r),c=a.length;return u<0||u>=c?e?"":void 0:(i=a.charCodeAt(u),i<55296||i>56319||u+1===c||(s=a.charCodeAt(u+1))<56320||s>57343?e?a.charAt(u):i:e?a.slice(u,u+2):s-56320+(i-55296<<10)+65536)}}},{"./_defined":133,"./_to-integer":192}],190:[function(e,t,r){var n,o,i,s=e("./_ctx"),a=e("./_invoke"),u=e("./_html"),c=e("./_dom-create"),l=e("./_global"),d=l.process,f=l.setImmediate,p=l.clearImmediate,h=l.MessageChannel,v=l.Dispatch,m=0,y={},_=function(){var e=+this;if(y.hasOwnProperty(e)){var t=y[e];delete y[e],t()}},g=function(e){_.call(e.data)};f&&p||(f=function(e){for(var t=[],r=1;arguments.length>r;)t.push(arguments[r++]);return y[++m]=function(){a("function"==typeof e?e:Function(e),t)},n(m),m},p=function(e){delete y[e]},"process"==e("./_cof")(d)?n=function(e){d.nextTick(s(_,e,1))}:v&&v.now?n=function(e){v.now(s(_,e,1))}:h?(o=new h,i=o.port2,o.port1.onmessage=g,n=s(i.postMessage,i,1)):l.addEventListener&&"function"==typeof postMessage&&!l.importScripts?(n=function(e){l.postMessage(e+"","*")},l.addEventListener("message",g,!1)):n="onreadystatechange"in c("script")?function(e){u.appendChild(c("script")).onreadystatechange=function(){u.removeChild(this),_.call(e)}}:function(e){setTimeout(s(_,e,1),0)}),t.exports={set:f,clear:p}},{"./_cof":127,"./_ctx":132,"./_dom-create":135,"./_global":141,"./_html":144,"./_invoke":146}],191:[function(e,t,r){var n=e("./_to-integer"),o=Math.max,i=Math.min;t.exports=function(e,t){return e=n(e),e<0?o(e+t,0):i(e,t)}},{"./_to-integer":192}],192:[function(e,t,r){var n=Math.ceil,o=Math.floor;t.exports=function(e){return isNaN(e=+e)?0:(e>0?o:n)(e)}},{}],193:[function(e,t,r){var n=e("./_iobject"),o=e("./_defined");t.exports=function(e){return n(o(e))}},{"./_defined":133,"./_iobject":147}],194:[function(e,t,r){var n=e("./_to-integer"),o=Math.min;t.exports=function(e){return e>0?o(n(e),9007199254740991):0}},{"./_to-integer":192}],195:[function(e,t,r){var n=e("./_defined");t.exports=function(e){return Object(n(e))}},{"./_defined":133}],196:[function(e,t,r){var n=e("./_is-object");t.exports=function(e,t){if(!n(e))return e;var r,o;if(t&&"function"==typeof(r=e.toString)&&!n(o=r.call(e)))return o;if("function"==typeof(r=e.valueOf)&&!n(o=r.call(e)))return o;if(!t&&"function"==typeof(r=e.toString)&&!n(o=r.call(e)))return o;throw TypeError("Can't convert object to primitive value")}},{"./_is-object":151}],197:[function(e,t,r){var n=0,o=Math.random();t.exports=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++n+o).toString(36))}},{}],198:[function(e,t,r){var n=e("./_global"),o=n.navigator;t.exports=o&&o.userAgent||""},{"./_global":141}],199:[function(e,t,r){var n=e("./_is-object");t.exports=function(e,t){if(!n(e)||e._t!==t)throw TypeError("Incompatible receiver, "+t+" required!");return e}},{"./_is-object":151}],200:[function(e,t,r){var n=e("./_global"),o=e("./_core"),i=e("./_library"),s=e("./_wks-ext"),a=e("./_object-dp").f;t.exports=function(e){var t=o.Symbol||(o.Symbol=i?{}:n.Symbol||{});"_"==e.charAt(0)||e in t||a(t,e,{value:s.f(e)})}},{"./_core":131,"./_global":141,"./_library":158,"./_object-dp":164,"./_wks-ext":201}],201:[function(e,t,r){r.f=e("./_wks")},{"./_wks":202}],202:[function(e,t,r){var n=e("./_shared")("wks"),o=e("./_uid"),i=e("./_global").Symbol,s="function"==typeof i;(t.exports=function(e){return n[e]||(n[e]=s&&i[e]||(s?i:o)("Symbol."+e))}).store=n},{"./_global":141,"./_shared":187,"./_uid":197}],203:[function(e,t,r){var n=e("./_classof"),o=e("./_wks")("iterator"),i=e("./_iterators");t.exports=e("./_core").getIteratorMethod=function(e){if(void 0!=e)return e[o]||e["@@iterator"]||i[n(e)]}},{"./_classof":126,"./_core":131,"./_iterators":157,"./_wks":202}],204:[function(e,t,r){var n=e("./_an-object"),o=e("./core.get-iterator-method");t.exports=e("./_core").getIterator=function(e){var t=o(e);if("function"!=typeof t)throw TypeError(e+" is not iterable!");return n(t.call(e))}},{"./_an-object":119,"./_core":131,"./core.get-iterator-method":203}],205:[function(e,t,r){var n=e("./_classof"),o=e("./_wks")("iterator"),i=e("./_iterators");t.exports=e("./_core").isIterable=function(e){var t=Object(e);return void 0!==t[o]||"@@iterator"in t||i.hasOwnProperty(n(t))}},{"./_classof":126,"./_core":131,"./_iterators":157,"./_wks":202}],206:[function(e,t,r){"use strict";var n=e("./_add-to-unscopables"),o=e("./_iter-step"),i=e("./_iterators"),s=e("./_to-iobject");t.exports=e("./_iter-define")(Array,"Array",function(e,t){this._t=s(e),this._i=0,this._k=t},function(){var e=this._t,t=this._k,r=this._i++;return!e||r>=e.length?(this._t=void 0,o(1)):"keys"==t?o(0,r):"values"==t?o(0,e[r]):o(0,[r,e[r]])},"values"),i.Arguments=i.Array,n("keys"),n("values"),n("entries")},{"./_add-to-unscopables":117,"./_iter-define":154,"./_iter-step":156,"./_iterators":157,"./_to-iobject":193}],207:[function(e,t,r){var n=e("./_export"),o=e("./_global").isFinite;n(n.S,"Number",{isFinite:function(e){return"number"==typeof e&&o(e)}})},{"./_export":138,"./_global":141}],208:[function(e,t,r){var n=e("./_export");n(n.S,"Number",{isInteger:e("./_is-integer")})},{"./_export":138,"./_is-integer":150}],209:[function(e,t,r){var n=e("./_export");n(n.S+n.F,"Object",{assign:e("./_object-assign")})},{"./_export":138,"./_object-assign":162}],210:[function(e,t,r){var n=e("./_export");n(n.S,"Object",{create:e("./_object-create")})},{"./_export":138,"./_object-create":163}],211:[function(e,t,r){var n=e("./_export");n(n.S+n.F*!e("./_descriptors"),"Object",{defineProperty:e("./_object-dp").f})},{"./_descriptors":134,"./_export":138,"./_object-dp":164}],212:[function(e,t,r){var n=e("./_is-object"),o=e("./_meta").onFreeze;e("./_object-sap")("freeze",function(e){return function(t){return e&&n(t)?e(o(t)):t}})},{"./_is-object":151,"./_meta":159,"./_object-sap":174}],213:[function(e,t,r){var n=e("./_to-object"),o=e("./_object-gpo");e("./_object-sap")("getPrototypeOf",function(){return function(e){return o(n(e))}})},{"./_object-gpo":170,"./_object-sap":174,"./_to-object":195}],214:[function(e,t,r){var n=e("./_to-object"),o=e("./_object-keys");e("./_object-sap")("keys",function(){return function(e){return o(n(e))}})},{"./_object-keys":172,"./_object-sap":174,"./_to-object":195}],215:[function(e,t,r){var n=e("./_export");n(n.S,"Object",{setPrototypeOf:e("./_set-proto").set})},{"./_export":138,"./_set-proto":183}],216:[function(e,t,r){},{}],217:[function(e,t,r){"use strict";var n,o,i,s,a=e("./_library"),u=e("./_global"),c=e("./_ctx"),l=e("./_classof"),d=e("./_export"),f=e("./_is-object"),p=e("./_a-function"),h=e("./_an-instance"),v=e("./_for-of"),m=e("./_species-constructor"),y=e("./_task").set,_=e("./_microtask")(),g=e("./_new-promise-capability"),b=e("./_perform"),E=e("./_user-agent"),w=e("./_promise-resolve"),S=u.TypeError,k=u.process,T=k&&k.versions,x=T&&T.v8||"",R=u.Promise,I="process"==l(k),C=function(){},j=o=g.f,O=!!function(){try{var t=R.resolve(1),r=(t.constructor={})[e("./_wks")("species")]=function(e){e(C,C)};return(I||"function"==typeof PromiseRejectionEvent)&&t.then(C)instanceof r&&0!==x.indexOf("6.6")&&-1===E.indexOf("Chrome/66")}catch(e){}}(),A=function(e){var t;return!(!f(e)||"function"!=typeof(t=e.then))&&t},D=function(e,t){if(!e._n){e._n=!0;var r=e._c;_(function(){for(var n=e._v,o=1==e._s,i=0;r.length>i;)!function(t){var r,i,s,a=o?t.ok:t.fail,u=t.resolve,c=t.reject,l=t.domain;try{a?(o||(2==e._h&&L(e),e._h=1),!0===a?r=n:(l&&l.enter(),r=a(n),l&&(l.exit(),s=!0)),r===t.promise?c(S("Promise-chain cycle")):(i=A(r))?i.call(r,u,c):u(r)):c(n)}catch(e){l&&!s&&l.exit(),c(e)}}(r[i++]);e._c=[],e._n=!1,t&&!e._h&&M(e)})}},M=function(e){y.call(u,function(){var t,r,n,o=e._v,i=P(e);if(i&&(t=b(function(){I?k.emit("unhandledRejection",o,e):(r=u.onunhandledrejection)?r({promise:e,reason:o}):(n=u.console)&&n.error&&n.error("Unhandled promise rejection",o)}),e._h=I||P(e)?2:1),e._a=void 0,i&&t.e)throw t.v})},P=function(e){return 1!==e._h&&0===(e._a||e._c).length},L=function(e){y.call(u,function(){var t;I?k.emit("rejectionHandled",e):(t=u.onrejectionhandled)&&t({promise:e,reason:e._v})})},U=function(e){var t=this;t._d||(t._d=!0,t=t._w||t,t._v=e,t._s=2,t._a||(t._a=t._c.slice()),D(t,!0))},N=function(e){var t,r=this;if(!r._d){r._d=!0,r=r._w||r;try{if(r===e)throw S("Promise can't be resolved itself");(t=A(e))?_(function(){var n={_w:r,_d:!1};try{t.call(e,c(N,n,1),c(U,n,1))}catch(e){U.call(n,e)}}):(r._v=e,r._s=1,D(r,!1))}catch(e){U.call({_w:r,_d:!1},e)}}};O||(R=function(e){h(this,R,"Promise","_h"),p(e),n.call(this);try{e(c(N,this,1),c(U,this,1))}catch(e){U.call(this,e)}},n=function(e){this._c=[],this._a=void 0,this._s=0,this._d=!1,this._v=void 0,this._h=0,this._n=!1},n.prototype=e("./_redefine-all")(R.prototype,{then:function(e,t){var r=j(m(this,R));return r.ok="function"!=typeof e||e,r.fail="function"==typeof t&&t,r.domain=I?k.domain:void 0,this._c.push(r),this._a&&this._a.push(r),this._s&&D(this,!1),r.promise},catch:function(e){return this.then(void 0,e)}}),i=function(){var e=new n;this.promise=e,this.resolve=c(N,e,1),this.reject=c(U,e,1)},g.f=j=function(e){return e===R||e===s?new i(e):o(e)}),d(d.G+d.W+d.F*!O,{Promise:R}),e("./_set-to-string-tag")(R,"Promise"),e("./_set-species")("Promise"),s=e("./_core").Promise,d(d.S+d.F*!O,"Promise",{reject:function(e){var t=j(this);return(0,t.reject)(e),t.promise}}),d(d.S+d.F*(a||!O),"Promise",{resolve:function(e){return w(a&&this===s?R:this,e)}}),d(d.S+d.F*!(O&&e("./_iter-detect")(function(e){R.all(e).catch(C)})),"Promise",{all:function(e){var t=this,r=j(t),n=r.resolve,o=r.reject,i=b(function(){var r=[],i=0,s=1;v(e,!1,function(e){var a=i++,u=!1;r.push(void 0),s++,t.resolve(e).then(function(e){u||(u=!0,r[a]=e,--s||n(r))},o)}),--s||n(r)});return i.e&&o(i.v),r.promise},race:function(e){var t=this,r=j(t),n=r.reject,o=b(function(){v(e,!1,function(e){t.resolve(e).then(r.resolve,n)})});return o.e&&n(o.v),r.promise}})},{"./_a-function":116,"./_an-instance":118,"./_classof":126,"./_core":131,"./_ctx":132,"./_export":138,"./_for-of":140,"./_global":141,"./_is-object":151,"./_iter-detect":155,"./_library":158,"./_microtask":160,"./_new-promise-capability":161,"./_perform":176,"./_promise-resolve":177,"./_redefine-all":179,"./_set-species":184,"./_set-to-string-tag":185,"./_species-constructor":188,"./_task":190,"./_user-agent":198,"./_wks":202}],218:[function(e,t,r){var n=e("./_export"),o=e("./_object-create"),i=e("./_a-function"),s=e("./_an-object"),a=e("./_is-object"),u=e("./_fails"),c=e("./_bind"),l=(e("./_global").Reflect||{}).construct,d=u(function(){function e(){}return!(l(function(){},[],e)instanceof e)}),f=!u(function(){l(function(){})});n(n.S+n.F*(d||f),"Reflect",{construct:function(e,t){i(e),s(t);var r=arguments.length<3?e:i(arguments[2]);if(f&&!d)return l(e,t,r);if(e==r){switch(t.length){case 0:return new e;case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3])}var n=[null];return n.push.apply(n,t),new(c.apply(e,n))}var u=r.prototype,p=o(a(u)?u:Object.prototype),h=Function.apply.call(e,p,t);return a(h)?h:p}})},{"./_a-function":116,"./_an-object":119,"./_bind":125,"./_export":138,"./_fails":139,"./_global":141,"./_is-object":151,"./_object-create":163}],219:[function(e,t,r){var n=e("./_export"),o=e("./_object-gpo"),i=e("./_an-object");n(n.S,"Reflect",{getPrototypeOf:function(e){return o(i(e))}})},{"./_an-object":119,"./_export":138,"./_object-gpo":170}],220:[function(e,t,r){var n=e("./_export"),o=e("./_set-proto");o&&n(n.S,"Reflect",{setPrototypeOf:function(e,t){o.check(e,t);try{return o.set(e,t),!0}catch(e){return!1}}})},{"./_export":138,"./_set-proto":183}],221:[function(e,t,r){"use strict";var n=e("./_collection-strong"),o=e("./_validate-collection");t.exports=e("./_collection")("Set",function(e){return function(){return e(this,arguments.length>0?arguments[0]:void 0)}},{add:function(e){return n.def(o(this,"Set"),e=0===e?0:e,e)}},n)},{"./_collection":130,"./_collection-strong":128,"./_validate-collection":199}],222:[function(e,t,r){"use strict";var n=e("./_string-at")(!0);e("./_iter-define")(String,"String",function(e){this._t=String(e),this._i=0},function(){var e,t=this._t,r=this._i;return r>=t.length?{value:void 0,done:!0}:(e=n(t,r),this._i+=e.length,{value:e,done:!1})})},{"./_iter-define":154,"./_string-at":189}],223:[function(e,t,r){"use strict";var n=e("./_global"),o=e("./_has"),i=e("./_descriptors"),s=e("./_export"),a=e("./_redefine"),u=e("./_meta").KEY,c=e("./_fails"),l=e("./_shared"),d=e("./_set-to-string-tag"),f=e("./_uid"),p=e("./_wks"),h=e("./_wks-ext"),v=e("./_wks-define"),m=e("./_enum-keys"),y=e("./_is-array"),_=e("./_an-object"),g=e("./_is-object"),b=e("./_to-iobject"),E=e("./_to-primitive"),w=e("./_property-desc"),S=e("./_object-create"),k=e("./_object-gopn-ext"),T=e("./_object-gopd"),x=e("./_object-dp"),R=e("./_object-keys"),I=T.f,C=x.f,j=k.f,O=n.Symbol,A=n.JSON,D=A&&A.stringify,M=p("_hidden"),P=p("toPrimitive"),L={}.propertyIsEnumerable,U=l("symbol-registry"),N=l("symbols"),F=l("op-symbols"),q=Object.prototype,B="function"==typeof O,K=n.QObject,G=!K||!K.prototype||!K.prototype.findChild,$=i&&c(function(){return 7!=S(C({},"a",{get:function(){return C(this,"a",{value:7}).a}})).a})?function(e,t,r){var n=I(q,t);n&&delete q[t],C(e,t,r),n&&e!==q&&C(q,t,n)}:C,V=function(e){var t=N[e]=S(O.prototype);return t._k=e,t},W=B&&"symbol"==typeof O.iterator?function(e){return"symbol"==typeof e}:function(e){return e instanceof O},H=function(e,t,r){return e===q&&H(F,t,r),_(e),t=E(t,!0),_(r),o(N,t)?(r.enumerable?(o(e,M)&&e[M][t]&&(e[M][t]=!1),r=S(r,{enumerable:w(0,!1)})):(o(e,M)||C(e,M,w(1,{})),e[M][t]=!0),$(e,t,r)):C(e,t,r)},z=function(e,t){_(e);for(var r,n=m(t=b(t)),o=0,i=n.length;i>o;)H(e,r=n[o++],t[r]);return e},Q=function(e,t){return void 0===t?S(e):z(S(e),t)},J=function(e){var t=L.call(this,e=E(e,!0));return!(this===q&&o(N,e)&&!o(F,e))&&(!(t||!o(this,e)||!o(N,e)||o(this,M)&&this[M][e])||t)},Y=function(e,t){if(e=b(e),t=E(t,!0),e!==q||!o(N,t)||o(F,t)){var r=I(e,t);return!r||!o(N,t)||o(e,M)&&e[M][t]||(r.enumerable=!0),r}},X=function(e){for(var t,r=j(b(e)),n=[],i=0;r.length>i;)o(N,t=r[i++])||t==M||t==u||n.push(t);return n},Z=function(e){for(var t,r=e===q,n=j(r?F:b(e)),i=[],s=0;n.length>s;)!o(N,t=n[s++])||r&&!o(q,t)||i.push(N[t]);return i};B||(O=function(){if(this instanceof O)throw TypeError("Symbol is not a constructor!");var e=f(arguments.length>0?arguments[0]:void 0),t=function(r){this===q&&t.call(F,r),o(this,M)&&o(this[M],e)&&(this[M][e]=!1),$(this,e,w(1,r))};return i&&G&&$(q,e,{configurable:!0,set:t}),V(e)},a(O.prototype,"toString",function(){return this._k}),T.f=Y,x.f=H,e("./_object-gopn").f=k.f=X,e("./_object-pie").f=J,e("./_object-gops").f=Z,
i&&!e("./_library")&&a(q,"propertyIsEnumerable",J,!0),h.f=function(e){return V(p(e))}),s(s.G+s.W+s.F*!B,{Symbol:O});for(var ee="hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(","),te=0;ee.length>te;)p(ee[te++]);for(var re=R(p.store),ne=0;re.length>ne;)v(re[ne++]);s(s.S+s.F*!B,"Symbol",{for:function(e){return o(U,e+="")?U[e]:U[e]=O(e)},keyFor:function(e){if(!W(e))throw TypeError(e+" is not a symbol!");for(var t in U)if(U[t]===e)return t},useSetter:function(){G=!0},useSimple:function(){G=!1}}),s(s.S+s.F*!B,"Object",{create:Q,defineProperty:H,defineProperties:z,getOwnPropertyDescriptor:Y,getOwnPropertyNames:X,getOwnPropertySymbols:Z}),A&&s(s.S+s.F*(!B||c(function(){var e=O();return"[null]"!=D([e])||"{}"!=D({a:e})||"{}"!=D(Object(e))})),"JSON",{stringify:function(e){for(var t,r,n=[e],o=1;arguments.length>o;)n.push(arguments[o++]);if(r=t=n[1],(g(t)||void 0!==e)&&!W(e))return y(t)||(t=function(e,t){if("function"==typeof r&&(t=r.call(this,e,t)),!W(t))return t}),n[1]=t,D.apply(A,n)}}),O.prototype[P]||e("./_hide")(O.prototype,P,O.prototype.valueOf),d(O,"Symbol"),d(Math,"Math",!0),d(n.JSON,"JSON",!0)},{"./_an-object":119,"./_descriptors":134,"./_enum-keys":137,"./_export":138,"./_fails":139,"./_global":141,"./_has":142,"./_hide":143,"./_is-array":149,"./_is-object":151,"./_library":158,"./_meta":159,"./_object-create":163,"./_object-dp":164,"./_object-gopd":166,"./_object-gopn":168,"./_object-gopn-ext":167,"./_object-gops":169,"./_object-keys":172,"./_object-pie":173,"./_property-desc":178,"./_redefine":180,"./_set-to-string-tag":185,"./_shared":187,"./_to-iobject":193,"./_to-primitive":196,"./_uid":197,"./_wks":202,"./_wks-define":200,"./_wks-ext":201}],224:[function(e,t,r){var n=e("./_export"),o=e("./_object-to-array")(!0);n(n.S,"Object",{entries:function(e){return o(e)}})},{"./_export":138,"./_object-to-array":175}],225:[function(e,t,r){var n=e("./_export"),o=e("./_object-to-array")(!1);n(n.S,"Object",{values:function(e){return o(e)}})},{"./_export":138,"./_object-to-array":175}],226:[function(e,t,r){"use strict";var n=e("./_export"),o=e("./_core"),i=e("./_global"),s=e("./_species-constructor"),a=e("./_promise-resolve");n(n.P+n.R,"Promise",{finally:function(e){var t=s(this,o.Promise||i.Promise),r="function"==typeof e;return this.then(r?function(r){return a(t,e()).then(function(){return r})}:e,r?function(r){return a(t,e()).then(function(){throw r})}:e)}})},{"./_core":131,"./_export":138,"./_global":141,"./_promise-resolve":177,"./_species-constructor":188}],227:[function(e,t,r){"use strict";var n=e("./_export"),o=e("./_new-promise-capability"),i=e("./_perform");n(n.S,"Promise",{try:function(e){var t=o.f(this),r=i(e);return(r.e?t.reject:t.resolve)(r.v),t.promise}})},{"./_export":138,"./_new-promise-capability":161,"./_perform":176}],228:[function(e,t,r){e("./_set-collection-from")("Set")},{"./_set-collection-from":181}],229:[function(e,t,r){e("./_set-collection-of")("Set")},{"./_set-collection-of":182}],230:[function(e,t,r){var n=e("./_export");n(n.P+n.R,"Set",{toJSON:e("./_collection-to-json")("Set")})},{"./_collection-to-json":129,"./_export":138}],231:[function(e,t,r){e("./_wks-define")("asyncIterator")},{"./_wks-define":200}],232:[function(e,t,r){e("./_wks-define")("observable")},{"./_wks-define":200}],233:[function(e,t,r){e("./es6.array.iterator");for(var n=e("./_global"),o=e("./_hide"),i=e("./_iterators"),s=e("./_wks")("toStringTag"),a="CSSRuleList,CSSStyleDeclaration,CSSValueList,ClientRectList,DOMRectList,DOMStringList,DOMTokenList,DataTransferItemList,FileList,HTMLAllCollection,HTMLCollection,HTMLFormElement,HTMLSelectElement,MediaList,MimeTypeArray,NamedNodeMap,NodeList,PaintRequestList,Plugin,PluginArray,SVGLengthList,SVGNumberList,SVGPathSegList,SVGPointList,SVGStringList,SVGTransformList,SourceBufferList,StyleSheetList,TextTrackCueList,TextTrackList,TouchList".split(","),u=0;u<a.length;u++){var c=a[u],l=n[c],d=l&&l.prototype;d&&!d[s]&&o(d,s,c),i[c]=i.Array}},{"./_global":141,"./_hide":143,"./_iterators":157,"./_wks":202,"./es6.array.iterator":206}],234:[function(e,t,r){function n(){this._events&&Object.prototype.hasOwnProperty.call(this,"_events")||(this._events=E(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0}function o(e){return void 0===e._maxListeners?n.defaultMaxListeners:e._maxListeners}function i(e,t,r){if(t)e.call(r);else for(var n=e.length,o=m(e,n),i=0;i<n;++i)o[i].call(r)}function s(e,t,r,n){if(t)e.call(r,n);else for(var o=e.length,i=m(e,o),s=0;s<o;++s)i[s].call(r,n)}function a(e,t,r,n,o){if(t)e.call(r,n,o);else for(var i=e.length,s=m(e,i),a=0;a<i;++a)s[a].call(r,n,o)}function u(e,t,r,n,o,i){if(t)e.call(r,n,o,i);else for(var s=e.length,a=m(e,s),u=0;u<s;++u)a[u].call(r,n,o,i)}function c(e,t,r,n){if(t)e.apply(r,n);else for(var o=e.length,i=m(e,o),s=0;s<o;++s)i[s].apply(r,n)}function l(e,t,r,n){var i,s,a;if("function"!=typeof r)throw new TypeError('"listener" argument must be a function');if(s=e._events,s?(s.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),a=s[t]):(s=e._events=E(null),e._eventsCount=0),a){if("function"==typeof a?a=s[t]=n?[r,a]:[a,r]:n?a.unshift(r):a.push(r),!a.warned&&(i=o(e))&&i>0&&a.length>i){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",u.name,u.message)}}else a=s[t]=r,++e._eventsCount;return e}function d(){if(!this.fired)switch(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length){case 0:return this.listener.call(this.target);case 1:return this.listener.call(this.target,arguments[0]);case 2:return this.listener.call(this.target,arguments[0],arguments[1]);case 3:return this.listener.call(this.target,arguments[0],arguments[1],arguments[2]);default:for(var e=new Array(arguments.length),t=0;t<e.length;++t)e[t]=arguments[t];this.listener.apply(this.target,e)}}function f(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=S.call(d,n);return o.listener=r,n.wrapFn=o,o}function p(e,t,r){var n=e._events;if(!n)return[];var o=n[t];return o?"function"==typeof o?r?[o.listener||o]:[o]:r?y(o):m(o,o.length):[]}function h(e){var t=this._events;if(t){var r=t[e];if("function"==typeof r)return 1;if(r)return r.length}return 0}function v(e,t){for(var r=t,n=r+1,o=e.length;n<o;r+=1,n+=1)e[r]=e[n];e.pop()}function m(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function y(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function _(e){var t=function(){};return t.prototype=e,new t}function g(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return r}function b(e){var t=this;return function(){return t.apply(e,arguments)}}var E=Object.create||_,w=Object.keys||g,S=Function.prototype.bind||b;t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0;var k,T=10;try{var x={};Object.defineProperty&&Object.defineProperty(x,"x",{value:0}),k=0===x.x}catch(e){k=!1}k?Object.defineProperty(n,"defaultMaxListeners",{enumerable:!0,get:function(){return T},set:function(e){if("number"!=typeof e||e<0||e!==e)throw new TypeError('"defaultMaxListeners" must be a positive number');T=e}}):n.defaultMaxListeners=T,n.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},n.prototype.getMaxListeners=function(){return o(this)},n.prototype.emit=function(e){var t,r,n,o,l,d,f="error"===e;if(d=this._events)f=f&&null==d.error;else if(!f)return!1;if(f){if(arguments.length>1&&(t=arguments[1]),t instanceof Error)throw t;var p=new Error('Unhandled "error" event. ('+t+")");throw p.context=t,p}if(!(r=d[e]))return!1;var h="function"==typeof r;switch(n=arguments.length){case 1:i(r,h,this);break;case 2:s(r,h,this,arguments[1]);break;case 3:a(r,h,this,arguments[1],arguments[2]);break;case 4:u(r,h,this,arguments[1],arguments[2],arguments[3]);break;default:for(o=new Array(n-1),l=1;l<n;l++)o[l-1]=arguments[l];c(r,h,this,o)}return!0},n.prototype.addListener=function(e,t){return l(this,e,t,!1)},n.prototype.on=n.prototype.addListener,n.prototype.prependListener=function(e,t){return l(this,e,t,!0)},n.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,f(this,e,t)),this},n.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,f(this,e,t)),this},n.prototype.removeListener=function(e,t){var r,n,o,i,s;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(n=this._events))return this;if(!(r=n[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=E(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(o=-1,i=r.length-1;i>=0;i--)if(r[i]===t||r[i].listener===t){s=r[i].listener,o=i;break}if(o<0)return this;0===o?r.shift():v(r,o),1===r.length&&(n[e]=r[0]),n.removeListener&&this.emit("removeListener",e,s||t)}return this},n.prototype.removeAllListeners=function(e){var t,r,n;if(!(r=this._events))return this;if(!r.removeListener)return 0===arguments.length?(this._events=E(null),this._eventsCount=0):r[e]&&(0==--this._eventsCount?this._events=E(null):delete r[e]),this;if(0===arguments.length){var o,i=w(r);for(n=0;n<i.length;++n)"removeListener"!==(o=i[n])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=E(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},n.prototype.listeners=function(e){return p(this,e,!0)},n.prototype.rawListeners=function(e){return p(this,e,!1)},n.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):h.call(e,t)},n.prototype.listenerCount=h,n.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],235:[function(e,t,r){r.read=function(e,t,r,n,o){var i,s,a=8*o-n-1,u=(1<<a)-1,c=u>>1,l=-7,d=r?o-1:0,f=r?-1:1,p=e[t+d];for(d+=f,i=p&(1<<-l)-1,p>>=-l,l+=a;l>0;i=256*i+e[t+d],d+=f,l-=8);for(s=i&(1<<-l)-1,i>>=-l,l+=n;l>0;s=256*s+e[t+d],d+=f,l-=8);if(0===i)i=1-c;else{if(i===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),i-=c}return(p?-1:1)*s*Math.pow(2,i-n)},r.write=function(e,t,r,n,o,i){var s,a,u,c=8*i-o-1,l=(1<<c)-1,d=l>>1,f=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,h=n?1:-1,v=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=l):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),t+=s+d>=1?f/u:f*Math.pow(2,1-d),t*u>=2&&(s++,u/=2),s+d>=l?(a=0,s=l):s+d>=1?(a=(t*u-1)*Math.pow(2,o),s+=d):(a=t*Math.pow(2,d-1)*Math.pow(2,o),s=0));o>=8;e[r+p]=255&a,p+=h,a/=256,o-=8);for(s=s<<o|a,c+=o;c>0;e[r+p]=255&s,p+=h,s/=256,c-=8);e[r+p-h]|=128*v}},{}],236:[function(e,t,r){!function(e,r){"use strict";"function"==typeof define&&define.amd?define(r):"object"==typeof t&&t.exports?t.exports=r():e.log=r()}(this,function(){"use strict";function e(e,t){var r=e[t];if("function"==typeof r.bind)return r.bind(e);try{return Function.prototype.bind.call(r,e)}catch(t){return function(){return Function.prototype.apply.apply(r,[e,arguments])}}}function t(t){return"debug"===t&&(t="log"),typeof console!==a&&(void 0!==console[t]?e(console,t):void 0!==console.log?e(console,"log"):s)}function r(e,t){for(var r=0;r<u.length;r++){var n=u[r];this[n]=r<e?s:this.methodFactory(n,e,t)}this.log=this.debug}function n(e,t,n){return function(){typeof console!==a&&(r.call(this,t,n),this[e].apply(this,arguments))}}function o(e,r,o){return t(e)||n.apply(this,arguments)}function i(e,t,n){function i(e){var t=(u[e]||"silent").toUpperCase();if(typeof window!==a){try{return void(window.localStorage[d]=t)}catch(e){}try{window.document.cookie=encodeURIComponent(d)+"="+t+";"}catch(e){}}}function s(){var e;if(typeof window!==a){try{e=window.localStorage[d]}catch(e){}if(typeof e===a)try{var t=window.document.cookie,r=t.indexOf(encodeURIComponent(d)+"=");-1!==r&&(e=/^([^;]+)/.exec(t.slice(r))[1])}catch(e){}return void 0===l.levels[e]&&(e=void 0),e}}var c,l=this,d="loglevel";e&&(d+=":"+e),l.name=e,l.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},l.methodFactory=n||o,l.getLevel=function(){return c},l.setLevel=function(t,n){if("string"==typeof t&&void 0!==l.levels[t.toUpperCase()]&&(t=l.levels[t.toUpperCase()]),!("number"==typeof t&&t>=0&&t<=l.levels.SILENT))throw"log.setLevel() called with invalid level: "+t;if(c=t,!1!==n&&i(t),r.call(l,t,e),typeof console===a&&t<l.levels.SILENT)return"No console available for logging"},l.setDefaultLevel=function(e){s()||l.setLevel(e,!1)},l.enableAll=function(e){l.setLevel(l.levels.TRACE,e)},l.disableAll=function(e){l.setLevel(l.levels.SILENT,e)};var f=s();null==f&&(f=null==t?"WARN":t),l.setLevel(f,!1)}var s=function(){},a="undefined",u=["trace","debug","info","warn","error"],c=new i,l={};c.getLogger=function(e){if("string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=l[e];return t||(t=l[e]=new i(e,c.getLevel(),c.methodFactory)),t};var d=typeof window!==a?window.log:void 0;return c.noConflict=function(){return typeof window!==a&&window.log===c&&(window.log=d),c},c.getLoggers=function(){return l},c})},{}],237:[function(e,t,r){function n(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(e){if(d===setTimeout)return setTimeout(e,0);if((d===n||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}function s(e){if(f===clearTimeout)return clearTimeout(e);if((f===o||!f)&&clearTimeout)return f=clearTimeout,clearTimeout(e);try{return f(e)}catch(t){try{return f.call(null,e)}catch(t){return f.call(this,e)}}}function a(){m&&h&&(m=!1,h.length?v=h.concat(v):y=-1,v.length&&u())}function u(){if(!m){var e=i(a);m=!0;for(var t=v.length;t;){for(h=v,v=[];++y<t;)h&&h[y].run();y=-1,t=v.length}h=null,m=!1,s(e)}}function c(e,t){this.fun=e,this.array=t}function l(){}var d,f,p=t.exports={};!function(){try{d="function"==typeof setTimeout?setTimeout:n}catch(e){d=n}try{f="function"==typeof clearTimeout?clearTimeout:o}catch(e){f=o}}();var h,v=[],m=!1,y=-1;p.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];v.push(new c(e,t)),1!==v.length||m||i(u)},c.prototype.run=function(){this.fun.apply(null,this.array)},p.title="browser",p.browser=!0,p.env={},p.argv=[],p.version="",p.versions={},p.on=l,p.addListener=l,p.once=l,p.off=l,p.removeListener=l,p.removeAllListeners=l,p.emit=l,p.prependListener=l,p.prependOnceListener=l,p.listeners=function(e){return[]},p.binding=function(e){throw new Error("process.binding is not supported")},p.cwd=function(){return"/"},p.chdir=function(e){throw new Error("process.chdir is not supported")},p.umask=function(){return 0}},{}],238:[function(e,t,r){"use strict";var n=String.prototype.replace,o=/%20/g;t.exports={default:"RFC3986",formatters:{RFC1738:function(e){return n.call(e,o,"+")},RFC3986:function(e){return e}},RFC1738:"RFC1738",RFC3986:"RFC3986"}},{}],239:[function(e,t,r){"use strict";var n=e("./stringify"),o=e("./parse"),i=e("./formats");t.exports={formats:i,parse:o,stringify:n}},{"./formats":238,"./parse":240,"./stringify":241}],240:[function(e,t,r){"use strict";var n=e("./utils"),o=Object.prototype.hasOwnProperty,i={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:n.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1},s=function(e,t){for(var r={},n=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,s=t.parameterLimit===1/0?void 0:t.parameterLimit,a=n.split(t.delimiter,s),u=0;u<a.length;++u){var c,l,d=a[u],f=d.indexOf("]="),p=-1===f?d.indexOf("="):f+1;-1===p?(c=t.decoder(d,i.decoder),l=t.strictNullHandling?null:""):(c=t.decoder(d.slice(0,p),i.decoder),l=t.decoder(d.slice(p+1),i.decoder)),o.call(r,c)?r[c]=[].concat(r[c]).concat(l):r[c]=l}return r},a=function(e,t,r){for(var n=t,o=e.length-1;o>=0;--o){var i,s=e[o];if("[]"===s)i=[],i=i.concat(n);else{i=r.plainObjects?Object.create(null):{};var a="["===s.charAt(0)&&"]"===s.charAt(s.length-1)?s.slice(1,-1):s,u=parseInt(a,10);!isNaN(u)&&s!==a&&String(u)===a&&u>=0&&r.parseArrays&&u<=r.arrayLimit?(i=[],i[u]=n):i[a]=n}n=i}return n},u=function(e,t,r){if(e){var n=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/,s=/(\[[^[\]]*])/g,u=i.exec(n),c=u?n.slice(0,u.index):n,l=[];if(c){if(!r.plainObjects&&o.call(Object.prototype,c)&&!r.allowPrototypes)return;l.push(c)}for(var d=0;null!==(u=s.exec(n))&&d<r.depth;){if(d+=1,!r.plainObjects&&o.call(Object.prototype,u[1].slice(1,-1))&&!r.allowPrototypes)return;l.push(u[1])}return u&&l.push("["+n.slice(u.index)+"]"),a(l,t,r)}};t.exports=function(e,t){var r=t?n.assign({},t):{};if(null!==r.decoder&&void 0!==r.decoder&&"function"!=typeof r.decoder)throw new TypeError("Decoder has to be a function.");if(r.ignoreQueryPrefix=!0===r.ignoreQueryPrefix,r.delimiter="string"==typeof r.delimiter||n.isRegExp(r.delimiter)?r.delimiter:i.delimiter,r.depth="number"==typeof r.depth?r.depth:i.depth,r.arrayLimit="number"==typeof r.arrayLimit?r.arrayLimit:i.arrayLimit,r.parseArrays=!1!==r.parseArrays,r.decoder="function"==typeof r.decoder?r.decoder:i.decoder,r.allowDots="boolean"==typeof r.allowDots?r.allowDots:i.allowDots,r.plainObjects="boolean"==typeof r.plainObjects?r.plainObjects:i.plainObjects,r.allowPrototypes="boolean"==typeof r.allowPrototypes?r.allowPrototypes:i.allowPrototypes,r.parameterLimit="number"==typeof r.parameterLimit?r.parameterLimit:i.parameterLimit,r.strictNullHandling="boolean"==typeof r.strictNullHandling?r.strictNullHandling:i.strictNullHandling,""===e||null===e||void 0===e)return r.plainObjects?Object.create(null):{};for(var o="string"==typeof e?s(e,r):e,a=r.plainObjects?Object.create(null):{},c=Object.keys(o),l=0;l<c.length;++l){var d=c[l],f=u(d,o[d],r);a=n.merge(a,f,r)}return n.compact(a)}},{"./utils":242}],241:[function(e,t,r){"use strict";var n=e("./utils"),o=e("./formats"),i={brackets:function(e){return e+"[]"},indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},s=Date.prototype.toISOString,a={delimiter:"&",encode:!0,encoder:n.encode,encodeValuesOnly:!1,serializeDate:function(e){return s.call(e)},skipNulls:!1,strictNullHandling:!1},u=function e(t,r,o,i,s,u,c,l,d,f,p,h){var v=t;if("function"==typeof c)v=c(r,v);else if(v instanceof Date)v=f(v);else if(null===v){if(i)return u&&!h?u(r,a.encoder):r;v=""}if("string"==typeof v||"number"==typeof v||"boolean"==typeof v||n.isBuffer(v)){if(u){return[p(h?r:u(r,a.encoder))+"="+p(u(v,a.encoder))]}return[p(r)+"="+p(String(v))]}var m=[];if(void 0===v)return m;var y;if(Array.isArray(c))y=c;else{var _=Object.keys(v);y=l?_.sort(l):_}for(var g=0;g<y.length;++g){var b=y[g];s&&null===v[b]||(m=Array.isArray(v)?m.concat(e(v[b],o(r,b),o,i,s,u,c,l,d,f,p,h)):m.concat(e(v[b],r+(d?"."+b:"["+b+"]"),o,i,s,u,c,l,d,f,p,h)))}return m};t.exports=function(e,t){var r=e,s=t?n.assign({},t):{};if(null!==s.encoder&&void 0!==s.encoder&&"function"!=typeof s.encoder)throw new TypeError("Encoder has to be a function.");var c=void 0===s.delimiter?a.delimiter:s.delimiter,l="boolean"==typeof s.strictNullHandling?s.strictNullHandling:a.strictNullHandling,d="boolean"==typeof s.skipNulls?s.skipNulls:a.skipNulls,f="boolean"==typeof s.encode?s.encode:a.encode,p="function"==typeof s.encoder?s.encoder:a.encoder,h="function"==typeof s.sort?s.sort:null,v=void 0!==s.allowDots&&s.allowDots,m="function"==typeof s.serializeDate?s.serializeDate:a.serializeDate,y="boolean"==typeof s.encodeValuesOnly?s.encodeValuesOnly:a.encodeValuesOnly;if(void 0===s.format)s.format=o.default;else if(!Object.prototype.hasOwnProperty.call(o.formatters,s.format))throw new TypeError("Unknown format option provided.");var _,g,b=o.formatters[s.format];"function"==typeof s.filter?(g=s.filter,r=g("",r)):Array.isArray(s.filter)&&(g=s.filter,_=g);var E=[];if("object"!=typeof r||null===r)return"";var w;w=s.arrayFormat in i?s.arrayFormat:"indices"in s?s.indices?"indices":"repeat":"indices";var S=i[w];_||(_=Object.keys(r)),h&&_.sort(h);for(var k=0;k<_.length;++k){var T=_[k];d&&null===r[T]||(E=E.concat(u(r[T],T,S,l,d,f?p:null,g,h,v,m,b,y)))}var x=E.join(c),R=!0===s.addQueryPrefix?"?":"";return x.length>0?R+x:""}},{"./formats":238,"./utils":242}],242:[function(e,t,r){"use strict";var n=Object.prototype.hasOwnProperty,o=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),i=function(e){for(var t;e.length;){var r=e.pop();if(t=r.obj[r.prop],Array.isArray(t)){for(var n=[],o=0;o<t.length;++o)void 0!==t[o]&&n.push(t[o]);r.obj[r.prop]=n}}return t},s=function(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},n=0;n<e.length;++n)void 0!==e[n]&&(r[n]=e[n]);return r},a=function e(t,r,o){if(!r)return t;if("object"!=typeof r){if(Array.isArray(t))t.push(r);else{if("object"!=typeof t)return[t,r];(o.plainObjects||o.allowPrototypes||!n.call(Object.prototype,r))&&(t[r]=!0)}return t}if("object"!=typeof t)return[t].concat(r);var i=t;return Array.isArray(t)&&!Array.isArray(r)&&(i=s(t,o)),Array.isArray(t)&&Array.isArray(r)?(r.forEach(function(r,i){n.call(t,i)?t[i]&&"object"==typeof t[i]?t[i]=e(t[i],r,o):t.push(r):t[i]=r}),t):Object.keys(r).reduce(function(t,i){var s=r[i];return n.call(t,i)?t[i]=e(t[i],s,o):t[i]=s,t},i)},u=function(e,t){return Object.keys(t).reduce(function(e,r){return e[r]=t[r],e},e)},c=function(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(t){return e}},l=function(e){if(0===e.length)return e;for(var t="string"==typeof e?e:String(e),r="",n=0;n<t.length;++n){var i=t.charCodeAt(n);45===i||46===i||95===i||126===i||i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122?r+=t.charAt(n):i<128?r+=o[i]:i<2048?r+=o[192|i>>6]+o[128|63&i]:i<55296||i>=57344?r+=o[224|i>>12]+o[128|i>>6&63]+o[128|63&i]:(n+=1,i=65536+((1023&i)<<10|1023&t.charCodeAt(n)),r+=o[240|i>>18]+o[128|i>>12&63]+o[128|i>>6&63]+o[128|63&i])}return r},d=function(e){for(var t=[{obj:{o:e},prop:"o"}],r=[],n=0;n<t.length;++n)for(var o=t[n],s=o.obj[o.prop],a=Object.keys(s),u=0;u<a.length;++u){var c=a[u],l=s[c];"object"==typeof l&&null!==l&&-1===r.indexOf(l)&&(t.push({obj:s,prop:c}),r.push(l))}return i(t)},f=function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},p=function(e){return null!==e&&void 0!==e&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))};t.exports={arrayToObject:s,assign:u,compact:d,decode:c,encode:l,isBuffer:p,isRegExp:f,merge:a}},{}],243:[function(e,t,r){"use strict";function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.exports=function(e,t,r,i){t=t||"&",r=r||"=";var s={};if("string"!=typeof e||0===e.length)return s;var a=/\+/g;e=e.split(t);var u=1e3;i&&"number"==typeof i.maxKeys&&(u=i.maxKeys);var c=e.length;u>0&&c>u&&(c=u);for(var l=0;l<c;++l){var d,f,p,h,v=e[l].replace(a,"%20"),m=v.indexOf(r);m>=0?(d=v.substr(0,m),f=v.substr(m+1)):(d=v,f=""),p=decodeURIComponent(d),h=decodeURIComponent(f),n(s,p)?o(s[p])?s[p].push(h):s[p]=[s[p],h]:s[p]=h}return s};var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},{}],244:[function(e,t,r){"use strict";function n(e,t){if(e.map)return e.map(t);for(var r=[],n=0;n<e.length;n++)r.push(t(e[n],n));return r}var o=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};t.exports=function(e,t,r,a){return t=t||"&",r=r||"=",null===e&&(e=void 0),"object"==typeof e?n(s(e),function(s){var a=encodeURIComponent(o(s))+r;return i(e[s])?n(e[s],function(e){return a+encodeURIComponent(o(e))}).join(t):a+encodeURIComponent(o(e[s]))}).join(t):a?encodeURIComponent(o(a))+r+encodeURIComponent(o(e)):""};var i=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},s=Object.keys||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return t}},{}],245:[function(e,t,r){"use strict";r.decode=r.parse=e("./decode"),r.encode=r.stringify=e("./encode")},{"./decode":243,"./encode":244}],246:[function(e,t,r){var n=function(){return this}()||Function("return this")(),o=n.regeneratorRuntime&&Object.getOwnPropertyNames(n).indexOf("regeneratorRuntime")>=0,i=o&&n.regeneratorRuntime;if(n.regeneratorRuntime=void 0,t.exports=e("./runtime"),o)n.regeneratorRuntime=i;else try{delete n.regeneratorRuntime}catch(e){n.regeneratorRuntime=void 0}},{"./runtime":247}],247:[function(e,t,r){!function(e){"use strict";function r(e,t,r,n){var i=t&&t.prototype instanceof o?t:o,s=Object.create(i.prototype),a=new p(n||[]);return s._invoke=c(e,r,a),s}function n(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}function o(){}function i(){}function s(){}function a(e){["next","throw","return"].forEach(function(t){e[t]=function(e){return this._invoke(t,e)}})}function u(e){function t(r,o,i,s){var a=n(e[r],e,o);if("throw"!==a.type){var u=a.arg,c=u.value;return c&&"object"==typeof c&&_.call(c,"__await")?Promise.resolve(c.__await).then(function(e){t("next",e,i,s)},function(e){t("throw",e,i,s)}):Promise.resolve(c).then(function(e){u.value=e,i(u)},s)}s(a.arg)}function r(e,r){function n(){return new Promise(function(n,o){t(e,r,n,o)})}return o=o?o.then(n,n):n()}var o;this._invoke=r}function c(e,t,r){var o=T;return function(i,s){if(o===R)throw new Error("Generator is already running");if(o===I){if("throw"===i)throw s;return v()}for(r.method=i,r.arg=s;;){var a=r.delegate;if(a){var u=l(a,r);if(u){if(u===C)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===T)throw o=I,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=R;var c=n(e,t,r);if("normal"===c.type){if(o=r.done?I:x,c.arg===C)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(o=I,r.method="throw",r.arg=c.arg)}}}function l(e,t){var r=e.iterator[t.method];if(r===m){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=m,l(e,t),"throw"===t.method))return C;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return C}var o=n(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,C;var i=o.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=m),t.delegate=null,C):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,C)}function d(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function f(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function p(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(d,this),this.reset(!0)}function h(e){if(e){var t=e[b];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function t(){for(;++r<e.length;)if(_.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=m,t.done=!0,t};return n.next=n}}return{next:v}}function v(){return{value:m,done:!0}}var m,y=Object.prototype,_=y.hasOwnProperty,g="function"==typeof Symbol?Symbol:{},b=g.iterator||"@@iterator",E=g.asyncIterator||"@@asyncIterator",w=g.toStringTag||"@@toStringTag",S="object"==typeof t,k=e.regeneratorRuntime;if(k)return void(S&&(t.exports=k));k=e.regeneratorRuntime=S?t.exports:{},k.wrap=r;var T="suspendedStart",x="suspendedYield",R="executing",I="completed",C={},j={};j[b]=function(){return this};var O=Object.getPrototypeOf,A=O&&O(O(h([])));A&&A!==y&&_.call(A,b)&&(j=A);var D=s.prototype=o.prototype=Object.create(j);i.prototype=D.constructor=s,s.constructor=i,s[w]=i.displayName="GeneratorFunction",k.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===i||"GeneratorFunction"===(t.displayName||t.name))},k.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,w in e||(e[w]="GeneratorFunction")),e.prototype=Object.create(D),e},k.awrap=function(e){return{__await:e}},a(u.prototype),u.prototype[E]=function(){return this},k.AsyncIterator=u,k.async=function(e,t,n,o){var i=new u(r(e,t,n,o));return k.isGeneratorFunction(t)?i:i.next().then(function(e){return e.done?e.value:i.next()})},a(D),D[w]="Generator",D[b]=function(){return this},D.toString=function(){return"[object Generator]"},k.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},k.values=h,p.prototype={constructor:p,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=m,this.done=!1,this.delegate=null,this.method="next",this.arg=m,this.tryEntries.forEach(f),!e)for(var t in this)"t"===t.charAt(0)&&_.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=m)},stop:function(){this.done=!0;var e=this.tryEntries[0],t=e.completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){function t(t,n){return i.type="throw",i.arg=e,r.next=t,n&&(r.method="next",r.arg=m),!!n}if(this.done)throw e;for(var r=this,n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var s=_.call(o,"catchLoc"),a=_.call(o,"finallyLoc");if(s&&a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!a)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&_.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o.finallyLoc,C):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),C},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),f(r),C}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;f(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:h(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=m),C}}}(function(){return this}()||Function("return this")())},{}],248:[function(e,t,r){function n(e,t){for(var r in e)t[r]=e[r]}function o(e,t,r){return s(e,t,r)}var i=e("buffer"),s=i.Buffer;s.from&&s.alloc&&s.allocUnsafe&&s.allocUnsafeSlow?t.exports=i:(n(i,r),r.Buffer=o),n(s,o),o.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return s(e,t,r)},o.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var n=s(e);return void 0!==t?"string"==typeof r?n.fill(t,r):n.fill(t):n.fill(0),n},o.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return s(e)},o.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return i.SlowBuffer(e)}},{buffer:93}],249:[function(e,t,r){(function(t,n){
function o(e,t){this._id=e,this._clearFn=t}var i=e("process/browser.js").nextTick,s=Function.prototype.apply,a=Array.prototype.slice,u={},c=0;r.setTimeout=function(){return new o(s.call(setTimeout,window,arguments),clearTimeout)},r.setInterval=function(){return new o(s.call(setInterval,window,arguments),clearInterval)},r.clearTimeout=r.clearInterval=function(e){e.close()},o.prototype.unref=o.prototype.ref=function(){},o.prototype.close=function(){this._clearFn.call(window,this._id)},r.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},r.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},r._unrefActive=r.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},r.setImmediate="function"==typeof t?t:function(e){var t=c++,n=!(arguments.length<2)&&a.call(arguments,1);return u[t]=!0,i(function(){u[t]&&(n?e.apply(null,n):e.call(null),r.clearImmediate(t))}),t},r.clearImmediate="function"==typeof n?n:function(e){delete u[e]}}).call(this,e("timers").setImmediate,e("timers").clearImmediate)},{"process/browser.js":237,timers:249}],250:[function(e,t,r){"use strict";function n(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}function o(e,t,r){if(e&&c.isObject(e)&&e instanceof n)return e;var o=new n;return o.parse(e,t,r),o}function i(e){return c.isString(e)&&(e=o(e)),e instanceof n?e.format():n.prototype.format.call(e)}function s(e,t){return o(e,!1,!0).resolve(t)}function a(e,t){return e?o(e,!1,!0).resolveObject(t):t}var u=e("punycode"),c=e("./util");r.parse=o,r.resolve=s,r.resolveObject=a,r.format=i,r.Url=n;var l=/^([a-z0-9.+-]+:)/i,d=/:[0-9]*$/,f=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,p=["<",">",'"',"`"," ","\r","\n","\t"],h=["{","}","|","\\","^","`"].concat(p),v=["'"].concat(h),m=["%","/","?",";","#"].concat(v),y=["/","?","#"],_=/^[+a-z0-9A-Z_-]{0,63}$/,g=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,b={javascript:!0,"javascript:":!0},E={javascript:!0,"javascript:":!0},w={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},S=e("querystring");n.prototype.parse=function(e,t,r){if(!c.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var n=e.indexOf("?"),o=-1!==n&&n<e.indexOf("#")?"?":"#",i=e.split(o),s=/\\/g;i[0]=i[0].replace(s,"/"),e=i.join(o);var a=e;if(a=a.trim(),!r&&1===e.split("#").length){var d=f.exec(a);if(d)return this.path=a,this.href=a,this.pathname=d[1],d[2]?(this.search=d[2],this.query=t?S.parse(this.search.substr(1)):this.search.substr(1)):t&&(this.search="",this.query={}),this}var p=l.exec(a);if(p){p=p[0];var h=p.toLowerCase();this.protocol=h,a=a.substr(p.length)}if(r||p||a.match(/^\/\/[^@\/]+@[^@\/]+/)){var k="//"===a.substr(0,2);!k||p&&E[p]||(a=a.substr(2),this.slashes=!0)}if(!E[p]&&(k||p&&!w[p])){for(var T=-1,x=0;x<y.length;x++){var R=a.indexOf(y[x]);-1!==R&&(-1===T||R<T)&&(T=R)}var I,C;C=-1===T?a.lastIndexOf("@"):a.lastIndexOf("@",T),-1!==C&&(I=a.slice(0,C),a=a.slice(C+1),this.auth=decodeURIComponent(I)),T=-1;for(var x=0;x<m.length;x++){var R=a.indexOf(m[x]);-1!==R&&(-1===T||R<T)&&(T=R)}-1===T&&(T=a.length),this.host=a.slice(0,T),a=a.slice(T),this.parseHost(),this.hostname=this.hostname||"";var j="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!j)for(var O=this.hostname.split(/\./),x=0,A=O.length;x<A;x++){var D=O[x];if(D&&!D.match(_)){for(var M="",P=0,L=D.length;P<L;P++)D.charCodeAt(P)>127?M+="x":M+=D[P];if(!M.match(_)){var U=O.slice(0,x),N=O.slice(x+1),F=D.match(g);F&&(U.push(F[1]),N.unshift(F[2])),N.length&&(a="/"+N.join(".")+a),this.hostname=U.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),j||(this.hostname=u.toASCII(this.hostname));var q=this.port?":"+this.port:"",B=this.hostname||"";this.host=B+q,this.href+=this.host,j&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==a[0]&&(a="/"+a))}if(!b[h])for(var x=0,A=v.length;x<A;x++){var K=v[x];if(-1!==a.indexOf(K)){var G=encodeURIComponent(K);G===K&&(G=escape(K)),a=a.split(K).join(G)}}var $=a.indexOf("#");-1!==$&&(this.hash=a.substr($),a=a.slice(0,$));var V=a.indexOf("?");if(-1!==V?(this.search=a.substr(V),this.query=a.substr(V+1),t&&(this.query=S.parse(this.query)),a=a.slice(0,V)):t&&(this.search="",this.query={}),a&&(this.pathname=a),w[h]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var q=this.pathname||"",W=this.search||"";this.path=q+W}return this.href=this.format(),this},n.prototype.format=function(){var e=this.auth||"";e&&(e=encodeURIComponent(e),e=e.replace(/%3A/i,":"),e+="@");var t=this.protocol||"",r=this.pathname||"",n=this.hash||"",o=!1,i="";this.host?o=e+this.host:this.hostname&&(o=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(o+=":"+this.port)),this.query&&c.isObject(this.query)&&Object.keys(this.query).length&&(i=S.stringify(this.query));var s=this.search||i&&"?"+i||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||w[t])&&!1!==o?(o="//"+(o||""),r&&"/"!==r.charAt(0)&&(r="/"+r)):o||(o=""),n&&"#"!==n.charAt(0)&&(n="#"+n),s&&"?"!==s.charAt(0)&&(s="?"+s),r=r.replace(/[?#]/g,function(e){return encodeURIComponent(e)}),s=s.replace("#","%23"),t+o+r+s+n},n.prototype.resolve=function(e){return this.resolveObject(o(e,!1,!0)).format()},n.prototype.resolveObject=function(e){if(c.isString(e)){var t=new n;t.parse(e,!1,!0),e=t}for(var r=new n,o=Object.keys(this),i=0;i<o.length;i++){var s=o[i];r[s]=this[s]}if(r.hash=e.hash,""===e.href)return r.href=r.format(),r;if(e.slashes&&!e.protocol){for(var a=Object.keys(e),u=0;u<a.length;u++){var l=a[u];"protocol"!==l&&(r[l]=e[l])}return w[r.protocol]&&r.hostname&&!r.pathname&&(r.path=r.pathname="/"),r.href=r.format(),r}if(e.protocol&&e.protocol!==r.protocol){if(!w[e.protocol]){for(var d=Object.keys(e),f=0;f<d.length;f++){var p=d[f];r[p]=e[p]}return r.href=r.format(),r}if(r.protocol=e.protocol,e.host||E[e.protocol])r.pathname=e.pathname;else{for(var h=(e.pathname||"").split("/");h.length&&!(e.host=h.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==h[0]&&h.unshift(""),h.length<2&&h.unshift(""),r.pathname=h.join("/")}if(r.search=e.search,r.query=e.query,r.host=e.host||"",r.auth=e.auth,r.hostname=e.hostname||e.host,r.port=e.port,r.pathname||r.search){var v=r.pathname||"",m=r.search||"";r.path=v+m}return r.slashes=r.slashes||e.slashes,r.href=r.format(),r}var y=r.pathname&&"/"===r.pathname.charAt(0),_=e.host||e.pathname&&"/"===e.pathname.charAt(0),g=_||y||r.host&&e.pathname,b=g,S=r.pathname&&r.pathname.split("/")||[],h=e.pathname&&e.pathname.split("/")||[],k=r.protocol&&!w[r.protocol];if(k&&(r.hostname="",r.port=null,r.host&&(""===S[0]?S[0]=r.host:S.unshift(r.host)),r.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===h[0]?h[0]=e.host:h.unshift(e.host)),e.host=null),g=g&&(""===h[0]||""===S[0])),_)r.host=e.host||""===e.host?e.host:r.host,r.hostname=e.hostname||""===e.hostname?e.hostname:r.hostname,r.search=e.search,r.query=e.query,S=h;else if(h.length)S||(S=[]),S.pop(),S=S.concat(h),r.search=e.search,r.query=e.query;else if(!c.isNullOrUndefined(e.search)){if(k){r.hostname=r.host=S.shift();var T=!!(r.host&&r.host.indexOf("@")>0)&&r.host.split("@");T&&(r.auth=T.shift(),r.host=r.hostname=T.shift())}return r.search=e.search,r.query=e.query,c.isNull(r.pathname)&&c.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r}if(!S.length)return r.pathname=null,r.search?r.path="/"+r.search:r.path=null,r.href=r.format(),r;for(var x=S.slice(-1)[0],R=(r.host||e.host||S.length>1)&&("."===x||".."===x)||""===x,I=0,C=S.length;C>=0;C--)x=S[C],"."===x?S.splice(C,1):".."===x?(S.splice(C,1),I++):I&&(S.splice(C,1),I--);if(!g&&!b)for(;I--;I)S.unshift("..");!g||""===S[0]||S[0]&&"/"===S[0].charAt(0)||S.unshift(""),R&&"/"!==S.join("/").substr(-1)&&S.push("");var j=""===S[0]||S[0]&&"/"===S[0].charAt(0);if(k){r.hostname=r.host=j?"":S.length?S.shift():"";var T=!!(r.host&&r.host.indexOf("@")>0)&&r.host.split("@");T&&(r.auth=T.shift(),r.host=r.hostname=T.shift())}return g=g||r.host&&S.length,g&&!j&&S.unshift(""),S.length?r.pathname=S.join("/"):(r.pathname=null,r.path=null),c.isNull(r.pathname)&&c.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=e.auth||r.auth,r.slashes=r.slashes||e.slashes,r.href=r.format(),r},n.prototype.parseHost=function(){var e=this.host,t=d.exec(e);t&&(t=t[0],":"!==t&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)}},{"./util":251,punycode:91,querystring:245}],251:[function(e,t,r){"use strict";t.exports={isString:function(e){return"string"==typeof e},isObject:function(e){return"object"==typeof e&&null!==e},isNull:function(e){return null===e},isNullOrUndefined:function(e){return null==e}}},{}]},{},[1]);
//# sourceMappingURL=dist/browser-matrix.min.js.map