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..8cf17a16 100644 --- a/src/Cursors.ts +++ b/src/Cursors.ts @@ -105,7 +105,11 @@ 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); + /** + * Since server-side batching is automically enabled for cursors channels, we can now adjust the client-side batching interval more granularly. + * E.g. multiply the configured outboundBatchInterval by groups of 100 members instead of the total number of members. + */ + this.cursorBatching.setBatchTime(Math.ceil(cursorsMembers.length / 100) * this.options.outboundBatchInterval); } private isUnsubscribed() {