Skip to content

Commit

Permalink
Fix bug where space.enter() sometimes wouldn’t return
Browse files Browse the repository at this point in the history
Calling presence.enter() does not necessarily result in the presence
object emitting an ENTER event. This could happen, for example, if the
channel does not become attached quickly enough, or if a transport
upgrade is happening at roughly the same time as the presence enter call
(note that the latter possibility means that we wouldn’t gain much by
trying to work around the former by making sure the channel becomes
attached before performing the presence enter). In both these cases, the
only visible side effect of the presence enter call will be a PRESENT
event emitted as a result of a presence SYNC.

So, we update space.enter such that it also will return if it receives a
PRESENT event for the current member.

Resolves COL-335.
  • Loading branch information
lawrence-forooghian committed Oct 19, 2023
1 parent a4e0351 commit c8d9e25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Space.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ describe('Space', () => {
});

it<SpaceTestContext>('enter a space successfully', async ({ space, presence }) => {
const spy = vi.spyOn(presence, 'enter');
const presenceEnterSpy = vi.spyOn(presence, 'enter');
const presenceSubscribeSpy = vi.spyOn(presence, 'subscribe');
await space.enter({ name: 'Betty' });
expect(spy).toHaveBeenNthCalledWith(1, createProfileUpdate({ current: { name: 'Betty' } }));
expect(presenceEnterSpy).toHaveBeenNthCalledWith(1, createProfileUpdate({ current: { name: 'Betty' } }));
expect(presenceSubscribeSpy).toHaveBeenCalledWith(['enter', 'present'], expect.any(Function));
});

describe.each([
Expand Down
2 changes: 1 addition & 1 deletion src/Space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class Space extends EventEmitter<SpaceEventMap> {
resolve(members);
};

presence.subscribe('enter', presenceListener);
presence.subscribe(['enter', 'present'], presenceListener);

const update = new SpaceUpdate({ self: null, extras: null });
this.presenceEnter(update.updateProfileData(profileData));
Expand Down

0 comments on commit c8d9e25

Please sign in to comment.