im-node.js 308 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var platformAdaptersNode = require('@leancloud/platform-adapters-node');
  5. var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty'));
  6. var protobufLight = _interopDefault(require('protobufjs/dist/protobuf-light'));
  7. var EventEmitter = _interopDefault(require('eventemitter3'));
  8. var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator'));
  9. var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator'));
  10. var _toConsumableArray = _interopDefault(require('@babel/runtime/helpers/toConsumableArray'));
  11. var _objectWithoutProperties = _interopDefault(require('@babel/runtime/helpers/objectWithoutProperties'));
  12. var _assertThisInitialized = _interopDefault(require('@babel/runtime/helpers/assertThisInitialized'));
  13. var _inheritsLoose = _interopDefault(require('@babel/runtime/helpers/inheritsLoose'));
  14. var d = _interopDefault(require('debug'));
  15. var shuffle = _interopDefault(require('lodash/shuffle'));
  16. var values = _interopDefault(require('lodash/values'));
  17. var _toArray = _interopDefault(require('@babel/runtime/helpers/toArray'));
  18. var _createClass = _interopDefault(require('@babel/runtime/helpers/createClass'));
  19. var _applyDecoratedDescriptor = _interopDefault(require('@babel/runtime/helpers/applyDecoratedDescriptor'));
  20. var StateMachine = _interopDefault(require('javascript-state-machine'));
  21. var _typeof = _interopDefault(require('@babel/runtime/helpers/typeof'));
  22. var isPlainObject = _interopDefault(require('lodash/isPlainObject'));
  23. var promiseTimeout = require('promise-timeout');
  24. var uuid = _interopDefault(require('uuid/v4'));
  25. var _slicedToArray = _interopDefault(require('@babel/runtime/helpers/slicedToArray'));
  26. var base64Arraybuffer = require('base64-arraybuffer');
  27. var remove = _interopDefault(require('lodash/remove'));
  28. var isEmpty = _interopDefault(require('lodash/isEmpty'));
  29. var cloneDeep = _interopDefault(require('lodash/cloneDeep'));
  30. var find = _interopDefault(require('lodash/find'));
  31. var _get = _interopDefault(require('lodash/get'));
  32. var messageCompiled = protobufLight.newBuilder({})['import']({
  33. "package": 'push_server.messages2',
  34. syntax: 'proto2',
  35. options: {
  36. objc_class_prefix: 'AVIM'
  37. },
  38. messages: [{
  39. name: 'JsonObjectMessage',
  40. syntax: 'proto2',
  41. fields: [{
  42. rule: 'required',
  43. type: 'string',
  44. name: 'data',
  45. id: 1
  46. }]
  47. }, {
  48. name: 'UnreadTuple',
  49. syntax: 'proto2',
  50. fields: [{
  51. rule: 'required',
  52. type: 'string',
  53. name: 'cid',
  54. id: 1
  55. }, {
  56. rule: 'required',
  57. type: 'int32',
  58. name: 'unread',
  59. id: 2
  60. }, {
  61. rule: 'optional',
  62. type: 'string',
  63. name: 'mid',
  64. id: 3
  65. }, {
  66. rule: 'optional',
  67. type: 'int64',
  68. name: 'timestamp',
  69. id: 4
  70. }, {
  71. rule: 'optional',
  72. type: 'string',
  73. name: 'from',
  74. id: 5
  75. }, {
  76. rule: 'optional',
  77. type: 'string',
  78. name: 'data',
  79. id: 6
  80. }, {
  81. rule: 'optional',
  82. type: 'int64',
  83. name: 'patchTimestamp',
  84. id: 7
  85. }, {
  86. rule: 'optional',
  87. type: 'bool',
  88. name: 'mentioned',
  89. id: 8
  90. }, {
  91. rule: 'optional',
  92. type: 'bytes',
  93. name: 'binaryMsg',
  94. id: 9
  95. }, {
  96. rule: 'optional',
  97. type: 'int32',
  98. name: 'convType',
  99. id: 10
  100. }]
  101. }, {
  102. name: 'LogItem',
  103. syntax: 'proto2',
  104. fields: [{
  105. rule: 'optional',
  106. type: 'string',
  107. name: 'from',
  108. id: 1
  109. }, {
  110. rule: 'optional',
  111. type: 'string',
  112. name: 'data',
  113. id: 2
  114. }, {
  115. rule: 'optional',
  116. type: 'int64',
  117. name: 'timestamp',
  118. id: 3
  119. }, {
  120. rule: 'optional',
  121. type: 'string',
  122. name: 'msgId',
  123. id: 4
  124. }, {
  125. rule: 'optional',
  126. type: 'int64',
  127. name: 'ackAt',
  128. id: 5
  129. }, {
  130. rule: 'optional',
  131. type: 'int64',
  132. name: 'readAt',
  133. id: 6
  134. }, {
  135. rule: 'optional',
  136. type: 'int64',
  137. name: 'patchTimestamp',
  138. id: 7
  139. }, {
  140. rule: 'optional',
  141. type: 'bool',
  142. name: 'mentionAll',
  143. id: 8
  144. }, {
  145. rule: 'repeated',
  146. type: 'string',
  147. name: 'mentionPids',
  148. id: 9
  149. }, {
  150. rule: 'optional',
  151. type: 'bool',
  152. name: 'bin',
  153. id: 10
  154. }, {
  155. rule: 'optional',
  156. type: 'int32',
  157. name: 'convType',
  158. id: 11
  159. }]
  160. }, {
  161. name: 'ConvMemberInfo',
  162. syntax: 'proto2',
  163. fields: [{
  164. rule: 'optional',
  165. type: 'string',
  166. name: 'pid',
  167. id: 1
  168. }, {
  169. rule: 'optional',
  170. type: 'string',
  171. name: 'role',
  172. id: 2
  173. }, {
  174. rule: 'optional',
  175. type: 'string',
  176. name: 'infoId',
  177. id: 3
  178. }]
  179. }, {
  180. name: 'DataCommand',
  181. syntax: 'proto2',
  182. fields: [{
  183. rule: 'repeated',
  184. type: 'string',
  185. name: 'ids',
  186. id: 1
  187. }, {
  188. rule: 'repeated',
  189. type: 'JsonObjectMessage',
  190. name: 'msg',
  191. id: 2
  192. }, {
  193. rule: 'optional',
  194. type: 'bool',
  195. name: 'offline',
  196. id: 3
  197. }]
  198. }, {
  199. name: 'SessionCommand',
  200. syntax: 'proto2',
  201. fields: [{
  202. rule: 'optional',
  203. type: 'int64',
  204. name: 't',
  205. id: 1
  206. }, {
  207. rule: 'optional',
  208. type: 'string',
  209. name: 'n',
  210. id: 2
  211. }, {
  212. rule: 'optional',
  213. type: 'string',
  214. name: 's',
  215. id: 3
  216. }, {
  217. rule: 'optional',
  218. type: 'string',
  219. name: 'ua',
  220. id: 4
  221. }, {
  222. rule: 'optional',
  223. type: 'bool',
  224. name: 'r',
  225. id: 5
  226. }, {
  227. rule: 'optional',
  228. type: 'string',
  229. name: 'tag',
  230. id: 6
  231. }, {
  232. rule: 'optional',
  233. type: 'string',
  234. name: 'deviceId',
  235. id: 7
  236. }, {
  237. rule: 'repeated',
  238. type: 'string',
  239. name: 'sessionPeerIds',
  240. id: 8
  241. }, {
  242. rule: 'repeated',
  243. type: 'string',
  244. name: 'onlineSessionPeerIds',
  245. id: 9
  246. }, {
  247. rule: 'optional',
  248. type: 'string',
  249. name: 'st',
  250. id: 10
  251. }, {
  252. rule: 'optional',
  253. type: 'int32',
  254. name: 'stTtl',
  255. id: 11
  256. }, {
  257. rule: 'optional',
  258. type: 'int32',
  259. name: 'code',
  260. id: 12
  261. }, {
  262. rule: 'optional',
  263. type: 'string',
  264. name: 'reason',
  265. id: 13
  266. }, {
  267. rule: 'optional',
  268. type: 'string',
  269. name: 'deviceToken',
  270. id: 14
  271. }, {
  272. rule: 'optional',
  273. type: 'bool',
  274. name: 'sp',
  275. id: 15
  276. }, {
  277. rule: 'optional',
  278. type: 'string',
  279. name: 'detail',
  280. id: 16
  281. }, {
  282. rule: 'optional',
  283. type: 'int64',
  284. name: 'lastUnreadNotifTime',
  285. id: 17
  286. }, {
  287. rule: 'optional',
  288. type: 'int64',
  289. name: 'lastPatchTime',
  290. id: 18
  291. }, {
  292. rule: 'optional',
  293. type: 'int64',
  294. name: 'configBitmap',
  295. id: 19
  296. }]
  297. }, {
  298. name: 'ErrorCommand',
  299. syntax: 'proto2',
  300. fields: [{
  301. rule: 'required',
  302. type: 'int32',
  303. name: 'code',
  304. id: 1
  305. }, {
  306. rule: 'required',
  307. type: 'string',
  308. name: 'reason',
  309. id: 2
  310. }, {
  311. rule: 'optional',
  312. type: 'int32',
  313. name: 'appCode',
  314. id: 3
  315. }, {
  316. rule: 'optional',
  317. type: 'string',
  318. name: 'detail',
  319. id: 4
  320. }, {
  321. rule: 'repeated',
  322. type: 'string',
  323. name: 'pids',
  324. id: 5
  325. }, {
  326. rule: 'optional',
  327. type: 'string',
  328. name: 'appMsg',
  329. id: 6
  330. }]
  331. }, {
  332. name: 'DirectCommand',
  333. syntax: 'proto2',
  334. fields: [{
  335. rule: 'optional',
  336. type: 'string',
  337. name: 'msg',
  338. id: 1
  339. }, {
  340. rule: 'optional',
  341. type: 'string',
  342. name: 'uid',
  343. id: 2
  344. }, {
  345. rule: 'optional',
  346. type: 'string',
  347. name: 'fromPeerId',
  348. id: 3
  349. }, {
  350. rule: 'optional',
  351. type: 'int64',
  352. name: 'timestamp',
  353. id: 4
  354. }, {
  355. rule: 'optional',
  356. type: 'bool',
  357. name: 'offline',
  358. id: 5
  359. }, {
  360. rule: 'optional',
  361. type: 'bool',
  362. name: 'hasMore',
  363. id: 6
  364. }, {
  365. rule: 'repeated',
  366. type: 'string',
  367. name: 'toPeerIds',
  368. id: 7
  369. }, {
  370. rule: 'optional',
  371. type: 'bool',
  372. name: 'r',
  373. id: 10
  374. }, {
  375. rule: 'optional',
  376. type: 'string',
  377. name: 'cid',
  378. id: 11
  379. }, {
  380. rule: 'optional',
  381. type: 'string',
  382. name: 'id',
  383. id: 12
  384. }, {
  385. rule: 'optional',
  386. type: 'bool',
  387. name: 'transient',
  388. id: 13
  389. }, {
  390. rule: 'optional',
  391. type: 'string',
  392. name: 'dt',
  393. id: 14
  394. }, {
  395. rule: 'optional',
  396. type: 'string',
  397. name: 'roomId',
  398. id: 15
  399. }, {
  400. rule: 'optional',
  401. type: 'string',
  402. name: 'pushData',
  403. id: 16
  404. }, {
  405. rule: 'optional',
  406. type: 'bool',
  407. name: 'will',
  408. id: 17
  409. }, {
  410. rule: 'optional',
  411. type: 'int64',
  412. name: 'patchTimestamp',
  413. id: 18
  414. }, {
  415. rule: 'optional',
  416. type: 'bytes',
  417. name: 'binaryMsg',
  418. id: 19
  419. }, {
  420. rule: 'repeated',
  421. type: 'string',
  422. name: 'mentionPids',
  423. id: 20
  424. }, {
  425. rule: 'optional',
  426. type: 'bool',
  427. name: 'mentionAll',
  428. id: 21
  429. }, {
  430. rule: 'optional',
  431. type: 'int32',
  432. name: 'convType',
  433. id: 22
  434. }]
  435. }, {
  436. name: 'AckCommand',
  437. syntax: 'proto2',
  438. fields: [{
  439. rule: 'optional',
  440. type: 'int32',
  441. name: 'code',
  442. id: 1
  443. }, {
  444. rule: 'optional',
  445. type: 'string',
  446. name: 'reason',
  447. id: 2
  448. }, {
  449. rule: 'optional',
  450. type: 'string',
  451. name: 'mid',
  452. id: 3
  453. }, {
  454. rule: 'optional',
  455. type: 'string',
  456. name: 'cid',
  457. id: 4
  458. }, {
  459. rule: 'optional',
  460. type: 'int64',
  461. name: 't',
  462. id: 5
  463. }, {
  464. rule: 'optional',
  465. type: 'string',
  466. name: 'uid',
  467. id: 6
  468. }, {
  469. rule: 'optional',
  470. type: 'int64',
  471. name: 'fromts',
  472. id: 7
  473. }, {
  474. rule: 'optional',
  475. type: 'int64',
  476. name: 'tots',
  477. id: 8
  478. }, {
  479. rule: 'optional',
  480. type: 'string',
  481. name: 'type',
  482. id: 9
  483. }, {
  484. rule: 'repeated',
  485. type: 'string',
  486. name: 'ids',
  487. id: 10
  488. }, {
  489. rule: 'optional',
  490. type: 'int32',
  491. name: 'appCode',
  492. id: 11
  493. }, {
  494. rule: 'optional',
  495. type: 'string',
  496. name: 'appMsg',
  497. id: 12
  498. }]
  499. }, {
  500. name: 'UnreadCommand',
  501. syntax: 'proto2',
  502. fields: [{
  503. rule: 'repeated',
  504. type: 'UnreadTuple',
  505. name: 'convs',
  506. id: 1
  507. }, {
  508. rule: 'optional',
  509. type: 'int64',
  510. name: 'notifTime',
  511. id: 2
  512. }]
  513. }, {
  514. name: 'ConvCommand',
  515. syntax: 'proto2',
  516. fields: [{
  517. rule: 'repeated',
  518. type: 'string',
  519. name: 'm',
  520. id: 1
  521. }, {
  522. rule: 'optional',
  523. type: 'bool',
  524. name: 'transient',
  525. id: 2
  526. }, {
  527. rule: 'optional',
  528. type: 'bool',
  529. name: 'unique',
  530. id: 3
  531. }, {
  532. rule: 'optional',
  533. type: 'string',
  534. name: 'cid',
  535. id: 4
  536. }, {
  537. rule: 'optional',
  538. type: 'string',
  539. name: 'cdate',
  540. id: 5
  541. }, {
  542. rule: 'optional',
  543. type: 'string',
  544. name: 'initBy',
  545. id: 6
  546. }, {
  547. rule: 'optional',
  548. type: 'string',
  549. name: 'sort',
  550. id: 7
  551. }, {
  552. rule: 'optional',
  553. type: 'int32',
  554. name: 'limit',
  555. id: 8
  556. }, {
  557. rule: 'optional',
  558. type: 'int32',
  559. name: 'skip',
  560. id: 9
  561. }, {
  562. rule: 'optional',
  563. type: 'int32',
  564. name: 'flag',
  565. id: 10
  566. }, {
  567. rule: 'optional',
  568. type: 'int32',
  569. name: 'count',
  570. id: 11
  571. }, {
  572. rule: 'optional',
  573. type: 'string',
  574. name: 'udate',
  575. id: 12
  576. }, {
  577. rule: 'optional',
  578. type: 'int64',
  579. name: 't',
  580. id: 13
  581. }, {
  582. rule: 'optional',
  583. type: 'string',
  584. name: 'n',
  585. id: 14
  586. }, {
  587. rule: 'optional',
  588. type: 'string',
  589. name: 's',
  590. id: 15
  591. }, {
  592. rule: 'optional',
  593. type: 'bool',
  594. name: 'statusSub',
  595. id: 16
  596. }, {
  597. rule: 'optional',
  598. type: 'bool',
  599. name: 'statusPub',
  600. id: 17
  601. }, {
  602. rule: 'optional',
  603. type: 'int32',
  604. name: 'statusTTL',
  605. id: 18
  606. }, {
  607. rule: 'optional',
  608. type: 'string',
  609. name: 'uniqueId',
  610. id: 19
  611. }, {
  612. rule: 'optional',
  613. type: 'string',
  614. name: 'targetClientId',
  615. id: 20
  616. }, {
  617. rule: 'optional',
  618. type: 'int64',
  619. name: 'maxReadTimestamp',
  620. id: 21
  621. }, {
  622. rule: 'optional',
  623. type: 'int64',
  624. name: 'maxAckTimestamp',
  625. id: 22
  626. }, {
  627. rule: 'optional',
  628. type: 'bool',
  629. name: 'queryAllMembers',
  630. id: 23
  631. }, {
  632. rule: 'repeated',
  633. type: 'MaxReadTuple',
  634. name: 'maxReadTuples',
  635. id: 24
  636. }, {
  637. rule: 'repeated',
  638. type: 'string',
  639. name: 'cids',
  640. id: 25
  641. }, {
  642. rule: 'optional',
  643. type: 'ConvMemberInfo',
  644. name: 'info',
  645. id: 26
  646. }, {
  647. rule: 'optional',
  648. type: 'bool',
  649. name: 'tempConv',
  650. id: 27
  651. }, {
  652. rule: 'optional',
  653. type: 'int32',
  654. name: 'tempConvTTL',
  655. id: 28
  656. }, {
  657. rule: 'repeated',
  658. type: 'string',
  659. name: 'tempConvIds',
  660. id: 29
  661. }, {
  662. rule: 'repeated',
  663. type: 'string',
  664. name: 'allowedPids',
  665. id: 30
  666. }, {
  667. rule: 'repeated',
  668. type: 'ErrorCommand',
  669. name: 'failedPids',
  670. id: 31
  671. }, {
  672. rule: 'optional',
  673. type: 'string',
  674. name: 'next',
  675. id: 40
  676. }, {
  677. rule: 'optional',
  678. type: 'JsonObjectMessage',
  679. name: 'results',
  680. id: 100
  681. }, {
  682. rule: 'optional',
  683. type: 'JsonObjectMessage',
  684. name: 'where',
  685. id: 101
  686. }, {
  687. rule: 'optional',
  688. type: 'JsonObjectMessage',
  689. name: 'attr',
  690. id: 103
  691. }, {
  692. rule: 'optional',
  693. type: 'JsonObjectMessage',
  694. name: 'attrModified',
  695. id: 104
  696. }]
  697. }, {
  698. name: 'RoomCommand',
  699. syntax: 'proto2',
  700. fields: [{
  701. rule: 'optional',
  702. type: 'string',
  703. name: 'roomId',
  704. id: 1
  705. }, {
  706. rule: 'optional',
  707. type: 'string',
  708. name: 's',
  709. id: 2
  710. }, {
  711. rule: 'optional',
  712. type: 'int64',
  713. name: 't',
  714. id: 3
  715. }, {
  716. rule: 'optional',
  717. type: 'string',
  718. name: 'n',
  719. id: 4
  720. }, {
  721. rule: 'optional',
  722. type: 'bool',
  723. name: 'transient',
  724. id: 5
  725. }, {
  726. rule: 'repeated',
  727. type: 'string',
  728. name: 'roomPeerIds',
  729. id: 6
  730. }, {
  731. rule: 'optional',
  732. type: 'string',
  733. name: 'byPeerId',
  734. id: 7
  735. }]
  736. }, {
  737. name: 'LogsCommand',
  738. syntax: 'proto2',
  739. fields: [{
  740. rule: 'optional',
  741. type: 'string',
  742. name: 'cid',
  743. id: 1
  744. }, {
  745. rule: 'optional',
  746. type: 'int32',
  747. name: 'l',
  748. id: 2
  749. }, {
  750. rule: 'optional',
  751. type: 'int32',
  752. name: 'limit',
  753. id: 3
  754. }, {
  755. rule: 'optional',
  756. type: 'int64',
  757. name: 't',
  758. id: 4
  759. }, {
  760. rule: 'optional',
  761. type: 'int64',
  762. name: 'tt',
  763. id: 5
  764. }, {
  765. rule: 'optional',
  766. type: 'string',
  767. name: 'tmid',
  768. id: 6
  769. }, {
  770. rule: 'optional',
  771. type: 'string',
  772. name: 'mid',
  773. id: 7
  774. }, {
  775. rule: 'optional',
  776. type: 'string',
  777. name: 'checksum',
  778. id: 8
  779. }, {
  780. rule: 'optional',
  781. type: 'bool',
  782. name: 'stored',
  783. id: 9
  784. }, {
  785. rule: 'optional',
  786. type: 'QueryDirection',
  787. name: 'direction',
  788. id: 10,
  789. options: {
  790. "default": 'OLD'
  791. }
  792. }, {
  793. rule: 'optional',
  794. type: 'bool',
  795. name: 'tIncluded',
  796. id: 11
  797. }, {
  798. rule: 'optional',
  799. type: 'bool',
  800. name: 'ttIncluded',
  801. id: 12
  802. }, {
  803. rule: 'optional',
  804. type: 'int32',
  805. name: 'lctype',
  806. id: 13
  807. }, {
  808. rule: 'repeated',
  809. type: 'LogItem',
  810. name: 'logs',
  811. id: 105
  812. }],
  813. enums: [{
  814. name: 'QueryDirection',
  815. syntax: 'proto2',
  816. values: [{
  817. name: 'OLD',
  818. id: 1
  819. }, {
  820. name: 'NEW',
  821. id: 2
  822. }]
  823. }]
  824. }, {
  825. name: 'RcpCommand',
  826. syntax: 'proto2',
  827. fields: [{
  828. rule: 'optional',
  829. type: 'string',
  830. name: 'id',
  831. id: 1
  832. }, {
  833. rule: 'optional',
  834. type: 'string',
  835. name: 'cid',
  836. id: 2
  837. }, {
  838. rule: 'optional',
  839. type: 'int64',
  840. name: 't',
  841. id: 3
  842. }, {
  843. rule: 'optional',
  844. type: 'bool',
  845. name: 'read',
  846. id: 4
  847. }, {
  848. rule: 'optional',
  849. type: 'string',
  850. name: 'from',
  851. id: 5
  852. }]
  853. }, {
  854. name: 'ReadTuple',
  855. syntax: 'proto2',
  856. fields: [{
  857. rule: 'required',
  858. type: 'string',
  859. name: 'cid',
  860. id: 1
  861. }, {
  862. rule: 'optional',
  863. type: 'int64',
  864. name: 'timestamp',
  865. id: 2
  866. }, {
  867. rule: 'optional',
  868. type: 'string',
  869. name: 'mid',
  870. id: 3
  871. }]
  872. }, {
  873. name: 'MaxReadTuple',
  874. syntax: 'proto2',
  875. fields: [{
  876. rule: 'optional',
  877. type: 'string',
  878. name: 'pid',
  879. id: 1
  880. }, {
  881. rule: 'optional',
  882. type: 'int64',
  883. name: 'maxAckTimestamp',
  884. id: 2
  885. }, {
  886. rule: 'optional',
  887. type: 'int64',
  888. name: 'maxReadTimestamp',
  889. id: 3
  890. }]
  891. }, {
  892. name: 'ReadCommand',
  893. syntax: 'proto2',
  894. fields: [{
  895. rule: 'optional',
  896. type: 'string',
  897. name: 'cid',
  898. id: 1
  899. }, {
  900. rule: 'repeated',
  901. type: 'string',
  902. name: 'cids',
  903. id: 2
  904. }, {
  905. rule: 'repeated',
  906. type: 'ReadTuple',
  907. name: 'convs',
  908. id: 3
  909. }]
  910. }, {
  911. name: 'PresenceCommand',
  912. syntax: 'proto2',
  913. fields: [{
  914. rule: 'optional',
  915. type: 'StatusType',
  916. name: 'status',
  917. id: 1
  918. }, {
  919. rule: 'repeated',
  920. type: 'string',
  921. name: 'sessionPeerIds',
  922. id: 2
  923. }, {
  924. rule: 'optional',
  925. type: 'string',
  926. name: 'cid',
  927. id: 3
  928. }]
  929. }, {
  930. name: 'ReportCommand',
  931. syntax: 'proto2',
  932. fields: [{
  933. rule: 'optional',
  934. type: 'bool',
  935. name: 'initiative',
  936. id: 1
  937. }, {
  938. rule: 'optional',
  939. type: 'string',
  940. name: 'type',
  941. id: 2
  942. }, {
  943. rule: 'optional',
  944. type: 'string',
  945. name: 'data',
  946. id: 3
  947. }]
  948. }, {
  949. name: 'PatchItem',
  950. syntax: 'proto2',
  951. fields: [{
  952. rule: 'optional',
  953. type: 'string',
  954. name: 'cid',
  955. id: 1
  956. }, {
  957. rule: 'optional',
  958. type: 'string',
  959. name: 'mid',
  960. id: 2
  961. }, {
  962. rule: 'optional',
  963. type: 'int64',
  964. name: 'timestamp',
  965. id: 3
  966. }, {
  967. rule: 'optional',
  968. type: 'bool',
  969. name: 'recall',
  970. id: 4
  971. }, {
  972. rule: 'optional',
  973. type: 'string',
  974. name: 'data',
  975. id: 5
  976. }, {
  977. rule: 'optional',
  978. type: 'int64',
  979. name: 'patchTimestamp',
  980. id: 6
  981. }, {
  982. rule: 'optional',
  983. type: 'string',
  984. name: 'from',
  985. id: 7
  986. }, {
  987. rule: 'optional',
  988. type: 'bytes',
  989. name: 'binaryMsg',
  990. id: 8
  991. }, {
  992. rule: 'optional',
  993. type: 'bool',
  994. name: 'mentionAll',
  995. id: 9
  996. }, {
  997. rule: 'repeated',
  998. type: 'string',
  999. name: 'mentionPids',
  1000. id: 10
  1001. }, {
  1002. rule: 'optional',
  1003. type: 'int64',
  1004. name: 'patchCode',
  1005. id: 11
  1006. }, {
  1007. rule: 'optional',
  1008. type: 'string',
  1009. name: 'patchReason',
  1010. id: 12
  1011. }]
  1012. }, {
  1013. name: 'PatchCommand',
  1014. syntax: 'proto2',
  1015. fields: [{
  1016. rule: 'repeated',
  1017. type: 'PatchItem',
  1018. name: 'patches',
  1019. id: 1
  1020. }, {
  1021. rule: 'optional',
  1022. type: 'int64',
  1023. name: 'lastPatchTime',
  1024. id: 2
  1025. }]
  1026. }, {
  1027. name: 'PubsubCommand',
  1028. syntax: 'proto2',
  1029. fields: [{
  1030. rule: 'optional',
  1031. type: 'string',
  1032. name: 'cid',
  1033. id: 1
  1034. }, {
  1035. rule: 'repeated',
  1036. type: 'string',
  1037. name: 'cids',
  1038. id: 2
  1039. }, {
  1040. rule: 'optional',
  1041. type: 'string',
  1042. name: 'topic',
  1043. id: 3
  1044. }, {
  1045. rule: 'optional',
  1046. type: 'string',
  1047. name: 'subtopic',
  1048. id: 4
  1049. }, {
  1050. rule: 'repeated',
  1051. type: 'string',
  1052. name: 'topics',
  1053. id: 5
  1054. }, {
  1055. rule: 'repeated',
  1056. type: 'string',
  1057. name: 'subtopics',
  1058. id: 6
  1059. }, {
  1060. rule: 'optional',
  1061. type: 'JsonObjectMessage',
  1062. name: 'results',
  1063. id: 7
  1064. }]
  1065. }, {
  1066. name: 'BlacklistCommand',
  1067. syntax: 'proto2',
  1068. fields: [{
  1069. rule: 'optional',
  1070. type: 'string',
  1071. name: 'srcCid',
  1072. id: 1
  1073. }, {
  1074. rule: 'repeated',
  1075. type: 'string',
  1076. name: 'toPids',
  1077. id: 2
  1078. }, {
  1079. rule: 'optional',
  1080. type: 'string',
  1081. name: 'srcPid',
  1082. id: 3
  1083. }, {
  1084. rule: 'repeated',
  1085. type: 'string',
  1086. name: 'toCids',
  1087. id: 4
  1088. }, {
  1089. rule: 'optional',
  1090. type: 'int32',
  1091. name: 'limit',
  1092. id: 5
  1093. }, {
  1094. rule: 'optional',
  1095. type: 'string',
  1096. name: 'next',
  1097. id: 6
  1098. }, {
  1099. rule: 'repeated',
  1100. type: 'string',
  1101. name: 'blockedPids',
  1102. id: 8
  1103. }, {
  1104. rule: 'repeated',
  1105. type: 'string',
  1106. name: 'blockedCids',
  1107. id: 9
  1108. }, {
  1109. rule: 'repeated',
  1110. type: 'string',
  1111. name: 'allowedPids',
  1112. id: 10
  1113. }, {
  1114. rule: 'repeated',
  1115. type: 'ErrorCommand',
  1116. name: 'failedPids',
  1117. id: 11
  1118. }, {
  1119. rule: 'optional',
  1120. type: 'int64',
  1121. name: 't',
  1122. id: 12
  1123. }, {
  1124. rule: 'optional',
  1125. type: 'string',
  1126. name: 'n',
  1127. id: 13
  1128. }, {
  1129. rule: 'optional',
  1130. type: 'string',
  1131. name: 's',
  1132. id: 14
  1133. }]
  1134. }, {
  1135. name: 'GenericCommand',
  1136. syntax: 'proto2',
  1137. fields: [{
  1138. rule: 'optional',
  1139. type: 'CommandType',
  1140. name: 'cmd',
  1141. id: 1
  1142. }, {
  1143. rule: 'optional',
  1144. type: 'OpType',
  1145. name: 'op',
  1146. id: 2
  1147. }, {
  1148. rule: 'optional',
  1149. type: 'string',
  1150. name: 'appId',
  1151. id: 3
  1152. }, {
  1153. rule: 'optional',
  1154. type: 'string',
  1155. name: 'peerId',
  1156. id: 4
  1157. }, {
  1158. rule: 'optional',
  1159. type: 'int32',
  1160. name: 'i',
  1161. id: 5
  1162. }, {
  1163. rule: 'optional',
  1164. type: 'string',
  1165. name: 'installationId',
  1166. id: 6
  1167. }, {
  1168. rule: 'optional',
  1169. type: 'int32',
  1170. name: 'priority',
  1171. id: 7
  1172. }, {
  1173. rule: 'optional',
  1174. type: 'int32',
  1175. name: 'service',
  1176. id: 8
  1177. }, {
  1178. rule: 'optional',
  1179. type: 'int64',
  1180. name: 'serverTs',
  1181. id: 9
  1182. }, {
  1183. rule: 'optional',
  1184. type: 'int64',
  1185. name: 'clientTs',
  1186. id: 10
  1187. }, {
  1188. rule: 'optional',
  1189. type: 'int32',
  1190. name: 'notificationType',
  1191. id: 11
  1192. }, {
  1193. rule: 'optional',
  1194. type: 'DataCommand',
  1195. name: 'dataMessage',
  1196. id: 101
  1197. }, {
  1198. rule: 'optional',
  1199. type: 'SessionCommand',
  1200. name: 'sessionMessage',
  1201. id: 102
  1202. }, {
  1203. rule: 'optional',
  1204. type: 'ErrorCommand',
  1205. name: 'errorMessage',
  1206. id: 103
  1207. }, {
  1208. rule: 'optional',
  1209. type: 'DirectCommand',
  1210. name: 'directMessage',
  1211. id: 104
  1212. }, {
  1213. rule: 'optional',
  1214. type: 'AckCommand',
  1215. name: 'ackMessage',
  1216. id: 105
  1217. }, {
  1218. rule: 'optional',
  1219. type: 'UnreadCommand',
  1220. name: 'unreadMessage',
  1221. id: 106
  1222. }, {
  1223. rule: 'optional',
  1224. type: 'ReadCommand',
  1225. name: 'readMessage',
  1226. id: 107
  1227. }, {
  1228. rule: 'optional',
  1229. type: 'RcpCommand',
  1230. name: 'rcpMessage',
  1231. id: 108
  1232. }, {
  1233. rule: 'optional',
  1234. type: 'LogsCommand',
  1235. name: 'logsMessage',
  1236. id: 109
  1237. }, {
  1238. rule: 'optional',
  1239. type: 'ConvCommand',
  1240. name: 'convMessage',
  1241. id: 110
  1242. }, {
  1243. rule: 'optional',
  1244. type: 'RoomCommand',
  1245. name: 'roomMessage',
  1246. id: 111
  1247. }, {
  1248. rule: 'optional',
  1249. type: 'PresenceCommand',
  1250. name: 'presenceMessage',
  1251. id: 112
  1252. }, {
  1253. rule: 'optional',
  1254. type: 'ReportCommand',
  1255. name: 'reportMessage',
  1256. id: 113
  1257. }, {
  1258. rule: 'optional',
  1259. type: 'PatchCommand',
  1260. name: 'patchMessage',
  1261. id: 114
  1262. }, {
  1263. rule: 'optional',
  1264. type: 'PubsubCommand',
  1265. name: 'pubsubMessage',
  1266. id: 115
  1267. }, {
  1268. rule: 'optional',
  1269. type: 'BlacklistCommand',
  1270. name: 'blacklistMessage',
  1271. id: 116
  1272. }]
  1273. }],
  1274. enums: [{
  1275. name: 'CommandType',
  1276. syntax: 'proto2',
  1277. values: [{
  1278. name: 'session',
  1279. id: 0
  1280. }, {
  1281. name: 'conv',
  1282. id: 1
  1283. }, {
  1284. name: 'direct',
  1285. id: 2
  1286. }, {
  1287. name: 'ack',
  1288. id: 3
  1289. }, {
  1290. name: 'rcp',
  1291. id: 4
  1292. }, {
  1293. name: 'unread',
  1294. id: 5
  1295. }, {
  1296. name: 'logs',
  1297. id: 6
  1298. }, {
  1299. name: 'error',
  1300. id: 7
  1301. }, {
  1302. name: 'login',
  1303. id: 8
  1304. }, {
  1305. name: 'data',
  1306. id: 9
  1307. }, {
  1308. name: 'room',
  1309. id: 10
  1310. }, {
  1311. name: 'read',
  1312. id: 11
  1313. }, {
  1314. name: 'presence',
  1315. id: 12
  1316. }, {
  1317. name: 'report',
  1318. id: 13
  1319. }, {
  1320. name: 'echo',
  1321. id: 14
  1322. }, {
  1323. name: 'loggedin',
  1324. id: 15
  1325. }, {
  1326. name: 'logout',
  1327. id: 16
  1328. }, {
  1329. name: 'loggedout',
  1330. id: 17
  1331. }, {
  1332. name: 'patch',
  1333. id: 18
  1334. }, {
  1335. name: 'pubsub',
  1336. id: 19
  1337. }, {
  1338. name: 'blacklist',
  1339. id: 20
  1340. }, {
  1341. name: 'goaway',
  1342. id: 21
  1343. }]
  1344. }, {
  1345. name: 'OpType',
  1346. syntax: 'proto2',
  1347. values: [{
  1348. name: 'open',
  1349. id: 1
  1350. }, {
  1351. name: 'add',
  1352. id: 2
  1353. }, {
  1354. name: 'remove',
  1355. id: 3
  1356. }, {
  1357. name: 'close',
  1358. id: 4
  1359. }, {
  1360. name: 'opened',
  1361. id: 5
  1362. }, {
  1363. name: 'closed',
  1364. id: 6
  1365. }, {
  1366. name: 'query',
  1367. id: 7
  1368. }, {
  1369. name: 'query_result',
  1370. id: 8
  1371. }, {
  1372. name: 'conflict',
  1373. id: 9
  1374. }, {
  1375. name: 'added',
  1376. id: 10
  1377. }, {
  1378. name: 'removed',
  1379. id: 11
  1380. }, {
  1381. name: 'refresh',
  1382. id: 12
  1383. }, {
  1384. name: 'refreshed',
  1385. id: 13
  1386. }, {
  1387. name: 'start',
  1388. id: 30
  1389. }, {
  1390. name: 'started',
  1391. id: 31
  1392. }, {
  1393. name: 'joined',
  1394. id: 32
  1395. }, {
  1396. name: 'members_joined',
  1397. id: 33
  1398. }, {
  1399. name: 'left',
  1400. id: 39
  1401. }, {
  1402. name: 'members_left',
  1403. id: 40
  1404. }, {
  1405. name: 'results',
  1406. id: 42
  1407. }, {
  1408. name: 'count',
  1409. id: 43
  1410. }, {
  1411. name: 'result',
  1412. id: 44
  1413. }, {
  1414. name: 'update',
  1415. id: 45
  1416. }, {
  1417. name: 'updated',
  1418. id: 46
  1419. }, {
  1420. name: 'mute',
  1421. id: 47
  1422. }, {
  1423. name: 'unmute',
  1424. id: 48
  1425. }, {
  1426. name: 'status',
  1427. id: 49
  1428. }, {
  1429. name: 'members',
  1430. id: 50
  1431. }, {
  1432. name: 'max_read',
  1433. id: 51
  1434. }, {
  1435. name: 'is_member',
  1436. id: 52
  1437. }, {
  1438. name: 'member_info_update',
  1439. id: 53
  1440. }, {
  1441. name: 'member_info_updated',
  1442. id: 54
  1443. }, {
  1444. name: 'member_info_changed',
  1445. id: 55
  1446. }, {
  1447. name: 'join',
  1448. id: 80
  1449. }, {
  1450. name: 'invite',
  1451. id: 81
  1452. }, {
  1453. name: 'leave',
  1454. id: 82
  1455. }, {
  1456. name: 'kick',
  1457. id: 83
  1458. }, {
  1459. name: 'reject',
  1460. id: 84
  1461. }, {
  1462. name: 'invited',
  1463. id: 85
  1464. }, {
  1465. name: 'kicked',
  1466. id: 86
  1467. }, {
  1468. name: 'upload',
  1469. id: 100
  1470. }, {
  1471. name: 'uploaded',
  1472. id: 101
  1473. }, {
  1474. name: 'subscribe',
  1475. id: 120
  1476. }, {
  1477. name: 'subscribed',
  1478. id: 121
  1479. }, {
  1480. name: 'unsubscribe',
  1481. id: 122
  1482. }, {
  1483. name: 'unsubscribed',
  1484. id: 123
  1485. }, {
  1486. name: 'is_subscribed',
  1487. id: 124
  1488. }, {
  1489. name: 'modify',
  1490. id: 150
  1491. }, {
  1492. name: 'modified',
  1493. id: 151
  1494. }, {
  1495. name: 'block',
  1496. id: 170
  1497. }, {
  1498. name: 'unblock',
  1499. id: 171
  1500. }, {
  1501. name: 'blocked',
  1502. id: 172
  1503. }, {
  1504. name: 'unblocked',
  1505. id: 173
  1506. }, {
  1507. name: 'members_blocked',
  1508. id: 174
  1509. }, {
  1510. name: 'members_unblocked',
  1511. id: 175
  1512. }, {
  1513. name: 'check_block',
  1514. id: 176
  1515. }, {
  1516. name: 'check_result',
  1517. id: 177
  1518. }, {
  1519. name: 'add_shutup',
  1520. id: 180
  1521. }, {
  1522. name: 'remove_shutup',
  1523. id: 181
  1524. }, {
  1525. name: 'query_shutup',
  1526. id: 182
  1527. }, {
  1528. name: 'shutup_added',
  1529. id: 183
  1530. }, {
  1531. name: 'shutup_removed',
  1532. id: 184
  1533. }, {
  1534. name: 'shutup_result',
  1535. id: 185
  1536. }, {
  1537. name: 'shutuped',
  1538. id: 186
  1539. }, {
  1540. name: 'unshutuped',
  1541. id: 187
  1542. }, {
  1543. name: 'members_shutuped',
  1544. id: 188
  1545. }, {
  1546. name: 'members_unshutuped',
  1547. id: 189
  1548. }, {
  1549. name: 'check_shutup',
  1550. id: 190
  1551. }]
  1552. }, {
  1553. name: 'StatusType',
  1554. syntax: 'proto2',
  1555. values: [{
  1556. name: 'on',
  1557. id: 1
  1558. }, {
  1559. name: 'off',
  1560. id: 2
  1561. }]
  1562. }],
  1563. isNamespace: true
  1564. }).build();
  1565. var _messages$push_server = messageCompiled.push_server.messages2,
  1566. JsonObjectMessage = _messages$push_server.JsonObjectMessage,
  1567. UnreadTuple = _messages$push_server.UnreadTuple,
  1568. LogItem = _messages$push_server.LogItem,
  1569. DataCommand = _messages$push_server.DataCommand,
  1570. SessionCommand = _messages$push_server.SessionCommand,
  1571. ErrorCommand = _messages$push_server.ErrorCommand,
  1572. DirectCommand = _messages$push_server.DirectCommand,
  1573. AckCommand = _messages$push_server.AckCommand,
  1574. UnreadCommand = _messages$push_server.UnreadCommand,
  1575. ConvCommand = _messages$push_server.ConvCommand,
  1576. RoomCommand = _messages$push_server.RoomCommand,
  1577. LogsCommand = _messages$push_server.LogsCommand,
  1578. RcpCommand = _messages$push_server.RcpCommand,
  1579. ReadTuple = _messages$push_server.ReadTuple,
  1580. MaxReadTuple = _messages$push_server.MaxReadTuple,
  1581. ReadCommand = _messages$push_server.ReadCommand,
  1582. PresenceCommand = _messages$push_server.PresenceCommand,
  1583. ReportCommand = _messages$push_server.ReportCommand,
  1584. GenericCommand = _messages$push_server.GenericCommand,
  1585. BlacklistCommand = _messages$push_server.BlacklistCommand,
  1586. PatchCommand = _messages$push_server.PatchCommand,
  1587. PatchItem = _messages$push_server.PatchItem,
  1588. ConvMemberInfo = _messages$push_server.ConvMemberInfo,
  1589. CommandType = _messages$push_server.CommandType,
  1590. OpType = _messages$push_server.OpType,
  1591. StatusType = _messages$push_server.StatusType;
  1592. var message = /*#__PURE__*/Object.freeze({
  1593. __proto__: null,
  1594. JsonObjectMessage: JsonObjectMessage,
  1595. UnreadTuple: UnreadTuple,
  1596. LogItem: LogItem,
  1597. DataCommand: DataCommand,
  1598. SessionCommand: SessionCommand,
  1599. ErrorCommand: ErrorCommand,
  1600. DirectCommand: DirectCommand,
  1601. AckCommand: AckCommand,
  1602. UnreadCommand: UnreadCommand,
  1603. ConvCommand: ConvCommand,
  1604. RoomCommand: RoomCommand,
  1605. LogsCommand: LogsCommand,
  1606. RcpCommand: RcpCommand,
  1607. ReadTuple: ReadTuple,
  1608. MaxReadTuple: MaxReadTuple,
  1609. ReadCommand: ReadCommand,
  1610. PresenceCommand: PresenceCommand,
  1611. ReportCommand: ReportCommand,
  1612. GenericCommand: GenericCommand,
  1613. BlacklistCommand: BlacklistCommand,
  1614. PatchCommand: PatchCommand,
  1615. PatchItem: PatchItem,
  1616. ConvMemberInfo: ConvMemberInfo,
  1617. CommandType: CommandType,
  1618. OpType: OpType,
  1619. StatusType: StatusType
  1620. });
  1621. var adapters = {};
  1622. var getAdapter = function getAdapter(name) {
  1623. var adapter = adapters[name];
  1624. if (adapter === undefined) {
  1625. throw new Error("".concat(name, " adapter is not configured"));
  1626. }
  1627. return adapter;
  1628. };
  1629. /**
  1630. * 指定 Adapters
  1631. * @function
  1632. * @memberof module:leancloud-realtime
  1633. * @param {Adapters} newAdapters Adapters 的类型请参考 {@link https://url.leanapp.cn/adapter-type-definitions @leancloud/adapter-types} 中的定义
  1634. */
  1635. var setAdapters = function setAdapters(newAdapters) {
  1636. Object.assign(adapters, newAdapters);
  1637. };
  1638. /* eslint-disable */
  1639. var global$1 = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : {};
  1640. var EXPIRED = Symbol('expired');
  1641. var debug = d('LC:Expirable');
  1642. var Expirable = /*#__PURE__*/function () {
  1643. function Expirable(value, ttl) {
  1644. this.originalValue = value;
  1645. if (typeof ttl === 'number') {
  1646. this.expiredAt = Date.now() + ttl;
  1647. }
  1648. }
  1649. _createClass(Expirable, [{
  1650. key: "value",
  1651. get: function get() {
  1652. var expired = this.expiredAt && this.expiredAt <= Date.now();
  1653. if (expired) debug("expired: ".concat(this.originalValue));
  1654. return expired ? EXPIRED : this.originalValue;
  1655. }
  1656. }]);
  1657. return Expirable;
  1658. }();
  1659. Expirable.EXPIRED = EXPIRED;
  1660. var debug$1 = d('LC:Cache');
  1661. var Cache = /*#__PURE__*/function () {
  1662. function Cache() {
  1663. var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'anonymous';
  1664. this.name = name;
  1665. this._map = {};
  1666. }
  1667. var _proto = Cache.prototype;
  1668. _proto.get = function get(key) {
  1669. var cache = this._map[key];
  1670. if (cache) {
  1671. var value = cache.value;
  1672. if (value !== Expirable.EXPIRED) {
  1673. debug$1('[%s] hit: %s', this.name, key);
  1674. return value;
  1675. }
  1676. delete this._map[key];
  1677. }
  1678. debug$1("[".concat(this.name, "] missed: ").concat(key));
  1679. return null;
  1680. };
  1681. _proto.set = function set(key, value, ttl) {
  1682. debug$1('[%s] set: %s %d', this.name, key, ttl);
  1683. this._map[key] = new Expirable(value, ttl);
  1684. };
  1685. return Cache;
  1686. }();
  1687. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  1688. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  1689. /**
  1690. * 调试日志控制器
  1691. * @const
  1692. * @memberof module:leancloud-realtime
  1693. * @example
  1694. * debug.enable(); // 启用调试日志
  1695. * debug.disable(); // 关闭调试日志
  1696. */
  1697. var debug$2 = {
  1698. enable: function enable() {
  1699. var namespaces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'LC*';
  1700. return d.enable(namespaces);
  1701. },
  1702. disable: d.disable
  1703. };
  1704. var tryAll = function tryAll(promiseConstructors) {
  1705. var promise = new Promise(promiseConstructors[0]);
  1706. if (promiseConstructors.length === 1) {
  1707. return promise;
  1708. }
  1709. return promise["catch"](function () {
  1710. return tryAll(promiseConstructors.slice(1));
  1711. });
  1712. }; // eslint-disable-next-line no-sequences
  1713. var tap = function tap(interceptor) {
  1714. return function (value) {
  1715. return interceptor(value), value;
  1716. };
  1717. };
  1718. var finalize = function finalize(callback) {
  1719. return [// eslint-disable-next-line no-sequences
  1720. function (value) {
  1721. return callback(), value;
  1722. }, function (error) {
  1723. callback();
  1724. throw error;
  1725. }];
  1726. };
  1727. /**
  1728. * 将对象转换为 Date,支持 string、number、ProtoBuf Long 以及 LeanCloud 的 Date 类型,
  1729. * 其他情况下(包括对象为 falsy)返回原值。
  1730. * @private
  1731. */
  1732. var decodeDate = function decodeDate(date) {
  1733. if (!date) return date;
  1734. if (typeof date === 'string' || typeof date === 'number') {
  1735. return new Date(date);
  1736. }
  1737. if (date.__type === 'Date' && date.iso) {
  1738. return new Date(date.iso);
  1739. } // Long
  1740. if (typeof date.toNumber === 'function') {
  1741. return new Date(date.toNumber());
  1742. }
  1743. return date;
  1744. };
  1745. /**
  1746. * 获取 Date 的毫秒数,如果不是一个 Date 返回 undefined。
  1747. * @private
  1748. */
  1749. var getTime = function getTime(date) {
  1750. return date && date.getTime ? date.getTime() : undefined;
  1751. };
  1752. /**
  1753. * 解码对象中的 LeanCloud 数据结构。
  1754. * 目前仅会处理 Date 类型。
  1755. * @private
  1756. */
  1757. var decode = function decode(value) {
  1758. if (!value) return value;
  1759. if (value.__type === 'Date' && value.iso) {
  1760. return new Date(value.iso);
  1761. }
  1762. if (Array.isArray(value)) {
  1763. return value.map(decode);
  1764. }
  1765. if (isPlainObject(value)) {
  1766. return Object.keys(value).reduce(function (result, key) {
  1767. return _objectSpread(_objectSpread({}, result), {}, _defineProperty({}, key, decode(value[key])));
  1768. }, {});
  1769. }
  1770. return value;
  1771. };
  1772. /**
  1773. * 将对象中的特殊类型编码为 LeanCloud 数据结构。
  1774. * 目前仅会处理 Date 类型。
  1775. * @private
  1776. */
  1777. var encode = function encode(value) {
  1778. if (value instanceof Date) return {
  1779. __type: 'Date',
  1780. iso: value.toJSON()
  1781. };
  1782. if (Array.isArray(value)) {
  1783. return value.map(encode);
  1784. }
  1785. if (isPlainObject(value)) {
  1786. return Object.keys(value).reduce(function (result, key) {
  1787. return _objectSpread(_objectSpread({}, result), {}, _defineProperty({}, key, encode(value[key])));
  1788. }, {});
  1789. }
  1790. return value;
  1791. };
  1792. var keyRemap = function keyRemap(keymap, obj) {
  1793. return Object.keys(obj).reduce(function (newObj, key) {
  1794. var newKey = keymap[key] || key;
  1795. return Object.assign(newObj, _defineProperty({}, newKey, obj[key]));
  1796. }, {});
  1797. };
  1798. var isIE10 = global$1.navigator && global$1.navigator.userAgent && global$1.navigator.userAgent.indexOf('MSIE 10.') !== -1;
  1799. /* eslint-disable no-proto */
  1800. var getStaticProperty = function getStaticProperty(klass, property) {
  1801. return klass[property] || (klass.__proto__ ? getStaticProperty(klass.__proto__, property) : undefined);
  1802. };
  1803. /* eslint-enable no-proto */
  1804. var union = function union(a, b) {
  1805. return Array.from(new Set([].concat(_toConsumableArray(a), _toConsumableArray(b))));
  1806. };
  1807. var difference = function difference(a, b) {
  1808. return Array.from(function (bSet) {
  1809. return new Set(a.filter(function (x) {
  1810. return !bSet.has(x);
  1811. }));
  1812. }(new Set(b)));
  1813. };
  1814. var map = new WeakMap(); // protected property helper
  1815. var internal = function internal(object) {
  1816. if (!map.has(object)) {
  1817. map.set(object, {});
  1818. }
  1819. return map.get(object);
  1820. };
  1821. var compact = function compact(obj, filter) {
  1822. if (!isPlainObject(obj)) return obj;
  1823. var object = _objectSpread({}, obj);
  1824. Object.keys(object).forEach(function (prop) {
  1825. var value = object[prop];
  1826. if (value === filter) {
  1827. delete object[prop];
  1828. } else {
  1829. object[prop] = compact(value, filter);
  1830. }
  1831. });
  1832. return object;
  1833. }; // debug utility
  1834. var removeNull = function removeNull(obj) {
  1835. return compact(obj, null);
  1836. };
  1837. var trim = function trim(message) {
  1838. return removeNull(JSON.parse(JSON.stringify(message)));
  1839. };
  1840. var ensureArray = function ensureArray(target) {
  1841. if (Array.isArray(target)) {
  1842. return target;
  1843. }
  1844. if (target === undefined || target === null) {
  1845. return [];
  1846. }
  1847. return [target];
  1848. };
  1849. var setValue = function setValue(target, key, value) {
  1850. // '.' is not allowed in Class keys, escaping is not in concern now.
  1851. var segs = key.split('.');
  1852. var lastSeg = segs.pop();
  1853. var currentTarget = target;
  1854. segs.forEach(function (seg) {
  1855. if (currentTarget[seg] === undefined) currentTarget[seg] = {};
  1856. currentTarget = currentTarget[seg];
  1857. });
  1858. currentTarget[lastSeg] = value;
  1859. return target;
  1860. };
  1861. var isWeapp = // eslint-disable-next-line no-undef
  1862. (typeof wx === "undefined" ? "undefined" : _typeof(wx)) === 'object' && typeof wx.connectSocket === 'function'; // throttle decorator
  1863. var throttle = function throttle(wait) {
  1864. return function (target, property, descriptor) {
  1865. var callback = descriptor.value; // very naive, internal use only
  1866. if (callback.length) {
  1867. throw new Error('throttled function should not accept any arguments');
  1868. }
  1869. return _objectSpread(_objectSpread({}, descriptor), {}, {
  1870. value: function value() {
  1871. var _this = this;
  1872. var _internal = internal(this),
  1873. throttleMeta = _internal.throttleMeta;
  1874. if (!throttleMeta) {
  1875. throttleMeta = {};
  1876. internal(this).throttleMeta = throttleMeta;
  1877. }
  1878. var _throttleMeta = throttleMeta,
  1879. propertyMeta = _throttleMeta[property];
  1880. if (!propertyMeta) {
  1881. propertyMeta = {};
  1882. throttleMeta[property] = propertyMeta;
  1883. }
  1884. var _propertyMeta = propertyMeta,
  1885. _propertyMeta$previou = _propertyMeta.previouseTimestamp,
  1886. previouseTimestamp = _propertyMeta$previou === void 0 ? 0 : _propertyMeta$previou,
  1887. timeout = _propertyMeta.timeout;
  1888. var now = Date.now();
  1889. var remainingTime = wait - (now - previouseTimestamp);
  1890. if (remainingTime <= 0) {
  1891. throttleMeta[property].previouseTimestamp = now;
  1892. callback.apply(this);
  1893. } else if (!timeout) {
  1894. propertyMeta.timeout = setTimeout(function () {
  1895. propertyMeta.previouseTimestamp = Date.now();
  1896. delete propertyMeta.timeout;
  1897. callback.apply(_this);
  1898. }, remainingTime);
  1899. }
  1900. }
  1901. });
  1902. };
  1903. };
  1904. var isCNApp = function isCNApp(appId) {
  1905. return appId.slice(-9) !== '-MdYXbMMI';
  1906. };
  1907. var equalBuffer = function equalBuffer(buffer1, buffer2) {
  1908. if (!buffer1 || !buffer2) return false;
  1909. if (buffer1.byteLength !== buffer2.byteLength) return false;
  1910. var a = new Uint8Array(buffer1);
  1911. var b = new Uint8Array(buffer2);
  1912. return !a.some(function (value, index) {
  1913. return value !== b[index];
  1914. });
  1915. };
  1916. var _class;
  1917. function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  1918. function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  1919. var debug$3 = d('LC:WebSocketPlus');
  1920. var OPEN = 'open';
  1921. var DISCONNECT = 'disconnect';
  1922. var RECONNECT = 'reconnect';
  1923. var RETRY = 'retry';
  1924. var SCHEDULE = 'schedule';
  1925. var OFFLINE = 'offline';
  1926. var ONLINE = 'online';
  1927. var ERROR = 'error';
  1928. var MESSAGE = 'message';
  1929. var HEARTBEAT_TIME = 180000;
  1930. var TIMEOUT_TIME = 380000;
  1931. var DEFAULT_RETRY_STRATEGY = function DEFAULT_RETRY_STRATEGY(attempt) {
  1932. return Math.min(1000 * Math.pow(2, attempt), 300000);
  1933. };
  1934. var requireConnected = function requireConnected(target, name, descriptor) {
  1935. return _objectSpread$1(_objectSpread$1({}, descriptor), {}, {
  1936. value: function requireConnectedWrapper() {
  1937. var _descriptor$value;
  1938. this.checkConnectionAvailability(name);
  1939. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  1940. args[_key] = arguments[_key];
  1941. }
  1942. return (_descriptor$value = descriptor.value).call.apply(_descriptor$value, [this].concat(args));
  1943. }
  1944. });
  1945. };
  1946. var WebSocketPlus = (_class = /*#__PURE__*/function (_EventEmitter) {
  1947. _inheritsLoose(WebSocketPlus, _EventEmitter);
  1948. _createClass(WebSocketPlus, [{
  1949. key: "urls",
  1950. get: function get() {
  1951. return this._urls;
  1952. },
  1953. set: function set(urls) {
  1954. this._urls = ensureArray(urls);
  1955. }
  1956. }]);
  1957. function WebSocketPlus(getUrls, protocol) {
  1958. var _this;
  1959. _this = _EventEmitter.call(this) || this;
  1960. _this.init();
  1961. _this._protocol = protocol;
  1962. Promise.resolve(typeof getUrls === 'function' ? getUrls() : getUrls).then(ensureArray).then(function (urls) {
  1963. _this._urls = urls;
  1964. return _this._open();
  1965. }).then(function () {
  1966. _this.__postponeTimeoutTimer = _this._postponeTimeoutTimer.bind(_assertThisInitialized(_this));
  1967. if (global$1.addEventListener) {
  1968. _this.__pause = function () {
  1969. if (_this.can('pause')) _this.pause();
  1970. };
  1971. _this.__resume = function () {
  1972. if (_this.can('resume')) _this.resume();
  1973. };
  1974. global$1.addEventListener('offline', _this.__pause);
  1975. global$1.addEventListener('online', _this.__resume);
  1976. }
  1977. _this.open();
  1978. })["catch"](_this["throw"].bind(_assertThisInitialized(_this)));
  1979. return _this;
  1980. }
  1981. var _proto = WebSocketPlus.prototype;
  1982. _proto._open = function _open() {
  1983. var _this2 = this;
  1984. return this._createWs(this._urls, this._protocol).then(function (ws) {
  1985. var _this2$_urls = _toArray(_this2._urls),
  1986. first = _this2$_urls[0],
  1987. reset = _this2$_urls.slice(1);
  1988. _this2._urls = [].concat(_toConsumableArray(reset), [first]);
  1989. return ws;
  1990. });
  1991. };
  1992. _proto._createWs = function _createWs(urls, protocol) {
  1993. var _this3 = this;
  1994. return tryAll(urls.map(function (url) {
  1995. return function (resolve, reject) {
  1996. debug$3("connect [".concat(url, "] ").concat(protocol));
  1997. var WebSocket = getAdapter('WebSocket');
  1998. var ws = protocol ? new WebSocket(url, protocol) : new WebSocket(url);
  1999. ws.binaryType = _this3.binaryType || 'arraybuffer';
  2000. ws.onopen = function () {
  2001. return resolve(ws);
  2002. };
  2003. ws.onclose = function (error) {
  2004. if (error instanceof Error) {
  2005. return reject(error);
  2006. } // in browser, error event is useless
  2007. return reject(new Error("Failed to connect [".concat(url, "]")));
  2008. };
  2009. ws.onerror = ws.onclose;
  2010. };
  2011. })).then(function (ws) {
  2012. _this3._ws = ws;
  2013. _this3._ws.onclose = _this3._handleClose.bind(_this3);
  2014. _this3._ws.onmessage = _this3._handleMessage.bind(_this3);
  2015. return ws;
  2016. });
  2017. };
  2018. _proto._destroyWs = function _destroyWs() {
  2019. var ws = this._ws;
  2020. if (!ws) return;
  2021. ws.onopen = null;
  2022. ws.onclose = null;
  2023. ws.onerror = null;
  2024. ws.onmessage = null;
  2025. this._ws = null;
  2026. ws.close();
  2027. } // eslint-disable-next-line class-methods-use-this
  2028. ;
  2029. _proto.onbeforeevent = function onbeforeevent(event, from, to) {
  2030. for (var _len2 = arguments.length, payload = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
  2031. payload[_key2 - 3] = arguments[_key2];
  2032. }
  2033. debug$3("".concat(event, ": ").concat(from, " -> ").concat(to, " %o"), payload);
  2034. };
  2035. _proto.onopen = function onopen() {
  2036. this.emit(OPEN);
  2037. };
  2038. _proto.onconnected = function onconnected() {
  2039. this._startConnectionKeeper();
  2040. };
  2041. _proto.onleaveconnected = function onleaveconnected(event, from, to) {
  2042. this._stopConnectionKeeper();
  2043. this._destroyWs();
  2044. if (to === 'offline' || to === 'disconnected') {
  2045. this.emit(DISCONNECT);
  2046. }
  2047. };
  2048. _proto.onpause = function onpause() {
  2049. this.emit(OFFLINE);
  2050. };
  2051. _proto.onbeforeresume = function onbeforeresume() {
  2052. this.emit(ONLINE);
  2053. };
  2054. _proto.onreconnect = function onreconnect() {
  2055. this.emit(RECONNECT);
  2056. };
  2057. _proto.ondisconnected = function ondisconnected(event, from, to) {
  2058. var _this4 = this;
  2059. var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  2060. var delay = from === OFFLINE ? 0 : DEFAULT_RETRY_STRATEGY.call(null, attempt);
  2061. debug$3("schedule attempt=".concat(attempt, " delay=").concat(delay));
  2062. this.emit(SCHEDULE, attempt, delay);
  2063. if (this.__scheduledRetry) {
  2064. clearTimeout(this.__scheduledRetry);
  2065. }
  2066. this.__scheduledRetry = setTimeout(function () {
  2067. if (_this4.is('disconnected')) {
  2068. _this4.retry(attempt);
  2069. }
  2070. }, delay);
  2071. };
  2072. _proto.onretry = function onretry(event, from, to) {
  2073. var _this5 = this;
  2074. var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  2075. this.emit(RETRY, attempt);
  2076. this._open().then(function () {
  2077. return _this5.can('reconnect') && _this5.reconnect();
  2078. }, function () {
  2079. return _this5.can('fail') && _this5.fail(attempt + 1);
  2080. });
  2081. };
  2082. _proto.onerror = function onerror(event, from, to, error) {
  2083. this.emit(ERROR, error);
  2084. };
  2085. _proto.onclose = function onclose() {
  2086. if (global$1.removeEventListener) {
  2087. if (this.__pause) global$1.removeEventListener('offline', this.__pause);
  2088. if (this.__resume) global$1.removeEventListener('online', this.__resume);
  2089. }
  2090. };
  2091. _proto.checkConnectionAvailability = function checkConnectionAvailability() {
  2092. var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'API';
  2093. if (!this.is('connected')) {
  2094. var currentState = this.current;
  2095. console.warn("".concat(name, " should not be called when the connection is ").concat(currentState));
  2096. if (this.is('disconnected') || this.is('reconnecting')) {
  2097. console.warn('disconnect and reconnect event should be handled to avoid such calls.');
  2098. }
  2099. throw new Error('Connection unavailable');
  2100. }
  2101. } // jsdoc-ignore-start
  2102. ;
  2103. _proto. // jsdoc-ignore-end
  2104. _ping = function _ping() {
  2105. debug$3('ping');
  2106. try {
  2107. this.ping();
  2108. } catch (error) {
  2109. console.warn("websocket ping error: ".concat(error.message));
  2110. }
  2111. };
  2112. _proto.ping = function ping() {
  2113. if (this._ws.ping) {
  2114. this._ws.ping();
  2115. } else {
  2116. console.warn("The WebSocket implement does not support sending ping frame.\n Override ping method to use application defined ping/pong mechanism.");
  2117. }
  2118. };
  2119. _proto._postponeTimeoutTimer = function _postponeTimeoutTimer() {
  2120. var _this6 = this;
  2121. debug$3('_postponeTimeoutTimer');
  2122. this._clearTimeoutTimers();
  2123. this._timeoutTimer = setTimeout(function () {
  2124. debug$3('timeout');
  2125. _this6.disconnect();
  2126. }, TIMEOUT_TIME);
  2127. };
  2128. _proto._clearTimeoutTimers = function _clearTimeoutTimers() {
  2129. if (this._timeoutTimer) {
  2130. clearTimeout(this._timeoutTimer);
  2131. }
  2132. };
  2133. _proto._startConnectionKeeper = function _startConnectionKeeper() {
  2134. debug$3('start connection keeper');
  2135. this._heartbeatTimer = setInterval(this._ping.bind(this), HEARTBEAT_TIME);
  2136. var addListener = this._ws.addListener || this._ws.addEventListener;
  2137. if (!addListener) {
  2138. debug$3('connection keeper disabled due to the lack of #addEventListener.');
  2139. return;
  2140. }
  2141. addListener.call(this._ws, 'message', this.__postponeTimeoutTimer);
  2142. addListener.call(this._ws, 'pong', this.__postponeTimeoutTimer);
  2143. this._postponeTimeoutTimer();
  2144. };
  2145. _proto._stopConnectionKeeper = function _stopConnectionKeeper() {
  2146. debug$3('stop connection keeper'); // websockets/ws#489
  2147. var removeListener = this._ws.removeListener || this._ws.removeEventListener;
  2148. if (removeListener) {
  2149. removeListener.call(this._ws, 'message', this.__postponeTimeoutTimer);
  2150. removeListener.call(this._ws, 'pong', this.__postponeTimeoutTimer);
  2151. this._clearTimeoutTimers();
  2152. }
  2153. if (this._heartbeatTimer) {
  2154. clearInterval(this._heartbeatTimer);
  2155. }
  2156. };
  2157. _proto._handleClose = function _handleClose(event) {
  2158. debug$3("ws closed [".concat(event.code, "] ").concat(event.reason)); // socket closed manually, ignore close event.
  2159. if (this.isFinished()) return;
  2160. this.handleClose(event);
  2161. };
  2162. _proto.handleClose = function handleClose() {
  2163. // reconnect
  2164. this.disconnect();
  2165. } // jsdoc-ignore-start
  2166. ;
  2167. _proto. // jsdoc-ignore-end
  2168. send = function send(data) {
  2169. debug$3('send', data);
  2170. this._ws.send(data);
  2171. };
  2172. _proto._handleMessage = function _handleMessage(event) {
  2173. debug$3('message', event.data);
  2174. this.handleMessage(event.data);
  2175. };
  2176. _proto.handleMessage = function handleMessage(message) {
  2177. this.emit(MESSAGE, message);
  2178. };
  2179. return WebSocketPlus;
  2180. }(EventEmitter), (_applyDecoratedDescriptor(_class.prototype, "_ping", [requireConnected], Object.getOwnPropertyDescriptor(_class.prototype, "_ping"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "send", [requireConnected], Object.getOwnPropertyDescriptor(_class.prototype, "send"), _class.prototype)), _class);
  2181. StateMachine.create({
  2182. target: WebSocketPlus.prototype,
  2183. initial: {
  2184. state: 'initialized',
  2185. event: 'init',
  2186. defer: true
  2187. },
  2188. terminal: 'closed',
  2189. events: [{
  2190. name: 'open',
  2191. from: 'initialized',
  2192. to: 'connected'
  2193. }, {
  2194. name: 'disconnect',
  2195. from: 'connected',
  2196. to: 'disconnected'
  2197. }, {
  2198. name: 'retry',
  2199. from: 'disconnected',
  2200. to: 'reconnecting'
  2201. }, {
  2202. name: 'fail',
  2203. from: 'reconnecting',
  2204. to: 'disconnected'
  2205. }, {
  2206. name: 'reconnect',
  2207. from: 'reconnecting',
  2208. to: 'connected'
  2209. }, {
  2210. name: 'pause',
  2211. from: ['connected', 'disconnected', 'reconnecting'],
  2212. to: 'offline'
  2213. }, {}, {
  2214. name: 'resume',
  2215. from: 'offline',
  2216. to: 'disconnected'
  2217. }, {
  2218. name: 'close',
  2219. from: ['connected', 'disconnected', 'reconnecting', 'offline'],
  2220. to: 'closed'
  2221. }, {
  2222. name: 'throw',
  2223. from: '*',
  2224. to: 'error'
  2225. }]
  2226. });
  2227. var error = Object.freeze({
  2228. 1000: {
  2229. name: 'CLOSE_NORMAL'
  2230. },
  2231. 1006: {
  2232. name: 'CLOSE_ABNORMAL'
  2233. },
  2234. 4100: {
  2235. name: 'APP_NOT_AVAILABLE',
  2236. message: 'App not exists or realtime message service is disabled.'
  2237. },
  2238. 4102: {
  2239. name: 'SIGNATURE_FAILED',
  2240. message: 'Login signature mismatch.'
  2241. },
  2242. 4103: {
  2243. name: 'INVALID_LOGIN',
  2244. message: 'Malformed clientId.'
  2245. },
  2246. 4105: {
  2247. name: 'SESSION_REQUIRED',
  2248. message: 'Message sent before session opened.'
  2249. },
  2250. 4107: {
  2251. name: 'READ_TIMEOUT'
  2252. },
  2253. 4108: {
  2254. name: 'LOGIN_TIMEOUT'
  2255. },
  2256. 4109: {
  2257. name: 'FRAME_TOO_LONG'
  2258. },
  2259. 4110: {
  2260. name: 'INVALID_ORIGIN',
  2261. message: 'Access denied by domain whitelist.'
  2262. },
  2263. 4111: {
  2264. name: 'SESSION_CONFLICT'
  2265. },
  2266. 4112: {
  2267. name: 'SESSION_TOKEN_EXPIRED'
  2268. },
  2269. 4113: {
  2270. name: 'APP_QUOTA_EXCEEDED',
  2271. message: 'The daily active users limit exceeded.'
  2272. },
  2273. 4116: {
  2274. name: 'MESSAGE_SENT_QUOTA_EXCEEDED',
  2275. message: 'Command sent too fast.'
  2276. },
  2277. 4200: {
  2278. name: 'INTERNAL_ERROR',
  2279. message: 'Internal error, please contact LeanCloud for support.'
  2280. },
  2281. 4301: {
  2282. name: 'CONVERSATION_API_FAILED',
  2283. message: 'Upstream Conversatoin API failed, see error.detail for details.'
  2284. },
  2285. 4302: {
  2286. name: 'CONVERSATION_SIGNATURE_FAILED',
  2287. message: 'Conversation action signature mismatch.'
  2288. },
  2289. 4303: {
  2290. name: 'CONVERSATION_NOT_FOUND'
  2291. },
  2292. 4304: {
  2293. name: 'CONVERSATION_FULL'
  2294. },
  2295. 4305: {
  2296. name: 'CONVERSATION_REJECTED_BY_APP',
  2297. message: 'Conversation action rejected by hook.'
  2298. },
  2299. 4306: {
  2300. name: 'CONVERSATION_UPDATE_FAILED'
  2301. },
  2302. 4307: {
  2303. name: 'CONVERSATION_READ_ONLY'
  2304. },
  2305. 4308: {
  2306. name: 'CONVERSATION_NOT_ALLOWED'
  2307. },
  2308. 4309: {
  2309. name: 'CONVERSATION_UPDATE_REJECTED',
  2310. message: 'Conversation update rejected because the client is not a member.'
  2311. },
  2312. 4310: {
  2313. name: 'CONVERSATION_QUERY_FAILED',
  2314. message: 'Conversation query failed because it is too expansive.'
  2315. },
  2316. 4311: {
  2317. name: 'CONVERSATION_LOG_FAILED'
  2318. },
  2319. 4312: {
  2320. name: 'CONVERSATION_LOG_REJECTED',
  2321. message: 'Message query rejected because the client is not a member of the conversation.'
  2322. },
  2323. 4313: {
  2324. name: 'SYSTEM_CONVERSATION_REQUIRED'
  2325. },
  2326. 4314: {
  2327. name: 'NORMAL_CONVERSATION_REQUIRED'
  2328. },
  2329. 4315: {
  2330. name: 'CONVERSATION_BLACKLISTED',
  2331. message: 'Blacklisted in the conversation.'
  2332. },
  2333. 4316: {
  2334. name: 'TRANSIENT_CONVERSATION_REQUIRED'
  2335. },
  2336. 4317: {
  2337. name: 'CONVERSATION_MEMBERSHIP_REQUIRED'
  2338. },
  2339. 4318: {
  2340. name: 'CONVERSATION_API_QUOTA_EXCEEDED',
  2341. message: 'LeanCloud API quota exceeded. You may upgrade your plan.'
  2342. },
  2343. 4323: {
  2344. name: 'TEMPORARY_CONVERSATION_EXPIRED',
  2345. message: 'Temporary conversation expired or does not exist.'
  2346. },
  2347. 4401: {
  2348. name: 'INVALID_MESSAGING_TARGET',
  2349. message: 'Conversation does not exist or client is not a member.'
  2350. },
  2351. 4402: {
  2352. name: 'MESSAGE_REJECTED_BY_APP',
  2353. message: 'Message rejected by hook.'
  2354. },
  2355. 4403: {
  2356. name: 'MESSAGE_OWNERSHIP_REQUIRED'
  2357. },
  2358. 4404: {
  2359. name: 'MESSAGE_NOT_FOUND'
  2360. },
  2361. 4405: {
  2362. name: 'MESSAGE_UPDATE_REJECTED_BY_APP',
  2363. message: 'Message update rejected by hook.'
  2364. },
  2365. 4406: {
  2366. name: 'MESSAGE_EDIT_DISABLED'
  2367. },
  2368. 4407: {
  2369. name: 'MESSAGE_RECALL_DISABLED'
  2370. },
  2371. 5130: {
  2372. name: 'OWNER_PROMOTION_NOT_ALLOWED',
  2373. message: "Updating a member's role to owner is not allowed."
  2374. }
  2375. });
  2376. var ErrorCode = Object.freeze(Object.keys(error).reduce(function (result, code) {
  2377. return Object.assign(result, _defineProperty({}, error[code].name, Number(code)));
  2378. }, {}));
  2379. var createError = function createError(_ref) {
  2380. var code = _ref.code,
  2381. reason = _ref.reason,
  2382. appCode = _ref.appCode,
  2383. detail = _ref.detail,
  2384. errorMessage = _ref.error;
  2385. var message = reason || detail || errorMessage;
  2386. var name = reason;
  2387. if (!message && error[code]) {
  2388. name = error[code].name;
  2389. message = error[code].message || name;
  2390. }
  2391. if (!message) {
  2392. message = "Unknow Error: ".concat(code);
  2393. }
  2394. var err = new Error(message);
  2395. return Object.assign(err, {
  2396. code: code,
  2397. appCode: appCode,
  2398. detail: detail,
  2399. name: name
  2400. });
  2401. };
  2402. var debug$4 = d('LC:Connection');
  2403. var COMMAND_TIMEOUT = 20000;
  2404. var EXPIRE = Symbol('expire');
  2405. var isIdempotentCommand = function isIdempotentCommand(command) {
  2406. return !(command.cmd === CommandType.direct || command.cmd === CommandType.session && command.op === OpType.open || command.cmd === CommandType.conv && (command.op === OpType.start || command.op === OpType.update || command.op === OpType.members));
  2407. };
  2408. var Connection = /*#__PURE__*/function (_WebSocketPlus) {
  2409. _inheritsLoose(Connection, _WebSocketPlus);
  2410. function Connection(getUrl, _ref) {
  2411. var _this;
  2412. var format = _ref.format,
  2413. version = _ref.version;
  2414. debug$4('initializing Connection');
  2415. var protocolString = "lc.".concat(format, ".").concat(version);
  2416. _this = _WebSocketPlus.call(this, getUrl, protocolString) || this;
  2417. _this._protocolFormat = format;
  2418. _this._commands = {};
  2419. _this._serialId = 0;
  2420. return _this;
  2421. }
  2422. var _proto = Connection.prototype;
  2423. _proto.send = /*#__PURE__*/function () {
  2424. var _send = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(command) {
  2425. var _this2 = this;
  2426. var waitingForRespond,
  2427. buffer,
  2428. serialId,
  2429. duplicatedCommand,
  2430. message,
  2431. promise,
  2432. _args = arguments;
  2433. return _regeneratorRuntime.wrap(function _callee$(_context) {
  2434. while (1) {
  2435. switch (_context.prev = _context.next) {
  2436. case 0:
  2437. waitingForRespond = _args.length > 1 && _args[1] !== undefined ? _args[1] : true;
  2438. if (!waitingForRespond) {
  2439. _context.next = 11;
  2440. break;
  2441. }
  2442. if (!isIdempotentCommand(command)) {
  2443. _context.next = 8;
  2444. break;
  2445. }
  2446. buffer = command.toArrayBuffer();
  2447. duplicatedCommand = values(this._commands).find(function (_ref2) {
  2448. var targetBuffer = _ref2.buffer,
  2449. targetCommand = _ref2.command;
  2450. return targetCommand.cmd === command.cmd && targetCommand.op === command.op && equalBuffer(targetBuffer, buffer);
  2451. });
  2452. if (!duplicatedCommand) {
  2453. _context.next = 8;
  2454. break;
  2455. }
  2456. console.warn("Duplicated command [cmd:".concat(command.cmd, " op:").concat(command.op, "] is throttled."));
  2457. return _context.abrupt("return", duplicatedCommand.promise);
  2458. case 8:
  2459. this._serialId += 1;
  2460. serialId = this._serialId;
  2461. command.i = serialId; // eslint-disable-line no-param-reassign
  2462. case 11:
  2463. if (debug$4.enabled) debug$4('↑ %O sent', trim(command));
  2464. if (this._protocolFormat === 'proto2base64') {
  2465. message = command.toBase64();
  2466. } else if (command.toArrayBuffer) {
  2467. message = command.toArrayBuffer();
  2468. }
  2469. if (message) {
  2470. _context.next = 15;
  2471. break;
  2472. }
  2473. throw new TypeError("".concat(command, " is not a GenericCommand"));
  2474. case 15:
  2475. _WebSocketPlus.prototype.send.call(this, message);
  2476. if (waitingForRespond) {
  2477. _context.next = 18;
  2478. break;
  2479. }
  2480. return _context.abrupt("return", undefined);
  2481. case 18:
  2482. promise = new Promise(function (resolve, reject) {
  2483. _this2._commands[serialId] = {
  2484. command: command,
  2485. buffer: buffer,
  2486. resolve: resolve,
  2487. reject: reject,
  2488. timeout: setTimeout(function () {
  2489. if (_this2._commands[serialId]) {
  2490. if (debug$4.enabled) debug$4('✗ %O timeout', trim(command));
  2491. reject(createError({
  2492. error: "Command Timeout [cmd:".concat(command.cmd, " op:").concat(command.op, "]"),
  2493. name: 'COMMAND_TIMEOUT'
  2494. }));
  2495. delete _this2._commands[serialId];
  2496. }
  2497. }, COMMAND_TIMEOUT)
  2498. };
  2499. });
  2500. this._commands[serialId].promise = promise;
  2501. return _context.abrupt("return", promise);
  2502. case 21:
  2503. case "end":
  2504. return _context.stop();
  2505. }
  2506. }
  2507. }, _callee, this);
  2508. }));
  2509. function send(_x) {
  2510. return _send.apply(this, arguments);
  2511. }
  2512. return send;
  2513. }();
  2514. _proto.handleMessage = function handleMessage(msg) {
  2515. var message;
  2516. try {
  2517. message = GenericCommand.decode(msg);
  2518. if (debug$4.enabled) debug$4('↓ %O received', trim(message));
  2519. } catch (e) {
  2520. console.warn('Decode message failed:', e.message, msg);
  2521. return;
  2522. }
  2523. var serialId = message.i;
  2524. if (serialId) {
  2525. if (this._commands[serialId]) {
  2526. clearTimeout(this._commands[serialId].timeout);
  2527. if (message.cmd === CommandType.error) {
  2528. this._commands[serialId].reject(createError(message.errorMessage));
  2529. } else {
  2530. this._commands[serialId].resolve(message);
  2531. }
  2532. delete this._commands[serialId];
  2533. } else {
  2534. console.warn("Unexpected command received with serialId [".concat(serialId, "],\n which have timed out or never been requested."));
  2535. }
  2536. } else {
  2537. switch (message.cmd) {
  2538. case CommandType.error:
  2539. {
  2540. this.emit(ERROR, createError(message.errorMessage));
  2541. return;
  2542. }
  2543. case CommandType.goaway:
  2544. {
  2545. this.emit(EXPIRE);
  2546. return;
  2547. }
  2548. default:
  2549. {
  2550. this.emit(MESSAGE, message);
  2551. }
  2552. }
  2553. }
  2554. };
  2555. _proto.ping = function ping() {
  2556. return this.send(new GenericCommand({
  2557. cmd: CommandType.echo
  2558. }))["catch"](function (error) {
  2559. return debug$4('ping failed:', error);
  2560. });
  2561. };
  2562. return Connection;
  2563. }(WebSocketPlus);
  2564. var debug$5 = d('LC:request');
  2565. var request = (function (_ref) {
  2566. var _ref$method = _ref.method,
  2567. method = _ref$method === void 0 ? 'GET' : _ref$method,
  2568. _url = _ref.url,
  2569. query = _ref.query,
  2570. headers = _ref.headers,
  2571. data = _ref.data,
  2572. time = _ref.timeout;
  2573. var url = _url;
  2574. if (query) {
  2575. var queryString = Object.keys(query).map(function (key) {
  2576. var value = query[key];
  2577. if (value === undefined) return undefined;
  2578. var v = isPlainObject(value) ? JSON.stringify(value) : value;
  2579. return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(v));
  2580. }).filter(function (qs) {
  2581. return qs;
  2582. }).join('&');
  2583. url = "".concat(url, "?").concat(queryString);
  2584. }
  2585. debug$5('Req: %O %O %O', method, url, {
  2586. headers: headers,
  2587. data: data
  2588. });
  2589. var request = getAdapter('request');
  2590. var promise = request(url, {
  2591. method: method,
  2592. headers: headers,
  2593. data: data
  2594. }).then(function (response) {
  2595. if (response.ok === false) {
  2596. var error = createError(response.data);
  2597. error.response = response;
  2598. throw error;
  2599. }
  2600. debug$5('Res: %O %O %O', url, response.status, response.data);
  2601. return response.data;
  2602. })["catch"](function (error) {
  2603. if (error.response) {
  2604. debug$5('Error: %O %O %O', url, error.response.status, error.response.data);
  2605. }
  2606. throw error;
  2607. });
  2608. return time ? promiseTimeout.timeout(promise, time) : promise;
  2609. });
  2610. var checkType = function checkType(middleware) {
  2611. return function (param) {
  2612. var constructor = param.constructor;
  2613. return Promise.resolve(param).then(middleware).then(tap(function (result) {
  2614. if (result === undefined || result === null) {
  2615. // eslint-disable-next-line max-len
  2616. return console.warn("Middleware[".concat(middleware._pluginName || 'anonymous plugin', ":").concat(middleware.name || 'anonymous middleware', "] param/return types not match. It returns ").concat(result, " while a ").concat(param.constructor.name, " expected."));
  2617. }
  2618. if (!(result instanceof constructor)) {
  2619. // eslint-disable-next-line max-len
  2620. return console.warn("Middleware[".concat(middleware._pluginName || 'anonymous plugin', ":").concat(middleware.name || 'anonymous middleware', "] param/return types not match. It returns a ").concat(result.constructor.name, " while a ").concat(param.constructor.name, " expected."));
  2621. }
  2622. return 0;
  2623. }));
  2624. };
  2625. };
  2626. var applyDecorators = function applyDecorators(decorators, target) {
  2627. if (decorators) {
  2628. decorators.forEach(function (decorator) {
  2629. try {
  2630. decorator(target);
  2631. } catch (error) {
  2632. if (decorator._pluginName) {
  2633. error.message += "[".concat(decorator._pluginName, "]");
  2634. }
  2635. throw error;
  2636. }
  2637. });
  2638. }
  2639. };
  2640. var applyMiddlewares = function applyMiddlewares(middlewares) {
  2641. return function (target) {
  2642. return ensureArray(middlewares).reduce(function (previousPromise, middleware) {
  2643. return previousPromise.then(checkType(middleware))["catch"](function (error) {
  2644. if (middleware._pluginName) {
  2645. // eslint-disable-next-line no-param-reassign
  2646. error.message += "[".concat(middleware._pluginName, "]");
  2647. }
  2648. throw error;
  2649. });
  2650. }, Promise.resolve(target));
  2651. };
  2652. };
  2653. var applyDispatcher = function applyDispatcher(dispatchers, payload) {
  2654. return ensureArray(dispatchers).reduce(function (resultPromise, dispatcher) {
  2655. return resultPromise.then(function (shouldDispatch) {
  2656. return shouldDispatch === false ? false : dispatcher.apply(void 0, _toConsumableArray(payload));
  2657. })["catch"](function (error) {
  2658. if (dispatcher._pluginName) {
  2659. // eslint-disable-next-line no-param-reassign
  2660. error.message += "[".concat(dispatcher._pluginName, "]");
  2661. }
  2662. throw error;
  2663. });
  2664. }, Promise.resolve(true));
  2665. };
  2666. var version = "5.0.0-rc.7";
  2667. function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  2668. function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  2669. var debug$6 = d('LC:Realtime');
  2670. var routerCache = new Cache('push-router');
  2671. var initializedApp = {};
  2672. var Realtime = /*#__PURE__*/function (_EventEmitter) {
  2673. _inheritsLoose(Realtime, _EventEmitter);
  2674. /**
  2675. * @extends EventEmitter
  2676. * @param {Object} options
  2677. * @param {String} options.appId
  2678. * @param {String} options.appKey (since 4.0.0)
  2679. * @param {String|Object} [options.server] 指定服务器域名,中国节点应用此参数必填(since 4.0.0)
  2680. * @param {Boolean} [options.noBinary=false] 设置 WebSocket 使用字符串格式收发消息(默认为二进制格式)。
  2681. * 适用于 WebSocket 实现不支持二进制数据格式的情况
  2682. * @param {Boolean} [options.ssl=true] 使用 wss 进行连接
  2683. * @param {String|String[]} [options.RTMServers] 指定私有部署的 RTM 服务器地址(since 4.0.0)
  2684. * @param {Plugin[]} [options.plugins] 加载插件(since 3.1.0)
  2685. */
  2686. function Realtime(_ref) {
  2687. var _this2;
  2688. var plugins = _ref.plugins,
  2689. options = _objectWithoutProperties(_ref, ["plugins"]);
  2690. debug$6('initializing Realtime %s %O', version, options);
  2691. _this2 = _EventEmitter.call(this) || this;
  2692. var appId = options.appId;
  2693. if (typeof appId !== 'string') {
  2694. throw new TypeError("appId [".concat(appId, "] is not a string"));
  2695. }
  2696. if (initializedApp[appId]) {
  2697. throw new Error("App [".concat(appId, "] is already initialized."));
  2698. }
  2699. initializedApp[appId] = true;
  2700. if (typeof options.appKey !== 'string') {
  2701. throw new TypeError("appKey [".concat(options.appKey, "] is not a string"));
  2702. }
  2703. if (isCNApp(appId)) {
  2704. if (!options.server) {
  2705. throw new TypeError("server option is required for apps from CN region");
  2706. }
  2707. }
  2708. _this2._options = _objectSpread$2({
  2709. appId: undefined,
  2710. appKey: undefined,
  2711. noBinary: false,
  2712. ssl: true,
  2713. RTMServerName: typeof process !== 'undefined' ? process.env.RTM_SERVER_NAME : undefined
  2714. }, options);
  2715. _this2._cache = new Cache('endpoints');
  2716. var _this = internal(_assertThisInitialized(_this2));
  2717. _this.clients = new Set();
  2718. _this.pendingClients = new Set();
  2719. var mergedPlugins = [].concat(_toConsumableArray(ensureArray(Realtime.__preRegisteredPlugins)), _toConsumableArray(ensureArray(plugins)));
  2720. debug$6('Using plugins %o', mergedPlugins.map(function (plugin) {
  2721. return plugin.name;
  2722. }));
  2723. _this2._plugins = mergedPlugins.reduce(function (result, plugin) {
  2724. Object.keys(plugin).forEach(function (hook) {
  2725. if ({}.hasOwnProperty.call(plugin, hook) && hook !== 'name') {
  2726. if (plugin.name) {
  2727. ensureArray(plugin[hook]).forEach(function (value) {
  2728. // eslint-disable-next-line no-param-reassign
  2729. value._pluginName = plugin.name;
  2730. });
  2731. } // eslint-disable-next-line no-param-reassign
  2732. result[hook] = ensureArray(result[hook]).concat(plugin[hook]);
  2733. }
  2734. });
  2735. return result;
  2736. }, {}); // onRealtimeCreate hook
  2737. applyDecorators(_this2._plugins.onRealtimeCreate, _assertThisInitialized(_this2));
  2738. return _this2;
  2739. }
  2740. var _proto = Realtime.prototype;
  2741. _proto._request = /*#__PURE__*/function () {
  2742. var _request2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2) {
  2743. var method, _url, _ref2$version, version, path, query, headers, data, url, _this$_options, appId, server, _yield$this$construct, api;
  2744. return _regeneratorRuntime.wrap(function _callee$(_context) {
  2745. while (1) {
  2746. switch (_context.prev = _context.next) {
  2747. case 0:
  2748. method = _ref2.method, _url = _ref2.url, _ref2$version = _ref2.version, version = _ref2$version === void 0 ? '1.1' : _ref2$version, path = _ref2.path, query = _ref2.query, headers = _ref2.headers, data = _ref2.data;
  2749. url = _url;
  2750. if (url) {
  2751. _context.next = 9;
  2752. break;
  2753. }
  2754. _this$_options = this._options, appId = _this$_options.appId, server = _this$_options.server;
  2755. _context.next = 6;
  2756. return this.constructor._getServerUrls({
  2757. appId: appId,
  2758. server: server
  2759. });
  2760. case 6:
  2761. _yield$this$construct = _context.sent;
  2762. api = _yield$this$construct.api;
  2763. url = "".concat(api, "/").concat(version).concat(path);
  2764. case 9:
  2765. return _context.abrupt("return", request({
  2766. url: url,
  2767. method: method,
  2768. query: query,
  2769. headers: _objectSpread$2({
  2770. 'X-LC-Id': this._options.appId,
  2771. 'X-LC-Key': this._options.appKey
  2772. }, headers),
  2773. data: data
  2774. }));
  2775. case 10:
  2776. case "end":
  2777. return _context.stop();
  2778. }
  2779. }
  2780. }, _callee, this);
  2781. }));
  2782. function _request(_x) {
  2783. return _request2.apply(this, arguments);
  2784. }
  2785. return _request;
  2786. }();
  2787. _proto._open = function _open() {
  2788. var _this3 = this;
  2789. if (this._openPromise) return this._openPromise;
  2790. var format = 'protobuf2';
  2791. if (this._options.noBinary) {
  2792. // 不发送 binary data,fallback to base64 string
  2793. format = 'proto2base64';
  2794. }
  2795. var version = 3;
  2796. var protocol = {
  2797. format: format,
  2798. version: version
  2799. };
  2800. this._openPromise = new Promise(function (resolve, reject) {
  2801. debug$6('No connection established, create a new one.');
  2802. var connection = new Connection(function () {
  2803. return _this3._getRTMServers(_this3._options);
  2804. }, protocol);
  2805. connection.on(OPEN, function () {
  2806. return resolve(connection);
  2807. }).on(ERROR, function (error) {
  2808. delete _this3._openPromise;
  2809. reject(error);
  2810. }).on(EXPIRE, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
  2811. return _regeneratorRuntime.wrap(function _callee2$(_context2) {
  2812. while (1) {
  2813. switch (_context2.prev = _context2.next) {
  2814. case 0:
  2815. debug$6('Connection expired. Refresh endpoints.');
  2816. _this3._cache.set('endpoints', null, 0);
  2817. _context2.next = 4;
  2818. return _this3._getRTMServers(_this3._options);
  2819. case 4:
  2820. connection.urls = _context2.sent;
  2821. connection.disconnect();
  2822. case 6:
  2823. case "end":
  2824. return _context2.stop();
  2825. }
  2826. }
  2827. }, _callee2);
  2828. }))).on(MESSAGE, _this3._dispatchCommand.bind(_this3));
  2829. /**
  2830. * 连接断开。
  2831. * 连接断开可能是因为 SDK 进入了离线状态(see {@link Realtime#event:OFFLINE}),或长时间没有收到服务器心跳。
  2832. * 连接断开后所有的网络操作都会失败,请在连接断开后禁用相关的 UI 元素。
  2833. * @event Realtime#DISCONNECT
  2834. */
  2835. /**
  2836. * 计划在一段时间后尝试重新连接
  2837. * @event Realtime#SCHEDULE
  2838. * @param {Number} attempt 尝试重连的次数
  2839. * @param {Number} delay 延迟的毫秒数
  2840. */
  2841. /**
  2842. * 正在尝试重新连接
  2843. * @event Realtime#RETRY
  2844. * @param {Number} attempt 尝试重连的次数
  2845. */
  2846. /**
  2847. * 连接恢复正常。
  2848. * 请重新启用在 {@link Realtime#event:DISCONNECT} 事件中禁用的相关 UI 元素
  2849. * @event Realtime#RECONNECT
  2850. */
  2851. /**
  2852. * 客户端连接断开
  2853. * @event IMClient#DISCONNECT
  2854. * @see Realtime#event:DISCONNECT
  2855. * @since 3.2.0
  2856. */
  2857. /**
  2858. * 计划在一段时间后尝试重新连接
  2859. * @event IMClient#SCHEDULE
  2860. * @param {Number} attempt 尝试重连的次数
  2861. * @param {Number} delay 延迟的毫秒数
  2862. * @since 3.2.0
  2863. */
  2864. /**
  2865. * 正在尝试重新连接
  2866. * @event IMClient#RETRY
  2867. * @param {Number} attempt 尝试重连的次数
  2868. * @since 3.2.0
  2869. */
  2870. /**
  2871. * 客户端进入离线状态。
  2872. * 这通常意味着网络已断开,或者 {@link Realtime#pause} 被调用
  2873. * @event Realtime#OFFLINE
  2874. * @since 3.4.0
  2875. */
  2876. /**
  2877. * 客户端恢复在线状态
  2878. * 这通常意味着网络已恢复,或者 {@link Realtime#resume} 被调用
  2879. * @event Realtime#ONLINE
  2880. * @since 3.4.0
  2881. */
  2882. /**
  2883. * 进入离线状态。
  2884. * 这通常意味着网络已断开,或者 {@link Realtime#pause} 被调用
  2885. * @event IMClient#OFFLINE
  2886. * @since 3.4.0
  2887. */
  2888. /**
  2889. * 恢复在线状态
  2890. * 这通常意味着网络已恢复,或者 {@link Realtime#resume} 被调用
  2891. * @event IMClient#ONLINE
  2892. * @since 3.4.0
  2893. */
  2894. // event proxy
  2895. [DISCONNECT, RECONNECT, RETRY, SCHEDULE, OFFLINE, ONLINE].forEach(function (event) {
  2896. return connection.on(event, function () {
  2897. for (var _len = arguments.length, payload = new Array(_len), _key = 0; _key < _len; _key++) {
  2898. payload[_key] = arguments[_key];
  2899. }
  2900. debug$6("".concat(event, " event emitted. %o"), payload);
  2901. _this3.emit.apply(_this3, [event].concat(payload));
  2902. if (event !== RECONNECT) {
  2903. internal(_this3).clients.forEach(function (client) {
  2904. client.emit.apply(client, [event].concat(payload));
  2905. });
  2906. }
  2907. });
  2908. }); // override handleClose
  2909. connection.handleClose = function handleClose(event) {
  2910. var isFatal = [ErrorCode.APP_NOT_AVAILABLE, ErrorCode.INVALID_LOGIN, ErrorCode.INVALID_ORIGIN].some(function (errorCode) {
  2911. return errorCode === event.code;
  2912. });
  2913. if (isFatal) {
  2914. // in these cases, SDK should throw.
  2915. this["throw"](createError(event));
  2916. } else {
  2917. // reconnect
  2918. this.disconnect();
  2919. }
  2920. };
  2921. internal(_this3).connection = connection;
  2922. });
  2923. return this._openPromise;
  2924. };
  2925. _proto._getRTMServers = /*#__PURE__*/function () {
  2926. var _getRTMServers2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(options) {
  2927. var info, cachedEndPoints, _info, server, secondary, ttl;
  2928. return _regeneratorRuntime.wrap(function _callee3$(_context3) {
  2929. while (1) {
  2930. switch (_context3.prev = _context3.next) {
  2931. case 0:
  2932. if (!options.RTMServers) {
  2933. _context3.next = 2;
  2934. break;
  2935. }
  2936. return _context3.abrupt("return", shuffle(ensureArray(options.RTMServers)));
  2937. case 2:
  2938. cachedEndPoints = this._cache.get('endpoints');
  2939. if (!cachedEndPoints) {
  2940. _context3.next = 7;
  2941. break;
  2942. }
  2943. info = cachedEndPoints;
  2944. _context3.next = 14;
  2945. break;
  2946. case 7:
  2947. _context3.next = 9;
  2948. return this.constructor._fetchRTMServers(options);
  2949. case 9:
  2950. info = _context3.sent;
  2951. _info = info, server = _info.server, secondary = _info.secondary, ttl = _info.ttl;
  2952. if (!(typeof server !== 'string' && typeof secondary !== 'string' && typeof ttl !== 'number')) {
  2953. _context3.next = 13;
  2954. break;
  2955. }
  2956. throw new Error("malformed RTM route response: ".concat(JSON.stringify(info)));
  2957. case 13:
  2958. this._cache.set('endpoints', info, info.ttl * 1000);
  2959. case 14:
  2960. debug$6('endpoint info: %O', info);
  2961. return _context3.abrupt("return", [info.server, info.secondary]);
  2962. case 16:
  2963. case "end":
  2964. return _context3.stop();
  2965. }
  2966. }
  2967. }, _callee3, this);
  2968. }));
  2969. function _getRTMServers(_x2) {
  2970. return _getRTMServers2.apply(this, arguments);
  2971. }
  2972. return _getRTMServers;
  2973. }();
  2974. Realtime._getServerUrls = /*#__PURE__*/function () {
  2975. var _getServerUrls2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref4) {
  2976. var appId, server, cachedRouter, defaultProtocol;
  2977. return _regeneratorRuntime.wrap(function _callee4$(_context4) {
  2978. while (1) {
  2979. switch (_context4.prev = _context4.next) {
  2980. case 0:
  2981. appId = _ref4.appId, server = _ref4.server;
  2982. debug$6('fetch server urls');
  2983. if (!server) {
  2984. _context4.next = 6;
  2985. break;
  2986. }
  2987. if (!(typeof server !== 'string')) {
  2988. _context4.next = 5;
  2989. break;
  2990. }
  2991. return _context4.abrupt("return", server);
  2992. case 5:
  2993. return _context4.abrupt("return", {
  2994. RTMRouter: server,
  2995. api: server
  2996. });
  2997. case 6:
  2998. cachedRouter = routerCache.get(appId);
  2999. if (!cachedRouter) {
  3000. _context4.next = 9;
  3001. break;
  3002. }
  3003. return _context4.abrupt("return", cachedRouter);
  3004. case 9:
  3005. defaultProtocol = 'https://';
  3006. return _context4.abrupt("return", request({
  3007. url: 'https://app-router.com/2/route',
  3008. query: {
  3009. appId: appId
  3010. },
  3011. timeout: 20000
  3012. }).then(tap(debug$6)).then(function (_ref5) {
  3013. var RTMRouterServer = _ref5.rtm_router_server,
  3014. APIServer = _ref5.api_server,
  3015. _ref5$ttl = _ref5.ttl,
  3016. ttl = _ref5$ttl === void 0 ? 3600 : _ref5$ttl;
  3017. if (!RTMRouterServer) {
  3018. throw new Error('rtm router not exists');
  3019. }
  3020. var serverUrls = {
  3021. RTMRouter: "".concat(defaultProtocol).concat(RTMRouterServer),
  3022. api: "".concat(defaultProtocol).concat(APIServer)
  3023. };
  3024. routerCache.set(appId, serverUrls, ttl * 1000);
  3025. return serverUrls;
  3026. })["catch"](function () {
  3027. var id = appId.slice(0, 8).toLowerCase();
  3028. var domain = 'lncldglobal.com';
  3029. return {
  3030. RTMRouter: "".concat(defaultProtocol).concat(id, ".rtm.").concat(domain),
  3031. api: "".concat(defaultProtocol).concat(id, ".api.").concat(domain)
  3032. };
  3033. }));
  3034. case 11:
  3035. case "end":
  3036. return _context4.stop();
  3037. }
  3038. }
  3039. }, _callee4);
  3040. }));
  3041. function _getServerUrls(_x3) {
  3042. return _getServerUrls2.apply(this, arguments);
  3043. }
  3044. return _getServerUrls;
  3045. }();
  3046. Realtime._fetchRTMServers = function _fetchRTMServers(_ref6) {
  3047. var appId = _ref6.appId,
  3048. ssl = _ref6.ssl,
  3049. server = _ref6.server,
  3050. RTMServerName = _ref6.RTMServerName;
  3051. debug$6('fetch endpoint info');
  3052. return this._getServerUrls({
  3053. appId: appId,
  3054. server: server
  3055. }).then(tap(debug$6)).then(function (_ref7) {
  3056. var RTMRouter = _ref7.RTMRouter;
  3057. return request({
  3058. url: "".concat(RTMRouter, "/v1/route"),
  3059. query: {
  3060. appId: appId,
  3061. secure: ssl,
  3062. features: isWeapp ? 'wechat' : undefined,
  3063. server: RTMServerName,
  3064. _t: Date.now()
  3065. },
  3066. timeout: 20000
  3067. }).then(tap(debug$6));
  3068. });
  3069. };
  3070. _proto._close = function _close() {
  3071. if (this._openPromise) {
  3072. this._openPromise.then(function (connection) {
  3073. return connection.close();
  3074. });
  3075. }
  3076. delete this._openPromise;
  3077. }
  3078. /**
  3079. * 手动进行重连。
  3080. * SDK 在网络出现异常时会自动按照一定的时间间隔尝试重连,调用该方法会立即尝试重连并重置重连尝试计数器。
  3081. * 只能在 `SCHEDULE` 事件之后,`RETRY` 事件之前调用,如果当前网络正常或者正在进行重连,调用该方法会抛异常。
  3082. */
  3083. ;
  3084. _proto.retry = function retry() {
  3085. var _internal = internal(this),
  3086. connection = _internal.connection;
  3087. if (!connection) {
  3088. throw new Error('no connection established');
  3089. }
  3090. if (connection.cannot('retry')) {
  3091. throw new Error("retrying not allowed when not disconnected. the connection is now ".concat(connection.current));
  3092. }
  3093. return connection.retry();
  3094. }
  3095. /**
  3096. * 暂停,使 SDK 进入离线状态。
  3097. * 你可以在网络断开、应用进入后台等时刻调用该方法让 SDK 进入离线状态,离线状态下不会尝试重连。
  3098. * 在浏览器中 SDK 会自动监听网络变化,因此无需手动调用该方法。
  3099. *
  3100. * @since 3.4.0
  3101. * @see Realtime#event:OFFLINE
  3102. */
  3103. ;
  3104. _proto.pause = function pause() {
  3105. // 这个方法常常在网络断开、进入后台时被调用,此时 connection 可能没有建立或者已经 close。
  3106. // 因此不像 retry,这个方法应该尽可能 loose
  3107. var _internal2 = internal(this),
  3108. connection = _internal2.connection;
  3109. if (!connection) return;
  3110. if (connection.can('pause')) connection.pause();
  3111. }
  3112. /**
  3113. * 恢复在线状态。
  3114. * 你可以在网络恢复、应用回到前台等时刻调用该方法让 SDK 恢复在线状态,恢复在线状态后 SDK 会开始尝试重连。
  3115. *
  3116. * @since 3.4.0
  3117. * @see Realtime#event:ONLINE
  3118. */
  3119. ;
  3120. _proto.resume = function resume() {
  3121. // 与 pause 一样,这个方法应该尽可能 loose
  3122. var _internal3 = internal(this),
  3123. connection = _internal3.connection;
  3124. if (!connection) return;
  3125. if (connection.can('resume')) connection.resume();
  3126. };
  3127. _proto._registerPending = function _registerPending(value) {
  3128. internal(this).pendingClients.add(value);
  3129. };
  3130. _proto._deregisterPending = function _deregisterPending(client) {
  3131. internal(this).pendingClients["delete"](client);
  3132. };
  3133. _proto._register = function _register(client) {
  3134. internal(this).clients.add(client);
  3135. };
  3136. _proto._deregister = function _deregister(client) {
  3137. var _this = internal(this);
  3138. _this.clients["delete"](client);
  3139. if (_this.clients.size + _this.pendingClients.size === 0) {
  3140. this._close();
  3141. }
  3142. };
  3143. _proto._dispatchCommand = function _dispatchCommand(command) {
  3144. return applyDispatcher(this._plugins.beforeCommandDispatch, [command, this]).then(function (shouldDispatch) {
  3145. // no plugin handled this command
  3146. if (shouldDispatch) return debug$6('[WARN] Unexpected message received: %O', trim(command));
  3147. return false;
  3148. });
  3149. };
  3150. return Realtime;
  3151. }(EventEmitter); // For test purpose only
  3152. var polyfilledPromise = Promise;
  3153. // IMClient
  3154. var UNREAD_MESSAGES_COUNT_UPDATE = 'unreadmessagescountupdate';
  3155. var CLOSE = 'close';
  3156. var CONFLICT = 'conflict';
  3157. var CONVERSATION_INFO_UPDATED = 'conversationinfoupdated';
  3158. var UNHANDLED_MESSAGE = 'unhandledmessage'; // shared
  3159. var INVITED = 'invited';
  3160. var KICKED = 'kicked';
  3161. var MEMBERS_JOINED = 'membersjoined';
  3162. var MEMBERS_LEFT = 'membersleft';
  3163. var MEMBER_INFO_UPDATED = 'memberinfoupdated';
  3164. var BLOCKED = 'blocked';
  3165. var UNBLOCKED = 'unblocked';
  3166. var MEMBERS_BLOCKED = 'membersblocked';
  3167. var MEMBERS_UNBLOCKED = 'membersunblocked';
  3168. var MUTED = 'muted';
  3169. var UNMUTED = 'unmuted';
  3170. var MEMBERS_MUTED = 'membersmuted';
  3171. var MEMBERS_UNMUTED = 'membersunmuted';
  3172. var MESSAGE$1 = 'message';
  3173. var MESSAGE_RECALL = 'messagerecall';
  3174. var MESSAGE_UPDATE = 'messageupdate'; // Conversation
  3175. var LAST_DELIVERED_AT_UPDATE = 'lastdeliveredatupdate';
  3176. var LAST_READ_AT_UPDATE = 'lastreadatupdate';
  3177. var INFO_UPDATED = 'infoupdated';
  3178. var IMEvent = /*#__PURE__*/Object.freeze({
  3179. __proto__: null,
  3180. UNREAD_MESSAGES_COUNT_UPDATE: UNREAD_MESSAGES_COUNT_UPDATE,
  3181. CLOSE: CLOSE,
  3182. CONFLICT: CONFLICT,
  3183. CONVERSATION_INFO_UPDATED: CONVERSATION_INFO_UPDATED,
  3184. UNHANDLED_MESSAGE: UNHANDLED_MESSAGE,
  3185. INVITED: INVITED,
  3186. KICKED: KICKED,
  3187. MEMBERS_JOINED: MEMBERS_JOINED,
  3188. MEMBERS_LEFT: MEMBERS_LEFT,
  3189. MEMBER_INFO_UPDATED: MEMBER_INFO_UPDATED,
  3190. BLOCKED: BLOCKED,
  3191. UNBLOCKED: UNBLOCKED,
  3192. MEMBERS_BLOCKED: MEMBERS_BLOCKED,
  3193. MEMBERS_UNBLOCKED: MEMBERS_UNBLOCKED,
  3194. MUTED: MUTED,
  3195. UNMUTED: UNMUTED,
  3196. MEMBERS_MUTED: MEMBERS_MUTED,
  3197. MEMBERS_UNMUTED: MEMBERS_UNMUTED,
  3198. MESSAGE: MESSAGE$1,
  3199. MESSAGE_RECALL: MESSAGE_RECALL,
  3200. MESSAGE_UPDATE: MESSAGE_UPDATE,
  3201. LAST_DELIVERED_AT_UPDATE: LAST_DELIVERED_AT_UPDATE,
  3202. LAST_READ_AT_UPDATE: LAST_READ_AT_UPDATE,
  3203. INFO_UPDATED: INFO_UPDATED
  3204. });
  3205. var _rMessageStatus;
  3206. function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  3207. function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  3208. /**
  3209. * 消息状态枚举
  3210. * @enum {Symbol}
  3211. * @since 3.2.0
  3212. * @memberof module:leancloud-realtime
  3213. */
  3214. var MessageStatus = {
  3215. /** 初始状态、未知状态 */
  3216. NONE: Symbol('none'),
  3217. /** 正在发送 */
  3218. SENDING: Symbol('sending'),
  3219. /** 已发送 */
  3220. SENT: Symbol('sent'),
  3221. /** 已送达 */
  3222. DELIVERED: Symbol('delivered'),
  3223. /** 发送失败 */
  3224. FAILED: Symbol('failed')
  3225. };
  3226. Object.freeze(MessageStatus);
  3227. var rMessageStatus = (_rMessageStatus = {}, _defineProperty(_rMessageStatus, MessageStatus.NONE, true), _defineProperty(_rMessageStatus, MessageStatus.SENDING, true), _defineProperty(_rMessageStatus, MessageStatus.SENT, true), _defineProperty(_rMessageStatus, MessageStatus.DELIVERED, true), _defineProperty(_rMessageStatus, MessageStatus.READ, true), _defineProperty(_rMessageStatus, MessageStatus.FAILED, true), _rMessageStatus);
  3228. var Message = /*#__PURE__*/function () {
  3229. /**
  3230. * @implements AVMessage
  3231. * @param {Object|String|ArrayBuffer} content 消息内容
  3232. */
  3233. function Message(content) {
  3234. Object.assign(this, {
  3235. content: content
  3236. }, {
  3237. /**
  3238. * @type {String}
  3239. * @memberof Message#
  3240. */
  3241. id: uuid(),
  3242. /**
  3243. * 消息所在的 conversation id
  3244. * @memberof Message#
  3245. * @type {String?}
  3246. */
  3247. cid: null,
  3248. /**
  3249. * 消息发送时间
  3250. * @memberof Message#
  3251. * @type {Date}
  3252. */
  3253. timestamp: new Date(),
  3254. /**
  3255. * 消息发送者
  3256. * @memberof Message#
  3257. * @type {String}
  3258. */
  3259. from: undefined,
  3260. /**
  3261. * 消息提及的用户
  3262. * @since 4.0.0
  3263. * @memberof Message#
  3264. * @type {String[]}
  3265. */
  3266. mentionList: [],
  3267. /**
  3268. * 消息是否提及了所有人
  3269. * @since 4.0.0
  3270. * @memberof Message#
  3271. * @type {Boolean}
  3272. */
  3273. mentionedAll: false,
  3274. _mentioned: false
  3275. });
  3276. this._setStatus(MessageStatus.NONE);
  3277. }
  3278. /**
  3279. * 将当前消息的内容序列化为 JSON 对象
  3280. * @private
  3281. * @return {Object}
  3282. */
  3283. var _proto = Message.prototype;
  3284. _proto.getPayload = function getPayload() {
  3285. return this.content;
  3286. };
  3287. _proto._toJSON = function _toJSON() {
  3288. var id = this.id,
  3289. cid = this.cid,
  3290. from = this.from,
  3291. timestamp = this.timestamp,
  3292. deliveredAt = this.deliveredAt,
  3293. updatedAt = this.updatedAt,
  3294. mentionList = this.mentionList,
  3295. mentionedAll = this.mentionedAll,
  3296. mentioned = this.mentioned;
  3297. return {
  3298. id: id,
  3299. cid: cid,
  3300. from: from,
  3301. timestamp: timestamp,
  3302. deliveredAt: deliveredAt,
  3303. updatedAt: updatedAt,
  3304. mentionList: mentionList,
  3305. mentionedAll: mentionedAll,
  3306. mentioned: mentioned
  3307. };
  3308. }
  3309. /**
  3310. * 返回 JSON 格式的消息
  3311. * @return {Object} 返回值是一个 plain Object
  3312. */
  3313. ;
  3314. _proto.toJSON = function toJSON() {
  3315. return _objectSpread$3(_objectSpread$3({}, this._toJSON()), {}, {
  3316. data: this.content
  3317. });
  3318. }
  3319. /**
  3320. * 返回 JSON 格式的消息,与 toJSON 不同的是,该对象包含了完整的信息,可以通过 {@link IMClient#parseMessage} 反序列化。
  3321. * @return {Object} 返回值是一个 plain Object
  3322. * @since 4.0.0
  3323. */
  3324. ;
  3325. _proto.toFullJSON = function toFullJSON() {
  3326. var content = this.content,
  3327. id = this.id,
  3328. cid = this.cid,
  3329. from = this.from,
  3330. timestamp = this.timestamp,
  3331. deliveredAt = this.deliveredAt,
  3332. _updatedAt = this._updatedAt,
  3333. mentionList = this.mentionList,
  3334. mentionedAll = this.mentionedAll;
  3335. return {
  3336. data: content,
  3337. id: id,
  3338. cid: cid,
  3339. from: from,
  3340. timestamp: getTime(timestamp),
  3341. deliveredAt: getTime(deliveredAt),
  3342. updatedAt: getTime(_updatedAt),
  3343. mentionList: mentionList,
  3344. mentionedAll: mentionedAll
  3345. };
  3346. }
  3347. /**
  3348. * 消息状态,值为 {@link module:leancloud-realtime.MessageStatus} 之一
  3349. * @type {Symbol}
  3350. * @readonly
  3351. * @since 3.2.0
  3352. */
  3353. ;
  3354. _proto._setStatus = function _setStatus(status) {
  3355. if (!rMessageStatus[status]) {
  3356. throw new Error('Invalid message status');
  3357. }
  3358. this._status = status;
  3359. };
  3360. _proto._updateMentioned = function _updateMentioned(client) {
  3361. this._mentioned = this.from !== client && (this.mentionedAll || this.mentionList.indexOf(client) > -1);
  3362. }
  3363. /**
  3364. * 获取提及用户列表
  3365. * @since 4.0.0
  3366. * @return {String[]} 提及用户的 id 列表
  3367. */
  3368. ;
  3369. _proto.getMentionList = function getMentionList() {
  3370. return this.mentionList;
  3371. }
  3372. /**
  3373. * 设置提及用户列表
  3374. * @since 4.0.0
  3375. * @param {String[]} clients 提及用户的 id 列表
  3376. * @return {this} self
  3377. */
  3378. ;
  3379. _proto.setMentionList = function setMentionList(clients) {
  3380. this.mentionList = ensureArray(clients);
  3381. return this;
  3382. }
  3383. /**
  3384. * 设置是否提及所有人
  3385. * @since 4.0.0
  3386. * @param {Boolean} [value=true]
  3387. * @return {this} self
  3388. */
  3389. ;
  3390. _proto.mentionAll = function mentionAll() {
  3391. var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  3392. this.mentionedAll = Boolean(value);
  3393. return this;
  3394. }
  3395. /**
  3396. * 判断给定的内容是否是有效的 Message,
  3397. * 该方法始终返回 true
  3398. * @private
  3399. * @returns {Boolean}
  3400. * @implements AVMessage.validate
  3401. */
  3402. ;
  3403. Message.validate = function validate() {
  3404. return true;
  3405. }
  3406. /**
  3407. * 解析处理消息内容
  3408. * <pre>
  3409. * 如果子类提供了 message,返回该 message
  3410. * 如果没有提供,将 json 作为 content 实例化一个 Message
  3411. * @private
  3412. * @param {Object} json json 格式的消息内容
  3413. * @param {Message} message 子类提供的 message
  3414. * @return {Message}
  3415. * @implements AVMessage.parse
  3416. */
  3417. ;
  3418. Message.parse = function parse(json, message) {
  3419. return message || new this(json);
  3420. };
  3421. _createClass(Message, [{
  3422. key: "status",
  3423. get: function get() {
  3424. return this._status;
  3425. }
  3426. }, {
  3427. key: "timestamp",
  3428. get: function get() {
  3429. return this._timestamp;
  3430. },
  3431. set: function set(value) {
  3432. this._timestamp = decodeDate(value);
  3433. }
  3434. /**
  3435. * 消息送达时间
  3436. * @type {?Date}
  3437. */
  3438. }, {
  3439. key: "deliveredAt",
  3440. get: function get() {
  3441. return this._deliveredAt;
  3442. },
  3443. set: function set(value) {
  3444. this._deliveredAt = decodeDate(value);
  3445. }
  3446. /**
  3447. * 消息修改或撤回时间,可以通过比较其与消息的 timestamp 是否相等判断消息是否被修改过或撤回过。
  3448. * @type {Date}
  3449. * @since 3.5.0
  3450. */
  3451. }, {
  3452. key: "updatedAt",
  3453. get: function get() {
  3454. return this._updatedAt || this.timestamp;
  3455. },
  3456. set: function set(value) {
  3457. this._updatedAt = decodeDate(value);
  3458. }
  3459. /**
  3460. * 当前用户是否在该消息中被提及
  3461. * @type {Boolean}
  3462. * @readonly
  3463. * @since 4.0.0
  3464. */
  3465. }, {
  3466. key: "mentioned",
  3467. get: function get() {
  3468. return this._mentioned;
  3469. }
  3470. }]);
  3471. return Message;
  3472. }();
  3473. /* eslint-disable no-param-reassign */
  3474. var messageType = function messageType(type) {
  3475. if (typeof type !== 'number') {
  3476. throw new TypeError("".concat(type, " is not a Number"));
  3477. }
  3478. return function (target) {
  3479. target.TYPE = type;
  3480. target.validate = function (json) {
  3481. return json._lctype === type;
  3482. };
  3483. target.prototype._getType = function () {
  3484. return {
  3485. _lctype: type
  3486. };
  3487. };
  3488. };
  3489. }; // documented in ../plugin-im.js
  3490. var messageField = function messageField(fields) {
  3491. if (typeof fields !== 'string') {
  3492. if (!Array.isArray(fields)) {
  3493. throw new TypeError("".concat(fields, " is not an Array"));
  3494. } else if (fields.some(function (value) {
  3495. return typeof value !== 'string';
  3496. })) {
  3497. throw new TypeError('fields contains non-string typed member');
  3498. }
  3499. }
  3500. return function (target) {
  3501. // IE10 Hack:
  3502. // static properties in IE10 will not be inherited from super
  3503. // search for parse method and assign it manually
  3504. var originalCustomFields = isIE10 ? getStaticProperty(target, '_customFields') : target._customFields;
  3505. originalCustomFields = Array.isArray(originalCustomFields) ? originalCustomFields : [];
  3506. target._customFields = originalCustomFields.concat(fields);
  3507. };
  3508. }; // IE10 Hack:
  3509. // static properties in IE10 will not be inherited from super
  3510. // search for parse method and assign it manually
  3511. var IE10Compatible = function IE10Compatible(target) {
  3512. if (isIE10) {
  3513. target.parse = getStaticProperty(target, 'parse');
  3514. }
  3515. };
  3516. var _dec, _class$1;
  3517. function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  3518. function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$4(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  3519. var // jsdoc-ignore-end
  3520. /**
  3521. * 所有内置的富媒体消息均继承自本类
  3522. * @extends Message
  3523. */
  3524. TypedMessage = (_dec = messageField(['_lctext', '_lcattrs']), _dec(_class$1 = /*#__PURE__*/function (_Message) {
  3525. _inheritsLoose(TypedMessage, _Message);
  3526. function TypedMessage() {
  3527. return _Message.apply(this, arguments) || this;
  3528. }
  3529. var _proto = TypedMessage.prototype;
  3530. /**
  3531. * @param {String} text
  3532. * @return {this} self
  3533. */
  3534. _proto.setText = function setText(text) {
  3535. this._lctext = text;
  3536. return this;
  3537. }
  3538. /**
  3539. * @return {String}
  3540. */
  3541. ;
  3542. _proto.getText = function getText() {
  3543. return this._lctext;
  3544. }
  3545. /**
  3546. * @param {Object} attributes
  3547. * @return {this} self
  3548. */
  3549. ;
  3550. _proto.setAttributes = function setAttributes(attributes) {
  3551. this._lcattrs = attributes;
  3552. return this;
  3553. }
  3554. /**
  3555. * @return {Object}
  3556. */
  3557. ;
  3558. _proto.getAttributes = function getAttributes() {
  3559. return this._lcattrs;
  3560. };
  3561. _proto._getCustomFields = function _getCustomFields() {
  3562. var _this = this;
  3563. var fields = Array.isArray(this.constructor._customFields) ? this.constructor._customFields : [];
  3564. return fields.reduce(function (result, field) {
  3565. if (typeof field !== 'string') return result;
  3566. result[field] = _this[field]; // eslint-disable-line no-param-reassign
  3567. return result;
  3568. }, {});
  3569. }
  3570. /* eslint-disable class-methods-use-this */
  3571. ;
  3572. _proto._getType = function _getType() {
  3573. throw new Error('not implemented');
  3574. }
  3575. /* eslint-enable class-methods-use-this */
  3576. ;
  3577. _proto.getPayload = function getPayload() {
  3578. return compact(_objectSpread$4(_objectSpread$4({
  3579. _lctext: this.getText(),
  3580. _lcattrs: this.getAttributes()
  3581. }, this._getCustomFields()), this._getType()));
  3582. };
  3583. _proto.toJSON = function toJSON() {
  3584. var type = this.type,
  3585. text = this.text,
  3586. attributes = this.attributes,
  3587. summary = this.summary;
  3588. return _objectSpread$4(_objectSpread$4({}, _Message.prototype._toJSON.call(this)), {}, {
  3589. type: type,
  3590. text: text,
  3591. attributes: attributes,
  3592. summary: summary
  3593. });
  3594. };
  3595. _proto.toFullJSON = function toFullJSON() {
  3596. return _objectSpread$4(_objectSpread$4({}, _Message.prototype.toFullJSON.call(this)), {}, {
  3597. data: this.getPayload()
  3598. });
  3599. }
  3600. /**
  3601. * 解析处理消息内容
  3602. * <pre>
  3603. * 为给定的 message 设置 text 与 attributes 属性,返回该 message
  3604. * 如果子类没有提供 message,new this()
  3605. * @protected
  3606. * @param {Object} json json 格式的消息内容
  3607. * @param {TypedMessage} message 子类提供的 message
  3608. * @return {TypedMessage}
  3609. * @implements AVMessage.parse
  3610. */
  3611. ;
  3612. TypedMessage.parse = function parse(json) {
  3613. var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new this();
  3614. message.content = json; // eslint-disable-line no-param-reassign
  3615. var customFields = isIE10 ? getStaticProperty(message.constructor, '_customFields') : message.constructor._customFields;
  3616. var fields = Array.isArray(customFields) ? customFields : [];
  3617. fields = fields.reduce(function (result, field) {
  3618. if (typeof field !== 'string') return result;
  3619. result[field] = json[field]; // eslint-disable-line no-param-reassign
  3620. return result;
  3621. }, {});
  3622. Object.assign(message, fields);
  3623. return _Message.parse.call(this, json, message);
  3624. };
  3625. _createClass(TypedMessage, [{
  3626. key: "type",
  3627. /**
  3628. * @type {Number}
  3629. * @readonly
  3630. */
  3631. get: function get() {
  3632. return this.constructor.TYPE;
  3633. }
  3634. /** @type {String} */
  3635. }, {
  3636. key: "text",
  3637. set: function set(text) {
  3638. return this.setText(text);
  3639. },
  3640. get: function get() {
  3641. return this.getText();
  3642. }
  3643. /** @type {Object} */
  3644. }, {
  3645. key: "attributes",
  3646. set: function set(attributes) {
  3647. return this.setAttributes(attributes);
  3648. },
  3649. get: function get() {
  3650. return this.getAttributes();
  3651. }
  3652. /**
  3653. * 在客户端需要以文本形式展示该消息时显示的文案,
  3654. * 如 <code>[红包] 新春快乐</code>。
  3655. * 默认值为消息的 text。
  3656. * @type {String}
  3657. * @readonly
  3658. */
  3659. }, {
  3660. key: "summary",
  3661. get: function get() {
  3662. return this.text;
  3663. }
  3664. }]);
  3665. return TypedMessage;
  3666. }(Message)) || _class$1);
  3667. var _dec$1, _class$2;
  3668. var // jsdoc-ignore-end
  3669. /**
  3670. * 已撤回类型消息,当消息被撤回时,SDK 会使用该类型的消息替代原始消息
  3671. * @extends TypedMessage
  3672. */
  3673. RecalledMessage = (_dec$1 = messageType(-127), _dec$1(_class$2 = IE10Compatible(_class$2 = /*#__PURE__*/function (_TypedMessage) {
  3674. _inheritsLoose(RecalledMessage, _TypedMessage);
  3675. function RecalledMessage() {
  3676. return _TypedMessage.apply(this, arguments) || this;
  3677. }
  3678. _createClass(RecalledMessage, [{
  3679. key: "summary",
  3680. /**
  3681. * 在客户端需要以文本形式展示该消息时显示的文案,值为 <code>[该消息已撤回]</code>
  3682. * @type {String}
  3683. * @readonly
  3684. */
  3685. // eslint-disable-next-line class-methods-use-this
  3686. get: function get() {
  3687. return '[该消息已撤回]';
  3688. }
  3689. }]);
  3690. return RecalledMessage;
  3691. }(TypedMessage)) || _class$2) || _class$2);
  3692. function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  3693. function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$5(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  3694. var debug$7 = d('LC:Conversation');
  3695. var serializeMessage = function serializeMessage(message) {
  3696. var content = message.getPayload();
  3697. var msg;
  3698. var binaryMsg;
  3699. if (content instanceof ArrayBuffer) {
  3700. binaryMsg = content;
  3701. } else if (typeof content !== 'string') {
  3702. msg = JSON.stringify(content);
  3703. } else {
  3704. msg = content;
  3705. }
  3706. return {
  3707. msg: msg,
  3708. binaryMsg: binaryMsg
  3709. };
  3710. };
  3711. var _LogsCommand$QueryDir = LogsCommand.QueryDirection,
  3712. NEW = _LogsCommand$QueryDir.NEW,
  3713. OLD = _LogsCommand$QueryDir.OLD;
  3714. /**
  3715. * 历史消息查询方向枚举
  3716. * @enum {Number}
  3717. * @since 4.0.0
  3718. * @memberof module:leancloud-realtime
  3719. */
  3720. var MessageQueryDirection = {
  3721. /** 从后向前 */
  3722. NEW_TO_OLD: OLD,
  3723. /** 从前向后 */
  3724. OLD_TO_NEW: NEW
  3725. };
  3726. Object.freeze(MessageQueryDirection);
  3727. var ConversationBase = /*#__PURE__*/function (_EventEmitter) {
  3728. _inheritsLoose(ConversationBase, _EventEmitter);
  3729. /**
  3730. * @extends EventEmitter
  3731. * @private
  3732. * @abstract
  3733. */
  3734. function ConversationBase(_ref, client) {
  3735. var _this;
  3736. var id = _ref.id,
  3737. lastMessageAt = _ref.lastMessageAt,
  3738. lastMessage = _ref.lastMessage,
  3739. lastDeliveredAt = _ref.lastDeliveredAt,
  3740. lastReadAt = _ref.lastReadAt,
  3741. _ref$unreadMessagesCo = _ref.unreadMessagesCount,
  3742. unreadMessagesCount = _ref$unreadMessagesCo === void 0 ? 0 : _ref$unreadMessagesCo,
  3743. _ref$members = _ref.members,
  3744. members = _ref$members === void 0 ? [] : _ref$members,
  3745. _ref$mentioned = _ref.mentioned,
  3746. mentioned = _ref$mentioned === void 0 ? false : _ref$mentioned,
  3747. properties = _objectWithoutProperties(_ref, ["id", "lastMessageAt", "lastMessage", "lastDeliveredAt", "lastReadAt", "unreadMessagesCount", "members", "mentioned"]);
  3748. _this = _EventEmitter.call(this) || this;
  3749. Object.assign(_assertThisInitialized(_this), _objectSpread$5({
  3750. /**
  3751. * 对话 id,对应 _Conversation 表中的 objectId
  3752. * @memberof ConversationBase#
  3753. * @type {String}
  3754. */
  3755. id: id,
  3756. /**
  3757. * 最后一条消息时间
  3758. * @memberof ConversationBase#
  3759. * @type {?Date}
  3760. */
  3761. lastMessageAt: lastMessageAt,
  3762. /**
  3763. * 最后一条消息
  3764. * @memberof ConversationBase#
  3765. * @type {?Message}
  3766. */
  3767. lastMessage: lastMessage,
  3768. /**
  3769. * 参与该对话的用户列表
  3770. * @memberof ConversationBase#
  3771. * @type {String[]}
  3772. */
  3773. members: members
  3774. }, properties));
  3775. _this.members = Array.from(new Set(_this.members));
  3776. Object.assign(internal(_assertThisInitialized(_this)), {
  3777. messagesWaitingForReceipt: {},
  3778. lastDeliveredAt: lastDeliveredAt,
  3779. lastReadAt: lastReadAt,
  3780. unreadMessagesCount: unreadMessagesCount,
  3781. mentioned: mentioned
  3782. });
  3783. _this._client = client;
  3784. if (debug$7.enabled) {
  3785. values(IMEvent).forEach(function (event) {
  3786. return _this.on(event, function () {
  3787. for (var _len = arguments.length, payload = new Array(_len), _key = 0; _key < _len; _key++) {
  3788. payload[_key] = arguments[_key];
  3789. }
  3790. return _this._debug("".concat(event, " event emitted. %o"), payload);
  3791. });
  3792. });
  3793. } // onConversationCreate hook
  3794. applyDecorators(_this._client._plugins.onConversationCreate, _assertThisInitialized(_this));
  3795. return _this;
  3796. }
  3797. /**
  3798. * 当前用户是否在该对话的未读消息中被提及
  3799. * @type {Boolean}
  3800. * @since 4.0.0
  3801. */
  3802. var _proto = ConversationBase.prototype;
  3803. _proto._setUnreadMessagesMentioned = function _setUnreadMessagesMentioned(value) {
  3804. internal(this).unreadMessagesMentioned = Boolean(value);
  3805. };
  3806. _proto._setLastDeliveredAt = function _setLastDeliveredAt(value) {
  3807. var date = decodeDate(value);
  3808. if (!(date < internal(this).lastDeliveredAt)) {
  3809. internal(this).lastDeliveredAt = date;
  3810. /**
  3811. * 最后消息送达时间更新
  3812. * @event ConversationBase#LAST_DELIVERED_AT_UPDATE
  3813. * @since 3.4.0
  3814. */
  3815. this.emit(LAST_DELIVERED_AT_UPDATE);
  3816. }
  3817. }
  3818. /**
  3819. * 最后消息被阅读时间,常用来实现发送消息的「已读」标记,可通过 {@link Conversation#fetchReceiptTimestamps} 获取或更新该属性
  3820. * @type {?Date}
  3821. * @since 3.4.0
  3822. */
  3823. ;
  3824. _proto._setLastReadAt = function _setLastReadAt(value) {
  3825. var date = decodeDate(value);
  3826. if (!(date < internal(this).lastReadAt)) {
  3827. internal(this).lastReadAt = date;
  3828. /**
  3829. * 最后消息被阅读时间更新
  3830. * @event ConversationBase#LAST_READ_AT_UPDATE
  3831. * @since 3.4.0
  3832. */
  3833. this.emit(LAST_READ_AT_UPDATE);
  3834. }
  3835. }
  3836. /**
  3837. * 返回 JSON 格式的对话,与 toJSON 不同的是,该对象包含了完整的信息,可以通过 {@link IMClient#parseConversation} 反序列化。
  3838. * @return {Object} 返回值是一个 plain Object
  3839. * @since 4.0.0
  3840. */
  3841. ;
  3842. _proto.toFullJSON = function toFullJSON() {
  3843. var id = this.id,
  3844. members = this.members,
  3845. lastMessageAt = this.lastMessageAt,
  3846. lastDeliveredAt = this.lastDeliveredAt,
  3847. lastReadAt = this.lastReadAt,
  3848. lastMessage = this.lastMessage,
  3849. unreadMessagesCount = this.unreadMessagesCount;
  3850. return {
  3851. id: id,
  3852. members: members,
  3853. lastMessageAt: getTime(lastMessageAt),
  3854. lastDeliveredAt: getTime(lastDeliveredAt),
  3855. lastReadAt: getTime(lastReadAt),
  3856. lastMessage: lastMessage ? lastMessage.toFullJSON() : undefined,
  3857. unreadMessagesCount: unreadMessagesCount
  3858. };
  3859. }
  3860. /**
  3861. * 返回 JSON 格式的对话
  3862. * @return {Object} 返回值是一个 plain Object
  3863. * @since 4.0.0
  3864. */
  3865. ;
  3866. _proto.toJSON = function toJSON() {
  3867. var id = this.id,
  3868. members = this.members,
  3869. lastMessageAt = this.lastMessageAt,
  3870. lastDeliveredAt = this.lastDeliveredAt,
  3871. lastReadAt = this.lastReadAt,
  3872. lastMessage = this.lastMessage,
  3873. unreadMessagesCount = this.unreadMessagesCount,
  3874. unreadMessagesMentioned = this.unreadMessagesMentioned;
  3875. return {
  3876. id: id,
  3877. members: members,
  3878. lastMessageAt: lastMessageAt,
  3879. lastDeliveredAt: lastDeliveredAt,
  3880. lastReadAt: lastReadAt,
  3881. lastMessage: lastMessage ? lastMessage.toJSON() : undefined,
  3882. unreadMessagesCount: unreadMessagesCount,
  3883. unreadMessagesMentioned: unreadMessagesMentioned
  3884. };
  3885. };
  3886. _proto._debug = function _debug() {
  3887. for (var _len2 = arguments.length, params = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  3888. params[_key2] = arguments[_key2];
  3889. }
  3890. debug$7.apply(void 0, params.concat(["[".concat(this.id, "]")]));
  3891. };
  3892. _proto._send = function _send(command) {
  3893. var _this$_client;
  3894. /* eslint-disable no-param-reassign */
  3895. if (command.cmd === null) {
  3896. command.cmd = 'conv';
  3897. }
  3898. if (command.cmd === 'conv' && command.convMessage === null) {
  3899. command.convMessage = new ConvCommand();
  3900. }
  3901. if (command.convMessage && command.convMessage.cid === null) {
  3902. command.convMessage.cid = this.id;
  3903. }
  3904. /* eslint-enable no-param-reassign */
  3905. for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
  3906. args[_key3 - 1] = arguments[_key3];
  3907. }
  3908. return (_this$_client = this._client)._send.apply(_this$_client, [command].concat(args));
  3909. }
  3910. /**
  3911. * 发送消息
  3912. * @param {Message} message 消息,Message 及其子类的实例
  3913. * @param {Object} [options] since v3.3.0,发送选项
  3914. * @param {Boolean} [options.transient] since v3.3.1,是否作为暂态消息发送
  3915. * @param {Boolean} [options.receipt] 是否需要回执,仅在普通对话中有效
  3916. * @param {Boolean} [options.will] since v3.4.0,是否指定该消息作为「掉线消息」发送,
  3917. * 「掉线消息」会延迟到当前用户掉线后发送,常用来实现「下线通知」功能
  3918. * @param {MessagePriority} [options.priority] 消息优先级,仅在暂态对话中有效,
  3919. * see: {@link module:leancloud-realtime.MessagePriority MessagePriority}
  3920. * @param {Object} [options.pushData] 消息对应的离线推送内容,如果消息接收方不在线,会推送指定的内容。其结构说明参见: {@link https://url.leanapp.cn/pushData 推送消息内容}
  3921. * @return {Promise.<Message>} 发送的消息
  3922. */
  3923. ;
  3924. _proto.send =
  3925. /*#__PURE__*/
  3926. function () {
  3927. var _send2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(message, options) {
  3928. var _message$constructor$, _transient, receipt, priority, pushData, will, _serializeMessage, msg, binaryMsg, command, resCommand, _resCommand$ackMessag, uid, t, code, reason, appCode;
  3929. return _regeneratorRuntime.wrap(function _callee$(_context) {
  3930. while (1) {
  3931. switch (_context.prev = _context.next) {
  3932. case 0:
  3933. this._debug(message, 'send');
  3934. if (message instanceof Message) {
  3935. _context.next = 3;
  3936. break;
  3937. }
  3938. throw new TypeError("".concat(message, " is not a Message"));
  3939. case 3:
  3940. _message$constructor$ = _objectSpread$5(_objectSpread$5(_objectSpread$5({}, message.constructor.sendOptions), typeof message.constructor.getSendOptions === 'function' ? message.constructor.getSendOptions(message) : {}), options), _transient = _message$constructor$["transient"], receipt = _message$constructor$.receipt, priority = _message$constructor$.priority, pushData = _message$constructor$.pushData, will = _message$constructor$.will;
  3941. if (receipt) {
  3942. if (this["transient"]) {
  3943. console.warn('receipt option is ignored as the conversation is transient.');
  3944. } else if (_transient) {
  3945. console.warn('receipt option is ignored as the message is sent transiently.');
  3946. } else if (this.members.length > 2) {
  3947. console.warn('receipt option is recommended to be used in one-on-one conversation.'); // eslint-disable-line max-len
  3948. }
  3949. }
  3950. if (priority && !this["transient"]) {
  3951. console.warn('priority option is ignored as the conversation is not transient.');
  3952. }
  3953. Object.assign(message, {
  3954. cid: this.id,
  3955. from: this._client.id
  3956. });
  3957. message._setStatus(MessageStatus.SENDING);
  3958. _serializeMessage = serializeMessage(message), msg = _serializeMessage.msg, binaryMsg = _serializeMessage.binaryMsg;
  3959. command = new GenericCommand({
  3960. cmd: 'direct',
  3961. directMessage: new DirectCommand({
  3962. msg: msg,
  3963. binaryMsg: binaryMsg,
  3964. cid: this.id,
  3965. r: receipt,
  3966. "transient": _transient,
  3967. dt: message.id,
  3968. pushData: JSON.stringify(pushData),
  3969. will: will,
  3970. mentionPids: message.mentionList,
  3971. mentionAll: message.mentionedAll
  3972. }),
  3973. priority: priority
  3974. });
  3975. _context.prev = 10;
  3976. _context.next = 13;
  3977. return this._send(command);
  3978. case 13:
  3979. resCommand = _context.sent;
  3980. _resCommand$ackMessag = resCommand.ackMessage, uid = _resCommand$ackMessag.uid, t = _resCommand$ackMessag.t, code = _resCommand$ackMessag.code, reason = _resCommand$ackMessag.reason, appCode = _resCommand$ackMessag.appCode;
  3981. if (!(code !== null)) {
  3982. _context.next = 17;
  3983. break;
  3984. }
  3985. throw createError({
  3986. code: code,
  3987. reason: reason,
  3988. appCode: appCode
  3989. });
  3990. case 17:
  3991. Object.assign(message, {
  3992. id: uid,
  3993. timestamp: t
  3994. });
  3995. if (!_transient) {
  3996. this.lastMessage = message;
  3997. this.lastMessageAt = message.timestamp;
  3998. }
  3999. message._setStatus(MessageStatus.SENT);
  4000. if (receipt) {
  4001. internal(this).messagesWaitingForReceipt[message.id] = message;
  4002. }
  4003. return _context.abrupt("return", message);
  4004. case 24:
  4005. _context.prev = 24;
  4006. _context.t0 = _context["catch"](10);
  4007. message._setStatus(MessageStatus.FAILED);
  4008. throw _context.t0;
  4009. case 28:
  4010. case "end":
  4011. return _context.stop();
  4012. }
  4013. }
  4014. }, _callee, this, [[10, 24]]);
  4015. }));
  4016. function send(_x, _x2) {
  4017. return _send2.apply(this, arguments);
  4018. }
  4019. return send;
  4020. }();
  4021. _proto._update = /*#__PURE__*/function () {
  4022. var _update2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(message, newMessage, recall) {
  4023. var msg, binaryMsg, content, id, cid, timestamp, from, _status;
  4024. return _regeneratorRuntime.wrap(function _callee2$(_context2) {
  4025. while (1) {
  4026. switch (_context2.prev = _context2.next) {
  4027. case 0:
  4028. this._debug('patch %O %O %O', message, newMessage, recall);
  4029. if (!(message instanceof Message)) {
  4030. _context2.next = 8;
  4031. break;
  4032. }
  4033. if (!(message.from !== this._client.id)) {
  4034. _context2.next = 4;
  4035. break;
  4036. }
  4037. throw new Error('Updating message from others is not allowed');
  4038. case 4:
  4039. if (!(message.status !== MessageStatus.SENT && message.status !== MessageStatus.DELIVERED)) {
  4040. _context2.next = 6;
  4041. break;
  4042. }
  4043. throw new Error('Message is not sent');
  4044. case 6:
  4045. _context2.next = 10;
  4046. break;
  4047. case 8:
  4048. if (message.id && message.timestamp) {
  4049. _context2.next = 10;
  4050. break;
  4051. }
  4052. throw new TypeError("".concat(message, " is not a Message"));
  4053. case 10:
  4054. if (!recall) {
  4055. content = serializeMessage(newMessage);
  4056. msg = content.msg;
  4057. binaryMsg = content.binaryMsg;
  4058. }
  4059. _context2.next = 13;
  4060. return this._send(new GenericCommand({
  4061. cmd: CommandType.patch,
  4062. op: OpType.modify,
  4063. patchMessage: new PatchCommand({
  4064. patches: [new PatchItem({
  4065. cid: this.id,
  4066. mid: message.id,
  4067. timestamp: Number(message.timestamp),
  4068. recall: recall,
  4069. data: msg,
  4070. binaryMsg: binaryMsg,
  4071. mentionPids: newMessage.mentionList,
  4072. mentionAll: newMessage.mentionedAll
  4073. })],
  4074. lastPatchTime: this._client._lastPatchTime
  4075. })
  4076. }));
  4077. case 13:
  4078. id = message.id, cid = message.cid, timestamp = message.timestamp, from = message.from, _status = message._status;
  4079. Object.assign(newMessage, {
  4080. id: id,
  4081. cid: cid,
  4082. timestamp: timestamp,
  4083. from: from,
  4084. _status: _status
  4085. });
  4086. if (this.lastMessage && this.lastMessage.id === newMessage.id) {
  4087. this.lastMessage = newMessage;
  4088. }
  4089. return _context2.abrupt("return", newMessage);
  4090. case 17:
  4091. case "end":
  4092. return _context2.stop();
  4093. }
  4094. }
  4095. }, _callee2, this);
  4096. }));
  4097. function _update(_x3, _x4, _x5) {
  4098. return _update2.apply(this, arguments);
  4099. }
  4100. return _update;
  4101. }()
  4102. /**
  4103. * 获取对话人数,或暂态对话的在线人数
  4104. * @return {Promise.<Number>}
  4105. */
  4106. ;
  4107. _proto.count =
  4108. /*#__PURE__*/
  4109. function () {
  4110. var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
  4111. var resCommand;
  4112. return _regeneratorRuntime.wrap(function _callee3$(_context3) {
  4113. while (1) {
  4114. switch (_context3.prev = _context3.next) {
  4115. case 0:
  4116. this._debug('count');
  4117. _context3.next = 3;
  4118. return this._send(new GenericCommand({
  4119. op: 'count'
  4120. }));
  4121. case 3:
  4122. resCommand = _context3.sent;
  4123. return _context3.abrupt("return", resCommand.convMessage.count);
  4124. case 5:
  4125. case "end":
  4126. return _context3.stop();
  4127. }
  4128. }
  4129. }, _callee3, this);
  4130. }));
  4131. function count() {
  4132. return _count.apply(this, arguments);
  4133. }
  4134. return count;
  4135. }()
  4136. /**
  4137. * 应用增加成员的操作,产生副作用
  4138. * @param {string[]} members
  4139. * @abstract
  4140. * @private
  4141. */
  4142. ;
  4143. _proto._addMembers = function _addMembers() {}
  4144. /**
  4145. * 应用减少成员的操作,产生副作用
  4146. * @param {string[]} members
  4147. * @abstract
  4148. * @private
  4149. */
  4150. ;
  4151. _proto._removeMembers = function _removeMembers() {}
  4152. /**
  4153. * 修改已发送的消息
  4154. * @param {AVMessage} message 要修改的消息,该消息必须是由当前用户发送的。也可以提供一个包含消息 {id, timestamp} 的对象
  4155. * @param {AVMessage} newMessage 新的消息
  4156. * @return {Promise.<AVMessage>} 更新后的消息
  4157. */
  4158. ;
  4159. _proto.update =
  4160. /*#__PURE__*/
  4161. function () {
  4162. var _update3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(message, newMessage) {
  4163. return _regeneratorRuntime.wrap(function _callee4$(_context4) {
  4164. while (1) {
  4165. switch (_context4.prev = _context4.next) {
  4166. case 0:
  4167. if (newMessage instanceof Message) {
  4168. _context4.next = 2;
  4169. break;
  4170. }
  4171. throw new TypeError("".concat(newMessage, " is not a Message"));
  4172. case 2:
  4173. return _context4.abrupt("return", this._update(message, newMessage, false));
  4174. case 3:
  4175. case "end":
  4176. return _context4.stop();
  4177. }
  4178. }
  4179. }, _callee4, this);
  4180. }));
  4181. function update(_x6, _x7) {
  4182. return _update3.apply(this, arguments);
  4183. }
  4184. return update;
  4185. }()
  4186. /**
  4187. * 撤回已发送的消息
  4188. * @param {AVMessage} message 要撤回的消息,该消息必须是由当前用户发送的。也可以提供一个包含消息 {id, timestamp} 的对象
  4189. * @return {Promise.<RecalledMessage>} 一条已撤回的消息
  4190. */
  4191. ;
  4192. _proto.recall =
  4193. /*#__PURE__*/
  4194. function () {
  4195. var _recall = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(message) {
  4196. return _regeneratorRuntime.wrap(function _callee5$(_context5) {
  4197. while (1) {
  4198. switch (_context5.prev = _context5.next) {
  4199. case 0:
  4200. return _context5.abrupt("return", this._update(message, new RecalledMessage(), true));
  4201. case 1:
  4202. case "end":
  4203. return _context5.stop();
  4204. }
  4205. }
  4206. }, _callee5, this);
  4207. }));
  4208. function recall(_x8) {
  4209. return _recall.apply(this, arguments);
  4210. }
  4211. return recall;
  4212. }()
  4213. /**
  4214. * 查询消息记录
  4215. * 如果仅需实现消息向前记录翻页查询需求,建议使用 {@link Conversation#createMessagesIterator}。
  4216. * 不论何种方向,获得的消息都是按照时间升序排列的。
  4217. * startClosed 与 endClosed 用于指定查询区间的开闭。
  4218. *
  4219. * @param {Object} [options]
  4220. * @param {Number} [options.limit] 限制查询结果的数量,目前服务端默认为 20
  4221. * @param {Number} [options.type] 指定查询的富媒体消息类型,不指定则查询所有消息。
  4222. * @param {MessageQueryDirection} [options.direction] 查询的方向。
  4223. * 在不指定的情况下如果 startTime 大于 endTime,则为从新到旧查询,可以实现加载聊天记录等场景。
  4224. * 如果 startTime 小于 endTime,则为从旧到新查询,可以实现弹幕等场景。
  4225. * @param {Date} [options.startTime] 从该时间开始查询,不传则从当前时间开始查询
  4226. * @param {String} [options.startMessageId] 从该消息之前开始查询,需要与 startTime 同时使用,为防止某时刻有重复消息
  4227. * @param {Boolean}[options.startClosed] 指定查询范围是否包括开始的时间点,默认不包括
  4228. * @param {Date} [options.endTime] 查询到该时间为止,不传则查询最早消息为止
  4229. * @param {String} [options.endMessageId] 查询到该消息为止,需要与 endTime 同时使用,为防止某时刻有重复消息
  4230. * @param {Boolean}[options.endClosed] 指定查询范围是否包括结束的时间点,默认不包括
  4231. *
  4232. * @param {Date} [options.beforeTime] DEPRECATED: 使用 startTime 代替。限制查询结果为小于该时间之前的消息,不传则为当前时间
  4233. * @param {String} [options.beforeMessageId] DEPRECATED: 使用 startMessageId 代替。
  4234. * 限制查询结果为该消息之前的消息,需要与 beforeTime 同时使用,为防止某时刻有重复消息
  4235. * @param {Date} [options.afterTime] DEPRECATED: 使用 endTime 代替。限制查询结果为大于该时间之前的消息
  4236. * @param {String} [options.afterMessageId] DEPRECATED: 使用 endMessageId 代替。
  4237. * 限制查询结果为该消息之后的消息,需要与 afterTime 同时使用,为防止某时刻有重复消息
  4238. * @return {Promise.<Message[]>} 消息列表
  4239. */
  4240. ;
  4241. _proto.queryMessages =
  4242. /*#__PURE__*/
  4243. function () {
  4244. var _queryMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
  4245. var _this2 = this;
  4246. var options,
  4247. beforeTime,
  4248. beforeMessageId,
  4249. afterTime,
  4250. afterMessageId,
  4251. limit,
  4252. direction,
  4253. type,
  4254. startTime,
  4255. startMessageId,
  4256. startClosed,
  4257. endTime,
  4258. endMessageId,
  4259. endClosed,
  4260. conditions,
  4261. resCommand,
  4262. _args7 = arguments;
  4263. return _regeneratorRuntime.wrap(function _callee7$(_context7) {
  4264. while (1) {
  4265. switch (_context7.prev = _context7.next) {
  4266. case 0:
  4267. options = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
  4268. this._debug('query messages %O', options);
  4269. beforeTime = options.beforeTime, beforeMessageId = options.beforeMessageId, afterTime = options.afterTime, afterMessageId = options.afterMessageId, limit = options.limit, direction = options.direction, type = options.type, startTime = options.startTime, startMessageId = options.startMessageId, startClosed = options.startClosed, endTime = options.endTime, endMessageId = options.endMessageId, endClosed = options.endClosed;
  4270. if (!(beforeMessageId || beforeTime || afterMessageId || afterTime)) {
  4271. _context7.next = 6;
  4272. break;
  4273. }
  4274. console.warn('DEPRECATION: queryMessages options beforeTime, beforeMessageId, afterTime and afterMessageId are deprecated in favor of startTime, startMessageId, endTime and endMessageId.');
  4275. return _context7.abrupt("return", this.queryMessages({
  4276. startTime: beforeTime,
  4277. startMessageId: beforeMessageId,
  4278. endTime: afterTime,
  4279. endMessageId: afterMessageId,
  4280. limit: limit
  4281. }));
  4282. case 6:
  4283. if (!(startMessageId && !startTime)) {
  4284. _context7.next = 8;
  4285. break;
  4286. }
  4287. throw new Error('query option startMessageId must be used with option startTime');
  4288. case 8:
  4289. if (!(endMessageId && !endTime)) {
  4290. _context7.next = 10;
  4291. break;
  4292. }
  4293. throw new Error('query option endMessageId must be used with option endTime');
  4294. case 10:
  4295. conditions = {
  4296. t: startTime,
  4297. mid: startMessageId,
  4298. tIncluded: startClosed,
  4299. tt: endTime,
  4300. tmid: endMessageId,
  4301. ttIncluded: endClosed,
  4302. l: limit,
  4303. lctype: type
  4304. };
  4305. if (conditions.t instanceof Date) {
  4306. conditions.t = conditions.t.getTime();
  4307. }
  4308. if (conditions.tt instanceof Date) {
  4309. conditions.tt = conditions.tt.getTime();
  4310. }
  4311. if (direction !== undefined) {
  4312. conditions.direction = direction;
  4313. } else if (conditions.tt > conditions.t) {
  4314. conditions.direction = MessageQueryDirection.OLD_TO_NEW;
  4315. }
  4316. _context7.next = 16;
  4317. return this._send(new GenericCommand({
  4318. cmd: 'logs',
  4319. logsMessage: new LogsCommand(Object.assign(conditions, {
  4320. cid: this.id
  4321. }))
  4322. }));
  4323. case 16:
  4324. resCommand = _context7.sent;
  4325. return _context7.abrupt("return", Promise.all(resCommand.logsMessage.logs.map( /*#__PURE__*/function () {
  4326. var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref2) {
  4327. var msgId, timestamp, patchTimestamp, from, ackAt, readAt, data, mentionAll, mentionPids, bin, messageData, message, status;
  4328. return _regeneratorRuntime.wrap(function _callee6$(_context6) {
  4329. while (1) {
  4330. switch (_context6.prev = _context6.next) {
  4331. case 0:
  4332. msgId = _ref2.msgId, timestamp = _ref2.timestamp, patchTimestamp = _ref2.patchTimestamp, from = _ref2.from, ackAt = _ref2.ackAt, readAt = _ref2.readAt, data = _ref2.data, mentionAll = _ref2.mentionAll, mentionPids = _ref2.mentionPids, bin = _ref2.bin;
  4333. messageData = {
  4334. data: data,
  4335. bin: bin,
  4336. id: msgId,
  4337. cid: _this2.id,
  4338. timestamp: timestamp,
  4339. from: from,
  4340. deliveredAt: ackAt,
  4341. updatedAt: patchTimestamp,
  4342. mentionList: mentionPids,
  4343. mentionedAll: mentionAll
  4344. };
  4345. _context6.next = 4;
  4346. return _this2._client.parseMessage(messageData);
  4347. case 4:
  4348. message = _context6.sent;
  4349. status = MessageStatus.SENT;
  4350. if (_this2.members.length === 2) {
  4351. if (ackAt) status = MessageStatus.DELIVERED;
  4352. if (ackAt) _this2._setLastDeliveredAt(ackAt);
  4353. if (readAt) _this2._setLastReadAt(readAt);
  4354. }
  4355. message._setStatus(status);
  4356. return _context6.abrupt("return", message);
  4357. case 9:
  4358. case "end":
  4359. return _context6.stop();
  4360. }
  4361. }
  4362. }, _callee6);
  4363. }));
  4364. return function (_x9) {
  4365. return _ref3.apply(this, arguments);
  4366. };
  4367. }())));
  4368. case 18:
  4369. case "end":
  4370. return _context7.stop();
  4371. }
  4372. }
  4373. }, _callee7, this);
  4374. }));
  4375. function queryMessages() {
  4376. return _queryMessages.apply(this, arguments);
  4377. }
  4378. return queryMessages;
  4379. }()
  4380. /**
  4381. * 获取消息翻页迭代器
  4382. * @param {Object} [options]
  4383. * @param {Date} [options.beforeTime] 限制起始查询结果为小于该时间之前的消息,不传则为当前时间
  4384. * @param {String} [options.beforeMessageId] 限制起始查询结果为该消息之前的消息,需要与 beforeTime 同时使用,为防止某时刻有重复消息
  4385. * @param {Number} [options.limit] 限制每页查询结果的数量,目前服务端默认为 20
  4386. * @return {AsyncIterater.<Promise.<IteratorResult<Message[]>>>} [AsyncIterator]{@link https://github.com/tc39/proposal-async-iteration},调用其 next 方法返回获取下一页消息的 Promise
  4387. * @example
  4388. * var messageIterator = conversation.createMessagesIterator({ limit: 10 });
  4389. * messageIterator.next().then(function(result) {
  4390. * // result: {
  4391. * // value: [message1, ..., message10],
  4392. * // done: false,
  4393. * // }
  4394. * });
  4395. * messageIterator.next().then(function(result) {
  4396. * // result: {
  4397. * // value: [message11, ..., message20],
  4398. * // done: false,
  4399. * // }
  4400. * });
  4401. * messageIterator.next().then(function(result) {
  4402. * // No more messages
  4403. * // result: { value: [], done: true }
  4404. * });
  4405. */
  4406. ;
  4407. _proto.createMessagesIterator = function createMessagesIterator() {
  4408. var _this3 = this;
  4409. var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  4410. beforeTime = _ref4.beforeTime,
  4411. beforeMessageId = _ref4.beforeMessageId,
  4412. limit = _ref4.limit;
  4413. var promise;
  4414. return {
  4415. next: function next() {
  4416. if (promise === undefined) {
  4417. // first call
  4418. promise = _this3.queryMessages({
  4419. limit: limit,
  4420. startTime: beforeTime,
  4421. startMessageId: beforeMessageId
  4422. });
  4423. } else {
  4424. promise = promise.then(function (prevMessages) {
  4425. if (prevMessages.length === 0 || prevMessages.length < limit) {
  4426. // no more messages
  4427. return [];
  4428. }
  4429. return _this3.queryMessages({
  4430. startTime: prevMessages[0].timestamp,
  4431. startMessageId: prevMessages[0].id,
  4432. limit: limit
  4433. });
  4434. });
  4435. }
  4436. return promise.then(function (value) {
  4437. return {
  4438. value: Array.from(value),
  4439. done: value.length === 0 || value.length < limit
  4440. };
  4441. });
  4442. }
  4443. };
  4444. }
  4445. /**
  4446. * 将该会话标记为已读
  4447. * @return {Promise.<this>} self
  4448. */
  4449. ;
  4450. _proto.read =
  4451. /*#__PURE__*/
  4452. function () {
  4453. var _read = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
  4454. var client;
  4455. return _regeneratorRuntime.wrap(function _callee8$(_context8) {
  4456. while (1) {
  4457. switch (_context8.prev = _context8.next) {
  4458. case 0:
  4459. this.unreadMessagesCount = 0;
  4460. this._setUnreadMessagesMentioned(false); // 跳过暂态会话
  4461. if (!this["transient"]) {
  4462. _context8.next = 4;
  4463. break;
  4464. }
  4465. return _context8.abrupt("return", this);
  4466. case 4:
  4467. client = this._client;
  4468. if (!internal(client).readConversationsBuffer) {
  4469. internal(client).readConversationsBuffer = new Set();
  4470. }
  4471. internal(client).readConversationsBuffer.add(this);
  4472. client._doSendRead();
  4473. return _context8.abrupt("return", this);
  4474. case 9:
  4475. case "end":
  4476. return _context8.stop();
  4477. }
  4478. }
  4479. }, _callee8, this);
  4480. }));
  4481. function read() {
  4482. return _read.apply(this, arguments);
  4483. }
  4484. return read;
  4485. }();
  4486. _proto._handleReceipt = function _handleReceipt(_ref5) {
  4487. var messageId = _ref5.messageId,
  4488. timestamp = _ref5.timestamp,
  4489. read = _ref5.read;
  4490. if (read) {
  4491. this._setLastReadAt(timestamp);
  4492. } else {
  4493. this._setLastDeliveredAt(timestamp);
  4494. }
  4495. var _internal = internal(this),
  4496. messagesWaitingForReceipt = _internal.messagesWaitingForReceipt;
  4497. var message = messagesWaitingForReceipt[messageId];
  4498. if (!message) return;
  4499. message._setStatus(MessageStatus.DELIVERED);
  4500. message.deliveredAt = timestamp;
  4501. delete messagesWaitingForReceipt[messageId];
  4502. }
  4503. /**
  4504. * 更新对话的最新回执时间戳(lastDeliveredAt、lastReadAt)
  4505. * @since 3.4.0
  4506. * @return {Promise.<this>} this
  4507. */
  4508. ;
  4509. _proto.fetchReceiptTimestamps =
  4510. /*#__PURE__*/
  4511. function () {
  4512. var _fetchReceiptTimestamps = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
  4513. var _yield$this$_send, _yield$this$_send$con, maxReadTimestamp, maxAckTimestamp;
  4514. return _regeneratorRuntime.wrap(function _callee9$(_context9) {
  4515. while (1) {
  4516. switch (_context9.prev = _context9.next) {
  4517. case 0:
  4518. if (!(this["transient"] || this.system)) {
  4519. _context9.next = 2;
  4520. break;
  4521. }
  4522. return _context9.abrupt("return", this);
  4523. case 2:
  4524. _context9.next = 4;
  4525. return this._send(new GenericCommand({
  4526. op: 'max_read'
  4527. }));
  4528. case 4:
  4529. _yield$this$_send = _context9.sent;
  4530. _yield$this$_send$con = _yield$this$_send.convMessage;
  4531. maxReadTimestamp = _yield$this$_send$con.maxReadTimestamp;
  4532. maxAckTimestamp = _yield$this$_send$con.maxAckTimestamp;
  4533. this._setLastDeliveredAt(maxAckTimestamp);
  4534. this._setLastReadAt(maxReadTimestamp);
  4535. return _context9.abrupt("return", this);
  4536. case 11:
  4537. case "end":
  4538. return _context9.stop();
  4539. }
  4540. }
  4541. }, _callee9, this);
  4542. }));
  4543. function fetchReceiptTimestamps() {
  4544. return _fetchReceiptTimestamps.apply(this, arguments);
  4545. }
  4546. return fetchReceiptTimestamps;
  4547. }();
  4548. _proto._fetchAllReceiptTimestamps = function _fetchAllReceiptTimestamps() {
  4549. // 暂态/系统会话不支持回执
  4550. if (this["transient"] || this.system) return this;
  4551. var convMessage = new ConvCommand({
  4552. queryAllMembers: true
  4553. });
  4554. return this._send(new GenericCommand({
  4555. op: 'max_read',
  4556. convMessage: convMessage
  4557. })).then(function (_ref6) {
  4558. var maxReadTuples = _ref6.convMessage.maxReadTuples;
  4559. return maxReadTuples.filter(function (maxReadTuple) {
  4560. return maxReadTuple.maxAckTimestamp || maxReadTuple.maxReadTimestamp;
  4561. }).map(function (_ref7) {
  4562. var pid = _ref7.pid,
  4563. maxAckTimestamp = _ref7.maxAckTimestamp,
  4564. maxReadTimestamp = _ref7.maxReadTimestamp;
  4565. return {
  4566. pid: pid,
  4567. lastDeliveredAt: decodeDate(maxAckTimestamp),
  4568. lastReadAt: decodeDate(maxReadTimestamp)
  4569. };
  4570. });
  4571. });
  4572. };
  4573. _createClass(ConversationBase, [{
  4574. key: "unreadMessagesMentioned",
  4575. get: function get() {
  4576. return internal(this).unreadMessagesMentioned;
  4577. }
  4578. }, {
  4579. key: "unreadMessagesCount",
  4580. set: function set(value) {
  4581. if (value !== this.unreadMessagesCount) {
  4582. internal(this).unreadMessagesCount = value;
  4583. this._client.emit(UNREAD_MESSAGES_COUNT_UPDATE, [this]);
  4584. }
  4585. }
  4586. /**
  4587. * 当前用户在该对话的未读消息数
  4588. * @type {Number}
  4589. */
  4590. ,
  4591. get: function get() {
  4592. return internal(this).unreadMessagesCount;
  4593. }
  4594. }, {
  4595. key: "lastMessageAt",
  4596. set: function set(value) {
  4597. var time = decodeDate(value);
  4598. if (time <= this._lastMessageAt) return;
  4599. this._lastMessageAt = time;
  4600. },
  4601. get: function get() {
  4602. return this._lastMessageAt;
  4603. }
  4604. /**
  4605. * 最后消息送达时间,常用来实现消息的「已送达」标记,可通过 {@link Conversation#fetchReceiptTimestamps} 获取或更新该属性
  4606. * @type {?Date}
  4607. * @since 3.4.0
  4608. */
  4609. }, {
  4610. key: "lastDeliveredAt",
  4611. get: function get() {
  4612. if (this.members.length !== 2) return null;
  4613. return internal(this).lastDeliveredAt;
  4614. }
  4615. }, {
  4616. key: "lastReadAt",
  4617. get: function get() {
  4618. if (this.members.length !== 2) return null;
  4619. return internal(this).lastReadAt;
  4620. }
  4621. }]);
  4622. return ConversationBase;
  4623. }(EventEmitter);
  4624. var debug$8 = d('LC:SignatureFactoryRunner');
  4625. function _validateSignature() {
  4626. var signatureResult = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  4627. var signature = signatureResult.signature,
  4628. timestamp = signatureResult.timestamp,
  4629. nonce = signatureResult.nonce;
  4630. if (typeof signature !== 'string' || typeof timestamp !== 'number' || typeof nonce !== 'string') {
  4631. throw new Error('malformed signature');
  4632. }
  4633. return {
  4634. signature: signature,
  4635. timestamp: timestamp,
  4636. nonce: nonce
  4637. };
  4638. }
  4639. var runSignatureFactory = (function (signatureFactory, params) {
  4640. return Promise.resolve().then(function () {
  4641. debug$8('call signatureFactory with %O', params);
  4642. return signatureFactory.apply(void 0, _toConsumableArray(params));
  4643. }).then(tap(function (signatureResult) {
  4644. return debug$8('sign result %O', signatureResult);
  4645. }), function (error) {
  4646. // eslint-disable-next-line no-param-reassign
  4647. error.message = "sign error: ".concat(error.message);
  4648. debug$8(error);
  4649. throw error;
  4650. }).then(_validateSignature);
  4651. });
  4652. function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  4653. function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$6(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  4654. /**
  4655. * 部分失败异常
  4656. * @typedef OperationFailureError
  4657. * @type {Error}
  4658. * @property {string} message 异常信息
  4659. * @property {string[]} clientIds 因为该原因失败的 client id 列表
  4660. * @property {number} [code] 错误码
  4661. * @property {string} [detail] 详细信息
  4662. */
  4663. /**
  4664. * 部分成功的结果
  4665. * @typedef PartiallySuccess
  4666. * @type {Object}
  4667. * @property {string[]} successfulClientIds 成功的 client id 列表
  4668. * @property {OperationFailureError[]} failures 失败的异常列表
  4669. */
  4670. /**
  4671. * 分页查询结果
  4672. * @typedef PagedResults
  4673. * @type {Object}
  4674. * @property {T[]} results 查询结果
  4675. * @property {string} [next] 存在表示还有更多结果,在下次查询中带上可实现翻页。
  4676. */
  4677. var createPartiallySuccess = function createPartiallySuccess(_ref) {
  4678. var allowedPids = _ref.allowedPids,
  4679. failedPids = _ref.failedPids;
  4680. return {
  4681. successfulClientIds: allowedPids,
  4682. failures: failedPids.map(function (_ref2) {
  4683. var pids = _ref2.pids,
  4684. error = _objectWithoutProperties(_ref2, ["pids"]);
  4685. return Object.assign(createError(error), {
  4686. clientIds: pids
  4687. });
  4688. })
  4689. };
  4690. };
  4691. /**
  4692. * @extends ConversationBase
  4693. * @private
  4694. * @abstract
  4695. */
  4696. var PersistentConversation = /*#__PURE__*/function (_ConversationBase) {
  4697. _inheritsLoose(PersistentConversation, _ConversationBase);
  4698. function PersistentConversation(data, _ref3, client) {
  4699. var _this;
  4700. var creator = _ref3.creator,
  4701. createdAt = _ref3.createdAt,
  4702. updatedAt = _ref3.updatedAt,
  4703. _ref3$transient = _ref3["transient"],
  4704. _transient = _ref3$transient === void 0 ? false : _ref3$transient,
  4705. _ref3$system = _ref3.system,
  4706. system = _ref3$system === void 0 ? false : _ref3$system,
  4707. _ref3$muted = _ref3.muted,
  4708. muted = _ref3$muted === void 0 ? false : _ref3$muted,
  4709. _ref3$mutedMembers = _ref3.mutedMembers,
  4710. mutedMembers = _ref3$mutedMembers === void 0 ? [] : _ref3$mutedMembers,
  4711. attributes = _objectWithoutProperties(_ref3, ["creator", "createdAt", "updatedAt", "transient", "system", "muted", "mutedMembers"]);
  4712. _this = _ConversationBase.call(this, _objectSpread$6(_objectSpread$6({}, data), {}, {
  4713. /**
  4714. * 对话创建者
  4715. * @memberof PersistentConversation#
  4716. * @type {String}
  4717. */
  4718. creator: creator,
  4719. /**
  4720. * 对话创建时间
  4721. * @memberof PersistentConversation#
  4722. * @type {Date}
  4723. */
  4724. createdAt: createdAt,
  4725. /**
  4726. * 对话更新时间
  4727. * @memberof PersistentConversation#
  4728. * @type {Date}
  4729. */
  4730. updatedAt: updatedAt,
  4731. /**
  4732. * 对该对话设置了静音的用户列表
  4733. * @memberof PersistentConversation#
  4734. * @type {?String[]}
  4735. */
  4736. mutedMembers: mutedMembers,
  4737. /**
  4738. * 暂态对话标记
  4739. * @memberof PersistentConversation#
  4740. * @type {Boolean}
  4741. */
  4742. "transient": _transient,
  4743. /**
  4744. * 系统对话标记
  4745. * @memberof PersistentConversation#
  4746. * @type {Boolean}
  4747. * @since 3.3.0
  4748. */
  4749. system: system,
  4750. /**
  4751. * 当前用户静音该对话标记
  4752. * @memberof PersistentConversation#
  4753. * @type {Boolean}
  4754. */
  4755. muted: muted,
  4756. _attributes: attributes
  4757. }), client) || this;
  4758. _this._reset();
  4759. return _this;
  4760. }
  4761. var _proto = PersistentConversation.prototype;
  4762. /**
  4763. * 获取对话的自定义属性
  4764. * @since 3.2.0
  4765. * @param {String} key key 属性的键名,'x' 对应 Conversation 表中的 x 列
  4766. * @return {Any} 属性的值
  4767. */
  4768. _proto.get = function get(key) {
  4769. return _get(internal(this).currentAttributes, key);
  4770. }
  4771. /**
  4772. * 设置对话的自定义属性
  4773. * @since 3.2.0
  4774. * @param {String} key 属性的键名,'x' 对应 Conversation 表中的 x 列,支持使用 'x.y.z' 来修改对象的部分字段。
  4775. * @param {Any} value 属性的值
  4776. * @return {this} self
  4777. * @example
  4778. *
  4779. * // 设置对话的 color 属性
  4780. * conversation.set('color', {
  4781. * text: '#000',
  4782. * background: '#DDD',
  4783. * });
  4784. * // 设置对话的 color.text 属性
  4785. * conversation.set('color.text', '#333');
  4786. */
  4787. ;
  4788. _proto.set = function set(key, value) {
  4789. this._debug("set [".concat(key, "]: ").concat(value));
  4790. var _internal = internal(this),
  4791. pendingAttributes = _internal.pendingAttributes;
  4792. var pendingKeys = Object.keys(pendingAttributes); // suppose pendingAttributes = { 'a.b': {} }
  4793. // set 'a' or 'a.b': delete 'a.b'
  4794. var re = new RegExp("^".concat(key));
  4795. var childKeys = pendingKeys.filter(re.test.bind(re));
  4796. childKeys.forEach(function (k) {
  4797. delete pendingAttributes[k];
  4798. });
  4799. if (childKeys.length) {
  4800. pendingAttributes[key] = value;
  4801. } else {
  4802. // set 'a.c': nothing to do
  4803. // set 'a.b.c.d': assign c: { d: {} } to 'a.b'
  4804. var parentKey = find(pendingKeys, function (k) {
  4805. return key.indexOf(k) === 0;
  4806. }); // 'a.b'
  4807. if (parentKey) {
  4808. setValue(pendingAttributes[parentKey], key.slice(parentKey.length + 1), value);
  4809. } else {
  4810. pendingAttributes[key] = value;
  4811. }
  4812. }
  4813. this._buildCurrentAttributes();
  4814. return this;
  4815. };
  4816. _proto._buildCurrentAttributes = function _buildCurrentAttributes() {
  4817. var _internal2 = internal(this),
  4818. pendingAttributes = _internal2.pendingAttributes;
  4819. internal(this).currentAttributes = Object.keys(pendingAttributes).reduce(function (target, k) {
  4820. return setValue(target, k, pendingAttributes[k]);
  4821. }, cloneDeep(this._attributes));
  4822. };
  4823. _proto._updateServerAttributes = function _updateServerAttributes(attributes) {
  4824. var _this2 = this;
  4825. Object.keys(attributes).forEach(function (key) {
  4826. return setValue(_this2._attributes, key, attributes[key]);
  4827. });
  4828. this._buildCurrentAttributes();
  4829. };
  4830. _proto._reset = function _reset() {
  4831. Object.assign(internal(this), {
  4832. pendingAttributes: {},
  4833. currentAttributes: this._attributes
  4834. });
  4835. }
  4836. /**
  4837. * 保存当前对话的属性至服务器
  4838. * @return {Promise.<this>} self
  4839. */
  4840. ;
  4841. _proto.save =
  4842. /*#__PURE__*/
  4843. function () {
  4844. var _save = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
  4845. var attr, convMessage, resCommand;
  4846. return _regeneratorRuntime.wrap(function _callee$(_context) {
  4847. while (1) {
  4848. switch (_context.prev = _context.next) {
  4849. case 0:
  4850. this._debug('save');
  4851. attr = internal(this).pendingAttributes;
  4852. if (!isEmpty(attr)) {
  4853. _context.next = 5;
  4854. break;
  4855. }
  4856. this._debug('nothing touched, resolve with self');
  4857. return _context.abrupt("return", this);
  4858. case 5:
  4859. this._debug('attr: %O', attr);
  4860. convMessage = new ConvCommand({
  4861. attr: new JsonObjectMessage({
  4862. data: JSON.stringify(encode(attr))
  4863. })
  4864. });
  4865. _context.next = 9;
  4866. return this._send(new GenericCommand({
  4867. op: 'update',
  4868. convMessage: convMessage
  4869. }));
  4870. case 9:
  4871. resCommand = _context.sent;
  4872. this.updatedAt = resCommand.convMessage.udate;
  4873. this._attributes = internal(this).currentAttributes;
  4874. internal(this).pendingAttributes = {};
  4875. return _context.abrupt("return", this);
  4876. case 14:
  4877. case "end":
  4878. return _context.stop();
  4879. }
  4880. }
  4881. }, _callee, this);
  4882. }));
  4883. function save() {
  4884. return _save.apply(this, arguments);
  4885. }
  4886. return save;
  4887. }()
  4888. /**
  4889. * 从服务器更新对话的属性
  4890. * @return {Promise.<this>} self
  4891. */
  4892. ;
  4893. _proto.fetch =
  4894. /*#__PURE__*/
  4895. function () {
  4896. var _fetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
  4897. var query;
  4898. return _regeneratorRuntime.wrap(function _callee2$(_context2) {
  4899. while (1) {
  4900. switch (_context2.prev = _context2.next) {
  4901. case 0:
  4902. query = this._client.getQuery().equalTo('objectId', this.id);
  4903. _context2.next = 3;
  4904. return query.find();
  4905. case 3:
  4906. return _context2.abrupt("return", this);
  4907. case 4:
  4908. case "end":
  4909. return _context2.stop();
  4910. }
  4911. }
  4912. }, _callee2, this);
  4913. }));
  4914. function fetch() {
  4915. return _fetch.apply(this, arguments);
  4916. }
  4917. return fetch;
  4918. }()
  4919. /**
  4920. * 静音,客户端拒绝收到服务器端的离线推送通知
  4921. * @return {Promise.<this>} self
  4922. */
  4923. ;
  4924. _proto.mute =
  4925. /*#__PURE__*/
  4926. function () {
  4927. var _mute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
  4928. return _regeneratorRuntime.wrap(function _callee3$(_context3) {
  4929. while (1) {
  4930. switch (_context3.prev = _context3.next) {
  4931. case 0:
  4932. this._debug('mute');
  4933. _context3.next = 3;
  4934. return this._send(new GenericCommand({
  4935. op: 'mute'
  4936. }));
  4937. case 3:
  4938. if (!this["transient"]) {
  4939. this.muted = true;
  4940. this.mutedMembers = union(this.mutedMembers, [this._client.id]);
  4941. }
  4942. return _context3.abrupt("return", this);
  4943. case 5:
  4944. case "end":
  4945. return _context3.stop();
  4946. }
  4947. }
  4948. }, _callee3, this);
  4949. }));
  4950. function mute() {
  4951. return _mute.apply(this, arguments);
  4952. }
  4953. return mute;
  4954. }()
  4955. /**
  4956. * 取消静音
  4957. * @return {Promise.<this>} self
  4958. */
  4959. ;
  4960. _proto.unmute =
  4961. /*#__PURE__*/
  4962. function () {
  4963. var _unmute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
  4964. return _regeneratorRuntime.wrap(function _callee4$(_context4) {
  4965. while (1) {
  4966. switch (_context4.prev = _context4.next) {
  4967. case 0:
  4968. this._debug('unmute');
  4969. _context4.next = 3;
  4970. return this._send(new GenericCommand({
  4971. op: 'unmute'
  4972. }));
  4973. case 3:
  4974. if (!this["transient"]) {
  4975. this.muted = false;
  4976. this.mutedMembers = difference(this.mutedMembers, [this._client.id]);
  4977. }
  4978. return _context4.abrupt("return", this);
  4979. case 5:
  4980. case "end":
  4981. return _context4.stop();
  4982. }
  4983. }
  4984. }, _callee4, this);
  4985. }));
  4986. function unmute() {
  4987. return _unmute.apply(this, arguments);
  4988. }
  4989. return unmute;
  4990. }();
  4991. _proto._appendConversationSignature = /*#__PURE__*/function () {
  4992. var _appendConversationSignature2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(command, action, clientIds) {
  4993. var params, signatureResult;
  4994. return _regeneratorRuntime.wrap(function _callee5$(_context5) {
  4995. while (1) {
  4996. switch (_context5.prev = _context5.next) {
  4997. case 0:
  4998. if (!this._client.options.conversationSignatureFactory) {
  4999. _context5.next = 6;
  5000. break;
  5001. }
  5002. params = [this.id, this._client.id, clientIds.sort(), action];
  5003. _context5.next = 4;
  5004. return runSignatureFactory(this._client.options.conversationSignatureFactory, params);
  5005. case 4:
  5006. signatureResult = _context5.sent;
  5007. Object.assign(command.convMessage, keyRemap({
  5008. signature: 's',
  5009. timestamp: 't',
  5010. nonce: 'n'
  5011. }, signatureResult));
  5012. case 6:
  5013. case "end":
  5014. return _context5.stop();
  5015. }
  5016. }
  5017. }, _callee5, this);
  5018. }));
  5019. function _appendConversationSignature(_x, _x2, _x3) {
  5020. return _appendConversationSignature2.apply(this, arguments);
  5021. }
  5022. return _appendConversationSignature;
  5023. }();
  5024. _proto._appendBlacklistSignature = /*#__PURE__*/function () {
  5025. var _appendBlacklistSignature2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(command, action, clientIds) {
  5026. var params, signatureResult;
  5027. return _regeneratorRuntime.wrap(function _callee6$(_context6) {
  5028. while (1) {
  5029. switch (_context6.prev = _context6.next) {
  5030. case 0:
  5031. if (!this._client.options.blacklistSignatureFactory) {
  5032. _context6.next = 6;
  5033. break;
  5034. }
  5035. params = [this.id, this._client.id, clientIds.sort(), action];
  5036. _context6.next = 4;
  5037. return runSignatureFactory(this._client.options.blacklistSignatureFactory, params);
  5038. case 4:
  5039. signatureResult = _context6.sent;
  5040. Object.assign(command.blacklistMessage, keyRemap({
  5041. signature: 's',
  5042. timestamp: 't',
  5043. nonce: 'n'
  5044. }, signatureResult));
  5045. case 6:
  5046. case "end":
  5047. return _context6.stop();
  5048. }
  5049. }
  5050. }, _callee6, this);
  5051. }));
  5052. function _appendBlacklistSignature(_x4, _x5, _x6) {
  5053. return _appendBlacklistSignature2.apply(this, arguments);
  5054. }
  5055. return _appendBlacklistSignature;
  5056. }()
  5057. /**
  5058. * 增加成员
  5059. * @param {String|String[]} clientIds 新增成员 client id
  5060. * @return {Promise.<PartiallySuccess>} 部分成功结果,包含了成功的 id 列表、失败原因与对应的 id 列表
  5061. */
  5062. ;
  5063. _proto.add =
  5064. /*#__PURE__*/
  5065. function () {
  5066. var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(clientIds) {
  5067. var command, _yield$this$_send, convMessage, allowedPids;
  5068. return _regeneratorRuntime.wrap(function _callee7$(_context7) {
  5069. while (1) {
  5070. switch (_context7.prev = _context7.next) {
  5071. case 0:
  5072. this._debug('add', clientIds);
  5073. if (typeof clientIds === 'string') {
  5074. clientIds = [clientIds]; // eslint-disable-line no-param-reassign
  5075. }
  5076. command = new GenericCommand({
  5077. op: 'add',
  5078. convMessage: new ConvCommand({
  5079. m: clientIds
  5080. })
  5081. });
  5082. _context7.next = 5;
  5083. return this._appendConversationSignature(command, 'invite', clientIds);
  5084. case 5:
  5085. _context7.next = 7;
  5086. return this._send(command);
  5087. case 7:
  5088. _yield$this$_send = _context7.sent;
  5089. convMessage = _yield$this$_send.convMessage;
  5090. allowedPids = _yield$this$_send.convMessage.allowedPids;
  5091. this._addMembers(allowedPids);
  5092. return _context7.abrupt("return", createPartiallySuccess(convMessage));
  5093. case 12:
  5094. case "end":
  5095. return _context7.stop();
  5096. }
  5097. }
  5098. }, _callee7, this);
  5099. }));
  5100. function add(_x7) {
  5101. return _add.apply(this, arguments);
  5102. }
  5103. return add;
  5104. }()
  5105. /**
  5106. * 剔除成员
  5107. * @param {String|String[]} clientIds 成员 client id
  5108. * @return {Promise.<PartiallySuccess>} 部分成功结果,包含了成功的 id 列表、失败原因与对应的 id 列表
  5109. */
  5110. ;
  5111. _proto.remove =
  5112. /*#__PURE__*/
  5113. function () {
  5114. var _remove = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(clientIds) {
  5115. var command, _yield$this$_send2, convMessage, allowedPids;
  5116. return _regeneratorRuntime.wrap(function _callee8$(_context8) {
  5117. while (1) {
  5118. switch (_context8.prev = _context8.next) {
  5119. case 0:
  5120. this._debug('remove', clientIds);
  5121. if (typeof clientIds === 'string') {
  5122. clientIds = [clientIds]; // eslint-disable-line no-param-reassign
  5123. }
  5124. command = new GenericCommand({
  5125. op: 'remove',
  5126. convMessage: new ConvCommand({
  5127. m: clientIds
  5128. })
  5129. });
  5130. _context8.next = 5;
  5131. return this._appendConversationSignature(command, 'kick', clientIds);
  5132. case 5:
  5133. _context8.next = 7;
  5134. return this._send(command);
  5135. case 7:
  5136. _yield$this$_send2 = _context8.sent;
  5137. convMessage = _yield$this$_send2.convMessage;
  5138. allowedPids = _yield$this$_send2.convMessage.allowedPids;
  5139. this._removeMembers(allowedPids);
  5140. return _context8.abrupt("return", createPartiallySuccess(convMessage));
  5141. case 12:
  5142. case "end":
  5143. return _context8.stop();
  5144. }
  5145. }
  5146. }, _callee8, this);
  5147. }));
  5148. function remove(_x8) {
  5149. return _remove.apply(this, arguments);
  5150. }
  5151. return remove;
  5152. }()
  5153. /**
  5154. * (当前用户)加入该对话
  5155. * @return {Promise.<this>} self
  5156. */
  5157. ;
  5158. _proto.join =
  5159. /*#__PURE__*/
  5160. function () {
  5161. var _join = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
  5162. var _this3 = this;
  5163. return _regeneratorRuntime.wrap(function _callee9$(_context9) {
  5164. while (1) {
  5165. switch (_context9.prev = _context9.next) {
  5166. case 0:
  5167. this._debug('join');
  5168. return _context9.abrupt("return", this.add(this._client.id).then(function (_ref4) {
  5169. var failures = _ref4.failures;
  5170. if (failures[0]) throw failures[0];
  5171. return _this3;
  5172. }));
  5173. case 2:
  5174. case "end":
  5175. return _context9.stop();
  5176. }
  5177. }
  5178. }, _callee9, this);
  5179. }));
  5180. function join() {
  5181. return _join.apply(this, arguments);
  5182. }
  5183. return join;
  5184. }()
  5185. /**
  5186. * (当前用户)退出该对话
  5187. * @return {Promise.<this>} self
  5188. */
  5189. ;
  5190. _proto.quit =
  5191. /*#__PURE__*/
  5192. function () {
  5193. var _quit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
  5194. var _this4 = this;
  5195. return _regeneratorRuntime.wrap(function _callee10$(_context10) {
  5196. while (1) {
  5197. switch (_context10.prev = _context10.next) {
  5198. case 0:
  5199. this._debug('quit');
  5200. return _context10.abrupt("return", this.remove(this._client.id).then(function (_ref5) {
  5201. var failures = _ref5.failures;
  5202. if (failures[0]) throw failures[0];
  5203. return _this4;
  5204. }));
  5205. case 2:
  5206. case "end":
  5207. return _context10.stop();
  5208. }
  5209. }
  5210. }, _callee10, this);
  5211. }));
  5212. function quit() {
  5213. return _quit.apply(this, arguments);
  5214. }
  5215. return quit;
  5216. }()
  5217. /**
  5218. * 在该对话中禁言成员
  5219. * @param {String|String[]} clientIds 成员 client id
  5220. * @return {Promise.<PartiallySuccess>} 部分成功结果,包含了成功的 id 列表、失败原因与对应的 id 列表
  5221. */
  5222. ;
  5223. _proto.muteMembers =
  5224. /*#__PURE__*/
  5225. function () {
  5226. var _muteMembers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(clientIds) {
  5227. var command, _yield$this$_send3, convMessage;
  5228. return _regeneratorRuntime.wrap(function _callee11$(_context11) {
  5229. while (1) {
  5230. switch (_context11.prev = _context11.next) {
  5231. case 0:
  5232. this._debug('mute', clientIds);
  5233. clientIds = ensureArray(clientIds); // eslint-disable-line no-param-reassign
  5234. command = new GenericCommand({
  5235. op: OpType.add_shutup,
  5236. convMessage: new ConvCommand({
  5237. m: clientIds
  5238. })
  5239. });
  5240. _context11.next = 5;
  5241. return this._send(command);
  5242. case 5:
  5243. _yield$this$_send3 = _context11.sent;
  5244. convMessage = _yield$this$_send3.convMessage;
  5245. return _context11.abrupt("return", createPartiallySuccess(convMessage));
  5246. case 8:
  5247. case "end":
  5248. return _context11.stop();
  5249. }
  5250. }
  5251. }, _callee11, this);
  5252. }));
  5253. function muteMembers(_x9) {
  5254. return _muteMembers.apply(this, arguments);
  5255. }
  5256. return muteMembers;
  5257. }()
  5258. /**
  5259. * 在该对话中解除成员禁言
  5260. * @param {String|String[]} clientIds 成员 client id
  5261. * @return {Promise.<PartiallySuccess>} 部分成功结果,包含了成功的 id 列表、失败原因与对应的 id 列表
  5262. */
  5263. ;
  5264. _proto.unmuteMembers =
  5265. /*#__PURE__*/
  5266. function () {
  5267. var _unmuteMembers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(clientIds) {
  5268. var command, _yield$this$_send4, convMessage;
  5269. return _regeneratorRuntime.wrap(function _callee12$(_context12) {
  5270. while (1) {
  5271. switch (_context12.prev = _context12.next) {
  5272. case 0:
  5273. this._debug('unmute', clientIds);
  5274. clientIds = ensureArray(clientIds); // eslint-disable-line no-param-reassign
  5275. command = new GenericCommand({
  5276. op: OpType.remove_shutup,
  5277. convMessage: new ConvCommand({
  5278. m: clientIds
  5279. })
  5280. });
  5281. _context12.next = 5;
  5282. return this._send(command);
  5283. case 5:
  5284. _yield$this$_send4 = _context12.sent;
  5285. convMessage = _yield$this$_send4.convMessage;
  5286. return _context12.abrupt("return", createPartiallySuccess(convMessage));
  5287. case 8:
  5288. case "end":
  5289. return _context12.stop();
  5290. }
  5291. }
  5292. }, _callee12, this);
  5293. }));
  5294. function unmuteMembers(_x10) {
  5295. return _unmuteMembers.apply(this, arguments);
  5296. }
  5297. return unmuteMembers;
  5298. }()
  5299. /**
  5300. * 查询该对话禁言成员列表
  5301. * @param {Object} [options]
  5302. * @param {Number} [options.limit] 返回的成员数量,服务器默认值 10
  5303. * @param {String} [options.next] 从指定 next 开始查询,与 limit 一起使用可以完成翻页。
  5304. * @return {PagedResults.<string>} 查询结果。其中的 cureser 存在表示还有更多结果。
  5305. */
  5306. ;
  5307. _proto.queryMutedMembers =
  5308. /*#__PURE__*/
  5309. function () {
  5310. var _queryMutedMembers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
  5311. var _ref6,
  5312. limit,
  5313. next,
  5314. command,
  5315. _yield$this$_send5,
  5316. _yield$this$_send5$co,
  5317. m,
  5318. newNext,
  5319. _args13 = arguments;
  5320. return _regeneratorRuntime.wrap(function _callee13$(_context13) {
  5321. while (1) {
  5322. switch (_context13.prev = _context13.next) {
  5323. case 0:
  5324. _ref6 = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {}, limit = _ref6.limit, next = _ref6.next;
  5325. this._debug('query muted: limit %O, next: %O', limit, next);
  5326. command = new GenericCommand({
  5327. op: OpType.query_shutup,
  5328. convMessage: new ConvCommand({
  5329. limit: limit,
  5330. next: next
  5331. })
  5332. });
  5333. _context13.next = 5;
  5334. return this._send(command);
  5335. case 5:
  5336. _yield$this$_send5 = _context13.sent;
  5337. _yield$this$_send5$co = _yield$this$_send5.convMessage;
  5338. m = _yield$this$_send5$co.m;
  5339. newNext = _yield$this$_send5$co.next;
  5340. return _context13.abrupt("return", {
  5341. results: m,
  5342. next: newNext
  5343. });
  5344. case 10:
  5345. case "end":
  5346. return _context13.stop();
  5347. }
  5348. }
  5349. }, _callee13, this);
  5350. }));
  5351. function queryMutedMembers() {
  5352. return _queryMutedMembers.apply(this, arguments);
  5353. }
  5354. return queryMutedMembers;
  5355. }()
  5356. /**
  5357. * 将用户加入该对话黑名单
  5358. * @param {String|String[]} clientIds 成员 client id
  5359. * @return {Promise.<PartiallySuccess>} 部分成功结果,包含了成功的 id 列表、失败原因与对应的 id 列表
  5360. */
  5361. ;
  5362. _proto.blockMembers =
  5363. /*#__PURE__*/
  5364. function () {
  5365. var _blockMembers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(clientIds) {
  5366. var command, _yield$this$_send6, blacklistMessage;
  5367. return _regeneratorRuntime.wrap(function _callee14$(_context14) {
  5368. while (1) {
  5369. switch (_context14.prev = _context14.next) {
  5370. case 0:
  5371. this._debug('block', clientIds);
  5372. clientIds = ensureArray(clientIds); // eslint-disable-line no-param-reassign
  5373. command = new GenericCommand({
  5374. cmd: 'blacklist',
  5375. op: OpType.block,
  5376. blacklistMessage: new BlacklistCommand({
  5377. srcCid: this.id,
  5378. toPids: clientIds
  5379. })
  5380. });
  5381. _context14.next = 5;
  5382. return this._appendBlacklistSignature(command, 'conversation-block-clients', clientIds);
  5383. case 5:
  5384. _context14.next = 7;
  5385. return this._send(command);
  5386. case 7:
  5387. _yield$this$_send6 = _context14.sent;
  5388. blacklistMessage = _yield$this$_send6.blacklistMessage;
  5389. return _context14.abrupt("return", createPartiallySuccess(blacklistMessage));
  5390. case 10:
  5391. case "end":
  5392. return _context14.stop();
  5393. }
  5394. }
  5395. }, _callee14, this);
  5396. }));
  5397. function blockMembers(_x11) {
  5398. return _blockMembers.apply(this, arguments);
  5399. }
  5400. return blockMembers;
  5401. }()
  5402. /**
  5403. * 将用户移出该对话黑名单
  5404. * @param {String|String[]} clientIds 成员 client id
  5405. * @return {Promise.<PartiallySuccess>} 部分成功结果,包含了成功的 id 列表、失败原因与对应的 id 列表
  5406. */
  5407. ;
  5408. _proto.unblockMembers =
  5409. /*#__PURE__*/
  5410. function () {
  5411. var _unblockMembers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(clientIds) {
  5412. var command, _yield$this$_send7, blacklistMessage;
  5413. return _regeneratorRuntime.wrap(function _callee15$(_context15) {
  5414. while (1) {
  5415. switch (_context15.prev = _context15.next) {
  5416. case 0:
  5417. this._debug('unblock', clientIds);
  5418. clientIds = ensureArray(clientIds); // eslint-disable-line no-param-reassign
  5419. command = new GenericCommand({
  5420. cmd: 'blacklist',
  5421. op: OpType.unblock,
  5422. blacklistMessage: new BlacklistCommand({
  5423. srcCid: this.id,
  5424. toPids: clientIds
  5425. })
  5426. });
  5427. _context15.next = 5;
  5428. return this._appendBlacklistSignature(command, 'conversation-unblock-clients', clientIds);
  5429. case 5:
  5430. _context15.next = 7;
  5431. return this._send(command);
  5432. case 7:
  5433. _yield$this$_send7 = _context15.sent;
  5434. blacklistMessage = _yield$this$_send7.blacklistMessage;
  5435. return _context15.abrupt("return", createPartiallySuccess(blacklistMessage));
  5436. case 10:
  5437. case "end":
  5438. return _context15.stop();
  5439. }
  5440. }
  5441. }, _callee15, this);
  5442. }));
  5443. function unblockMembers(_x12) {
  5444. return _unblockMembers.apply(this, arguments);
  5445. }
  5446. return unblockMembers;
  5447. }()
  5448. /**
  5449. * 查询该对话黑名单
  5450. * @param {Object} [options]
  5451. * @param {Number} [options.limit] 返回的成员数量,服务器默认值 10
  5452. * @param {String} [options.next] 从指定 next 开始查询,与 limit 一起使用可以完成翻页
  5453. * @return {PagedResults.<string>} 查询结果。其中的 cureser 存在表示还有更多结果。
  5454. */
  5455. ;
  5456. _proto.queryBlockedMembers =
  5457. /*#__PURE__*/
  5458. function () {
  5459. var _queryBlockedMembers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
  5460. var _ref7,
  5461. limit,
  5462. next,
  5463. command,
  5464. _yield$this$_send8,
  5465. _yield$this$_send8$bl,
  5466. blockedPids,
  5467. newNext,
  5468. _args16 = arguments;
  5469. return _regeneratorRuntime.wrap(function _callee16$(_context16) {
  5470. while (1) {
  5471. switch (_context16.prev = _context16.next) {
  5472. case 0:
  5473. _ref7 = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {}, limit = _ref7.limit, next = _ref7.next;
  5474. this._debug('query blocked: limit %O, next: %O', limit, next);
  5475. command = new GenericCommand({
  5476. cmd: 'blacklist',
  5477. op: OpType.query,
  5478. blacklistMessage: new BlacklistCommand({
  5479. srcCid: this.id,
  5480. limit: limit,
  5481. next: next
  5482. })
  5483. });
  5484. _context16.next = 5;
  5485. return this._send(command);
  5486. case 5:
  5487. _yield$this$_send8 = _context16.sent;
  5488. _yield$this$_send8$bl = _yield$this$_send8.blacklistMessage;
  5489. blockedPids = _yield$this$_send8$bl.blockedPids;
  5490. newNext = _yield$this$_send8$bl.next;
  5491. return _context16.abrupt("return", {
  5492. results: blockedPids,
  5493. next: newNext
  5494. });
  5495. case 10:
  5496. case "end":
  5497. return _context16.stop();
  5498. }
  5499. }
  5500. }, _callee16, this);
  5501. }));
  5502. function queryBlockedMembers() {
  5503. return _queryBlockedMembers.apply(this, arguments);
  5504. }
  5505. return queryBlockedMembers;
  5506. }();
  5507. _proto.toFullJSON = function toFullJSON() {
  5508. var creator = this.creator,
  5509. system = this.system,
  5510. _transient2 = this["transient"],
  5511. createdAt = this.createdAt,
  5512. updatedAt = this.updatedAt,
  5513. _attributes = this._attributes;
  5514. return _objectSpread$6(_objectSpread$6({}, _ConversationBase.prototype.toFullJSON.call(this)), {}, {
  5515. creator: creator,
  5516. system: system,
  5517. "transient": _transient2,
  5518. createdAt: getTime(createdAt),
  5519. updatedAt: getTime(updatedAt)
  5520. }, _attributes);
  5521. };
  5522. _proto.toJSON = function toJSON() {
  5523. var creator = this.creator,
  5524. system = this.system,
  5525. _transient3 = this["transient"],
  5526. muted = this.muted,
  5527. mutedMembers = this.mutedMembers,
  5528. createdAt = this.createdAt,
  5529. updatedAt = this.updatedAt,
  5530. _attributes = this._attributes;
  5531. return _objectSpread$6(_objectSpread$6({}, _ConversationBase.prototype.toJSON.call(this)), {}, {
  5532. creator: creator,
  5533. system: system,
  5534. "transient": _transient3,
  5535. muted: muted,
  5536. mutedMembers: mutedMembers,
  5537. createdAt: createdAt,
  5538. updatedAt: updatedAt
  5539. }, _attributes);
  5540. };
  5541. _createClass(PersistentConversation, [{
  5542. key: "createdAt",
  5543. set: function set(value) {
  5544. this._createdAt = decodeDate(value);
  5545. },
  5546. get: function get() {
  5547. return this._createdAt;
  5548. }
  5549. }, {
  5550. key: "updatedAt",
  5551. set: function set(value) {
  5552. this._updatedAt = decodeDate(value);
  5553. },
  5554. get: function get() {
  5555. return this._updatedAt;
  5556. }
  5557. /**
  5558. * 对话名字,对应 _Conversation 表中的 name
  5559. * @type {String}
  5560. */
  5561. }, {
  5562. key: "name",
  5563. get: function get() {
  5564. return this.get('name');
  5565. },
  5566. set: function set(value) {
  5567. this.set('name', value);
  5568. }
  5569. }]);
  5570. return PersistentConversation;
  5571. }(ConversationBase);
  5572. /**
  5573. * 对话成员角色枚举
  5574. * @enum {String}
  5575. * @since 4.0.0
  5576. * @memberof module:leancloud-realtime
  5577. */
  5578. var ConversationMemberRole = {
  5579. /** 所有者 */
  5580. OWNER: 'Owner',
  5581. /** 管理员 */
  5582. MANAGER: 'Manager',
  5583. /** 成员 */
  5584. MEMBER: 'Member'
  5585. };
  5586. Object.freeze(ConversationMemberRole);
  5587. var ConversationMemberInfo = /*#__PURE__*/function () {
  5588. /**
  5589. * 对话成员属性,保存了成员与某个对话相关的属性,对应 _ConversationMemberInfo 表
  5590. * @since 4.0.0
  5591. */
  5592. function ConversationMemberInfo(_ref) {
  5593. var conversation = _ref.conversation,
  5594. memberId = _ref.memberId,
  5595. role = _ref.role;
  5596. if (!conversation) throw new Error('conversation requried');
  5597. if (!memberId) throw new Error('memberId requried');
  5598. Object.assign(internal(this), {
  5599. conversation: conversation,
  5600. memberId: memberId,
  5601. role: role
  5602. });
  5603. }
  5604. /**
  5605. * 对话 Id
  5606. * @type {String}
  5607. * @readonly
  5608. */
  5609. var _proto = ConversationMemberInfo.prototype;
  5610. _proto.toJSON = function toJSON() {
  5611. var conversationId = this.conversationId,
  5612. memberId = this.memberId,
  5613. role = this.role,
  5614. isOwner = this.isOwner;
  5615. return {
  5616. conversationId: conversationId,
  5617. memberId: memberId,
  5618. role: role,
  5619. isOwner: isOwner
  5620. };
  5621. };
  5622. _createClass(ConversationMemberInfo, [{
  5623. key: "conversationId",
  5624. get: function get() {
  5625. return internal(this).conversation.id;
  5626. }
  5627. /**
  5628. * 成员 Id
  5629. * @type {String}
  5630. * @readonly
  5631. */
  5632. }, {
  5633. key: "memberId",
  5634. get: function get() {
  5635. return internal(this).memberId;
  5636. }
  5637. /**
  5638. * 角色
  5639. * @type {module:leancloud-realtime.ConversationMemberRole | String}
  5640. * @readonly
  5641. */
  5642. }, {
  5643. key: "role",
  5644. get: function get() {
  5645. if (this.isOwner) return ConversationMemberRole.OWNER;
  5646. return internal(this).role;
  5647. }
  5648. /**
  5649. * 是否是管理员
  5650. * @type {Boolean}
  5651. * @readonly
  5652. */
  5653. }, {
  5654. key: "isOwner",
  5655. get: function get() {
  5656. return this.memberId === internal(this).conversation.creator;
  5657. }
  5658. }]);
  5659. return ConversationMemberInfo;
  5660. }();
  5661. /**
  5662. * 普通对话
  5663. *
  5664. * 无法直接实例化,请使用 {@link IMClient#createConversation} 创建新的普通对话。
  5665. * @extends PersistentConversation
  5666. * @public
  5667. */
  5668. var Conversation = /*#__PURE__*/function (_PersistentConversati) {
  5669. _inheritsLoose(Conversation, _PersistentConversati);
  5670. function Conversation() {
  5671. return _PersistentConversati.apply(this, arguments) || this;
  5672. }
  5673. var _proto = Conversation.prototype;
  5674. _proto._addMembers = function _addMembers(members) {
  5675. var _this = this;
  5676. _PersistentConversati.prototype._addMembers.call(this, members);
  5677. this.members = union(this.members, members);
  5678. var _internal = internal(this),
  5679. memberInfoMap = _internal.memberInfoMap;
  5680. if (!memberInfoMap) return;
  5681. members.forEach(function (memberId) {
  5682. memberInfoMap[memberId] = memberInfoMap[memberId] || new ConversationMemberInfo({
  5683. conversation: _this,
  5684. memberId: memberId,
  5685. role: ConversationMemberRole.MEMBER
  5686. });
  5687. });
  5688. };
  5689. _proto._removeMembers = function _removeMembers(members) {
  5690. _PersistentConversati.prototype._removeMembers.call(this, members);
  5691. this.members = difference(this.members, members);
  5692. var _internal2 = internal(this),
  5693. memberInfoMap = _internal2.memberInfoMap;
  5694. if (!memberInfoMap) return;
  5695. members.forEach(function (memberId) {
  5696. delete memberInfoMap[memberId];
  5697. });
  5698. };
  5699. _proto._fetchAllMemberInfo = /*#__PURE__*/function () {
  5700. var _fetchAllMemberInfo2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
  5701. var _this2 = this;
  5702. var response, memberInfos, memberInfoMap;
  5703. return _regeneratorRuntime.wrap(function _callee$(_context) {
  5704. while (1) {
  5705. switch (_context.prev = _context.next) {
  5706. case 0:
  5707. _context.next = 2;
  5708. return this._client._requestWithSessionToken({
  5709. method: 'GET',
  5710. path: '/classes/_ConversationMemberInfo',
  5711. query: {
  5712. where: {
  5713. cid: this.id
  5714. }
  5715. }
  5716. });
  5717. case 2:
  5718. response = _context.sent;
  5719. memberInfos = response.results.map(function (info) {
  5720. return new ConversationMemberInfo({
  5721. conversation: _this2,
  5722. memberId: info.clientId,
  5723. role: info.role
  5724. });
  5725. });
  5726. memberInfoMap = {};
  5727. memberInfos.forEach(function (memberInfo) {
  5728. memberInfoMap[memberInfo.memberId] = memberInfo;
  5729. });
  5730. this.members.forEach(function (memberId) {
  5731. memberInfoMap[memberId] = memberInfoMap[memberId] || new ConversationMemberInfo({
  5732. conversation: _this2,
  5733. memberId: memberId,
  5734. role: ConversationMemberRole.MEMBER
  5735. });
  5736. });
  5737. internal(this).memberInfoMap = memberInfoMap;
  5738. return _context.abrupt("return", memberInfoMap);
  5739. case 9:
  5740. case "end":
  5741. return _context.stop();
  5742. }
  5743. }
  5744. }, _callee, this);
  5745. }));
  5746. function _fetchAllMemberInfo() {
  5747. return _fetchAllMemberInfo2.apply(this, arguments);
  5748. }
  5749. return _fetchAllMemberInfo;
  5750. }()
  5751. /**
  5752. * 获取所有成员的对话属性
  5753. * @since 4.0.0
  5754. * @return {Promise.<ConversationMemberInfo[]>} 所有成员的对话属性列表
  5755. */
  5756. ;
  5757. _proto.getAllMemberInfo =
  5758. /*#__PURE__*/
  5759. function () {
  5760. var _getAllMemberInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
  5761. var _ref,
  5762. _ref$noCache,
  5763. noCache,
  5764. _internal3,
  5765. memberInfoMap,
  5766. _args2 = arguments;
  5767. return _regeneratorRuntime.wrap(function _callee2$(_context2) {
  5768. while (1) {
  5769. switch (_context2.prev = _context2.next) {
  5770. case 0:
  5771. _ref = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref$noCache = _ref.noCache, noCache = _ref$noCache === void 0 ? false : _ref$noCache;
  5772. _internal3 = internal(this), memberInfoMap = _internal3.memberInfoMap;
  5773. if (!(!memberInfoMap || noCache)) {
  5774. _context2.next = 6;
  5775. break;
  5776. }
  5777. _context2.next = 5;
  5778. return this._fetchAllMemberInfo();
  5779. case 5:
  5780. memberInfoMap = _context2.sent;
  5781. case 6:
  5782. return _context2.abrupt("return", this.members.map(function (memberId) {
  5783. return memberInfoMap[memberId];
  5784. }));
  5785. case 7:
  5786. case "end":
  5787. return _context2.stop();
  5788. }
  5789. }
  5790. }, _callee2, this);
  5791. }));
  5792. function getAllMemberInfo() {
  5793. return _getAllMemberInfo.apply(this, arguments);
  5794. }
  5795. return getAllMemberInfo;
  5796. }()
  5797. /**
  5798. * 获取指定成员的对话属性
  5799. * @since 4.0.0
  5800. * @param {String} memberId 成员 Id
  5801. * @return {Promise.<ConversationMemberInfo>} 指定成员的对话属性
  5802. */
  5803. ;
  5804. _proto.getMemberInfo =
  5805. /*#__PURE__*/
  5806. function () {
  5807. var _getMemberInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(memberId) {
  5808. var _internal4, memberInfoMap;
  5809. return _regeneratorRuntime.wrap(function _callee3$(_context3) {
  5810. while (1) {
  5811. switch (_context3.prev = _context3.next) {
  5812. case 0:
  5813. if (!(this.members.indexOf(memberId) === -1)) {
  5814. _context3.next = 2;
  5815. break;
  5816. }
  5817. throw new Error("".concat(memberId, " is not the mumber of conversation[").concat(this.id, "]"));
  5818. case 2:
  5819. _internal4 = internal(this), memberInfoMap = _internal4.memberInfoMap;
  5820. if (memberInfoMap && memberInfoMap[memberId]) {
  5821. _context3.next = 6;
  5822. break;
  5823. }
  5824. _context3.next = 6;
  5825. return this.getAllMemberInfo();
  5826. case 6:
  5827. return _context3.abrupt("return", internal(this).memberInfoMap[memberId]);
  5828. case 7:
  5829. case "end":
  5830. return _context3.stop();
  5831. }
  5832. }
  5833. }, _callee3, this);
  5834. }));
  5835. function getMemberInfo(_x) {
  5836. return _getMemberInfo.apply(this, arguments);
  5837. }
  5838. return getMemberInfo;
  5839. }()
  5840. /**
  5841. * 更新指定用户的角色
  5842. * @since 4.0.0
  5843. * @param {String} memberId 成员 Id
  5844. * @param {module:leancloud-realtime.ConversationMemberRole | String} role 角色
  5845. * @return {Promise.<this>} self
  5846. */
  5847. ;
  5848. _proto.updateMemberRole =
  5849. /*#__PURE__*/
  5850. function () {
  5851. var _updateMemberRole = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(memberId, role) {
  5852. var _internal5, memberInfos;
  5853. return _regeneratorRuntime.wrap(function _callee4$(_context4) {
  5854. while (1) {
  5855. switch (_context4.prev = _context4.next) {
  5856. case 0:
  5857. this._debug('update member role');
  5858. if (!(role === ConversationMemberRole.OWNER)) {
  5859. _context4.next = 3;
  5860. break;
  5861. }
  5862. throw createError({
  5863. code: ErrorCode.OWNER_PROMOTION_NOT_ALLOWED
  5864. });
  5865. case 3:
  5866. _context4.next = 5;
  5867. return this._send(new GenericCommand({
  5868. op: OpType.member_info_update,
  5869. convMessage: new ConvCommand({
  5870. targetClientId: memberId,
  5871. info: new ConvMemberInfo({
  5872. pid: memberId,
  5873. role: role
  5874. })
  5875. })
  5876. }));
  5877. case 5:
  5878. _internal5 = internal(this), memberInfos = _internal5.memberInfos;
  5879. if (memberInfos && memberInfos[memberId]) {
  5880. internal(memberInfos[memberId]).role = role;
  5881. }
  5882. return _context4.abrupt("return", this);
  5883. case 8:
  5884. case "end":
  5885. return _context4.stop();
  5886. }
  5887. }
  5888. }, _callee4, this);
  5889. }));
  5890. function updateMemberRole(_x2, _x3) {
  5891. return _updateMemberRole.apply(this, arguments);
  5892. }
  5893. return updateMemberRole;
  5894. }();
  5895. return Conversation;
  5896. }(PersistentConversation);
  5897. /**
  5898. * 聊天室。
  5899. *
  5900. * 无法直接实例化,请使用 {@link IMClient#createChatRoom} 创建新的聊天室。
  5901. * @since 4.0.0
  5902. * @extends PersistentConversation
  5903. * @public
  5904. */
  5905. var ChatRoom = /*#__PURE__*/function (_PersistentConversati) {
  5906. _inheritsLoose(ChatRoom, _PersistentConversati);
  5907. function ChatRoom() {
  5908. return _PersistentConversati.apply(this, arguments) || this;
  5909. }
  5910. return ChatRoom;
  5911. }(PersistentConversation);
  5912. /**
  5913. * 服务号。
  5914. *
  5915. * 服务号不支持在客户端创建。
  5916. * @since 4.0.0
  5917. * @extends PersistentConversation
  5918. * @public
  5919. */
  5920. var ServiceConversation = /*#__PURE__*/function (_PersistentConversati) {
  5921. _inheritsLoose(ServiceConversation, _PersistentConversati);
  5922. function ServiceConversation() {
  5923. return _PersistentConversati.apply(this, arguments) || this;
  5924. }
  5925. var _proto = ServiceConversation.prototype;
  5926. /**
  5927. * 订阅该服务号
  5928. * @return {Promise.<this>} self
  5929. */
  5930. _proto.subscribe =
  5931. /*#__PURE__*/
  5932. function () {
  5933. var _subscribe = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
  5934. return _regeneratorRuntime.wrap(function _callee$(_context) {
  5935. while (1) {
  5936. switch (_context.prev = _context.next) {
  5937. case 0:
  5938. return _context.abrupt("return", this.join());
  5939. case 1:
  5940. case "end":
  5941. return _context.stop();
  5942. }
  5943. }
  5944. }, _callee, this);
  5945. }));
  5946. function subscribe() {
  5947. return _subscribe.apply(this, arguments);
  5948. }
  5949. return subscribe;
  5950. }()
  5951. /**
  5952. * 退订该服务号
  5953. * @return {Promise.<this>} self
  5954. */
  5955. ;
  5956. _proto.unsubscribe =
  5957. /*#__PURE__*/
  5958. function () {
  5959. var _unsubscribe = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
  5960. return _regeneratorRuntime.wrap(function _callee2$(_context2) {
  5961. while (1) {
  5962. switch (_context2.prev = _context2.next) {
  5963. case 0:
  5964. return _context2.abrupt("return", this.quit());
  5965. case 1:
  5966. case "end":
  5967. return _context2.stop();
  5968. }
  5969. }
  5970. }, _callee2, this);
  5971. }));
  5972. function unsubscribe() {
  5973. return _unsubscribe.apply(this, arguments);
  5974. }
  5975. return unsubscribe;
  5976. }();
  5977. return ServiceConversation;
  5978. }(PersistentConversation);
  5979. function ownKeys$7(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  5980. function _objectSpread$7(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$7(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$7(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  5981. var transformNotFoundError = function transformNotFoundError(error) {
  5982. return error.code === ErrorCode.CONVERSATION_NOT_FOUND ? createError({
  5983. code: ErrorCode.TEMPORARY_CONVERSATION_EXPIRED
  5984. }) : error;
  5985. };
  5986. /**
  5987. * 临时对话
  5988. * @since 4.0.0
  5989. * @extends ConversationBase
  5990. * @public
  5991. */
  5992. var TemporaryConversation = /*#__PURE__*/function (_ConversationBase) {
  5993. _inheritsLoose(TemporaryConversation, _ConversationBase);
  5994. /**
  5995. * 无法直接实例化,请使用 {@link IMClient#createTemporaryConversation} 创建新的临时对话。
  5996. */
  5997. function TemporaryConversation(data, _ref, client) {
  5998. var expiredAt = _ref.expiredAt;
  5999. return _ConversationBase.call(this, _objectSpread$7(_objectSpread$7({}, data), {}, {
  6000. expiredAt: expiredAt
  6001. }), client) || this;
  6002. }
  6003. /**
  6004. * 对话失效时间
  6005. * @type {Date}
  6006. */
  6007. var _proto = TemporaryConversation.prototype;
  6008. _proto._send = /*#__PURE__*/function () {
  6009. var _send2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
  6010. var _ConversationBase$pro,
  6011. _len,
  6012. args,
  6013. _key,
  6014. _args = arguments;
  6015. return _regeneratorRuntime.wrap(function _callee$(_context) {
  6016. while (1) {
  6017. switch (_context.prev = _context.next) {
  6018. case 0:
  6019. if (!this.expired) {
  6020. _context.next = 2;
  6021. break;
  6022. }
  6023. throw createError({
  6024. code: ErrorCode.TEMPORARY_CONVERSATION_EXPIRED
  6025. });
  6026. case 2:
  6027. _context.prev = 2;
  6028. for (_len = _args.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  6029. args[_key] = _args[_key];
  6030. }
  6031. _context.next = 6;
  6032. return (_ConversationBase$pro = _ConversationBase.prototype._send).call.apply(_ConversationBase$pro, [this].concat(args));
  6033. case 6:
  6034. return _context.abrupt("return", _context.sent);
  6035. case 9:
  6036. _context.prev = 9;
  6037. _context.t0 = _context["catch"](2);
  6038. throw transformNotFoundError(_context.t0);
  6039. case 12:
  6040. case "end":
  6041. return _context.stop();
  6042. }
  6043. }
  6044. }, _callee, this, [[2, 9]]);
  6045. }));
  6046. function _send() {
  6047. return _send2.apply(this, arguments);
  6048. }
  6049. return _send;
  6050. }();
  6051. _proto.send = /*#__PURE__*/function () {
  6052. var _send3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
  6053. var _ConversationBase$pro2,
  6054. _len2,
  6055. args,
  6056. _key2,
  6057. _args2 = arguments;
  6058. return _regeneratorRuntime.wrap(function _callee2$(_context2) {
  6059. while (1) {
  6060. switch (_context2.prev = _context2.next) {
  6061. case 0:
  6062. _context2.prev = 0;
  6063. for (_len2 = _args2.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  6064. args[_key2] = _args2[_key2];
  6065. }
  6066. _context2.next = 4;
  6067. return (_ConversationBase$pro2 = _ConversationBase.prototype.send).call.apply(_ConversationBase$pro2, [this].concat(args));
  6068. case 4:
  6069. return _context2.abrupt("return", _context2.sent);
  6070. case 7:
  6071. _context2.prev = 7;
  6072. _context2.t0 = _context2["catch"](0);
  6073. throw transformNotFoundError(_context2.t0);
  6074. case 10:
  6075. case "end":
  6076. return _context2.stop();
  6077. }
  6078. }
  6079. }, _callee2, this, [[0, 7]]);
  6080. }));
  6081. function send() {
  6082. return _send3.apply(this, arguments);
  6083. }
  6084. return send;
  6085. }();
  6086. _proto.toFullJSON = function toFullJSON() {
  6087. var expiredAt = this.expiredAt;
  6088. return _objectSpread$7(_objectSpread$7({}, _ConversationBase.prototype.toFullJSON.call(this)), {}, {
  6089. expiredAt: getTime(expiredAt)
  6090. });
  6091. };
  6092. _proto.toJSON = function toJSON() {
  6093. var expiredAt = this.expiredAt,
  6094. expired = this.expired;
  6095. return _objectSpread$7(_objectSpread$7({}, _ConversationBase.prototype.toJSON.call(this)), {}, {
  6096. expiredAt: expiredAt,
  6097. expired: expired
  6098. });
  6099. };
  6100. _createClass(TemporaryConversation, [{
  6101. key: "expiredAt",
  6102. set: function set(value) {
  6103. this._expiredAt = decodeDate(value);
  6104. },
  6105. get: function get() {
  6106. return this._expiredAt;
  6107. }
  6108. /**
  6109. * 对话是否已失效
  6110. * @type {Boolean}
  6111. */
  6112. }, {
  6113. key: "expired",
  6114. get: function get() {
  6115. return this.expiredAt < new Date();
  6116. }
  6117. }]);
  6118. return TemporaryConversation;
  6119. }(ConversationBase);
  6120. var debug$9 = d('LC:ConversationQuery');
  6121. var ConversationQuery = /*#__PURE__*/function () {
  6122. ConversationQuery._encode = function _encode(value) {
  6123. if (value instanceof Date) {
  6124. return {
  6125. __type: 'Date',
  6126. iso: value.toJSON()
  6127. };
  6128. }
  6129. if (value instanceof RegExp) {
  6130. return value.source;
  6131. }
  6132. return value;
  6133. };
  6134. ConversationQuery._quote = function _quote(s) {
  6135. return "\\Q".concat(s.replace('\\E', '\\E\\\\E\\Q'), "\\E");
  6136. };
  6137. ConversationQuery._calculateFlag = function _calculateFlag(options) {
  6138. return ['withLastMessagesRefreshed', 'compact'].reduce( // eslint-disable-next-line no-bitwise
  6139. function (prev, key) {
  6140. return (prev << 1) + Boolean(options[key]);
  6141. }, 0);
  6142. }
  6143. /**
  6144. * 构造一个用 AND 连接所有查询的 ConversationQuery
  6145. * @param {...ConversationQuery} queries
  6146. * @return {ConversationQuery}
  6147. */
  6148. ;
  6149. ConversationQuery.and = function and() {
  6150. for (var _len = arguments.length, queries = new Array(_len), _key = 0; _key < _len; _key++) {
  6151. queries[_key] = arguments[_key];
  6152. }
  6153. if (queries.length < 2) {
  6154. throw new Error('The queries must contain at least two elements');
  6155. }
  6156. if (!queries.every(function (q) {
  6157. return q instanceof ConversationQuery;
  6158. })) {
  6159. throw new Error('The element of queries must be an instance of ConversationQuery');
  6160. }
  6161. var combined = new ConversationQuery(queries[0]._client);
  6162. combined._where.$and = queries.map(function (q) {
  6163. return q._where;
  6164. });
  6165. return combined;
  6166. }
  6167. /**
  6168. * 构造一个用 OR 连接所有查询的 ConversationQuery
  6169. * @param {...ConversationQuery} queries
  6170. * @return {ConversationQuery}
  6171. */
  6172. ;
  6173. ConversationQuery.or = function or() {
  6174. var combined = ConversationQuery.and.apply(ConversationQuery, arguments);
  6175. combined._where.$or = combined._where.$and;
  6176. delete combined._where.$and;
  6177. return combined;
  6178. }
  6179. /**
  6180. * Create a ConversationQuery
  6181. * @param {IMClient} client
  6182. */
  6183. ;
  6184. function ConversationQuery(client) {
  6185. this._client = client;
  6186. this._where = {};
  6187. this._extraOptions = {};
  6188. }
  6189. var _proto = ConversationQuery.prototype;
  6190. _proto._addCondition = function _addCondition(key, condition, value) {
  6191. // Check if we already have a condition
  6192. if (!this._where[key]) {
  6193. this._where[key] = {};
  6194. }
  6195. this._where[key][condition] = this.constructor._encode(value);
  6196. return this;
  6197. };
  6198. _proto.toJSON = function toJSON() {
  6199. var json = {
  6200. where: this._where,
  6201. flag: this.constructor._calculateFlag(this._extraOptions)
  6202. };
  6203. if (typeof this._skip !== 'undefined') json.skip = this._skip;
  6204. if (typeof this._limit !== 'undefined') json.limit = this._limit;
  6205. if (typeof this._order !== 'undefined') json.sort = this._order;
  6206. debug$9(json);
  6207. return json;
  6208. }
  6209. /**
  6210. * 增加查询条件,指定聊天室的组员包含某些成员即可返回
  6211. * @param {string[]} peerIds - 成员 ID 列表
  6212. * @return {ConversationQuery} self
  6213. */
  6214. ;
  6215. _proto.containsMembers = function containsMembers(peerIds) {
  6216. return this.containsAll('m', peerIds);
  6217. }
  6218. /**
  6219. * 增加查询条件,指定聊天室的组员条件满足条件的才返回
  6220. *
  6221. * @param {string[]} - 成员 ID 列表
  6222. * @param {Boolean} includeSelf - 是否包含自己
  6223. * @return {ConversationQuery} self
  6224. */
  6225. ;
  6226. _proto.withMembers = function withMembers(peerIds, includeSelf) {
  6227. var peerIdsSet = new Set(peerIds);
  6228. if (includeSelf) {
  6229. peerIdsSet.add(this._client.id);
  6230. }
  6231. this.sizeEqualTo('m', peerIdsSet.size);
  6232. return this.containsMembers(Array.from(peerIdsSet));
  6233. }
  6234. /**
  6235. * 增加查询条件,当 conversation 的属性中对应的字段满足等于条件时即可返回
  6236. *
  6237. * @param {string} key
  6238. * @param value
  6239. * @return {ConversationQuery} self
  6240. */
  6241. ;
  6242. _proto.equalTo = function equalTo(key, value) {
  6243. this._where[key] = this.constructor._encode(value);
  6244. return this;
  6245. }
  6246. /**
  6247. * 增加查询条件,当 conversation 的属性中对应的字段满足小于条件时即可返回
  6248. * @param {string} key
  6249. * @param value
  6250. * @return {ConversationQuery} self
  6251. */
  6252. ;
  6253. _proto.lessThan = function lessThan(key, value) {
  6254. return this._addCondition(key, '$lt', value);
  6255. }
  6256. /**
  6257. * 增加查询条件,当 conversation 的属性中对应的字段满足小于等于条件时即可返回
  6258. * @param {string} key
  6259. * @param value
  6260. * @return {ConversationQuery} self
  6261. */
  6262. ;
  6263. _proto.lessThanOrEqualTo = function lessThanOrEqualTo(key, value) {
  6264. return this._addCondition(key, '$lte', value);
  6265. }
  6266. /**
  6267. * 增加查询条件,当 conversation 的属性中对应的字段满足大于条件时即可返回
  6268. *
  6269. * @param {string} key
  6270. * @param value
  6271. * @return {ConversationQuery} self
  6272. */
  6273. ;
  6274. _proto.greaterThan = function greaterThan(key, value) {
  6275. return this._addCondition(key, '$gt', value);
  6276. }
  6277. /**
  6278. * 增加查询条件,当 conversation 的属性中对应的字段满足大于等于条件时即可返回
  6279. *
  6280. * @param {string} key
  6281. * @param value
  6282. * @return {ConversationQuery} self
  6283. */
  6284. ;
  6285. _proto.greaterThanOrEqualTo = function greaterThanOrEqualTo(key, value) {
  6286. return this._addCondition(key, '$gte', value);
  6287. }
  6288. /**
  6289. * 增加查询条件,当 conversation 的属性中对应的字段满足不等于条件时即可返回
  6290. *
  6291. * @param {string} key
  6292. * @param value
  6293. * @return {ConversationQuery} self
  6294. */
  6295. ;
  6296. _proto.notEqualTo = function notEqualTo(key, value) {
  6297. return this._addCondition(key, '$ne', value);
  6298. }
  6299. /**
  6300. * 增加查询条件,当 conversation 存在指定的字段时即可返回
  6301. *
  6302. * @since 3.5.0
  6303. * @param {string} key
  6304. * @return {ConversationQuery} self
  6305. */
  6306. ;
  6307. _proto.exists = function exists(key) {
  6308. return this._addCondition(key, '$exists', true);
  6309. }
  6310. /**
  6311. * 增加查询条件,当 conversation 不存在指定的字段时即可返回
  6312. *
  6313. * @since 3.5.0
  6314. * @param {string} key
  6315. * @return {ConversationQuery} self
  6316. */
  6317. ;
  6318. _proto.doesNotExist = function doesNotExist(key) {
  6319. return this._addCondition(key, '$exists', false);
  6320. }
  6321. /**
  6322. * 增加查询条件,当 conversation 的属性中对应的字段对应的值包含在指定值中时即可返回
  6323. *
  6324. * @param {string} key
  6325. * @param values
  6326. * @return {ConversationQuery} self
  6327. */
  6328. ;
  6329. _proto.containedIn = function containedIn(key, values) {
  6330. return this._addCondition(key, '$in', values);
  6331. }
  6332. /**
  6333. * 增加查询条件,当 conversation 的属性中对应的字段对应的值不包含在指定值中时即可返回
  6334. *
  6335. * @param {string} key
  6336. * @param values
  6337. * @return {ConversationQuery} self
  6338. */
  6339. ;
  6340. _proto.notContainsIn = function notContainsIn(key, values) {
  6341. return this._addCondition(key, '$nin', values);
  6342. }
  6343. /**
  6344. * 增加查询条件,当conversation的属性中对应的字段中的元素包含所有的值才可返回
  6345. *
  6346. * @param {string} key
  6347. * @param values
  6348. * @return {ConversationQuery} self
  6349. */
  6350. ;
  6351. _proto.containsAll = function containsAll(key, values) {
  6352. return this._addCondition(key, '$all', values);
  6353. }
  6354. /**
  6355. * 增加查询条件,当 conversation 的属性中对应的字段对应的值包含此字符串即可返回
  6356. *
  6357. * @param {string} key
  6358. * @param {string} subString
  6359. * @return {ConversationQuery} self
  6360. */
  6361. ;
  6362. _proto.contains = function contains(key, subString) {
  6363. return this._addCondition(key, '$regex', ConversationQuery._quote(subString));
  6364. }
  6365. /**
  6366. * 增加查询条件,当 conversation 的属性中对应的字段对应的值以此字符串起始即可返回
  6367. *
  6368. * @param {string} key
  6369. * @param {string} prefix
  6370. * @return {ConversationQuery} self
  6371. */
  6372. ;
  6373. _proto.startsWith = function startsWith(key, prefix) {
  6374. return this._addCondition(key, '$regex', "^".concat(ConversationQuery._quote(prefix)));
  6375. }
  6376. /**
  6377. * 增加查询条件,当 conversation 的属性中对应的字段对应的值以此字符串结束即可返回
  6378. *
  6379. * @param {string} key
  6380. * @param {string} suffix
  6381. * @return {ConversationQuery} self
  6382. */
  6383. ;
  6384. _proto.endsWith = function endsWith(key, suffix) {
  6385. return this._addCondition(key, '$regex', "".concat(ConversationQuery._quote(suffix), "$"));
  6386. }
  6387. /**
  6388. * 增加查询条件,当 conversation 的属性中对应的字段对应的值满足提供的正则表达式即可返回
  6389. *
  6390. * @param {string} key
  6391. * @param {RegExp} regex
  6392. * @return {ConversationQuery} self
  6393. */
  6394. ;
  6395. _proto.matches = function matches(key, regex) {
  6396. this._addCondition(key, '$regex', regex); // Javascript regex options support mig as inline options but store them
  6397. // as properties of the object. We support mi & should migrate them to
  6398. // modifiers
  6399. var _modifiers = '';
  6400. if (regex.ignoreCase) {
  6401. _modifiers += 'i';
  6402. }
  6403. if (regex.multiline) {
  6404. _modifiers += 'm';
  6405. }
  6406. if (_modifiers && _modifiers.length) {
  6407. this._addCondition(key, '$options', _modifiers);
  6408. }
  6409. return this;
  6410. }
  6411. /**
  6412. * 添加查询约束条件,查找 key 类型是数组,该数组的长度匹配提供的数值
  6413. *
  6414. * @param {string} key
  6415. * @param {Number} length
  6416. * @return {ConversationQuery} self
  6417. */
  6418. ;
  6419. _proto.sizeEqualTo = function sizeEqualTo(key, length) {
  6420. return this._addCondition(key, '$size', length);
  6421. }
  6422. /**
  6423. * 设置返回集合的大小上限
  6424. *
  6425. * @param {Number} limit - 上限
  6426. * @return {ConversationQuery} self
  6427. */
  6428. ;
  6429. _proto.limit = function limit(_limit) {
  6430. this._limit = _limit;
  6431. return this;
  6432. }
  6433. /**
  6434. * 设置返回集合的起始位置,一般用于分页
  6435. *
  6436. * @param {Number} skip - 起始位置跳过几个对象
  6437. * @return {ConversationQuery} self
  6438. */
  6439. ;
  6440. _proto.skip = function skip(_skip) {
  6441. this._skip = _skip;
  6442. return this;
  6443. }
  6444. /**
  6445. * 设置返回集合按照指定key进行增序排列
  6446. *
  6447. * @param {string} key
  6448. * @return {ConversationQuery} self
  6449. */
  6450. ;
  6451. _proto.ascending = function ascending(key) {
  6452. this._order = key;
  6453. return this;
  6454. }
  6455. /**
  6456. * 设置返回集合按照指定key进行增序排列,如果已设置其他排序,原排序的优先级较高
  6457. *
  6458. * @param {string} key
  6459. * @return {ConversationQuery} self
  6460. */
  6461. ;
  6462. _proto.addAscending = function addAscending(key) {
  6463. if (this._order) {
  6464. this._order += ",".concat(key);
  6465. } else {
  6466. this._order = key;
  6467. }
  6468. return this;
  6469. }
  6470. /**
  6471. * 设置返回集合按照指定 key 进行降序排列
  6472. *
  6473. * @param {string} key
  6474. * @return {ConversationQuery} self
  6475. */
  6476. ;
  6477. _proto.descending = function descending(key) {
  6478. this._order = "-".concat(key);
  6479. return this;
  6480. }
  6481. /**
  6482. * 设置返回集合按照指定 key 进行降序排列,如果已设置其他排序,原排序的优先级较高
  6483. *
  6484. * @param {string} key
  6485. * @return {ConversationQuery} self
  6486. */
  6487. ;
  6488. _proto.addDescending = function addDescending(key) {
  6489. if (this._order) {
  6490. this._order += ",-".concat(key);
  6491. } else {
  6492. this._order = "-".concat(key);
  6493. }
  6494. return this;
  6495. }
  6496. /**
  6497. * 设置返回的 conversations 刷新最后一条消息
  6498. * @param {Boolean} [enabled=true]
  6499. * @return {ConversationQuery} self
  6500. */
  6501. ;
  6502. _proto.withLastMessagesRefreshed = function withLastMessagesRefreshed() {
  6503. var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  6504. this._extraOptions.withLastMessagesRefreshed = enabled;
  6505. return this;
  6506. }
  6507. /**
  6508. * 设置返回的 conversations 为精简模式,即不含成员列表
  6509. * @param {Boolean} [enabled=true]
  6510. * @return {ConversationQuery} self
  6511. */
  6512. ;
  6513. _proto.compact = function compact() {
  6514. var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  6515. this._extraOptions.compact = enabled;
  6516. return this;
  6517. }
  6518. /**
  6519. * 执行查询
  6520. * @return {Promise.<ConversationBase[]>}
  6521. */
  6522. ;
  6523. _proto.find =
  6524. /*#__PURE__*/
  6525. function () {
  6526. var _find = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
  6527. return _regeneratorRuntime.wrap(function _callee$(_context) {
  6528. while (1) {
  6529. switch (_context.prev = _context.next) {
  6530. case 0:
  6531. return _context.abrupt("return", this._client._executeQuery(this));
  6532. case 1:
  6533. case "end":
  6534. return _context.stop();
  6535. }
  6536. }
  6537. }, _callee, this);
  6538. }));
  6539. function find() {
  6540. return _find.apply(this, arguments);
  6541. }
  6542. return find;
  6543. }()
  6544. /**
  6545. * 返回符合条件的第一个结果
  6546. * @return {Promise.<ConversationBase>}
  6547. */
  6548. ;
  6549. _proto.first =
  6550. /*#__PURE__*/
  6551. function () {
  6552. var _first = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
  6553. return _regeneratorRuntime.wrap(function _callee2$(_context2) {
  6554. while (1) {
  6555. switch (_context2.prev = _context2.next) {
  6556. case 0:
  6557. _context2.next = 2;
  6558. return this.limit(1).find();
  6559. case 2:
  6560. return _context2.abrupt("return", _context2.sent[0]);
  6561. case 3:
  6562. case "end":
  6563. return _context2.stop();
  6564. }
  6565. }
  6566. }, _callee2, this);
  6567. }));
  6568. function first() {
  6569. return _first.apply(this, arguments);
  6570. }
  6571. return first;
  6572. }();
  6573. return ConversationQuery;
  6574. }();
  6575. var debug$a = d('LC:SessionManager');
  6576. var SessionManager = /*#__PURE__*/function () {
  6577. function SessionManager() {
  6578. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  6579. refresh = _ref.refresh,
  6580. onBeforeGetSessionToken = _ref.onBeforeGetSessionToken;
  6581. this.refresh = refresh;
  6582. this._onBeforeGetSessionToken = onBeforeGetSessionToken;
  6583. this.setSessionToken(null, 0);
  6584. }
  6585. var _proto = SessionManager.prototype;
  6586. _proto.setSessionToken = function setSessionToken(token, ttl) {
  6587. debug$a('set session token', token, ttl);
  6588. var sessionToken = new Expirable(token, ttl * 1000);
  6589. this._sessionToken = sessionToken;
  6590. delete this._pendingSessionTokenPromise;
  6591. return sessionToken;
  6592. };
  6593. _proto.setSessionTokenAsync = /*#__PURE__*/function () {
  6594. var _setSessionTokenAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(promise) {
  6595. var _this = this;
  6596. var currentSessionToken;
  6597. return _regeneratorRuntime.wrap(function _callee$(_context) {
  6598. while (1) {
  6599. switch (_context.prev = _context.next) {
  6600. case 0:
  6601. currentSessionToken = this._sessionToken;
  6602. this._pendingSessionTokenPromise = promise["catch"](function (error) {
  6603. // revert, otherwise the following getSessionToken calls
  6604. // will all be rejected
  6605. _this._sessionToken = currentSessionToken;
  6606. throw error;
  6607. });
  6608. _context.t0 = this.setSessionToken;
  6609. _context.t1 = this;
  6610. _context.t2 = _toConsumableArray;
  6611. _context.next = 7;
  6612. return this._pendingSessionTokenPromise;
  6613. case 7:
  6614. _context.t3 = _context.sent;
  6615. _context.t4 = (0, _context.t2)(_context.t3);
  6616. return _context.abrupt("return", _context.t0.apply.call(_context.t0, _context.t1, _context.t4));
  6617. case 10:
  6618. case "end":
  6619. return _context.stop();
  6620. }
  6621. }
  6622. }, _callee, this);
  6623. }));
  6624. function setSessionTokenAsync(_x) {
  6625. return _setSessionTokenAsync.apply(this, arguments);
  6626. }
  6627. return setSessionTokenAsync;
  6628. }();
  6629. _proto.getSessionToken = /*#__PURE__*/function () {
  6630. var _getSessionToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
  6631. var _ref2,
  6632. _ref2$autoRefresh,
  6633. autoRefresh,
  6634. _ref3,
  6635. value,
  6636. originalValue,
  6637. _yield$this$setSessio,
  6638. newValue,
  6639. _args2 = arguments;
  6640. return _regeneratorRuntime.wrap(function _callee2$(_context2) {
  6641. while (1) {
  6642. switch (_context2.prev = _context2.next) {
  6643. case 0:
  6644. _ref2 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref2$autoRefresh = _ref2.autoRefresh, autoRefresh = _ref2$autoRefresh === void 0 ? true : _ref2$autoRefresh;
  6645. debug$a('get session token');
  6646. if (this._onBeforeGetSessionToken) {
  6647. this._onBeforeGetSessionToken(this);
  6648. }
  6649. _context2.t0 = this._sessionToken;
  6650. if (_context2.t0) {
  6651. _context2.next = 8;
  6652. break;
  6653. }
  6654. _context2.next = 7;
  6655. return this._pendingSessionTokenPromise;
  6656. case 7:
  6657. _context2.t0 = _context2.sent;
  6658. case 8:
  6659. _ref3 = _context2.t0;
  6660. value = _ref3.value;
  6661. originalValue = _ref3.originalValue;
  6662. if (!(value === Expirable.EXPIRED && autoRefresh && this.refresh)) {
  6663. _context2.next = 19;
  6664. break;
  6665. }
  6666. debug$a('refresh expired session token');
  6667. _context2.next = 15;
  6668. return this.setSessionTokenAsync(this.refresh(this, originalValue));
  6669. case 15:
  6670. _yield$this$setSessio = _context2.sent;
  6671. newValue = _yield$this$setSessio.value;
  6672. debug$a('session token', newValue);
  6673. return _context2.abrupt("return", newValue);
  6674. case 19:
  6675. debug$a('session token', value);
  6676. return _context2.abrupt("return", value);
  6677. case 21:
  6678. case "end":
  6679. return _context2.stop();
  6680. }
  6681. }
  6682. }, _callee2, this);
  6683. }));
  6684. function getSessionToken() {
  6685. return _getSessionToken.apply(this, arguments);
  6686. }
  6687. return getSessionToken;
  6688. }();
  6689. _proto.revoke = function revoke() {
  6690. if (this._sessionToken) this._sessionToken.expiredAt = -1;
  6691. };
  6692. return SessionManager;
  6693. }();
  6694. var _dec$2, _dec2, _class$3;
  6695. function ownKeys$8(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  6696. function _objectSpread$8(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$8(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$8(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  6697. var debug$b = d('LC:IMClient');
  6698. var INVITED$1 = INVITED,
  6699. KICKED$1 = KICKED,
  6700. MEMBERS_JOINED$1 = MEMBERS_JOINED,
  6701. MEMBERS_LEFT$1 = MEMBERS_LEFT,
  6702. MEMBER_INFO_UPDATED$1 = MEMBER_INFO_UPDATED,
  6703. BLOCKED$1 = BLOCKED,
  6704. UNBLOCKED$1 = UNBLOCKED,
  6705. MEMBERS_BLOCKED$1 = MEMBERS_BLOCKED,
  6706. MEMBERS_UNBLOCKED$1 = MEMBERS_UNBLOCKED,
  6707. MUTED$1 = MUTED,
  6708. UNMUTED$1 = UNMUTED,
  6709. MEMBERS_MUTED$1 = MEMBERS_MUTED,
  6710. MEMBERS_UNMUTED$1 = MEMBERS_UNMUTED,
  6711. MESSAGE$2 = MESSAGE$1,
  6712. UNREAD_MESSAGES_COUNT_UPDATE$1 = UNREAD_MESSAGES_COUNT_UPDATE,
  6713. CLOSE$1 = CLOSE,
  6714. CONFLICT$1 = CONFLICT,
  6715. UNHANDLED_MESSAGE$1 = UNHANDLED_MESSAGE,
  6716. CONVERSATION_INFO_UPDATED$1 = CONVERSATION_INFO_UPDATED,
  6717. MESSAGE_RECALL$1 = MESSAGE_RECALL,
  6718. MESSAGE_UPDATE$1 = MESSAGE_UPDATE,
  6719. INFO_UPDATED$1 = INFO_UPDATED;
  6720. var isTemporaryConversatrionId = function isTemporaryConversatrionId(id) {
  6721. return /^_tmp:/.test(id);
  6722. };
  6723. /**
  6724. * 1 patch-msg
  6725. * 1 temp-conv-msg
  6726. * 0 auto-bind-deviceid-and-installation
  6727. * 1 transient-msg-ack
  6728. * 1 keep-notification
  6729. * 1 partial-failed-msg
  6730. * 0 group-chat-rcp
  6731. * 1 omit-peer-id
  6732. * @ignore
  6733. */
  6734. var configBitmap = 187;
  6735. var IMClient = (_dec$2 = throttle(1000), _dec2 = throttle(1000), (_class$3 = /*#__PURE__*/function (_EventEmitter) {
  6736. _inheritsLoose(IMClient, _EventEmitter);
  6737. /**
  6738. * 无法直接实例化,请使用 {@link Realtime#createIMClient} 创建新的 IMClient。
  6739. *
  6740. * @extends EventEmitter
  6741. */
  6742. function IMClient(id) {
  6743. var _this;
  6744. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  6745. var props = arguments.length > 2 ? arguments[2] : undefined;
  6746. if (!(id === undefined || typeof id === 'string')) {
  6747. throw new TypeError("Client id [".concat(id, "] is not a String"));
  6748. }
  6749. _this = _EventEmitter.call(this) || this;
  6750. Object.assign(_assertThisInitialized(_this), {
  6751. /**
  6752. * @var id {String} 客户端 id
  6753. * @memberof IMClient#
  6754. */
  6755. id: id,
  6756. options: options
  6757. }, props);
  6758. if (!_this._messageParser) {
  6759. throw new Error('IMClient must be initialized with a MessageParser');
  6760. }
  6761. _this._conversationCache = new Cache("client:".concat(_this.id));
  6762. _this._ackMessageBuffer = {};
  6763. internal(_assertThisInitialized(_this)).lastPatchTime = Date.now();
  6764. internal(_assertThisInitialized(_this)).lastNotificationTime = undefined;
  6765. internal(_assertThisInitialized(_this))._eventemitter = new EventEmitter();
  6766. if (debug$b.enabled) {
  6767. values(IMEvent).forEach(function (event) {
  6768. return _this.on(event, function () {
  6769. for (var _len = arguments.length, payload = new Array(_len), _key = 0; _key < _len; _key++) {
  6770. payload[_key] = arguments[_key];
  6771. }
  6772. return _this._debug("".concat(event, " event emitted. %o"), payload);
  6773. });
  6774. });
  6775. } // onIMClientCreate hook
  6776. applyDecorators(_this._plugins.onIMClientCreate, _assertThisInitialized(_this));
  6777. return _this;
  6778. }
  6779. var _proto = IMClient.prototype;
  6780. _proto._debug = function _debug() {
  6781. for (var _len2 = arguments.length, params = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  6782. params[_key2] = arguments[_key2];
  6783. }
  6784. debug$b.apply(void 0, params.concat(["[".concat(this.id, "]")]));
  6785. }
  6786. /**
  6787. * @override
  6788. * @private
  6789. */
  6790. ;
  6791. _proto._dispatchCommand =
  6792. /*#__PURE__*/
  6793. function () {
  6794. var _dispatchCommand2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(command) {
  6795. return _regeneratorRuntime.wrap(function _callee$(_context) {
  6796. while (1) {
  6797. switch (_context.prev = _context.next) {
  6798. case 0:
  6799. this._debug(trim(command), 'received');
  6800. if (command.serverTs && command.notificationType === 1) {
  6801. internal(this).lastNotificationTime = getTime(decodeDate(command.serverTs));
  6802. }
  6803. _context.t0 = command.cmd;
  6804. _context.next = _context.t0 === CommandType.conv ? 5 : _context.t0 === CommandType.direct ? 6 : _context.t0 === CommandType.session ? 7 : _context.t0 === CommandType.unread ? 8 : _context.t0 === CommandType.rcp ? 9 : _context.t0 === CommandType.patch ? 10 : 11;
  6805. break;
  6806. case 5:
  6807. return _context.abrupt("return", this._dispatchConvMessage(command));
  6808. case 6:
  6809. return _context.abrupt("return", this._dispatchDirectMessage(command));
  6810. case 7:
  6811. return _context.abrupt("return", this._dispatchSessionMessage(command));
  6812. case 8:
  6813. return _context.abrupt("return", this._dispatchUnreadMessage(command));
  6814. case 9:
  6815. return _context.abrupt("return", this._dispatchRcpMessage(command));
  6816. case 10:
  6817. return _context.abrupt("return", this._dispatchPatchMessage(command));
  6818. case 11:
  6819. return _context.abrupt("return", this.emit(UNHANDLED_MESSAGE$1, command));
  6820. case 12:
  6821. case "end":
  6822. return _context.stop();
  6823. }
  6824. }
  6825. }, _callee, this);
  6826. }));
  6827. function _dispatchCommand(_x) {
  6828. return _dispatchCommand2.apply(this, arguments);
  6829. }
  6830. return _dispatchCommand;
  6831. }();
  6832. _proto._dispatchSessionMessage = /*#__PURE__*/function () {
  6833. var _dispatchSessionMessage2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(message) {
  6834. var _message$sessionMessa, code, reason;
  6835. return _regeneratorRuntime.wrap(function _callee2$(_context2) {
  6836. while (1) {
  6837. switch (_context2.prev = _context2.next) {
  6838. case 0:
  6839. _message$sessionMessa = message.sessionMessage, code = _message$sessionMessa.code, reason = _message$sessionMessa.reason;
  6840. _context2.t0 = message.op;
  6841. _context2.next = _context2.t0 === OpType.closed ? 4 : 8;
  6842. break;
  6843. case 4:
  6844. internal(this)._eventemitter.emit('close');
  6845. if (!(code === ErrorCode.SESSION_CONFLICT)) {
  6846. _context2.next = 7;
  6847. break;
  6848. }
  6849. return _context2.abrupt("return", this.emit(CONFLICT$1, {
  6850. reason: reason
  6851. }));
  6852. case 7:
  6853. return _context2.abrupt("return", this.emit(CLOSE$1, {
  6854. code: code,
  6855. reason: reason
  6856. }));
  6857. case 8:
  6858. this.emit(UNHANDLED_MESSAGE$1, message);
  6859. throw new Error('Unrecognized session command');
  6860. case 10:
  6861. case "end":
  6862. return _context2.stop();
  6863. }
  6864. }
  6865. }, _callee2, this);
  6866. }));
  6867. function _dispatchSessionMessage(_x2) {
  6868. return _dispatchSessionMessage2.apply(this, arguments);
  6869. }
  6870. return _dispatchSessionMessage;
  6871. }();
  6872. _proto._dispatchUnreadMessage = function _dispatchUnreadMessage(_ref) {
  6873. var _this2 = this;
  6874. var _ref$unreadMessage = _ref.unreadMessage,
  6875. convs = _ref$unreadMessage.convs,
  6876. notifTime = _ref$unreadMessage.notifTime;
  6877. internal(this).lastUnreadNotifTime = notifTime; // ensure all converstions are cached
  6878. return this.getConversations(convs.map(function (conv) {
  6879. return conv.cid;
  6880. })).then(function () {
  6881. return (// update conversations data
  6882. Promise.all(convs.map(function (_ref2) {
  6883. var cid = _ref2.cid,
  6884. unread = _ref2.unread,
  6885. mid = _ref2.mid,
  6886. ts = _ref2.timestamp,
  6887. from = _ref2.from,
  6888. data = _ref2.data,
  6889. binaryMsg = _ref2.binaryMsg,
  6890. patchTimestamp = _ref2.patchTimestamp,
  6891. mentioned = _ref2.mentioned;
  6892. var conversation = _this2._conversationCache.get(cid); // deleted conversation
  6893. if (!conversation) return null;
  6894. var timestamp;
  6895. if (ts) {
  6896. timestamp = decodeDate(ts);
  6897. conversation.lastMessageAt = timestamp; // eslint-disable-line no-param-reassign
  6898. }
  6899. return (mid ? _this2._messageParser.parse(binaryMsg || data).then(function (message) {
  6900. var messageProps = {
  6901. id: mid,
  6902. cid: cid,
  6903. timestamp: timestamp,
  6904. updatedAt: patchTimestamp,
  6905. from: from
  6906. };
  6907. Object.assign(message, messageProps);
  6908. conversation.lastMessage = message; // eslint-disable-line no-param-reassign
  6909. }) : Promise.resolve()).then(function () {
  6910. conversation._setUnreadMessagesMentioned(mentioned);
  6911. var countNotUpdated = unread === internal(conversation).unreadMessagesCount;
  6912. if (countNotUpdated) return null; // to be filtered
  6913. // manipulate internal property directly to skip unreadmessagescountupdate event
  6914. internal(conversation).unreadMessagesCount = unread;
  6915. return conversation;
  6916. }); // filter conversations without unread count update
  6917. })).then(function (conversations) {
  6918. return conversations.filter(function (conversation) {
  6919. return conversation;
  6920. });
  6921. })
  6922. );
  6923. }).then(function (conversations) {
  6924. if (conversations.length) {
  6925. /**
  6926. * 未读消息数目更新
  6927. * @event IMClient#UNREAD_MESSAGES_COUNT_UPDATE
  6928. * @since 3.4.0
  6929. * @param {Conversation[]} conversations 未读消息数目有更新的对话列表
  6930. */
  6931. _this2.emit(UNREAD_MESSAGES_COUNT_UPDATE$1, conversations);
  6932. }
  6933. });
  6934. };
  6935. _proto._dispatchRcpMessage = /*#__PURE__*/function () {
  6936. var _dispatchRcpMessage2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(message) {
  6937. var rcpMessage, read, conversationId, messageId, timestamp, conversation;
  6938. return _regeneratorRuntime.wrap(function _callee3$(_context3) {
  6939. while (1) {
  6940. switch (_context3.prev = _context3.next) {
  6941. case 0:
  6942. rcpMessage = message.rcpMessage, read = message.rcpMessage.read;
  6943. conversationId = rcpMessage.cid;
  6944. messageId = rcpMessage.id;
  6945. timestamp = decodeDate(rcpMessage.t);
  6946. conversation = this._conversationCache.get(conversationId); // conversation not cached means the client does not send the message
  6947. // during this session
  6948. if (conversation) {
  6949. _context3.next = 7;
  6950. break;
  6951. }
  6952. return _context3.abrupt("return");
  6953. case 7:
  6954. conversation._handleReceipt({
  6955. messageId: messageId,
  6956. timestamp: timestamp,
  6957. read: read
  6958. });
  6959. case 8:
  6960. case "end":
  6961. return _context3.stop();
  6962. }
  6963. }
  6964. }, _callee3, this);
  6965. }));
  6966. function _dispatchRcpMessage(_x3) {
  6967. return _dispatchRcpMessage2.apply(this, arguments);
  6968. }
  6969. return _dispatchRcpMessage;
  6970. }();
  6971. _proto._dispatchPatchMessage = function _dispatchPatchMessage(_ref3) {
  6972. var _this3 = this;
  6973. var patches = _ref3.patchMessage.patches;
  6974. // ensure all converstions are cached
  6975. return this.getConversations(patches.map(function (patch) {
  6976. return patch.cid;
  6977. })).then(function () {
  6978. return Promise.all(patches.map(function (_ref4) {
  6979. var cid = _ref4.cid,
  6980. mid = _ref4.mid,
  6981. timestamp = _ref4.timestamp,
  6982. recall = _ref4.recall,
  6983. data = _ref4.data,
  6984. patchTimestamp = _ref4.patchTimestamp,
  6985. from = _ref4.from,
  6986. binaryMsg = _ref4.binaryMsg,
  6987. mentionAll = _ref4.mentionAll,
  6988. mentionPids = _ref4.mentionPids,
  6989. patchCode = _ref4.patchCode,
  6990. patchReason = _ref4.patchReason;
  6991. var conversation = _this3._conversationCache.get(cid); // deleted conversation
  6992. if (!conversation) return null;
  6993. return _this3._messageParser.parse(binaryMsg || data).then(function (message) {
  6994. var patchTime = getTime(decodeDate(patchTimestamp));
  6995. var messageProps = {
  6996. id: mid,
  6997. cid: cid,
  6998. timestamp: timestamp,
  6999. updatedAt: patchTime,
  7000. from: from,
  7001. mentionList: mentionPids,
  7002. mentionedAll: mentionAll
  7003. };
  7004. Object.assign(message, messageProps);
  7005. message._setStatus(MessageStatus.SENT);
  7006. message._updateMentioned(_this3.id);
  7007. if (internal(_this3).lastPatchTime < patchTime) {
  7008. internal(_this3).lastPatchTime = patchTime;
  7009. } // update conversation lastMessage
  7010. if (conversation.lastMessage && conversation.lastMessage.id === mid) {
  7011. conversation.lastMessage = message; // eslint-disable-line no-param-reassign
  7012. }
  7013. var reason;
  7014. if (patchCode) {
  7015. reason = {
  7016. code: patchCode.toNumber(),
  7017. detail: patchReason
  7018. };
  7019. }
  7020. if (recall) {
  7021. /**
  7022. * 消息被撤回
  7023. * @event IMClient#MESSAGE_RECALL
  7024. * @param {AVMessage} message 被撤回的消息
  7025. * @param {ConversationBase} conversation 消息所在的会话
  7026. * @param {PatchReason} [reason] 撤回的原因,不存在代表是发送者主动撤回
  7027. */
  7028. _this3.emit(MESSAGE_RECALL$1, message, conversation, reason);
  7029. /**
  7030. * 消息被撤回
  7031. * @event ConversationBase#MESSAGE_RECALL
  7032. * @param {AVMessage} message 被撤回的消息
  7033. * @param {PatchReason} [reason] 撤回的原因,不存在代表是发送者主动撤回
  7034. */
  7035. conversation.emit(MESSAGE_RECALL$1, message, reason);
  7036. } else {
  7037. /**
  7038. * 消息被修改
  7039. * @event IMClient#MESSAGE_UPDATE
  7040. * @param {AVMessage} message 被修改的消息
  7041. * @param {ConversationBase} conversation 消息所在的会话
  7042. * @param {PatchReason} [reason] 修改的原因,不存在代表是发送者主动修改
  7043. */
  7044. _this3.emit(MESSAGE_UPDATE$1, message, conversation, reason);
  7045. /**
  7046. * 消息被修改
  7047. * @event ConversationBase#MESSAGE_UPDATE
  7048. * @param {AVMessage} message 被修改的消息
  7049. * @param {PatchReason} [reason] 修改的原因,不存在代表是发送者主动修改
  7050. */
  7051. conversation.emit(MESSAGE_UPDATE$1, message, reason);
  7052. }
  7053. });
  7054. }));
  7055. });
  7056. };
  7057. _proto._dispatchConvMessage = /*#__PURE__*/function () {
  7058. var _dispatchConvMessage2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(message) {
  7059. var convMessage, _message$convMessage, initBy, m, info, attr, conversation, payload, _payload, _payload2, _payload3, _payload4, _payload5, _payload6, _payload7, _payload8, _payload9, _payload10, _payload11, pid, role, _internal, memberInfoMap, memberInfo, _payload12, attributes, _payload13;
  7060. return _regeneratorRuntime.wrap(function _callee4$(_context4) {
  7061. while (1) {
  7062. switch (_context4.prev = _context4.next) {
  7063. case 0:
  7064. convMessage = message.convMessage, _message$convMessage = message.convMessage, initBy = _message$convMessage.initBy, m = _message$convMessage.m, info = _message$convMessage.info, attr = _message$convMessage.attr;
  7065. _context4.next = 3;
  7066. return this.getConversation(convMessage.cid);
  7067. case 3:
  7068. conversation = _context4.sent;
  7069. _context4.t0 = message.op;
  7070. _context4.next = _context4.t0 === OpType.joined ? 7 : _context4.t0 === OpType.left ? 12 : _context4.t0 === OpType.members_joined ? 17 : _context4.t0 === OpType.members_left ? 22 : _context4.t0 === OpType.members_blocked ? 27 : _context4.t0 === OpType.members_unblocked ? 31 : _context4.t0 === OpType.blocked ? 35 : _context4.t0 === OpType.unblocked ? 39 : _context4.t0 === OpType.members_shutuped ? 43 : _context4.t0 === OpType.members_unshutuped ? 47 : _context4.t0 === OpType.shutuped ? 51 : _context4.t0 === OpType.unshutuped ? 55 : _context4.t0 === OpType.member_info_changed ? 59 : _context4.t0 === OpType.updated ? 71 : 77;
  7071. break;
  7072. case 7:
  7073. conversation._addMembers([this.id]);
  7074. payload = {
  7075. invitedBy: initBy
  7076. };
  7077. /**
  7078. * 当前用户被添加至某个对话
  7079. * @event IMClient#INVITED
  7080. * @param {Object} payload
  7081. * @param {String} payload.invitedBy 邀请者 id
  7082. * @param {ConversationBase} conversation
  7083. */
  7084. this.emit(INVITED$1, payload, conversation);
  7085. /**
  7086. * 当前用户被添加至当前对话
  7087. * @event ConversationBase#INVITED
  7088. * @param {Object} payload
  7089. * @param {String} payload.invitedBy 该移除操作的发起者 id
  7090. */
  7091. conversation.emit(INVITED$1, payload);
  7092. return _context4.abrupt("return");
  7093. case 12:
  7094. conversation._removeMembers([this.id]);
  7095. _payload = {
  7096. kickedBy: initBy
  7097. };
  7098. /**
  7099. * 当前用户被从某个对话中移除
  7100. * @event IMClient#KICKED
  7101. * @param {Object} payload
  7102. * @param {String} payload.kickedBy 该移除操作的发起者 id
  7103. * @param {ConversationBase} conversation
  7104. */
  7105. this.emit(KICKED$1, _payload, conversation);
  7106. /**
  7107. * 当前用户被从当前对话中移除
  7108. * @event ConversationBase#KICKED
  7109. * @param {Object} payload
  7110. * @param {String} payload.kickedBy 该移除操作的发起者 id
  7111. */
  7112. conversation.emit(KICKED$1, _payload);
  7113. return _context4.abrupt("return");
  7114. case 17:
  7115. conversation._addMembers(m);
  7116. _payload2 = {
  7117. invitedBy: initBy,
  7118. members: m
  7119. };
  7120. /**
  7121. * 有用户被添加至某个对话
  7122. * @event IMClient#MEMBERS_JOINED
  7123. * @param {Object} payload
  7124. * @param {String[]} payload.members 被添加的用户 id 列表
  7125. * @param {String} payload.invitedBy 邀请者 id
  7126. * @param {ConversationBase} conversation
  7127. */
  7128. this.emit(MEMBERS_JOINED$1, _payload2, conversation);
  7129. /**
  7130. * 有成员被添加至当前对话
  7131. * @event ConversationBase#MEMBERS_JOINED
  7132. * @param {Object} payload
  7133. * @param {String[]} payload.members 被添加的成员 id 列表
  7134. * @param {String} payload.invitedBy 邀请者 id
  7135. */
  7136. conversation.emit(MEMBERS_JOINED$1, _payload2);
  7137. return _context4.abrupt("return");
  7138. case 22:
  7139. conversation._removeMembers(m);
  7140. _payload3 = {
  7141. kickedBy: initBy,
  7142. members: m
  7143. };
  7144. /**
  7145. * 有成员被从某个对话中移除
  7146. * @event IMClient#MEMBERS_LEFT
  7147. * @param {Object} payload
  7148. * @param {String[]} payload.members 被移除的成员 id 列表
  7149. * @param {String} payload.kickedBy 该移除操作的发起者 id
  7150. * @param {ConversationBase} conversation
  7151. */
  7152. this.emit(MEMBERS_LEFT$1, _payload3, conversation);
  7153. /**
  7154. * 有成员被从当前对话中移除
  7155. * @event ConversationBase#MEMBERS_LEFT
  7156. * @param {Object} payload
  7157. * @param {String[]} payload.members 被移除的成员 id 列表
  7158. * @param {String} payload.kickedBy 该移除操作的发起者 id
  7159. */
  7160. conversation.emit(MEMBERS_LEFT$1, _payload3);
  7161. return _context4.abrupt("return");
  7162. case 27:
  7163. _payload4 = {
  7164. blockedBy: initBy,
  7165. members: m
  7166. };
  7167. /**
  7168. * 有成员被加入某个对话的黑名单
  7169. * @event IMClient#MEMBERS_BLOCKED
  7170. * @param {Object} payload
  7171. * @param {String[]} payload.members 成员 id 列表
  7172. * @param {String} payload.blockedBy 该操作的发起者 id
  7173. * @param {ConversationBase} conversation
  7174. */
  7175. this.emit(MEMBERS_BLOCKED$1, _payload4, conversation);
  7176. /**
  7177. * 有成员被加入当前对话的黑名单
  7178. * @event ConversationBase#MEMBERS_BLOCKED
  7179. * @param {Object} payload
  7180. * @param {String[]} payload.members 成员 id 列表
  7181. * @param {String} payload.blockedBy 该操作的发起者 id
  7182. */
  7183. conversation.emit(MEMBERS_BLOCKED$1, _payload4);
  7184. return _context4.abrupt("return");
  7185. case 31:
  7186. _payload5 = {
  7187. unblockedBy: initBy,
  7188. members: m
  7189. };
  7190. /**
  7191. * 有成员被移出某个对话的黑名单
  7192. * @event IMClient#MEMBERS_UNBLOCKED
  7193. * @param {Object} payload
  7194. * @param {String[]} payload.members 成员 id 列表
  7195. * @param {String} payload.unblockedBy 该操作的发起者 id
  7196. * @param {ConversationBase} conversation
  7197. */
  7198. this.emit(MEMBERS_UNBLOCKED$1, _payload5, conversation);
  7199. /**
  7200. * 有成员被移出当前对话的黑名单
  7201. * @event ConversationBase#MEMBERS_UNBLOCKED
  7202. * @param {Object} payload
  7203. * @param {String[]} payload.members 成员 id 列表
  7204. * @param {String} payload.unblockedBy 该操作的发起者 id
  7205. */
  7206. conversation.emit(MEMBERS_UNBLOCKED$1, _payload5);
  7207. return _context4.abrupt("return");
  7208. case 35:
  7209. _payload6 = {
  7210. blockedBy: initBy
  7211. };
  7212. /**
  7213. * 当前用户被加入某个对话的黑名单
  7214. * @event IMClient#BLOCKED
  7215. * @param {Object} payload
  7216. * @param {String} payload.blockedBy 该操作的发起者 id
  7217. * @param {ConversationBase} conversation
  7218. */
  7219. this.emit(BLOCKED$1, _payload6, conversation);
  7220. /**
  7221. * 当前用户被加入当前对话的黑名单
  7222. * @event ConversationBase#BLOCKED
  7223. * @param {Object} payload
  7224. * @param {String} payload.blockedBy 该操作的发起者 id
  7225. */
  7226. conversation.emit(BLOCKED$1, _payload6);
  7227. return _context4.abrupt("return");
  7228. case 39:
  7229. _payload7 = {
  7230. unblockedBy: initBy
  7231. };
  7232. /**
  7233. * 当前用户被移出某个对话的黑名单
  7234. * @event IMClient#UNBLOCKED
  7235. * @param {Object} payload
  7236. * @param {String} payload.unblockedBy 该操作的发起者 id
  7237. * @param {ConversationBase} conversation
  7238. */
  7239. this.emit(UNBLOCKED$1, _payload7, conversation);
  7240. /**
  7241. * 当前用户被移出当前对话的黑名单
  7242. * @event ConversationBase#UNBLOCKED
  7243. * @param {Object} payload
  7244. * @param {String} payload.unblockedBy 该操作的发起者 id
  7245. */
  7246. conversation.emit(UNBLOCKED$1, _payload7);
  7247. return _context4.abrupt("return");
  7248. case 43:
  7249. _payload8 = {
  7250. mutedBy: initBy,
  7251. members: m
  7252. };
  7253. /**
  7254. * 有成员在某个对话中被禁言
  7255. * @event IMClient#MEMBERS_MUTED
  7256. * @param {Object} payload
  7257. * @param {String[]} payload.members 成员 id 列表
  7258. * @param {String} payload.mutedBy 该操作的发起者 id
  7259. * @param {ConversationBase} conversation
  7260. */
  7261. this.emit(MEMBERS_MUTED$1, _payload8, conversation);
  7262. /**
  7263. * 有成员在当前对话中被禁言
  7264. * @event ConversationBase#MEMBERS_MUTED
  7265. * @param {Object} payload
  7266. * @param {String[]} payload.members 成员 id 列表
  7267. * @param {String} payload.mutedBy 该操作的发起者 id
  7268. */
  7269. conversation.emit(MEMBERS_MUTED$1, _payload8);
  7270. return _context4.abrupt("return");
  7271. case 47:
  7272. _payload9 = {
  7273. unmutedBy: initBy,
  7274. members: m
  7275. };
  7276. /**
  7277. * 有成员在某个对话中被解除禁言
  7278. * @event IMClient#MEMBERS_UNMUTED
  7279. * @param {Object} payload
  7280. * @param {String[]} payload.members 成员 id 列表
  7281. * @param {String} payload.unmutedBy 该操作的发起者 id
  7282. * @param {ConversationBase} conversation
  7283. */
  7284. this.emit(MEMBERS_UNMUTED$1, _payload9, conversation);
  7285. /**
  7286. * 有成员在当前对话中被解除禁言
  7287. * @event ConversationBase#MEMBERS_UNMUTED
  7288. * @param {Object} payload
  7289. * @param {String[]} payload.members 成员 id 列表
  7290. * @param {String} payload.unmutedBy 该操作的发起者 id
  7291. */
  7292. conversation.emit(MEMBERS_UNMUTED$1, _payload9);
  7293. return _context4.abrupt("return");
  7294. case 51:
  7295. _payload10 = {
  7296. mutedBy: initBy
  7297. };
  7298. /**
  7299. * 有成员在某个对话中被禁言
  7300. * @event IMClient#MUTED
  7301. * @param {Object} payload
  7302. * @param {String} payload.mutedBy 该操作的发起者 id
  7303. * @param {ConversationBase} conversation
  7304. */
  7305. this.emit(MUTED$1, _payload10, conversation);
  7306. /**
  7307. * 有成员在当前对话中被禁言
  7308. * @event ConversationBase#MUTED
  7309. * @param {Object} payload
  7310. * @param {String} payload.mutedBy 该操作的发起者 id
  7311. */
  7312. conversation.emit(MUTED$1, _payload10);
  7313. return _context4.abrupt("return");
  7314. case 55:
  7315. _payload11 = {
  7316. unmutedBy: initBy
  7317. };
  7318. /**
  7319. * 有成员在某个对话中被解除禁言
  7320. * @event IMClient#UNMUTED
  7321. * @param {Object} payload
  7322. * @param {String} payload.unmutedBy 该操作的发起者 id
  7323. * @param {ConversationBase} conversation
  7324. */
  7325. this.emit(UNMUTED$1, _payload11, conversation);
  7326. /**
  7327. * 有成员在当前对话中被解除禁言
  7328. * @event ConversationBase#UNMUTED
  7329. * @param {Object} payload
  7330. * @param {String} payload.unmutedBy 该操作的发起者 id
  7331. */
  7332. conversation.emit(UNMUTED$1, _payload11);
  7333. return _context4.abrupt("return");
  7334. case 59:
  7335. pid = info.pid, role = info.role;
  7336. _internal = internal(conversation), memberInfoMap = _internal.memberInfoMap; // 如果不存在缓存,且不是 role 的更新,则不通知
  7337. if (!(!memberInfoMap && !role)) {
  7338. _context4.next = 63;
  7339. break;
  7340. }
  7341. return _context4.abrupt("return");
  7342. case 63:
  7343. _context4.next = 65;
  7344. return conversation.getMemberInfo(pid);
  7345. case 65:
  7346. memberInfo = _context4.sent;
  7347. internal(memberInfo).role = role;
  7348. _payload12 = {
  7349. member: pid,
  7350. memberInfo: memberInfo,
  7351. updatedBy: initBy
  7352. };
  7353. /**
  7354. * 有成员的对话信息被更新
  7355. * @event IMClient#MEMBER_INFO_UPDATED
  7356. * @param {Object} payload
  7357. * @param {String} payload.member 被更新对话信息的成员 id
  7358. * @param {ConversationMumberInfo} payload.memberInfo 被更新的成员对话信息
  7359. * @param {String} payload.updatedBy 该操作的发起者 id
  7360. * @param {ConversationBase} conversation
  7361. */
  7362. this.emit(MEMBER_INFO_UPDATED$1, _payload12, conversation);
  7363. /**
  7364. * 有成员的对话信息被更新
  7365. * @event ConversationBase#MEMBER_INFO_UPDATED
  7366. * @param {Object} payload
  7367. * @param {String} payload.member 被更新对话信息的成员 id
  7368. * @param {ConversationMumberInfo} payload.memberInfo 被更新的成员对话信息
  7369. * @param {String} payload.updatedBy 该操作的发起者 id
  7370. */
  7371. conversation.emit(MEMBER_INFO_UPDATED$1, _payload12);
  7372. return _context4.abrupt("return");
  7373. case 71:
  7374. attributes = decode(JSON.parse(attr.data));
  7375. conversation._updateServerAttributes(attributes);
  7376. _payload13 = {
  7377. attributes: attributes,
  7378. updatedBy: initBy
  7379. };
  7380. /**
  7381. * 该对话信息被更新
  7382. * @event IMClient#CONVERSATION_INFO_UPDATED
  7383. * @param {Object} payload
  7384. * @param {Object} payload.attributes 被更新的属性
  7385. * @param {String} payload.updatedBy 该操作的发起者 id
  7386. * @param {ConversationBase} conversation
  7387. */
  7388. this.emit(CONVERSATION_INFO_UPDATED$1, _payload13, conversation);
  7389. /**
  7390. * 有对话信息被更新
  7391. * @event ConversationBase#INFO_UPDATED
  7392. * @param {Object} payload
  7393. * @param {Object} payload.attributes 被更新的属性
  7394. * @param {String} payload.updatedBy 该操作的发起者 id
  7395. */
  7396. conversation.emit(INFO_UPDATED$1, _payload13);
  7397. return _context4.abrupt("return");
  7398. case 77:
  7399. this.emit(UNHANDLED_MESSAGE$1, message);
  7400. throw new Error('Unrecognized conversation command');
  7401. case 79:
  7402. case "end":
  7403. return _context4.stop();
  7404. }
  7405. }
  7406. }, _callee4, this);
  7407. }));
  7408. function _dispatchConvMessage(_x4) {
  7409. return _dispatchConvMessage2.apply(this, arguments);
  7410. }
  7411. return _dispatchConvMessage;
  7412. }();
  7413. _proto._dispatchDirectMessage = function _dispatchDirectMessage(originalMessage) {
  7414. var _this4 = this;
  7415. var directMessage = originalMessage.directMessage,
  7416. _originalMessage$dire = originalMessage.directMessage,
  7417. id = _originalMessage$dire.id,
  7418. cid = _originalMessage$dire.cid,
  7419. fromPeerId = _originalMessage$dire.fromPeerId,
  7420. timestamp = _originalMessage$dire.timestamp,
  7421. _transient = _originalMessage$dire["transient"],
  7422. patchTimestamp = _originalMessage$dire.patchTimestamp,
  7423. mentionPids = _originalMessage$dire.mentionPids,
  7424. mentionAll = _originalMessage$dire.mentionAll,
  7425. binaryMsg = _originalMessage$dire.binaryMsg,
  7426. msg = _originalMessage$dire.msg;
  7427. var content = binaryMsg ? binaryMsg.toArrayBuffer() : msg;
  7428. return Promise.all([this.getConversation(directMessage.cid), this._messageParser.parse(content)]).then(function (_ref5) {
  7429. var _ref6 = _slicedToArray(_ref5, 2),
  7430. conversation = _ref6[0],
  7431. message = _ref6[1];
  7432. // deleted conversation
  7433. if (!conversation) return undefined;
  7434. var messageProps = {
  7435. id: id,
  7436. cid: cid,
  7437. timestamp: timestamp,
  7438. updatedAt: patchTimestamp,
  7439. from: fromPeerId,
  7440. mentionList: mentionPids,
  7441. mentionedAll: mentionAll
  7442. };
  7443. Object.assign(message, messageProps);
  7444. message._updateMentioned(_this4.id);
  7445. message._setStatus(MessageStatus.SENT); // filter outgoing message sent from another device
  7446. if (message.from !== _this4.id) {
  7447. if (!(_transient || conversation["transient"])) {
  7448. _this4._sendAck(message);
  7449. }
  7450. }
  7451. return _this4._dispatchParsedMessage(message, conversation);
  7452. });
  7453. };
  7454. _proto._dispatchParsedMessage = function _dispatchParsedMessage(message, conversation) {
  7455. var _this5 = this;
  7456. // beforeMessageDispatch hook
  7457. return applyDispatcher(this._plugins.beforeMessageDispatch, [message, conversation]).then(function (shouldDispatch) {
  7458. if (shouldDispatch === false) return;
  7459. conversation.lastMessage = message; // eslint-disable-line no-param-reassign
  7460. conversation.lastMessageAt = message.timestamp; // eslint-disable-line no-param-reassign
  7461. // filter outgoing message sent from another device
  7462. if (message.from !== _this5.id) {
  7463. conversation.unreadMessagesCount += 1; // eslint-disable-line no-param-reassign
  7464. if (message.mentioned) conversation._setUnreadMessagesMentioned(true);
  7465. }
  7466. /**
  7467. * 当前用户收到消息
  7468. * @event IMClient#MESSAGE
  7469. * @param {Message} message
  7470. * @param {ConversationBase} conversation 收到消息的对话
  7471. */
  7472. _this5.emit(MESSAGE$2, message, conversation);
  7473. /**
  7474. * 当前对话收到消息
  7475. * @event ConversationBase#MESSAGE
  7476. * @param {Message} message
  7477. */
  7478. conversation.emit(MESSAGE$2, message);
  7479. });
  7480. };
  7481. _proto._sendAck = function _sendAck(message) {
  7482. this._debug('send ack for %O', message);
  7483. var cid = message.cid;
  7484. if (!cid) {
  7485. throw new Error('missing cid');
  7486. }
  7487. if (!this._ackMessageBuffer[cid]) {
  7488. this._ackMessageBuffer[cid] = [];
  7489. }
  7490. this._ackMessageBuffer[cid].push(message);
  7491. return this._doSendAck();
  7492. } // jsdoc-ignore-start
  7493. ;
  7494. _proto. // jsdoc-ignore-end
  7495. _doSendAck = function _doSendAck() {
  7496. var _this6 = this;
  7497. // if not connected, just skip everything
  7498. if (!this._connection.is('connected')) return;
  7499. this._debug('do send ack %O', this._ackMessageBuffer);
  7500. Promise.all(Object.keys(this._ackMessageBuffer).map(function (cid) {
  7501. var convAckMessages = _this6._ackMessageBuffer[cid];
  7502. var timestamps = convAckMessages.map(function (message) {
  7503. return message.timestamp;
  7504. });
  7505. var command = new GenericCommand({
  7506. cmd: 'ack',
  7507. ackMessage: new AckCommand({
  7508. cid: cid,
  7509. fromts: Math.min.apply(null, timestamps),
  7510. tots: Math.max.apply(null, timestamps)
  7511. })
  7512. });
  7513. delete _this6._ackMessageBuffer[cid];
  7514. return _this6._send(command, false)["catch"](function (error) {
  7515. _this6._debug('send ack failed: %O', error);
  7516. _this6._ackMessageBuffer[cid] = convAckMessages;
  7517. });
  7518. }));
  7519. };
  7520. _proto._omitPeerId = function _omitPeerId(value) {
  7521. internal(this).peerIdOmittable = value;
  7522. };
  7523. _proto._send = function _send(cmd) {
  7524. var _this$_connection;
  7525. var command = cmd;
  7526. if (!internal(this).peerIdOmittable && this.id) {
  7527. command.peerId = this.id;
  7528. }
  7529. for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
  7530. args[_key3 - 1] = arguments[_key3];
  7531. }
  7532. return (_this$_connection = this._connection).send.apply(_this$_connection, [command].concat(args));
  7533. };
  7534. _proto._open = /*#__PURE__*/function () {
  7535. var _open2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(appId, tag, deviceId) {
  7536. var isReconnect,
  7537. _internal2,
  7538. lastUnreadNotifTime,
  7539. lastPatchTime,
  7540. lastNotificationTime,
  7541. command,
  7542. signatureResult,
  7543. sessionToken,
  7544. resCommand,
  7545. _resCommand,
  7546. peerId,
  7547. sessionMessage,
  7548. _resCommand$sessionMe,
  7549. token,
  7550. tokenTTL,
  7551. code,
  7552. serverTs,
  7553. serverTime,
  7554. _args5 = arguments;
  7555. return _regeneratorRuntime.wrap(function _callee5$(_context5) {
  7556. while (1) {
  7557. switch (_context5.prev = _context5.next) {
  7558. case 0:
  7559. isReconnect = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : false;
  7560. this._debug('open session');
  7561. _internal2 = internal(this), lastUnreadNotifTime = _internal2.lastUnreadNotifTime, lastPatchTime = _internal2.lastPatchTime, lastNotificationTime = _internal2.lastNotificationTime;
  7562. command = new GenericCommand({
  7563. cmd: 'session',
  7564. op: 'open',
  7565. appId: appId,
  7566. peerId: this.id,
  7567. sessionMessage: new SessionCommand({
  7568. ua: "js/".concat(version),
  7569. r: isReconnect,
  7570. lastUnreadNotifTime: lastUnreadNotifTime,
  7571. lastPatchTime: lastPatchTime,
  7572. configBitmap: configBitmap
  7573. })
  7574. });
  7575. if (isReconnect) {
  7576. _context5.next = 13;
  7577. break;
  7578. }
  7579. Object.assign(command.sessionMessage, trim({
  7580. tag: tag,
  7581. deviceId: deviceId
  7582. }));
  7583. if (!this.options.signatureFactory) {
  7584. _context5.next = 11;
  7585. break;
  7586. }
  7587. _context5.next = 9;
  7588. return runSignatureFactory(this.options.signatureFactory, [this._identity]);
  7589. case 9:
  7590. signatureResult = _context5.sent;
  7591. Object.assign(command.sessionMessage, keyRemap({
  7592. signature: 's',
  7593. timestamp: 't',
  7594. nonce: 'n'
  7595. }, signatureResult));
  7596. case 11:
  7597. _context5.next = 17;
  7598. break;
  7599. case 13:
  7600. _context5.next = 15;
  7601. return this._sessionManager.getSessionToken({
  7602. autoRefresh: false
  7603. });
  7604. case 15:
  7605. sessionToken = _context5.sent;
  7606. if (sessionToken && sessionToken !== Expirable.EXPIRED) {
  7607. Object.assign(command.sessionMessage, {
  7608. st: sessionToken
  7609. });
  7610. }
  7611. case 17:
  7612. _context5.prev = 17;
  7613. _context5.next = 20;
  7614. return this._send(command);
  7615. case 20:
  7616. resCommand = _context5.sent;
  7617. _context5.next = 32;
  7618. break;
  7619. case 23:
  7620. _context5.prev = 23;
  7621. _context5.t0 = _context5["catch"](17);
  7622. if (!(_context5.t0.code === ErrorCode.SESSION_TOKEN_EXPIRED)) {
  7623. _context5.next = 31;
  7624. break;
  7625. }
  7626. if (this._sessionManager) {
  7627. _context5.next = 28;
  7628. break;
  7629. }
  7630. throw new Error('Unexpected session expiration');
  7631. case 28:
  7632. debug$b('Session token expired, reopening');
  7633. this._sessionManager.revoke();
  7634. return _context5.abrupt("return", this._open(appId, tag, deviceId, isReconnect));
  7635. case 31:
  7636. throw _context5.t0;
  7637. case 32:
  7638. _resCommand = resCommand, peerId = _resCommand.peerId, sessionMessage = _resCommand.sessionMessage, _resCommand$sessionMe = _resCommand.sessionMessage, token = _resCommand$sessionMe.st, tokenTTL = _resCommand$sessionMe.stTtl, code = _resCommand$sessionMe.code, serverTs = _resCommand.serverTs;
  7639. if (!code) {
  7640. _context5.next = 35;
  7641. break;
  7642. }
  7643. throw createError(sessionMessage);
  7644. case 35:
  7645. if (peerId) {
  7646. this.id = peerId;
  7647. if (!this._identity) this._identity = peerId;
  7648. if (token) {
  7649. this._sessionManager = this._sessionManager || this._createSessionManager();
  7650. this._sessionManager.setSessionToken(token, tokenTTL);
  7651. }
  7652. serverTime = getTime(decodeDate(serverTs));
  7653. if (serverTs) {
  7654. internal(this).lastPatchTime = serverTime;
  7655. }
  7656. if (lastNotificationTime) {
  7657. // Do not await for it as this is failable
  7658. this._syncNotifications(lastNotificationTime)["catch"](function (error) {
  7659. return console.warn('Syncing notifications failed:', error);
  7660. });
  7661. } else {
  7662. // Set timestamp to now for next reconnection
  7663. internal(this).lastNotificationTime = serverTime;
  7664. }
  7665. } else {
  7666. console.warn('Unexpected session opened without peerId.');
  7667. }
  7668. return _context5.abrupt("return", undefined);
  7669. case 37:
  7670. case "end":
  7671. return _context5.stop();
  7672. }
  7673. }
  7674. }, _callee5, this, [[17, 23]]);
  7675. }));
  7676. function _open(_x5, _x6, _x7) {
  7677. return _open2.apply(this, arguments);
  7678. }
  7679. return _open;
  7680. }();
  7681. _proto._syncNotifications = /*#__PURE__*/function () {
  7682. var _syncNotifications2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(timestamp) {
  7683. var _this7 = this;
  7684. var _yield$this$_fetchNot, hasMore, notifications;
  7685. return _regeneratorRuntime.wrap(function _callee6$(_context6) {
  7686. while (1) {
  7687. switch (_context6.prev = _context6.next) {
  7688. case 0:
  7689. _context6.next = 2;
  7690. return this._fetchNotifications(timestamp);
  7691. case 2:
  7692. _yield$this$_fetchNot = _context6.sent;
  7693. hasMore = _yield$this$_fetchNot.hasMore;
  7694. notifications = _yield$this$_fetchNot.notifications;
  7695. notifications.forEach(function (notification) {
  7696. var cmd = notification.cmd,
  7697. op = notification.op,
  7698. serverTs = notification.serverTs,
  7699. notificationType = notification.notificationType,
  7700. payload = _objectWithoutProperties(notification, ["cmd", "op", "serverTs", "notificationType"]);
  7701. _this7._dispatchCommand(_defineProperty({
  7702. cmd: CommandType[cmd],
  7703. op: OpType[op],
  7704. serverTs: serverTs,
  7705. notificationType: notificationType
  7706. }, "".concat(cmd, "Message"), payload));
  7707. });
  7708. if (!hasMore) {
  7709. _context6.next = 8;
  7710. break;
  7711. }
  7712. return _context6.abrupt("return", this._syncNotifications(internal(this).lastNotificationTime));
  7713. case 8:
  7714. return _context6.abrupt("return", undefined);
  7715. case 9:
  7716. case "end":
  7717. return _context6.stop();
  7718. }
  7719. }
  7720. }, _callee6, this);
  7721. }));
  7722. function _syncNotifications(_x8) {
  7723. return _syncNotifications2.apply(this, arguments);
  7724. }
  7725. return _syncNotifications;
  7726. }();
  7727. _proto._fetchNotifications = /*#__PURE__*/function () {
  7728. var _fetchNotifications2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(timestamp) {
  7729. return _regeneratorRuntime.wrap(function _callee7$(_context7) {
  7730. while (1) {
  7731. switch (_context7.prev = _context7.next) {
  7732. case 0:
  7733. return _context7.abrupt("return", this._requestWithSessionToken({
  7734. method: 'GET',
  7735. path: '/rtm/notifications',
  7736. query: {
  7737. start_ts: timestamp,
  7738. notification_type: 'permanent'
  7739. }
  7740. }));
  7741. case 1:
  7742. case "end":
  7743. return _context7.stop();
  7744. }
  7745. }
  7746. }, _callee7, this);
  7747. }));
  7748. function _fetchNotifications(_x9) {
  7749. return _fetchNotifications2.apply(this, arguments);
  7750. }
  7751. return _fetchNotifications;
  7752. }();
  7753. _proto._createSessionManager = function _createSessionManager() {
  7754. var _this8 = this;
  7755. debug$b('create SessionManager');
  7756. return new SessionManager({
  7757. onBeforeGetSessionToken: this._connection.checkConnectionAvailability.bind(this._connection),
  7758. refresh: function refresh(manager, expiredSessionToken) {
  7759. return manager.setSessionTokenAsync(Promise.resolve(new GenericCommand({
  7760. cmd: 'session',
  7761. op: 'refresh',
  7762. sessionMessage: new SessionCommand({
  7763. ua: "js/".concat(version),
  7764. st: expiredSessionToken
  7765. })
  7766. })).then( /*#__PURE__*/function () {
  7767. var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(command) {
  7768. var signatureResult;
  7769. return _regeneratorRuntime.wrap(function _callee8$(_context8) {
  7770. while (1) {
  7771. switch (_context8.prev = _context8.next) {
  7772. case 0:
  7773. if (!_this8.options.signatureFactory) {
  7774. _context8.next = 5;
  7775. break;
  7776. }
  7777. _context8.next = 3;
  7778. return runSignatureFactory(_this8.options.signatureFactory, [_this8._identity]);
  7779. case 3:
  7780. signatureResult = _context8.sent;
  7781. Object.assign(command.sessionMessage, keyRemap({
  7782. signature: 's',
  7783. timestamp: 't',
  7784. nonce: 'n'
  7785. }, signatureResult));
  7786. case 5:
  7787. return _context8.abrupt("return", command);
  7788. case 6:
  7789. case "end":
  7790. return _context8.stop();
  7791. }
  7792. }
  7793. }, _callee8);
  7794. }));
  7795. return function (_x10) {
  7796. return _ref7.apply(this, arguments);
  7797. };
  7798. }()).then(_this8._send.bind(_this8)).then(function (_ref8) {
  7799. var _ref8$sessionMessage = _ref8.sessionMessage,
  7800. token = _ref8$sessionMessage.st,
  7801. ttl = _ref8$sessionMessage.stTtl;
  7802. return [token, ttl];
  7803. }));
  7804. }
  7805. });
  7806. };
  7807. _proto._requestWithSessionToken = /*#__PURE__*/function () {
  7808. var _requestWithSessionToken2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref9) {
  7809. var headers, query, params, sessionToken;
  7810. return _regeneratorRuntime.wrap(function _callee9$(_context9) {
  7811. while (1) {
  7812. switch (_context9.prev = _context9.next) {
  7813. case 0:
  7814. headers = _ref9.headers, query = _ref9.query, params = _objectWithoutProperties(_ref9, ["headers", "query"]);
  7815. _context9.next = 3;
  7816. return this._sessionManager.getSessionToken();
  7817. case 3:
  7818. sessionToken = _context9.sent;
  7819. return _context9.abrupt("return", this._request(_objectSpread$8({
  7820. headers: _objectSpread$8({
  7821. 'X-LC-IM-Session-Token': sessionToken
  7822. }, headers),
  7823. query: _objectSpread$8({
  7824. client_id: this.id
  7825. }, query)
  7826. }, params)));
  7827. case 5:
  7828. case "end":
  7829. return _context9.stop();
  7830. }
  7831. }
  7832. }, _callee9, this);
  7833. }));
  7834. function _requestWithSessionToken(_x11) {
  7835. return _requestWithSessionToken2.apply(this, arguments);
  7836. }
  7837. return _requestWithSessionToken;
  7838. }()
  7839. /**
  7840. * 关闭客户端
  7841. * @return {Promise}
  7842. */
  7843. ;
  7844. _proto.close =
  7845. /*#__PURE__*/
  7846. function () {
  7847. var _close = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
  7848. var _ee, command;
  7849. return _regeneratorRuntime.wrap(function _callee10$(_context10) {
  7850. while (1) {
  7851. switch (_context10.prev = _context10.next) {
  7852. case 0:
  7853. this._debug('close session');
  7854. _ee = internal(this)._eventemitter;
  7855. _ee.emit('beforeclose');
  7856. if (!this._connection.is('connected')) {
  7857. _context10.next = 7;
  7858. break;
  7859. }
  7860. command = new GenericCommand({
  7861. cmd: 'session',
  7862. op: 'close'
  7863. });
  7864. _context10.next = 7;
  7865. return this._send(command);
  7866. case 7:
  7867. _ee.emit('close');
  7868. this.emit(CLOSE$1, {
  7869. code: 0
  7870. });
  7871. case 9:
  7872. case "end":
  7873. return _context10.stop();
  7874. }
  7875. }
  7876. }, _callee10, this);
  7877. }));
  7878. function close() {
  7879. return _close.apply(this, arguments);
  7880. }
  7881. return close;
  7882. }()
  7883. /**
  7884. * 获取 client 列表中在线的 client,每次查询最多 20 个 clientId,超出部分会被忽略
  7885. * @param {String[]} clientIds 要查询的 client ids
  7886. * @return {Primse.<String[]>} 在线的 client ids
  7887. */
  7888. ;
  7889. _proto.ping =
  7890. /*#__PURE__*/
  7891. function () {
  7892. var _ping = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(clientIds) {
  7893. var command, resCommand;
  7894. return _regeneratorRuntime.wrap(function _callee11$(_context11) {
  7895. while (1) {
  7896. switch (_context11.prev = _context11.next) {
  7897. case 0:
  7898. this._debug('ping');
  7899. if (clientIds instanceof Array) {
  7900. _context11.next = 3;
  7901. break;
  7902. }
  7903. throw new TypeError("clientIds ".concat(clientIds, " is not an Array"));
  7904. case 3:
  7905. if (clientIds.length) {
  7906. _context11.next = 5;
  7907. break;
  7908. }
  7909. return _context11.abrupt("return", Promise.resolve([]));
  7910. case 5:
  7911. command = new GenericCommand({
  7912. cmd: 'session',
  7913. op: 'query',
  7914. sessionMessage: new SessionCommand({
  7915. sessionPeerIds: clientIds
  7916. })
  7917. });
  7918. _context11.next = 8;
  7919. return this._send(command);
  7920. case 8:
  7921. resCommand = _context11.sent;
  7922. return _context11.abrupt("return", resCommand.sessionMessage.onlineSessionPeerIds);
  7923. case 10:
  7924. case "end":
  7925. return _context11.stop();
  7926. }
  7927. }
  7928. }, _callee11, this);
  7929. }));
  7930. function ping(_x12) {
  7931. return _ping.apply(this, arguments);
  7932. }
  7933. return ping;
  7934. }()
  7935. /**
  7936. * 获取某个特定的对话
  7937. * @param {String} id 对话 id,对应 _Conversation 表中的 objectId
  7938. * @param {Boolean} [noCache=false] 强制不从缓存中获取
  7939. * @return {Promise.<ConversationBase>} 如果 id 对应的对话不存在则返回 null
  7940. */
  7941. ;
  7942. _proto.getConversation =
  7943. /*#__PURE__*/
  7944. function () {
  7945. var _getConversation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(id) {
  7946. var noCache,
  7947. cachedConversation,
  7948. _args12 = arguments;
  7949. return _regeneratorRuntime.wrap(function _callee12$(_context12) {
  7950. while (1) {
  7951. switch (_context12.prev = _context12.next) {
  7952. case 0:
  7953. noCache = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : false;
  7954. if (!(typeof id !== 'string')) {
  7955. _context12.next = 3;
  7956. break;
  7957. }
  7958. throw new TypeError("".concat(id, " is not a String"));
  7959. case 3:
  7960. if (noCache) {
  7961. _context12.next = 7;
  7962. break;
  7963. }
  7964. cachedConversation = this._conversationCache.get(id);
  7965. if (!cachedConversation) {
  7966. _context12.next = 7;
  7967. break;
  7968. }
  7969. return _context12.abrupt("return", cachedConversation);
  7970. case 7:
  7971. if (!isTemporaryConversatrionId(id)) {
  7972. _context12.next = 14;
  7973. break;
  7974. }
  7975. _context12.next = 10;
  7976. return this._getTemporaryConversations([id]);
  7977. case 10:
  7978. _context12.t0 = _context12.sent[0];
  7979. if (_context12.t0) {
  7980. _context12.next = 13;
  7981. break;
  7982. }
  7983. _context12.t0 = null;
  7984. case 13:
  7985. return _context12.abrupt("return", _context12.t0);
  7986. case 14:
  7987. return _context12.abrupt("return", this.getQuery().equalTo('objectId', id).find().then(function (conversations) {
  7988. return conversations[0] || null;
  7989. }));
  7990. case 15:
  7991. case "end":
  7992. return _context12.stop();
  7993. }
  7994. }
  7995. }, _callee12, this);
  7996. }));
  7997. function getConversation(_x13) {
  7998. return _getConversation.apply(this, arguments);
  7999. }
  8000. return getConversation;
  8001. }()
  8002. /**
  8003. * 通过 id 批量获取某个特定的对话
  8004. * @since 3.4.0
  8005. * @param {String[]} ids 对话 id 列表,对应 _Conversation 表中的 objectId
  8006. * @param {Boolean} [noCache=false] 强制不从缓存中获取
  8007. * @return {Promise.<ConversationBase[]>} 如果 id 对应的对话不存在则返回 null
  8008. */
  8009. ;
  8010. _proto.getConversations =
  8011. /*#__PURE__*/
  8012. function () {
  8013. var _getConversations = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(ids) {
  8014. var _this9 = this;
  8015. var noCache,
  8016. remoteConversationIds,
  8017. remoteTemporaryConversationIds,
  8018. query,
  8019. remoteTemporaryConversationsPromise,
  8020. _args13 = arguments;
  8021. return _regeneratorRuntime.wrap(function _callee13$(_context13) {
  8022. while (1) {
  8023. switch (_context13.prev = _context13.next) {
  8024. case 0:
  8025. noCache = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : false;
  8026. remoteConversationIds = noCache ? ids : ids.filter(function (id) {
  8027. return _this9._conversationCache.get(id) === null;
  8028. });
  8029. if (!remoteConversationIds.length) {
  8030. _context13.next = 9;
  8031. break;
  8032. }
  8033. remoteTemporaryConversationIds = remove(remoteConversationIds, isTemporaryConversatrionId);
  8034. query = [];
  8035. if (remoteConversationIds.length) {
  8036. query.push(this.getQuery().containedIn('objectId', remoteConversationIds).limit(999).find());
  8037. }
  8038. if (remoteTemporaryConversationIds.length) {
  8039. remoteTemporaryConversationsPromise = remoteTemporaryConversationIds.map(this._getTemporaryConversations.bind(this));
  8040. query.push.apply(query, _toConsumableArray(remoteTemporaryConversationsPromise));
  8041. }
  8042. _context13.next = 9;
  8043. return Promise.all(query);
  8044. case 9:
  8045. return _context13.abrupt("return", ids.map(function (id) {
  8046. return _this9._conversationCache.get(id);
  8047. }));
  8048. case 10:
  8049. case "end":
  8050. return _context13.stop();
  8051. }
  8052. }
  8053. }, _callee13, this);
  8054. }));
  8055. function getConversations(_x14) {
  8056. return _getConversations.apply(this, arguments);
  8057. }
  8058. return getConversations;
  8059. }();
  8060. _proto._getTemporaryConversations = /*#__PURE__*/function () {
  8061. var _getTemporaryConversations2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(ids) {
  8062. var command, resCommand;
  8063. return _regeneratorRuntime.wrap(function _callee14$(_context14) {
  8064. while (1) {
  8065. switch (_context14.prev = _context14.next) {
  8066. case 0:
  8067. command = new GenericCommand({
  8068. cmd: 'conv',
  8069. op: 'query',
  8070. convMessage: new ConvCommand({
  8071. tempConvIds: ids
  8072. })
  8073. });
  8074. _context14.next = 3;
  8075. return this._send(command);
  8076. case 3:
  8077. resCommand = _context14.sent;
  8078. return _context14.abrupt("return", this._handleQueryResults(resCommand));
  8079. case 5:
  8080. case "end":
  8081. return _context14.stop();
  8082. }
  8083. }
  8084. }, _callee14, this);
  8085. }));
  8086. function _getTemporaryConversations(_x15) {
  8087. return _getTemporaryConversations2.apply(this, arguments);
  8088. }
  8089. return _getTemporaryConversations;
  8090. }()
  8091. /**
  8092. * 构造一个 ConversationQuery 来查询对话
  8093. * @return {ConversationQuery.<PersistentConversation>}
  8094. */
  8095. ;
  8096. _proto.getQuery = function getQuery() {
  8097. return new ConversationQuery(this);
  8098. }
  8099. /**
  8100. * 构造一个 ConversationQuery 来查询聊天室
  8101. * @return {ConversationQuery.<ChatRoom>}
  8102. */
  8103. ;
  8104. _proto.getChatRoomQuery = function getChatRoomQuery() {
  8105. return this.getQuery().equalTo('tr', true);
  8106. }
  8107. /**
  8108. * 构造一个 ConversationQuery 来查询服务号
  8109. * @return {ConversationQuery.<ServiceConversation>}
  8110. */
  8111. ;
  8112. _proto.getServiceConversationQuery = function getServiceConversationQuery() {
  8113. return this.getQuery().equalTo('sys', true);
  8114. };
  8115. _proto._executeQuery = /*#__PURE__*/function () {
  8116. var _executeQuery2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(query) {
  8117. var queryJSON, command, resCommand;
  8118. return _regeneratorRuntime.wrap(function _callee15$(_context15) {
  8119. while (1) {
  8120. switch (_context15.prev = _context15.next) {
  8121. case 0:
  8122. queryJSON = query.toJSON();
  8123. queryJSON.where = new JsonObjectMessage({
  8124. data: JSON.stringify(encode(queryJSON.where))
  8125. });
  8126. command = new GenericCommand({
  8127. cmd: 'conv',
  8128. op: 'query',
  8129. convMessage: new ConvCommand(queryJSON)
  8130. });
  8131. _context15.next = 5;
  8132. return this._send(command);
  8133. case 5:
  8134. resCommand = _context15.sent;
  8135. return _context15.abrupt("return", this._handleQueryResults(resCommand));
  8136. case 7:
  8137. case "end":
  8138. return _context15.stop();
  8139. }
  8140. }
  8141. }, _callee15, this);
  8142. }));
  8143. function _executeQuery(_x16) {
  8144. return _executeQuery2.apply(this, arguments);
  8145. }
  8146. return _executeQuery;
  8147. }();
  8148. _proto._handleQueryResults = /*#__PURE__*/function () {
  8149. var _handleQueryResults2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(resCommand) {
  8150. var conversations, commandString;
  8151. return _regeneratorRuntime.wrap(function _callee16$(_context16) {
  8152. while (1) {
  8153. switch (_context16.prev = _context16.next) {
  8154. case 0:
  8155. _context16.prev = 0;
  8156. conversations = decode(JSON.parse(resCommand.convMessage.results.data));
  8157. _context16.next = 8;
  8158. break;
  8159. case 4:
  8160. _context16.prev = 4;
  8161. _context16.t0 = _context16["catch"](0);
  8162. commandString = JSON.stringify(trim(resCommand));
  8163. throw new Error("Parse query result failed: ".concat(_context16.t0.message, ". Command: ").concat(commandString));
  8164. case 8:
  8165. _context16.next = 10;
  8166. return Promise.all(conversations.map(this._parseConversationFromRawData.bind(this)));
  8167. case 10:
  8168. conversations = _context16.sent;
  8169. return _context16.abrupt("return", conversations.map(this._upsertConversationToCache.bind(this)));
  8170. case 12:
  8171. case "end":
  8172. return _context16.stop();
  8173. }
  8174. }
  8175. }, _callee16, this, [[0, 4]]);
  8176. }));
  8177. function _handleQueryResults(_x17) {
  8178. return _handleQueryResults2.apply(this, arguments);
  8179. }
  8180. return _handleQueryResults;
  8181. }();
  8182. _proto._upsertConversationToCache = function _upsertConversationToCache(fetchedConversation) {
  8183. var conversation = this._conversationCache.get(fetchedConversation.id);
  8184. if (!conversation) {
  8185. conversation = fetchedConversation;
  8186. this._debug('no match, set cache');
  8187. this._conversationCache.set(fetchedConversation.id, fetchedConversation);
  8188. } else {
  8189. this._debug('update cached conversation');
  8190. ['creator', 'createdAt', 'updatedAt', 'lastMessageAt', 'lastMessage', 'mutedMembers', 'members', '_attributes', 'transient', 'muted'].forEach(function (key) {
  8191. var value = fetchedConversation[key];
  8192. if (value !== undefined) conversation[key] = value;
  8193. });
  8194. if (conversation._reset) conversation._reset();
  8195. }
  8196. return conversation;
  8197. }
  8198. /**
  8199. * 反序列化消息,与 {@link Message#toFullJSON} 相对。
  8200. * @param {Object}
  8201. * @return {AVMessage} 解析后的消息
  8202. * @since 4.0.0
  8203. */
  8204. ;
  8205. _proto.parseMessage =
  8206. /*#__PURE__*/
  8207. function () {
  8208. var _parseMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref10) {
  8209. var data, _ref10$bin, bin, properties, content, message;
  8210. return _regeneratorRuntime.wrap(function _callee17$(_context17) {
  8211. while (1) {
  8212. switch (_context17.prev = _context17.next) {
  8213. case 0:
  8214. data = _ref10.data, _ref10$bin = _ref10.bin, bin = _ref10$bin === void 0 ? false : _ref10$bin, properties = _objectWithoutProperties(_ref10, ["data", "bin"]);
  8215. content = bin ? base64Arraybuffer.decode(data) : data;
  8216. _context17.next = 4;
  8217. return this._messageParser.parse(content);
  8218. case 4:
  8219. message = _context17.sent;
  8220. Object.assign(message, properties);
  8221. message._updateMentioned(this.id);
  8222. return _context17.abrupt("return", message);
  8223. case 8:
  8224. case "end":
  8225. return _context17.stop();
  8226. }
  8227. }
  8228. }, _callee17, this);
  8229. }));
  8230. function parseMessage(_x18) {
  8231. return _parseMessage.apply(this, arguments);
  8232. }
  8233. return parseMessage;
  8234. }()
  8235. /**
  8236. * 反序列化对话,与 {@link Conversation#toFullJSON} 相对。
  8237. * @param {Object}
  8238. * @return {ConversationBase} 解析后的对话
  8239. * @since 4.0.0
  8240. */
  8241. ;
  8242. _proto.parseConversation =
  8243. /*#__PURE__*/
  8244. function () {
  8245. var _parseConversation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(_ref11) {
  8246. var id, lastMessageAt, lastMessage, lastDeliveredAt, lastReadAt, unreadMessagesCount, members, mentioned, properties, conversationData, _transient2, system, expiredAt;
  8247. return _regeneratorRuntime.wrap(function _callee18$(_context18) {
  8248. while (1) {
  8249. switch (_context18.prev = _context18.next) {
  8250. case 0:
  8251. id = _ref11.id, lastMessageAt = _ref11.lastMessageAt, lastMessage = _ref11.lastMessage, lastDeliveredAt = _ref11.lastDeliveredAt, lastReadAt = _ref11.lastReadAt, unreadMessagesCount = _ref11.unreadMessagesCount, members = _ref11.members, mentioned = _ref11.mentioned, properties = _objectWithoutProperties(_ref11, ["id", "lastMessageAt", "lastMessage", "lastDeliveredAt", "lastReadAt", "unreadMessagesCount", "members", "mentioned"]);
  8252. conversationData = {
  8253. id: id,
  8254. lastMessageAt: lastMessageAt,
  8255. lastMessage: lastMessage,
  8256. lastDeliveredAt: lastDeliveredAt,
  8257. lastReadAt: lastReadAt,
  8258. unreadMessagesCount: unreadMessagesCount,
  8259. members: members,
  8260. mentioned: mentioned
  8261. };
  8262. if (!lastMessage) {
  8263. _context18.next = 7;
  8264. break;
  8265. }
  8266. _context18.next = 5;
  8267. return this.parseMessage(lastMessage);
  8268. case 5:
  8269. conversationData.lastMessage = _context18.sent;
  8270. conversationData.lastMessage._setStatus(MessageStatus.SENT);
  8271. case 7:
  8272. _transient2 = properties["transient"], system = properties.system, expiredAt = properties.expiredAt;
  8273. if (!_transient2) {
  8274. _context18.next = 10;
  8275. break;
  8276. }
  8277. return _context18.abrupt("return", new ChatRoom(conversationData, properties, this));
  8278. case 10:
  8279. if (!system) {
  8280. _context18.next = 12;
  8281. break;
  8282. }
  8283. return _context18.abrupt("return", new ServiceConversation(conversationData, properties, this));
  8284. case 12:
  8285. if (!(expiredAt || isTemporaryConversatrionId(id))) {
  8286. _context18.next = 14;
  8287. break;
  8288. }
  8289. return _context18.abrupt("return", new TemporaryConversation(conversationData, {
  8290. expiredAt: expiredAt
  8291. }, this));
  8292. case 14:
  8293. return _context18.abrupt("return", new Conversation(conversationData, properties, this));
  8294. case 15:
  8295. case "end":
  8296. return _context18.stop();
  8297. }
  8298. }
  8299. }, _callee18, this);
  8300. }));
  8301. function parseConversation(_x19) {
  8302. return _parseConversation.apply(this, arguments);
  8303. }
  8304. return parseConversation;
  8305. }();
  8306. _proto._parseConversationFromRawData = /*#__PURE__*/function () {
  8307. var _parseConversationFromRawData2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(rawData) {
  8308. var data, ttl;
  8309. return _regeneratorRuntime.wrap(function _callee19$(_context19) {
  8310. while (1) {
  8311. switch (_context19.prev = _context19.next) {
  8312. case 0:
  8313. data = keyRemap({
  8314. objectId: 'id',
  8315. lm: 'lastMessageAt',
  8316. m: 'members',
  8317. tr: 'transient',
  8318. sys: 'system',
  8319. c: 'creator',
  8320. mu: 'mutedMembers'
  8321. }, rawData);
  8322. if (data.msg) {
  8323. data.lastMessage = {
  8324. data: data.msg,
  8325. bin: data.bin,
  8326. from: data.msg_from,
  8327. id: data.msg_mid,
  8328. timestamp: data.msg_timestamp,
  8329. updatedAt: data.patch_timestamp
  8330. };
  8331. delete data.lastMessageFrom;
  8332. delete data.lastMessageId;
  8333. delete data.lastMessageTimestamp;
  8334. delete data.lastMessagePatchTimestamp;
  8335. }
  8336. ttl = data.ttl;
  8337. if (ttl) data.expiredAt = Date.now() + ttl * 1000;
  8338. return _context19.abrupt("return", this.parseConversation(data));
  8339. case 5:
  8340. case "end":
  8341. return _context19.stop();
  8342. }
  8343. }
  8344. }, _callee19, this);
  8345. }));
  8346. function _parseConversationFromRawData(_x20) {
  8347. return _parseConversationFromRawData2.apply(this, arguments);
  8348. }
  8349. return _parseConversationFromRawData;
  8350. }()
  8351. /**
  8352. * 创建一个对话
  8353. * @param {Object} options 除了下列字段外的其他字段将被视为对话的自定义属性
  8354. * @param {String[]} options.members 对话的初始成员列表,默认包含当前 client
  8355. * @param {String} [options.name] 对话的名字
  8356. * @param {Boolean} [options.unique=true] 唯一对话,当其为 true 时,如果当前已经有相同成员的对话存在则返回该对话,否则会创建新的对话
  8357. * @return {Promise.<Conversation>}
  8358. */
  8359. ;
  8360. _proto.createConversation =
  8361. /*#__PURE__*/
  8362. function () {
  8363. var _createConversation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20() {
  8364. var _ref12,
  8365. m,
  8366. name,
  8367. _transient3,
  8368. _ref12$unique,
  8369. unique,
  8370. tempConv,
  8371. tempConvTTL,
  8372. properties,
  8373. members,
  8374. attr,
  8375. startCommandJson,
  8376. command,
  8377. params,
  8378. signatureResult,
  8379. _yield$this$_send,
  8380. _yield$this$_send$con,
  8381. cid,
  8382. cdate,
  8383. ttl,
  8384. data,
  8385. conversation,
  8386. _args20 = arguments;
  8387. return _regeneratorRuntime.wrap(function _callee20$(_context20) {
  8388. while (1) {
  8389. switch (_context20.prev = _context20.next) {
  8390. case 0:
  8391. _ref12 = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : {}, m = _ref12.members, name = _ref12.name, _transient3 = _ref12["transient"], _ref12$unique = _ref12.unique, unique = _ref12$unique === void 0 ? true : _ref12$unique, tempConv = _ref12._tempConv, tempConvTTL = _ref12._tempConvTTL, properties = _objectWithoutProperties(_ref12, ["members", "name", "transient", "unique", "_tempConv", "_tempConvTTL"]);
  8392. if (_transient3 || Array.isArray(m)) {
  8393. _context20.next = 3;
  8394. break;
  8395. }
  8396. throw new TypeError("conversation members ".concat(m, " is not an array"));
  8397. case 3:
  8398. members = new Set(m);
  8399. members.add(this.id);
  8400. members = Array.from(members).sort();
  8401. attr = properties || {};
  8402. if (!name) {
  8403. _context20.next = 11;
  8404. break;
  8405. }
  8406. if (!(typeof name !== 'string')) {
  8407. _context20.next = 10;
  8408. break;
  8409. }
  8410. throw new TypeError("conversation name ".concat(name, " is not a string"));
  8411. case 10:
  8412. attr.name = name;
  8413. case 11:
  8414. attr = new JsonObjectMessage({
  8415. data: JSON.stringify(encode(attr))
  8416. });
  8417. startCommandJson = {
  8418. m: members,
  8419. attr: attr,
  8420. "transient": _transient3,
  8421. unique: unique,
  8422. tempConv: tempConv,
  8423. tempConvTTL: tempConvTTL
  8424. };
  8425. command = new GenericCommand({
  8426. cmd: 'conv',
  8427. op: 'start',
  8428. convMessage: new ConvCommand(startCommandJson)
  8429. });
  8430. if (!this.options.conversationSignatureFactory) {
  8431. _context20.next = 20;
  8432. break;
  8433. }
  8434. params = [null, this._identity, members, 'create'];
  8435. _context20.next = 18;
  8436. return runSignatureFactory(this.options.conversationSignatureFactory, params);
  8437. case 18:
  8438. signatureResult = _context20.sent;
  8439. Object.assign(command.convMessage, keyRemap({
  8440. signature: 's',
  8441. timestamp: 't',
  8442. nonce: 'n'
  8443. }, signatureResult));
  8444. case 20:
  8445. _context20.next = 22;
  8446. return this._send(command);
  8447. case 22:
  8448. _yield$this$_send = _context20.sent;
  8449. _yield$this$_send$con = _yield$this$_send.convMessage;
  8450. cid = _yield$this$_send$con.cid;
  8451. cdate = _yield$this$_send$con.cdate;
  8452. ttl = _yield$this$_send$con.tempConvTTL;
  8453. data = _objectSpread$8({
  8454. name: name,
  8455. "transient": _transient3,
  8456. unique: unique,
  8457. id: cid,
  8458. createdAt: cdate,
  8459. updatedAt: cdate,
  8460. lastMessageAt: null,
  8461. creator: this.id,
  8462. members: _transient3 ? [] : members
  8463. }, properties);
  8464. if (ttl) data.expiredAt = Date.now() + ttl * 1000;
  8465. _context20.next = 31;
  8466. return this.parseConversation(data);
  8467. case 31:
  8468. conversation = _context20.sent;
  8469. return _context20.abrupt("return", this._upsertConversationToCache(conversation));
  8470. case 33:
  8471. case "end":
  8472. return _context20.stop();
  8473. }
  8474. }
  8475. }, _callee20, this);
  8476. }));
  8477. function createConversation() {
  8478. return _createConversation.apply(this, arguments);
  8479. }
  8480. return createConversation;
  8481. }()
  8482. /**
  8483. * 创建一个聊天室
  8484. * @since 4.0.0
  8485. * @param {Object} options 除了下列字段外的其他字段将被视为对话的自定义属性
  8486. * @param {String} [options.name] 对话的名字
  8487. * @return {Promise.<ChatRoom>}
  8488. */
  8489. ;
  8490. _proto.createChatRoom =
  8491. /*#__PURE__*/
  8492. function () {
  8493. var _createChatRoom = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(param) {
  8494. return _regeneratorRuntime.wrap(function _callee21$(_context21) {
  8495. while (1) {
  8496. switch (_context21.prev = _context21.next) {
  8497. case 0:
  8498. return _context21.abrupt("return", this.createConversation(_objectSpread$8(_objectSpread$8({}, param), {}, {
  8499. "transient": true,
  8500. members: null,
  8501. unique: false,
  8502. _tempConv: false
  8503. })));
  8504. case 1:
  8505. case "end":
  8506. return _context21.stop();
  8507. }
  8508. }
  8509. }, _callee21, this);
  8510. }));
  8511. function createChatRoom(_x21) {
  8512. return _createChatRoom.apply(this, arguments);
  8513. }
  8514. return createChatRoom;
  8515. }()
  8516. /**
  8517. * 创建一个临时对话
  8518. * @since 4.0.0
  8519. * @param {Object} options
  8520. * @param {String[]} options.members 对话的初始成员列表,默认包含当前 client
  8521. * @param {String} [options.ttl] 对话存在时间,单位为秒,最大值与默认值均为 86400(一天),过期后该对话不再可用。
  8522. * @return {Promise.<TemporaryConversation>}
  8523. */
  8524. ;
  8525. _proto.createTemporaryConversation =
  8526. /*#__PURE__*/
  8527. function () {
  8528. var _createTemporaryConversation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(_ref13) {
  8529. var _tempConvTTL, param;
  8530. return _regeneratorRuntime.wrap(function _callee22$(_context22) {
  8531. while (1) {
  8532. switch (_context22.prev = _context22.next) {
  8533. case 0:
  8534. _tempConvTTL = _ref13.ttl, param = _objectWithoutProperties(_ref13, ["ttl"]);
  8535. return _context22.abrupt("return", this.createConversation(_objectSpread$8(_objectSpread$8({}, param), {}, {
  8536. _tempConv: true,
  8537. _tempConvTTL: _tempConvTTL
  8538. })));
  8539. case 2:
  8540. case "end":
  8541. return _context22.stop();
  8542. }
  8543. }
  8544. }, _callee22, this);
  8545. }));
  8546. function createTemporaryConversation(_x22) {
  8547. return _createTemporaryConversation.apply(this, arguments);
  8548. }
  8549. return createTemporaryConversation;
  8550. }() // jsdoc-ignore-start
  8551. ;
  8552. _proto. // jsdoc-ignore-end
  8553. _doSendRead = function _doSendRead() {
  8554. var _this10 = this;
  8555. // if not connected, just skip everything
  8556. if (!this._connection.is('connected')) return;
  8557. var buffer = internal(this).readConversationsBuffer;
  8558. var conversations = Array.from(buffer);
  8559. if (!conversations.length) return;
  8560. var ids = conversations.map(function (conversation) {
  8561. if (!(conversation instanceof ConversationBase)) {
  8562. throw new TypeError("".concat(conversation, " is not a Conversation"));
  8563. }
  8564. return conversation.id;
  8565. });
  8566. this._debug("mark [".concat(ids, "] as read"));
  8567. buffer.clear();
  8568. this._sendReadCommand(conversations)["catch"](function (error) {
  8569. _this10._debug('send read failed: %O', error);
  8570. conversations.forEach(buffer.add.bind(buffer));
  8571. });
  8572. };
  8573. _proto._sendReadCommand = function _sendReadCommand(conversations) {
  8574. var _this11 = this;
  8575. return this._send(new GenericCommand({
  8576. cmd: 'read',
  8577. readMessage: new ReadCommand({
  8578. convs: conversations.map(function (conversation) {
  8579. return new ReadTuple({
  8580. cid: conversation.id,
  8581. mid: conversation.lastMessage && conversation.lastMessage.from !== _this11.id ? conversation.lastMessage.id : undefined,
  8582. timestamp: (conversation.lastMessageAt || new Date()).getTime()
  8583. });
  8584. })
  8585. })
  8586. }), false);
  8587. };
  8588. return IMClient;
  8589. }(EventEmitter), (_applyDecoratedDescriptor(_class$3.prototype, "_doSendAck", [_dec$2], Object.getOwnPropertyDescriptor(_class$3.prototype, "_doSendAck"), _class$3.prototype), _applyDecoratedDescriptor(_class$3.prototype, "_doSendRead", [_dec2], Object.getOwnPropertyDescriptor(_class$3.prototype, "_doSendRead"), _class$3.prototype)), _class$3));
  8590. /**
  8591. * 修改、撤回消息的原因
  8592. * @typedef PatchReason
  8593. * @type {Object}
  8594. * @property {number} code 负数为内置 code,正数为开发者在 hook 中自定义的 code。比如因为敏感词过滤被修改的 code 为 -4408。
  8595. * @property {string} [detail] 具体的原因说明。
  8596. */
  8597. var RECONNECT_ERROR = 'reconnecterror';
  8598. var CoreEvent = /*#__PURE__*/Object.freeze({
  8599. __proto__: null,
  8600. RECONNECT_ERROR: RECONNECT_ERROR,
  8601. DISCONNECT: DISCONNECT,
  8602. RECONNECT: RECONNECT,
  8603. RETRY: RETRY,
  8604. SCHEDULE: SCHEDULE,
  8605. OFFLINE: OFFLINE,
  8606. ONLINE: ONLINE
  8607. });
  8608. var _class$4;
  8609. function ownKeys$9(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  8610. function _objectSpread$9(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$9(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$9(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  8611. var // jsdoc-ignore-end
  8612. BinaryMessage = IE10Compatible(_class$4 = /*#__PURE__*/function (_Message) {
  8613. _inheritsLoose(BinaryMessage, _Message);
  8614. /**
  8615. * 二进制消息
  8616. * @extends Message
  8617. * @param {ArrayBuffer} buffer
  8618. * @since 4.0.0
  8619. */
  8620. function BinaryMessage(buffer) {
  8621. if (!(buffer instanceof ArrayBuffer)) {
  8622. throw new TypeError("".concat(buffer, " is not an ArrayBuffer"));
  8623. }
  8624. return _Message.call(this, buffer) || this;
  8625. }
  8626. /**
  8627. * @type ArrayBuffer
  8628. */
  8629. BinaryMessage.validate = function validate(target) {
  8630. return target instanceof ArrayBuffer;
  8631. };
  8632. var _proto = BinaryMessage.prototype;
  8633. _proto.toJSON = function toJSON() {
  8634. return _objectSpread$9(_objectSpread$9({}, _Message.prototype._toJSON.call(this)), {}, {
  8635. data: base64Arraybuffer.encode(this.content)
  8636. });
  8637. };
  8638. _proto.toFullJSON = function toFullJSON() {
  8639. return _objectSpread$9(_objectSpread$9({}, _Message.prototype.toFullJSON.call(this)), {}, {
  8640. bin: true,
  8641. data: base64Arraybuffer.encode(this.content)
  8642. });
  8643. };
  8644. _createClass(BinaryMessage, [{
  8645. key: "buffer",
  8646. get: function get() {
  8647. return this.content;
  8648. },
  8649. set: function set(buffer) {
  8650. this.content = buffer;
  8651. }
  8652. }]);
  8653. return BinaryMessage;
  8654. }(Message)) || _class$4;
  8655. var _dec$3, _class$5;
  8656. var // jsdoc-ignore-end
  8657. TextMessage = (_dec$3 = messageType(-1), _dec$3(_class$5 = IE10Compatible(_class$5 = /*#__PURE__*/function (_TypedMessage) {
  8658. _inheritsLoose(TextMessage, _TypedMessage);
  8659. /**
  8660. * 文类类型消息
  8661. * @extends TypedMessage
  8662. * @param {String} [text='']
  8663. * @throws {TypeError} text 不是 String 类型
  8664. */
  8665. function TextMessage() {
  8666. var _this;
  8667. var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  8668. if (typeof text !== 'string') {
  8669. throw new TypeError("".concat(text, " is not a string"));
  8670. }
  8671. _this = _TypedMessage.call(this) || this;
  8672. _this.setText(text);
  8673. return _this;
  8674. }
  8675. return TextMessage;
  8676. }(TypedMessage)) || _class$5) || _class$5);
  8677. /**
  8678. * @name TYPE
  8679. * @memberof TextMessage
  8680. * @type Number
  8681. * @static
  8682. * @const
  8683. */
  8684. var _class$6;
  8685. function ownKeys$a(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  8686. function _objectSpread$a(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$a(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$a(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  8687. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  8688. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  8689. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  8690. var debug$c = d('LC:MessageParser');
  8691. var tryParseJson = function tryParseJson(target, key, descriptor) {
  8692. var fn = descriptor.value; // eslint-disable-next-line no-param-reassign
  8693. descriptor.value = function wrapper(param) {
  8694. var content;
  8695. if (typeof param !== 'string') {
  8696. content = param;
  8697. } else {
  8698. try {
  8699. content = JSON.parse(param);
  8700. } catch (error) {
  8701. content = param;
  8702. }
  8703. }
  8704. return fn.call(this, content);
  8705. };
  8706. };
  8707. var applyPlugins = function applyPlugins(target, key, descriptor) {
  8708. var fn = descriptor.value; // eslint-disable-next-line no-param-reassign
  8709. descriptor.value = function wrapper(json) {
  8710. var _this = this;
  8711. return Promise.resolve(json).then(applyMiddlewares(this._plugins.beforeMessageParse)).then(function (decoratedJson) {
  8712. return fn.call(_this, decoratedJson);
  8713. }).then(applyMiddlewares(this._plugins.afterMessageParse));
  8714. };
  8715. };
  8716. var MessageParser = (_class$6 = /*#__PURE__*/function () {
  8717. /**
  8718. * 消息解析器
  8719. * @param {Object} plugins 插件,插件的 messageClasses 会自动被注册,在解析时 beforeMessageParse 与 afterMessageParse Middleware 会被应用。
  8720. */
  8721. function MessageParser() {
  8722. var plugins = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  8723. this._plugins = plugins;
  8724. this._messageClasses = [];
  8725. this.register(plugins.messageClasses);
  8726. }
  8727. /**
  8728. * 注册消息类
  8729. *
  8730. * @param {Function | Function[]} messageClass 消息类,需要实现 {@link AVMessage} 接口,
  8731. * 建议继承自 {@link TypedMessage},也可以传入一个消息类数组。
  8732. * @throws {TypeError} 如果 messageClass 没有实现 {@link AVMessage} 接口则抛出异常
  8733. */
  8734. var _proto = MessageParser.prototype;
  8735. _proto.register = function register(messageClasses) {
  8736. var _this2 = this;
  8737. ensureArray(messageClasses).map(function (klass) {
  8738. return _this2._register(klass);
  8739. });
  8740. };
  8741. _proto._register = function _register(messageClass) {
  8742. if (messageClass && messageClass.parse && messageClass.prototype && messageClass.prototype.getPayload) {
  8743. this._messageClasses.unshift(messageClass);
  8744. } else {
  8745. throw new TypeError('Invalid messageClass');
  8746. }
  8747. } // jsdoc-ignore-start
  8748. ;
  8749. _proto. // jsdoc-ignore-end
  8750. /**
  8751. * 解析消息内容
  8752. * @param {Object | string | any} target 消息内容,如果是字符串会尝试 parse 为 JSON。
  8753. * @return {AVMessage} 解析后的消息
  8754. * @throws {Error} 如果不匹配任何注册的消息则抛出异常
  8755. */
  8756. parse = function parse(content) {
  8757. debug$c('parsing message: %O', content); // eslint-disable-next-line
  8758. var _iterator = _createForOfIteratorHelper(this._messageClasses),
  8759. _step;
  8760. try {
  8761. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  8762. var Klass = _step.value;
  8763. var contentCopy = isPlainObject(content) ? _objectSpread$a({}, content) : content;
  8764. var valid = void 0;
  8765. var result = void 0;
  8766. try {
  8767. valid = Klass.validate(contentCopy);
  8768. } catch (error) {// eslint-disable-line no-empty
  8769. }
  8770. if (valid) {
  8771. try {
  8772. result = Klass.parse(contentCopy);
  8773. } catch (error) {
  8774. console.warn('parsing a valid message content error', {
  8775. error: error,
  8776. Klass: Klass,
  8777. content: contentCopy
  8778. });
  8779. }
  8780. if (result !== undefined) {
  8781. debug$c('parse result: %O', result);
  8782. return result;
  8783. }
  8784. }
  8785. }
  8786. } catch (err) {
  8787. _iterator.e(err);
  8788. } finally {
  8789. _iterator.f();
  8790. }
  8791. throw new Error('No Message Class matched');
  8792. };
  8793. return MessageParser;
  8794. }(), (_applyDecoratedDescriptor(_class$6.prototype, "parse", [tryParseJson, applyPlugins], Object.getOwnPropertyDescriptor(_class$6.prototype, "parse"), _class$6.prototype)), _class$6);
  8795. function ownKeys$b(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  8796. function _objectSpread$b(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$b(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$b(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  8797. var debug$d = d('LC:IMPlugin');
  8798. /**
  8799. * 消息优先级枚举
  8800. * @enum {Number}
  8801. * @since 3.3.0
  8802. */
  8803. var MessagePriority = {
  8804. /** 高 */
  8805. HIGH: 1,
  8806. /** 普通 */
  8807. NORMAL: 2,
  8808. /** 低 */
  8809. LOW: 3
  8810. };
  8811. Object.freeze(MessagePriority);
  8812. /**
  8813. * 为 Conversation 定义一个新属性
  8814. * @param {String} prop 属性名
  8815. * @param {Object} [descriptor] 属性的描述符,参见 {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor#Description getOwnPropertyDescriptor#Description - MDN},默认为该属性名对应的 Conversation 自定义属性的 getter/setter
  8816. * @returns void
  8817. * @example
  8818. *
  8819. * conversation.get('type');
  8820. * conversation.set('type', 1);
  8821. *
  8822. * // equals to
  8823. * defineConversationProperty('type');
  8824. * conversation.type;
  8825. * conversation.type = 1;
  8826. */
  8827. var defineConversationProperty = function defineConversationProperty(prop) {
  8828. var descriptor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  8829. get: function get() {
  8830. return this.get(prop);
  8831. },
  8832. set: function set(value) {
  8833. this.set(prop, value);
  8834. }
  8835. };
  8836. Object.defineProperty(Conversation.prototype, prop, descriptor);
  8837. };
  8838. var onRealtimeCreate = function onRealtimeCreate(realtime) {
  8839. /* eslint-disable no-param-reassign */
  8840. var deviceId = uuid();
  8841. realtime._IMClients = {};
  8842. realtime._IMClientsCreationCount = 0;
  8843. var messageParser = new MessageParser(realtime._plugins);
  8844. realtime._messageParser = messageParser;
  8845. var signAVUser = /*#__PURE__*/function () {
  8846. var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(user) {
  8847. return _regeneratorRuntime.wrap(function _callee$(_context) {
  8848. while (1) {
  8849. switch (_context.prev = _context.next) {
  8850. case 0:
  8851. return _context.abrupt("return", realtime._request({
  8852. method: 'POST',
  8853. path: '/rtm/sign',
  8854. data: {
  8855. session_token: user.getSessionToken()
  8856. }
  8857. }));
  8858. case 1:
  8859. case "end":
  8860. return _context.stop();
  8861. }
  8862. }
  8863. }, _callee);
  8864. }));
  8865. return function signAVUser(_x) {
  8866. return _ref.apply(this, arguments);
  8867. };
  8868. }();
  8869. /**
  8870. * 注册消息类
  8871. *
  8872. * 在接收消息、查询消息时,会按照消息类注册顺序的逆序依次尝试解析消息内容
  8873. *
  8874. * @memberof Realtime
  8875. * @instance
  8876. * @param {Function | Function[]} messageClass 消息类,需要实现 {@link AVMessage} 接口,
  8877. * 建议继承自 {@link TypedMessage}
  8878. * @throws {TypeError} 如果 messageClass 没有实现 {@link AVMessage} 接口则抛出异常
  8879. */
  8880. var register = messageParser.register.bind(messageParser);
  8881. /**
  8882. * 创建一个即时通讯客户端,多次创建相同 id 的客户端会返回同一个实例
  8883. * @memberof Realtime
  8884. * @instance
  8885. * @param {String|AV.User} [identity] 客户端 identity,如果不指定该参数,服务端会随机生成一个字符串作为 identity,
  8886. * 如果传入一个已登录的 AV.User,则会使用该用户的 id 作为客户端 identity 登录。
  8887. * @param {Object} [options]
  8888. * @param {Function} [options.signatureFactory] open session 时的签名方法 // TODO need details
  8889. * @param {Function} [options.conversationSignatureFactory] 对话创建、增减成员操作时的签名方法
  8890. * @param {Function} [options.blacklistSignatureFactory] 黑名单操作时的签名方法
  8891. * @param {String} [options.tag] 客户端类型标记,以支持单点登录功能
  8892. * @param {String} [options.isReconnect=false] 单点登录时标记该次登录是不是应用启动时自动重新登录
  8893. * @return {Promise.<IMClient>}
  8894. */
  8895. var createIMClient = /*#__PURE__*/function () {
  8896. var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(identity) {
  8897. var _realtime$_open$then;
  8898. var _ref3,
  8899. tag,
  8900. isReconnect,
  8901. clientOptions,
  8902. lagecyTag,
  8903. id,
  8904. buildinOptions,
  8905. sessionToken,
  8906. _tag,
  8907. promise,
  8908. _args2 = arguments;
  8909. return _regeneratorRuntime.wrap(function _callee2$(_context2) {
  8910. while (1) {
  8911. switch (_context2.prev = _context2.next) {
  8912. case 0:
  8913. _ref3 = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}, tag = _ref3.tag, isReconnect = _ref3.isReconnect, clientOptions = _objectWithoutProperties(_ref3, ["tag", "isReconnect"]);
  8914. lagecyTag = _args2.length > 2 ? _args2[2] : undefined;
  8915. buildinOptions = {};
  8916. if (!identity) {
  8917. _context2.next = 19;
  8918. break;
  8919. }
  8920. if (!(typeof identity === 'string')) {
  8921. _context2.next = 8;
  8922. break;
  8923. }
  8924. id = identity;
  8925. _context2.next = 17;
  8926. break;
  8927. case 8:
  8928. if (!(identity.id && identity.getSessionToken)) {
  8929. _context2.next = 16;
  8930. break;
  8931. }
  8932. id = identity.id;
  8933. sessionToken = identity.getSessionToken();
  8934. if (sessionToken) {
  8935. _context2.next = 13;
  8936. break;
  8937. }
  8938. throw new Error('User must be authenticated');
  8939. case 13:
  8940. buildinOptions.signatureFactory = signAVUser;
  8941. _context2.next = 17;
  8942. break;
  8943. case 16:
  8944. throw new TypeError('Identity must be a String or an AV.User');
  8945. case 17:
  8946. if (!(realtime._IMClients[id] !== undefined)) {
  8947. _context2.next = 19;
  8948. break;
  8949. }
  8950. return _context2.abrupt("return", realtime._IMClients[id]);
  8951. case 19:
  8952. if (lagecyTag) {
  8953. console.warn('DEPRECATION createIMClient tag param: Use options.tag instead.');
  8954. }
  8955. _tag = tag || lagecyTag;
  8956. promise = (_realtime$_open$then = realtime._open().then(function (connection) {
  8957. var client = new IMClient(id, _objectSpread$b(_objectSpread$b({}, buildinOptions), clientOptions), {
  8958. _connection: connection,
  8959. _request: realtime._request.bind(realtime),
  8960. _messageParser: messageParser,
  8961. _plugins: realtime._plugins,
  8962. _identity: identity
  8963. });
  8964. connection.on(RECONNECT, function () {
  8965. return client._open(realtime._options.appId, _tag, deviceId, true)
  8966. /**
  8967. * 客户端连接恢复正常,该事件通常在 {@link Realtime#event:RECONNECT} 之后发生
  8968. * @event IMClient#RECONNECT
  8969. * @see Realtime#event:RECONNECT
  8970. * @since 3.2.0
  8971. */
  8972. /**
  8973. * 客户端重新登录发生错误(网络连接已恢复,但重新登录错误)
  8974. * @event IMClient#RECONNECT_ERROR
  8975. * @since 3.2.0
  8976. */
  8977. .then(function () {
  8978. return client.emit(RECONNECT);
  8979. }, function (error) {
  8980. return client.emit(RECONNECT_ERROR, error);
  8981. });
  8982. });
  8983. internal(client)._eventemitter.on('beforeclose', function () {
  8984. delete realtime._IMClients[client.id];
  8985. if (realtime._firstIMClient === client) {
  8986. delete realtime._firstIMClient;
  8987. }
  8988. }, realtime);
  8989. internal(client)._eventemitter.on('close', function () {
  8990. realtime._deregister(client);
  8991. }, realtime);
  8992. return client._open(realtime._options.appId, _tag, deviceId, isReconnect).then(function () {
  8993. realtime._IMClients[client.id] = client;
  8994. realtime._IMClientsCreationCount += 1;
  8995. if (realtime._IMClientsCreationCount === 1) {
  8996. client._omitPeerId(true);
  8997. realtime._firstIMClient = client;
  8998. } else if (realtime._IMClientsCreationCount > 1 && realtime._firstIMClient) {
  8999. realtime._firstIMClient._omitPeerId(false);
  9000. }
  9001. realtime._register(client);
  9002. return client;
  9003. })["catch"](function (error) {
  9004. delete realtime._IMClients[client.id];
  9005. throw error;
  9006. });
  9007. })).then.apply(_realtime$_open$then, _toConsumableArray(finalize(function () {
  9008. realtime._deregisterPending(promise);
  9009. })))["catch"](function (error) {
  9010. delete realtime._IMClients[id];
  9011. throw error;
  9012. });
  9013. if (identity) {
  9014. realtime._IMClients[id] = promise;
  9015. }
  9016. realtime._registerPending(promise);
  9017. return _context2.abrupt("return", promise);
  9018. case 25:
  9019. case "end":
  9020. return _context2.stop();
  9021. }
  9022. }
  9023. }, _callee2);
  9024. }));
  9025. return function createIMClient(_x2) {
  9026. return _ref2.apply(this, arguments);
  9027. };
  9028. }();
  9029. Object.assign(realtime, {
  9030. register: register,
  9031. createIMClient: createIMClient
  9032. });
  9033. /* eslint-enable no-param-reassign */
  9034. };
  9035. var beforeCommandDispatch = function beforeCommandDispatch(command, realtime) {
  9036. var isIMCommand = command.service === null || command.service === 2;
  9037. if (!isIMCommand) return true;
  9038. var targetClient = command.peerId ? realtime._IMClients[command.peerId] : realtime._firstIMClient;
  9039. if (targetClient) {
  9040. Promise.resolve(targetClient).then(function (client) {
  9041. return client._dispatchCommand(command);
  9042. })["catch"](debug$d);
  9043. } else {
  9044. debug$d('[WARN] Unexpected message received without any live client match: %O', trim(command));
  9045. }
  9046. return false;
  9047. };
  9048. var IMPlugin = {
  9049. name: 'leancloud-realtime-plugin-im',
  9050. onRealtimeCreate: onRealtimeCreate,
  9051. beforeCommandDispatch: beforeCommandDispatch,
  9052. messageClasses: [Message, BinaryMessage, RecalledMessage, TextMessage]
  9053. };
  9054. function ownKeys$c(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  9055. function _objectSpread$c(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$c(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$c(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  9056. Realtime.defineConversationProperty = defineConversationProperty;
  9057. Realtime.__preRegisteredPlugins = [IMPlugin];
  9058. var Event = _objectSpread$c(_objectSpread$c({}, CoreEvent), IMEvent);
  9059. /** core + plugins + platform adapters */
  9060. setAdapters({
  9061. WebSocket: platformAdaptersNode.WebSocket,
  9062. request: platformAdaptersNode.request
  9063. });
  9064. exports.EventEmitter = EventEmitter;
  9065. exports.BinaryMessage = BinaryMessage;
  9066. exports.ChatRoom = ChatRoom;
  9067. exports.Conversation = Conversation;
  9068. exports.ConversationMemberRole = ConversationMemberRole;
  9069. exports.ConversationQuery = ConversationQuery;
  9070. exports.ErrorCode = ErrorCode;
  9071. exports.Event = Event;
  9072. exports.IE10Compatible = IE10Compatible;
  9073. exports.IMPlugin = IMPlugin;
  9074. exports.Message = Message;
  9075. exports.MessageParser = MessageParser;
  9076. exports.MessagePriority = MessagePriority;
  9077. exports.MessageQueryDirection = MessageQueryDirection;
  9078. exports.MessageStatus = MessageStatus;
  9079. exports.Promise = polyfilledPromise;
  9080. exports.Protocals = message;
  9081. exports.Protocols = message;
  9082. exports.Realtime = Realtime;
  9083. exports.RecalledMessage = RecalledMessage;
  9084. exports.ServiceConversation = ServiceConversation;
  9085. exports.TemporaryConversation = TemporaryConversation;
  9086. exports.TextMessage = TextMessage;
  9087. exports.TypedMessage = TypedMessage;
  9088. exports.debug = debug$2;
  9089. exports.defineConversationProperty = defineConversationProperty;
  9090. exports.getAdapter = getAdapter;
  9091. exports.messageField = messageField;
  9092. exports.messageType = messageType;
  9093. exports.setAdapters = setAdapters;
  9094. //# sourceMappingURL=im-node.js.map