diff --git a/remote/index.html b/remote/index.html new file mode 100644 index 0000000..7301995 --- /dev/null +++ b/remote/index.html @@ -0,0 +1,25 @@ + + + + + + + + + +
+ + +
+
+
+
+ + + + +
+ + + + diff --git a/remote/index.js b/remote/index.js new file mode 100644 index 0000000..7066a98 --- /dev/null +++ b/remote/index.js @@ -0,0 +1,80 @@ +"use strict"; +console.log("Loading Matrix sdk"); + +var client = matrixcs.createClient({ + baseUrl: hs, + accessToken: accessToken, + userId: uid +}); + + +var room = rooms[0]; +var txn = 0; + +function setRoom(inRoom) { + room = rooms[inRoom]; + init(client); +} + +function setBrightness() { + var brightness = $("#brightness").val(); + client.sendEvent(room, "m.room.message", { + body: "!brightness " + brightness, + msgtype: "m.text" + }, txn); + txn = txn + 1; + +} + +function setPattern(name) { + client.sendEvent(room, "m.room.message", { + body: name, + msgtype: "m.text" + }, txn); + txn = txn + 1; +} + +var sendColor = function(color) { + txn = txn + 1; + if (txn % 3 == 0) { + client.sendEvent(room, "org.lightrix.color", { + color: color.toRgb() + }, txn); + } +} + +var init = function(client) { + client.getStateEvent(room, "org.lightrix.pattern", "", function(err, resp) { + var colorState; + if(err) { + var colorState = 255; + } else { + console.log(resp) + var colorState = resp.state[0]; + } + + $("#picker").spectrum({ + flat: true, + color: pad(colorState.toString(16), 6), + showInput: true, + move: sendColor + }); + }); + + client.getStateEvent(room, "org.lightrix.brightness", "", function(err, resp) { + var brightness = 255; + if(!err) { + var brightness = resp; + } + + $("#brightness").val(brightness); + }); +}; + +init(client); + +function pad(number, length) { + var str = '' + number; + while (str.length < length) str = '0' + str; + return str; +} diff --git a/remote/matrix-0.4.1.min.js b/remote/matrix-0.4.1.min.js new file mode 100644 index 0000000..49ba90c --- /dev/null +++ b/remote/matrix-0.4.1.min.js @@ -0,0 +1,5 @@ +!function e(t,n,r){function o(s,a){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[s]={exports:{}};t[s][0].call(l.exports,function(e){var n=t[s][1][e];return o(n?n:e)},l,l.exports,e,t,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s1&&a(t,n,E.QUEUED)),o||(o=u(e,n)),o.done(function(e){if(t){var o=e.event_id,a=t.getTimelineForEvent(o);if(a){var u=b.findElement(a.getEvents(),function(e){return e.getId()===o},!0);n.encryptedType&&(u.event.content=n.event.content,u.event.type=n.event.type),t.removeEvents([i]),u.status=null}else{var c=n.status;t.removeEvents([i]),n.event.event_id=e.event_id,n.status=null,t.addEventsToTimeline([n]),t.emit("Room.localEchoUpdated",n,t,i,c)}}f(r,s,e)},function(e){a(t,n,E.NOT_SENT),h(r,s,e)}),s.promise}function a(e,t,n){e?e.updateLocalEchoStatus(t,n):t.status=n}function u(e,t){var n,r={$roomId:t.getRoomId(),$eventType:t.getWireType(),$stateKey:t.getStateKey(),$txnId:t._txnId?t._txnId:(new Date).getTime()};if(t.isState()){var o="/rooms/$roomId/state/$eventType";t.getStateKey()&&t.getStateKey().length>0&&(o="/rooms/$roomId/state/$eventType/$stateKey"),n=b.encodeUri(o,r)}else n=b.encodeUri("/rooms/$roomId/send/$eventType/$txnId",r);return e._http.authedRequest(void 0,"PUT",n,void 0,t.getWireContent())}function c(e,t,n,r,o,i){b.isFunction(o)&&(i=o,o=void 0);var s=b.encodeUri("/rooms/$roomId/state/m.room.member/$userId",{$roomId:t,$userId:n});return e._http.authedRequest(i,"PUT",s,void 0,{membership:r,reason:o})}function l(e,t,n,r,o,i){b.isFunction(o)&&(i=o,o=void 0);var s=b.encodeUri("/rooms/$room_id/$membership",{$room_id:t,$membership:r});return e._http.authedRequest(i,"POST",s,void 0,{user_id:n,reason:o})}function d(e){function t(t){if(0===t.getType().indexOf("m.call.")){var r,o=t.getContent(),i=o.call_id?e.callList[o.call_id]:void 0;if("m.call.invite"===t.getType()){if(t.getSender()===e.credentials.userId)return;if(t.getAge()>o.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.",o.call_id),i=I.createNewMatrixCall(e,t.getRoomId()),!i)return void console.log("Incoming call ID "+o.call_id+" but this client doesn't support WebRTC");if(i.callId=o.call_id,i._initWithInvite(t),e.callList[i.callId]=i,n[i.callId])for(r=0;ri.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(o):i._receivedAnswer(o)}else if("m.call.candidates"===t.getType()){if(t.getSender()===e.credentials.userId)return;if(i)for(r=0;r=0;i--){var s=r[i];("m.call.answer"===s.getType()||"m.call.hangup"===s.getType())&&(n[s.getContent().call_id]="yep")}r.forEach(function(e){n[e.getContent().call_id]||t(e)}),r=[]}}),e.on("event",function(e){return o?void t(e):void(0===e.getType().indexOf("m.call.")&&r.push(e))})}function p(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],setTimeout(function(){p(e)},1e3*(t.ttl||3600)*.9)}},function(){console.error("Failed to get TURN URIs"),setTimeout(function(){p(e)},6e4)}))}function h(e,t,n){e&&e(n),t.reject(n)}function f(e,t,n){e&&e(null,n),t.resolve(n)}function m(e){function t(t){var n=new S(t);return"m.room.encrypted"===n.getType()?o(e,n):n}return t}var v=e("./pushprocessor"),g=e("events").EventEmitter,y=e("q"),_=e("./http-api"),S=e("./models/event").MatrixEvent,E=e("./models/event").EventStatus,T=e("./models/event-timeline"),R=e("./models/search-result"),w=e("./store/stub"),I=e("./webrtc/call"),b=e("./utils"),k=e("./content-repo"),x=e("./filter"),A=e("./sync"),C=_.MatrixError,U=3e3,M=!1;try{var O=e("olm");O.Account&&O.Session&&(M=!0)}catch(L){}var P="m.olm.v1.curve25519-aes-sha2";b.inherits(n,g),n.prototype.getHomeserverUrl=function(){return this.baseUrl},n.prototype.getIdentityServerUrl=function(){return this.idBaseUrl},n.prototype.getDomain=function(){return this.credentials&&this.credentials.userId?this.credentials.userId.replace(/^.*?:/,""):null},n.prototype.getAccessToken=function(){return this._http.opts.accessToken||null},n.prototype.getUserIdLocalpart=function(){return this.credentials&&this.credentials.userId?this.credentials.userId.split(":")[0].substring(1):null},n.prototype.supportsVoip=function(){return this._supportsVoip},n.prototype.getSyncState=function(){return this._syncApi?this._syncApi.getSyncState():null},n.prototype.isGuest=function(){return this._isGuest},n.prototype.getScheduler=function(){return this.scheduler},n.prototype.setGuest=function(e){this._isGuest=e},n.prototype.retryImmediately=function(){return this._syncApi.retryImmediately()},n.prototype.isCryptoEnabled=function(){return M&&null!==this.sessionStore},n.prototype.uploadKeys=function(e,t){if(!M||null===this.sessionStore)return y.reject(new Error("End-to-end encryption disabled"));var n=void 0===t;t=t||y.defer();var r="/keys/upload/"+this.deviceId,o=this.sessionStore.getEndToEndAccount();if(!o)return y.reject(new Error("End-to-end account not found"));var i,s=new O.Account;try{s.unpickle(this.accountKey,o),i=JSON.parse(s.one_time_keys());var a=s.max_number_of_one_time_keys()}finally{s.free()}var u={};for(var c in i.curve25519)i.curve25519.hasOwnProperty(c)&&(u["curve25519:"+c]=i.curve25519[c]);var l={device_keys:this.deviceKeys,one_time_keys:u},d=this;return this._http.authedRequestWithPrefix(void 0,"POST",r,void 0,l,_.PREFIX_UNSTABLE).then(function(r){var o=Math.floor(a/2),i=r.one_time_key_counts.curve25519||0,s=o>i,u=d.sessionStore.getEndToEndAccount(),c=new O.Account;try{if(c.unpickle(d.accountKey,u),c.mark_keys_as_published(),s){var l=o-i;e&&(l=Math.min(l,e)),c.generate_one_time_keys(l)}u=c.pickle(d.accountKey),d.sessionStore.storeEndToEndAccount(u)}finally{c.free()}s&&n?d.uploadKeys(e,t):t.resolve()}),t.promise},n.prototype.downloadKeys=function(e,t){if(!M||null===this.sessionStore)return y.reject(new Error("End-to-end encryption disabled"));for(var n={},r={},o=!1,i=0;i0){var d={};for(o=0;on;n++)e+=t.charAt(Math.floor(Math.random()*t.length));return e},t.exports.MatrixClient=n,t.exports.CRYPTO_ENABLED=M},{"./content-repo":3,"./filter":4,"./http-api":5,"./models/event":9,"./models/event-timeline":8,"./models/search-result":14,"./pushprocessor":16,"./store/stub":20,"./sync":22,"./utils":24,"./webrtc/call":25,events:27,olm:void 0,q:29}],3:[function(e,t){var n=e("./utils");t.exports={getHttpUriForMxc:function(e,t,r,o,i,s){if("string"!=typeof t||!t)return"";if(0!==t.indexOf("mxc://"))return s?t:"";var a=t.slice(6),u="/_matrix/media/v1/download/",c={};r&&(c.width=r),o&&(c.height=o),i&&(c.method=i),n.keys(c).length>0&&(u="/_matrix/media/v1/thumbnail/");var l=a.indexOf("#"),d="";return l>=0&&(d=a.substr(l),a=a.substr(0,l)),e+u+a+(0===n.keys(c).length?"":"?"+n.encodeParams(c))+d},getIdenticonUri:function(e,t,r,o){if(!t)return null;r||(r=96),o||(o=96);var i={width:r,height:o},s=n.encodeUri("/_matrix/media/v1/identicon/$ident",{$ident:t});return e+s+(0===n.keys(i).length?"":"?"+n.encodeParams(i))}}},{"./utils":24}],4:[function(e,t){"use strict";function n(e,t,n){for(var r=t.split("."),o=e,i=0;i=400&&(o=new t.exports.MatrixError(s),o.httpStatus=i.statusCode),o)e.reject(o),n(o);else{var a={code:i.statusCode,headers:i.headers,data:s};e.resolve(r?s:a),n(null,r?s:a)}}};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:{})},{"./utils":24,q:29}],6:[function(e,t){(function(n){"use strict";t.exports.MatrixEvent=e("./models/event").MatrixEvent,t.exports.EventStatus=e("./models/event").EventStatus,t.exports.MatrixInMemoryStore=e("./store/memory").MatrixInMemoryStore,t.exports.WebStorageStore=e("./store/webstorage"),t.exports.MatrixHttpApi=e("./http-api").MatrixHttpApi,t.exports.MatrixError=e("./http-api").MatrixError,t.exports.MatrixClient=e("./client").MatrixClient,t.exports.Room=e("./models/room"),t.exports.EventTimeline=e("./models/event-timeline"),t.exports.RoomMember=e("./models/room-member"),t.exports.RoomState=e("./models/room-state"),t.exports.User=e("./models/user"),t.exports.MatrixScheduler=e("./scheduler"),t.exports.WebStorageSessionStore=e("./store/session/webstorage"),t.exports.CRYPTO_ENABLED=e("./client").CRYPTO_ENABLED,t.exports.ContentRepo=e("./content-repo"),t.exports.Filter=e("./filter"),t.exports.TimelineWindow=e("./timeline-window").TimelineWindow,t.exports.createNewMatrixCall=e("./webrtc/call").createNewMatrixCall;var r;t.exports.request=function(e){r=e},t.exports.createClient=function(e){return"string"==typeof e&&(e={baseUrl:e}),e.request=e.request||r,e.store=e.store||new t.exports.MatrixInMemoryStore({localStorage:n.localStorage}),e.scheduler=e.scheduler||new t.exports.MatrixScheduler,new t.exports.MatrixClient(e)}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./client":2,"./content-repo":3,"./filter":4,"./http-api":5,"./models/event":9,"./models/event-timeline":8,"./models/room":13,"./models/room-member":10,"./models/room-state":11,"./models/user":15,"./scheduler":17,"./store/memory":18,"./store/session/webstorage":19,"./store/webstorage":21,"./timeline-window":23,"./webrtc/call":25}],7:[function(e,t){"use strict";function n(e){this._timeline=[e],this._ourEventIndex=0,this._paginateTokens={b:null,f:null},this._paginateRequests={b:null,f:null}}n.prototype.getEvent=function(){return this._timeline[this._ourEventIndex]},n.prototype.getTimeline=function(){return this._timeline},n.prototype.getOurEventIndex=function(){return this._ourEventIndex},n.prototype.getPaginateToken=function(e){return this._paginateTokens[e?"b":"f"]},n.prototype.setPaginateToken=function(e,t){this._paginateTokens[t?"b":"f"]=e},n.prototype.addEvents=function(e,t){t?(this._timeline=e.concat(this._timeline),this._ourEventIndex+=e.length):this._timeline=this._timeline.concat(e)},t.exports=n},{}],8:[function(e,t){"use strict";function n(e){this._roomId=e,this._events=[],this._baseIndex=0,this._startState=new o(e),this._startState.paginationToken=null,this._endState=new o(e),this._endState.paginationToken=null,this._prevTimeline=null,this._nextTimeline=null,this._paginationRequests={b:null,f:null}}function r(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)}var o=e("./room-state"),i=e("../utils"),s=e("./event").MatrixEvent;n.BACKWARDS="b",n.FORWARDS="f",n.prototype.initialiseState=function(e){if(this._events.length>0)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 s(e)});this._startState.setStateEvents(t),this._endState.setStateEvents(e)},n.prototype.getRoomId=function(){return this._roomId},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,n){var o=t?this._startState:this._endState;r(e,o,t),e.isState()&&(o.setStateEvents([e]),e.sender&&"m.room.member"!==e.getType()||r(e,o,t));var i;if(t)i=0;else if(i=this._events.length,n)for(var s=this._events.length-1;s>=0;s--)if(!this._events[s].status){i=s+1;break}this._events.splice(i,0,e),t&&this._baseIndex++},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+" ("+o+")":r}var o=e("events").EventEmitter,i=e("../content-repo"),s=e("../utils");s.inherits(n,o),n.prototype.setMembershipEvent=function(e,t){if("m.room.member"===e.getType()){this.events.member=e;var n=this.membership;this.membership=e.getDirectionalContent().membership;var o=this.name;this.name=r(this,e,t),n!==this.membership&&(this._updateModifiedTime(),this.emit("RoomMember.membership",e,this)),o!==this.name&&(this._updateModifiedTime(),this.emit("RoomMember.name",e,this))}},n.prototype.setPowerLevelEvent=function(e){if("m.room.power_levels"===e.getType()){var t=e.getContent().users_default||0;s.forEach(s.values(e.getContent().users),function(e){t=Math.max(t,e)});var n=this.powerLevel,r=this.powerLevelNorm;this.powerLevel=e.getContent().users[this.userId]||e.getContent().users_default||0,this.powerLevelNorm=0,t>0&&(this.powerLevelNorm=100*this.powerLevel/t),(n!==this.powerLevel||r!==this.powerLevelNorm)&&(this._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,o,s){if(void 0===o&&(o=!0),!this.events.member&&!o)return null;var a=this.events.member?this.events.member.getContent().avatar_url:null,u=i.getHttpUriForMxc(e,a,t,n,r,s);return u?u:o?i.getIdenticonUri(e,this.userId,t,n):null},t.exports=n},{"../content-repo":3,"../utils":24,events:27}],11:[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 o(e,t,n){var r=e._userIdsToDisplayNames[t];if(delete e._userIdsToDisplayNames[t],r){for(var o=e._displayNameToUserIds[r]||[],i=0;i0){var h="Inviting "+p[0].getContent().display_name;return p.length>1&&(h+=2==p.length?" and "+p[1].getContent().display_name:" and "+p.length+" others"),h}return"Empty room"}return u[0].name}return"Empty room"}return 1===a.length?a[0].name:2===a.length?a[0].name+" and "+a[1].name:a[0].name+" and "+(a.length-1)+" others"}var s=e("events").EventEmitter,a=e("./event").EventStatus,u=e("./room-summary"),c=e("./event").MatrixEvent,l=e("../utils"),d=e("../content-repo"),p=e("./event-timeline");l.inherits(r,s),r.prototype.getLiveTimeline=function(){return this._liveTimeline},r.prototype.resetLiveTimeline=function(e){var t;this._timelineSupport?t=this.addTimeline():(t=new p(this.roomId),this._timelines=[t],this._eventIdToTimeline={});var n=this._liveTimeline.getState(p.FORWARDS).events,r=[];for(var o in n)if(n.hasOwnProperty(o))for(var i in n[o])n[o].hasOwnProperty(i)&&r.push(n[o][i]);t.initialiseState(r),t.setPaginationToken(e,p.BACKWARDS),this._liveTimeline=t,this._fixUpLegacyTimelineFields(),this.emit("Room.timelineReset",this)},r.prototype._fixUpLegacyTimelineFields=function(){this.timeline=this._liveTimeline.getEvents(),this.oldState=this._liveTimeline.getState(p.BACKWARDS),this.currentState=this._liveTimeline.getState(p.FORWARDS)},r.prototype.getTimelineForEvent=function(e){var t=this._eventIdToTimeline[e];return void 0===t?null:t},r.prototype.findEventById=function(e){var t=this.getTimelineForEvent(e);return t?l.findElement(t.getEvents(),function(t){return t.getId()==e}):void 0},r.prototype.getUnreadNotificationCount=function(e){return e=e||"total",this._notificationCounts[e]},r.prototype.setUnreadNotificationCount=function(e,t){this._notificationCounts[e]=t},r.prototype.getAvatarUrl=function(e,t,n,r,o){var i=this.currentState.getStateEvents("m.room.avatar","");if(void 0===o&&(o=!0),!i&&!o)return null;var s=i?i.getContent().url:null;return s?d.getHttpUriForMxc(e,s,t,n,r):o?d.getIdenticonUri(e,this.roomId,t,n):null},r.prototype.getMember=function(e){var t=this.currentState.members[e];return t?t:null},r.prototype.getJoinedMembers=function(){return this.getMembersWithMembership("join")},r.prototype.getMembersWithMembership=function(e){return l.filter(this.currentState.getMembers(),function(t){return t.membership===e})},r.prototype.getDefaultRoomName=function(e){return i(this,e,!0)},r.prototype.hasMembershipState=function(e,t){var n=this.getMember(e);return n?n.membership===t:!1},r.prototype.addTimeline=function(){if(!this._timelineSupport)throw Error("timeline support is disabled. Set the 'timelineSupport' parameter to true when creating MatrixClient to enable it.");var e=new p(this.roomId);return this._timelines.push(e),e},r.prototype.addEventsToTimeline=function(e,t,n,r){if(n||(n=this._liveTimeline),!t&&n==this._liveTimeline)return void this._addLiveEvents(e);for(var o=t?p.BACKWARDS:p.FORWARDS,i=t?p.FORWARDS:p.BACKWARDS,s=!1,a=!1,u=0;u=0)return}else t[o][i]={};t[o][i]={eventId:r,data:s}})})})},r.prototype._buildReciptCache=function(e){var t={};return l.keys(e).forEach(function(n){l.keys(e[n]).forEach(function(r){var o=e[n][r];t[o.eventId]||(t[o.eventId]=[]),t[o.eventId].push({userId:r,type:n,data:o.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;t0&&this._updateModifiedTime();for(var r=0;r]*)([0-9]*)$/);if(!i)return!1;var s=i[1],a=parseInt(i[2]);if(isNaN(a))return!1;switch(s){case"":case"==":return o==a;case"<":return a>o;case">":return o>a;case"<=":return a>=o;case">=":return o>=a;default:return!1}},a=function(n,r){if(!r.content||!r.content.body||"string"!=typeof r.content.body)return!1;var o=e.getRoom(r.room_id);if(!(o&&o.currentState&&o.currentState.members&&o.currentState.getMember(e.credentials.userId)))return!1;var i=o.currentState.getMember(e.credentials.userId).name,s=new RegExp("\\b"+t(i)+"\\b","i");return r.content.body.search(s)>-1},u=function(){return!1},c=function(e,t){var n=d(e.key,t);if(!n||"string"!=typeof n)return!1;var r;r="content.body"==e.key?"\\b"+l(e.pattern)+"\\b":"^"+l(e.pattern)+"$";var o=new RegExp(r,"i");return!!n.match(o)},l=function(e){var n=t(e);return n=n.replace(/\\\*/,".*"),n=n.replace(/\?/,"."),n=n.replace(/\\\[(!|)(.*)\\]/,function(e,t,n){var r=t&&"^"||"",o=n.replace(/\\\-/,"-");return"["+r+o+"]"})},d=function(e,t){for(var n=e.split("."),r=t;n.length>0;){var o=n.shift();if(!r[o])return null;r=r[o]}return r},p=function(t,r){if(!r||!r.device)return null;if(t.user_id==e.credentials.userId)return null;for(var o=Object.keys(r.device),i=0;i0}),function(t){e._activeQueues.push(t),a("Spinning up queue: '%s'",t),o(e,t)})}function o(e,t){var n=i(e,t);if(!n){var r=e._activeQueues.indexOf(t);return r>=0&&e._activeQueues.splice(r,1),void 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),o(e,t)},function(r){n.attempts+=1;var i=e.retryAlgorithm(n.event,n.attempts,r);a("retry(%s) err=%s event_id=%s waitTime=%s",n.attempts,r,n.event.getId(),i),-1===i?(a("Queue '%s' giving up on event %s",t,n.event.getId()),s(e,t),n.defer.reject(r),o(e,t)):setTimeout(function(){o(e,t)},i)})}function i(e,t){var n=e._queues[t];return u.isArray(n)?n[0]:null}function s(e,t){var n=e._queues[t];return u.isArray(n)?n.shift():null}function a(){l&&console.log.apply(console,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":24,q:29}],18:[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.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||this.users[n.userId]&&this.users[n.userId].events.presence)){var o=new r(n.userId);o.setDisplayName(n.name);var i=n.events.member?n.events.member.getContent().avatar_url:null;o.setAvatarUrl(i),this.users[o.userId]=o}},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){}}}},{"../models/user":15,"../utils":24}],19:[function(e,t){"use strict";function n(e){if(this.store=e,!c.isFunction(e.getItem)||!c.isFunction(e.setItem)||!c.isFunction(e.removeItem))throw new Error("Supplied webStore does not meet the WebStorage API interface")}function r(e){return d+"devices/"+e}function o(e){return d+"sessions/"+e}function i(e){return d+"rooms/"+e}function s(e,t){try{return JSON.parse(e.getItem(t))}catch(n){u("Failed to get key %s: %s",t,n),u(n.stack)}return null}function a(e,t,n){e.setItem(t,JSON.stringify(n))}function u(){l&&console.log.apply(console,arguments)}var c=e("../../utils"),l=!1,d="session.e2e.";n.prototype={storeEndToEndAccount:function(e){this.store.setItem(p,e)},getEndToEndAccount:function(){return this.store.getItem(p)},storeEndToEndDevicesForUser:function(e,t){a(this.store,r(e),t)},getEndToEndDevicesForUser:function(e){return s(this.store,r(e))},storeEndToEndSession:function(e,t,n){var r=this.getEndToEndSessions(e)||{};r[t]=n,a(this.store,o(e),r)},getEndToEndSessions:function(e){return s(this.store,o(e))},storeEndToEndRoom:function(e,t){a(this.store,i(e),t)},getEndToEndRoom:function(e){return s(this.store,i(e))}};var p=d+"account";t.exports=n},{"../../utils":24}],20:[function(e,t){"use strict";function n(){this.fromToken=null}n.prototype={getSyncToken:function(){return this.fromToken},setSyncToken:function(e){this.fromToken=e},storeRoom:function(){},getRoom:function(){return null},getRooms:function(){return[]},removeRoom:function(){},getRoomSummaries:function(){return[]},storeUser:function(){},getUser:function(){return null},getUsers:function(){return[]},scrollback:function(){return[]},storeEvents:function(){},storeFilter:function(){},getFilter:function(){return null},getFilterIdByName:function(){return null},setFilterIdByName:function(){}},t.exports=n},{}],21:[function(e,t){"use strict";function n(e,t){if(this.store=e,this.batchSize=t,!(h.isFunction(e.getItem)&&h.isFunction(e.setItem)&&h.isFunction(e.removeItem)&&h.isFunction(e.key)))throw new Error("Supplied webStore does not meet the WebStorage API interface");if(!parseInt(e.length)&&0!==e.length)throw new Error("Supplied webStore does not meet the WebStorage API interface (length)");this._roomIds=[],this._syncedWithStore=!1,this._tokens=[]}function r(e){this.state={events:{}},this.timeline={},this.roomId=e}function o(e,t,n,r){var o=new f(t,{storageToken:r.length}),i=c(e,u(t,"state")),l=[];h.forEach(h.keys(i.events),function(e){h.forEach(h.keys(i.events[e]),function(t){l.push(i.events[e][t])})});var d=h.map(h.deepCopy(l),function(e){return new v(e)}),p=h.map(l,function(e){return new v(e)});o.oldState.setStateEvents(d),o.currentState.setStateEvents(p);for(var m,g,y,_=[],S=a(s(e,t)),E=S;_.length=0;m--)if(_.unshift(new v(y[m])),_.length===n){E=S;break}S--}return o.addEventsToTimeline(_.reverse(),!0),o.oldState.paginationToken=i.pagination_token,r.push({earliestIndex:E}),o}function i(e,t){l(e,u(t.roomId,"state"),t.state),h.forEach(h.keys(t.timeline),function(n){l(e,u(t.roomId,"timeline",n),t.timeline[n])})}function s(e,t){for(var n=[],r=0;rn||t&&n>r)&&(n=r);return n}function u(e,t,n){return"room_"+e+"_"+t+(void 0===n?"":"_"+n)}function c(e,t){try{return JSON.parse(e.getItem(t))}catch(n){d("Failed to get key %s: %s",t,n),d(n.stack)}return null}function l(e,t,n){e.setItem(t,JSON.stringify(n))}function d(){p&&console.log.apply(console,arguments)}var p=!1,h=e("../utils"),f=e("../models/room"),m=e("../models/user"),v=e("../models/event").MatrixEvent;n.prototype.getSyncToken=function(){return this.store.getItem("sync_token")},n.prototype.setSyncToken=function(e){this.store.setItem("sync_token",e)},n.prototype.storeRoom=function(e){var t=r.fromRoom(e,this.batchSize);i(this.store,t),-1===this._roomIds.indexOf(e.roomId)&&this._roomIds.push(e.roomId)},n.prototype.getRoom=function(e){if(!c(this.store,u(e,"state")))return d("getRoom: No room with id %s found.",e),null;var t=s(this.store,e);return-1!==t.indexOf("live")&&(d("getRoom: Live events found. Syncing timeline for %s",e),this._syncTimeline(e,t)),o(this.store,e,this.batchSize,this._tokens)},n.prototype.getRooms=function(){var e,t=[];if(!this._syncedWithStore){for(this._roomIds=[],e=0;e=this._tokens.length)return[];var n,r=this._tokens[e.storageToken]||{},o=r.earliestIndex,i=e.timeline[0]?e.timeline[0].getId():null;d("scrollback in %s (timeline=%s msgs) i=%s, timeline[0].id=%s - req %s events",e.roomId,e.timeline.length,o,i,t);var s=c(this.store,u(e.roomId,"timeline",o));if(!s)return d("No batch with index %s found.",o),[];var a=[],l=!1;for(n=s.length-1;n>=0;n--){var p=new v(s[n]);if(p.getId()!==i){if(l&&(d("Add event at position %s in batch %s",n,o),a.push(s[n]),a.length===t))break}else l=!0,d("Found timeline[0] event at position %s in batch %s",n,o)}if(a.length===t)return d("Batch has enough events to satisfy request."),a;if(!l)return d("Failed to find event ID %s in batch %s",i,o),[];for(;a.length=0&&(d("Add event at position %s in batch %s",n,o),a.push(s[n]),a.length!==t);n--);}return d("Out of %s requested events, returning %s. New index=%s",t,a.length,o),e.addEventsToTimeline(h.map(a,function(e){return new v(e)}),!0),this._tokens[e.storageToken]={earliestIndex:o},a},n.prototype.storeEvents=function(e,t,n,o){if(o){var i,p,f,m=a(s(this.store,e.roomId),!0);for(i=0;i0;)i.push(n.shift());l(this.store,o,i);for(var d=[];n.length>0;)d.push(n.shift()),(d.length===this.batchSize||0===n.length)&&(r++,o=u(e,"timeline",r),l(this.store,o,d),d=[]);l(this.store,u(e,"timeline","live"),[])},n.prototype.storeFilter=function(){},n.prototype.getFilter=function(){return null},r.fromRoom=function(e,t){var n,o=new r(e.roomId);if(o.state.pagination_token=e.oldState.paginationToken,h.forEach(h.keys(e.currentState.events),function(t){h.forEach(h.keys(e.currentState.events[t]),function(n){o.state.events[t]||(o.state.events[t]={}),o.state.events[t][n]=e.currentState.events[t][n].event})}),t>0)for(n=0;n*t=0;d--){var p=a[d].getId();if(i.getTimelineForEvent(p)){o("Already have event "+p+" in limited sync - not resetting"),l=!1,a.splice(0,d);break}}l&&(i.currentState.paginationToken=e,r._deregisterStateListeners(i),i.resetLiveTimeline(t.timeline.prev_batch),r._registerStateListeners(i))}r._processRoomEvents(i,s,a),i.addEvents(u),i.addAccountData(c),i.recalculate(n.credentials.userId),t.isBrandNewRoom&&(n.store.storeRoom(i),n.emit("Room",i)),s.forEach(function(e){n.emit("event",e)}),a.forEach(function(e){n.emit("event",e)}),u.forEach(function(e){n.emit("event",e)}),c.forEach(function(e){n.emit("event",e)})}),u.forEach(function(e){var t=e.room,o=r._mapSyncEventsFormat(e.timeline,t);t.addEvents(o),o.forEach(function(e){n.emit("event",e)})})},i.prototype._startKeepAlives=function(){return null!==this._keepAliveTimer&&clearTimeout(this._keepAliveTimer),this._pokeKeepAlive(),this._connectionReturnedDefer||(this._connectionReturnedDefer=u.defer()),this._connectionReturnedDefer.promise},i.prototype._pokeKeepAlive=function(){function e(){clearTimeout(t._keepAliveTimer),t._connectionReturnedDefer&&(t._connectionReturnedDefer.resolve(),t._connectionReturnedDefer=null)}var t=this;this.client._http.requestWithPrefix(void 0,"GET","/_matrix/client/versions",void 0,void 0,"",15e3).done(function(){e()},function(n){t._keepAliveTimer=400==n.httpStatus?setTimeout(e,2e3):setTimeout(t._pokeKeepAlive.bind(t),5e3+Math.floor(5e3*Math.random()))})},i.prototype._getOrCreateFilter=function(e,t){var n=this.client,r=n.store.getFilterIdByName(e),i=u();return r&&(i=n.getFilter(n.credentials.userId,r,!0).then(function(e){var n=JSON.stringify(e.getDefinition()),i=JSON.stringify(t.getDefinition());return n==i?(o("Using existing filter ID %s: %s",r,n),u(r)):void o("Existing filter ID %s: %s; new filter: %s",r,n,i)})),i.then(function(r){return r?r:n.createFilter(t.getDefinition()).then(function(t){return o("Created new filter ID %s: %s",t.filterId,JSON.stringify(t.getDefinition())),n.store.setFilterIdByName(e,t.filterId),t.filterId})})},i.prototype._mapSyncResponseToRoomArray=function(e){var t=this.client,n=this;return d.keys(e).map(function(r){var o=e[r],i=t.store.getRoom(r),s=!1;return i||(i=n.createRoom(r),s=!0),o.room=i,o.isBrandNewRoom=s,o})},i.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)})},i.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,o=t.getUser(n.userId);r=o?u({avatar_url:o.avatarUrl,displayname:o.displayName}):t.getProfileInfo(n.userId),r.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(){})}})}},i.prototype._processRoomEvents=function(e,t,n){n=n||[];var r=this.client,o=d.map(d.deepCopy(t.map(function(e){return e.event})),r.getEventMapper()),i=t;e.oldState.setStateEvents(o),e.currentState.setStateEvents(i),this._resolveInvites(e),e.recalculate(this.client.credentials.userId),e.addEventsToTimeline(n)},i.prototype._getGuestFilter=function(){var e=this.client._guestRooms;return e?JSON.stringify({room:{timeline:{limit:20}}}):"{}"},i.prototype._updateSyncState=function(e,t){var n=this._syncState;this._syncState=e,this.client.emit("sync",this._syncState,n,t)},i.prototype._onOnline=function(){o("Browser thinks we are back online"),this._startKeepAlives()},t.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./filter":4,"./models/event-timeline":8,"./models/room":13,"./models/user":15,"./utils":24,q:29}],23:[function(e,t){"use strict";function n(e,t,n){n=n||{},this._client=e,this._room=t,this._start=null,this._end=null,this._eventCount=0,this._windowLimit=n.windowLimit||1e3}function r(e,t){this.timeline=e,this.index=t}var o=e("q"),i=e("./models/event-timeline"),s=!1,a=s?console.log.bind(console):function(){};n.prototype.load=function(e,t){var n=this;t=t||20;var i=function(e,o){var i=Math.min(e.getEvents().length,o+Math.ceil(t/2)),s=Math.max(0,i-t);n._start=new r(e,s-e.getBaseIndex()),n._end=new r(e,i-e.getBaseIndex()),n._eventCount=i-s};if(e)return this._client.getEventTimeline(this._room,e).then(function(t){for(var n=0;nt.minIndex())return!0}else if(t.index0&&this._unpaginate(u,e!=i.BACKWARDS),o(!0)}if(!n)return o(!1);var c=r.timeline.getPaginationToken(e);if(!c)return a("TimelineWindow: no token"),o(!1);a("TimelineWindow: starting request");var l=this,d=this._client.paginateEventTimeline(r.timeline,{backwards:e==i.BACKWARDS,limit:t})["finally"](function(){r.pendingPaginate=null}).then(function(n){return a("TimelineWindow: request completed with result "+n),n?l.paginate(e,t,!1):!1});return r.pendingPaginate=d,d},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,o=n.length;t===this._start.timeline&&(r=this._start.index+t.getBaseIndex()),t===this._end.timeline&&(o=this._end.index+t.getBaseIndex());for(var s=r;o>s;s++)e.push(n[s]);if(t===this._end.timeline)break;t=t.getNeighbouringTimeline(i.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;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?i.BACKWARDS:i.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":8,q:29}],24:[function(e,t){"use strict";t.exports.encodeParams=function(e){var t="";for(var n in e)e.hasOwnProperty(n)&&(t+="&"+encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t.substring(1)},t.exports.encodeUri=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e=e.replace(n,encodeURIComponent(t[n])));return e},t.exports.map=function(e,t){for(var n=new Array(e.length),r=0;r=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 o=e[r],e.splice(r,1), +o}else for(r=0;r>>0;if("function"!=typeof e)throw new TypeError;for(var r=[],o=arguments.length>=2?arguments[1]:void 0,i=0;n>i;i++)if(i in t){var s=t[i];e.call(o,s,i,t)&&r.push(s)}return r}),Array.prototype.map||(Array.prototype.map=function(e,t){var n,r,o;if(null===this||void 0===this)throw new TypeError(" this is null or not defined");var i=Object(this),s=i.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(arguments.length>1&&(n=t),r=new Array(s),o=0;s>o;){var a,u;o in i&&(a=i[o],u=e.call(n,a,o,i),r[o]=u),o++}return r}),Array.prototype.forEach||(Array.prototype.forEach=function(e,t){var n,r;if(null===this||void 0===this)throw new TypeError(" this is null or not defined");var o=Object(this),i=o.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(arguments.length>1&&(n=t),r=0;i>r;){var s;r in o&&(s=o[r],e.call(n,s,r,o)),r++}})},t.exports.inherits=function(e,t){"function"!=typeof Object.create&&(Object.create=function(){function e(){}var t=Object.prototype.hasOwnProperty;return function(n){if("object"!=typeof n)throw new TypeError("Object prototype may only be an Object or null");e.prototype=n;var r=new e;if(e.prototype=null,arguments.length>1){var o=Object(arguments[1]);for(var i in o)t.call(o,i)&&(r[i]=o[i])}return r}}()),e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}},{}],25:[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]}),o.forEach(this.turnServers,function(e){o.checkObjectHasKeys(e,["urls"])}),this.callId="c"+(new Date).getTime(),this.state="fledgling",this.didConnect=!1,this.candidateSendQueue=[],this.candidateSendTries=0,this.screenSharingStream=null}var o=e("../utils"),i=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",o.inherits(r,i),r.prototype.placeVoiceCall=function(){y("placeVoiceCall"),v(this),S(this,R("voice")),this.type="voice"},r.prototype.placeVideoCall=function(e,t){y("placeVideoCall"),v(this),this.localVideoElement=t,this.remoteVideoElement=e,S(this,R("video")),this.type="video",f(this)},r.prototype.placeScreenSharingCall=function(e,t){y("placeScreenSharingCall"),v(this);var n=T(this);if(n){this.localVideoElement=t,this.remoteVideoElement=e;var o=this;this.webRtc.getUserMedia(n,function(e){o.screenSharingStream=e,y("Got screen stream, requesting audio stream...");var t=R("voice");S(o,t)},function(e){o.emit("error",g(r.ERR_NO_USER_MEDIA,"Failed to get screen-sharing stream: "+e))}),this.type="video",f(this)}},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){if(this.localVideoElement=e,e&&this.localAVStream&&"video"===this.type){e.autoplay=!0,e.src=this.URL.createObjectURL(this.localAVStream),e.muted=!0;var t=this;setTimeout(function(){var e=t.getLocalVideoElement();e.play&&e.play()},0)}},r.prototype.setRemoteVideoElement=function(e){this.remoteVideoElement=e,f(this)},r.prototype.setRemoteAudioElement=function(e){this.remoteAudioElement=e,m(this)},r.prototype._initWithInvite=function(e){this.msg=e.getContent(),this.peerConn=E(this);var t=this;this.peerConn&&this.peerConn.setRemoteDescription(new this.webRtc.RtcSessionDescription(this.msg.offer),w(t,t._onSetRemoteDescriptionSuccess),w(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&&(y("Call invite has expired. Hanging up."),t.hangupParty="remote",c(t,"ended"),h(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(){y("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(R(this.type),w(e,e._gotUserMediaForAnswer),w(e,e._getUserMediaFailed)),c(this,"wait_local_media"))},r.prototype._replacedBy=function(e){y(this.callId+" being replaced by "+e.callId),"wait_local_media"==this.state?(y("Telling new call to wait for local media"),e.waitForLocalAVStream=!0):"create_offer"==this.state?(y("Handing local stream to new call"),e._gotUserMediaForAnswer(this.localAVStream),delete this.localAVStream):"invite_sent"==this.state&&(y("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){y("Ending call "+this.callId),p(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){y("_gotUserMediaForInvite -> "+this.type);var t=this,n=this.getLocalVideoElement();n&&"video"==this.type&&(n.autoplay=!0,this.screenSharingStream?(y("Setting screen sharing stream to the local video element"),n.src=this.URL.createObjectURL(this.screenSharingStream)):n.src=this.URL.createObjectURL(e),n.muted=!0,setTimeout(function(){var e=t.getLocalVideoElement();e.play&&e.play()},0)),this.localAVStream=e,a(e.getAudioTracks(),!0),this.peerConn=E(this),this.peerConn.addStream(e),this.screenSharingStream&&(console.log("Adding screen-sharing stream to peer connection"),this.peerConn.addStream(this.screenSharingStream),this.localAVStream=this.screenSharingStream),this.peerConn.createOffer(w(t,t._gotLocalOffer),w(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,n.src=t.URL.createObjectURL(e),n.muted=!0,setTimeout(function(){var e=t.getLocalVideoElement();e.play&&e.play()},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){y("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(){y("Error setting local description!")},r)},function(e){y("Failed to create answer: "+e)}),c(t,"create_answer")}},r.prototype._gotLocalIceCandidate=function(e){if(e.candidate){y("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&&(y("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),w(t,t._onSetRemoteDescriptionSuccess),w(t,t._onSetRemoteDescriptionError)),c(t,"connecting")}},r.prototype._gotLocalOffer=function(e){var t=this;return y("Created offer: "+e),"ended"==t.state?void y("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(){y("Error setting local description!")})},r.prototype._getLocalOfferFailed=function(){this.emit("error",g(r.ERR_LOCAL_OFFER_FAILED,"Failed to start audio for call!"))},r.prototype._getUserMediaFailed=function(){this.emit("error",g(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&&(y("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(){y("call "+this.callId+": Signalling state changed to: "+this.peerConn.signalingState)},r.prototype._onSetRemoteDescriptionSuccess=function(){y("Set remote description")},r.prototype._onSetRemoteDescriptionError=function(e){y("Failed to set remote description"+e)},r.prototype._onAddStream=function(e){y("Stream id "+e.stream.id+" added");var t=e.stream;t.getVideoTracks().length>0?(this.type="video",this.remoteAVStream=t):(this.type="voice",this.remoteAStream=t);var n=this;k(t,function(e){y("Track id "+e.id+" added"),e.onstarted=w(n,n._onRemoteStreamTrackStarted)}),e.stream.onended=w(n,n._onRemoteStreamEnded),e.stream.onstarted=w(n,n._onRemoteStreamStarted),"video"===this.type?f(this):m(this)},r.prototype._onRemoteStreamStarted=function(){c(this,"connected")},r.prototype._onRemoteStreamEnded=function(){y("Remote stream ended"),this.hangupParty="remote",c(this,"ended"),h(this),"closed"!=this.peerConn.signalingState&&this.peerConn.close(),this.emit("hangup",this)},r.prototype._onRemoteStreamTrackStarted=function(){c(this,"connected")},r.prototype._onHangupReceived=function(e){y("Hangup received"),p(this,"remote",e.reason,!0)},r.prototype._onAnsweredElsewhere=function(){y("Answered elsewhere"),p(this,"remote","answered_elsewhere",!0)};var a=function(e,t){for(var n=0;n5)return y("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,y("Failed to send candidates. Retrying in "+r+"ms"),setTimeout(function(){_(e)},r)})}},S=function(e,t){e.client.callList[e.callId]=e,e.webRtc.getUserMedia(t,w(e,e._gotUserMediaForInvite),w(e,e._getUserMediaFailed)),c(e,"wait_local_media"),e.direction="outbound",e.config=t},E=function(e){var t=e.turnServers;if("mozilla"===e.webRtc.vendor){t=[];for(var n=0;n-1)return!0;return!1};var a=o.navigator.getUserMedia||o.navigator.webkitGetUserMedia||o.navigator.mozGetUserMedia;if(a&&(s.getUserMedia=function(){return a.apply(o.navigator,arguments)}),s.RtcPeerConnection=o.RTCPeerConnection||o.webkitRTCPeerConnection||o.mozRTCPeerConnection,s.RtcSessionDescription=o.RTCSessionDescription||o.webkitRTCSessionDescription||o.mozRTCSessionDescription,s.RtcIceCandidate=o.RTCIceCandidate||o.webkitRTCIceCandidate||o.mozRTCIceCandidate,s.vendor=null,o.mozRTCPeerConnection?s.vendor="mozilla":o.webkitRTCPeerConnection?s.vendor="webkit":o.RTCPeerConnection&&(s.vendor="generic"),!(s.RtcIceCandidate&&s.RtcSessionDescription&&s.RtcPeerConnection&&s.getUserMedia))return null;var u={webRtc:s,client:e,URL:o.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":24,events:27}],26:[function(e,t,n){!function(e,r){"function"==typeof define&&define.amd?define([],r):"object"==typeof n?t.exports=r():e.returnExports=r()}(this,function(){function e(o,i){if("function"!=typeof i)throw new Error("Bad callback given: "+i);if(!o)throw new Error("No options given");var a=o.onResponse;if(o="string"==typeof o?{uri:o}:JSON.parse(JSON.stringify(o)),o.onResponse=a,o.verbose&&(e.log=r()),o.url&&(o.uri=o.url,delete o.url),!o.uri&&""!==o.uri)throw new Error("options.uri is a required argument");if("string"!=typeof o.uri)throw new Error("options.uri must be a string");for(var u=["proxy","_redirectsFollowed","maxRedirects","followRedirect"],c=0;c>18&63,i=u>>12&63,s=u>>6&63,a=63&u,h[d++]=c.charAt(o)+c.charAt(i)+c.charAt(s)+c.charAt(a);while(l299)&&n.error){e=new Error("CouchDB error: "+(n.error.reason||n.error.error));for(var o in n)e[o]=n[o];return r(e,t,n)}return r(e,t,n)}"string"==typeof t&&(t={uri:t}),t.json=!0,t.body&&(t.json=t.body),delete t.body,r=r||n;var i=e(t,o);return i},e})},{}],27:[function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(e){return"function"==typeof e}function o(e){return"number"==typeof e}function i(e){return"object"==typeof e&&null!==e}function s(e){return void 0===e}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!o(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,o,a,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[e],s(n))return!1;if(r(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:for(o=arguments.length,a=new Array(o-1),u=1;o>u;u++)a[u-1]=arguments[u];n.apply(this,a)}else if(i(n)){for(o=arguments.length,a=new Array(o-1),u=1;o>u;u++)a[u-1]=arguments[u];for(c=n.slice(),o=c.length,u=0;o>u;u++)c[u].apply(this,a)}return!0},n.prototype.addListener=function(e,t){var o;if(!r(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,r(t.listener)?t.listener:t),this._events[e]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned){var o;o=s(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,o&&o>0&&this._events[e].length>o&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),o||(o=!0,t.apply(this,arguments))}if(!r(t))throw TypeError("listener must be a function");var o=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,o,s,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,o=-1,n===t||r(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(n)){for(a=s;a-->0;)if(n[a]===t||n[a].listener&&n[a].listener===t){o=a;break}if(0>o)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],r(n))this.removeListener(e,n);else for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?r(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.listenerCount=function(e,t){var n;return n=e._events&&e._events[t]?r(e._events[t])?1:e._events[t].length:0}},{}],28:[function(e,t){function n(){c=!1,s.length?u=s.concat(u):l=-1,u.length&&r()}function r(){if(!c){var e=setTimeout(n);c=!0;for(var t=u.length;t;){for(s=u,u=[];++l1)for(var n=1;n=G&&ce>=r}function c(){if(B)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 K=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 m?e:_(e)?x(e):k(e)}function p(){function e(e){t=e,i.source=e,z(n,function(t,n){d.nextTick(function(){e.promiseDispatch.apply(e,n)})},void 0),n=void 0,r=void 0}var t,n=[],r=[],o=ee(p.prototype),i=ee(m.prototype);if(i.promiseDispatch=function(e,o,i){var s=X(arguments);n?(n.push(s),"when"===o&&i[1]&&r.push(i[1])):d.nextTick(function(){t.promiseDispatch.apply(t,s)})},i.valueOf=function(){if(n)return i;var e=g(t);return y(e)&&(t=e),e},i.inspect=function(){return t?t.inspect():{state:"pending"}},d.longStackSupport&&B)try{throw new Error}catch(s){i.stack=s.stack.substring(s.stack.indexOf("\n")+1)}return o.promise=i,o.resolve=function(n){t||e(d(n))},o.fulfill=function(n){t||e(k(n))},o.reject=function(n){t||e(b(n))},o.notify=function(e){t||z(r,function(t,n){d.nextTick(function(){n(e)})},void 0)},o}function h(e){if("function"!=typeof e)throw new TypeError("resolver must be a function.");var t=p();try{e(t.resolve,t.reject,t.notify)}catch(n){t.reject(n)}return t.promise}function f(e){return h(function(t,n){for(var r=0,o=e.length;o>r;r++)d(e[r]).then(t,n)})}function m(e,t,n){void 0===t&&(t=function(e){return b(new Error("Promise does not support operation: "+e))}),void 0===n&&(n=function(){return{state:"unknown"}});var r=ee(m.prototype);if(r.promiseDispatch=function(n,o,i){var s;try{s=e[o]?e[o].apply(r,i):t.call(r,o,i)}catch(a){s=b(a)}n&&n(s)},r.inspect=n,n){var o=n();"rejected"===o.state&&(r.exception=o.reason),r.valueOf=function(){var e=n();return"pending"===e.state||"rejected"===e.state?r:e.value}}return r}function v(e,t,n,r){return d(e).then(t,n,r)}function g(e){if(y(e)){var t=e.inspect();if("fulfilled"===t.state)return t.value}return e}function y(e){return e instanceof m}function _(e){return n(e)&&"function"==typeof e.then}function S(e){return y(e)&&"pending"===e.inspect().state}function E(e){return!y(e)||"fulfilled"===e.inspect().state}function T(e){return y(e)&&"rejected"===e.inspect().state}function R(){ie.length=0,se.length=0,ue||(ue=!0)}function w(t,n){ue&&("object"==typeof e&&"function"==typeof e.emit&&d.nextTick.runAfter(function(){-1!==Y(se,t)&&(e.emit("unhandledRejection",n,t),ae.push(t))}),se.push(t),ie.push(n&&"undefined"!=typeof n.stack?n.stack:"(no stack) "+n))}function I(t){if(ue){var n=Y(se,t);-1!==n&&("object"==typeof e&&"function"==typeof e.emit&&d.nextTick.runAfter(function(){ +var r=Y(ae,t);-1!==r&&(e.emit("rejectionHandled",ie[n],t),ae.splice(r,1))}),se.splice(n,1),ie.splice(n,1))}}function b(e){var t=m({when:function(t){return t&&I(this),t?t(e):this}},function(){return this},function(){return{state:"rejected",reason:e}});return w(t,e),t}function k(e){return m({when:function(){return e},get:function(t){return e[t]},set:function(t,n){e[t]=n},"delete":function(t){delete e[t]},post:function(t,n){return null===t||void 0===t?e.apply(void 0,n):e[t].apply(e,n)},apply:function(t,n){return e.apply(t,n)},keys:function(){return ne(e)}},void 0,function(){return{state:"fulfilled",value:e}})}function x(e){var t=p();return d.nextTick(function(){try{e.then(t.resolve,t.reject,t.notify)}catch(n){t.reject(n)}}),t.promise}function A(e){return m({isDef:function(){}},function(t,n){return P(e,t,n)},function(){return d(e).inspect()})}function C(e,t,n){return d(e).spread(t,n)}function U(e){return function(){function t(e,t){var s;if("undefined"==typeof StopIteration){try{s=n[e](t)}catch(a){return b(a)}return s.done?d(s.value):v(s.value,o,i)}try{s=n[e](t)}catch(a){return r(a)?d(a.value):b(a)}return v(s,o,i)}var n=e.apply(this,arguments),o=t.bind(t,"next"),i=t.bind(t,"throw");return o()}}function M(e){d.done(d.async(e)())}function O(e){throw new W(e)}function L(e){return function(){return C([this,D(arguments)],function(t,n){return e.apply(t,n)})}}function P(e,t,n){return d(e).dispatch(t,n)}function D(e){return v(e,function(e){var t=0,n=p();return z(e,function(r,o,i){var s;y(o)&&"fulfilled"===(s=o.inspect()).state?e[i]=s.value:(++t,v(o,function(r){e[i]=r,0===--t&&n.resolve(e)},n.reject,function(e){n.notify({index:i,value:e})}))},void 0),0===t&&n.resolve(e),n.promise})}function q(e){if(0===e.length)return d.resolve();var t=d.defer(),n=0;return z(e,function(r,o,i){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:i,value:e})}var c=e[i];n++,v(c,s,a,u)},void 0),t.promise}function F(e){return v(e,function(e){return e=Z(e,d),v(D(Z(e,function(e){return v(e,H,H)})),function(){return e})})}function N(e){return d(e).allSettled()}function j(e,t){return d(e).then(void 0,void 0,t)}function $(e,t){return d(e).nodeify(t)}var B=!1;try{throw new Error}catch(V){B=!!V.stack}var K,W,G=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);i=!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},o=r,i=!1,s=void 0,a=!1,u=[];if(J=function(t){o=o.next={task:t,domain:a&&e.domain,next:null},i||(i=!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),i||(i=!0,s())},J}(),Q=Function.call,X=t(Array.prototype.slice),z=t(Array.prototype.reduce||function(e,t){var n=0,r=this.length;if(1===arguments.length)for(;;){if(n in this){t=this[n++];break}if(++n>=r)throw new TypeError}for(;r>n;n++)n in this&&(t=e(t,this[n],n));return t}),Y=t(Array.prototype.indexOf||function(e){for(var t=0;t2?X(arguments,1):n)}},d.Promise=h,d.promise=h,h.race=f,h.all=D,h.reject=b,h.resolve=d,d.passByCopy=function(e){return e},m.prototype.passByCopy=function(){return this},d.join=function(e,t){return d(e).join(t)},m.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,m.prototype.race=function(){return this.then(d.race)},d.makePromise=m,m.prototype.toString=function(){return"[object Promise]"},m.prototype.then=function(e,t,n){function r(t){try{return"function"==typeof e?e(t):t}catch(n){return b(n)}}function i(e){if("function"==typeof t){o(e,a);try{return t(e)}catch(n){return b(n)}}return b(e)}function s(e){return"function"==typeof n?n(e):e}var a=this,u=p(),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(i(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)},m.prototype.tap=function(e){return e=d(e),this.then(function(t){return e.fcall(t).thenResolve(t)})},d.when=v,m.prototype.thenResolve=function(e){return this.then(function(){return e})},d.thenResolve=function(e,t){return d(e).thenResolve(t)},m.prototype.thenReject=function(e){return this.then(function(){throw e})},d.thenReject=function(e,t){return d(e).thenReject(t)},d.nearer=g,d.isPromise=y,d.isPromiseAlike=_,d.isPending=S,m.prototype.isPending=function(){return"pending"===this.inspect().state},d.isFulfilled=E,m.prototype.isFulfilled=function(){return"fulfilled"===this.inspect().state},d.isRejected=T,m.prototype.isRejected=function(){return"rejected"===this.inspect().state};var ie=[],se=[],ae=[],ue=!0;d.resetUnhandledRejections=R,d.getUnhandledReasons=function(){return ie.slice()},d.stopUnhandledRejectionTracking=function(){R(),ue=!1},R(),d.reject=b,d.fulfill=k,d.master=A,d.spread=C,m.prototype.spread=function(e,t){return this.all().then(function(t){return e.apply(void 0,t)},t)},d.async=U,d.spawn=M,d["return"]=O,d.promised=L,d.dispatch=P,m.prototype.dispatch=function(e,t){var n=this,r=p();return d.nextTick(function(){n.promiseDispatch(r.resolve,e,t)}),r.promise},d.get=function(e,t){return d(e).dispatch("get",[t])},m.prototype.get=function(e){return this.dispatch("get",[e])},d.set=function(e,t,n){return d(e).dispatch("set",[t,n])},m.prototype.set=function(e,t){return this.dispatch("set",[e,t])},d.del=d["delete"]=function(e,t){return d(e).dispatch("delete",[t])},m.prototype.del=m.prototype["delete"]=function(e){return this.dispatch("delete",[e])},d.mapply=d.post=function(e,t,n){return d(e).dispatch("post",[t,n])},m.prototype.mapply=m.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)])},m.prototype.send=m.prototype.mcall=m.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])},m.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)])},m.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))])}},m.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",[])},m.prototype.keys=function(){return this.dispatch("keys",[])},d.all=D,m.prototype.all=function(){return D(this)},d.any=q,m.prototype.any=function(){return q(this)},d.allResolved=l(F,"allResolved","allSettled"),m.prototype.allResolved=function(){return F(this)},d.allSettled=N,m.prototype.allSettled=function(){return this.then(function(e){return D(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)},m.prototype.fail=m.prototype["catch"]=function(e){return this.then(void 0,e)},d.progress=j,m.prototype.progress=function(e){return this.then(void 0,void 0,e)},d.fin=d["finally"]=function(e,t){return d(e)["finally"](t)},m.prototype.fin=m.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)},m.prototype.done=function(t,n,r){var i=function(e){d.nextTick(function(){if(o(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&&(i=e.domain.bind(i)),s.then(void 0,i)},d.timeout=function(e,t,n){return d(e).timeout(t,n)},m.prototype.timeout=function(e,t){var n=p(),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)},m.prototype.delay=function(e){return this.then(function(t){var n=p();return setTimeout(function(){n.resolve(t)},e),n.promise})},d.nfapply=function(e,t){return d(e).nfapply(t)},m.prototype.nfapply=function(e){var t=p(),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)},m.prototype.nfcall=function(){var e=X(arguments),t=p();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=p();return n.push(r.makeNodeResolver()),d(e).fapply(n).fail(r.reject),r.promise}},m.prototype.nfbind=m.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 o=n.concat(X(arguments)),i=p();return o.push(i.makeNodeResolver()),d(r).fapply(o).fail(i.reject),i.promise}},m.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)},m.prototype.nmapply=m.prototype.npost=function(e,t){var n=X(t||[]),r=p();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=p();return n.push(r.makeNodeResolver()),d(e).dispatch("post",[t,n]).fail(r.reject),r.promise},m.prototype.nsend=m.prototype.nmcall=m.prototype.ninvoke=function(e){var t=X(arguments,1),n=p();return t.push(n.makeNodeResolver()),this.dispatch("post",[e,t]).fail(n.reject),n.promise},d.nodeify=$,m.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:28}]},{},[1]); \ No newline at end of file diff --git a/remote/style.css b/remote/style.css new file mode 100644 index 0000000..55770ab --- /dev/null +++ b/remote/style.css @@ -0,0 +1,14 @@ +.sp-container { + height: 90%; + width: 100%; +} + +.sp-picker-container { + width: 600px; +} + +.sp-button-container { + display: none; +} + +