
    <h1>Random Webcam and Microphone Connection</h1>
    
    <!-- Video display area -->
    <div id="video-container">
        <video id="local-video" autoplay muted></video>
        <video id="remote-video" autoplay></video>
    </div>
    
    <!-- Skip button -->
    <button id="skip-button">Skip</button>

    <script>
        const localVideo = document.getElementById('local-video');
        const remoteVideo = document.getElementById('remote-video');
        const skipButton = document.getElementById('skip-button');
        let localStream;
        let peerConnection;

        // Get user media for webcam and microphone
        async function getUserMedia() {
            try {
                localStream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
                localVideo.srcObject = localStream;
            } catch (error) {
                console.error('Error accessing webcam and microphone:', error);
            }
        }

        // Create and configure peer connection
        function createPeerConnection() {
            peerConnection = new RTCPeerConnection();

            // Add the local stream to the peer connection
            localStream.getTracks().forEach((track) => {
                peerConnection.addTrack(track, localStream);
            });

            // Set up event handlers for peer connection

            // Handle incoming video stream
            peerConnection.ontrack = (event) => {
                remoteVideo.srcObject = event.streams[0];
            };

            // Handle ICE candidate events
            peerConnection.onicecandidate = (event) => {
                if (event.candidate) {
                    // Send the ICE candidate to the other peer (not shown in this example)
                }
            };
        }

        // Function to initiate the connection
        function startConnection() {
            getUserMedia();
            createPeerConnection();
            // Code to find and connect to another random user (not shown in this example)
        }

        // Function to skip and connect to another random user
        function skipConnection() {
            // Code to disconnect from the current user and find another random user (not shown in this example)
        }

        // Event listener for the skip button
        skipButton.addEventListener('click', skipConnection);

        // Start the initial connection
        startConnection();
    </script>