@oox/client 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser.js +1139 -1109
- package/browser.js.map +1 -1
- package/config.js +1 -0
- package/context.js +22 -0
- package/index.js +3 -82
- package/keepalive-connection-sample.js +8 -8
- package/keepalive-connection.js +55 -0
- package/package.json +1 -1
- package/proxy.js +30 -0
- package/types/config.d.ts +1 -0
- package/types/context.d.ts +7 -0
- package/types/index.d.ts +3 -19
- package/types/keepalive-connection-sample.d.ts +1 -1
- package/types/keepalive-connection.d.ts +6 -0
- package/types/proxy.d.ts +1 -0
package/browser.js
CHANGED
|
@@ -1,1113 +1,1143 @@
|
|
|
1
1
|
var oox = (function (exports) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
function getDefaultExportFromCjs (x) {
|
|
5
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
var events = {exports: {}};
|
|
9
|
+
|
|
10
|
+
var hasRequiredEvents;
|
|
11
|
+
|
|
12
|
+
function requireEvents () {
|
|
13
|
+
if (hasRequiredEvents) return events.exports;
|
|
14
|
+
hasRequiredEvents = 1;
|
|
15
|
+
|
|
16
|
+
var R = typeof Reflect === 'object' ? Reflect : null;
|
|
17
|
+
var ReflectApply = R && typeof R.apply === 'function'
|
|
18
|
+
? R.apply
|
|
19
|
+
: function ReflectApply(target, receiver, args) {
|
|
20
|
+
return Function.prototype.apply.call(target, receiver, args);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var ReflectOwnKeys;
|
|
24
|
+
if (R && typeof R.ownKeys === 'function') {
|
|
25
|
+
ReflectOwnKeys = R.ownKeys;
|
|
26
|
+
} else if (Object.getOwnPropertySymbols) {
|
|
27
|
+
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
28
|
+
return Object.getOwnPropertyNames(target)
|
|
29
|
+
.concat(Object.getOwnPropertySymbols(target));
|
|
30
|
+
};
|
|
31
|
+
} else {
|
|
32
|
+
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
33
|
+
return Object.getOwnPropertyNames(target);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function ProcessEmitWarning(warning) {
|
|
38
|
+
if (console && console.warn) console.warn(warning);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
|
|
42
|
+
return value !== value;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function EventEmitter() {
|
|
46
|
+
EventEmitter.init.call(this);
|
|
47
|
+
}
|
|
48
|
+
events.exports = EventEmitter;
|
|
49
|
+
events.exports.once = once;
|
|
50
|
+
|
|
51
|
+
// Backwards-compat with node 0.10.x
|
|
52
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
53
|
+
|
|
54
|
+
EventEmitter.prototype._events = undefined;
|
|
55
|
+
EventEmitter.prototype._eventsCount = 0;
|
|
56
|
+
EventEmitter.prototype._maxListeners = undefined;
|
|
57
|
+
|
|
58
|
+
// By default EventEmitters will print a warning if more than 10 listeners are
|
|
59
|
+
// added to it. This is a useful default which helps finding memory leaks.
|
|
60
|
+
var defaultMaxListeners = 10;
|
|
61
|
+
|
|
62
|
+
function checkListener(listener) {
|
|
63
|
+
if (typeof listener !== 'function') {
|
|
64
|
+
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function() {
|
|
71
|
+
return defaultMaxListeners;
|
|
72
|
+
},
|
|
73
|
+
set: function(arg) {
|
|
74
|
+
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
|
|
75
|
+
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
|
|
76
|
+
}
|
|
77
|
+
defaultMaxListeners = arg;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
EventEmitter.init = function() {
|
|
82
|
+
|
|
83
|
+
if (this._events === undefined ||
|
|
84
|
+
this._events === Object.getPrototypeOf(this)._events) {
|
|
85
|
+
this._events = Object.create(null);
|
|
86
|
+
this._eventsCount = 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this._maxListeners = this._maxListeners || undefined;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Obviously not all Emitters should be limited to 10. This function allows
|
|
93
|
+
// that to be increased. Set to zero for unlimited.
|
|
94
|
+
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
|
95
|
+
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
|
|
96
|
+
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
|
|
97
|
+
}
|
|
98
|
+
this._maxListeners = n;
|
|
99
|
+
return this;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
function _getMaxListeners(that) {
|
|
103
|
+
if (that._maxListeners === undefined)
|
|
104
|
+
return EventEmitter.defaultMaxListeners;
|
|
105
|
+
return that._maxListeners;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
|
109
|
+
return _getMaxListeners(this);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
EventEmitter.prototype.emit = function emit(type) {
|
|
113
|
+
var args = [];
|
|
114
|
+
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
|
|
115
|
+
var doError = (type === 'error');
|
|
116
|
+
|
|
117
|
+
var events = this._events;
|
|
118
|
+
if (events !== undefined)
|
|
119
|
+
doError = (doError && events.error === undefined);
|
|
120
|
+
else if (!doError)
|
|
121
|
+
return false;
|
|
122
|
+
|
|
123
|
+
// If there is no 'error' event listener then throw.
|
|
124
|
+
if (doError) {
|
|
125
|
+
var er;
|
|
126
|
+
if (args.length > 0)
|
|
127
|
+
er = args[0];
|
|
128
|
+
if (er instanceof Error) {
|
|
129
|
+
// Note: The comments on the `throw` lines are intentional, they show
|
|
130
|
+
// up in Node's output if this results in an unhandled exception.
|
|
131
|
+
throw er; // Unhandled 'error' event
|
|
132
|
+
}
|
|
133
|
+
// At least give some kind of context to the user
|
|
134
|
+
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
|
|
135
|
+
err.context = er;
|
|
136
|
+
throw err; // Unhandled 'error' event
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
var handler = events[type];
|
|
140
|
+
|
|
141
|
+
if (handler === undefined)
|
|
142
|
+
return false;
|
|
143
|
+
|
|
144
|
+
if (typeof handler === 'function') {
|
|
145
|
+
ReflectApply(handler, this, args);
|
|
146
|
+
} else {
|
|
147
|
+
var len = handler.length;
|
|
148
|
+
var listeners = arrayClone(handler, len);
|
|
149
|
+
for (var i = 0; i < len; ++i)
|
|
150
|
+
ReflectApply(listeners[i], this, args);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return true;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
function _addListener(target, type, listener, prepend) {
|
|
157
|
+
var m;
|
|
158
|
+
var events;
|
|
159
|
+
var existing;
|
|
160
|
+
|
|
161
|
+
checkListener(listener);
|
|
162
|
+
|
|
163
|
+
events = target._events;
|
|
164
|
+
if (events === undefined) {
|
|
165
|
+
events = target._events = Object.create(null);
|
|
166
|
+
target._eventsCount = 0;
|
|
167
|
+
} else {
|
|
168
|
+
// To avoid recursion in the case that type === "newListener"! Before
|
|
169
|
+
// adding it to the listeners, first emit "newListener".
|
|
170
|
+
if (events.newListener !== undefined) {
|
|
171
|
+
target.emit('newListener', type,
|
|
172
|
+
listener.listener ? listener.listener : listener);
|
|
173
|
+
|
|
174
|
+
// Re-assign `events` because a newListener handler could have caused the
|
|
175
|
+
// this._events to be assigned to a new object
|
|
176
|
+
events = target._events;
|
|
177
|
+
}
|
|
178
|
+
existing = events[type];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (existing === undefined) {
|
|
182
|
+
// Optimize the case of one listener. Don't need the extra array object.
|
|
183
|
+
existing = events[type] = listener;
|
|
184
|
+
++target._eventsCount;
|
|
185
|
+
} else {
|
|
186
|
+
if (typeof existing === 'function') {
|
|
187
|
+
// Adding the second element, need to change to array.
|
|
188
|
+
existing = events[type] =
|
|
189
|
+
prepend ? [listener, existing] : [existing, listener];
|
|
190
|
+
// If we've already got an array, just append.
|
|
191
|
+
} else if (prepend) {
|
|
192
|
+
existing.unshift(listener);
|
|
193
|
+
} else {
|
|
194
|
+
existing.push(listener);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Check for listener leak
|
|
198
|
+
m = _getMaxListeners(target);
|
|
199
|
+
if (m > 0 && existing.length > m && !existing.warned) {
|
|
200
|
+
existing.warned = true;
|
|
201
|
+
// No error code for this since it is a Warning
|
|
202
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
203
|
+
var w = new Error('Possible EventEmitter memory leak detected. ' +
|
|
204
|
+
existing.length + ' ' + String(type) + ' listeners ' +
|
|
205
|
+
'added. Use emitter.setMaxListeners() to ' +
|
|
206
|
+
'increase limit');
|
|
207
|
+
w.name = 'MaxListenersExceededWarning';
|
|
208
|
+
w.emitter = target;
|
|
209
|
+
w.type = type;
|
|
210
|
+
w.count = existing.length;
|
|
211
|
+
ProcessEmitWarning(w);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return target;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
EventEmitter.prototype.addListener = function addListener(type, listener) {
|
|
219
|
+
return _addListener(this, type, listener, false);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
223
|
+
|
|
224
|
+
EventEmitter.prototype.prependListener =
|
|
225
|
+
function prependListener(type, listener) {
|
|
226
|
+
return _addListener(this, type, listener, true);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
function onceWrapper() {
|
|
230
|
+
if (!this.fired) {
|
|
231
|
+
this.target.removeListener(this.type, this.wrapFn);
|
|
232
|
+
this.fired = true;
|
|
233
|
+
if (arguments.length === 0)
|
|
234
|
+
return this.listener.call(this.target);
|
|
235
|
+
return this.listener.apply(this.target, arguments);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function _onceWrap(target, type, listener) {
|
|
240
|
+
var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
|
|
241
|
+
var wrapped = onceWrapper.bind(state);
|
|
242
|
+
wrapped.listener = listener;
|
|
243
|
+
state.wrapFn = wrapped;
|
|
244
|
+
return wrapped;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
EventEmitter.prototype.once = function once(type, listener) {
|
|
248
|
+
checkListener(listener);
|
|
249
|
+
this.on(type, _onceWrap(this, type, listener));
|
|
250
|
+
return this;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
EventEmitter.prototype.prependOnceListener =
|
|
254
|
+
function prependOnceListener(type, listener) {
|
|
255
|
+
checkListener(listener);
|
|
256
|
+
this.prependListener(type, _onceWrap(this, type, listener));
|
|
257
|
+
return this;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// Emits a 'removeListener' event if and only if the listener was removed.
|
|
261
|
+
EventEmitter.prototype.removeListener =
|
|
262
|
+
function removeListener(type, listener) {
|
|
263
|
+
var list, events, position, i, originalListener;
|
|
264
|
+
|
|
265
|
+
checkListener(listener);
|
|
266
|
+
|
|
267
|
+
events = this._events;
|
|
268
|
+
if (events === undefined)
|
|
269
|
+
return this;
|
|
270
|
+
|
|
271
|
+
list = events[type];
|
|
272
|
+
if (list === undefined)
|
|
273
|
+
return this;
|
|
274
|
+
|
|
275
|
+
if (list === listener || list.listener === listener) {
|
|
276
|
+
if (--this._eventsCount === 0)
|
|
277
|
+
this._events = Object.create(null);
|
|
278
|
+
else {
|
|
279
|
+
delete events[type];
|
|
280
|
+
if (events.removeListener)
|
|
281
|
+
this.emit('removeListener', type, list.listener || listener);
|
|
282
|
+
}
|
|
283
|
+
} else if (typeof list !== 'function') {
|
|
284
|
+
position = -1;
|
|
285
|
+
|
|
286
|
+
for (i = list.length - 1; i >= 0; i--) {
|
|
287
|
+
if (list[i] === listener || list[i].listener === listener) {
|
|
288
|
+
originalListener = list[i].listener;
|
|
289
|
+
position = i;
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (position < 0)
|
|
295
|
+
return this;
|
|
296
|
+
|
|
297
|
+
if (position === 0)
|
|
298
|
+
list.shift();
|
|
299
|
+
else {
|
|
300
|
+
spliceOne(list, position);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (list.length === 1)
|
|
304
|
+
events[type] = list[0];
|
|
305
|
+
|
|
306
|
+
if (events.removeListener !== undefined)
|
|
307
|
+
this.emit('removeListener', type, originalListener || listener);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return this;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
314
|
+
|
|
315
|
+
EventEmitter.prototype.removeAllListeners =
|
|
316
|
+
function removeAllListeners(type) {
|
|
317
|
+
var listeners, events, i;
|
|
318
|
+
|
|
319
|
+
events = this._events;
|
|
320
|
+
if (events === undefined)
|
|
321
|
+
return this;
|
|
322
|
+
|
|
323
|
+
// not listening for removeListener, no need to emit
|
|
324
|
+
if (events.removeListener === undefined) {
|
|
325
|
+
if (arguments.length === 0) {
|
|
326
|
+
this._events = Object.create(null);
|
|
327
|
+
this._eventsCount = 0;
|
|
328
|
+
} else if (events[type] !== undefined) {
|
|
329
|
+
if (--this._eventsCount === 0)
|
|
330
|
+
this._events = Object.create(null);
|
|
331
|
+
else
|
|
332
|
+
delete events[type];
|
|
333
|
+
}
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// emit removeListener for all listeners on all events
|
|
338
|
+
if (arguments.length === 0) {
|
|
339
|
+
var keys = Object.keys(events);
|
|
340
|
+
var key;
|
|
341
|
+
for (i = 0; i < keys.length; ++i) {
|
|
342
|
+
key = keys[i];
|
|
343
|
+
if (key === 'removeListener') continue;
|
|
344
|
+
this.removeAllListeners(key);
|
|
345
|
+
}
|
|
346
|
+
this.removeAllListeners('removeListener');
|
|
347
|
+
this._events = Object.create(null);
|
|
348
|
+
this._eventsCount = 0;
|
|
349
|
+
return this;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
listeners = events[type];
|
|
353
|
+
|
|
354
|
+
if (typeof listeners === 'function') {
|
|
355
|
+
this.removeListener(type, listeners);
|
|
356
|
+
} else if (listeners !== undefined) {
|
|
357
|
+
// LIFO order
|
|
358
|
+
for (i = listeners.length - 1; i >= 0; i--) {
|
|
359
|
+
this.removeListener(type, listeners[i]);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return this;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
function _listeners(target, type, unwrap) {
|
|
367
|
+
var events = target._events;
|
|
368
|
+
|
|
369
|
+
if (events === undefined)
|
|
370
|
+
return [];
|
|
371
|
+
|
|
372
|
+
var evlistener = events[type];
|
|
373
|
+
if (evlistener === undefined)
|
|
374
|
+
return [];
|
|
375
|
+
|
|
376
|
+
if (typeof evlistener === 'function')
|
|
377
|
+
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
|
378
|
+
|
|
379
|
+
return unwrap ?
|
|
380
|
+
unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
EventEmitter.prototype.listeners = function listeners(type) {
|
|
384
|
+
return _listeners(this, type, true);
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
|
388
|
+
return _listeners(this, type, false);
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
EventEmitter.listenerCount = function(emitter, type) {
|
|
392
|
+
if (typeof emitter.listenerCount === 'function') {
|
|
393
|
+
return emitter.listenerCount(type);
|
|
394
|
+
} else {
|
|
395
|
+
return listenerCount.call(emitter, type);
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
EventEmitter.prototype.listenerCount = listenerCount;
|
|
400
|
+
function listenerCount(type) {
|
|
401
|
+
var events = this._events;
|
|
402
|
+
|
|
403
|
+
if (events !== undefined) {
|
|
404
|
+
var evlistener = events[type];
|
|
405
|
+
|
|
406
|
+
if (typeof evlistener === 'function') {
|
|
407
|
+
return 1;
|
|
408
|
+
} else if (evlistener !== undefined) {
|
|
409
|
+
return evlistener.length;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return 0;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
417
|
+
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
function arrayClone(arr, n) {
|
|
421
|
+
var copy = new Array(n);
|
|
422
|
+
for (var i = 0; i < n; ++i)
|
|
423
|
+
copy[i] = arr[i];
|
|
424
|
+
return copy;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function spliceOne(list, index) {
|
|
428
|
+
for (; index + 1 < list.length; index++)
|
|
429
|
+
list[index] = list[index + 1];
|
|
430
|
+
list.pop();
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function unwrapListeners(arr) {
|
|
434
|
+
var ret = new Array(arr.length);
|
|
435
|
+
for (var i = 0; i < ret.length; ++i) {
|
|
436
|
+
ret[i] = arr[i].listener || arr[i];
|
|
437
|
+
}
|
|
438
|
+
return ret;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function once(emitter, name) {
|
|
442
|
+
return new Promise(function (resolve, reject) {
|
|
443
|
+
function errorListener(err) {
|
|
444
|
+
emitter.removeListener(name, resolver);
|
|
445
|
+
reject(err);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function resolver() {
|
|
449
|
+
if (typeof emitter.removeListener === 'function') {
|
|
450
|
+
emitter.removeListener('error', errorListener);
|
|
451
|
+
}
|
|
452
|
+
resolve([].slice.call(arguments));
|
|
453
|
+
}
|
|
454
|
+
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
|
|
455
|
+
if (name !== 'error') {
|
|
456
|
+
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
|
|
462
|
+
if (typeof emitter.on === 'function') {
|
|
463
|
+
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
468
|
+
if (typeof emitter.on === 'function') {
|
|
469
|
+
if (flags.once) {
|
|
470
|
+
emitter.once(name, listener);
|
|
471
|
+
} else {
|
|
472
|
+
emitter.on(name, listener);
|
|
473
|
+
}
|
|
474
|
+
} else if (typeof emitter.addEventListener === 'function') {
|
|
475
|
+
// EventTarget does not have `error` event semantics like Node
|
|
476
|
+
// EventEmitters, we do not listen for `error` events here.
|
|
477
|
+
emitter.addEventListener(name, function wrapListener(arg) {
|
|
478
|
+
// IE does not have builtin `{ once: true }` support so we
|
|
479
|
+
// have to do it manually.
|
|
480
|
+
if (flags.once) {
|
|
481
|
+
emitter.removeEventListener(name, wrapListener);
|
|
482
|
+
}
|
|
483
|
+
listener(arg);
|
|
484
|
+
});
|
|
485
|
+
} else {
|
|
486
|
+
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return events.exports;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
var eventsExports = requireEvents();
|
|
493
|
+
var EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventsExports);
|
|
494
|
+
|
|
495
|
+
function getAllCallablePropertyNames(obj) {
|
|
496
|
+
if (!obj)
|
|
497
|
+
return [];
|
|
498
|
+
let props = [], tmpProps = [], index = 0, size = 0, tmpProp = '';
|
|
499
|
+
const bans = ["constructor", "__defineGetter__", "__defineSetter__",
|
|
500
|
+
"hasOwnProperty", "__lookupGetter__", "__lookupSetter__",
|
|
501
|
+
"isPrototypeOf", "propertyIsEnumerable", "toString",
|
|
502
|
+
"valueOf", "__proto__", "toLocaleString"];
|
|
503
|
+
do {
|
|
504
|
+
tmpProps = Object.getOwnPropertyNames(obj);
|
|
505
|
+
index = -1, size = tmpProps.length;
|
|
506
|
+
while (++index < size) {
|
|
507
|
+
tmpProp = tmpProps[index];
|
|
508
|
+
if (!props.includes(tmpProp) && !bans.includes(tmpProp)) {
|
|
509
|
+
props.push(tmpProp);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
} while (obj = Object.getPrototypeOf(obj));
|
|
513
|
+
return props;
|
|
514
|
+
}
|
|
515
|
+
function genKVMethods(methods, kvMethods = new Map(), sourceKVMethods = new Map(), nameStack = []) {
|
|
516
|
+
let keys = getAllCallablePropertyNames(methods);
|
|
517
|
+
for (const key of keys) {
|
|
518
|
+
/**
|
|
519
|
+
* @type {Function}
|
|
520
|
+
*/
|
|
521
|
+
let val = methods[key];
|
|
522
|
+
if ('function' === typeof val) {
|
|
523
|
+
const action = nameStack.concat(key).join('.');
|
|
524
|
+
// 原函数绑定
|
|
525
|
+
sourceKVMethods.set(action, val);
|
|
526
|
+
// 壳函数绑定
|
|
527
|
+
kvMethods.set(action, val.bind(methods));
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
genKVMethods(val, kvMethods, sourceKVMethods, nameStack.concat(key));
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return { kvMethods, sourceKVMethods };
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const contexts = {};
|
|
537
|
+
function parseTraceIdByStack(stack) {
|
|
538
|
+
const [traceRow] = stack.split('/').filter(row => row.includes('OOX_TRACER.<computed>'));
|
|
539
|
+
if (traceRow) {
|
|
540
|
+
return traceRow.match(/(?<=as\s).*?(?=\s|\])/g)?.[0] || null;
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function enterWith(context) {
|
|
547
|
+
const traceId = context.traceId || '';
|
|
548
|
+
contexts[traceId] = context;
|
|
549
|
+
}
|
|
550
|
+
function exitWith(context) {
|
|
551
|
+
const traceId = context.traceId || '';
|
|
552
|
+
delete contexts[traceId];
|
|
553
|
+
}
|
|
554
|
+
function getContext$1() {
|
|
555
|
+
const traceId = parseTraceIdByStack(new Error().stack || '') || '';
|
|
556
|
+
return contexts[traceId] || null;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
const eventHub = new eventsExports.EventEmitter();
|
|
560
|
+
/**
|
|
561
|
+
* sourceMethods => methods
|
|
562
|
+
*/
|
|
563
|
+
let sourceMethods = {};
|
|
564
|
+
/**
|
|
565
|
+
* the kvMethods is all actions refs [has bind this]
|
|
566
|
+
*/
|
|
567
|
+
const kvMethods = new Map();
|
|
568
|
+
const sourceKVMethods = new Map();
|
|
569
|
+
function setMethods(methods) {
|
|
570
|
+
sourceMethods = methods;
|
|
571
|
+
kvMethods.clear();
|
|
572
|
+
sourceKVMethods.clear();
|
|
573
|
+
genKVMethods(methods, kvMethods, sourceKVMethods);
|
|
574
|
+
}
|
|
575
|
+
function getMethods() {
|
|
576
|
+
return sourceMethods;
|
|
577
|
+
}
|
|
578
|
+
function on(event, listener) {
|
|
579
|
+
eventHub.on(event, listener);
|
|
580
|
+
}
|
|
581
|
+
function once(event, listener) {
|
|
582
|
+
eventHub.once(event, listener);
|
|
583
|
+
}
|
|
584
|
+
function off(event, listener) {
|
|
585
|
+
eventHub.off(event, listener);
|
|
586
|
+
}
|
|
587
|
+
function emit(event, ...args) {
|
|
588
|
+
return eventHub.emit(event, ...args);
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Call an Function on RPC server
|
|
592
|
+
* @param action
|
|
593
|
+
* @param params
|
|
594
|
+
* @param context
|
|
595
|
+
* @returns
|
|
596
|
+
*/
|
|
597
|
+
async function call(action, params = [], context) {
|
|
598
|
+
if (!Array.isArray(params))
|
|
599
|
+
params = [params];
|
|
600
|
+
const { traceId } = context;
|
|
601
|
+
emit('call:start', Date.now(), action, params, context);
|
|
602
|
+
const returns = {
|
|
603
|
+
traceId,
|
|
604
|
+
success: true
|
|
605
|
+
};
|
|
606
|
+
const OOX_TRACER = {};
|
|
607
|
+
OOX_TRACER[traceId] = async (action, [...params], context) => {
|
|
608
|
+
return await execute(action, [...params], context);
|
|
609
|
+
};
|
|
610
|
+
enterWith(context);
|
|
611
|
+
try {
|
|
612
|
+
const result = await OOX_TRACER[traceId](action, [...params], context);
|
|
613
|
+
returns.body = result;
|
|
614
|
+
emit('call:success', Date.now(), action, params, context, result);
|
|
615
|
+
}
|
|
616
|
+
catch (error) {
|
|
617
|
+
returns.success = false;
|
|
618
|
+
returns.error = {
|
|
619
|
+
message: error.message,
|
|
620
|
+
stack: error.stack
|
|
621
|
+
};
|
|
622
|
+
emit('call:fail', Date.now(), action, params, context, error);
|
|
623
|
+
}
|
|
624
|
+
finally {
|
|
625
|
+
exitWith(context);
|
|
626
|
+
return returns;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
async function execute(action, params, context) {
|
|
630
|
+
const __proxy = '__proxy', _proxy = '_proxy';
|
|
631
|
+
if (__proxy === action || _proxy === action || action.endsWith(_proxy))
|
|
632
|
+
throw new Error('Invalid Action[' + action + ']');
|
|
633
|
+
const methods = kvMethods;
|
|
634
|
+
// 目标函数
|
|
635
|
+
const target = methods.get(action);
|
|
636
|
+
// 目标代理函数
|
|
637
|
+
const targetProxy = methods.get(action + _proxy);
|
|
638
|
+
// 即不存在目标也不存在目标代理时, 报错函数不存在
|
|
639
|
+
if (!target && !targetProxy)
|
|
640
|
+
throw new Error('Unknown Action [' + action + ']');
|
|
641
|
+
// ============================ PROXY BEGIN ============================
|
|
642
|
+
// 最顶层代理
|
|
643
|
+
const topProxy = methods.get(__proxy);
|
|
644
|
+
if (topProxy) {
|
|
645
|
+
const proxyReturns = await topProxy(action, params, context);
|
|
646
|
+
if (proxyReturns !== undefined)
|
|
647
|
+
return proxyReturns;
|
|
648
|
+
}
|
|
649
|
+
// 'x.y.z' => [ 'x', 'y', 'z' ]
|
|
650
|
+
const nameStack = action.split('.'), size = nameStack.length - 1;
|
|
651
|
+
let index = -1, proxyPrefix = '';
|
|
652
|
+
// 根代理遍历
|
|
653
|
+
while (++index < size) {
|
|
654
|
+
// x.
|
|
655
|
+
// x.y.
|
|
656
|
+
proxyPrefix += nameStack[index] + '.';
|
|
657
|
+
// x.__proxy
|
|
658
|
+
// x.y.__proxy
|
|
659
|
+
const rootProxy = methods.get(proxyPrefix + __proxy);
|
|
660
|
+
// x.__proxy ( 'y.z', ... )
|
|
661
|
+
// x.y.__proxy ( 'z', ... )
|
|
662
|
+
if (rootProxy) {
|
|
663
|
+
const proxyReturns = await rootProxy(nameStack.slice(index).join('.'), params, context);
|
|
664
|
+
if (proxyReturns !== undefined)
|
|
665
|
+
return proxyReturns;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
// 同级代理
|
|
669
|
+
const layerProxy = methods.get(proxyPrefix + _proxy);
|
|
670
|
+
if (layerProxy) {
|
|
671
|
+
const proxyReturns = await layerProxy(nameStack[index], params, context);
|
|
672
|
+
if (proxyReturns !== undefined)
|
|
673
|
+
return proxyReturns;
|
|
674
|
+
}
|
|
675
|
+
if (targetProxy) {
|
|
676
|
+
const proxyReturns = await targetProxy(params, context);
|
|
677
|
+
if (proxyReturns !== undefined)
|
|
678
|
+
return proxyReturns;
|
|
679
|
+
}
|
|
680
|
+
// ============================= PROXY END =============================
|
|
681
|
+
// make sure target action execute after all proxies
|
|
682
|
+
if (target) {
|
|
683
|
+
return await target(...params);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
class Config {
|
|
688
|
+
id = '';
|
|
689
|
+
name = 'DEFAULT_NAME';
|
|
690
|
+
}
|
|
691
|
+
const config = new Config();
|
|
692
|
+
|
|
693
|
+
class AppContext {
|
|
694
|
+
// 请求溯源ID
|
|
695
|
+
traceId = '';
|
|
696
|
+
}
|
|
697
|
+
class Context extends AppContext {
|
|
698
|
+
// 请求溯源IP
|
|
699
|
+
sourceIP = '';
|
|
700
|
+
// 请求者IP
|
|
701
|
+
ip = '';
|
|
702
|
+
// 请求者名称
|
|
703
|
+
caller = 'anonymous';
|
|
704
|
+
// 请求者ID (长连接专用)
|
|
705
|
+
callerId = '';
|
|
706
|
+
// 请求者连接把柄
|
|
707
|
+
connection;
|
|
708
|
+
constructor(context) {
|
|
709
|
+
super();
|
|
710
|
+
if (context) {
|
|
711
|
+
if ('toJSON' in context && typeof context.toJSON !== 'function') {
|
|
712
|
+
throw new Error('Context.toJSON must be a function');
|
|
713
|
+
}
|
|
714
|
+
Object.assign(this, context);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
toJSON() {
|
|
718
|
+
const context = Object.assign({}, this);
|
|
719
|
+
delete context.connection;
|
|
720
|
+
return context;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
let genTraceIdFunction = () => crypto.randomUUID();
|
|
724
|
+
function setGenTraceIdFunction(fn) {
|
|
725
|
+
genTraceIdFunction = fn;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* 生成随机不重复id
|
|
729
|
+
*/
|
|
730
|
+
function genTraceId() {
|
|
731
|
+
return genTraceIdFunction();
|
|
732
|
+
}
|
|
733
|
+
function genContext(context) {
|
|
734
|
+
const newContext = new Context(context);
|
|
735
|
+
if (!newContext.traceId)
|
|
736
|
+
newContext.traceId = genTraceId();
|
|
737
|
+
if (!newContext.sourceIP)
|
|
738
|
+
newContext.sourceIP = newContext.ip;
|
|
739
|
+
return newContext;
|
|
740
|
+
}
|
|
741
|
+
function getContext() {
|
|
742
|
+
return getContext$1() || genContext();
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
class KeepAliveConnectionError extends Error {
|
|
746
|
+
connection;
|
|
747
|
+
constructor(message, connection) {
|
|
748
|
+
super(message);
|
|
749
|
+
this.connection = connection;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
class KeepAliveConnection extends EventEmitter {
|
|
753
|
+
// 是否为注册服务连接
|
|
754
|
+
isRegistry = false;
|
|
755
|
+
// 连接是否可用
|
|
756
|
+
#enabled = false;
|
|
757
|
+
data;
|
|
758
|
+
nativeConnection;
|
|
759
|
+
adapter;
|
|
760
|
+
constructor(adapter, nativeConnection, data) {
|
|
761
|
+
super();
|
|
762
|
+
this.adapter = adapter;
|
|
763
|
+
this.nativeConnection = nativeConnection;
|
|
764
|
+
this.data = Object.assign(data, {
|
|
765
|
+
adapter: adapter.name,
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* 设置连接是否可用,并自动触发enabled或disabled事件
|
|
770
|
+
* @param enabled 是否可用
|
|
771
|
+
*/
|
|
772
|
+
set enabled(enabled) {
|
|
773
|
+
if (enabled !== this.#enabled) {
|
|
774
|
+
this.#enabled = enabled;
|
|
775
|
+
this.emit(enabled ? 'enabled' : 'disabled');
|
|
776
|
+
if (enabled) {
|
|
777
|
+
enabledKeepAliveConnections.add(this);
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
enabledKeepAliveConnections.remove(this);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
get enabled() {
|
|
785
|
+
return this.#enabled;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* enable & mount connection
|
|
789
|
+
* @param params
|
|
790
|
+
* @returns
|
|
791
|
+
*/
|
|
792
|
+
ready(params) {
|
|
793
|
+
// 连接已就绪,不允许重复就绪
|
|
794
|
+
if (this.enabled)
|
|
795
|
+
return;
|
|
796
|
+
const { id, name } = params;
|
|
797
|
+
keepAliveConnections.remove(this);
|
|
798
|
+
// 更新连接数据
|
|
799
|
+
this.data.id = id;
|
|
800
|
+
this.data.name = name;
|
|
801
|
+
keepAliveConnections.add(this);
|
|
802
|
+
this.enabled = true;
|
|
803
|
+
}
|
|
804
|
+
disconnect() {
|
|
805
|
+
this.enabled = false;
|
|
806
|
+
this.nativeConnection.disconnect();
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
class KeepAliveConnectionStore {
|
|
810
|
+
#map = new Map();
|
|
811
|
+
entries() {
|
|
812
|
+
return this.#map.entries();
|
|
813
|
+
}
|
|
814
|
+
getConnectionsOfService(name) {
|
|
815
|
+
return this.#map.get(name) || new Map();
|
|
816
|
+
}
|
|
817
|
+
has(name, id) {
|
|
818
|
+
const connections = this.#map.get(name);
|
|
819
|
+
if (!connections)
|
|
820
|
+
return false;
|
|
821
|
+
return connections.has(id);
|
|
822
|
+
}
|
|
823
|
+
get(name, id) {
|
|
824
|
+
const connections = this.#map.get(name);
|
|
825
|
+
if (!connections)
|
|
826
|
+
return null;
|
|
827
|
+
return connections.get(id) || null;
|
|
828
|
+
}
|
|
829
|
+
add(connection) {
|
|
830
|
+
const { name, id } = connection.data;
|
|
831
|
+
const connections = this.#map.get(name);
|
|
832
|
+
if (connections) {
|
|
833
|
+
connections.set(id, connection);
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
this.#map.set(name, new Map([[id, connection]]));
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
remove(name, id) {
|
|
840
|
+
if (name instanceof KeepAliveConnection) {
|
|
841
|
+
id = name.data.id;
|
|
842
|
+
name = name.data.name;
|
|
843
|
+
}
|
|
844
|
+
const connections = this.#map.get(name);
|
|
845
|
+
if (connections && id !== undefined) {
|
|
846
|
+
connections.delete(id);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
const keepAliveConnectionAdapters = new Map();
|
|
851
|
+
const keepAliveConnections = new KeepAliveConnectionStore();
|
|
852
|
+
const enabledKeepAliveConnections = new KeepAliveConnectionStore();
|
|
853
|
+
function addKeepAliveConnection(connection) {
|
|
854
|
+
if (keepAliveConnections.has(connection.data.name, connection.data.id)) {
|
|
855
|
+
connection.disconnect();
|
|
856
|
+
throw new KeepAliveConnectionError('Connection already exists', connection);
|
|
857
|
+
}
|
|
858
|
+
keepAliveConnections.add(connection);
|
|
859
|
+
}
|
|
860
|
+
function removeKeepAliveConnection(arg1, arg2) {
|
|
861
|
+
if (typeof arg1 === 'string') {
|
|
862
|
+
const connection = keepAliveConnections.get(arg1, arg2);
|
|
863
|
+
if (connection)
|
|
864
|
+
connection.disconnect();
|
|
865
|
+
keepAliveConnections.remove(arg1, arg2);
|
|
866
|
+
enabledKeepAliveConnections.remove(arg1, arg2);
|
|
867
|
+
}
|
|
868
|
+
else {
|
|
869
|
+
arg1.disconnect();
|
|
870
|
+
keepAliveConnections.remove(arg1);
|
|
871
|
+
enabledKeepAliveConnections.remove(arg1);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* random connection select for default load balance policy
|
|
876
|
+
* @param name service name
|
|
877
|
+
* @returns selected connection
|
|
878
|
+
*/
|
|
879
|
+
let loadBalancePolicy = (name) => {
|
|
880
|
+
const connections = enabledKeepAliveConnections.getConnectionsOfService(name);
|
|
881
|
+
if (!connections || !connections.size)
|
|
882
|
+
return null;
|
|
883
|
+
const arrayConnections = Array.from(connections.values());
|
|
884
|
+
const index = Math.floor(Math.random() * arrayConnections.length);
|
|
885
|
+
return arrayConnections[index];
|
|
886
|
+
};
|
|
887
|
+
function setLoadBalancePolicy(policy) {
|
|
888
|
+
loadBalancePolicy = policy;
|
|
889
|
+
}
|
|
890
|
+
async function rpc(arg1, action, params, context) {
|
|
891
|
+
if (!context || !context.traceId) {
|
|
892
|
+
context = getContext();
|
|
893
|
+
}
|
|
894
|
+
let connection = null;
|
|
895
|
+
if (arg1 instanceof KeepAliveConnection) {
|
|
896
|
+
connection = arg1;
|
|
897
|
+
}
|
|
898
|
+
else if ('string' === typeof arg1) {
|
|
899
|
+
connection = loadBalancePolicy(arg1);
|
|
900
|
+
}
|
|
901
|
+
else
|
|
902
|
+
throw new Error(`Unknown rpc arg1<${arg1}>`);
|
|
903
|
+
if (!connection)
|
|
904
|
+
throw new Error(`Connection<${arg1}> not found`);
|
|
905
|
+
return connection.adapter.rpc(connection, action, params, context);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
class SampleKeepAliveConnectionAdapter {
|
|
909
|
+
OOXEvent = {
|
|
910
|
+
CONNECT: 'connect',
|
|
911
|
+
DISCONNECT: 'disconnect',
|
|
912
|
+
ERROR: 'error',
|
|
913
|
+
CALL: 'call',
|
|
914
|
+
READY: 'oox:ready',
|
|
915
|
+
ENABLED: 'oox:enabled',
|
|
916
|
+
DISABLED: 'oox:disabled',
|
|
917
|
+
REGISTRY_SYNC_CONNECTIONS: 'oox:registry:sync_connections',
|
|
918
|
+
REGISTRY_SUBSCRIBE: 'oox:registry:subscribe',
|
|
919
|
+
REGISTRY_NOTIFY: 'oox:registry:notify',
|
|
920
|
+
};
|
|
921
|
+
/**
|
|
922
|
+
* 通知连接列表
|
|
923
|
+
*/
|
|
924
|
+
['registry:notify'](connection, datas) {
|
|
925
|
+
connection.nativeConnection.emit(this.OOXEvent.REGISTRY_NOTIFY, datas);
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* 订阅连接列表
|
|
929
|
+
*/
|
|
930
|
+
['registry:subscribe'](connection, query) {
|
|
931
|
+
connection.nativeConnection.emit(this.OOXEvent.REGISTRY_SUBSCRIBE, query);
|
|
932
|
+
}
|
|
933
|
+
bindConnectionEvents(connection) {
|
|
934
|
+
const socket = connection.nativeConnection;
|
|
935
|
+
socket.on(this.OOXEvent.READY, (params) => {
|
|
936
|
+
connection.ready(params);
|
|
937
|
+
});
|
|
938
|
+
socket.on(this.OOXEvent.ENABLED, () => {
|
|
939
|
+
connection.enabled = true;
|
|
940
|
+
});
|
|
941
|
+
socket.on(this.OOXEvent.DISABLED, () => {
|
|
942
|
+
connection.enabled = false;
|
|
943
|
+
});
|
|
944
|
+
socket.on(this.OOXEvent.DISCONNECT, () => {
|
|
945
|
+
removeKeepAliveConnection(connection);
|
|
946
|
+
socket.removeAllListeners();
|
|
947
|
+
connection.emit('disconnect');
|
|
948
|
+
});
|
|
949
|
+
socket.on(this.OOXEvent.CONNECT, () => {
|
|
950
|
+
connection.emit('connect');
|
|
951
|
+
});
|
|
952
|
+
socket.on(this.OOXEvent.ERROR, (error) => {
|
|
953
|
+
removeKeepAliveConnection(connection);
|
|
954
|
+
socket.removeAllListeners();
|
|
955
|
+
connection.emit('error', new KeepAliveConnectionError(error.message, connection));
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
async open(identify) {
|
|
959
|
+
const connection = this.newConnection(identify);
|
|
960
|
+
addKeepAliveConnection(connection);
|
|
961
|
+
this.bindConnectionEvents(connection);
|
|
962
|
+
this.bindCall(connection);
|
|
963
|
+
await new Promise((resolve, reject) => {
|
|
964
|
+
connection.once('enabled', resolve);
|
|
965
|
+
connection.once('error', reject);
|
|
966
|
+
connection.once('disconnect', () => {
|
|
967
|
+
reject(new Error('disconnect'));
|
|
968
|
+
});
|
|
969
|
+
if (connection.nativeConnection.connect) {
|
|
970
|
+
connection.nativeConnection.connect();
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
return connection;
|
|
974
|
+
}
|
|
975
|
+
async close(connection) {
|
|
976
|
+
connection.nativeConnection.disconnect();
|
|
977
|
+
return Promise.resolve();
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* 发送事件
|
|
981
|
+
* @param socket
|
|
982
|
+
* @param event
|
|
983
|
+
* @param params
|
|
984
|
+
*/
|
|
985
|
+
async emit(socket, event, params) {
|
|
986
|
+
if (!socket.connected)
|
|
987
|
+
throw new Error('Socket not connected');
|
|
988
|
+
return await new Promise((resolve, reject) => {
|
|
989
|
+
const onError = (reason) => {
|
|
990
|
+
const message = 'string' === typeof reason ? reason : reason instanceof Error ? reason.message : 'connect error';
|
|
991
|
+
reject(new Error(message));
|
|
992
|
+
};
|
|
993
|
+
// RPC 执行时中断连接
|
|
994
|
+
socket.once(this.OOXEvent.DISCONNECT, onError);
|
|
995
|
+
socket.emit(event, ...params, (returns) => {
|
|
996
|
+
socket.off(this.OOXEvent.DISCONNECT, onError);
|
|
997
|
+
resolve(returns);
|
|
998
|
+
});
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* RPC
|
|
1003
|
+
*/
|
|
1004
|
+
async rpc(connection, action, params, context) {
|
|
1005
|
+
if (!context)
|
|
1006
|
+
context = getContext();
|
|
1007
|
+
const miniContext = {
|
|
1008
|
+
sourceIP: context.sourceIP,
|
|
1009
|
+
traceId: context.traceId,
|
|
1010
|
+
};
|
|
1011
|
+
const { success, error, body } = await this.emit(connection.nativeConnection, this.OOXEvent.CALL, [action, params, miniContext]);
|
|
1012
|
+
if (success)
|
|
1013
|
+
return body;
|
|
1014
|
+
else if (error)
|
|
1015
|
+
throw new Error(error.message);
|
|
1016
|
+
else
|
|
1017
|
+
throw new Error('[RPC] Unknown Error');
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* 绑定 call 事件
|
|
1021
|
+
* @param connection
|
|
1022
|
+
*/
|
|
1023
|
+
bindCall(connection) {
|
|
1024
|
+
const { id, name, ip } = connection.data;
|
|
1025
|
+
connection.nativeConnection.on(this.OOXEvent.CALL, async (action, params, context, callback) => {
|
|
1026
|
+
const validContext = new Context({
|
|
1027
|
+
...context,
|
|
1028
|
+
ip: ip,
|
|
1029
|
+
caller: name,
|
|
1030
|
+
callerId: id,
|
|
1031
|
+
connection
|
|
1032
|
+
});
|
|
1033
|
+
this.call(action, params, validContext, callback);
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
async call(action, params, context, callback) {
|
|
1037
|
+
const returns = await call(action, params, context);
|
|
1038
|
+
'function' === typeof callback && callback(returns);
|
|
1039
|
+
return returns;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
function info(...content) {
|
|
1044
|
+
const context = getContext$1() || null;
|
|
1045
|
+
emit('log', Date.now(), context, 'info', content);
|
|
1046
|
+
}
|
|
1047
|
+
function warn(...content) {
|
|
1048
|
+
const context = getContext$1() || null;
|
|
1049
|
+
emit('log', Date.now(), context, 'warn', content);
|
|
1050
|
+
}
|
|
1051
|
+
function error(...content) {
|
|
1052
|
+
const context = getContext$1() || null;
|
|
1053
|
+
emit('log', Date.now(), context, 'error', content);
|
|
1054
|
+
}
|
|
1055
|
+
function tag(name) {
|
|
1056
|
+
const context = getContext$1() || null;
|
|
1057
|
+
emit('log', Date.now(), context, 'tag', name);
|
|
1058
|
+
}
|
|
1059
|
+
function trace(name) {
|
|
1060
|
+
const context = getContext$1() || null;
|
|
1061
|
+
const trace = { stack: '' };
|
|
1062
|
+
Error.captureStackTrace(trace);
|
|
1063
|
+
const stack = trace.stack
|
|
1064
|
+
.replace(/.*\n.*logger.js.*\n/, name || 'Untitle\n');
|
|
1065
|
+
emit('log', Date.now(), context, 'trace', stack);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
var logger = /*#__PURE__*/Object.freeze({
|
|
1069
|
+
__proto__: null,
|
|
1070
|
+
error: error,
|
|
1071
|
+
info: info,
|
|
1072
|
+
tag: tag,
|
|
1073
|
+
trace: trace,
|
|
1074
|
+
warn: warn
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* 为了不重复创建Proxy,这个对象用于保存各个RPC服务的各个属性Proxy
|
|
1079
|
+
*/
|
|
1080
|
+
const rpcServiceAttrMap = Object.create(null);
|
|
1081
|
+
function proxy(name, action = '') {
|
|
1082
|
+
return new Proxy(function () { }, {
|
|
1083
|
+
get(target, key) {
|
|
1084
|
+
if (typeof key !== 'string')
|
|
1085
|
+
return undefined;
|
|
1086
|
+
const attrKey = action ? action + '.' + key : key;
|
|
1087
|
+
const attrKeyPath = name + '.' + attrKey;
|
|
1088
|
+
if (attrKeyPath in rpcServiceAttrMap) {
|
|
1089
|
+
// 不重复创建Proxy
|
|
1090
|
+
return rpcServiceAttrMap[attrKeyPath];
|
|
1091
|
+
}
|
|
1092
|
+
const attrProxy = proxy(name, attrKey);
|
|
1093
|
+
rpcServiceAttrMap[attrKeyPath] = attrProxy;
|
|
1094
|
+
return attrProxy;
|
|
1095
|
+
},
|
|
1096
|
+
has(target, key) {
|
|
1097
|
+
if (typeof key !== 'string')
|
|
1098
|
+
return false;
|
|
1099
|
+
return true;
|
|
1100
|
+
},
|
|
1101
|
+
apply(target, thisArg, args) {
|
|
1102
|
+
return rpc(name, action, args);
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
exports.AppContext = AppContext;
|
|
1108
|
+
exports.Config = Config;
|
|
1109
|
+
exports.Context = Context;
|
|
1110
|
+
exports.KeepAliveConnection = KeepAliveConnection;
|
|
1111
|
+
exports.KeepAliveConnectionError = KeepAliveConnectionError;
|
|
1112
|
+
exports.KeepAliveConnectionStore = KeepAliveConnectionStore;
|
|
1113
|
+
exports.SampleKeepAliveConnectionAdapter = SampleKeepAliveConnectionAdapter;
|
|
1114
|
+
exports.addKeepAliveConnection = addKeepAliveConnection;
|
|
1115
|
+
exports.call = call;
|
|
1116
|
+
exports.config = config;
|
|
1117
|
+
exports.emit = emit;
|
|
1118
|
+
exports.enabledKeepAliveConnections = enabledKeepAliveConnections;
|
|
1119
|
+
exports.eventHub = eventHub;
|
|
1120
|
+
exports.execute = execute;
|
|
1121
|
+
exports.genContext = genContext;
|
|
1122
|
+
exports.genTraceId = genTraceId;
|
|
1123
|
+
exports.getContext = getContext;
|
|
1124
|
+
exports.getMethods = getMethods;
|
|
1125
|
+
exports.keepAliveConnectionAdapters = keepAliveConnectionAdapters;
|
|
1126
|
+
exports.keepAliveConnections = keepAliveConnections;
|
|
1127
|
+
exports.kvMethods = kvMethods;
|
|
1128
|
+
exports.logger = logger;
|
|
1129
|
+
exports.off = off;
|
|
1130
|
+
exports.on = on;
|
|
1131
|
+
exports.once = once;
|
|
1132
|
+
exports.proxy = proxy;
|
|
1133
|
+
exports.removeKeepAliveConnection = removeKeepAliveConnection;
|
|
1134
|
+
exports.rpc = rpc;
|
|
1135
|
+
exports.setGenTraceIdFunction = setGenTraceIdFunction;
|
|
1136
|
+
exports.setLoadBalancePolicy = setLoadBalancePolicy;
|
|
1137
|
+
exports.setMethods = setMethods;
|
|
1138
|
+
exports.sourceKVMethods = sourceKVMethods;
|
|
1139
|
+
|
|
1140
|
+
return exports;
|
|
1111
1141
|
|
|
1112
1142
|
})({});
|
|
1113
1143
|
//# sourceMappingURL=browser.js.map
|