/* twilio-chat.js 3.2.3
The following license applies to all parts of this software except as
documented below.
Copyright (c) 2018, Twilio, inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. Neither the name of Twilio nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software includes javascript-state-machine under the following license.
Copyright (c) 2012, 2013, 2014, 2015, Jake Gordon and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
This software includes loglevel under the following license.
Copyright (c) 2013 Tim Perry
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
This software includes q under the following license.
Copyright 2009–2014 Kristopher Michael Kowal. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
This software includes platform.js under the following license.
Copyright 2014 Benjamin Tan
Copyright 2011-2015 John-David Dalton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;((t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Twilio||(t.Twilio={})).Chat=e()}}(function(){return function(){return function e(t,r,n){function i(a,o){if(!r[a]){if(!t[a]){var u="function"==typeof require&&require;if(!o&&u)return u(a,!0);if(s)return s(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var l=r[a]={exports:{}};t[a][0].call(l.exports,function(e){return i(t[a][1][e]||e)},l,l.exports,e,t,r,n)}return r[a].exports}for(var s="function"==typeof require&&require,a=0;a0&&this.emit("updated",{channel:this,updateReasons:r})}},{key:"_onMessageAdded",value:function(e){var t=!0,r=!1,i=void 0;try{for(var s,a=(0,n.default)(this.members.values());!(t=(s=a.next()).done);t=!0){var o=s.value;if(o.identity===e.author){o._endTyping();break}}}catch(e){r=!0,i=e}finally{try{!t&&a.return&&a.return()}finally{if(r)throw i}}this.emit("messageAdded",e)}},{key:"add",value:function(e){return b(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e&&"string"==typeof e){t.next=2;break}throw new Error("Channel.add requires an identity parameter");case 2:return t.abrupt("return",this.membersEntity.add(e));case 3:case"end":return t.stop()}},t,this)}))}},{key:"advanceLastConsumedMessageIndex",value:function(e){return b(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if((0,o.default)(e)){t.next=2;break}throw new Error("Channel.advanceLastConsumedMessageIndex requires an integral index parameter");case 2:return t.next=4,this._subscribeStreams();case 4:return t.abrupt("return",this.services.consumptionHorizon.advanceLastConsumedMessageIndexForChannel(this.sid,e,this.lastConsumedMessageIndex));case 5:case"end":return t.stop()}},t,this)}))}},{key:"decline",value:function(){return b(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("declineInvitation",{channelSid:this.sid});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}},e,this)}))}},{key:"delete",value:function(){return b(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("destroyChannel",{channelSid:this.sid});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}},e,this)}))}},{key:"getAttributes",value:function(){return b(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribe();case 2:return e.abrupt("return",this.attributes);case 3:case"end":return e.stop()}},e,this)}))}},{key:"getMessages",value:function(e,t,r){return b(this,void 0,void 0,i.default.mark(function n(){return i.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(void 0===t||(0,o.default)(t)){n.next=2;break}throw new Error("Anchor should be a valid message index");case 2:return n.next=4,this._subscribeStreams();case 4:return n.abrupt("return",this.messagesEntity.getMessages(e,t,r));case 5:case"end":return n.stop()}},n,this)}))}},{key:"getMembers",value:function(){return b(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.membersEntity.getMembers());case 3:case"end":return e.stop()}},e,this)}))}},{key:"getMembersCount",value:function(){return b(this,void 0,void 0,i.default.mark(function e(){var t,r,n;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.getSessionLinks();case 2:return t=e.sent,r=new k.UriBuilder(t.publicChannelsUrl).path(this.sid).build(),e.next=6,this.services.network.get(r);case 6:return n=e.sent,e.abrupt("return",n.body.members_count);case 8:case"end":return e.stop()}},e,this)}))}},{key:"getMessagesCount",value:function(){return b(this,void 0,void 0,i.default.mark(function e(){var t,r,n;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.getSessionLinks();case 2:return t=e.sent,r=new k.UriBuilder(t.publicChannelsUrl).path(this.sid).build(),e.next=6,this.services.network.get(r);case 6:return n=e.sent,e.abrupt("return",n.body.messages_count);case 8:case"end":return e.stop()}},e,this)}))}},{key:"getUnconsumedMessagesCount",value:function(){return b(this,void 0,void 0,i.default.mark(function e(){var t,r,n;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.getSessionLinks();case 2:return t=e.sent,r=new k.UriBuilder(t.myChannelsUrl).arg("ChannelSid",this.sid).build(),e.next=6,this.services.network.get(r);case 6:if(!(n=e.sent).body.channels.length||n.body.channels[0].channel_sid!=this.sid){e.next=11;break}if(void 0===n.body.channels[0].unread_messages_count||null==n.body.channels[0].unread_messages_count){e.next=10;break}return e.abrupt("return",n.body.channels[0].unread_messages_count);case 10:return e.abrupt("return",null);case 11:throw new Error("Channel is not in user channels list");case 12:case"end":return e.stop()}},e,this)}))}},{key:"invite",value:function(e){return b(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if("string"==typeof e&&e.length){t.next=2;break}throw new Error("Channel.invite requires an identity parameter");case 2:return t.abrupt("return",this.membersEntity.invite(e));case 3:case"end":return t.stop()}},t,this)}))}},{key:"join",value:function(){return b(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("joinChannelV2",{channelSid:this.sid});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}},e,this)}))}},{key:"leave",value:function(){return b(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("joined"!==this.state.status){e.next=3;break}return e.next=3,this.services.session.addCommand("leaveChannel",{channelSid:this.sid});case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}},e,this)}))}},{key:"removeMember",value:function(e){return b(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e&&("string"==typeof e||e instanceof g.Member)){t.next=2;break}throw new Error("Channel.removeMember requires a member parameter.");case 2:return t.abrupt("return",this.membersEntity.remove("string"==typeof e?e:e.identity));case 3:case"end":return t.stop()}},t,this)}))}},{key:"sendMessage",value:function(e,t){return b(this,void 0,void 0,i.default.mark(function r(){var n,s;return i.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==e){r.next=2;break}throw new Error("Message is required parameter");case 2:if("string"!=typeof e&&null!==e){r.next=9;break}return r.next=5,this.messagesEntity.send(e,t);case 5:return n=r.sent,r.abrupt("return",k.parseToNumber(n.messageId));case 9:return r.next=11,this.messagesEntity.sendMedia(e,t);case 11:return s=r.sent,r.abrupt("return",k.parseToNumber(s.messageId));case 13:case"end":return r.stop()}},r,this)}))}},{key:"setAllMessagesConsumed",value:function(){return b(this,void 0,void 0,i.default.mark(function e(){var t;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.next=4,this.getMessages(1);case 4:if(!((t=e.sent).items.length>0)){e.next=7;break}return e.abrupt("return",this.advanceLastConsumedMessageIndex(t.items[0].index));case 7:return e.abrupt("return",p.default.resolve(0));case 8:case"end":return e.stop()}},e,this)}))}},{key:"setNoMessagesConsumed",value:function(){return b(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.services.consumptionHorizon.updateLastConsumedMessageIndexForChannel(this.sid,null));case 3:case"end":return e.stop()}},e,this)}))}},{key:"setUserNotificationLevel",value:function(e){return b(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e){t.next=2;break}throw new Error("notificationLevel can't be null");case 2:return t.next=4,this.services.session.addCommand("editNotificationLevel",{channelSid:this.sid,notificationLevel:e});case 4:case"end":return t.stop()}},t,this)}))}},{key:"typing",value:function(){return this.services.typingIndicator.send(this.sid)}},{key:"updateAttributes",value:function(e){return b(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0!==e){t.next=4;break}throw new Error("Attributes is required parameter");case 4:if(null!==e){t.next=8;break}throw new Error("Attributes can't be null");case 8:if(e.constructor===Object){t.next=10;break}throw new Error("Attributes must be a valid JSON object.");case 10:return t.next=12,this.services.session.addCommand("editAttributes",{channelSid:this.sid,attributes:(0,a.default)(e)});case 12:return t.abrupt("return",this);case 13:case"end":return t.stop()}},t,this)}))}},{key:"updateFriendlyName",value:function(e){return b(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state.friendlyName===e){t.next=3;break}return t.next=3,this.services.session.addCommand("editFriendlyName",{channelSid:this.sid,friendlyName:e});case 3:return t.abrupt("return",this);case 4:case"end":return t.stop()}},t,this)}))}},{key:"updateLastConsumedMessageIndex",value:function(e){return b(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if((0,o.default)(e)||null===e){t.next=2;break}throw new Error('Incorrect argument "index": integer number or null expected');case 2:return t.next=4,this._subscribeStreams();case 4:return t.abrupt("return",this.services.consumptionHorizon.updateLastConsumedMessageIndexForChannel(this.sid,e));case 5:case"end":return t.stop()}},t,this)}))}},{key:"updateUniqueName",value:function(e){return b(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state.uniqueName===e){t.next=4;break}return e||(e=""),t.next=4,this.services.session.addCommand("editUniqueName",{channelSid:this.sid,uniqueName:e});case 4:return t.abrupt("return",this);case 5:case"end":return t.stop()}},t,this)}))}},{key:"getUserDescriptors",value:function(){return b(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.services.users.getChannelUserDescriptors(this.sid));case 1:case"end":return e.stop()}},e,this)}))}},{key:"status",get:function(){return this.state.status}},{key:"type",get:function(){return this.state.type}},{key:"uniqueName",get:function(){return this.state.uniqueName}},{key:"isPrivate",get:function(){return"private"===this.state.type}},{key:"friendlyName",get:function(){return this.state.friendlyName}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"createdBy",get:function(){return this.state.createdBy}},{key:"attributes",get:function(){return this.state.attributes}},{key:"lastConsumedMessageIndex",get:function(){return this.state.lastConsumedMessageIndex}},{key:"lastMessage",get:function(){return this.state.lastMessage}},{key:"notificationLevel",get:function(){return this.state.notificationLevel}}],[{key:"preprocessUpdate",value:function(e,t){try{"string"==typeof e.attributes?e.attributes=JSON.parse(e.attributes):e.attributes&&(0,a.default)(e.attributes)}catch(r){w.warn("Retrieved malformed attributes from the server for channel: "+t),e.attributes={}}try{e.dateCreated&&(e.dateCreated=new Date(e.dateCreated))}catch(r){w.warn("Retrieved malformed dateCreated from the server for channel: "+t),delete e.dateCreated}try{e.dateUpdated&&(e.dateUpdated=new Date(e.dateUpdated))}catch(r){w.warn("Retrieved malformed dateUpdated from the server for channel: "+t),delete e.dateUpdated}try{e.lastMessage&&e.lastMessage.timestamp&&(e.lastMessage.timestamp=new Date(e.lastMessage.timestamp))}catch(r){w.warn("Retrieved malformed lastMessage.timestamp from the server for channel: "+t),delete e.lastMessage.timestamp}}}]),t}(m.EventEmitter);r.Channel=S},{"./data/members":6,"./data/messages":7,"./logger":14,"./member":16,"./util":30,"babel-runtime/core-js/get-iterator":32,"babel-runtime/core-js/json/stringify":34,"babel-runtime/core-js/map":35,"babel-runtime/core-js/number/is-integer":36,"babel-runtime/core-js/object/get-prototype-of":41,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/helpers/inherits":53,"babel-runtime/helpers/possibleConstructorReturn":54,"babel-runtime/regenerator":58,events:202}],2:[function(e,t,r){"use strict";var n=s(e("babel-runtime/helpers/classCallCheck")),i=s(e("babel-runtime/helpers/createClass"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var a=e("./logger"),o=e("./channel"),u=a.Logger.scope("ChannelDescriptor");function c(e){try{return new Date(e)}catch(e){return null}}var l=function(){function e(t,r){(0,n.default)(this,e),this.client=t,this.descriptor=r,r.sid?(this.sid=r.sid,this.channel=r.sid+".channel"):(this.sid=r.channel_sid,this.channel=r.channel_sid+".channel"),this.uniqueName=r.unique_name,this.friendlyName=r.friendly_name,this.attributes=function(e){try{return JSON.parse(e)}catch(e){u.warn("Failed to parse channel attributes",e)}return{}}(r.attributes),this.createdBy=r.created_by,this.dateCreated=c(r.date_created),this.dateUpdated=c(r.date_updated),this.messagesCount=r.messages_count,this.membersCount=r.members_count,this.type=r.type,this.isPrivate="private"==r.type,this.lastConsumedMessageIndex=r.last_consumed_message_index,r.notification_level&&(this.notificationLevel=r.notification_level),r.status?this.status=o.filterStatus(r.status):this.status="unknown"}return(0,i.default)(e,[{key:"getChannel",value:function(){return this.client.getChannelBySid(this.sid)}}]),e}();r.ChannelDescriptor=l},{"./channel":1,"./logger":14,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51}],3:[function(e,t,r){"use strict";var n=f(e("babel-runtime/regenerator")),i=f(e("babel-runtime/core-js/object/assign")),s=f(e("babel-runtime/core-js/object/get-prototype-of")),a=f(e("babel-runtime/helpers/createClass")),o=f(e("babel-runtime/helpers/possibleConstructorReturn")),u=f(e("babel-runtime/helpers/inherits")),c=f(e("babel-runtime/helpers/classCallCheck")),l=f(e("babel-runtime/core-js/promise"));function f(e){return e&&e.__esModule?e:{default:e}}var d=function(e,t,r,n){return new(r||(r=l.default))(function(i,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function o(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(a,o)}u((n=n.apply(e,t||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0});var p=e("events"),h=e("./logger"),b=e("./configuration"),m=e("./user");r.User=m.User;var v=e("./data/publicchannels"),y=e("./services/network"),g=e("./interfaces/notificationtypes"),_=e("./synclist"),k=e("twilsock"),w=e("twilio-notifications"),x=e("twilio-sync"),C=e("twilio-mcs-client"),j=e("./session"),S=e("./data/channels"),T=e("./data/users"),E=e("./services/typingindicator"),M=e("./services/consumptionhorizon"),I=e("./data/userchannels"),P=e("./pushnotification");r.PushNotification=P.PushNotification;var R=e("./util"),O=h.Logger.scope("Client"),N=e("./../package.json").version,U="A valid Twilio token should be provided",A=function e(){(0,c.default)(this,e)},L=function(e){function t(e,r){(0,c.default)(this,t);var n=(0,o.default)(this,(t.__proto__||(0,s.default)(t)).call(this));n.connectionState="connecting",n.sessionPromise=null,n.channelsPromise=null,n.version=N,n.parsePushNotification=t.parsePushNotification,n.options=r||{},n.options.disableDeepClone||(n.options=R.deepClone(n.options)),n.options.logLevel=n.options.logLevel||"silent",O.setLevel(n.options.logLevel);var i=n.options.productId="ip_messaging";if(n.options.Sync=n.options.Sync||{},void 0===n.options.Sync.enableSessionStorage&&(n.options.Sync.enableSessionStorage=!0),n.options.region&&(n.options.Sync.region=n.options.region),!e)throw new Error(U);return n.services=new A,n.config=new b.Configuration(n.options),n.options.twilsockClient=n.options.twilsockClient||new k.Twilsock(e,i,n.options),n.options.transport=n.options.transport||n.options.twilsockClient,n.options.notificationsClient=n.options.notificationsClient||new w.Notifications(e,n.options),n.options.syncClient=n.options.syncClient||new x.SyncClient(e,n.options),n.services.syncClient=n.options.syncClient,n.services.transport=n.options.transport,n.services.twilsockClient=n.options.twilsockClient,n.services.notificationClient=n.options.notificationsClient,n.services.session=new j.Session(n.services,n.config),n.sessionPromise=n.services.session.initialize(),n.services.network=new y.Network(n.config,n.services),n.services.users=new T.Users({session:n.services.session,network:n.services.network,syncClient:n.services.syncClient}),n.services.users.on("userSubscribed",n.emit.bind(n,"userSubscribed")),n.services.users.on("userUpdated",function(e){return n.emit("userUpdated",e)}),n.services.users.on("userUnsubscribed",n.emit.bind(n,"userUnsubscribed")),n.services.twilsockClient.on("tokenAboutToExpire",function(e){return n.emit("tokenAboutToExpire",e)}),n.services.twilsockClient.on("tokenExpired",function(){return n.emit("tokenExpired")}),n.services.consumptionHorizon=new M.ConsumptionHorizon(n.services),n.services.typingIndicator=new E.TypingIndicator(n.config,{transport:n.services.twilsockClient,notificationClient:n.services.notificationClient},n.getChannelBySid.bind(n)),n.services.syncList=new _.SyncList(n.services),n.channels=new S.Channels(n.services),n.channelsPromise=n.sessionPromise.then(function(){return n.channels.on("channelAdded",n.emit.bind(n,"channelAdded")),n.channels.on("channelRemoved",n.emit.bind(n,"channelRemoved")),n.channels.on("channelInvited",n.emit.bind(n,"channelInvited")),n.channels.on("channelJoined",n.emit.bind(n,"channelJoined")),n.channels.on("channelLeft",n.emit.bind(n,"channelLeft")),n.channels.on("channelUpdated",function(e){return n.emit("channelUpdated",e)}),n.channels.on("memberJoined",n.emit.bind(n,"memberJoined")),n.channels.on("memberLeft",n.emit.bind(n,"memberLeft")),n.channels.on("memberUpdated",function(e){return n.emit("memberUpdated",e)}),n.channels.on("messageAdded",n.emit.bind(n,"messageAdded")),n.channels.on("messageUpdated",function(e){return n.emit("messageUpdated",e)}),n.channels.on("messageRemoved",n.emit.bind(n,"messageRemoved")),n.channels.on("typingStarted",n.emit.bind(n,"typingStarted")),n.channels.on("typingEnded",n.emit.bind(n,"typingEnded")),n.channels.fetchChannels()}).then(function(){return n.channels}),n.services.notificationClient.on("connectionStateChanged",function(e){var t=null;switch(e){case"connected":t="connected";break;case"denied":t="denied";break;case"disconnecting":t="disconnecting";break;case"disconnected":t="disconnected";break;default:t="connecting"}t!==n.connectionState&&(n.connectionState=t,n.emit("connectionStateChanged",n.connectionState))}),n.fpaToken=e,n}return(0,u.default)(t,e),(0,a.default)(t,[{key:"subscribeToPushNotifications",value:function(e){var t=this,r=[];return[g.NotificationTypes.NEW_MESSAGE,g.NotificationTypes.ADDED_TO_CHANNEL,g.NotificationTypes.INVITED_TO_CHANNEL,g.NotificationTypes.REMOVED_FROM_CHANNEL,g.NotificationTypes.TYPING_INDICATOR,g.NotificationTypes.CONSUMPTION_UPDATE].forEach(function(n){r.push(t.services.notificationClient.subscribe(n,e))}),l.default.all(r)}},{key:"unsubscribeFromPushNotifications",value:function(e){var t=this,r=[];return[g.NotificationTypes.NEW_MESSAGE,g.NotificationTypes.ADDED_TO_CHANNEL,g.NotificationTypes.INVITED_TO_CHANNEL,g.NotificationTypes.REMOVED_FROM_CHANNEL,g.NotificationTypes.TYPING_INDICATOR,g.NotificationTypes.CONSUMPTION_UPDATE].forEach(function(n){r.push(t.services.notificationClient.unsubscribe(n,e))}),l.default.all(r)}},{key:"initialize",value:function(){return d(this,void 0,void 0,n.default.mark(function e(){var r,s,a=this;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sessionPromise;case 2:return t.supportedPushChannels.forEach(function(e){return a.subscribeToPushNotifications(e)}),e.next=5,this.services.session.getSessionLinks();case 5:return r=e.sent,this.services.publicChannels=new v.PublicChannels(this,this.services,r.publicChannelsUrl),this.services.userChannels=new I.UserChannels(this,this.services,r.myChannelsUrl),(s=(0,i.default)(this.options)).transport=null,this.services.mcsClient=new C.McsClient(this.fpaToken,r.mediaServiceUrl,s),e.next=13,this.services.typingIndicator.initialize();case 13:case"end":return e.stop()}},e,this)}))}},{key:"shutdown",value:function(){return d(this,void 0,void 0,n.default.mark(function e(){return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.twilsockClient.disconnect();case 2:case"end":return e.stop()}},e,this)}))}},{key:"updateToken",value:function(e){return d(this,void 0,void 0,n.default.mark(function t(){var r=this;return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(O.info("updateToken"),e){t.next=3;break}throw new Error(U);case 3:if(this.fpaToken!==e){t.next=5;break}return t.abrupt("return",this);case 5:return t.next=7,this.services.twilsockClient.updateToken(e).then(function(){return r.fpaToken=e}).then(function(){return r.services.mcsClient.updateToken(e)}).then(function(){return r.sessionPromise});case 7:return t.abrupt("return",this);case 8:case"end":return t.stop()}},t,this)}))}},{key:"getChannelBySid",value:function(e){return d(this,void 0,void 0,n.default.mark(function t(){var r=this;return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e&&"string"==typeof e){t.next=2;break}throw new Error("Client.getChannelBySid requires a channelSid parameter");case 2:return t.abrupt("return",this.channels.syncListRead.promise.then(function(){return r.channels.getChannel(e).then(function(t){return t||r.services.publicChannels.getChannelBySid(e).then(function(e){return r.channels.pushChannel(e)})})}));case 3:case"end":return t.stop()}},t,this)}))}},{key:"getChannelByUniqueName",value:function(e){return d(this,void 0,void 0,n.default.mark(function t(){var r=this;return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e&&"string"==typeof e){t.next=2;break}throw new Error("Client.getChannelByUniqueName requires a uniqueName parameter");case 2:return t.abrupt("return",this.channels.syncListRead.promise.then(function(){return r.services.publicChannels.getChannelByUniqueName(e).then(function(e){return r.channels.pushChannel(e)})}));case 3:case"end":return t.stop()}},t,this)}))}},{key:"getSubscribedChannels",value:function(e){return this.channelsPromise.then(function(t){return t.getChannels(e)})}},{key:"getLocalChannels",value:function(e){return this.channelsPromise.then(function(r){var n=[];r.channels.forEach(function(e){n.push(e)});var i="ascending";if(e&&e.order)if("descending"===e.order)i="descending";else if("ascending"!==e.order)throw new Error("Sorting order should be `ascending` or `descending`");if(e&&e.criteria)if("lastMessage"===e.criteria)n.sort(function(e,r){return t.compareChannelsByLastMessage(e,r,i)});else if("uniqueName"===e.criteria)n.sort(function(e,r){return t.compareChannelsByStringProperty(e.uniqueName,r.uniqueName,i)});else{if("friendlyName"!==e.criteria)throw new Error("Sorting criteria should be one of `lastMessage`, `uniqueName` or `friendlyName`");n.sort(function(e,r){return t.compareChannelsByStringProperty(e.friendlyName,r.friendlyName,i)})}return n})}},{key:"getPublicChannelDescriptors",value:function(){return this.services.publicChannels.getChannels()}},{key:"getUserChannelDescriptors",value:function(){return this.services.userChannels.getChannels()}},{key:"createChannel",value:function(e){return e=e||{},this.channelsPromise.then(function(t){return t.addChannel(e)})}},{key:"setPushRegistrationId",value:function(e,r){return d(this,void 0,void 0,n.default.mark(function i(){var s=this;return n.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(-1!==t.supportedPushChannels.indexOf(e)){n.next=2;break}throw new Error("Invalid or unsupported channelType: "+e);case 2:return n.next=4,this.subscribeToPushNotifications(e).then(function(){return s.services.notificationClient.setPushRegistrationId(r,e)});case 4:case"end":return n.stop()}},i,this)}))}},{key:"unsetPushRegistrationId",value:function(e){return d(this,void 0,void 0,n.default.mark(function r(){return n.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(-1!==t.supportedPushChannels.indexOf(e)){r.next=2;break}throw new Error("Invalid or unsupported channelType: "+e);case 2:return r.next=4,this.unsubscribeFromPushNotifications(e);case 4:case"end":return r.stop()}},r,this)}))}},{key:"handlePushNotification",value:function(e){return d(this,void 0,void 0,n.default.mark(function r(){return n.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:O.debug("handlePushNotification, notificationPayload=",e),this.emit("pushNotification",t.parsePushNotification(e));case 2:case"end":return r.stop()}},r,this)}))}},{key:"getUser",value:function(e){return this.services.users.getUser(e)}},{key:"getUserDescriptor",value:function(e){return d(this,void 0,void 0,n.default.mark(function t(){return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.services.users.getUserDescriptor(e));case 1:case"end":return t.stop()}},t,this)}))}},{key:"getSubscribedUsers",value:function(){return d(this,void 0,void 0,n.default.mark(function e(){return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.services.users.getSubscribedUsers());case 1:case"end":return e.stop()}},e,this)}))}},{key:"user",get:function(){return this.services.users.myself}},{key:"reachabilityEnabled",get:function(){return this.services.session.reachabilityEnabled}},{key:"token",get:function(){return this.fpaToken}}],[{key:"create",value:function(e,r){return d(this,void 0,void 0,n.default.mark(function i(){var s;return n.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return s=new t(e,r),n.next=3,s.initialize();case 3:return n.abrupt("return",s);case 4:case"end":return n.stop()}},i,this)}))}},{key:"compareChannelsByLastMessage",value:function(e,t,r){if(e.lastMessage&&t.lastMessage){if(e.lastMessage.timestamp&&t.lastMessage.timestamp)return e.lastMessage.timestamp.getTime()0?e[0]:null})}},{key:"pushChannel",value:function(e){var t=e.sid,r={name:null,entityName:null,lastConsumedMessageIndex:e.lastConsumedMessageIndex,type:e.type,status:e.status,friendlyName:e.friendlyName,dateUpdated:e.dateUpdated,dateCreated:e.dateCreated,uniqueName:e.uniqueName,createdBy:e.createdBy,attributes:e.attributes,channel:e.channel,notificationLevel:e.notificationLevel,sid:t};return this.upsertChannel("chat",t,r)}},{key:"upsertChannel",value:function(e,t,r){var n=this;_.trace("upsertChannel(sid="+t+", data=",r);var i=this.channels.get(t);if(i){if(_.trace("upsertChannel: channel "+t+" is known and it's status is known from source "+i._statusSource()+" and update came from source "+e,i),void 0===i._statusSource()||e===i._statusSource()||"synclist"===e&&"sync"!==i._statusSource()||"sync"===e)if("joined"===r.status&&"joined"!==i.status){i._setStatus("joined",e);var s={};void 0!==r.notificationLevel&&(s.notificationLevel=r.notificationLevel),void 0!==r.lastConsumedMessageIndex&&(s.lastConsumedMessageIndex=r.lastConsumedMessageIndex),g.isDeepEqual(s,{})||i._update(s),i._subscribe().then(function(){n.emit("channelJoined",i)})}else if("invited"===r.status&&"invited"!==i.status){i._setStatus("invited",e);var a={};void 0!==r.notificationLevel&&(a.notificationLevel=r.notificationLevel),void 0!==r.lastConsumedMessageIndex&&(a.lastConsumedMessageIndex=r.lastConsumedMessageIndex),g.isDeepEqual(a,{})||i._update(a),i._subscribe().then(function(){n.emit("channelInvited",i)})}else"known"!==r.status||"invited"!==i.status&&"joined"!==i.status?"notParticipating"!==r.status&&"known"!==r.status||"private"!==r.type?i._update(r):i._subscribe():(i._setStatus("known",e),i._update(r),i._subscribe().then(function(){n.emit("channelLeft",i)}));else _.trace("upsertChannel: channel is known from sync and came from chat, ignoring",{sid:t,data:r.status,channel:i.status});return i._subscribe().then(function(){return i})}if("chat"!==e&&"synclist"!==e||!this.thumbstones.has(t))return _.trace("upsertChannel: creating local channel object with sid "+t,r),i=new v.Channel(this.services,r,t),this.channels.set(t,i),i._subscribe().then(function(){return n.registerForEvents(i),n.emit("channelAdded",i),"joined"===r.status?(i._setStatus("joined",e),n.emit("channelJoined",i)):"invited"===r.status&&(i._setStatus("invited",e),n.emit("channelInvited",i)),i});_.trace("upsertChannel: channel is deleted and came again from chat, ignoring",t)}},{key:"onChannelRemoved",value:function(e){var t=this.channels.get(e);t&&(this.channels.delete(e),this.emit("channelRemoved",t))}},{key:"registerForEvents",value:function(e){var t=this;e.on("removed",function(){return t.onChannelRemoved(e.sid)}),e.on("updated",function(e){return t.emit("channelUpdated",e)}),e.on("memberJoined",this.emit.bind(this,"memberJoined")),e.on("memberLeft",this.emit.bind(this,"memberLeft")),e.on("memberUpdated",function(e){return t.emit("memberUpdated",e)}),e.on("messageAdded",this.emit.bind(this,"messageAdded")),e.on("messageUpdated",function(e){return t.emit("messageUpdated",e)}),e.on("messageRemoved",this.emit.bind(this,"messageRemoved")),e.on("typingStarted",this.emit.bind(this,"typingStarted")),e.on("typingEnded",this.emit.bind(this,"typingEnded"))}}]),t}(b.EventEmitter);r.Channels=k},{"../channel":1,"../logger":14,"../util":30,"../util/deferred":29,"babel-runtime/core-js/json/stringify":34,"babel-runtime/core-js/map":35,"babel-runtime/core-js/object/get-prototype-of":41,"babel-runtime/core-js/promise":44,"babel-runtime/core-js/set":46,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/helpers/inherits":53,"babel-runtime/helpers/possibleConstructorReturn":54,"babel-runtime/regenerator":58,events:202}],6:[function(e,t,r){"use strict";var n=l(e("babel-runtime/regenerator")),i=l(e("babel-runtime/core-js/object/get-prototype-of")),s=l(e("babel-runtime/helpers/classCallCheck")),a=l(e("babel-runtime/helpers/createClass")),o=l(e("babel-runtime/helpers/possibleConstructorReturn")),u=l(e("babel-runtime/helpers/inherits")),c=l(e("babel-runtime/core-js/promise"));function l(e){return e&&e.__esModule?e:{default:e}}var f=function(e,t,r,n){return new(r||(r=c.default))(function(i,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function o(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(a,o)}u((n=n.apply(e,t||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0});var d=e("events"),p=e("../member"),h=e("../logger").Logger.scope("Members"),b=function(e){function t(e,r,n){(0,s.default)(this,t);var a=(0,o.default)(this,(t.__proto__||(0,i.default)(t)).call(this));return a.services=r,a.channel=e,a.members=n,a}return(0,u.default)(t,e),(0,a.default)(t,[{key:"unsubscribe",value:function(){return f(this,void 0,void 0,n.default.mark(function e(){return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.rosterEntityPromise){e.next=6;break}return e.next=3,this.rosterEntityPromise;case 3:e.sent.close(),this.rosterEntityPromise=null;case 6:case"end":return e.stop()}},e,this)}))}},{key:"subscribe",value:function(e){var t=this;return this.rosterEntityPromise=this.rosterEntityPromise||this.services.syncClient.map({id:e,mode:"open_existing"}).then(function(e){e.on("itemAdded",function(e){t.upsertMember(e.item.key,e.item.value).then(function(e){t.emit("memberJoined",e)})}),e.on("itemRemoved",function(e){var r=e.key;if(t.members.has(r)){var n=t.members.get(r);t.members.delete(r),t.emit("memberLeft",n)}}),e.on("itemUpdated",function(e){t.upsertMember(e.item.key,e.item.value)});var r=[];return e.forEach(function(e){r.push(t.upsertMember(e.key,e.value))}).then(function(){return c.default.all(r)}).then(function(){return e})}).catch(function(e){throw t.rosterEntityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&h.error("Failed to get roster object for channel",t.channel.sid,e),h.debug("ERROR: Failed to get roster object for channel",t.channel.sid,e),e})}},{key:"upsertMember",value:function(e,t){return f(this,void 0,void 0,n.default.mark(function r(){var i,s=this;return n.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(!(i=this.members.get(e))){r.next=3;break}return r.abrupt("return",i._update(t));case 3:return i=new p.Member(this.services,this.channel,t,e),this.members.set(e,i),i.on("updated",function(e){return s.emit("memberUpdated",e)}),r.abrupt("return",i);case 7:case"end":return r.stop()}},r,this)}))}},{key:"getMembers",value:function(){var e=this;return this.rosterEntityPromise.then(function(){var t=[];return e.members.forEach(function(e){return t.push(e)}),t})}},{key:"add",value:function(e){return this.services.session.addCommand("addMemberV2",{channelSid:this.channel.sid,username:e})}},{key:"invite",value:function(e){return this.services.session.addCommand("inviteMember",{channelSid:this.channel.sid,username:e})}},{key:"remove",value:function(e){return this.services.session.addCommand("removeMember",{channelSid:this.channel.sid,username:e})}}]),t}(d.EventEmitter);r.Members=b},{"../logger":14,"../member":16,"babel-runtime/core-js/object/get-prototype-of":41,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/helpers/inherits":53,"babel-runtime/helpers/possibleConstructorReturn":54,"babel-runtime/regenerator":58,events:202}],7:[function(e,t,r){"use strict";var n=d(e("babel-runtime/core-js/json/stringify")),i=d(e("babel-runtime/regenerator")),s=d(e("babel-runtime/core-js/map")),a=d(e("babel-runtime/core-js/object/get-prototype-of")),o=d(e("babel-runtime/helpers/classCallCheck")),u=d(e("babel-runtime/helpers/createClass")),c=d(e("babel-runtime/helpers/possibleConstructorReturn")),l=d(e("babel-runtime/helpers/inherits")),f=d(e("babel-runtime/core-js/promise"));function d(e){return e&&e.__esModule?e:{default:e}}var p=function(e,t,r,n){return new(r||(r=f.default))(function(i,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function o(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(a,o)}u((n=n.apply(e,t||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0});var h=e("events"),b=e("../logger"),m=e("../message"),v=e("isomorphic-form-data"),y=b.Logger.scope("Messages"),g=function(e){function t(e,r){(0,o.default)(this,t);var n=(0,c.default)(this,(t.__proto__||(0,a.default)(t)).call(this));return n.channel=e,n.services=r,n.messagesByIndex=new s.default,n.messagesListPromise=null,n}return(0,l.default)(t,e),(0,u.default)(t,[{key:"subscribe",value:function(e){var t=this;return this.messagesListPromise=this.messagesListPromise||this.services.syncClient.list({id:e,mode:"open_existing"}).then(function(e){return e.on("itemAdded",function(e){var r=new m.Message(t.channel,t.services,e.item.index,e.item.value);t.messagesByIndex.has(r.index)?y.debug("Message arrived, but already known and ignored",t.channel.sid,r.index):(t.messagesByIndex.set(r.index,r),r.on("updated",function(e){return t.emit("messageUpdated",e)}),t.emit("messageAdded",r))}),e.on("itemRemoved",function(e){var r=e.index;if(t.messagesByIndex.has(r)){var n=t.messagesByIndex.get(r);t.messagesByIndex.delete(n.index),n.removeAllListeners("updated"),t.emit("messageRemoved",n)}}),e.on("itemUpdated",function(e){var r=t.messagesByIndex.get(e.item.index);r&&r._update(e.item.value)}),e}).catch(function(e){throw t.messagesListPromise=null,"disconnected"!=t.services.syncClient.connectionState&&y.error("Failed to get messages object for channel",t.channel.sid,e),y.debug("ERROR: Failed to get messages object for channel",t.channel.sid,e),e})}},{key:"unsubscribe",value:function(){return p(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.messagesListPromise){e.next=6;break}return e.next=3,this.messagesListPromise;case 3:e.sent.close(),this.messagesListPromise=null;case 6:case"end":return e.stop()}},e,this)}))}},{key:"send",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return p(this,void 0,void 0,i.default.mark(function r(){return i.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(y.debug("Sending text message",e,t),null!==t){r.next=3;break}throw new Error("Attributes can't be null");case 3:if(t.constructor===Object){r.next=5;break}throw new Error("Attributes must be a valid JSON object");case 5:return r.abrupt("return",this.services.session.addCommand("sendMessage",{channelSid:this.channel.sid,text:e,attributes:(0,n.default)(t)}));case 6:case"end":return r.stop()}},r,this)}))}},{key:"sendMedia",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return p(this,void 0,void 0,i.default.mark(function r(){var s,a;return i.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(y.debug("Sending media message",e,t),t.constructor===Object){r.next=3;break}throw new Error("Attributes must be a valid JSON object");case 3:if(s=void 0,!(e instanceof v)){r.next=11;break}return y.debug("Sending media message as FormData",e,t),r.next=8,this.services.mcsClient.postFormData(e);case 8:s=r.sent,r.next=18;break;case 11:if(y.debug("Sending media message as SendMediaOptions",e,t),(a=e).contentType&&a.media){r.next=15;break}throw new Error("Media content must contain non-empty contentType and media");case 15:return r.next=17,this.services.mcsClient.post(a.contentType,a.media);case 17:s=r.sent;case 18:return r.abrupt("return",this.services.session.addCommand("sendMediaMessage",{channelSid:this.channel.sid,mediaSid:s.sid,attributes:(0,n.default)(t)}));case 19:case"end":return r.stop()}},r,this)}))}},{key:"getMessages",value:function(e,t,r){return t=void 0!==t?t:"end",r=r||"backwards",this._getMessages(e,t,r)}},{key:"wrapPaginator",value:function(e,t,r){var n=this,i="desc"===e,s=function(){return t.nextPage().then(function(t){return n.wrapPaginator(e,t,r)})},a=function(){return t.prevPage().then(function(t){return n.wrapPaginator(e,t,r)})};return r(t.items).then(function(e){return{items:e.sort(function(e,t){return e.index-t.index}),hasPrevPage:i?t.hasNextPage:t.hasPrevPage,hasNextPage:i?t.hasPrevPage:t.hasNextPage,prevPage:i?s:a,nextPage:i?a:s}})}},{key:"_upsertMessage",value:function(e,t){var r=this,n=this.messagesByIndex.get(e);if(n)return n;var i=new m.Message(this.channel,this.services,e,t);return this.messagesByIndex.set(i.index,i),i.on("updated",function(e){return r.emit("messageUpdated",e)}),i}},{key:"_getMessages",value:function(e,t,r){var n=this;t=void 0!==t?t:"end",e=e||30;var i="backwards"===r?"desc":"asc";return this.messagesListPromise.then(function(r){return r.getItems({from:"end"!==t?t:void 0,pageSize:e,order:i})}).then(function(e){return n.wrapPaginator(i,e,function(e){return f.default.all(e.map(function(e){return n._upsertMessage(e.index,e.value)}))})})}}]),t}(h.EventEmitter);r.Messages=g},{"../logger":14,"../message":17,"babel-runtime/core-js/json/stringify":34,"babel-runtime/core-js/map":35,"babel-runtime/core-js/object/get-prototype-of":41,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/helpers/inherits":53,"babel-runtime/helpers/possibleConstructorReturn":54,"babel-runtime/regenerator":58,events:202,"isomorphic-form-data":205}],8:[function(e,t,r){"use strict";var n=o(e("babel-runtime/regenerator")),i=o(e("babel-runtime/helpers/classCallCheck")),s=o(e("babel-runtime/helpers/createClass")),a=o(e("babel-runtime/core-js/promise"));function o(e){return e&&e.__esModule?e:{default:e}}var u=function(e,t,r,n){return new(r||(r=a.default))(function(i,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function o(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(a,o)}u((n=n.apply(e,t||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0});var c=e("../util/index"),l=e("../restpaginator"),f=e("../channeldescriptor"),d=function(){function e(t,r,n){(0,i.default)(this,e),this.client=t,this.services=r,this.url=n}return(0,s.default)(e,[{key:"getChannels",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return u(this,void 0,void 0,n.default.mark(function t(){var r,i,s=this;return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=new c.UriBuilder(this.url).arg("PageToken",e.pageToken).build(),t.next=3,this.services.network.get(r);case 3:return i=t.sent,t.abrupt("return",new l.RestPaginator(i.body.channels.map(function(e){return new f.ChannelDescriptor(s.client,e)}),function(e){return s.getChannels({pageToken:e})},i.body.meta.previous_token,i.body.meta.next_token));case 5:case"end":return t.stop()}},t,this)}))}},{key:"getChannelBySid",value:function(e){return u(this,void 0,void 0,n.default.mark(function t(){var r,i;return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=new c.UriBuilder(this.url).path(e).build(),t.next=3,this.services.network.get(r);case 3:return i=t.sent,t.abrupt("return",new f.ChannelDescriptor(this.client,i.body));case 5:case"end":return t.stop()}},t,this)}))}},{key:"getChannelByUniqueName",value:function(e){return u(this,void 0,void 0,n.default.mark(function t(){var r,i;return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=new c.UriBuilder(this.url).path(e).build(),t.next=3,this.services.network.get(r);case 3:return i=t.sent,t.abrupt("return",new f.ChannelDescriptor(this.client,i.body));case 5:case"end":return t.stop()}},t,this)}))}}]),e}();r.PublicChannels=d},{"../channeldescriptor":2,"../restpaginator":19,"../util/index":30,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/regenerator":58}],9:[function(e,t,r){"use strict";var n=o(e("babel-runtime/regenerator")),i=o(e("babel-runtime/helpers/classCallCheck")),s=o(e("babel-runtime/helpers/createClass")),a=o(e("babel-runtime/core-js/promise"));function o(e){return e&&e.__esModule?e:{default:e}}var u=function(e,t,r,n){return new(r||(r=a.default))(function(i,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function o(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(a,o)}u((n=n.apply(e,t||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0});var c=e("../util/index"),l=e("../restpaginator"),f=e("../channeldescriptor"),d=function(){function e(t,r,n){(0,i.default)(this,e),this.client=t,this.services=r,this.url=n}return(0,s.default)(e,[{key:"getChannels",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return u(this,void 0,void 0,n.default.mark(function t(){var r,i,s=this;return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=new c.UriBuilder(this.url).arg("PageToken",e.pageToken).build(),t.next=3,this.services.network.get(r);case 3:return i=t.sent,t.abrupt("return",new l.RestPaginator(i.body.channels.map(function(e){return new f.ChannelDescriptor(s.client,e)}),function(e){return s.getChannels({pageToken:e})},i.body.meta.previous_token,i.body.meta.next_token));case 5:case"end":return t.stop()}},t,this)}))}}]),e}();r.UserChannels=d},{"../channeldescriptor":2,"../restpaginator":19,"../util/index":30,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/regenerator":58}],10:[function(e,t,r){"use strict";var n=o(e("babel-runtime/regenerator")),i=o(e("babel-runtime/helpers/classCallCheck")),s=o(e("babel-runtime/helpers/createClass")),a=o(e("babel-runtime/core-js/promise"));function o(e){return e&&e.__esModule?e:{default:e}}var u=function(e,t,r,n){return new(r||(r=a.default))(function(i,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function o(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(a,o)}u((n=n.apply(e,t||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0});var c=e("../util/index"),l=e("../restpaginator"),f=e("../userdescriptor"),d=function(){function e(t,r){(0,i.default)(this,e),this.services=t,this.url=r}return(0,s.default)(e,[{key:"getUserDescriptor",value:function(e){return u(this,void 0,void 0,n.default.mark(function t(){var r,i;return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=new c.UriBuilder(this.url).path(e).build(),t.next=3,this.services.network.get(r);case 3:return i=t.sent,t.abrupt("return",new f.UserDescriptor(this.services,i.body));case 5:case"end":return t.stop()}},t,this)}))}},{key:"getChannelUserDescriptors",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return u(this,void 0,void 0,n.default.mark(function r(){var i,s,a=this;return n.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return i=new c.UriBuilder(this.url).arg("ChannelSid",e).arg("PageToken",t.pageToken).build(),r.next=3,this.services.network.get(i);case 3:return s=r.sent,r.abrupt("return",new l.RestPaginator(s.body.users.map(function(e){return new f.UserDescriptor(a.services,e)}),function(t){return a.getChannelUserDescriptors(e,{pageToken:t})},s.body.meta.prev_token,s.body.meta.next_token));case 5:case"end":return r.stop()}},r,this)}))}}]),e}();r.UserDescriptors=d},{"../restpaginator":19,"../userdescriptor":28,"../util/index":30,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/regenerator":58}],11:[function(e,t,r){"use strict";var n=f(e("babel-runtime/regenerator")),i=f(e("babel-runtime/core-js/map")),s=f(e("babel-runtime/core-js/object/get-prototype-of")),a=f(e("babel-runtime/helpers/classCallCheck")),o=f(e("babel-runtime/helpers/createClass")),u=f(e("babel-runtime/helpers/possibleConstructorReturn")),c=f(e("babel-runtime/helpers/inherits")),l=f(e("babel-runtime/core-js/promise"));function f(e){return e&&e.__esModule?e:{default:e}}var d=function(e,t,r,n){return new(r||(r=l.default))(function(i,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function o(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(a,o)}u((n=n.apply(e,t||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0});var p=e("events"),h=e("../user"),b=e("./userdescriptors"),m=function(e){function t(e){(0,a.default)(this,t);var r=(0,u.default)(this,(t.__proto__||(0,s.default)(t)).call(this));return r.services=e,r.fifoStack=[],r.fifoStackMaxLength=100,r.myself=new h.User(null,null,r.services),r.myself.on("updated",function(e){return r.emit("userUpdated",e)}),r.myself.on("userSubscribed",function(){return r.emit("userSubscribed",r.myself)}),r.myself.on("userUnsubscribed",function(){r.emit("userUnsubscribed",r.myself),r.myself._ensureFetched()}),r.services=e,r.subscribedUsers=new i.default,r.userDescriptorsPromise=r.services.session.getSessionLinks().then(function(e){return r.userDescriptors=new b.UserDescriptors({users:r,network:r.services.network},e.usersUrl),r.userDescriptors}),r.services.session.getMaxUserInfosToSubscribe().then(function(e){r.fifoStackMaxLength=e}),r.services.session.getUsersData().then(function(e){return r.myself.identity=e.identity,r.myself.entityName=e.user,r.myself._ensureFetched()}),r}return(0,c.default)(t,e),(0,o.default)(t,[{key:"handleUnsubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)&&this.subscribedUsers.delete(e.identity);var t=-1;this.fifoStack.find(function(r,n){return r==e.identity&&(t=n,!0)})&&this.fifoStack.splice(t,1),this.emit("userUnsubscribed",e)}},{key:"handleSubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)||(this.fifoStack.length>=this.fifoStackMaxLength&&this.subscribedUsers.get(this.fifoStack.shift()).unsubscribe(),this.fifoStack.push(e.identity),this.subscribedUsers.set(e.identity,e),this.emit("userSubscribed",e))}},{key:"getUser",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return d(this,void 0,void 0,n.default.mark(function r(){var i,s,a=this;return n.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.services.session.getUsersData();case 2:return r.next=4,this.myself._ensureFetched();case 4:if(e!=this.myself.identity){r.next=6;break}return r.abrupt("return",this.myself);case 6:if(i=this.subscribedUsers.get(e)){r.next=19;break}if(t){r.next=13;break}return r.next=11,this.getUserDescriptor(e);case 11:s=r.sent,t=s._getDescriptor().sync_unique_name;case 13:return(i=new h.User(e,t,this.services)).on("updated",function(e){return a.emit("userUpdated",e)}),i.on("userSubscribed",function(){return a.handleSubscribeUser(i)}),i.on("userUnsubscribed",function(){return a.handleUnsubscribeUser(i)}),r.next=19,i._ensureFetched();case 19:return r.abrupt("return",i);case 20:case"end":return r.stop()}},r,this)}))}},{key:"getUserDescriptor",value:function(e){return d(this,void 0,void 0,n.default.mark(function t(){return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.userDescriptorsPromise;case 2:return t.abrupt("return",this.userDescriptors.getUserDescriptor(e));case 3:case"end":return t.stop()}},t,this)}))}},{key:"getChannelUserDescriptors",value:function(e){return d(this,void 0,void 0,n.default.mark(function t(){return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.userDescriptorsPromise;case 2:return t.abrupt("return",this.userDescriptors.getChannelUserDescriptors(e));case 3:case"end":return t.stop()}},t,this)}))}},{key:"getSubscribedUsers",value:function(){return d(this,void 0,void 0,n.default.mark(function e(){var t;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.getUsersData();case 2:return e.next=4,this.myself._ensureFetched();case 4:return t=[this.myself],this.subscribedUsers.forEach(function(e){return t.push(e)}),e.abrupt("return",t);case 7:case"end":return e.stop()}},e,this)}))}}]),t}(p.EventEmitter);r.Users=m},{"../user":27,"./userdescriptors":10,"babel-runtime/core-js/map":35,"babel-runtime/core-js/object/get-prototype-of":41,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/helpers/inherits":53,"babel-runtime/helpers/possibleConstructorReturn":54,"babel-runtime/regenerator":58,events:202}],12:[function(e,t,r){"use strict";var n,i=e("babel-runtime/helpers/classCallCheck"),s=(n=i)&&n.__esModule?n:{default:n};Object.defineProperty(r,"__esModule",{value:!0});var a=function e(){(0,s.default)(this,e)};a.TYPING_INDICATOR="twilio.ipmsg.typing_indicator",a.NEW_MESSAGE="twilio.channel.new_message",a.ADDED_TO_CHANNEL="twilio.channel.added_to_channel",a.INVITED_TO_CHANNEL="twilio.channel.invited_to_channel",a.REMOVED_FROM_CHANNEL="twilio.channel.removed_from_channel",a.CONSUMPTION_UPDATE="twilio.channel.consumption_update",r.NotificationTypes=a},{"babel-runtime/helpers/classCallCheck":50}],13:[function(e,t,r){"use strict";var n,i=e("babel-runtime/helpers/classCallCheck"),s=(n=i)&&n.__esModule?n:{default:n};Object.defineProperty(r,"__esModule",{value:!0});var a=function e(){(0,s.default)(this,e)};a.HTTP_200_OK=200,a.HTTP_400_BAD_REQUEST=400,a.HTTP_404_NOT_FOUND=404,a.ACCESS_FORBIDDEN_FOR_IDENTITY=54007,a.LIST_NOT_FOUND=54150,r.ResponseCodes=a},{"babel-runtime/helpers/classCallCheck":50}],14:[function(e,t,r){"use strict";var n=a(e("babel-runtime/helpers/classCallCheck")),i=a(e("babel-runtime/helpers/createClass")),s=a(e("babel-runtime/core-js/array/from"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=e("loglevel");function u(e,t){return[(new Date).toISOString()+" Chat "+e+":"].concat((0,s.default)(t))}var c=function(){function e(t){(0,n.default)(this,e),this.prefix="",this.prefix=null!=t&&t.length>0?t+" ":""}return(0,i.default)(e,[{key:"setLevel",value:function(e){o.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=Array(e),r=0;r0&&this.emit("updated",{member:this,updateReasons:t}),this}},{key:"getUserDescriptor",value:function(){return p(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("chat"==this.type){e.next=2;break}throw new Error("Getting User Descriptor is not supported for this Member type: "+this.type);case 2:return e.abrupt("return",this.services.users.getUserDescriptor(this.state.identity));case 3:case"end":return e.stop()}},e,this)}))}},{key:"getUser",value:function(){return p(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("chat"==this.type){e.next=2;break}throw new Error("Getting User is not supported for this Member type: "+this.type);case 2:return e.abrupt("return",this.services.users.getUser(this.state.identity,this.state.userInfo));case 3:case"end":return e.stop()}},e,this)}))}},{key:"remove",value:function(){return p(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("chat"==this.type){e.next=2;break}throw new Error("Removing this member is not supported for this Member type: "+this.type);case 2:return e.abrupt("return",this.channel.removeMember(this));case 3:case"end":return e.stop()}},e,this)}))}},{key:"updateAttributes",value:function(e){return p(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0!==e){t.next=4;break}throw new Error("Attributes is required parameter");case 4:if(null!==e){t.next=8;break}throw new Error("Attributes can't be null");case 8:if(e.constructor===Object){t.next=10;break}throw new Error("Attributes must be a valid JSON object");case 10:return t.next=12,this.services.session.addCommand("editMemberAttributes",{channelSid:this.channel.sid,memberSid:this.sid,attributes:(0,n.default)(e)});case 12:return t.abrupt("return",this);case 13:case"end":return t.stop()}},t,this)}))}}]),t}(h.EventEmitter);r.Member=v},{"./logger":14,"./util":30,"babel-runtime/core-js/json/stringify":34,"babel-runtime/core-js/number/is-integer":36,"babel-runtime/core-js/object/get-prototype-of":41,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/helpers/inherits":53,"babel-runtime/helpers/possibleConstructorReturn":54,"babel-runtime/regenerator":58,events:202}],17:[function(e,t,r){"use strict";var n=f(e("babel-runtime/core-js/json/stringify")),i=f(e("babel-runtime/regenerator")),s=f(e("babel-runtime/core-js/object/get-prototype-of")),a=f(e("babel-runtime/helpers/classCallCheck")),o=f(e("babel-runtime/helpers/createClass")),u=f(e("babel-runtime/helpers/possibleConstructorReturn")),c=f(e("babel-runtime/helpers/inherits")),l=f(e("babel-runtime/core-js/promise"));function f(e){return e&&e.__esModule?e:{default:e}}var d=function(e,t,r,n){return new(r||(r=l.default))(function(i,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function o(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(a,o)}u((n=n.apply(e,t||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0});var p=e("events"),h=e("./util/index"),b=e("./logger"),m=e("./media"),v=b.Logger.scope("Message");function y(e,t){try{return t?JSON.parse(t):{}}catch(t){return v.warn("Got malformed attributes for the message",e),{}}}var g=function(e){function t(e,r,n,i){(0,a.default)(this,t);var o=(0,u.default)(this,(t.__proto__||(0,s.default)(t)).call(this));return o.channel=e,o.services=r,o.state={sid:i.sid,index:n,author:i.author,body:i.text,timestamp:i.timestamp?new Date(i.timestamp):null,dateUpdated:i.dateUpdated?new Date(i.dateUpdated):null,lastUpdatedBy:i.lastUpdatedBy?i.lastUpdatedBy:null,attributes:y(i.sid,i.attributes),type:i.type?i.type:"text",media:i.type&&"media"===i.type&&i.media?new m.Media(i.media,o.services):null},o}return(0,c.default)(t,e),(0,o.default)(t,[{key:"_update",value:function(e){var t=[];!e.text&&"string"!=typeof e.text||e.text===this.state.body||(this.state.body=e.text,t.push("body")),e.lastUpdatedBy&&e.lastUpdatedBy!==this.state.lastUpdatedBy&&(this.state.lastUpdatedBy=e.lastUpdatedBy,t.push("lastUpdatedBy")),e.author&&e.author!==this.state.author&&(this.state.author=e.author,t.push("author")),e.dateUpdated&&new Date(e.dateUpdated).getTime()!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=new Date(e.dateUpdated),t.push("dateUpdated")),e.timestamp&&new Date(e.timestamp).getTime()!==(this.state.timestamp&&this.state.timestamp.getTime())&&(this.state.timestamp=new Date(e.timestamp),t.push("timestamp"));var r=y(this.sid,e.attributes);h.isDeepEqual(this.state.attributes,r)||(this.state.attributes=r,t.push("attributes")),t.length>0&&this.emit("updated",{message:this,updateReasons:t})}},{key:"remove",value:function(){return d(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("deleteMessage",{channelSid:this.channel.sid,messageIdx:this.index.toString()});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}},e,this)}))}},{key:"updateBody",value:function(e){return d(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if("string"==typeof e){t.next=2;break}throw new Error("Body is a required parameter for updateBody");case 2:return t.next=4,this.services.session.addCommand("editMessage",{channelSid:this.channel.sid,messageIdx:this.index.toString(),text:e});case 4:return t.abrupt("return",this);case 5:case"end":return t.stop()}},t,this)}))}},{key:"updateAttributes",value:function(e){return d(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0!==e){t.next=4;break}throw new Error("Attributes is required parameter");case 4:if(null!==e){t.next=8;break}throw new Error("Attributes can't be null");case 8:if(e.constructor===Object){t.next=10;break}throw new Error("Attributes must be a valid JSON object");case 10:return t.next=12,this.services.session.addCommand("editMessageAttributes",{channelSid:this.channel.sid,messageIdx:this.index,attributes:(0,n.default)(e)});case 12:return t.abrupt("return",this);case 13:case"end":return t.stop()}},t,this)}))}},{key:"sid",get:function(){return this.state.sid}},{key:"author",get:function(){return this.state.author}},{key:"body",get:function(){return"media"===this.type?null:this.state.body}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"index",get:function(){return this.state.index}},{key:"lastUpdatedBy",get:function(){return this.state.lastUpdatedBy}},{key:"timestamp",get:function(){return this.state.timestamp}},{key:"attributes",get:function(){return this.state.attributes}},{key:"type",get:function(){return this.state.type}},{key:"media",get:function(){return this.state.media}}]),t}(p.EventEmitter);r.Message=g},{"./logger":14,"./media":15,"./util/index":30,"babel-runtime/core-js/json/stringify":34,"babel-runtime/core-js/object/get-prototype-of":41,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/helpers/inherits":53,"babel-runtime/helpers/possibleConstructorReturn":54,"babel-runtime/regenerator":58,events:202}],18:[function(e,t,r){"use strict";var n,i=e("babel-runtime/helpers/classCallCheck"),s=(n=i)&&n.__esModule?n:{default:n};Object.defineProperty(r,"__esModule",{value:!0});r.PushNotification=function e(t){(0,s.default)(this,e),this.title=t.title||null,this.body=t.body||null,this.sound=t.sound||null,this.badge=t.badge||null,this.action=t.action||null,this.type=t.type||null,this.data=t.data||{}}},{"babel-runtime/helpers/classCallCheck":50}],19:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/promise")),i=a(e("babel-runtime/helpers/classCallCheck")),s=a(e("babel-runtime/helpers/createClass"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(t,r,n,s){(0,i.default)(this,e),this.state={prevToken:n,nextToken:s,source:r,items:t}}return(0,s.default)(e,[{key:"nextPage",value:function(){return this.hasNextPage?this.state.source(this.state.nextToken):n.default.reject(new Error("No next page"))}},{key:"prevPage",value:function(){return this.hasPrevPage?this.state.source(this.state.prevToken):n.default.reject(new Error("No previous page"))}},{key:"hasNextPage",get:function(){return!!this.state.nextToken}},{key:"hasPrevPage",get:function(){return!!this.state.prevToken}},{key:"items",get:function(){return this.state.items}}]),e}();r.RestPaginator=o},{"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51}],20:[function(e,t,r){"use strict";var n=o(e("babel-runtime/core-js/promise")),i=o(e("babel-runtime/core-js/map")),s=o(e("babel-runtime/helpers/createClass")),a=o(e("babel-runtime/helpers/classCallCheck"));function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=e("../sessionerror"),c=function(){function e(t){(0,a.default)(this,e),this.services=t,this.consumptionHorizonRequests=new i.default,this.consumptionHorizonUpdateTimer=null}return(0,s.default)(e,[{key:"getReportInterval",value:function(){return this.services.session.getConsumptionReportInterval().then(function(e){return 1e3*e})}},{key:"delayedSendConsumptionHorizon",value:function(e){var t=this;null===this.consumptionHorizonUpdateTimer&&(this.sendConsumptionReport(!0),this.consumptionHorizonUpdateTimer=setTimeout(function(){t.sendConsumptionReport(!1)},e))}},{key:"sendConsumptionReport",value:function(e){var t=this,r=[],n=new i.default;this.consumptionHorizonRequests.forEach(function(e,t){r.push(e.entry),n.set(t,e.promises)}),r.length>0&&this.services.session.addCommand("consumptionReportV2",{report:r}).then(function(e){return t.processConsumptionReportResponse(e,n)}).catch(function(e){return t.processConsumptionReportError(e,n)}),e||(this.consumptionHorizonUpdateTimer=null),this.consumptionHorizonRequests.clear()}},{key:"processConsumptionReportResponse",value:function(e,t){e&&e.report&&Array.isArray(e.report)&&e.report.length>0&&e.report.forEach(function(e){var r=e;if(t.has(r.channelSid)){var n=null;void 0!==r.unreadMessagesCount&&null!=r.unreadMessagesCount&&(n=r.unreadMessagesCount),t.get(r.channelSid).forEach(function(e){return e.resolve(n)}),t.delete(r.channelSid)}}),this.processConsumptionReportError(new u.SessionError("Error while setting LastConsumedMessageIndex",null),t)}},{key:"processConsumptionReportError",value:function(e,t){t.forEach(function(t){return t.forEach(function(t){return t.reject(e)})})}},{key:"updateLastConsumedMessageIndexForChannel",value:function(e,t){var r=this;return new n.default(function(n,i){r.addPendingConsumptionHorizonRequest(e,{channelSid:e,messageIdx:t},{resolve:n,reject:i}),r.getReportInterval().then(function(e){return r.delayedSendConsumptionHorizon(e)})})}},{key:"advanceLastConsumedMessageIndexForChannel",value:function(e,t,r){var i=this,s=this.consumptionHorizonRequests.get(e);return new n.default(function(n,a){s&&s.entry?s.entry.messageIdx>=t?i.addPendingConsumptionHorizonRequest(e,s.entry,{resolve:n,reject:a}):i.addPendingConsumptionHorizonRequest(e,{channelSid:e,messageIdx:t},{resolve:n,reject:a}):null!==r&&tthis.cacheLifetime}},{key:"cleanupCache",value:function(){var e=!0,t=!1,r=void 0;try{for(var n,a=(0,i.default)(this.cache);!(e=(n=a.next()).done);e=!0){var o=n.value,u=(0,s.default)(o,2),c=u[0],l=u[1];this.isExpired(l.timestamp)&&this.cache.delete(c)}}catch(e){t=!0,r=e}finally{try{!e&&a.return&&a.return()}finally{if(t)throw r}}0===this.cache.size&&clearInterval(this.timer)}},{key:"pokeTimer",value:function(){var e=this;this.timer=this.timer||setInterval(function(){return e.cleanupCache()},2*this.cacheLifetime)}},{key:"executeWithRetry",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return new l.default(function(n,i){var s=[502,503,504];r&&s.push(429);var a=new p.default(t.backoffConfig());a.on("attempt",function(){e().then(function(e){return a.succeeded(e)}).catch(function(e){s.indexOf(e.status)>-1?a.failed(e):"Twilsock disconnected"===e.message?a.failed(e):(a.removeAllListeners(),a.cancel(),i(e))})}),a.on("succeeded",function(e){n(e)}),a.on("cancelled",function(e){return i(e)}),a.on("failed",function(e){return i(e)}),a.start()})}},{key:"get",value:function(e){return d(this,void 0,void 0,n.default.mark(function t(){var r,i,s,a=this;return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!(r=this.cache.get(e))||this.isExpired(r.timestamp)){t.next=3;break}return t.abrupt("return",r.response);case 3:return i={},t.next=6,this.executeWithRetry(function(){return a.services.transport.get(e,i)},this.retryWhenThrottled());case 6:return s=t.sent,this.cache.set(e,{response:s,timestamp:Date.now()}),this.pokeTimer(),t.abrupt("return",s);case 10:case"end":return t.stop()}},t,this)}))}}]),e}();r.Network=h},{"babel-runtime/core-js/get-iterator":32,"babel-runtime/core-js/map":35,"babel-runtime/core-js/object/assign":37,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/helpers/slicedToArray":55,"babel-runtime/regenerator":58,"operation-retrier":208}],22:[function(e,t,r){"use strict";var n=o(e("babel-runtime/core-js/promise")),i=o(e("babel-runtime/core-js/map")),s=o(e("babel-runtime/helpers/classCallCheck")),a=o(e("babel-runtime/helpers/createClass"));function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=e("../logger"),c=e("../interfaces/notificationtypes"),l=u.Logger.scope("TypingIndicator"),f=function(){function e(t,r,n){(0,s.default)(this,e),this.config=t,this.services=r,this.getChannel=n,this.serviceTypingTimeout=null,this.sentUpdates=new i.default}return(0,a.default)(e,[{key:"initialize",value:function(){var e=this;this.services.notificationClient.subscribe(c.NotificationTypes.TYPING_INDICATOR,"twilsock"),this.services.notificationClient.on("message",function(t,r){t===c.NotificationTypes.TYPING_INDICATOR&&e.handleRemoteTyping(r)})}},{key:"handleRemoteTyping",value:function(e){var t=this;l.trace("Got new typing indicator ",e),this.getChannel(e.channel_sid).then(function(r){r&&r.members.forEach(function(r){r.identity===e.identity&&r._startTyping(t.typingTimeout)})}).catch(function(e){throw l.error(e),e})}},{key:"send",value:function(e){var t=this.sentUpdates.get(e);return t&&t>Date.now()-this.typingTimeout?n.default.resolve():(this.sentUpdates.set(e,Date.now()),this._send(e))}},{key:"_send",value:function(e){var t=this;l.trace("Sending typing indicator");var r=this.config.typingIndicatorUri,n="ChannelSid="+e;return this.services.transport.post(r,{"Content-Type":"application/x-www-form-urlencoded"},n).then(function(e){e.body.hasOwnProperty("typing_timeout")&&(t.serviceTypingTimeout=1e3*e.body.typing_timeout)}).catch(function(e){throw l.error("Failed to send typing indicator:",e),e})}},{key:"typingTimeout",get:function(){return this.config.typingIndicatorTimeoutOverride||this.serviceTypingTimeout||this.config.typingIndicatorTimeoutDefault}}]),e}();r.TypingIndicator=f},{"../interfaces/notificationtypes":12,"../logger":14,"babel-runtime/core-js/map":35,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51}],23:[function(e,t,r){"use strict";var n=u(e("babel-runtime/regenerator")),i=u(e("babel-runtime/core-js/map")),s=u(e("babel-runtime/helpers/createClass")),a=u(e("babel-runtime/helpers/classCallCheck")),o=u(e("babel-runtime/core-js/promise"));function u(e){return e&&e.__esModule?e:{default:e}}var c=function(e,t,r,n){return new(r||(r=o.default))(function(i,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function o(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(a,o)}u((n=n.apply(e,t||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0});var l=e("uuid"),f=e("platform"),d=e("./interfaces/responsecodes"),p=e("./logger"),h=e("./sessionerror"),b=e("./util/deferred"),m=e("iso8601-duration"),v=e("./../package.json").version,y=p.Logger.scope("Session"),g=function e(){(0,a.default)(this,e)};var _=function(){function e(t,r){(0,a.default)(this,e);var n="undefined"!=typeof navigator?f.parse(navigator.userAgent):f;this.services=t,this.config=r,this.sessionInfo=new b.Deferred,this.currentContext={},this.pendingCommands=new i.default,this.sessionStreamPromise=null,this.endpointPlatform=["js",v,n.os,n.name,n.version].join("|")}return(0,s.default)(e,[{key:"handleContextUpdate",value:function(e){var t;(y.info("Session context updated"),y.debug("new session context:",e),this.currentContext=e,t=e,["identity","userInfo","links","myChannels","channels"].some(function(e){return!t.hasOwnProperty(e)}))||(y.info("new session context accepted"),this.sessionInfo.set(e))}},{key:"initialize",value:function(){var e=this,t={type:"IpMsgSession",apiVersion:"3",endpointPlatform:this.endpointPlatform};return this.sessionStreamPromise=this.services.syncClient.list({purpose:"com.twilio.rtd.ipmsg",context:t}).then(function(t){return y.info("Session created",t.sid),t.on("itemAdded",function(t){return e.processCommandResponse(t.item)}),t.on("itemUpdated",function(t){return e.processCommandResponse(t.item)}),t.on("contextUpdated",function(t){return e.handleContextUpdate(t.context)}),t}).catch(function(e){throw y.error("Failed to create session",e),e}),this.sessionStreamPromise}},{key:"addCommand",value:function(e,t){return this.processCommand(e,t)}},{key:"processCommand",value:function(e,t){var r=this,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=new g;return i.request=t,i.request.action=e,i.commandId=l.v4(),y.info("Adding command: ",e,i.commandId),y.debug("command arguments:",t,n),new o.default(function(s,a){r.sessionStreamPromise.then(function(e){return r.pendingCommands.set(i.commandId,{resolve:s,reject:a,commandId:i.commandId,request:i.request}),e.push(i)}).then(function(){return y.debug("Command accepted by server",i.commandId)}).catch(function(o){r.pendingCommands.delete(i.commandId),y.error("Failed to add a command to the session",o),o.code!=d.ResponseCodes.ACCESS_FORBIDDEN_FOR_IDENTITY&&o.code!==d.ResponseCodes.LIST_NOT_FOUND||!n?a(new Error("Can't add command: "+o.message)):(y.info("recreating session..."),r.initialize(),s(r.processCommand(e,t,!1)))})})}},{key:"processCommandResponse",value:function(e){if(e.value.hasOwnProperty("response")&&e.value.hasOwnProperty("commandId")&&this.pendingCommands.has(e.value.commandId)){var t=e.value,r=e.value.commandId;if(t.response.status===d.ResponseCodes.HTTP_200_OK){y.debug("Command succeeded: ",t);var n=this.pendingCommands.get(r).resolve;this.pendingCommands.delete(r),n(t.response)}else{y.error("Command failed: ",t);var i=this.pendingCommands.get(r).reject;this.pendingCommands.delete(r),i(new h.SessionError(t.response.statusText,t.response.status))}}}},{key:"getSessionContext",value:function(){return this.sessionStreamPromise.then(function(e){return e.getContext()})}},{key:"getSessionLinks",value:function(){return c(this,void 0,void 0,n.default.mark(function e(){var t;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sessionInfo.promise;case 2:return t=e.sent,e.abrupt("return",{publicChannelsUrl:this.config.baseUrl+t.links.publicChannelsUrl,myChannelsUrl:this.config.baseUrl+t.links.myChannelsUrl,typingUrl:this.config.baseUrl+t.links.typingUrl,syncListUrl:this.config.baseUrl+t.links.syncListUrl,usersUrl:this.config.baseUrl+t.links.usersUrl,mediaServiceUrl:t.links.mediaServiceUrl});case 4:case"end":return e.stop()}},e,this)}))}},{key:"getChannelsId",value:function(){return c(this,void 0,void 0,n.default.mark(function e(){var t;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sessionInfo.promise;case 2:return t=e.sent,e.abrupt("return",t.channels);case 4:case"end":return e.stop()}},e,this)}))}},{key:"getMyChannelsId",value:function(){return c(this,void 0,void 0,n.default.mark(function e(){var t;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sessionInfo.promise;case 2:return t=e.sent,e.abrupt("return",t.myChannels);case 4:case"end":return e.stop()}},e,this)}))}},{key:"getMaxUserInfosToSubscribe",value:function(){return c(this,void 0,void 0,n.default.mark(function e(){var t;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sessionInfo.promise;case 2:return t=e.sent,e.abrupt("return",this.config.userInfosToSubscribeOverride||t.userInfosToSubscribe||this.config.userInfosToSubscribeDefault);case 4:case"end":return e.stop()}},e,this)}))}},{key:"getUsersData",value:function(){return this.sessionInfo.promise.then(function(e){return{user:e.userInfo,identity:e.identity}})}},{key:"getConsumptionReportInterval",value:function(){return c(this,void 0,void 0,n.default.mark(function e(){var t,r;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getSessionContext();case 2:return t=e.sent,r=this.config.consumptionReportIntervalOverride||t.consumptionReportInterval||this.config.consumptionReportIntervalDefault,e.prev=4,e.abrupt("return",m.toSeconds(m.parse(r)));case 8:return e.prev=8,e.t0=e.catch(4),y.error("Failed to parse consumption report interval",r,"using default value",this.config.consumptionReportIntervalDefault),e.abrupt("return",m.toSeconds(m.parse(this.config.consumptionReportIntervalDefault)));case 12:case"end":return e.stop()}},e,this,[[4,8]])}))}},{key:"getHttpCacheInterval",value:function(){return c(this,void 0,void 0,n.default.mark(function e(){var t,r;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getSessionContext();case 2:return t=e.sent,r=this.config.httpCacheIntervalOverride||t.httpCacheInterval||this.config.httpCacheIntervalDefault,e.prev=4,e.abrupt("return",m.toSeconds(m.parse(r)));case 8:return e.prev=8,e.t0=e.catch(4),y.error("Failed to parse cache interval",r,"using default value",this.config.httpCacheIntervalDefault),e.abrupt("return",m.toSeconds(m.parse(this.config.httpCacheIntervalDefault)));case 12:case"end":return e.stop()}},e,this,[[4,8]])}))}},{key:"identity",get:function(){return this.sessionInfo.current.identity}},{key:"reachabilityEnabled",get:function(){return this.currentContext.reachabilityEnabled}}]),e}();r.Session=_},{"./../package.json":299,"./interfaces/responsecodes":13,"./logger":14,"./sessionerror":24,"./util/deferred":29,"babel-runtime/core-js/map":35,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/regenerator":58,"iso8601-duration":204,platform:209,uuid:294}],24:[function(e,t,r){"use strict";var n=f(e("babel-runtime/core-js/object/create")),i=f(e("babel-runtime/core-js/object/set-prototype-of")),s=f(e("babel-runtime/core-js/array/from")),a=f(e("babel-runtime/core-js/reflect/construct")),o=f(e("babel-runtime/core-js/object/get-prototype-of")),u=f(e("babel-runtime/helpers/classCallCheck")),c=f(e("babel-runtime/helpers/possibleConstructorReturn")),l=f(e("babel-runtime/helpers/inherits"));function f(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var d=function(e){function t(e,r){(0,u.default)(this,t);var n=(0,c.default)(this,(t.__proto__||(0,o.default)(t)).call(this));return n.name=n.constructor.name,n.message=e,n.code=r,Error.captureStackTrace?Error.captureStackTrace(n,n.constructor):n.stack=(new Error).stack,n}return(0,l.default)(t,e),t}(function(e){function t(){var t=(0,a.default)(e,(0,s.default)(arguments));return(0,i.default)(t,(0,o.default)(this)),t}return t.prototype=(0,n.default)(e.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),i.default?(0,i.default)(t,e):t.__proto__=e,t}(Error));r.SessionError=d},{"babel-runtime/core-js/array/from":31,"babel-runtime/core-js/object/create":38,"babel-runtime/core-js/object/get-prototype-of":41,"babel-runtime/core-js/object/set-prototype-of":43,"babel-runtime/core-js/reflect/construct":45,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/inherits":53,"babel-runtime/helpers/possibleConstructorReturn":54}],25:[function(e,t,r){"use strict";var n=o(e("babel-runtime/regenerator")),i=o(e("babel-runtime/helpers/classCallCheck")),s=o(e("babel-runtime/helpers/createClass")),a=o(e("babel-runtime/core-js/promise"));function o(e){return e&&e.__esModule?e:{default:e}}var u=function(e,t,r,n){return new(r||(r=a.default))(function(i,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function o(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(a,o)}u((n=n.apply(e,t||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0});var c=e("./util/index"),l=e("./restpaginator"),f=e("./synclistdescriptor"),d=function(){function e(t){(0,i.default)(this,e),this.services=t}return(0,s.default)(e,[{key:"getPage",value:function(e){return u(this,void 0,void 0,n.default.mark(function t(){var r,i,s,a=this;return n.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=e||{},t.next=3,this.services.session.getSessionLinks();case 3:return r=t.sent,i=new c.UriBuilder(r.syncListUrl).arg("PageToken",e.pageToken).build(),t.next=7,this.services.network.get(i);case 7:return s=t.sent,t.abrupt("return",new l.RestPaginator(s.body.channels.map(function(e){return new f.SyncListDescriptor(e)}),function(e){return a.getPage({pageToken:e})},s.body.meta.previous_token,s.body.meta.next_token));case 9:case"end":return t.stop()}},t,this)}))}}]),e}();r.SyncList=d},{"./restpaginator":19,"./synclistdescriptor":26,"./util/index":30,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/regenerator":58}],26:[function(e,t,r){"use strict";var n,i=e("babel-runtime/helpers/classCallCheck"),s=(n=i)&&n.__esModule?n:{default:n};Object.defineProperty(r,"__esModule",{value:!0});r.SyncListDescriptor=function e(t){(0,s.default)(this,e),this.descriptor=t,this.channel_sid=t.channel_sid,this.status=t.status,this.channel=t.channel,this.messages=t.messages,this.roster=t.roster,this.lastConsumedMessageIndex=t.last_consumed_message_index,this.notificationLevel=t.notification_level,this.status=t.status}},{"babel-runtime/helpers/classCallCheck":50}],27:[function(e,t,r){"use strict";var n=f(e("babel-runtime/core-js/json/stringify")),i=f(e("babel-runtime/regenerator")),s=f(e("babel-runtime/core-js/object/get-prototype-of")),a=f(e("babel-runtime/helpers/classCallCheck")),o=f(e("babel-runtime/helpers/createClass")),u=f(e("babel-runtime/helpers/possibleConstructorReturn")),c=f(e("babel-runtime/helpers/inherits")),l=f(e("babel-runtime/core-js/promise"));function f(e){return e&&e.__esModule?e:{default:e}}var d=function(e,t,r,n){return new(r||(r=l.default))(function(i,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function o(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(a,o)}u((n=n.apply(e,t||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0});var p=e("events"),h=e("./logger"),b=e("./util"),m=h.Logger.scope("User"),v=function(e){function t(e,r,n){(0,a.default)(this,t);var i=(0,u.default)(this,(t.__proto__||(0,s.default)(t)).call(this));return i.subscribed="initializing",i.setMaxListeners(0),i.services=n,i.state={identity:e,entityName:r,friendlyName:null,attributes:{},online:null,notifiable:null},i}return(0,c.default)(t,e),(0,o.default)(t,[{key:"_update",value:function(e,t){var r=[];switch(m.debug("User for",this.state.identity,"updated:",e,t),e){case"friendlyName":this.state.friendlyName!==t.value&&(r.push("friendlyName"),this.state.friendlyName=t.value);break;case"attributes":var n={};try{n=JSON.parse(t.value)}catch(e){m.warn("Retrieved malformed attributes from the server for user: "+this.state.identity)}b.isDeepEqual(this.state.attributes,n)||(this.state.attributes=n,r.push("attributes"));break;case"reachability":this.state.online!==t.online&&(this.state.online=t.online,r.push("online")),this.state.notifiable!==t.notifiable&&(this.state.notifiable=t.notifiable,r.push("notifiable"));break;default:return}r.length>0&&this.emit("updated",{user:this,updateReasons:r})}},{key:"_updateReachabilityInfo",value:function(e,t){var r=this;return this.services.session.reachabilityEnabled?e.get("reachability").then(t).catch(function(e){m.warn("Failed to get reachability info for ",r.state.identity,e)}):l.default.resolve()}},{key:"_fetch",value:function(){return d(this,void 0,void 0,i.default.mark(function e(){var t=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.state.entityName){e.next=2;break}return e.abrupt("return",this);case 2:return this.promiseToFetch=this.services.syncClient.map({id:this.state.entityName,mode:"open_existing",includeItems:!0}).then(function(e){return t.entity=e,e.on("itemUpdated",function(e){return t._update(e.item.key,e.item.value)}),l.default.all([e.get("friendlyName").then(function(e){return t._update(e.key,e.value)}),e.get("attributes").then(function(e){return t._update(e.key,e.value)}),t._updateReachabilityInfo(e,function(e){return t._update(e.key,e.value)})])}).then(function(){return m.debug("Fetched for",t.identity),t.subscribed="subscribed",t.emit("userSubscribed",t),t}).catch(function(e){throw t.promiseToFetch=null,e}),e.abrupt("return",this.promiseToFetch);case 4:case"end":return e.stop()}},e,this)}))}},{key:"_ensureFetched",value:function(){return this.promiseToFetch||this._fetch()}},{key:"updateAttributes",value:function(e){return d(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0!==e){t.next=4;break}throw new Error("Attributes is required parameter");case 4:if(null!==e){t.next=8;break}throw new Error("Attributes can't be null");case 8:if(e.constructor===Object){t.next=10;break}throw new Error("Attributes must be a valid JSON object");case 10:if("unsubscribed"!=this.subscribed){t.next=12;break}throw new Error("Can't modify unsubscribed object");case 12:return t.next=14,this.services.session.addCommand("editUserAttributes",{username:this.state.identity,attributes:(0,n.default)(e)});case 14:return t.abrupt("return",this);case 15:case"end":return t.stop()}},t,this)}))}},{key:"updateFriendlyName",value:function(e){return d(this,void 0,void 0,i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!e||"string"==typeof e){t.next=2;break}throw new Error("friendlyName must be string or empty");case 2:if("unsubscribed"!=this.subscribed){t.next=4;break}throw new Error("Can't modify unsubscribed object");case 4:return t.next=6,this.services.session.addCommand("editUserFriendlyName",{username:this.state.identity,friendlyName:e});case 6:return t.abrupt("return",this);case 7:case"end":return t.stop()}},t,this)}))}},{key:"unsubscribe",value:function(){return d(this,void 0,void 0,i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.promiseToFetch){e.next=7;break}return e.next=3,this.promiseToFetch;case 3:this.entity.close(),this.promiseToFetch=null,this.subscribed="unsubscribed",this.emit("userUnsubscribed",this);case 7:case"end":return e.stop()}},e,this)}))}},{key:"identity",get:function(){return this.state.identity},set:function(e){this.state.identity=e}},{key:"entityName",set:function(e){this.state.entityName=e}},{key:"attributes",get:function(){return this.state.attributes}},{key:"friendlyName",get:function(){return this.state.friendlyName}},{key:"online",get:function(){return this.state.online}},{key:"notifiable",get:function(){return this.state.notifiable}},{key:"isSubscribed",get:function(){return"subscribed"==this.subscribed}}]),t}(p.EventEmitter);r.User=v},{"./logger":14,"./util":30,"babel-runtime/core-js/json/stringify":34,"babel-runtime/core-js/object/get-prototype-of":41,"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,"babel-runtime/helpers/inherits":53,"babel-runtime/helpers/possibleConstructorReturn":54,"babel-runtime/regenerator":58,events:202}],28:[function(e,t,r){"use strict";var n=s(e("babel-runtime/helpers/classCallCheck")),i=s(e("babel-runtime/helpers/createClass"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var a=e("./logger").Logger.scope("UserDescriptor");var o=function(){function e(t,r){(0,n.default)(this,e),this.services=t,this.descriptor=r,this.identity=r.identity,this.friendlyName=r.friendly_name,this.attributes=function(e){try{return JSON.parse(e)}catch(e){a.warn("Failed to parse user attributes",e)}return{}}(r.attributes),this.online=r.is_online,this.notifiable=r.is_notifiable}return(0,i.default)(e,[{key:"subscribe",value:function(){return this.services.users.getUser(this.identity,this.descriptor.sync_unique_name)}},{key:"_getDescriptor",value:function(){return this.descriptor}}]),e}();r.UserDescriptor=o},{"./logger":14,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51}],29:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/promise")),i=a(e("babel-runtime/helpers/classCallCheck")),s=a(e("babel-runtime/helpers/createClass"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(){var t=this;(0,i.default)(this,e),this._promise=new n.default(function(e,r){t._resolve=e,t._reject=r})}return(0,s.default)(e,[{key:"update",value:function(e){this._resolve(e)}},{key:"set",value:function(e){this.current=e,this._resolve(e)}},{key:"fail",value:function(e){this._reject(e)}},{key:"promise",get:function(){return this._promise}}]),e}();r.Deferred=o},{"babel-runtime/core-js/promise":44,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51}],30:[function(e,t,r){"use strict";var n=a(e("babel-runtime/helpers/classCallCheck")),i=a(e("babel-runtime/helpers/createClass")),s=a(e("babel-runtime/core-js/json/stringify"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=e("rfc6902");r.isDeepEqual=function(e,t){return 0===o.createPatch(e,t).length},r.deepClone=function(e){return JSON.parse((0,s.default)(e))},r.parseToNumber=function(e){return void 0===e||isNaN(Number(e))?null:Number(e)},r.parseTime=function(e){try{return new Date(e)}catch(e){return null}},r.parseAttributes=function(e,t,r){var n={};if(e)try{n=JSON.parse(e)}catch(e){r.warn(t)}return n};var u=function(){function e(t){(0,n.default)(this,e),this.base=t.replace(/\/$/,""),this.args=[],this.paths=[]}return(0,i.default)(e,[{key:"arg",value:function(e,t){return void 0!==t&&this.args.push(encodeURIComponent(e)+"="+encodeURIComponent(t)),this}},{key:"path",value:function(e){return this.paths.push(encodeURIComponent(e)),this}},{key:"build",value:function(){var e=this.base;return this.paths.length&&(e+="/"+this.paths.join("/")),this.args.length&&(e+="?"+this.args.join("&")),e}}]),e}();r.UriBuilder=u},{"babel-runtime/core-js/json/stringify":34,"babel-runtime/helpers/classCallCheck":50,"babel-runtime/helpers/createClass":51,rfc6902:219}],31:[function(e,t,r){t.exports={default:e("core-js/library/fn/array/from"),__esModule:!0}},{"core-js/library/fn/array/from":66}],32:[function(e,t,r){t.exports={default:e("core-js/library/fn/get-iterator"),__esModule:!0}},{"core-js/library/fn/get-iterator":67}],33:[function(e,t,r){t.exports={default:e("core-js/library/fn/is-iterable"),__esModule:!0}},{"core-js/library/fn/is-iterable":68}],34:[function(e,t,r){t.exports={default:e("core-js/library/fn/json/stringify"),__esModule:!0}},{"core-js/library/fn/json/stringify":69}],35:[function(e,t,r){t.exports={default:e("core-js/library/fn/map"),__esModule:!0}},{"core-js/library/fn/map":70}],36:[function(e,t,r){t.exports={default:e("core-js/library/fn/number/is-integer"),__esModule:!0}},{"core-js/library/fn/number/is-integer":71}],37:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/assign"),__esModule:!0}},{"core-js/library/fn/object/assign":72}],38:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/create"),__esModule:!0}},{"core-js/library/fn/object/create":73}],39:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/define-property"),__esModule:!0}},{"core-js/library/fn/object/define-property":74}],40:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/get-own-property-descriptor"),__esModule:!0}},{"core-js/library/fn/object/get-own-property-descriptor":75}],41:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/get-prototype-of"),__esModule:!0}},{"core-js/library/fn/object/get-prototype-of":76}],42:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/keys"),__esModule:!0}},{"core-js/library/fn/object/keys":77}],43:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/set-prototype-of"),__esModule:!0}},{"core-js/library/fn/object/set-prototype-of":78}],44:[function(e,t,r){t.exports={default:e("core-js/library/fn/promise"),__esModule:!0}},{"core-js/library/fn/promise":79}],45:[function(e,t,r){t.exports={default:e("core-js/library/fn/reflect/construct"),__esModule:!0}},{"core-js/library/fn/reflect/construct":80}],46:[function(e,t,r){t.exports={default:e("core-js/library/fn/set"),__esModule:!0}},{"core-js/library/fn/set":81}],47:[function(e,t,r){t.exports={default:e("core-js/library/fn/symbol"),__esModule:!0}},{"core-js/library/fn/symbol":82}],48:[function(e,t,r){t.exports={default:e("core-js/library/fn/symbol/iterator"),__esModule:!0}},{"core-js/library/fn/symbol/iterator":83}],49:[function(e,t,r){"use strict";r.__esModule=!0;var n,i=e("../core-js/promise"),s=(n=i)&&n.__esModule?n:{default:n};r.default=function(e){return function(){var t=e.apply(this,arguments);return new s.default(function(e,r){return function n(i,a){try{var o=t[i](a),u=o.value}catch(e){return void r(e)}if(!o.done)return s.default.resolve(u).then(function(e){n("next",e)},function(e){n("throw",e)});e(u)}("next")})}}},{"../core-js/promise":44}],50:[function(e,t,r){"use strict";r.__esModule=!0,r.default=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},{}],51:[function(e,t,r){"use strict";r.__esModule=!0;var n,i=e("../core-js/object/define-property"),s=(n=i)&&n.__esModule?n:{default:n};r.default=function(){function e(e,t){for(var r=0;r0,"Expected a maximum number of retry greater than 0 but got %s.",e),this.maxNumberOfRetry_=e},s.prototype.backoff=function(e){i.checkState(-1===this.timeoutID_,"Backoff in progress."),this.backoffNumber_===this.maxNumberOfRetry_?(this.emit("fail",e),this.reset()):(this.backoffDelay_=this.backoffStrategy_.next(),this.timeoutID_=setTimeout(this.handlers.backoff,this.backoffDelay_),this.emit("backoff",this.backoffNumber_,this.backoffDelay_,e))},s.prototype.onBackoff_=function(){this.timeoutID_=-1,this.emit("ready",this.backoffNumber_,this.backoffDelay_),this.backoffNumber_++},s.prototype.reset=function(){this.backoffNumber_=0,this.backoffStrategy_.reset(),clearTimeout(this.timeoutID_),this.timeoutID_=-1},t.exports=s},{events:202,precond:210,util:293}],61:[function(e,t,r){
// Copyright (c) 2012 Mathieu Turcotte
// Licensed under the MIT license.
var n=e("events"),i=e("precond"),s=e("util"),a=e("./backoff"),o=e("./strategy/fibonacci");function u(e,t,r){n.EventEmitter.call(this),i.checkIsFunction(e,"Expected fn to be a function."),i.checkIsArray(t,"Expected args to be an array."),i.checkIsFunction(r,"Expected callback to be a function."),this.function_=e,this.arguments_=t,this.callback_=r,this.lastResult_=[],this.numRetries_=0,this.backoff_=null,this.strategy_=null,this.failAfter_=-1,this.retryPredicate_=u.DEFAULT_RETRY_PREDICATE_,this.state_=u.State_.PENDING}s.inherits(u,n.EventEmitter),u.State_={PENDING:0,RUNNING:1,COMPLETED:2,ABORTED:3},u.DEFAULT_RETRY_PREDICATE_=function(e){return!0},u.prototype.isPending=function(){return this.state_==u.State_.PENDING},u.prototype.isRunning=function(){return this.state_==u.State_.RUNNING},u.prototype.isCompleted=function(){return this.state_==u.State_.COMPLETED},u.prototype.isAborted=function(){return this.state_==u.State_.ABORTED},u.prototype.setStrategy=function(e){return i.checkState(this.isPending(),"FunctionCall in progress."),this.strategy_=e,this},u.prototype.retryIf=function(e){return i.checkState(this.isPending(),"FunctionCall in progress."),this.retryPredicate_=e,this},u.prototype.getLastResult=function(){return this.lastResult_.concat()},u.prototype.getNumRetries=function(){return this.numRetries_},u.prototype.failAfter=function(e){return i.checkState(this.isPending(),"FunctionCall in progress."),this.failAfter_=e,this},u.prototype.abort=function(){this.isCompleted()||this.isAborted()||(this.isRunning()&&this.backoff_.reset(),this.state_=u.State_.ABORTED,this.lastResult_=[new Error("Backoff aborted.")],this.emit("abort"),this.doCallback_())},u.prototype.start=function(e){i.checkState(!this.isAborted(),"FunctionCall is aborted."),i.checkState(this.isPending(),"FunctionCall already started.");var t=this.strategy_||new o;this.backoff_=e?e(t):new a(t),this.backoff_.on("ready",this.doCall_.bind(this,!0)),this.backoff_.on("fail",this.doCallback_.bind(this)),this.backoff_.on("backoff",this.handleBackoff_.bind(this)),this.failAfter_>0&&this.backoff_.failAfter(this.failAfter_),this.state_=u.State_.RUNNING,this.doCall_(!1)},u.prototype.doCall_=function(e){e&&this.numRetries_++;var t=["call"].concat(this.arguments_);n.EventEmitter.prototype.emit.apply(this,t);var r=this.handleFunctionCallback_.bind(this);this.function_.apply(null,this.arguments_.concat(r))},u.prototype.doCallback_=function(){this.callback_.apply(null,this.lastResult_)},u.prototype.handleFunctionCallback_=function(){if(!this.isAborted()){var e=Array.prototype.slice.call(arguments);this.lastResult_=e,n.EventEmitter.prototype.emit.apply(this,["callback"].concat(e));var t=e[0];t&&this.retryPredicate_(t)?this.backoff_.backoff(t):(this.state_=u.State_.COMPLETED,this.doCallback_())}},u.prototype.handleBackoff_=function(e,t,r){this.emit("backoff",e,t,r)},t.exports=u},{"./backoff":60,"./strategy/fibonacci":63,events:202,precond:210,util:293}],62:[function(e,t,r){
// Copyright (c) 2012 Mathieu Turcotte
// Licensed under the MIT license.
var n=e("util"),i=e("precond"),s=e("./strategy");function a(e){s.call(this,e),this.backoffDelay_=0,this.nextBackoffDelay_=this.getInitialDelay(),this.factor_=a.DEFAULT_FACTOR,e&&void 0!==e.factor&&(i.checkArgument(e.factor>1,"Exponential factor should be greater than 1 but got %s.",e.factor),this.factor_=e.factor)}n.inherits(a,s),a.DEFAULT_FACTOR=2,a.prototype.next_=function(){return this.backoffDelay_=Math.min(this.nextBackoffDelay_,this.getMaxDelay()),this.nextBackoffDelay_=this.backoffDelay_*this.factor_,this.backoffDelay_},a.prototype.reset_=function(){this.backoffDelay_=0,this.nextBackoffDelay_=this.getInitialDelay()},t.exports=a},{"./strategy":64,precond:210,util:293}],63:[function(e,t,r){
// Copyright (c) 2012 Mathieu Turcotte
// Licensed under the MIT license.
var n=e("util"),i=e("./strategy");function s(e){i.call(this,e),this.backoffDelay_=0,this.nextBackoffDelay_=this.getInitialDelay()}n.inherits(s,i),s.prototype.next_=function(){var e=Math.min(this.nextBackoffDelay_,this.getMaxDelay());return this.nextBackoffDelay_+=this.backoffDelay_,this.backoffDelay_=e,e},s.prototype.reset_=function(){this.nextBackoffDelay_=this.getInitialDelay(),this.backoffDelay_=0},t.exports=s},{"./strategy":64,util:293}],64:[function(e,t,r){
// Copyright (c) 2012 Mathieu Turcotte
// Licensed under the MIT license.
e("events"),e("util");function n(e){return null!=e}function i(e){if(n((e=e||{}).initialDelay)&&e.initialDelay<1)throw new Error("The initial timeout must be greater than 0.");if(n(e.maxDelay)&&e.maxDelay<1)throw new Error("The maximal timeout must be greater than 0.");if(this.initialDelay_=e.initialDelay||100,this.maxDelay_=e.maxDelay||1e4,this.maxDelay_<=this.initialDelay_)throw new Error("The maximal backoff delay must be greater than the initial backoff delay.");if(n(e.randomisationFactor)&&(e.randomisationFactor<0||e.randomisationFactor>1))throw new Error("The randomisation factor must be between 0 and 1.");this.randomisationFactor_=e.randomisationFactor||0}i.prototype.getMaxDelay=function(){return this.maxDelay_},i.prototype.getInitialDelay=function(){return this.initialDelay_},i.prototype.next=function(){var e=this.next_(),t=1+Math.random()*this.randomisationFactor_;return Math.round(e*t)},i.prototype.next_=function(){throw new Error("BackoffStrategy.next_() unimplemented.")},i.prototype.reset=function(){this.reset_()},i.prototype.reset_=function(){throw new Error("BackoffStrategy.reset_() unimplemented.")},t.exports=i},{events:202,util:293}],65:[function(e,t,r){},{}],66:[function(e,t,r){e("../../modules/es6.string.iterator"),e("../../modules/es6.array.from"),t.exports=e("../../modules/_core").Array.from},{"../../modules/_core":99,"../../modules/es6.array.from":174,"../../modules/es6.string.iterator":189}],67:[function(e,t,r){e("../modules/web.dom.iterable"),e("../modules/es6.string.iterator"),t.exports=e("../modules/core.get-iterator")},{"../modules/core.get-iterator":172,"../modules/es6.string.iterator":189,"../modules/web.dom.iterable":201}],68:[function(e,t,r){e("../modules/web.dom.iterable"),e("../modules/es6.string.iterator"),t.exports=e("../modules/core.is-iterable")},{"../modules/core.is-iterable":173,"../modules/es6.string.iterator":189,"../modules/web.dom.iterable":201}],69:[function(e,t,r){var n=e("../../modules/_core"),i=n.JSON||(n.JSON={stringify:JSON.stringify});t.exports=function(e){return i.stringify.apply(i,arguments)}},{"../../modules/_core":99}],70:[function(e,t,r){e("../modules/es6.object.to-string"),e("../modules/es6.string.iterator"),e("../modules/web.dom.iterable"),e("../modules/es6.map"),e("../modules/es7.map.to-json"),e("../modules/es7.map.of"),e("../modules/es7.map.from"),t.exports=e("../modules/_core").Map},{"../modules/_core":99,"../modules/es6.map":176,"../modules/es6.object.to-string":185,"../modules/es6.string.iterator":189,"../modules/es7.map.from":191,"../modules/es7.map.of":192,"../modules/es7.map.to-json":193,"../modules/web.dom.iterable":201}],71:[function(e,t,r){e("../../modules/es6.number.is-integer"),t.exports=e("../../modules/_core").Number.isInteger},{"../../modules/_core":99,"../../modules/es6.number.is-integer":177}],72:[function(e,t,r){e("../../modules/es6.object.assign"),t.exports=e("../../modules/_core").Object.assign},{"../../modules/_core":99,"../../modules/es6.object.assign":178}],73:[function(e,t,r){e("../../modules/es6.object.create");var n=e("../../modules/_core").Object;t.exports=function(e,t){return n.create(e,t)}},{"../../modules/_core":99,"../../modules/es6.object.create":179}],74:[function(e,t,r){e("../../modules/es6.object.define-property");var n=e("../../modules/_core").Object;t.exports=function(e,t,r){return n.defineProperty(e,t,r)}},{"../../modules/_core":99,"../../modules/es6.object.define-property":180}],75:[function(e,t,r){e("../../modules/es6.object.get-own-property-descriptor");var n=e("../../modules/_core").Object;t.exports=function(e,t){return n.getOwnPropertyDescriptor(e,t)}},{"../../modules/_core":99,"../../modules/es6.object.get-own-property-descriptor":181}],76:[function(e,t,r){e("../../modules/es6.object.get-prototype-of"),t.exports=e("../../modules/_core").Object.getPrototypeOf},{"../../modules/_core":99,"../../modules/es6.object.get-prototype-of":182}],77:[function(e,t,r){e("../../modules/es6.object.keys"),t.exports=e("../../modules/_core").Object.keys},{"../../modules/_core":99,"../../modules/es6.object.keys":183}],78:[function(e,t,r){e("../../modules/es6.object.set-prototype-of"),t.exports=e("../../modules/_core").Object.setPrototypeOf},{"../../modules/_core":99,"../../modules/es6.object.set-prototype-of":184}],79:[function(e,t,r){e("../modules/es6.object.to-string"),e("../modules/es6.string.iterator"),e("../modules/web.dom.iterable"),e("../modules/es6.promise"),e("../modules/es7.promise.finally"),e("../modules/es7.promise.try"),t.exports=e("../modules/_core").Promise},{"../modules/_core":99,"../modules/es6.object.to-string":185,"../modules/es6.promise":186,"../modules/es6.string.iterator":189,"../modules/es7.promise.finally":194,"../modules/es7.promise.try":195,"../modules/web.dom.iterable":201}],80:[function(e,t,r){e("../../modules/es6.reflect.construct"),t.exports=e("../../modules/_core").Reflect.construct},{"../../modules/_core":99,"../../modules/es6.reflect.construct":187}],81:[function(e,t,r){e("../modules/es6.object.to-string"),e("../modules/es6.string.iterator"),e("../modules/web.dom.iterable"),e("../modules/es6.set"),e("../modules/es7.set.to-json"),e("../modules/es7.set.of"),e("../modules/es7.set.from"),t.exports=e("../modules/_core").Set},{"../modules/_core":99,"../modules/es6.object.to-string":185,"../modules/es6.set":188,"../modules/es6.string.iterator":189,"../modules/es7.set.from":196,"../modules/es7.set.of":197,"../modules/es7.set.to-json":198,"../modules/web.dom.iterable":201}],82:[function(e,t,r){e("../../modules/es6.symbol"),e("../../modules/es6.object.to-string"),e("../../modules/es7.symbol.async-iterator"),e("../../modules/es7.symbol.observable"),t.exports=e("../../modules/_core").Symbol},{"../../modules/_core":99,"../../modules/es6.object.to-string":185,"../../modules/es6.symbol":190,"../../modules/es7.symbol.async-iterator":199,"../../modules/es7.symbol.observable":200}],83:[function(e,t,r){e("../../modules/es6.string.iterator"),e("../../modules/web.dom.iterable"),t.exports=e("../../modules/_wks-ext").f("iterator")},{"../../modules/_wks-ext":169,"../../modules/es6.string.iterator":189,"../../modules/web.dom.iterable":201}],84:[function(e,t,r){t.exports=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e}},{}],85:[function(e,t,r){t.exports=function(){}},{}],86:[function(e,t,r){t.exports=function(e,t,r,n){if(!(e instanceof t)||void 0!==n&&n in e)throw TypeError(r+": incorrect invocation!");return e}},{}],87:[function(e,t,r){var n=e("./_is-object");t.exports=function(e){if(!n(e))throw TypeError(e+" is not an object!");return e}},{"./_is-object":120}],88:[function(e,t,r){var n=e("./_for-of");t.exports=function(e,t){var r=[];return n(e,!1,r.push,r,t),r}},{"./_for-of":109}],89:[function(e,t,r){var n=e("./_to-iobject"),i=e("./_to-length"),s=e("./_to-absolute-index");t.exports=function(e){return function(t,r,a){var o,u=n(t),c=i(u.length),l=s(a,c);if(e&&r!=r){for(;c>l;)if((o=u[l++])!=o)return!0}else for(;c>l;l++)if((e||l in u)&&u[l]===r)return e||l||0;return!e&&-1}}},{"./_to-absolute-index":159,"./_to-iobject":161,"./_to-length":162}],90:[function(e,t,r){var n=e("./_ctx"),i=e("./_iobject"),s=e("./_to-object"),a=e("./_to-length"),o=e("./_array-species-create");t.exports=function(e,t){var r=1==e,u=2==e,c=3==e,l=4==e,f=6==e,d=5==e||f,p=t||o;return function(t,o,h){for(var b,m,v=s(t),y=i(v),g=n(o,h,3),_=a(y.length),k=0,w=r?p(t,_):u?p(t,0):void 0;_>k;k++)if((d||k in y)&&(m=g(b=y[k],k,v),e))if(r)w[k]=m;else if(m)switch(e){case 3:return!0;case 5:return b;case 6:return k;case 2:w.push(b)}else if(l)return!1;return f?-1:c||l?l:w}}},{"./_array-species-create":92,"./_ctx":101,"./_iobject":116,"./_to-length":162,"./_to-object":163}],91:[function(e,t,r){var n=e("./_is-object"),i=e("./_is-array"),s=e("./_wks")("species");t.exports=function(e){var t;return i(e)&&("function"!=typeof(t=e.constructor)||t!==Array&&!i(t.prototype)||(t=void 0),n(t)&&null===(t=t[s])&&(t=void 0)),void 0===t?Array:t}},{"./_is-array":118,"./_is-object":120,"./_wks":170}],92:[function(e,t,r){var n=e("./_array-species-constructor");t.exports=function(e,t){return new(n(e))(t)}},{"./_array-species-constructor":91}],93:[function(e,t,r){"use strict";var n=e("./_a-function"),i=e("./_is-object"),s=e("./_invoke"),a=[].slice,o={};t.exports=Function.bind||function(e){var t=n(this),r=a.call(arguments,1),u=function(){var n=r.concat(a.call(arguments));return this instanceof u?function(e,t,r){if(!(t in o)){for(var n=[],i=0;i1?arguments[1]:void 0,3);r=r?r.n:this._f;)for(n(r.v,r.k,this);r&&r.r;)r=r.p},has:function(e){return!!m(h(this,t),e)}}),d&&n(l.prototype,"size",{get:function(){return h(this,t)[b]}}),l},def:function(e,t,r){var n,i,s=m(e,t);return s?s.v=r:(e._l=s={i:i=p(t,!0),k:t,v:r,p:n=e._l,n:void 0,r:!1},e._f||(e._f=s),n&&(n.n=s),e[b]++,"F"!==i&&(e._i[i]=s)),e},getEntry:m,setStrong:function(e,t,r){c(e,t,function(e,r){this._t=h(e,t),this._k=r,this._l=void 0},function(){for(var e=this._k,t=this._l;t&&t.r;)t=t.p;return this._t&&(this._l=t=t?t.n:this._t._f)?l(0,"keys"==e?t.k:"values"==e?t.v:[t.k,t.v]):(this._t=void 0,l(1))},r?"entries":"values",!r,!0),f(t)}}},{"./_an-instance":86,"./_ctx":101,"./_descriptors":103,"./_for-of":109,"./_iter-define":123,"./_iter-step":125,"./_meta":128,"./_object-create":132,"./_object-dp":133,"./_redefine-all":147,"./_set-species":152,"./_validate-collection":167}],97:[function(e,t,r){var n=e("./_classof"),i=e("./_array-from-iterable");t.exports=function(e){return function(){if(n(this)!=e)throw TypeError(e+"#toJSON isn't generic");return i(this)}}},{"./_array-from-iterable":88,"./_classof":94}],98:[function(e,t,r){"use strict";var n=e("./_global"),i=e("./_export"),s=e("./_meta"),a=e("./_fails"),o=e("./_hide"),u=e("./_redefine-all"),c=e("./_for-of"),l=e("./_an-instance"),f=e("./_is-object"),d=e("./_set-to-string-tag"),p=e("./_object-dp").f,h=e("./_array-methods")(0),b=e("./_descriptors");t.exports=function(e,t,r,m,v,y){var g=n[e],_=g,k=v?"set":"add",w=_&&_.prototype,x={};return b&&"function"==typeof _&&(y||w.forEach&&!a(function(){(new _).entries().next()}))?(_=t(function(t,r){l(t,_,e,"_c"),t._c=new g,null!=r&&c(r,v,t[k],t)}),h("add,clear,delete,forEach,get,has,set,keys,values,entries,toJSON".split(","),function(e){var t="add"==e||"set"==e;e in w&&(!y||"clear"!=e)&&o(_.prototype,e,function(r,n){if(l(this,_,e),!t&&y&&!f(r))return"get"==e&&void 0;var i=this._c[e](0===r?0:r,n);return t?this:i})}),y||p(_.prototype,"size",{get:function(){return this._c.size}})):(_=m.getConstructor(t,e,v,k),u(_.prototype,r),s.NEED=!0),d(_,e),x[e]=_,i(i.G+i.W+i.F,x),y||m.setStrong(_,e,v),_}},{"./_an-instance":86,"./_array-methods":90,"./_descriptors":103,"./_export":107,"./_fails":108,"./_for-of":109,"./_global":110,"./_hide":112,"./_is-object":120,"./_meta":128,"./_object-dp":133,"./_redefine-all":147,"./_set-to-string-tag":153}],99:[function(e,t,r){var n=t.exports={version:"2.6.5"};"number"==typeof __e&&(__e=n)},{}],100:[function(e,t,r){"use strict";var n=e("./_object-dp"),i=e("./_property-desc");t.exports=function(e,t,r){t in e?n.f(e,t,i(0,r)):e[t]=r}},{"./_object-dp":133,"./_property-desc":146}],101:[function(e,t,r){var n=e("./_a-function");t.exports=function(e,t,r){if(n(e),void 0===t)return e;switch(r){case 1:return function(r){return e.call(t,r)};case 2:return function(r,n){return e.call(t,r,n)};case 3:return function(r,n,i){return e.call(t,r,n,i)}}return function(){return e.apply(t,arguments)}}},{"./_a-function":84}],102:[function(e,t,r){t.exports=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e}},{}],103:[function(e,t,r){t.exports=!e("./_fails")(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},{"./_fails":108}],104:[function(e,t,r){var n=e("./_is-object"),i=e("./_global").document,s=n(i)&&n(i.createElement);t.exports=function(e){return s?i.createElement(e):{}}},{"./_global":110,"./_is-object":120}],105:[function(e,t,r){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},{}],106:[function(e,t,r){var n=e("./_object-keys"),i=e("./_object-gops"),s=e("./_object-pie");t.exports=function(e){var t=n(e),r=i.f;if(r)for(var a,o=r(e),u=s.f,c=0;o.length>c;)u.call(e,a=o[c++])&&t.push(a);return t}},{"./_object-gops":138,"./_object-keys":141,"./_object-pie":142}],107:[function(e,t,r){var n=e("./_global"),i=e("./_core"),s=e("./_ctx"),a=e("./_hide"),o=e("./_has"),u=function(e,t,r){var c,l,f,d=e&u.F,p=e&u.G,h=e&u.S,b=e&u.P,m=e&u.B,v=e&u.W,y=p?i:i[t]||(i[t]={}),g=y.prototype,_=p?n:h?n[t]:(n[t]||{}).prototype;for(c in p&&(r=t),r)(l=!d&&_&&void 0!==_[c])&&o(y,c)||(f=l?_[c]:r[c],y[c]=p&&"function"!=typeof _[c]?r[c]:m&&l?s(f,n):v&&_[c]==f?function(e){var t=function(t,r,n){if(this instanceof e){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,r)}return new e(t,r,n)}return e.apply(this,arguments)};return t.prototype=e.prototype,t}(f):b&&"function"==typeof f?s(Function.call,f):f,b&&((y.virtual||(y.virtual={}))[c]=f,e&u.R&&g&&!g[c]&&a(g,c,f)))};u.F=1,u.G=2,u.S=4,u.P=8,u.B=16,u.W=32,u.U=64,u.R=128,t.exports=u},{"./_core":99,"./_ctx":101,"./_global":110,"./_has":111,"./_hide":112}],108:[function(e,t,r){t.exports=function(e){try{return!!e()}catch(e){return!0}}},{}],109:[function(e,t,r){var n=e("./_ctx"),i=e("./_iter-call"),s=e("./_is-array-iter"),a=e("./_an-object"),o=e("./_to-length"),u=e("./core.get-iterator-method"),c={},l={};(r=t.exports=function(e,t,r,f,d){var p,h,b,m,v=d?function(){return e}:u(e),y=n(r,f,t?2:1),g=0;if("function"!=typeof v)throw TypeError(e+" is not iterable!");if(s(v)){for(p=o(e.length);p>g;g++)if((m=t?y(a(h=e[g])[0],h[1]):y(e[g]))===c||m===l)return m}else for(b=v.call(e);!(h=b.next()).done;)if((m=i(b,y,h.value,t))===c||m===l)return m}).BREAK=c,r.RETURN=l},{"./_an-object":87,"./_ctx":101,"./_is-array-iter":117,"./_iter-call":121,"./_to-length":162,"./core.get-iterator-method":171}],110:[function(e,t,r){var n=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},{}],111:[function(e,t,r){var n={}.hasOwnProperty;t.exports=function(e,t){return n.call(e,t)}},{}],112:[function(e,t,r){var n=e("./_object-dp"),i=e("./_property-desc");t.exports=e("./_descriptors")?function(e,t,r){return n.f(e,t,i(1,r))}:function(e,t,r){return e[t]=r,e}},{"./_descriptors":103,"./_object-dp":133,"./_property-desc":146}],113:[function(e,t,r){var n=e("./_global").document;t.exports=n&&n.documentElement},{"./_global":110}],114:[function(e,t,r){t.exports=!e("./_descriptors")&&!e("./_fails")(function(){return 7!=Object.defineProperty(e("./_dom-create")("div"),"a",{get:function(){return 7}}).a})},{"./_descriptors":103,"./_dom-create":104,"./_fails":108}],115:[function(e,t,r){t.exports=function(e,t,r){var n=void 0===r;switch(t.length){case 0:return n?e():e.call(r);case 1:return n?e(t[0]):e.call(r,t[0]);case 2:return n?e(t[0],t[1]):e.call(r,t[0],t[1]);case 3:return n?e(t[0],t[1],t[2]):e.call(r,t[0],t[1],t[2]);case 4:return n?e(t[0],t[1],t[2],t[3]):e.call(r,t[0],t[1],t[2],t[3])}return e.apply(r,t)}},{}],116:[function(e,t,r){var n=e("./_cof");t.exports=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==n(e)?e.split(""):Object(e)}},{"./_cof":95}],117:[function(e,t,r){var n=e("./_iterators"),i=e("./_wks")("iterator"),s=Array.prototype;t.exports=function(e){return void 0!==e&&(n.Array===e||s[i]===e)}},{"./_iterators":126,"./_wks":170}],118:[function(e,t,r){var n=e("./_cof");t.exports=Array.isArray||function(e){return"Array"==n(e)}},{"./_cof":95}],119:[function(e,t,r){var n=e("./_is-object"),i=Math.floor;t.exports=function(e){return!n(e)&&isFinite(e)&&i(e)===e}},{"./_is-object":120}],120:[function(e,t,r){t.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},{}],121:[function(e,t,r){var n=e("./_an-object");t.exports=function(e,t,r,i){try{return i?t(n(r)[0],r[1]):t(r)}catch(t){var s=e.return;throw void 0!==s&&n(s.call(e)),t}}},{"./_an-object":87}],122:[function(e,t,r){"use strict";var n=e("./_object-create"),i=e("./_property-desc"),s=e("./_set-to-string-tag"),a={};e("./_hide")(a,e("./_wks")("iterator"),function(){return this}),t.exports=function(e,t,r){e.prototype=n(a,{next:i(1,r)}),s(e,t+" Iterator")}},{"./_hide":112,"./_object-create":132,"./_property-desc":146,"./_set-to-string-tag":153,"./_wks":170}],123:[function(e,t,r){"use strict";var n=e("./_library"),i=e("./_export"),s=e("./_redefine"),a=e("./_hide"),o=e("./_iterators"),u=e("./_iter-create"),c=e("./_set-to-string-tag"),l=e("./_object-gpo"),f=e("./_wks")("iterator"),d=!([].keys&&"next"in[].keys()),p=function(){return this};t.exports=function(e,t,r,h,b,m,v){u(r,t,h);var y,g,_,k=function(e){if(!d&&e in j)return j[e];switch(e){case"keys":case"values":return function(){return new r(this,e)}}return function(){return new r(this,e)}},w=t+" Iterator",x="values"==b,C=!1,j=e.prototype,S=j[f]||j["@@iterator"]||b&&j[b],T=S||k(b),E=b?x?k("entries"):T:void 0,M="Array"==t&&j.entries||S;if(M&&(_=l(M.call(new e)))!==Object.prototype&&_.next&&(c(_,w,!0),n||"function"==typeof _[f]||a(_,f,p)),x&&S&&"values"!==S.name&&(C=!0,T=function(){return S.call(this)}),n&&!v||!d&&!C&&j[f]||a(j,f,T),o[t]=T,o[w]=p,b)if(y={values:x?T:k("values"),keys:m?T:k("keys"),entries:E},v)for(g in y)g in j||s(j,g,y[g]);else i(i.P+i.F*(d||C),t,y);return y}},{"./_export":107,"./_hide":112,"./_iter-create":122,"./_iterators":126,"./_library":127,"./_object-gpo":139,"./_redefine":148,"./_set-to-string-tag":153,"./_wks":170}],124:[function(e,t,r){var n=e("./_wks")("iterator"),i=!1;try{var s=[7][n]();s.return=function(){i=!0},Array.from(s,function(){throw 2})}catch(e){}t.exports=function(e,t){if(!t&&!i)return!1;var r=!1;try{var s=[7],a=s[n]();a.next=function(){return{done:r=!0}},s[n]=function(){return a},e(s)}catch(e){}return r}},{"./_wks":170}],125:[function(e,t,r){t.exports=function(e,t){return{value:t,done:!!e}}},{}],126:[function(e,t,r){t.exports={}},{}],127:[function(e,t,r){t.exports=!0},{}],128:[function(e,t,r){var n=e("./_uid")("meta"),i=e("./_is-object"),s=e("./_has"),a=e("./_object-dp").f,o=0,u=Object.isExtensible||function(){return!0},c=!e("./_fails")(function(){return u(Object.preventExtensions({}))}),l=function(e){a(e,n,{value:{i:"O"+ ++o,w:{}}})},f=t.exports={KEY:n,NEED:!1,fastKey:function(e,t){if(!i(e))return"symbol"==typeof e?e:("string"==typeof e?"S":"P")+e;if(!s(e,n)){if(!u(e))return"F";if(!t)return"E";l(e)}return e[n].i},getWeak:function(e,t){if(!s(e,n)){if(!u(e))return!0;if(!t)return!1;l(e)}return e[n].w},onFreeze:function(e){return c&&f.NEED&&u(e)&&!s(e,n)&&l(e),e}}},{"./_fails":108,"./_has":111,"./_is-object":120,"./_object-dp":133,"./_uid":165}],129:[function(e,t,r){var n=e("./_global"),i=e("./_task").set,s=n.MutationObserver||n.WebKitMutationObserver,a=n.process,o=n.Promise,u="process"==e("./_cof")(a);t.exports=function(){var e,t,r,c=function(){var n,i;for(u&&(n=a.domain)&&n.exit();e;){i=e.fn,e=e.next;try{i()}catch(n){throw e?r():t=void 0,n}}t=void 0,n&&n.enter()};if(u)r=function(){a.nextTick(c)};else if(!s||n.navigator&&n.navigator.standalone)if(o&&o.resolve){var l=o.resolve(void 0);r=function(){l.then(c)}}else r=function(){i.call(n,c)};else{var f=!0,d=document.createTextNode("");new s(c).observe(d,{characterData:!0}),r=function(){d.data=f=!f}}return function(n){var i={fn:n,next:void 0};t&&(t.next=i),e||(e=i,r()),t=i}}},{"./_cof":95,"./_global":110,"./_task":158}],130:[function(e,t,r){"use strict";
// 25.4.1.5 NewPromiseCapability(C)
var n=e("./_a-function");function i(e){var t,r;this.promise=new e(function(e,n){if(void 0!==t||void 0!==r)throw TypeError("Bad Promise constructor");t=e,r=n}),this.resolve=n(t),this.reject=n(r)}t.exports.f=function(e){return new i(e)}},{"./_a-function":84}],131:[function(e,t,r){"use strict";var n=e("./_object-keys"),i=e("./_object-gops"),s=e("./_object-pie"),a=e("./_to-object"),o=e("./_iobject"),u=Object.assign;t.exports=!u||e("./_fails")(function(){var e={},t={},r=Symbol(),n="abcdefghijklmnopqrst";return e[r]=7,n.split("").forEach(function(e){t[e]=e}),7!=u({},e)[r]||Object.keys(u({},t)).join("")!=n})?function(e,t){for(var r=a(e),u=arguments.length,c=1,l=i.f,f=s.f;u>c;)for(var d,p=o(arguments[c++]),h=l?n(p).concat(l(p)):n(p),b=h.length,m=0;b>m;)f.call(p,d=h[m++])&&(r[d]=p[d]);return r}:u},{"./_fails":108,"./_iobject":116,"./_object-gops":138,"./_object-keys":141,"./_object-pie":142,"./_to-object":163}],132:[function(e,t,r){var n=e("./_an-object"),i=e("./_object-dps"),s=e("./_enum-bug-keys"),a=e("./_shared-key")("IE_PROTO"),o=function(){},u=function(){var t,r=e("./_dom-create")("iframe"),n=s.length;for(r.style.display="none",e("./_html").appendChild(r),r.src="javascript:",(t=r.contentWindow.document).open(),t.write("