Fixed some stability issues when connecting
This commit is contained in:
parent
1e285cc029
commit
3ee51b45ae
@ -196,7 +196,7 @@ export class Bot extends EventEmitter<
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
resolve(this.connect().then(() => this.send(name, ...args)))
|
this.connect().then(() => this.send(name, ...args)).catch(reject).then(resolve)
|
||||||
}, 1000)
|
}, 1000)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -251,11 +251,11 @@ export class Bot extends EventEmitter<
|
|||||||
|
|
||||||
this.#ws = null
|
this.#ws = null
|
||||||
this.emit("close", { code: event.code, reason: event.reason })
|
this.emit("close", { code: event.code, reason: event.reason })
|
||||||
this.#processingMessages.forEach((message) => {
|
for (const message of this.#processingMessages.values()) {
|
||||||
message.data.reject(
|
message.data.reject(
|
||||||
new ConnectionClosedError(event.code, event.reason),
|
new ConnectionClosedError(event.code, event.reason),
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
this.#processingMessages.clear()
|
this.#processingMessages.clear()
|
||||||
|
|
||||||
if (this.autoReconnect) {
|
if (this.autoReconnect) {
|
||||||
@ -270,7 +270,7 @@ export class Bot extends EventEmitter<
|
|||||||
return connectedPromise.promise
|
return connectedPromise.promise
|
||||||
},
|
},
|
||||||
100,
|
100,
|
||||||
{ leading: true, trailing: false },
|
{ leading: true, trailing: true },
|
||||||
)
|
)
|
||||||
|
|
||||||
sendMessage(channelUID: string, message: string) {
|
sendMessage(channelUID: string, message: string) {
|
||||||
@ -280,9 +280,9 @@ export class Bot extends EventEmitter<
|
|||||||
async uploadFiles(channelUID: string, ...files: File[]) {
|
async uploadFiles(channelUID: string, ...files: File[]) {
|
||||||
const imageForm = new FormData()
|
const imageForm = new FormData()
|
||||||
imageForm.append("channel_uid", channelUID)
|
imageForm.append("channel_uid", channelUID)
|
||||||
files.forEach((file) => {
|
for (const file of files) {
|
||||||
imageForm.append("files[]", file)
|
imageForm.append("files[]", file)
|
||||||
})
|
}
|
||||||
|
|
||||||
return await fetch("https://snek.molodetz.nl/drive.bin", {
|
return await fetch("https://snek.molodetz.nl/drive.bin", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
Loading…
Reference in New Issue
Block a user