core.js 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247
  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 protobufLight = _interopDefault(require('protobufjs/dist/protobuf-light'));
  5. var EventEmitter = _interopDefault(require('eventemitter3'));
  6. var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator'));
  7. var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator'));
  8. var _toConsumableArray = _interopDefault(require('@babel/runtime/helpers/toConsumableArray'));
  9. var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty'));
  10. var _objectWithoutProperties = _interopDefault(require('@babel/runtime/helpers/objectWithoutProperties'));
  11. var _assertThisInitialized = _interopDefault(require('@babel/runtime/helpers/assertThisInitialized'));
  12. var _inheritsLoose = _interopDefault(require('@babel/runtime/helpers/inheritsLoose'));
  13. var d = _interopDefault(require('debug'));
  14. var shuffle = _interopDefault(require('lodash/shuffle'));
  15. var values = _interopDefault(require('lodash/values'));
  16. var _toArray = _interopDefault(require('@babel/runtime/helpers/toArray'));
  17. var _createClass = _interopDefault(require('@babel/runtime/helpers/createClass'));
  18. var _applyDecoratedDescriptor = _interopDefault(require('@babel/runtime/helpers/applyDecoratedDescriptor'));
  19. var StateMachine = _interopDefault(require('javascript-state-machine'));
  20. var _typeof = _interopDefault(require('@babel/runtime/helpers/typeof'));
  21. var isPlainObject = _interopDefault(require('lodash/isPlainObject'));
  22. var promiseTimeout = require('promise-timeout');
  23. var messageCompiled = protobufLight.newBuilder({})['import']({
  24. "package": 'push_server.messages2',
  25. syntax: 'proto2',
  26. options: {
  27. objc_class_prefix: 'AVIM'
  28. },
  29. messages: [{
  30. name: 'JsonObjectMessage',
  31. syntax: 'proto2',
  32. fields: [{
  33. rule: 'required',
  34. type: 'string',
  35. name: 'data',
  36. id: 1
  37. }]
  38. }, {
  39. name: 'UnreadTuple',
  40. syntax: 'proto2',
  41. fields: [{
  42. rule: 'required',
  43. type: 'string',
  44. name: 'cid',
  45. id: 1
  46. }, {
  47. rule: 'required',
  48. type: 'int32',
  49. name: 'unread',
  50. id: 2
  51. }, {
  52. rule: 'optional',
  53. type: 'string',
  54. name: 'mid',
  55. id: 3
  56. }, {
  57. rule: 'optional',
  58. type: 'int64',
  59. name: 'timestamp',
  60. id: 4
  61. }, {
  62. rule: 'optional',
  63. type: 'string',
  64. name: 'from',
  65. id: 5
  66. }, {
  67. rule: 'optional',
  68. type: 'string',
  69. name: 'data',
  70. id: 6
  71. }, {
  72. rule: 'optional',
  73. type: 'int64',
  74. name: 'patchTimestamp',
  75. id: 7
  76. }, {
  77. rule: 'optional',
  78. type: 'bool',
  79. name: 'mentioned',
  80. id: 8
  81. }, {
  82. rule: 'optional',
  83. type: 'bytes',
  84. name: 'binaryMsg',
  85. id: 9
  86. }, {
  87. rule: 'optional',
  88. type: 'int32',
  89. name: 'convType',
  90. id: 10
  91. }]
  92. }, {
  93. name: 'LogItem',
  94. syntax: 'proto2',
  95. fields: [{
  96. rule: 'optional',
  97. type: 'string',
  98. name: 'from',
  99. id: 1
  100. }, {
  101. rule: 'optional',
  102. type: 'string',
  103. name: 'data',
  104. id: 2
  105. }, {
  106. rule: 'optional',
  107. type: 'int64',
  108. name: 'timestamp',
  109. id: 3
  110. }, {
  111. rule: 'optional',
  112. type: 'string',
  113. name: 'msgId',
  114. id: 4
  115. }, {
  116. rule: 'optional',
  117. type: 'int64',
  118. name: 'ackAt',
  119. id: 5
  120. }, {
  121. rule: 'optional',
  122. type: 'int64',
  123. name: 'readAt',
  124. id: 6
  125. }, {
  126. rule: 'optional',
  127. type: 'int64',
  128. name: 'patchTimestamp',
  129. id: 7
  130. }, {
  131. rule: 'optional',
  132. type: 'bool',
  133. name: 'mentionAll',
  134. id: 8
  135. }, {
  136. rule: 'repeated',
  137. type: 'string',
  138. name: 'mentionPids',
  139. id: 9
  140. }, {
  141. rule: 'optional',
  142. type: 'bool',
  143. name: 'bin',
  144. id: 10
  145. }, {
  146. rule: 'optional',
  147. type: 'int32',
  148. name: 'convType',
  149. id: 11
  150. }]
  151. }, {
  152. name: 'ConvMemberInfo',
  153. syntax: 'proto2',
  154. fields: [{
  155. rule: 'optional',
  156. type: 'string',
  157. name: 'pid',
  158. id: 1
  159. }, {
  160. rule: 'optional',
  161. type: 'string',
  162. name: 'role',
  163. id: 2
  164. }, {
  165. rule: 'optional',
  166. type: 'string',
  167. name: 'infoId',
  168. id: 3
  169. }]
  170. }, {
  171. name: 'DataCommand',
  172. syntax: 'proto2',
  173. fields: [{
  174. rule: 'repeated',
  175. type: 'string',
  176. name: 'ids',
  177. id: 1
  178. }, {
  179. rule: 'repeated',
  180. type: 'JsonObjectMessage',
  181. name: 'msg',
  182. id: 2
  183. }, {
  184. rule: 'optional',
  185. type: 'bool',
  186. name: 'offline',
  187. id: 3
  188. }]
  189. }, {
  190. name: 'SessionCommand',
  191. syntax: 'proto2',
  192. fields: [{
  193. rule: 'optional',
  194. type: 'int64',
  195. name: 't',
  196. id: 1
  197. }, {
  198. rule: 'optional',
  199. type: 'string',
  200. name: 'n',
  201. id: 2
  202. }, {
  203. rule: 'optional',
  204. type: 'string',
  205. name: 's',
  206. id: 3
  207. }, {
  208. rule: 'optional',
  209. type: 'string',
  210. name: 'ua',
  211. id: 4
  212. }, {
  213. rule: 'optional',
  214. type: 'bool',
  215. name: 'r',
  216. id: 5
  217. }, {
  218. rule: 'optional',
  219. type: 'string',
  220. name: 'tag',
  221. id: 6
  222. }, {
  223. rule: 'optional',
  224. type: 'string',
  225. name: 'deviceId',
  226. id: 7
  227. }, {
  228. rule: 'repeated',
  229. type: 'string',
  230. name: 'sessionPeerIds',
  231. id: 8
  232. }, {
  233. rule: 'repeated',
  234. type: 'string',
  235. name: 'onlineSessionPeerIds',
  236. id: 9
  237. }, {
  238. rule: 'optional',
  239. type: 'string',
  240. name: 'st',
  241. id: 10
  242. }, {
  243. rule: 'optional',
  244. type: 'int32',
  245. name: 'stTtl',
  246. id: 11
  247. }, {
  248. rule: 'optional',
  249. type: 'int32',
  250. name: 'code',
  251. id: 12
  252. }, {
  253. rule: 'optional',
  254. type: 'string',
  255. name: 'reason',
  256. id: 13
  257. }, {
  258. rule: 'optional',
  259. type: 'string',
  260. name: 'deviceToken',
  261. id: 14
  262. }, {
  263. rule: 'optional',
  264. type: 'bool',
  265. name: 'sp',
  266. id: 15
  267. }, {
  268. rule: 'optional',
  269. type: 'string',
  270. name: 'detail',
  271. id: 16
  272. }, {
  273. rule: 'optional',
  274. type: 'int64',
  275. name: 'lastUnreadNotifTime',
  276. id: 17
  277. }, {
  278. rule: 'optional',
  279. type: 'int64',
  280. name: 'lastPatchTime',
  281. id: 18
  282. }, {
  283. rule: 'optional',
  284. type: 'int64',
  285. name: 'configBitmap',
  286. id: 19
  287. }]
  288. }, {
  289. name: 'ErrorCommand',
  290. syntax: 'proto2',
  291. fields: [{
  292. rule: 'required',
  293. type: 'int32',
  294. name: 'code',
  295. id: 1
  296. }, {
  297. rule: 'required',
  298. type: 'string',
  299. name: 'reason',
  300. id: 2
  301. }, {
  302. rule: 'optional',
  303. type: 'int32',
  304. name: 'appCode',
  305. id: 3
  306. }, {
  307. rule: 'optional',
  308. type: 'string',
  309. name: 'detail',
  310. id: 4
  311. }, {
  312. rule: 'repeated',
  313. type: 'string',
  314. name: 'pids',
  315. id: 5
  316. }, {
  317. rule: 'optional',
  318. type: 'string',
  319. name: 'appMsg',
  320. id: 6
  321. }]
  322. }, {
  323. name: 'DirectCommand',
  324. syntax: 'proto2',
  325. fields: [{
  326. rule: 'optional',
  327. type: 'string',
  328. name: 'msg',
  329. id: 1
  330. }, {
  331. rule: 'optional',
  332. type: 'string',
  333. name: 'uid',
  334. id: 2
  335. }, {
  336. rule: 'optional',
  337. type: 'string',
  338. name: 'fromPeerId',
  339. id: 3
  340. }, {
  341. rule: 'optional',
  342. type: 'int64',
  343. name: 'timestamp',
  344. id: 4
  345. }, {
  346. rule: 'optional',
  347. type: 'bool',
  348. name: 'offline',
  349. id: 5
  350. }, {
  351. rule: 'optional',
  352. type: 'bool',
  353. name: 'hasMore',
  354. id: 6
  355. }, {
  356. rule: 'repeated',
  357. type: 'string',
  358. name: 'toPeerIds',
  359. id: 7
  360. }, {
  361. rule: 'optional',
  362. type: 'bool',
  363. name: 'r',
  364. id: 10
  365. }, {
  366. rule: 'optional',
  367. type: 'string',
  368. name: 'cid',
  369. id: 11
  370. }, {
  371. rule: 'optional',
  372. type: 'string',
  373. name: 'id',
  374. id: 12
  375. }, {
  376. rule: 'optional',
  377. type: 'bool',
  378. name: 'transient',
  379. id: 13
  380. }, {
  381. rule: 'optional',
  382. type: 'string',
  383. name: 'dt',
  384. id: 14
  385. }, {
  386. rule: 'optional',
  387. type: 'string',
  388. name: 'roomId',
  389. id: 15
  390. }, {
  391. rule: 'optional',
  392. type: 'string',
  393. name: 'pushData',
  394. id: 16
  395. }, {
  396. rule: 'optional',
  397. type: 'bool',
  398. name: 'will',
  399. id: 17
  400. }, {
  401. rule: 'optional',
  402. type: 'int64',
  403. name: 'patchTimestamp',
  404. id: 18
  405. }, {
  406. rule: 'optional',
  407. type: 'bytes',
  408. name: 'binaryMsg',
  409. id: 19
  410. }, {
  411. rule: 'repeated',
  412. type: 'string',
  413. name: 'mentionPids',
  414. id: 20
  415. }, {
  416. rule: 'optional',
  417. type: 'bool',
  418. name: 'mentionAll',
  419. id: 21
  420. }, {
  421. rule: 'optional',
  422. type: 'int32',
  423. name: 'convType',
  424. id: 22
  425. }]
  426. }, {
  427. name: 'AckCommand',
  428. syntax: 'proto2',
  429. fields: [{
  430. rule: 'optional',
  431. type: 'int32',
  432. name: 'code',
  433. id: 1
  434. }, {
  435. rule: 'optional',
  436. type: 'string',
  437. name: 'reason',
  438. id: 2
  439. }, {
  440. rule: 'optional',
  441. type: 'string',
  442. name: 'mid',
  443. id: 3
  444. }, {
  445. rule: 'optional',
  446. type: 'string',
  447. name: 'cid',
  448. id: 4
  449. }, {
  450. rule: 'optional',
  451. type: 'int64',
  452. name: 't',
  453. id: 5
  454. }, {
  455. rule: 'optional',
  456. type: 'string',
  457. name: 'uid',
  458. id: 6
  459. }, {
  460. rule: 'optional',
  461. type: 'int64',
  462. name: 'fromts',
  463. id: 7
  464. }, {
  465. rule: 'optional',
  466. type: 'int64',
  467. name: 'tots',
  468. id: 8
  469. }, {
  470. rule: 'optional',
  471. type: 'string',
  472. name: 'type',
  473. id: 9
  474. }, {
  475. rule: 'repeated',
  476. type: 'string',
  477. name: 'ids',
  478. id: 10
  479. }, {
  480. rule: 'optional',
  481. type: 'int32',
  482. name: 'appCode',
  483. id: 11
  484. }, {
  485. rule: 'optional',
  486. type: 'string',
  487. name: 'appMsg',
  488. id: 12
  489. }]
  490. }, {
  491. name: 'UnreadCommand',
  492. syntax: 'proto2',
  493. fields: [{
  494. rule: 'repeated',
  495. type: 'UnreadTuple',
  496. name: 'convs',
  497. id: 1
  498. }, {
  499. rule: 'optional',
  500. type: 'int64',
  501. name: 'notifTime',
  502. id: 2
  503. }]
  504. }, {
  505. name: 'ConvCommand',
  506. syntax: 'proto2',
  507. fields: [{
  508. rule: 'repeated',
  509. type: 'string',
  510. name: 'm',
  511. id: 1
  512. }, {
  513. rule: 'optional',
  514. type: 'bool',
  515. name: 'transient',
  516. id: 2
  517. }, {
  518. rule: 'optional',
  519. type: 'bool',
  520. name: 'unique',
  521. id: 3
  522. }, {
  523. rule: 'optional',
  524. type: 'string',
  525. name: 'cid',
  526. id: 4
  527. }, {
  528. rule: 'optional',
  529. type: 'string',
  530. name: 'cdate',
  531. id: 5
  532. }, {
  533. rule: 'optional',
  534. type: 'string',
  535. name: 'initBy',
  536. id: 6
  537. }, {
  538. rule: 'optional',
  539. type: 'string',
  540. name: 'sort',
  541. id: 7
  542. }, {
  543. rule: 'optional',
  544. type: 'int32',
  545. name: 'limit',
  546. id: 8
  547. }, {
  548. rule: 'optional',
  549. type: 'int32',
  550. name: 'skip',
  551. id: 9
  552. }, {
  553. rule: 'optional',
  554. type: 'int32',
  555. name: 'flag',
  556. id: 10
  557. }, {
  558. rule: 'optional',
  559. type: 'int32',
  560. name: 'count',
  561. id: 11
  562. }, {
  563. rule: 'optional',
  564. type: 'string',
  565. name: 'udate',
  566. id: 12
  567. }, {
  568. rule: 'optional',
  569. type: 'int64',
  570. name: 't',
  571. id: 13
  572. }, {
  573. rule: 'optional',
  574. type: 'string',
  575. name: 'n',
  576. id: 14
  577. }, {
  578. rule: 'optional',
  579. type: 'string',
  580. name: 's',
  581. id: 15
  582. }, {
  583. rule: 'optional',
  584. type: 'bool',
  585. name: 'statusSub',
  586. id: 16
  587. }, {
  588. rule: 'optional',
  589. type: 'bool',
  590. name: 'statusPub',
  591. id: 17
  592. }, {
  593. rule: 'optional',
  594. type: 'int32',
  595. name: 'statusTTL',
  596. id: 18
  597. }, {
  598. rule: 'optional',
  599. type: 'string',
  600. name: 'uniqueId',
  601. id: 19
  602. }, {
  603. rule: 'optional',
  604. type: 'string',
  605. name: 'targetClientId',
  606. id: 20
  607. }, {
  608. rule: 'optional',
  609. type: 'int64',
  610. name: 'maxReadTimestamp',
  611. id: 21
  612. }, {
  613. rule: 'optional',
  614. type: 'int64',
  615. name: 'maxAckTimestamp',
  616. id: 22
  617. }, {
  618. rule: 'optional',
  619. type: 'bool',
  620. name: 'queryAllMembers',
  621. id: 23
  622. }, {
  623. rule: 'repeated',
  624. type: 'MaxReadTuple',
  625. name: 'maxReadTuples',
  626. id: 24
  627. }, {
  628. rule: 'repeated',
  629. type: 'string',
  630. name: 'cids',
  631. id: 25
  632. }, {
  633. rule: 'optional',
  634. type: 'ConvMemberInfo',
  635. name: 'info',
  636. id: 26
  637. }, {
  638. rule: 'optional',
  639. type: 'bool',
  640. name: 'tempConv',
  641. id: 27
  642. }, {
  643. rule: 'optional',
  644. type: 'int32',
  645. name: 'tempConvTTL',
  646. id: 28
  647. }, {
  648. rule: 'repeated',
  649. type: 'string',
  650. name: 'tempConvIds',
  651. id: 29
  652. }, {
  653. rule: 'repeated',
  654. type: 'string',
  655. name: 'allowedPids',
  656. id: 30
  657. }, {
  658. rule: 'repeated',
  659. type: 'ErrorCommand',
  660. name: 'failedPids',
  661. id: 31
  662. }, {
  663. rule: 'optional',
  664. type: 'string',
  665. name: 'next',
  666. id: 40
  667. }, {
  668. rule: 'optional',
  669. type: 'JsonObjectMessage',
  670. name: 'results',
  671. id: 100
  672. }, {
  673. rule: 'optional',
  674. type: 'JsonObjectMessage',
  675. name: 'where',
  676. id: 101
  677. }, {
  678. rule: 'optional',
  679. type: 'JsonObjectMessage',
  680. name: 'attr',
  681. id: 103
  682. }, {
  683. rule: 'optional',
  684. type: 'JsonObjectMessage',
  685. name: 'attrModified',
  686. id: 104
  687. }]
  688. }, {
  689. name: 'RoomCommand',
  690. syntax: 'proto2',
  691. fields: [{
  692. rule: 'optional',
  693. type: 'string',
  694. name: 'roomId',
  695. id: 1
  696. }, {
  697. rule: 'optional',
  698. type: 'string',
  699. name: 's',
  700. id: 2
  701. }, {
  702. rule: 'optional',
  703. type: 'int64',
  704. name: 't',
  705. id: 3
  706. }, {
  707. rule: 'optional',
  708. type: 'string',
  709. name: 'n',
  710. id: 4
  711. }, {
  712. rule: 'optional',
  713. type: 'bool',
  714. name: 'transient',
  715. id: 5
  716. }, {
  717. rule: 'repeated',
  718. type: 'string',
  719. name: 'roomPeerIds',
  720. id: 6
  721. }, {
  722. rule: 'optional',
  723. type: 'string',
  724. name: 'byPeerId',
  725. id: 7
  726. }]
  727. }, {
  728. name: 'LogsCommand',
  729. syntax: 'proto2',
  730. fields: [{
  731. rule: 'optional',
  732. type: 'string',
  733. name: 'cid',
  734. id: 1
  735. }, {
  736. rule: 'optional',
  737. type: 'int32',
  738. name: 'l',
  739. id: 2
  740. }, {
  741. rule: 'optional',
  742. type: 'int32',
  743. name: 'limit',
  744. id: 3
  745. }, {
  746. rule: 'optional',
  747. type: 'int64',
  748. name: 't',
  749. id: 4
  750. }, {
  751. rule: 'optional',
  752. type: 'int64',
  753. name: 'tt',
  754. id: 5
  755. }, {
  756. rule: 'optional',
  757. type: 'string',
  758. name: 'tmid',
  759. id: 6
  760. }, {
  761. rule: 'optional',
  762. type: 'string',
  763. name: 'mid',
  764. id: 7
  765. }, {
  766. rule: 'optional',
  767. type: 'string',
  768. name: 'checksum',
  769. id: 8
  770. }, {
  771. rule: 'optional',
  772. type: 'bool',
  773. name: 'stored',
  774. id: 9
  775. }, {
  776. rule: 'optional',
  777. type: 'QueryDirection',
  778. name: 'direction',
  779. id: 10,
  780. options: {
  781. "default": 'OLD'
  782. }
  783. }, {
  784. rule: 'optional',
  785. type: 'bool',
  786. name: 'tIncluded',
  787. id: 11
  788. }, {
  789. rule: 'optional',
  790. type: 'bool',
  791. name: 'ttIncluded',
  792. id: 12
  793. }, {
  794. rule: 'optional',
  795. type: 'int32',
  796. name: 'lctype',
  797. id: 13
  798. }, {
  799. rule: 'repeated',
  800. type: 'LogItem',
  801. name: 'logs',
  802. id: 105
  803. }],
  804. enums: [{
  805. name: 'QueryDirection',
  806. syntax: 'proto2',
  807. values: [{
  808. name: 'OLD',
  809. id: 1
  810. }, {
  811. name: 'NEW',
  812. id: 2
  813. }]
  814. }]
  815. }, {
  816. name: 'RcpCommand',
  817. syntax: 'proto2',
  818. fields: [{
  819. rule: 'optional',
  820. type: 'string',
  821. name: 'id',
  822. id: 1
  823. }, {
  824. rule: 'optional',
  825. type: 'string',
  826. name: 'cid',
  827. id: 2
  828. }, {
  829. rule: 'optional',
  830. type: 'int64',
  831. name: 't',
  832. id: 3
  833. }, {
  834. rule: 'optional',
  835. type: 'bool',
  836. name: 'read',
  837. id: 4
  838. }, {
  839. rule: 'optional',
  840. type: 'string',
  841. name: 'from',
  842. id: 5
  843. }]
  844. }, {
  845. name: 'ReadTuple',
  846. syntax: 'proto2',
  847. fields: [{
  848. rule: 'required',
  849. type: 'string',
  850. name: 'cid',
  851. id: 1
  852. }, {
  853. rule: 'optional',
  854. type: 'int64',
  855. name: 'timestamp',
  856. id: 2
  857. }, {
  858. rule: 'optional',
  859. type: 'string',
  860. name: 'mid',
  861. id: 3
  862. }]
  863. }, {
  864. name: 'MaxReadTuple',
  865. syntax: 'proto2',
  866. fields: [{
  867. rule: 'optional',
  868. type: 'string',
  869. name: 'pid',
  870. id: 1
  871. }, {
  872. rule: 'optional',
  873. type: 'int64',
  874. name: 'maxAckTimestamp',
  875. id: 2
  876. }, {
  877. rule: 'optional',
  878. type: 'int64',
  879. name: 'maxReadTimestamp',
  880. id: 3
  881. }]
  882. }, {
  883. name: 'ReadCommand',
  884. syntax: 'proto2',
  885. fields: [{
  886. rule: 'optional',
  887. type: 'string',
  888. name: 'cid',
  889. id: 1
  890. }, {
  891. rule: 'repeated',
  892. type: 'string',
  893. name: 'cids',
  894. id: 2
  895. }, {
  896. rule: 'repeated',
  897. type: 'ReadTuple',
  898. name: 'convs',
  899. id: 3
  900. }]
  901. }, {
  902. name: 'PresenceCommand',
  903. syntax: 'proto2',
  904. fields: [{
  905. rule: 'optional',
  906. type: 'StatusType',
  907. name: 'status',
  908. id: 1
  909. }, {
  910. rule: 'repeated',
  911. type: 'string',
  912. name: 'sessionPeerIds',
  913. id: 2
  914. }, {
  915. rule: 'optional',
  916. type: 'string',
  917. name: 'cid',
  918. id: 3
  919. }]
  920. }, {
  921. name: 'ReportCommand',
  922. syntax: 'proto2',
  923. fields: [{
  924. rule: 'optional',
  925. type: 'bool',
  926. name: 'initiative',
  927. id: 1
  928. }, {
  929. rule: 'optional',
  930. type: 'string',
  931. name: 'type',
  932. id: 2
  933. }, {
  934. rule: 'optional',
  935. type: 'string',
  936. name: 'data',
  937. id: 3
  938. }]
  939. }, {
  940. name: 'PatchItem',
  941. syntax: 'proto2',
  942. fields: [{
  943. rule: 'optional',
  944. type: 'string',
  945. name: 'cid',
  946. id: 1
  947. }, {
  948. rule: 'optional',
  949. type: 'string',
  950. name: 'mid',
  951. id: 2
  952. }, {
  953. rule: 'optional',
  954. type: 'int64',
  955. name: 'timestamp',
  956. id: 3
  957. }, {
  958. rule: 'optional',
  959. type: 'bool',
  960. name: 'recall',
  961. id: 4
  962. }, {
  963. rule: 'optional',
  964. type: 'string',
  965. name: 'data',
  966. id: 5
  967. }, {
  968. rule: 'optional',
  969. type: 'int64',
  970. name: 'patchTimestamp',
  971. id: 6
  972. }, {
  973. rule: 'optional',
  974. type: 'string',
  975. name: 'from',
  976. id: 7
  977. }, {
  978. rule: 'optional',
  979. type: 'bytes',
  980. name: 'binaryMsg',
  981. id: 8
  982. }, {
  983. rule: 'optional',
  984. type: 'bool',
  985. name: 'mentionAll',
  986. id: 9
  987. }, {
  988. rule: 'repeated',
  989. type: 'string',
  990. name: 'mentionPids',
  991. id: 10
  992. }, {
  993. rule: 'optional',
  994. type: 'int64',
  995. name: 'patchCode',
  996. id: 11
  997. }, {
  998. rule: 'optional',
  999. type: 'string',
  1000. name: 'patchReason',
  1001. id: 12
  1002. }]
  1003. }, {
  1004. name: 'PatchCommand',
  1005. syntax: 'proto2',
  1006. fields: [{
  1007. rule: 'repeated',
  1008. type: 'PatchItem',
  1009. name: 'patches',
  1010. id: 1
  1011. }, {
  1012. rule: 'optional',
  1013. type: 'int64',
  1014. name: 'lastPatchTime',
  1015. id: 2
  1016. }]
  1017. }, {
  1018. name: 'PubsubCommand',
  1019. syntax: 'proto2',
  1020. fields: [{
  1021. rule: 'optional',
  1022. type: 'string',
  1023. name: 'cid',
  1024. id: 1
  1025. }, {
  1026. rule: 'repeated',
  1027. type: 'string',
  1028. name: 'cids',
  1029. id: 2
  1030. }, {
  1031. rule: 'optional',
  1032. type: 'string',
  1033. name: 'topic',
  1034. id: 3
  1035. }, {
  1036. rule: 'optional',
  1037. type: 'string',
  1038. name: 'subtopic',
  1039. id: 4
  1040. }, {
  1041. rule: 'repeated',
  1042. type: 'string',
  1043. name: 'topics',
  1044. id: 5
  1045. }, {
  1046. rule: 'repeated',
  1047. type: 'string',
  1048. name: 'subtopics',
  1049. id: 6
  1050. }, {
  1051. rule: 'optional',
  1052. type: 'JsonObjectMessage',
  1053. name: 'results',
  1054. id: 7
  1055. }]
  1056. }, {
  1057. name: 'BlacklistCommand',
  1058. syntax: 'proto2',
  1059. fields: [{
  1060. rule: 'optional',
  1061. type: 'string',
  1062. name: 'srcCid',
  1063. id: 1
  1064. }, {
  1065. rule: 'repeated',
  1066. type: 'string',
  1067. name: 'toPids',
  1068. id: 2
  1069. }, {
  1070. rule: 'optional',
  1071. type: 'string',
  1072. name: 'srcPid',
  1073. id: 3
  1074. }, {
  1075. rule: 'repeated',
  1076. type: 'string',
  1077. name: 'toCids',
  1078. id: 4
  1079. }, {
  1080. rule: 'optional',
  1081. type: 'int32',
  1082. name: 'limit',
  1083. id: 5
  1084. }, {
  1085. rule: 'optional',
  1086. type: 'string',
  1087. name: 'next',
  1088. id: 6
  1089. }, {
  1090. rule: 'repeated',
  1091. type: 'string',
  1092. name: 'blockedPids',
  1093. id: 8
  1094. }, {
  1095. rule: 'repeated',
  1096. type: 'string',
  1097. name: 'blockedCids',
  1098. id: 9
  1099. }, {
  1100. rule: 'repeated',
  1101. type: 'string',
  1102. name: 'allowedPids',
  1103. id: 10
  1104. }, {
  1105. rule: 'repeated',
  1106. type: 'ErrorCommand',
  1107. name: 'failedPids',
  1108. id: 11
  1109. }, {
  1110. rule: 'optional',
  1111. type: 'int64',
  1112. name: 't',
  1113. id: 12
  1114. }, {
  1115. rule: 'optional',
  1116. type: 'string',
  1117. name: 'n',
  1118. id: 13
  1119. }, {
  1120. rule: 'optional',
  1121. type: 'string',
  1122. name: 's',
  1123. id: 14
  1124. }]
  1125. }, {
  1126. name: 'GenericCommand',
  1127. syntax: 'proto2',
  1128. fields: [{
  1129. rule: 'optional',
  1130. type: 'CommandType',
  1131. name: 'cmd',
  1132. id: 1
  1133. }, {
  1134. rule: 'optional',
  1135. type: 'OpType',
  1136. name: 'op',
  1137. id: 2
  1138. }, {
  1139. rule: 'optional',
  1140. type: 'string',
  1141. name: 'appId',
  1142. id: 3
  1143. }, {
  1144. rule: 'optional',
  1145. type: 'string',
  1146. name: 'peerId',
  1147. id: 4
  1148. }, {
  1149. rule: 'optional',
  1150. type: 'int32',
  1151. name: 'i',
  1152. id: 5
  1153. }, {
  1154. rule: 'optional',
  1155. type: 'string',
  1156. name: 'installationId',
  1157. id: 6
  1158. }, {
  1159. rule: 'optional',
  1160. type: 'int32',
  1161. name: 'priority',
  1162. id: 7
  1163. }, {
  1164. rule: 'optional',
  1165. type: 'int32',
  1166. name: 'service',
  1167. id: 8
  1168. }, {
  1169. rule: 'optional',
  1170. type: 'int64',
  1171. name: 'serverTs',
  1172. id: 9
  1173. }, {
  1174. rule: 'optional',
  1175. type: 'int64',
  1176. name: 'clientTs',
  1177. id: 10
  1178. }, {
  1179. rule: 'optional',
  1180. type: 'int32',
  1181. name: 'notificationType',
  1182. id: 11
  1183. }, {
  1184. rule: 'optional',
  1185. type: 'DataCommand',
  1186. name: 'dataMessage',
  1187. id: 101
  1188. }, {
  1189. rule: 'optional',
  1190. type: 'SessionCommand',
  1191. name: 'sessionMessage',
  1192. id: 102
  1193. }, {
  1194. rule: 'optional',
  1195. type: 'ErrorCommand',
  1196. name: 'errorMessage',
  1197. id: 103
  1198. }, {
  1199. rule: 'optional',
  1200. type: 'DirectCommand',
  1201. name: 'directMessage',
  1202. id: 104
  1203. }, {
  1204. rule: 'optional',
  1205. type: 'AckCommand',
  1206. name: 'ackMessage',
  1207. id: 105
  1208. }, {
  1209. rule: 'optional',
  1210. type: 'UnreadCommand',
  1211. name: 'unreadMessage',
  1212. id: 106
  1213. }, {
  1214. rule: 'optional',
  1215. type: 'ReadCommand',
  1216. name: 'readMessage',
  1217. id: 107
  1218. }, {
  1219. rule: 'optional',
  1220. type: 'RcpCommand',
  1221. name: 'rcpMessage',
  1222. id: 108
  1223. }, {
  1224. rule: 'optional',
  1225. type: 'LogsCommand',
  1226. name: 'logsMessage',
  1227. id: 109
  1228. }, {
  1229. rule: 'optional',
  1230. type: 'ConvCommand',
  1231. name: 'convMessage',
  1232. id: 110
  1233. }, {
  1234. rule: 'optional',
  1235. type: 'RoomCommand',
  1236. name: 'roomMessage',
  1237. id: 111
  1238. }, {
  1239. rule: 'optional',
  1240. type: 'PresenceCommand',
  1241. name: 'presenceMessage',
  1242. id: 112
  1243. }, {
  1244. rule: 'optional',
  1245. type: 'ReportCommand',
  1246. name: 'reportMessage',
  1247. id: 113
  1248. }, {
  1249. rule: 'optional',
  1250. type: 'PatchCommand',
  1251. name: 'patchMessage',
  1252. id: 114
  1253. }, {
  1254. rule: 'optional',
  1255. type: 'PubsubCommand',
  1256. name: 'pubsubMessage',
  1257. id: 115
  1258. }, {
  1259. rule: 'optional',
  1260. type: 'BlacklistCommand',
  1261. name: 'blacklistMessage',
  1262. id: 116
  1263. }]
  1264. }],
  1265. enums: [{
  1266. name: 'CommandType',
  1267. syntax: 'proto2',
  1268. values: [{
  1269. name: 'session',
  1270. id: 0
  1271. }, {
  1272. name: 'conv',
  1273. id: 1
  1274. }, {
  1275. name: 'direct',
  1276. id: 2
  1277. }, {
  1278. name: 'ack',
  1279. id: 3
  1280. }, {
  1281. name: 'rcp',
  1282. id: 4
  1283. }, {
  1284. name: 'unread',
  1285. id: 5
  1286. }, {
  1287. name: 'logs',
  1288. id: 6
  1289. }, {
  1290. name: 'error',
  1291. id: 7
  1292. }, {
  1293. name: 'login',
  1294. id: 8
  1295. }, {
  1296. name: 'data',
  1297. id: 9
  1298. }, {
  1299. name: 'room',
  1300. id: 10
  1301. }, {
  1302. name: 'read',
  1303. id: 11
  1304. }, {
  1305. name: 'presence',
  1306. id: 12
  1307. }, {
  1308. name: 'report',
  1309. id: 13
  1310. }, {
  1311. name: 'echo',
  1312. id: 14
  1313. }, {
  1314. name: 'loggedin',
  1315. id: 15
  1316. }, {
  1317. name: 'logout',
  1318. id: 16
  1319. }, {
  1320. name: 'loggedout',
  1321. id: 17
  1322. }, {
  1323. name: 'patch',
  1324. id: 18
  1325. }, {
  1326. name: 'pubsub',
  1327. id: 19
  1328. }, {
  1329. name: 'blacklist',
  1330. id: 20
  1331. }, {
  1332. name: 'goaway',
  1333. id: 21
  1334. }]
  1335. }, {
  1336. name: 'OpType',
  1337. syntax: 'proto2',
  1338. values: [{
  1339. name: 'open',
  1340. id: 1
  1341. }, {
  1342. name: 'add',
  1343. id: 2
  1344. }, {
  1345. name: 'remove',
  1346. id: 3
  1347. }, {
  1348. name: 'close',
  1349. id: 4
  1350. }, {
  1351. name: 'opened',
  1352. id: 5
  1353. }, {
  1354. name: 'closed',
  1355. id: 6
  1356. }, {
  1357. name: 'query',
  1358. id: 7
  1359. }, {
  1360. name: 'query_result',
  1361. id: 8
  1362. }, {
  1363. name: 'conflict',
  1364. id: 9
  1365. }, {
  1366. name: 'added',
  1367. id: 10
  1368. }, {
  1369. name: 'removed',
  1370. id: 11
  1371. }, {
  1372. name: 'refresh',
  1373. id: 12
  1374. }, {
  1375. name: 'refreshed',
  1376. id: 13
  1377. }, {
  1378. name: 'start',
  1379. id: 30
  1380. }, {
  1381. name: 'started',
  1382. id: 31
  1383. }, {
  1384. name: 'joined',
  1385. id: 32
  1386. }, {
  1387. name: 'members_joined',
  1388. id: 33
  1389. }, {
  1390. name: 'left',
  1391. id: 39
  1392. }, {
  1393. name: 'members_left',
  1394. id: 40
  1395. }, {
  1396. name: 'results',
  1397. id: 42
  1398. }, {
  1399. name: 'count',
  1400. id: 43
  1401. }, {
  1402. name: 'result',
  1403. id: 44
  1404. }, {
  1405. name: 'update',
  1406. id: 45
  1407. }, {
  1408. name: 'updated',
  1409. id: 46
  1410. }, {
  1411. name: 'mute',
  1412. id: 47
  1413. }, {
  1414. name: 'unmute',
  1415. id: 48
  1416. }, {
  1417. name: 'status',
  1418. id: 49
  1419. }, {
  1420. name: 'members',
  1421. id: 50
  1422. }, {
  1423. name: 'max_read',
  1424. id: 51
  1425. }, {
  1426. name: 'is_member',
  1427. id: 52
  1428. }, {
  1429. name: 'member_info_update',
  1430. id: 53
  1431. }, {
  1432. name: 'member_info_updated',
  1433. id: 54
  1434. }, {
  1435. name: 'member_info_changed',
  1436. id: 55
  1437. }, {
  1438. name: 'join',
  1439. id: 80
  1440. }, {
  1441. name: 'invite',
  1442. id: 81
  1443. }, {
  1444. name: 'leave',
  1445. id: 82
  1446. }, {
  1447. name: 'kick',
  1448. id: 83
  1449. }, {
  1450. name: 'reject',
  1451. id: 84
  1452. }, {
  1453. name: 'invited',
  1454. id: 85
  1455. }, {
  1456. name: 'kicked',
  1457. id: 86
  1458. }, {
  1459. name: 'upload',
  1460. id: 100
  1461. }, {
  1462. name: 'uploaded',
  1463. id: 101
  1464. }, {
  1465. name: 'subscribe',
  1466. id: 120
  1467. }, {
  1468. name: 'subscribed',
  1469. id: 121
  1470. }, {
  1471. name: 'unsubscribe',
  1472. id: 122
  1473. }, {
  1474. name: 'unsubscribed',
  1475. id: 123
  1476. }, {
  1477. name: 'is_subscribed',
  1478. id: 124
  1479. }, {
  1480. name: 'modify',
  1481. id: 150
  1482. }, {
  1483. name: 'modified',
  1484. id: 151
  1485. }, {
  1486. name: 'block',
  1487. id: 170
  1488. }, {
  1489. name: 'unblock',
  1490. id: 171
  1491. }, {
  1492. name: 'blocked',
  1493. id: 172
  1494. }, {
  1495. name: 'unblocked',
  1496. id: 173
  1497. }, {
  1498. name: 'members_blocked',
  1499. id: 174
  1500. }, {
  1501. name: 'members_unblocked',
  1502. id: 175
  1503. }, {
  1504. name: 'check_block',
  1505. id: 176
  1506. }, {
  1507. name: 'check_result',
  1508. id: 177
  1509. }, {
  1510. name: 'add_shutup',
  1511. id: 180
  1512. }, {
  1513. name: 'remove_shutup',
  1514. id: 181
  1515. }, {
  1516. name: 'query_shutup',
  1517. id: 182
  1518. }, {
  1519. name: 'shutup_added',
  1520. id: 183
  1521. }, {
  1522. name: 'shutup_removed',
  1523. id: 184
  1524. }, {
  1525. name: 'shutup_result',
  1526. id: 185
  1527. }, {
  1528. name: 'shutuped',
  1529. id: 186
  1530. }, {
  1531. name: 'unshutuped',
  1532. id: 187
  1533. }, {
  1534. name: 'members_shutuped',
  1535. id: 188
  1536. }, {
  1537. name: 'members_unshutuped',
  1538. id: 189
  1539. }, {
  1540. name: 'check_shutup',
  1541. id: 190
  1542. }]
  1543. }, {
  1544. name: 'StatusType',
  1545. syntax: 'proto2',
  1546. values: [{
  1547. name: 'on',
  1548. id: 1
  1549. }, {
  1550. name: 'off',
  1551. id: 2
  1552. }]
  1553. }],
  1554. isNamespace: true
  1555. }).build();
  1556. var _messages$push_server = messageCompiled.push_server.messages2,
  1557. JsonObjectMessage = _messages$push_server.JsonObjectMessage,
  1558. UnreadTuple = _messages$push_server.UnreadTuple,
  1559. LogItem = _messages$push_server.LogItem,
  1560. DataCommand = _messages$push_server.DataCommand,
  1561. SessionCommand = _messages$push_server.SessionCommand,
  1562. ErrorCommand = _messages$push_server.ErrorCommand,
  1563. DirectCommand = _messages$push_server.DirectCommand,
  1564. AckCommand = _messages$push_server.AckCommand,
  1565. UnreadCommand = _messages$push_server.UnreadCommand,
  1566. ConvCommand = _messages$push_server.ConvCommand,
  1567. RoomCommand = _messages$push_server.RoomCommand,
  1568. LogsCommand = _messages$push_server.LogsCommand,
  1569. RcpCommand = _messages$push_server.RcpCommand,
  1570. ReadTuple = _messages$push_server.ReadTuple,
  1571. MaxReadTuple = _messages$push_server.MaxReadTuple,
  1572. ReadCommand = _messages$push_server.ReadCommand,
  1573. PresenceCommand = _messages$push_server.PresenceCommand,
  1574. ReportCommand = _messages$push_server.ReportCommand,
  1575. GenericCommand = _messages$push_server.GenericCommand,
  1576. BlacklistCommand = _messages$push_server.BlacklistCommand,
  1577. PatchCommand = _messages$push_server.PatchCommand,
  1578. PatchItem = _messages$push_server.PatchItem,
  1579. ConvMemberInfo = _messages$push_server.ConvMemberInfo,
  1580. CommandType = _messages$push_server.CommandType,
  1581. OpType = _messages$push_server.OpType,
  1582. StatusType = _messages$push_server.StatusType;
  1583. var message = /*#__PURE__*/Object.freeze({
  1584. __proto__: null,
  1585. JsonObjectMessage: JsonObjectMessage,
  1586. UnreadTuple: UnreadTuple,
  1587. LogItem: LogItem,
  1588. DataCommand: DataCommand,
  1589. SessionCommand: SessionCommand,
  1590. ErrorCommand: ErrorCommand,
  1591. DirectCommand: DirectCommand,
  1592. AckCommand: AckCommand,
  1593. UnreadCommand: UnreadCommand,
  1594. ConvCommand: ConvCommand,
  1595. RoomCommand: RoomCommand,
  1596. LogsCommand: LogsCommand,
  1597. RcpCommand: RcpCommand,
  1598. ReadTuple: ReadTuple,
  1599. MaxReadTuple: MaxReadTuple,
  1600. ReadCommand: ReadCommand,
  1601. PresenceCommand: PresenceCommand,
  1602. ReportCommand: ReportCommand,
  1603. GenericCommand: GenericCommand,
  1604. BlacklistCommand: BlacklistCommand,
  1605. PatchCommand: PatchCommand,
  1606. PatchItem: PatchItem,
  1607. ConvMemberInfo: ConvMemberInfo,
  1608. CommandType: CommandType,
  1609. OpType: OpType,
  1610. StatusType: StatusType
  1611. });
  1612. var adapters = {};
  1613. var getAdapter = function getAdapter(name) {
  1614. var adapter = adapters[name];
  1615. if (adapter === undefined) {
  1616. throw new Error("".concat(name, " adapter is not configured"));
  1617. }
  1618. return adapter;
  1619. };
  1620. /**
  1621. * 指定 Adapters
  1622. * @function
  1623. * @memberof module:leancloud-realtime
  1624. * @param {Adapters} newAdapters Adapters 的类型请参考 {@link https://url.leanapp.cn/adapter-type-definitions @leancloud/adapter-types} 中的定义
  1625. */
  1626. var setAdapters = function setAdapters(newAdapters) {
  1627. Object.assign(adapters, newAdapters);
  1628. };
  1629. /* eslint-disable */
  1630. var global$1 = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : {};
  1631. var EXPIRED = Symbol('expired');
  1632. var debug = d('LC:Expirable');
  1633. var Expirable = /*#__PURE__*/function () {
  1634. function Expirable(value, ttl) {
  1635. this.originalValue = value;
  1636. if (typeof ttl === 'number') {
  1637. this.expiredAt = Date.now() + ttl;
  1638. }
  1639. }
  1640. _createClass(Expirable, [{
  1641. key: "value",
  1642. get: function get() {
  1643. var expired = this.expiredAt && this.expiredAt <= Date.now();
  1644. if (expired) debug("expired: ".concat(this.originalValue));
  1645. return expired ? EXPIRED : this.originalValue;
  1646. }
  1647. }]);
  1648. return Expirable;
  1649. }();
  1650. Expirable.EXPIRED = EXPIRED;
  1651. var debug$1 = d('LC:Cache');
  1652. var Cache = /*#__PURE__*/function () {
  1653. function Cache() {
  1654. var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'anonymous';
  1655. this.name = name;
  1656. this._map = {};
  1657. }
  1658. var _proto = Cache.prototype;
  1659. _proto.get = function get(key) {
  1660. var cache = this._map[key];
  1661. if (cache) {
  1662. var value = cache.value;
  1663. if (value !== Expirable.EXPIRED) {
  1664. debug$1('[%s] hit: %s', this.name, key);
  1665. return value;
  1666. }
  1667. delete this._map[key];
  1668. }
  1669. debug$1("[".concat(this.name, "] missed: ").concat(key));
  1670. return null;
  1671. };
  1672. _proto.set = function set(key, value, ttl) {
  1673. debug$1('[%s] set: %s %d', this.name, key, ttl);
  1674. this._map[key] = new Expirable(value, ttl);
  1675. };
  1676. return Cache;
  1677. }();
  1678. 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; }
  1679. 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; }
  1680. /**
  1681. * 调试日志控制器
  1682. * @const
  1683. * @memberof module:leancloud-realtime
  1684. * @example
  1685. * debug.enable(); // 启用调试日志
  1686. * debug.disable(); // 关闭调试日志
  1687. */
  1688. var debug$2 = {
  1689. enable: function enable() {
  1690. var namespaces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'LC*';
  1691. return d.enable(namespaces);
  1692. },
  1693. disable: d.disable
  1694. };
  1695. var tryAll = function tryAll(promiseConstructors) {
  1696. var promise = new Promise(promiseConstructors[0]);
  1697. if (promiseConstructors.length === 1) {
  1698. return promise;
  1699. }
  1700. return promise["catch"](function () {
  1701. return tryAll(promiseConstructors.slice(1));
  1702. });
  1703. }; // eslint-disable-next-line no-sequences
  1704. var tap = function tap(interceptor) {
  1705. return function (value) {
  1706. return interceptor(value), value;
  1707. };
  1708. };
  1709. var isIE10 = global$1.navigator && global$1.navigator.userAgent && global$1.navigator.userAgent.indexOf('MSIE 10.') !== -1;
  1710. var map = new WeakMap(); // protected property helper
  1711. var internal = function internal(object) {
  1712. if (!map.has(object)) {
  1713. map.set(object, {});
  1714. }
  1715. return map.get(object);
  1716. };
  1717. var compact = function compact(obj, filter) {
  1718. if (!isPlainObject(obj)) return obj;
  1719. var object = _objectSpread({}, obj);
  1720. Object.keys(object).forEach(function (prop) {
  1721. var value = object[prop];
  1722. if (value === filter) {
  1723. delete object[prop];
  1724. } else {
  1725. object[prop] = compact(value, filter);
  1726. }
  1727. });
  1728. return object;
  1729. }; // debug utility
  1730. var removeNull = function removeNull(obj) {
  1731. return compact(obj, null);
  1732. };
  1733. var trim = function trim(message) {
  1734. return removeNull(JSON.parse(JSON.stringify(message)));
  1735. };
  1736. var ensureArray = function ensureArray(target) {
  1737. if (Array.isArray(target)) {
  1738. return target;
  1739. }
  1740. if (target === undefined || target === null) {
  1741. return [];
  1742. }
  1743. return [target];
  1744. };
  1745. var isWeapp = // eslint-disable-next-line no-undef
  1746. (typeof wx === "undefined" ? "undefined" : _typeof(wx)) === 'object' && typeof wx.connectSocket === 'function'; // throttle decorator
  1747. var isCNApp = function isCNApp(appId) {
  1748. return appId.slice(-9) !== '-MdYXbMMI';
  1749. };
  1750. var equalBuffer = function equalBuffer(buffer1, buffer2) {
  1751. if (!buffer1 || !buffer2) return false;
  1752. if (buffer1.byteLength !== buffer2.byteLength) return false;
  1753. var a = new Uint8Array(buffer1);
  1754. var b = new Uint8Array(buffer2);
  1755. return !a.some(function (value, index) {
  1756. return value !== b[index];
  1757. });
  1758. };
  1759. var _class;
  1760. 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; }
  1761. 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; }
  1762. var debug$3 = d('LC:WebSocketPlus');
  1763. var OPEN = 'open';
  1764. var DISCONNECT = 'disconnect';
  1765. var RECONNECT = 'reconnect';
  1766. var RETRY = 'retry';
  1767. var SCHEDULE = 'schedule';
  1768. var OFFLINE = 'offline';
  1769. var ONLINE = 'online';
  1770. var ERROR = 'error';
  1771. var MESSAGE = 'message';
  1772. var HEARTBEAT_TIME = 180000;
  1773. var TIMEOUT_TIME = 380000;
  1774. var DEFAULT_RETRY_STRATEGY = function DEFAULT_RETRY_STRATEGY(attempt) {
  1775. return Math.min(1000 * Math.pow(2, attempt), 300000);
  1776. };
  1777. var requireConnected = function requireConnected(target, name, descriptor) {
  1778. return _objectSpread$1(_objectSpread$1({}, descriptor), {}, {
  1779. value: function requireConnectedWrapper() {
  1780. var _descriptor$value;
  1781. this.checkConnectionAvailability(name);
  1782. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  1783. args[_key] = arguments[_key];
  1784. }
  1785. return (_descriptor$value = descriptor.value).call.apply(_descriptor$value, [this].concat(args));
  1786. }
  1787. });
  1788. };
  1789. var WebSocketPlus = (_class = /*#__PURE__*/function (_EventEmitter) {
  1790. _inheritsLoose(WebSocketPlus, _EventEmitter);
  1791. _createClass(WebSocketPlus, [{
  1792. key: "urls",
  1793. get: function get() {
  1794. return this._urls;
  1795. },
  1796. set: function set(urls) {
  1797. this._urls = ensureArray(urls);
  1798. }
  1799. }]);
  1800. function WebSocketPlus(getUrls, protocol) {
  1801. var _this;
  1802. _this = _EventEmitter.call(this) || this;
  1803. _this.init();
  1804. _this._protocol = protocol;
  1805. Promise.resolve(typeof getUrls === 'function' ? getUrls() : getUrls).then(ensureArray).then(function (urls) {
  1806. _this._urls = urls;
  1807. return _this._open();
  1808. }).then(function () {
  1809. _this.__postponeTimeoutTimer = _this._postponeTimeoutTimer.bind(_assertThisInitialized(_this));
  1810. if (global$1.addEventListener) {
  1811. _this.__pause = function () {
  1812. if (_this.can('pause')) _this.pause();
  1813. };
  1814. _this.__resume = function () {
  1815. if (_this.can('resume')) _this.resume();
  1816. };
  1817. global$1.addEventListener('offline', _this.__pause);
  1818. global$1.addEventListener('online', _this.__resume);
  1819. }
  1820. _this.open();
  1821. })["catch"](_this["throw"].bind(_assertThisInitialized(_this)));
  1822. return _this;
  1823. }
  1824. var _proto = WebSocketPlus.prototype;
  1825. _proto._open = function _open() {
  1826. var _this2 = this;
  1827. return this._createWs(this._urls, this._protocol).then(function (ws) {
  1828. var _this2$_urls = _toArray(_this2._urls),
  1829. first = _this2$_urls[0],
  1830. reset = _this2$_urls.slice(1);
  1831. _this2._urls = [].concat(_toConsumableArray(reset), [first]);
  1832. return ws;
  1833. });
  1834. };
  1835. _proto._createWs = function _createWs(urls, protocol) {
  1836. var _this3 = this;
  1837. return tryAll(urls.map(function (url) {
  1838. return function (resolve, reject) {
  1839. debug$3("connect [".concat(url, "] ").concat(protocol));
  1840. var WebSocket = getAdapter('WebSocket');
  1841. var ws = protocol ? new WebSocket(url, protocol) : new WebSocket(url);
  1842. ws.binaryType = _this3.binaryType || 'arraybuffer';
  1843. ws.onopen = function () {
  1844. return resolve(ws);
  1845. };
  1846. ws.onclose = function (error) {
  1847. if (error instanceof Error) {
  1848. return reject(error);
  1849. } // in browser, error event is useless
  1850. return reject(new Error("Failed to connect [".concat(url, "]")));
  1851. };
  1852. ws.onerror = ws.onclose;
  1853. };
  1854. })).then(function (ws) {
  1855. _this3._ws = ws;
  1856. _this3._ws.onclose = _this3._handleClose.bind(_this3);
  1857. _this3._ws.onmessage = _this3._handleMessage.bind(_this3);
  1858. return ws;
  1859. });
  1860. };
  1861. _proto._destroyWs = function _destroyWs() {
  1862. var ws = this._ws;
  1863. if (!ws) return;
  1864. ws.onopen = null;
  1865. ws.onclose = null;
  1866. ws.onerror = null;
  1867. ws.onmessage = null;
  1868. this._ws = null;
  1869. ws.close();
  1870. } // eslint-disable-next-line class-methods-use-this
  1871. ;
  1872. _proto.onbeforeevent = function onbeforeevent(event, from, to) {
  1873. for (var _len2 = arguments.length, payload = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
  1874. payload[_key2 - 3] = arguments[_key2];
  1875. }
  1876. debug$3("".concat(event, ": ").concat(from, " -> ").concat(to, " %o"), payload);
  1877. };
  1878. _proto.onopen = function onopen() {
  1879. this.emit(OPEN);
  1880. };
  1881. _proto.onconnected = function onconnected() {
  1882. this._startConnectionKeeper();
  1883. };
  1884. _proto.onleaveconnected = function onleaveconnected(event, from, to) {
  1885. this._stopConnectionKeeper();
  1886. this._destroyWs();
  1887. if (to === 'offline' || to === 'disconnected') {
  1888. this.emit(DISCONNECT);
  1889. }
  1890. };
  1891. _proto.onpause = function onpause() {
  1892. this.emit(OFFLINE);
  1893. };
  1894. _proto.onbeforeresume = function onbeforeresume() {
  1895. this.emit(ONLINE);
  1896. };
  1897. _proto.onreconnect = function onreconnect() {
  1898. this.emit(RECONNECT);
  1899. };
  1900. _proto.ondisconnected = function ondisconnected(event, from, to) {
  1901. var _this4 = this;
  1902. var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  1903. var delay = from === OFFLINE ? 0 : DEFAULT_RETRY_STRATEGY.call(null, attempt);
  1904. debug$3("schedule attempt=".concat(attempt, " delay=").concat(delay));
  1905. this.emit(SCHEDULE, attempt, delay);
  1906. if (this.__scheduledRetry) {
  1907. clearTimeout(this.__scheduledRetry);
  1908. }
  1909. this.__scheduledRetry = setTimeout(function () {
  1910. if (_this4.is('disconnected')) {
  1911. _this4.retry(attempt);
  1912. }
  1913. }, delay);
  1914. };
  1915. _proto.onretry = function onretry(event, from, to) {
  1916. var _this5 = this;
  1917. var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  1918. this.emit(RETRY, attempt);
  1919. this._open().then(function () {
  1920. return _this5.can('reconnect') && _this5.reconnect();
  1921. }, function () {
  1922. return _this5.can('fail') && _this5.fail(attempt + 1);
  1923. });
  1924. };
  1925. _proto.onerror = function onerror(event, from, to, error) {
  1926. this.emit(ERROR, error);
  1927. };
  1928. _proto.onclose = function onclose() {
  1929. if (global$1.removeEventListener) {
  1930. if (this.__pause) global$1.removeEventListener('offline', this.__pause);
  1931. if (this.__resume) global$1.removeEventListener('online', this.__resume);
  1932. }
  1933. };
  1934. _proto.checkConnectionAvailability = function checkConnectionAvailability() {
  1935. var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'API';
  1936. if (!this.is('connected')) {
  1937. var currentState = this.current;
  1938. console.warn("".concat(name, " should not be called when the connection is ").concat(currentState));
  1939. if (this.is('disconnected') || this.is('reconnecting')) {
  1940. console.warn('disconnect and reconnect event should be handled to avoid such calls.');
  1941. }
  1942. throw new Error('Connection unavailable');
  1943. }
  1944. } // jsdoc-ignore-start
  1945. ;
  1946. _proto. // jsdoc-ignore-end
  1947. _ping = function _ping() {
  1948. debug$3('ping');
  1949. try {
  1950. this.ping();
  1951. } catch (error) {
  1952. console.warn("websocket ping error: ".concat(error.message));
  1953. }
  1954. };
  1955. _proto.ping = function ping() {
  1956. if (this._ws.ping) {
  1957. this._ws.ping();
  1958. } else {
  1959. console.warn("The WebSocket implement does not support sending ping frame.\n Override ping method to use application defined ping/pong mechanism.");
  1960. }
  1961. };
  1962. _proto._postponeTimeoutTimer = function _postponeTimeoutTimer() {
  1963. var _this6 = this;
  1964. debug$3('_postponeTimeoutTimer');
  1965. this._clearTimeoutTimers();
  1966. this._timeoutTimer = setTimeout(function () {
  1967. debug$3('timeout');
  1968. _this6.disconnect();
  1969. }, TIMEOUT_TIME);
  1970. };
  1971. _proto._clearTimeoutTimers = function _clearTimeoutTimers() {
  1972. if (this._timeoutTimer) {
  1973. clearTimeout(this._timeoutTimer);
  1974. }
  1975. };
  1976. _proto._startConnectionKeeper = function _startConnectionKeeper() {
  1977. debug$3('start connection keeper');
  1978. this._heartbeatTimer = setInterval(this._ping.bind(this), HEARTBEAT_TIME);
  1979. var addListener = this._ws.addListener || this._ws.addEventListener;
  1980. if (!addListener) {
  1981. debug$3('connection keeper disabled due to the lack of #addEventListener.');
  1982. return;
  1983. }
  1984. addListener.call(this._ws, 'message', this.__postponeTimeoutTimer);
  1985. addListener.call(this._ws, 'pong', this.__postponeTimeoutTimer);
  1986. this._postponeTimeoutTimer();
  1987. };
  1988. _proto._stopConnectionKeeper = function _stopConnectionKeeper() {
  1989. debug$3('stop connection keeper'); // websockets/ws#489
  1990. var removeListener = this._ws.removeListener || this._ws.removeEventListener;
  1991. if (removeListener) {
  1992. removeListener.call(this._ws, 'message', this.__postponeTimeoutTimer);
  1993. removeListener.call(this._ws, 'pong', this.__postponeTimeoutTimer);
  1994. this._clearTimeoutTimers();
  1995. }
  1996. if (this._heartbeatTimer) {
  1997. clearInterval(this._heartbeatTimer);
  1998. }
  1999. };
  2000. _proto._handleClose = function _handleClose(event) {
  2001. debug$3("ws closed [".concat(event.code, "] ").concat(event.reason)); // socket closed manually, ignore close event.
  2002. if (this.isFinished()) return;
  2003. this.handleClose(event);
  2004. };
  2005. _proto.handleClose = function handleClose() {
  2006. // reconnect
  2007. this.disconnect();
  2008. } // jsdoc-ignore-start
  2009. ;
  2010. _proto. // jsdoc-ignore-end
  2011. send = function send(data) {
  2012. debug$3('send', data);
  2013. this._ws.send(data);
  2014. };
  2015. _proto._handleMessage = function _handleMessage(event) {
  2016. debug$3('message', event.data);
  2017. this.handleMessage(event.data);
  2018. };
  2019. _proto.handleMessage = function handleMessage(message) {
  2020. this.emit(MESSAGE, message);
  2021. };
  2022. return WebSocketPlus;
  2023. }(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);
  2024. StateMachine.create({
  2025. target: WebSocketPlus.prototype,
  2026. initial: {
  2027. state: 'initialized',
  2028. event: 'init',
  2029. defer: true
  2030. },
  2031. terminal: 'closed',
  2032. events: [{
  2033. name: 'open',
  2034. from: 'initialized',
  2035. to: 'connected'
  2036. }, {
  2037. name: 'disconnect',
  2038. from: 'connected',
  2039. to: 'disconnected'
  2040. }, {
  2041. name: 'retry',
  2042. from: 'disconnected',
  2043. to: 'reconnecting'
  2044. }, {
  2045. name: 'fail',
  2046. from: 'reconnecting',
  2047. to: 'disconnected'
  2048. }, {
  2049. name: 'reconnect',
  2050. from: 'reconnecting',
  2051. to: 'connected'
  2052. }, {
  2053. name: 'pause',
  2054. from: ['connected', 'disconnected', 'reconnecting'],
  2055. to: 'offline'
  2056. }, {}, {
  2057. name: 'resume',
  2058. from: 'offline',
  2059. to: 'disconnected'
  2060. }, {
  2061. name: 'close',
  2062. from: ['connected', 'disconnected', 'reconnecting', 'offline'],
  2063. to: 'closed'
  2064. }, {
  2065. name: 'throw',
  2066. from: '*',
  2067. to: 'error'
  2068. }]
  2069. });
  2070. var error = Object.freeze({
  2071. 1000: {
  2072. name: 'CLOSE_NORMAL'
  2073. },
  2074. 1006: {
  2075. name: 'CLOSE_ABNORMAL'
  2076. },
  2077. 4100: {
  2078. name: 'APP_NOT_AVAILABLE',
  2079. message: 'App not exists or realtime message service is disabled.'
  2080. },
  2081. 4102: {
  2082. name: 'SIGNATURE_FAILED',
  2083. message: 'Login signature mismatch.'
  2084. },
  2085. 4103: {
  2086. name: 'INVALID_LOGIN',
  2087. message: 'Malformed clientId.'
  2088. },
  2089. 4105: {
  2090. name: 'SESSION_REQUIRED',
  2091. message: 'Message sent before session opened.'
  2092. },
  2093. 4107: {
  2094. name: 'READ_TIMEOUT'
  2095. },
  2096. 4108: {
  2097. name: 'LOGIN_TIMEOUT'
  2098. },
  2099. 4109: {
  2100. name: 'FRAME_TOO_LONG'
  2101. },
  2102. 4110: {
  2103. name: 'INVALID_ORIGIN',
  2104. message: 'Access denied by domain whitelist.'
  2105. },
  2106. 4111: {
  2107. name: 'SESSION_CONFLICT'
  2108. },
  2109. 4112: {
  2110. name: 'SESSION_TOKEN_EXPIRED'
  2111. },
  2112. 4113: {
  2113. name: 'APP_QUOTA_EXCEEDED',
  2114. message: 'The daily active users limit exceeded.'
  2115. },
  2116. 4116: {
  2117. name: 'MESSAGE_SENT_QUOTA_EXCEEDED',
  2118. message: 'Command sent too fast.'
  2119. },
  2120. 4200: {
  2121. name: 'INTERNAL_ERROR',
  2122. message: 'Internal error, please contact LeanCloud for support.'
  2123. },
  2124. 4301: {
  2125. name: 'CONVERSATION_API_FAILED',
  2126. message: 'Upstream Conversatoin API failed, see error.detail for details.'
  2127. },
  2128. 4302: {
  2129. name: 'CONVERSATION_SIGNATURE_FAILED',
  2130. message: 'Conversation action signature mismatch.'
  2131. },
  2132. 4303: {
  2133. name: 'CONVERSATION_NOT_FOUND'
  2134. },
  2135. 4304: {
  2136. name: 'CONVERSATION_FULL'
  2137. },
  2138. 4305: {
  2139. name: 'CONVERSATION_REJECTED_BY_APP',
  2140. message: 'Conversation action rejected by hook.'
  2141. },
  2142. 4306: {
  2143. name: 'CONVERSATION_UPDATE_FAILED'
  2144. },
  2145. 4307: {
  2146. name: 'CONVERSATION_READ_ONLY'
  2147. },
  2148. 4308: {
  2149. name: 'CONVERSATION_NOT_ALLOWED'
  2150. },
  2151. 4309: {
  2152. name: 'CONVERSATION_UPDATE_REJECTED',
  2153. message: 'Conversation update rejected because the client is not a member.'
  2154. },
  2155. 4310: {
  2156. name: 'CONVERSATION_QUERY_FAILED',
  2157. message: 'Conversation query failed because it is too expansive.'
  2158. },
  2159. 4311: {
  2160. name: 'CONVERSATION_LOG_FAILED'
  2161. },
  2162. 4312: {
  2163. name: 'CONVERSATION_LOG_REJECTED',
  2164. message: 'Message query rejected because the client is not a member of the conversation.'
  2165. },
  2166. 4313: {
  2167. name: 'SYSTEM_CONVERSATION_REQUIRED'
  2168. },
  2169. 4314: {
  2170. name: 'NORMAL_CONVERSATION_REQUIRED'
  2171. },
  2172. 4315: {
  2173. name: 'CONVERSATION_BLACKLISTED',
  2174. message: 'Blacklisted in the conversation.'
  2175. },
  2176. 4316: {
  2177. name: 'TRANSIENT_CONVERSATION_REQUIRED'
  2178. },
  2179. 4317: {
  2180. name: 'CONVERSATION_MEMBERSHIP_REQUIRED'
  2181. },
  2182. 4318: {
  2183. name: 'CONVERSATION_API_QUOTA_EXCEEDED',
  2184. message: 'LeanCloud API quota exceeded. You may upgrade your plan.'
  2185. },
  2186. 4323: {
  2187. name: 'TEMPORARY_CONVERSATION_EXPIRED',
  2188. message: 'Temporary conversation expired or does not exist.'
  2189. },
  2190. 4401: {
  2191. name: 'INVALID_MESSAGING_TARGET',
  2192. message: 'Conversation does not exist or client is not a member.'
  2193. },
  2194. 4402: {
  2195. name: 'MESSAGE_REJECTED_BY_APP',
  2196. message: 'Message rejected by hook.'
  2197. },
  2198. 4403: {
  2199. name: 'MESSAGE_OWNERSHIP_REQUIRED'
  2200. },
  2201. 4404: {
  2202. name: 'MESSAGE_NOT_FOUND'
  2203. },
  2204. 4405: {
  2205. name: 'MESSAGE_UPDATE_REJECTED_BY_APP',
  2206. message: 'Message update rejected by hook.'
  2207. },
  2208. 4406: {
  2209. name: 'MESSAGE_EDIT_DISABLED'
  2210. },
  2211. 4407: {
  2212. name: 'MESSAGE_RECALL_DISABLED'
  2213. },
  2214. 5130: {
  2215. name: 'OWNER_PROMOTION_NOT_ALLOWED',
  2216. message: "Updating a member's role to owner is not allowed."
  2217. }
  2218. });
  2219. var ErrorCode = Object.freeze(Object.keys(error).reduce(function (result, code) {
  2220. return Object.assign(result, _defineProperty({}, error[code].name, Number(code)));
  2221. }, {}));
  2222. var createError = function createError(_ref) {
  2223. var code = _ref.code,
  2224. reason = _ref.reason,
  2225. appCode = _ref.appCode,
  2226. detail = _ref.detail,
  2227. errorMessage = _ref.error;
  2228. var message = reason || detail || errorMessage;
  2229. var name = reason;
  2230. if (!message && error[code]) {
  2231. name = error[code].name;
  2232. message = error[code].message || name;
  2233. }
  2234. if (!message) {
  2235. message = "Unknow Error: ".concat(code);
  2236. }
  2237. var err = new Error(message);
  2238. return Object.assign(err, {
  2239. code: code,
  2240. appCode: appCode,
  2241. detail: detail,
  2242. name: name
  2243. });
  2244. };
  2245. var debug$4 = d('LC:Connection');
  2246. var COMMAND_TIMEOUT = 20000;
  2247. var EXPIRE = Symbol('expire');
  2248. var isIdempotentCommand = function isIdempotentCommand(command) {
  2249. 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));
  2250. };
  2251. var Connection = /*#__PURE__*/function (_WebSocketPlus) {
  2252. _inheritsLoose(Connection, _WebSocketPlus);
  2253. function Connection(getUrl, _ref) {
  2254. var _this;
  2255. var format = _ref.format,
  2256. version = _ref.version;
  2257. debug$4('initializing Connection');
  2258. var protocolString = "lc.".concat(format, ".").concat(version);
  2259. _this = _WebSocketPlus.call(this, getUrl, protocolString) || this;
  2260. _this._protocolFormat = format;
  2261. _this._commands = {};
  2262. _this._serialId = 0;
  2263. return _this;
  2264. }
  2265. var _proto = Connection.prototype;
  2266. _proto.send = /*#__PURE__*/function () {
  2267. var _send = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(command) {
  2268. var _this2 = this;
  2269. var waitingForRespond,
  2270. buffer,
  2271. serialId,
  2272. duplicatedCommand,
  2273. message,
  2274. promise,
  2275. _args = arguments;
  2276. return _regeneratorRuntime.wrap(function _callee$(_context) {
  2277. while (1) {
  2278. switch (_context.prev = _context.next) {
  2279. case 0:
  2280. waitingForRespond = _args.length > 1 && _args[1] !== undefined ? _args[1] : true;
  2281. if (!waitingForRespond) {
  2282. _context.next = 11;
  2283. break;
  2284. }
  2285. if (!isIdempotentCommand(command)) {
  2286. _context.next = 8;
  2287. break;
  2288. }
  2289. buffer = command.toArrayBuffer();
  2290. duplicatedCommand = values(this._commands).find(function (_ref2) {
  2291. var targetBuffer = _ref2.buffer,
  2292. targetCommand = _ref2.command;
  2293. return targetCommand.cmd === command.cmd && targetCommand.op === command.op && equalBuffer(targetBuffer, buffer);
  2294. });
  2295. if (!duplicatedCommand) {
  2296. _context.next = 8;
  2297. break;
  2298. }
  2299. console.warn("Duplicated command [cmd:".concat(command.cmd, " op:").concat(command.op, "] is throttled."));
  2300. return _context.abrupt("return", duplicatedCommand.promise);
  2301. case 8:
  2302. this._serialId += 1;
  2303. serialId = this._serialId;
  2304. command.i = serialId; // eslint-disable-line no-param-reassign
  2305. case 11:
  2306. if (debug$4.enabled) debug$4('↑ %O sent', trim(command));
  2307. if (this._protocolFormat === 'proto2base64') {
  2308. message = command.toBase64();
  2309. } else if (command.toArrayBuffer) {
  2310. message = command.toArrayBuffer();
  2311. }
  2312. if (message) {
  2313. _context.next = 15;
  2314. break;
  2315. }
  2316. throw new TypeError("".concat(command, " is not a GenericCommand"));
  2317. case 15:
  2318. _WebSocketPlus.prototype.send.call(this, message);
  2319. if (waitingForRespond) {
  2320. _context.next = 18;
  2321. break;
  2322. }
  2323. return _context.abrupt("return", undefined);
  2324. case 18:
  2325. promise = new Promise(function (resolve, reject) {
  2326. _this2._commands[serialId] = {
  2327. command: command,
  2328. buffer: buffer,
  2329. resolve: resolve,
  2330. reject: reject,
  2331. timeout: setTimeout(function () {
  2332. if (_this2._commands[serialId]) {
  2333. if (debug$4.enabled) debug$4('✗ %O timeout', trim(command));
  2334. reject(createError({
  2335. error: "Command Timeout [cmd:".concat(command.cmd, " op:").concat(command.op, "]"),
  2336. name: 'COMMAND_TIMEOUT'
  2337. }));
  2338. delete _this2._commands[serialId];
  2339. }
  2340. }, COMMAND_TIMEOUT)
  2341. };
  2342. });
  2343. this._commands[serialId].promise = promise;
  2344. return _context.abrupt("return", promise);
  2345. case 21:
  2346. case "end":
  2347. return _context.stop();
  2348. }
  2349. }
  2350. }, _callee, this);
  2351. }));
  2352. function send(_x) {
  2353. return _send.apply(this, arguments);
  2354. }
  2355. return send;
  2356. }();
  2357. _proto.handleMessage = function handleMessage(msg) {
  2358. var message;
  2359. try {
  2360. message = GenericCommand.decode(msg);
  2361. if (debug$4.enabled) debug$4('↓ %O received', trim(message));
  2362. } catch (e) {
  2363. console.warn('Decode message failed:', e.message, msg);
  2364. return;
  2365. }
  2366. var serialId = message.i;
  2367. if (serialId) {
  2368. if (this._commands[serialId]) {
  2369. clearTimeout(this._commands[serialId].timeout);
  2370. if (message.cmd === CommandType.error) {
  2371. this._commands[serialId].reject(createError(message.errorMessage));
  2372. } else {
  2373. this._commands[serialId].resolve(message);
  2374. }
  2375. delete this._commands[serialId];
  2376. } else {
  2377. console.warn("Unexpected command received with serialId [".concat(serialId, "],\n which have timed out or never been requested."));
  2378. }
  2379. } else {
  2380. switch (message.cmd) {
  2381. case CommandType.error:
  2382. {
  2383. this.emit(ERROR, createError(message.errorMessage));
  2384. return;
  2385. }
  2386. case CommandType.goaway:
  2387. {
  2388. this.emit(EXPIRE);
  2389. return;
  2390. }
  2391. default:
  2392. {
  2393. this.emit(MESSAGE, message);
  2394. }
  2395. }
  2396. }
  2397. };
  2398. _proto.ping = function ping() {
  2399. return this.send(new GenericCommand({
  2400. cmd: CommandType.echo
  2401. }))["catch"](function (error) {
  2402. return debug$4('ping failed:', error);
  2403. });
  2404. };
  2405. return Connection;
  2406. }(WebSocketPlus);
  2407. var debug$5 = d('LC:request');
  2408. var request = (function (_ref) {
  2409. var _ref$method = _ref.method,
  2410. method = _ref$method === void 0 ? 'GET' : _ref$method,
  2411. _url = _ref.url,
  2412. query = _ref.query,
  2413. headers = _ref.headers,
  2414. data = _ref.data,
  2415. time = _ref.timeout;
  2416. var url = _url;
  2417. if (query) {
  2418. var queryString = Object.keys(query).map(function (key) {
  2419. var value = query[key];
  2420. if (value === undefined) return undefined;
  2421. var v = isPlainObject(value) ? JSON.stringify(value) : value;
  2422. return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(v));
  2423. }).filter(function (qs) {
  2424. return qs;
  2425. }).join('&');
  2426. url = "".concat(url, "?").concat(queryString);
  2427. }
  2428. debug$5('Req: %O %O %O', method, url, {
  2429. headers: headers,
  2430. data: data
  2431. });
  2432. var request = getAdapter('request');
  2433. var promise = request(url, {
  2434. method: method,
  2435. headers: headers,
  2436. data: data
  2437. }).then(function (response) {
  2438. if (response.ok === false) {
  2439. var error = createError(response.data);
  2440. error.response = response;
  2441. throw error;
  2442. }
  2443. debug$5('Res: %O %O %O', url, response.status, response.data);
  2444. return response.data;
  2445. })["catch"](function (error) {
  2446. if (error.response) {
  2447. debug$5('Error: %O %O %O', url, error.response.status, error.response.data);
  2448. }
  2449. throw error;
  2450. });
  2451. return time ? promiseTimeout.timeout(promise, time) : promise;
  2452. });
  2453. var applyDecorators = function applyDecorators(decorators, target) {
  2454. if (decorators) {
  2455. decorators.forEach(function (decorator) {
  2456. try {
  2457. decorator(target);
  2458. } catch (error) {
  2459. if (decorator._pluginName) {
  2460. error.message += "[".concat(decorator._pluginName, "]");
  2461. }
  2462. throw error;
  2463. }
  2464. });
  2465. }
  2466. };
  2467. var applyDispatcher = function applyDispatcher(dispatchers, payload) {
  2468. return ensureArray(dispatchers).reduce(function (resultPromise, dispatcher) {
  2469. return resultPromise.then(function (shouldDispatch) {
  2470. return shouldDispatch === false ? false : dispatcher.apply(void 0, _toConsumableArray(payload));
  2471. })["catch"](function (error) {
  2472. if (dispatcher._pluginName) {
  2473. // eslint-disable-next-line no-param-reassign
  2474. error.message += "[".concat(dispatcher._pluginName, "]");
  2475. }
  2476. throw error;
  2477. });
  2478. }, Promise.resolve(true));
  2479. };
  2480. var version = "5.0.0-rc.7";
  2481. 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; }
  2482. 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; }
  2483. var debug$6 = d('LC:Realtime');
  2484. var routerCache = new Cache('push-router');
  2485. var initializedApp = {};
  2486. var Realtime = /*#__PURE__*/function (_EventEmitter) {
  2487. _inheritsLoose(Realtime, _EventEmitter);
  2488. /**
  2489. * @extends EventEmitter
  2490. * @param {Object} options
  2491. * @param {String} options.appId
  2492. * @param {String} options.appKey (since 4.0.0)
  2493. * @param {String|Object} [options.server] 指定服务器域名,中国节点应用此参数必填(since 4.0.0)
  2494. * @param {Boolean} [options.noBinary=false] 设置 WebSocket 使用字符串格式收发消息(默认为二进制格式)。
  2495. * 适用于 WebSocket 实现不支持二进制数据格式的情况
  2496. * @param {Boolean} [options.ssl=true] 使用 wss 进行连接
  2497. * @param {String|String[]} [options.RTMServers] 指定私有部署的 RTM 服务器地址(since 4.0.0)
  2498. * @param {Plugin[]} [options.plugins] 加载插件(since 3.1.0)
  2499. */
  2500. function Realtime(_ref) {
  2501. var _this2;
  2502. var plugins = _ref.plugins,
  2503. options = _objectWithoutProperties(_ref, ["plugins"]);
  2504. debug$6('initializing Realtime %s %O', version, options);
  2505. _this2 = _EventEmitter.call(this) || this;
  2506. var appId = options.appId;
  2507. if (typeof appId !== 'string') {
  2508. throw new TypeError("appId [".concat(appId, "] is not a string"));
  2509. }
  2510. if (initializedApp[appId]) {
  2511. throw new Error("App [".concat(appId, "] is already initialized."));
  2512. }
  2513. initializedApp[appId] = true;
  2514. if (typeof options.appKey !== 'string') {
  2515. throw new TypeError("appKey [".concat(options.appKey, "] is not a string"));
  2516. }
  2517. if (isCNApp(appId)) {
  2518. if (!options.server) {
  2519. throw new TypeError("server option is required for apps from CN region");
  2520. }
  2521. }
  2522. _this2._options = _objectSpread$2({
  2523. appId: undefined,
  2524. appKey: undefined,
  2525. noBinary: false,
  2526. ssl: true,
  2527. RTMServerName: typeof process !== 'undefined' ? process.env.RTM_SERVER_NAME : undefined
  2528. }, options);
  2529. _this2._cache = new Cache('endpoints');
  2530. var _this = internal(_assertThisInitialized(_this2));
  2531. _this.clients = new Set();
  2532. _this.pendingClients = new Set();
  2533. var mergedPlugins = [].concat(_toConsumableArray(ensureArray(Realtime.__preRegisteredPlugins)), _toConsumableArray(ensureArray(plugins)));
  2534. debug$6('Using plugins %o', mergedPlugins.map(function (plugin) {
  2535. return plugin.name;
  2536. }));
  2537. _this2._plugins = mergedPlugins.reduce(function (result, plugin) {
  2538. Object.keys(plugin).forEach(function (hook) {
  2539. if ({}.hasOwnProperty.call(plugin, hook) && hook !== 'name') {
  2540. if (plugin.name) {
  2541. ensureArray(plugin[hook]).forEach(function (value) {
  2542. // eslint-disable-next-line no-param-reassign
  2543. value._pluginName = plugin.name;
  2544. });
  2545. } // eslint-disable-next-line no-param-reassign
  2546. result[hook] = ensureArray(result[hook]).concat(plugin[hook]);
  2547. }
  2548. });
  2549. return result;
  2550. }, {}); // onRealtimeCreate hook
  2551. applyDecorators(_this2._plugins.onRealtimeCreate, _assertThisInitialized(_this2));
  2552. return _this2;
  2553. }
  2554. var _proto = Realtime.prototype;
  2555. _proto._request = /*#__PURE__*/function () {
  2556. var _request2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2) {
  2557. var method, _url, _ref2$version, version, path, query, headers, data, url, _this$_options, appId, server, _yield$this$construct, api;
  2558. return _regeneratorRuntime.wrap(function _callee$(_context) {
  2559. while (1) {
  2560. switch (_context.prev = _context.next) {
  2561. case 0:
  2562. 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;
  2563. url = _url;
  2564. if (url) {
  2565. _context.next = 9;
  2566. break;
  2567. }
  2568. _this$_options = this._options, appId = _this$_options.appId, server = _this$_options.server;
  2569. _context.next = 6;
  2570. return this.constructor._getServerUrls({
  2571. appId: appId,
  2572. server: server
  2573. });
  2574. case 6:
  2575. _yield$this$construct = _context.sent;
  2576. api = _yield$this$construct.api;
  2577. url = "".concat(api, "/").concat(version).concat(path);
  2578. case 9:
  2579. return _context.abrupt("return", request({
  2580. url: url,
  2581. method: method,
  2582. query: query,
  2583. headers: _objectSpread$2({
  2584. 'X-LC-Id': this._options.appId,
  2585. 'X-LC-Key': this._options.appKey
  2586. }, headers),
  2587. data: data
  2588. }));
  2589. case 10:
  2590. case "end":
  2591. return _context.stop();
  2592. }
  2593. }
  2594. }, _callee, this);
  2595. }));
  2596. function _request(_x) {
  2597. return _request2.apply(this, arguments);
  2598. }
  2599. return _request;
  2600. }();
  2601. _proto._open = function _open() {
  2602. var _this3 = this;
  2603. if (this._openPromise) return this._openPromise;
  2604. var format = 'protobuf2';
  2605. if (this._options.noBinary) {
  2606. // 不发送 binary data,fallback to base64 string
  2607. format = 'proto2base64';
  2608. }
  2609. var version = 3;
  2610. var protocol = {
  2611. format: format,
  2612. version: version
  2613. };
  2614. this._openPromise = new Promise(function (resolve, reject) {
  2615. debug$6('No connection established, create a new one.');
  2616. var connection = new Connection(function () {
  2617. return _this3._getRTMServers(_this3._options);
  2618. }, protocol);
  2619. connection.on(OPEN, function () {
  2620. return resolve(connection);
  2621. }).on(ERROR, function (error) {
  2622. delete _this3._openPromise;
  2623. reject(error);
  2624. }).on(EXPIRE, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
  2625. return _regeneratorRuntime.wrap(function _callee2$(_context2) {
  2626. while (1) {
  2627. switch (_context2.prev = _context2.next) {
  2628. case 0:
  2629. debug$6('Connection expired. Refresh endpoints.');
  2630. _this3._cache.set('endpoints', null, 0);
  2631. _context2.next = 4;
  2632. return _this3._getRTMServers(_this3._options);
  2633. case 4:
  2634. connection.urls = _context2.sent;
  2635. connection.disconnect();
  2636. case 6:
  2637. case "end":
  2638. return _context2.stop();
  2639. }
  2640. }
  2641. }, _callee2);
  2642. }))).on(MESSAGE, _this3._dispatchCommand.bind(_this3));
  2643. /**
  2644. * 连接断开。
  2645. * 连接断开可能是因为 SDK 进入了离线状态(see {@link Realtime#event:OFFLINE}),或长时间没有收到服务器心跳。
  2646. * 连接断开后所有的网络操作都会失败,请在连接断开后禁用相关的 UI 元素。
  2647. * @event Realtime#DISCONNECT
  2648. */
  2649. /**
  2650. * 计划在一段时间后尝试重新连接
  2651. * @event Realtime#SCHEDULE
  2652. * @param {Number} attempt 尝试重连的次数
  2653. * @param {Number} delay 延迟的毫秒数
  2654. */
  2655. /**
  2656. * 正在尝试重新连接
  2657. * @event Realtime#RETRY
  2658. * @param {Number} attempt 尝试重连的次数
  2659. */
  2660. /**
  2661. * 连接恢复正常。
  2662. * 请重新启用在 {@link Realtime#event:DISCONNECT} 事件中禁用的相关 UI 元素
  2663. * @event Realtime#RECONNECT
  2664. */
  2665. /**
  2666. * 客户端连接断开
  2667. * @event IMClient#DISCONNECT
  2668. * @see Realtime#event:DISCONNECT
  2669. * @since 3.2.0
  2670. */
  2671. /**
  2672. * 计划在一段时间后尝试重新连接
  2673. * @event IMClient#SCHEDULE
  2674. * @param {Number} attempt 尝试重连的次数
  2675. * @param {Number} delay 延迟的毫秒数
  2676. * @since 3.2.0
  2677. */
  2678. /**
  2679. * 正在尝试重新连接
  2680. * @event IMClient#RETRY
  2681. * @param {Number} attempt 尝试重连的次数
  2682. * @since 3.2.0
  2683. */
  2684. /**
  2685. * 客户端进入离线状态。
  2686. * 这通常意味着网络已断开,或者 {@link Realtime#pause} 被调用
  2687. * @event Realtime#OFFLINE
  2688. * @since 3.4.0
  2689. */
  2690. /**
  2691. * 客户端恢复在线状态
  2692. * 这通常意味着网络已恢复,或者 {@link Realtime#resume} 被调用
  2693. * @event Realtime#ONLINE
  2694. * @since 3.4.0
  2695. */
  2696. /**
  2697. * 进入离线状态。
  2698. * 这通常意味着网络已断开,或者 {@link Realtime#pause} 被调用
  2699. * @event IMClient#OFFLINE
  2700. * @since 3.4.0
  2701. */
  2702. /**
  2703. * 恢复在线状态
  2704. * 这通常意味着网络已恢复,或者 {@link Realtime#resume} 被调用
  2705. * @event IMClient#ONLINE
  2706. * @since 3.4.0
  2707. */
  2708. // event proxy
  2709. [DISCONNECT, RECONNECT, RETRY, SCHEDULE, OFFLINE, ONLINE].forEach(function (event) {
  2710. return connection.on(event, function () {
  2711. for (var _len = arguments.length, payload = new Array(_len), _key = 0; _key < _len; _key++) {
  2712. payload[_key] = arguments[_key];
  2713. }
  2714. debug$6("".concat(event, " event emitted. %o"), payload);
  2715. _this3.emit.apply(_this3, [event].concat(payload));
  2716. if (event !== RECONNECT) {
  2717. internal(_this3).clients.forEach(function (client) {
  2718. client.emit.apply(client, [event].concat(payload));
  2719. });
  2720. }
  2721. });
  2722. }); // override handleClose
  2723. connection.handleClose = function handleClose(event) {
  2724. var isFatal = [ErrorCode.APP_NOT_AVAILABLE, ErrorCode.INVALID_LOGIN, ErrorCode.INVALID_ORIGIN].some(function (errorCode) {
  2725. return errorCode === event.code;
  2726. });
  2727. if (isFatal) {
  2728. // in these cases, SDK should throw.
  2729. this["throw"](createError(event));
  2730. } else {
  2731. // reconnect
  2732. this.disconnect();
  2733. }
  2734. };
  2735. internal(_this3).connection = connection;
  2736. });
  2737. return this._openPromise;
  2738. };
  2739. _proto._getRTMServers = /*#__PURE__*/function () {
  2740. var _getRTMServers2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(options) {
  2741. var info, cachedEndPoints, _info, server, secondary, ttl;
  2742. return _regeneratorRuntime.wrap(function _callee3$(_context3) {
  2743. while (1) {
  2744. switch (_context3.prev = _context3.next) {
  2745. case 0:
  2746. if (!options.RTMServers) {
  2747. _context3.next = 2;
  2748. break;
  2749. }
  2750. return _context3.abrupt("return", shuffle(ensureArray(options.RTMServers)));
  2751. case 2:
  2752. cachedEndPoints = this._cache.get('endpoints');
  2753. if (!cachedEndPoints) {
  2754. _context3.next = 7;
  2755. break;
  2756. }
  2757. info = cachedEndPoints;
  2758. _context3.next = 14;
  2759. break;
  2760. case 7:
  2761. _context3.next = 9;
  2762. return this.constructor._fetchRTMServers(options);
  2763. case 9:
  2764. info = _context3.sent;
  2765. _info = info, server = _info.server, secondary = _info.secondary, ttl = _info.ttl;
  2766. if (!(typeof server !== 'string' && typeof secondary !== 'string' && typeof ttl !== 'number')) {
  2767. _context3.next = 13;
  2768. break;
  2769. }
  2770. throw new Error("malformed RTM route response: ".concat(JSON.stringify(info)));
  2771. case 13:
  2772. this._cache.set('endpoints', info, info.ttl * 1000);
  2773. case 14:
  2774. debug$6('endpoint info: %O', info);
  2775. return _context3.abrupt("return", [info.server, info.secondary]);
  2776. case 16:
  2777. case "end":
  2778. return _context3.stop();
  2779. }
  2780. }
  2781. }, _callee3, this);
  2782. }));
  2783. function _getRTMServers(_x2) {
  2784. return _getRTMServers2.apply(this, arguments);
  2785. }
  2786. return _getRTMServers;
  2787. }();
  2788. Realtime._getServerUrls = /*#__PURE__*/function () {
  2789. var _getServerUrls2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref4) {
  2790. var appId, server, cachedRouter, defaultProtocol;
  2791. return _regeneratorRuntime.wrap(function _callee4$(_context4) {
  2792. while (1) {
  2793. switch (_context4.prev = _context4.next) {
  2794. case 0:
  2795. appId = _ref4.appId, server = _ref4.server;
  2796. debug$6('fetch server urls');
  2797. if (!server) {
  2798. _context4.next = 6;
  2799. break;
  2800. }
  2801. if (!(typeof server !== 'string')) {
  2802. _context4.next = 5;
  2803. break;
  2804. }
  2805. return _context4.abrupt("return", server);
  2806. case 5:
  2807. return _context4.abrupt("return", {
  2808. RTMRouter: server,
  2809. api: server
  2810. });
  2811. case 6:
  2812. cachedRouter = routerCache.get(appId);
  2813. if (!cachedRouter) {
  2814. _context4.next = 9;
  2815. break;
  2816. }
  2817. return _context4.abrupt("return", cachedRouter);
  2818. case 9:
  2819. defaultProtocol = 'https://';
  2820. return _context4.abrupt("return", request({
  2821. url: 'https://app-router.com/2/route',
  2822. query: {
  2823. appId: appId
  2824. },
  2825. timeout: 20000
  2826. }).then(tap(debug$6)).then(function (_ref5) {
  2827. var RTMRouterServer = _ref5.rtm_router_server,
  2828. APIServer = _ref5.api_server,
  2829. _ref5$ttl = _ref5.ttl,
  2830. ttl = _ref5$ttl === void 0 ? 3600 : _ref5$ttl;
  2831. if (!RTMRouterServer) {
  2832. throw new Error('rtm router not exists');
  2833. }
  2834. var serverUrls = {
  2835. RTMRouter: "".concat(defaultProtocol).concat(RTMRouterServer),
  2836. api: "".concat(defaultProtocol).concat(APIServer)
  2837. };
  2838. routerCache.set(appId, serverUrls, ttl * 1000);
  2839. return serverUrls;
  2840. })["catch"](function () {
  2841. var id = appId.slice(0, 8).toLowerCase();
  2842. var domain = 'lncldglobal.com';
  2843. return {
  2844. RTMRouter: "".concat(defaultProtocol).concat(id, ".rtm.").concat(domain),
  2845. api: "".concat(defaultProtocol).concat(id, ".api.").concat(domain)
  2846. };
  2847. }));
  2848. case 11:
  2849. case "end":
  2850. return _context4.stop();
  2851. }
  2852. }
  2853. }, _callee4);
  2854. }));
  2855. function _getServerUrls(_x3) {
  2856. return _getServerUrls2.apply(this, arguments);
  2857. }
  2858. return _getServerUrls;
  2859. }();
  2860. Realtime._fetchRTMServers = function _fetchRTMServers(_ref6) {
  2861. var appId = _ref6.appId,
  2862. ssl = _ref6.ssl,
  2863. server = _ref6.server,
  2864. RTMServerName = _ref6.RTMServerName;
  2865. debug$6('fetch endpoint info');
  2866. return this._getServerUrls({
  2867. appId: appId,
  2868. server: server
  2869. }).then(tap(debug$6)).then(function (_ref7) {
  2870. var RTMRouter = _ref7.RTMRouter;
  2871. return request({
  2872. url: "".concat(RTMRouter, "/v1/route"),
  2873. query: {
  2874. appId: appId,
  2875. secure: ssl,
  2876. features: isWeapp ? 'wechat' : undefined,
  2877. server: RTMServerName,
  2878. _t: Date.now()
  2879. },
  2880. timeout: 20000
  2881. }).then(tap(debug$6));
  2882. });
  2883. };
  2884. _proto._close = function _close() {
  2885. if (this._openPromise) {
  2886. this._openPromise.then(function (connection) {
  2887. return connection.close();
  2888. });
  2889. }
  2890. delete this._openPromise;
  2891. }
  2892. /**
  2893. * 手动进行重连。
  2894. * SDK 在网络出现异常时会自动按照一定的时间间隔尝试重连,调用该方法会立即尝试重连并重置重连尝试计数器。
  2895. * 只能在 `SCHEDULE` 事件之后,`RETRY` 事件之前调用,如果当前网络正常或者正在进行重连,调用该方法会抛异常。
  2896. */
  2897. ;
  2898. _proto.retry = function retry() {
  2899. var _internal = internal(this),
  2900. connection = _internal.connection;
  2901. if (!connection) {
  2902. throw new Error('no connection established');
  2903. }
  2904. if (connection.cannot('retry')) {
  2905. throw new Error("retrying not allowed when not disconnected. the connection is now ".concat(connection.current));
  2906. }
  2907. return connection.retry();
  2908. }
  2909. /**
  2910. * 暂停,使 SDK 进入离线状态。
  2911. * 你可以在网络断开、应用进入后台等时刻调用该方法让 SDK 进入离线状态,离线状态下不会尝试重连。
  2912. * 在浏览器中 SDK 会自动监听网络变化,因此无需手动调用该方法。
  2913. *
  2914. * @since 3.4.0
  2915. * @see Realtime#event:OFFLINE
  2916. */
  2917. ;
  2918. _proto.pause = function pause() {
  2919. // 这个方法常常在网络断开、进入后台时被调用,此时 connection 可能没有建立或者已经 close。
  2920. // 因此不像 retry,这个方法应该尽可能 loose
  2921. var _internal2 = internal(this),
  2922. connection = _internal2.connection;
  2923. if (!connection) return;
  2924. if (connection.can('pause')) connection.pause();
  2925. }
  2926. /**
  2927. * 恢复在线状态。
  2928. * 你可以在网络恢复、应用回到前台等时刻调用该方法让 SDK 恢复在线状态,恢复在线状态后 SDK 会开始尝试重连。
  2929. *
  2930. * @since 3.4.0
  2931. * @see Realtime#event:ONLINE
  2932. */
  2933. ;
  2934. _proto.resume = function resume() {
  2935. // 与 pause 一样,这个方法应该尽可能 loose
  2936. var _internal3 = internal(this),
  2937. connection = _internal3.connection;
  2938. if (!connection) return;
  2939. if (connection.can('resume')) connection.resume();
  2940. };
  2941. _proto._registerPending = function _registerPending(value) {
  2942. internal(this).pendingClients.add(value);
  2943. };
  2944. _proto._deregisterPending = function _deregisterPending(client) {
  2945. internal(this).pendingClients["delete"](client);
  2946. };
  2947. _proto._register = function _register(client) {
  2948. internal(this).clients.add(client);
  2949. };
  2950. _proto._deregister = function _deregister(client) {
  2951. var _this = internal(this);
  2952. _this.clients["delete"](client);
  2953. if (_this.clients.size + _this.pendingClients.size === 0) {
  2954. this._close();
  2955. }
  2956. };
  2957. _proto._dispatchCommand = function _dispatchCommand(command) {
  2958. return applyDispatcher(this._plugins.beforeCommandDispatch, [command, this]).then(function (shouldDispatch) {
  2959. // no plugin handled this command
  2960. if (shouldDispatch) return debug$6('[WARN] Unexpected message received: %O', trim(command));
  2961. return false;
  2962. });
  2963. };
  2964. return Realtime;
  2965. }(EventEmitter); // For test purpose only
  2966. var polyfilledPromise = Promise;
  2967. exports.EventEmitter = EventEmitter;
  2968. exports.Promise = polyfilledPromise;
  2969. exports.Protocals = message;
  2970. exports.Protocols = message;
  2971. exports.Realtime = Realtime;
  2972. exports.debug = debug$2;
  2973. exports.getAdapter = getAdapter;
  2974. exports.setAdapters = setAdapters;
  2975. //# sourceMappingURL=core.js.map