im-weapp.min.js 219 KB

123456789101112131415161718192021222324252627282930313233343536
  1. !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("leancloud-realtime",["exports"],t):t((e=e||self).AV=e.AV||{})}(this,(function(e){"use strict";var t="undefined"!=typeof window&&window.process||{};function n(){return function(){return{}}}t.env=t.env||{},global.Object=Object;var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(e,t,n){return e(n={path:t,exports:{},require:function(e,t){return s(null==t&&n.path)}},n.exports),n.exports}function s(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}var o,a=i((function(e,t){Object.defineProperty(t,"__esModule",{value:!0});
  2. /*! *****************************************************************************
  3. Copyright (c) Microsoft Corporation.
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  7. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  8. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  9. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  10. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  11. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  12. PERFORMANCE OF THIS SOFTWARE.
  13. ***************************************************************************** */
  14. var n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};var r=function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function i(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}function s(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function a(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}l((r=r.apply(e,t||[])).next())}))}function o(e,t){var n,r,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],r=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}var a={getItem:function(e){return wx.getStorageSync(e)},setItem:function(e,t){return wx.setStorageSync(e,t)},removeItem:function(e){return wx.removeStorageSync(e)},clear:function(){return wx.clearStorageSync()}};const l=new WeakMap,u=new WeakMap;function c(e){const t=l.get(e);return console.assert(null!=t,"'this' is expected an Event object, but got",e),t}function f(e){null==e.passiveListener?e.event.cancelable&&(e.canceled=!0,"function"==typeof e.event.preventDefault&&e.event.preventDefault()):"undefined"!=typeof console&&"function"==typeof console.error&&console.error("Unable to preventDefault inside passive event listener invocation.",e.passiveListener)}function h(e,t){l.set(this,{eventTarget:e,event:t,eventPhase:2,currentTarget:e,canceled:!1,stopped:!1,immediateStopped:!1,passiveListener:null,timeStamp:t.timeStamp||Date.now()}),Object.defineProperty(this,"isTrusted",{value:!1,enumerable:!0});const n=Object.keys(t);for(let e=0;e<n.length;++e){const t=n[e];t in this||Object.defineProperty(this,t,d(t))}}function d(e){return{get(){return c(this).event[e]},set(t){c(this).event[e]=t},configurable:!0,enumerable:!0}}function p(e){return{value(){const t=c(this).event;return t[e].apply(t,arguments)},configurable:!0,enumerable:!0}}function m(e){if(null==e||e===Object.prototype)return h;let t=u.get(e);return null==t&&(t=function(e,t){const n=Object.keys(t);if(0===n.length)return e;function r(t,n){e.call(this,t,n)}r.prototype=Object.create(e.prototype,{constructor:{value:r,configurable:!0,writable:!0}});for(let i=0;i<n.length;++i){const s=n[i];if(!(s in e.prototype)){const e="function"==typeof Object.getOwnPropertyDescriptor(t,s).value;Object.defineProperty(r.prototype,s,e?p(s):d(s))}}return r}(m(Object.getPrototypeOf(e)),e),u.set(e,t)),t}function g(e){return c(e).immediateStopped}function y(e,t){c(e).passiveListener=t}h.prototype={get type(){return c(this).event.type},get target(){return c(this).eventTarget},get currentTarget(){return c(this).currentTarget},composedPath(){const e=c(this).currentTarget;return null==e?[]:[e]},get NONE(){return 0},get CAPTURING_PHASE(){return 1},get AT_TARGET(){return 2},get BUBBLING_PHASE(){return 3},get eventPhase(){return c(this).eventPhase},stopPropagation(){const e=c(this);e.stopped=!0,"function"==typeof e.event.stopPropagation&&e.event.stopPropagation()},stopImmediatePropagation(){const e=c(this);e.stopped=!0,e.immediateStopped=!0,"function"==typeof e.event.stopImmediatePropagation&&e.event.stopImmediatePropagation()},get bubbles(){return Boolean(c(this).event.bubbles)},get cancelable(){return Boolean(c(this).event.cancelable)},preventDefault(){f(c(this))},get defaultPrevented(){return c(this).canceled},get composed(){return Boolean(c(this).event.composed)},get timeStamp(){return c(this).timeStamp},get srcElement(){return c(this).eventTarget},get cancelBubble(){return c(this).stopped},set cancelBubble(e){if(!e)return;const t=c(this);t.stopped=!0,"boolean"==typeof t.event.cancelBubble&&(t.event.cancelBubble=!0)},get returnValue(){return!c(this).canceled},set returnValue(e){e||f(c(this))},initEvent(){}},Object.defineProperty(h.prototype,"constructor",{value:h,configurable:!0,writable:!0}),"undefined"!=typeof window&&void 0!==window.Event&&(Object.setPrototypeOf(h.prototype,window.Event.prototype),u.set(window.Event.prototype,h));const v=new WeakMap;function b(e){return null!==e&&"object"==typeof e}function w(e){const t=v.get(e);if(null==t)throw new TypeError("'this' is expected an EventTarget object, but got another value.");return t}function E(e,t){Object.defineProperty(e,`on${t}`,function(e){return{get(){let t=w(this).get(e);for(;null!=t;){if(3===t.listenerType)return t.listener;t=t.next}return null},set(t){"function"==typeof t||b(t)||(t=null);const n=w(this);let r=null,i=n.get(e);for(;null!=i;)3===i.listenerType?null!==r?r.next=i.next:null!==i.next?n.set(e,i.next):n.delete(e):r=i,i=i.next;if(null!==t){const i={listener:t,listenerType:3,passive:!1,once:!1,next:null};null===r?n.set(e,i):r.next=i}},configurable:!0,enumerable:!0}}(t))}function _(e){function t(){T.call(this)}t.prototype=Object.create(T.prototype,{constructor:{value:t,configurable:!0,writable:!0}});for(let n=0;n<e.length;++n)E(t.prototype,e[n]);return t}function T(){if(!(this instanceof T)){if(1===arguments.length&&Array.isArray(arguments[0]))return _(arguments[0]);if(arguments.length>0){const e=new Array(arguments.length);for(let t=0;t<arguments.length;++t)e[t]=arguments[t];return _(e)}throw new TypeError("Cannot call a class as a function")}v.set(this,new Map)}T.prototype={addEventListener(e,t,n){if(null==t)return;if("function"!=typeof t&&!b(t))throw new TypeError("'listener' should be a function or an object.");const r=w(this),i=b(n),s=(i?Boolean(n.capture):Boolean(n))?1:2,o={listener:t,listenerType:s,passive:i&&Boolean(n.passive),once:i&&Boolean(n.once),next:null};let a=r.get(e);if(void 0===a)return void r.set(e,o);let l=null;for(;null!=a;){if(a.listener===t&&a.listenerType===s)return;l=a,a=a.next}l.next=o},removeEventListener(e,t,n){if(null==t)return;const r=w(this),i=(b(n)?Boolean(n.capture):Boolean(n))?1:2;let s=null,o=r.get(e);for(;null!=o;){if(o.listener===t&&o.listenerType===i)return void(null!==s?s.next=o.next:null!==o.next?r.set(e,o.next):r.delete(e));s=o,o=o.next}},dispatchEvent(e){if(null==e||"string"!=typeof e.type)throw new TypeError('"event.type" should be a string.');const t=w(this),n=e.type;let r=t.get(n);if(null==r)return!0;const i=function(e,t){return new(m(Object.getPrototypeOf(t)))(e,t)}(this,e);let s=null;for(;null!=r;){if(r.once?null!==s?s.next=r.next:null!==r.next?t.set(n,r.next):t.delete(n):s=r,y(i,r.passive?r.listener:null),"function"==typeof r.listener)try{r.listener.call(this,i)}catch(e){"undefined"!=typeof console&&"function"==typeof console.error&&console.error(e)}else 3!==r.listenerType&&"function"==typeof r.listener.handleEvent&&r.listener.handleEvent(i);if(g(i))break;r=r.next}return y(i,null),function(e,t){c(e).eventPhase=t}(i,0),function(e,t){c(e).currentTarget=t}(i,null),!i.defaultPrevented}},Object.defineProperty(T.prototype,"constructor",{value:T,configurable:!0,writable:!0}),"undefined"!=typeof window&&void 0!==window.EventTarget&&Object.setPrototypeOf(T.prototype,window.EventTarget.prototype);var S=function(e){function t(n,r){var i=this;if(!n)throw new TypeError("Failed to construct 'WebSocket': url required");if(r&&(!wx.canIUse||!wx.canIUse("connectSocket.object.protocols")))throw new Error("subprotocol not supported in weapp");(i=e.call(this)||this)._url=n,i._protocol=r,i._readyState=t.CONNECTING;var s=function(e){i._readyState=t.CLOSED,i.dispatchEvent({type:"error",message:e.errMsg})},o=wx.connectSocket({url:n,protocols:void 0===i._protocol||Array.isArray(i._protocol)?i._protocol:[i._protocol],fail:function(e){return setTimeout((function(){return s(e)}),0)}});return i._socketTask=o,o.onOpen((function(e){i._readyState=t.OPEN,i.dispatchEvent({type:"open"})})),o.onError(s),o.onMessage((function(e){var t=e.data;i.dispatchEvent({data:t,type:"message"})})),o.onClose((function(e){i._readyState=t.CLOSED;var n=e.code,r=e.reason;i.dispatchEvent({code:n,reason:r,type:"close"})})),i}return function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}(t,e),Object.defineProperty(t.prototype,"url",{get:function(){return this._url},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"protocol",{get:function(){return this._protocol},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"readyState",{get:function(){return this._readyState},enumerable:!0,configurable:!0}),t.prototype.close=function(){this.readyState!==t.CLOSED&&(this.readyState===t.CONNECTING&&console.warn("close WebSocket which is connecting might not work"),this._socketTask.close({}))},t.prototype.send=function(e){if(this.readyState!==t.OPEN)throw new Error("INVALID_STATE_ERR");if(!("string"==typeof e||e instanceof ArrayBuffer))throw new TypeError("only String/ArrayBuffer supported");this._socketTask.send({data:e})},t.CONNECTING=0,t.OPEN=1,t.CLOSING=2,t.CLOSED=3,t}(T(["open","error","message","close"]));t.WebSocket=S,t.getAuthInfo=function(e){var t=void 0===e?{}:e,n=t.platform,r=void 0===n?"weixin":n,i=t.preferUnionId,a=void 0!==i&&i,l=t.asMainAccount,u=void 0!==l&&l;return s(this,void 0,void 0,(function(){var e,t;return o(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(e,t){wx.login({success:function(n){return n.code?e(n.code):t(new Error(n.errMsg))},fail:function(e){var n=e.errMsg;return t(new Error(n))}})}))];case 1:return e=n.sent(),t={code:e},a&&(t.platform=r,t.main_account=u),[2,{authData:t,platform:r,provider:"lc_weapp"}]}}))}))},t.platformInfo={name:"Weapp"},t.request=function(e,t){var n=void 0===t?{}:t,s=n.method,o=n.data,a=n.headers;return new Promise((function(t,n){return wx.request({url:e,method:s,data:o,header:a,responseType:"text",success:function(e){var n=e.statusCode,s=e.data,o=i(e,["statusCode","data"]);t(r(r({},o),{data:"string"==typeof s?JSON.parse(s):s,status:n,ok:!(n>=400)}))},fail:function(e){n(new Error(e.errMsg))}})}))},t.storage=a,t.upload=function(e,t,n){var s=void 0===n?{}:n,o=s.headers,a=s.data,l=s.onprogress;return t&&t.data&&t.data.uri?new Promise((function(n,s){var u,c=wx.uploadFile({url:e,header:o,filePath:t.data.uri,name:t.field,formData:a,success:function(e){var t=e.statusCode,s=e.data,o=i(e,["statusCode","data"]);n(r(r({},o),{data:"string"==typeof s?JSON.parse(s):s,status:t,ok:!(t>=400)}))},fail:function(e){s(new Error(e.errMsg))}});null===(u=null==c?void 0:c.onProgressUpdate)||void 0===u||u.call(c,(function(e){var t=e.progress,n=e.totalBytesSent,r=e.totalBytesExpectedToSend;return null==l?void 0:l({percent:t,loaded:n,total:r})}))})):Promise.reject(new TypeError("File data must be an object like { uri: localPath }."))}}));(o=a)&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")&&o.default;var l,u=a.WebSocket,c=(a.getAuthInfo,a.platformInfo,a.request),f=(a.storage,a.upload,i((function(e){
  15. /**
  16. * @license long.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
  17. * Released under the Apache License, Version 2.0
  18. * see: https://github.com/dcodeIO/long.js for details
  19. */
  20. !function(t,n){e&&e.exports?e.exports=n():(t.dcodeIO=t.dcodeIO||{}).Long=n()}(r,(function(){function e(e,t,n){this.low=0|e,this.high=0|t,this.unsigned=!!n}function t(e){return!0===(e&&e.__isLong__)}e.prototype.__isLong__,Object.defineProperty(e.prototype,"__isLong__",{value:!0,enumerable:!1,configurable:!1}),e.isLong=t;var n={},r={};function i(e,t){var i,s,a;return t?(a=0<=(e>>>=0)&&e<256)&&(s=r[e])?s:(i=o(e,(0|e)<0?-1:0,!0),a&&(r[e]=i),i):(a=-128<=(e|=0)&&e<128)&&(s=n[e])?s:(i=o(e,e<0?-1:0,!1),a&&(n[e]=i),i)}function s(e,t){if(isNaN(e)||!isFinite(e))return t?m:p;if(t){if(e<0)return m;if(e>=f)return w}else{if(e<=-h)return E;if(e+1>=h)return b}return e<0?s(-e,t).neg():o(e%c|0,e/c|0,t)}function o(t,n,r){return new e(t,n,r)}e.fromInt=i,e.fromNumber=s,e.fromBits=o;var a=Math.pow;function l(e,t,n){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return p;if("number"==typeof t?(n=t,t=!1):t=!!t,(n=n||10)<2||36<n)throw RangeError("radix");var r;if((r=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===r)return l(e.substring(1),t,n).neg();for(var i=s(a(n,8)),o=p,u=0;u<e.length;u+=8){var c=Math.min(8,e.length-u),f=parseInt(e.substring(u,u+c),n);if(c<8){var h=s(a(n,c));o=o.mul(h).add(s(f))}else o=(o=o.mul(i)).add(s(f))}return o.unsigned=t,o}function u(t){return t instanceof e?t:"number"==typeof t?s(t):"string"==typeof t?l(t):o(t.low,t.high,t.unsigned)}e.fromString=l,e.fromValue=u;var c=4294967296,f=c*c,h=f/2,d=i(1<<24),p=i(0);e.ZERO=p;var m=i(0,!0);e.UZERO=m;var g=i(1);e.ONE=g;var y=i(1,!0);e.UONE=y;var v=i(-1);e.NEG_ONE=v;var b=o(-1,2147483647,!1);e.MAX_VALUE=b;var w=o(-1,-1,!0);e.MAX_UNSIGNED_VALUE=w;var E=o(0,-2147483648,!1);e.MIN_VALUE=E;var _=e.prototype;return _.toInt=function(){return this.unsigned?this.low>>>0:this.low},_.toNumber=function(){return this.unsigned?(this.high>>>0)*c+(this.low>>>0):this.high*c+(this.low>>>0)},_.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(E)){var t=s(e),n=this.div(t),r=n.mul(t).sub(this);return n.toString(e)+r.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var i=s(a(e,6),this.unsigned),o=this,l="";;){var u=o.div(i),c=(o.sub(u.mul(i)).toInt()>>>0).toString(e);if((o=u).isZero())return c+l;for(;c.length<6;)c="0"+c;l=""+c+l}},_.getHighBits=function(){return this.high},_.getHighBitsUnsigned=function(){return this.high>>>0},_.getLowBits=function(){return this.low},_.getLowBitsUnsigned=function(){return this.low>>>0},_.getNumBitsAbs=function(){if(this.isNegative())return this.eq(E)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&0==(e&1<<t);t--);return 0!=this.high?t+33:t+1},_.isZero=function(){return 0===this.high&&0===this.low},_.isNegative=function(){return!this.unsigned&&this.high<0},_.isPositive=function(){return this.unsigned||this.high>=0},_.isOdd=function(){return 1==(1&this.low)},_.isEven=function(){return 0==(1&this.low)},_.equals=function(e){return t(e)||(e=u(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},_.eq=_.equals,_.notEquals=function(e){return!this.eq(e)},_.neq=_.notEquals,_.lessThan=function(e){return this.comp(e)<0},_.lt=_.lessThan,_.lessThanOrEqual=function(e){return this.comp(e)<=0},_.lte=_.lessThanOrEqual,_.greaterThan=function(e){return this.comp(e)>0},_.gt=_.greaterThan,_.greaterThanOrEqual=function(e){return this.comp(e)>=0},_.gte=_.greaterThanOrEqual,_.compare=function(e){if(t(e)||(e=u(e)),this.eq(e))return 0;var n=this.isNegative(),r=e.isNegative();return n&&!r?-1:!n&&r?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},_.comp=_.compare,_.negate=function(){return!this.unsigned&&this.eq(E)?E:this.not().add(g)},_.neg=_.negate,_.add=function(e){t(e)||(e=u(e));var n=this.high>>>16,r=65535&this.high,i=this.low>>>16,s=65535&this.low,a=e.high>>>16,l=65535&e.high,c=e.low>>>16,f=0,h=0,d=0,p=0;return d+=(p+=s+(65535&e.low))>>>16,h+=(d+=i+c)>>>16,f+=(h+=r+l)>>>16,f+=n+a,o((d&=65535)<<16|(p&=65535),(f&=65535)<<16|(h&=65535),this.unsigned)},_.subtract=function(e){return t(e)||(e=u(e)),this.add(e.neg())},_.sub=_.subtract,_.multiply=function(e){if(this.isZero())return p;if(t(e)||(e=u(e)),e.isZero())return p;if(this.eq(E))return e.isOdd()?E:p;if(e.eq(E))return this.isOdd()?E:p;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(d)&&e.lt(d))return s(this.toNumber()*e.toNumber(),this.unsigned);var n=this.high>>>16,r=65535&this.high,i=this.low>>>16,a=65535&this.low,l=e.high>>>16,c=65535&e.high,f=e.low>>>16,h=65535&e.low,m=0,g=0,y=0,v=0;return y+=(v+=a*h)>>>16,g+=(y+=i*h)>>>16,y&=65535,g+=(y+=a*f)>>>16,m+=(g+=r*h)>>>16,g&=65535,m+=(g+=i*f)>>>16,g&=65535,m+=(g+=a*c)>>>16,m+=n*h+r*f+i*c+a*l,o((y&=65535)<<16|(v&=65535),(m&=65535)<<16|(g&=65535),this.unsigned)},_.mul=_.multiply,_.divide=function(e){if(t(e)||(e=u(e)),e.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?m:p;var n,r,i;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return m;if(e.gt(this.shru(1)))return y;i=m}else{if(this.eq(E))return e.eq(g)||e.eq(v)?E:e.eq(E)?g:(n=this.shr(1).div(e).shl(1)).eq(p)?e.isNegative()?g:v:(r=this.sub(e.mul(n)),i=n.add(r.div(e)));if(e.eq(E))return this.unsigned?m:p;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();i=p}for(r=this;r.gte(e);){n=Math.max(1,Math.floor(r.toNumber()/e.toNumber()));for(var o=Math.ceil(Math.log(n)/Math.LN2),l=o<=48?1:a(2,o-48),c=s(n),f=c.mul(e);f.isNegative()||f.gt(r);)f=(c=s(n-=l,this.unsigned)).mul(e);c.isZero()&&(c=g),i=i.add(c),r=r.sub(f)}return i},_.div=_.divide,_.modulo=function(e){return t(e)||(e=u(e)),this.sub(this.div(e).mul(e))},_.mod=_.modulo,_.not=function(){return o(~this.low,~this.high,this.unsigned)},_.and=function(e){return t(e)||(e=u(e)),o(this.low&e.low,this.high&e.high,this.unsigned)},_.or=function(e){return t(e)||(e=u(e)),o(this.low|e.low,this.high|e.high,this.unsigned)},_.xor=function(e){return t(e)||(e=u(e)),o(this.low^e.low,this.high^e.high,this.unsigned)},_.shiftLeft=function(e){return t(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?o(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):o(0,this.low<<e-32,this.unsigned)},_.shl=_.shiftLeft,_.shiftRight=function(e){return t(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?o(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):o(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},_.shr=_.shiftRight,_.shiftRightUnsigned=function(e){if(t(e)&&(e=e.toInt()),0===(e&=63))return this;var n=this.high;return e<32?o(this.low>>>e|n<<32-e,n>>>e,this.unsigned):o(32===e?n:n>>>e-32,0,this.unsigned)},_.shru=_.shiftRightUnsigned,_.toSigned=function(){return this.unsigned?o(this.low,this.high,!1):this},_.toUnsigned=function(){return this.unsigned?this:o(this.low,this.high,!0)},_.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},_.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255]},_.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24&255,e>>>16&255,e>>>8&255,255&e,t>>>24&255,t>>>16&255,t>>>8&255,255&t]},e}))}))),h=i((function(e){
  21. /**
  22. * @license bytebuffer.js (c) 2015 Daniel Wirtz <dcode@dcode.io>
  23. * Backing buffer: ArrayBuffer, Accessor: Uint8Array
  24. * Released under the Apache License, Version 2.0
  25. * see: https://github.com/dcodeIO/bytebuffer.js for details
  26. */
  27. !function(t,n){e&&e.exports?e.exports=function(){var e;try{e=f}catch(e){}return n(e)}():(t.dcodeIO=t.dcodeIO||{}).ByteBuffer=n(t.dcodeIO.Long)}(r,(function(e){var t=function(e,n,i){if(void 0===e&&(e=t.DEFAULT_CAPACITY),void 0===n&&(n=t.DEFAULT_ENDIAN),void 0===i&&(i=t.DEFAULT_NOASSERT),!i){if((e|=0)<0)throw RangeError("Illegal capacity");n=!!n,i=!!i}this.buffer=0===e?r:new ArrayBuffer(e),this.view=0===e?null:new Uint8Array(this.buffer),this.offset=0,this.markedOffset=-1,this.limit=e,this.littleEndian=n,this.noAssert=i};t.VERSION="5.0.1",t.LITTLE_ENDIAN=!0,t.BIG_ENDIAN=!1,t.DEFAULT_CAPACITY=16,t.DEFAULT_ENDIAN=t.BIG_ENDIAN,t.DEFAULT_NOASSERT=!1,t.Long=e||null;var n=t.prototype;n.__isByteBuffer__,Object.defineProperty(n,"__isByteBuffer__",{value:!0,enumerable:!1,configurable:!1});var r=new ArrayBuffer(0),i=String.fromCharCode;function s(e){var t=0;return function(){return t<e.length?e.charCodeAt(t++):null}}function o(){var e=[],t=[];return function(){if(0===arguments.length)return t.join("")+i.apply(String,e);e.length+arguments.length>1024&&(t.push(i.apply(String,e)),e.length=0),Array.prototype.push.apply(e,arguments)}}function a(e,t,n,r,i){var s,o,a=8*i-r-1,l=(1<<a)-1,u=l>>1,c=-7,f=n?i-1:0,h=n?-1:1,d=e[t+f];for(f+=h,s=d&(1<<-c)-1,d>>=-c,c+=a;c>0;s=256*s+e[t+f],f+=h,c-=8);for(o=s&(1<<-c)-1,s>>=-c,c+=r;c>0;o=256*o+e[t+f],f+=h,c-=8);if(0===s)s=1-u;else{if(s===l)return o?NaN:1/0*(d?-1:1);o+=Math.pow(2,r),s-=u}return(d?-1:1)*o*Math.pow(2,s-r)}function l(e,t,n,r,i,s){var o,a,l,u=8*s-i-1,c=(1<<u)-1,f=c>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:s-1,p=r?1:-1,m=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=c):(o=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-o))<1&&(o--,l*=2),(t+=o+f>=1?h/l:h*Math.pow(2,1-f))*l>=2&&(o++,l/=2),o+f>=c?(a=0,o=c):o+f>=1?(a=(t*l-1)*Math.pow(2,i),o+=f):(a=t*Math.pow(2,f-1)*Math.pow(2,i),o=0));i>=8;e[n+d]=255&a,d+=p,a/=256,i-=8);for(o=o<<i|a,u+=i;u>0;e[n+d]=255&o,d+=p,o/=256,u-=8);e[n+d-p]|=128*m}t.accessor=function(){return Uint8Array},t.allocate=function(e,n,r){return new t(e,n,r)},t.concat=function(e,n,r,i){"boolean"!=typeof n&&"string"==typeof n||(i=r,r=n,n=void 0);for(var s,o=0,a=0,l=e.length;a<l;++a)t.isByteBuffer(e[a])||(e[a]=t.wrap(e[a],n)),(s=e[a].limit-e[a].offset)>0&&(o+=s);if(0===o)return new t(0,r,i);var u,c=new t(o,r,i);for(a=0;a<l;)(s=(u=e[a++]).limit-u.offset)<=0||(c.view.set(u.view.subarray(u.offset,u.limit),c.offset),c.offset+=s);return c.limit=c.offset,c.offset=0,c},t.isByteBuffer=function(e){return!0===(e&&e.__isByteBuffer__)},t.type=function(){return ArrayBuffer},t.wrap=function(e,r,i,s){if("string"!=typeof r&&(s=i,i=r,r=void 0),"string"==typeof e)switch(void 0===r&&(r="utf8"),r){case"base64":return t.fromBase64(e,i);case"hex":return t.fromHex(e,i);case"binary":return t.fromBinary(e,i);case"utf8":return t.fromUTF8(e,i);case"debug":return t.fromDebug(e,i);default:throw Error("Unsupported encoding: "+r)}if(null===e||"object"!=typeof e)throw TypeError("Illegal buffer");var o;if(t.isByteBuffer(e))return(o=n.clone.call(e)).markedOffset=-1,o;if(e instanceof Uint8Array)o=new t(0,i,s),e.length>0&&(o.buffer=e.buffer,o.offset=e.byteOffset,o.limit=e.byteOffset+e.byteLength,o.view=new Uint8Array(e.buffer));else if(e instanceof ArrayBuffer)o=new t(0,i,s),e.byteLength>0&&(o.buffer=e,o.offset=0,o.limit=e.byteLength,o.view=e.byteLength>0?new Uint8Array(e):null);else{if("[object Array]"!==Object.prototype.toString.call(e))throw TypeError("Illegal buffer");(o=new t(e.length,i,s)).limit=e.length;for(var a=0;a<e.length;++a)o.view[a]=e[a]}return o},n.writeBitSet=function(e,t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if(!(e instanceof Array))throw TypeError("Illegal BitSet: Not an array");if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}var r,i=t,s=e.length,o=s>>3,a=0;for(t+=this.writeVarint32(s,t);o--;)r=1&!!e[a++]|(1&!!e[a++])<<1|(1&!!e[a++])<<2|(1&!!e[a++])<<3|(1&!!e[a++])<<4|(1&!!e[a++])<<5|(1&!!e[a++])<<6|(1&!!e[a++])<<7,this.writeByte(r,t++);if(a<s){var l=0;for(r=0;a<s;)r|=(1&!!e[a++])<<l++;this.writeByte(r,t++)}return n?(this.offset=t,this):t-i},n.readBitSet=function(e){var t=void 0===e;t&&(e=this.offset);var n,r=this.readVarint32(e),i=r.value,s=i>>3,o=0,a=[];for(e+=r.length;s--;)n=this.readByte(e++),a[o++]=!!(1&n),a[o++]=!!(2&n),a[o++]=!!(4&n),a[o++]=!!(8&n),a[o++]=!!(16&n),a[o++]=!!(32&n),a[o++]=!!(64&n),a[o++]=!!(128&n);if(o<i){var l=0;for(n=this.readByte(e++);o<i;)a[o++]=!!(n>>l++&1)}return t&&(this.offset=e),a},n.readBytes=function(e,t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+e>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+"+e+") <= "+this.buffer.byteLength)}var r=this.slice(t,t+e);return n&&(this.offset+=e),r},n.writeBytes=n.append,n.writeInt8=function(e,t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=1;var r=this.buffer.byteLength;return t>r&&this.resize((r*=2)>t?r:t),t-=1,this.view[t]=e,n&&(this.offset+=1),this},n.writeByte=n.writeInt8,n.readInt8=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var n=this.view[e];return 128==(128&n)&&(n=-(255-n+1)),t&&(this.offset+=1),n},n.readByte=n.readInt8,n.writeUint8=function(e,t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=1;var r=this.buffer.byteLength;return t>r&&this.resize((r*=2)>t?r:t),t-=1,this.view[t]=e,n&&(this.offset+=1),this},n.writeUInt8=n.writeUint8,n.readUint8=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var n=this.view[e];return t&&(this.offset+=1),n},n.readUInt8=n.readUint8,n.writeInt16=function(e,t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=2;var r=this.buffer.byteLength;return t>r&&this.resize((r*=2)>t?r:t),t-=2,this.littleEndian?(this.view[t+1]=(65280&e)>>>8,this.view[t]=255&e):(this.view[t]=(65280&e)>>>8,this.view[t+1]=255&e),n&&(this.offset+=2),this},n.writeShort=n.writeInt16,n.readInt16=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+2>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+2) <= "+this.buffer.byteLength)}var n=0;return this.littleEndian?(n=this.view[e],n|=this.view[e+1]<<8):(n=this.view[e]<<8,n|=this.view[e+1]),32768==(32768&n)&&(n=-(65535-n+1)),t&&(this.offset+=2),n},n.readShort=n.readInt16,n.writeUint16=function(e,t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=2;var r=this.buffer.byteLength;return t>r&&this.resize((r*=2)>t?r:t),t-=2,this.littleEndian?(this.view[t+1]=(65280&e)>>>8,this.view[t]=255&e):(this.view[t]=(65280&e)>>>8,this.view[t+1]=255&e),n&&(this.offset+=2),this},n.writeUInt16=n.writeUint16,n.readUint16=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+2>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+2) <= "+this.buffer.byteLength)}var n=0;return this.littleEndian?(n=this.view[e],n|=this.view[e+1]<<8):(n=this.view[e]<<8,n|=this.view[e+1]),t&&(this.offset+=2),n},n.readUInt16=n.readUint16,n.writeInt32=function(e,t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=4;var r=this.buffer.byteLength;return t>r&&this.resize((r*=2)>t?r:t),t-=4,this.littleEndian?(this.view[t+3]=e>>>24&255,this.view[t+2]=e>>>16&255,this.view[t+1]=e>>>8&255,this.view[t]=255&e):(this.view[t]=e>>>24&255,this.view[t+1]=e>>>16&255,this.view[t+2]=e>>>8&255,this.view[t+3]=255&e),n&&(this.offset+=4),this},n.writeInt=n.writeInt32,n.readInt32=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+4) <= "+this.buffer.byteLength)}var n=0;return this.littleEndian?(n=this.view[e+2]<<16,n|=this.view[e+1]<<8,n|=this.view[e],n+=this.view[e+3]<<24>>>0):(n=this.view[e+1]<<16,n|=this.view[e+2]<<8,n|=this.view[e+3],n+=this.view[e]<<24>>>0),n|=0,t&&(this.offset+=4),n},n.readInt=n.readInt32,n.writeUint32=function(e,t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=4;var r=this.buffer.byteLength;return t>r&&this.resize((r*=2)>t?r:t),t-=4,this.littleEndian?(this.view[t+3]=e>>>24&255,this.view[t+2]=e>>>16&255,this.view[t+1]=e>>>8&255,this.view[t]=255&e):(this.view[t]=e>>>24&255,this.view[t+1]=e>>>16&255,this.view[t+2]=e>>>8&255,this.view[t+3]=255&e),n&&(this.offset+=4),this},n.writeUInt32=n.writeUint32,n.readUint32=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+4) <= "+this.buffer.byteLength)}var n=0;return this.littleEndian?(n=this.view[e+2]<<16,n|=this.view[e+1]<<8,n|=this.view[e],n+=this.view[e+3]<<24>>>0):(n=this.view[e+1]<<16,n|=this.view[e+2]<<8,n|=this.view[e+3],n+=this.view[e]<<24>>>0),t&&(this.offset+=4),n},n.readUInt32=n.readUint32,e&&(n.writeInt64=function(t,n){var r=void 0===n;if(r&&(n=this.offset),!this.noAssert){if("number"==typeof t)t=e.fromNumber(t);else if("string"==typeof t)t=e.fromString(t);else if(!(t&&t instanceof e))throw TypeError("Illegal value: "+t+" (not an integer or Long)");if("number"!=typeof n||n%1!=0)throw TypeError("Illegal offset: "+n+" (not an integer)");if((n>>>=0)<0||n+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+n+" (+0) <= "+this.buffer.byteLength)}"number"==typeof t?t=e.fromNumber(t):"string"==typeof t&&(t=e.fromString(t)),n+=8;var i=this.buffer.byteLength;n>i&&this.resize((i*=2)>n?i:n),n-=8;var s=t.low,o=t.high;return this.littleEndian?(this.view[n+3]=s>>>24&255,this.view[n+2]=s>>>16&255,this.view[n+1]=s>>>8&255,this.view[n]=255&s,n+=4,this.view[n+3]=o>>>24&255,this.view[n+2]=o>>>16&255,this.view[n+1]=o>>>8&255,this.view[n]=255&o):(this.view[n]=o>>>24&255,this.view[n+1]=o>>>16&255,this.view[n+2]=o>>>8&255,this.view[n+3]=255&o,n+=4,this.view[n]=s>>>24&255,this.view[n+1]=s>>>16&255,this.view[n+2]=s>>>8&255,this.view[n+3]=255&s),r&&(this.offset+=8),this},n.writeLong=n.writeInt64,n.readInt64=function(t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+8) <= "+this.buffer.byteLength)}var r=0,i=0;this.littleEndian?(r=this.view[t+2]<<16,r|=this.view[t+1]<<8,r|=this.view[t],r+=this.view[t+3]<<24>>>0,t+=4,i=this.view[t+2]<<16,i|=this.view[t+1]<<8,i|=this.view[t],i+=this.view[t+3]<<24>>>0):(i=this.view[t+1]<<16,i|=this.view[t+2]<<8,i|=this.view[t+3],i+=this.view[t]<<24>>>0,t+=4,r=this.view[t+1]<<16,r|=this.view[t+2]<<8,r|=this.view[t+3],r+=this.view[t]<<24>>>0);var s=new e(r,i,!1);return n&&(this.offset+=8),s},n.readLong=n.readInt64,n.writeUint64=function(t,n){var r=void 0===n;if(r&&(n=this.offset),!this.noAssert){if("number"==typeof t)t=e.fromNumber(t);else if("string"==typeof t)t=e.fromString(t);else if(!(t&&t instanceof e))throw TypeError("Illegal value: "+t+" (not an integer or Long)");if("number"!=typeof n||n%1!=0)throw TypeError("Illegal offset: "+n+" (not an integer)");if((n>>>=0)<0||n+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+n+" (+0) <= "+this.buffer.byteLength)}"number"==typeof t?t=e.fromNumber(t):"string"==typeof t&&(t=e.fromString(t)),n+=8;var i=this.buffer.byteLength;n>i&&this.resize((i*=2)>n?i:n),n-=8;var s=t.low,o=t.high;return this.littleEndian?(this.view[n+3]=s>>>24&255,this.view[n+2]=s>>>16&255,this.view[n+1]=s>>>8&255,this.view[n]=255&s,n+=4,this.view[n+3]=o>>>24&255,this.view[n+2]=o>>>16&255,this.view[n+1]=o>>>8&255,this.view[n]=255&o):(this.view[n]=o>>>24&255,this.view[n+1]=o>>>16&255,this.view[n+2]=o>>>8&255,this.view[n+3]=255&o,n+=4,this.view[n]=s>>>24&255,this.view[n+1]=s>>>16&255,this.view[n+2]=s>>>8&255,this.view[n+3]=255&s),r&&(this.offset+=8),this},n.writeUInt64=n.writeUint64,n.readUint64=function(t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+8) <= "+this.buffer.byteLength)}var r=0,i=0;this.littleEndian?(r=this.view[t+2]<<16,r|=this.view[t+1]<<8,r|=this.view[t],r+=this.view[t+3]<<24>>>0,t+=4,i=this.view[t+2]<<16,i|=this.view[t+1]<<8,i|=this.view[t],i+=this.view[t+3]<<24>>>0):(i=this.view[t+1]<<16,i|=this.view[t+2]<<8,i|=this.view[t+3],i+=this.view[t]<<24>>>0,t+=4,r=this.view[t+1]<<16,r|=this.view[t+2]<<8,r|=this.view[t+3],r+=this.view[t]<<24>>>0);var s=new e(r,i,!0);return n&&(this.offset+=8),s},n.readUInt64=n.readUint64),n.writeFloat32=function(e,t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof e)throw TypeError("Illegal value: "+e+" (not a number)");if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=4;var r=this.buffer.byteLength;return t>r&&this.resize((r*=2)>t?r:t),t-=4,l(this.view,e,t,this.littleEndian,23,4),n&&(this.offset+=4),this},n.writeFloat=n.writeFloat32,n.readFloat32=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+4) <= "+this.buffer.byteLength)}var n=a(this.view,e,this.littleEndian,23,4);return t&&(this.offset+=4),n},n.readFloat=n.readFloat32,n.writeFloat64=function(e,t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof e)throw TypeError("Illegal value: "+e+" (not a number)");if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=8;var r=this.buffer.byteLength;return t>r&&this.resize((r*=2)>t?r:t),t-=8,l(this.view,e,t,this.littleEndian,52,8),n&&(this.offset+=8),this},n.writeDouble=n.writeFloat64,n.readFloat64=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+8) <= "+this.buffer.byteLength)}var n=a(this.view,e,this.littleEndian,52,8);return t&&(this.offset+=8),n},n.readDouble=n.readFloat64,t.MAX_VARINT32_BYTES=5,t.calculateVarint32=function(e){return(e>>>=0)<128?1:e<16384?2:e<1<<21?3:e<1<<28?4:5},t.zigZagEncode32=function(e){return((e|=0)<<1^e>>31)>>>0},t.zigZagDecode32=function(e){return e>>>1^-(1&e)|0},n.writeVarint32=function(e,n){var r=void 0===n;if(r&&(n=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof n||n%1!=0)throw TypeError("Illegal offset: "+n+" (not an integer)");if((n>>>=0)<0||n+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+n+" (+0) <= "+this.buffer.byteLength)}var i,s=t.calculateVarint32(e);n+=s;var o=this.buffer.byteLength;for(n>o&&this.resize((o*=2)>n?o:n),n-=s,e>>>=0;e>=128;)i=127&e|128,this.view[n++]=i,e>>>=7;return this.view[n++]=e,r?(this.offset=n,this):s},n.writeVarint32ZigZag=function(e,n){return this.writeVarint32(t.zigZagEncode32(e),n)},n.readVarint32=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var n,r=0,i=0;do{if(!this.noAssert&&e>this.limit){var s=Error("Truncated");throw s.truncated=!0,s}n=this.view[e++],r<5&&(i|=(127&n)<<7*r),++r}while(0!=(128&n));return i|=0,t?(this.offset=e,i):{value:i,length:r}},n.readVarint32ZigZag=function(e){var n=this.readVarint32(e);return"object"==typeof n?n.value=t.zigZagDecode32(n.value):n=t.zigZagDecode32(n),n},e&&(t.MAX_VARINT64_BYTES=10,t.calculateVarint64=function(t){"number"==typeof t?t=e.fromNumber(t):"string"==typeof t&&(t=e.fromString(t));var n=t.toInt()>>>0,r=t.shiftRightUnsigned(28).toInt()>>>0,i=t.shiftRightUnsigned(56).toInt()>>>0;return 0==i?0==r?n<16384?n<128?1:2:n<1<<21?3:4:r<16384?r<128?5:6:r<1<<21?7:8:i<128?9:10},t.zigZagEncode64=function(t){return"number"==typeof t?t=e.fromNumber(t,!1):"string"==typeof t?t=e.fromString(t,!1):!1!==t.unsigned&&(t=t.toSigned()),t.shiftLeft(1).xor(t.shiftRight(63)).toUnsigned()},t.zigZagDecode64=function(t){return"number"==typeof t?t=e.fromNumber(t,!1):"string"==typeof t?t=e.fromString(t,!1):!1!==t.unsigned&&(t=t.toSigned()),t.shiftRightUnsigned(1).xor(t.and(e.ONE).toSigned().negate()).toSigned()},n.writeVarint64=function(n,r){var i=void 0===r;if(i&&(r=this.offset),!this.noAssert){if("number"==typeof n)n=e.fromNumber(n);else if("string"==typeof n)n=e.fromString(n);else if(!(n&&n instanceof e))throw TypeError("Illegal value: "+n+" (not an integer or Long)");if("number"!=typeof r||r%1!=0)throw TypeError("Illegal offset: "+r+" (not an integer)");if((r>>>=0)<0||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}"number"==typeof n?n=e.fromNumber(n,!1):"string"==typeof n?n=e.fromString(n,!1):!1!==n.unsigned&&(n=n.toSigned());var s=t.calculateVarint64(n),o=n.toInt()>>>0,a=n.shiftRightUnsigned(28).toInt()>>>0,l=n.shiftRightUnsigned(56).toInt()>>>0;r+=s;var u=this.buffer.byteLength;switch(r>u&&this.resize((u*=2)>r?u:r),r-=s,s){case 10:this.view[r+9]=l>>>7&1;case 9:this.view[r+8]=9!==s?128|l:127&l;case 8:this.view[r+7]=8!==s?a>>>21|128:a>>>21&127;case 7:this.view[r+6]=7!==s?a>>>14|128:a>>>14&127;case 6:this.view[r+5]=6!==s?a>>>7|128:a>>>7&127;case 5:this.view[r+4]=5!==s?128|a:127&a;case 4:this.view[r+3]=4!==s?o>>>21|128:o>>>21&127;case 3:this.view[r+2]=3!==s?o>>>14|128:o>>>14&127;case 2:this.view[r+1]=2!==s?o>>>7|128:o>>>7&127;case 1:this.view[r]=1!==s?128|o:127&o}return i?(this.offset+=s,this):s},n.writeVarint64ZigZag=function(e,n){return this.writeVarint64(t.zigZagEncode64(e),n)},n.readVarint64=function(t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+1) <= "+this.buffer.byteLength)}var r=t,i=0,s=0,o=0,a=0;if(i=127&(a=this.view[t++]),128&a&&(i|=(127&(a=this.view[t++]))<<7,(128&a||this.noAssert&&void 0===a)&&(i|=(127&(a=this.view[t++]))<<14,(128&a||this.noAssert&&void 0===a)&&(i|=(127&(a=this.view[t++]))<<21,(128&a||this.noAssert&&void 0===a)&&(s=127&(a=this.view[t++]),(128&a||this.noAssert&&void 0===a)&&(s|=(127&(a=this.view[t++]))<<7,(128&a||this.noAssert&&void 0===a)&&(s|=(127&(a=this.view[t++]))<<14,(128&a||this.noAssert&&void 0===a)&&(s|=(127&(a=this.view[t++]))<<21,(128&a||this.noAssert&&void 0===a)&&(o=127&(a=this.view[t++]),(128&a||this.noAssert&&void 0===a)&&(o|=(127&(a=this.view[t++]))<<7,128&a||this.noAssert&&void 0===a))))))))))throw Error("Buffer overrun");var l=e.fromBits(i|s<<28,s>>>4|o<<24,!1);return n?(this.offset=t,l):{value:l,length:t-r}},n.readVarint64ZigZag=function(n){var r=this.readVarint64(n);return r&&r.value instanceof e?r.value=t.zigZagDecode64(r.value):r=t.zigZagDecode64(r),r}),n.writeCString=function(e,t){var n=void 0===t;n&&(t=this.offset);var r,i=e.length;if(!this.noAssert){if("string"!=typeof e)throw TypeError("Illegal str: Not a string");for(r=0;r<i;++r)if(0===e.charCodeAt(r))throw RangeError("Illegal str: Contains NULL-characters");if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}i=c.calculateUTF16asUTF8(s(e))[1],t+=i+1;var o=this.buffer.byteLength;return t>o&&this.resize((o*=2)>t?o:t),t-=i+1,c.encodeUTF16toUTF8(s(e),function(e){this.view[t++]=e}.bind(this)),this.view[t++]=0,n?(this.offset=t,this):i},n.readCString=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var n,r=e,i=-1;return c.decodeUTF8toUTF16(function(){if(0===i)return null;if(e>=this.limit)throw RangeError("Illegal range: Truncated data, "+e+" < "+this.limit);return 0===(i=this.view[e++])?null:i}.bind(this),n=o(),!0),t?(this.offset=e,n()):{string:n(),length:e-r}},n.writeIString=function(e,t){var n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("string"!=typeof e)throw TypeError("Illegal str: Not a string");if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}var r,i=t;r=c.calculateUTF16asUTF8(s(e),this.noAssert)[1],t+=4+r;var o=this.buffer.byteLength;if(t>o&&this.resize((o*=2)>t?o:t),t-=4+r,this.littleEndian?(this.view[t+3]=r>>>24&255,this.view[t+2]=r>>>16&255,this.view[t+1]=r>>>8&255,this.view[t]=255&r):(this.view[t]=r>>>24&255,this.view[t+1]=r>>>16&255,this.view[t+2]=r>>>8&255,this.view[t+3]=255&r),t+=4,c.encodeUTF16toUTF8(s(e),function(e){this.view[t++]=e}.bind(this)),t!==i+4+r)throw RangeError("Illegal range: Truncated data, "+t+" == "+(t+4+r));return n?(this.offset=t,this):t-i},n.readIString=function(e){var n=void 0===e;if(n&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+4) <= "+this.buffer.byteLength)}var r=e,i=this.readUint32(e),s=this.readUTF8String(i,t.METRICS_BYTES,e+=4);return e+=s.length,n?(this.offset=e,s.string):{string:s.string,length:e-r}},t.METRICS_CHARS="c",t.METRICS_BYTES="b",n.writeUTF8String=function(e,t){var n,r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}var i=t;n=c.calculateUTF16asUTF8(s(e))[1],t+=n;var o=this.buffer.byteLength;return t>o&&this.resize((o*=2)>t?o:t),t-=n,c.encodeUTF16toUTF8(s(e),function(e){this.view[t++]=e}.bind(this)),r?(this.offset=t,this):t-i},n.writeString=n.writeUTF8String,t.calculateUTF8Chars=function(e){return c.calculateUTF16asUTF8(s(e))[0]},t.calculateUTF8Bytes=function(e){return c.calculateUTF16asUTF8(s(e))[1]},t.calculateString=t.calculateUTF8Bytes,n.readUTF8String=function(e,n,r){"number"==typeof n&&(r=n,n=void 0);var i=void 0===r;if(i&&(r=this.offset),void 0===n&&(n=t.METRICS_CHARS),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal length: "+e+" (not an integer)");if(e|=0,"number"!=typeof r||r%1!=0)throw TypeError("Illegal offset: "+r+" (not an integer)");if((r>>>=0)<0||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}var s,a=0,l=r;if(n===t.METRICS_CHARS){if(s=o(),c.decodeUTF8(function(){return a<e&&r<this.limit?this.view[r++]:null}.bind(this),(function(e){++a,c.UTF8toUTF16(e,s)})),a!==e)throw RangeError("Illegal range: Truncated data, "+a+" == "+e);return i?(this.offset=r,s()):{string:s(),length:r-l}}if(n===t.METRICS_BYTES){if(!this.noAssert){if("number"!=typeof r||r%1!=0)throw TypeError("Illegal offset: "+r+" (not an integer)");if((r>>>=0)<0||r+e>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+"+e+") <= "+this.buffer.byteLength)}var u=r+e;if(c.decodeUTF8toUTF16(function(){return r<u?this.view[r++]:null}.bind(this),s=o(),this.noAssert),r!==u)throw RangeError("Illegal range: Truncated data, "+r+" == "+u);return i?(this.offset=r,s()):{string:s(),length:r-l}}throw TypeError("Unsupported metrics: "+n)},n.readString=n.readUTF8String,n.writeVString=function(e,n){var r=void 0===n;if(r&&(n=this.offset),!this.noAssert){if("string"!=typeof e)throw TypeError("Illegal str: Not a string");if("number"!=typeof n||n%1!=0)throw TypeError("Illegal offset: "+n+" (not an integer)");if((n>>>=0)<0||n+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+n+" (+0) <= "+this.buffer.byteLength)}var i,o,a=n;i=c.calculateUTF16asUTF8(s(e),this.noAssert)[1],o=t.calculateVarint32(i),n+=o+i;var l=this.buffer.byteLength;if(n>l&&this.resize((l*=2)>n?l:n),n-=o+i,n+=this.writeVarint32(i,n),c.encodeUTF16toUTF8(s(e),function(e){this.view[n++]=e}.bind(this)),n!==a+i+o)throw RangeError("Illegal range: Truncated data, "+n+" == "+(n+i+o));return r?(this.offset=n,this):n-a},n.readVString=function(e){var n=void 0===e;if(n&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var r=e,i=this.readVarint32(e),s=this.readUTF8String(i.value,t.METRICS_BYTES,e+=i.length);return e+=s.length,n?(this.offset=e,s.string):{string:s.string,length:e-r}},n.append=function(e,n,r){"number"!=typeof n&&"string"==typeof n||(r=n,n=void 0);var i=void 0===r;if(i&&(r=this.offset),!this.noAssert){if("number"!=typeof r||r%1!=0)throw TypeError("Illegal offset: "+r+" (not an integer)");if((r>>>=0)<0||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}e instanceof t||(e=t.wrap(e,n));var s=e.limit-e.offset;if(s<=0)return this;r+=s;var o=this.buffer.byteLength;return r>o&&this.resize((o*=2)>r?o:r),r-=s,this.view.set(e.view.subarray(e.offset,e.limit),r),e.offset+=s,i&&(this.offset+=s),this},n.appendTo=function(e,t){return e.append(this,t),this},n.assert=function(e){return this.noAssert=!e,this},n.capacity=function(){return this.buffer.byteLength},n.clear=function(){return this.offset=0,this.limit=this.buffer.byteLength,this.markedOffset=-1,this},n.clone=function(e){var n=new t(0,this.littleEndian,this.noAssert);return e?(n.buffer=new ArrayBuffer(this.buffer.byteLength),n.view=new Uint8Array(n.buffer)):(n.buffer=this.buffer,n.view=this.view),n.offset=this.offset,n.markedOffset=this.markedOffset,n.limit=this.limit,n},n.compact=function(e,t){if(void 0===e&&(e=this.offset),void 0===t&&(t=this.limit),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,e<0||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}if(0===e&&t===this.buffer.byteLength)return this;var n=t-e;if(0===n)return this.buffer=r,this.view=null,this.markedOffset>=0&&(this.markedOffset-=e),this.offset=0,this.limit=0,this;var i=new ArrayBuffer(n),s=new Uint8Array(i);return s.set(this.view.subarray(e,t)),this.buffer=i,this.view=s,this.markedOffset>=0&&(this.markedOffset-=e),this.offset=0,this.limit=n,this},n.copy=function(e,n){if(void 0===e&&(e=this.offset),void 0===n&&(n=this.limit),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof n||n%1!=0)throw TypeError("Illegal end: Not an integer");if(n>>>=0,e<0||e>n||n>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+n+" <= "+this.buffer.byteLength)}if(e===n)return new t(0,this.littleEndian,this.noAssert);var r=n-e,i=new t(r,this.littleEndian,this.noAssert);return i.offset=0,i.limit=r,i.markedOffset>=0&&(i.markedOffset-=e),this.copyTo(i,0,e,n),i},n.copyTo=function(e,n,r,i){var s,o;if(!this.noAssert&&!t.isByteBuffer(e))throw TypeError("Illegal target: Not a ByteBuffer");if(n=(o=void 0===n)?e.offset:0|n,r=(s=void 0===r)?this.offset:0|r,i=void 0===i?this.limit:0|i,n<0||n>e.buffer.byteLength)throw RangeError("Illegal target range: 0 <= "+n+" <= "+e.buffer.byteLength);if(r<0||i>this.buffer.byteLength)throw RangeError("Illegal source range: 0 <= "+r+" <= "+this.buffer.byteLength);var a=i-r;return 0===a?e:(e.ensureCapacity(n+a),e.view.set(this.view.subarray(r,i),n),s&&(this.offset+=a),o&&(e.offset+=a),this)},n.ensureCapacity=function(e){var t=this.buffer.byteLength;return t<e?this.resize((t*=2)>e?t:e):this},n.fill=function(e,t,n){var r=void 0===t;if(r&&(t=this.offset),"string"==typeof e&&e.length>0&&(e=e.charCodeAt(0)),void 0===t&&(t=this.offset),void 0===n&&(n=this.limit),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal begin: Not an integer");if(t>>>=0,"number"!=typeof n||n%1!=0)throw TypeError("Illegal end: Not an integer");if(n>>>=0,t<0||t>n||n>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+t+" <= "+n+" <= "+this.buffer.byteLength)}if(t>=n)return this;for(;t<n;)this.view[t++]=e;return r&&(this.offset=t),this},n.flip=function(){return this.limit=this.offset,this.offset=0,this},n.mark=function(e){if(e=void 0===e?this.offset:e,!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+0) <= "+this.buffer.byteLength)}return this.markedOffset=e,this},n.order=function(e){if(!this.noAssert&&"boolean"!=typeof e)throw TypeError("Illegal littleEndian: Not a boolean");return this.littleEndian=!!e,this},n.LE=function(e){return this.littleEndian=void 0===e||!!e,this},n.BE=function(e){return this.littleEndian=void 0!==e&&!e,this},n.prepend=function(e,n,r){"number"!=typeof n&&"string"==typeof n||(r=n,n=void 0);var i=void 0===r;if(i&&(r=this.offset),!this.noAssert){if("number"!=typeof r||r%1!=0)throw TypeError("Illegal offset: "+r+" (not an integer)");if((r>>>=0)<0||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}e instanceof t||(e=t.wrap(e,n));var s=e.limit-e.offset;if(s<=0)return this;var o=s-r;if(o>0){var a=new ArrayBuffer(this.buffer.byteLength+o),l=new Uint8Array(a);l.set(this.view.subarray(r,this.buffer.byteLength),s),this.buffer=a,this.view=l,this.offset+=o,this.markedOffset>=0&&(this.markedOffset+=o),this.limit+=o,r+=o}else new Uint8Array(this.buffer);return this.view.set(e.view.subarray(e.offset,e.limit),r-s),e.offset=e.limit,i&&(this.offset-=s),this},n.prependTo=function(e,t){return e.prepend(this,t),this},n.printDebug=function(e){"function"!=typeof e&&(e=console.log.bind(console)),e(this.toString()+"\n-------------------------------------------------------------------\n"+this.toDebug(!0))},n.remaining=function(){return this.limit-this.offset},n.reset=function(){return this.markedOffset>=0?(this.offset=this.markedOffset,this.markedOffset=-1):this.offset=0,this},n.resize=function(e){if(!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal capacity: "+e+" (not an integer)");if((e|=0)<0)throw RangeError("Illegal capacity: 0 <= "+e)}if(this.buffer.byteLength<e){var t=new ArrayBuffer(e),n=new Uint8Array(t);n.set(this.view),this.buffer=t,this.view=n}return this},n.reverse=function(e,t){if(void 0===e&&(e=this.offset),void 0===t&&(t=this.limit),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,e<0||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}return e===t||Array.prototype.reverse.call(this.view.subarray(e,t)),this},n.skip=function(e){if(!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal length: "+e+" (not an integer)");e|=0}var t=this.offset+e;if(!this.noAssert&&(t<0||t>this.buffer.byteLength))throw RangeError("Illegal length: 0 <= "+this.offset+" + "+e+" <= "+this.buffer.byteLength);return this.offset=t,this},n.slice=function(e,t){if(void 0===e&&(e=this.offset),void 0===t&&(t=this.limit),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,e<0||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}var n=this.clone();return n.offset=e,n.limit=t,n},n.toBuffer=function(e){var t=this.offset,n=this.limit;if(!this.noAssert){if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: Not an integer");if(t>>>=0,"number"!=typeof n||n%1!=0)throw TypeError("Illegal limit: Not an integer");if(n>>>=0,t<0||t>n||n>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+t+" <= "+n+" <= "+this.buffer.byteLength)}if(!e&&0===t&&n===this.buffer.byteLength)return this.buffer;if(t===n)return r;var i=new ArrayBuffer(n-t);return new Uint8Array(i).set(new Uint8Array(this.buffer).subarray(t,n),0),i},n.toArrayBuffer=n.toBuffer,n.toString=function(e,t,n){if(void 0===e)return"ByteBufferAB(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+")";switch("number"==typeof e&&(n=t=e="utf8"),e){case"utf8":return this.toUTF8(t,n);case"base64":return this.toBase64(t,n);case"hex":return this.toHex(t,n);case"binary":return this.toBinary(t,n);case"debug":return this.toDebug();case"columns":return this.toColumns();default:throw Error("Unsupported encoding: "+e)}};var u=function(){for(var e={},t=[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47],n=[],r=0,i=t.length;r<i;++r)n[t[r]]=r;return e.encode=function(e,n){for(var r,i;null!==(r=e());)n(t[r>>2&63]),i=(3&r)<<4,null!==(r=e())?(n(t[63&((i|=r>>4&15)|r>>4&15)]),i=(15&r)<<2,null!==(r=e())?(n(t[63&(i|r>>6&3)]),n(t[63&r])):(n(t[63&i]),n(61))):(n(t[63&i]),n(61),n(61))},e.decode=function(e,t){var r,i,s;function o(e){throw Error("Illegal character code: "+e)}for(;null!==(r=e());)if(void 0===(i=n[r])&&o(r),null!==(r=e())&&(void 0===(s=n[r])&&o(r),t(i<<2>>>0|(48&s)>>4),null!==(r=e()))){if(void 0===(i=n[r])){if(61===r)break;o(r)}if(t((15&s)<<4>>>0|(60&i)>>2),null!==(r=e())){if(void 0===(s=n[r])){if(61===r)break;o(r)}t((3&i)<<6>>>0|s)}}},e.test=function(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)},e}();n.toBase64=function(e,t){if(void 0===e&&(e=this.offset),void 0===t&&(t=this.limit),t|=0,(e|=0)<0||t>this.capacity||e>t)throw RangeError("begin, end");var n;return u.encode(function(){return e<t?this.view[e++]:null}.bind(this),n=o()),n()},t.fromBase64=function(e,n){if("string"!=typeof e)throw TypeError("str");var r=new t(e.length/4*3,n),i=0;return u.decode(s(e),(function(e){r.view[i++]=e})),r.limit=i,r},t.btoa=function(e){return t.fromBinary(e).toBase64()},t.atob=function(e){return t.fromBase64(e).toBinary()},n.toBinary=function(e,t){if(void 0===e&&(e=this.offset),void 0===t&&(t=this.limit),t|=0,(e|=0)<0||t>this.capacity()||e>t)throw RangeError("begin, end");if(e===t)return"";for(var n=[],r=[];e<t;)n.push(this.view[e++]),n.length>=1024&&(r.push(String.fromCharCode.apply(String,n)),n=[]);return r.join("")+String.fromCharCode.apply(String,n)},t.fromBinary=function(e,n){if("string"!=typeof e)throw TypeError("str");for(var r,i=0,s=e.length,o=new t(s,n);i<s;){if((r=e.charCodeAt(i))>255)throw RangeError("illegal char code: "+r);o.view[i++]=r}return o.limit=s,o},n.toDebug=function(e){for(var t,n=-1,r=this.buffer.byteLength,i="",s="",o="";n<r;){if(-1!==n&&(i+=(t=this.view[n])<16?"0"+t.toString(16).toUpperCase():t.toString(16).toUpperCase(),e&&(s+=t>32&&t<127?String.fromCharCode(t):".")),++n,e&&n>0&&n%16==0&&n!==r){for(;i.length<51;)i+=" ";o+=i+s+"\n",i=s=""}n===this.offset&&n===this.limit?i+=n===this.markedOffset?"!":"|":n===this.offset?i+=n===this.markedOffset?"[":"<":n===this.limit?i+=n===this.markedOffset?"]":">":i+=n===this.markedOffset?"'":e||0!==n&&n!==r?" ":""}if(e&&" "!==i){for(;i.length<51;)i+=" ";o+=i+s+"\n"}return e?o:i},t.fromDebug=function(e,n,r){for(var i,s,o=e.length,a=new t((o+1)/3|0,n,r),l=0,u=0,c=!1,f=!1,h=!1,d=!1,p=!1;l<o;){switch(i=e.charAt(l++)){case"!":if(!r){if(f||h||d){p=!0;break}f=h=d=!0}a.offset=a.markedOffset=a.limit=u,c=!1;break;case"|":if(!r){if(f||d){p=!0;break}f=d=!0}a.offset=a.limit=u,c=!1;break;case"[":if(!r){if(f||h){p=!0;break}f=h=!0}a.offset=a.markedOffset=u,c=!1;break;case"<":if(!r){if(f){p=!0;break}f=!0}a.offset=u,c=!1;break;case"]":if(!r){if(d||h){p=!0;break}d=h=!0}a.limit=a.markedOffset=u,c=!1;break;case">":if(!r){if(d){p=!0;break}d=!0}a.limit=u,c=!1;break;case"'":if(!r){if(h){p=!0;break}h=!0}a.markedOffset=u,c=!1;break;case" ":c=!1;break;default:if(!r&&c){p=!0;break}if(s=parseInt(i+e.charAt(l++),16),!r&&(isNaN(s)||s<0||s>255))throw TypeError("Illegal str: Not a debug encoded string");a.view[u++]=s,c=!0}if(p)throw TypeError("Illegal str: Invalid symbol at "+l)}if(!r){if(!f||!d)throw TypeError("Illegal str: Missing offset or limit");if(u<a.buffer.byteLength)throw TypeError("Illegal str: Not a debug encoded string (is it hex?) "+u+" < "+o)}return a},n.toHex=function(e,t){if(e=void 0===e?this.offset:e,t=void 0===t?this.limit:t,!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,e<0||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}for(var n,r=new Array(t-e);e<t;)(n=this.view[e++])<16?r.push("0",n.toString(16)):r.push(n.toString(16));return r.join("")},t.fromHex=function(e,n,r){if(!r){if("string"!=typeof e)throw TypeError("Illegal str: Not a string");if(e.length%2!=0)throw TypeError("Illegal str: Length not a multiple of 2")}for(var i,s=e.length,o=new t(s/2|0,n),a=0,l=0;a<s;a+=2){if(i=parseInt(e.substring(a,a+2),16),!r&&(!isFinite(i)||i<0||i>255))throw TypeError("Illegal str: Contains non-hex characters");o.view[l++]=i}return o.limit=l,o};var c=function(){var e={MAX_CODEPOINT:1114111,encodeUTF8:function(e,t){var n=null;for("number"==typeof e&&(n=e,e=function(){return null});null!==n||null!==(n=e());)n<128?t(127&n):n<2048?(t(n>>6&31|192),t(63&n|128)):n<65536?(t(n>>12&15|224),t(n>>6&63|128),t(63&n|128)):(t(n>>18&7|240),t(n>>12&63|128),t(n>>6&63|128),t(63&n|128)),n=null},decodeUTF8:function(e,t){for(var n,r,i,s,o=function(e){e=e.slice(0,e.indexOf(null));var t=Error(e.toString());throw t.name="TruncatedError",t.bytes=e,t};null!==(n=e());)if(0==(128&n))t(n);else if(192==(224&n))null===(r=e())&&o([n,r]),t((31&n)<<6|63&r);else if(224==(240&n))(null===(r=e())||null===(i=e()))&&o([n,r,i]),t((15&n)<<12|(63&r)<<6|63&i);else{if(240!=(248&n))throw RangeError("Illegal starting byte: "+n);(null===(r=e())||null===(i=e())||null===(s=e()))&&o([n,r,i,s]),t((7&n)<<18|(63&r)<<12|(63&i)<<6|63&s)}},UTF16toUTF8:function(e,t){for(var n,r=null;null!==(n=null!==r?r:e());)n>=55296&&n<=57343&&null!==(r=e())&&r>=56320&&r<=57343?(t(1024*(n-55296)+r-56320+65536),r=null):t(n);null!==r&&t(r)},UTF8toUTF16:function(e,t){var n=null;for("number"==typeof e&&(n=e,e=function(){return null});null!==n||null!==(n=e());)n<=65535?t(n):(t(55296+((n-=65536)>>10)),t(n%1024+56320)),n=null},encodeUTF16toUTF8:function(t,n){e.UTF16toUTF8(t,(function(t){e.encodeUTF8(t,n)}))},decodeUTF8toUTF16:function(t,n){e.decodeUTF8(t,(function(t){e.UTF8toUTF16(t,n)}))},calculateCodePoint:function(e){return e<128?1:e<2048?2:e<65536?3:4},calculateUTF8:function(e){for(var t,n=0;null!==(t=e());)n+=t<128?1:t<2048?2:t<65536?3:4;return n},calculateUTF16asUTF8:function(t){var n=0,r=0;return e.UTF16toUTF8(t,(function(e){++n,r+=e<128?1:e<2048?2:e<65536?3:4})),[n,r]}};return e}();return n.toUTF8=function(e,t){if(void 0===e&&(e=this.offset),void 0===t&&(t=this.limit),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,e<0||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}var n;try{c.decodeUTF8toUTF16(function(){return e<t?this.view[e++]:null}.bind(this),n=o())}catch(n){if(e!==t)throw RangeError("Illegal range: Truncated data, "+e+" != "+t)}return n()},t.fromUTF8=function(e,n,r){if(!r&&"string"!=typeof e)throw TypeError("Illegal str: Not a string");var i=new t(c.calculateUTF16asUTF8(s(e),!0)[1],n,r),o=0;return c.encodeUTF16toUTF8(s(e),(function(e){i.view[o++]=e})),i.limit=o,i},t}))})),d=(l=Object.freeze({__proto__:null,default:{}}))&&l.default||l,p=i((function(e){
  28. /**
  29. * @license protobuf.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
  30. * Released under the Apache License, Version 2.0
  31. * see: https://github.com/dcodeIO/protobuf.js for details
  32. */
  33. !function(t,n){e&&e.exports?e.exports=n(h,!0):(t.dcodeIO=t.dcodeIO||{}).ProtoBuf=n(t.dcodeIO.ByteBuffer)}(r,(function(e,n){var r,i={};return i.ByteBuffer=e,i.Long=e.Long||null,i.VERSION="5.0.3",i.WIRE_TYPES={},i.WIRE_TYPES.VARINT=0,i.WIRE_TYPES.BITS64=1,i.WIRE_TYPES.LDELIM=2,i.WIRE_TYPES.STARTGROUP=3,i.WIRE_TYPES.ENDGROUP=4,i.WIRE_TYPES.BITS32=5,i.PACKABLE_WIRE_TYPES=[i.WIRE_TYPES.VARINT,i.WIRE_TYPES.BITS64,i.WIRE_TYPES.BITS32],i.TYPES={int32:{name:"int32",wireType:i.WIRE_TYPES.VARINT,defaultValue:0},uint32:{name:"uint32",wireType:i.WIRE_TYPES.VARINT,defaultValue:0},sint32:{name:"sint32",wireType:i.WIRE_TYPES.VARINT,defaultValue:0},int64:{name:"int64",wireType:i.WIRE_TYPES.VARINT,defaultValue:i.Long?i.Long.ZERO:void 0},uint64:{name:"uint64",wireType:i.WIRE_TYPES.VARINT,defaultValue:i.Long?i.Long.UZERO:void 0},sint64:{name:"sint64",wireType:i.WIRE_TYPES.VARINT,defaultValue:i.Long?i.Long.ZERO:void 0},bool:{name:"bool",wireType:i.WIRE_TYPES.VARINT,defaultValue:!1},double:{name:"double",wireType:i.WIRE_TYPES.BITS64,defaultValue:0},string:{name:"string",wireType:i.WIRE_TYPES.LDELIM,defaultValue:""},bytes:{name:"bytes",wireType:i.WIRE_TYPES.LDELIM,defaultValue:null},fixed32:{name:"fixed32",wireType:i.WIRE_TYPES.BITS32,defaultValue:0},sfixed32:{name:"sfixed32",wireType:i.WIRE_TYPES.BITS32,defaultValue:0},fixed64:{name:"fixed64",wireType:i.WIRE_TYPES.BITS64,defaultValue:i.Long?i.Long.UZERO:void 0},sfixed64:{name:"sfixed64",wireType:i.WIRE_TYPES.BITS64,defaultValue:i.Long?i.Long.ZERO:void 0},float:{name:"float",wireType:i.WIRE_TYPES.BITS32,defaultValue:0},enum:{name:"enum",wireType:i.WIRE_TYPES.VARINT,defaultValue:0},message:{name:"message",wireType:i.WIRE_TYPES.LDELIM,defaultValue:null},group:{name:"group",wireType:i.WIRE_TYPES.STARTGROUP,defaultValue:null}},i.MAP_KEY_TYPES=[i.TYPES.int32,i.TYPES.sint32,i.TYPES.sfixed32,i.TYPES.uint32,i.TYPES.fixed32,i.TYPES.int64,i.TYPES.sint64,i.TYPES.sfixed64,i.TYPES.uint64,i.TYPES.fixed64,i.TYPES.bool,i.TYPES.string,i.TYPES.bytes],i.ID_MIN=1,i.ID_MAX=536870911,i.convertFieldsToCamelCase=!1,i.populateAccessors=!0,i.populateDefaults=!0,i.Util=((r={}).IS_NODE=!("object"!=typeof t||t+""!="[object process]"||t.browser),r.XHR=function(){for(var e=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],t=null,n=0;n<e.length;n++){try{t=e[n]()}catch(e){continue}break}if(!t)throw Error("XMLHttpRequest is not supported");return t},r.fetch=function(e,t){if(t&&"function"!=typeof t&&(t=null),r.IS_NODE){var n=d;if(t)n.readFile(e,(function(e,n){t(e?null:""+n)}));else try{return n.readFileSync(e)}catch(e){return null}}else{var i=r.XHR();if(i.open("GET",e,!!t),i.setRequestHeader("Accept","text/plain"),"function"==typeof i.overrideMimeType&&i.overrideMimeType("text/plain"),!t)return i.send(null),200==i.status||0==i.status&&"string"==typeof i.responseText?i.responseText:null;if(i.onreadystatechange=function(){4==i.readyState&&(200==i.status||0==i.status&&"string"==typeof i.responseText?t(i.responseText):t(null))},4==i.readyState)return;i.send(null)}},r.toCamelCase=function(e){return e.replace(/_([a-zA-Z])/g,(function(e,t){return t.toUpperCase()}))},r),i.Lang={DELIM:/[\s\{\}=;:\[\],'"\(\)<>]/g,RULE:/^(?:required|optional|repeated|map)$/,TYPE:/^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/,NAME:/^[a-zA-Z_][a-zA-Z_0-9]*$/,TYPEDEF:/^[a-zA-Z][a-zA-Z_0-9]*$/,TYPEREF:/^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,FQTYPEREF:/^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/,NUMBER:/^-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+|([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?)|inf|nan)$/,NUMBER_DEC:/^(?:[1-9][0-9]*|0)$/,NUMBER_HEX:/^0[xX][0-9a-fA-F]+$/,NUMBER_OCT:/^0[0-7]+$/,NUMBER_FLT:/^([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?|inf|nan)$/,BOOL:/^(?:true|false)$/i,ID:/^(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,NEGID:/^\-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,STRING_DQ:/(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,STRING_SQ:/(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g},i.Reflect=function(t){var n={},r=function(e,t,n){this.builder=e,this.parent=t,this.name=n,this.className},i=r.prototype;i.fqn=function(){for(var e=this.name,t=this;;){if(null==(t=t.parent))break;e=t.name+"."+e}return e},i.toString=function(e){return(e?this.className+" ":"")+this.fqn()},i.build=function(){throw Error(this.toString(!0)+" cannot be built directly")},n.T=r;var s=function(e,t,n,i,s){r.call(this,e,t,n),this.className="Namespace",this.children=[],this.options=i||{},this.syntax=s||"proto2"},o=s.prototype=Object.create(r.prototype);o.getChildren=function(e){if(null==(e=e||null))return this.children.slice();for(var t=[],n=0,r=this.children.length;n<r;++n)this.children[n]instanceof e&&t.push(this.children[n]);return t},o.addChild=function(e){var t;if(t=this.getChild(e.name))if(t instanceof c.Field&&t.name!==t.originalName&&null===this.getChild(t.originalName))t.name=t.originalName;else{if(!(e instanceof c.Field&&e.name!==e.originalName&&null===this.getChild(e.originalName)))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+e.name);e.name=e.originalName}this.children.push(e)},o.getChild=function(e){for(var t="number"==typeof e?"id":"name",n=0,r=this.children.length;n<r;++n)if(this.children[n][t]===e)return this.children[n];return null},o.resolve=function(e,t){var r,i="string"==typeof e?e.split("."):e,s=this,o=0;if(""===i[o]){for(;null!==s.parent;)s=s.parent;o++}do{do{if(!(s instanceof n.Namespace)){s=null;break}if(!(r=s.getChild(i[o]))||!(r instanceof n.T)||t&&!(r instanceof n.Namespace)){s=null;break}s=r,o++}while(o<i.length);if(null!=s)break;if(null!==this.parent)return this.parent.resolve(e,t)}while(null!=s);return s},o.qn=function(e){var t=[],r=e;do{t.unshift(r.name),r=r.parent}while(null!==r);for(var i=1;i<=t.length;i++){var s=t.slice(t.length-i);if(e===this.resolve(s,e instanceof n.Namespace))return s.join(".")}return e.fqn()},o.build=function(){for(var e,t={},n=this.children,r=0,i=n.length;r<i;++r)(e=n[r])instanceof s&&(t[e.name]=e.build());return Object.defineProperty&&Object.defineProperty(t,"$options",{value:this.buildOpt()}),t},o.buildOpt=function(){for(var e={},t=Object.keys(this.options),n=0,r=t.length;n<r;++n){var i=t[n],s=this.options[t[n]];e[i]=s}return e},o.getOption=function(e){return void 0===e?this.options:void 0!==this.options[e]?this.options[e]:null},n.Namespace=s;var a=function(e,n,r,i,s){if(this.type=e,this.resolvedType=n,this.isMapKey=r,this.syntax=i,this.name=s,r&&t.MAP_KEY_TYPES.indexOf(e)<0)throw Error("Invalid map key type: "+e.name)},l=a.prototype;function u(e,n){if(e&&"number"==typeof e.low&&"number"==typeof e.high&&"boolean"==typeof e.unsigned&&e.low==e.low&&e.high==e.high)return new t.Long(e.low,e.high,void 0===n?e.unsigned:n);if("string"==typeof e)return t.Long.fromString(e,n||!1,10);if("number"==typeof e)return t.Long.fromNumber(e,n||!1);throw Error("not convertible to Long")}a.defaultFieldValue=function(n){if("string"==typeof n&&(n=t.TYPES[n]),void 0===n.defaultValue)throw Error("default value for type "+n.name+" is not supported");return n==t.TYPES.bytes?new e(0):n.defaultValue},l.toString=function(){return(this.name||"")+(this.isMapKey?"map":"value")+" element"},l.verifyValue=function(n){var r=this;function i(e,t){throw Error("Illegal value for "+r.toString(!0)+" of type "+r.type.name+": "+e+" ("+t+")")}switch(this.type){case t.TYPES.int32:case t.TYPES.sint32:case t.TYPES.sfixed32:return("number"!=typeof n||n==n&&n%1!=0)&&i(typeof n,"not an integer"),n>4294967295?0|n:n;case t.TYPES.uint32:case t.TYPES.fixed32:return("number"!=typeof n||n==n&&n%1!=0)&&i(typeof n,"not an integer"),n<0?n>>>0:n;case t.TYPES.int64:case t.TYPES.sint64:case t.TYPES.sfixed64:if(t.Long)try{return u(n,!1)}catch(e){i(typeof n,e.message)}else i(typeof n,"requires Long.js");case t.TYPES.uint64:case t.TYPES.fixed64:if(t.Long)try{return u(n,!0)}catch(e){i(typeof n,e.message)}else i(typeof n,"requires Long.js");case t.TYPES.bool:return"boolean"!=typeof n&&i(typeof n,"not a boolean"),n;case t.TYPES.float:case t.TYPES.double:return"number"!=typeof n&&i(typeof n,"not a number"),n;case t.TYPES.string:return"string"==typeof n||n&&n instanceof String||i(typeof n,"not a string"),""+n;case t.TYPES.bytes:return e.isByteBuffer(n)?n:e.wrap(n,"base64");case t.TYPES.enum:var s=this.resolvedType.getChildren(t.Reflect.Enum.Value);for(a=0;a<s.length;a++){if(s[a].name==n)return s[a].id;if(s[a].id==n)return s[a].id}if("proto3"===this.syntax)return("number"!=typeof n||n==n&&n%1!=0)&&i(typeof n,"not an integer"),(n>4294967295||n<0)&&i(typeof n,"not in range for uint32"),n;i(n,"not a valid enum value");case t.TYPES.group:case t.TYPES.message:if(n&&"object"==typeof n||i(typeof n,"object expected"),n instanceof this.resolvedType.clazz)return n;if(n instanceof t.Builder.Message){var o={};for(var a in n)n.hasOwnProperty(a)&&(o[a]=n[a]);n=o}return new this.resolvedType.clazz(n)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+n+" (undefined type "+this.type+")")},l.calculateLength=function(n,r){if(null===r)return 0;var i;switch(this.type){case t.TYPES.int32:return r<0?e.calculateVarint64(r):e.calculateVarint32(r);case t.TYPES.uint32:return e.calculateVarint32(r);case t.TYPES.sint32:return e.calculateVarint32(e.zigZagEncode32(r));case t.TYPES.fixed32:case t.TYPES.sfixed32:case t.TYPES.float:return 4;case t.TYPES.int64:case t.TYPES.uint64:return e.calculateVarint64(r);case t.TYPES.sint64:return e.calculateVarint64(e.zigZagEncode64(r));case t.TYPES.fixed64:case t.TYPES.sfixed64:return 8;case t.TYPES.bool:return 1;case t.TYPES.enum:return e.calculateVarint32(r);case t.TYPES.double:return 8;case t.TYPES.string:return i=e.calculateUTF8Bytes(r),e.calculateVarint32(i)+i;case t.TYPES.bytes:if(r.remaining()<0)throw Error("Illegal value for "+this.toString(!0)+": "+r.remaining()+" bytes remaining");return e.calculateVarint32(r.remaining())+r.remaining();case t.TYPES.message:return i=this.resolvedType.calculate(r),e.calculateVarint32(i)+i;case t.TYPES.group:return(i=this.resolvedType.calculate(r))+e.calculateVarint32(n<<3|t.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+r+" (unknown type)")},l.encodeValue=function(n,r,i){if(null===r)return i;switch(this.type){case t.TYPES.int32:r<0?i.writeVarint64(r):i.writeVarint32(r);break;case t.TYPES.uint32:i.writeVarint32(r);break;case t.TYPES.sint32:i.writeVarint32ZigZag(r);break;case t.TYPES.fixed32:i.writeUint32(r);break;case t.TYPES.sfixed32:i.writeInt32(r);break;case t.TYPES.int64:case t.TYPES.uint64:i.writeVarint64(r);break;case t.TYPES.sint64:i.writeVarint64ZigZag(r);break;case t.TYPES.fixed64:i.writeUint64(r);break;case t.TYPES.sfixed64:i.writeInt64(r);break;case t.TYPES.bool:"string"==typeof r?i.writeVarint32("false"===r.toLowerCase()?0:!!r):i.writeVarint32(r?1:0);break;case t.TYPES.enum:i.writeVarint32(r);break;case t.TYPES.float:i.writeFloat32(r);break;case t.TYPES.double:i.writeFloat64(r);break;case t.TYPES.string:i.writeVString(r);break;case t.TYPES.bytes:if(r.remaining()<0)throw Error("Illegal value for "+this.toString(!0)+": "+r.remaining()+" bytes remaining");var s=r.offset;i.writeVarint32(r.remaining()),i.append(r),r.offset=s;break;case t.TYPES.message:var o=(new e).LE();this.resolvedType.encode(r,o),i.writeVarint32(o.offset),i.append(o.flip());break;case t.TYPES.group:this.resolvedType.encode(r,i),i.writeVarint32(n<<3|t.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+r+" (unknown type)")}return i},l.decode=function(e,n,r){if(n!=this.type.wireType)throw Error("Unexpected wire type for element");var i,s;switch(this.type){case t.TYPES.int32:return 0|e.readVarint32();case t.TYPES.uint32:return e.readVarint32()>>>0;case t.TYPES.sint32:return 0|e.readVarint32ZigZag();case t.TYPES.fixed32:return e.readUint32()>>>0;case t.TYPES.sfixed32:return 0|e.readInt32();case t.TYPES.int64:return e.readVarint64();case t.TYPES.uint64:return e.readVarint64().toUnsigned();case t.TYPES.sint64:return e.readVarint64ZigZag();case t.TYPES.fixed64:return e.readUint64();case t.TYPES.sfixed64:return e.readInt64();case t.TYPES.bool:return!!e.readVarint32();case t.TYPES.enum:return e.readVarint32();case t.TYPES.float:return e.readFloat();case t.TYPES.double:return e.readDouble();case t.TYPES.string:return e.readVString();case t.TYPES.bytes:if(s=e.readVarint32(),e.remaining()<s)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+s+" required but got only "+e.remaining());return(i=e.clone()).limit=i.offset+s,e.offset+=s,i;case t.TYPES.message:return s=e.readVarint32(),this.resolvedType.decode(e,s);case t.TYPES.group:return this.resolvedType.decode(e,-1,r)}throw Error("[INTERNAL] Illegal decode type")},l.valueFromString=function(n){if(!this.isMapKey)throw Error("valueFromString() called on non-map-key element");switch(this.type){case t.TYPES.int32:case t.TYPES.sint32:case t.TYPES.sfixed32:case t.TYPES.uint32:case t.TYPES.fixed32:return this.verifyValue(parseInt(n));case t.TYPES.int64:case t.TYPES.sint64:case t.TYPES.sfixed64:case t.TYPES.uint64:case t.TYPES.fixed64:return this.verifyValue(n);case t.TYPES.bool:return"true"===n;case t.TYPES.string:return this.verifyValue(n);case t.TYPES.bytes:return e.fromBinary(n)}},l.valueToString=function(e){if(!this.isMapKey)throw Error("valueToString() called on non-map-key element");return this.type===t.TYPES.bytes?e.toString("binary"):e.toString()},n.Element=a;var c=function(e,t,n,r,i,o){s.call(this,e,t,n,r,o),this.className="Message",this.extensions=void 0,this.clazz=null,this.isGroup=!!i,this._fields=null,this._fieldsById=null,this._fieldsByName=null},f=c.prototype=Object.create(s.prototype);function h(e,n){var r=n.readVarint32(),i=7&r,s=r>>>3;switch(i){case t.WIRE_TYPES.VARINT:do{r=n.readUint8()}while(128==(128&r));break;case t.WIRE_TYPES.BITS64:n.offset+=8;break;case t.WIRE_TYPES.LDELIM:r=n.readVarint32(),n.offset+=r;break;case t.WIRE_TYPES.STARTGROUP:h(s,n);break;case t.WIRE_TYPES.ENDGROUP:if(s===e)return!1;throw Error("Illegal GROUPEND after unknown group: "+s+" ("+e+" expected)");case t.WIRE_TYPES.BITS32:n.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+e+": "+i)}return!0}f.build=function(n){if(this.clazz&&!n)return this.clazz;var r=function(t,n){var r=n.getChildren(t.Reflect.Message.Field),i=n.getChildren(t.Reflect.Message.OneOf),s=function(o,a){t.Builder.Message.call(this);for(var l=0,u=i.length;l<u;++l)this[i[l].name]=null;for(l=0,u=r.length;l<u;++l){var c=r[l];this[c.name]=c.repeated?[]:c.map?new t.Map(c):null,!c.required&&"proto3"!==n.syntax||null===c.defaultValue||(this[c.name]=c.defaultValue)}var f;if(arguments.length>0)if(1!==arguments.length||null===o||"object"!=typeof o||!("function"!=typeof o.encode||o instanceof s)||Array.isArray(o)||o instanceof t.Map||e.isByteBuffer(o)||o instanceof ArrayBuffer||t.Long&&o instanceof t.Long)for(l=0,u=arguments.length;l<u;++l)void 0!==(f=arguments[l])&&this.$set(r[l].name,f);else this.$set(o)},o=s.prototype=Object.create(t.Builder.Message.prototype);o.add=function(e,r,i){var s=n._fieldsByName[e];if(!i){if(!s)throw Error(this+"#"+e+" is undefined");if(!(s instanceof t.Reflect.Message.Field))throw Error(this+"#"+e+" is not a field: "+s.toString(!0));if(!s.repeated)throw Error(this+"#"+e+" is not a repeated field");r=s.verifyValue(r,!0)}return null===this[e]&&(this[e]=[]),this[e].push(r),this},o.$add=o.add,o.set=function(e,r,i){if(e&&"object"==typeof e){for(var s in i=r,e)e.hasOwnProperty(s)&&void 0!==(r=e[s])&&void 0===n._oneofsByName[s]&&this.$set(s,r,i);return this}var o=n._fieldsByName[e];if(i)this[e]=r;else{if(!o)throw Error(this+"#"+e+" is not a field: undefined");if(!(o instanceof t.Reflect.Message.Field))throw Error(this+"#"+e+" is not a field: "+o.toString(!0));this[o.name]=r=o.verifyValue(r)}if(o&&o.oneof){var a=this[o.oneof.name];null!==r?(null!==a&&a!==o.name&&(this[a]=null),this[o.oneof.name]=o.name):a===e&&(this[o.oneof.name]=null)}return this},o.$set=o.set,o.get=function(e,r){if(r)return this[e];var i=n._fieldsByName[e];if(!(i&&i instanceof t.Reflect.Message.Field))throw Error(this+"#"+e+" is not a field: undefined");if(!(i instanceof t.Reflect.Message.Field))throw Error(this+"#"+e+" is not a field: "+i.toString(!0));return this[i.name]},o.$get=o.get;for(var a=0;a<r.length;a++){var l=r[a];l instanceof t.Reflect.Message.ExtensionField||n.builder.options.populateAccessors&&function(e){var t=e.originalName.replace(/(_[a-zA-Z])/g,(function(e){return e.toUpperCase().replace("_","")}));t=t.substring(0,1).toUpperCase()+t.substring(1);var r=e.originalName.replace(/([A-Z])/g,(function(e){return"_"+e})),i=function(t,n){return this[e.name]=n?t:e.verifyValue(t),this},s=function(){return this[e.name]};null===n.getChild("set"+t)&&(o["set"+t]=i),null===n.getChild("set_"+r)&&(o["set_"+r]=i),null===n.getChild("get"+t)&&(o["get"+t]=s),null===n.getChild("get_"+r)&&(o["get_"+r]=s)}(l)}function u(n,r,i,s){if(null===n||"object"!=typeof n){if(s&&s instanceof t.Reflect.Enum){var o=t.Reflect.Enum.getName(s.object,n);if(null!==o)return o}return n}if(e.isByteBuffer(n))return r?n.toBase64():n.toBuffer();if(t.Long.isLong(n))return i?n.toString():t.Long.fromValue(n);var a;if(Array.isArray(n))return a=[],n.forEach((function(e,t){a[t]=u(e,r,i,s)})),a;if(a={},n instanceof t.Map){for(var l=n.entries(),c=l.next();!c.done;c=l.next())a[n.keyElem.valueToString(c.value[0])]=u(c.value[1],r,i,n.valueElem.resolvedType);return a}var f=n.$type,h=void 0;for(var d in n)n.hasOwnProperty(d)&&(f&&(h=f.getChild(d))?a[d]=u(n[d],r,i,h.resolvedType):a[d]=u(n[d],r,i));return a}return o.encode=function(t,r){"boolean"==typeof t&&(r=t,t=void 0);var i=!1;t||(t=new e,i=!0);var s=t.littleEndian;try{return n.encode(this,t.LE(),r),(i?t.flip():t).LE(s)}catch(e){throw t.LE(s),e}},s.encode=function(e,t,n){return new s(e).encode(t,n)},o.calculate=function(){return n.calculate(this)},o.encodeDelimited=function(t,r){var i=!1;t||(t=new e,i=!0);var s=(new e).LE();return n.encode(this,s,r).flip(),t.writeVarint32(s.remaining()),t.append(s),i?t.flip():t},o.encodeAB=function(){try{return this.encode().toArrayBuffer()}catch(e){throw e.encoded&&(e.encoded=e.encoded.toArrayBuffer()),e}},o.toArrayBuffer=o.encodeAB,o.encodeNB=function(){try{return this.encode().toBuffer()}catch(e){throw e.encoded&&(e.encoded=e.encoded.toBuffer()),e}},o.toBuffer=o.encodeNB,o.encode64=function(){try{return this.encode().toBase64()}catch(e){throw e.encoded&&(e.encoded=e.encoded.toBase64()),e}},o.toBase64=o.encode64,o.encodeHex=function(){try{return this.encode().toHex()}catch(e){throw e.encoded&&(e.encoded=e.encoded.toHex()),e}},o.toHex=o.encodeHex,o.toRaw=function(e,t){return u(this,!!e,!!t,this.$type)},o.encodeJSON=function(){return JSON.stringify(u(this,!0,!0,this.$type))},s.decode=function(t,r,i){"string"==typeof r&&(i=r,r=-1),"string"==typeof t?t=e.wrap(t,i||"base64"):e.isByteBuffer(t)||(t=e.wrap(t));var s=t.littleEndian;try{var o=n.decode(t.LE(),r);return t.LE(s),o}catch(e){throw t.LE(s),e}},s.decodeDelimited=function(t,r){if("string"==typeof t?t=e.wrap(t,r||"base64"):e.isByteBuffer(t)||(t=e.wrap(t)),t.remaining()<1)return null;var i=t.offset,s=t.readVarint32();if(t.remaining()<s)return t.offset=i,null;try{var o=n.decode(t.slice(t.offset,t.offset+s).LE());return t.offset+=s,o}catch(e){throw t.offset+=s,e}},s.decode64=function(e){return s.decode(e,"base64")},s.decodeHex=function(e){return s.decode(e,"hex")},s.decodeJSON=function(e){return new s(JSON.parse(e))},o.toString=function(){return n.toString()},Object.defineProperty&&(Object.defineProperty(s,"$options",{value:n.buildOpt()}),Object.defineProperty(o,"$options",{value:s.$options}),Object.defineProperty(s,"$type",{value:n}),Object.defineProperty(o,"$type",{value:n})),s}(t,this);this._fields=[],this._fieldsById={},this._fieldsByName={},this._oneofsByName={};for(var i,s=0,o=this.children.length;s<o;s++)if((i=this.children[s])instanceof g||i instanceof c||i instanceof b){if(r.hasOwnProperty(i.name))throw Error("Illegal reflect child of "+this.toString(!0)+": "+i.toString(!0)+" cannot override static property '"+i.name+"'");r[i.name]=i.build()}else if(i instanceof c.Field)i.build(),this._fields.push(i),this._fieldsById[i.id]=i,this._fieldsByName[i.name]=i;else if(i instanceof c.OneOf)this._oneofsByName[i.name]=i;else if(!(i instanceof c.OneOf||i instanceof v))throw Error("Illegal reflect child of "+this.toString(!0)+": "+this.children[s].toString(!0));return this.clazz=r},f.encode=function(e,t,n){for(var r,i,s=null,o=0,a=this._fields.length;o<a;++o)i=e[(r=this._fields[o]).name],r.required&&null===i?null===s&&(s=r):r.encode(n?i:r.verifyValue(i),t,e);if(null!==s){var l=Error("Missing at least one required field for "+this.toString(!0)+": "+s);throw l.encoded=t,l}return t},f.calculate=function(e){for(var t,n,r=0,i=0,s=this._fields.length;i<s;++i){if(n=e[(t=this._fields[i]).name],t.required&&null===n)throw Error("Missing at least one required field for "+this.toString(!0)+": "+t);r+=t.calculate(n,e)}return r},f.decode=function(e,n,r){"number"!=typeof n&&(n=-1);for(var i,s,o,a,l=e.offset,u=new this.clazz;e.offset<l+n||-1===n&&e.remaining()>0;){if(o=(i=e.readVarint32())>>>3,(s=7&i)===t.WIRE_TYPES.ENDGROUP){if(o!==r)throw Error("Illegal group end indicator for "+this.toString(!0)+": "+o+" ("+(r?r+" expected":"not a group")+")");break}if(a=this._fieldsById[o]){if(a.repeated&&!a.options.packed)u[a.name].push(a.decode(s,e));else if(a.map){var c=a.decode(s,e);u[a.name].set(c[0],c[1])}else if(u[a.name]=a.decode(s,e),a.oneof){var f=u[a.oneof.name];null!==f&&f!==a.name&&(u[f]=null),u[a.oneof.name]=a.name}}else switch(s){case t.WIRE_TYPES.VARINT:e.readVarint32();break;case t.WIRE_TYPES.BITS32:e.offset+=4;break;case t.WIRE_TYPES.BITS64:e.offset+=8;break;case t.WIRE_TYPES.LDELIM:var d=e.readVarint32();e.offset+=d;break;case t.WIRE_TYPES.STARTGROUP:for(;h(o,e););break;default:throw Error("Illegal wire type for unknown field "+o+" in "+this.toString(!0)+"#decode: "+s)}}for(var p=0,m=this._fields.length;p<m;++p)if(null===u[(a=this._fields[p]).name])if("proto3"===this.syntax)u[a.name]=a.defaultValue;else{if(a.required){var g=Error("Missing at least one required field for "+this.toString(!0)+": "+a.name);throw g.decoded=u,g}t.populateDefaults&&null!==a.defaultValue&&(u[a.name]=a.defaultValue)}return u},n.Message=c;var d=function(e,n,i,s,o,a,l,u,f,h){r.call(this,e,n,a),this.className="Message.Field",this.required="required"===i,this.repeated="repeated"===i,this.map="map"===i,this.keyType=s||null,this.type=o,this.resolvedType=null,this.id=l,this.options=u||{},this.defaultValue=null,this.oneof=f||null,this.syntax=h||"proto2",this.originalName=this.name,this.element=null,this.keyElement=null,!this.builder.options.convertFieldsToCamelCase||this instanceof c.ExtensionField||(this.name=t.Util.toCamelCase(this.name))},p=d.prototype=Object.create(r.prototype);p.build=function(){this.element=new a(this.type,this.resolvedType,!1,this.syntax,this.name),this.map&&(this.keyElement=new a(this.keyType,void 0,!0,this.syntax,this.name)),"proto3"!==this.syntax||this.repeated||this.map?void 0!==this.options.default&&(this.defaultValue=this.verifyValue(this.options.default)):this.defaultValue=a.defaultFieldValue(this.type)},p.verifyValue=function(e,n){n=n||!1;var r,i=this;function s(e,t){throw Error("Illegal value for "+i.toString(!0)+" of type "+i.type.name+": "+e+" ("+t+")")}if(null===e)return this.required&&s(typeof e,"required"),"proto3"===this.syntax&&this.type!==t.TYPES.message&&s(typeof e,"proto3 field without field presence cannot be null"),null;if(this.repeated&&!n){Array.isArray(e)||(e=[e]);var o=[];for(r=0;r<e.length;r++)o.push(this.element.verifyValue(e[r]));return o}return this.map&&!n?e instanceof t.Map?e:(e instanceof Object||s(typeof e,"expected ProtoBuf.Map or raw object for map field"),new t.Map(this,e)):(!this.repeated&&Array.isArray(e)&&s(typeof e,"no array expected"),this.element.verifyValue(e))},p.hasWirePresence=function(e,n){if("proto3"!==this.syntax)return null!==e;if(this.oneof&&n[this.oneof.name]===this.name)return!0;switch(this.type){case t.TYPES.int32:case t.TYPES.sint32:case t.TYPES.sfixed32:case t.TYPES.uint32:case t.TYPES.fixed32:return 0!==e;case t.TYPES.int64:case t.TYPES.sint64:case t.TYPES.sfixed64:case t.TYPES.uint64:case t.TYPES.fixed64:return 0!==e.low||0!==e.high;case t.TYPES.bool:return e;case t.TYPES.float:case t.TYPES.double:return 0!==e;case t.TYPES.string:return e.length>0;case t.TYPES.bytes:return e.remaining()>0;case t.TYPES.enum:return 0!==e;case t.TYPES.message:return null!==e;default:return!0}},p.encode=function(n,r,i){if(null===this.type||"object"!=typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===n||this.repeated&&0==n.length)return r;try{var s;if(this.repeated)if(this.options.packed&&t.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)>=0){r.writeVarint32(this.id<<3|t.WIRE_TYPES.LDELIM),r.ensureCapacity(r.offset+=1);var o=r.offset;for(s=0;s<n.length;s++)this.element.encodeValue(this.id,n[s],r);var a=r.offset-o,l=e.calculateVarint32(a);if(l>1){var u=r.slice(o,r.offset);o+=l-1,r.offset=o,r.append(u)}r.writeVarint32(a,o-l)}else for(s=0;s<n.length;s++)r.writeVarint32(this.id<<3|this.type.wireType),this.element.encodeValue(this.id,n[s],r);else this.map?n.forEach((function(n,i,s){var o=e.calculateVarint32(8|this.keyType.wireType)+this.keyElement.calculateLength(1,i)+e.calculateVarint32(16|this.type.wireType)+this.element.calculateLength(2,n);r.writeVarint32(this.id<<3|t.WIRE_TYPES.LDELIM),r.writeVarint32(o),r.writeVarint32(8|this.keyType.wireType),this.keyElement.encodeValue(1,i,r),r.writeVarint32(16|this.type.wireType),this.element.encodeValue(2,n,r)}),this):this.hasWirePresence(n,i)&&(r.writeVarint32(this.id<<3|this.type.wireType),this.element.encodeValue(this.id,n,r))}catch(e){throw Error("Illegal value for "+this.toString(!0)+": "+n+" ("+e+")")}return r},p.calculate=function(n,r){if(n=this.verifyValue(n),null===this.type||"object"!=typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===n||this.repeated&&0==n.length)return 0;var i=0;try{var s,o;if(this.repeated)if(this.options.packed&&t.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)>=0){for(i+=e.calculateVarint32(this.id<<3|t.WIRE_TYPES.LDELIM),o=0,s=0;s<n.length;s++)o+=this.element.calculateLength(this.id,n[s]);i+=e.calculateVarint32(o),i+=o}else for(s=0;s<n.length;s++)i+=e.calculateVarint32(this.id<<3|this.type.wireType),i+=this.element.calculateLength(this.id,n[s]);else this.map?n.forEach((function(n,r,s){var o=e.calculateVarint32(8|this.keyType.wireType)+this.keyElement.calculateLength(1,r)+e.calculateVarint32(16|this.type.wireType)+this.element.calculateLength(2,n);i+=e.calculateVarint32(this.id<<3|t.WIRE_TYPES.LDELIM),i+=e.calculateVarint32(o),i+=o}),this):this.hasWirePresence(n,r)&&(i+=e.calculateVarint32(this.id<<3|this.type.wireType),i+=this.element.calculateLength(this.id,n))}catch(e){throw Error("Illegal value for "+this.toString(!0)+": "+n+" ("+e+")")}return i},p.decode=function(e,n,r){var i,s;if(!(!this.map&&e==this.type.wireType||!r&&this.repeated&&this.options.packed&&e==t.WIRE_TYPES.LDELIM||this.map&&e==t.WIRE_TYPES.LDELIM))throw Error("Illegal wire type for field "+this.toString(!0)+": "+e+" ("+this.type.wireType+" expected)");if(e==t.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&t.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)>=0&&!r){s=n.readVarint32(),s=n.offset+s;for(var o=[];n.offset<s;)o.push(this.decode(this.type.wireType,n,!0));return o}if(this.map){var l=a.defaultFieldValue(this.keyType);if(i=a.defaultFieldValue(this.type),s=n.readVarint32(),n.remaining()<s)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+s+" required but got only "+n.remaining());var u=n.clone();for(u.limit=u.offset+s,n.offset+=s;u.remaining()>0;){var c=u.readVarint32();e=7&c;var f=c>>>3;if(1===f)l=this.keyElement.decode(u,e,f);else{if(2!==f)throw Error("Unexpected tag in map field key/value submessage");i=this.element.decode(u,e,f)}}return[l,i]}return this.element.decode(n,e,this.id)},n.Message.Field=d;var m=function(e,t,n,r,i,s,o){d.call(this,e,t,n,null,r,i,s,o),this.extension};m.prototype=Object.create(d.prototype),n.Message.ExtensionField=m;n.Message.OneOf=function(e,t,n){r.call(this,e,t,n),this.fields=[]};var g=function(e,t,n,r,i){s.call(this,e,t,n,r,i),this.className="Enum",this.object=null};g.getName=function(e,t){for(var n,r=Object.keys(e),i=0;i<r.length;++i)if(e[n=r[i]]===t)return n;return null},(g.prototype=Object.create(s.prototype)).build=function(e){if(this.object&&!e)return this.object;for(var n=new t.Builder.Enum,r=this.getChildren(g.Value),i=0,s=r.length;i<s;++i)n[r[i].name]=r[i].id;return Object.defineProperty&&Object.defineProperty(n,"$options",{value:this.buildOpt(),enumerable:!1}),this.object=n},n.Enum=g;var y=function(e,t,n,i){r.call(this,e,t,n),this.className="Enum.Value",this.id=i};y.prototype=Object.create(r.prototype),n.Enum.Value=y;var v=function(e,t,n,i){r.call(this,e,t,n),this.field=i};v.prototype=Object.create(r.prototype),n.Extension=v;var b=function(e,t,n,r){s.call(this,e,t,n,r),this.className="Service",this.clazz=null};(b.prototype=Object.create(s.prototype)).build=function(n){return this.clazz&&!n?this.clazz:this.clazz=function(t,n){for(var r=function(e){t.Builder.Service.call(this),this.rpcImpl=e||function(e,t,n){setTimeout(n.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),0)}},i=r.prototype=Object.create(t.Builder.Service.prototype),s=n.getChildren(t.Reflect.Service.RPCMethod),o=0;o<s.length;o++)!function(t){i[t.name]=function(r,i){try{try{r=t.resolvedRequestType.clazz.decode(e.wrap(r))}catch(e){if(!(e instanceof TypeError))throw e}if(null===r||"object"!=typeof r)throw Error("Illegal arguments");r instanceof t.resolvedRequestType.clazz||(r=new t.resolvedRequestType.clazz(r)),this.rpcImpl(t.fqn(),r,(function(e,r){if(e)i(e);else{null===r&&(r="");try{r=t.resolvedResponseType.clazz.decode(r)}catch(e){}r&&r instanceof t.resolvedResponseType.clazz?i(null,r):i(Error("Illegal response type received in service method "+n.name+"#"+t.name))}}))}catch(e){setTimeout(i.bind(this,e),0)}},r[t.name]=function(e,n,i){new r(e)[t.name](n,i)},Object.defineProperty&&(Object.defineProperty(r[t.name],"$options",{value:t.buildOpt()}),Object.defineProperty(i[t.name],"$options",{value:r[t.name].$options}))}(s[o]);return Object.defineProperty&&(Object.defineProperty(r,"$options",{value:n.buildOpt()}),Object.defineProperty(i,"$options",{value:r.$options}),Object.defineProperty(r,"$type",{value:n}),Object.defineProperty(i,"$type",{value:n})),r}(t,this)},n.Service=b;var w=function(e,t,n,i){r.call(this,e,t,n),this.className="Service.Method",this.options=i||{}};(w.prototype=Object.create(r.prototype)).buildOpt=o.buildOpt,n.Service.Method=w;var E=function(e,t,n,r,i,s,o,a){w.call(this,e,t,n,a),this.className="Service.RPCMethod",this.requestName=r,this.responseName=i,this.requestStream=s,this.responseStream=o,this.resolvedRequestType=null,this.resolvedResponseType=null};return E.prototype=Object.create(w.prototype),n.Service.RPCMethod=E,n}(i),i.Builder=function(e,t,n){var r=function(e){this.ns=new n.Namespace(this,null,""),this.ptr=this.ns,this.resolved=!1,this.result=null,this.files={},this.importRoot=null,this.options=e||{}},i=r.prototype;return r.isMessage=function(e){return"string"==typeof e.name&&(void 0===e.values&&void 0===e.rpc)},r.isMessageField=function(e){return"string"==typeof e.rule&&"string"==typeof e.name&&"string"==typeof e.type&&void 0!==e.id},r.isEnum=function(e){return"string"==typeof e.name&&!(void 0===e.values||!Array.isArray(e.values)||0===e.values.length)},r.isService=function(e){return!("string"!=typeof e.name||"object"!=typeof e.rpc||!e.rpc)},r.isExtend=function(e){return"string"==typeof e.ref},i.reset=function(){return this.ptr=this.ns,this},i.define=function(e){if("string"!=typeof e||!t.TYPEREF.test(e))throw Error("illegal namespace: "+e);return e.split(".").forEach((function(e){var t=this.ptr.getChild(e);null===t&&this.ptr.addChild(t=new n.Namespace(this,this.ptr,e)),this.ptr=t}),this),this},i.create=function(t){if(!t)return this;if(Array.isArray(t)){if(0===t.length)return this;t=t.slice()}else t=[t];for(var i=[t];i.length>0;){if(t=i.pop(),!Array.isArray(t))throw Error("not a valid namespace: "+JSON.stringify(t));for(;t.length>0;){var s=t.shift();if(r.isMessage(s)){var o=new n.Message(this,this.ptr,s.name,s.options,s.isGroup,s.syntax),a={};s.oneofs&&Object.keys(s.oneofs).forEach((function(e){o.addChild(a[e]=new n.Message.OneOf(this,o,e))}),this),s.fields&&s.fields.forEach((function(e){if(null!==o.getChild(0|e.id))throw Error("duplicate or invalid field id in "+o.name+": "+e.id);if(e.options&&"object"!=typeof e.options)throw Error("illegal field options in "+o.name+"#"+e.name);var t=null;if("string"==typeof e.oneof&&!(t=a[e.oneof]))throw Error("illegal oneof in "+o.name+"#"+e.name+": "+e.oneof);e=new n.Message.Field(this,o,e.rule,e.keytype,e.type,e.name,e.id,e.options,t,s.syntax),t&&t.fields.push(e),o.addChild(e)}),this);var l=[];if(s.enums&&s.enums.forEach((function(e){l.push(e)})),s.messages&&s.messages.forEach((function(e){l.push(e)})),s.services&&s.services.forEach((function(e){l.push(e)})),s.extensions&&("number"==typeof s.extensions[0]?o.extensions=[s.extensions]:o.extensions=s.extensions),this.ptr.addChild(o),l.length>0){i.push(t),t=l,l=null,this.ptr=o,o=null;continue}l=null}else if(r.isEnum(s))o=new n.Enum(this,this.ptr,s.name,s.options,s.syntax),s.values.forEach((function(e){o.addChild(new n.Enum.Value(this,o,e.name,e.id))}),this),this.ptr.addChild(o);else if(r.isService(s))o=new n.Service(this,this.ptr,s.name,s.options),Object.keys(s.rpc).forEach((function(e){var t=s.rpc[e];o.addChild(new n.Service.RPCMethod(this,o,e,t.request,t.response,!!t.request_stream,!!t.response_stream,t.options))}),this),this.ptr.addChild(o);else{if(!r.isExtend(s))throw Error("not a valid definition: "+JSON.stringify(s));if(o=this.ptr.resolve(s.ref,!0))s.fields.forEach((function(t){if(null!==o.getChild(0|t.id))throw Error("duplicate extended field id in "+o.name+": "+t.id);if(o.extensions){var r=!1;if(o.extensions.forEach((function(e){t.id>=e[0]&&t.id<=e[1]&&(r=!0)})),!r)throw Error("illegal extended field id in "+o.name+": "+t.id+" (not within valid ranges)")}var i=t.name;this.options.convertFieldsToCamelCase&&(i=e.Util.toCamelCase(i));var s=new n.Message.ExtensionField(this,o,t.rule,t.type,this.ptr.fqn()+"."+i,t.id,t.options),a=new n.Extension(this,this.ptr,t.name,s);s.extension=a,this.ptr.addChild(a),o.addChild(s)}),this);else if(!/\.?google\.protobuf\./.test(s.ref))throw Error("extended message "+s.ref+" is not defined")}s=null,o=null}t=null,this.ptr=this.ptr.parent}return this.resolved=!1,this.result=null,this},i.import=function(t,n){var r="/";if("string"==typeof n){if(e.Util.IS_NODE&&(n=d.resolve(n)),!0===this.files[n])return this.reset();this.files[n]=!0}else if("object"==typeof n){var i,s=n.root;if(e.Util.IS_NODE&&(s=d.resolve(s)),(s.indexOf("\\")>=0||n.file.indexOf("\\")>=0)&&(r="\\"),i=e.Util.IS_NODE?d.join(s,n.file):s+r+n.file,!0===this.files[i])return this.reset();this.files[i]=!0}if(t.imports&&t.imports.length>0){var o,a=!1;"object"==typeof n?(this.importRoot=n.root,a=!0,o=this.importRoot,n=n.file,(o.indexOf("\\")>=0||n.indexOf("\\")>=0)&&(r="\\")):"string"==typeof n?this.importRoot?o=this.importRoot:n.indexOf("/")>=0?""===(o=n.replace(/\/[^\/]*$/,""))&&(o="/"):n.indexOf("\\")>=0?(o=n.replace(/\\[^\\]*$/,""),r="\\"):o=".":o=null;for(var l=0;l<t.imports.length;l++)if("string"==typeof t.imports[l]){if(!o)throw Error("cannot determine import root");var u=t.imports[l];if("google/protobuf/descriptor.proto"===u)continue;if(u=e.Util.IS_NODE?d.join(o,u):o+r+u,!0===this.files[u])continue;/\.proto$/i.test(u)&&!e.DotProto&&(u=u.replace(/\.proto$/,".json"));var c=e.Util.fetch(u);if(null===c)throw Error("failed to import '"+u+"' in '"+n+"': file not found");/\.json$/i.test(u)?this.import(JSON.parse(c+""),u):this.import(e.DotProto.Parser.parse(c),u)}else n?/\.(\w+)$/.test(n)?this.import(t.imports[l],n.replace(/^(.+)\.(\w+)$/,(function(e,t,n){return t+"_import"+l+"."+n}))):this.import(t.imports[l],n+"_import"+l):this.import(t.imports[l]);a&&(this.importRoot=null)}t.package&&this.define(t.package),t.syntax&&function e(t){t.messages&&t.messages.forEach((function(n){n.syntax=t.syntax,e(n)})),t.enums&&t.enums.forEach((function(e){e.syntax=t.syntax}))}(t);var f=this.ptr;return t.options&&Object.keys(t.options).forEach((function(e){f.options[e]=t.options[e]})),t.messages&&(this.create(t.messages),this.ptr=f),t.enums&&(this.create(t.enums),this.ptr=f),t.services&&(this.create(t.services),this.ptr=f),t.extends&&this.create(t.extends),this.reset()},i.resolveAll=function(){var r;if(null==this.ptr||"object"==typeof this.ptr.type)return this;if(this.ptr instanceof n.Namespace)this.ptr.children.forEach((function(e){this.ptr=e,this.resolveAll()}),this);else if(this.ptr instanceof n.Message.Field){if(t.TYPE.test(this.ptr.type))this.ptr.type=e.TYPES[this.ptr.type];else{if(!t.TYPEREF.test(this.ptr.type))throw Error("illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);if(!(r=(this.ptr instanceof n.Message.ExtensionField?this.ptr.extension.parent:this.ptr.parent).resolve(this.ptr.type,!0)))throw Error("unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);if(this.ptr.resolvedType=r,r instanceof n.Enum){if(this.ptr.type=e.TYPES.enum,"proto3"===this.ptr.syntax&&"proto3"!==r.syntax)throw Error("proto3 message cannot reference proto2 enum")}else{if(!(r instanceof n.Message))throw Error("illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.type=r.isGroup?e.TYPES.group:e.TYPES.message}}if(this.ptr.map){if(!t.TYPE.test(this.ptr.keyType))throw Error("illegal key type for map field in "+this.ptr.toString(!0)+": "+this.ptr.keyType);this.ptr.keyType=e.TYPES[this.ptr.keyType]}"proto3"===this.ptr.syntax&&this.ptr.repeated&&void 0===this.ptr.options.packed&&-1!==e.PACKABLE_WIRE_TYPES.indexOf(this.ptr.type.wireType)&&(this.ptr.options.packed=!0)}else if(this.ptr instanceof e.Reflect.Service.Method){if(!(this.ptr instanceof e.Reflect.Service.RPCMethod))throw Error("illegal service type in "+this.ptr.toString(!0));if(!((r=this.ptr.parent.resolve(this.ptr.requestName,!0))&&r instanceof e.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.requestName);if(this.ptr.resolvedRequestType=r,!((r=this.ptr.parent.resolve(this.ptr.responseName,!0))&&r instanceof e.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.responseName);this.ptr.resolvedResponseType=r}else if(!(this.ptr instanceof e.Reflect.Message.OneOf||this.ptr instanceof e.Reflect.Extension||this.ptr instanceof e.Reflect.Enum.Value))throw Error("illegal object in namespace: "+typeof this.ptr+": "+this.ptr);return this.reset()},i.build=function(e){if(this.reset(),this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null),null===this.result&&(this.result=this.ns.build()),!e)return this.result;for(var t="string"==typeof e?e.split("."):e,n=this.result,r=0;r<t.length;r++){if(!n[t[r]]){n=null;break}n=n[t[r]]}return n},i.lookup=function(e,t){return e?this.ns.resolve(e,t):this.ns},i.toString=function(){return"Builder"},r.Message=function(){},r.Enum=function(){},r.Service=function(){},r}(i,i.Lang,i.Reflect),i.Map=function(e,t){var n=function(e,n){if(!e.map)throw Error("field is not a map");if(this.field=e,this.keyElem=new t.Element(e.keyType,null,!0,e.syntax),this.valueElem=new t.Element(e.type,e.resolvedType,!1,e.syntax),this.map={},Object.defineProperty(this,"size",{get:function(){return Object.keys(this.map).length}}),n)for(var r=Object.keys(n),i=0;i<r.length;i++){var s=this.keyElem.valueFromString(r[i]),o=this.valueElem.verifyValue(n[r[i]]);this.map[this.keyElem.valueToString(s)]={key:s,value:o}}},r=n.prototype;function i(e){var t=0;return{next:function(){return t<e.length?{done:!1,value:e[t++]}:{done:!0}}}}return r.clear=function(){this.map={}},r.delete=function(e){var t=this.keyElem.valueToString(this.keyElem.verifyValue(e)),n=t in this.map;return delete this.map[t],n},r.entries=function(){for(var e,t=[],n=Object.keys(this.map),r=0;r<n.length;r++)t.push([(e=this.map[n[r]]).key,e.value]);return i(t)},r.keys=function(){for(var e=[],t=Object.keys(this.map),n=0;n<t.length;n++)e.push(this.map[t[n]].key);return i(e)},r.values=function(){for(var e=[],t=Object.keys(this.map),n=0;n<t.length;n++)e.push(this.map[t[n]].value);return i(e)},r.forEach=function(e,t){for(var n,r=Object.keys(this.map),i=0;i<r.length;i++)e.call(t,(n=this.map[r[i]]).value,n.key,this)},r.set=function(e,t){var n=this.keyElem.verifyValue(e),r=this.valueElem.verifyValue(t);return this.map[this.keyElem.valueToString(n)]={key:n,value:r},this},r.get=function(e){var t=this.keyElem.valueToString(this.keyElem.verifyValue(e));if(t in this.map)return this.map[t].value},r.has=function(e){return this.keyElem.valueToString(this.keyElem.verifyValue(e))in this.map},n}(0,i.Reflect),i.newBuilder=function(e){return void 0===(e=e||{}).convertFieldsToCamelCase&&(e.convertFieldsToCamelCase=i.convertFieldsToCamelCase),void 0===e.populateAccessors&&(e.populateAccessors=i.populateAccessors),new i.Builder(e)},i.loadJson=function(e,t,n){return("string"==typeof t||t&&"string"==typeof t.file&&"string"==typeof t.root)&&(n=t,t=null),t&&"object"==typeof t||(t=i.newBuilder()),"string"==typeof e&&(e=JSON.parse(e)),t.import(e,n),t.resolveAll(),t},i.loadJsonFile=function(e,t,n){if(t&&"object"==typeof t?(n=t,t=null):t&&"function"==typeof t||(t=null),t)return i.Util.fetch("string"==typeof e?e:e.root+"/"+e.file,(function(r){if(null!==r)try{t(null,i.loadJson(JSON.parse(r),n,e))}catch(e){t(e)}else t(Error("Failed to fetch file"))}));var r=i.Util.fetch("object"==typeof e?e.root+"/"+e.file:e);return null===r?null:i.loadJson(JSON.parse(r),n,e)},i}))})).newBuilder({}).import({package:"push_server.messages2",syntax:"proto2",options:{objc_class_prefix:"AVIM"},messages:[{name:"JsonObjectMessage",syntax:"proto2",fields:[{rule:"required",type:"string",name:"data",id:1}]},{name:"UnreadTuple",syntax:"proto2",fields:[{rule:"required",type:"string",name:"cid",id:1},{rule:"required",type:"int32",name:"unread",id:2},{rule:"optional",type:"string",name:"mid",id:3},{rule:"optional",type:"int64",name:"timestamp",id:4},{rule:"optional",type:"string",name:"from",id:5},{rule:"optional",type:"string",name:"data",id:6},{rule:"optional",type:"int64",name:"patchTimestamp",id:7},{rule:"optional",type:"bool",name:"mentioned",id:8},{rule:"optional",type:"bytes",name:"binaryMsg",id:9},{rule:"optional",type:"int32",name:"convType",id:10}]},{name:"LogItem",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"from",id:1},{rule:"optional",type:"string",name:"data",id:2},{rule:"optional",type:"int64",name:"timestamp",id:3},{rule:"optional",type:"string",name:"msgId",id:4},{rule:"optional",type:"int64",name:"ackAt",id:5},{rule:"optional",type:"int64",name:"readAt",id:6},{rule:"optional",type:"int64",name:"patchTimestamp",id:7},{rule:"optional",type:"bool",name:"mentionAll",id:8},{rule:"repeated",type:"string",name:"mentionPids",id:9},{rule:"optional",type:"bool",name:"bin",id:10},{rule:"optional",type:"int32",name:"convType",id:11}]},{name:"ConvMemberInfo",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"pid",id:1},{rule:"optional",type:"string",name:"role",id:2},{rule:"optional",type:"string",name:"infoId",id:3}]},{name:"DataCommand",syntax:"proto2",fields:[{rule:"repeated",type:"string",name:"ids",id:1},{rule:"repeated",type:"JsonObjectMessage",name:"msg",id:2},{rule:"optional",type:"bool",name:"offline",id:3}]},{name:"SessionCommand",syntax:"proto2",fields:[{rule:"optional",type:"int64",name:"t",id:1},{rule:"optional",type:"string",name:"n",id:2},{rule:"optional",type:"string",name:"s",id:3},{rule:"optional",type:"string",name:"ua",id:4},{rule:"optional",type:"bool",name:"r",id:5},{rule:"optional",type:"string",name:"tag",id:6},{rule:"optional",type:"string",name:"deviceId",id:7},{rule:"repeated",type:"string",name:"sessionPeerIds",id:8},{rule:"repeated",type:"string",name:"onlineSessionPeerIds",id:9},{rule:"optional",type:"string",name:"st",id:10},{rule:"optional",type:"int32",name:"stTtl",id:11},{rule:"optional",type:"int32",name:"code",id:12},{rule:"optional",type:"string",name:"reason",id:13},{rule:"optional",type:"string",name:"deviceToken",id:14},{rule:"optional",type:"bool",name:"sp",id:15},{rule:"optional",type:"string",name:"detail",id:16},{rule:"optional",type:"int64",name:"lastUnreadNotifTime",id:17},{rule:"optional",type:"int64",name:"lastPatchTime",id:18},{rule:"optional",type:"int64",name:"configBitmap",id:19}]},{name:"ErrorCommand",syntax:"proto2",fields:[{rule:"required",type:"int32",name:"code",id:1},{rule:"required",type:"string",name:"reason",id:2},{rule:"optional",type:"int32",name:"appCode",id:3},{rule:"optional",type:"string",name:"detail",id:4},{rule:"repeated",type:"string",name:"pids",id:5},{rule:"optional",type:"string",name:"appMsg",id:6}]},{name:"DirectCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"msg",id:1},{rule:"optional",type:"string",name:"uid",id:2},{rule:"optional",type:"string",name:"fromPeerId",id:3},{rule:"optional",type:"int64",name:"timestamp",id:4},{rule:"optional",type:"bool",name:"offline",id:5},{rule:"optional",type:"bool",name:"hasMore",id:6},{rule:"repeated",type:"string",name:"toPeerIds",id:7},{rule:"optional",type:"bool",name:"r",id:10},{rule:"optional",type:"string",name:"cid",id:11},{rule:"optional",type:"string",name:"id",id:12},{rule:"optional",type:"bool",name:"transient",id:13},{rule:"optional",type:"string",name:"dt",id:14},{rule:"optional",type:"string",name:"roomId",id:15},{rule:"optional",type:"string",name:"pushData",id:16},{rule:"optional",type:"bool",name:"will",id:17},{rule:"optional",type:"int64",name:"patchTimestamp",id:18},{rule:"optional",type:"bytes",name:"binaryMsg",id:19},{rule:"repeated",type:"string",name:"mentionPids",id:20},{rule:"optional",type:"bool",name:"mentionAll",id:21},{rule:"optional",type:"int32",name:"convType",id:22}]},{name:"AckCommand",syntax:"proto2",fields:[{rule:"optional",type:"int32",name:"code",id:1},{rule:"optional",type:"string",name:"reason",id:2},{rule:"optional",type:"string",name:"mid",id:3},{rule:"optional",type:"string",name:"cid",id:4},{rule:"optional",type:"int64",name:"t",id:5},{rule:"optional",type:"string",name:"uid",id:6},{rule:"optional",type:"int64",name:"fromts",id:7},{rule:"optional",type:"int64",name:"tots",id:8},{rule:"optional",type:"string",name:"type",id:9},{rule:"repeated",type:"string",name:"ids",id:10},{rule:"optional",type:"int32",name:"appCode",id:11},{rule:"optional",type:"string",name:"appMsg",id:12}]},{name:"UnreadCommand",syntax:"proto2",fields:[{rule:"repeated",type:"UnreadTuple",name:"convs",id:1},{rule:"optional",type:"int64",name:"notifTime",id:2}]},{name:"ConvCommand",syntax:"proto2",fields:[{rule:"repeated",type:"string",name:"m",id:1},{rule:"optional",type:"bool",name:"transient",id:2},{rule:"optional",type:"bool",name:"unique",id:3},{rule:"optional",type:"string",name:"cid",id:4},{rule:"optional",type:"string",name:"cdate",id:5},{rule:"optional",type:"string",name:"initBy",id:6},{rule:"optional",type:"string",name:"sort",id:7},{rule:"optional",type:"int32",name:"limit",id:8},{rule:"optional",type:"int32",name:"skip",id:9},{rule:"optional",type:"int32",name:"flag",id:10},{rule:"optional",type:"int32",name:"count",id:11},{rule:"optional",type:"string",name:"udate",id:12},{rule:"optional",type:"int64",name:"t",id:13},{rule:"optional",type:"string",name:"n",id:14},{rule:"optional",type:"string",name:"s",id:15},{rule:"optional",type:"bool",name:"statusSub",id:16},{rule:"optional",type:"bool",name:"statusPub",id:17},{rule:"optional",type:"int32",name:"statusTTL",id:18},{rule:"optional",type:"string",name:"uniqueId",id:19},{rule:"optional",type:"string",name:"targetClientId",id:20},{rule:"optional",type:"int64",name:"maxReadTimestamp",id:21},{rule:"optional",type:"int64",name:"maxAckTimestamp",id:22},{rule:"optional",type:"bool",name:"queryAllMembers",id:23},{rule:"repeated",type:"MaxReadTuple",name:"maxReadTuples",id:24},{rule:"repeated",type:"string",name:"cids",id:25},{rule:"optional",type:"ConvMemberInfo",name:"info",id:26},{rule:"optional",type:"bool",name:"tempConv",id:27},{rule:"optional",type:"int32",name:"tempConvTTL",id:28},{rule:"repeated",type:"string",name:"tempConvIds",id:29},{rule:"repeated",type:"string",name:"allowedPids",id:30},{rule:"repeated",type:"ErrorCommand",name:"failedPids",id:31},{rule:"optional",type:"string",name:"next",id:40},{rule:"optional",type:"JsonObjectMessage",name:"results",id:100},{rule:"optional",type:"JsonObjectMessage",name:"where",id:101},{rule:"optional",type:"JsonObjectMessage",name:"attr",id:103},{rule:"optional",type:"JsonObjectMessage",name:"attrModified",id:104}]},{name:"RoomCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"roomId",id:1},{rule:"optional",type:"string",name:"s",id:2},{rule:"optional",type:"int64",name:"t",id:3},{rule:"optional",type:"string",name:"n",id:4},{rule:"optional",type:"bool",name:"transient",id:5},{rule:"repeated",type:"string",name:"roomPeerIds",id:6},{rule:"optional",type:"string",name:"byPeerId",id:7}]},{name:"LogsCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"cid",id:1},{rule:"optional",type:"int32",name:"l",id:2},{rule:"optional",type:"int32",name:"limit",id:3},{rule:"optional",type:"int64",name:"t",id:4},{rule:"optional",type:"int64",name:"tt",id:5},{rule:"optional",type:"string",name:"tmid",id:6},{rule:"optional",type:"string",name:"mid",id:7},{rule:"optional",type:"string",name:"checksum",id:8},{rule:"optional",type:"bool",name:"stored",id:9},{rule:"optional",type:"QueryDirection",name:"direction",id:10,options:{default:"OLD"}},{rule:"optional",type:"bool",name:"tIncluded",id:11},{rule:"optional",type:"bool",name:"ttIncluded",id:12},{rule:"optional",type:"int32",name:"lctype",id:13},{rule:"repeated",type:"LogItem",name:"logs",id:105}],enums:[{name:"QueryDirection",syntax:"proto2",values:[{name:"OLD",id:1},{name:"NEW",id:2}]}]},{name:"RcpCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"id",id:1},{rule:"optional",type:"string",name:"cid",id:2},{rule:"optional",type:"int64",name:"t",id:3},{rule:"optional",type:"bool",name:"read",id:4},{rule:"optional",type:"string",name:"from",id:5}]},{name:"ReadTuple",syntax:"proto2",fields:[{rule:"required",type:"string",name:"cid",id:1},{rule:"optional",type:"int64",name:"timestamp",id:2},{rule:"optional",type:"string",name:"mid",id:3}]},{name:"MaxReadTuple",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"pid",id:1},{rule:"optional",type:"int64",name:"maxAckTimestamp",id:2},{rule:"optional",type:"int64",name:"maxReadTimestamp",id:3}]},{name:"ReadCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"cid",id:1},{rule:"repeated",type:"string",name:"cids",id:2},{rule:"repeated",type:"ReadTuple",name:"convs",id:3}]},{name:"PresenceCommand",syntax:"proto2",fields:[{rule:"optional",type:"StatusType",name:"status",id:1},{rule:"repeated",type:"string",name:"sessionPeerIds",id:2},{rule:"optional",type:"string",name:"cid",id:3}]},{name:"ReportCommand",syntax:"proto2",fields:[{rule:"optional",type:"bool",name:"initiative",id:1},{rule:"optional",type:"string",name:"type",id:2},{rule:"optional",type:"string",name:"data",id:3}]},{name:"PatchItem",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"cid",id:1},{rule:"optional",type:"string",name:"mid",id:2},{rule:"optional",type:"int64",name:"timestamp",id:3},{rule:"optional",type:"bool",name:"recall",id:4},{rule:"optional",type:"string",name:"data",id:5},{rule:"optional",type:"int64",name:"patchTimestamp",id:6},{rule:"optional",type:"string",name:"from",id:7},{rule:"optional",type:"bytes",name:"binaryMsg",id:8},{rule:"optional",type:"bool",name:"mentionAll",id:9},{rule:"repeated",type:"string",name:"mentionPids",id:10},{rule:"optional",type:"int64",name:"patchCode",id:11},{rule:"optional",type:"string",name:"patchReason",id:12}]},{name:"PatchCommand",syntax:"proto2",fields:[{rule:"repeated",type:"PatchItem",name:"patches",id:1},{rule:"optional",type:"int64",name:"lastPatchTime",id:2}]},{name:"PubsubCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"cid",id:1},{rule:"repeated",type:"string",name:"cids",id:2},{rule:"optional",type:"string",name:"topic",id:3},{rule:"optional",type:"string",name:"subtopic",id:4},{rule:"repeated",type:"string",name:"topics",id:5},{rule:"repeated",type:"string",name:"subtopics",id:6},{rule:"optional",type:"JsonObjectMessage",name:"results",id:7}]},{name:"BlacklistCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"srcCid",id:1},{rule:"repeated",type:"string",name:"toPids",id:2},{rule:"optional",type:"string",name:"srcPid",id:3},{rule:"repeated",type:"string",name:"toCids",id:4},{rule:"optional",type:"int32",name:"limit",id:5},{rule:"optional",type:"string",name:"next",id:6},{rule:"repeated",type:"string",name:"blockedPids",id:8},{rule:"repeated",type:"string",name:"blockedCids",id:9},{rule:"repeated",type:"string",name:"allowedPids",id:10},{rule:"repeated",type:"ErrorCommand",name:"failedPids",id:11},{rule:"optional",type:"int64",name:"t",id:12},{rule:"optional",type:"string",name:"n",id:13},{rule:"optional",type:"string",name:"s",id:14}]},{name:"GenericCommand",syntax:"proto2",fields:[{rule:"optional",type:"CommandType",name:"cmd",id:1},{rule:"optional",type:"OpType",name:"op",id:2},{rule:"optional",type:"string",name:"appId",id:3},{rule:"optional",type:"string",name:"peerId",id:4},{rule:"optional",type:"int32",name:"i",id:5},{rule:"optional",type:"string",name:"installationId",id:6},{rule:"optional",type:"int32",name:"priority",id:7},{rule:"optional",type:"int32",name:"service",id:8},{rule:"optional",type:"int64",name:"serverTs",id:9},{rule:"optional",type:"int64",name:"clientTs",id:10},{rule:"optional",type:"int32",name:"notificationType",id:11},{rule:"optional",type:"DataCommand",name:"dataMessage",id:101},{rule:"optional",type:"SessionCommand",name:"sessionMessage",id:102},{rule:"optional",type:"ErrorCommand",name:"errorMessage",id:103},{rule:"optional",type:"DirectCommand",name:"directMessage",id:104},{rule:"optional",type:"AckCommand",name:"ackMessage",id:105},{rule:"optional",type:"UnreadCommand",name:"unreadMessage",id:106},{rule:"optional",type:"ReadCommand",name:"readMessage",id:107},{rule:"optional",type:"RcpCommand",name:"rcpMessage",id:108},{rule:"optional",type:"LogsCommand",name:"logsMessage",id:109},{rule:"optional",type:"ConvCommand",name:"convMessage",id:110},{rule:"optional",type:"RoomCommand",name:"roomMessage",id:111},{rule:"optional",type:"PresenceCommand",name:"presenceMessage",id:112},{rule:"optional",type:"ReportCommand",name:"reportMessage",id:113},{rule:"optional",type:"PatchCommand",name:"patchMessage",id:114},{rule:"optional",type:"PubsubCommand",name:"pubsubMessage",id:115},{rule:"optional",type:"BlacklistCommand",name:"blacklistMessage",id:116}]}],enums:[{name:"CommandType",syntax:"proto2",values:[{name:"session",id:0},{name:"conv",id:1},{name:"direct",id:2},{name:"ack",id:3},{name:"rcp",id:4},{name:"unread",id:5},{name:"logs",id:6},{name:"error",id:7},{name:"login",id:8},{name:"data",id:9},{name:"room",id:10},{name:"read",id:11},{name:"presence",id:12},{name:"report",id:13},{name:"echo",id:14},{name:"loggedin",id:15},{name:"logout",id:16},{name:"loggedout",id:17},{name:"patch",id:18},{name:"pubsub",id:19},{name:"blacklist",id:20},{name:"goaway",id:21}]},{name:"OpType",syntax:"proto2",values:[{name:"open",id:1},{name:"add",id:2},{name:"remove",id:3},{name:"close",id:4},{name:"opened",id:5},{name:"closed",id:6},{name:"query",id:7},{name:"query_result",id:8},{name:"conflict",id:9},{name:"added",id:10},{name:"removed",id:11},{name:"refresh",id:12},{name:"refreshed",id:13},{name:"start",id:30},{name:"started",id:31},{name:"joined",id:32},{name:"members_joined",id:33},{name:"left",id:39},{name:"members_left",id:40},{name:"results",id:42},{name:"count",id:43},{name:"result",id:44},{name:"update",id:45},{name:"updated",id:46},{name:"mute",id:47},{name:"unmute",id:48},{name:"status",id:49},{name:"members",id:50},{name:"max_read",id:51},{name:"is_member",id:52},{name:"member_info_update",id:53},{name:"member_info_updated",id:54},{name:"member_info_changed",id:55},{name:"join",id:80},{name:"invite",id:81},{name:"leave",id:82},{name:"kick",id:83},{name:"reject",id:84},{name:"invited",id:85},{name:"kicked",id:86},{name:"upload",id:100},{name:"uploaded",id:101},{name:"subscribe",id:120},{name:"subscribed",id:121},{name:"unsubscribe",id:122},{name:"unsubscribed",id:123},{name:"is_subscribed",id:124},{name:"modify",id:150},{name:"modified",id:151},{name:"block",id:170},{name:"unblock",id:171},{name:"blocked",id:172},{name:"unblocked",id:173},{name:"members_blocked",id:174},{name:"members_unblocked",id:175},{name:"check_block",id:176},{name:"check_result",id:177},{name:"add_shutup",id:180},{name:"remove_shutup",id:181},{name:"query_shutup",id:182},{name:"shutup_added",id:183},{name:"shutup_removed",id:184},{name:"shutup_result",id:185},{name:"shutuped",id:186},{name:"unshutuped",id:187},{name:"members_shutuped",id:188},{name:"members_unshutuped",id:189},{name:"check_shutup",id:190}]},{name:"StatusType",syntax:"proto2",values:[{name:"on",id:1},{name:"off",id:2}]}],isNamespace:!0}).build();const{JsonObjectMessage:m,UnreadTuple:g,LogItem:y,DataCommand:v,SessionCommand:b,ErrorCommand:w,DirectCommand:E,AckCommand:_,UnreadCommand:T,ConvCommand:S,RoomCommand:I,LogsCommand:A,RcpCommand:C,ReadTuple:O,MaxReadTuple:M,ReadCommand:P,PresenceCommand:R,ReportCommand:N,GenericCommand:L,BlacklistCommand:x,PatchCommand:j,PatchItem:k,ConvMemberInfo:D,CommandType:U,OpType:B,StatusType:F}=p.push_server.messages2;var V=Object.freeze({__proto__:null,JsonObjectMessage:m,UnreadTuple:g,LogItem:y,DataCommand:v,SessionCommand:b,ErrorCommand:w,DirectCommand:E,AckCommand:_,UnreadCommand:T,ConvCommand:S,RoomCommand:I,LogsCommand:A,RcpCommand:C,ReadTuple:O,MaxReadTuple:M,ReadCommand:P,PresenceCommand:R,ReportCommand:N,GenericCommand:L,BlacklistCommand:x,PatchCommand:j,PatchItem:k,ConvMemberInfo:D,CommandType:U,OpType:B,StatusType:F}),Y=i((function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function i(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,r,s,o){if("function"!=typeof r)throw new TypeError("The listener must be a function");var a=new i(r,s||e,o),l=n?n+t:t;return e._events[l]?e._events[l].fn?e._events[l]=[e._events[l],a]:e._events[l].push(a):(e._events[l]=a,e._eventsCount++),e}function o(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function a(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,r,i=[];if(0===this._eventsCount)return i;for(r in e=this._events)t.call(e,r)&&i.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},a.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var i=0,s=r.length,o=new Array(s);i<s;i++)o[i]=r[i].fn;return o},a.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},a.prototype.emit=function(e,t,r,i,s,o){var a=n?n+e:e;if(!this._events[a])return!1;var l,u,c=this._events[a],f=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,r),!0;case 4:return c.fn.call(c.context,t,r,i),!0;case 5:return c.fn.call(c.context,t,r,i,s),!0;case 6:return c.fn.call(c.context,t,r,i,s,o),!0}for(u=1,l=new Array(f-1);u<f;u++)l[u-1]=arguments[u];c.fn.apply(c.context,l)}else{var h,d=c.length;for(u=0;u<d;u++)switch(c[u].once&&this.removeListener(e,c[u].fn,void 0,!0),f){case 1:c[u].fn.call(c[u].context);break;case 2:c[u].fn.call(c[u].context,t);break;case 3:c[u].fn.call(c[u].context,t,r);break;case 4:c[u].fn.call(c[u].context,t,r,i);break;default:if(!l)for(h=1,l=new Array(f-1);h<f;h++)l[h-1]=arguments[h];c[u].fn.apply(c[u].context,l)}}return!0},a.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,r,i){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return o(this,s),this;var a=this._events[s];if(a.fn)a.fn!==t||i&&!a.once||r&&a.context!==r||o(this,s);else{for(var l=0,u=[],c=a.length;l<c;l++)(a[l].fn!==t||i&&!a[l].once||r&&a[l].context!==r)&&u.push(a[l]);u.length?this._events[s]=1===u.length?u[0]:u:o(this,s)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&o(this,t)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a})),$=1e3,q=6e4,z=60*q,W=24*z,G=function(e,t){t=t||{};var n=typeof e;if("string"===n&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return;var n=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*n;case"weeks":case"week":case"w":return 6048e5*n;case"days":case"day":case"d":return n*W;case"hours":case"hour":case"hrs":case"hr":case"h":return n*z;case"minutes":case"minute":case"mins":case"min":case"m":return n*q;case"seconds":case"second":case"secs":case"sec":case"s":return n*$;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(e);if("number"===n&&!1===isNaN(e))return t.long?function(e){var t=Math.abs(e);if(t>=W)return J(e,t,W,"day");if(t>=z)return J(e,t,z,"hour");if(t>=q)return J(e,t,q,"minute");if(t>=$)return J(e,t,$,"second");return e+" ms"}(e):function(e){var t=Math.abs(e);if(t>=W)return Math.round(e/W)+"d";if(t>=z)return Math.round(e/z)+"h";if(t>=q)return Math.round(e/q)+"m";if(t>=$)return Math.round(e/$)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function J(e,t,n,r){var i=t>=1.5*n;return Math.round(e/n)+" "+r+(i?"s":"")}var Z=function(e){function t(e){for(var t=0,r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t|=0;return n.colors[Math.abs(t)%n.colors.length]}function n(e){var s;function o(){if(o.enabled){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var i=o,a=Number(new Date),l=a-(s||a);i.diff=l,i.prev=s,i.curr=a,s=a,t[0]=n.coerce(t[0]),"string"!=typeof t[0]&&t.unshift("%O");var u=0;t[0]=t[0].replace(/%([a-zA-Z%])/g,(function(e,r){if("%%"===e)return e;u++;var s=n.formatters[r];if("function"==typeof s){var o=t[u];e=s.call(i,o),t.splice(u,1),u--}return e})),n.formatArgs.call(i,t);var c=i.log||n.log;c.apply(i,t)}}return o.namespace=e,o.enabled=n.enabled(e),o.useColors=n.useColors(),o.color=t(e),o.destroy=r,o.extend=i,"function"==typeof n.init&&n.init(o),n.instances.push(o),o}function r(){var e=n.instances.indexOf(this);return-1!==e&&(n.instances.splice(e,1),!0)}function i(e,t){return n(this.namespace+(void 0===t?":":t)+e)}return n.debug=n,n.default=n,n.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},n.disable=function(){n.enable("")},n.enable=function(e){var t;n.save(e),n.names=[],n.skips=[];var r=("string"==typeof e?e:"").split(/[\s,]+/),i=r.length;for(t=0;t<i;t++)r[t]&&("-"===(e=r[t].replace(/\*/g,".*?"))[0]?n.skips.push(new RegExp("^"+e.substr(1)+"$")):n.names.push(new RegExp("^"+e+"$")));for(t=0;t<n.instances.length;t++){var s=n.instances[t];s.enabled=n.enabled(s.namespace)}},n.enabled=function(e){if("*"===e[e.length-1])return!0;var t,r;for(t=0,r=n.skips.length;t<r;t++)if(n.skips[t].test(e))return!1;for(t=0,r=n.names.length;t<r;t++)if(n.names[t].test(e))return!0;return!1},n.humanize=G,Object.keys(e).forEach((function(t){n[t]=e[t]})),n.instances=[],n.names=[],n.skips=[],n.formatters={},n.selectColor=t,n.enable(n.load()),n},K=i((function(e,n){function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}n.log=function(){var e;return"object"===("undefined"==typeof console?"undefined":r(console))&&console.log&&(e=console).log.apply(e,arguments)},n.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;var n="color: "+this.color;t.splice(1,0,n,"color: inherit");var r=0,i=0;t[0].replace(/%[a-zA-Z%]/g,(function(e){"%%"!==e&&(r++,"%c"===e&&(i=r))})),t.splice(i,0,n)},n.save=function(e){try{e?n.storage.setItem("debug",e):n.storage.removeItem("debug")}catch(e){}},n.load=function(){var e;try{e=n.storage.getItem("debug")}catch(e){}!e&&void 0!==t&&"env"in t&&(e=t.env.DEBUG);return e},n.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},n.storage=function(){try{return localStorage}catch(e){}}(),n.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.exports=Z(n),e.exports.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}));K.log,K.formatArgs,K.save,K.load,K.useColors,K.storage,K.colors;var X=function(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t},Q=Math.floor,H=Math.random;var ee=function(e,t){return e+Q(H()*(t-e+1))};var te=function(e,t){var n=-1,r=e.length,i=r-1;for(t=void 0===t?r:t;++n<t;){var s=ee(n,i),o=e[s];e[s]=e[n],e[n]=o}return e.length=t,e};var ne=function(e){return te(X(e))};var re=function(e,t){for(var n=-1,r=null==e?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i};var ie=function(e,t){return re(t,(function(t){return e[t]}))};var se=function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r},oe="object"==typeof r&&r&&r.Object===Object&&r,ae="object"==typeof self&&self&&self.Object===Object&&self,le=oe||ae||{},ue=le.Symbol,ce=Object.prototype,fe=ce.hasOwnProperty,he=ce.toString,de=ue?ue.toStringTag:void 0;var pe=function(e){var t=fe.call(e,de),n=e[de];try{e[de]=void 0;var r=!0}catch(e){}var i=he.call(e);return r&&(t?e[de]=n:delete e[de]),i},me=Object.prototype.toString;var ge=function(e){return me.call(e)},ye=ue?ue.toStringTag:void 0;var ve=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":ye&&ye in Object(e)?pe(e):ge(e)};var be=function(e){return null!=e&&"object"==typeof e};var we=function(e){return be(e)&&"[object Arguments]"==ve(e)},Ee=Object.prototype,_e=Ee.hasOwnProperty,Te=Ee.propertyIsEnumerable,Se=we(function(){return arguments}())?we:function(e){return be(e)&&_e.call(e,"callee")&&!Te.call(e,"callee")},Ie=Array.isArray;var Ae=function(){return!1},Ce=i((function(e,t){var n=t&&!t.nodeType&&t,r=n&&e&&!e.nodeType&&e,i=r&&r.exports===n?le.Buffer:void 0,s=(i?i.isBuffer:void 0)||Ae;e.exports=s})),Oe=/^(?:0|[1-9]\d*)$/;var Me=function(e,t){var n=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==n||"symbol"!=n&&Oe.test(e))&&e>-1&&e%1==0&&e<t};var Pe=function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991},Re={};Re["[object Float32Array]"]=Re["[object Float64Array]"]=Re["[object Int8Array]"]=Re["[object Int16Array]"]=Re["[object Int32Array]"]=Re["[object Uint8Array]"]=Re["[object Uint8ClampedArray]"]=Re["[object Uint16Array]"]=Re["[object Uint32Array]"]=!0,Re["[object Arguments]"]=Re["[object Array]"]=Re["[object ArrayBuffer]"]=Re["[object Boolean]"]=Re["[object DataView]"]=Re["[object Date]"]=Re["[object Error]"]=Re["[object Function]"]=Re["[object Map]"]=Re["[object Number]"]=Re["[object Object]"]=Re["[object RegExp]"]=Re["[object Set]"]=Re["[object String]"]=Re["[object WeakMap]"]=!1;var Ne=function(e){return be(e)&&Pe(e.length)&&!!Re[ve(e)]};var Le=function(e){return function(t){return e(t)}},xe=i((function(e,t){var n=t&&!t.nodeType&&t,r=n&&e&&!e.nodeType&&e,i=r&&r.exports===n&&oe.process,s=function(){try{var e=r&&r.require&&r.require("util").types;return e||i&&i.binding&&i.binding("util")}catch(e){}}();e.exports=s})),je=xe&&xe.isTypedArray,ke=je?Le(je):Ne,De=Object.prototype.hasOwnProperty;var Ue=function(e,t){var n=Ie(e),r=!n&&Se(e),i=!n&&!r&&Ce(e),s=!n&&!r&&!i&&ke(e),o=n||r||i||s,a=o?se(e.length,String):[],l=a.length;for(var u in e)!t&&!De.call(e,u)||o&&("length"==u||i&&("offset"==u||"parent"==u)||s&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||Me(u,l))||a.push(u);return a},Be=Object.prototype;var Fe=function(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||Be)};var Ve=function(e,t){return function(n){return e(t(n))}},Ye=Ve(Object.keys,Object),$e=Object.prototype.hasOwnProperty;var qe=function(e){if(!Fe(e))return Ye(e);var t=[];for(var n in Object(e))$e.call(e,n)&&"constructor"!=n&&t.push(n);return t};var ze=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)};var We=function(e){if(!ze(e))return!1;var t=ve(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t};var Ge=function(e){return null!=e&&Pe(e.length)&&!We(e)};var Je=function(e){return Ge(e)?Ue(e):qe(e)};var Ze=function(e){return null==e?[]:ie(e,Je(e))};var Ke=function(e){return te(Ze(e))};var Xe=function(e){return(Ie(e)?ne:Ke)(e)};function Qe(e,t,n,r,i){var s={};return Object.keys(r).forEach((function(e){s[e]=r[e]})),s.enumerable=!!s.enumerable,s.configurable=!!s.configurable,("value"in s||s.initializer)&&(s.writable=!0),s=n.slice().reverse().reduce((function(n,r){return r(e,t,n)||n}),s),i&&void 0!==s.initializer&&(s.value=s.initializer?s.initializer.call(i):void 0,s.initializer=void 0),void 0===s.initializer&&(Object.defineProperty(e,t,s),s=null),s}var He=i((function(e,t){var n;n={VERSION:"2.4.0",Result:{SUCCEEDED:1,NOTRANSITION:2,CANCELLED:3,PENDING:4},Error:{INVALID_TRANSITION:100,PENDING_TRANSITION:200,INVALID_CALLBACK:300},WILDCARD:"*",ASYNC:"async",create:function(e,t){var r="string"==typeof e.initial?{state:e.initial}:e.initial,i=e.terminal||e.final,s=t||e.target||{},o=e.events||[],a=e.callbacks||{},l={},u={},c=function(e){var t=Array.isArray(e.from)?e.from:e.from?[e.from]:[n.WILDCARD];l[e.name]=l[e.name]||{};for(var r=0;r<t.length;r++)u[t[r]]=u[t[r]]||[],u[t[r]].push(e.name),l[e.name][t[r]]=e.to||t[r];e.to&&(u[e.to]=u[e.to]||[])};r&&(r.event=r.event||"startup",c({name:r.event,from:"none",to:r.state}));for(var f=0;f<o.length;f++)c(o[f]);for(var h in l)l.hasOwnProperty(h)&&(s[h]=n.buildEvent(h,l[h]));for(var h in a)a.hasOwnProperty(h)&&(s[h]=a[h]);return s.current="none",s.is=function(e){return Array.isArray(e)?e.indexOf(this.current)>=0:this.current===e},s.can=function(e){return!this.transition&&void 0!==l[e]&&(l[e].hasOwnProperty(this.current)||l[e].hasOwnProperty(n.WILDCARD))},s.cannot=function(e){return!this.can(e)},s.transitions=function(){return(u[this.current]||[]).concat(u[n.WILDCARD]||[])},s.isFinished=function(){return this.is(i)},s.error=e.error||function(e,t,n,r,i,s,o){throw o||s},s.states=function(){return Object.keys(u).sort()},r&&!r.defer&&s[r.event](),s},doCallback:function(e,t,r,i,s,o){if(t)try{return t.apply(e,[r,i,s].concat(o))}catch(t){return e.error(r,i,s,o,n.Error.INVALID_CALLBACK,"an exception occurred in a caller-provided callback function",t)}},beforeAnyEvent:function(e,t,r,i,s){return n.doCallback(e,e.onbeforeevent,t,r,i,s)},afterAnyEvent:function(e,t,r,i,s){return n.doCallback(e,e.onafterevent||e.onevent,t,r,i,s)},leaveAnyState:function(e,t,r,i,s){return n.doCallback(e,e.onleavestate,t,r,i,s)},enterAnyState:function(e,t,r,i,s){return n.doCallback(e,e.onenterstate||e.onstate,t,r,i,s)},changeState:function(e,t,r,i,s){return n.doCallback(e,e.onchangestate,t,r,i,s)},beforeThisEvent:function(e,t,r,i,s){return n.doCallback(e,e["onbefore"+t],t,r,i,s)},afterThisEvent:function(e,t,r,i,s){return n.doCallback(e,e["onafter"+t]||e["on"+t],t,r,i,s)},leaveThisState:function(e,t,r,i,s){return n.doCallback(e,e["onleave"+r],t,r,i,s)},enterThisState:function(e,t,r,i,s){return n.doCallback(e,e["onenter"+i]||e["on"+i],t,r,i,s)},beforeEvent:function(e,t,r,i,s){if(!1===n.beforeThisEvent(e,t,r,i,s)||!1===n.beforeAnyEvent(e,t,r,i,s))return!1},afterEvent:function(e,t,r,i,s){n.afterThisEvent(e,t,r,i,s),n.afterAnyEvent(e,t,r,i,s)},leaveState:function(e,t,r,i,s){var o=n.leaveThisState(e,t,r,i,s),a=n.leaveAnyState(e,t,r,i,s);return!1!==o&&!1!==a&&(n.ASYNC===o||n.ASYNC===a?n.ASYNC:void 0)},enterState:function(e,t,r,i,s){n.enterThisState(e,t,r,i,s),n.enterAnyState(e,t,r,i,s)},buildEvent:function(e,t){return function(){var r=this.current,i=t[r]||(t[n.WILDCARD]!=n.WILDCARD?t[n.WILDCARD]:r)||r,s=Array.prototype.slice.call(arguments);if(this.transition)return this.error(e,r,i,s,n.Error.PENDING_TRANSITION,"event "+e+" inappropriate because previous transition did not complete");if(this.cannot(e))return this.error(e,r,i,s,n.Error.INVALID_TRANSITION,"event "+e+" inappropriate in current state "+this.current);if(!1===n.beforeEvent(this,e,r,i,s))return n.Result.CANCELLED;if(r===i)return n.afterEvent(this,e,r,i,s),n.Result.NOTRANSITION;var o=this;this.transition=function(){return o.transition=null,o.current=i,n.enterState(o,e,r,i,s),n.changeState(o,e,r,i,s),n.afterEvent(o,e,r,i,s),n.Result.SUCCEEDED},this.transition.cancel=function(){o.transition=null,n.afterEvent(o,e,r,i,s)};var a=n.leaveState(this,e,r,i,s);return!1===a?(this.transition=null,n.Result.CANCELLED):n.ASYNC===a?n.Result.PENDING:this.transition?this.transition():void 0}}},e.exports&&(t=e.exports=n),t.StateMachine=n}));He.StateMachine;const et={},tt=e=>{const t=et[e];if(void 0===t)throw new Error(`${e} adapter is not configured`);return t},nt=e=>{Object.assign(et,e)};var rt=Ve(Object.getPrototypeOf,Object),it=n.prototype,st=Object.prototype,ot=it.toString,at=st.hasOwnProperty,lt=ot.call(Object);var ut=function(e){if(!be(e)||"[object Object]"!=ve(e))return!1;var t=rt(e);if(null===t)return!0;var n=at.call(t,"constructor")&&t.constructor;return"function"==typeof n&&n instanceof n&&ot.call(n)==lt},ct="undefined"!=typeof global?global:"undefined"!=typeof window?window:{};const ft=Symbol("expired"),ht=K("LC:Expirable");class dt{constructor(e,t){this.originalValue=e,"number"==typeof t&&(this.expiredAt=Date.now()+t)}get value(){const e=this.expiredAt&&this.expiredAt<=Date.now();return e&&ht(`expired: ${this.originalValue}`),e?ft:this.originalValue}}dt.EXPIRED=ft;const pt=K("LC:Cache");class mt{constructor(e="anonymous"){this.name=e,this._map={}}get(e){const t=this._map[e];if(t){const{value:n}=t;if(n!==dt.EXPIRED)return pt("[%s] hit: %s",this.name,e),n;delete this._map[e]}return pt(`[${this.name}] missed: ${e}`),null}set(e,t,n){pt("[%s] set: %s %d",this.name,e,n),this._map[e]=new dt(t,n)}}const gt={enable:(e="LC*")=>K.enable(e),disable:K.disable},yt=e=>{const t=new Promise(e[0]);return 1===e.length?t:t.catch(()=>yt(e.slice(1)))},vt=e=>t=>(e(t),t),bt=e=>e?"string"==typeof e||"number"==typeof e?new Date(e):"Date"===e.__type&&e.iso?new Date(e.iso):"function"==typeof e.toNumber?new Date(e.toNumber()):e:e,wt=e=>e&&e.getTime?e.getTime():void 0,Et=e=>e?"Date"===e.__type&&e.iso?new Date(e.iso):Array.isArray(e)?e.map(Et):ut(e)?Object.keys(e).reduce((t,n)=>({...t,[n]:Et(e[n])}),{}):e:e,_t=e=>e instanceof Date?{__type:"Date",iso:e.toJSON()}:Array.isArray(e)?e.map(_t):ut(e)?Object.keys(e).reduce((t,n)=>({...t,[n]:_t(e[n])}),{}):e,Tt=(e,t)=>Object.keys(t).reduce((n,r)=>{const i=e[r]||r;return Object.assign(n,{[i]:t[r]})},{}),St=ct.navigator&&ct.navigator.userAgent&&-1!==ct.navigator.userAgent.indexOf("MSIE 10."),It=(e,t)=>e[t]||(e.__proto__?It(e.__proto__,t):void 0),At=(e,t)=>Array.from(new Set([...e,...t])),Ct=(e,t)=>{return Array.from((n=new Set(t),new Set(e.filter(e=>!n.has(e)))));var n},Ot=new WeakMap,Mt=e=>(Ot.has(e)||Ot.set(e,{}),Ot.get(e)),Pt=(e,t)=>{if(!ut(e))return e;const n={...e};return Object.keys(n).forEach(e=>{const r=n[e];r===t?delete n[e]:n[e]=Pt(r,t)}),n},Rt=e=>{return t=JSON.parse(JSON.stringify(e)),Pt(t,null);var t},Nt=e=>Array.isArray(e)?e:null==e?[]:[e],Lt=(e,t,n)=>{const r=t.split("."),i=r.pop();let s=e;return r.forEach(e=>{void 0===s[e]&&(s[e]={}),s=s[e]}),s[i]=n,e},xt="object"==typeof wx&&"function"==typeof wx.connectSocket,jt=e=>(t,n,r)=>{const i=r.value;if(i.length)throw new Error("throttled function should not accept any arguments");return{...r,value(){let{throttleMeta:t}=Mt(this);t||(t={},Mt(this).throttleMeta=t);let{[n]:r}=t;r||(r={},t[n]=r);const{previouseTimestamp:s=0,timeout:o}=r,a=Date.now(),l=e-(a-s);l<=0?(t[n].previouseTimestamp=a,i.apply(this)):o||(r.timeout=setTimeout(()=>{r.previouseTimestamp=Date.now(),delete r.timeout,i.apply(this)},l))}}};var kt;const Dt=K("LC:WebSocketPlus"),Ut="disconnect",Bt="reconnect",Ft="retry",Vt="schedule",Yt="offline",$t="online",qt=e=>Math.min(1e3*2**e,3e5),zt=(e,t,n)=>({...n,value:function(...e){return this.checkConnectionAvailability(t),n.value.call(this,...e)}});let Wt=(Qe((kt=class extends Y{get urls(){return this._urls}set urls(e){this._urls=Nt(e)}constructor(e,t){super(),this.init(),this._protocol=t,Promise.resolve("function"==typeof e?e():e).then(Nt).then(e=>(this._urls=e,this._open())).then(()=>{this.__postponeTimeoutTimer=this._postponeTimeoutTimer.bind(this),ct.addEventListener&&(this.__pause=()=>{this.can("pause")&&this.pause()},this.__resume=()=>{this.can("resume")&&this.resume()},ct.addEventListener("offline",this.__pause),ct.addEventListener("online",this.__resume)),this.open()}).catch(this.throw.bind(this))}_open(){return this._createWs(this._urls,this._protocol).then(e=>{const[t,...n]=this._urls;return this._urls=[...n,t],e})}_createWs(e,t){return yt(e.map(e=>(n,r)=>{Dt(`connect [${e}] ${t}`);const i=tt("WebSocket"),s=t?new i(e,t):new i(e);s.binaryType=this.binaryType||"arraybuffer",s.onopen=()=>n(s),s.onclose=t=>t instanceof Error?r(t):r(new Error(`Failed to connect [${e}]`)),s.onerror=s.onclose})).then(e=>(this._ws=e,this._ws.onclose=this._handleClose.bind(this),this._ws.onmessage=this._handleMessage.bind(this),e))}_destroyWs(){const e=this._ws;e&&(e.onopen=null,e.onclose=null,e.onerror=null,e.onmessage=null,this._ws=null,e.close())}onbeforeevent(e,t,n,...r){Dt(`${e}: ${t} -> ${n} %o`,r)}onopen(){this.emit("open")}onconnected(){this._startConnectionKeeper()}onleaveconnected(e,t,n){this._stopConnectionKeeper(),this._destroyWs(),"offline"!==n&&"disconnected"!==n||this.emit(Ut)}onpause(){this.emit(Yt)}onbeforeresume(){this.emit($t)}onreconnect(){this.emit(Bt)}ondisconnected(e,t,n,r=0){const i=t===Yt?0:qt.call(null,r);Dt(`schedule attempt=${r} delay=${i}`),this.emit(Vt,r,i),this.__scheduledRetry&&clearTimeout(this.__scheduledRetry),this.__scheduledRetry=setTimeout(()=>{this.is("disconnected")&&this.retry(r)},i)}onretry(e,t,n,r=0){this.emit(Ft,r),this._open().then(()=>this.can("reconnect")&&this.reconnect(),()=>this.can("fail")&&this.fail(r+1))}onerror(e,t,n,r){this.emit("error",r)}onclose(){ct.removeEventListener&&(this.__pause&&ct.removeEventListener("offline",this.__pause),this.__resume&&ct.removeEventListener("online",this.__resume))}checkConnectionAvailability(e="API"){if(!this.is("connected")){const t=this.current;throw console.warn(`${e} should not be called when the connection is ${t}`),(this.is("disconnected")||this.is("reconnecting"))&&console.warn("disconnect and reconnect event should be handled to avoid such calls."),new Error("Connection unavailable")}}_ping(){Dt("ping");try{this.ping()}catch(e){console.warn(`websocket ping error: ${e.message}`)}}ping(){this._ws.ping?this._ws.ping():console.warn("The WebSocket implement does not support sending ping frame.\n Override ping method to use application defined ping/pong mechanism.")}_postponeTimeoutTimer(){Dt("_postponeTimeoutTimer"),this._clearTimeoutTimers(),this._timeoutTimer=setTimeout(()=>{Dt("timeout"),this.disconnect()},38e4)}_clearTimeoutTimers(){this._timeoutTimer&&clearTimeout(this._timeoutTimer)}_startConnectionKeeper(){Dt("start connection keeper"),this._heartbeatTimer=setInterval(this._ping.bind(this),18e4);const e=this._ws.addListener||this._ws.addEventListener;e?(e.call(this._ws,"message",this.__postponeTimeoutTimer),e.call(this._ws,"pong",this.__postponeTimeoutTimer),this._postponeTimeoutTimer()):Dt("connection keeper disabled due to the lack of #addEventListener.")}_stopConnectionKeeper(){Dt("stop connection keeper");const e=this._ws.removeListener||this._ws.removeEventListener;e&&(e.call(this._ws,"message",this.__postponeTimeoutTimer),e.call(this._ws,"pong",this.__postponeTimeoutTimer),this._clearTimeoutTimers()),this._heartbeatTimer&&clearInterval(this._heartbeatTimer)}_handleClose(e){Dt(`ws closed [${e.code}] ${e.reason}`),this.isFinished()||this.handleClose(e)}handleClose(){this.disconnect()}send(e){Dt("send",e),this._ws.send(e)}_handleMessage(e){Dt("message",e.data),this.handleMessage(e.data)}handleMessage(e){this.emit("message",e)}}).prototype,"_ping",[zt],Object.getOwnPropertyDescriptor(kt.prototype,"_ping"),kt.prototype),Qe(kt.prototype,"send",[zt],Object.getOwnPropertyDescriptor(kt.prototype,"send"),kt.prototype),kt);He.create({target:Wt.prototype,initial:{state:"initialized",event:"init",defer:!0},terminal:"closed",events:[{name:"open",from:"initialized",to:"connected"},{name:"disconnect",from:"connected",to:"disconnected"},{name:"retry",from:"disconnected",to:"reconnecting"},{name:"fail",from:"reconnecting",to:"disconnected"},{name:"reconnect",from:"reconnecting",to:"connected"},{name:"pause",from:["connected","disconnected","reconnecting"],to:"offline"},{},{name:"resume",from:"offline",to:"disconnected"},{name:"close",from:["connected","disconnected","reconnecting","offline"],to:"closed"},{name:"throw",from:"*",to:"error"}]});const Gt=Object.freeze({1e3:{name:"CLOSE_NORMAL"},1006:{name:"CLOSE_ABNORMAL"},4100:{name:"APP_NOT_AVAILABLE",message:"App not exists or realtime message service is disabled."},4102:{name:"SIGNATURE_FAILED",message:"Login signature mismatch."},4103:{name:"INVALID_LOGIN",message:"Malformed clientId."},4105:{name:"SESSION_REQUIRED",message:"Message sent before session opened."},4107:{name:"READ_TIMEOUT"},4108:{name:"LOGIN_TIMEOUT"},4109:{name:"FRAME_TOO_LONG"},4110:{name:"INVALID_ORIGIN",message:"Access denied by domain whitelist."},4111:{name:"SESSION_CONFLICT"},4112:{name:"SESSION_TOKEN_EXPIRED"},4113:{name:"APP_QUOTA_EXCEEDED",message:"The daily active users limit exceeded."},4116:{name:"MESSAGE_SENT_QUOTA_EXCEEDED",message:"Command sent too fast."},4200:{name:"INTERNAL_ERROR",message:"Internal error, please contact LeanCloud for support."},4301:{name:"CONVERSATION_API_FAILED",message:"Upstream Conversatoin API failed, see error.detail for details."},4302:{name:"CONVERSATION_SIGNATURE_FAILED",message:"Conversation action signature mismatch."},4303:{name:"CONVERSATION_NOT_FOUND"},4304:{name:"CONVERSATION_FULL"},4305:{name:"CONVERSATION_REJECTED_BY_APP",message:"Conversation action rejected by hook."},4306:{name:"CONVERSATION_UPDATE_FAILED"},4307:{name:"CONVERSATION_READ_ONLY"},4308:{name:"CONVERSATION_NOT_ALLOWED"},4309:{name:"CONVERSATION_UPDATE_REJECTED",message:"Conversation update rejected because the client is not a member."},4310:{name:"CONVERSATION_QUERY_FAILED",message:"Conversation query failed because it is too expansive."},4311:{name:"CONVERSATION_LOG_FAILED"},4312:{name:"CONVERSATION_LOG_REJECTED",message:"Message query rejected because the client is not a member of the conversation."},4313:{name:"SYSTEM_CONVERSATION_REQUIRED"},4314:{name:"NORMAL_CONVERSATION_REQUIRED"},4315:{name:"CONVERSATION_BLACKLISTED",message:"Blacklisted in the conversation."},4316:{name:"TRANSIENT_CONVERSATION_REQUIRED"},4317:{name:"CONVERSATION_MEMBERSHIP_REQUIRED"},4318:{name:"CONVERSATION_API_QUOTA_EXCEEDED",message:"LeanCloud API quota exceeded. You may upgrade your plan."},4323:{name:"TEMPORARY_CONVERSATION_EXPIRED",message:"Temporary conversation expired or does not exist."},4401:{name:"INVALID_MESSAGING_TARGET",message:"Conversation does not exist or client is not a member."},4402:{name:"MESSAGE_REJECTED_BY_APP",message:"Message rejected by hook."},4403:{name:"MESSAGE_OWNERSHIP_REQUIRED"},4404:{name:"MESSAGE_NOT_FOUND"},4405:{name:"MESSAGE_UPDATE_REJECTED_BY_APP",message:"Message update rejected by hook."},4406:{name:"MESSAGE_EDIT_DISABLED"},4407:{name:"MESSAGE_RECALL_DISABLED"},5130:{name:"OWNER_PROMOTION_NOT_ALLOWED",message:"Updating a member's role to owner is not allowed."}}),Jt=Object.freeze(Object.keys(Gt).reduce((e,t)=>Object.assign(e,{[Gt[t].name]:Number(t)}),{})),Zt=({code:e,reason:t,appCode:n,detail:r,error:i})=>{let s=t||r||i,o=t;!s&&Gt[e]&&(({name:o}=Gt[e]),s=Gt[e].message||o),s||(s=`Unknow Error: ${e}`);const a=new Error(s);return Object.assign(a,{code:e,appCode:n,detail:r,name:o})},Kt=K("LC:Connection"),Xt=Symbol("expire");class Qt extends Wt{constructor(e,{format:t,version:n}){Kt("initializing Connection"),super(e,`lc.${t}.${n}`),this._protocolFormat=t,this._commands={},this._serialId=0}async send(e,t=!0){let n,r,i;if(t){if((e=>!(e.cmd===U.direct||e.cmd===U.session&&e.op===B.open||e.cmd===U.conv&&(e.op===B.start||e.op===B.update||e.op===B.members)))(e)){n=e.toArrayBuffer();const t=Ze(this._commands).find(({buffer:t,command:r})=>r.cmd===e.cmd&&r.op===e.op&&((e,t)=>{if(!e||!t)return!1;if(e.byteLength!==t.byteLength)return!1;const n=new Uint8Array(e),r=new Uint8Array(t);return!n.some((e,t)=>e!==r[t])})(t,n));if(t)return console.warn(`Duplicated command [cmd:${e.cmd} op:${e.op}] is throttled.`),t.promise}this._serialId+=1,r=this._serialId,e.i=r}if(Kt.enabled&&Kt("↑ %O sent",Rt(e)),"proto2base64"===this._protocolFormat?i=e.toBase64():e.toArrayBuffer&&(i=e.toArrayBuffer()),!i)throw new TypeError(`${e} is not a GenericCommand`);if(super.send(i),!t)return;const s=new Promise((t,i)=>{this._commands[r]={command:e,buffer:n,resolve:t,reject:i,timeout:setTimeout(()=>{this._commands[r]&&(Kt.enabled&&Kt("✗ %O timeout",Rt(e)),i(Zt({error:`Command Timeout [cmd:${e.cmd} op:${e.op}]`,name:"COMMAND_TIMEOUT"})),delete this._commands[r])},2e4)}});return this._commands[r].promise=s,s}handleMessage(e){let t;try{t=L.decode(e),Kt.enabled&&Kt("↓ %O received",Rt(t))}catch(t){return void console.warn("Decode message failed:",t.message,e)}const n=t.i;if(n)this._commands[n]?(clearTimeout(this._commands[n].timeout),t.cmd===U.error?this._commands[n].reject(Zt(t.errorMessage)):this._commands[n].resolve(t),delete this._commands[n]):console.warn(`Unexpected command received with serialId [${n}],\n which have timed out or never been requested.`);else switch(t.cmd){case U.error:return void this.emit("error",Zt(t.errorMessage));case U.goaway:return void this.emit(Xt);default:this.emit("message",t)}}ping(){return this.send(new L({cmd:U.echo})).catch(e=>Kt("ping failed:",e))}}var Ht=i((function(e){var t;e.exports.timeout=function(e,n){var r,i=new t;return Promise.race([e,new Promise((function(e,t){r=setTimeout((function(){t(i)}),n)}))]).then((function(e){return clearTimeout(r),e}),(function(e){throw clearTimeout(r),e}))};(t=e.exports.TimeoutError=function(){Error.call(this),this.stack=Error().stack,this.message="Timeout"}).prototype=Object.create(Error.prototype),t.prototype.name="TimeoutError"})),en=Ht.timeout;Ht.TimeoutError;const tn=K("LC:request");var nn=({method:e="GET",url:t,query:n,headers:r,data:i,timeout:s})=>{let o=t;if(n){const e=Object.keys(n).map(e=>{const t=n[e];if(void 0===t)return;const r=ut(t)?JSON.stringify(t):t;return`${encodeURIComponent(e)}=${encodeURIComponent(r)}`}).filter(e=>e).join("&");o=`${o}?${e}`}tn("Req: %O %O %O",e,o,{headers:r,data:i});const a=tt("request")(o,{method:e,headers:r,data:i}).then(e=>{if(!1===e.ok){const t=Zt(e.data);throw t.response=e,t}return tn("Res: %O %O %O",o,e.status,e.data),e.data}).catch(e=>{throw e.response&&tn("Error: %O %O %O",o,e.response.status,e.response.data),e});return s?en(a,s):a};const rn=(e,t)=>{e&&e.forEach(e=>{try{e(t)}catch(t){throw e._pluginName&&(t.message+=`[${e._pluginName}]`),t}})},sn=e=>t=>Nt(e).reduce((e,t)=>e.then((e=>t=>{const{constructor:n}=t;return Promise.resolve(t).then(e).then(vt(r=>null==r?console.warn(`Middleware[${e._pluginName||"anonymous plugin"}:${e.name||"anonymous middleware"}] param/return types not match. It returns ${r} while a ${t.constructor.name} expected.`):r instanceof n?0:console.warn(`Middleware[${e._pluginName||"anonymous plugin"}:${e.name||"anonymous middleware"}] param/return types not match. It returns a ${r.constructor.name} while a ${t.constructor.name} expected.`)))})(t)).catch(e=>{throw t._pluginName&&(e.message+=`[${t._pluginName}]`),e}),Promise.resolve(t)),on=(e,t)=>Nt(e).reduce((e,n)=>e.then(e=>!1!==e&&n(...t)).catch(e=>{throw n._pluginName&&(e.message+=`[${n._pluginName}]`),e}),Promise.resolve(!0));const an=K("LC:Realtime"),ln=new mt("push-router"),un={};class cn extends Y{constructor({plugins:e,...n}){an("initializing Realtime %s %O","5.0.0-rc.7",n),super();const{appId:r}=n;if("string"!=typeof r)throw new TypeError(`appId [${r}] is not a string`);if(un[r])throw new Error(`App [${r}] is already initialized.`);if(un[r]=!0,"string"!=typeof n.appKey)throw new TypeError(`appKey [${n.appKey}] is not a string`);if((e=>"-MdYXbMMI"!==e.slice(-9))(r)&&!n.server)throw new TypeError("server option is required for apps from CN region");this._options={appId:void 0,appKey:void 0,noBinary:!1,ssl:!0,RTMServerName:void 0!==t?t.env.RTM_SERVER_NAME:void 0,...n},this._cache=new mt("endpoints");const i=Mt(this);i.clients=new Set,i.pendingClients=new Set;const s=[...Nt(cn.__preRegisteredPlugins),...Nt(e)];an("Using plugins %o",s.map(e=>e.name)),this._plugins=s.reduce((e,t)=>(Object.keys(t).forEach(n=>{({}).hasOwnProperty.call(t,n)&&"name"!==n&&(t.name&&Nt(t[n]).forEach(e=>{e._pluginName=t.name}),e[n]=Nt(e[n]).concat(t[n]))}),e),{}),rn(this._plugins.onRealtimeCreate,this)}async _request({method:e,url:t,version:n="1.1",path:r,query:i,headers:s,data:o}){let a=t;if(!a){const{appId:e,server:t}=this._options,{api:i}=await this.constructor._getServerUrls({appId:e,server:t});a=`${i}/${n}${r}`}return nn({url:a,method:e,query:i,headers:{"X-LC-Id":this._options.appId,"X-LC-Key":this._options.appKey,...s},data:o})}_open(){if(this._openPromise)return this._openPromise;let e="protobuf2";this._options.noBinary&&(e="proto2base64");const t={format:e,version:3};return this._openPromise=new Promise((e,n)=>{an("No connection established, create a new one.");const r=new Qt(()=>this._getRTMServers(this._options),t);r.on("open",()=>e(r)).on("error",e=>{delete this._openPromise,n(e)}).on(Xt,async()=>{an("Connection expired. Refresh endpoints."),this._cache.set("endpoints",null,0),r.urls=await this._getRTMServers(this._options),r.disconnect()}).on("message",this._dispatchCommand.bind(this)),[Ut,Bt,Ft,Vt,Yt,$t].forEach(e=>r.on(e,(...t)=>{an(`${e} event emitted. %o`,t),this.emit(e,...t),e!==Bt&&Mt(this).clients.forEach(n=>{n.emit(e,...t)})})),r.handleClose=function(e){[Jt.APP_NOT_AVAILABLE,Jt.INVALID_LOGIN,Jt.INVALID_ORIGIN].some(t=>t===e.code)?this.throw(Zt(e)):this.disconnect()},Mt(this).connection=r}),this._openPromise}async _getRTMServers(e){if(e.RTMServers)return Xe(Nt(e.RTMServers));let t;const n=this._cache.get("endpoints");if(n)t=n;else{t=await this.constructor._fetchRTMServers(e);const{server:n,secondary:r,ttl:i}=t;if("string"!=typeof n&&"string"!=typeof r&&"number"!=typeof i)throw new Error(`malformed RTM route response: ${JSON.stringify(t)}`);this._cache.set("endpoints",t,1e3*t.ttl)}return an("endpoint info: %O",t),[t.server,t.secondary]}static async _getServerUrls({appId:e,server:t}){if(an("fetch server urls"),t)return"string"!=typeof t?t:{RTMRouter:t,api:t};const n=ln.get(e);if(n)return n;return nn({url:"https://app-router.com/2/route",query:{appId:e},timeout:2e4}).then(vt(an)).then(({rtm_router_server:t,api_server:n,ttl:r=3600})=>{if(!t)throw new Error("rtm router not exists");const i={RTMRouter:`https://${t}`,api:`https://${n}`};return ln.set(e,i,1e3*r),i}).catch(()=>{const t=e.slice(0,8).toLowerCase();return{RTMRouter:`https://${t}.rtm.lncldglobal.com`,api:`https://${t}.api.lncldglobal.com`}})}static _fetchRTMServers({appId:e,ssl:t,server:n,RTMServerName:r}){return an("fetch endpoint info"),this._getServerUrls({appId:e,server:n}).then(vt(an)).then(({RTMRouter:n})=>nn({url:`${n}/v1/route`,query:{appId:e,secure:t,features:xt?"wechat":void 0,server:r,_t:Date.now()},timeout:2e4}).then(vt(an)))}_close(){this._openPromise&&this._openPromise.then(e=>e.close()),delete this._openPromise}retry(){const{connection:e}=Mt(this);if(!e)throw new Error("no connection established");if(e.cannot("retry"))throw new Error(`retrying not allowed when not disconnected. the connection is now ${e.current}`);return e.retry()}pause(){const{connection:e}=Mt(this);e&&e.can("pause")&&e.pause()}resume(){const{connection:e}=Mt(this);e&&e.can("resume")&&e.resume()}_registerPending(e){Mt(this).pendingClients.add(e)}_deregisterPending(e){Mt(this).pendingClients.delete(e)}_register(e){Mt(this).clients.add(e)}_deregister(e){const t=Mt(this);t.clients.delete(e),t.clients.size+t.pendingClients.size===0&&this._close()}_dispatchCommand(e){return on(this._plugins.beforeCommandDispatch,[e,this]).then(t=>!!t&&an("[WARN] Unexpected message received: %O",Rt(e)))}}const fn=Promise;for(var hn=i((function(e){var t="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(t){var n=new Uint8Array(16);e.exports=function(){return t(n),n}}else{var r=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),r[t]=e>>>((3&t)<<3)&255;return r}}})),dn=[],pn=0;pn<256;++pn)dn[pn]=(pn+256).toString(16).substr(1);var mn=function(e,t){var n=t||0,r=dn;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")};var gn=function(e,t,n){var r=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var i=(e=e||{}).random||(e.rng||hn)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(var s=0;s<16;++s)t[r+s]=i[s];return t||mn(i)},yn=i((function(e,t){!function(){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(256),r=0;r<e.length;r++)n[e.charCodeAt(r)]=r;t.encode=function(t){var n,r=new Uint8Array(t),i=r.length,s="";for(n=0;n<i;n+=3)s+=e[r[n]>>2],s+=e[(3&r[n])<<4|r[n+1]>>4],s+=e[(15&r[n+1])<<2|r[n+2]>>6],s+=e[63&r[n+2]];return i%3==2?s=s.substring(0,s.length-1)+"=":i%3==1&&(s=s.substring(0,s.length-2)+"=="),s},t.decode=function(e){var t,r,i,s,o,a=.75*e.length,l=e.length,u=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);var c=new ArrayBuffer(a),f=new Uint8Array(c);for(t=0;t<l;t+=4)r=n[e.charCodeAt(t)],i=n[e.charCodeAt(t+1)],s=n[e.charCodeAt(t+2)],o=n[e.charCodeAt(t+3)],f[u++]=r<<2|i>>4,f[u++]=(15&i)<<4|s>>2,f[u++]=(3&s)<<6|63&o;return c}}()})),vn=yn.encode,bn=yn.decode;var wn=function(){this.__data__=[],this.size=0};var En=function(e,t){return e===t||e!=e&&t!=t};var _n=function(e,t){for(var n=e.length;n--;)if(En(e[n][0],t))return n;return-1},Tn=Array.prototype.splice;var Sn=function(e){var t=this.__data__,n=_n(t,e);return!(n<0)&&(n==t.length-1?t.pop():Tn.call(t,n,1),--this.size,!0)};var In=function(e){var t=this.__data__,n=_n(t,e);return n<0?void 0:t[n][1]};var An=function(e){return _n(this.__data__,e)>-1};var Cn=function(e,t){var n=this.__data__,r=_n(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this};function On(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}On.prototype.clear=wn,On.prototype.delete=Sn,On.prototype.get=In,On.prototype.has=An,On.prototype.set=Cn;var Mn=On;var Pn=function(){this.__data__=new Mn,this.size=0};var Rn=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n};var Nn=function(e){return this.__data__.get(e)};var Ln,xn=function(e){return this.__data__.has(e)},jn=le["__core-js_shared__"],kn=(Ln=/[^.]+$/.exec(jn&&jn.keys&&jn.keys.IE_PROTO||""))?"Symbol(src)_1."+Ln:"";var Dn=function(e){return!!kn&&kn in e},Un=n.prototype.toString;var Bn=function(e){if(null!=e){try{return Un.call(e)}catch(e){}try{return e+""}catch(e){}}return""},Fn=/^\[object .+?Constructor\]$/,Vn=n.prototype,Yn=Object.prototype,$n=Vn.toString,qn=Yn.hasOwnProperty,zn=RegExp("^"+$n.call(qn).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var Wn=function(e){return!(!ze(e)||Dn(e))&&(We(e)?zn:Fn).test(Bn(e))};var Gn=function(e,t){return null==e?void 0:e[t]};var Jn=function(e,t){var n=Gn(e,t);return Wn(n)?n:void 0},Zn=Jn(le,"Map"),Kn=Jn(Object,"create");var Xn=function(){this.__data__=Kn?Kn(null):{},this.size=0};var Qn=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},Hn=Object.prototype.hasOwnProperty;var er=function(e){var t=this.__data__;if(Kn){var n=t[e];return"__lodash_hash_undefined__"===n?void 0:n}return Hn.call(t,e)?t[e]:void 0},tr=Object.prototype.hasOwnProperty;var nr=function(e){var t=this.__data__;return Kn?void 0!==t[e]:tr.call(t,e)};var rr=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Kn&&void 0===t?"__lodash_hash_undefined__":t,this};function ir(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}ir.prototype.clear=Xn,ir.prototype.delete=Qn,ir.prototype.get=er,ir.prototype.has=nr,ir.prototype.set=rr;var sr=ir;var or=function(){this.size=0,this.__data__={hash:new sr,map:new(Zn||Mn),string:new sr}};var ar=function(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e};var lr=function(e,t){var n=e.__data__;return ar(t)?n["string"==typeof t?"string":"hash"]:n.map};var ur=function(e){var t=lr(this,e).delete(e);return this.size-=t?1:0,t};var cr=function(e){return lr(this,e).get(e)};var fr=function(e){return lr(this,e).has(e)};var hr=function(e,t){var n=lr(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this};function dr(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}dr.prototype.clear=or,dr.prototype.delete=ur,dr.prototype.get=cr,dr.prototype.has=fr,dr.prototype.set=hr;var pr=dr;var mr=function(e,t){var n=this.__data__;if(n instanceof Mn){var r=n.__data__;if(!Zn||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new pr(r)}return n.set(e,t),this.size=n.size,this};function gr(e){var t=this.__data__=new Mn(e);this.size=t.size}gr.prototype.clear=Pn,gr.prototype.delete=Rn,gr.prototype.get=Nn,gr.prototype.has=xn,gr.prototype.set=mr;var yr=gr;var vr=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this};var br=function(e){return this.__data__.has(e)};function wr(e){var t=-1,n=null==e?0:e.length;for(this.__data__=new pr;++t<n;)this.add(e[t])}wr.prototype.add=wr.prototype.push=vr,wr.prototype.has=br;var Er=wr;var _r=function(e,t){for(var n=-1,r=null==e?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1};var Tr=function(e,t){return e.has(t)};var Sr=function(e,t,n,r,i,s){var o=1&n,a=e.length,l=t.length;if(a!=l&&!(o&&l>a))return!1;var u=s.get(e),c=s.get(t);if(u&&c)return u==t&&c==e;var f=-1,h=!0,d=2&n?new Er:void 0;for(s.set(e,t),s.set(t,e);++f<a;){var p=e[f],m=t[f];if(r)var g=o?r(m,p,f,t,e,s):r(p,m,f,e,t,s);if(void 0!==g){if(g)continue;h=!1;break}if(d){if(!_r(t,(function(e,t){if(!Tr(d,t)&&(p===e||i(p,e,n,r,s)))return d.push(t)}))){h=!1;break}}else if(p!==m&&!i(p,m,n,r,s)){h=!1;break}}return s.delete(e),s.delete(t),h},Ir=le.Uint8Array;var Ar=function(e){var t=-1,n=Array(e.size);return e.forEach((function(e,r){n[++t]=[r,e]})),n};var Cr=function(e){var t=-1,n=Array(e.size);return e.forEach((function(e){n[++t]=e})),n},Or=ue?ue.prototype:void 0,Mr=Or?Or.valueOf:void 0;var Pr=function(e,t,n,r,i,s,o){switch(n){case"[object DataView]":if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case"[object ArrayBuffer]":return!(e.byteLength!=t.byteLength||!s(new Ir(e),new Ir(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return En(+e,+t);case"[object Error]":return e.name==t.name&&e.message==t.message;case"[object RegExp]":case"[object String]":return e==t+"";case"[object Map]":var a=Ar;case"[object Set]":var l=1&r;if(a||(a=Cr),e.size!=t.size&&!l)return!1;var u=o.get(e);if(u)return u==t;r|=2,o.set(e,t);var c=Sr(a(e),a(t),r,i,s,o);return o.delete(e),c;case"[object Symbol]":if(Mr)return Mr.call(e)==Mr.call(t)}return!1};var Rr=function(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e};var Nr=function(e,t,n){var r=t(e);return Ie(e)?r:Rr(r,n(e))};var Lr=function(e,t){for(var n=-1,r=null==e?0:e.length,i=0,s=[];++n<r;){var o=e[n];t(o,n,e)&&(s[i++]=o)}return s};var xr=function(){return[]},jr=Object.prototype.propertyIsEnumerable,kr=Object.getOwnPropertySymbols,Dr=kr?function(e){return null==e?[]:(e=Object(e),Lr(kr(e),(function(t){return jr.call(e,t)})))}:xr;var Ur=function(e){return Nr(e,Je,Dr)},Br=Object.prototype.hasOwnProperty;var Fr=function(e,t,n,r,i,s){var o=1&n,a=Ur(e),l=a.length;if(l!=Ur(t).length&&!o)return!1;for(var u=l;u--;){var c=a[u];if(!(o?c in t:Br.call(t,c)))return!1}var f=s.get(e),h=s.get(t);if(f&&h)return f==t&&h==e;var d=!0;s.set(e,t),s.set(t,e);for(var p=o;++u<l;){var m=e[c=a[u]],g=t[c];if(r)var y=o?r(g,m,c,t,e,s):r(m,g,c,e,t,s);if(!(void 0===y?m===g||i(m,g,n,r,s):y)){d=!1;break}p||(p="constructor"==c)}if(d&&!p){var v=e.constructor,b=t.constructor;v==b||!("constructor"in e)||!("constructor"in t)||"function"==typeof v&&v instanceof v&&"function"==typeof b&&b instanceof b||(d=!1)}return s.delete(e),s.delete(t),d},Vr=Jn(le,"DataView"),Yr=Jn(le,"Promise"),$r=Jn(le,"Set"),qr=Jn(le,"WeakMap"),zr=Bn(Vr),Wr=Bn(Zn),Gr=Bn(Yr),Jr=Bn($r),Zr=Bn(qr),Kr=ve;(Vr&&"[object DataView]"!=Kr(new Vr(new ArrayBuffer(1)))||Zn&&"[object Map]"!=Kr(new Zn)||Yr&&"[object Promise]"!=Kr(Yr.resolve())||$r&&"[object Set]"!=Kr(new $r)||qr&&"[object WeakMap]"!=Kr(new qr))&&(Kr=function(e){var t=ve(e),n="[object Object]"==t?e.constructor:void 0,r=n?Bn(n):"";if(r)switch(r){case zr:return"[object DataView]";case Wr:return"[object Map]";case Gr:return"[object Promise]";case Jr:return"[object Set]";case Zr:return"[object WeakMap]"}return t});var Xr=Kr,Qr=Object.prototype.hasOwnProperty;var Hr=function(e,t,n,r,i,s){var o=Ie(e),a=Ie(t),l=o?"[object Array]":Xr(e),u=a?"[object Array]":Xr(t),c="[object Object]"==(l="[object Arguments]"==l?"[object Object]":l),f="[object Object]"==(u="[object Arguments]"==u?"[object Object]":u),h=l==u;if(h&&Ce(e)){if(!Ce(t))return!1;o=!0,c=!1}if(h&&!c)return s||(s=new yr),o||ke(e)?Sr(e,t,n,r,i,s):Pr(e,t,l,n,r,i,s);if(!(1&n)){var d=c&&Qr.call(e,"__wrapped__"),p=f&&Qr.call(t,"__wrapped__");if(d||p){var m=d?e.value():e,g=p?t.value():t;return s||(s=new yr),i(m,g,n,r,s)}}return!!h&&(s||(s=new yr),Fr(e,t,n,r,i,s))};var ei=function e(t,n,r,i,s){return t===n||(null==t||null==n||!be(t)&&!be(n)?t!=t&&n!=n:Hr(t,n,r,i,e,s))};var ti=function(e,t,n,r){var i=n.length,s=i,o=!r;if(null==e)return!s;for(e=Object(e);i--;){var a=n[i];if(o&&a[2]?a[1]!==e[a[0]]:!(a[0]in e))return!1}for(;++i<s;){var l=(a=n[i])[0],u=e[l],c=a[1];if(o&&a[2]){if(void 0===u&&!(l in e))return!1}else{var f=new yr;if(r)var h=r(u,c,l,e,t,f);if(!(void 0===h?ei(c,u,3,r,f):h))return!1}}return!0};var ni=function(e){return e==e&&!ze(e)};var ri=function(e){for(var t=Je(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,ni(i)]}return t};var ii=function(e,t){return function(n){return null!=n&&(n[e]===t&&(void 0!==t||e in Object(n)))}};var si=function(e){var t=ri(e);return 1==t.length&&t[0][2]?ii(t[0][0],t[0][1]):function(n){return n===e||ti(n,e,t)}};var oi=function(e){return"symbol"==typeof e||be(e)&&"[object Symbol]"==ve(e)},ai=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,li=/^\w*$/;var ui=function(e,t){if(Ie(e))return!1;var n=typeof e;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=e&&!oi(e))||(li.test(e)||!ai.test(e)||null!=t&&e in Object(t))};function ci(e,t){if("function"!=typeof e||null!=t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],s=n.cache;if(s.has(i))return s.get(i);var o=e.apply(this,r);return n.cache=s.set(i,o)||s,o};return n.cache=new(ci.Cache||pr),n}ci.Cache=pr;var fi=ci;var hi=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,di=/\\(\\)?/g,pi=function(e){var t=fi(e,(function(e){return 500===n.size&&n.clear(),e})),n=t.cache;return t}((function(e){var t=[];return 46===e.charCodeAt(0)&&t.push(""),e.replace(hi,(function(e,n,r,i){t.push(r?i.replace(di,"$1"):n||e)})),t})),mi=ue?ue.prototype:void 0,gi=mi?mi.toString:void 0;var yi=function e(t){if("string"==typeof t)return t;if(Ie(t))return re(t,e)+"";if(oi(t))return gi?gi.call(t):"";var n=t+"";return"0"==n&&1/t==-1/0?"-0":n};var vi=function(e){return null==e?"":yi(e)};var bi=function(e,t){return Ie(e)?e:ui(e,t)?[e]:pi(vi(e))};var wi=function(e){if("string"==typeof e||oi(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t};var Ei=function(e,t){for(var n=0,r=(t=bi(t,e)).length;null!=e&&n<r;)e=e[wi(t[n++])];return n&&n==r?e:void 0};var _i=function(e,t,n){var r=null==e?void 0:Ei(e,t);return void 0===r?n:r};var Ti=function(e,t){return null!=e&&t in Object(e)};var Si=function(e,t,n){for(var r=-1,i=(t=bi(t,e)).length,s=!1;++r<i;){var o=wi(t[r]);if(!(s=null!=e&&n(e,o)))break;e=e[o]}return s||++r!=i?s:!!(i=null==e?0:e.length)&&Pe(i)&&Me(o,i)&&(Ie(e)||Se(e))};var Ii=function(e,t){return null!=e&&Si(e,t,Ti)};var Ai=function(e,t){return ui(e)&&ni(t)?ii(wi(e),t):function(n){var r=_i(n,e);return void 0===r&&r===t?Ii(n,e):ei(t,r,3)}};var Ci=function(e){return e};var Oi=function(e){return function(t){return null==t?void 0:t[e]}};var Mi=function(e){return function(t){return Ei(t,e)}};var Pi=function(e){return ui(e)?Oi(wi(e)):Mi(e)};var Ri=function(e){return"function"==typeof e?e:null==e?Ci:"object"==typeof e?Ie(e)?Ai(e[0],e[1]):si(e):Pi(e)};var Ni=function(e){var t=null==e?0:e.length;return t?e[t-1]:void 0};var Li=function(e,t,n){var r=-1,i=e.length;t<0&&(t=-t>i?0:i+t),(n=n>i?i:n)<0&&(n+=i),i=t>n?0:n-t>>>0,t>>>=0;for(var s=Array(i);++r<i;)s[r]=e[r+t];return s};var xi=function(e,t){return t.length<2?e:Ei(e,Li(t,0,-1))};var ji=function(e,t){return t=bi(t,e),null==(e=xi(e,t))||delete e[wi(Ni(t))]},ki=Array.prototype.splice;var Di=function(e,t){for(var n=e?t.length:0,r=n-1;n--;){var i=t[n];if(n==r||i!==s){var s=i;Me(i)?ki.call(e,i,1):ji(e,i)}}return e};var Ui=function(e,t){var n=[];if(!e||!e.length)return n;var r=-1,i=[],s=e.length;for(t=Ri(t);++r<s;){var o=e[r];t(o,r,e)&&(n.push(o),i.push(r))}return Di(e,i),n},Bi=Object.prototype.hasOwnProperty;var Fi=function(e){if(null==e)return!0;if(Ge(e)&&(Ie(e)||"string"==typeof e||"function"==typeof e.splice||Ce(e)||ke(e)||Se(e)))return!e.length;var t=Xr(e);if("[object Map]"==t||"[object Set]"==t)return!e.size;if(Fe(e))return!qe(e).length;for(var n in e)if(Bi.call(e,n))return!1;return!0};var Vi=function(e,t){for(var n=-1,r=null==e?0:e.length;++n<r&&!1!==t(e[n],n,e););return e},Yi=function(){try{var e=Jn(Object,"defineProperty");return e({},"",{}),e}catch(e){}}();var $i=function(e,t,n){"__proto__"==t&&Yi?Yi(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n},qi=Object.prototype.hasOwnProperty;var zi=function(e,t,n){var r=e[t];qi.call(e,t)&&En(r,n)&&(void 0!==n||t in e)||$i(e,t,n)};var Wi=function(e,t,n,r){var i=!n;n||(n={});for(var s=-1,o=t.length;++s<o;){var a=t[s],l=r?r(n[a],e[a],a,n,e):void 0;void 0===l&&(l=e[a]),i?$i(n,a,l):zi(n,a,l)}return n};var Gi=function(e,t){return e&&Wi(t,Je(t),e)};var Ji=function(e){var t=[];if(null!=e)for(var n in Object(e))t.push(n);return t},Zi=Object.prototype.hasOwnProperty;var Ki=function(e){if(!ze(e))return Ji(e);var t=Fe(e),n=[];for(var r in e)("constructor"!=r||!t&&Zi.call(e,r))&&n.push(r);return n};var Xi=function(e){return Ge(e)?Ue(e,!0):Ki(e)};var Qi=function(e,t){return e&&Wi(t,Xi(t),e)},Hi=i((function(e,t){var n=t&&!t.nodeType&&t,r=n&&e&&!e.nodeType&&e,i=r&&r.exports===n?le.Buffer:void 0,s=i?i.allocUnsafe:void 0;e.exports=function(e,t){if(t)return e.slice();var n=e.length,r=s?s(n):new e.constructor(n);return e.copy(r),r}}));var es=function(e,t){return Wi(e,Dr(e),t)},ts=Object.getOwnPropertySymbols?function(e){for(var t=[];e;)Rr(t,Dr(e)),e=rt(e);return t}:xr;var ns=function(e,t){return Wi(e,ts(e),t)};var rs=function(e){return Nr(e,Xi,ts)},is=Object.prototype.hasOwnProperty;var ss=function(e){var t=e.length,n=new e.constructor(t);return t&&"string"==typeof e[0]&&is.call(e,"index")&&(n.index=e.index,n.input=e.input),n};var os=function(e){var t=new e.constructor(e.byteLength);return new Ir(t).set(new Ir(e)),t};var as=function(e,t){var n=t?os(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)},ls=/\w*$/;var us=function(e){var t=new e.constructor(e.source,ls.exec(e));return t.lastIndex=e.lastIndex,t},cs=ue?ue.prototype:void 0,fs=cs?cs.valueOf:void 0;var hs=function(e){return fs?Object(fs.call(e)):{}};var ds=function(e,t){var n=t?os(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)};var ps=function(e,t,n){var r=e.constructor;switch(t){case"[object ArrayBuffer]":return os(e);case"[object Boolean]":case"[object Date]":return new r(+e);case"[object DataView]":return as(e,n);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return ds(e,n);case"[object Map]":return new r;case"[object Number]":case"[object String]":return new r(e);case"[object RegExp]":return us(e);case"[object Set]":return new r;case"[object Symbol]":return hs(e)}},ms=Object.create,gs=function(){function e(){}return function(t){if(!ze(t))return{};if(ms)return ms(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}();var ys=function(e){return"function"!=typeof e.constructor||Fe(e)?{}:gs(rt(e))};var vs=function(e){return be(e)&&"[object Map]"==Xr(e)},bs=xe&&xe.isMap,ws=bs?Le(bs):vs;var Es=function(e){return be(e)&&"[object Set]"==Xr(e)},_s=xe&&xe.isSet,Ts=_s?Le(_s):Es,Ss={};Ss["[object Arguments]"]=Ss["[object Array]"]=Ss["[object ArrayBuffer]"]=Ss["[object DataView]"]=Ss["[object Boolean]"]=Ss["[object Date]"]=Ss["[object Float32Array]"]=Ss["[object Float64Array]"]=Ss["[object Int8Array]"]=Ss["[object Int16Array]"]=Ss["[object Int32Array]"]=Ss["[object Map]"]=Ss["[object Number]"]=Ss["[object Object]"]=Ss["[object RegExp]"]=Ss["[object Set]"]=Ss["[object String]"]=Ss["[object Symbol]"]=Ss["[object Uint8Array]"]=Ss["[object Uint8ClampedArray]"]=Ss["[object Uint16Array]"]=Ss["[object Uint32Array]"]=!0,Ss["[object Error]"]=Ss["[object Function]"]=Ss["[object WeakMap]"]=!1;var Is=function e(t,n,r,i,s,o){var a,l=1&n,u=2&n,c=4&n;if(r&&(a=s?r(t,i,s,o):r(t)),void 0!==a)return a;if(!ze(t))return t;var f=Ie(t);if(f){if(a=ss(t),!l)return X(t,a)}else{var h=Xr(t),d="[object Function]"==h||"[object GeneratorFunction]"==h;if(Ce(t))return Hi(t,l);if("[object Object]"==h||"[object Arguments]"==h||d&&!s){if(a=u||d?{}:ys(t),!l)return u?ns(t,Qi(a,t)):es(t,Gi(a,t))}else{if(!Ss[h])return s?t:{};a=ps(t,h,l)}}o||(o=new yr);var p=o.get(t);if(p)return p;o.set(t,a),Ts(t)?t.forEach((function(i){a.add(e(i,n,r,i,t,o))})):ws(t)&&t.forEach((function(i,s){a.set(s,e(i,n,r,s,t,o))}));var m=f?void 0:(c?u?rs:Ur:u?Xi:Je)(t);return Vi(m||t,(function(i,s){m&&(i=t[s=i]),zi(a,s,e(i,n,r,s,t,o))})),a};var As=function(e){return Is(e,5)};var Cs=function(e){return function(t,n,r){var i=Object(t);if(!Ge(t)){var s=Ri(n);t=Je(t),n=function(e){return s(i[e],e,i)}}var o=e(t,n,r);return o>-1?i[s?t[o]:o]:void 0}};var Os=function(e,t,n,r){for(var i=e.length,s=n+(r?1:-1);r?s--:++s<i;)if(t(e[s],s,e))return s;return-1},Ms=/\s/;var Ps=function(e){for(var t=e.length;t--&&Ms.test(e.charAt(t)););return t},Rs=/^\s+/;var Ns=function(e){return e?e.slice(0,Ps(e)+1).replace(Rs,""):e},Ls=/^[-+]0x[0-9a-f]+$/i,xs=/^0b[01]+$/i,js=/^0o[0-7]+$/i,ks=parseInt;var Ds=function(e){if("number"==typeof e)return e;if(oi(e))return NaN;if(ze(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=ze(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=Ns(e);var n=xs.test(e);return n||js.test(e)?ks(e.slice(2),n?2:8):Ls.test(e)?NaN:+e};var Us=function(e){return e?(e=Ds(e))===1/0||e===-1/0?17976931348623157e292*(e<0?-1:1):e==e?e:0:0===e?e:0};var Bs=function(e){var t=Us(e),n=t%1;return t==t?n?t-n:t:0},Fs=Math.max;var Vs=Cs((function(e,t,n){var r=null==e?0:e.length;if(!r)return-1;var i=null==n?0:Bs(n);return i<0&&(i=Fs(r+i,0)),Os(e,Ri(t),i)}));var Ys=Object.freeze({__proto__:null,UNREAD_MESSAGES_COUNT_UPDATE:"unreadmessagescountupdate",CLOSE:"close",CONFLICT:"conflict",CONVERSATION_INFO_UPDATED:"conversationinfoupdated",UNHANDLED_MESSAGE:"unhandledmessage",INVITED:"invited",KICKED:"kicked",MEMBERS_JOINED:"membersjoined",MEMBERS_LEFT:"membersleft",MEMBER_INFO_UPDATED:"memberinfoupdated",BLOCKED:"blocked",UNBLOCKED:"unblocked",MEMBERS_BLOCKED:"membersblocked",MEMBERS_UNBLOCKED:"membersunblocked",MUTED:"muted",UNMUTED:"unmuted",MEMBERS_MUTED:"membersmuted",MEMBERS_UNMUTED:"membersunmuted",MESSAGE:"message",MESSAGE_RECALL:"messagerecall",MESSAGE_UPDATE:"messageupdate",LAST_DELIVERED_AT_UPDATE:"lastdeliveredatupdate",LAST_READ_AT_UPDATE:"lastreadatupdate",INFO_UPDATED:"infoupdated"});const $s={NONE:Symbol("none"),SENDING:Symbol("sending"),SENT:Symbol("sent"),DELIVERED:Symbol("delivered"),FAILED:Symbol("failed")};Object.freeze($s);const qs={[$s.NONE]:!0,[$s.SENDING]:!0,[$s.SENT]:!0,[$s.DELIVERED]:!0,[$s.READ]:!0,[$s.FAILED]:!0};class zs{constructor(e){Object.assign(this,{content:e},{id:gn(),cid:null,timestamp:new Date,from:void 0,mentionList:[],mentionedAll:!1,_mentioned:!1}),this._setStatus($s.NONE)}getPayload(){return this.content}_toJSON(){const{id:e,cid:t,from:n,timestamp:r,deliveredAt:i,updatedAt:s,mentionList:o,mentionedAll:a,mentioned:l}=this;return{id:e,cid:t,from:n,timestamp:r,deliveredAt:i,updatedAt:s,mentionList:o,mentionedAll:a,mentioned:l}}toJSON(){return{...this._toJSON(),data:this.content}}toFullJSON(){const{content:e,id:t,cid:n,from:r,timestamp:i,deliveredAt:s,_updatedAt:o,mentionList:a,mentionedAll:l}=this;return{data:e,id:t,cid:n,from:r,timestamp:wt(i),deliveredAt:wt(s),updatedAt:wt(o),mentionList:a,mentionedAll:l}}get status(){return this._status}_setStatus(e){if(!qs[e])throw new Error("Invalid message status");this._status=e}get timestamp(){return this._timestamp}set timestamp(e){this._timestamp=bt(e)}get deliveredAt(){return this._deliveredAt}set deliveredAt(e){this._deliveredAt=bt(e)}get updatedAt(){return this._updatedAt||this.timestamp}set updatedAt(e){this._updatedAt=bt(e)}get mentioned(){return this._mentioned}_updateMentioned(e){this._mentioned=this.from!==e&&(this.mentionedAll||this.mentionList.indexOf(e)>-1)}getMentionList(){return this.mentionList}setMentionList(e){return this.mentionList=Nt(e),this}mentionAll(e=!0){return this.mentionedAll=Boolean(e),this}static validate(){return!0}static parse(e,t){return t||new this(e)}}const Ws=e=>{if("number"!=typeof e)throw new TypeError(`${e} is not a Number`);return t=>{t.TYPE=e,t.validate=t=>t._lctype===e,t.prototype._getType=()=>({_lctype:e})}},Gs=e=>{if("string"!=typeof e){if(!Array.isArray(e))throw new TypeError(`${e} is not an Array`);if(e.some(e=>"string"!=typeof e))throw new TypeError("fields contains non-string typed member")}return t=>{let n=St?It(t,"_customFields"):t._customFields;n=Array.isArray(n)?n:[],t._customFields=n.concat(e)}},Js=e=>{St&&(e.parse=It(e,"parse"))};var Zs;let Ks=Gs(["_lctext","_lcattrs"])(Zs=class extends zs{get type(){return this.constructor.TYPE}set text(e){return this.setText(e)}get text(){return this.getText()}set attributes(e){return this.setAttributes(e)}get attributes(){return this.getAttributes()}get summary(){return this.text}setText(e){return this._lctext=e,this}getText(){return this._lctext}setAttributes(e){return this._lcattrs=e,this}getAttributes(){return this._lcattrs}_getCustomFields(){return(Array.isArray(this.constructor._customFields)?this.constructor._customFields:[]).reduce((e,t)=>("string"!=typeof t||(e[t]=this[t]),e),{})}_getType(){throw new Error("not implemented")}getPayload(){return Pt({_lctext:this.getText(),_lcattrs:this.getAttributes(),...this._getCustomFields(),...this._getType()})}toJSON(){const{type:e,text:t,attributes:n,summary:r}=this;return{...super._toJSON(),type:e,text:t,attributes:n,summary:r}}toFullJSON(){return{...super.toFullJSON(),data:this.getPayload()}}static parse(e,t=new this){t.content=e;const n=St?It(t.constructor,"_customFields"):t.constructor._customFields;let r=Array.isArray(n)?n:[];return r=r.reduce((t,n)=>("string"!=typeof n||(t[n]=e[n]),t),{}),Object.assign(t,r),super.parse(e,t)}})||Zs;var Xs;let Qs=Ws(-127)(Xs=Js(Xs=class extends Ks{get summary(){return"[该消息已撤回]"}})||Xs)||Xs;const Hs=K("LC:Conversation"),eo=e=>{const t=e.getPayload();let n,r;return t instanceof ArrayBuffer?r=t:n="string"!=typeof t?JSON.stringify(t):t,{msg:n,binaryMsg:r}},{NEW:to,OLD:no}=A.QueryDirection,ro={NEW_TO_OLD:no,OLD_TO_NEW:to};Object.freeze(ro);class io extends Y{constructor({id:e,lastMessageAt:t,lastMessage:n,lastDeliveredAt:r,lastReadAt:i,unreadMessagesCount:s=0,members:o=[],mentioned:a=!1,...l},u){super(),Object.assign(this,{id:e,lastMessageAt:t,lastMessage:n,members:o,...l}),this.members=Array.from(new Set(this.members)),Object.assign(Mt(this),{messagesWaitingForReceipt:{},lastDeliveredAt:r,lastReadAt:i,unreadMessagesCount:s,mentioned:a}),this._client=u,Hs.enabled&&Ze(Ys).forEach(e=>this.on(e,(...t)=>this._debug(`${e} event emitted. %o`,t))),rn(this._client._plugins.onConversationCreate,this)}get unreadMessagesMentioned(){return Mt(this).unreadMessagesMentioned}_setUnreadMessagesMentioned(e){Mt(this).unreadMessagesMentioned=Boolean(e)}set unreadMessagesCount(e){e!==this.unreadMessagesCount&&(Mt(this).unreadMessagesCount=e,this._client.emit("unreadmessagescountupdate",[this]))}get unreadMessagesCount(){return Mt(this).unreadMessagesCount}set lastMessageAt(e){const t=bt(e);t<=this._lastMessageAt||(this._lastMessageAt=t)}get lastMessageAt(){return this._lastMessageAt}get lastDeliveredAt(){return 2!==this.members.length?null:Mt(this).lastDeliveredAt}_setLastDeliveredAt(e){const t=bt(e);t<Mt(this).lastDeliveredAt||(Mt(this).lastDeliveredAt=t,this.emit("lastdeliveredatupdate"))}get lastReadAt(){return 2!==this.members.length?null:Mt(this).lastReadAt}_setLastReadAt(e){const t=bt(e);t<Mt(this).lastReadAt||(Mt(this).lastReadAt=t,this.emit("lastreadatupdate"))}toFullJSON(){const{id:e,members:t,lastMessageAt:n,lastDeliveredAt:r,lastReadAt:i,lastMessage:s,unreadMessagesCount:o}=this;return{id:e,members:t,lastMessageAt:wt(n),lastDeliveredAt:wt(r),lastReadAt:wt(i),lastMessage:s?s.toFullJSON():void 0,unreadMessagesCount:o}}toJSON(){const{id:e,members:t,lastMessageAt:n,lastDeliveredAt:r,lastReadAt:i,lastMessage:s,unreadMessagesCount:o,unreadMessagesMentioned:a}=this;return{id:e,members:t,lastMessageAt:n,lastDeliveredAt:r,lastReadAt:i,lastMessage:s?s.toJSON():void 0,unreadMessagesCount:o,unreadMessagesMentioned:a}}_debug(...e){Hs(...e,`[${this.id}]`)}_send(e,...t){return null===e.cmd&&(e.cmd="conv"),"conv"===e.cmd&&null===e.convMessage&&(e.convMessage=new S),e.convMessage&&null===e.convMessage.cid&&(e.convMessage.cid=this.id),this._client._send(e,...t)}async send(e,t){if(this._debug(e,"send"),!(e instanceof zs))throw new TypeError(`${e} is not a Message`);const{transient:n,receipt:r,priority:i,pushData:s,will:o}={...e.constructor.sendOptions,..."function"==typeof e.constructor.getSendOptions?e.constructor.getSendOptions(e):{},...t};r&&(this.transient?console.warn("receipt option is ignored as the conversation is transient."):n?console.warn("receipt option is ignored as the message is sent transiently."):this.members.length>2&&console.warn("receipt option is recommended to be used in one-on-one conversation.")),i&&!this.transient&&console.warn("priority option is ignored as the conversation is not transient."),Object.assign(e,{cid:this.id,from:this._client.id}),e._setStatus($s.SENDING);const{msg:a,binaryMsg:l}=eo(e),u=new L({cmd:"direct",directMessage:new E({msg:a,binaryMsg:l,cid:this.id,r:r,transient:n,dt:e.id,pushData:JSON.stringify(s),will:o,mentionPids:e.mentionList,mentionAll:e.mentionedAll}),priority:i});try{const t=await this._send(u),{ackMessage:{uid:i,t:s,code:o,reason:a,appCode:l}}=t;if(null!==o)throw Zt({code:o,reason:a,appCode:l});return Object.assign(e,{id:i,timestamp:s}),n||(this.lastMessage=e,this.lastMessageAt=e.timestamp),e._setStatus($s.SENT),r&&(Mt(this).messagesWaitingForReceipt[e.id]=e),e}catch(t){throw e._setStatus($s.FAILED),t}}async _update(e,t,n){if(this._debug("patch %O %O %O",e,t,n),e instanceof zs){if(e.from!==this._client.id)throw new Error("Updating message from others is not allowed");if(e.status!==$s.SENT&&e.status!==$s.DELIVERED)throw new Error("Message is not sent")}else if(!e.id||!e.timestamp)throw new TypeError(`${e} is not a Message`);let r,i;if(!n){const e=eo(t);({msg:r,binaryMsg:i}=e)}await this._send(new L({cmd:U.patch,op:B.modify,patchMessage:new j({patches:[new k({cid:this.id,mid:e.id,timestamp:Number(e.timestamp),recall:n,data:r,binaryMsg:i,mentionPids:t.mentionList,mentionAll:t.mentionedAll})],lastPatchTime:this._client._lastPatchTime})}));const{id:s,cid:o,timestamp:a,from:l,_status:u}=e;return Object.assign(t,{id:s,cid:o,timestamp:a,from:l,_status:u}),this.lastMessage&&this.lastMessage.id===t.id&&(this.lastMessage=t),t}async count(){return this._debug("count"),(await this._send(new L({op:"count"}))).convMessage.count}_addMembers(){}_removeMembers(){}async update(e,t){if(!(t instanceof zs))throw new TypeError(`${t} is not a Message`);return this._update(e,t,!1)}async recall(e){return this._update(e,new Qs,!0)}async queryMessages(e={}){this._debug("query messages %O",e);const{beforeTime:t,beforeMessageId:n,afterTime:r,afterMessageId:i,limit:s,direction:o,type:a,startTime:l,startMessageId:u,startClosed:c,endTime:f,endMessageId:h,endClosed:d}=e;if(n||t||i||r)return console.warn("DEPRECATION: queryMessages options beforeTime, beforeMessageId, afterTime and afterMessageId are deprecated in favor of startTime, startMessageId, endTime and endMessageId."),this.queryMessages({startTime:t,startMessageId:n,endTime:r,endMessageId:i,limit:s});if(u&&!l)throw new Error("query option startMessageId must be used with option startTime");if(h&&!f)throw new Error("query option endMessageId must be used with option endTime");const p={t:l,mid:u,tIncluded:c,tt:f,tmid:h,ttIncluded:d,l:s,lctype:a};p.t instanceof Date&&(p.t=p.t.getTime()),p.tt instanceof Date&&(p.tt=p.tt.getTime()),void 0!==o?p.direction=o:p.tt>p.t&&(p.direction=ro.OLD_TO_NEW);const m=await this._send(new L({cmd:"logs",logsMessage:new A(Object.assign(p,{cid:this.id}))}));return Promise.all(m.logsMessage.logs.map(async({msgId:e,timestamp:t,patchTimestamp:n,from:r,ackAt:i,readAt:s,data:o,mentionAll:a,mentionPids:l,bin:u})=>{const c={data:o,bin:u,id:e,cid:this.id,timestamp:t,from:r,deliveredAt:i,updatedAt:n,mentionList:l,mentionedAll:a},f=await this._client.parseMessage(c);let h=$s.SENT;return 2===this.members.length&&(i&&(h=$s.DELIVERED),i&&this._setLastDeliveredAt(i),s&&this._setLastReadAt(s)),f._setStatus(h),f}))}createMessagesIterator({beforeTime:e,beforeMessageId:t,limit:n}={}){let r;return{next:()=>(r=void 0===r?this.queryMessages({limit:n,startTime:e,startMessageId:t}):r.then(e=>0===e.length||e.length<n?[]:this.queryMessages({startTime:e[0].timestamp,startMessageId:e[0].id,limit:n})),r.then(e=>({value:Array.from(e),done:0===e.length||e.length<n})))}}async read(){if(this.unreadMessagesCount=0,this._setUnreadMessagesMentioned(!1),this.transient)return this;const e=this._client;return Mt(e).readConversationsBuffer||(Mt(e).readConversationsBuffer=new Set),Mt(e).readConversationsBuffer.add(this),e._doSendRead(),this}_handleReceipt({messageId:e,timestamp:t,read:n}){n?this._setLastReadAt(t):this._setLastDeliveredAt(t);const{messagesWaitingForReceipt:r}=Mt(this),i=r[e];i&&(i._setStatus($s.DELIVERED),i.deliveredAt=t,delete r[e])}async fetchReceiptTimestamps(){if(this.transient||this.system)return this;const{convMessage:{maxReadTimestamp:e,maxAckTimestamp:t}}=await this._send(new L({op:"max_read"}));return this._setLastDeliveredAt(t),this._setLastReadAt(e),this}_fetchAllReceiptTimestamps(){if(this.transient||this.system)return this;const e=new S({queryAllMembers:!0});return this._send(new L({op:"max_read",convMessage:e})).then(({convMessage:{maxReadTuples:e}})=>e.filter(e=>e.maxAckTimestamp||e.maxReadTimestamp).map(({pid:e,maxAckTimestamp:t,maxReadTimestamp:n})=>({pid:e,lastDeliveredAt:bt(t),lastReadAt:bt(n)})))}}const so=K("LC:SignatureFactoryRunner");function oo(e={}){const{signature:t,timestamp:n,nonce:r}=e;if("string"!=typeof t||"number"!=typeof n||"string"!=typeof r)throw new Error("malformed signature");return{signature:t,timestamp:n,nonce:r}}var ao=(e,t)=>Promise.resolve().then(()=>(so("call signatureFactory with %O",t),e(...t))).then(vt(e=>so("sign result %O",e)),e=>{throw e.message=`sign error: ${e.message}`,so(e),e}).then(oo);const lo=({allowedPids:e,failedPids:t})=>({successfulClientIds:e,failures:t.map(({pids:e,...t})=>Object.assign(Zt(t),{clientIds:e}))});class uo extends io{constructor(e,{creator:t,createdAt:n,updatedAt:r,transient:i=!1,system:s=!1,muted:o=!1,mutedMembers:a=[],...l},u){super({...e,creator:t,createdAt:n,updatedAt:r,mutedMembers:a,transient:i,system:s,muted:o,_attributes:l},u),this._reset()}set createdAt(e){this._createdAt=bt(e)}get createdAt(){return this._createdAt}set updatedAt(e){this._updatedAt=bt(e)}get updatedAt(){return this._updatedAt}get name(){return this.get("name")}set name(e){this.set("name",e)}get(e){return _i(Mt(this).currentAttributes,e)}set(e,t){this._debug(`set [${e}]: ${t}`);const{pendingAttributes:n}=Mt(this),r=Object.keys(n),i=new RegExp(`^${e}`),s=r.filter(i.test.bind(i));if(s.forEach(e=>{delete n[e]}),s.length)n[e]=t;else{const i=Vs(r,t=>0===e.indexOf(t));i?Lt(n[i],e.slice(i.length+1),t):n[e]=t}return this._buildCurrentAttributes(),this}_buildCurrentAttributes(){const{pendingAttributes:e}=Mt(this);Mt(this).currentAttributes=Object.keys(e).reduce((t,n)=>Lt(t,n,e[n]),As(this._attributes))}_updateServerAttributes(e){Object.keys(e).forEach(t=>Lt(this._attributes,t,e[t])),this._buildCurrentAttributes()}_reset(){Object.assign(Mt(this),{pendingAttributes:{},currentAttributes:this._attributes})}async save(){this._debug("save");const e=Mt(this).pendingAttributes;if(Fi(e))return this._debug("nothing touched, resolve with self"),this;this._debug("attr: %O",e);const t=new S({attr:new m({data:JSON.stringify(_t(e))})}),n=await this._send(new L({op:"update",convMessage:t}));return this.updatedAt=n.convMessage.udate,this._attributes=Mt(this).currentAttributes,Mt(this).pendingAttributes={},this}async fetch(){const e=this._client.getQuery().equalTo("objectId",this.id);return await e.find(),this}async mute(){return this._debug("mute"),await this._send(new L({op:"mute"})),this.transient||(this.muted=!0,this.mutedMembers=At(this.mutedMembers,[this._client.id])),this}async unmute(){return this._debug("unmute"),await this._send(new L({op:"unmute"})),this.transient||(this.muted=!1,this.mutedMembers=Ct(this.mutedMembers,[this._client.id])),this}async _appendConversationSignature(e,t,n){if(this._client.options.conversationSignatureFactory){const r=[this.id,this._client.id,n.sort(),t],i=await ao(this._client.options.conversationSignatureFactory,r);Object.assign(e.convMessage,Tt({signature:"s",timestamp:"t",nonce:"n"},i))}}async _appendBlacklistSignature(e,t,n){if(this._client.options.blacklistSignatureFactory){const r=[this.id,this._client.id,n.sort(),t],i=await ao(this._client.options.blacklistSignatureFactory,r);Object.assign(e.blacklistMessage,Tt({signature:"s",timestamp:"t",nonce:"n"},i))}}async add(e){this._debug("add",e),"string"==typeof e&&(e=[e]);const t=new L({op:"add",convMessage:new S({m:e})});await this._appendConversationSignature(t,"invite",e);const{convMessage:n,convMessage:{allowedPids:r}}=await this._send(t);return this._addMembers(r),lo(n)}async remove(e){this._debug("remove",e),"string"==typeof e&&(e=[e]);const t=new L({op:"remove",convMessage:new S({m:e})});await this._appendConversationSignature(t,"kick",e);const{convMessage:n,convMessage:{allowedPids:r}}=await this._send(t);return this._removeMembers(r),lo(n)}async join(){return this._debug("join"),this.add(this._client.id).then(({failures:e})=>{if(e[0])throw e[0];return this})}async quit(){return this._debug("quit"),this.remove(this._client.id).then(({failures:e})=>{if(e[0])throw e[0];return this})}async muteMembers(e){this._debug("mute",e),e=Nt(e);const t=new L({op:B.add_shutup,convMessage:new S({m:e})}),{convMessage:n}=await this._send(t);return lo(n)}async unmuteMembers(e){this._debug("unmute",e),e=Nt(e);const t=new L({op:B.remove_shutup,convMessage:new S({m:e})}),{convMessage:n}=await this._send(t);return lo(n)}async queryMutedMembers({limit:e,next:t}={}){this._debug("query muted: limit %O, next: %O",e,t);const n=new L({op:B.query_shutup,convMessage:new S({limit:e,next:t})}),{convMessage:{m:r,next:i}}=await this._send(n);return{results:r,next:i}}async blockMembers(e){this._debug("block",e),e=Nt(e);const t=new L({cmd:"blacklist",op:B.block,blacklistMessage:new x({srcCid:this.id,toPids:e})});await this._appendBlacklistSignature(t,"conversation-block-clients",e);const{blacklistMessage:n}=await this._send(t);return lo(n)}async unblockMembers(e){this._debug("unblock",e),e=Nt(e);const t=new L({cmd:"blacklist",op:B.unblock,blacklistMessage:new x({srcCid:this.id,toPids:e})});await this._appendBlacklistSignature(t,"conversation-unblock-clients",e);const{blacklistMessage:n}=await this._send(t);return lo(n)}async queryBlockedMembers({limit:e,next:t}={}){this._debug("query blocked: limit %O, next: %O",e,t);const n=new L({cmd:"blacklist",op:B.query,blacklistMessage:new x({srcCid:this.id,limit:e,next:t})}),{blacklistMessage:{blockedPids:r,next:i}}=await this._send(n);return{results:r,next:i}}toFullJSON(){const{creator:e,system:t,transient:n,createdAt:r,updatedAt:i,_attributes:s}=this;return{...super.toFullJSON(),creator:e,system:t,transient:n,createdAt:wt(r),updatedAt:wt(i),...s}}toJSON(){const{creator:e,system:t,transient:n,muted:r,mutedMembers:i,createdAt:s,updatedAt:o,_attributes:a}=this;return{...super.toJSON(),creator:e,system:t,transient:n,muted:r,mutedMembers:i,createdAt:s,updatedAt:o,...a}}}const co={OWNER:"Owner",MANAGER:"Manager",MEMBER:"Member"};Object.freeze(co);class fo{constructor({conversation:e,memberId:t,role:n}){if(!e)throw new Error("conversation requried");if(!t)throw new Error("memberId requried");Object.assign(Mt(this),{conversation:e,memberId:t,role:n})}get conversationId(){return Mt(this).conversation.id}get memberId(){return Mt(this).memberId}get role(){return this.isOwner?co.OWNER:Mt(this).role}get isOwner(){return this.memberId===Mt(this).conversation.creator}toJSON(){const{conversationId:e,memberId:t,role:n,isOwner:r}=this;return{conversationId:e,memberId:t,role:n,isOwner:r}}}class ho extends uo{_addMembers(e){super._addMembers(e),this.members=At(this.members,e);const{memberInfoMap:t}=Mt(this);t&&e.forEach(e=>{t[e]=t[e]||new fo({conversation:this,memberId:e,role:co.MEMBER})})}_removeMembers(e){super._removeMembers(e),this.members=Ct(this.members,e);const{memberInfoMap:t}=Mt(this);t&&e.forEach(e=>{delete t[e]})}async _fetchAllMemberInfo(){const e=(await this._client._requestWithSessionToken({method:"GET",path:"/classes/_ConversationMemberInfo",query:{where:{cid:this.id}}})).results.map(e=>new fo({conversation:this,memberId:e.clientId,role:e.role})),t={};return e.forEach(e=>{t[e.memberId]=e}),this.members.forEach(e=>{t[e]=t[e]||new fo({conversation:this,memberId:e,role:co.MEMBER})}),Mt(this).memberInfoMap=t,t}async getAllMemberInfo({noCache:e=!1}={}){let{memberInfoMap:t}=Mt(this);return t&&!e||(t=await this._fetchAllMemberInfo()),this.members.map(e=>t[e])}async getMemberInfo(e){if(-1===this.members.indexOf(e))throw new Error(`${e} is not the mumber of conversation[${this.id}]`);const{memberInfoMap:t}=Mt(this);return t&&t[e]||await this.getAllMemberInfo(),Mt(this).memberInfoMap[e]}async updateMemberRole(e,t){if(this._debug("update member role"),t===co.OWNER)throw Zt({code:Jt.OWNER_PROMOTION_NOT_ALLOWED});await this._send(new L({op:B.member_info_update,convMessage:new S({targetClientId:e,info:new D({pid:e,role:t})})}));const{memberInfos:n}=Mt(this);return n&&n[e]&&(Mt(n[e]).role=t),this}}class po extends uo{}class mo extends uo{async subscribe(){return this.join()}async unsubscribe(){return this.quit()}}const go=e=>e.code===Jt.CONVERSATION_NOT_FOUND?Zt({code:Jt.TEMPORARY_CONVERSATION_EXPIRED}):e;class yo extends io{constructor(e,{expiredAt:t},n){super({...e,expiredAt:t},n)}set expiredAt(e){this._expiredAt=bt(e)}get expiredAt(){return this._expiredAt}get expired(){return this.expiredAt<new Date}async _send(...e){if(this.expired)throw Zt({code:Jt.TEMPORARY_CONVERSATION_EXPIRED});try{return await super._send(...e)}catch(e){throw go(e)}}async send(...e){try{return await super.send(...e)}catch(e){throw go(e)}}toFullJSON(){const{expiredAt:e}=this;return{...super.toFullJSON(),expiredAt:wt(e)}}toJSON(){const{expiredAt:e,expired:t}=this;return{...super.toJSON(),expiredAt:e,expired:t}}}const vo=K("LC:ConversationQuery");class bo{static _encode(e){return e instanceof Date?{__type:"Date",iso:e.toJSON()}:e instanceof RegExp?e.source:e}static _quote(e){return`\\Q${e.replace("\\E","\\E\\\\E\\Q")}\\E`}static _calculateFlag(e){return["withLastMessagesRefreshed","compact"].reduce((t,n)=>(t<<1)+Boolean(e[n]),0)}static and(...e){if(e.length<2)throw new Error("The queries must contain at least two elements");if(!e.every(e=>e instanceof bo))throw new Error("The element of queries must be an instance of ConversationQuery");const t=new bo(e[0]._client);return t._where.$and=e.map(e=>e._where),t}static or(...e){const t=bo.and(...e);return t._where.$or=t._where.$and,delete t._where.$and,t}constructor(e){this._client=e,this._where={},this._extraOptions={}}_addCondition(e,t,n){return this._where[e]||(this._where[e]={}),this._where[e][t]=this.constructor._encode(n),this}toJSON(){const e={where:this._where,flag:this.constructor._calculateFlag(this._extraOptions)};return void 0!==this._skip&&(e.skip=this._skip),void 0!==this._limit&&(e.limit=this._limit),void 0!==this._order&&(e.sort=this._order),vo(e),e}containsMembers(e){return this.containsAll("m",e)}withMembers(e,t){const n=new Set(e);return t&&n.add(this._client.id),this.sizeEqualTo("m",n.size),this.containsMembers(Array.from(n))}equalTo(e,t){return this._where[e]=this.constructor._encode(t),this}lessThan(e,t){return this._addCondition(e,"$lt",t)}lessThanOrEqualTo(e,t){return this._addCondition(e,"$lte",t)}greaterThan(e,t){return this._addCondition(e,"$gt",t)}greaterThanOrEqualTo(e,t){return this._addCondition(e,"$gte",t)}notEqualTo(e,t){return this._addCondition(e,"$ne",t)}exists(e){return this._addCondition(e,"$exists",!0)}doesNotExist(e){return this._addCondition(e,"$exists",!1)}containedIn(e,t){return this._addCondition(e,"$in",t)}notContainsIn(e,t){return this._addCondition(e,"$nin",t)}containsAll(e,t){return this._addCondition(e,"$all",t)}contains(e,t){return this._addCondition(e,"$regex",bo._quote(t))}startsWith(e,t){return this._addCondition(e,"$regex",`^${bo._quote(t)}`)}endsWith(e,t){return this._addCondition(e,"$regex",`${bo._quote(t)}$`)}matches(e,t){this._addCondition(e,"$regex",t);let n="";return t.ignoreCase&&(n+="i"),t.multiline&&(n+="m"),n&&n.length&&this._addCondition(e,"$options",n),this}sizeEqualTo(e,t){return this._addCondition(e,"$size",t)}limit(e){return this._limit=e,this}skip(e){return this._skip=e,this}ascending(e){return this._order=e,this}addAscending(e){return this._order?this._order+=`,${e}`:this._order=e,this}descending(e){return this._order=`-${e}`,this}addDescending(e){return this._order?this._order+=`,-${e}`:this._order=`-${e}`,this}withLastMessagesRefreshed(e=!0){return this._extraOptions.withLastMessagesRefreshed=e,this}compact(e=!0){return this._extraOptions.compact=e,this}async find(){return this._client._executeQuery(this)}async first(){return(await this.limit(1).find())[0]}}const wo=K("LC:SessionManager");class Eo{constructor({refresh:e,onBeforeGetSessionToken:t}={}){this.refresh=e,this._onBeforeGetSessionToken=t,this.setSessionToken(null,0)}setSessionToken(e,t){wo("set session token",e,t);const n=new dt(e,1e3*t);return this._sessionToken=n,delete this._pendingSessionTokenPromise,n}async setSessionTokenAsync(e){const t=this._sessionToken;return this._pendingSessionTokenPromise=e.catch(e=>{throw this._sessionToken=t,e}),this.setSessionToken(...await this._pendingSessionTokenPromise)}async getSessionToken({autoRefresh:e=!0}={}){wo("get session token"),this._onBeforeGetSessionToken&&this._onBeforeGetSessionToken(this);const{value:t,originalValue:n}=this._sessionToken||await this._pendingSessionTokenPromise;if(t===dt.EXPIRED&&e&&this.refresh){wo("refresh expired session token");const{value:e}=await this.setSessionTokenAsync(this.refresh(this,n));return wo("session token",e),e}return wo("session token",t),t}revoke(){this._sessionToken&&(this._sessionToken.expiredAt=-1)}}var _o,To,So;const Io=K("LC:IMClient"),{INVITED:Ao,KICKED:Co,MEMBERS_JOINED:Oo,MEMBERS_LEFT:Mo,MEMBER_INFO_UPDATED:Po,BLOCKED:Ro,UNBLOCKED:No,MEMBERS_BLOCKED:Lo,MEMBERS_UNBLOCKED:xo,MUTED:jo,UNMUTED:ko,MEMBERS_MUTED:Do,MEMBERS_UNMUTED:Uo,MESSAGE:Bo,UNREAD_MESSAGES_COUNT_UPDATE:Fo,CLOSE:Vo,CONFLICT:Yo,UNHANDLED_MESSAGE:$o,CONVERSATION_INFO_UPDATED:qo,MESSAGE_RECALL:zo,MESSAGE_UPDATE:Wo,INFO_UPDATED:Go}=Ys,Jo=e=>/^_tmp:/.test(e);let Zo=(_o=jt(1e3),To=jt(1e3),Qe((So=class extends Y{constructor(e,t={},n){if(void 0!==e&&"string"!=typeof e)throw new TypeError(`Client id [${e}] is not a String`);if(super(),Object.assign(this,{id:e,options:t},n),!this._messageParser)throw new Error("IMClient must be initialized with a MessageParser");this._conversationCache=new mt(`client:${this.id}`),this._ackMessageBuffer={},Mt(this).lastPatchTime=Date.now(),Mt(this).lastNotificationTime=void 0,Mt(this)._eventemitter=new Y,Io.enabled&&Ze(Ys).forEach(e=>this.on(e,(...t)=>this._debug(`${e} event emitted. %o`,t))),rn(this._plugins.onIMClientCreate,this)}_debug(...e){Io(...e,`[${this.id}]`)}async _dispatchCommand(e){switch(this._debug(Rt(e),"received"),e.serverTs&&1===e.notificationType&&(Mt(this).lastNotificationTime=wt(bt(e.serverTs))),e.cmd){case U.conv:return this._dispatchConvMessage(e);case U.direct:return this._dispatchDirectMessage(e);case U.session:return this._dispatchSessionMessage(e);case U.unread:return this._dispatchUnreadMessage(e);case U.rcp:return this._dispatchRcpMessage(e);case U.patch:return this._dispatchPatchMessage(e);default:return this.emit($o,e)}}async _dispatchSessionMessage(e){const{sessionMessage:{code:t,reason:n}}=e;switch(e.op){case B.closed:return Mt(this)._eventemitter.emit("close"),t===Jt.SESSION_CONFLICT?this.emit(Yo,{reason:n}):this.emit(Vo,{code:t,reason:n});default:throw this.emit($o,e),new Error("Unrecognized session command")}}_dispatchUnreadMessage({unreadMessage:{convs:e,notifTime:t}}){return Mt(this).lastUnreadNotifTime=t,this.getConversations(e.map(e=>e.cid)).then(()=>Promise.all(e.map(({cid:e,unread:t,mid:n,timestamp:r,from:i,data:s,binaryMsg:o,patchTimestamp:a,mentioned:l})=>{const u=this._conversationCache.get(e);if(!u)return null;let c;return r&&(c=bt(r),u.lastMessageAt=c),(n?this._messageParser.parse(o||s).then(t=>{const r={id:n,cid:e,timestamp:c,updatedAt:a,from:i};Object.assign(t,r),u.lastMessage=t}):Promise.resolve()).then(()=>(u._setUnreadMessagesMentioned(l),t===Mt(u).unreadMessagesCount?null:(Mt(u).unreadMessagesCount=t,u)))})).then(e=>e.filter(e=>e))).then(e=>{e.length&&this.emit(Fo,e)})}async _dispatchRcpMessage(e){const{rcpMessage:t,rcpMessage:{read:n}}=e,r=t.cid,i=t.id,s=bt(t.t),o=this._conversationCache.get(r);o&&o._handleReceipt({messageId:i,timestamp:s,read:n})}_dispatchPatchMessage({patchMessage:{patches:e}}){return this.getConversations(e.map(e=>e.cid)).then(()=>Promise.all(e.map(({cid:e,mid:t,timestamp:n,recall:r,data:i,patchTimestamp:s,from:o,binaryMsg:a,mentionAll:l,mentionPids:u,patchCode:c,patchReason:f})=>{const h=this._conversationCache.get(e);return h?this._messageParser.parse(a||i).then(i=>{const a=wt(bt(s)),d={id:t,cid:e,timestamp:n,updatedAt:a,from:o,mentionList:u,mentionedAll:l};let p;Object.assign(i,d),i._setStatus($s.SENT),i._updateMentioned(this.id),Mt(this).lastPatchTime<a&&(Mt(this).lastPatchTime=a),h.lastMessage&&h.lastMessage.id===t&&(h.lastMessage=i),c&&(p={code:c.toNumber(),detail:f}),r?(this.emit(zo,i,h,p),h.emit(zo,i,p)):(this.emit(Wo,i,h,p),h.emit(Wo,i,p))}):null})))}async _dispatchConvMessage(e){const{convMessage:t,convMessage:{initBy:n,m:r,info:i,attr:s}}=e,o=await this.getConversation(t.cid);switch(e.op){case B.joined:{o._addMembers([this.id]);const e={invitedBy:n};return this.emit(Ao,e,o),void o.emit(Ao,e)}case B.left:{o._removeMembers([this.id]);const e={kickedBy:n};return this.emit(Co,e,o),void o.emit(Co,e)}case B.members_joined:{o._addMembers(r);const e={invitedBy:n,members:r};return this.emit(Oo,e,o),void o.emit(Oo,e)}case B.members_left:{o._removeMembers(r);const e={kickedBy:n,members:r};return this.emit(Mo,e,o),void o.emit(Mo,e)}case B.members_blocked:{const e={blockedBy:n,members:r};return this.emit(Lo,e,o),void o.emit(Lo,e)}case B.members_unblocked:{const e={unblockedBy:n,members:r};return this.emit(xo,e,o),void o.emit(xo,e)}case B.blocked:{const e={blockedBy:n};return this.emit(Ro,e,o),void o.emit(Ro,e)}case B.unblocked:{const e={unblockedBy:n};return this.emit(No,e,o),void o.emit(No,e)}case B.members_shutuped:{const e={mutedBy:n,members:r};return this.emit(Do,e,o),void o.emit(Do,e)}case B.members_unshutuped:{const e={unmutedBy:n,members:r};return this.emit(Uo,e,o),void o.emit(Uo,e)}case B.shutuped:{const e={mutedBy:n};return this.emit(jo,e,o),void o.emit(jo,e)}case B.unshutuped:{const e={unmutedBy:n};return this.emit(ko,e,o),void o.emit(ko,e)}case B.member_info_changed:{const{pid:e,role:t}=i,{memberInfoMap:r}=Mt(o);if(!r&&!t)return;const s=await o.getMemberInfo(e);Mt(s).role=t;const a={member:e,memberInfo:s,updatedBy:n};return this.emit(Po,a,o),void o.emit(Po,a)}case B.updated:{const e=Et(JSON.parse(s.data));o._updateServerAttributes(e);const t={attributes:e,updatedBy:n};return this.emit(qo,t,o),void o.emit(Go,t)}default:throw this.emit($o,e),new Error("Unrecognized conversation command")}}_dispatchDirectMessage(e){const{directMessage:t,directMessage:{id:n,cid:r,fromPeerId:i,timestamp:s,transient:o,patchTimestamp:a,mentionPids:l,mentionAll:u,binaryMsg:c,msg:f}}=e,h=c?c.toArrayBuffer():f;return Promise.all([this.getConversation(t.cid),this._messageParser.parse(h)]).then(([e,t])=>{if(!e)return;const c={id:n,cid:r,timestamp:s,updatedAt:a,from:i,mentionList:l,mentionedAll:u};return Object.assign(t,c),t._updateMentioned(this.id),t._setStatus($s.SENT),t.from!==this.id&&(o||e.transient||this._sendAck(t)),this._dispatchParsedMessage(t,e)})}_dispatchParsedMessage(e,t){return on(this._plugins.beforeMessageDispatch,[e,t]).then(n=>{!1!==n&&(t.lastMessage=e,t.lastMessageAt=e.timestamp,e.from!==this.id&&(t.unreadMessagesCount+=1,e.mentioned&&t._setUnreadMessagesMentioned(!0)),this.emit(Bo,e,t),t.emit(Bo,e))})}_sendAck(e){this._debug("send ack for %O",e);const{cid:t}=e;if(!t)throw new Error("missing cid");return this._ackMessageBuffer[t]||(this._ackMessageBuffer[t]=[]),this._ackMessageBuffer[t].push(e),this._doSendAck()}_doSendAck(){this._connection.is("connected")&&(this._debug("do send ack %O",this._ackMessageBuffer),Promise.all(Object.keys(this._ackMessageBuffer).map(e=>{const t=this._ackMessageBuffer[e],n=t.map(e=>e.timestamp),r=new L({cmd:"ack",ackMessage:new _({cid:e,fromts:Math.min.apply(null,n),tots:Math.max.apply(null,n)})});return delete this._ackMessageBuffer[e],this._send(r,!1).catch(n=>{this._debug("send ack failed: %O",n),this._ackMessageBuffer[e]=t})})))}_omitPeerId(e){Mt(this).peerIdOmittable=e}_send(e,...t){const n=e;return!Mt(this).peerIdOmittable&&this.id&&(n.peerId=this.id),this._connection.send(n,...t)}async _open(e,t,n,r=!1){this._debug("open session");const{lastUnreadNotifTime:i,lastPatchTime:s,lastNotificationTime:o}=Mt(this),a=new L({cmd:"session",op:"open",appId:e,peerId:this.id,sessionMessage:new b({ua:"js/5.0.0-rc.7",r:r,lastUnreadNotifTime:i,lastPatchTime:s,configBitmap:187})});if(r){const e=await this._sessionManager.getSessionToken({autoRefresh:!1});e&&e!==dt.EXPIRED&&Object.assign(a.sessionMessage,{st:e})}else if(Object.assign(a.sessionMessage,Rt({tag:t,deviceId:n})),this.options.signatureFactory){const e=await ao(this.options.signatureFactory,[this._identity]);Object.assign(a.sessionMessage,Tt({signature:"s",timestamp:"t",nonce:"n"},e))}let l;try{l=await this._send(a)}catch(i){if(i.code===Jt.SESSION_TOKEN_EXPIRED){if(!this._sessionManager)throw new Error("Unexpected session expiration");return Io("Session token expired, reopening"),this._sessionManager.revoke(),this._open(e,t,n,r)}throw i}const{peerId:u,sessionMessage:c,sessionMessage:{st:f,stTtl:h,code:d},serverTs:p}=l;if(d)throw Zt(c);if(u){this.id=u,this._identity||(this._identity=u),f&&(this._sessionManager=this._sessionManager||this._createSessionManager(),this._sessionManager.setSessionToken(f,h));const e=wt(bt(p));p&&(Mt(this).lastPatchTime=e),o?this._syncNotifications(o).catch(e=>console.warn("Syncing notifications failed:",e)):Mt(this).lastNotificationTime=e}else console.warn("Unexpected session opened without peerId.")}async _syncNotifications(e){const{hasMore:t,notifications:n}=await this._fetchNotifications(e);if(n.forEach(e=>{const{cmd:t,op:n,serverTs:r,notificationType:i,...s}=e;this._dispatchCommand({cmd:U[t],op:B[n],serverTs:r,notificationType:i,[`${t}Message`]:s})}),t)return this._syncNotifications(Mt(this).lastNotificationTime)}async _fetchNotifications(e){return this._requestWithSessionToken({method:"GET",path:"/rtm/notifications",query:{start_ts:e,notification_type:"permanent"}})}_createSessionManager(){return Io("create SessionManager"),new Eo({onBeforeGetSessionToken:this._connection.checkConnectionAvailability.bind(this._connection),refresh:(e,t)=>e.setSessionTokenAsync(Promise.resolve(new L({cmd:"session",op:"refresh",sessionMessage:new b({ua:"js/5.0.0-rc.7",st:t})})).then(async e=>{if(this.options.signatureFactory){const t=await ao(this.options.signatureFactory,[this._identity]);Object.assign(e.sessionMessage,Tt({signature:"s",timestamp:"t",nonce:"n"},t))}return e}).then(this._send.bind(this)).then(({sessionMessage:{st:e,stTtl:t}})=>[e,t]))})}async _requestWithSessionToken({headers:e,query:t,...n}){const r=await this._sessionManager.getSessionToken();return this._request({headers:{"X-LC-IM-Session-Token":r,...e},query:{client_id:this.id,...t},...n})}async close(){this._debug("close session");const e=Mt(this)._eventemitter;if(e.emit("beforeclose"),this._connection.is("connected")){const e=new L({cmd:"session",op:"close"});await this._send(e)}e.emit("close"),this.emit(Vo,{code:0})}async ping(e){if(this._debug("ping"),!(e instanceof Array))throw new TypeError(`clientIds ${e} is not an Array`);if(!e.length)return Promise.resolve([]);const t=new L({cmd:"session",op:"query",sessionMessage:new b({sessionPeerIds:e})});return(await this._send(t)).sessionMessage.onlineSessionPeerIds}async getConversation(e,t=!1){if("string"!=typeof e)throw new TypeError(`${e} is not a String`);if(!t){const t=this._conversationCache.get(e);if(t)return t}return Jo(e)?(await this._getTemporaryConversations([e]))[0]||null:this.getQuery().equalTo("objectId",e).find().then(e=>e[0]||null)}async getConversations(e,t=!1){const n=t?e:e.filter(e=>null===this._conversationCache.get(e));if(n.length){const e=Ui(n,Jo),t=[];if(n.length&&t.push(this.getQuery().containedIn("objectId",n).limit(999).find()),e.length){const n=e.map(this._getTemporaryConversations.bind(this));t.push(...n)}await Promise.all(t)}return e.map(e=>this._conversationCache.get(e))}async _getTemporaryConversations(e){const t=new L({cmd:"conv",op:"query",convMessage:new S({tempConvIds:e})}),n=await this._send(t);return this._handleQueryResults(n)}getQuery(){return new bo(this)}getChatRoomQuery(){return this.getQuery().equalTo("tr",!0)}getServiceConversationQuery(){return this.getQuery().equalTo("sys",!0)}async _executeQuery(e){const t=e.toJSON();t.where=new m({data:JSON.stringify(_t(t.where))});const n=new L({cmd:"conv",op:"query",convMessage:new S(t)}),r=await this._send(n);return this._handleQueryResults(r)}async _handleQueryResults(e){let t;try{t=Et(JSON.parse(e.convMessage.results.data))}catch(t){const n=JSON.stringify(Rt(e));throw new Error(`Parse query result failed: ${t.message}. Command: ${n}`)}return t=await Promise.all(t.map(this._parseConversationFromRawData.bind(this))),t.map(this._upsertConversationToCache.bind(this))}_upsertConversationToCache(e){let t=this._conversationCache.get(e.id);return t?(this._debug("update cached conversation"),["creator","createdAt","updatedAt","lastMessageAt","lastMessage","mutedMembers","members","_attributes","transient","muted"].forEach(n=>{const r=e[n];void 0!==r&&(t[n]=r)}),t._reset&&t._reset()):(t=e,this._debug("no match, set cache"),this._conversationCache.set(e.id,e)),t}async parseMessage({data:e,bin:t=!1,...n}){const r=t?bn(e):e,i=await this._messageParser.parse(r);return Object.assign(i,n),i._updateMentioned(this.id),i}async parseConversation({id:e,lastMessageAt:t,lastMessage:n,lastDeliveredAt:r,lastReadAt:i,unreadMessagesCount:s,members:o,mentioned:a,...l}){const u={id:e,lastMessageAt:t,lastMessage:n,lastDeliveredAt:r,lastReadAt:i,unreadMessagesCount:s,members:o,mentioned:a};n&&(u.lastMessage=await this.parseMessage(n),u.lastMessage._setStatus($s.SENT));const{transient:c,system:f,expiredAt:h}=l;return c?new po(u,l,this):f?new mo(u,l,this):h||Jo(e)?new yo(u,{expiredAt:h},this):new ho(u,l,this)}async _parseConversationFromRawData(e){const t=Tt({objectId:"id",lm:"lastMessageAt",m:"members",tr:"transient",sys:"system",c:"creator",mu:"mutedMembers"},e);t.msg&&(t.lastMessage={data:t.msg,bin:t.bin,from:t.msg_from,id:t.msg_mid,timestamp:t.msg_timestamp,updatedAt:t.patch_timestamp},delete t.lastMessageFrom,delete t.lastMessageId,delete t.lastMessageTimestamp,delete t.lastMessagePatchTimestamp);const{ttl:n}=t;return n&&(t.expiredAt=Date.now()+1e3*n),this.parseConversation(t)}async createConversation({members:e,name:t,transient:n,unique:r=!0,_tempConv:i,_tempConvTTL:s,...o}={}){if(!n&&!Array.isArray(e))throw new TypeError(`conversation members ${e} is not an array`);let a=new Set(e);a.add(this.id),a=Array.from(a).sort();let l=o||{};if(t){if("string"!=typeof t)throw new TypeError(`conversation name ${t} is not a string`);l.name=t}l=new m({data:JSON.stringify(_t(l))});const u=new L({cmd:"conv",op:"start",convMessage:new S({m:a,attr:l,transient:n,unique:r,tempConv:i,tempConvTTL:s})});if(this.options.conversationSignatureFactory){const e=[null,this._identity,a,"create"],t=await ao(this.options.conversationSignatureFactory,e);Object.assign(u.convMessage,Tt({signature:"s",timestamp:"t",nonce:"n"},t))}const{convMessage:{cid:c,cdate:f,tempConvTTL:h}}=await this._send(u),d={name:t,transient:n,unique:r,id:c,createdAt:f,updatedAt:f,lastMessageAt:null,creator:this.id,members:n?[]:a,...o};h&&(d.expiredAt=Date.now()+1e3*h);const p=await this.parseConversation(d);return this._upsertConversationToCache(p)}async createChatRoom(e){return this.createConversation({...e,transient:!0,members:null,unique:!1,_tempConv:!1})}async createTemporaryConversation({ttl:e,...t}){return this.createConversation({...t,_tempConv:!0,_tempConvTTL:e})}_doSendRead(){if(!this._connection.is("connected"))return;const e=Mt(this).readConversationsBuffer,t=Array.from(e);if(!t.length)return;const n=t.map(e=>{if(!(e instanceof io))throw new TypeError(`${e} is not a Conversation`);return e.id});this._debug(`mark [${n}] as read`),e.clear(),this._sendReadCommand(t).catch(n=>{this._debug("send read failed: %O",n),t.forEach(e.add.bind(e))})}_sendReadCommand(e){return this._send(new L({cmd:"read",readMessage:new P({convs:e.map(e=>new O({cid:e.id,mid:e.lastMessage&&e.lastMessage.from!==this.id?e.lastMessage.id:void 0,timestamp:(e.lastMessageAt||new Date).getTime()}))})}),!1)}}).prototype,"_doSendAck",[_o],Object.getOwnPropertyDescriptor(So.prototype,"_doSendAck"),So.prototype),Qe(So.prototype,"_doSendRead",[To],Object.getOwnPropertyDescriptor(So.prototype,"_doSendRead"),So.prototype),So);var Ko,Xo=Object.freeze({__proto__:null,RECONNECT_ERROR:"reconnecterror",DISCONNECT:Ut,RECONNECT:Bt,RETRY:Ft,SCHEDULE:Vt,OFFLINE:Yt,ONLINE:$t});let Qo=Js(Ko=class extends zs{constructor(e){if(!(e instanceof ArrayBuffer))throw new TypeError(`${e} is not an ArrayBuffer`);super(e)}get buffer(){return this.content}set buffer(e){this.content=e}static validate(e){return e instanceof ArrayBuffer}toJSON(){return{...super._toJSON(),data:vn(this.content)}}toFullJSON(){return{...super.toFullJSON(),bin:!0,data:vn(this.content)}}})||Ko;var Ho;let ea=Ws(-1)(Ho=Js(Ho=class extends Ks{constructor(e=""){if("string"!=typeof e)throw new TypeError(`${e} is not a string`);super(),this.setText(e)}})||Ho)||Ho;var ta;const na=K("LC:MessageParser");let ra=(Qe((ta=class{constructor(e={}){this._plugins=e,this._messageClasses=[],this.register(e.messageClasses)}register(e){Nt(e).map(e=>this._register(e))}_register(e){if(!(e&&e.parse&&e.prototype&&e.prototype.getPayload))throw new TypeError("Invalid messageClass");this._messageClasses.unshift(e)}parse(e){na("parsing message: %O",e);for(const t of this._messageClasses){const n=ut(e)?{...e}:e;let r,i;try{r=t.validate(n)}catch(e){}if(r){try{i=t.parse(n)}catch(e){console.warn("parsing a valid message content error",{error:e,Klass:t,content:n})}if(void 0!==i)return na("parse result: %O",i),i}}throw new Error("No Message Class matched")}}).prototype,"parse",[(e,t,n)=>{const r=n.value;n.value=function(e){let t;if("string"!=typeof e)t=e;else try{t=JSON.parse(e)}catch(n){t=e}return r.call(this,t)}},(e,t,n)=>{const r=n.value;n.value=function(e){return Promise.resolve(e).then(sn(this._plugins.beforeMessageParse)).then(e=>r.call(this,e)).then(sn(this._plugins.afterMessageParse))}}],Object.getOwnPropertyDescriptor(ta.prototype,"parse"),ta.prototype),ta);const ia=K("LC:IMPlugin"),sa={HIGH:1,NORMAL:2,LOW:3};Object.freeze(sa);const oa=(e,t={get(){return this.get(e)},set(t){this.set(e,t)}})=>{Object.defineProperty(ho.prototype,e,t)},aa={name:"leancloud-realtime-plugin-im",onRealtimeCreate:e=>{const t=gn();e._IMClients={},e._IMClientsCreationCount=0;const n=new ra(e._plugins);e._messageParser=n;const r=async t=>e._request({method:"POST",path:"/rtm/sign",data:{session_token:t.getSessionToken()}}),i=n.register.bind(n);Object.assign(e,{register:i,createIMClient:async(i,{tag:s,isReconnect:o,...a}={},l)=>{let u;const c={};if(i){if("string"==typeof i)u=i;else{if(!i.id||!i.getSessionToken)throw new TypeError("Identity must be a String or an AV.User");if(({id:u}=i),!i.getSessionToken())throw new Error("User must be authenticated");c.signatureFactory=r}if(void 0!==e._IMClients[u])return e._IMClients[u]}l&&console.warn("DEPRECATION createIMClient tag param: Use options.tag instead.");const f=s||l,h=e._open().then(r=>{const s=new Zo(u,{...c,...a},{_connection:r,_request:e._request.bind(e),_messageParser:n,_plugins:e._plugins,_identity:i});return r.on(Bt,()=>s._open(e._options.appId,f,t,!0).then(()=>s.emit(Bt),e=>s.emit("reconnecterror",e))),Mt(s)._eventemitter.on("beforeclose",()=>{delete e._IMClients[s.id],e._firstIMClient===s&&delete e._firstIMClient},e),Mt(s)._eventemitter.on("close",()=>{e._deregister(s)},e),s._open(e._options.appId,f,t,o).then(()=>(e._IMClients[s.id]=s,e._IMClientsCreationCount+=1,1===e._IMClientsCreationCount?(s._omitPeerId(!0),e._firstIMClient=s):e._IMClientsCreationCount>1&&e._firstIMClient&&e._firstIMClient._omitPeerId(!1),e._register(s),s)).catch(t=>{throw delete e._IMClients[s.id],t})}).then(...(d=()=>{e._deregisterPending(h)},[e=>(d(),e),e=>{throw d(),e}])).catch(t=>{throw delete e._IMClients[u],t});var d;return i&&(e._IMClients[u]=h),e._registerPending(h),h}})},beforeCommandDispatch:(e,t)=>{if(!(null===e.service||2===e.service))return!0;const n=e.peerId?t._IMClients[e.peerId]:t._firstIMClient;return n?Promise.resolve(n).then(t=>t._dispatchCommand(e)).catch(ia):ia("[WARN] Unexpected message received without any live client match: %O",Rt(e)),!1},messageClasses:[zs,Qo,Qs,ea]};cn.defineConversationProperty=oa,cn.__preRegisteredPlugins=[aa];const la={...Xo,...Ys};nt({WebSocket:u,request:c}),e.BinaryMessage=Qo,e.ChatRoom=po,e.Conversation=ho,e.ConversationMemberRole=co,e.ConversationQuery=bo,e.ErrorCode=Jt,e.Event=la,e.EventEmitter=Y,e.IE10Compatible=Js,e.IMPlugin=aa,e.Message=zs,e.MessageParser=ra,e.MessagePriority=sa,e.MessageQueryDirection=ro,e.MessageStatus=$s,e.Promise=fn,e.Protocals=V,e.Protocols=V,e.Realtime=cn,e.RecalledMessage=Qs,e.ServiceConversation=mo,e.TemporaryConversation=yo,e.TextMessage=ea,e.TypedMessage=Ks,e.debug=gt,e.defineConversationProperty=oa,e.getAdapter=tt,e.messageField=Gs,e.messageType=Ws,e.setAdapters=nt,Object.defineProperty(e,"__esModule",{value:!0})}));
  34. //# sourceMappingURL=im-weapp.min.js.map