diff --git a/src/classes/ClientWSInterface/index.js b/src/classes/ClientWSInterface/index.js new file mode 100644 index 0000000..ea5d5e4 --- /dev/null +++ b/src/classes/ClientWSInterface/index.js @@ -0,0 +1,25 @@ +import io from "socket.io-client" + +module.exports = class WSInterface { + constructor(params = {}) { + this.params = params + this.manager = new io.Manager(this.params.origin, { + autoConnect: true, + transports: ["websocket"], + ...this.params.managerOptions, + }) + this.sockets = {} + + this.register("/", "main") + } + + register = (socket, as) => { + if (typeof socket !== "string") { + console.error("socket must be string") + return false + } + + socket = this.manager.socket(socket) + return this.sockets[as ?? socket] = socket + } +} \ No newline at end of file