From 867a674d6d9cbbf9ee189be76f7a17240e61880e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Monteiro=20Morgado=20Dias?= Date: Wed, 4 Sep 2024 16:41:58 +0100 Subject: [PATCH] Change cursors batch time formula on presence update --- src/Cursors.test.ts | 4 ++-- src/Cursors.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Cursors.test.ts b/src/Cursors.test.ts index 383f4ae8..1f0c8802 100644 --- a/src/Cursors.test.ts +++ b/src/Cursors.test.ts @@ -116,7 +116,7 @@ describe('Cursors', () => { vi.spyOn(channel.presence, 'get').mockImplementation(createPresenceCount(2)); await cursors['onPresenceUpdate'](); expect(batching.shouldSend).toBeTruthy(); - expect(batching.batchTime).toEqual(50); + expect(batching.batchTime).toEqual(25); }); it('batchTime is updated when multiple people are present', async ({ @@ -126,7 +126,7 @@ describe('Cursors', () => { }) => { vi.spyOn(channel.presence, 'get').mockImplementation(createPresenceCount(2)); await cursors['onPresenceUpdate'](); - expect(batching.batchTime).toEqual(50); + expect(batching.batchTime).toEqual(25); }); describe('pushCursorPosition', () => { diff --git a/src/Cursors.ts b/src/Cursors.ts index 7548f463..145e8379 100644 --- a/src/Cursors.ts +++ b/src/Cursors.ts @@ -105,7 +105,7 @@ export default class Cursors extends EventEmitter { const channel = this.getChannel(); const cursorsMembers = await channel.presence.get(); this.cursorBatching.setShouldSend(cursorsMembers.length > 1); - this.cursorBatching.setBatchTime(cursorsMembers.length * this.options.outboundBatchInterval); + this.cursorBatching.setBatchTime(Math.ceil(cursorsMembers.length / 100) * this.options.outboundBatchInterval); } private isUnsubscribed() {