Skip to content

Commit

Permalink
Merge branch 'main' into fix/spaces_connection_id
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiankistner authored Nov 1, 2024
2 parents 285e3e4 + 9b74209 commit b24a327
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ To use Spaces you must also set a [`clientId`](https://ably.com/docs/auth/identi
You can also use Spaces with a CDN, such as [unpkg](https://www.unpkg.com/):

```html
<script src="https://cdn.ably.com/lib/ably.min-1.js"></script>
<script src="https://cdn.ably.com/spaces/0.1.2/iife/index.bundle.js"></script>
<script src="https://cdn.ably.com/lib/ably.min-2.js"></script>
<script src="https://cdn.ably.com/spaces/0.4.0/iife/index.bundle.js"></script>
```

After this, instantiate the SDK in the same way as in the NPM option above:
Expand Down
4 changes: 2 additions & 2 deletions src/Cursors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CursorsTestContext>('batchTime is updated when multiple people are present', async ({
Expand All @@ -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', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/Cursors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ export default class Cursors extends EventEmitter<CursorsEventMap> {
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() {
Expand Down

0 comments on commit b24a327

Please sign in to comment.