1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* @Author: 634665781 634665781@qq.com
* @Date: 2023-04-06 11:18:25
* @LastEditors: 634665781 634665781@qq.com
* @LastEditTime: 2023-04-12 14:29:59
* @FilePath: \ui\src\components\VideoEsy\index.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import EZUIKit, { log } from 'ezuikit-js';
import React, { useState, useRef, useEffect, useImperativeHandle, forwardRef } from 'react';
import axios from 'axios';
const VideoEsy = (props, ref) => {
const _video1 = useRef(null);
//console.log(props,'props');
const { appKey, appSecret, key } = props.VideoInfo;
const [jessibuca, setPlayers] = useState(null);
const getToken = async () => {
axios
.post(
`https://open.ys7.com/api/lapp/token/get?appKey=${appKey}&appSecret=${appSecret}`,
{},
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
},
)
.then(function (response) {
let accessToken = response.data.data.accessToken;
let PlayersA = new EZUIKit.EZUIKitPlayer({
id: 'video-container', // 视频容器ID
accessToken: accessToken,
url: `ezopen://open.ys7.com/${key}/1.hd.live`,
});
setPlayers(PlayersA);
useImperativeHandle(props.Appref, () => {
// changeVal 就是暴露给父组件的方法, newVal是父组件传递的参数
return jessibuca; // _video&& _video.current&&_video.current.jessibuca
});
})
.catch(function (error) {
console.log(error);
});
};
useEffect(() => {
getToken();
}, []);
return <div id="video-container"></div>;
};
const $VideoEsy = forwardRef(VideoEsy);
export default $VideoEsy;