@polyvharmony/live-scenes-foundation 1.2.0-rc.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/Index.d.ets +30 -0
  3. package/Index.js +28 -0
  4. package/LICENSE +8 -0
  5. package/README.md +21 -0
  6. package/ResourceTable.txt +16 -0
  7. package/libs/plvjsbridge.har +0 -0
  8. package/libs/plvsocket.har +0 -0
  9. package/obfuscation.txt +4 -0
  10. package/oh-package.json5 +1 -0
  11. package/package.json +1 -0
  12. package/src/main/ets/common/IPLVBackwardInterface.d.ets +5 -0
  13. package/src/main/ets/common/IPLVBackwardInterface.js +1 -0
  14. package/src/main/ets/common/PLVBasicDataSource.d.ets +30 -0
  15. package/src/main/ets/common/PLVBasicDataSource.js +172 -0
  16. package/src/main/ets/common/PLVCallback.d.ets +52 -0
  17. package/src/main/ets/common/PLVCallback.js +128 -0
  18. package/src/main/ets/common/PLVCommonConstants.d.ets +13 -0
  19. package/src/main/ets/common/PLVCommonConstants.js +10 -0
  20. package/src/main/ets/common/PLVCommonEnums.d.ets +19 -0
  21. package/src/main/ets/common/PLVCommonEnums.js +22 -0
  22. package/src/main/ets/common/PLVDeviceUtils.d.ets +4 -0
  23. package/src/main/ets/common/PLVDeviceUtils.js +9 -0
  24. package/src/main/ets/common/PLVHashMap.d.ets +4 -0
  25. package/src/main/ets/common/PLVHashMap.js +7 -0
  26. package/src/main/ets/common/PLVJSONUtils.d.ets +21 -0
  27. package/src/main/ets/common/PLVJSONUtils.js +103 -0
  28. package/src/main/ets/common/PLVNetUtils.d.ets +5 -0
  29. package/src/main/ets/common/PLVNetUtils.js +29 -0
  30. package/src/main/ets/common/PLVPreferencesUtils.d.ets +58 -0
  31. package/src/main/ets/common/PLVPreferencesUtils.js +30 -0
  32. package/src/main/ets/common/PLVScheduledTask.d.ets +12 -0
  33. package/src/main/ets/common/PLVScheduledTask.js +44 -0
  34. package/src/main/ets/common/PLVSimpleBuffer.d.ets +11 -0
  35. package/src/main/ets/common/PLVSimpleBuffer.js +30 -0
  36. package/src/main/ets/common/PLVTextUtils.d.ets +9 -0
  37. package/src/main/ets/common/PLVTextUtils.js +73 -0
  38. package/src/main/ets/common/PLVTimeUtils.d.ets +8 -0
  39. package/src/main/ets/common/PLVTimeUtils.js +14 -0
  40. package/src/main/ets/common/PLVToastUtils.d.ets +7 -0
  41. package/src/main/ets/common/PLVToastUtils.js +17 -0
  42. package/src/main/ets/common/PLVType.d.ets +8 -0
  43. package/src/main/ets/common/PLVType.js +1 -0
  44. package/src/main/ets/common/PLVUACreator.d.ets +3 -0
  45. package/src/main/ets/common/PLVUACreator.js +11 -0
  46. package/src/main/ets/common/PLVUtils.d.ets +25 -0
  47. package/src/main/ets/common/PLVUtils.js +197 -0
  48. package/src/main/ets/common/PLVWebUtils.d.ets +6 -0
  49. package/src/main/ets/common/PLVWebUtils.js +79 -0
  50. package/src/main/ets/modules/log/PLVLogger.d.ets +20 -0
  51. package/src/main/ets/modules/log/PLVLogger.js +67 -0
  52. package/src/main/ets/modules/log/PLVXLogFilePrinter.d.ets +12 -0
  53. package/src/main/ets/modules/log/PLVXLogFilePrinter.js +37 -0
  54. package/src/main/ets/modules/log/PLVXLogWorker.d.ets +1 -0
  55. package/src/main/ets/modules/log/PLVXLogWorker.js +4 -0
  56. package/src/main/ets/modules/net/PLVApiConstants.d.ets +7 -0
  57. package/src/main/ets/modules/net/PLVApiConstants.js +7 -0
  58. package/src/main/ets/modules/net/PLVHttpData.d.ets +8 -0
  59. package/src/main/ets/modules/net/PLVHttpData.js +8 -0
  60. package/src/main/ets/modules/net/PLVHttpError.d.ets +5 -0
  61. package/src/main/ets/modules/net/PLVHttpError.js +13 -0
  62. package/src/main/ets/modules/net/PLVHttpRequest.d.ets +25 -0
  63. package/src/main/ets/modules/net/PLVHttpRequest.js +147 -0
  64. package/src/main/ets/modules/net/PLVRequestSetting.d.ets +9 -0
  65. package/src/main/ets/modules/net/PLVRequestSetting.js +33 -0
  66. package/src/main/ets/modules/socket/PLVSocketIO.d.ets +50 -0
  67. package/src/main/ets/modules/socket/PLVSocketIO.js +164 -0
  68. package/src/main/ets/modules/web/PLVFailureLayout.d.ets +5 -0
  69. package/src/main/ets/modules/web/PLVFailureLayout.js +77 -0
  70. package/src/main/ets/modules/web/PLVLoadingLayout.d.ets +4 -0
  71. package/src/main/ets/modules/web/PLVLoadingLayout.js +46 -0
  72. package/src/main/ets/modules/web/PLVNewWindowLayout.d.ets +8 -0
  73. package/src/main/ets/modules/web/PLVNewWindowLayout.js +62 -0
  74. package/src/main/ets/modules/web/PLVSimpleWeb.d.ets +14 -0
  75. package/src/main/ets/modules/web/PLVSimpleWeb.js +260 -0
  76. package/src/main/ets/modules/web/PLVWebController.d.ets +86 -0
  77. package/src/main/ets/modules/web/PLVWebController.js +275 -0
  78. package/src/main/ets/modules/web/PLVWebModel.d.ets +30 -0
  79. package/src/main/ets/modules/web/PLVWebModel.js +1 -0
  80. package/src/main/module.json +28 -0
  81. package/src/main/resources/base/element/color.json +12 -0
  82. package/src/main/resources/base/element/float.json +40 -0
  83. package/src/main/resources/base/element/string.json +12 -0
  84. package/src/main/resources/base/media/plv_web_ic_failure.svg +30 -0
  85. package/src/main/resources/en_US/element/string.json +12 -0
  86. package/src/main/resources/zh_CN/element/string.json +12 -0
@@ -0,0 +1,197 @@
1
+ import PLVLogger from '../modules/log/PLVLogger';
2
+ import PLVCommonConstants from './PLVCommonConstants';
3
+ import { AppUtil, DeviceUtil, PasteboardUtil } from '@pura/harmony-utils';
4
+ import ConfigurationConstant from "@ohos.app.ability.ConfigurationConstant";
5
+ import window from "@ohos.window";
6
+ import scanBarcode from "@hms.core.scan.scanBarcode";
7
+ import scanCore from "@hms.core.scan.scanCore";
8
+ const TAG = '[PLVUtils]';
9
+ export default class PLVUtils {
10
+ constructor() {
11
+ }
12
+ static init(context, windowStage) {
13
+ AppUtil.init(context, windowStage);
14
+ }
15
+ static getClassTag(tag, f6 = true) {
16
+ let key = f6 ? '[Anonymous]' : undefined;
17
+ if (typeof tag == 'string') {
18
+ key = tag;
19
+ }
20
+ else {
21
+ if (tag && tag.constructor) {
22
+ key = `[${tag.constructor.name}]`;
23
+ }
24
+ }
25
+ return key;
26
+ }
27
+ static retryWhen(when, retry) {
28
+ try {
29
+ return Promise.resolve(when());
30
+ }
31
+ catch (err) {
32
+ PLVLogger.printWarn(TAG, 'retryWhen catch error', err);
33
+ try {
34
+ return Promise.resolve(retry());
35
+ }
36
+ catch (err) {
37
+ PLVLogger.printWarn(TAG, 'retryWhen catch error while retry', err);
38
+ return Promise.reject(err);
39
+ }
40
+ }
41
+ }
42
+ static async disposablePromise(promise, e6) {
43
+ try {
44
+ await promise;
45
+ }
46
+ catch (error) {
47
+ return Promise.reject(error);
48
+ }
49
+ if (e6?.isDispose()) {
50
+ return Promise.reject(new Error('error'));
51
+ }
52
+ return promise;
53
+ }
54
+ static safePromise(callback, a6) {
55
+ const promise = new Promise(async (c6, d6) => {
56
+ try {
57
+ await callback(c6, d6);
58
+ }
59
+ catch (err) {
60
+ PLVLogger.printWarn(TAG, 'safePromise catch error', err);
61
+ d6(err);
62
+ }
63
+ });
64
+ return PLVUtils.disposablePromise(promise, a6);
65
+ }
66
+ static async retryPromise(w5, x5, promise, y5) {
67
+ let z5 = 0;
68
+ let error = new Error('error');
69
+ while (z5 <= w5) {
70
+ try {
71
+ const result = await promise;
72
+ if (!y5?.isDispose()) {
73
+ return result;
74
+ }
75
+ }
76
+ catch (err) {
77
+ error = err;
78
+ PLVLogger.printWarn(TAG, `retryPromise retryCount=${z5} catch error`, err);
79
+ }
80
+ if (++z5 > w5) {
81
+ break;
82
+ }
83
+ if (y5?.isDispose()) {
84
+ return Promise.reject(error);
85
+ }
86
+ await PLVUtils.delay(x5);
87
+ }
88
+ return Promise.reject(error);
89
+ }
90
+ static async delay(delay) {
91
+ return PLVUtils.safePromise((v5) => {
92
+ setTimeout(v5, delay);
93
+ });
94
+ }
95
+ static validCallback(callback) {
96
+ return '/' != callback;
97
+ }
98
+ static getPid() {
99
+ const current = Date.now();
100
+ const random = Math.floor(Math.random() * 1000000) + 1000000;
101
+ return current + "X" + random;
102
+ }
103
+ static getDeviceId() {
104
+ return DeviceUtil.getDeviceId();
105
+ }
106
+ static undefinedToValue(data, callback, delay) {
107
+ setTimeout(() => {
108
+ callback(data);
109
+ }, delay ? delay : PLVCommonConstants.DELAY_TIME_S);
110
+ return undefined;
111
+ }
112
+ static copyText(text) {
113
+ return PasteboardUtil.setDataText(text);
114
+ }
115
+ static changeOrientation(m5, component, n5) {
116
+ let context = getContext(component);
117
+ let o5 = (s5) => {
118
+ s5.setPreferredOrientation(m5 ? window.Orientation.LANDSCAPE : window.Orientation.PORTRAIT);
119
+ };
120
+ n5 ? o5(n5) :
121
+ window.getLastWindow(context).then((r5) => {
122
+ o5(r5);
123
+ });
124
+ }
125
+ static isLandscape(component) {
126
+ let context = getContext(component);
127
+ return context.config.direction === ConfigurationConstant.Direction.DIRECTION_HORIZONTAL;
128
+ }
129
+ static setWindowFullScreen(isLayoutFullScreen = false, isFullScreen = false, component, c5) {
130
+ return new Promise((e5) => {
131
+ let context = getContext(component);
132
+ let f5 = (j5) => {
133
+ let k5 = j5.getWindowProperties().isLayoutFullScreen;
134
+ let l5 = j5.getWindowProperties().isFullScreen;
135
+ j5.setWindowLayoutFullScreen(isLayoutFullScreen);
136
+ if (canIUse("SystemCapability.Window.SessionManager")) {
137
+ j5.setSpecificSystemBarEnabled('status', !isFullScreen);
138
+ e5([k5, l5]);
139
+ }
140
+ };
141
+ c5 ? f5(c5) :
142
+ window.getLastWindow(context).then((i5) => {
143
+ f5(i5);
144
+ });
145
+ });
146
+ }
147
+ static startScan(component) {
148
+ return new Promise((z4) => {
149
+ if (canIUse('SystemCapability.Multimedia.Scan.Core') && canIUse('SystemCapability.Multimedia.Scan.ScanBarcode')) {
150
+ let options = {
151
+ scanTypes: [scanCore.ScanType.ALL],
152
+ enableMultiMode: true,
153
+ enableAlbum: true
154
+ };
155
+ try {
156
+ scanBarcode.startScanForResult(getContext(component), options).then((result) => {
157
+ PLVLogger.info(TAG, 'Promise scan result: ' + JSON.stringify(result));
158
+ z4(result.originalValue);
159
+ }).catch((error) => {
160
+ PLVLogger.error(TAG, 'Promise error: ' + JSON.stringify(error));
161
+ });
162
+ }
163
+ catch (error) {
164
+ PLVLogger.error(TAG, 'failReason: ' + JSON.stringify(error));
165
+ }
166
+ }
167
+ });
168
+ }
169
+ static getVideoRectJS(w4) {
170
+ let x4 = "function getVideoRect() {";
171
+ {
172
+ x4 += "let tags = document.getElementsByTagName('video');";
173
+ x4 += "if (tags.length > 0) {";
174
+ {
175
+ x4 += "let video = tags[0];";
176
+ x4 += "return {";
177
+ {
178
+ x4 += "'width': video.videoWidth,";
179
+ x4 += "'height': video.videoHeight";
180
+ }
181
+ x4 += "};";
182
+ }
183
+ x4 += "}";
184
+ x4 += "return {};";
185
+ }
186
+ x4 += "}";
187
+ x4 += "getVideoRect();";
188
+ return w4 ? PLVCommonConstants.JS_PRE + x4 : x4;
189
+ }
190
+ static getExitFullScreenJS(u4) {
191
+ let v4 = "function exitFullScreen() {";
192
+ v4 += "document.getElementsByTagName('video')[0].webkitExitFullScreen()";
193
+ v4 += "}";
194
+ v4 += "exitFullScreen();";
195
+ return u4 ? PLVCommonConstants.JS_PRE + v4 : v4;
196
+ }
197
+ }
@@ -0,0 +1,6 @@
1
+ export declare class PLVWebUtils {
2
+ static toWebViewContent(content?: string, color?: string): string;
3
+ static toRGBA(l6: string): string;
4
+ static cleanHTML(input: string): string;
5
+ static openWebLink(url?: string, component?: object): void;
6
+ }
@@ -0,0 +1,79 @@
1
+ import { PLVTextUtils } from './PLVTextUtils';
2
+ import PLVLogger from '../modules/log/PLVLogger';
3
+ const TAG = '[PLVWebUtils]';
4
+ export class PLVWebUtils {
5
+ static toWebViewContent(content, color) {
6
+ if (!content) {
7
+ return content;
8
+ }
9
+ if (!color) {
10
+ color = "rgba(0, 0, 0, 1)";
11
+ }
12
+ const style = "style=\" width:100%;\"";
13
+ const m6 = "word-break:break-all;";
14
+ const n6 = "color: " + color + ";";
15
+ content = content.replace(/src=\"\/\//g, "src=\"https://");
16
+ content = content.replace(/<img /g, "<img " + style + " ");
17
+ content = content.replace(/<li>/g, "<li style=\"" + n6 + "\">");
18
+ content = content.replace(/<p>/g, "<p style=\"" + m6 + n6 + "\">");
19
+ content = content.replace(/<div>/g, "<div style=\"" + m6 + n6 + "\">");
20
+ content = content.replace(/<table>/g, "<table border='1' rules=all style=\"" + n6 + "\">");
21
+ content = content.replace(/<td>/g, "<td width=\"36\">");
22
+ content = content.replace(/color: (#([0-9a-fA-F]{6}|[0-9a-fA-F]{8}));/g, (p6, q6) => {
23
+ return `color: ${PLVWebUtils.toRGBA(q6)};`;
24
+ });
25
+ content = "<!DOCTYPE html>\n" +
26
+ "<html lang=\"en\">\n" +
27
+ "<head>\n" +
28
+ " <meta charset=\"UTF-8\">\n" +
29
+ " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
30
+ " <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n" +
31
+ " <title>Document</title>\n" +
32
+ "</head>\n" +
33
+ "<body style=\" color: " + color + ";margin:0;padding:0\">" +
34
+ content + "</body>\n" +
35
+ "</html>";
36
+ return content;
37
+ }
38
+ static toRGBA(l6) {
39
+ let alpha = 1;
40
+ if (l6.length > 7) {
41
+ alpha = parseInt(l6.substring(1, 3), 16) / 255;
42
+ l6 = `#${l6.substring(3)}`;
43
+ }
44
+ const red = parseInt(l6.substring(1, 3), 16);
45
+ const green = parseInt(l6.substring(3, 5), 16);
46
+ const blue = parseInt(l6.substring(5, 7), 16);
47
+ return `rgba(${red}, ${green}, ${blue}, ${alpha})`;
48
+ }
49
+ static cleanHTML(input) {
50
+ let i6 = input.replace(/<p>((?:<img[^>]*>)+)<\/p>/g, (match, k6) => {
51
+ return k6.replace(/<img[^>]*>/g, '[图片]');
52
+ });
53
+ i6 = i6.replace(/<p><a[^>]*>(.*?)<\/a><\/p>/g, '$1');
54
+ i6 = i6.replace(/<p>(.*?)<\/p>/g, '$1');
55
+ i6 = i6.replace(/\n/g, ' ');
56
+ i6 = PLVTextUtils.convertSpecialString(i6);
57
+ return i6;
58
+ }
59
+ static openWebLink(url, component) {
60
+ let want = {
61
+ action: 'ohos.want.action.viewData',
62
+ entities: ['entity.system.browsable'],
63
+ uri: url
64
+ };
65
+ const context = getContext(component);
66
+ if (context) {
67
+ context.startAbility(want)
68
+ .then(() => {
69
+ PLVLogger.info(TAG, `openWebLink success, url: ${url}`);
70
+ })
71
+ .catch((err) => {
72
+ PLVLogger.error(TAG, `openWebLink error, url: ${url}, code: ${err.code}, message: ${err.message}`);
73
+ });
74
+ }
75
+ else {
76
+ PLVLogger.error(TAG, `openWebLink error, context: undefined`);
77
+ }
78
+ }
79
+ }
@@ -0,0 +1,20 @@
1
+ import { PLVPrintLogLevel } from '../../common/PLVCommonEnums';
2
+ import { common } from '@kit.AbilityKit';
3
+ export declare class PLVLogger {
4
+ private printLogLevel;
5
+ private tag;
6
+ private format;
7
+ private filePrinter?;
8
+ init(context: common.UIAbilityContext): void;
9
+ level(a7: PLVPrintLogLevel): void;
10
+ debug(tag: string, message: string, z6?: boolean): void;
11
+ info(tag: string, message: string, y6?: boolean): void;
12
+ warn(tag: string, message: string, x6?: boolean): void;
13
+ error(tag: string, message: string, w6?: boolean): void;
14
+ printWarn(tag: string, v6: string, err: Error): string;
15
+ printError(tag: string, u6: string, err: Error): string;
16
+ private generateErrorMsg;
17
+ private intercept;
18
+ }
19
+ declare const x11: PLVLogger;
20
+ export default x11;
@@ -0,0 +1,67 @@
1
+ import PLVCommonConstants from '../../common/PLVCommonConstants';
2
+ import { PLVPrintLogLevel } from '../../common/PLVCommonEnums';
3
+ import { DateFileNameGenerator, FileLastModifiedCleanStrategy, FileSizeBackupStrategy, LogConfiguration, OhPrinter, XLog } from '@ohos-port/xlog';
4
+ import util from "@ohos.util";
5
+ import { PLVXLogBuilder } from './PLVXLogFilePrinter';
6
+ export class PLVLogger {
7
+ constructor() {
8
+ this.printLogLevel = PLVPrintLogLevel.ALL;
9
+ this.tag = PLVCommonConstants.TAG.substring(1, PLVCommonConstants.TAG.length - 1);
10
+ this.format = "%s";
11
+ }
12
+ init(context) {
13
+ const config = new LogConfiguration.Builder()
14
+ .setTag(this.tag)
15
+ .build();
16
+ const filesDir = context.filesDir;
17
+ this.filePrinter = new PLVXLogBuilder(`${filesDir}/log`, true, '../../modules/log/PLVXLogWorker.ets')
18
+ .setCleanStrategy(new FileLastModifiedCleanStrategy(5 * 24 * 60 * 60 * 1000))
19
+ .setFileNameGenerator(new DateFileNameGenerator())
20
+ .setBackupStrategy(new FileSizeBackupStrategy(10 * 1024 * 1024))
21
+ .build();
22
+ XLog.init(config, [new OhPrinter()]);
23
+ }
24
+ level(a7) {
25
+ this.printLogLevel = a7;
26
+ }
27
+ debug(tag, message, z6 = true) {
28
+ const msg = util.format(this.format, tag, message);
29
+ this.intercept(PLVPrintLogLevel.DEBUG, msg, z6) || XLog.d(msg);
30
+ }
31
+ info(tag, message, y6 = true) {
32
+ const msg = util.format(this.format, tag, message);
33
+ this.intercept(PLVPrintLogLevel.INFO, msg, y6) || XLog.i(msg);
34
+ }
35
+ warn(tag, message, x6 = true) {
36
+ const msg = util.format(this.format, tag, message);
37
+ this.intercept(PLVPrintLogLevel.WARN, msg, x6) || XLog.w(msg);
38
+ }
39
+ error(tag, message, w6 = true) {
40
+ const msg = util.format(this.format, tag, message);
41
+ this.intercept(PLVPrintLogLevel.ERROR, msg, w6) || XLog.e(msg);
42
+ }
43
+ printWarn(tag, v6, err) {
44
+ const msg = this.generateErrorMsg(v6, err);
45
+ this.warn(tag, msg);
46
+ return msg;
47
+ }
48
+ printError(tag, u6, err) {
49
+ const msg = this.generateErrorMsg(u6, err);
50
+ this.error(tag, msg);
51
+ return msg;
52
+ }
53
+ generateErrorMsg(s6, err) {
54
+ let t6 = '';
55
+ if (err && err.code) {
56
+ t6 = `, code=${err.code}`;
57
+ }
58
+ return `${s6}: name=${err.name}, message=${err.message}${t6}\n${err.stack}`;
59
+ }
60
+ intercept(level, msg, r6 = true) {
61
+ if (r6) {
62
+ this.filePrinter?.println(level, this.tag, msg);
63
+ }
64
+ return this.printLogLevel > level;
65
+ }
66
+ }
67
+ export default new PLVLogger();
@@ -0,0 +1,12 @@
1
+ import worker from '@ohos.worker';
2
+ import { FilePrinter } from '@ohos-port/xlog';
3
+ import { Printer } from '@ohos-port/xlog/src/main/ets/printer/Printer';
4
+ export declare class PLVXLogFilePrinter extends Printer {
5
+ builder: FilePrinter.Builder;
6
+ workerInstance?: worker.ThreadWorker;
7
+ constructor(builder: FilePrinter.Builder);
8
+ println(b7: number, tag: string, msg: string): void;
9
+ }
10
+ export declare class PLVXLogBuilder extends FilePrinter.Builder {
11
+ build(): FilePrinter;
12
+ }
@@ -0,0 +1,37 @@
1
+ import worker from '@ohos.worker';
2
+ import { FilePrinter } from '@ohos-port/xlog';
3
+ import { LogAddMessage, LogInitMessage } from '@ohos-port/xlog/src/main/ets/printer/file/MessageType';
4
+ import { Printer } from '@ohos-port/xlog/src/main/ets/printer/Printer';
5
+ export class PLVXLogFilePrinter extends Printer {
6
+ constructor(builder) {
7
+ super();
8
+ this.builder = builder;
9
+ if (this.builder.useWorker) {
10
+ try {
11
+ this.workerInstance = new worker.ThreadWorker(this.builder.workerPath);
12
+ this.workerInstance.onmessage = (e) => {
13
+ let data = e.data;
14
+ let type = data.type;
15
+ };
16
+ this.workerInstance.onexit = (code) => {
17
+ };
18
+ let data = new LogInitMessage(this.builder);
19
+ this.workerInstance.postMessage(data);
20
+ }
21
+ catch (err) {
22
+ }
23
+ }
24
+ }
25
+ println(b7, tag, msg) {
26
+ if (this.workerInstance != null) {
27
+ let data = new LogAddMessage(b7, tag, msg);
28
+ this.workerInstance.postMessage(data);
29
+ }
30
+ }
31
+ }
32
+ export class PLVXLogBuilder extends FilePrinter.Builder {
33
+ build() {
34
+ super.build();
35
+ return new PLVXLogFilePrinter(this);
36
+ }
37
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import worker from '@ohos.worker';
2
+ import { logErrorHandler, logHandler } from '@ohos-port/xlog/XLogBaseWorker';
3
+ worker.workerPort.onmessage = logHandler;
4
+ worker.workerPort.onerror = logErrorHandler;
@@ -0,0 +1,7 @@
1
+ export declare class PLVApiConstants {
2
+ static readonly API_PLV_NET = "https://api.polyv.net";
3
+ static readonly ELOG_PLV_NET = "https://elog.polyv.net";
4
+ static readonly HTTPS_LIVEIMAGES_VIDEOCC_NET = "https://liveimages.videocc.net";
5
+ static readonly RTAS_VIDEOCC_NET = "https://rtas.videocc.net";
6
+ static readonly NGB_PUSH_URL = "https://sdkoptedge.chinanetcenter.com";
7
+ }
@@ -0,0 +1,7 @@
1
+ export class PLVApiConstants {
2
+ }
3
+ PLVApiConstants.API_PLV_NET = 'https://api.polyv.net';
4
+ PLVApiConstants.ELOG_PLV_NET = 'https://elog.polyv.net';
5
+ PLVApiConstants.HTTPS_LIVEIMAGES_VIDEOCC_NET = 'https://liveimages.videocc.net';
6
+ PLVApiConstants.RTAS_VIDEOCC_NET = 'https://rtas.videocc.net';
7
+ PLVApiConstants.NGB_PUSH_URL = 'https://sdkoptedge.chinanetcenter.com';
@@ -0,0 +1,8 @@
1
+ import { PLVResponse } from '../../common/PLVType';
2
+ export declare class PLVHttpData<T> {
3
+ code?: number;
4
+ status?: string;
5
+ message?: string;
6
+ data?: T;
7
+ static fill<T>(e7: T, data: PLVResponse<T>): void;
8
+ }
@@ -0,0 +1,8 @@
1
+ import PLVJSONUtils from '../../common/PLVJSONUtils';
2
+ export class PLVHttpData {
3
+ static fill(e7, data) {
4
+ if (data) {
5
+ PLVJSONUtils.httpData2Bean(e7, data.data);
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,5 @@
1
+ import { AxiosError } from '@ohos/axios';
2
+ export declare class PLVHttpError extends AxiosError {
3
+ constructor(g7: AxiosError);
4
+ log(tag: string, f7: string): this;
5
+ }
@@ -0,0 +1,13 @@
1
+ import { AxiosError } from '@ohos/axios';
2
+ import PLVJSONUtils from '../../common/PLVJSONUtils';
3
+ import PLVLogger from '../log/PLVLogger';
4
+ export class PLVHttpError extends AxiosError {
5
+ constructor(g7) {
6
+ const message = (g7.response?.data && PLVJSONUtils.safeStringify(g7.response.data)) || g7.message;
7
+ super(message, g7.code, g7.config, g7.request, g7.response);
8
+ }
9
+ log(tag, f7) {
10
+ PLVLogger.printError(tag, f7, this);
11
+ return this;
12
+ }
13
+ }
@@ -0,0 +1,25 @@
1
+ import { AxiosRequestConfig, AxiosResponse } from '@ohos/axios';
2
+ import { HashMap } from '@kit.ArkTS';
3
+ export declare class PLVHttpRequest {
4
+ static readonly CACHE_TIMEOUT: number;
5
+ static readonly CACHE_DATA_MAP: HashMap<string, AxiosResponse>;
6
+ static token?: string;
7
+ baseURL?: string;
8
+ userAgent?: string;
9
+ private method?;
10
+ constructor(x7?: string);
11
+ ua(w7?: string): this;
12
+ create<g12 = Object>(config?: PLVAxiosRequestConfig<g12>): import("@ohos/axios").AxiosInstance;
13
+ request<T = Object, f12 = AxiosResponse<T>>(p: Promise<AxiosResponse<T>>): Promise<f12>;
14
+ get<T = Object, d12 = AxiosResponse<T>, e12 = Object>(config?: PLVAxiosRequestConfig<e12>): Promise<d12>;
15
+ post<T = Object, b12 = AxiosResponse<T>, c12 = Object>(config?: PLVAxiosRequestConfig<c12>): Promise<b12>;
16
+ checkCache<T = Object, z11 = AxiosResponse<T>, a12 = Object>(config?: PLVAxiosRequestConfig<a12>): Promise<z11> | undefined;
17
+ generateCacheKey(config?: AxiosRequestConfig): string;
18
+ }
19
+ export interface PLVAxiosRequestConfig<D = Object> extends AxiosRequestConfig<D> {
20
+ formUrlEncoded?: boolean;
21
+ aesDecrypted?: boolean;
22
+ useCache?: boolean;
23
+ fillData?: Object;
24
+ signKey?: string;
25
+ }
@@ -0,0 +1,147 @@
1
+ import axios, { AxiosError } from '@ohos/axios';
2
+ import HashMap from "@ohos.util.HashMap";
3
+ import PLVJSONUtils from '../../common/PLVJSONUtils';
4
+ import { PLVHttpError } from './PLVHttpError';
5
+ import PLVLogger from '../log/PLVLogger';
6
+ import { PLVRequestSetting } from './PLVRequestSetting';
7
+ import { PLVHttpData } from './PLVHttpData';
8
+ import PLVUtils from '../../common/PLVUtils';
9
+ import { PLVNetUtils } from '../../common/PLVNetUtils';
10
+ const TAG = '[PLVHttpRequest]';
11
+ export class PLVHttpRequest {
12
+ constructor(x7) {
13
+ this.baseURL = x7;
14
+ }
15
+ ua(w7) {
16
+ this.userAgent = w7;
17
+ return this;
18
+ }
19
+ create(config) {
20
+ const o7 = axios.create();
21
+ o7.defaults.timeout = 10000;
22
+ o7.defaults.readTimeout = 10000;
23
+ o7.defaults.connectTimeout = 10000;
24
+ o7.defaults.baseURL = this.baseURL;
25
+ o7.defaults.headers.common["w1"] = this.userAgent;
26
+ if (config?.formUrlEncoded) {
27
+ o7.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
28
+ }
29
+ let cacheKey = '';
30
+ o7.interceptors.request.use((v7) => {
31
+ if (config?.signKey) {
32
+ const data = v7.params ? v7.params : v7.data;
33
+ const map = PLVJSONUtils.object2Map(data);
34
+ map.delete('log');
35
+ data['sign'] = PLVRequestSetting.createSign(map, config.signKey);
36
+ }
37
+ if (PLVHttpRequest.token) {
38
+ const params = v7.params;
39
+ const data = v7.data;
40
+ if (params && Object.keys(params).includes('appId')) {
41
+ params['token'] = PLVHttpRequest.token;
42
+ params["z1"] = PLVHttpRequest.token;
43
+ }
44
+ if (data && Object.keys(data).includes('appId')) {
45
+ data['token'] = PLVHttpRequest.token;
46
+ data["z1"] = PLVHttpRequest.token;
47
+ }
48
+ }
49
+ if (config?.useCache) {
50
+ cacheKey = this.generateCacheKey(v7);
51
+ }
52
+ PLVLogger.info(TAG, `--> ${this.method} ${this.baseURL}${config?.url}${PLVNetUtils.formatParams(v7?.params)}`);
53
+ PLVLogger.info(TAG, `--> ${PLVNetUtils.formatParams(v7?.data)}`);
54
+ return v7;
55
+ }, (error) => {
56
+ return Promise.reject(error);
57
+ });
58
+ o7.interceptors.response.use((response) => {
59
+ PLVLogger.info(TAG, `<-- ${response.status} ${this.method} ${this.baseURL}${response.config.url}${PLVNetUtils.formatParams(config?.params)} (${response.performanceTiming?.totalTiming}ms)`);
60
+ PLVLogger.info(TAG, `Header: ${PLVJSONUtils.safeStringify(response.headers)}`);
61
+ PLVLogger.info(TAG, `Result: ${PLVJSONUtils.safeStringify(response.data)}`);
62
+ if (config?.aesDecrypted) {
63
+ const u7 = response.data;
64
+ if (u7) {
65
+ u7['data'] = PLVJSONUtils.safeParse(PLVRequestSetting.decryptDataSync(u7['data']));
66
+ }
67
+ else {
68
+ PLVLogger.printError(TAG, 'response error', new Error('jsonData undefined'));
69
+ }
70
+ }
71
+ if (config?.fillData) {
72
+ PLVHttpData.fill(config.fillData, response);
73
+ }
74
+ if (cacheKey) {
75
+ PLVHttpRequest.CACHE_DATA_MAP.set(cacheKey, response);
76
+ setTimeout(() => {
77
+ PLVHttpRequest.CACHE_DATA_MAP.remove(cacheKey);
78
+ }, PLVHttpRequest.CACHE_TIMEOUT);
79
+ }
80
+ return response;
81
+ }, (error) => {
82
+ return Promise.reject(error);
83
+ });
84
+ return o7;
85
+ }
86
+ request(p) {
87
+ return PLVUtils.safePromise((k7, l7) => {
88
+ p.then((r) => {
89
+ const data = r.data;
90
+ if (data) {
91
+ for (const key of Object.keys(data)) {
92
+ if (key == 'code' && data[key] != 200 + '') {
93
+ l7(new PLVHttpError(new AxiosError(PLVJSONUtils.safeStringify(r.data || ''), data[key], undefined, undefined, r)));
94
+ return;
95
+ }
96
+ }
97
+ }
98
+ k7(r);
99
+ }).catch((err) => {
100
+ l7(new PLVHttpError(err));
101
+ });
102
+ });
103
+ }
104
+ get(config) {
105
+ this.method = 'GET';
106
+ return this.checkCache(config) || this.request(this.create(config).get(config?.url, config));
107
+ }
108
+ post(config) {
109
+ this.method = 'POST';
110
+ return this.checkCache(config) || this.request(this.create(config).post(config?.url, config?.data, config));
111
+ }
112
+ checkCache(config) {
113
+ if (config?.useCache) {
114
+ const cacheKey = this.generateCacheKey(config);
115
+ if (PLVHttpRequest.CACHE_DATA_MAP.hasKey(cacheKey)) {
116
+ PLVLogger.info(TAG, `--> ${this.method} ${this.baseURL}${config?.url} use cache`);
117
+ return Promise.resolve(PLVHttpRequest.CACHE_DATA_MAP.get(cacheKey));
118
+ }
119
+ }
120
+ return undefined;
121
+ }
122
+ generateCacheKey(config) {
123
+ let cacheKey = this.baseURL + '' + config?.url;
124
+ const params = config?.params;
125
+ const data = config?.data;
126
+ const h7 = (record) => {
127
+ if (record) {
128
+ for (const key of Object.keys(record)) {
129
+ if (key == 'timestamp' || key == 'sign' || key == 'token' || key == 'viewerToken') {
130
+ continue;
131
+ }
132
+ if (key == 'appId' && PLVHttpRequest.token) {
133
+ cacheKey += PLVHttpRequest.token;
134
+ }
135
+ else {
136
+ cacheKey += record[key];
137
+ }
138
+ }
139
+ }
140
+ };
141
+ h7(params);
142
+ h7(data);
143
+ return cacheKey;
144
+ }
145
+ }
146
+ PLVHttpRequest.CACHE_TIMEOUT = 1000 * 60 * 5;
147
+ PLVHttpRequest.CACHE_DATA_MAP = new HashMap();
@@ -0,0 +1,9 @@
1
+ export declare class PLVRequestSetting {
2
+ static readonly KEY_1 = "polyv_sdk_api_innor";
3
+ static readonly PLV_SWITCH_API_INNOR = "polyv_switch_api_innor";
4
+ static readonly DECRYPT_KEY_1_SRC = "PolyvApiResponse";
5
+ static readonly DECRYPT_KEY_2_SRC = "PolyvLiveEncrypt";
6
+ static createSign(map: Map<string, Object | undefined>, key?: string): string;
7
+ static decryptDataSync(data: string): string;
8
+ static concatParams(map: Map<string, Object | undefined>): string;
9
+ }