import React, { useState, useEffect } from "react";
import XmlPanel from "./XmlPanel";
import mediator from "./mediator";
import axios from "axios";

// const defaulturl = `http://47.111.130.18:48088`;
const defaultValue = {
  host: "106.75.231.63",
  port: "2021",
  ws_url: "wss://pre-webssh.educoder.net/ws",
  username: "root",
  secret: "Dron_123123",
};
function Index() {
  const [sshConfigData, setSshConfigData] = useState(undefined);

  useEffect(() => {
    if (!sshConfigData) {
      init();
    }
    setTimeout(() => {
      mediator.publish("create-socket", 1);
    }, 300);
  }, [sshConfigData]);

  // 获取服务器连接信息
  function init() {
    const url = `/api/ci/pipelines/ssh_server.json`;
    axios.get(url).then(result=>{
      if(result && result.data){
        setSshConfigData({...result.data})
      }
    }).catch(error=>{})
  }
  return (
    <XmlPanel
      sshConfigData={sshConfigData||{}}
      sid={1}
    />
  );
}
export default Index;
