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