@ray-js/ipc-player-integration 0.0.1-beta-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 (108) hide show
  1. package/README.md +32 -0
  2. package/lib/core.d.ts +0 -0
  3. package/lib/core.js +0 -0
  4. package/lib/ctx/ctx.composition.d.ts +1 -0
  5. package/lib/ctx/ctx.composition.js +38 -0
  6. package/lib/ctx/ctx.d.ts +10 -0
  7. package/lib/ctx/ctx.js +159 -0
  8. package/lib/ctx/ctx.test.d.ts +1 -0
  9. package/lib/ctx/ctx.test.js +95 -0
  10. package/lib/ctx/index.d.ts +2 -0
  11. package/lib/ctx/index.js +2 -0
  12. package/lib/ctx/ports.output.d.ts +1 -0
  13. package/lib/ctx/ports.output.js +1 -0
  14. package/lib/ctx/useCtx.d.ts +0 -0
  15. package/lib/ctx/useCtx.js +0 -0
  16. package/lib/hooks/index.d.ts +5 -0
  17. package/lib/hooks/index.js +5 -0
  18. package/lib/hooks/useBattery/index.d.ts +2 -0
  19. package/lib/hooks/useBattery/index.js +17 -0
  20. package/lib/hooks/useDpState/index.d.ts +1 -0
  21. package/lib/hooks/useDpState/index.js +1 -0
  22. package/lib/hooks/useDpState/useDpState.d.ts +6 -0
  23. package/lib/hooks/useDpState/useDpState.js +79 -0
  24. package/lib/hooks/useHumidity/index.d.ts +1 -0
  25. package/lib/hooks/useHumidity/index.js +16 -0
  26. package/lib/hooks/useMuted/index.d.ts +1 -0
  27. package/lib/hooks/useMuted/index.js +3 -0
  28. package/lib/hooks/useTemperature/index.d.ts +5 -0
  29. package/lib/hooks/useTemperature/index.js +30 -0
  30. package/lib/hooks/useVideoBitKbps/index.d.ts +1 -0
  31. package/lib/hooks/useVideoBitKbps/index.js +44 -0
  32. package/lib/iconfont/demo.css +539 -0
  33. package/lib/iconfont/demo_index.html +556 -0
  34. package/lib/iconfont/iconfont.css +79 -0
  35. package/lib/iconfont/iconfont.js +42 -0
  36. package/lib/iconfont/iconfont.json +121 -0
  37. package/lib/iconfont/iconfont.ttf +0 -0
  38. package/lib/iconfont/iconfont.woff +0 -0
  39. package/lib/iconfont/iconfont.woff2 +0 -0
  40. package/lib/index.config.js +14 -0
  41. package/lib/index.d.ts +3 -0
  42. package/lib/index.js +3 -0
  43. package/lib/index.less +7 -0
  44. package/lib/interface.d.ts +59 -0
  45. package/lib/interface.js +19 -0
  46. package/lib/plugins/battery/battery.composition.d.ts +27 -0
  47. package/lib/plugins/battery/battery.composition.js +5 -0
  48. package/lib/plugins/battery/battery.d.ts +13 -0
  49. package/lib/plugins/battery/battery.js +39 -0
  50. package/lib/plugins/battery/battery.less +67 -0
  51. package/lib/plugins/battery/index.d.ts +1 -0
  52. package/lib/plugins/battery/index.js +1 -0
  53. package/lib/plugins/fullScreen/fullScreen.d.ts +6 -0
  54. package/lib/plugins/fullScreen/fullScreen.js +71 -0
  55. package/lib/plugins/fullScreen/fullScreen.less +16 -0
  56. package/lib/plugins/fullScreen/index.d.ts +1 -0
  57. package/lib/plugins/fullScreen/index.js +1 -0
  58. package/lib/plugins/fullScreen/verticalScreen.d.ts +8 -0
  59. package/lib/plugins/fullScreen/verticalScreen.js +15 -0
  60. package/lib/plugins/fullScreen/verticalScreen.less +11 -0
  61. package/lib/plugins/index.d.ts +8 -0
  62. package/lib/plugins/index.js +8 -0
  63. package/lib/plugins/muted/index.d.ts +1 -0
  64. package/lib/plugins/muted/index.js +1 -0
  65. package/lib/plugins/muted/muted.d.ts +4 -0
  66. package/lib/plugins/muted/muted.js +42 -0
  67. package/lib/plugins/muted/muted.less +5 -0
  68. package/lib/plugins/recordVideo/index.d.ts +1 -0
  69. package/lib/plugins/recordVideo/index.js +1 -0
  70. package/lib/plugins/recordVideo/recordVideo.d.ts +6 -0
  71. package/lib/plugins/recordVideo/recordVideo.js +93 -0
  72. package/lib/plugins/recordVideo/recordVideo.less +37 -0
  73. package/lib/plugins/screenshot/index.d.ts +1 -0
  74. package/lib/plugins/screenshot/index.js +1 -0
  75. package/lib/plugins/screenshot/screenshot.d.ts +6 -0
  76. package/lib/plugins/screenshot/screenshot.js +55 -0
  77. package/lib/plugins/screenshot/screenshot.less +38 -0
  78. package/lib/plugins/tempHumidity/index.d.ts +1 -0
  79. package/lib/plugins/tempHumidity/index.js +1 -0
  80. package/lib/plugins/tempHumidity/tempHumidity.d.ts +8 -0
  81. package/lib/plugins/tempHumidity/tempHumidity.js +54 -0
  82. package/lib/plugins/tempHumidity/tempHumidity.less +21 -0
  83. package/lib/plugins/videoBitKbps/index.d.ts +1 -0
  84. package/lib/plugins/videoBitKbps/index.js +1 -0
  85. package/lib/plugins/videoBitKbps/videoBitKbps.d.ts +6 -0
  86. package/lib/plugins/videoBitKbps/videoBitKbps.js +13 -0
  87. package/lib/plugins/videoBitKbps/videoBitKbps.less +11 -0
  88. package/lib/plugins/voiceIntercom/index.d.ts +1 -0
  89. package/lib/plugins/voiceIntercom/index.js +1 -0
  90. package/lib/plugins/voiceIntercom/voiceIntercom.d.ts +9 -0
  91. package/lib/plugins/voiceIntercom/voiceIntercom.js +67 -0
  92. package/lib/plugins/voiceIntercom/voiceIntercom.less +10 -0
  93. package/lib/ports.output.d.ts +6 -0
  94. package/lib/ports.output.js +1 -0
  95. package/lib/props.d.ts +14 -0
  96. package/lib/props.js +1 -0
  97. package/lib/ui/index.d.ts +1 -0
  98. package/lib/ui/index.js +1 -0
  99. package/lib/ui/ui.d.ts +21 -0
  100. package/lib/ui/ui.js +121 -0
  101. package/lib/ui/ui.less +44 -0
  102. package/lib/utils/authorize/index.d.ts +1 -0
  103. package/lib/utils/authorize/index.js +31 -0
  104. package/lib/utils/content/dpCode.d.ts +4 -0
  105. package/lib/utils/content/dpCode.js +7 -0
  106. package/lib/utils/device/index.d.ts +13 -0
  107. package/lib/utils/device/index.js +68 -0
  108. package/package.json +74 -0
package/lib/ui/ui.js ADDED
@@ -0,0 +1,121 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import React, { useRef } from 'react';
3
+ import { View, CoverView, getSystemInfoSync } from '@ray-js/ray';
4
+ import clsx from 'clsx';
5
+ import IPCPlayer from '@ray-js/ray-ipc-player';
6
+ import { PlayState, PlayerStreamStatus } from '../interface';
7
+ import { useCtx } from '../ctx/ctx.composition';
8
+ import './ui.less';
9
+ function getCtxInstance(instance, devId) {
10
+ if (instance) return instance;
11
+ return useCtx({
12
+ // eslint-disable-line
13
+ devId
14
+ });
15
+ }
16
+
17
+ // todo 提出更多 CSS变量以支持自定义样式
18
+
19
+ const defaultCSSVariable = {
20
+ '--iconColor': '#fff',
21
+ '--iconFontSize': '40rpx',
22
+ '--bg-color': '#000',
23
+ '--fontColor': '#fff'
24
+ };
25
+ export const IPCPlayerIntegration = props => {
26
+ const {
27
+ className,
28
+ devId,
29
+ style,
30
+ CSSVariable = defaultCSSVariable
31
+ } = props;
32
+ const instance = getCtxInstance(props.instance, devId);
33
+ const {
34
+ topContent,
35
+ absoluteContent,
36
+ bottomContent,
37
+ playState,
38
+ setPlayState
39
+ } = instance;
40
+ const systemInfo = useRef(null);
41
+ if (!systemInfo.current) {
42
+ systemInfo.current = getSystemInfoSync();
43
+ }
44
+
45
+ /**
46
+ * 视频流加载状态封装
47
+ */
48
+
49
+ return /*#__PURE__*/React.createElement(View, {
50
+ className: clsx('ipc-player-content', className),
51
+ style: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, defaultCSSVariable), CSSVariable), style), {}, {
52
+ height: instance.screenType === 'full' ? `${systemInfo.current.screenWidth}px` : style === null || style === void 0 ? void 0 : style.height
53
+ })
54
+ }, /*#__PURE__*/React.createElement(View, {
55
+ style: {
56
+ width: '100%',
57
+ height: '100%'
58
+ }
59
+ }, /*#__PURE__*/React.createElement(IPCPlayer, {
60
+ objectFit: "fillCrop",
61
+ defaultMute: true,
62
+ devId: devId,
63
+ onlineStatus: true,
64
+ ipcPlayerContext: instance.IPCPlayerInstance
65
+ // updateLayout={`${playerLayout}`}
66
+ ,
67
+ onChangeStreamStatus: code => {
68
+ var _props$onPlayStatus;
69
+ const playStateMap = {
70
+ [PlayerStreamStatus.PreviewSuccess]: PlayState.PLAYING,
71
+ // 播放中
72
+ [PlayerStreamStatus.PAUSE]: PlayState.PAUSE // 暂停
73
+ };
74
+ const playState = playStateMap[code];
75
+ if (typeof playState !== 'undefined') {
76
+ setPlayState(playState);
77
+ }
78
+ (_props$onPlayStatus = props.onPlayStatus) === null || _props$onPlayStatus === void 0 || _props$onPlayStatus.call(props, {
79
+ playState,
80
+ playCode: code
81
+ });
82
+ instance.changeStreamStatus(code);
83
+ }
84
+ // onCtx={getIpcPlayer}
85
+ // onPlayerTap={handlePlayerClick}
86
+ ,
87
+ clarity: "hd",
88
+ privateState: false
89
+ })), /*#__PURE__*/React.createElement(CoverView, {
90
+ style: {
91
+ height: instance.screenType === 'vertical' ? '48px' : '69px'
92
+ },
93
+ className: clsx('ipc-player-top-content', playState === PlayState.PLAYING ? 'ipc-player-element-visible' : 'ipc-player-element-hidden')
94
+ }, (() => {
95
+ if (!topContent || !(topContent !== null && topContent !== void 0 && topContent.length)) return null;
96
+ return topContent.map(item => /*#__PURE__*/React.createElement(item.content, _objectSpread(_objectSpread(_objectSpread({
97
+ key: item.id
98
+ }, item.initProps), instance), {}, {
99
+ IPCPlayerContext: instance.IPCPlayerInstance
100
+ })));
101
+ })()), /*#__PURE__*/React.createElement(CoverView, {
102
+ style: {
103
+ height: instance.screenType === 'vertical' ? '48px' : '69px'
104
+ },
105
+ className: clsx('ipc-player-bottom-content', playState === PlayState.PLAYING ? 'ipc-player-element-visible' : 'ipc-player-element-hidden')
106
+ }, (() => {
107
+ if (!bottomContent || !(bottomContent !== null && bottomContent !== void 0 && bottomContent.length)) return null;
108
+ return bottomContent.map(item => /*#__PURE__*/React.createElement(item.content, _objectSpread(_objectSpread(_objectSpread({}, item.initProps), {}, {
109
+ key: item.id
110
+ }, instance), {}, {
111
+ IPCPlayerContext: instance.IPCPlayerInstance
112
+ })));
113
+ })()), playState === PlayState.PLAYING && (() => {
114
+ if (!absoluteContent || !(absoluteContent !== null && absoluteContent !== void 0 && absoluteContent.length)) return null;
115
+ return absoluteContent.map(item => /*#__PURE__*/React.createElement(item.content, _objectSpread(_objectSpread(_objectSpread({
116
+ key: item.id
117
+ }, item.initProps), instance), {}, {
118
+ IPCPlayerContext: instance.IPCPlayerInstance
119
+ })));
120
+ })());
121
+ };
package/lib/ui/ui.less ADDED
@@ -0,0 +1,44 @@
1
+ .ipc-player-content {
2
+ position: relative;
3
+
4
+ &.ipc-player-content-full {
5
+ height: 100vw;
6
+ }
7
+
8
+ .ipc-player-top-content {
9
+ position: absolute;
10
+ width: 100%;
11
+ left: 0;
12
+ top: 0;
13
+ gap: 20rpx;
14
+ z-index: 2;
15
+ display: flex;
16
+ justify-content: flex-end;
17
+ align-items: center;
18
+ padding: 11rpx;
19
+ font-size: 24rpx;
20
+ box-sizing: border-box;
21
+ }
22
+
23
+ .ipc-player-bottom-content {
24
+ position: absolute;
25
+ z-index: 2;
26
+ display: flex;
27
+ width: 100%;
28
+ left: 0;
29
+ bottom: 0;
30
+ align-items: center;
31
+ gap: 20rpx;
32
+ padding: 11rpx;
33
+ font-size: 24rpx;
34
+ box-sizing: border-box;
35
+ }
36
+ }
37
+
38
+ .ipc-player-element-visible {
39
+ visibility: visible !important;
40
+ }
41
+
42
+ .ipc-player-element-hidden {
43
+ visibility: hidden !important;
44
+ }
@@ -0,0 +1 @@
1
+ export declare function authorizeStatus(scope: string): Promise<boolean>;
@@ -0,0 +1,31 @@
1
+ import { authorizeStatus as _authorizeStatus, authorize } from '@ray-js/ray';
2
+ const memory = {};
3
+ export function authorizeStatus(scope) {
4
+ return new Promise(resolve => {
5
+ if (memory[scope]) {
6
+ resolve(true);
7
+ return;
8
+ }
9
+ _authorizeStatus({
10
+ scope,
11
+ success: () => {
12
+ memory[scope] = true;
13
+ resolve(true);
14
+ },
15
+ fail: () => {
16
+ authorize({
17
+ scope,
18
+ success: res => {
19
+ console.log('authorize success', res);
20
+ memory[scope] = true;
21
+ resolve(true);
22
+ },
23
+ fail: err => {
24
+ console.log('authorize fail', err);
25
+ resolve(false);
26
+ }
27
+ });
28
+ }
29
+ });
30
+ });
31
+ }
@@ -0,0 +1,4 @@
1
+ export declare const TEMP_UNIT_SELECT = "temp_unit_select";
2
+ export declare const TEMP_REPORT_F = "temp_report_f";
3
+ export declare const SENSOR_TEMPERATURE = "sensor_temperature";
4
+ export declare const SENSOR_HUMIDITY = "sensor_humidity";
@@ -0,0 +1,7 @@
1
+ export const TEMP_UNIT_SELECT = 'temp_unit_select'; // 温度单位选择
2
+
3
+ export const TEMP_REPORT_F = 'temp_report_f'; // 华氏度
4
+
5
+ export const SENSOR_TEMPERATURE = 'sensor_temperature'; // 摄氏度
6
+
7
+ export const SENSOR_HUMIDITY = 'sensor_humidity'; // 湿度
@@ -0,0 +1,13 @@
1
+ export declare function getDpValue<T extends string>(options: {
2
+ devId: string;
3
+ dps: T[];
4
+ }): Promise<Record<T, number | string | boolean>>;
5
+ export interface IDpCode {
6
+ code: string;
7
+ dpId: number;
8
+ value: string;
9
+ time: number;
10
+ type: string;
11
+ }
12
+ export declare function getDpCodeObj(devId: string, dpCode: string): Promise<IDpCode | undefined>;
13
+ export declare function getDpIdsByCodes<T extends string>(devId: string, dpIds: T[]): Promise<Record<T, string>>;
@@ -0,0 +1,68 @@
1
+ import { getDpsInfos } from '@ray-js/ray';
2
+ export function getDpValue(options) {
3
+ return new Promise((resolve, reject) => {
4
+ ty.device.getDeviceInfo({
5
+ deviceId: options.devId,
6
+ success: res => {
7
+ console.log('res', res);
8
+ const {
9
+ dps
10
+ } = res;
11
+ // @ts-ignore
12
+ const ret = {};
13
+ options.dps.forEach(dpId => {
14
+ ret[dpId] = dps[dpId];
15
+ });
16
+ resolve(ret);
17
+ },
18
+ fail: err => {
19
+ reject(err); // eslint-disable-line
20
+ }
21
+ });
22
+ });
23
+ }
24
+ export function getDpCodeObj(devId, dpCode) {
25
+ return new Promise((resolve, reject) => {
26
+ getDpsInfos({
27
+ devId: devId,
28
+ gwId: devId
29
+ }).then(res => {
30
+ let result;
31
+ for (let i = 0; i < res.length; i++) {
32
+ const ele = res[i];
33
+ const {
34
+ code,
35
+ value
36
+ } = ele;
37
+ if (code === dpCode) {
38
+ result = ele;
39
+ break;
40
+ }
41
+ }
42
+ resolve(result);
43
+ }).catch(error => {
44
+ reject(error);
45
+ });
46
+ });
47
+ }
48
+ export function getDpIdsByCodes(devId) {
49
+ return new Promise((resolve, reject) => {
50
+ ty.device.getDeviceInfo({
51
+ deviceId: devId,
52
+ success: res => {
53
+ console.log('res', res);
54
+ // console.log('res', res);
55
+ // const { dps } = res;
56
+ // // @ts-ignore
57
+ // const ret: Record<T, any> = {};
58
+ // options.dps.forEach(dpId => {
59
+ // ret[dpId] = dps[dpId];
60
+ // });
61
+ // resolve(ret);
62
+ },
63
+ fail: err => {
64
+ reject(err); // eslint-disable-line
65
+ }
66
+ });
67
+ });
68
+ }
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@ray-js/ipc-player-integration",
3
+ "version": "0.0.1-beta-1",
4
+ "description": "IPC 播放器功能集成",
5
+ "main": "lib/index",
6
+ "files": [
7
+ "lib"
8
+ ],
9
+ "license": "MIT",
10
+ "types": "lib/index.d.ts",
11
+ "maintainers": [
12
+ "tuya_npm",
13
+ {
14
+ "name": "tuyafe",
15
+ "email": "tuyafe@tuya.com"
16
+ }
17
+ ],
18
+ "scripts": {
19
+ "lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
20
+ "build": "ray build --type=component",
21
+ "watch": "ray start --type=component --output ./example/src/lib",
22
+ "build:tuya": "ray build -t tuya ./example",
23
+ "build:wechat": "ray build ./example --target=wechat",
24
+ "build:web": "ray build ./example --target=web",
25
+ "build:native": "ray build ./example --target=native",
26
+ "start:native": "ray start ./example -t native --verbose",
27
+ "start:tuya": "ray start -t tuya ./example --bundler=webpack",
28
+ "start:wechat": "ray start ./example -t wechat --verbose",
29
+ "start:web": "ray start ./example -t web",
30
+ "prepublishOnly": "yarn build",
31
+ "release-it": "standard-version",
32
+ "test": "yarn jest"
33
+ },
34
+ "peerDependencies": {
35
+ "@ray-js/ray": "^1.4.9"
36
+ },
37
+ "dependencies": {
38
+ "@ray-js/ray-ipc-player": "2.0.17-beta-beta-1",
39
+ "clsx": "^1.2.1"
40
+ },
41
+ "devDependencies": {
42
+ "@commitlint/cli": "^7.2.1",
43
+ "@commitlint/config-conventional": "^9.0.1",
44
+ "@ray-js/cli": "^1.4.9",
45
+ "@ray-js/panel-sdk": "^1.13.0-storage.7",
46
+ "@ray-js/ray": "^1.4.9",
47
+ "@testing-library/react-hooks": "^8.0.1",
48
+ "@types/jest": "^29.5.14",
49
+ "core-js": "^3.19.1",
50
+ "eslint-config-tuya-panel": "^0.4.2",
51
+ "husky": "^1.2.0",
52
+ "lint-staged": "^10.2.11",
53
+ "standard-version": "9.3.2"
54
+ },
55
+ "resolutions": {
56
+ "@ray-js/builder-mp": "1.4.15"
57
+ },
58
+ "husky": {
59
+ "hooks": {
60
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS --config commitlint.config.js",
61
+ "pre-commit": "lint-staged"
62
+ }
63
+ },
64
+ "lint-staged": {
65
+ "*.{ts,tsx,js,jsx}": [
66
+ "eslint --fix",
67
+ "git add"
68
+ ],
69
+ "*.{json,md,yml,yaml}": [
70
+ "prettier --write",
71
+ "git add"
72
+ ]
73
+ }
74
+ }