mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
added unlisten
method
This commit is contained in:
parent
d47f07fe8b
commit
4359a1b1b3
@ -12,7 +12,8 @@ export default class ApiCore extends Core {
|
||||
this.WSInterface = {
|
||||
...this.apiBridge.wsInterface,
|
||||
request: this.WSRequest,
|
||||
listen: this.handleWSListener,
|
||||
listen: this.listenEvent,
|
||||
unlisten: this.unlistenEvent,
|
||||
mainSocketConnected: false
|
||||
}
|
||||
|
||||
@ -23,7 +24,6 @@ export default class ApiCore extends Core {
|
||||
}
|
||||
|
||||
async intialize() {
|
||||
console.log(this.apiBridge)
|
||||
this.WSInterface.sockets.main.on("authenticated", () => {
|
||||
console.debug("[WS] Authenticated")
|
||||
})
|
||||
@ -127,7 +127,7 @@ export default class ApiCore extends Core {
|
||||
await this.apiBridge.initialize()
|
||||
}
|
||||
|
||||
handleWSListener = (to, fn) => {
|
||||
listenEvent = (to, fn) => {
|
||||
if (typeof to === "undefined") {
|
||||
console.error("handleWSListener: to must be defined")
|
||||
return false
|
||||
@ -152,6 +152,29 @@ export default class ApiCore extends Core {
|
||||
})
|
||||
}
|
||||
|
||||
unlistenEvent = (to, fn) => {
|
||||
if (typeof to === "undefined") {
|
||||
console.error("handleWSListener: to must be defined")
|
||||
return false
|
||||
}
|
||||
if (typeof fn !== "function") {
|
||||
console.error("handleWSListener: fn must be function")
|
||||
return false
|
||||
}
|
||||
|
||||
let ns = "main"
|
||||
let event = null
|
||||
|
||||
if (typeof to === "string") {
|
||||
event = to
|
||||
} else if (typeof to === "object") {
|
||||
ns = to.ns
|
||||
event = to.event
|
||||
}
|
||||
|
||||
return window.app.ws.sockets[ns].removeListener(event, fn)
|
||||
}
|
||||
|
||||
WSRequest = (socket = "main", channel, ...args) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const request = await window.app.ws.sockets[socket].emit(channel, ...args)
|
||||
|
Loading…
x
Reference in New Issue
Block a user