Files
XCDesktop/remote/public/js/app.js
2026-03-08 01:34:54 +08:00

44 lines
1.2 KiB
JavaScript

(function() {
const password = getCookie('auth') || '';
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsHost = window.location.hostname;
const wsPort = window.location.port;
const wsUrlBase = wsPort ? `${wsProtocol}//${wsHost}:${wsPort}/ws` : `${wsProtocol}//${wsHost}/ws`;
const WS_URL = password ? `${wsUrlBase}?password=${encodeURIComponent(password)}` : wsUrlBase;
let videoPlayer = null;
let inputHandler = null;
function init() {
videoPlayer = new VideoPlayer('video-canvas', WS_URL);
videoPlayer.init();
inputHandler = new InputHandler(videoPlayer.getCanvas(), {
wsUrl: WS_URL
});
inputHandler.init();
console.log('xc-remote initialized');
}
function destroy() {
if (inputHandler) {
inputHandler.destroy();
inputHandler = null;
}
if (videoPlayer) {
videoPlayer.destroy();
videoPlayer = null;
}
}
window.addEventListener('beforeunload', destroy);
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();