diff --git a/share/webapp/browser-matrix.min.js b/share/webapp/browser-matrix.min.js deleted file mode 100644 index 60e5d58eb..000000000 --- a/share/webapp/browser-matrix.min.js +++ /dev/null @@ -1,10 +0,0 @@ -!function e(t,n,r){function i(s,a){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[s]={exports:{}};t[s][0].call(l.exports,function(e){var n=t[s][1][e];return i(n?n:e)},l,l.exports,e,t,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s1&&u(t,n,I.QUEUED)),r||(r=c(e,n)),r}).then(function(e){return t&&t.updatePendingEvent(n,I.SENT,e.event_id),r&&r(null,e),e},function(e){console.error("Error sending event",e.stack||e);try{u(t,n,I.NOT_SENT),n.error=e,r&&r(e)}catch(i){console.error("Exception in error handler!",i.stack||e)}throw e})}function u(e,t,n){e?e.updatePendingEvent(t,n):t.status=n}function c(e,t){var n=t._txnId?t._txnId:e.makeTxnId(),r={$roomId:t.getRoomId(),$eventType:t.getWireType(),$stateKey:t.getStateKey(),$txnId:n},i=void 0;if(t.isState()){var o="/rooms/$roomId/state/$eventType";t.getStateKey()&&t.getStateKey().length>0&&(o="/rooms/$roomId/state/$eventType/$stateKey"),i=x.encodeUri(o,r)}else i=x.encodeUri("/rooms/$roomId/send/$eventType/$txnId",r);return e._http.authedRequest(void 0,"PUT",i,void 0,t.getWireContent())}function l(e,t,n,r,i,o){x.isFunction(i)&&(o=i,i=void 0);var s=x.encodeUri("/rooms/$roomId/state/m.room.member/$userId",{$roomId:t,$userId:n});return e._http.authedRequest(o,"PUT",s,void 0,{membership:r,reason:i})}function d(e,t,n,r,i,o){x.isFunction(i)&&(o=i,i=void 0);var s=x.encodeUri("/rooms/$room_id/$membership",{$room_id:t,$membership:r});return e._http.authedRequest(o,"POST",s,void 0,{user_id:n,reason:i})}function h(e,t,n,r){var i=x.encodeUri("/presence/list/$userId",{$userId:t.credentials.userId});return t._http.authedRequest(e,r,i,void 0,n)}function p(e){function t(t){if(0===t.getType().indexOf("m.call.")){var r=t.getContent(),i=r.call_id?e.callList[r.call_id]:void 0,o=void 0;if("m.call.invite"===t.getType()){if(t.getSender()===e.credentials.userId)return;if(t.getAge()>r.lifetime)return;if(i&&"ended"===i.state)return;if(i&&console.log("WARN: Already have a MatrixCall with id %s but got an invite. Clobbering.",r.call_id),i=A.createNewMatrixCall(e,t.getRoomId()),!i)return void console.log("Incoming call ID "+r.call_id+" but this client doesn't support WebRTC");if(i.callId=r.call_id,i._initWithInvite(t),e.callList[i.callId]=i,n[i.callId])for(o=0;oi.callId?(console.log("Glare detected: answering incoming call "+i.callId+" and canceling outgoing call "+s.callId),s._replacedBy(i),i.answer()):(console.log("Glare detected: rejecting incoming call "+i.callId+" and keeping outgoing call "+s.callId),i.hangup()):e.emit("Call.incoming",i)}else if("m.call.answer"===t.getType()){if(!i)return;t.getSender()===e.credentials.userId?"ringing"===i.state&&i._onAnsweredElsewhere(r):i._receivedAnswer(r)}else if("m.call.candidates"===t.getType()){if(t.getSender()===e.credentials.userId)return;if(i)for(o=0;o=0;n--){var o=r[n];("m.call.answer"===o.getType()||"m.call.hangup"===o.getType())&&(e[o.getContent().call_id]="yep")}r.forEach(function(n){e[n.getContent().call_id]||t(n)}),r=[]}()}),e.on("event",function(e){return i?void t(e):void(0===e.getType().indexOf("m.call.")&&r.push(e))})}function f(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 n={urls:t.uris,username:t.username,credential:t.password};e._turnServers=[n],e._checkTurnServersTimeoutID=setTimeout(function(){f(e)},1e3*(t.ttl||3600)*.9)}},function(){console.error("Failed to get TURN URIs"),e._checkTurnServersTimeoutID=setTimeout(function(){f(e)},6e4)}))}function v(e,t,n){e&&e(n),t.reject(n)}function m(e,t,n){e&&e(null,n),t.resolve(n)}function y(e){function t(t){var n=new b(t);return n.isEncrypted()&&o(e,n),n}return t}var g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_=e("./pushprocessor"),E=e("events").EventEmitter,S=e("q"),T=e("url"),w=e("./http-api"),b=e("./models/event").MatrixEvent,I=e("./models/event").EventStatus,R=e("./models/event-timeline"),k=e("./models/search-result"),D=e("./store/stub"),A=e("./webrtc/call"),x=e("./utils"),C=e("./content-repo"),O=e("./filter"),U=e("./sync"),P=e("./base-apis"),M=w.MatrixError,L=3e3,N=!1;try{var F=e("./crypto");N=!0}catch(q){console.error("olm load error",q)}x.inherits(r,E),x.extend(r.prototype,P.prototype),r.prototype.getDomain=function(){return this.credentials&&this.credentials.userId?this.credentials.userId.replace(/^.*?:/,""):null},r.prototype.getUserIdLocalpart=function(){return this.credentials&&this.credentials.userId?this.credentials.userId.split(":")[0].substring(1):null},r.prototype.getDeviceId=function(){return this.deviceId},r.prototype.supportsVoip=function(){return this._supportsVoip},r.prototype.getSyncState=function(){return this._syncApi?this._syncApi.getSyncState():null},r.prototype.isGuest=function(){return this._isGuest},r.prototype.getScheduler=function(){return this.scheduler},r.prototype.setGuest=function(e){this._isGuest=e},r.prototype.retryImmediately=function(){return this._syncApi.retryImmediately()},r.prototype.getNotifTimelineSet=function(){return this._notifTimelineSet},r.prototype.setNotifTimelineSet=function(e){this._notifTimelineSet=e},r.prototype.isCryptoEnabled=function(){return null!==this._crypto},r.prototype.getDeviceEd25519Key=function(){return this._crypto?this._crypto.getDeviceEd25519Key():null},r.prototype.uploadKeys=function(e){if(null===this._crypto)throw new Error("End-to-end encryption disabled");return this._crypto.uploadKeys(e)},r.prototype.downloadKeys=function(e,t){return null===this._crypto?S.reject(new Error("End-to-end encryption disabled")):this._crypto.downloadKeys(e,t)},r.prototype.listDeviceKeys=function(e){if(null===this._crypto)throw new Error("End-to-end encryption disabled");return this._crypto.listDeviceKeys(e)},r.prototype.getStoredDevicesForUser=function(e){if(null===this._crypto)throw new Error("End-to-end encryption disabled");return this._crypto.getStoredDevicesForUser(e)||[]},r.prototype.setDeviceVerified=function(e,t,n){void 0===n&&(n=!0),i(this,e,t,n,null)},r.prototype.setDeviceBlocked=function(e,t,n){void 0===n&&(n=!0),i(this,e,t,null,n)},r.prototype.setDeviceKnown=function(e,t,n){void 0===n&&(n=!0),i(this,e,t,null,null,n)},r.prototype.setGlobalBlacklistUnverifiedDevices=function(e){if(null===this._crypto)throw new Error("End-to-end encryption disabled");this._crypto.setGlobalBlacklistUnverifiedDevices(e)},r.prototype.getGlobalBlacklistUnverifiedDevices=function(){if(null===this._crypto)throw new Error("End-to-end encryption disabled");return this._crypto.getGlobalBlacklistUnverifiedDevices()},r.prototype.getEventSenderDeviceInfo=function(e){return this._crypto?this._crypto.getEventSenderDeviceInfo(e):null},r.prototype.isEventSenderVerified=function(e){var t=this.getEventSenderDeviceInfo(e);return t?t.isVerified():!1},r.prototype.setRoomEncryption=function(e,t){if(!this._crypto)throw new Error("End-to-End encryption disabled");return this._crypto.setRoomEncryption(e,t),S()},r.prototype.isRoomEncrypted=function(e){return this._crypto?this._crypto.isRoomEncrypted(e):!1},r.prototype.exportRoomKeys=function(){return this._crypto?this._crypto.exportRoomKeys():S.reject(new Error("End-to-end encryption disabled"))},r.prototype.importRoomKeys=function(e){if(!this._crypto)throw new Error("End-to-end encryption disabled");this._crypto.importRoomKeys(e)},r.prototype.getRoom=function(e){return this.store.getRoom(e)},r.prototype.getRooms=function(){return this.store.getRooms()},r.prototype.getUser=function(e){return this.store.getUser(e)},r.prototype.getUsers=function(){return this.store.getUsers()},r.prototype.setAccountData=function(e,t,n){var r=x.encodeUri("/user/$userId/account_data/$type",{$userId:this.credentials.userId,$type:e});return this._http.authedRequest(n,"PUT",r,void 0,t)},r.prototype.getAccountData=function(e){return this.store.getAccountData(e)},r.prototype.joinRoom=function(e,t,n){if(x.isFunction(t))throw new Error("Expected 'opts' object, got function.");t=t||{},void 0===t.syncRoom&&(t.syncRoom=!0);var r=this.getRoom(e);if(r&&r.hasMembershipState(this.credentials.userId,"join"))return S(r);var i=S();t.inviteSignUrl&&(i=this._http.requestOtherUrl(void 0,"POST",t.inviteSignUrl,{mxid:this.credentials.userId}));var o=S.defer(),s=this;return i.then(function(t){var n={};t&&(n.third_party_signed=t);var r=x.encodeUri("/join/$roomid",{$roomid:e});return s._http.authedRequest(void 0,"POST",r,void 0,n)}).then(function(e){var n=e.room_id,r=new U(s,s._clientOpts),i=r.createRoom(n);return t.syncRoom,S(i)}).done(function(e){m(n,o,e)},function(e){v(n,o,e)}),o.promise},r.prototype.resendEvent=function(e,t){return u(t,e,I.SENDING),a(this,t,e)},r.prototype.cancelPendingEvent=function(e){if([I.QUEUED,I.NOT_SENT].indexOf(e.status)<0)throw new Error("cannot cancel an event with status "+e.status);this.scheduler&&this.scheduler.removeEventFromQueue(e);var t=this.getRoom(e.getRoomId());u(t,e,I.CANCELLED)},r.prototype.setRoomName=function(e,t,n){return this.sendStateEvent(e,"m.room.name",{name:t},void 0,n)},r.prototype.setRoomTopic=function(e,t,n){return this.sendStateEvent(e,"m.room.topic",{topic:t},void 0,n)},r.prototype.getRoomTags=function(e,t){var n=x.encodeUri("/user/$userId/rooms/$roomId/tags/",{$userId:this.credentials.userId,$roomId:e});return this._http.authedRequest(t,"GET",n,void 0)},r.prototype.setRoomTag=function(e,t,n,r){var i=x.encodeUri("/user/$userId/rooms/$roomId/tags/$tag",{$userId:this.credentials.userId,$roomId:e,$tag:t});return this._http.authedRequest(r,"PUT",i,void 0,n)},r.prototype.deleteRoomTag=function(e,t,n){var r=x.encodeUri("/user/$userId/rooms/$roomId/tags/$tag",{$userId:this.credentials.userId,$roomId:e,$tag:t});return this._http.authedRequest(n,"DELETE",r,void 0,void 0)},r.prototype.setRoomAccountData=function(e,t,n,r){var i=x.encodeUri("/user/$userId/rooms/$roomId/account_data/$type",{$userId:this.credentials.userId,$roomId:e,$type:t});return this._http.authedRequest(r,"PUT",i,void 0,n)},r.prototype.setPowerLevel=function(e,t,n,r,i){var o={users:{}};r&&"m.room.power_levels"===r.getType()&&(o=x.deepCopy(r.getContent())),o.users[t]=n;var s=x.encodeUri("/rooms/$roomId/state/m.room.power_levels",{$roomId:e});return this._http.authedRequest(i,"PUT",s,void 0,o)},r.prototype.sendEvent=function(e,t,n,r,i){x.isFunction(r)&&(i=r,r=void 0),r||(r=this.makeTxnId());var o=this.getRoom(e),s=new b({event_id:"~"+e+":"+r,user_id:this.credentials.userId,room_id:e,type:t,origin_server_ts:(new Date).getTime(),content:n});return s._txnId=r,s.status=I.SENDING,o&&o.addPendingEvent(s,r),a(this,o,s,i)},r.prototype.sendMessage=function(e,t,n,r){return x.isFunction(n)&&(r=n,n=void 0),this.sendEvent(e,"m.room.message",t,n,r)},r.prototype.sendTextMessage=function(e,t,n,r){var i={msgtype:"m.text",body:t};return this.sendMessage(e,i,n,r)},r.prototype.sendNotice=function(e,t,n,r){var i={msgtype:"m.notice",body:t};return this.sendMessage(e,i,n,r)},r.prototype.sendEmoteMessage=function(e,t,n,r){var i={msgtype:"m.emote",body:t};return this.sendMessage(e,i,n,r)},r.prototype.sendImageMessage=function(e,t,n,r,i){x.isFunction(r)&&(i=r,r=void 0),r||(r="Image");var o={msgtype:"m.image",url:t,info:n,body:r};return this.sendMessage(e,o,i)},r.prototype.sendHtmlMessage=function(e,t,n,r){var i={msgtype:"m.text",format:"org.matrix.custom.html",body:t,formatted_body:n};return this.sendMessage(e,i,r)},r.prototype.sendHtmlNotice=function(e,t,n,r){var i={msgtype:"m.notice",format:"org.matrix.custom.html",body:t,formatted_body:n};return this.sendMessage(e,i,r)},r.prototype.sendHtmlEmote=function(e,t,n,r){var i={msgtype:"m.emote",format:"org.matrix.custom.html",body:t,formatted_body:n};return this.sendMessage(e,i,r)},r.prototype.sendReceipt=function(e,t,n){if(this.isGuest())return S({});var r=x.encodeUri("/rooms/$roomId/receipt/$receiptType/$eventId",{$roomId:e.getRoomId(),$receiptType:t,$eventId:e.getId()}),i=this._http.authedRequest(n,"POST",r,void 0,{}),o=this.getRoom(e.getRoomId());return o&&o._addLocalEchoReceipt(this.credentials.userId,e,t),i},r.prototype.sendReadReceipt=function(e,t){return this.sendReceipt(e,"m.read",t)},r.prototype.getUrlPreview=function(e,t,n){var r=t+"_"+e,i=this.urlPreviewCache[r];if(i)return S(i);var o=this;return this._http.authedRequestWithPrefix(n,"GET","/preview_url",{url:e,ts:t},void 0,w.PREFIX_MEDIA_R0).then(function(e){return o.urlPreviewCache[r]=e,e})},r.prototype.sendTyping=function(e,t,n,r){if(this.isGuest())return S({});var i=x.encodeUri("/rooms/$roomId/typing/$userId",{$roomId:e,$userId:this.credentials.userId}),o={typing:t};return t&&(o.timeout=n?n:2e4),this._http.authedRequest(r,"PUT",i,void 0,o)},r.prototype.invite=function(e,t,n){return d(this,e,t,"invite",void 0,n)},r.prototype.inviteByEmail=function(e,t,n){return this.inviteByThreePid(e,"email",t,n)},r.prototype.inviteByThreePid=function(e,t,n,r){var i=x.encodeUri("/rooms/$roomId/invite",{$roomId:e}),o=this.getIdentityServerUrl();return o?((0===o.indexOf("http://")||0===o.indexOf("https://"))&&(o=o.split("://")[1]),this._http.authedRequest(r,"POST",i,void 0,{id_server:o,medium:t,address:n})):S.reject(new M({error:"No supplied identity server URL",errcode:"ORG.MATRIX.JSSDK_MISSING_PARAM"}))},r.prototype.leave=function(e,t){return d(this,e,void 0,"leave",void 0,t)},r.prototype.ban=function(e,t,n,r){return d(this,e,t,"ban",n,r)},r.prototype.forget=function(e,t,n){void 0===t&&(t=!0);var r=d(this,e,void 0,"forget",void 0,n);if(!t)return r;var i=this;return r.then(function(t){return i.store.removeRoom(e),i.emit("deleteRoom",e),t})},r.prototype.unban=function(e,t,n){return l(this,e,t,"leave",void 0,n)},r.prototype.kick=function(e,t,n,r){return l(this,e,t,"leave",n,r)},r.prototype.getPushActionsForEvent=function(e){if(!e.getPushActions()){var t=new _(this);e.setPushActions(t.actionsForEvent(e))}return e.getPushActions()},r.prototype.setProfileInfo=function(e,t,n){var r=x.encodeUri("/profile/$userId/$info",{$userId:this.credentials.userId,$info:e});return this._http.authedRequest(n,"PUT",r,void 0,t)},r.prototype.setDisplayName=function(e,t){return this.setProfileInfo("displayname",{displayname:e},t)},r.prototype.setAvatarUrl=function(e,t){return this.setProfileInfo("avatar_url",{avatar_url:e},t)},r.prototype.mxcUrlToHttp=function(e,t,n,r,i){return C.getHttpUriForMxc(this.baseUrl,e,t,n,r,i)},r.prototype.setPresence=function(e,t){var n=x.encodeUri("/presence/$userId/status",{$userId:this.credentials.userId});"string"==typeof e&&(e={presence:e});var r=["offline","online","unavailable"];if(-1==r.indexOf(e.presence))throw new Error("Bad presence value: "+e.presence);return this._http.authedRequest(t,"PUT",n,void 0,e)},r.prototype.getPresenceList=function(e){return h(e,this,void 0,"GET")},r.prototype.inviteToPresenceList=function(e,t){var n={invite:t};return h(e,this,n,"POST")},r.prototype.dropFromPresenceList=function(e,t){var n={drop:t};return h(e,this,n,"POST")},r.prototype.scrollback=function(e,t,n){x.isFunction(t)&&(n=t,t=void 0),t=t||30;var r=0,i=this._ongoingScrollbacks[e.roomId]||{};if(i.promise)return i.promise;if(i.errorTs){var o=Date.now()-i.errorTs;r=Math.max(L-o,0)}if(null===e.oldState.paginationToken)return S(e);var s=this.store.scrollback(e,t).length;if(s===t)return S(e);t-=s;var a=x.encodeUri("/rooms/$roomId/messages",{$roomId:e.roomId}),u={from:e.oldState.paginationToken,limit:t,dir:"b"},c=S.defer();i={promise:c.promise,errorTs:null};var l=this;return S.delay(r).then(function(){return l._http.authedRequest(n,"GET",a,u)}).done(function(t){var r=x.map(t.chunk,y(l));e.addEventsToTimeline(r,!0,e.getLiveTimeline()),e.oldState.paginationToken=t.end,0===t.chunk.length&&(e.oldState.paginationToken=null),l.store.storeEvents(e,r,t.end,!0),l._ongoingScrollbacks[e.roomId]=null,m(n,c,e)},function(t){l._ongoingScrollbacks[e.roomId]={errorTs:Date.now()},v(n,c,t)}),this._ongoingScrollbacks[e.roomId]=i,c.promise},r.prototype.paginateEventContext=function(e,t){t=t||{};var n=t.backwards||!1,r=e.getPaginateToken(n);if(!r)return S.reject(new Error("No paginate token"));var i=n?"b":"f",o=e._paginateRequests[i];if(o)return o;var s=x.encodeUri("/rooms/$roomId/messages",{$roomId:e.getEvent().getRoomId()}),a={from:r,limit:"limit"in t?t.limit:30,dir:i},u=this,c=u._http.authedRequest(void 0,"GET",s,a).then(function(t){var r=t.end;if(0===t.chunk.length)r=null;else{var i=x.map(t.chunk,u.getEventMapper());n&&i.reverse(),e.addEvents(i,n)}return e.setPaginateToken(r,n),e})["finally"](function(){e._paginateRequests[i]=null});return e._paginateRequests[i]=c,c},r.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 S(e.getTimelineForEvent(t));var n=x.encodeUri("/rooms/$roomId/context/$eventId",{$roomId:e.room.roomId,$eventId:t}),r=this,i=r._http.authedRequest(void 0,"GET",n).then(function(n){if(!n.event)throw new Error("'event' not in '/context' result - homeserver too old?");if(e.getTimelineForEvent(t))return e.getTimelineForEvent(t);n.events_after.reverse();var i=n.events_after.concat([n.event]).concat(n.events_before),o=x.map(i,r.getEventMapper()),s=e.getTimelineForEvent(o[0].getId());s||(s=e.addTimeline(),s.initialiseState(x.map(n.state,r.getEventMapper())),s.getState(R.FORWARDS).paginationToken=n.end),e.addEventsToTimeline(o,!0,s,n.start);var a=e.getTimelineForEvent(t)||s;return a});return i},r.prototype.paginateEventTimeline=function(e,t){var n=e.getTimelineSet()===this._notifTimelineSet;t=t||{};var r=t.backwards||!1;if(n&&!r)throw new Error("paginateNotifTimeline can only paginate backwards");var i=r?R.BACKWARDS:R.FORWARDS,o=e.getPaginationToken(i);if(!o)return S(!1);var s=e._paginationRequests[i];if(s)return s;var a=void 0,u=void 0,c=void 0,l=this;if(n)a="/notifications",u={limit:"limit"in t?t.limit:30,only:"highlight"},o&&"end"!==o&&(u.from=o),c=this._http.authedRequestWithPrefix(void 0,"GET",a,u,void 0,w.PREFIX_UNSTABLE).then(function(t){for(var n=t.next_token,o=[],s=0;sn;n++)e+=t.charAt(Math.floor(Math.random()*t.length));return e},t.exports.MatrixClient=r,t.exports.CRYPTO_ENABLED=N}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./base-apis":2,"./content-repo":4,"./crypto":12,"./filter":15,"./http-api":16,"./models/event":22,"./models/event-timeline":21,"./models/search-result":27,"./pushprocessor":29,"./store/stub":34,"./sync":35,"./utils":37,"./webrtc/call":38,events:41,q:44,url:48}],4:[function(e,t){"use strict";var n=e("./utils");t.exports={getHttpUriForMxc:function(e,t,r,i,o,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),i&&(c.height=i),o&&(c.method=o),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,i){if(!t)return null;r||(r=96),i||(i=96);var o={width:r,height:i},s=n.encodeUri("/_matrix/media/v1/identicon/$ident",{$ident:t});return e+s+(0===n.keys(o).length?"":"?"+n.encodeParams(o))}}},{"./utils":37}],5:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t,n,r){var i=!1;for(var o in n)n.hasOwnProperty(o)&&(o in r||(console.log("Device "+t+":"+o+" has been removed"),delete n[o],i=!0));for(o in r)if(r.hasOwnProperty(o)){var a=r[o];a.user_id===t?a.device_id===o?s(e,n,a)&&(i=!0):console.warn("Mismatched device_id "+a.device_id+" in keys from "+t+":"+o):console.warn("Mismatched user_id "+a.user_id+" in keys from "+t+":"+o)}return i}function s(e,t,n){if(!n.keys)return!1;var r=n.device_id,i=n.user_id,o="ed25519:"+r,s=n.keys[o];if(!s)return console.log("Device "+i+":"+r+" has no ed25519 key"),!1;var a=n.unsigned||{};try{p["default"].verifySignature(e,n,i,r,s)}catch(u){return console.log("Unable to verify signature on device "+i+":"+r+":",u),!1}var c=void 0;if(r in t){if(c=t[r],c.getFingerprint()!=s)return console.warn("Ed25519 key for device"+i+": "+r+" has changed"),!1}else t[r]=c=new d["default"](r);return c.keys=n.keys||{},c.algorithms=n.algorithms||[],c.unsigned=a,!0}Object.defineProperty(n,"__esModule",{value:!0});var a=function(){function e(e,t){for(var n=0;nu)throw new Error("Message too long ("+e.length+" bytes). The maximum for an encrypted message is "+u+" bytes.")}function i(e){this._sessionStore=e,this._pickleKey="DEFAULT_KEY";var t=void 0,n=new s.Account;try{o(this._sessionStore,this._pickleKey,n),t=JSON.parse(n.identity_keys())}finally{n.free()}this.deviceCurve25519Key=t.curve25519,this.deviceEd25519Key=t.ed25519,this._outboundGroupSessionStore={},this._inboundGroupSessionMessageIndexes={}}function o(e,t,n){var r=e.getEndToEndAccount();if(null!==r)return void n.unpickle(t,r);n.create();var i=n.pickle(t);e.storeEndToEndAccount(i)}var s="undefined"!=typeof window?window.Olm:"undefined"!=typeof n?n.Olm:null;if(!s)throw new Error("Olm is not defined");var a=e("../utils"),u=49152;i.getOlmVersion=function(){return s.get_library_version()},i.prototype._getAccount=function(e){var t=new s.Account;try{var n=this._sessionStore.getEndToEndAccount();return t.unpickle(this._pickleKey,n),e(t)}finally{t.free()}},i.prototype._saveAccount=function(e){var t=e.pickle(this._pickleKey);this._sessionStore.storeEndToEndAccount(t)},i.prototype._getSession=function(e,t,n){var r=this._sessionStore.getEndToEndSessions(e),i=r[t],o=new s.Session;try{return o.unpickle(this._pickleKey,i),n(o)}finally{o.free()}},i.prototype._saveSession=function(e,t){var n=t.pickle(this._pickleKey);this._sessionStore.storeEndToEndSession(e,t.session_id(),n)},i.prototype._getUtility=function(e){var t=new s.Utility;try{return e(t)}finally{t.free()}},i.prototype.sign=function(e){return this._getAccount(function(t){return t.sign(e)})},i.prototype.getOneTimeKeys=function(){return this._getAccount(function(e){return JSON.parse(e.one_time_keys())})},i.prototype.maxNumberOfOneTimeKeys=function(){return this._getAccount(function(e){return e.max_number_of_one_time_keys()})},i.prototype.markKeysAsPublished=function(){var e=this;this._getAccount(function(t){t.mark_keys_as_published(),e._saveAccount(t)})},i.prototype.generateOneTimeKeys=function(e){var t=this;this._getAccount(function(n){n.generate_one_time_keys(e),t._saveAccount(n)})},i.prototype.createOutboundSession=function(e,t){var n=this;return this._getAccount(function(r){var i=new s.Session;try{return i.create_outbound(r,e,t),n._saveSession(e,i),i.session_id()}finally{i.free()}})},i.prototype.createInboundSession=function(e,t,n){if(0!==t)throw new Error("Need message_type == 0 to create inbound session");var r=this;return this._getAccount(function(i){var o=new s.Session;try{o.create_inbound_from(i,e,n),i.remove_one_time_keys(o),r._saveAccount(i);var a=o.decrypt(t,n);return r._saveSession(e,o),{payload:a,session_id:o.session_id()}}finally{o.free()}})},i.prototype.getSessionIdsForDevice=function(e){var t=this._sessionStore.getEndToEndSessions(e);return a.keys(t)},i.prototype.getSessionIdForDevice=function(e){var t=this.getSessionIdsForDevice(e);return 0===t.length?null:(t.sort(),t[0])},i.prototype.getSessionInfoForDevice=function(e){function t(e){return{hasReceivedMessage:e.has_received_message()}}var n=this.getSessionIdsForDevice(e);n.sort();for(var r=[],i=0;i=e||n>=t?(console.log("Rotating megolm session after "+this.useCount+" messages, "+n+"ms"),!0):!1},t.prototype.sharedWithTooManyDevices=function(e){for(var t in this.sharedWithDevices)if(this.sharedWithDevices.hasOwnProperty(t)){if(!e.hasOwnProperty(t))return console.log("Starting new session because we shared with "+t),!0;for(var n in this.sharedWithDevices[t])if(this.sharedWithDevices[t].hasOwnProperty(n)&&!e[t].hasOwnProperty(n))return console.log("Starting new session because we shared with "+t+":"+n),!0}},o.inherits(n,a.EncryptionAlgorithm),n.prototype._ensureOutboundSession=function(e){function t(t){i=t,i&&i.needsRotation(r._sessionRotationPeriodMsgs,r._sessionRotationPeriodMs)&&(console.log("Starting new megolm session because we need to rotate."),i=null),i&&i.sharedWithTooManyDevices(e)&&(i=null),i||(i=r._prepareNewSession());var n={};for(var o in e)if(e.hasOwnProperty(o)){var s=e[o];for(var a in s)if(s.hasOwnProperty(a)){var u=s[a],c=u.getIdentityKey();c!=r._olmDevice.deviceCurve25519Key&&(i.sharedWithDevices[o]&&void 0!==i.sharedWithDevices[o][a]||(n[o]=n[o]||[],n[o].push(u)))}}return r._shareKeyWithDevices(i,n)}function n(){return i}var r=this,i=void 0,o=this._setupPromise.then(t);return this._setupPromise=o.then(n,n),o.then(n)},n.prototype._prepareNewSession=function(){var e=this._olmDevice.createOutboundGroupSession(),n=this._olmDevice.getOutboundGroupSessionKey(e);return this._olmDevice.addInboundGroupSession(this._roomId,this._olmDevice.deviceCurve25519Key,e,n.key,{ed25519:this._olmDevice.deviceEd25519Key}),new t(e)},n.prototype._shareKeyWithDevices=function(e,t){var n=this,r=this._olmDevice.getOutboundGroupSessionKey(e.sessionId),o={type:"m.room_key",content:{algorithm:s.MEGOLM_ALGORITHM,room_id:this._roomId,session_id:e.sessionId,session_key:r.key,chain_index:r.chain_index}},a={};return s.ensureOlmSessionsForDevices(this._olmDevice,this._baseApis,t).then(function(e){var r=!1;for(var u in t)if(t.hasOwnProperty(u))for(var c=t[u],l=e[u],d=0;d=a?void 0:(t._olmDevice.generateOneTimeKeys(a),o(t))})},n.prototype.downloadKeys=function(e,t){return this._deviceList.downloadKeys(e,t)},n.prototype.getStoredDevicesForUser=function(e){return this._deviceList.getStoredDevicesForUser(e)},n.prototype.getStoredDevice=function(e,t){return this._deviceList.getStoredDevice(e,t)},n.prototype.listDeviceKeys=function(e){for(var t=this.getStoredDevicesForUser(e)||[],n=[],r=0;rt.deviceId?1:0}),n},n.prototype.setDeviceVerification=function(e,t,n,r,i){var o=this._sessionStore.getEndToEndDevicesForUser(e);if(!o||!o[t])throw new Error("Unknown device "+e+":"+t);var s=o[t],a=s.verified;n?a=p.VERIFIED:null!==n&&a==p.VERIFIED&&(a=p.UNVERIFIED),r?a=p.BLOCKED:null!==r&&a==p.BLOCKED&&(a=p.UNVERIFIED);var u=s.known;return null!==i&&void 0!==i&&(u=i),(s.verified!==a||s.known!==u)&&(s.verified=a,s.known=u,this._sessionStore.storeEndToEndDevicesForUser(e,o)),h.fromStorage(s,t)},n.prototype.getOlmSessionsForUser=function(e){for(var t=this.getStoredDevicesForUser(e)||[],n={},r=0;r=400?(i&&(u=JSON.parse(u)),s=new t.exports.MatrixError(u)):o&&(u=o(u))}catch(c){s=c}s&&(s.httpStatus=a.statusCode)}if(s)e.reject(s),n(s);else{var l={code:a.statusCode,headers:a.headers,data:u};e.resolve(r?u:l),n(null,r?u:l)}}};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=Object.create(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":30,"./utils":37,q:44}],17:[function(e,t){"use strict";function n(e){this._data=e.authData,this._requestCallback=e.doRequest,this._startAuthStageCallback=e.startAuthStage,this._completionDeferred=null}var r=e("q"),i=e("./utils");n.prototype={attemptAuth:function(){return this._completionDeferred=r.defer(),this._data?this._startNextAuthStage():this._doRequest(null),this._completionDeferred.promise},getSessionId:function(){return this._data?this._data.session:void 0},getStageParams:function(e){var t={};return this._data&&this._data.params&&(t=this._data.params),t[e]},submitAuthDict:function(e){if(!this._completionDeferred)throw new Error("submitAuthDict() called before attemptAuth()");var t={session:this._data.session};i.extend(t,e),this._doRequest(t)},_doRequest:function(e){var t=this,n=void 0;try{n=this._requestCallback(e)}catch(i){n=r.reject(i)}n.then(function(e){console.log("result from request: ",e),t._completionDeferred.resolve(e)},function(e){if(401!==e.httpStatus||!e.data||!e.data.flows)throw e;t._data=e.data,t._startNextAuthStage()})["catch"](this._completionDeferred.reject).done()},_startNextAuthStage:function(){var e=this._chooseStage();if(!e)throw new Error("No incomplete flows from the server");var t=null;(this._data.errcode||this._data.error)&&(t={errcode:this._data.errcode||"",error:this._data.error||""}),this._startAuthStageCallback(e,t)},_chooseStage:function(){var e=this._chooseFlow();console.log("Active flow => %s",JSON.stringify(e));var t=this._firstUncompletedStage(e);return console.log("Next stage: %s",t),t},_chooseFlow:function(){var e=this._data.flows||[];return e[0]},_firstUncompletedStage:function(e){for(var t=(this._data||{}).completed||[],n=0;n0)throw new Error("Cannot initialise state after events are added");var t=i.map(i.deepCopy(e.map(function(e){return e.event})),function(e){return new o(e)});this._startState.setStateEvents(t),this._endState.setStateEvents(e)},n.prototype.getRoomId=function(){return this._roomId},n.prototype.getFilter=function(){return this._eventTimelineSet.getFilter()},n.prototype.getTimelineSet=function(){return this._eventTimelineSet},n.prototype.getBaseIndex=function(){return this._baseIndex},n.prototype.getEvents=function(){return this._events},n.prototype.getState=function(e){if(e==n.BACKWARDS)return this._startState;if(e==n.FORWARDS)return this._endState;throw new Error("Invalid direction '"+e+"'")},n.prototype.getPaginationToken=function(e){return this.getState(e).paginationToken},n.prototype.setPaginationToken=function(e,t){this.getState(t).paginationToken=e},n.prototype.getNeighbouringTimeline=function(e){if(e==n.BACKWARDS)return this._prevTimeline;if(e==n.FORWARDS)return this._nextTimeline;throw new Error("Invalid direction '"+e+"'")},n.prototype.setNeighbouringTimeline=function(e,t){if(this.getNeighbouringTimeline(t))throw new Error("timeline already has a neighbouring timeline - cannot reset neighbour");if(t==n.BACKWARDS)this._prevTimeline=e;else{if(t!=n.FORWARDS)throw new Error("Invalid direction '"+t+"'");this._nextTimeline=e}this.setPaginationToken(null,t)},n.prototype.addEvent=function(e,t){var r=t?this._startState:this._endState,i=this.getTimelineSet(); - -i.room&&i.room.getUnfilteredTimelineSet()===i&&(n.setEventMetadata(e,r,t),e.isState()&&(r.setStateEvents([e]),(!e.sender||"m.room.member"===e.getType()&&!t)&&n.setEventMetadata(e,r,t)));var o=void 0;o=t?0:this._events.length,this._events.splice(o,0,e),t&&this._baseIndex++},n.setEventMetadata=function(e,t,n){e.sender=t.getSentinelMember(e.getSender()),"m.room.member"===e.getType()&&(e.target=t.getSentinelMember(e.getStateKey())),e.isState()&&n&&(e.forwardLooking=!1)},n.prototype.removeEvent=function(e){for(var t=this._events.length-1;t>=0;t--){var n=this._events[t];if(n.getId()==e)return this._events.splice(t,1),t0?r+" ("+i+")":r}var i=e("events").EventEmitter,o=e("../content-repo"),s=e("../utils");s.inherits(n,i),n.prototype.setMembershipEvent=function(e,t){if("m.room.member"===e.getType()){this.events.member=e;var n=this.membership;this.membership=e.getDirectionalContent().membership;var i=this.name;this.name=r(this,e,t),n!==this.membership&&(this._updateModifiedTime(),this.emit("RoomMember.membership",e,this,n)),i!==this.name&&(this._updateModifiedTime(),this.emit("RoomMember.name",e,this,i))}},n.prototype.setPowerLevelEvent=function(e){if("m.room.power_levels"===e.getType()){var t=e.getContent().users_default||0;s.forEach(s.values(e.getContent().users),function(e){t=Math.max(t,e)});var n=this.powerLevel,r=this.powerLevelNorm;this.powerLevel=void 0!==e.getContent().users[this.userId]?e.getContent().users[this.userId]:void 0!==e.getContent().users_default?e.getContent().users_default:0,this.powerLevelNorm=0,t>0&&(this.powerLevelNorm=100*this.powerLevel/t),(n!==this.powerLevel||r!==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 n=e.getContent().user_ids;s.isArray(n)&&(-1!==n.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.getAvatarUrl=function(e,t,n,r,i,s){if(void 0===i&&(i=!0),!this.events.member&&!i)return null;var a=this.events.member?this.events.member.getContent().avatar_url:null,u=o.getHttpUriForMxc(e,a,t,n,r,s);return u?u:i?o.getIdenticonUri(e,this.userId,t,n):null},t.exports=n},{"../content-repo":4,"../utils":37,events:41}],24:[function(e,t){"use strict";function n(e){this.roomId=e,this.members={},this.events={},this.paginationToken=null,this._sentinels={},this._updateModifiedTime(),this._displayNameToUserIds={},this._userIdsToDisplayNames={},this._tokenToInvite={}}function r(e,t){if(t.getContent().third_party_invite){var n=(t.getContent().third_party_invite.signed||{}).token;if(n){var r=e.getStateEvents("m.room.third_party_invite",n);r&&(e._tokenToInvite[n]=t)}}}function i(e,t,n){var r=e._userIdsToDisplayNames[t];if(delete e._userIdsToDisplayNames[t],r){for(var i=e._displayNameToUserIds[r]||[],o=0;o=c},t.exports=n},{"../utils":37,"./room-member":23,events:41}],25:[function(e,t){"use strict";function n(e,t){this.roomId=e,this.info=t}t.exports=n},{}],26:[function(e,t){"use strict";function n(e,t,n){var r={content:{},type:"m.receipt",room_id:t.getRoomId()};return r.content[t.getId()]={},r.content[t.getId()][n]={},r.content[t.getId()][n][e]={ts:t.getTs()},new c(r)}function r(e,t){if(t=t||{},t.pendingEventOrdering=t.pendingEventOrdering||"chronological",-1===["chronological","detached"].indexOf(t.pendingEventOrdering))throw new Error("opts.pendingEventOrdering MUST be either 'chronological' or 'detached'. Got: '"+t.pendingEventOrdering+"'");this.roomId=e,this.name=e,this.tags={},this.accountData={},this.summary=null,this.storageToken=t.storageToken,this._opts=t,this._txnToEvent={},this._receipts={},this._receiptCacheByEventId={},this._realReceipts={},this._notificationCounts={},this._timelineSets=[new p(this,t)],o(this,this.getUnfilteredTimelineSet(),["Room.timeline","Room.timelineReset"]),this._fixUpLegacyTimelineFields(),this._filteredTimelineSets={},"detached"==this._opts.pendingEventOrdering&&(this._pendingEventList=[]),this._blacklistUnverifiedDevices=!1}function i(e,t,n){if(!n){var r=e.currentState.getStateEvents("m.room.name","");if(r&&r.getContent()&&r.getContent().name)return r.getContent().name}var i=e.getCanonicalAlias();if(!i){var o=e.getAliases();o.length&&(i=o[0])}if(i)return i;var s=l.filter(e.currentState.getMembers(),function(e){return e.userId!==t&&"leave"!==e.membership}),a=l.filter(e.currentState.getMembers(),function(e){return"leave"!==e.membership}),u=l.filter(e.currentState.getMembers(),function(e){return e.userId==t}),c=u.length&&u[0].events?u[0].events.member.event:void 0;if(c&&"invite"==c.content.membership)return e.currentState.getMember(c.sender)?"Invite from "+e.currentState.getMember(c.sender).name:a[0].events.member?"Invite from "+c.sender:"Room Invite";if(0===s.length){if(1===a.length){if(a[0].userId===t){var d=e.currentState.getStateEvents("m.room.third_party_invite");if(d&&d.length>0){var h="Inviting "+d[0].getContent().display_name;return d.length>1&&(h+=2==d.length?" and "+d[1].getContent().display_name:" and "+d.length+" others"),h}return"Empty room"}return a[0].name}return"Empty room"}return 1===s.length?s[0].name:2===s.length?s[0].name+" and "+s[1].name:s[0].name+" and "+(s.length-1)+" others"}function o(e,t,n){l.forEach(n,function(n){t.on(n,function(){for(var t=[n],r=0;r-1&&this._timelineSets.splice(n,1)},r.prototype._addLiveEvent=function(e,t){var r=void 0;if("m.room.redaction"===e.getType()){var i=e.event.redacts,o=this.getUnfilteredTimelineSet().findEventById(i);o&&(o.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"+t);if(e.status=t,t==a.SENT){e.event.event_id=n;for(var u=0;u=0)return}else t[i][o]={};t[i][o]={eventId:r,data:s}})})})},r.prototype._buildReceiptCache=function(e){var t={};return l.keys(e).forEach(function(n){l.keys(e[n]).forEach(function(r){var i=e[n][r];t[i.eventId]||(t[i.eventId]=[]),t[i.eventId].push({userId:r,type:n,data:i.data})})}),t},r.prototype._addLocalEchoReceipt=function(e,t,r){this.addReceipt(n(e,t,r),!0)},r.prototype.addTags=function(e){this.tags=e.getContent().tags,this.emit("Room.tags",e,this)},r.prototype.addAccountData=function(e){for(var t=0;t]*)([0-9]*)$/);if(!o)return!1;var s=o[1],a=parseInt(o[2]);if(isNaN(a))return!1;switch(s){case"":case"==":return i==a;case"<":return a>i;case">":return i>a;case"<=":return a>=i;case">=":return i>=a;default:return!1}},u=function(n,r){var i=r.getContent();if(!i||!i.body||"string"!=typeof i.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 s=o.currentState.getMember(e.credentials.userId).name,a=new RegExp("(^|\\W)"+t(s)+"(\\W|$)","i");return i.body.search(a)>-1},c=function(){return!1},l=function(e,t){var n=h(e.key,t);if(!n||"string"!=typeof n)return!1;var r=void 0;r="content.body"==e.key?"(^|\\W)"+d(e.pattern)+"(\\W|$)":"^"+d(e.pattern)+"$";var i=new RegExp(r,"i");return!!n.match(i)},d=function(e){var n=t(e);return n=n.replace(/\\\*/,".*"),n=n.replace(/\?/,"."),n=n.replace(/\\\[(!|)(.*)\\]/,function(e,t,n){var r=t&&"^"||"",i=n.replace(/\\\-/,"-");return"["+r+i+"]"})},h=function(e,t){var n=e.split("."),r=void 0,i=n[0];for("content"==i?(r=t.getContent(),n.shift()):"type"==i?(r=t.getType(),n.shift()):r=t.event;n.length>0;){var o=n.shift();if(!r[o])return null;r=r[o]}return r},p=function(t,n){if(!n||!n.device)return null;if(t.getSender()==e.credentials.userId)return null;for(var i=Object.keys(n.device),o=0;ot)break;e=u.shift(),c("_runCallbacks: popping",e.key),r.push(e)}n();for(var o=0;on;){var i=n+r>>1,o=t(e[i]);o>0?r=i:n=i+1}return n}var o=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&&(t=0);var r=Array.prototype.slice.call(arguments,2),o=l()+t,a=s++;c("setTimeout: scheduling cb",a,"at",o,"(delay",t,")");var d={runAt:o,func:e,params:r,key:a},h=i(u,function(e){return e.runAt-o});return u.splice(h,0,d),n(),a},t.exports.clearTimeout=function(e){if(0!==u.length){var t=void 0;for(t=0;t0}),function(t){e._activeQueues.push(t),a("Spinning up queue: '%s'",t),i(e,t)})}function i(e,t){var n=o(e,t);if(!n){var r=e._activeQueues.indexOf(t);return r>=0&&e._activeQueues.splice(r,1),void a("Stopping queue '%s' as it is now empty",t)}a("Queue '%s' has %s pending events",t,e._queues[t].length),e._procFn(n.event).done(function(r){s(e,t),a("Queue '%s' sent event %s",t,n.event.getId()),n.defer.resolve(r),i(e,t)},function(r){n.attempts+=1;var o=e.retryAlgorithm(n.event,n.attempts,r);a("retry(%s) err=%s event_id=%s waitTime=%s",n.attempts,r,n.event.getId(),o),-1===o?(a("Queue '%s' giving up on event %s",t,n.event.getId()),s(e,t),n.defer.reject(r),i(e,t)):setTimeout(function(){i(e,t)},o)})}function o(e,t){var n=e._queues[t];return u.isArray(n)?n[0]:null}function s(e,t){var n=e._queues[t];return u.isArray(n)?n.shift():null}function a(){if(l){var e;(e=console).log.apply(e,arguments)}}var u=e("./utils"),c=e("q"),l=!1;n.prototype.getQueueForEvent=function(e){var t=this.queueAlgorithm(e);return t&&this._queues[t]?u.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 n=!1;return u.removeElement(this._queues[t],function(t){return t.event.getId()===e.getId()?(n=!0,!0):void 0}),n},n.prototype.setProcessFunction=function(e){this._procFn=e,r(this)},n.prototype.queueEvent=function(e){var t=this.queueAlgorithm(e);if(!t)return null;this._queues[t]||(this._queues[t]=[]);var n=c.defer();return this._queues[t].push({event:e,defer:n,attempts:0}),a("Queue algorithm dumped event %s into queue '%s'",e.getId(),t),r(this),n.promise},n.RETRY_BACKOFF_RATELIMIT=function(e,t,n){if(400===n.httpStatus||403===n.httpStatus||401===n.httpStatus)return-1;if("rejected"===n.cors)return-1;if("M_LIMIT_EXCEEDED"===n.name){var r=n.data.retry_after_ms;if(r)return r}return t>4?-1:1e3*Math.pow(2,t)},n.QUEUE_MESSAGES=function(e){return"m.room.message"===e.getType()?"message":null},t.exports=n},{"./utils":37,q:44}],32:[function(e,t){"use strict";var n=e("../utils"),r=e("../models/user");t.exports.MatrixInMemoryStore=function(e){e=e||{},this.rooms={},this.users={},this.syncToken=null,this.filters={},this.accountData={},this.localStorage=e.localStorage},t.exports.MatrixInMemoryStore.prototype={getSyncToken:function(){return this.syncToken},setSyncToken:function(e){this.syncToken=e},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(n){t._onRoomMember(null,e.currentState,n)})},_onRoomMember:function(e,t,n){if("invite"!==n.membership){var i=this.users[n.userId]||new r(n.userId);n.name&&(i.setDisplayName(n.name),n.events.member&&i.setRawDisplayName(n.events.member.getDirectionalContent().displayname)),n.events.member&&n.events.member.getContent().avatar_url&&i.setAvatarUrl(n.events.member.getContent().avatar_url),this.users[i.userId]=i}},getRoom:function(e){return this.rooms[e]||null},getRooms:function(){return n.values(this.rooms)},removeRoom:function(e){this.rooms[e]&&this.rooms[e].removeListener("RoomState.members",this._onRoomMember),delete this.rooms[e]},getRoomSummaries:function(){return n.map(n.values(this.rooms),function(e){return e.summary})},storeUser:function(e){this.users[e.userId]=e},getUser:function(e){return this.users[e]||null},getUsers:function(){return n.values(this.users)},scrollback:function(){return[]},storeEvents:function(){},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(t){}return null},setFilterIdByName:function(e,t){if(this.localStorage)try{this.localStorage.setItem("mxjssdk_memory_filter_"+e,t)}catch(n){}},storeAccountDataEvents:function(e){var t=this;e.forEach(function(e){t.accountData[e.getType()]=e})},getAccountData:function(e){return this.accountData[e]}}},{"../models/user":28,"../utils":37}],33:[function(e,t){"use strict";function n(e){if(this.store=e,!(l.isFunction(e.getItem)&&l.isFunction(e.setItem)&&l.isFunction(e.removeItem)&&l.isFunction(e.key)&&"number"==typeof e.length))throw new Error("Supplied webStore does not meet the WebStorage API interface")}function r(e){return h+"devices/"+e}function i(e){return h+"sessions/"+e}function o(e,t){return h+"inboundgroupsessions/"+e+"/"+t}function s(e){return h+"rooms/"+e}function a(e,t){try{return JSON.parse(e.getItem(t))}catch(n){c("Failed to get key %s: %s",t,n),c(n.stack)}return null}function u(e,t,n){e.setItem(t,JSON.stringify(n))}function c(){if(d){var e;(e=console).log.apply(e,arguments)}}var l=e("../../utils"),d=!1,h="session.e2e.";n.prototype={storeEndToEndAccount:function(e){this.store.setItem(p,e)},getEndToEndAccount:function(){return this.store.getItem(p)},setDeviceAnnounced:function(){this.store.setItem(f,"true")},getDeviceAnnounced:function(){return"true"==this.store.getItem(f)},storeEndToEndDevicesForUser:function(e,t){u(this.store,r(e),t)},getEndToEndDevicesForUser:function(e){return a(this.store,r(e))},storeEndToEndDeviceSyncToken:function(e){u(this.store,v,e)},getEndToEndDeviceSyncToken:function(){return a(this.store,v)},storeEndToEndSession:function(e,t,n){var r=this.getEndToEndSessions(e)||{};r[t]=n,u(this.store,i(e),r)},getEndToEndSessions:function(e){return a(this.store,i(e))},getAllEndToEndInboundGroupSessionKeys:function(){for(var e=h+"inboundgroupsessions/",t=[],n=0;n=0;d--){var h=a[d].getId();if(n.getTimelineForEvent(h)){i("Already have event "+h+" in limited sync - not resetting"),l=!1,a.splice(0,d);break}}l&&(n.currentState.paginationToken=e,o._deregisterStateListeners(n),n.resetLiveTimeline(t.timeline.prev_batch),r.resetNotifTimelineSet(),o._registerStateListeners(n))}o._processRoomEvents(n,s,a),n.addLiveEvents(u),n.addAccountData(c),n.recalculate(r.credentials.userId),t.isBrandNewRoom&&(r.store.storeRoom(n),r.emit("Room",n)),s.forEach(function(e){r.emit("event",e)}),a.forEach(function(e){r.emit("event",e)}),u.forEach(function(e){r.emit("event",e)}),c.forEach(function(e){r.emit("event",e)})}),l.forEach(function(e){var t=e.room,n=o._mapSyncEventsFormat(e.state,t),i=o._mapSyncEventsFormat(e.timeline,t),s=o._mapSyncEventsFormat(e.account_data);o._processRoomEvents(t,n,i),t.addAccountData(s),t.recalculate(r.credentials.userId),e.isBrandNewRoom&&(r.store.storeRoom(t),r.emit("Room",t)),n.forEach(function(e){r.emit("event",e)}),i.forEach(function(e){r.emit("event",e)}),s.forEach(function(e){r.emit("event",e)})}),e&&this._notifEvents.length&&(this._notifEvents.sort(function(e,t){return e.getTs()-t.getTs()}),this._notifEvents.forEach(function(e){r.getNotifTimelineSet().addLiveEvent(e)})),this.opts.crypto&&t.device_lists&&t.device_lists.changed&&t.device_lists.changed.forEach(function(e){n.opts.crypto.userDeviceListChanged(e)})},o.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=u.defer()),this._connectionReturnedDefer.promise},o.prototype._pokeKeepAlive=function(){function e(){clearTimeout(t._keepAliveTimer),t._connectionReturnedDefer&&(t._connectionReturnedDefer.resolve(),t._connectionReturnedDefer=null)}var t=this;this.client._http.request(void 0,"GET","/_matrix/client/versions",void 0,void 0,{prefix:"",localTimeoutMs:15e3}).done(function(){e()},function(n){400==n.httpStatus?t._keepAliveTimer=setTimeout(e,2e3):(t._keepAliveTimer=setTimeout(t._pokeKeepAlive.bind(t),5e3+Math.floor(5e3*Math.random())),t._updateSyncState("ERROR",{error:n}))})},o.prototype._mapSyncResponseToRoomArray=function(e){var t=this.client,n=this;return d.keys(e).map(function(r){var i=e[r],o=t.store.getRoom(r),s=!1;return o||(o=n.createRoom(r),s=!0),i.room=o,i.isBrandNewRoom=s,i})},o.prototype._mapSyncEventsFormat=function(e,t){if(!e||!d.isArray(e.events))return[];var n=this.client.getEventMapper();return e.events.map(function(e){return t&&(e.room_id=t.roomId),n(e)})},o.prototype._resolveInvites=function(e){if(e&&this.opts.resolveInvitesToProfiles){var t=this.client;e.getMembersWithMembership("invite").forEach(function(n){if(!n._requestedProfileInfo){n._requestedProfileInfo=!0;var r=t.getUser(n.userId),i=void 0;i=r?u({avatar_url:r.avatarUrl,displayname:r.displayName}):t.getProfileInfo(n.userId),i.done(function(t){var r=n.events.member;"invite"===r.getContent().membership&&(r.getContent().avatar_url=t.avatar_url,r.getContent().displayname=t.displayname,n.setMembershipEvent(r,e.currentState))},function(){})}})}},o.prototype._processRoomEvents=function(e,t,n){n=n||[];var r=this.client,i=d.map(d.deepCopy(t.map(function(e){return e.event})),r.getEventMapper()),o=t;if(e.oldState.setStateEvents(i),e.currentState.setStateEvents(o),this._resolveInvites(e),e.recalculate(this.client.credentials.userId),r.getNotifTimelineSet())for(var s=0;st.minIndex())return!0}else if(t.index0&&this.unpaginate(l,e!=o.BACKWARDS),i(!0)}if(!n||0===r)return i(!1);var d=s.timeline.getPaginationToken(e);if(!d)return a("TimelineWindow: no token"),i(!1);a("TimelineWindow: starting request");var h=this,p=this._client.paginateEventTimeline(s.timeline,{backwards:e==o.BACKWARDS,limit:t})["finally"](function(){s.pendingPaginate=null}).then(function(n){return a("TimelineWindow: request completed with result "+n),n?h.paginate(e,t,!0,r-1):!1});return s.pendingPaginate=p,p},n.prototype.unpaginate=function(e,t){var n=t?this._start:this._end;if(e>this._eventCount||0>e)throw new Error("Attemting to unpaginate "+e+" events, but only have "+this._eventCount+" in the timeline");for(;e>0;){var r=t?n.advance(e):n.retreat(e);if(0>=r)throw new Error("Unable to unpaginate any further, but still have "+this._eventCount+" events");e-=r,this._eventCount-=r,a("TimelineWindow.unpaginate: dropped "+r+" (now "+this._eventCount+")")}},n.prototype.getEvents=function(){if(!this._start)return[];for(var e=[],t=this._start.timeline;;){var n=t.getEvents(),r=0,i=n.length;t===this._start.timeline&&(r=this._start.index+t.getBaseIndex()),t===this._end.timeline&&(i=this._end.index+t.getBaseIndex());for(var s=r;i>s;s++)e.push(n[s]);if(t===this._end.timeline)break;t=t.getNeighbouringTimeline(o.FORWARDS)}return e},r.prototype.minIndex=function(){return-1*this.timeline.getBaseIndex()},r.prototype.maxIndex=function(){return this.timeline.getEvents().length-this.timeline.getBaseIndex()},r.prototype.advance=function(e){if(!e)return 0;var t=void 0;if(0>e){if(t=Math.max(e,this.minIndex()-this.index),0>t)return this.index+=t,t}else if(t=Math.min(e,this.maxIndex()-this.index),t>0)return this.index+=t,t;var n=this.timeline.getNeighbouringTimeline(0>e?o.BACKWARDS:o.FORWARDS);return n?(this.timeline=n,this.index=0>e?this.maxIndex():this.minIndex(),a("paginate: switched to new neighbour"),this.advance(e)):0},r.prototype.retreat=function(e){return-1*this.advance(-1*e)},t.exports.TimelineWindow=n,t.exports.TimelineIndex=r},{"./models/event-timeline":21,q:44}],37:[function(e,t){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.exports.encodeParams=function(e){var t="";for(var n in e)e.hasOwnProperty(n)&&(t+="&"+encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t.substring(1)},t.exports.encodeUri=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e=e.replace(n,encodeURIComponent(t[n])));return e},t.exports.map=function(e,t){for(var n=new Array(e.length),r=0;r=0;r--)if(t(e[r],r,e))return e[r]}else for(r=0;r=0;r--)if(t(e[r],r,e))return i=e[r],e.splice(r,1),i}else for(r=0;r>>0;if("function"!=typeof e)throw new TypeError;for(var r=[],i=arguments.length>=2?arguments[1]:void 0,o=0;n>o;o++)if(o in t){var s=t[o];e.call(i,s,o,t)&&r.push(s)}return r}),Array.prototype.map||(Array.prototype.map=function(e,t){var n=void 0,r=void 0;if(null===this||void 0===this)throw new TypeError(" this is null or not defined");var i=Object(this),o=i.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");arguments.length>1&&(n=t);var s=new Array(o);for(r=0;o>r;){var a,u;r in i&&(a=i[r],u=e.call(n,a,r,i),s[r]=u),r++}return s}),Array.prototype.forEach||(Array.prototype.forEach=function(e,t){var n=void 0,r=void 0;if(null===this||void 0===this)throw new TypeError(" this is null or not defined");var i=Object(this),o=i.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(arguments.length>1&&(n=t),r=0;o>r;){var s;r in i&&(s=i[r],e.call(n,s,r,i)),r++}})},t.exports.inherits=function(e,t){"function"!=typeof Object.create&&(Object.create=function(){function e(){}var t=Object.prototype.hasOwnProperty;return function(r){if("object"!=("undefined"==typeof r?"undefined":n(r)))throw new TypeError("Object prototype may only be an Object or null");e.prototype=r;var i=new e;if(e.prototype=null,arguments.length>1){var o=Object(arguments[1]);for(var s in o)t.call(o,s)&&(i[s]=o[s])}return i}}()),e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}},{}],38:[function(e,t){(function(n){"use strict";function r(e){this.roomId=e.roomId,this.client=e.client,this.webRtc=e.webRtc,this.URL=e.URL,this.turnServers=e.turnServers||[],0===this.turnServers.length&&this.turnServers.push({urls:[r.FALLBACK_STUN_SERVER]}),i.forEach(this.turnServers,function(e){i.checkObjectHasKeys(e,["urls"])}),this.callId="c"+(new Date).getTime(),this.state="fledgling",this.didConnect=!1,this.candidateSendQueue=[],this.candidateSendTries=0,this.mediaPromises=Object.create(null),this.screenSharingStream=null}var i=e("../utils"),o=e("events").EventEmitter,s=!0;r.CALL_TIMEOUT_MS=6e4,r.FALLBACK_STUN_SERVER="stun:stun.l.google.com:19302",r.ERR_LOCAL_OFFER_FAILED="local_offer_failed",r.ERR_NO_USER_MEDIA="no_user_media",i.inherits(r,o),r.prototype.placeVoiceCall=function(){g("placeVoiceCall"),m(this),E(this,w("voice")),this.type="voice"},r.prototype.placeVideoCall=function(e,t){g("placeVideoCall"),m(this),this.localVideoElement=t,this.remoteVideoElement=e,E(this,w("video")),this.type="video",f(this)},r.prototype.placeScreenSharingCall=function(e,t){g("placeScreenSharingCall"),m(this);var n=T(this);if(n){this.localVideoElement=t,this.remoteVideoElement=e;var i=this;this.webRtc.getUserMedia(n,function(e){i.screenSharingStream=e,g("Got screen stream, requesting audio stream...");var t=w("voice");E(i,t)},function(e){i.emit("error",y(r.ERR_NO_USER_MEDIA,"Failed to get screen-sharing stream: "+e))}),this.type="video",f(this)}},r.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()}):e.play()},r.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()}):e.pause()},r.prototype.assignElement=function(e,t,n){console.log("queuing assign on "+n+" element "+e+" for "+t),this.mediaPromises[n]?this.mediaPromises[n]=this.mediaPromises[n].then(function(){console.log("previous promise completed for "+n),e.src=t},function(){console.log("previous promise failed for "+n),e.src=t}):e.src=t},r.prototype.getLocalVideoElement=function(){return this.localVideoElement},r.prototype.getRemoteVideoElement=function(){return this.remoteVideoElement},r.prototype.getRemoteAudioElement=function(){return this.remoteAudioElement},r.prototype.setLocalVideoElement=function(e){var t=this;this.localVideoElement=e,e&&this.localAVStream&&"video"===this.type&&!function(){e.autoplay=!0,t.assignElement(e,t.URL.createObjectURL(t.localAVStream),"localVideo"),e.muted=!0;var n=t;setTimeout(function(){var e=n.getLocalVideoElement();e.play&&n.playElement(e,"localVideo")},0)}()},r.prototype.setRemoteVideoElement=function(e){this.remoteVideoElement=e,f(this)},r.prototype.setRemoteAudioElement=function(e){this.remoteVideoElement.muted=!0,this.remoteAudioElement=e,v(this)},r.prototype._initWithInvite=function(e){this.msg=e.getContent(),this.peerConn=S(this);var t=this;this.peerConn&&this.peerConn.setRemoteDescription(new this.webRtc.RtcSessionDescription(this.msg.offer),b(t,t._onSetRemoteDescriptionSuccess),b(t,t._onSetRemoteDescriptionError)),c(this,"ringing"),this.direction="inbound",this.type=this.msg.offer&&this.msg.offer.sdp&&this.msg.offer.sdp.indexOf("m=video")>-1?"video":"voice",e.getAge()&&setTimeout(function(){"ringing"==t.state&&(g("Call invite has expired. Hanging up."),t.hangupParty="remote",c(t,"ended"),p(t),"closed"!=t.peerConn.signalingState&&t.peerConn.close(),t.emit("hangup",t))},this.msg.lifetime-e.getAge())},r.prototype._initWithHangup=function(e){this.msg=e.getContent(),c(this,"ended")},r.prototype.answer=function(){g("Answering call %s of type %s",this.callId,this.type);var e=this;this.localAVStream||this.waitForLocalAVStream?this.localAVStream?this._gotUserMediaForAnswer(this.localAVStream):this.waitForLocalAVStream&&c(this,"wait_local_media"):(this.webRtc.getUserMedia(w(this.type),b(e,e._gotUserMediaForAnswer),b(e,e._getUserMediaFailed)),c(this,"wait_local_media"))},r.prototype._replacedBy=function(e){g(this.callId+" being replaced by "+e.callId),"wait_local_media"==this.state?(g("Telling new call to wait for local media"),e.waitForLocalAVStream=!0):"create_offer"==this.state?(g("Handing local stream to new call"),e._gotUserMediaForAnswer(this.localAVStream),delete this.localAVStream):"invite_sent"==this.state&&(g("Handing local stream to new call"),e._gotUserMediaForAnswer(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)},r.prototype.hangup=function(e,t){g("Ending call "+this.callId),h(this,"local",e,!t);var n={version:0,call_id:this.callId,reason:e};l(this,"m.call.hangup",n)},r.prototype.setLocalVideoMuted=function(e){this.localAVStream&&a(this.localAVStream.getVideoTracks(),!e)},r.prototype.isLocalVideoMuted=function(){return this.localAVStream?!u(this.localAVStream.getVideoTracks()):!1},r.prototype.setMicrophoneMuted=function(e){this.localAVStream&&a(this.localAVStream.getAudioTracks(),!e)},r.prototype.isMicrophoneMuted=function(){return this.localAVStream?!u(this.localAVStream.getAudioTracks()):!1},r.prototype._gotUserMediaForInvite=function(e){if(this.successor)return void this.successor._gotUserMediaForAnswer(e);if("ended"!=this.state){g("_gotUserMediaForInvite -> "+this.type);var t=this,n=this.getLocalVideoElement();n&&"video"==this.type&&(n.autoplay=!0,this.screenSharingStream?(g("Setting screen sharing stream to the local video element"),this.assignElement(n,this.URL.createObjectURL(this.screenSharingStream),"localVideo")):this.assignElement(n,this.URL.createObjectURL(e),"localVideo"), -n.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,a(e.getAudioTracks(),!0),this.peerConn=S(this),this.peerConn.addStream(e),this.peerConn.createOffer(b(t,t._gotLocalOffer),b(t,t._getLocalOfferFailed)),c(t,"create_offer")}},r.prototype._gotUserMediaForAnswer=function(e){var t=this;if("ended"!=t.state){var n=t.getLocalVideoElement();n&&"video"==t.type&&(n.autoplay=!0,this.assignElement(n,this.URL.createObjectURL(e),"localVideo"),n.muted=!0,setTimeout(function(){var e=t.getLocalVideoElement();e.play&&t.playElement(e,"localVideo")},0)),t.localAVStream=e,a(e.getAudioTracks(),!0),t.peerConn.addStream(e);var r={mandatory:{OfferToReceiveAudio:!0,OfferToReceiveVideo:"video"==t.type}};t.peerConn.createAnswer(function(e){g("Created answer: "+e),t.peerConn.setLocalDescription(e,function(){var e={version:0,call_id:t.callId,answer:{sdp:t.peerConn.localDescription.sdp,type:t.peerConn.localDescription.type}};l(t,"m.call.answer",e),c(t,"connecting")},function(){g("Error setting local description!")},r)},function(e){g("Failed to create answer: "+e)}),c(t,"create_answer")}},r.prototype._gotLocalIceCandidate=function(e){if(e.candidate){g("Got local ICE "+e.candidate.sdpMid+" candidate: "+e.candidate.candidate);var t={candidate:e.candidate.candidate,sdpMid:e.candidate.sdpMid,sdpMLineIndex:e.candidate.sdpMLineIndex};d(this,t)}},r.prototype._gotRemoteIceCandidate=function(e){"ended"!=this.state&&(g("Got remote ICE "+e.sdpMid+" candidate: "+e.candidate),this.peerConn.addIceCandidate(new this.webRtc.RtcIceCandidate(e),function(){},function(){}))},r.prototype._receivedAnswer=function(e){if("ended"!=this.state){var t=this;this.peerConn.setRemoteDescription(new this.webRtc.RtcSessionDescription(e.answer),b(t,t._onSetRemoteDescriptionSuccess),b(t,t._onSetRemoteDescriptionError)),c(t,"connecting")}},r.prototype._gotLocalOffer=function(e){var t=this;return g("Created offer: "+e),"ended"==t.state?void g("Ignoring newly created offer on call ID "+t.callId+" because the call has ended"):void 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:r.CALL_TIMEOUT_MS};l(t,"m.call.invite",e),setTimeout(function(){"invite_sent"==t.state&&t.hangup("invite_timeout")},r.CALL_TIMEOUT_MS),c(t,"invite_sent")},function(){g("Error setting local description!")})},r.prototype._getLocalOfferFailed=function(){this.emit("error",y(r.ERR_LOCAL_OFFER_FAILED,"Failed to start audio for call!"))},r.prototype._getUserMediaFailed=function(){this.emit("error",y(r.ERR_NO_USER_MEDIA,"Couldn't start capturing media! Is your microphone set up and does this app have permission?")),this.hangup("user_media_failed")},r.prototype._onIceConnectionStateChanged=function(){"ended"!=this.state&&(g("Ice connection state changed to: "+this.peerConn.iceConnectionState),"completed"==this.peerConn.iceConnectionState||"connected"==this.peerConn.iceConnectionState?(c(this,"connected"),this.didConnect=!0):"failed"==this.peerConn.iceConnectionState&&this.hangup("ice_failed"))},r.prototype._onSignallingStateChanged=function(){g("call "+this.callId+": Signalling state changed to: "+this.peerConn.signalingState)},r.prototype._onSetRemoteDescriptionSuccess=function(){g("Set remote description")},r.prototype._onSetRemoteDescriptionError=function(e){g("Failed to set remote description"+e)},r.prototype._onAddStream=function(e){g("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 n=this;k(t,function(e){g("Track id "+e.id+" added"),e.onstarted=b(n,n._onRemoteStreamTrackStarted)}),void 0!==e.stream.oninactive?e.stream.oninactive=b(n,n._onRemoteStreamEnded):e.stream.onended=b(n,n._onRemoteStreamEnded),e.stream.onstarted=b(n,n._onRemoteStreamStarted),"video"===this.type?(f(this),v(this)):v(this)},r.prototype._onRemoteStreamStarted=function(){c(this,"connected")},r.prototype._onRemoteStreamEnded=function(){g("Remote stream ended"),this.hangupParty="remote",c(this,"ended"),p(this),"closed"!=this.peerConn.signalingState&&this.peerConn.close(),this.emit("hangup",this)},r.prototype._onRemoteStreamTrackStarted=function(){c(this,"connected")},r.prototype._onHangupReceived=function(e){g("Hangup received"),h(this,"remote",e.reason,!0)},r.prototype._onAnsweredElsewhere=function(){g("Answered elsewhere"),h(this,"remote","answered_elsewhere",!0)};var a=function(e,t){for(var n=0;n5)return g("Failed to send candidates on attempt %s. Giving up for now.",e.candidateSendTries),void(e.candidateSendTries=0);var r=500*Math.pow(2,e.candidateSendTries);++e.candidateSendTries,g("Failed to send candidates. Retrying in "+r+"ms"),setTimeout(function(){D(e)},r)})}},E=function(e,t){e.client.callList[e.callId]=e,e.webRtc.getUserMedia(t,b(e,e._gotUserMediaForInvite),b(e,e._getUserMediaFailed)),c(e,"wait_local_media"),e.direction="outbound",e.config=t},S=function(e){var t=e.turnServers;if("mozilla"===e.webRtc.vendor){t=[];for(var n=0;n-1)return!0;return!1};var a=i.navigator.getUserMedia||i.navigator.webkitGetUserMedia||i.navigator.mozGetUserMedia;if(a&&(s.getUserMedia=function(){return a.apply(i.navigator,arguments)}),s.RtcPeerConnection=i.RTCPeerConnection||i.webkitRTCPeerConnection||i.mozRTCPeerConnection,s.RtcSessionDescription=i.RTCSessionDescription||i.webkitRTCSessionDescription||i.mozRTCSessionDescription,s.RtcIceCandidate=i.RTCIceCandidate||i.webkitRTCIceCandidate||i.mozRTCIceCandidate,s.vendor=null,i.mozRTCPeerConnection?s.vendor="mozilla":i.webkitRTCPeerConnection?s.vendor="webkit":i.RTCPeerConnection&&(s.vendor="generic"),!(s.RtcIceCandidate&&s.RtcSessionDescription&&s.RtcPeerConnection&&s.getUserMedia))return null;var u={webRtc:s,client:e,URL:i.URL,roomId:t,turnServers:e.getTurnServers()};return new r(u)}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils":37,events:41}],39:[function(e,t){"use strict";function n(e){return s.lastIndex=0,e.replace(s,function(e){return a[e]})}function r(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):o(e);default:throw new Error("Cannot stringify: "+typeof e)}}function i(e){for(var t="[",n="",i=0;iu;++u)a[String.fromCharCode(u)]="\\U"+("0000"+u.toString(16)).slice(-4).toUpperCase();a["\b"]="\\b",a[" "]="\\t",a["\n"]="\\n",a["\f"]="\\f",a["\r"]="\\r",a['"']='\\"',a["\\"]="\\\\",t.exports={stringify:r}},{}],40:[function(e,t,n){!function(e,r){"function"==typeof define&&define.amd?define([],r):"object"==typeof n?t.exports=r():e.returnExports=r()}(this,function(){function e(i,o){if("function"!=typeof o)throw new Error("Bad callback given: "+o);if(!i)throw new Error("No options given");var a=i.onResponse;if(i="string"==typeof i?{uri:i}:JSON.parse(JSON.stringify(i)),i.onResponse=a,i.verbose&&(e.log=r()),i.url&&(i.uri=i.url,delete i.url),!i.uri&&""!==i.uri)throw new Error("options.uri is a required argument");if("string"!=typeof i.uri)throw new Error("options.uri must be a string");for(var u=["proxy","_redirectsFollowed","maxRedirects","followRedirect"],c=0;c>18&63,o=u>>12&63,s=u>>6&63,a=63&u,p[d++]=c.charAt(i)+c.charAt(o)+c.charAt(s)+c.charAt(a);while(l299)&&n.error){e=new Error("CouchDB error: "+(n.error.reason||n.error.error));for(var i in n)e[i]=n[i];return r(e,t,n)}return r(e,t,n)}"string"==typeof t&&(t={uri:t}),t.json=!0,t.body&&(t.json=t.body),delete t.body,r=r||n;var o=e(t,i);return o},e})},{}],41:[function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(e){return"function"==typeof e}function i(e){return"number"==typeof e}function o(e){return"object"==typeof e&&null!==e}function s(e){return void 0===e}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!i(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,i,a,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;var l=new Error('Uncaught, unspecified "error" event. ('+t+")");throw l.context=t,l}if(n=this._events[e],s(n))return!1;if(r(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),n.apply(this,a)}else if(o(n))for(a=Array.prototype.slice.call(arguments,1),c=n.slice(),i=c.length,u=0;i>u;u++)c[u].apply(this,a);return!0},n.prototype.addListener=function(e,t){var i;if(!r(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,r(t.listener)?t.listener:t),this._events[e]?o(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,o(this._events[e])&&!this._events[e].warned&&(i=s(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,i&&i>0&&this._events[e].length>i&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),i||(i=!0,t.apply(this,arguments))}if(!r(t))throw TypeError("listener must be a function");var i=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,i,s,a;if(!r(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],s=n.length,i=-1,n===t||r(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(o(n)){for(a=s;a-->0;)if(n[a]===t||n[a].listener&&n[a].listener===t){i=a;break}if(0>i)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],r(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?r(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(r(t))return 1;if(t)return t.length}return 0},n.listenerCount=function(e,t){return e.listenerCount(t)}},{}],42:[function(e,t){function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function i(e){if(l===setTimeout)return setTimeout(e,0);if((l===n||!l)&&setTimeout)return l=setTimeout,setTimeout(e,0);try{return l(e,0)}catch(t){try{return l.call(null,e,0)}catch(t){return l.call(this,e,0)}}}function o(e){if(d===clearTimeout)return clearTimeout(e);if((d===r||!d)&&clearTimeout)return d=clearTimeout,clearTimeout(e);try{return d(e)}catch(t){try{return d.call(null,e)}catch(t){return d.call(this,e)}}}function s(){v&&p&&(v=!1,p.length?f=p.concat(f):m=-1,f.length&&a())}function a(){if(!v){var e=i(s);v=!0;for(var t=f.length;t;){for(p=f,f=[];++m1)for(var n=1;n1&&(r=n[0]+"@",e=n[1]),e=e.replace(O,".");var i=e.split("."),s=o(i,t).join(".");return r+s}function a(e){for(var t,n,r=[],i=0,o=e.length;o>i;)t=e.charCodeAt(i++),t>=55296&&56319>=t&&o>i?(n=e.charCodeAt(i++),56320==(64512&n)?r.push(((1023&t)<<10)+(1023&n)+65536):(r.push(t),i--)):r.push(t);return r}function u(e){return o(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 10>e-48?e-22:26>e-65?e-65:26>e-97?e-97:T}function l(e,t){return e+22+75*(26>e)-((0!=t)<<5)}function d(e,t,n){var r=0;for(e=n?M(e/R):e>>1,e+=M(e/t);e>P*b>>1;r+=T)e=M(e/P);return M(r+(P+1)*e/(e+I))}function h(e){var t,n,r,o,s,a,l,h,p,f,v=[],m=e.length,y=0,g=D,_=k;for(n=e.lastIndexOf(A),0>n&&(n=0),r=0;n>r;++r)e.charCodeAt(r)>=128&&i("not-basic"),v.push(e.charCodeAt(r));for(o=n>0?n+1:0;m>o;){for(s=y,a=1,l=T;o>=m&&i("invalid-input"),h=c(e.charCodeAt(o++)),(h>=T||h>M((S-y)/a))&&i("overflow"),y+=h*a,p=_>=l?w:l>=_+b?b:l-_,!(p>h);l+=T)f=T-p,a>M(S/f)&&i("overflow"),a*=f;t=v.length+1,_=d(y-s,t,0==s),M(y/t)>S-g&&i("overflow"),g+=M(y/t),y%=t,v.splice(y++,0,g)}return u(v)}function p(e){var t,n,r,o,s,u,c,h,p,f,v,m,y,g,_,E=[];for(e=a(e),m=e.length,t=D,n=0,s=k,u=0;m>u;++u)v=e[u],128>v&&E.push(L(v));for(r=o=E.length,o&&E.push(A);m>r;){for(c=S,u=0;m>u;++u)v=e[u],v>=t&&c>v&&(c=v);for(y=r+1,c-t>M((S-n)/y)&&i("overflow"),n+=(c-t)*y,t=c,u=0;m>u;++u)if(v=e[u],t>v&&++n>S&&i("overflow"),v==t){for(h=n,p=T;f=s>=p?w:p>=s+b?b:p-s,!(f>h);p+=T)_=h-f,g=T-f,E.push(L(l(f+_%g,0))),h=M(_/g);E.push(L(l(h,0))),s=d(n,y,r==o),n=0,++r}++n,++t}return E.join("")}function f(e){return s(e,function(e){return x.test(e)?h(e.slice(4).toLowerCase()):e})}function v(e){return s(e,function(e){return C.test(e)?"xn--"+p(e):e})}var m="object"==typeof n&&n&&!n.nodeType&&n,y="object"==typeof t&&t&&!t.nodeType&&t,g="object"==typeof e&&e;(g.global===g||g.window===g||g.self===g)&&(r=g);var _,E,S=2147483647,T=36,w=1,b=26,I=38,R=700,k=72,D=128,A="-",x=/^xn--/,C=/[^\x20-\x7E]/,O=/[\x2E\u3002\uFF0E\uFF61]/g,U={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},P=T-w,M=Math.floor,L=String.fromCharCode;if(_={version:"1.4.1",ucs2:{decode:a,encode:u},decode:h,encode:p,toASCII:v,toUnicode:f},"function"==typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return _});else if(m&&y)if(t.exports==m)y.exports=_;else for(E in _)_.hasOwnProperty(E)&&(m[E]=_[E]);else r.punycode=_}(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],44:[function(e,t,n){(function(e){!function(e){"use strict";if("function"==typeof bootstrap)bootstrap("promise",e);else if("object"==typeof n&&"object"==typeof t)t.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeQ=e}else{if("undefined"==typeof window&&"undefined"==typeof self)throw new Error("This environment was not anticipated by Q. Please file a bug.");var r="undefined"!=typeof window?window:self,i=r.Q;r.Q=e(),r.Q.noConflict=function(){return r.Q=i,this}}}(function(){"use strict";function t(e){return function(){return Q.apply(e,arguments)}}function n(e){return e===Object(e)}function r(e){return"[object StopIteration]"===re(e)||e instanceof V}function i(e,t){if($&&t.stack&&"object"==typeof e&&null!==e&&e.stack&&-1===e.stack.indexOf(ie)){for(var n=[],r=t;r;r=r.source)r.stack&&n.unshift(r.stack);n.unshift(e.stack);var i=n.join("\n"+ie+"\n");e.stack=o(i)}}function o(e){for(var t=e.split("\n"),n=[],r=0;r=W&&ce>=r}function c(){if($)try{throw new Error}catch(e){var t=e.stack.split("\n"),n=t[0].indexOf("@")>0?t[1]:t[2],r=a(n);if(!r)return;return B=r[0],r[1]}}function l(e,t,n){return function(){return"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn(t+" is deprecated, use "+n+" instead.",new Error("").stack),e.apply(e,arguments)}}function d(e){return e instanceof v?e:_(e)?D(e):k(e)}function h(){function e(e){t=e,o.source=e,Y(n,function(t,n){d.nextTick(function(){e.promiseDispatch.apply(e,n)})},void 0),n=void 0,r=void 0}var t,n=[],r=[],i=ee(h.prototype),o=ee(v.prototype);if(o.promiseDispatch=function(e,i,o){var s=X(arguments);n?(n.push(s),"when"===i&&o[1]&&r.push(o[1])):d.nextTick(function(){t.promiseDispatch.apply(t,s)})},o.valueOf=function(){if(n)return o;var e=y(t);return g(e)&&(t=e),e},o.inspect=function(){return t?t.inspect():{state:"pending"}},d.longStackSupport&&$)try{throw new Error}catch(s){o.stack=s.stack.substring(s.stack.indexOf("\n")+1)}return i.promise=o,i.resolve=function(n){t||e(d(n))},i.fulfill=function(n){t||e(k(n))},i.reject=function(n){t||e(R(n))},i.notify=function(e){t||Y(r,function(t,n){d.nextTick(function(){n(e)})},void 0)},i}function p(e){if("function"!=typeof e)throw new TypeError("resolver must be a function.");var t=h();try{e(t.resolve,t.reject,t.notify)}catch(n){t.reject(n)}return t.promise}function f(e){return p(function(t,n){for(var r=0,i=e.length;i>r;r++)d(e[r]).then(t,n)})}function v(e,t,n){void 0===t&&(t=function(e){return R(new Error("Promise does not support operation: "+e))}),void 0===n&&(n=function(){return{state:"unknown"}});var r=ee(v.prototype);if(r.promiseDispatch=function(n,i,o){var s;try{s=e[i]?e[i].apply(r,o):t.call(r,i,o)}catch(a){s=R(a)}n&&n(s)},r.inspect=n,n){var i=n();"rejected"===i.state&&(r.exception=i.reason),r.valueOf=function(){var e=n();return"pending"===e.state||"rejected"===e.state?r:e.value}}return r}function m(e,t,n,r){return d(e).then(t,n,r)}function y(e){if(g(e)){var t=e.inspect();if("fulfilled"===t.state)return t.value}return e}function g(e){return e instanceof v}function _(e){return n(e)&&"function"==typeof e.then}function E(e){return g(e)&&"pending"===e.inspect().state}function S(e){return!g(e)||"fulfilled"===e.inspect().state}function T(e){return g(e)&&"rejected"===e.inspect().state}function w(){oe.length=0,se.length=0,ue||(ue=!0)}function b(t,n){ue&&("object"==typeof e&&"function"==typeof e.emit&&d.nextTick.runAfter(function(){-1!==z(se,t)&&(e.emit("unhandledRejection",n,t),ae.push(t))}),se.push(t),oe.push(n&&"undefined"!=typeof n.stack?n.stack:"(no stack) "+n))}function I(t){if(ue){var n=z(se,t);-1!==n&&("object"==typeof e&&"function"==typeof e.emit&&d.nextTick.runAfter(function(){var r=z(ae,t);-1!==r&&(e.emit("rejectionHandled",oe[n],t),ae.splice(r,1))}),se.splice(n,1),oe.splice(n,1))}}function R(e){var t=v({when:function(t){return t&&I(this),t?t(e):this}},function(){return this},function(){return{state:"rejected",reason:e}});return b(t,e),t}function k(e){return v({when:function(){return e},get:function(t){return e[t]},set:function(t,n){e[t]=n},"delete":function(t){delete e[t]},post:function(t,n){return null===t||void 0===t?e.apply(void 0,n):e[t].apply(e,n)},apply:function(t,n){return e.apply(t,n)},keys:function(){return ne(e)}},void 0,function(){return{state:"fulfilled",value:e}})}function D(e){var t=h();return d.nextTick(function(){try{e.then(t.resolve,t.reject,t.notify)}catch(n){t.reject(n)}}),t.promise}function A(e){return v({isDef:function(){}},function(t,n){return M(e,t,n)},function(){return d(e).inspect()})}function x(e,t,n){return d(e).spread(t,n)}function C(e){return function(){function t(e,t){var s;if("undefined"==typeof StopIteration){try{s=n[e](t)}catch(a){return R(a)}return s.done?d(s.value):m(s.value,i,o)}try{s=n[e](t)}catch(a){return r(a)?d(a.value):R(a)}return m(s,i,o)}var n=e.apply(this,arguments),i=t.bind(t,"next"),o=t.bind(t,"throw");return i()}}function O(e){d.done(d.async(e)())}function U(e){throw new V(e)}function P(e){return function(){return x([this,L(arguments)],function(t,n){return e.apply(t,n)})}}function M(e,t,n){return d(e).dispatch(t,n)}function L(e){return m(e,function(e){var t=0,n=h();return Y(e,function(r,i,o){var s;g(i)&&"fulfilled"===(s=i.inspect()).state?e[o]=s.value:(++t,m(i,function(r){e[o]=r,0===--t&&n.resolve(e)},n.reject,function(e){n.notify({index:o,value:e})}))},void 0),0===t&&n.resolve(e),n.promise})}function N(e){if(0===e.length)return d.resolve();var t=d.defer(),n=0;return Y(e,function(r,i,o){function s(e){t.resolve(e)}function a(){n--,0===n&&t.reject(new Error("Can't get fulfillment value from any promise, all promises were rejected."))}function u(e){t.notify({index:o,value:e})}var c=e[o];n++,m(c,s,a,u)},void 0),t.promise}function F(e){return m(e,function(e){return e=Z(e,d),m(L(Z(e,function(e){return m(e,H,H)})),function(){return e})})}function q(e){return d(e).allSettled()}function j(e,t){return d(e).then(void 0,void 0,t)}function K(e,t){return d(e).nodeify(t)}var $=!1;try{throw new Error}catch(G){$=!!G.stack}var B,V,W=c(),H=function(){},J=function(){function t(){for(var e,t;r.next;)r=r.next,e=r.task,r.task=void 0,t=r.domain,t&&(r.domain=void 0, -t.enter()),n(e,t);for(;u.length;)e=u.pop(),n(e);o=!1}function n(e,n){try{e()}catch(r){if(a)throw n&&n.exit(),setTimeout(t,0),n&&n.enter(),r;setTimeout(function(){throw r},0)}n&&n.exit()}var r={task:void 0,next:null},i=r,o=!1,s=void 0,a=!1,u=[];if(J=function(t){i=i.next={task:t,domain:a&&e.domain,next:null},o||(o=!0,s())},"object"==typeof e&&"[object process]"===e.toString()&&e.nextTick)a=!0,s=function(){e.nextTick(t)};else if("function"==typeof setImmediate)s="undefined"!=typeof window?setImmediate.bind(window,t):function(){setImmediate(t)};else if("undefined"!=typeof MessageChannel){var c=new MessageChannel;c.port1.onmessage=function(){s=l,c.port1.onmessage=t,t()};var l=function(){c.port2.postMessage(0)};s=function(){setTimeout(t,0),l()}}else s=function(){setTimeout(t,0)};return J.runAfter=function(e){u.push(e),o||(o=!0,s())},J}(),Q=Function.call,X=t(Array.prototype.slice),Y=t(Array.prototype.reduce||function(e,t){var n=0,r=this.length;if(1===arguments.length)for(;;){if(n in this){t=this[n++];break}if(++n>=r)throw new TypeError}for(;r>n;n++)n in this&&(t=e(t,this[n],n));return t}),z=t(Array.prototype.indexOf||function(e){for(var t=0;t2?X(arguments,1):n)}},d.Promise=p,d.promise=p,p.race=f,p.all=L,p.reject=R,p.resolve=d,d.passByCopy=function(e){return e},v.prototype.passByCopy=function(){return this},d.join=function(e,t){return d(e).join(t)},v.prototype.join=function(e){return d([this,e]).spread(function(e,t){if(e===t)return e;throw new Error("Can't join: not the same: "+e+" "+t)})},d.race=f,v.prototype.race=function(){return this.then(d.race)},d.makePromise=v,v.prototype.toString=function(){return"[object Promise]"},v.prototype.then=function(e,t,n){function r(t){try{return"function"==typeof e?e(t):t}catch(n){return R(n)}}function o(e){if("function"==typeof t){i(e,a);try{return t(e)}catch(n){return R(n)}}return R(e)}function s(e){return"function"==typeof n?n(e):e}var a=this,u=h(),c=!1;return d.nextTick(function(){a.promiseDispatch(function(e){c||(c=!0,u.resolve(r(e)))},"when",[function(e){c||(c=!0,u.resolve(o(e)))}])}),a.promiseDispatch(void 0,"when",[void 0,function(e){var t,n=!1;try{t=s(e)}catch(r){if(n=!0,!d.onerror)throw r;d.onerror(r)}n||u.notify(t)}]),u.promise},d.tap=function(e,t){return d(e).tap(t)},v.prototype.tap=function(e){return e=d(e),this.then(function(t){return e.fcall(t).thenResolve(t)})},d.when=m,v.prototype.thenResolve=function(e){return this.then(function(){return e})},d.thenResolve=function(e,t){return d(e).thenResolve(t)},v.prototype.thenReject=function(e){return this.then(function(){throw e})},d.thenReject=function(e,t){return d(e).thenReject(t)},d.nearer=y,d.isPromise=g,d.isPromiseAlike=_,d.isPending=E,v.prototype.isPending=function(){return"pending"===this.inspect().state},d.isFulfilled=S,v.prototype.isFulfilled=function(){return"fulfilled"===this.inspect().state},d.isRejected=T,v.prototype.isRejected=function(){return"rejected"===this.inspect().state};var oe=[],se=[],ae=[],ue=!0;d.resetUnhandledRejections=w,d.getUnhandledReasons=function(){return oe.slice()},d.stopUnhandledRejectionTracking=function(){w(),ue=!1},w(),d.reject=R,d.fulfill=k,d.master=A,d.spread=x,v.prototype.spread=function(e,t){return this.all().then(function(t){return e.apply(void 0,t)},t)},d.async=C,d.spawn=O,d["return"]=U,d.promised=P,d.dispatch=M,v.prototype.dispatch=function(e,t){var n=this,r=h();return d.nextTick(function(){n.promiseDispatch(r.resolve,e,t)}),r.promise},d.get=function(e,t){return d(e).dispatch("get",[t])},v.prototype.get=function(e){return this.dispatch("get",[e])},d.set=function(e,t,n){return d(e).dispatch("set",[t,n])},v.prototype.set=function(e,t){return this.dispatch("set",[e,t])},d.del=d["delete"]=function(e,t){return d(e).dispatch("delete",[t])},v.prototype.del=v.prototype["delete"]=function(e){return this.dispatch("delete",[e])},d.mapply=d.post=function(e,t,n){return d(e).dispatch("post",[t,n])},v.prototype.mapply=v.prototype.post=function(e,t){return this.dispatch("post",[e,t])},d.send=d.mcall=d.invoke=function(e,t){return d(e).dispatch("post",[t,X(arguments,2)])},v.prototype.send=v.prototype.mcall=v.prototype.invoke=function(e){return this.dispatch("post",[e,X(arguments,1)])},d.fapply=function(e,t){return d(e).dispatch("apply",[void 0,t])},v.prototype.fapply=function(e){return this.dispatch("apply",[void 0,e])},d["try"]=d.fcall=function(e){return d(e).dispatch("apply",[void 0,X(arguments,1)])},v.prototype.fcall=function(){return this.dispatch("apply",[void 0,X(arguments)])},d.fbind=function(e){var t=d(e),n=X(arguments,1);return function(){return t.dispatch("apply",[this,n.concat(X(arguments))])}},v.prototype.fbind=function(){var e=this,t=X(arguments);return function(){return e.dispatch("apply",[this,t.concat(X(arguments))])}},d.keys=function(e){return d(e).dispatch("keys",[])},v.prototype.keys=function(){return this.dispatch("keys",[])},d.all=L,v.prototype.all=function(){return L(this)},d.any=N,v.prototype.any=function(){return N(this)},d.allResolved=l(F,"allResolved","allSettled"),v.prototype.allResolved=function(){return F(this)},d.allSettled=q,v.prototype.allSettled=function(){return this.then(function(e){return L(Z(e,function(e){function t(){return e.inspect()}return e=d(e),e.then(t,t)}))})},d.fail=d["catch"]=function(e,t){return d(e).then(void 0,t)},v.prototype.fail=v.prototype["catch"]=function(e){return this.then(void 0,e)},d.progress=j,v.prototype.progress=function(e){return this.then(void 0,void 0,e)},d.fin=d["finally"]=function(e,t){return d(e)["finally"](t)},v.prototype.fin=v.prototype["finally"]=function(e){return e=d(e),this.then(function(t){return e.fcall().then(function(){return t})},function(t){return e.fcall().then(function(){throw t})})},d.done=function(e,t,n,r){return d(e).done(t,n,r)},v.prototype.done=function(t,n,r){var o=function(e){d.nextTick(function(){if(i(e,s),!d.onerror)throw e;d.onerror(e)})},s=t||n||r?this.then(t,n,r):this;"object"==typeof e&&e&&e.domain&&(o=e.domain.bind(o)),s.then(void 0,o)},d.timeout=function(e,t,n){return d(e).timeout(t,n)},v.prototype.timeout=function(e,t){var n=h(),r=setTimeout(function(){t&&"string"!=typeof t||(t=new Error(t||"Timed out after "+e+" ms"),t.code="ETIMEDOUT"),n.reject(t)},e);return this.then(function(e){clearTimeout(r),n.resolve(e)},function(e){clearTimeout(r),n.reject(e)},n.notify),n.promise},d.delay=function(e,t){return void 0===t&&(t=e,e=void 0),d(e).delay(t)},v.prototype.delay=function(e){return this.then(function(t){var n=h();return setTimeout(function(){n.resolve(t)},e),n.promise})},d.nfapply=function(e,t){return d(e).nfapply(t)},v.prototype.nfapply=function(e){var t=h(),n=X(e);return n.push(t.makeNodeResolver()),this.fapply(n).fail(t.reject),t.promise},d.nfcall=function(e){var t=X(arguments,1);return d(e).nfapply(t)},v.prototype.nfcall=function(){var e=X(arguments),t=h();return e.push(t.makeNodeResolver()),this.fapply(e).fail(t.reject),t.promise},d.nfbind=d.denodeify=function(e){var t=X(arguments,1);return function(){var n=t.concat(X(arguments)),r=h();return n.push(r.makeNodeResolver()),d(e).fapply(n).fail(r.reject),r.promise}},v.prototype.nfbind=v.prototype.denodeify=function(){var e=X(arguments);return e.unshift(this),d.denodeify.apply(void 0,e)},d.nbind=function(e,t){var n=X(arguments,2);return function(){function r(){return e.apply(t,arguments)}var i=n.concat(X(arguments)),o=h();return i.push(o.makeNodeResolver()),d(r).fapply(i).fail(o.reject),o.promise}},v.prototype.nbind=function(){var e=X(arguments,0);return e.unshift(this),d.nbind.apply(void 0,e)},d.nmapply=d.npost=function(e,t,n){return d(e).npost(t,n)},v.prototype.nmapply=v.prototype.npost=function(e,t){var n=X(t||[]),r=h();return n.push(r.makeNodeResolver()),this.dispatch("post",[e,n]).fail(r.reject),r.promise},d.nsend=d.nmcall=d.ninvoke=function(e,t){var n=X(arguments,2),r=h();return n.push(r.makeNodeResolver()),d(e).dispatch("post",[t,n]).fail(r.reject),r.promise},v.prototype.nsend=v.prototype.nmcall=v.prototype.ninvoke=function(e){var t=X(arguments,1),n=h();return t.push(n.makeNodeResolver()),this.dispatch("post",[e,t]).fail(n.reject),n.promise},d.nodeify=K,v.prototype.nodeify=function(e){return e?void this.then(function(t){d.nextTick(function(){e(null,t)})},function(t){d.nextTick(function(){e(t)})}):this},d.noConflict=function(){throw new Error("Q.noConflict only works when Q is used as a global")};var ce=c();return d})}).call(this,e("_process"))},{_process:42}],45:[function(e,t){"use strict";function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.exports=function(e,t,i,o){t=t||"&",i=i||"=";var s={};if("string"!=typeof e||0===e.length)return s;var a=/\+/g;e=e.split(t);var u=1e3;o&&"number"==typeof o.maxKeys&&(u=o.maxKeys);var c=e.length;u>0&&c>u&&(c=u);for(var l=0;c>l;++l){var d,h,p,f,v=e[l].replace(a,"%20"),m=v.indexOf(i);m>=0?(d=v.substr(0,m),h=v.substr(m+1)):(d=v,h=""),p=decodeURIComponent(d),f=decodeURIComponent(h),n(s,p)?r(s[p])?s[p].push(f):s[p]=[s[p],f]:s[p]=f}return s};var r=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},{}],46:[function(e,t){"use strict";function n(e,t){if(e.map)return e.map(t);for(var n=[],r=0;r",'"',"`"," ","\r","\n"," "],f=["{","}","|","\\","^","`"].concat(p),v=["'"].concat(f),m=["%","/","?",";","#"].concat(v),y=["/","?","#"],g=255,_=/^[+a-z0-9A-Z_-]{0,63}$/,E=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,S={javascript:!0,"javascript:":!0},T={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},b=e("querystring");r.prototype.parse=function(e,t,n){if(!c.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var r=e.indexOf("?"),i=-1!==r&&rD)&&(R=D)}var A,x;x=-1===R?a.lastIndexOf("@"):a.lastIndexOf("@",R),-1!==x&&(A=a.slice(0,x),a=a.slice(x+1),this.auth=decodeURIComponent(A)),R=-1;for(var k=0;kD)&&(R=D)}-1===R&&(R=a.length),this.host=a.slice(0,R),a=a.slice(R),this.parseHost(),this.hostname=this.hostname||"";var C="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!C)for(var O=this.hostname.split(/\./),k=0,U=O.length;U>k;k++){var P=O[k];if(P&&!P.match(_)){for(var M="",L=0,N=P.length;N>L;L++)M+=P.charCodeAt(L)>127?"x":P[L];if(!M.match(_)){var F=O.slice(0,k),q=O.slice(k+1),j=P.match(E);j&&(F.push(j[1]),q.unshift(j[2])),q.length&&(a="/"+q.join(".")+a),this.hostname=F.join(".");break}}}this.hostname=this.hostname.length>g?"":this.hostname.toLowerCase(),C||(this.hostname=u.toASCII(this.hostname));var K=this.port?":"+this.port:"",$=this.hostname||"";this.host=$+K,this.href+=this.host,C&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==a[0]&&(a="/"+a))}if(!S[f])for(var k=0,U=v.length;U>k;k++){var G=v[k];if(-1!==a.indexOf(G)){var B=encodeURIComponent(G);B===G&&(B=escape(G)),a=a.split(G).join(B)}}var V=a.indexOf("#");-1!==V&&(this.hash=a.substr(V),a=a.slice(0,V));var W=a.indexOf("?");if(-1!==W?(this.search=a.substr(W),this.query=a.substr(W+1),t&&(this.query=b.parse(this.query)),a=a.slice(0,W)):t&&(this.search="",this.query={}),a&&(this.pathname=a),w[f]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var K=this.pathname||"",H=this.search||"";this.path=K+H}return this.href=this.format(),this},r.prototype.format=function(){var e=this.auth||"";e&&(e=encodeURIComponent(e),e=e.replace(/%3A/i,":"),e+="@");var t=this.protocol||"",n=this.pathname||"",r=this.hash||"",i=!1,o="";this.host?i=e+this.host:this.hostname&&(i=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(i+=":"+this.port)),this.query&&c.isObject(this.query)&&Object.keys(this.query).length&&(o=b.stringify(this.query));var s=this.search||o&&"?"+o||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||w[t])&&i!==!1?(i="//"+(i||""),n&&"/"!==n.charAt(0)&&(n="/"+n)):i||(i=""),r&&"#"!==r.charAt(0)&&(r="#"+r),s&&"?"!==s.charAt(0)&&(s="?"+s),n=n.replace(/[?#]/g,function(e){return encodeURIComponent(e)}),s=s.replace("#","%23"),t+i+n+s+r},r.prototype.resolve=function(e){return this.resolveObject(i(e,!1,!0)).format()},r.prototype.resolveObject=function(e){if(c.isString(e)){var t=new r;t.parse(e,!1,!0),e=t}for(var n=new r,i=Object.keys(this),o=0;o0?n.host.split("@"):!1;I&&(n.auth=I.shift(),n.host=n.hostname=I.shift())}return n.search=e.search,n.query=e.query,c.isNull(n.pathname)&&c.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n}if(!S.length)return n.pathname=null,n.path=n.search?"/"+n.search:null,n.href=n.format(),n;for(var R=S.slice(-1)[0],k=(n.host||e.host||S.length>1)&&("."===R||".."===R)||""===R,D=0,A=S.length;A>=0;A--)R=S[A],"."===R?S.splice(A,1):".."===R?(S.splice(A,1),D++):D&&(S.splice(A,1),D--);if(!_&&!E)for(;D--;D)S.unshift("..");!_||""===S[0]||S[0]&&"/"===S[0].charAt(0)||S.unshift(""),k&&"/"!==S.join("/").substr(-1)&&S.push("");var x=""===S[0]||S[0]&&"/"===S[0].charAt(0);if(b){n.hostname=n.host=x?"":S.length?S.shift():"";var I=n.host&&n.host.indexOf("@")>0?n.host.split("@"):!1;I&&(n.auth=I.shift(),n.host=n.hostname=I.shift())}return _=_||n.host&&S.length,_&&!x&&S.unshift(""),S.length?n.pathname=S.join("/"):(n.pathname=null,n.path=null),c.isNull(n.pathname)&&c.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=e.auth||n.auth,n.slashes=n.slashes||e.slashes,n.href=n.format(),n},r.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":49,punycode:43,querystring:47}],49:[function(e,t){"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