chore(project) rename main directory

This commit is contained in:
Benjamin Wegener
2024-04-02 23:24:31 +00:00
parent 9147658f30
commit a12d7f3343
10 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
export default class WetSockClient {
constructor(url) {
this.socket = new WebSocket(url);
this.listeners = new Map();
this.plugins = new Map();
this.socket.onopen = () => {
console.log('Connected to WetSock server');
};
this.socket.onmessage = (event) => {
const message = JSON.parse(event.data);
this.handleMessage(message);
};
this.socket.onclose = () => {
console.log('Disconnected from WetSock server');
};
}
on(event, callback) {
if (!this.listeners.has(event)) {
this.listeners.set(event, []);
}
this.listeners.get(event).push(callback);
}
emit(event, ...args) {
const listeners = this.listeners.get(event);
if (listeners) {
listeners.forEach((listener) => listener(...args));
}
}
handleMessage(message) {
const { event, ...data } = message;
if (event === 'pluginList') {
this.updatePlugins(data.plugins);
} else {
this.emit(event, data);
}
}
updatePlugins(plugins) {
plugins.forEach((plugin) => {
this.plugins.set(plugin.identifier, plugin.actions);
});
}
send(message) {
this.socket.send(JSON.stringify(message));
}
// Generic methods for interacting with plugins
createEntity(pluginIdentifier, entityData) {
this.send({ action: 'create', pluginIdentifier, data: entityData });
}
performAction(pluginIdentifier, entityId, actionName, ...args) {
this.send({ action: 'perform', pluginIdentifier, entityId, data: { actionName, args } });
}
// Helper methods for common actions
joinRoom(roomId) {
this.performAction('room', roomId, 'join');
}
leaveRoom(roomId) {
this.performAction('room', roomId, 'leave');
}
sendMessageToRoom(roomId, message) {
this.performAction('room', roomId, 'sendMessage', message);
}
createTask(taskData) {
this.createEntity('task', taskData);
}
// ... other helper methods ...
}

View File

@@ -0,0 +1,3 @@
import WetSockClient from './WetSockClient';
export default WetSockClient;