omnirtc-web 1.7.1-beta.1 → 1.7.2

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/dist/Testin.js ADDED
@@ -0,0 +1,1815 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Testin = {}));
5
+ }(this, (function (exports) { 'use strict';
6
+
7
+ /*! *****************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+
22
+ function __awaiter(thisArg, _arguments, P, generator) {
23
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
+ return new (P || (P = Promise))(function (resolve, reject) {
25
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
29
+ });
30
+ }
31
+
32
+ class ArrayList extends Array {
33
+ constructor(...args) {
34
+ super(...args);
35
+ }
36
+ add(item) {
37
+ this.push(item);
38
+ return true;
39
+ }
40
+ remove(item) {
41
+ const index = this.indexOf(item);
42
+ if (index > -1) {
43
+ this.splice(index, 1);
44
+ return true;
45
+ }
46
+ else {
47
+ return false;
48
+ }
49
+ }
50
+ has(item) {
51
+ return this.indexOf(item) > -1;
52
+ }
53
+ insert(item, index) {
54
+ if (index < 0 || index > this.length) {
55
+ throw new Error('Index out of bounds');
56
+ }
57
+ this.splice(index, 0, item);
58
+ }
59
+ getIndexOf(item) {
60
+ return this.indexOf(item);
61
+ }
62
+ getLastIndexOf(item) {
63
+ return this.lastIndexOf(item);
64
+ }
65
+ removeByIndex(index) {
66
+ if (index < 0 || index >= this.length) {
67
+ throw new Error('Index out of bounds');
68
+ }
69
+ const item = this[index];
70
+ this.splice(index, 1);
71
+ return item;
72
+ }
73
+ removeByRange(start, end) {
74
+ if (start < 0 || end >= this.length || start > end) {
75
+ throw new Error('Index out of bounds');
76
+ }
77
+ const items = this.slice(start, end + 1);
78
+ this.splice(start, end - start + 1);
79
+ return items;
80
+ }
81
+ replaceAllElements() {
82
+ throw new Error('Method not implemented.');
83
+ }
84
+ subArrayList(start, end) {
85
+ if (start < 0 || end >= this.length || start > end) {
86
+ throw new Error('Index out of bounds');
87
+ }
88
+ return new ArrayList(...this.slice(start, end + 1));
89
+ }
90
+ clone() {
91
+ return new ArrayList(...this);
92
+ }
93
+ clear() {
94
+ this.length = 0;
95
+ }
96
+ }
97
+
98
+ const isString = (param) => {
99
+ return typeof param === 'string';
100
+ };
101
+ const isNumber = (param) => {
102
+ return typeof param === 'number';
103
+ };
104
+ const isBoolean = (param) => {
105
+ return typeof param === 'boolean';
106
+ };
107
+ const isNull = (param) => {
108
+ return param === null;
109
+ };
110
+ const checkString = (param) => {
111
+ if (!isString(param)) {
112
+ throw new TypeError('param is not string');
113
+ }
114
+ };
115
+ const checkNumber = (param) => {
116
+ if (!isNumber(param)) {
117
+ throw new TypeError('param is not number');
118
+ }
119
+ };
120
+ const checkBoolean = (param) => {
121
+ if (!isBoolean(param)) {
122
+ throw new TypeError('param is not boolean');
123
+ }
124
+ };
125
+ const checkNull = (param) => {
126
+ if (!isNull(param)) {
127
+ throw new TypeError('param is not null');
128
+ }
129
+ };
130
+ const checkArray = (param) => {
131
+ if (!Array.isArray(param)) {
132
+ throw new TypeError('param is not array');
133
+ }
134
+ };
135
+ const checkObject = (param) => {
136
+ if (typeof param !== 'object') {
137
+ throw new TypeError('param is not object');
138
+ }
139
+ };
140
+ const generateRandomUUID = () => {
141
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
142
+ const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
143
+ return v.toString(16);
144
+ });
145
+ };
146
+ const generateHashCode = () => {
147
+ const hashCode = Math.floor(Math.random() * 1000000000);
148
+ return hashCode.toString(16);
149
+ };
150
+ const HashMap = new Map();
151
+ const getHash = (obj) => {
152
+ if (obj === null || obj === undefined) {
153
+ return '';
154
+ }
155
+ if (typeof obj === 'string') {
156
+ return obj;
157
+ }
158
+ if (typeof obj === 'object') {
159
+ if (HashMap.has(obj)) {
160
+ return HashMap.get(obj);
161
+ }
162
+ else {
163
+ const hash = generateHashCode();
164
+ HashMap.set(obj, hash);
165
+ return hash;
166
+ }
167
+ }
168
+ return String(obj);
169
+ };
170
+
171
+ const spliter = "@#@";
172
+ const internalIdMatcher = new RegExp('^[0-9a-f]+' + spliter);
173
+ const MAX_CACHE_SIZE = 65536;
174
+ const internalIdObjectMap = new Map();
175
+ const idCodeInternalIdMap = new Map();
176
+ const internalIdNameSpaceMap = new Map();
177
+ const nameSpaceInternalIdMap = new Map();
178
+ function getNewId(className) {
179
+ const id = generateRandomUUID().replace(/\-/g, '');
180
+ return `${id}${spliter}${className}`;
181
+ }
182
+ function saveInNameSpaceCache(nameSpace, internalId) {
183
+ if (!internalIdNameSpaceMap.has(internalId)) {
184
+ const list = new ArrayList();
185
+ internalIdNameSpaceMap.set(internalId, list);
186
+ }
187
+ const nameSpaceCacheList = internalIdNameSpaceMap.get(internalId);
188
+ if (!nameSpaceCacheList.has(nameSpace)) {
189
+ nameSpaceCacheList.add(nameSpace);
190
+ }
191
+ if (!nameSpaceInternalIdMap.has(nameSpace)) {
192
+ nameSpaceInternalIdMap.set(nameSpace, new ArrayList());
193
+ }
194
+ const internalIdList = nameSpaceInternalIdMap.get(nameSpace);
195
+ if (!internalIdList.has(internalId)) {
196
+ internalIdList.add(internalId);
197
+ }
198
+ }
199
+ function removeAllCaches() {
200
+ internalIdObjectMap.clear();
201
+ idCodeInternalIdMap.clear();
202
+ internalIdNameSpaceMap.clear();
203
+ nameSpaceInternalIdMap.clear();
204
+ }
205
+ function saveObjectInCache(object, className, nameSpace) {
206
+ const idCode = getHash(object);
207
+ let internalId = idCodeInternalIdMap.get(idCode);
208
+ if (internalId) {
209
+ saveInNameSpaceCache(nameSpace, internalId);
210
+ return internalId;
211
+ }
212
+ if (internalIdObjectMap.size >= MAX_CACHE_SIZE) {
213
+ console.log('Reach limit');
214
+ }
215
+ console.log('saveObjectInCache: ', idCode, internalId);
216
+ internalId = getNewId(className);
217
+ internalIdObjectMap.set(internalId, object);
218
+ idCodeInternalIdMap.set(idCode, internalId);
219
+ saveInNameSpaceCache(nameSpace, internalId);
220
+ return internalId;
221
+ }
222
+ function getInternalObject(internalId, nameSpace) {
223
+ const object = internalIdObjectMap.get(internalId);
224
+ const internalIdList = nameSpaceInternalIdMap.get(nameSpace);
225
+ if (object && (internalIdList === null || internalIdList === void 0 ? void 0 : internalIdList.has(internalId))) {
226
+ return object;
227
+ }
228
+ return null;
229
+ }
230
+ function deleteCacheWithId(internalId, nameSpace) {
231
+ const internalIdList = nameSpaceInternalIdMap.get(nameSpace);
232
+ if (internalIdList) {
233
+ internalIdList.remove(internalId);
234
+ }
235
+ const nameSpaceList = internalIdNameSpaceMap.get(internalId);
236
+ if (nameSpaceList === null || nameSpaceList === void 0 ? void 0 : nameSpaceList.has(nameSpace)) {
237
+ nameSpaceList.remove(nameSpace);
238
+ if (nameSpaceList.length === 0) {
239
+ deleteObjectInCache(internalId);
240
+ internalIdNameSpaceMap.delete(internalId);
241
+ }
242
+ }
243
+ }
244
+ function deleteObjectInCache(internalId) {
245
+ const object = internalIdObjectMap.get(internalId);
246
+ if (object) {
247
+ const idCode = getHash(object);
248
+ internalIdObjectMap.delete(internalId);
249
+ console.log('id->对象删除了:', internalId);
250
+ idCodeInternalIdMap.delete(idCode);
251
+ console.log('对象->id删除了:', idCode);
252
+ }
253
+ }
254
+ function getObjectIdList(nameSpace) {
255
+ var _a;
256
+ return ((_a = nameSpaceInternalIdMap.get(nameSpace)) === null || _a === void 0 ? void 0 : _a.clone()) || new ArrayList();
257
+ }
258
+ function getSpliter() {
259
+ return spliter;
260
+ }
261
+ /**
262
+ * return true if param is internalId
263
+ * @param param
264
+ * @returns
265
+ */
266
+ function isObjectId(param) {
267
+ if (!isString(param)) {
268
+ return false;
269
+ }
270
+ if (internalIdMatcher.test(param)) {
271
+ return true;
272
+ }
273
+ return false;
274
+ }
275
+
276
+ const setClassLoader = (loader) => {
277
+ loadClass = loader;
278
+ };
279
+ let loadClass = (path) => {
280
+ return import(path);
281
+ };
282
+ const getClassInfo = (className) => {
283
+ console.log('className: ', className);
284
+ // 类似 ./RTCListeners/RTCChannelListener 按最后一个/ 分割
285
+ // 取出最后一个/ 前面的部分作为path
286
+ // 取出最后一个/ 后面的部分作为clazz
287
+ // 例如 ./RTCListeners/RTCChannelListener
288
+ const [path, clazz] = className.split('?');
289
+ if (path && clazz) {
290
+ return {
291
+ path,
292
+ clazz
293
+ };
294
+ }
295
+ else {
296
+ throw new Error('MethodNotFound');
297
+ }
298
+ };
299
+ const formatParams = (paramList, nameSpace) => {
300
+ const params = [];
301
+ for (let i = 0; i < paramList.length; i++) {
302
+ if (paramList[i].length !== 2) {
303
+ throw new Error('params is wrong');
304
+ }
305
+ const key = paramList[i][0], value = paramList[i][1];
306
+ switch (key) {
307
+ case 'string':
308
+ checkString(value);
309
+ break;
310
+ case 'number':
311
+ checkNumber(value);
312
+ break;
313
+ case 'null':
314
+ checkNull(value);
315
+ break;
316
+ case 'boolean':
317
+ checkBoolean(value);
318
+ break;
319
+ case 'object':
320
+ checkObject(value);
321
+ break;
322
+ case 'array':
323
+ checkArray(value);
324
+ break;
325
+ case 'undefined':
326
+ params.push(undefined);
327
+ continue;
328
+ default:
329
+ if (!getClassInfo(key)) {
330
+ throw new Error('Unrecognized type: ' + key);
331
+ }
332
+ checkString(value);
333
+ if (isObjectId(value)) {
334
+ const data = getInternalObject(value, nameSpace);
335
+ params.push(data);
336
+ continue;
337
+ }
338
+ else {
339
+ const data = getStaticField(key, value);
340
+ params.push(data);
341
+ continue;
342
+ }
343
+ }
344
+ params.push(value);
345
+ }
346
+ return params;
347
+ };
348
+ const createObjectWithClassLoader = (className, params) => {
349
+ const classInfo = getClassInfo(className);
350
+ return loadClass(classInfo.path).then((module) => {
351
+ if (module[classInfo.clazz]) {
352
+ return new module[classInfo.clazz](...params);
353
+ }
354
+ else {
355
+ return Promise.reject('there is no class: ' + classInfo.clazz);
356
+ }
357
+ }).catch((err) => {
358
+ console.log('createObjectWithClassLoader err: ', err);
359
+ return Promise.reject('createObjectWithClassLoader err: ' + err);
360
+ });
361
+ };
362
+ const callMethod = (path, methodName, params) => {
363
+ return loadClass(path).then((module) => {
364
+ if (module[methodName] && typeof module[methodName] === 'function') {
365
+ return module[methodName](...params);
366
+ }
367
+ else {
368
+ return Promise.reject('there is no method: ' + methodName);
369
+ }
370
+ }).catch((err) => {
371
+ console.log('callMethod err: ', err);
372
+ return Promise.reject('callMethod err: ' + err);
373
+ });
374
+ };
375
+ const callObjectMethod = (obj, methodName, params) => {
376
+ if (obj[methodName] && typeof obj[methodName] === 'function') {
377
+ return obj[methodName](...params);
378
+ }
379
+ else {
380
+ return Promise.reject();
381
+ }
382
+ };
383
+ const callStaticMethod = (className, methodName, params) => {
384
+ const classInfo = getClassInfo(className);
385
+ return loadClass(classInfo.path).then((module) => {
386
+ if (module[classInfo.clazz] && module[classInfo.clazz][methodName]) {
387
+ return module[classInfo.clazz][methodName](...params);
388
+ }
389
+ else {
390
+ return Promise.reject('there is no class: ' + classInfo.clazz);
391
+ }
392
+ }).catch((err) => {
393
+ console.log('callStaticMethod err: ', err);
394
+ return Promise.reject('callStaticMethod err: ' + err);
395
+ });
396
+ };
397
+ const getObjectField = (obj, fieldName) => {
398
+ if (!fieldName) {
399
+ return undefined;
400
+ }
401
+ const index = fieldName.indexOf('.');
402
+ if (index > -1) {
403
+ const field = fieldName.substring(0, index);
404
+ const nextField = fieldName.substring(index + 1);
405
+ return getObjectField(obj[field], nextField);
406
+ }
407
+ else {
408
+ return obj[fieldName];
409
+ }
410
+ };
411
+ const getStaticField = (className, fieldName) => {
412
+ const classInfo = getClassInfo(className);
413
+ return loadClass(classInfo.path).then((module) => {
414
+ if (module[classInfo.clazz]) {
415
+ return getObjectField(module[classInfo.clazz], fieldName);
416
+ }
417
+ else {
418
+ throw new Error('there is no class: ' + classInfo.clazz);
419
+ }
420
+ }).catch((err) => {
421
+ console.log('getStaticField err: ', err);
422
+ return Promise.reject('getStaticField err: ' + err);
423
+ });
424
+ };
425
+ const setObjectField = (obj, fieldName, value) => {
426
+ if (!fieldName) {
427
+ return;
428
+ }
429
+ const index = fieldName.indexOf('.');
430
+ if (index > -1) {
431
+ const field = fieldName.substring(0, index);
432
+ const nextField = fieldName.substring(index + 1);
433
+ setObjectField(obj[field], nextField, value);
434
+ }
435
+ else {
436
+ obj[fieldName] = value;
437
+ }
438
+ };
439
+ const setStaticField = (className, fieldName, value) => {
440
+ const classInfo = getClassInfo(className);
441
+ return loadClass(classInfo.path).then((module) => {
442
+ if (module[classInfo.clazz]) {
443
+ setObjectField(module[classInfo.clazz], fieldName, value);
444
+ }
445
+ else {
446
+ throw new Error('there is no class: ' + classInfo.clazz);
447
+ }
448
+ }).catch((err) => {
449
+ console.log('setStaticField err: ', err);
450
+ return Promise.reject('setStaticField err: ' + err);
451
+ });
452
+ };
453
+
454
+ class Actions {
455
+ saveObject(obj, unknown, toString) {
456
+ if (typeof obj === 'undefined') {
457
+ // object is undefined, return null
458
+ return null;
459
+ }
460
+ try {
461
+ if (typeof obj === 'object' || unknown || toString) {
462
+ if (toString) {
463
+ obj = JSON.stringify(obj);
464
+ }
465
+ else {
466
+ obj = saveObjectInCache(obj, obj.constructor.name, Actions.nameSpace);
467
+ }
468
+ }
469
+ }
470
+ catch (e) {
471
+ console.error('saveObject error: ', e);
472
+ throw new Error('saveObject error: ' + String(e));
473
+ }
474
+ return obj;
475
+ }
476
+ getObject(objectId) {
477
+ return getInternalObject(objectId, Actions.nameSpace);
478
+ }
479
+ get_special_object() {
480
+ throw new Error("Method not implemented.");
481
+ }
482
+ get_virtual_spliter() {
483
+ return getSpliter();
484
+ }
485
+ create_object(className, params) {
486
+ const paramsList = formatParams(params, Actions.nameSpace);
487
+ return createObjectWithClassLoader(className, paramsList).then((obj) => {
488
+ return this.saveObject(obj, true, false);
489
+ });
490
+ }
491
+ delete_object(id) {
492
+ deleteCacheWithId(id, Actions.nameSpace);
493
+ }
494
+ get_object_list() {
495
+ return Array.from(getObjectIdList(Actions.nameSpace));
496
+ }
497
+ query_listener() {
498
+ throw new Error("Method not implemented.");
499
+ }
500
+ query_listener_last() {
501
+ throw new Error("Method not implemented.");
502
+ }
503
+ call_method(path, functionName, params) {
504
+ return __awaiter(this, void 0, void 0, function* () {
505
+ if (!path || !functionName) {
506
+ return Promise.reject('path or functionName is empty.');
507
+ }
508
+ try {
509
+ const paramsList = formatParams(params, Actions.nameSpace);
510
+ const res = yield callMethod(path, functionName, paramsList);
511
+ return this.saveObject(res, false, false);
512
+ }
513
+ catch (e) {
514
+ return Promise.reject('call_method fail: ' + String(e));
515
+ }
516
+ });
517
+ }
518
+ call_static_method(className, methodName, params) {
519
+ return __awaiter(this, void 0, void 0, function* () {
520
+ try {
521
+ const paramsList = formatParams(params, Actions.nameSpace);
522
+ const res = yield callStaticMethod(className, methodName, paramsList);
523
+ return this.saveObject(res, false, false);
524
+ }
525
+ catch (e) {
526
+ return Promise.reject('call_static_method fail: ' + String(e));
527
+ }
528
+ });
529
+ }
530
+ call_object_method(objectId, methodName, params) {
531
+ return __awaiter(this, void 0, void 0, function* () {
532
+ const obj = this.getObject(objectId);
533
+ try {
534
+ const paramsList = formatParams(params, Actions.nameSpace);
535
+ const res = yield callObjectMethod(obj, methodName, paramsList);
536
+ return this.saveObject(res, false, false);
537
+ }
538
+ catch (e) {
539
+ return Promise.reject('call_object_method fail: ' + String(e));
540
+ }
541
+ });
542
+ }
543
+ get_object_method_params_type() {
544
+ throw new Error("Method not implemented.");
545
+ }
546
+ get_class_method_params_type() {
547
+ throw new Error("Method not implemented.");
548
+ }
549
+ get_object_field(objectId, fieldName) {
550
+ return __awaiter(this, void 0, void 0, function* () {
551
+ const obj = this.getObject(objectId);
552
+ if (!obj || !fieldName) {
553
+ return Promise.reject('target is null.');
554
+ }
555
+ try {
556
+ const res = yield getObjectField(obj, fieldName);
557
+ return this.saveObject(res, false, false);
558
+ }
559
+ catch (e) {
560
+ return Promise.reject('get_object_field fail: ' + String(e));
561
+ }
562
+ });
563
+ }
564
+ get_object_field_list() {
565
+ throw new Error("Method not implemented.");
566
+ }
567
+ get_static_field(className, fieldName) {
568
+ return __awaiter(this, void 0, void 0, function* () {
569
+ try {
570
+ const res = yield getStaticField(className, fieldName);
571
+ return this.saveObject(res, false, false);
572
+ }
573
+ catch (e) {
574
+ return Promise.reject('get_static_field fail: ' + String(e));
575
+ }
576
+ });
577
+ }
578
+ set_object_field(objectId, fieldName, value) {
579
+ return __awaiter(this, void 0, void 0, function* () {
580
+ const obj = this.getObject(objectId);
581
+ if (!obj || !fieldName) {
582
+ return Promise.reject('target is null.');
583
+ }
584
+ try {
585
+ const param = formatParams([value], Actions.nameSpace)[0];
586
+ setObjectField(obj, fieldName, param);
587
+ }
588
+ catch (e) {
589
+ return Promise.reject('set_object_field fail: ' + String(e));
590
+ }
591
+ });
592
+ }
593
+ set_static_field(className, fieldName, value) {
594
+ return __awaiter(this, void 0, void 0, function* () {
595
+ try {
596
+ const param = formatParams([value], Actions.nameSpace)[0];
597
+ setStaticField(className, fieldName, param);
598
+ }
599
+ catch (e) {
600
+ return Promise.reject('set_static_field fail: ' + String(e));
601
+ }
602
+ });
603
+ }
604
+ get_object_json_string() {
605
+ throw new Error("Method not implemented.");
606
+ }
607
+ get_class_object() {
608
+ throw new Error("Method not implemented.");
609
+ }
610
+ get_enum_object() {
611
+ throw new Error("Method not implemented.");
612
+ }
613
+ get_operation_last() {
614
+ throw new Error("Method not implemented.");
615
+ }
616
+ get_operation_by_name() {
617
+ throw new Error("Method not implemented.");
618
+ }
619
+ clear_operation_logs_by_name() {
620
+ throw new Error("Method not implemented.");
621
+ }
622
+ clear_all_operation_logs() {
623
+ throw new Error("Method not implemented.");
624
+ }
625
+ get_context_object() {
626
+ return this.saveObject(Actions.context, true, false);
627
+ }
628
+ get_activity_object_by_name() {
629
+ throw new Error("Method not implemented.");
630
+ }
631
+ get_activity_objects() {
632
+ throw new Error("Method not implemented.");
633
+ }
634
+ get_activity_object_list() {
635
+ throw new Error("Method not implemented.");
636
+ }
637
+ get_current_activity_object() {
638
+ throw new Error("Method not implemented.");
639
+ }
640
+ get_current_activity_name() {
641
+ throw new Error("Method not implemented.");
642
+ }
643
+ get_package_name() {
644
+ throw new Error("Method not implemented.");
645
+ }
646
+ get_application_object() {
647
+ throw new Error("Method not implemented.");
648
+ }
649
+ get_current_activity_views() {
650
+ throw new Error("Method not implemented.");
651
+ }
652
+ get_current_activity_decor_view() {
653
+ throw new Error("Method not implemented.");
654
+ }
655
+ get_top_package_activity_name() {
656
+ throw new Error("Method not implemented.");
657
+ }
658
+ set_operate_record() {
659
+ throw new Error("Method not implemented.");
660
+ }
661
+ find_view_by_id() {
662
+ throw new Error("Method not implemented.");
663
+ }
664
+ find_view_by_id_with_context() {
665
+ throw new Error("Method not implemented.");
666
+ }
667
+ find_view_by_id_to_group() {
668
+ throw new Error("Method not implemented.");
669
+ }
670
+ find_view_by_id_to_group_with_context() {
671
+ throw new Error("Method not implemented.");
672
+ }
673
+ get_class_declaration() {
674
+ throw new Error("Method not implemented.");
675
+ }
676
+ get_view_all_children() {
677
+ throw new Error("Method not implemented.");
678
+ }
679
+ }
680
+ Actions.nameSpace = 'Action';
681
+
682
+ // **Github:** https://github.com/teambition/jsonrpc-lite
683
+ const isInteger = Number.isSafeInteger;
684
+ class JsonRpc {
685
+ constructor() {
686
+ this.jsonrpc = '2.0';
687
+ }
688
+ serialize() {
689
+ return JSON.stringify(this);
690
+ }
691
+ }
692
+ JsonRpc.VERSION = '2.0';
693
+ class RequestObject extends JsonRpc {
694
+ constructor(id, method, params) {
695
+ super();
696
+ this.id = id;
697
+ this.method = method;
698
+ if (params !== undefined) {
699
+ this.params = params;
700
+ }
701
+ }
702
+ }
703
+ class NotificationObject extends JsonRpc {
704
+ constructor(method, params) {
705
+ super();
706
+ this.method = method;
707
+ if (params !== undefined) {
708
+ this.params = params;
709
+ }
710
+ }
711
+ }
712
+ class SuccessObject extends JsonRpc {
713
+ constructor(id, result) {
714
+ super();
715
+ this.id = id;
716
+ this.result = result;
717
+ }
718
+ }
719
+ class ErrorObject extends JsonRpc {
720
+ constructor(id, error) {
721
+ super();
722
+ this.id = id;
723
+ this.error = error;
724
+ }
725
+ }
726
+ class JsonRpcParsed {
727
+ constructor(payload, type) {
728
+ this.payload = payload;
729
+ this.type = type;
730
+ }
731
+ }
732
+ /**
733
+ * JsonRpcError Class
734
+ *
735
+ * @param {String} message
736
+ * @param {Integer} code
737
+ * @return {String} name: optional
738
+ * @api public
739
+ */
740
+ class JsonRpcError extends Error {
741
+ constructor(message, code, data) {
742
+ super();
743
+ this.message = message;
744
+ this.code = isInteger(code) ? code : 0;
745
+ if (data != null) {
746
+ this.data = data;
747
+ }
748
+ }
749
+ static invalidRequest(data) {
750
+ return new JsonRpcError('Invalid request', -32600, data);
751
+ }
752
+ static methodNotFound(data) {
753
+ return new JsonRpcError('Method not found', -32601, data);
754
+ }
755
+ static invalidParams(data) {
756
+ return new JsonRpcError('Invalid params', -32602, data);
757
+ }
758
+ static internalError(data) {
759
+ return new JsonRpcError('Internal error', -32603, data);
760
+ }
761
+ static parseError(data) {
762
+ return new JsonRpcError('Parse error', -32700, data);
763
+ }
764
+ toJSONString() {
765
+ return JSON.stringify(this);
766
+ }
767
+ }
768
+ /**
769
+ * Creates a JSON-RPC 2.0 request object
770
+ *
771
+ * @param {String|Integer} id
772
+ * @param {String} method
773
+ * @param {Object|Array} [params]: optional
774
+ * @return {Object} JsonRpc object
775
+ * @api public
776
+ */
777
+ function request(id, method, params) {
778
+ const object = new RequestObject(id, method, params);
779
+ validateMessage(object, true);
780
+ return object;
781
+ }
782
+ /**
783
+ * Creates a JSON-RPC 2.0 notification object
784
+ *
785
+ * @param {String} method
786
+ * @param {Object|Array} [params]: optional
787
+ * @return {Object} JsonRpc object
788
+ * @api public
789
+ */
790
+ function notification(method, params) {
791
+ const object = new NotificationObject(method, params);
792
+ validateMessage(object, true);
793
+ return object;
794
+ }
795
+ /**
796
+ * Creates a JSON-RPC 2.0 success response object
797
+ *
798
+ * @param {String|Integer} id
799
+ * @param {Mixed} result
800
+ * @return {Object} JsonRpc object
801
+ * @api public
802
+ */
803
+ function success(id, result) {
804
+ const object = new SuccessObject(id, result);
805
+ validateMessage(object, true);
806
+ return object;
807
+ }
808
+ /**
809
+ * Creates a JSON-RPC 2.0 error response object
810
+ *
811
+ * @param {String|Integer} id
812
+ * @param {Object} JsonRpcError error
813
+ * @return {Object} JsonRpc object
814
+ * @api public
815
+ */
816
+ function error(id, err) {
817
+ const object = new ErrorObject(id, err);
818
+ validateMessage(object, true);
819
+ return object;
820
+ }
821
+ function parse(message) {
822
+ if (!isString$1(message)) {
823
+ return new JsonRpcParsed(JsonRpcError.invalidRequest(message), "invalid" /* invalid */);
824
+ }
825
+ let jsonrpcObj;
826
+ try {
827
+ jsonrpcObj = JSON.parse(message);
828
+ }
829
+ catch (err) {
830
+ return new JsonRpcParsed(JsonRpcError.parseError(message), "invalid" /* invalid */);
831
+ }
832
+ return parseJsonRpcObject(jsonrpcObj);
833
+ }
834
+ /**
835
+ * Takes a JSON-RPC 2.0 payload (Object) or batch (Object[]) and tries to parse it.
836
+ * If successful, determine what objects are inside (response, notification,
837
+ * success, error, or invalid), and return their types and properly formatted objects.
838
+ *
839
+ * @param {Object|Array} jsonrpcObj
840
+ * @return {Object|Array} a single object or an array of `JsonRpcParsed` objects with `type` and `payload`:
841
+ *
842
+ * {
843
+ * type: <Enum, 'request'|'notification'|'success'|'error'|'invalid'>
844
+ * payload: <JsonRpc|JsonRpcError>
845
+ * }
846
+ *
847
+ * @api public
848
+ */
849
+ function parseJsonRpcObject(jsonrpcObj) {
850
+ if (!Array.isArray(jsonrpcObj)) {
851
+ return parseObject(jsonrpcObj);
852
+ }
853
+ if (jsonrpcObj.length === 0) {
854
+ return new JsonRpcParsed(JsonRpcError.invalidRequest(JSON.stringify(jsonrpcObj)), "invalid" /* invalid */);
855
+ }
856
+ const parsedObjectArray = [];
857
+ for (let i = 0, len = jsonrpcObj.length; i < len; i++) {
858
+ parsedObjectArray[i] = parseObject(jsonrpcObj[i]);
859
+ }
860
+ return parsedObjectArray;
861
+ }
862
+ /**
863
+ * Takes a JSON-RPC 2.0 payload (Object) and tries to parse it into a JSON.
864
+ * If successful, determine what object is it (response, notification,
865
+ * success, error, or invalid), and return it's type and properly formatted object.
866
+ *
867
+ * @param {Object} obj
868
+ * @return {Object} an `JsonRpcParsed` object with `type` and `payload`:
869
+ *
870
+ * {
871
+ * type: <Enum, 'request'|'notification'|'success'|'error'|'invalid'>
872
+ * payload: <JsonRpc|JsonRpcError>
873
+ * }
874
+ *
875
+ * @api public
876
+ */
877
+ function parseObject(obj) {
878
+ let err = null;
879
+ let payload = null;
880
+ let payloadType = "invalid" /* invalid */;
881
+ if (obj == null /* || obj.jsonrpc !== JsonRpc.VERSION*/) {
882
+ err = JsonRpcError.invalidRequest(obj);
883
+ payloadType = "invalid" /* invalid */;
884
+ }
885
+ else if (!obj['id']) {
886
+ const tmp = obj;
887
+ payload = new NotificationObject(tmp.method, tmp.params);
888
+ err = validateMessage(payload);
889
+ payloadType = "notification" /* notification */;
890
+ }
891
+ else if (obj['method']) {
892
+ const tmp = obj;
893
+ payload = new RequestObject(tmp.id, tmp.method, tmp.params);
894
+ err = validateMessage(payload);
895
+ payloadType = "request" /* request */;
896
+ }
897
+ else if (obj['result']) {
898
+ const tmp = obj;
899
+ payload = new SuccessObject(tmp.id, tmp.result);
900
+ err = validateMessage(payload);
901
+ payloadType = "success" /* success */;
902
+ }
903
+ else if (obj['error']) {
904
+ const tmp = obj;
905
+ payloadType = "error" /* error */;
906
+ if (tmp.error == null) {
907
+ err = JsonRpcError.internalError(JSON.stringify(tmp));
908
+ }
909
+ else {
910
+ const errorObj = new JsonRpcError(tmp.error.message, tmp.error.code, tmp.error.data);
911
+ if (errorObj.message !== tmp.error.message || errorObj.code !== tmp.error.code) {
912
+ err = JsonRpcError.internalError(JSON.stringify(tmp));
913
+ }
914
+ else {
915
+ payload = new ErrorObject(tmp.id, errorObj);
916
+ err = validateMessage(payload);
917
+ }
918
+ }
919
+ }
920
+ if (err == null && payload != null) {
921
+ return new JsonRpcParsed(payload, payloadType);
922
+ }
923
+ return new JsonRpcParsed(err != null ? err : JsonRpcError.invalidRequest(obj), "invalid" /* invalid */);
924
+ }
925
+ // if error, return error, else return null
926
+ function validateMessage(obj, throwIt) {
927
+ let err = null;
928
+ if (obj instanceof RequestObject) {
929
+ err = checkId(obj.id);
930
+ if (err == null) {
931
+ err = checkMethod(obj.method);
932
+ }
933
+ if (err == null) {
934
+ err = checkParams(obj.params);
935
+ }
936
+ }
937
+ else if (obj instanceof NotificationObject) {
938
+ err = checkMethod(obj.method);
939
+ if (err == null) {
940
+ err = checkParams(obj.params);
941
+ }
942
+ }
943
+ else if (obj instanceof SuccessObject) {
944
+ err = checkId(obj.id);
945
+ if (err == null) {
946
+ err = checkResult(obj.result);
947
+ }
948
+ }
949
+ else if (obj instanceof ErrorObject) {
950
+ err = checkId(obj.id, true);
951
+ if (err == null) {
952
+ err = checkError(obj.error);
953
+ }
954
+ }
955
+ if (throwIt && err != null) {
956
+ throw new Error(JSON.stringify(err));
957
+ }
958
+ return err;
959
+ }
960
+ function checkId(id, maybeNull) {
961
+ if (maybeNull && id === null) {
962
+ return null;
963
+ }
964
+ return isString$1(id) || isInteger(id)
965
+ ? null
966
+ : JsonRpcError.internalError('"id" must be provided, a string or an integer.');
967
+ }
968
+ function checkMethod(method) {
969
+ return isString$1(method) ? null : JsonRpcError.invalidRequest(String(method));
970
+ }
971
+ function checkResult(result) {
972
+ return result === undefined
973
+ ? JsonRpcError.internalError('Result must exist for success Response objects')
974
+ : null;
975
+ }
976
+ function checkParams(params) {
977
+ if (params === undefined) {
978
+ return null;
979
+ }
980
+ if (Array.isArray(params) || isObject(params)) {
981
+ // ensure params can be stringify
982
+ try {
983
+ JSON.stringify(params);
984
+ return null;
985
+ }
986
+ catch (err) {
987
+ return JsonRpcError.parseError(JSON.stringify(params));
988
+ }
989
+ }
990
+ return JsonRpcError.invalidParams(JSON.stringify(params));
991
+ }
992
+ function checkError(err) {
993
+ if (!(err instanceof JsonRpcError)) {
994
+ return JsonRpcError.internalError('Error must be an instance of JsonRpcError');
995
+ }
996
+ if (!isInteger(err.code)) {
997
+ return JsonRpcError.internalError('Invalid error code. It must be an integer.');
998
+ }
999
+ if (!isString$1(err.message)) {
1000
+ return JsonRpcError.internalError('Message must exist or must be a string.');
1001
+ }
1002
+ return null;
1003
+ }
1004
+ function isString$1(obj) {
1005
+ return obj !== '' && typeof obj === 'string';
1006
+ }
1007
+ function isObject(obj) {
1008
+ return obj != null && typeof obj === 'object' && !Array.isArray(obj);
1009
+ }
1010
+
1011
+ class Client {
1012
+ constructor() {
1013
+ this.requestId = 0;
1014
+ }
1015
+ request(method, data) {
1016
+ return request(this.requestId++, method, data);
1017
+ }
1018
+ notification(method, data) {
1019
+ return notification(method, data);
1020
+ }
1021
+ }
1022
+
1023
+ class Server {
1024
+ constructor(processor) {
1025
+ this.processor = processor;
1026
+ }
1027
+ onmessage(message) {
1028
+ return __awaiter(this, void 0, void 0, function* () {
1029
+ const data = parse(message);
1030
+ if (Array.isArray(data)) {
1031
+ const result = [];
1032
+ for (let i = 0; i < data.length; i++) {
1033
+ try {
1034
+ // @ts-ignore
1035
+ result.push(yield this.process(data[i]));
1036
+ }
1037
+ catch (e) {
1038
+ console.error('Unknown error: ', String(e), e.stack);
1039
+ }
1040
+ }
1041
+ return result.length === 0 ? '' : JSON.stringify(result);
1042
+ }
1043
+ else {
1044
+ let result;
1045
+ try {
1046
+ result = yield this.process(data);
1047
+ }
1048
+ catch (e) {
1049
+ console.error('Unknown error: ', String(e), e.stack);
1050
+ }
1051
+ return Promise.resolve(result ? JSON.stringify(result) : '');
1052
+ }
1053
+ });
1054
+ }
1055
+ process(data) {
1056
+ return __awaiter(this, void 0, void 0, function* () {
1057
+ switch (data.type) {
1058
+ case "request" /* request */:
1059
+ return this.handleRequest(data.payload);
1060
+ case "notification" /* notification */:
1061
+ this.handleNotification(data.payload);
1062
+ case "success" /* success */:
1063
+ // TODO
1064
+ break;
1065
+ case "error" /* error */:
1066
+ // TODO
1067
+ break;
1068
+ case "invalid" /* invalid */:
1069
+ return error(null, data.payload);
1070
+ default:
1071
+ console.warn('Unrecognized type: ', JSON.stringify(data));
1072
+ break;
1073
+ }
1074
+ return null;
1075
+ });
1076
+ }
1077
+ handleRequest(payload) {
1078
+ return __awaiter(this, void 0, void 0, function* () {
1079
+ const { id, method, params } = payload;
1080
+ if (typeof this.processor[method] !== 'function') {
1081
+ return error(id, JsonRpcError.methodNotFound(`${String(method)} not found`));
1082
+ }
1083
+ if (!params || !Array.isArray(params)) {
1084
+ return error(id, JsonRpcError.invalidParams(`${JSON.stringify(params)} mute be Array`));
1085
+ }
1086
+ try {
1087
+ const result = yield this.processor[method](...params);
1088
+ // if (method === 'call_object_method') {
1089
+ // if(params.length >=2 && params[1] === 'destroy'){
1090
+ // // 如果params0 作为字符串,包含RTCEngine
1091
+ // // 直接删除缓存
1092
+ // if(params[0].indexOf('RTCEngine') >= 0)
1093
+ // {
1094
+ // removeAllCaches();
1095
+ // } else {
1096
+ // deleteObjectInCache(params[0]);
1097
+ // }
1098
+ // }
1099
+ // }
1100
+ return success(id, result);
1101
+ }
1102
+ catch (e) {
1103
+ return error(id, JsonRpcError.internalError(e.stack || String(e)));
1104
+ }
1105
+ });
1106
+ }
1107
+ handleNotification(payload) {
1108
+ const { method, params } = payload;
1109
+ if (typeof this.processor[method] !== 'function') {
1110
+ throw new Error('MethodNotFound');
1111
+ }
1112
+ if (!params || !Array.isArray(params)) {
1113
+ throw new Error('params must be Array');
1114
+ }
1115
+ this.processor[method](...params);
1116
+ }
1117
+ }
1118
+
1119
+ function createCommonjsModule(fn, basedir, module) {
1120
+ return module = {
1121
+ path: basedir,
1122
+ exports: {},
1123
+ require: function (path, base) {
1124
+ return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
1125
+ }
1126
+ }, fn(module, module.exports), module.exports;
1127
+ }
1128
+
1129
+ function commonjsRequire () {
1130
+ throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
1131
+ }
1132
+
1133
+ var eventemitter3 = createCommonjsModule(function (module) {
1134
+
1135
+ var has = Object.prototype.hasOwnProperty,
1136
+ prefix = '~';
1137
+
1138
+ /**
1139
+ * Constructor to create a storage for our `EE` objects.
1140
+ * An `Events` instance is a plain object whose properties are event names.
1141
+ *
1142
+ * @constructor
1143
+ * @private
1144
+ */
1145
+ function Events() {}
1146
+
1147
+ //
1148
+ // We try to not inherit from `Object.prototype`. In some engines creating an
1149
+ // instance in this way is faster than calling `Object.create(null)` directly.
1150
+ // If `Object.create(null)` is not supported we prefix the event names with a
1151
+ // character to make sure that the built-in object properties are not
1152
+ // overridden or used as an attack vector.
1153
+ //
1154
+ if (Object.create) {
1155
+ Events.prototype = Object.create(null);
1156
+
1157
+ //
1158
+ // This hack is needed because the `__proto__` property is still inherited in
1159
+ // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
1160
+ //
1161
+ if (!new Events().__proto__) prefix = false;
1162
+ }
1163
+
1164
+ /**
1165
+ * Representation of a single event listener.
1166
+ *
1167
+ * @param {Function} fn The listener function.
1168
+ * @param {*} context The context to invoke the listener with.
1169
+ * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
1170
+ * @constructor
1171
+ * @private
1172
+ */
1173
+ function EE(fn, context, once) {
1174
+ this.fn = fn;
1175
+ this.context = context;
1176
+ this.once = once || false;
1177
+ }
1178
+
1179
+ /**
1180
+ * Add a listener for a given event.
1181
+ *
1182
+ * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
1183
+ * @param {(String|Symbol)} event The event name.
1184
+ * @param {Function} fn The listener function.
1185
+ * @param {*} context The context to invoke the listener with.
1186
+ * @param {Boolean} once Specify if the listener is a one-time listener.
1187
+ * @returns {EventEmitter}
1188
+ * @private
1189
+ */
1190
+ function addListener(emitter, event, fn, context, once) {
1191
+ if (typeof fn !== 'function') {
1192
+ throw new TypeError('The listener must be a function');
1193
+ }
1194
+ var listener = new EE(fn, context || emitter, once),
1195
+ evt = prefix ? prefix + event : event;
1196
+ if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);else emitter._events[evt] = [emitter._events[evt], listener];
1197
+ return emitter;
1198
+ }
1199
+
1200
+ /**
1201
+ * Clear event by name.
1202
+ *
1203
+ * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
1204
+ * @param {(String|Symbol)} evt The Event name.
1205
+ * @private
1206
+ */
1207
+ function clearEvent(emitter, evt) {
1208
+ if (--emitter._eventsCount === 0) emitter._events = new Events();else delete emitter._events[evt];
1209
+ }
1210
+
1211
+ /**
1212
+ * Minimal `EventEmitter` interface that is molded against the Node.js
1213
+ * `EventEmitter` interface.
1214
+ *
1215
+ * @constructor
1216
+ * @public
1217
+ */
1218
+ function EventEmitter() {
1219
+ this._events = new Events();
1220
+ this._eventsCount = 0;
1221
+ }
1222
+
1223
+ /**
1224
+ * Return an array listing the events for which the emitter has registered
1225
+ * listeners.
1226
+ *
1227
+ * @returns {Array}
1228
+ * @public
1229
+ */
1230
+ EventEmitter.prototype.eventNames = function eventNames() {
1231
+ var names = [],
1232
+ events,
1233
+ name;
1234
+ if (this._eventsCount === 0) return names;
1235
+ for (name in events = this._events) {
1236
+ if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
1237
+ }
1238
+ if (Object.getOwnPropertySymbols) {
1239
+ return names.concat(Object.getOwnPropertySymbols(events));
1240
+ }
1241
+ return names;
1242
+ };
1243
+
1244
+ /**
1245
+ * Return the listeners registered for a given event.
1246
+ *
1247
+ * @param {(String|Symbol)} event The event name.
1248
+ * @returns {Array} The registered listeners.
1249
+ * @public
1250
+ */
1251
+ EventEmitter.prototype.listeners = function listeners(event) {
1252
+ var evt = prefix ? prefix + event : event,
1253
+ handlers = this._events[evt];
1254
+ if (!handlers) return [];
1255
+ if (handlers.fn) return [handlers.fn];
1256
+ for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
1257
+ ee[i] = handlers[i].fn;
1258
+ }
1259
+ return ee;
1260
+ };
1261
+
1262
+ /**
1263
+ * Return the number of listeners listening to a given event.
1264
+ *
1265
+ * @param {(String|Symbol)} event The event name.
1266
+ * @returns {Number} The number of listeners.
1267
+ * @public
1268
+ */
1269
+ EventEmitter.prototype.listenerCount = function listenerCount(event) {
1270
+ var evt = prefix ? prefix + event : event,
1271
+ listeners = this._events[evt];
1272
+ if (!listeners) return 0;
1273
+ if (listeners.fn) return 1;
1274
+ return listeners.length;
1275
+ };
1276
+
1277
+ /**
1278
+ * Calls each of the listeners registered for a given event.
1279
+ *
1280
+ * @param {(String|Symbol)} event The event name.
1281
+ * @returns {Boolean} `true` if the event had listeners, else `false`.
1282
+ * @public
1283
+ */
1284
+ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
1285
+ var evt = prefix ? prefix + event : event;
1286
+ if (!this._events[evt]) return false;
1287
+ var listeners = this._events[evt],
1288
+ len = arguments.length,
1289
+ args,
1290
+ i;
1291
+ if (listeners.fn) {
1292
+ if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
1293
+ switch (len) {
1294
+ case 1:
1295
+ return listeners.fn.call(listeners.context), true;
1296
+ case 2:
1297
+ return listeners.fn.call(listeners.context, a1), true;
1298
+ case 3:
1299
+ return listeners.fn.call(listeners.context, a1, a2), true;
1300
+ case 4:
1301
+ return listeners.fn.call(listeners.context, a1, a2, a3), true;
1302
+ case 5:
1303
+ return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
1304
+ case 6:
1305
+ return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
1306
+ }
1307
+ for (i = 1, args = new Array(len - 1); i < len; i++) {
1308
+ args[i - 1] = arguments[i];
1309
+ }
1310
+ listeners.fn.apply(listeners.context, args);
1311
+ } else {
1312
+ var length = listeners.length,
1313
+ j;
1314
+ for (i = 0; i < length; i++) {
1315
+ if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
1316
+ switch (len) {
1317
+ case 1:
1318
+ listeners[i].fn.call(listeners[i].context);
1319
+ break;
1320
+ case 2:
1321
+ listeners[i].fn.call(listeners[i].context, a1);
1322
+ break;
1323
+ case 3:
1324
+ listeners[i].fn.call(listeners[i].context, a1, a2);
1325
+ break;
1326
+ case 4:
1327
+ listeners[i].fn.call(listeners[i].context, a1, a2, a3);
1328
+ break;
1329
+ default:
1330
+ if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
1331
+ args[j - 1] = arguments[j];
1332
+ }
1333
+ listeners[i].fn.apply(listeners[i].context, args);
1334
+ }
1335
+ }
1336
+ }
1337
+ return true;
1338
+ };
1339
+
1340
+ /**
1341
+ * Add a listener for a given event.
1342
+ *
1343
+ * @param {(String|Symbol)} event The event name.
1344
+ * @param {Function} fn The listener function.
1345
+ * @param {*} [context=this] The context to invoke the listener with.
1346
+ * @returns {EventEmitter} `this`.
1347
+ * @public
1348
+ */
1349
+ EventEmitter.prototype.on = function on(event, fn, context) {
1350
+ return addListener(this, event, fn, context, false);
1351
+ };
1352
+
1353
+ /**
1354
+ * Add a one-time listener for a given event.
1355
+ *
1356
+ * @param {(String|Symbol)} event The event name.
1357
+ * @param {Function} fn The listener function.
1358
+ * @param {*} [context=this] The context to invoke the listener with.
1359
+ * @returns {EventEmitter} `this`.
1360
+ * @public
1361
+ */
1362
+ EventEmitter.prototype.once = function once(event, fn, context) {
1363
+ return addListener(this, event, fn, context, true);
1364
+ };
1365
+
1366
+ /**
1367
+ * Remove the listeners of a given event.
1368
+ *
1369
+ * @param {(String|Symbol)} event The event name.
1370
+ * @param {Function} fn Only remove the listeners that match this function.
1371
+ * @param {*} context Only remove the listeners that have this context.
1372
+ * @param {Boolean} once Only remove one-time listeners.
1373
+ * @returns {EventEmitter} `this`.
1374
+ * @public
1375
+ */
1376
+ EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
1377
+ var evt = prefix ? prefix + event : event;
1378
+ if (!this._events[evt]) return this;
1379
+ if (!fn) {
1380
+ clearEvent(this, evt);
1381
+ return this;
1382
+ }
1383
+ var listeners = this._events[evt];
1384
+ if (listeners.fn) {
1385
+ if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
1386
+ clearEvent(this, evt);
1387
+ }
1388
+ } else {
1389
+ for (var i = 0, events = [], length = listeners.length; i < length; i++) {
1390
+ if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
1391
+ events.push(listeners[i]);
1392
+ }
1393
+ }
1394
+
1395
+ //
1396
+ // Reset the array, or remove it completely if we have no more listeners.
1397
+ //
1398
+ if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;else clearEvent(this, evt);
1399
+ }
1400
+ return this;
1401
+ };
1402
+
1403
+ /**
1404
+ * Remove all listeners, or those of the specified event.
1405
+ *
1406
+ * @param {(String|Symbol)} [event] The event name.
1407
+ * @returns {EventEmitter} `this`.
1408
+ * @public
1409
+ */
1410
+ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
1411
+ var evt;
1412
+ if (event) {
1413
+ evt = prefix ? prefix + event : event;
1414
+ if (this._events[evt]) clearEvent(this, evt);
1415
+ } else {
1416
+ this._events = new Events();
1417
+ this._eventsCount = 0;
1418
+ }
1419
+ return this;
1420
+ };
1421
+
1422
+ //
1423
+ // Alias methods names because people roll like that.
1424
+ //
1425
+ EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
1426
+ EventEmitter.prototype.addListener = EventEmitter.prototype.on;
1427
+
1428
+ //
1429
+ // Expose the prefix.
1430
+ //
1431
+ EventEmitter.prefixed = prefix;
1432
+
1433
+ //
1434
+ // Allow `EventEmitter` to be imported as module namespace.
1435
+ //
1436
+ EventEmitter.EventEmitter = EventEmitter;
1437
+
1438
+ //
1439
+ // Expose the module.
1440
+ //
1441
+ {
1442
+ module.exports = EventEmitter;
1443
+ }
1444
+ });
1445
+
1446
+ // import { Context } from "@kit.AbilityKit";
1447
+ class Config {
1448
+ // static context: Context;
1449
+ static syncNetInfo() {
1450
+ // const net = connection.getDefaultNetSync();
1451
+ // if (net.netId < 100) {
1452
+ // return;
1453
+ // }
1454
+ // const cap = connection.getNetCapabilitiesSync(net);
1455
+ // if (cap.bearerTypes.length) {
1456
+ // switch (cap.bearerTypes[0]) {
1457
+ // case connection.NetBearType.BEARER_CELLULAR:
1458
+ // Config._networkType = 'MOBILE';
1459
+ // break;
1460
+ // case connection.NetBearType.BEARER_WIFI:
1461
+ // Config._networkType = 'WIFI';
1462
+ // const wifiInfos = wifiManager.getScanInfoList();
1463
+ // if (wifiInfos.length) {
1464
+ // Config._mac = wifiInfos[0].bssid;
1465
+ // }
1466
+ // break;
1467
+ // case connection.NetBearType.BEARER_BLUETOOTH:
1468
+ // Config._networkType = 'BLUETOOTH';
1469
+ // break;
1470
+ // case connection.NetBearType.BEARER_ETHERNET:
1471
+ // Config._networkType = 'LAN';
1472
+ // break;
1473
+ // case connection.NetBearType.BEARER_VPN:
1474
+ // Config._networkType = 'VPN';
1475
+ // break;
1476
+ // default :
1477
+ // Config._networkType = 'UNKNOWN';
1478
+ // }
1479
+ // }
1480
+ // const address = connection.getConnectionPropertiesSync(net).linkAddresses;
1481
+ // if (address.length) {
1482
+ // Config._ip = address[0].address.address;
1483
+ // }
1484
+ }
1485
+ static set deviceId(value) {
1486
+ console.log('Set deviceId: ', value);
1487
+ Config._deviceId = value;
1488
+ sessionStorage.setItem('testin.deviceId', value);
1489
+ }
1490
+ static get deviceId() {
1491
+ if (Config._deviceId) {
1492
+ return Config._deviceId;
1493
+ }
1494
+ Config._deviceId = sessionStorage.getItem('testin.deviceId') || '';
1495
+ if (!Config._deviceId) {
1496
+ console.log('Create deviceId');
1497
+ const id = generateRandomUUID();
1498
+ sessionStorage.setItem('testin.deviceId', id);
1499
+ Config._deviceId = id;
1500
+ }
1501
+ return Config._deviceId;
1502
+ }
1503
+ static get networkType() {
1504
+ if (Config._networkType === 'UNKNOWN') {
1505
+ Config.syncNetInfo();
1506
+ }
1507
+ return Config._networkType;
1508
+ }
1509
+ static get ip() {
1510
+ if (!Config._ip) {
1511
+ Config.syncNetInfo();
1512
+ }
1513
+ return Config._ip;
1514
+ }
1515
+ static get mac() {
1516
+ return Config._mac;
1517
+ }
1518
+ static get appName() {
1519
+ // return Config.context.applicationInfo.name;
1520
+ return 'WebDemo';
1521
+ }
1522
+ static get bundleName() {
1523
+ // return Config.context.applicationInfo.name;
1524
+ return 'WebDemo';
1525
+ }
1526
+ static set case(value) {
1527
+ console.log('Set case: ', value);
1528
+ Config._case = value;
1529
+ }
1530
+ static get case() {
1531
+ return Config._case;
1532
+ }
1533
+ }
1534
+ Config._deviceId = '';
1535
+ Config._networkType = 'UNKNOWN';
1536
+ Config._ip = '0.0.0.0';
1537
+ Config._case = 'unknown';
1538
+ Config._mac = '';
1539
+ Config.taskId = 0;
1540
+ Config.appId = 0;
1541
+
1542
+ class HeartBeatRequest {
1543
+ constructor() {
1544
+ this.topic = 'ApiCall';
1545
+ this.content = {
1546
+ path: '/api/device/heartBeat',
1547
+ data: {
1548
+ port: 0,
1549
+ time: 0,
1550
+ appInfo: {
1551
+ mtlBuildTaskId: -1,
1552
+ appName: Config.appName,
1553
+ appId: Config.appId,
1554
+ packageName: Config.bundleName,
1555
+ taskId: Config.taskId,
1556
+ platform: 'Web',
1557
+ versionCode: '',
1558
+ },
1559
+ deviceInfo: {
1560
+ serial: 'unknow_serial',
1561
+ utdid: 'unknow_utdid',
1562
+ rotation: 0,
1563
+ ip: Config.ip,
1564
+ deviceModel: 'unknow_device_model',
1565
+ networkType: Config.networkType,
1566
+ systemVersion: 'unknow_system_version',
1567
+ brand: 'unknow_brand',
1568
+ resolution: '834*1112',
1569
+ deviceId: Config.deviceId,
1570
+ apiLevel: 'unknow_api_level',
1571
+ mac: Config.mac,
1572
+ },
1573
+ },
1574
+ ip: Config.ip,
1575
+ sign: '',
1576
+ time: 0,
1577
+ packageName: '',
1578
+ version: '',
1579
+ taskId: Config.taskId,
1580
+ };
1581
+ const timestamp = Date.now();
1582
+ this.msgId = String(timestamp);
1583
+ this.content.time = timestamp;
1584
+ this.content.data.time = timestamp;
1585
+ Object.assign(this.content.data.appInfo, Config.extendAppInfo);
1586
+ }
1587
+ }
1588
+
1589
+ class Transport extends eventemitter3.EventEmitter {
1590
+ constructor() {
1591
+ super(...arguments);
1592
+ this.listener = null;
1593
+ this.hbInterval = 0;
1594
+ }
1595
+ addMessageListener(messageListener) {
1596
+ this.listener = messageListener;
1597
+ }
1598
+ removeMessageListener() {
1599
+ this.listener = null;
1600
+ }
1601
+ dispatchMessage(message) {
1602
+ if (!this.listener) {
1603
+ return null;
1604
+ }
1605
+ return this.listener(message);
1606
+ }
1607
+ send(message) {
1608
+ throw new Error("Method not implemented.");
1609
+ }
1610
+ startHeartbeat(cycle) {
1611
+ // @ts-ignore
1612
+ this.hbInterval = setInterval(() => {
1613
+ this.send(JSON.stringify(new HeartBeatRequest()));
1614
+ }, cycle);
1615
+ }
1616
+ registerDevice() {
1617
+ this.send(JSON.stringify({
1618
+ topic: 'DeviceConfig',
1619
+ msgId: Date.now(),
1620
+ content: {
1621
+ config: {
1622
+ screencap: "test",
1623
+ test: "123",
1624
+ adbdPort: {
1625
+ MiBOX1S: 5555
1626
+ }
1627
+ }
1628
+ },
1629
+ }));
1630
+ }
1631
+ onOpen() {
1632
+ this.registerDevice();
1633
+ }
1634
+ onMessage(message) {
1635
+ if (typeof message !== 'string') {
1636
+ return;
1637
+ }
1638
+ console.debug('message: ', message);
1639
+ const data = JSON.parse(message);
1640
+ if (data.topic === 'RpcCall') {
1641
+ const result = this.dispatchMessage(data.content.requestData);
1642
+ const response = {
1643
+ content: '',
1644
+ msgId: data.msgId,
1645
+ topic: data.topic,
1646
+ };
1647
+ if (result instanceof Promise) {
1648
+ result.then((value) => {
1649
+ response.content = value || '';
1650
+ console.log('response: ', JSON.stringify(response));
1651
+ this.send(JSON.stringify(response));
1652
+ });
1653
+ }
1654
+ else {
1655
+ response.content = result || '';
1656
+ console.log('response: ', JSON.stringify(response));
1657
+ this.send(JSON.stringify(response));
1658
+ }
1659
+ }
1660
+ else if (data.topic === 'ApiCall') ;
1661
+ }
1662
+ onClose(e) {
1663
+ // clearInterval(this.hbInterval);
1664
+ }
1665
+ onError(e) {
1666
+ console.error('onError: ', e);
1667
+ }
1668
+ }
1669
+
1670
+ class WebSocketTransport extends Transport {
1671
+ constructor(url) {
1672
+ super();
1673
+ this.reconnecting = false;
1674
+ this.ws = new WebSocket(url);
1675
+ this.bindListener();
1676
+ }
1677
+ bindListener() {
1678
+ this.ws.onopen = (e) => {
1679
+ console.log('WebSocketTransport: ', 'open');
1680
+ this.onOpen();
1681
+ };
1682
+ this.ws.onmessage = (e) => {
1683
+ this.onMessage(e.data);
1684
+ };
1685
+ this.ws.onclose = (e) => {
1686
+ console.log('WebSocketTransport: ', 'close');
1687
+ this.onClose(e);
1688
+ };
1689
+ this.ws.onerror = (e) => {
1690
+ console.error('WebSocketTransport: ', 'error', JSON.stringify(e.target));
1691
+ this.onError(e.target);
1692
+ };
1693
+ setTimeout(() => {
1694
+ if (this.ws.readyState !== WebSocket.OPEN) {
1695
+ this.reconnecting = false;
1696
+ this.reconnect('First connection failed, trying to reconnect...');
1697
+ }
1698
+ }, 3 * 1000);
1699
+ }
1700
+ onOpen() {
1701
+ this.reconnecting = false;
1702
+ super.onOpen();
1703
+ this.emit('connected');
1704
+ }
1705
+ onClose(e) {
1706
+ super.onClose(e);
1707
+ this.reconnect();
1708
+ }
1709
+ onError(e) {
1710
+ super.onError(e);
1711
+ }
1712
+ reconnect(reason = '') {
1713
+ console.log('WebSocketTransport: ', 'reconnect', reason);
1714
+ if (this.reconnecting) {
1715
+ return;
1716
+ }
1717
+ this.reconnecting = true;
1718
+ this.emit('reconnecting');
1719
+ this.ws = new WebSocket(this.ws.url);
1720
+ this.bindListener();
1721
+ }
1722
+ send(message) {
1723
+ try {
1724
+ this.ws.send(message);
1725
+ console.debug('WebSocketTransport: ', 'send', message);
1726
+ }
1727
+ catch (e) {
1728
+ console.error('WebSocketTransport: ', JSON.stringify(e));
1729
+ }
1730
+ }
1731
+ }
1732
+
1733
+ class Testin extends eventemitter3 {
1734
+ constructor(classLoader) {
1735
+ super();
1736
+ if (classLoader) {
1737
+ setClassLoader(classLoader);
1738
+ }
1739
+ this.actions = new Actions();
1740
+ this.rpcServer = new Server(this.actions);
1741
+ this.rpcClient = new Client();
1742
+ }
1743
+ init(context, appId, taskId, useHeartbeat, isObfuscate, httpUrl, wsUrl, secret, logTag = 'Testin', mtBuildId, deviceId) {
1744
+ Actions.context = context;
1745
+ Config.taskId = taskId;
1746
+ Config.appId = appId;
1747
+ this.transport = new WebSocketTransport(`${wsUrl}/${Config.deviceId}/${Config.bundleName}`);
1748
+ this.transport.addMessageListener((msg) => {
1749
+ return this.rpcServer.onmessage(msg);
1750
+ });
1751
+ this.transport.on('reconnecting', () => {
1752
+ this.emit('transport.reconnecting');
1753
+ });
1754
+ this.transport.on('connected', () => {
1755
+ this.emit('transport.connected');
1756
+ });
1757
+ if (useHeartbeat) {
1758
+ this.transport.startHeartbeat(2000);
1759
+ }
1760
+ if (deviceId) {
1761
+ Config.deviceId = deviceId;
1762
+ }
1763
+ }
1764
+ /**
1765
+ * JSON RPC message
1766
+ * @param method
1767
+ * @param data
1768
+ */
1769
+ request(method, data) {
1770
+ const content = this.rpcClient.request(method, data);
1771
+ this.send(content.serialize());
1772
+ }
1773
+ /**
1774
+ * JSON RPC message
1775
+ * @param method
1776
+ * @param data
1777
+ */
1778
+ notification(method, data) {
1779
+ const content = this.rpcClient.notification(method, data);
1780
+ this.send(content.serialize());
1781
+ }
1782
+ send(message) {
1783
+ if (!this.transport) {
1784
+ throw new Error('init Testin first');
1785
+ }
1786
+ this.transport.send(message);
1787
+ }
1788
+ saveObject(obj) {
1789
+ if (!obj || typeof obj !== 'object') {
1790
+ return obj;
1791
+ }
1792
+ // 保存对象到缓存中
1793
+ return saveObjectInCache(obj, obj.constructor.name, Actions.nameSpace);
1794
+ }
1795
+ getEngine() {
1796
+ // 从ObjectCacheUtil中获取RTCEngine对象
1797
+ // @talrtc/rtcengine/default
1798
+ var targetObject = null;
1799
+ getObjectIdList('Action').forEach((id) => {
1800
+ if (id.indexOf("RTCEngine") >= 0) {
1801
+ targetObject = getInternalObject(id, 'Action');
1802
+ }
1803
+ });
1804
+ return targetObject;
1805
+ }
1806
+ clearAllObjectCaches() {
1807
+ removeAllCaches();
1808
+ }
1809
+ }
1810
+
1811
+ exports.Testin = Testin;
1812
+
1813
+ Object.defineProperty(exports, '__esModule', { value: true });
1814
+
1815
+ })));