added ClientWSInterface

This commit is contained in:
srgooglo 2022-02-21 09:45:23 +01:00
parent a5281898ac
commit f22a488d49

View File

@ -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
}
}