File size: 1,036 Bytes
d7597b3
da79dee
 
 
6a7131f
da79dee
 
6a7131f
da79dee
 
6a7131f
 
 
 
 
 
 
 
da79dee
 
 
 
 
6a7131f
 
 
 
 
 
 
 
 
 
 
da79dee
 
 
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
import React, { useEffect, useState } from 'react';
import socket from './socket';

const ProxmoxVM = ({ vmAddress }) => {
    const [vncUrl, setVncUrl] = useState('');

    useEffect(() => {
        // Emitting to fetch VM data as before
        socket.emit('fetchVmData', { vm_address: vmAddress });

        // Fetching VNC URL from your server
        // This assumes you have an endpoint that returns the noVNC URL for a given VM
        fetch(`/api/getVncUrl?vmAddress=${vmAddress}`)
            .then(response => response.json())
            .then(data => {
                setVncUrl(data.vncUrl);
            });

        return () => {
            socket.off('vmData');
        };
    }, [vmAddress]);

    return (
        <div>
            {vncUrl && (
                <iframe
                    src={vncUrl}
                    style={{ width: '100%', height: '400px', border: 'none' }}
                    title="VM noVNC View"
                ></iframe>
            )}
        </div>
    );
};

export default ProxmoxVM;