mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 18:44:17 +00:00
reimplement attach
detach
methods
This commit is contained in:
parent
0d29a6d597
commit
1614d80ab0
@ -4,22 +4,40 @@ module.exports = class WSInterface {
|
|||||||
constructor(params = {}) {
|
constructor(params = {}) {
|
||||||
this.params = params
|
this.params = params
|
||||||
this.manager = new io.Manager(this.params.origin, {
|
this.manager = new io.Manager(this.params.origin, {
|
||||||
autoConnect: true,
|
autoConnect: false,
|
||||||
transports: ["websocket"],
|
transports: ["websocket"],
|
||||||
...this.params.managerOptions,
|
...this.params.managerOptions,
|
||||||
})
|
})
|
||||||
this.sockets = {}
|
this.sockets = {}
|
||||||
|
|
||||||
this.register("/", "main")
|
this.attach("/", "main", this.params.mainSocketOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
register = (socket, as) => {
|
attach = (socket, as, options) => {
|
||||||
if (typeof socket !== "string") {
|
if (typeof socket !== "string") {
|
||||||
console.error("socket must be string")
|
console.error("socket must be string")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
socket = this.manager.socket(socket)
|
socket = this.manager.socket(socket, options)
|
||||||
|
|
||||||
return this.sockets[as ?? socket] = socket
|
return this.sockets[as ?? socket] = socket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
detach = (socketName) => {
|
||||||
|
if (typeof socketName !== "string") {
|
||||||
|
console.error("socketName must be string")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (typeof this.sockets[socketName] === "undefined") {
|
||||||
|
console.error("socket not found")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.sockets[socketName].connected) {
|
||||||
|
this.sockets[socketName].disconnect()
|
||||||
|
}
|
||||||
|
|
||||||
|
delete this.sockets[socketName]
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user