diff --git a/src/Client.ts b/src/Client.ts index a5a0528..4072a97 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -343,14 +343,7 @@ export class Client { this.sendMessage(this.server.name, 'NOTICE', [this.user.nick, 'You are now synced to the network!'], message.tags); this.user.addClient(this, message.tags); }).catch(function (error) { - if (error.response) { - console.log(error.response.data); - } else if (error.request) { - console.log(error.request); - } else { - console.log('Error', error.message); - console.log(error.config); - } + console.log(error); }) } } diff --git a/src/IRCUser.ts b/src/IRCUser.ts index 09f590c..7f9e011 100644 --- a/src/IRCUser.ts +++ b/src/IRCUser.ts @@ -17,6 +17,8 @@ export class IRCUser { private txnIdStore: Map public nextBatch: string private initialSync: boolean + private isSyncing: boolean + private currentSyncTime: number private syncIntervalID: NodeJS.Timeout; constructor(public mxid: string, private accessToken: string, public homeserver: string, private server: Server) { this.clients = new Set(); @@ -30,6 +32,8 @@ export class IRCUser { this.txnIdStore = new Map(); this.nextBatch = ""; this.initialSync = false; + this.isSyncing = false; + this.currentSyncTime = 0; this.syncIntervalID = setInterval(this.doSync.bind(this), 2000); } @@ -67,7 +71,14 @@ export class IRCUser { console.log("not syncing, initial sync not completed"); return; } - const endpoint = `https://${this.homeserver}/_matrix/client/v3/sync?access_token=${this.accessToken}&since=${this.nextBatch}`; + if (this.isSyncing) { + if ((Date.now() - this.currentSyncTime) > 15000) + console.log(`Sync is lagging, current sync has been running for ${Date.now() - this.currentSyncTime} milliseconds`); + return; + } + this.currentSyncTime = Date.now(); + this.isSyncing = true; + const endpoint = `https://${this.homeserver}/_matrix/client/v3/sync?access_token=${this.accessToken}&since=${this.nextBatch}&timeout=15000`; axios.get(endpoint).then(response => { const data = response.data; this.nextBatch = data.next_batch; @@ -80,16 +91,19 @@ export class IRCUser { }); } } - }).catch(function (error) { + this.isSyncing = false; + }).catch((error) => { + console.log(error); if (error.response) { - console.log(error.response.data); - console.log(error.response.status); + console.log(`Response error: ${error.response.status}`); } else if (error.request) { console.log(error.request); + console.log(error.config); } else { console.log('Error', error.message); console.log(error.config); } + this.isSyncing = false; }); } diff --git a/src/Message.ts b/src/Message.ts index 5e185f4..09422ac 100644 --- a/src/Message.ts +++ b/src/Message.ts @@ -116,6 +116,6 @@ export function parseIRCMessage(rawLine: string) { if (lastParam !== '') { params.push(lastParam); } - console.log(parsedTags, prefix, command, params); + //console.log(parsedTags, prefix, command, params); return new IRCMessage(parsedTags, prefix, command, params); } \ No newline at end of file