Spaces:
Configuration error
Configuration error
zack
commited on
Commit
Β·
d7597b3
1
Parent(s):
f638612
π feat: enhance Proxmox component with new socket logic
Browse files
frontend/src/components/Proxmox/proxmox.js
CHANGED
|
@@ -1,25 +1,13 @@
|
|
| 1 |
-
import React, { useEffect,
|
| 2 |
-
import { Terminal } from 'xterm';
|
| 3 |
-
import 'xterm/css/xterm.css';
|
| 4 |
import socket from './socket';
|
| 5 |
|
| 6 |
const ProxmoxVM = ({ vmAddress }) => {
|
| 7 |
-
const terminalRef = useRef(null);
|
| 8 |
-
const terminal = useRef(new Terminal());
|
| 9 |
const [vncUrl, setVncUrl] = useState('');
|
| 10 |
|
| 11 |
useEffect(() => {
|
| 12 |
-
terminal.current.open(terminalRef.current);
|
| 13 |
-
terminal.current.writeln('Connecting to VM...');
|
| 14 |
-
|
| 15 |
// Emitting to fetch VM data as before
|
| 16 |
socket.emit('fetchVmData', { vm_address: vmAddress });
|
| 17 |
|
| 18 |
-
// Listening for VM data to write to the terminal
|
| 19 |
-
socket.on('vmData', (data) => {
|
| 20 |
-
terminal.current.writeln(data);
|
| 21 |
-
});
|
| 22 |
-
|
| 23 |
// Fetching VNC URL from your server
|
| 24 |
// This assumes you have an endpoint that returns the noVNC URL for a given VM
|
| 25 |
fetch(`/api/getVncUrl?vmAddress=${vmAddress}`)
|
|
@@ -30,13 +18,11 @@ const ProxmoxVM = ({ vmAddress }) => {
|
|
| 30 |
|
| 31 |
return () => {
|
| 32 |
socket.off('vmData');
|
| 33 |
-
terminal.current.dispose();
|
| 34 |
};
|
| 35 |
}, [vmAddress]);
|
| 36 |
|
| 37 |
return (
|
| 38 |
<div>
|
| 39 |
-
<div ref={terminalRef} />
|
| 40 |
{vncUrl && (
|
| 41 |
<iframe
|
| 42 |
src={vncUrl}
|
|
|
|
| 1 |
+
import React, { useEffect, useState } from 'react';
|
|
|
|
|
|
|
| 2 |
import socket from './socket';
|
| 3 |
|
| 4 |
const ProxmoxVM = ({ vmAddress }) => {
|
|
|
|
|
|
|
| 5 |
const [vncUrl, setVncUrl] = useState('');
|
| 6 |
|
| 7 |
useEffect(() => {
|
|
|
|
|
|
|
|
|
|
| 8 |
// Emitting to fetch VM data as before
|
| 9 |
socket.emit('fetchVmData', { vm_address: vmAddress });
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
// Fetching VNC URL from your server
|
| 12 |
// This assumes you have an endpoint that returns the noVNC URL for a given VM
|
| 13 |
fetch(`/api/getVncUrl?vmAddress=${vmAddress}`)
|
|
|
|
| 18 |
|
| 19 |
return () => {
|
| 20 |
socket.off('vmData');
|
|
|
|
| 21 |
};
|
| 22 |
}, [vmAddress]);
|
| 23 |
|
| 24 |
return (
|
| 25 |
<div>
|
|
|
|
| 26 |
{vncUrl && (
|
| 27 |
<iframe
|
| 28 |
src={vncUrl}
|