mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
added measurePing
method
This commit is contained in:
parent
63ec7daa7a
commit
8b83fb0ab1
@ -70,6 +70,7 @@ export default class ApiCore extends Core {
|
||||
autenticateWS: this.autenticateWS.bind(this),
|
||||
listenEvent: this.listenEvent.bind(this),
|
||||
unlistenEvent: this.unlistenEvent.bind(this),
|
||||
measurePing: this.measurePing.bind(this),
|
||||
}
|
||||
|
||||
async attach() {
|
||||
@ -298,4 +299,56 @@ export default class ApiCore extends Core {
|
||||
token,
|
||||
})
|
||||
}
|
||||
|
||||
async measurePing() {
|
||||
const timings = {}
|
||||
|
||||
const promises = [
|
||||
new Promise(async (resolve) => {
|
||||
const start = Date.now()
|
||||
|
||||
this.customRequest({
|
||||
method: "GET",
|
||||
url: "/ping",
|
||||
})
|
||||
.then(() => {
|
||||
// set http timing in ms
|
||||
timings.http = Date.now() - start
|
||||
|
||||
resolve()
|
||||
})
|
||||
.catch(() => {
|
||||
timings.http = "failed"
|
||||
resolve()
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
timings.http = "failed"
|
||||
|
||||
resolve()
|
||||
}, 10000)
|
||||
}),
|
||||
new Promise((resolve) => {
|
||||
const start = Date.now()
|
||||
|
||||
this.instance.wsInterface.sockets["main"].on("pong", () => {
|
||||
timings.ws = Date.now() - start
|
||||
|
||||
resolve()
|
||||
})
|
||||
|
||||
this.instance.wsInterface.sockets["main"].emit("ping")
|
||||
|
||||
setTimeout(() => {
|
||||
timings.ws = "failed"
|
||||
|
||||
resolve()
|
||||
}, 10000)
|
||||
})
|
||||
]
|
||||
|
||||
await Promise.all(promises)
|
||||
|
||||
return timings
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user