@polyvharmony/live-scenes-foundation 1.2.0 → 1.3.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.
- package/CHANGELOG.md +4 -0
- package/Index.d.ets +4 -2
- package/Index.js +3 -1
- package/ResourceTable.txt +2 -1
- package/libs/plvclasstransformer.har +0 -0
- package/oh-package.json5 +1 -1
- package/package.json +1 -1
- package/src/main/ets/common/PLVCallback.d.ets +31 -6
- package/src/main/ets/common/PLVCallback.js +85 -27
- package/src/main/ets/common/PLVCommonConstants.d.ets +1 -0
- package/src/main/ets/common/PLVCommonConstants.js +1 -0
- package/src/main/ets/common/PLVCommonEnums.js +16 -16
- package/src/main/ets/common/PLVDeviceUtils.d.ets +7 -0
- package/src/main/ets/common/PLVDeviceUtils.js +28 -1
- package/src/main/ets/common/PLVJSONUtils.d.ets +7 -7
- package/src/main/ets/common/PLVJSONUtils.js +20 -20
- package/src/main/ets/common/PLVNetUtils.d.ets +4 -3
- package/src/main/ets/common/PLVNetUtils.js +20 -14
- package/src/main/ets/common/PLVPreferencesUtils.d.ets +8 -8
- package/src/main/ets/common/PLVPreferencesUtils.js +16 -16
- package/src/main/ets/common/PLVScheduledTask.js +2 -2
- package/src/main/ets/common/PLVSimpleBuffer.d.ets +2 -2
- package/src/main/ets/common/PLVSimpleBuffer.js +6 -6
- package/src/main/ets/common/PLVSparseArray.d.ets +10 -0
- package/src/main/ets/common/PLVSparseArray.js +44 -0
- package/src/main/ets/common/PLVTextUtils.d.ets +2 -1
- package/src/main/ets/common/PLVTextUtils.js +28 -22
- package/src/main/ets/common/PLVTimeUtils.d.ets +1 -1
- package/src/main/ets/common/PLVTimeUtils.js +8 -8
- package/src/main/ets/common/PLVToastUtils.d.ets +2 -2
- package/src/main/ets/common/PLVType.d.ets +1 -0
- package/src/main/ets/common/PLVUACreator.d.ets +1 -1
- package/src/main/ets/common/PLVUACreator.js +6 -6
- package/src/main/ets/common/PLVUtils.d.ets +15 -8
- package/src/main/ets/common/PLVUtils.js +89 -45
- package/src/main/ets/common/PLVWebUtils.d.ets +1 -1
- package/src/main/ets/common/PLVWebUtils.js +22 -22
- package/src/main/ets/common/ui/PLVNodeController.d.ets +41 -0
- package/src/main/ets/common/ui/PLVNodeController.js +103 -0
- package/src/main/ets/modules/log/PLVLogger.d.ets +9 -9
- package/src/main/ets/modules/log/PLVLogger.js +20 -20
- package/src/main/ets/modules/log/PLVXLogFilePrinter.d.ets +1 -1
- package/src/main/ets/modules/log/PLVXLogFilePrinter.js +2 -2
- package/src/main/ets/modules/net/PLVHttpData.d.ets +1 -1
- package/src/main/ets/modules/net/PLVHttpData.js +2 -2
- package/src/main/ets/modules/net/PLVHttpError.d.ets +2 -2
- package/src/main/ets/modules/net/PLVHttpError.js +5 -5
- package/src/main/ets/modules/net/PLVHttpRequest.d.ets +7 -7
- package/src/main/ets/modules/net/PLVHttpRequest.js +31 -31
- package/src/main/ets/modules/net/PLVRequestSetting.js +7 -7
- package/src/main/ets/modules/socket/PLVSocketIO.d.ets +19 -18
- package/src/main/ets/modules/socket/PLVSocketIO.js +70 -53
- package/src/main/ets/modules/web/PLVSimpleWeb.js +3 -3
- package/src/main/ets/modules/web/PLVWebController.d.ets +5 -3
- package/src/main/ets/modules/web/PLVWebController.js +29 -21
- package/src/main/module.json +1 -28
|
@@ -10,17 +10,17 @@ export class PLVWebUtils {
|
|
|
10
10
|
color = "rgba(0, 0, 0, 1)";
|
|
11
11
|
}
|
|
12
12
|
const style = "style=\" width:100%;\"";
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const h6 = "word-break:break-all;";
|
|
14
|
+
const i6 = "color: " + color + ";";
|
|
15
15
|
content = content.replace(/src=\"\/\//g, "src=\"https://");
|
|
16
16
|
content = content.replace(/<img /g, "<img " + style + " ");
|
|
17
|
-
content = content.replace(/<li>/g, "<li style=\"" +
|
|
18
|
-
content = content.replace(/<p>/g, "<p style=\"" +
|
|
19
|
-
content = content.replace(/<div>/g, "<div style=\"" +
|
|
20
|
-
content = content.replace(/<table>/g, "<table border='1' rules=all style=\"" +
|
|
17
|
+
content = content.replace(/<li>/g, "<li style=\"" + i6 + "\">");
|
|
18
|
+
content = content.replace(/<p>/g, "<p style=\"" + h6 + i6 + "\">");
|
|
19
|
+
content = content.replace(/<div>/g, "<div style=\"" + h6 + i6 + "\">");
|
|
20
|
+
content = content.replace(/<table>/g, "<table border='1' rules=all style=\"" + i6 + "\">");
|
|
21
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, (
|
|
23
|
-
return `color: ${PLVWebUtils.toRGBA(
|
|
22
|
+
content = content.replace(/color: (#([0-9a-fA-F]{6}|[0-9a-fA-F]{8}));/g, (j6, k6) => {
|
|
23
|
+
return `color: ${PLVWebUtils.toRGBA(k6)};`;
|
|
24
24
|
});
|
|
25
25
|
content = "<!DOCTYPE html>\n" +
|
|
26
26
|
"<html lang=\"en\">\n" +
|
|
@@ -35,26 +35,26 @@ export class PLVWebUtils {
|
|
|
35
35
|
"</html>";
|
|
36
36
|
return content;
|
|
37
37
|
}
|
|
38
|
-
static toRGBA(
|
|
38
|
+
static toRGBA(g6) {
|
|
39
39
|
let alpha = 1;
|
|
40
|
-
if (
|
|
41
|
-
alpha = parseInt(
|
|
42
|
-
|
|
40
|
+
if (g6.length > 7) {
|
|
41
|
+
alpha = parseInt(g6.substring(1, 3), 16) / 255;
|
|
42
|
+
g6 = `#${g6.substring(3)}`;
|
|
43
43
|
}
|
|
44
|
-
const red = parseInt(
|
|
45
|
-
const green = parseInt(
|
|
46
|
-
const blue = parseInt(
|
|
44
|
+
const red = parseInt(g6.substring(1, 3), 16);
|
|
45
|
+
const green = parseInt(g6.substring(3, 5), 16);
|
|
46
|
+
const blue = parseInt(g6.substring(5, 7), 16);
|
|
47
47
|
return `rgba(${red}, ${green}, ${blue}, ${alpha})`;
|
|
48
48
|
}
|
|
49
49
|
static cleanHTML(input) {
|
|
50
|
-
let
|
|
51
|
-
return
|
|
50
|
+
let e6 = input.replace(/<p>((?:<img[^>]*>)+)<\/p>/g, (match, f6) => {
|
|
51
|
+
return f6.replace(/<img[^>]*>/g, '[图片]');
|
|
52
52
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return
|
|
53
|
+
e6 = e6.replace(/<p><a[^>]*>(.*?)<\/a><\/p>/g, '$1');
|
|
54
|
+
e6 = e6.replace(/<p>(.*?)<\/p>/g, '$1');
|
|
55
|
+
e6 = e6.replace(/\n/g, ' ');
|
|
56
|
+
e6 = PLVTextUtils.convertSpecialString(e6);
|
|
57
|
+
return e6;
|
|
58
58
|
}
|
|
59
59
|
static openWebLink(url, component) {
|
|
60
60
|
let want = {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BuilderNode, NodeController, UIContext } from '@kit.ArkUI';
|
|
2
|
+
import { PLVPromiseValue } from '../PLVCallback';
|
|
3
|
+
export declare class PLVNodeControllerManager {
|
|
4
|
+
private static controllerManagers;
|
|
5
|
+
private controllers;
|
|
6
|
+
private constructor();
|
|
7
|
+
static get(id?: number): PLVNodeControllerManager;
|
|
8
|
+
static delete(id: number): void;
|
|
9
|
+
getOrCreate(config: string | NodeControllerConfig): PLVNodeController;
|
|
10
|
+
private destroy;
|
|
11
|
+
}
|
|
12
|
+
export declare class PLVNodeController extends NodeController {
|
|
13
|
+
uniqueId: string;
|
|
14
|
+
viewNode: BuilderNode<[
|
|
15
|
+
ESObject
|
|
16
|
+
]> | undefined;
|
|
17
|
+
wrapBuilder: WrappedBuilder<[
|
|
18
|
+
ESObject
|
|
19
|
+
]> | undefined;
|
|
20
|
+
params: ESObject | undefined;
|
|
21
|
+
isShow?: boolean;
|
|
22
|
+
isShowPromise: PLVPromiseValue<boolean>;
|
|
23
|
+
private uiContext;
|
|
24
|
+
private environmentCallback?;
|
|
25
|
+
constructor(config: NodeControllerConfig);
|
|
26
|
+
makeNode(uiContext: UIContext): FrameNode | null;
|
|
27
|
+
fill(wrapBuilder: WrappedBuilder<[
|
|
28
|
+
ESObject
|
|
29
|
+
]>, params: ESObject): PLVNodeController;
|
|
30
|
+
show(isShow?: boolean): void;
|
|
31
|
+
destroy(): void;
|
|
32
|
+
private onEnvironment;
|
|
33
|
+
}
|
|
34
|
+
export interface NodeControllerConfig {
|
|
35
|
+
name: string;
|
|
36
|
+
isShow?: boolean;
|
|
37
|
+
wrapBuilder?: WrappedBuilder<[
|
|
38
|
+
ESObject
|
|
39
|
+
]>;
|
|
40
|
+
params?: ESObject;
|
|
41
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { BuilderNode, NodeController } from "@ohos.arkui.node";
|
|
2
|
+
import { PLVPromiseValue } from '../PLVCallback';
|
|
3
|
+
const l6 = new Map();
|
|
4
|
+
export class PLVNodeControllerManager {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.controllers = new Map();
|
|
7
|
+
}
|
|
8
|
+
static get(id = 0) {
|
|
9
|
+
if (!PLVNodeControllerManager.controllerManagers.has(id)) {
|
|
10
|
+
PLVNodeControllerManager.controllerManagers.set(id, new PLVNodeControllerManager());
|
|
11
|
+
}
|
|
12
|
+
return PLVNodeControllerManager.controllerManagers.get(id);
|
|
13
|
+
}
|
|
14
|
+
static delete(id) {
|
|
15
|
+
PLVNodeControllerManager.get(id).destroy();
|
|
16
|
+
PLVNodeControllerManager.controllerManagers.delete(id);
|
|
17
|
+
}
|
|
18
|
+
getOrCreate(config) {
|
|
19
|
+
const uniqueId = typeof config === 'string' ? config : config.name;
|
|
20
|
+
if (!this.controllers.has(uniqueId)) {
|
|
21
|
+
this.controllers.set(uniqueId, new PLVNodeController(typeof config === 'string' ? { name: uniqueId } : config));
|
|
22
|
+
}
|
|
23
|
+
const controller = this.controllers.get(uniqueId);
|
|
24
|
+
if (typeof config !== 'string' && config.wrapBuilder) {
|
|
25
|
+
controller.fill(config.wrapBuilder, config.params);
|
|
26
|
+
controller.show(config.isShow);
|
|
27
|
+
}
|
|
28
|
+
return controller;
|
|
29
|
+
}
|
|
30
|
+
destroy(uniqueId) {
|
|
31
|
+
if (uniqueId) {
|
|
32
|
+
this.controllers.get(uniqueId)?.destroy();
|
|
33
|
+
this.controllers.delete(uniqueId);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.controllers.forEach((controller) => {
|
|
37
|
+
controller.destroy();
|
|
38
|
+
});
|
|
39
|
+
this.controllers.clear();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
PLVNodeControllerManager.controllerManagers = new Map();
|
|
44
|
+
export class PLVNodeController extends NodeController {
|
|
45
|
+
constructor(config) {
|
|
46
|
+
super();
|
|
47
|
+
this.viewNode = undefined;
|
|
48
|
+
this.wrapBuilder = undefined;
|
|
49
|
+
this.params = undefined;
|
|
50
|
+
this.isShow = false;
|
|
51
|
+
this.isShowPromise = new PLVPromiseValue();
|
|
52
|
+
this.uiContext = undefined;
|
|
53
|
+
this.environmentCallback = undefined;
|
|
54
|
+
this.uniqueId = config.name;
|
|
55
|
+
this.isShow = config.isShow;
|
|
56
|
+
this.wrapBuilder = config.wrapBuilder;
|
|
57
|
+
this.params = config.params;
|
|
58
|
+
this.show(this.isShow);
|
|
59
|
+
}
|
|
60
|
+
makeNode(uiContext) {
|
|
61
|
+
if (!this.isShow || !this.wrapBuilder) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
this.uiContext = uiContext;
|
|
65
|
+
this.viewNode = l6.get(this.uniqueId) ?? new BuilderNode(uiContext);
|
|
66
|
+
l6.set(this.uniqueId, this.viewNode);
|
|
67
|
+
if (!this.viewNode.getFrameNode()) {
|
|
68
|
+
this.viewNode.build(this.wrapBuilder, this.params);
|
|
69
|
+
this.onEnvironment(uiContext);
|
|
70
|
+
}
|
|
71
|
+
return this.viewNode.getFrameNode();
|
|
72
|
+
}
|
|
73
|
+
fill(wrapBuilder, params) {
|
|
74
|
+
this.wrapBuilder = wrapBuilder;
|
|
75
|
+
this.params = params;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
show(isShow = false) {
|
|
79
|
+
if (this.isShow === isShow || !this.wrapBuilder) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this.isShow = isShow;
|
|
83
|
+
this.rebuild();
|
|
84
|
+
this.isShowPromise.set(isShow);
|
|
85
|
+
}
|
|
86
|
+
destroy() {
|
|
87
|
+
l6.get(this.uniqueId)?.dispose();
|
|
88
|
+
l6.delete(this.uniqueId);
|
|
89
|
+
if (this.environmentCallback !== undefined) {
|
|
90
|
+
this.uiContext?.getHostContext()?.getApplicationContext().off('environment', this.environmentCallback);
|
|
91
|
+
}
|
|
92
|
+
this.uiContext = undefined;
|
|
93
|
+
}
|
|
94
|
+
onEnvironment(uiContext) {
|
|
95
|
+
this.environmentCallback = uiContext.getHostContext()?.getApplicationContext().on('environment', {
|
|
96
|
+
onConfigurationUpdated: (config) => {
|
|
97
|
+
this.viewNode?.updateConfiguration();
|
|
98
|
+
},
|
|
99
|
+
onMemoryLevel: (level) => {
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -6,15 +6,15 @@ export declare class PLVLogger {
|
|
|
6
6
|
private format;
|
|
7
7
|
private filePrinter?;
|
|
8
8
|
init(context: common.UIAbilityContext): void;
|
|
9
|
-
level(
|
|
10
|
-
debug(tag: string, message: string,
|
|
11
|
-
info(tag: string, message: string,
|
|
12
|
-
warn(tag: string, message: string,
|
|
13
|
-
error(tag: string, message: string,
|
|
14
|
-
printWarn(tag: string,
|
|
15
|
-
printError(tag: string,
|
|
9
|
+
level(v6: PLVPrintLogLevel): void;
|
|
10
|
+
debug(tag: string, message: string, u6?: boolean): void;
|
|
11
|
+
info(tag: string, message: string, t6?: boolean): void;
|
|
12
|
+
warn(tag: string, message: string, s6?: boolean): void;
|
|
13
|
+
error(tag: string, message: string, r6?: boolean): void;
|
|
14
|
+
printWarn(tag: string, q6: string, err: Error): string;
|
|
15
|
+
printError(tag: string, p6: string, err: Error): string;
|
|
16
16
|
private generateErrorMsg;
|
|
17
17
|
private intercept;
|
|
18
18
|
}
|
|
19
|
-
declare const
|
|
20
|
-
export default
|
|
19
|
+
declare const u8: PLVLogger;
|
|
20
|
+
export default u8;
|
|
@@ -21,44 +21,44 @@ export class PLVLogger {
|
|
|
21
21
|
.build();
|
|
22
22
|
XLog.init(config, [new OhPrinter()]);
|
|
23
23
|
}
|
|
24
|
-
level(
|
|
25
|
-
this.printLogLevel =
|
|
24
|
+
level(v6) {
|
|
25
|
+
this.printLogLevel = v6;
|
|
26
26
|
}
|
|
27
|
-
debug(tag, message,
|
|
27
|
+
debug(tag, message, u6 = true) {
|
|
28
28
|
const msg = util.format(this.format, tag, message);
|
|
29
|
-
this.intercept(PLVPrintLogLevel.DEBUG, msg,
|
|
29
|
+
this.intercept(PLVPrintLogLevel.DEBUG, msg, u6) || XLog.d(msg);
|
|
30
30
|
}
|
|
31
|
-
info(tag, message,
|
|
31
|
+
info(tag, message, t6 = true) {
|
|
32
32
|
const msg = util.format(this.format, tag, message);
|
|
33
|
-
this.intercept(PLVPrintLogLevel.INFO, msg,
|
|
33
|
+
this.intercept(PLVPrintLogLevel.INFO, msg, t6) || XLog.i(msg);
|
|
34
34
|
}
|
|
35
|
-
warn(tag, message,
|
|
35
|
+
warn(tag, message, s6 = true) {
|
|
36
36
|
const msg = util.format(this.format, tag, message);
|
|
37
|
-
this.intercept(PLVPrintLogLevel.WARN, msg,
|
|
37
|
+
this.intercept(PLVPrintLogLevel.WARN, msg, s6) || XLog.w(msg);
|
|
38
38
|
}
|
|
39
|
-
error(tag, message,
|
|
39
|
+
error(tag, message, r6 = true) {
|
|
40
40
|
const msg = util.format(this.format, tag, message);
|
|
41
|
-
this.intercept(PLVPrintLogLevel.ERROR, msg,
|
|
41
|
+
this.intercept(PLVPrintLogLevel.ERROR, msg, r6) || XLog.e(msg);
|
|
42
42
|
}
|
|
43
|
-
printWarn(tag,
|
|
44
|
-
const msg = this.generateErrorMsg(
|
|
43
|
+
printWarn(tag, q6, err) {
|
|
44
|
+
const msg = this.generateErrorMsg(q6, err);
|
|
45
45
|
this.warn(tag, msg);
|
|
46
46
|
return msg;
|
|
47
47
|
}
|
|
48
|
-
printError(tag,
|
|
49
|
-
const msg = this.generateErrorMsg(
|
|
48
|
+
printError(tag, p6, err) {
|
|
49
|
+
const msg = this.generateErrorMsg(p6, err);
|
|
50
50
|
this.error(tag, msg);
|
|
51
51
|
return msg;
|
|
52
52
|
}
|
|
53
|
-
generateErrorMsg(
|
|
54
|
-
let
|
|
53
|
+
generateErrorMsg(n6, err) {
|
|
54
|
+
let o6 = '';
|
|
55
55
|
if (err && err.code) {
|
|
56
|
-
|
|
56
|
+
o6 = `, code=${err.code}`;
|
|
57
57
|
}
|
|
58
|
-
return `${
|
|
58
|
+
return `${n6}: name=${err.name}, message=${err.message}${o6}\n${err.stack}`;
|
|
59
59
|
}
|
|
60
|
-
intercept(level, msg,
|
|
61
|
-
if (
|
|
60
|
+
intercept(level, msg, m6 = true) {
|
|
61
|
+
if (m6) {
|
|
62
62
|
this.filePrinter?.println(level, this.tag, msg);
|
|
63
63
|
}
|
|
64
64
|
return this.printLogLevel > level;
|
|
@@ -5,7 +5,7 @@ export declare class PLVXLogFilePrinter extends Printer {
|
|
|
5
5
|
builder: FilePrinter.Builder;
|
|
6
6
|
workerInstance?: worker.ThreadWorker;
|
|
7
7
|
constructor(builder: FilePrinter.Builder);
|
|
8
|
-
println(
|
|
8
|
+
println(w6: number, tag: string, msg: string): void;
|
|
9
9
|
}
|
|
10
10
|
export declare class PLVXLogBuilder extends FilePrinter.Builder {
|
|
11
11
|
build(): FilePrinter;
|
|
@@ -22,9 +22,9 @@ export class PLVXLogFilePrinter extends Printer {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
println(
|
|
25
|
+
println(w6, tag, msg) {
|
|
26
26
|
if (this.workerInstance != null) {
|
|
27
|
-
let data = new LogAddMessage(
|
|
27
|
+
let data = new LogAddMessage(w6, tag, msg);
|
|
28
28
|
this.workerInstance.postMessage(data);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -2,12 +2,12 @@ import { AxiosError } from '@ohos/axios';
|
|
|
2
2
|
import PLVJSONUtils from '../../common/PLVJSONUtils';
|
|
3
3
|
import PLVLogger from '../log/PLVLogger';
|
|
4
4
|
export class PLVHttpError extends AxiosError {
|
|
5
|
-
constructor(
|
|
6
|
-
const message = (
|
|
7
|
-
super(message,
|
|
5
|
+
constructor(z6) {
|
|
6
|
+
const message = (z6.response?.data && PLVJSONUtils.safeStringify(z6.response.data)) || z6.message;
|
|
7
|
+
super(message, z6.code, z6.config, z6.request, z6.response);
|
|
8
8
|
}
|
|
9
|
-
log(tag,
|
|
10
|
-
PLVLogger.printError(tag,
|
|
9
|
+
log(tag, y6) {
|
|
10
|
+
PLVLogger.printError(tag, y6, this);
|
|
11
11
|
return this;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -7,13 +7,13 @@ export declare class PLVHttpRequest {
|
|
|
7
7
|
baseURL?: string;
|
|
8
8
|
userAgent?: string;
|
|
9
9
|
private method?;
|
|
10
|
-
constructor(
|
|
11
|
-
ua(
|
|
12
|
-
create<
|
|
13
|
-
request<T = Object,
|
|
14
|
-
get<T = Object,
|
|
15
|
-
post<T = Object,
|
|
16
|
-
checkCache<T = Object,
|
|
10
|
+
constructor(g7?: string);
|
|
11
|
+
ua(f7?: string): this;
|
|
12
|
+
create<z8 = Object>(config?: PLVAxiosRequestConfig<z8>): import("@ohos/axios").AxiosInstance;
|
|
13
|
+
request<T = Object, R = AxiosResponse<T>>(p: Promise<AxiosResponse<T>>): Promise<R>;
|
|
14
|
+
get<T = Object, R = AxiosResponse<T>, y8 = Object>(config?: PLVAxiosRequestConfig<y8>): Promise<R>;
|
|
15
|
+
post<T = Object, R = AxiosResponse<T>, x8 = Object>(config?: PLVAxiosRequestConfig<x8>): Promise<R>;
|
|
16
|
+
checkCache<T = Object, R = AxiosResponse<T>, w8 = Object>(config?: PLVAxiosRequestConfig<w8>): Promise<R> | undefined;
|
|
17
17
|
generateCacheKey(config?: AxiosRequestConfig): string;
|
|
18
18
|
}
|
|
19
19
|
export interface PLVAxiosRequestConfig<D = Object> extends AxiosRequestConfig<D> {
|
|
@@ -9,34 +9,34 @@ import PLVUtils from '../../common/PLVUtils';
|
|
|
9
9
|
import { PLVNetUtils } from '../../common/PLVNetUtils';
|
|
10
10
|
const TAG = '[PLVHttpRequest]';
|
|
11
11
|
export class PLVHttpRequest {
|
|
12
|
-
constructor(
|
|
13
|
-
this.baseURL =
|
|
12
|
+
constructor(g7) {
|
|
13
|
+
this.baseURL = g7;
|
|
14
14
|
}
|
|
15
|
-
ua(
|
|
16
|
-
this.userAgent =
|
|
15
|
+
ua(f7) {
|
|
16
|
+
this.userAgent = f7;
|
|
17
17
|
return this;
|
|
18
18
|
}
|
|
19
19
|
create(config) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const c7 = axios.create();
|
|
21
|
+
c7.defaults.timeout = 10000;
|
|
22
|
+
c7.defaults.readTimeout = 10000;
|
|
23
|
+
c7.defaults.connectTimeout = 10000;
|
|
24
|
+
c7.defaults.baseURL = this.baseURL;
|
|
25
|
+
c7.defaults.headers.common["w1"] = this.userAgent;
|
|
26
26
|
if (config?.formUrlEncoded) {
|
|
27
|
-
|
|
27
|
+
c7.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
28
28
|
}
|
|
29
29
|
let cacheKey = '';
|
|
30
|
-
|
|
30
|
+
c7.interceptors.request.use((e7) => {
|
|
31
31
|
if (config?.signKey) {
|
|
32
|
-
const data =
|
|
32
|
+
const data = e7.params ? e7.params : e7.data;
|
|
33
33
|
const map = PLVJSONUtils.object2Map(data);
|
|
34
34
|
map.delete('log');
|
|
35
35
|
data['sign'] = PLVRequestSetting.createSign(map, config.signKey);
|
|
36
36
|
}
|
|
37
37
|
if (PLVHttpRequest.token) {
|
|
38
|
-
const params =
|
|
39
|
-
const data =
|
|
38
|
+
const params = e7.params;
|
|
39
|
+
const data = e7.data;
|
|
40
40
|
if (params && Object.keys(params).includes('appId')) {
|
|
41
41
|
params['token'] = PLVHttpRequest.token;
|
|
42
42
|
params["z1"] = PLVHttpRequest.token;
|
|
@@ -47,22 +47,22 @@ export class PLVHttpRequest {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
if (config?.useCache) {
|
|
50
|
-
cacheKey = this.generateCacheKey(
|
|
50
|
+
cacheKey = this.generateCacheKey(e7);
|
|
51
51
|
}
|
|
52
|
-
PLVLogger.info(TAG, `--> ${this.method} ${this.baseURL}${config?.url}${PLVNetUtils.formatParams(
|
|
53
|
-
PLVLogger.info(TAG, `--> ${PLVNetUtils.formatParams(
|
|
54
|
-
return
|
|
52
|
+
PLVLogger.info(TAG, `--> ${this.method} ${this.baseURL}${config?.url}${PLVNetUtils.formatParams(e7?.params)}`);
|
|
53
|
+
PLVLogger.info(TAG, `--> ${PLVNetUtils.formatParams(e7?.data)}`);
|
|
54
|
+
return e7;
|
|
55
55
|
}, (error) => {
|
|
56
56
|
return Promise.reject(error);
|
|
57
57
|
});
|
|
58
|
-
|
|
58
|
+
c7.interceptors.response.use((response) => {
|
|
59
59
|
PLVLogger.info(TAG, `<-- ${response.status} ${this.method} ${this.baseURL}${response.config.url}${PLVNetUtils.formatParams(config?.params)} (${response.performanceTiming?.totalTiming}ms)`);
|
|
60
60
|
PLVLogger.info(TAG, `Header: ${PLVJSONUtils.safeStringify(response.headers)}`);
|
|
61
61
|
PLVLogger.info(TAG, `Result: ${PLVJSONUtils.safeStringify(response.data)}`);
|
|
62
62
|
if (config?.aesDecrypted) {
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
|
|
63
|
+
const d7 = response.data;
|
|
64
|
+
if (d7) {
|
|
65
|
+
d7['data'] = PLVJSONUtils.safeParse(PLVRequestSetting.decryptDataSync(d7['data']));
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
68
|
PLVLogger.printError(TAG, 'response error', new Error('jsonData undefined'));
|
|
@@ -81,23 +81,23 @@ export class PLVHttpRequest {
|
|
|
81
81
|
}, (error) => {
|
|
82
82
|
return Promise.reject(error);
|
|
83
83
|
});
|
|
84
|
-
return
|
|
84
|
+
return c7;
|
|
85
85
|
}
|
|
86
86
|
request(p) {
|
|
87
|
-
return PLVUtils.safePromise((
|
|
87
|
+
return PLVUtils.safePromise((b7, reject) => {
|
|
88
88
|
p.then((r) => {
|
|
89
89
|
const data = r.data;
|
|
90
90
|
if (data) {
|
|
91
91
|
for (const key of Object.keys(data)) {
|
|
92
92
|
if (key == 'code' && data[key] != 200 + '') {
|
|
93
|
-
|
|
93
|
+
reject(new PLVHttpError(new AxiosError(PLVJSONUtils.safeStringify(r.data || ''), data[key], undefined, undefined, r)));
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
|
|
98
|
+
b7(r);
|
|
99
99
|
}).catch((err) => {
|
|
100
|
-
|
|
100
|
+
reject(new PLVHttpError(err));
|
|
101
101
|
});
|
|
102
102
|
});
|
|
103
103
|
}
|
|
@@ -123,7 +123,7 @@ export class PLVHttpRequest {
|
|
|
123
123
|
let cacheKey = this.baseURL + '' + config?.url;
|
|
124
124
|
const params = config?.params;
|
|
125
125
|
const data = config?.data;
|
|
126
|
-
const
|
|
126
|
+
const a7 = (record) => {
|
|
127
127
|
if (record) {
|
|
128
128
|
for (const key of Object.keys(record)) {
|
|
129
129
|
if (key == 'timestamp' || key == 'sign' || key == 'token' || key == 'viewerToken') {
|
|
@@ -138,8 +138,8 @@ export class PLVHttpRequest {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
a7(params);
|
|
142
|
+
a7(data);
|
|
143
143
|
return cacheKey;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
@@ -2,23 +2,23 @@ import buffer from "@ohos.buffer";
|
|
|
2
2
|
import { CryptoJS } from '@ohos/crypto-js';
|
|
3
3
|
export class PLVRequestSetting {
|
|
4
4
|
static createSign(map, key) {
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
return
|
|
5
|
+
const j7 = key + PLVRequestSetting.concatParams(map) + key;
|
|
6
|
+
const k7 = CryptoJS.MD5(j7).toString().toUpperCase();
|
|
7
|
+
return k7;
|
|
8
8
|
}
|
|
9
9
|
static decryptDataSync(data) {
|
|
10
|
-
const
|
|
10
|
+
const i7 = CryptoJS.AES.decrypt(buffer.from(data, 'base64').toString('hex'), CryptoJS.enc.Utf8.parse(PLVRequestSetting.DECRYPT_KEY_1_SRC), {
|
|
11
11
|
format: CryptoJS.format.Hex,
|
|
12
12
|
iv: CryptoJS.enc.Utf8.parse(PLVRequestSetting.DECRYPT_KEY_2_SRC),
|
|
13
13
|
mode: CryptoJS.mode.CBC,
|
|
14
14
|
padding: CryptoJS.pad.Pkcs7
|
|
15
15
|
}).toString(CryptoJS.enc.Utf8);
|
|
16
|
-
return
|
|
16
|
+
return i7;
|
|
17
17
|
}
|
|
18
18
|
static concatParams(map) {
|
|
19
|
-
const
|
|
19
|
+
const h7 = Array.from(map.keys()).sort();
|
|
20
20
|
const builder = [];
|
|
21
|
-
for (const key of
|
|
21
|
+
for (const key of h7) {
|
|
22
22
|
if (!key || !map.get(key)) {
|
|
23
23
|
continue;
|
|
24
24
|
}
|
|
@@ -3,23 +3,24 @@ export declare class PLVSocketIO {
|
|
|
3
3
|
private client;
|
|
4
4
|
protected socketIOStatus: PLVSocketIOStatus;
|
|
5
5
|
protected onSocketIOStatusListener?: PLVCallback<PLVSocketIOStatus, void>;
|
|
6
|
+
protected isTokenExpired: boolean;
|
|
6
7
|
private set_open_listener;
|
|
7
|
-
protected set_fail_listener(
|
|
8
|
-
protected set_reconnecting_listener(
|
|
8
|
+
protected set_fail_listener(h8: () => void): void;
|
|
9
|
+
protected set_reconnecting_listener(g8: () => void): void;
|
|
9
10
|
private set_reconnect_listener;
|
|
10
|
-
protected set_close_listener(
|
|
11
|
-
protected set_socket_open_listener(
|
|
12
|
-
protected set_socket_close_listener(
|
|
11
|
+
protected set_close_listener(e8: (reason: string) => void): void;
|
|
12
|
+
protected set_socket_open_listener(d8: (nsp: string) => void): void;
|
|
13
|
+
protected set_socket_close_listener(c8: (nsp: string) => void): void;
|
|
13
14
|
protected connect(uri: string): void;
|
|
14
|
-
protected connectWithQuery(uri: string, query: string,
|
|
15
|
+
protected connectWithQuery(uri: string, query: string, b8: string): void;
|
|
15
16
|
connected(): boolean;
|
|
16
|
-
disconnect(
|
|
17
|
-
destroy(
|
|
17
|
+
disconnect(a8?: boolean): void;
|
|
18
|
+
destroy(z7?: boolean): void;
|
|
18
19
|
protected clear_con_listeners(): void;
|
|
19
20
|
protected clear_socket_listeners(): void;
|
|
20
|
-
protected set_reconnect_attempts(
|
|
21
|
-
protected set_reconnect_delay(
|
|
22
|
-
protected set_reconnect_delay_max(
|
|
21
|
+
protected set_reconnect_attempts(y7: number): void;
|
|
22
|
+
protected set_reconnect_delay(x7: number): void;
|
|
23
|
+
protected set_reconnect_delay_max(w7: number): void;
|
|
23
24
|
protected set_logs_default(): void;
|
|
24
25
|
protected set_logs_quiet(): void;
|
|
25
26
|
protected set_logs_verbose(): void;
|
|
@@ -28,16 +29,16 @@ export declare class PLVSocketIO {
|
|
|
28
29
|
protected set_proxy_basic_auth(uri: string, username: string, password: string): void;
|
|
29
30
|
private opened;
|
|
30
31
|
protected get_sessionid(): string;
|
|
31
|
-
protected set_nsp(
|
|
32
|
-
protected on(
|
|
33
|
-
protected once(
|
|
34
|
-
protected off(
|
|
32
|
+
protected set_nsp(v7: string): void;
|
|
33
|
+
protected on(t7: string, u7: (event_json: string) => void): void;
|
|
34
|
+
protected once(r7: string, s7: (event_json: string) => void): void;
|
|
35
|
+
protected off(q7: string): void;
|
|
35
36
|
protected off_all(): void;
|
|
36
37
|
private socket_close;
|
|
37
|
-
protected on_error(
|
|
38
|
+
protected on_error(p7: (message: string) => void): void;
|
|
38
39
|
protected off_error(): void;
|
|
39
|
-
protected emitSkipCheck(name: string, message: ESObject,
|
|
40
|
-
emit(name: string, message: ESObject,
|
|
40
|
+
protected emitSkipCheck(name: string, message: ESObject, o7?: (emit_callback_json: string) => void): void;
|
|
41
|
+
emit(name: string, message: ESObject, n7?: (emit_callback_json: string) => void): boolean;
|
|
41
42
|
private replaceJson;
|
|
42
43
|
}
|
|
43
44
|
export declare enum PLVSocketIOStatus {
|