Files
XCDesktop/remote/public/js/app.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2026-03-08 01:34:54 +08:00
(function() {
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsHost = window.location.hostname;
const wsPort = window.location.port;
const urlParams = new URLSearchParams(window.location.search);
const password = urlParams.get('password');
2026-03-08 01:34:54 +08:00
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();
}
})();