@ray-js/ray-ipc-player 2.0.3 → 2.0.5-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.
- package/README-zh_CN.md +201 -0
- package/README.md +126 -57
- package/package.json +2 -2
package/README-zh_CN.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# ray-ipc-player
|
|
2
|
+
|
|
3
|
+
针对 ipc-player 基础能力进行封装,包含 loading、设备异常、离线等提示
|
|
4
|
+
|
|
5
|
+
### 属性
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
export type IProps = {
|
|
9
|
+
/**
|
|
10
|
+
* @description.en devId
|
|
11
|
+
* @description.zh 设备id
|
|
12
|
+
* @default ""
|
|
13
|
+
*/
|
|
14
|
+
devId: string;
|
|
15
|
+
/**
|
|
16
|
+
* @description.en onlineStatus
|
|
17
|
+
* @description.zh 设备是否在线
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
onlineStatus: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* @description.en privateState
|
|
23
|
+
* @description.zh 隐私模式
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
privateState?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @description.en defaultMute
|
|
29
|
+
* @description.zh 默认静音
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
defaultMute?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* @description.en clarity
|
|
35
|
+
* @description.zh 清晰度 normal:标清,hd:高清
|
|
36
|
+
* @default "normal"
|
|
37
|
+
*/
|
|
38
|
+
clarity?: 'normal' | 'hd';
|
|
39
|
+
/**
|
|
40
|
+
* @description.en updateLayout
|
|
41
|
+
* @description.zh 外层父节点样式变化,播放器监听不到,需要主动触发播放器视图更新,每次需要设置不同的字符串值
|
|
42
|
+
* @default ""
|
|
43
|
+
*/
|
|
44
|
+
updateLayout?: any;
|
|
45
|
+
/**
|
|
46
|
+
* @description.en onChangeStreamStatus
|
|
47
|
+
* @description.zh 通知视频流状态发生变化
|
|
48
|
+
* @default (data) => void
|
|
49
|
+
*/
|
|
50
|
+
onChangeStreamStatus?: (data) => void;
|
|
51
|
+
/**
|
|
52
|
+
* @description.en onCtx
|
|
53
|
+
* @description.zh 获取ipcPlayer实例ctx以及重试方法retry
|
|
54
|
+
* @default (playerRef) => void
|
|
55
|
+
*/
|
|
56
|
+
onCtx?: (playerRef) => void;
|
|
57
|
+
/**
|
|
58
|
+
* @description.en onInitPreview
|
|
59
|
+
* @description.zh 初始化预览成功通知
|
|
60
|
+
* @default (devId) => void
|
|
61
|
+
*/
|
|
62
|
+
onInitPreview?: (data) => void;
|
|
63
|
+
/**
|
|
64
|
+
* @description.en onPlayerTap
|
|
65
|
+
* @description.zh 播放器区域点击事件
|
|
66
|
+
* @default (devId) => void
|
|
67
|
+
*/
|
|
68
|
+
onPlayerTap?: (data) => void;
|
|
69
|
+
/**
|
|
70
|
+
* @description.en scalable
|
|
71
|
+
* @description.zh 是否可缩放
|
|
72
|
+
* @default true
|
|
73
|
+
*/
|
|
74
|
+
scalable?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* @description.en scaleMultiple
|
|
77
|
+
* @description.zh 缩放比例
|
|
78
|
+
* @default 0
|
|
79
|
+
*/
|
|
80
|
+
scaleMultiple?: number;
|
|
81
|
+
/**
|
|
82
|
+
* @description.en rotateZ
|
|
83
|
+
* @description.zh 摄像头旋转角度
|
|
84
|
+
* @default 0
|
|
85
|
+
*/
|
|
86
|
+
rotateZ?: number;
|
|
87
|
+
/**
|
|
88
|
+
* @description.en ptzControllable
|
|
89
|
+
* @description.zh 是否开启视频区云平台控制
|
|
90
|
+
* @default true
|
|
91
|
+
*/
|
|
92
|
+
ptzControllable?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* @description.en playerStyle
|
|
95
|
+
* @description.zh 播放器样式
|
|
96
|
+
* @default {}
|
|
97
|
+
*/
|
|
98
|
+
playerStyle?: {
|
|
99
|
+
bgColor?: string; // 背景底色
|
|
100
|
+
borderRadius?: number | string; // 边框圆角
|
|
101
|
+
borderStyle?: 'solid' | 'dashed'; // 边框样式
|
|
102
|
+
borderColor?: string; // 边框颜色
|
|
103
|
+
borderWidth?: string | number; // 边框宽度
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* @description.en loadText
|
|
107
|
+
* @description.zh 加载过程中的文案,可结合onChangeStreamStatus事件做文案配置
|
|
108
|
+
* @default "正在获取视频流..."
|
|
109
|
+
*/
|
|
110
|
+
loadText?: string;
|
|
111
|
+
/**
|
|
112
|
+
* @description.en extend
|
|
113
|
+
* @description.zh 扩展属性
|
|
114
|
+
* @default {}
|
|
115
|
+
*/
|
|
116
|
+
extend?: Record<string, any>;
|
|
117
|
+
};
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### onChangeStreamStatus 说明
|
|
121
|
+
|
|
122
|
+
主要暴露出拉流过程中的一些状态事件:
|
|
123
|
+
|
|
124
|
+
- -1000: 未知异常
|
|
125
|
+
|
|
126
|
+
- 1001: connect 连接成功
|
|
127
|
+
|
|
128
|
+
- -1001: connect 连接失败
|
|
129
|
+
|
|
130
|
+
- 1002: preview 成功
|
|
131
|
+
|
|
132
|
+
- -1002: preview 失败
|
|
133
|
+
|
|
134
|
+
- -1010: 网络状态不可用
|
|
135
|
+
|
|
136
|
+
- -1012: 设备被移除
|
|
137
|
+
|
|
138
|
+
- 1009: disconnect 成功
|
|
139
|
+
|
|
140
|
+
- -1009: disconnect 失败
|
|
141
|
+
|
|
142
|
+
### 用法
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
import React, { useState, useCallback } from 'react';
|
|
146
|
+
import Player from '@ray-js/ray-ipc-player';
|
|
147
|
+
import { Button, View } from '@ray-js/components';
|
|
148
|
+
|
|
149
|
+
const PlayerDemo = () => {
|
|
150
|
+
const [updateLayout, setUpdateLayout] = useState('');
|
|
151
|
+
const [state, setState] = useState({}); // player实例
|
|
152
|
+
const [playerWidth, setPlayerWidth] = useState('200px'); // player宽度
|
|
153
|
+
/** onCtx用法
|
|
154
|
+
* playerCtx.ctx: 拿到的是通过createIpcPlayerContext创建的ipc-player实例,包含预览、清晰度、静音、录像、截图等方法
|
|
155
|
+
* playerCtx.retry: 暴露出的重试方法
|
|
156
|
+
*/
|
|
157
|
+
const onCtx = playerCtx => {
|
|
158
|
+
setState(playerCtx);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// 切换清晰度
|
|
162
|
+
const handleClarity = useCallback(() => {
|
|
163
|
+
if (previewStatus) {
|
|
164
|
+
state.ctx.setClarity({
|
|
165
|
+
clarity: 'hd',
|
|
166
|
+
success: res => {
|
|
167
|
+
console.log('切换清晰度成功:', res);
|
|
168
|
+
},
|
|
169
|
+
fail: e => {
|
|
170
|
+
console.log('切换清晰度失败:', e);
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}, [previewStatus]);
|
|
175
|
+
|
|
176
|
+
const handleChangeWidth = () => {
|
|
177
|
+
setPlayerWidth(playerWidth);
|
|
178
|
+
// 更新外层父节点宽度样式时,同步通知更新播放器视图
|
|
179
|
+
setUpdateLayout(Math.random().toString());
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<View style={{ width: playerWidth }}>
|
|
184
|
+
<Player
|
|
185
|
+
devId={devId}
|
|
186
|
+
onlineStatus={true}
|
|
187
|
+
onCtx={onCtx}
|
|
188
|
+
updateLayout={updateLayout}
|
|
189
|
+
extend={{
|
|
190
|
+
soundMode: 'speaker',
|
|
191
|
+
orientation: 'vertical',
|
|
192
|
+
}}
|
|
193
|
+
/>
|
|
194
|
+
<Button onClick={() => handleClarity}>切换清晰度</Button>
|
|
195
|
+
<Button onClick={() => handleChangeWidth}>更新宽度</Button>
|
|
196
|
+
</View>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export default PlayerDemo;
|
|
201
|
+
```
|
package/README.md
CHANGED
|
@@ -1,115 +1,184 @@
|
|
|
1
1
|
# ray-ipc-player
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Encapsulates basic ipc-player capabilities, including loading, device exception, and offline prompts
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### property
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
8
|
export type IProps = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @description.en devId
|
|
11
|
+
* @default ""
|
|
12
|
+
*/
|
|
13
|
+
devId: string;
|
|
14
|
+
/**
|
|
15
|
+
* @description.en Whether the device is online
|
|
16
|
+
* @default true
|
|
17
|
+
*/
|
|
18
|
+
onlineStatus: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* @description.en Privacy mode
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
privateState?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* @description.en defaultMute
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
defaultMute?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* @description.en clarity
|
|
31
|
+
* @default "normal"
|
|
32
|
+
*/
|
|
33
|
+
clarity?: 'normal' | 'hd';
|
|
34
|
+
/**
|
|
35
|
+
* @description.en Notifying the view of updates, each time you need to set a different value
|
|
36
|
+
* @default ""
|
|
37
|
+
*/
|
|
38
|
+
updateLayout?: any;
|
|
39
|
+
/**
|
|
40
|
+
* @description.en Notifies the video stream that the state has changed
|
|
41
|
+
* @default (data) => void
|
|
42
|
+
*/
|
|
43
|
+
onChangeStreamStatus?: (data) => void;
|
|
44
|
+
/**
|
|
45
|
+
* @description.en Obtain ipcPlayer instance ctx and retry method Retry
|
|
46
|
+
* @default (playerRef) => void
|
|
47
|
+
*/
|
|
48
|
+
onCtx?: (playerRef) => void;
|
|
49
|
+
/**
|
|
50
|
+
* @description.en The initialization preview is successful
|
|
51
|
+
* @default (devId) => void
|
|
52
|
+
*/
|
|
53
|
+
onInitPreview?: (data) => void;
|
|
54
|
+
/**
|
|
55
|
+
* @description.en Click events in the player area
|
|
56
|
+
* @default (devId) => void
|
|
57
|
+
*/
|
|
58
|
+
onPlayerTap?: (data) => void;
|
|
59
|
+
/**
|
|
60
|
+
* @description.en Scalable or not
|
|
61
|
+
* @default true
|
|
62
|
+
*/
|
|
63
|
+
scalable?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* @description.en Scale of scale
|
|
66
|
+
* @default 0
|
|
67
|
+
*/
|
|
68
|
+
scaleMultiple?: number;
|
|
69
|
+
/**
|
|
70
|
+
* @description.en Camera rotation Angle
|
|
71
|
+
* @default 0
|
|
72
|
+
*/
|
|
73
|
+
rotateZ?: number;
|
|
74
|
+
/**
|
|
75
|
+
* @description.en Whether to enable the video area cradle head control
|
|
76
|
+
* @default true
|
|
77
|
+
*/
|
|
78
|
+
ptzControllable?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* @description.en playerStyle
|
|
81
|
+
* @default {}
|
|
82
|
+
*/
|
|
83
|
+
playerStyle?: {
|
|
84
|
+
bgColor?: string;
|
|
85
|
+
borderRadius?: number | string;
|
|
86
|
+
borderStyle?: 'solid' | 'dashed';
|
|
87
|
+
borderColor?: string;
|
|
88
|
+
borderWidth?: string | number;
|
|
29
89
|
};
|
|
30
|
-
|
|
31
|
-
|
|
90
|
+
/**
|
|
91
|
+
* @description.en Loading copy
|
|
92
|
+
* @default "Getting a video stream..."
|
|
93
|
+
*/
|
|
94
|
+
loadText?: string;
|
|
95
|
+
/**
|
|
96
|
+
* @description.en Extended Attributes
|
|
97
|
+
* @default {}
|
|
98
|
+
*/
|
|
99
|
+
extend?: Record<string, any>;
|
|
32
100
|
};
|
|
33
101
|
```
|
|
34
102
|
|
|
35
|
-
#### onChangeStreamStatus
|
|
103
|
+
#### onChangeStreamStatus instructions
|
|
36
104
|
|
|
37
|
-
|
|
105
|
+
It mainly exposes some status events during the pull flow: the initialization preview is successful:
|
|
38
106
|
|
|
39
|
-
- -1000:
|
|
107
|
+
- -1000: Unknown anomaly
|
|
40
108
|
|
|
41
|
-
- 1001:
|
|
109
|
+
- 1001: Connection successful
|
|
42
110
|
|
|
43
|
-
- -1001:
|
|
111
|
+
- -1001: Connection failure
|
|
44
112
|
|
|
45
|
-
- 1002: preview
|
|
113
|
+
- 1002: preview successful
|
|
46
114
|
|
|
47
|
-
- -1002: preview
|
|
115
|
+
- -1002: preview failure
|
|
48
116
|
|
|
49
|
-
- -1010:
|
|
117
|
+
- -1010: The network status is unavailable
|
|
50
118
|
|
|
51
|
-
- -1012:
|
|
119
|
+
- -1012: The device is removed.
|
|
52
120
|
|
|
53
|
-
- 1009: disconnect
|
|
121
|
+
- 1009: disconnect successful
|
|
54
122
|
|
|
55
|
-
- -1009: disconnect
|
|
123
|
+
- -1009: disconnect failure
|
|
56
124
|
|
|
57
|
-
###
|
|
125
|
+
### usage
|
|
58
126
|
|
|
59
127
|
```tsx
|
|
60
128
|
import React, { useState, useCallback } from 'react';
|
|
61
|
-
import Player from
|
|
129
|
+
import Player from '@ray-js/ray-ipc-player';
|
|
62
130
|
import { Button, View } from '@ray-js/components';
|
|
63
131
|
|
|
64
132
|
const PlayerDemo = () => {
|
|
65
133
|
const [updateLayout, setUpdateLayout] = useState('');
|
|
66
|
-
const [state, setState] = useState({});
|
|
67
|
-
const [playerWidth, setPlayerWidth] = useState('200px');
|
|
68
|
-
/** onCtx
|
|
69
|
-
* playerCtx.ctx:
|
|
70
|
-
* playerCtx.retry:
|
|
134
|
+
const [state, setState] = useState({});
|
|
135
|
+
const [playerWidth, setPlayerWidth] = useState('200px');
|
|
136
|
+
/** onCtx usage
|
|
137
|
+
* playerCtx.ctx: The instance of ipc-player,includes preview, definition, mute, video, screenshot and other methods
|
|
138
|
+
* playerCtx.retry: retry
|
|
71
139
|
*/
|
|
72
|
-
const onCtx =
|
|
73
|
-
setState(playerCtx)
|
|
74
|
-
}
|
|
140
|
+
const onCtx = playerCtx => {
|
|
141
|
+
setState(playerCtx);
|
|
142
|
+
};
|
|
75
143
|
|
|
76
|
-
//
|
|
144
|
+
// Clarity of switching
|
|
77
145
|
const handleClarity = useCallback(() => {
|
|
78
146
|
if (previewStatus) {
|
|
79
147
|
state.ctx.setClarity({
|
|
80
148
|
clarity: 'hd',
|
|
81
149
|
success: res => {
|
|
82
|
-
console.log('
|
|
150
|
+
console.log('Succeeded in switching clarity:', res);
|
|
83
151
|
},
|
|
84
152
|
fail: e => {
|
|
85
|
-
console.log('
|
|
153
|
+
console.log('Failed to switch clarity:', e);
|
|
86
154
|
},
|
|
87
155
|
});
|
|
88
156
|
}
|
|
89
|
-
}, [previewStatus])
|
|
157
|
+
}, [previewStatus]);
|
|
90
158
|
|
|
91
159
|
const handleChangeWidth = () => {
|
|
92
160
|
setPlayerWidth(playerWidth);
|
|
93
|
-
//
|
|
161
|
+
// Update the player view with a synchronous notification when the width style of the outer parent node is updated
|
|
94
162
|
setUpdateLayout(Math.random().toString());
|
|
95
|
-
}
|
|
163
|
+
};
|
|
96
164
|
|
|
97
165
|
return (
|
|
98
|
-
<View style={{width: playerWidth}}>
|
|
166
|
+
<View style={{ width: playerWidth }}>
|
|
99
167
|
<Player
|
|
100
168
|
devId={devId}
|
|
169
|
+
onlineStatus={true}
|
|
101
170
|
onCtx={onCtx}
|
|
102
171
|
updateLayout={updateLayout}
|
|
103
172
|
extend={{
|
|
104
173
|
soundMode: 'speaker',
|
|
105
|
-
orientation: 'vertical'
|
|
174
|
+
orientation: 'vertical',
|
|
106
175
|
}}
|
|
107
176
|
/>
|
|
108
|
-
<Button onClick={() => handleClarity}
|
|
109
|
-
<Button onClick={() => handleChangeWidth}
|
|
177
|
+
<Button onClick={() => handleClarity}>Clarity of switching</Button>
|
|
178
|
+
<Button onClick={() => handleChangeWidth}>Update the width</Button>
|
|
110
179
|
</View>
|
|
111
|
-
)
|
|
112
|
-
}
|
|
180
|
+
);
|
|
181
|
+
};
|
|
113
182
|
|
|
114
183
|
export default PlayerDemo;
|
|
115
184
|
```
|