diff --git a/src/Space.test.ts b/src/Space.test.ts index e0c1de87..9c85a080 100644 --- a/src/Space.test.ts +++ b/src/Space.test.ts @@ -63,7 +63,9 @@ describe('Space', () => { beforeEach(({ presence }) => { vi.spyOn(presence, 'subscribe').mockImplementation( async (_, listener?: (presenceMessage: Types.PresenceMessage) => void) => { - listener!(createPresenceMessage('enter' /* arbitrarily chosen */)); + listener!( + createPresenceMessage('enter' /* arbitrarily chosen */, { clientId: 'MOCK_CLIENT_ID', connectionId: '1' }), + ); }, ); }); diff --git a/src/Space.ts b/src/Space.ts index f6fb22cf..7761b381 100644 --- a/src/Space.ts +++ b/src/Space.ts @@ -244,7 +244,16 @@ class Space extends EventEmitter { return new Promise((resolve) => { const presence = this.channel.presence; - const presenceListener = async () => { + const presenceListener = async (presenceMessage: Types.PresenceMessage) => { + if ( + !( + presenceMessage.clientId == this.client.auth.clientId && + presenceMessage.connectionId == this.client.connection.id + ) + ) { + return; + } + presence.unsubscribe(presenceListener); const presenceMessages = await presence.get();