funky reconnect when losing internet

This commit is contained in:
DeSqBlocki
2025-02-10 17:27:53 +01:00
parent 96af757961
commit 0ca35deb6e
2 changed files with 9 additions and 10 deletions
+5
View File
@@ -12,6 +12,7 @@ module.exports = {
name: 'Twitch/EventSub',
once: false,
async execute() {
console.log('Starting Event Subs...')
const endpoint = `wss://eventsub.wss.twitch.tv/ws`
const db = mClient.db('clients')
@@ -38,6 +39,9 @@ module.exports = {
}
function onDisconnect(reason) {
console.log(`Disconnecting due to reason`, reason)
if(connection.readyState === connection.OPEN){
connection.close(4003, 'manual disconnect')
}
}
function connect() {
connection = new ReconnectingWebSocket(endpoint, [], {
@@ -88,6 +92,7 @@ module.exports = {
subscriptionPayload, {
headers: headers
})
console.log(res)
console.log(`Subscribed to ${type}`)
subscribedEvents[type] = listener
return true