Initial commit
This commit is contained in:
43
remote/public/js/app.js
Normal file
43
remote/public/js/app.js
Normal file
@@ -0,0 +1,43 @@
|
||||
(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();
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user