chore: cleanup unused elements
This commit is contained in:
156
lib/WetSock/Client/Assets/index.html
Normal file
156
lib/WetSock/Client/Assets/index.html
Normal file
@@ -0,0 +1,156 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>WetSock Client Test</title>
|
||||
<style>
|
||||
/* Add some basic styling */
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
font-size: 16px;
|
||||
margin: 20px;
|
||||
}
|
||||
input, button {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
#output {
|
||||
border: 1px solid #ccc;
|
||||
padding: 10px;
|
||||
height: 300px;
|
||||
overflow-y: scroll;
|
||||
letter-spacing: 0.125em;
|
||||
font-size: 1rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>WetSock Client Test</h1>
|
||||
|
||||
<div>
|
||||
<label for="pluginIdentifier">Plugin:</label>
|
||||
<select id="pluginIdentifier">
|
||||
<!-- Options will be populated dynamically -->
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="actionName">Action:</label>
|
||||
<select id="actionName">
|
||||
<!-- Options will be populated dynamically -->
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="entityId">Entity ID:</label>
|
||||
<input type="text" id="entityId">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="args">Arguments (comma-separated):</label>
|
||||
<input type="text" id="args">
|
||||
</div>
|
||||
|
||||
<button id="sendButton">Send</button>
|
||||
|
||||
<h2>Output:</h2>
|
||||
<pre id="output"></pre>
|
||||
|
||||
<script type="module">
|
||||
import WetSockClient from './client.js';
|
||||
|
||||
const url = new URL(window.location.href);
|
||||
const wetsockAddr = [
|
||||
url.protocol.startsWith('https') ? 'wss' : 'ws',
|
||||
'://',
|
||||
url.host,
|
||||
'/chat'
|
||||
].join('');
|
||||
const client = new WetSockClient(wetsockAddr);
|
||||
const pluginIdentifierSelect = document.getElementById('pluginIdentifier');
|
||||
const actionNameSelect = document.getElementById('actionName');
|
||||
const entityIdInput = document.getElementById('entityId');
|
||||
const argsInput = document.getElementById('args');
|
||||
const sendButton = document.getElementById('sendButton');
|
||||
const outputDiv = document.getElementById('output');
|
||||
|
||||
client.on('message', (message) => {
|
||||
log(message);
|
||||
});
|
||||
|
||||
client.on('connected', () => {
|
||||
log('Connected to WetSock server');
|
||||
});
|
||||
|
||||
client.on('plugins', (plugins) => {
|
||||
updatePluginOptions(plugins);
|
||||
});
|
||||
|
||||
client.on('done', (data) => {
|
||||
log(`Action performed: ${JSON.stringify(data)}`);
|
||||
});
|
||||
|
||||
client.on('created', (data) => {
|
||||
log(`Entity created: ${JSON.stringify(data)}`);
|
||||
});
|
||||
|
||||
sendButton.addEventListener('click', () => {
|
||||
const pluginIdentifier = pluginIdentifierSelect.value;
|
||||
const actionName = actionNameSelect.value;
|
||||
const entityId = entityIdInput.value;
|
||||
const args = argsInput.value.split(',').map(arg => arg.trim());
|
||||
|
||||
client.send(JSON.stringify({
|
||||
action: [
|
||||
actionName ? `/${actionName}` : null,
|
||||
entityId ?? null
|
||||
].filter(v => !!v).join('.'),
|
||||
message: String(args.length > 0 ? args.join(' ') : pluginIdentifier),
|
||||
}));
|
||||
});
|
||||
|
||||
function addOptionElement(el, config = { value: '', identifier: 'select...' }) {
|
||||
const opt = document.createElement('option');
|
||||
opt.setAttribute('value', config.value);
|
||||
opt.textContent = config.identifier;
|
||||
el.appendChild(opt);
|
||||
}
|
||||
|
||||
function updatePluginOptions(plugins) {
|
||||
pluginIdentifierSelect.innerHTML = '';
|
||||
addOptionElement(pluginIdentifierSelect);
|
||||
plugins.forEach((plugin) => {
|
||||
addOptionElement(pluginIdentifierSelect, {
|
||||
value: plugin.identifier,
|
||||
identifier: plugin.identifier
|
||||
});
|
||||
});
|
||||
updateActionOptions();
|
||||
}
|
||||
|
||||
function updateActionOptions() {
|
||||
const pluginIdentifier = pluginIdentifierSelect.value;
|
||||
const actions = client.plugins.get(pluginIdentifier);
|
||||
actionNameSelect.innerHTML = '';
|
||||
addOptionElement(actionNameSelect);
|
||||
if(!pluginIdentifier) return;
|
||||
actions.forEach((action) => {
|
||||
addOptionElement(actionNameSelect, {
|
||||
value: action,
|
||||
identifier: action
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function log(message) {
|
||||
const entry = document.createElement('div');
|
||||
entry.textContent = typeof(message) == 'string' ? message : JSON.stringify(message);
|
||||
outputDiv.appendChild(entry);
|
||||
outputDiv.scrollTop = outputDiv.scrollHeight;
|
||||
}
|
||||
|
||||
pluginIdentifierSelect.addEventListener('change', updateActionOptions);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user