mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
added ClientWSInterface
This commit is contained in:
parent
a5281898ac
commit
f22a488d49
25
src/classes/ClientWSInterface/index.js
Normal file
25
src/classes/ClientWSInterface/index.js
Normal 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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user