This repository has been archived on 2023-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
gameserver/website/js/xonotic.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-02-02 03:36:29 +01:00
function xonotic_init() {
const command_form = document.getElementById('xonotic_form');
const command_input = document.getElementById('xonotic_command');
// Connect the command submission
if(command_input && command_form) {
command_form.addEventListener('submit', function(){
let line = document.createElement('p')
line.innerHTML = '<span class="TERM_FOREGROUND_7_INTENSE">$ </span>' + command_input.value;
xonotic_output.prepend(line);
socket.send(command_input.value);
command_input.value = "";
});
}
// Create WebSocket connection.
const socket = new WebSocket("ws://192.168.122.229/xonotic")
// Connection opened
socket.addEventListener('open', function (event) {
2022-02-04 01:50:55 +01:00
socket.send('who');
2022-02-02 03:36:29 +01:00
});
// Listen for messages
socket.addEventListener('message', function (event) {
const xonotic_output = document.getElementById('xonotic_output');
let line = document.createElement('p')
2022-02-04 01:50:55 +01:00
line.innerHTML = convertTerminalCodeToHtml(event.data);
2022-02-02 03:36:29 +01:00
xonotic_output.prepend(line);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', xonotic_init);
} else {
xonotic_init();
}