HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/glive/client.js
// client.js

let pc = null;
let localStream = null;

const videoElement = document.getElementById('video');
const startCameraButton = document.getElementById('start-camera');
const startScreenButton = document.getElementById('start-screen');

startCameraButton.onclick = async () => {
    await startMedia('camera');
};

startScreenButton.onclick = async () => {
    await startMedia('screen');
};

 let ws = new WebSocket('ws://' + window.location.host + '/ws');

   ws.onmessage = function(event) {
       let message = JSON.parse(event.data);
       if (message.type === 'text') {
           // Display text response
           displayResponse(message.text);
       } else if (message.type === 'data') {
           // Handle binary data (e.g., audio)
           let audioData = message.data;
           // Convert base64 data to ArrayBuffer
           let audioBuffer = base64ToArrayBuffer(audioData);
           // Play or process audio data
           playAudio(audioBuffer);
       }
   };

async function startMedia(mode) {
    if (localStream) {
        // Close existing tracks
        localStream.getTracks().forEach(track => track.stop());
    }

    try {
        if (mode === 'camera') {
            localStream = await navigator.mediaDevices.getUserMedia({ video: true, audio: false });
        } else if (mode === 'screen') {
            localStream = await navigator.mediaDevices.getDisplayMedia({ video: true, audio: false });
        }

        videoElement.srcObject = localStream;

        await connect();

    } catch (e) {
        console.error('Failed to get media stream:', e);
    }
}

async function connect() {
    pc = new RTCPeerConnection();

    // Add tracks to peer connection
    localStream.getTracks().forEach(track => pc.addTrack(track, localStream));

    pc.onicecandidate = event => {
        if (event.candidate === null) {
            fetch('/offer', {
                method: 'POST',
                body: JSON.stringify(pc.localDescription),
                headers: { 'Content-Type': 'application/json' }
            }).then(response => response.json())
            .then(answer => pc.setRemoteDescription(answer))
            .catch(e => console.error(e));
        }
    };

    const offer = await pc.createOffer();
    await pc.setLocalDescription(offer);
}

function displayResponse(text) {
       // Implement this function to display the text on the web UI
       let responseElement = document.getElementById('response');
       responseElement.innerText = text;
   }

   function base64ToArrayBuffer(base64) {
       let binary_string = window.atob(base64);
       let len = binary_string.length;
       let bytes = new Uint8Array(len);
       for (var i = 0; i < len; i++) {
           bytes[i] = binary_string.charCodeAt(i);
       }
       return bytes.buffer;
   }

   function playAudio(arrayBuffer) {
       let context = new (window.AudioContext || window.webkitAudioContext)();
       context.decodeAudioData(arrayBuffer, function(buffer) {
           let source = context.createBufferSource();
           source.buffer = buffer;
           source.connect(context.destination);
           source.start(0);
       }, function(error) {
           console.error("Error decoding audio data", error);
       });
   }