Skip to content

Commit

Permalink
fix: stale connectionId
Browse files Browse the repository at this point in the history
Instead of assigning the connectionId once in the space's constructor, it should be taken directly from the ably client. This ensures that the connectionId stays in sync even after a disconnect e.g. when the machine hibernates.
  • Loading branch information
bastiankistner committed Nov 1, 2024
1 parent a1e1bb2 commit 285e3e4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ class Space extends EventEmitter<SpaceEventMap> {
*/
readonly client: RealtimeClient;
private readonly channelName: string;
/**
* @internal
*/
readonly connectionId: string | undefined;

/**
* The options passed to {@link default.get | `Spaces.get()`}.
*/
Expand Down Expand Up @@ -126,7 +123,6 @@ class Space extends EventEmitter<SpaceEventMap> {

this.client = client;
this.options = this.setOptions(options);
this.connectionId = this.client.connection.id;
this.name = name;
this.channelName = `${name}${SPACE_CHANNEL_TAG}`;

Expand All @@ -140,6 +136,13 @@ class Space extends EventEmitter<SpaceEventMap> {
this.locks = new Locks(this, this.presenceUpdate);
}

/**
* @internal
*/
get connectionId(): string | undefined {
return this.client.connection.id;
}

private presenceUpdate = ({ data, extras }: SpacePresenceData) => {
if (!extras) {
return this.channel.presence.update(data);
Expand Down

0 comments on commit 285e3e4

Please sign in to comment.