/*
 * @Author: 634665781 634665781@qq.com
 * @Date: 2023-04-06 11:18:25
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-03-17 15:33:29
 * @FilePath: \wisdom-components\packages\base-components\VmsVideo\src\VideoEsy\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { EZUIKitPlayer } 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 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;
