Skip to content

Commit a07cc7a

Browse files
Fix bug where space.enter() sometimes wouldn’t return
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.
1 parent 1a43536 commit a07cc7a

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Space.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ describe('Space', () => {
7171
});
7272

7373
it<SpaceTestContext>('enter a space successfully', async ({ space, presence }) => {
74-
const spy = vi.spyOn(presence, 'enter');
74+
const presenceEnterSpy = vi.spyOn(presence, 'enter');
75+
const presenceSubscribeSpy = vi.spyOn(presence, 'subscribe');
7576
await space.enter({ name: 'Betty' });
76-
expect(spy).toHaveBeenNthCalledWith(1, createProfileUpdate({ current: { name: 'Betty' } }));
77+
expect(presenceEnterSpy).toHaveBeenNthCalledWith(1, createProfileUpdate({ current: { name: 'Betty' } }));
78+
expect(presenceSubscribeSpy).toHaveBeenCalledWith(['enter', 'present'], expect.any(Function));
7779
});
7880

7981
it<SpaceTestContext>('returns current space members', async ({ presenceMap, space }) => {

src/Space.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class Space extends EventEmitter<SpaceEventMap> {
264264
resolve(members);
265265
};
266266

267-
presence.subscribe('enter', presenceListener);
267+
presence.subscribe(['enter', 'present'], presenceListener);
268268

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

0 commit comments

Comments
 (0)