/* @twilio/conversations.js 1.2.0
The following license applies to all parts of this software except as
documented below.
Copyright (c) 2019, 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={})).Conversations=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;a=0;o--)(i=e[o])&&(a=(s<3?i(a):s>3?i(t,r,a):i(t,r))||a);return s>3&&a&&(0,p.default)(t,r,a),a},y=function(e,t){if("object"===("undefined"==typeof Reflect?"undefined":(0,h.default)(Reflect))&&"function"==typeof f.default)return(0,f.default)(e,t)};Object.defineProperty(r,"__esModule",{value:!0});var g=e("events"),_=e("./logger"),k=e("./configuration"),w=e("./user");r.User=w.User;var x=e("./services/network"),C=e("./interfaces/notificationtypes"),j=e("./synclist"),S=e("twilsock"),T=e("twilio-notifications"),E=e("twilio-sync"),I=e("twilio-mcs-client"),M=e("./session"),R=e("./data/conversations"),P=e("./data/users"),O=e("./services/typingindicator"),N=e("./services/readhorizon"),L=e("./pushnotification");r.PushNotification=L.PushNotification;var U=e("./util"),A=e("twilsock/lib/services/telemetrytracker"),D=e("twilio-sdk-type-validator"),F=_.Logger.scope("Client"),q=e("./../package.json").version,B=function e(){(0,d.default)(this,e)},z=function(e){function t(e,r){(0,d.default)(this,t);var n=(0,c.default)(this,(t.__proto__||(0,o.default)(t)).call(this));if(n.connectionState="connecting",n.sessionPromise=null,n.conversationsPromise=null,n.version=q,n.parsePushNotification=t.parsePushNotification,n.options=r||{},!n.options.disableDeepClone){var i=(0,a.default)((0,a.default)({},n.options),{transport:void 0,twilsockClient:void 0});(i=U.deepClone(i)).transport=n.options.transport,i.twilsockClient=n.options.twilsockClient,n.options=i}n.options.logLevel=n.options.logLevel||"silent",F.setLevel(n.options.logLevel);var s=n.options.productId="ip_messaging";if(n.options.clientMetadata=n.options.clientMetadata||{},n.options.clientMetadata.hasOwnProperty("type")||(n.options.clientMetadata.type="conversations"),n.options.clientMetadata.hasOwnProperty("sdk")||(n.options.clientMetadata.sdk="JS",n.options.clientMetadata.sdkv=q),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("A valid Twilio token should be provided");return n.services=new B,n.config=new k.Configuration(n.options),n.options.twilsockClient=n.options.twilsockClient||new S.Twilsock(e,s,n.options),n.options.transport=n.options.transport||n.options.twilsockClient,n.options.notificationsClient=n.options.notificationsClient||new T.Notifications(e,n.options),n.options.syncClient=n.options.syncClient||new E.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 M.Session(n.services,n.config),n.sessionPromise=n.services.session.initialize(),n.services.network=new x.Network(n.config,n.services),n.services.users=new P.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.twilsockClient.on("connectionError",function(e){return n.emit("connectionError",e)}),n.services.readHorizon=new N.ReadHorizon(n.services),n.services.typingIndicator=new O.TypingIndicator(n.config,{transport:n.services.twilsockClient,notificationClient:n.services.notificationClient},n.getConversationBySid.bind(n)),n.services.syncList=new j.SyncList(n.services),n.conversations=new R.Conversations(n.services),n.conversationsPromise=n.sessionPromise.then(function(){return n.conversations.on("conversationAdded",n.emit.bind(n,"conversationAdded")),n.conversations.on("conversationRemoved",n.emit.bind(n,"conversationRemoved")),n.conversations.on("conversationJoined",n.emit.bind(n,"conversationJoined")),n.conversations.on("conversationLeft",n.emit.bind(n,"conversationLeft")),n.conversations.on("conversationUpdated",function(e){return n.emit("conversationUpdated",e)}),n.conversations.on("participantJoined",n.emit.bind(n,"participantJoined")),n.conversations.on("participantLeft",n.emit.bind(n,"participantLeft")),n.conversations.on("participantUpdated",function(e){return n.emit("participantUpdated",e)}),n.conversations.on("messageAdded",n.emit.bind(n,"messageAdded")),n.conversations.on("messageUpdated",function(e){return n.emit("messageUpdated",e)}),n.conversations.on("messageRemoved",n.emit.bind(n,"messageRemoved")),n.conversations.on("typingStarted",n.emit.bind(n,"typingStarted")),n.conversations.on("typingEnded",n.emit.bind(n,"typingEnded")),n.conversations.fetchConversations()}).then(function(){return n.conversations}),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,l.default)(t,e),(0,u.default)(t,[{key:"subscribeToPushNotifications",value:function(e){var t=this,r=[];return[C.NotificationTypes.NEW_MESSAGE,C.NotificationTypes.ADDED_TO_CONVERSATION,C.NotificationTypes.REMOVED_FROM_CONVERSATION,C.NotificationTypes.TYPING_INDICATOR,C.NotificationTypes.CONSUMPTION_UPDATE].forEach(function(n){r.push(t.services.notificationClient.subscribe(n,e))}),s.default.all(r)}},{key:"unsubscribeFromPushNotifications",value:function(e){var t=this,r=[];return[C.NotificationTypes.NEW_MESSAGE,C.NotificationTypes.ADDED_TO_CONVERSATION,C.NotificationTypes.REMOVED_FROM_CONVERSATION,C.NotificationTypes.TYPING_INDICATOR,C.NotificationTypes.CONSUMPTION_UPDATE].forEach(function(n){r.push(t.services.notificationClient.unsubscribe(n,e))}),s.default.all(r)}},{key:"initialize",value:function(){var e=(0,i.default)(n.default.mark(function e(){var r,i,s=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 s.subscribeToPushNotifications(e)}),e.next=5,this.services.session.getSessionLinks();case 5:return r=e.sent,(i=(0,a.default)(this.options)).transport=null,this.services.mcsClient=new I.McsClient(this.fpaToken,r.mediaServiceUrl,i),e.next=11,this.services.typingIndicator.initialize();case 11:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"shutdown",value:function(){var e=(0,i.default)(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)}));return function(){return e.apply(this,arguments)}}()},{key:"updateToken",value:function(){var e=(0,i.default)(n.default.mark(function e(t){var r=this;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(F.info("updateToken"),this.fpaToken!==t){e.next=3;break}return e.abrupt("return",this);case 3:return e.next=5,this.services.twilsockClient.updateToken(t).then(function(){return r.fpaToken=t}).then(function(){return r.services.mcsClient.updateToken(t)}).then(function(){return r.sessionPromise});case 5:return e.abrupt("return",this);case 6:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getConversationBySid",value:function(){var e=(0,i.default)(n.default.mark(function e(t){var r;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.conversations.syncListRead.promise;case 2:return e.next=4,this.conversations.getConversation(t);case 4:if(r=e.sent){e.next=9;break}return e.next=8,this.conversations.getWhisperConversation(t);case 8:r=e.sent;case 9:if(r){e.next=11;break}throw new Error("Conversation with SID "+t+" is not found.");case 11:return e.abrupt("return",r);case 12:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getConversationByUniqueName",value:function(){var e=(0,i.default)(n.default.mark(function e(t){var r;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.conversations.syncListRead.promise;case 2:return e.next=4,this.conversations.getConversationByUniqueName(t);case 4:if(r=e.sent){e.next=7;break}throw new Error("Conversation with unique name "+t+" is not found.");case 7:return e.abrupt("return",r);case 8:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getSubscribedConversations",value:function(e){return this.conversationsPromise.then(function(t){return t.getConversations(e)})}},{key:"createConversation",value:function(e){return e=e||{},this.conversationsPromise.then(function(t){return t.addConversation(e)})}},{key:"setPushRegistrationId",value:function(){var e=(0,i.default)(n.default.mark(function e(t,r){var i=this;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.subscribeToPushNotifications(t).then(function(){return i.services.notificationClient.setPushRegistrationId(r,t)});case 2:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"unsetPushRegistrationId",value:function(){var e=(0,i.default)(n.default.mark(function e(r){return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(-1!==t.supportedPushChannels.indexOf(r)){e.next=2;break}throw new Error("Invalid or unsupported channelType: "+r);case 2:return e.next=4,this.unsubscribeFromPushNotifications(r);case 4:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"handlePushNotification",value:function(){var e=(0,i.default)(n.default.mark(function e(r){return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:F.debug("handlePushNotification, notificationPayload=",r),this.emit("pushNotification",t.parsePushNotification(r));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getUser",value:function(e){return this.services.users.getUser(e)}},{key:"getSubscribedUsers",value:function(){var e=(0,i.default)(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)}));return function(){return e.apply(this,arguments)}}()},{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(){var e=(0,i.default)(n.default.mark(function e(r,i){var s,a;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=new t(r,i),a="conversations.client.startup",s.services.twilsockClient.addPartialTelemetryEvent(new A.TelemetryEventDescription(a,"Conversations client startup",new Date),a,A.TelemetryPoint.Start),e.next=5,s.initialize();case 5:return s.services.twilsockClient.addPartialTelemetryEvent(new A.TelemetryEventDescription("","",new Date),a,A.TelemetryPoint.End),e.abrupt("return",s);case 7:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"parsePushNotificationChatData",value:function(e){var r={};for(var n in t.supportedPushDataFields)void 0!==e[n]&&null!==e[n]&&("message_index"===n?null!==U.parseToNumber(e[n])&&(r[t.supportedPushDataFields[n]]=Number(e[n])):r[t.supportedPushDataFields[n]]=e[n]);return r}},{key:"parsePushNotification",value:function(e){if(F.debug("parsePushNotification, notificationPayload=",e),void 0!==e.aps){if(!e.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var r=t.parsePushNotificationChatData(e),n=e.aps,i=null,s=null;return"string"==typeof n.alert?i=n.alert||null:(i=n.alert.body||null,s=n.alert.title||null),new L.PushNotification({title:s,body:i,sound:n.sound||null,badge:n.badge||null,action:n.category||null,type:e.twi_message_type,data:r})}if(void 0!==e.data){var a=e.data;if(!a.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var o=t.parsePushNotificationChatData(e.data);return new L.PushNotification({title:a.twi_title||null,body:a.twi_body||null,sound:a.twi_sound||null,badge:null,action:a.twi_action||null,type:a.twi_message_type,data:o})}throw new Error("Provided push notification payload is not Programmable Chat notification")}}]),t}(g.EventEmitter);z.version=q,z.supportedPushChannels=["fcm","apn"],z.supportedPushDataFields={conversation_sid:"conversationSid",message_sid:"messageSid",message_index:"messageIndex"},v([D.validateTypesAsync(D.nonEmptyString),y("design:type",Function),y("design:paramtypes",[String]),y("design:returntype",s.default)],z.prototype,"updateToken",null),v([D.validateTypesAsync(D.nonEmptyString),y("design:type",Function),y("design:paramtypes",[String]),y("design:returntype",s.default)],z.prototype,"getConversationBySid",null),v([D.validateTypesAsync(D.nonEmptyString),y("design:type",Function),y("design:paramtypes",[String]),y("design:returntype",s.default)],z.prototype,"getConversationByUniqueName",null),v([D.validateTypesAsync(["undefined",D.objectSchema("conversation options",{friendlyName:["string","undefined"],isPrivate:["boolean","undefined"],uniqueName:["string","undefined"]})]),y("design:type",Function),y("design:paramtypes",[Object]),y("design:returntype",s.default)],z.prototype,"createConversation",null),v([D.validateTypesAsync(D.literal("fcm","apn"),"string"),y("design:type",Function),y("design:paramtypes",[String,String]),y("design:returntype",s.default)],z.prototype,"setPushRegistrationId",null),v([D.validateTypesAsync(D.literal("fcm","apn")),y("design:type",Function),y("design:paramtypes",[String]),y("design:returntype",s.default)],z.prototype,"unsetPushRegistrationId",null),v([D.validateTypesAsync(D.pureObject),y("design:type",Function),y("design:paramtypes",[Object]),y("design:returntype",s.default)],z.prototype,"handlePushNotification",null),v([D.validateTypesAsync(D.nonEmptyString),y("design:type",Function),y("design:paramtypes",[String]),y("design:returntype",s.default)],z.prototype,"getUser",null),v([D.validateTypesAsync("string",["undefined",D.pureObject]),y("design:type",Function),y("design:paramtypes",[String,Object]),y("design:returntype",s.default)],z,"create",null),v([D.validateTypes(D.pureObject),y("design:type",Function),y("design:paramtypes",[Object]),y("design:returntype",L.PushNotification)],z,"parsePushNotification",null),r.Client=z,r.default=z},{"./../package.json":294,"./configuration":3,"./data/conversations":5,"./data/users":8,"./interfaces/notificationtypes":10,"./logger":12,"./pushnotification":16,"./services/network":18,"./services/readhorizon":19,"./services/typingindicator":20,"./session":21,"./synclist":23,"./user":25,"./util":27,"babel-runtime/core-js/object/assign":34,"babel-runtime/core-js/object/define-property":36,"babel-runtime/core-js/object/get-own-property-descriptor":37,"babel-runtime/core-js/object/get-prototype-of":38,"babel-runtime/core-js/promise":41,"babel-runtime/core-js/reflect/metadata":43,"babel-runtime/helpers/asyncToGenerator":47,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/helpers/typeof":55,"babel-runtime/regenerator":56,events:199,"twilio-mcs-client":217,"twilio-notifications":227,"twilio-sdk-type-validator":232,"twilio-sync":240,twilsock:268,"twilsock/lib/services/telemetrytracker":284}],3:[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="/v1/typing",o=function(){function e(t){(0,n.default)(this,e);var r=(t=t||{}).Chat||t.IPMessaging||t||{};this.region=r.region||t.region,this.baseUrl=r.apiUri||r.typingUri||(this.region&&"us1"!==this.region?"https://aim."+this.region+".twilio.com":"https://aim.twilio.com"),this.typingIndicatorUri=this.baseUrl+a,this.typingIndicatorTimeoutOverride=r.typingIndicatorTimeoutOverride,this.httpCacheIntervalOverride=r.httpCacheIntervalOverride,this.consumptionReportIntervalOverride=r.consumptionReportIntervalOverride,this.userInfosToSubscribeOverride=r.userInfosToSubscribeOverride,this.retryWhenThrottledOverride=r.retryWhenThrottledOverride,this.backoffConfigOverride=r.backoffConfigOverride,this.productId=t.productId}return(0,i.default)(e,[{key:"typingIndicatorTimeoutDefault",get:function(){return 5e3}},{key:"httpCacheIntervalDefault",get:function(){return"PT5S"}},{key:"consumptionReportIntervalDefault",get:function(){return"PT5S"}},{key:"userInfosToSubscribeDefault",get:function(){return 100}},{key:"retryWhenThrottledDefault",get:function(){return!0}},{key:"backoffConfigDefault",get:function(){return{min:1e3,max:4e3,maxAttemptsCount:3}}}]),e}();r.Configuration=o},{"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49}],4:[function(e,t,r){"use strict";var n=w(e("babel-runtime/core-js/object/keys")),i=w(e("babel-runtime/core-js/get-iterator")),s=w(e("babel-runtime/helpers/toConsumableArray")),a=w(e("babel-runtime/core-js/set")),o=w(e("babel-runtime/regenerator")),u=w(e("babel-runtime/core-js/promise")),c=w(e("babel-runtime/helpers/asyncToGenerator")),l=w(e("babel-runtime/core-js/map")),d=w(e("babel-runtime/core-js/json/stringify")),f=w(e("babel-runtime/core-js/number/is-integer")),p=w(e("babel-runtime/core-js/object/get-prototype-of")),h=w(e("babel-runtime/helpers/classCallCheck")),b=w(e("babel-runtime/helpers/createClass")),m=w(e("babel-runtime/helpers/possibleConstructorReturn")),v=w(e("babel-runtime/helpers/inherits")),y=w(e("babel-runtime/core-js/reflect/metadata")),g=w(e("babel-runtime/core-js/object/define-property")),_=w(e("babel-runtime/helpers/typeof")),k=w(e("babel-runtime/core-js/object/get-own-property-descriptor"));function w(e){return e&&e.__esModule?e:{default:e}}var x=function(e,t,r,n){var i,s=arguments.length,a=s<3?t:null===n?n=(0,k.default)(t,r):n;if("object"===("undefined"==typeof Reflect?"undefined":(0,_.default)(Reflect))&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(a=(s<3?i(a):s>3?i(t,r,a):i(t,r))||a);return s>3&&a&&(0,g.default)(t,r,a),a},C=function(e,t){if("object"===("undefined"==typeof Reflect?"undefined":(0,_.default)(Reflect))&&"function"==typeof y.default)return(0,y.default)(e,t)};Object.defineProperty(r,"__esModule",{value:!0});var j=e("events"),S=e("./logger"),T=e("./data/participants"),E=e("./participant"),I=e("./data/messages"),M=e("./util"),R=e("twilio-sdk-type-validator"),P=S.Logger.scope("Conversation"),O={lastMessage:"lastMessage",attributes:"attributes",createdBy:"createdBy",dateCreated:"dateCreated",dateUpdated:"dateUpdated",friendlyName:"friendlyName",lastConsumedMessageIndex:"lastConsumedMessageIndex",notificationLevel:"notificationLevel",sid:"sid",status:"status",uniqueName:"uniqueName",state:"state"};function N(e){try{return new Date(e)}catch(e){return null}}var L=function(e){function t(e,r,n){(0,h.default)(this,t);var i=(0,m.default)(this,(t.__proto__||(0,p.default)(t)).call(this)),s=r.attributes||{},a=r.createdBy,o=N(r.dateCreated),u=N(r.dateUpdated),c=r.friendlyName||null,b=(0,f.default)(r.lastConsumedMessageIndex)?r.lastConsumedMessageIndex:null,v=r.uniqueName||null;try{(0,d.default)(s)}catch(e){throw new Error("Attributes must be a valid JSON object.")}return i.services=e,i.sid=n,i.entityName=r.channel,i.channelState={uniqueName:v,status:"notParticipating",attributes:s,createdBy:a,dateCreated:o,dateUpdated:u,friendlyName:c,lastReadMessageIndex:b},r.notificationLevel&&(i.channelState.notificationLevel=r.notificationLevel),i.participants=new l.default,i.participantsEntity=new T.Participants(i,i.services,i.participants),i.participantsEntity.on("participantJoined",i.emit.bind(i,"participantJoined")),i.participantsEntity.on("participantLeft",i.emit.bind(i,"participantLeft")),i.participantsEntity.on("participantUpdated",function(e){return i.emit("participantUpdated",e)}),i.messagesEntity=new I.Messages(i,e),i.messagesEntity.on("messageAdded",function(e){return i._onMessageAdded(e)}),i.messagesEntity.on("messageUpdated",function(e){return i.emit("messageUpdated",e)}),i.messagesEntity.on("messageRemoved",i.emit.bind(i,"messageRemoved")),i}return(0,v.default)(t,e),(0,b.default)(t,[{key:"_subscribe",value:function(){var e=this;return this.entityPromise?this.entityPromise:this.entityPromise=this.entityPromise||this.services.syncClient.document({id:this.entityName,mode:"open_existing"}).then(function(t){return e.entity=t,e.entity.on("updated",function(t){e._update(t.data)}),e.entity.on("removed",function(){return e.emit("removed",e)}),e._update(e.entity.data),t}).catch(function(t){throw e.entity=null,e.entityPromise=null,"disconnected"!=e.services.syncClient.connectionState&&P.error("Failed to get conversation object",t),P.debug("ERROR: Failed to get conversation object",t),t})}},{key:"_subscribeStreams",value:function(){var e=(0,c.default)(o.default.mark(function e(){var t,r;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._subscribe();case 3:return P.trace("_subscribeStreams, this.entity.data=",this.entity.data),t=this.entity.data.messages,r=this.entity.data.roster,e.next=8,u.default.all([this.messagesEntity.subscribe(t),this.participantsEntity.subscribe(r)]);case 8:e.next=15;break;case 10:throw e.prev=10,e.t0=e.catch(0),"disconnected"!==this.services.syncClient.connectionState&&P.error("Failed to subscribe on conversation objects",this.sid,e.t0),P.debug("ERROR: Failed to subscribe on conversation objects",this.sid,e.t0),e.t0;case 15:case"end":return e.stop()}},e,this,[[0,10]])}));return function(){return e.apply(this,arguments)}}()},{key:"_unsubscribe",value:function(){var e=(0,c.default)(o.default.mark(function e(){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.entity){e.next=5;break}return e.next=3,this.entity.close();case 3:this.entity=null,this.entityPromise=null;case 5:return e.abrupt("return",u.default.all([this.participantsEntity.unsubscribe(),this.messagesEntity.unsubscribe()]));case 6:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"_setStatus",value:function(e,t){var r=this;this.statusSource=t,this.channelState.status!==e&&(this.channelState.status=e,"joined"===e?this._subscribeStreams().catch(function(t){if(P.debug("ERROR while setting conversation status "+e,t),"disconnected"!==r.services.syncClient.connectionState)throw t}):this.entityPromise&&this._unsubscribe().catch(function(t){if(P.debug("ERROR while setting conversation status "+e,t),"disconnected"!==r.services.syncClient.connectionState)throw t}))}},{key:"_statusSource",value:function(){return this.statusSource}},{key:"_update",value:function(e){var r,o,u,c,l;P.trace("_update",e),t.preprocessUpdate(e,this.sid);var d=new a.default,f=!0,p=!1,h=void 0;try{for(var b,m=(0,i.default)((0,n.default)(e));!(f=(b=m.next()).done);f=!0){var v=b.value,y=O[v];if(y)switch(y){case O.status:if(!e.status||"unknown"===e.status||this.channelState.status===e.status)break;this.channelState.status=e.status,d.add(y);break;case O.attributes:if(M.isDeepEqual(this.channelState.attributes,e.attributes))break;this.channelState.attributes=e.attributes,d.add(y);break;case O.lastConsumedMessageIndex:if(void 0===e.lastConsumedMessageIndex||e.lastConsumedMessageIndex===this.channelState.lastReadMessageIndex)break;this.channelState.lastReadMessageIndex=e.lastConsumedMessageIndex,d.add("lastReadMessageIndex");break;case O.lastMessage:if(this.channelState.lastMessage&&!e.lastMessage){delete this.channelState.lastMessage,d.add(y);break}this.channelState.lastMessage=this.channelState.lastMessage||{},void 0!==(null===(r=e.lastMessage)||void 0===r?void 0:r.index)&&e.lastMessage.index!==this.channelState.lastMessage.index&&(this.channelState.lastMessage.index=e.lastMessage.index,d.add(y)),void 0!==(null===(o=e.lastMessage)||void 0===o?void 0:o.timestamp)&&(null===(c=null===(u=this.channelState.lastMessage)||void 0===u?void 0:u.dateCreated)||void 0===c?void 0:c.getTime())!==e.lastMessage.timestamp.getTime()&&(this.channelState.lastMessage.dateCreated=e.lastMessage.timestamp,d.add(y)),M.isDeepEqual(this.channelState.lastMessage,{})&&delete this.channelState.lastMessage;break;case O.state:var g=e.state||void 0;if(void 0!==g&&(g.dateUpdated=new Date(g.dateUpdated)),M.isDeepEqual(this.channelState.state,g))break;this.channelState.state=g,d.add(y);break;default:var _=e[v]instanceof Date,k=_&&(null===(l=this.channelState[y])||void 0===l?void 0:l.getTime())===e[v].getTime(),w=!_&&this[y]===e[v];if(k||w)break;this.channelState[y]=e[v],d.add(y)}}}catch(e){p=!0,h=e}finally{try{!f&&m.return&&m.return()}finally{if(p)throw h}}d.size>0&&this.emit("updated",{conversation:this,updateReasons:[].concat((0,s.default)(d))})}},{key:"_onMessageAdded",value:function(e){var t=!0,r=!1,n=void 0;try{for(var s,a=(0,i.default)(this.participants.values());!(t=(s=a.next()).done);t=!0){var o=s.value;if(o.identity===e.author){o._endTyping();break}}}catch(e){r=!0,n=e}finally{try{!t&&a.return&&a.return()}finally{if(r)throw n}}this.emit("messageAdded",e)}},{key:"add",value:function(){var e=(0,c.default)(o.default.mark(function e(t,r){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.add(t,r));case 1:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"addNonChatParticipant",value:function(){var e=(0,c.default)(o.default.mark(function e(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.addNonChatParticipant(t,r,n));case 1:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"advanceLastReadMessageIndex",value:function(){var e=(0,c.default)(o.default.mark(function e(t){return o.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.readHorizon.advanceLastReadMessageIndexForConversation(this.sid,t,this.lastReadMessageIndex));case 3:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"delete",value:function(){var e=(0,c.default)(o.default.mark(function e(){return o.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)}));return function(){return e.apply(this,arguments)}}()},{key:"getAttributes",value:function(){var e=(0,c.default)(o.default.mark(function e(){return o.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)}));return function(){return e.apply(this,arguments)}}()},{key:"getMessages",value:function(){var e=(0,c.default)(o.default.mark(function e(t,r,n){return o.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.messagesEntity.getMessages(t,r,n));case 3:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"getParticipants",value:function(){var e=(0,c.default)(o.default.mark(function e(){return o.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.participantsEntity.getParticipants());case 3:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getParticipantsCount",value:function(){var e=(0,c.default)(o.default.mark(function e(){var t,r,n;return o.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 M.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)}));return function(){return e.apply(this,arguments)}}()},{key:"getParticipantBySid",value:function(){var e=(0,c.default)(o.default.mark(function e(t){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.getParticipantBySid(t));case 1:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getParticipantByIdentity",value:function(){var e=(0,c.default)(o.default.mark(function e(t){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.getParticipantByIdentity(t));case 1:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getMessagesCount",value:function(){var e=(0,c.default)(o.default.mark(function e(){var t,r,n;return o.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 M.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)}));return function(){return e.apply(this,arguments)}}()},{key:"getUnreadMessagesCount",value:function(){var e=(0,c.default)(o.default.mark(function e(){var t,r,n;return o.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 M.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("Conversation is not in user conversations list");case 12:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"join",value:function(){var e=(0,c.default)(o.default.mark(function e(){return o.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)}));return function(){return e.apply(this,arguments)}}()},{key:"leave",value:function(){var e=(0,c.default)(o.default.mark(function e(){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("joined"!==this.channelState.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)}));return function(){return e.apply(this,arguments)}}()},{key:"removeParticipant",value:function(){var e=(0,c.default)(o.default.mark(function e(t){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(t instanceof E.Participant)){e.next=4;break}return e.next=3,this.participantsEntity.removeBySid(t.sid);case 3:return e.abrupt("return");case 4:return e.next=6,this.participantsEntity.removeByIdentity(t);case 6:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"sendMessage",value:function(){var e=(0,c.default)(o.default.mark(function e(t,r,n){var i,s;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof t&&null!==t){e.next=5;break}return e.next=3,this.messagesEntity.send(t,r,n);case 3:return i=e.sent,e.abrupt("return",M.parseToNumber(i.messageId));case 5:return e.next=7,this.messagesEntity.sendMedia(t,r,n);case 7:return s=e.sent,e.abrupt("return",M.parseToNumber(s.messageId));case 9:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"setAllMessagesRead",value:function(){var e=(0,c.default)(o.default.mark(function e(){var t;return o.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.advanceLastReadMessageIndex(t.items[0].index));case 7:return e.abrupt("return",u.default.resolve(0));case 8:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"setAllMessagesUnread",value:function(){var e=(0,c.default)(o.default.mark(function e(){return o.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.readHorizon.updateLastReadMessageIndexForConversation(this.sid,null));case 3:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"setUserNotificationLevel",value:function(){var e=(0,c.default)(o.default.mark(function e(t){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("editNotificationLevel",{channelSid:this.sid,notificationLevel:t});case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"typing",value:function(){return this.services.typingIndicator.send(this.sid)}},{key:"updateAttributes",value:function(){var e=(0,c.default)(o.default.mark(function e(t){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("editAttributes",{channelSid:this.sid,attributes:(0,d.default)(t)});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"updateFriendlyName",value:function(){var e=(0,c.default)(o.default.mark(function e(t){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelState.friendlyName===t){e.next=3;break}return e.next=3,this.services.session.addCommand("editFriendlyName",{channelSid:this.sid,friendlyName:t});case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"updateLastReadMessageIndex",value:function(){var e=(0,c.default)(o.default.mark(function e(t){return o.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.readHorizon.updateLastReadMessageIndexForConversation(this.sid,t));case 3:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"updateUniqueName",value:function(){var e=(0,c.default)(o.default.mark(function e(t){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelState.uniqueName===t){e.next=4;break}return t||(t=""),e.next=4,this.services.session.addCommand("editUniqueName",{channelSid:this.sid,uniqueName:t});case 4:return e.abrupt("return",this);case 5:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"uniqueName",get:function(){return this.channelState.uniqueName}},{key:"status",get:function(){return this.channelState.status}},{key:"friendlyName",get:function(){return this.channelState.friendlyName}},{key:"dateUpdated",get:function(){return this.channelState.dateUpdated}},{key:"dateCreated",get:function(){return this.channelState.dateCreated}},{key:"createdBy",get:function(){return this.channelState.createdBy}},{key:"attributes",get:function(){return this.channelState.attributes}},{key:"lastReadMessageIndex",get:function(){return this.channelState.lastReadMessageIndex}},{key:"lastMessage",get:function(){return this.channelState.lastMessage}},{key:"notificationLevel",get:function(){return this.channelState.notificationLevel}},{key:"state",get:function(){return this.channelState.state}}],[{key:"preprocessUpdate",value:function(e,t){try{"string"==typeof e.attributes?e.attributes=JSON.parse(e.attributes):e.attributes&&(0,d.default)(e.attributes)}catch(r){P.warn("Retrieved malformed attributes from the server for conversation: "+t),e.attributes={}}try{e.dateCreated&&(e.dateCreated=new Date(e.dateCreated))}catch(r){P.warn("Retrieved malformed dateCreated from the server for conversation: "+t),delete e.dateCreated}try{e.dateUpdated&&(e.dateUpdated=new Date(e.dateUpdated))}catch(r){P.warn("Retrieved malformed dateUpdated from the server for conversation: "+t),delete e.dateUpdated}try{e.lastMessage&&e.lastMessage.timestamp&&(e.lastMessage.timestamp=new Date(e.lastMessage.timestamp))}catch(r){P.warn("Retrieved malformed lastMessage.timestamp from the server for conversation: "+t),delete e.lastMessage.timestamp}}}]),t}(j.EventEmitter);x([R.validateTypesAsync(R.nonEmptyString,["undefined","string","number","boolean","object",R.literal(null)]),C("design:type",Function),C("design:paramtypes",[String,Object]),C("design:returntype",u.default)],L.prototype,"add",null),x([R.validateTypesAsync(R.nonEmptyString,R.nonEmptyString,["undefined","object"]),C("design:type",Function),C("design:paramtypes",[String,String,Object]),C("design:returntype",u.default)],L.prototype,"addNonChatParticipant",null),x([R.validateTypesAsync(R.nonNegativeInteger),C("design:type",Function),C("design:paramtypes",[Number]),C("design:returntype",u.default)],L.prototype,"advanceLastReadMessageIndex",null),x([R.validateTypesAsync(["undefined",R.nonNegativeInteger],["undefined",R.nonNegativeInteger],["undefined",R.literal("backwards","forward")]),C("design:type",Function),C("design:paramtypes",[Number,Number,String]),C("design:returntype",u.default)],L.prototype,"getMessages",null),x([R.validateTypesAsync(R.nonEmptyString),C("design:type",Function),C("design:paramtypes",[String]),C("design:returntype",u.default)],L.prototype,"getParticipantBySid",null),x([R.validateTypesAsync(R.nonEmptyString),C("design:type",Function),C("design:paramtypes",[String]),C("design:returntype",u.default)],L.prototype,"getParticipantByIdentity",null),x([R.validateTypesAsync([R.nonEmptyString,E.Participant]),C("design:type",Function),C("design:paramtypes",[Object]),C("design:returntype",u.default)],L.prototype,"removeParticipant",null),x([R.validateTypesAsync(["string",R.literal(null),R.custom(function(e){return[e instanceof FormData,"an instance of FormData"]}),R.objectSchema("media options",{contentType:R.nonEmptyString,media:R.custom(function(e){var t="string"==typeof e&&e.length>0||e instanceof Uint8Array||e instanceof ArrayBuffer;return"function"==typeof Blob&&(t=t||e instanceof Blob),[t,"a non-empty string, an instance of Buffer or an instance of Blob"]})})],["undefined","string","number","boolean","object",R.literal(null)],["undefined",R.literal(null),R.objectSchema("email attributes",{subject:[R.nonEmptyString,"undefined"]})]),C("design:type",Function),C("design:paramtypes",[Object,Object,Object]),C("design:returntype",u.default)],L.prototype,"sendMessage",null),x([R.validateTypesAsync(R.literal("default","muted")),C("design:type",Function),C("design:paramtypes",[String]),C("design:returntype",u.default)],L.prototype,"setUserNotificationLevel",null),x([R.validateTypesAsync(["string","number","boolean","object",R.literal(null)]),C("design:type",Function),C("design:paramtypes",[Object]),C("design:returntype",u.default)],L.prototype,"updateAttributes",null),x([R.validateTypesAsync(["string",R.literal(null)]),C("design:type",Function),C("design:paramtypes",[String]),C("design:returntype",u.default)],L.prototype,"updateFriendlyName",null),x([R.validateTypesAsync([R.literal(null),R.nonNegativeInteger]),C("design:type",Function),C("design:paramtypes",[Number]),C("design:returntype",u.default)],L.prototype,"updateLastReadMessageIndex",null),x([R.validateTypesAsync(["string",R.literal(null)]),C("design:type",Function),C("design:paramtypes",[String]),C("design:returntype",u.default)],L.prototype,"updateUniqueName",null),r.Conversation=L},{"./data/messages":6,"./data/participants":7,"./logger":12,"./participant":15,"./util":27,"babel-runtime/core-js/get-iterator":29,"babel-runtime/core-js/json/stringify":31,"babel-runtime/core-js/map":32,"babel-runtime/core-js/number/is-integer":33,"babel-runtime/core-js/object/define-property":36,"babel-runtime/core-js/object/get-own-property-descriptor":37,"babel-runtime/core-js/object/get-prototype-of":38,"babel-runtime/core-js/object/keys":39,"babel-runtime/core-js/promise":41,"babel-runtime/core-js/reflect/metadata":43,"babel-runtime/core-js/set":44,"babel-runtime/helpers/asyncToGenerator":47,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/helpers/toConsumableArray":54,"babel-runtime/helpers/typeof":55,"babel-runtime/regenerator":56,events:199,"twilio-sdk-type-validator":232}],5:[function(e,t,r){"use strict";var n=b(e("babel-runtime/helpers/typeof")),i=b(e("babel-runtime/core-js/promise")),s=b(e("babel-runtime/regenerator")),a=b(e("babel-runtime/core-js/json/stringify")),o=b(e("babel-runtime/helpers/asyncToGenerator")),u=b(e("babel-runtime/core-js/set")),c=b(e("babel-runtime/core-js/map")),l=b(e("babel-runtime/core-js/object/get-prototype-of")),d=b(e("babel-runtime/helpers/classCallCheck")),f=b(e("babel-runtime/helpers/createClass")),p=b(e("babel-runtime/helpers/possibleConstructorReturn")),h=b(e("babel-runtime/helpers/inherits"));function b(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var m=e("events"),v=e("../logger"),y=e("../conversation");r.Conversation=y.Conversation;var g=e("../util/deferred"),_=e("../util"),k=v.Logger.scope("Conversations"),w=function(e){function t(e){(0,d.default)(this,t);var r=(0,p.default)(this,(t.__proto__||(0,l.default)(t)).call(this));return r.services=e,r.conversations=new c.default,r.thumbstones=new u.default,r.syncListFetched=!1,r.syncListRead=new g.Deferred,r}return(0,h.default)(t,e),(0,f.default)(t,[{key:"getMap",value:function(){var e=this;return this.services.session.getMyConversationsId().then(function(t){return e.services.syncClient.map({id:t,mode:"open_existing"})})}},{key:"addConversation",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r,n,i,o,u,c;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=void 0,r=void 0===t.attributes?{}:t.attributes,e.next=4,this.services.session.addCommand("createConversation",{friendlyName:t.friendlyName,uniqueName:t.uniqueName,attributes:(0,a.default)(r)});case 4:if(n=e.sent,i="conversationSid"in n?n.conversationSid:null,o="conversation"in n?n.conversation:null,!(u=this.conversations.get(i))){e.next=12;break}return e.next=11,u._subscribe();case 11:return e.abrupt("return",u);case 12:return c=new y.Conversation(this.services,{channel:o,entityName:null,uniqueName:null,attributes:null,createdBy:null,friendlyName:null,lastConsumedMessageIndex:null,dateCreated:null,dateUpdated:null},i),this.conversations.set(c.sid,c),this.registerForEvents(c),e.next=17,c._subscribe();case 17:return this.emit("conversationAdded",c),e.abrupt("return",c);case 19:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"fetchConversations",value:function(){var e,t=this;this.getMap().then((e=(0,o.default)(s.default.mark(function e(r){var n,a;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r.on("itemAdded",function(e){k.debug("itemAdded: "+e.item.key),t.upsertConversation("sync",e.item.key,e.item.data)}),r.on("itemRemoved",function(e){k.debug("itemRemoved: "+e.key);var r=e.key;t.syncListFetched||t.thumbstones.add(r);var n=t.conversations.get(r);n&&(n&&"joined"===n.status&&(n._setStatus("notParticipating","sync"),t.emit("conversationLeft",n)),t.conversations.delete(r),t.emit("conversationRemoved",n),n.emit("removed",n))}),r.on("itemUpdated",function(e){k.debug("itemUpdated: "+e.item.key),t.upsertConversation("sync",e.item.key,e.item.data)}),n=[],e.next=6,t.services.syncList.getPage();case 6:a=e.sent,a.items.forEach(function(e){n.push(t.upsertConversation("synclist",e.channel_sid,e))});case 9:if(!a.hasNextPage){e.next=16;break}return e.next=12,a.nextPage();case 12:(a=e.sent).items.forEach(function(e){n.push(t.upsertConversation("synclist",e.channel_sid,e))}),e.next=9;break;case 16:return t.syncListRead.set(!0),e.abrupt("return",i.default.all(n));case 18:case"end":return e.stop()}},e,t)})),function(t){return e.apply(this,arguments)})).then(function(){t.syncListFetched=!0,t.thumbstones.clear(),k.debug("Conversations list fetched")}).then(function(){return t}).catch(function(e){throw"disconnected"!=t.services.syncClient.connectionState&&k.error("Failed to get conversations list",e),k.debug("ERROR: Failed to get conversations list",e),e})}},{key:"_wrapPaginator",value:function(e,t){var r=this;return t(e.items).then(function(n){return{items:n,hasNextPage:e.hasNextPage,hasPrevPage:e.hasPrevPage,nextPage:function(){return e.nextPage().then(function(e){return r._wrapPaginator(e,t)})},prevPage:function(){return e.prevPage().then(function(e){return r._wrapPaginator(e,t)})}}})}},{key:"getConversations",value:function(e){var t=this;return this.getMap().then(function(t){return t.getItems(e)}).then(function(e){return t._wrapPaginator(e,function(e){return i.default.all(e.map(function(e){return t.upsertConversation("sync",e.key,e.data)}))})})}},{key:"getConversation",value:function(e){var t=this;return this.getMap().then(function(t){return t.getItems({key:e})}).then(function(e){return e.items.map(function(e){return t.upsertConversation("sync",e.key,e.data)})}).then(function(e){return e.length>0?e[0]:null})}},{key:"getConversationByUniqueName",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r,n,i,a,o,u,c,l;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.getSessionLinks();case 2:return i=e.sent,a=new _.UriBuilder(i.myChannelsUrl).path(t).build(),e.next=6,this.services.network.get(a);case 6:return o=e.sent,u=o.body,c=u.channel_sid,l={entityName:null,lastConsumedMessageIndex:u.last_consumed_message_index,status:(null===(r=u)||void 0===r?void 0:r.status)||"unknown",friendlyName:u.friendly_name,dateUpdated:u.date_updated,dateCreated:u.date_created,uniqueName:u.unique_name,createdBy:u.created_by,attributes:u.attributes,channel:c+".channel",notificationLevel:null===(n=u)||void 0===n?void 0:n.notification_level,sid:c},e.abrupt("return",this.upsertConversation("sync",c,l));case 11:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getWhisperConversation",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r,i,a,o,u,c,l,d,f,p;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.getSessionLinks();case 2:return u=e.sent,c=new _.UriBuilder(u.publicChannelsUrl).path(t).build(),e.next=6,this.services.network.get(c);case 6:if(l=e.sent,"private"===(d=l.body).type){e.next=10;break}return e.abrupt("return");case 10:if(f=void 0,"string"==typeof d.state&&(f=JSON.parse(d.state)),"object"===(0,n.default)(d.state)&&null!==d.state&&(f=d.state),"closed"!==(null===(i=null===(r=f)||void 0===r?void 0:r["state.v1"])||void 0===i?void 0:i.current)){e.next=15;break}return e.abrupt("return");case 15:return p={entityName:null,lastConsumedMessageIndex:d.last_consumed_message_index,status:(null===(a=d)||void 0===a?void 0:a.status)||"unknown",friendlyName:d.friendly_name,dateUpdated:d.date_updated,dateCreated:d.date_created,uniqueName:d.unique_name,createdBy:d.created_by,attributes:d.attributes,channel:t+".channel",notificationLevel:null===(o=d)||void 0===o?void 0:o.notification_level,sid:t},e.abrupt("return",this.upsertConversation("sync",t,p));case 17:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"upsertConversation",value:function(e,t,r){var n=this;k.trace("upsertConversation(sid="+t+", data=",r);var i=this.conversations.get(t);if(i){if(k.trace("upsertConversation: conversation "+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),_.isDeepEqual(s,{})||i._update(s),i._subscribe().then(function(){n.emit("conversationJoined",i)})}else"notParticipating"===r.status&&"joined"===i.status?(i._setStatus("notParticipating",e),i._update(r),i._subscribe().then(function(){n.emit("conversationLeft",i)})):"notParticipating"===r.status?i._subscribe():i._update(r);else k.trace("upsertConversation: conversation is known from sync and came from chat, ignoring",{sid:t,data:r.status,conversation:i.status});return i._subscribe().then(function(){return i})}if("chat"!==e&&"synclist"!==e||!this.thumbstones.has(t))return k.trace("upsertConversation: creating local conversation object with sid "+t,r),i=new y.Conversation(this.services,r,t),this.conversations.set(t,i),i._subscribe().then(function(){return n.registerForEvents(i),n.emit("conversationAdded",i),"joined"===r.status&&(i._setStatus("joined",e),n.emit("conversationJoined",i)),i});k.trace("upsertConversation: conversation is deleted and came again from chat, ignoring",t)}},{key:"onConversationRemoved",value:function(e){var t=this.conversations.get(e);t&&(this.conversations.delete(e),this.emit("conversationRemoved",t))}},{key:"registerForEvents",value:function(e){var t=this;e.on("removed",function(){return t.onConversationRemoved(e.sid)}),e.on("updated",function(e){return t.emit("conversationUpdated",e)}),e.on("participantJoined",this.emit.bind(this,"participantJoined")),e.on("participantLeft",this.emit.bind(this,"participantLeft")),e.on("participantUpdated",function(e){return t.emit("participantUpdated",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}(m.EventEmitter);r.Conversations=w},{"../conversation":4,"../logger":12,"../util":27,"../util/deferred":26,"babel-runtime/core-js/json/stringify":31,"babel-runtime/core-js/map":32,"babel-runtime/core-js/object/get-prototype-of":38,"babel-runtime/core-js/promise":41,"babel-runtime/core-js/set":44,"babel-runtime/helpers/asyncToGenerator":47,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/helpers/typeof":55,"babel-runtime/regenerator":56,events:199}],6:[function(e,t,r){"use strict";var n=p(e("babel-runtime/core-js/promise")),i=p(e("babel-runtime/core-js/json/stringify")),s=p(e("babel-runtime/regenerator")),a=p(e("babel-runtime/helpers/asyncToGenerator")),o=p(e("babel-runtime/core-js/map")),u=p(e("babel-runtime/core-js/object/get-prototype-of")),c=p(e("babel-runtime/helpers/classCallCheck")),l=p(e("babel-runtime/helpers/createClass")),d=p(e("babel-runtime/helpers/possibleConstructorReturn")),f=p(e("babel-runtime/helpers/inherits"));function p(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var h=e("events"),b=e("../logger"),m=e("../message"),v=b.Logger.scope("Messages"),y=function(e){function t(e,r){(0,c.default)(this,t);var n=(0,d.default)(this,(t.__proto__||(0,u.default)(t)).call(this));return n.conversation=e,n.services=r,n.messagesByIndex=new o.default,n.messagesListPromise=null,n}return(0,f.default)(t,e),(0,l.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){v.debug(t.conversation.sid+" itemAdded: "+e.item.index);var r=new m.Message(t.conversation,t.services,e.item.index,e.item.data);t.messagesByIndex.has(r.index)?v.debug("Message arrived, but already known and ignored",t.conversation.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){v.debug(t.conversation.sid+" itemRemoved: "+e.index);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){v.debug(t.conversation.sid+" itemUpdated: "+e.item.index);var r=t.messagesByIndex.get(e.item.index);r&&r._update(e.item.data)}),e}).catch(function(e){throw t.messagesListPromise=null,"disconnected"!=t.services.syncClient.connectionState&&v.error("Failed to get messages object for conversation",t.conversation.sid,e),v.debug("ERROR: Failed to get messages object for conversation",t.conversation.sid,e),e})}},{key:"unsubscribe",value:function(){var e=(0,a.default)(s.default.mark(function e(){return s.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)}));return function(){return e.apply(this,arguments)}}()},{key:"send",value:function(){var e=(0,a.default)(s.default.mark(function e(t){var r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=arguments[2];return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return v.debug("Sending text message",t,n,a),e.abrupt("return",this.services.session.addCommand("sendMessage",{channelSid:this.conversation.sid,text:t,attributes:(0,i.default)(n),subject:null===(r=a)||void 0===r?void 0:r.subject}));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"sendMedia",value:function(){var e=(0,a.default)(s.default.mark(function e(t){var r,n,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments[2];return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(v.debug("Sending media message",t,a,o),r=void 0,!("undefined"!=typeof FormData&&t instanceof FormData)){e.next=9;break}return v.debug("Sending media message as FormData",t,a),e.next=6,this.services.mcsClient.postFormData(t);case 6:r=e.sent,e.next=16;break;case 9:if(v.debug("Sending media message as SendMediaOptions",t,a),(n=t).contentType&&n.media){e.next=13;break}throw new Error("Media content must contain non-empty contentType and media");case 13:return e.next=15,this.services.mcsClient.post(n.contentType,n.media);case 15:r=e.sent;case 16:return e.abrupt("return",this.services.session.addCommand("sendMediaMessage",{channelSid:this.conversation.sid,mediaSid:r.sid,attributes:(0,i.default)(a)}));case 17:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{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.conversation,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 i=this;t=void 0!==t?t:"end",e=e||30;var s="backwards"===r?"desc":"asc";return this.messagesListPromise.then(function(r){return r.getItems({from:"end"!==t?t:void 0,pageSize:e,order:s})}).then(function(e){return i.wrapPaginator(s,e,function(e){return n.default.all(e.map(function(e){return i._upsertMessage(e.index,e.data)}))})})}}]),t}(h.EventEmitter);r.Messages=y},{"../logger":12,"../message":14,"babel-runtime/core-js/json/stringify":31,"babel-runtime/core-js/map":32,"babel-runtime/core-js/object/get-prototype-of":38,"babel-runtime/core-js/promise":41,"babel-runtime/helpers/asyncToGenerator":47,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/regenerator":56,events:199}],7:[function(e,t,r){"use strict";var n=f(e("babel-runtime/core-js/json/stringify")),i=f(e("babel-runtime/core-js/promise")),s=f(e("babel-runtime/regenerator")),a=f(e("babel-runtime/helpers/asyncToGenerator")),o=f(e("babel-runtime/core-js/object/get-prototype-of")),u=f(e("babel-runtime/helpers/classCallCheck")),c=f(e("babel-runtime/helpers/createClass")),l=f(e("babel-runtime/helpers/possibleConstructorReturn")),d=f(e("babel-runtime/helpers/inherits"));function f(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var p=e("events"),h=e("../participant"),b=e("../logger").Logger.scope("Participants"),m=function(e){function t(e,r,n){(0,u.default)(this,t);var i=(0,l.default)(this,(t.__proto__||(0,o.default)(t)).call(this));return i.services=r,i.conversation=e,i.participants=n,i}return(0,d.default)(t,e),(0,c.default)(t,[{key:"unsubscribe",value:function(){var e=(0,a.default)(s.default.mark(function e(){return s.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)}));return function(){return e.apply(this,arguments)}}()},{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){b.debug(t.conversation.sid+" itemAdded: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data).then(function(e){t.emit("participantJoined",e)})}),e.on("itemRemoved",function(e){b.debug(t.conversation.sid+" itemRemoved: "+e.key);var r=e.key;if(t.participants.has(r)){var n=t.participants.get(r);t.participants.delete(r),t.emit("participantLeft",n)}}),e.on("itemUpdated",function(e){b.debug(t.conversation.sid+" itemUpdated: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data)});var r=[],n=t;return e.getItems().then(function e(t){return t.items.forEach(function(e){r.push(n.upsertParticipant(e.key,e.data))}),t.hasNextPage?t.nextPage().then(e):null}).then(function(){return i.default.all(r)}).then(function(){return e})}).catch(function(e){throw t.rosterEntityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&b.error("Failed to get roster object for conversation",t.conversation.sid,e),b.debug("ERROR: Failed to get roster object for conversation",t.conversation.sid,e),e})}},{key:"upsertParticipant",value:function(){var e=(0,a.default)(s.default.mark(function e(t,r){var n,i=this;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n=this.participants.get(t))){e.next=3;break}return e.abrupt("return",n._update(r));case 3:return n=new h.Participant(this.services,this.conversation,r,t),this.participants.set(t,n),n.on("updated",function(e){return i.emit("participantUpdated",e)}),e.abrupt("return",n);case 7:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"getParticipants",value:function(){var e=this;return this.rosterEntityPromise.then(function(){var t=[];return e.participants.forEach(function(e){return t.push(e)}),t})}},{key:"getParticipantBySid",value:function(){var e=(0,a.default)(s.default.mark(function e(t){var r=this;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise.then(function(){var e=r.participants.get(t);if(!e)throw new Error("Participant with SID "+t+" was not found");return e}));case 1:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getParticipantByIdentity",value:function(){var e=(0,a.default)(s.default.mark(function e(t){var r,n=this;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=null,e.abrupt("return",this.rosterEntityPromise.then(function(){if(n.participants.forEach(function(e){e.identity===t&&(r=e)}),!r)throw new Error("Participant with identity "+t+" was not found");return r}));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"add",value:function(e,t){return this.services.session.addCommand("addMemberV2",{channelSid:this.conversation.sid,attributes:(0,n.default)(t),username:e})}},{key:"addNonChatParticipant",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.services.session.addCommand("addNonChatParticipant",{conversationSid:this.conversation.sid,proxyAddress:e,attributes:(0,n.default)(r),address:t})}},{key:"invite",value:function(e){return this.services.session.addCommand("inviteMember",{channelSid:this.conversation.sid,username:e})}},{key:"removeByIdentity",value:function(e){return this.services.session.addCommand("removeMember",{channelSid:this.conversation.sid,username:e})}},{key:"removeBySid",value:function(e){return this.services.session.addCommand("removeMember",{channelSid:this.conversation.sid,memberSid:e})}}]),t}(p.EventEmitter);r.Participants=m},{"../logger":12,"../participant":15,"babel-runtime/core-js/json/stringify":31,"babel-runtime/core-js/object/get-prototype-of":38,"babel-runtime/core-js/promise":41,"babel-runtime/helpers/asyncToGenerator":47,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/regenerator":56,events:199}],8:[function(e,t,r){"use strict";var n=d(e("babel-runtime/regenerator")),i=d(e("babel-runtime/helpers/asyncToGenerator")),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"));function d(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var f=e("events"),p=e("../user"),h=e("../util"),b=function(e){function t(e){(0,o.default)(this,t);var r=(0,c.default)(this,(t.__proto__||(0,a.default)(t)).call(this));return r.services=e,r.fifoStack=[],r.fifoStackMaxLength=100,r.myself=new p.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 s.default,r.userUrlPromise=r.services.session.getSessionLinks().then(function(e){return r.userUrl=e.usersUrl,r.userUrl}),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,l.default)(t,e),(0,u.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(){var e=(0,i.default)(n.default.mark(function e(t){var r,i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;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:if(t!=this.myself.identity){e.next=6;break}return e.abrupt("return",this.myself);case 6:if(r=this.subscribedUsers.get(t)){e.next=18;break}if(s){e.next=12;break}return e.next=11,this.getSyncUniqueName(t);case 11:s=e.sent;case 12:return(r=new p.User(t,s,this.services)).on("updated",function(e){return i.emit("userUpdated",e)}),r.on("userSubscribed",function(){return i.handleSubscribeUser(r)}),r.on("userUnsubscribed",function(){return i.handleUnsubscribeUser(r)}),e.next=18,r._ensureFetched();case 18:return e.abrupt("return",r);case 19:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getSubscribedUsers",value:function(){var e=(0,i.default)(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)}));return function(){return e.apply(this,arguments)}}()},{key:"getSyncUniqueName",value:function(){var e=(0,i.default)(n.default.mark(function e(t){var r,i;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=new h.UriBuilder(this.userUrl).path(t).build(),e.next=3,this.services.network.get(r);case 3:return i=e.sent,e.abrupt("return",i.body.sync_unique_name);case 5:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()}]),t}(f.EventEmitter);r.Users=b},{"../user":25,"../util":27,"babel-runtime/core-js/map":32,"babel-runtime/core-js/object/get-prototype-of":38,"babel-runtime/helpers/asyncToGenerator":47,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/regenerator":56,events:199}],9:[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.DetailedDeliveryReceipt=function e(t){(0,s.default)(this,e),this.sid=t.sid,this.messageSid=t.message_sid,this.conversationSid=t.conversation_sid,this.channelMessageSid=t.channel_message_sid,this.participantSid=t.participant_sid,this.status=t.status||"queued",this.errorCode=t.error_code||0,this.dateCreated=t.date_created,this.dateUpdated=t.date_updated}},{"babel-runtime/helpers/classCallCheck":48}],10:[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)};r.NotificationTypes=a,a.TYPING_INDICATOR="twilio.ipmsg.typing_indicator",a.NEW_MESSAGE="twilio.conversations.new_message",a.ADDED_TO_CONVERSATION="twilio.conversations.added_to_conversation",a.REMOVED_FROM_CONVERSATION="twilio.conversations.removed_from_conversation",a.CONSUMPTION_UPDATE="twilio.channel.consumption_update"},{"babel-runtime/helpers/classCallCheck":48}],11:[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)};r.ResponseCodes=a,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},{"babel-runtime/helpers/classCallCheck":48}],12:[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}}function o(e,t){return[(new Date).toISOString()+" Conversations "+e+":"].concat((0,s.default)(t))}Object.defineProperty(r,"__esModule",{value:!0});var u=e("loglevel").getLogger("twilio-conversations"),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){u.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=Array(e),r=0;r=0;o--)(i=e[o])&&(a=(s<3?i(a):s>3?i(t,r,a):i(t,r))||a);return s>3&&a&&(0,h.default)(t,r,a),a},g=function(e,t){if("object"===("undefined"==typeof Reflect?"undefined":(0,b.default)(Reflect))&&"function"==typeof p.default)return(0,p.default)(e,t)};Object.defineProperty(r,"__esModule",{value:!0});var _=e("events"),k=e("./util"),w=e("./logger"),x=e("./media"),C=e("./aggregateddeliveryreceipt"),j=e("twilio-sdk-type-validator"),S=e("./restpaginator"),T=e("./detaileddeliveryreceipt"),E=w.Logger.scope("Message"),I=function(e){function t(e,r,n,i){(0,c.default)(this,t);var s=(0,d.default)(this,(t.__proto__||(0,u.default)(t)).call(this));return s.conversation=e,s.services=r,s.state={sid:i.sid,index:n,author:null==i.author?null:i.author,subject:null==i.subject?null:i.subject,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:k.parseAttributes(i.attributes,"Got malformed attributes for the message "+i.sid,E),type:i.type?i.type:"text",media:i.type&&"media"===i.type&&i.media?new x.Media(i.media,s.services):null,participantSid:null==i.memberSid?null:i.memberSid,aggregatedDeliveryReceipt:i.delivery?new C.AggregatedDeliveryReceipt(i.delivery):null},s}return(0,f.default)(t,e),(0,l.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.subject&&e.subject!==this.state.subject&&(this.state.subject=e.subject,t.push("subject")),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("dateCreated"));var r=k.parseAttributes(e.attributes,"Got malformed attributes for the message "+this.sid,E);k.isDeepEqual(this.state.attributes,r)||(this.state.attributes=r,t.push("attributes"));var n=e.delivery,i=this.state.aggregatedDeliveryReceipt;!!(n&&n.total&&n.delivered&&n.failed&&n.read&&n.sent&&n.undelivered)&&(i?i._isEquals(n)||(i._update(n),t.push("deliveryReceipt")):(this.state.aggregatedDeliveryReceipt=new C.AggregatedDeliveryReceipt(n),t.push("deliveryReceipt"))),t.length>0&&this.emit("updated",{message:this,updateReasons:t})}},{key:"getParticipant",value:function(){var e=(0,o.default)(a.default.mark(function e(){var t,r,n=this;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=null,!this.state.participantSid){e.next=5;break}return e.next=4,this.conversation.getParticipantBySid(this.participantSid).catch(function(){return E.debug('Participant with sid "'+n.participantSid+'" not found for message '+n.sid),null});case 4:t=e.sent;case 5:if(t||!this.state.author){e.next=9;break}return e.next=8,this.conversation.getParticipantByIdentity(this.state.author).catch(function(){return E.debug('Participant with identity "'+n.author+'" not found for message '+n.sid),null});case 8:t=e.sent;case 9:if(!t){e.next=11;break}return e.abrupt("return",t);case 11:throw r="Participant with ",this.state.participantSid&&(r+="SID '"+this.state.participantSid+"' "),this.state.author&&(this.state.participantSid&&(r+="or "),r+="identity '"+this.state.author+"' "),"Participant with "===r&&(r="Participant "),r+="was not found",new Error(r);case 17:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getDetailedDeliveryReceipts",value:function(){var e=(0,o.default)(a.default.mark(function e(){var t,r;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getDetailedDeliveryReceiptsPaginator();case 2:t=e.sent,r=[];case 4:if(r=[].concat((0,s.default)(r),(0,s.default)(t.items)),t.hasNextPage){e.next=8;break}return e.abrupt("break",13);case 8:return e.next=10,t.nextPage();case 10:t=e.sent,e.next=4;break;case 13:return e.abrupt("return",r);case 14:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"remove",value:function(){var e=(0,o.default)(a.default.mark(function e(){return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("deleteMessage",{channelSid:this.conversation.sid,messageIdx:this.index.toString()});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"updateBody",value:function(){var e=(0,o.default)(a.default.mark(function e(t){return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("editMessage",{channelSid:this.conversation.sid,messageIdx:this.index.toString(),text:t});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"updateAttributes",value:function(){var e=(0,o.default)(a.default.mark(function e(t){return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("editMessageAttributes",{channelSid:this.conversation.sid,messageIdx:this.index,attributes:(0,i.default)(t)});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"_getDetailedDeliveryReceiptsPaginator",value:function(){var e=(0,o.default)(a.default.mark(function e(t){var r,n,i,s,o,u,c=this;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.getSessionLinks();case 2:return i=e.sent,s=i.messagesReceiptsUrl.replace("%s",this.conversation.sid).replace("%s",this.sid),o=new k.UriBuilder(s).arg("PageToken",null===(r=t)||void 0===r?void 0:r.pageToken).arg("PageSize",null===(n=t)||void 0===n?void 0:n.pageSize).build(),e.next=7,this.services.network.get(o);case 7:return u=e.sent,e.abrupt("return",new S.RestPaginator(u.body.delivery_receipts.map(function(e){return new T.DetailedDeliveryReceipt(e)}),function(e,t){return c._getDetailedDeliveryReceiptsPaginator({pageToken:e,pageSize:t})},u.body.meta.previous_token,u.body.meta.next_token));case 9:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"sid",get:function(){return this.state.sid}},{key:"author",get:function(){return this.state.author}},{key:"subject",get:function(){return this.state.subject}},{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:"dateCreated",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}},{key:"participantSid",get:function(){return this.state.participantSid}},{key:"aggregatedDeliveryReceipt",get:function(){return this.state.aggregatedDeliveryReceipt}}]),t}(_.EventEmitter);y([j.validateTypesAsync("string"),g("design:type",Function),g("design:paramtypes",[String]),g("design:returntype",n.default)],I.prototype,"updateBody",null),y([j.validateTypesAsync(["string","number","boolean","object",j.literal(null)]),g("design:type",Function),g("design:paramtypes",[Object]),g("design:returntype",n.default)],I.prototype,"updateAttributes",null),r.Message=I},{"./aggregateddeliveryreceipt":1,"./detaileddeliveryreceipt":9,"./logger":12,"./media":13,"./restpaginator":17,"./util":27,"babel-runtime/core-js/json/stringify":31,"babel-runtime/core-js/object/define-property":36,"babel-runtime/core-js/object/get-own-property-descriptor":37,"babel-runtime/core-js/object/get-prototype-of":38,"babel-runtime/core-js/promise":41,"babel-runtime/core-js/reflect/metadata":43,"babel-runtime/helpers/asyncToGenerator":47,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/helpers/toConsumableArray":54,"babel-runtime/helpers/typeof":55,"babel-runtime/regenerator":56,events:199,"twilio-sdk-type-validator":232}],15:[function(e,t,r){"use strict";var n=v(e("babel-runtime/core-js/promise")),i=v(e("babel-runtime/core-js/json/stringify")),s=v(e("babel-runtime/regenerator")),a=v(e("babel-runtime/helpers/asyncToGenerator")),o=v(e("babel-runtime/core-js/number/is-integer")),u=v(e("babel-runtime/core-js/object/get-prototype-of")),c=v(e("babel-runtime/helpers/classCallCheck")),l=v(e("babel-runtime/helpers/createClass")),d=v(e("babel-runtime/helpers/possibleConstructorReturn")),f=v(e("babel-runtime/helpers/inherits")),p=v(e("babel-runtime/core-js/reflect/metadata")),h=v(e("babel-runtime/core-js/object/define-property")),b=v(e("babel-runtime/helpers/typeof")),m=v(e("babel-runtime/core-js/object/get-own-property-descriptor"));function v(e){return e&&e.__esModule?e:{default:e}}var y=function(e,t,r,n){var i,s=arguments.length,a=s<3?t:null===n?n=(0,m.default)(t,r):n;if("object"===("undefined"==typeof Reflect?"undefined":(0,b.default)(Reflect))&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(a=(s<3?i(a):s>3?i(t,r,a):i(t,r))||a);return s>3&&a&&(0,h.default)(t,r,a),a},g=function(e,t){if("object"===("undefined"==typeof Reflect?"undefined":(0,b.default)(Reflect))&&"function"==typeof p.default)return(0,p.default)(e,t)};Object.defineProperty(r,"__esModule",{value:!0});var _=e("events"),k=e("./util"),w=e("./logger"),x=e("twilio-sdk-type-validator"),C=w.Logger.scope("Participant"),j=function(e){function t(e,r,n,i){(0,c.default)(this,t);var s=(0,d.default)(this,(t.__proto__||(0,u.default)(t)).call(this));if(s.conversation=r,s.services=e,s.state={attributes:k.parseAttributes(n.attributes,"Retrieved malformed attributes from the server for participant: "+i,C),dateCreated:n.dateCreated?k.parseTime(n.dateCreated):null,dateUpdated:n.dateCreated?k.parseTime(n.dateUpdated):null,sid:i,typingTimeout:null,isTyping:!1,identity:n.identity||null,roleSid:n.roleSid||null,lastReadMessageIndex:(0,o.default)(n.lastConsumedMessageIndex)?n.lastConsumedMessageIndex:null,lastReadTimestamp:n.lastConsumptionTimestamp?k.parseTime(n.lastConsumptionTimestamp):null,type:n.type||"chat",userInfo:n.userInfo},!n.identity&&!n.type)throw new Error("Received invalid Participant object from server: Missing identity or type of Participant.");return s}return(0,f.default)(t,e),(0,l.default)(t,[{key:"_startTyping",value:function(e){var t=this;return clearTimeout(this.state.typingTimeout),this.state.isTyping=!0,this.emit("typingStarted",this),this.conversation.emit("typingStarted",this),this.state.typingTimeout=setTimeout(function(){return t._endTyping()},e),this}},{key:"_endTyping",value:function(){this.state.typingTimeout&&(this.state.isTyping=!1,this.emit("typingEnded",this),this.conversation.emit("typingEnded",this),clearInterval(this.state.typingTimeout),this.state.typingTimeout=null)}},{key:"_update",value:function(e){var t=[],r=k.parseAttributes(e.attributes,"Retrieved malformed attributes from the server for participant: "+this.state.sid,C);e.attributes&&!k.isDeepEqual(this.state.attributes,r)&&(this.state.attributes=r,t.push("attributes"));var n=k.parseTime(e.dateUpdated);e.dateUpdated&&n.getTime()!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=n,t.push("dateUpdated"));var i=k.parseTime(e.dateCreated);if(e.dateCreated&&i.getTime()!==(this.state.dateCreated&&this.state.dateCreated.getTime())&&(this.state.dateCreated=i,t.push("dateCreated")),e.roleSid&&this.state.roleSid!==e.roleSid&&(this.state.roleSid=e.roleSid,t.push("roleSid")),!(0,o.default)(e.lastConsumedMessageIndex)&&null!==e.lastConsumedMessageIndex||this.state.lastReadMessageIndex===e.lastConsumedMessageIndex||(this.state.lastReadMessageIndex=e.lastConsumedMessageIndex,t.push("lastReadMessageIndex")),e.lastConsumptionTimestamp){var s=new Date(e.lastConsumptionTimestamp);this.state.lastReadTimestamp&&this.state.lastReadTimestamp.getTime()===s.getTime()||(this.state.lastReadTimestamp=s,t.push("lastReadTimestamp"))}return t.length>0&&this.emit("updated",{participant:this,updateReasons:t}),this}},{key:"getUser",value:function(){var e=(0,a.default)(s.default.mark(function e(){return s.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 Participant 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)}));return function(){return e.apply(this,arguments)}}()},{key:"remove",value:function(){var e=(0,a.default)(s.default.mark(function e(){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.conversation.removeParticipant(this));case 1:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"updateAttributes",value:function(){var e=(0,a.default)(s.default.mark(function e(t){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("editMemberAttributes",{channelSid:this.conversation.sid,memberSid:this.sid,attributes:(0,i.default)(t)});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"sid",get:function(){return this.state.sid}},{key:"attributes",get:function(){return this.state.attributes}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"identity",get:function(){return this.state.identity}},{key:"isTyping",get:function(){return this.state.isTyping}},{key:"lastReadMessageIndex",get:function(){return this.state.lastReadMessageIndex}},{key:"lastReadTimestamp",get:function(){return this.state.lastReadTimestamp}},{key:"roleSid",get:function(){return this.state.roleSid}},{key:"type",get:function(){return this.state.type}}]),t}(_.EventEmitter);y([x.validateTypesAsync(["string","number","boolean","object",x.literal(null)]),g("design:type",Function),g("design:paramtypes",[Object]),g("design:returntype",n.default)],j.prototype,"updateAttributes",null),r.Participant=j},{"./logger":12,"./util":27,"babel-runtime/core-js/json/stringify":31,"babel-runtime/core-js/number/is-integer":33,"babel-runtime/core-js/object/define-property":36,"babel-runtime/core-js/object/get-own-property-descriptor":37,"babel-runtime/core-js/object/get-prototype-of":38,"babel-runtime/core-js/promise":41,"babel-runtime/core-js/reflect/metadata":43,"babel-runtime/helpers/asyncToGenerator":47,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/helpers/typeof":55,"babel-runtime/regenerator":56,events:199,"twilio-sdk-type-validator":232}],16:[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":48}],17:[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":41,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49}],18:[function(e,t,r){"use strict";var n=f(e("babel-runtime/regenerator")),i=f(e("babel-runtime/helpers/asyncToGenerator")),s=f(e("babel-runtime/core-js/promise")),a=f(e("babel-runtime/core-js/get-iterator")),o=f(e("babel-runtime/helpers/slicedToArray")),u=f(e("babel-runtime/core-js/object/assign")),c=f(e("babel-runtime/core-js/map")),l=f(e("babel-runtime/helpers/classCallCheck")),d=f(e("babel-runtime/helpers/createClass"));function f(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var p=e("operation-retrier"),h=function(){function e(t,r){var n=this;(0,l.default)(this,e),this.config=t,this.services=r,this.cache=new c.default,this.cacheLifetime=0,this.services.session.getHttpCacheInterval().then(function(e){n.cacheLifetime=1e3*e,n.cleanupCache()})}return(0,d.default)(e,[{key:"backoffConfig",value:function(){return(0,u.default)(this.config.backoffConfigDefault,this.config.backoffConfigOverride)}},{key:"retryWhenThrottled",value:function(){return void 0!==this.config.retryWhenThrottledOverride?this.config.retryWhenThrottledOverride:void 0!==this.config.retryWhenThrottledDefault&&this.config.retryWhenThrottledDefault}},{key:"isExpired",value:function(e){return!this.cacheLifetime||Date.now()-e>this.cacheLifetime}},{key:"cleanupCache",value:function(){var e=!0,t=!1,r=void 0;try{for(var n,i=(0,a.default)(this.cache);!(e=(n=i.next()).done);e=!0){var s=n.value,u=(0,o.default)(s,2),c=u[0],l=u[1];this.isExpired(l.timestamp)&&this.cache.delete(c)}}catch(e){t=!0,r=e}finally{try{!e&&i.return&&i.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 s.default(function(n,i){var s=[502,503,504];r&&s.push(429);var a=new p.Retrier(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(){var e=(0,i.default)(n.default.mark(function e(t){var r,i,s,a=this;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.cache.get(t))||this.isExpired(r.timestamp)){e.next=3;break}return e.abrupt("return",r.response);case 3:return i={},e.next=6,this.executeWithRetry(function(){return a.services.transport.get(t,i,a.config.productId)},this.retryWhenThrottled());case 6:return s=e.sent,this.cache.set(t,{response:s,timestamp:Date.now()}),this.pokeTimer(),e.abrupt("return",s);case 10:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()}]),e}();r.Network=h},{"babel-runtime/core-js/get-iterator":29,"babel-runtime/core-js/map":32,"babel-runtime/core-js/object/assign":34,"babel-runtime/core-js/promise":41,"babel-runtime/helpers/asyncToGenerator":47,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/slicedToArray":53,"babel-runtime/regenerator":56,"operation-retrier":204}],19:[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.readHorizonRequests=new i.default,this.readHorizonUpdateTimer=null}return(0,s.default)(e,[{key:"getReportInterval",value:function(){return this.services.session.getConsumptionReportInterval().then(function(e){return 1e3*e})}},{key:"delayedSendReadHorizon",value:function(e){var t=this;null===this.readHorizonUpdateTimer&&(this.sendConsumptionReport(!0),this.readHorizonUpdateTimer=setTimeout(function(){t.sendConsumptionReport(!1)},e))}},{key:"sendConsumptionReport",value:function(e){var t=this,r=[],n=new i.default;this.readHorizonRequests.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.readHorizonUpdateTimer=null),this.readHorizonRequests.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 LastReadMessageIndex",null),t)}},{key:"processConsumptionReportError",value:function(e,t){t.forEach(function(t){return t.forEach(function(t){return t.reject(e)})})}},{key:"updateLastReadMessageIndexForConversation",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.delayedSendReadHorizon(e)})})}},{key:"advanceLastReadMessageIndexForConversation",value:function(e,t,r){var i=this,s=this.readHorizonRequests.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&&tDate.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,this.config.productId).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=d},{"../interfaces/notificationtypes":10,"../logger":12,"babel-runtime/core-js/map":32,"babel-runtime/core-js/promise":41,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49}],21:[function(e,t,r){"use strict";var n=c(e("babel-runtime/regenerator")),i=c(e("babel-runtime/helpers/asyncToGenerator")),s=c(e("babel-runtime/core-js/promise")),a=c(e("babel-runtime/core-js/map")),o=c(e("babel-runtime/helpers/createClass")),u=c(e("babel-runtime/helpers/classCallCheck"));function c(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var l=e("uuid"),d=e("platform"),f=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,u.default)(this,e)};var _=function(){function e(t,r){(0,u.default)(this,e);var n="undefined"!=typeof navigator?d.parse(navigator.userAgent):d;this.services=t,this.config=r,this.sessionInfo=new b.Deferred,this.currentContext={},this.pendingCommands=new a.default,this.sessionStreamPromise=null,this.endpointPlatform=["JS",v,n.os,n.name,n.version].join("|")}return(0,o.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:"4",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 s.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!=f.ResponseCodes.ACCESS_FORBIDDEN_FOR_IDENTITY&&o.code!==f.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.data.hasOwnProperty("response")&&e.data.hasOwnProperty("commandId")&&this.pendingCommands.has(e.data.commandId)){var t=e.data,r=t.commandId;if(t.response.status===f.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(){var e=(0,i.default)(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,messagesReceiptsUrl:this.config.baseUrl+t.links.messagesReceiptsUrl});case 4:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getConversationsId",value:function(){var e=(0,i.default)(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)}));return function(){return e.apply(this,arguments)}}()},{key:"getMyConversationsId",value:function(){var e=(0,i.default)(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)}));return function(){return e.apply(this,arguments)}}()},{key:"getMaxUserInfosToSubscribe",value:function(){var e=(0,i.default)(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)}));return function(){return e.apply(this,arguments)}}()},{key:"getUsersData",value:function(){return this.sessionInfo.promise.then(function(e){return{user:e.userInfo,identity:e.identity}})}},{key:"getConsumptionReportInterval",value:function(){var e=(0,i.default)(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]])}));return function(){return e.apply(this,arguments)}}()},{key:"getHttpCacheInterval",value:function(){var e=(0,i.default)(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]])}));return function(){return e.apply(this,arguments)}}()},{key:"identity",get:function(){return this.sessionInfo.current.identity}},{key:"reachabilityEnabled",get:function(){return this.currentContext.reachabilityEnabled}}]),e}();r.Session=_},{"./../package.json":294,"./interfaces/responsecodes":11,"./logger":12,"./sessionerror":22,"./util/deferred":26,"babel-runtime/core-js/map":32,"babel-runtime/core-js/promise":41,"babel-runtime/helpers/asyncToGenerator":47,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/regenerator":56,"iso8601-duration":200,platform:206,uuid:289}],22:[function(e,t,r){"use strict";var n=d(e("babel-runtime/core-js/object/create")),i=d(e("babel-runtime/core-js/object/set-prototype-of")),s=d(e("babel-runtime/core-js/array/from")),a=d(e("babel-runtime/core-js/reflect/construct")),o=d(e("babel-runtime/core-js/object/get-prototype-of")),u=d(e("babel-runtime/helpers/classCallCheck")),c=d(e("babel-runtime/helpers/possibleConstructorReturn")),l=d(e("babel-runtime/helpers/inherits"));function d(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var f=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=f},{"babel-runtime/core-js/array/from":28,"babel-runtime/core-js/object/create":35,"babel-runtime/core-js/object/get-prototype-of":38,"babel-runtime/core-js/object/set-prototype-of":40,"babel-runtime/core-js/reflect/construct":42,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52}],23:[function(e,t,r){"use strict";var n=o(e("babel-runtime/regenerator")),i=o(e("babel-runtime/helpers/asyncToGenerator")),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("./util/index"),c=e("./restpaginator"),l=e("./synclistdescriptor"),d=function(){function e(t){(0,s.default)(this,e),this.services=t}return(0,a.default)(e,[{key:"getPage",value:function(){var e=(0,i.default)(n.default.mark(function e(t){var r,i,s,a=this;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},e.next=3,this.services.session.getSessionLinks();case 3:return r=e.sent,i=new u.UriBuilder(r.syncListUrl).arg("PageToken",t.pageToken).build(),e.next=7,this.services.network.get(i);case 7:return s=e.sent,e.abrupt("return",new c.RestPaginator(s.body.channels.map(function(e){return new l.SyncListDescriptor(e)}),function(e){return a.getPage({pageToken:e})},s.body.meta.previous_token,s.body.meta.next_token));case 9:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()}]),e}();r.SyncList=d},{"./restpaginator":17,"./synclistdescriptor":24,"./util/index":27,"babel-runtime/helpers/asyncToGenerator":47,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/regenerator":56}],24:[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.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.descriptor=t}},{"babel-runtime/helpers/classCallCheck":48}],25:[function(e,t,r){"use strict";var n=m(e("babel-runtime/core-js/json/stringify")),i=m(e("babel-runtime/regenerator")),s=m(e("babel-runtime/helpers/asyncToGenerator")),a=m(e("babel-runtime/core-js/promise")),o=m(e("babel-runtime/core-js/object/get-prototype-of")),u=m(e("babel-runtime/helpers/classCallCheck")),c=m(e("babel-runtime/helpers/createClass")),l=m(e("babel-runtime/helpers/possibleConstructorReturn")),d=m(e("babel-runtime/helpers/inherits")),f=m(e("babel-runtime/core-js/reflect/metadata")),p=m(e("babel-runtime/core-js/object/define-property")),h=m(e("babel-runtime/helpers/typeof")),b=m(e("babel-runtime/core-js/object/get-own-property-descriptor"));function m(e){return e&&e.__esModule?e:{default:e}}var v=function(e,t,r,n){var i,s=arguments.length,a=s<3?t:null===n?n=(0,b.default)(t,r):n;if("object"===("undefined"==typeof Reflect?"undefined":(0,h.default)(Reflect))&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(a=(s<3?i(a):s>3?i(t,r,a):i(t,r))||a);return s>3&&a&&(0,p.default)(t,r,a),a},y=function(e,t){if("object"===("undefined"==typeof Reflect?"undefined":(0,h.default)(Reflect))&&"function"==typeof f.default)return(0,f.default)(e,t)};Object.defineProperty(r,"__esModule",{value:!0});var g=e("events"),_=e("./logger"),k=e("./util"),w=e("twilio-sdk-type-validator"),x=_.Logger.scope("User"),C=function(e){function t(e,r,n){(0,u.default)(this,t);var i=(0,l.default)(this,(t.__proto__||(0,o.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,d.default)(t,e),(0,c.default)(t,[{key:"_update",value:function(e,t){var r=[];switch(x.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=k.parseAttributes(t.value,"Retrieved malformed attributes from the server for user: "+this.state.identity,x);k.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("reachabilityOnline")),this.state.notifiable!==t.notifiable&&(this.state.notifiable=t.notifiable,r.push("reachabilityNotifiable"));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){x.warn("Failed to get reachability info for ",r.state.identity,e)}):a.default.resolve()}},{key:"_fetch",value:function(){var e=(0,s.default)(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 x.debug(t.state.entityName+" ("+t.state.identity+") itemUpdated: "+e.item.key),t._update(e.item.key,e.item.data)}),a.default.all([e.get("friendlyName").then(function(e){return t._update(e.key,e.data)}),e.get("attributes").then(function(e){return t._update(e.key,e.data)}),t._updateReachabilityInfo(e,function(e){return t._update(e.key,e.data)})])}).then(function(){return x.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)}));return function(){return e.apply(this,arguments)}}()},{key:"_ensureFetched",value:function(){return this.promiseToFetch||this._fetch()}},{key:"updateAttributes",value:function(){var e=(0,s.default)(i.default.mark(function e(t){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("unsubscribed"!=this.subscribed){e.next=2;break}throw new Error("Can't modify unsubscribed object");case 2:return e.next=4,this.services.session.addCommand("editUserAttributes",{username:this.state.identity,attributes:(0,n.default)(t)});case 4:return e.abrupt("return",this);case 5:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"updateFriendlyName",value:function(){var e=(0,s.default)(i.default.mark(function e(t){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("unsubscribed"!=this.subscribed){e.next=2;break}throw new Error("Can't modify unsubscribed object");case 2:return e.next=4,this.services.session.addCommand("editUserFriendlyName",{username:this.state.identity,friendlyName:t});case 4:return e.abrupt("return",this);case 5:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"unsubscribe",value:function(){var e=(0,s.default)(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)}));return function(){return e.apply(this,arguments)}}()},{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:"isOnline",get:function(){return this.state.online}},{key:"isNotifiable",get:function(){return this.state.notifiable}},{key:"isSubscribed",get:function(){return"subscribed"==this.subscribed}}]),t}(g.EventEmitter);v([w.validateTypesAsync(["string","number","boolean","object",w.literal(null)]),y("design:type",Function),y("design:paramtypes",[Object]),y("design:returntype",a.default)],C.prototype,"updateAttributes",null),v([w.validateTypesAsync(["string",w.literal(null)]),y("design:type",Function),y("design:paramtypes",[String]),y("design:returntype",a.default)],C.prototype,"updateFriendlyName",null),r.User=C},{"./logger":12,"./util":27,"babel-runtime/core-js/json/stringify":31,"babel-runtime/core-js/object/define-property":36,"babel-runtime/core-js/object/get-own-property-descriptor":37,"babel-runtime/core-js/object/get-prototype-of":38,"babel-runtime/core-js/promise":41,"babel-runtime/core-js/reflect/metadata":43,"babel-runtime/helpers/asyncToGenerator":47,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/helpers/typeof":55,"babel-runtime/regenerator":56,events:199,"twilio-sdk-type-validator":232}],26:[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":41,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49}],27:[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,e)}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":31,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,rfc6902:211}],28:[function(e,t,r){t.exports={default:e("core-js/library/fn/array/from"),__esModule:!0}},{"core-js/library/fn/array/from":58}],29:[function(e,t,r){t.exports={default:e("core-js/library/fn/get-iterator"),__esModule:!0}},{"core-js/library/fn/get-iterator":59}],30:[function(e,t,r){t.exports={default:e("core-js/library/fn/is-iterable"),__esModule:!0}},{"core-js/library/fn/is-iterable":60}],31:[function(e,t,r){t.exports={default:e("core-js/library/fn/json/stringify"),__esModule:!0}},{"core-js/library/fn/json/stringify":61}],32:[function(e,t,r){t.exports={default:e("core-js/library/fn/map"),__esModule:!0}},{"core-js/library/fn/map":62}],33:[function(e,t,r){t.exports={default:e("core-js/library/fn/number/is-integer"),__esModule:!0}},{"core-js/library/fn/number/is-integer":63}],34:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/assign"),__esModule:!0}},{"core-js/library/fn/object/assign":64}],35:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/create"),__esModule:!0}},{"core-js/library/fn/object/create":65}],36:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/define-property"),__esModule:!0}},{"core-js/library/fn/object/define-property":66}],37:[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":67}],38:[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":68}],39:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/keys"),__esModule:!0}},{"core-js/library/fn/object/keys":69}],40:[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":70}],41:[function(e,t,r){t.exports={default:e("core-js/library/fn/promise"),__esModule:!0}},{"core-js/library/fn/promise":71}],42:[function(e,t,r){t.exports={default:e("core-js/library/fn/reflect/construct"),__esModule:!0}},{"core-js/library/fn/reflect/construct":72}],43:[function(e,t,r){t.exports={default:e("core-js/library/fn/reflect/metadata"),__esModule:!0}},{"core-js/library/fn/reflect/metadata":73}],44:[function(e,t,r){t.exports={default:e("core-js/library/fn/set"),__esModule:!0}},{"core-js/library/fn/set":74}],45:[function(e,t,r){t.exports={default:e("core-js/library/fn/symbol"),__esModule:!0}},{"core-js/library/fn/symbol":75}],46:[function(e,t,r){t.exports={default:e("core-js/library/fn/symbol/iterator"),__esModule:!0}},{"core-js/library/fn/symbol/iterator":76}],47:[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":41}],48:[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")}},{}],49:[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;rl;)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":154,"./_to-iobject":156,"./_to-length":157}],83:[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,d=6==e,f=5==e||d,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((f||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 d?-1:c||l?l:w}}},{"./_array-species-create":85,"./_ctx":95,"./_iobject":110,"./_to-length":157,"./_to-object":158}],84:[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":112,"./_is-object":114,"./_wks":165}],85:[function(e,t,r){var n=e("./_array-species-constructor");t.exports=function(e,t){return new(n(e))(t)}},{"./_array-species-constructor":84}],86:[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)}}),f&&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),d(t)}}},{"./_an-instance":79,"./_ctx":95,"./_descriptors":97,"./_for-of":103,"./_iter-define":117,"./_iter-step":119,"./_meta":122,"./_object-create":127,"./_object-dp":128,"./_redefine-all":142,"./_set-species":147,"./_validate-collection":162}],90:[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":81,"./_classof":87}],91:[function(e,t,r){"use strict";var n=e("./_redefine-all"),i=e("./_meta").getWeak,s=e("./_an-object"),a=e("./_is-object"),o=e("./_an-instance"),u=e("./_for-of"),c=e("./_array-methods"),l=e("./_has"),d=e("./_validate-collection"),f=c(5),p=c(6),h=0,b=function(e){return e._l||(e._l=new m)},m=function(){this.a=[]},v=function(e,t){return f(e.a,function(e){return e[0]===t})};m.prototype={get:function(e){var t=v(this,e);if(t)return t[1]},has:function(e){return!!v(this,e)},set:function(e,t){var r=v(this,e);r?r[1]=t:this.a.push([e,t])},delete:function(e){var t=p(this.a,function(t){return t[0]===e});return~t&&this.a.splice(t,1),!!~t}},t.exports={getConstructor:function(e,t,r,s){var c=e(function(e,n){o(e,c,t,"_i"),e._t=t,e._i=h++,e._l=void 0,null!=n&&u(n,r,e[s],e)});return n(c.prototype,{delete:function(e){if(!a(e))return!1;var r=i(e);return!0===r?b(d(this,t)).delete(e):r&&l(r,this._i)&&delete r[this._i]},has:function(e){if(!a(e))return!1;var r=i(e);return!0===r?b(d(this,t)).has(e):r&&l(r,this._i)}}),c},def:function(e,t,r){var n=i(s(t),!0);return!0===n?b(e).set(t,r):n[e._i]=r,e},ufstore:b}},{"./_an-instance":79,"./_an-object":80,"./_array-methods":83,"./_for-of":103,"./_has":105,"./_is-object":114,"./_meta":122,"./_redefine-all":142,"./_validate-collection":162}],92:[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"),d=e("./_is-object"),f=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&&!d(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),f(_,e),x[e]=_,i(i.G+i.W+i.F,x),y||m.setStrong(_,e,v),_}},{"./_an-instance":79,"./_array-methods":83,"./_descriptors":97,"./_export":101,"./_fails":102,"./_for-of":103,"./_global":104,"./_hide":106,"./_is-object":114,"./_meta":122,"./_object-dp":128,"./_redefine-all":142,"./_set-to-string-tag":148}],93:[function(e,t,r){var n=t.exports={version:"2.6.11"};"number"==typeof __e&&(__e=n)},{}],94:[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":128,"./_property-desc":141}],95:[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":77}],96:[function(e,t,r){t.exports=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e}},{}],97:[function(e,t,r){t.exports=!e("./_fails")(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},{"./_fails":102}],98:[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":104,"./_is-object":114}],99:[function(e,t,r){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},{}],100:[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":133,"./_object-keys":136,"./_object-pie":137}],101:[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,d,f=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=!f&&_&&void 0!==_[c])&&o(y,c)||(d=l?_[c]:r[c],y[c]=p&&"function"!=typeof _[c]?r[c]:m&&l?s(d,n):v&&_[c]==d?function(e){var t=function(t,r,n){if(this instanceof e){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,r)}return new e(t,r,n)}return e.apply(this,arguments)};return t.prototype=e.prototype,t}(d):b&&"function"==typeof d?s(Function.call,d):d,b&&((y.virtual||(y.virtual={}))[c]=d,e&u.R&&g&&!g[c]&&a(g,c,d)))};u.F=1,u.G=2,u.S=4,u.P=8,u.B=16,u.W=32,u.U=64,u.R=128,t.exports=u},{"./_core":93,"./_ctx":95,"./_global":104,"./_has":105,"./_hide":106}],102:[function(e,t,r){t.exports=function(e){try{return!!e()}catch(e){return!0}}},{}],103:[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,d,f){var p,h,b,m,v=f?function(){return e}:u(e),y=n(r,d,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":80,"./_ctx":95,"./_is-array-iter":111,"./_iter-call":115,"./_to-length":157,"./core.get-iterator-method":166}],104:[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)},{}],105:[function(e,t,r){var n={}.hasOwnProperty;t.exports=function(e,t){return n.call(e,t)}},{}],106:[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":97,"./_object-dp":128,"./_property-desc":141}],107:[function(e,t,r){var n=e("./_global").document;t.exports=n&&n.documentElement},{"./_global":104}],108:[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":97,"./_dom-create":98,"./_fails":102}],109:[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)}},{}],110:[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":88}],111:[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":120,"./_wks":165}],112:[function(e,t,r){var n=e("./_cof");t.exports=Array.isArray||function(e){return"Array"==n(e)}},{"./_cof":88}],113:[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":114}],114:[function(e,t,r){t.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},{}],115:[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":80}],116:[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":106,"./_object-create":127,"./_property-desc":141,"./_set-to-string-tag":148,"./_wks":165}],117:[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"),d=e("./_wks")("iterator"),f=!([].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(!f&&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[d]||j["@@iterator"]||b&&j[b],T=S||k(b),E=b?x?k("entries"):T:void 0,I="Array"==t&&j.entries||S;if(I&&(_=l(I.call(new e)))!==Object.prototype&&_.next&&(c(_,w,!0),n||"function"==typeof _[d]||a(_,d,p)),x&&S&&"values"!==S.name&&(C=!0,T=function(){return S.call(this)}),n&&!v||!f&&!C&&j[d]||a(j,d,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*(f||C),t,y);return y}},{"./_export":101,"./_hide":106,"./_iter-create":116,"./_iterators":120,"./_library":121,"./_object-gpo":134,"./_redefine":143,"./_set-to-string-tag":148,"./_wks":165}],118:[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":165}],119:[function(e,t,r){t.exports=function(e,t){return{value:t,done:!!e}}},{}],120:[function(e,t,r){t.exports={}},{}],121:[function(e,t,r){t.exports=!0},{}],122:[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:{}}})},d=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&&d.NEED&&u(e)&&!s(e,n)&&l(e),e}}},{"./_fails":102,"./_has":105,"./_is-object":114,"./_object-dp":128,"./_uid":160}],123:[function(e,t,r){var n=e("./es6.map"),i=e("./_export"),s=e("./_shared")("metadata"),a=s.store||(s.store=new(e("./es6.weak-map"))),o=function(e,t,r){var i=a.get(e);if(!i){if(!r)return;a.set(e,i=new n)}var s=i.get(t);if(!s){if(!r)return;i.set(t,s=new n)}return s};t.exports={store:a,map:o,has:function(e,t,r){var n=o(t,r,!1);return void 0!==n&&n.has(e)},get:function(e,t,r){var n=o(t,r,!1);return void 0===n?void 0:n.get(e)},set:function(e,t,r,n){o(r,n,!0).set(e,t)},keys:function(e,t){var r=o(e,t,!1),n=[];return r&&r.forEach(function(e,t){n.push(t)}),n},key:function(e){return void 0===e||"symbol"==typeof e?e:String(e)},exp:function(e){i(i.S,"Reflect",e)}}},{"./_export":101,"./_shared":150,"./es6.map":171,"./es6.weak-map":186}],124:[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 d=!0,f=document.createTextNode("");new s(c).observe(f,{characterData:!0}),r=function(){f.data=d=!d}}return function(n){var i={fn:n,next:void 0};t&&(t.next=i),e||(e=i,r()),t=i}}},{"./_cof":88,"./_global":104,"./_task":153}],125:[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":77}],126:[function(e,t,r){"use strict";var n=e("./_descriptors"),i=e("./_object-keys"),s=e("./_object-gops"),a=e("./_object-pie"),o=e("./_to-object"),u=e("./_iobject"),c=Object.assign;t.exports=!c||e("./_fails")(function(){var e={},t={},r=Symbol(),n="abcdefghijklmnopqrst";return e[r]=7,n.split("").forEach(function(e){t[e]=e}),7!=c({},e)[r]||Object.keys(c({},t)).join("")!=n})?function(e,t){for(var r=o(e),c=arguments.length,l=1,d=s.f,f=a.f;c>l;)for(var p,h=u(arguments[l++]),b=d?i(h).concat(d(h)):i(h),m=b.length,v=0;m>v;)p=b[v++],n&&!f.call(h,p)||(r[p]=h[p]);return r}:c},{"./_descriptors":97,"./_fails":102,"./_iobject":110,"./_object-gops":133,"./_object-keys":136,"./_object-pie":137,"./_to-object":158}],127:[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("