Skip to content

Commit aa2ee59

Browse files
fix: stale connectionId (#336)
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.
1 parent 23f85ac commit aa2ee59

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Space.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ class Space extends EventEmitter<SpaceEventMap> {
8787
*/
8888
readonly client: RealtimeClient;
8989
private readonly channelName: string;
90-
/**
91-
* @internal
92-
*/
93-
readonly connectionId: string | undefined;
90+
9491
/**
9592
* The options passed to {@link default.get | `Spaces.get()`}.
9693
*/
@@ -126,7 +123,6 @@ class Space extends EventEmitter<SpaceEventMap> {
126123

127124
this.client = client;
128125
this.options = this.setOptions(options);
129-
this.connectionId = this.client.connection.id;
130126
this.name = name;
131127
this.channelName = `${name}${SPACE_CHANNEL_TAG}`;
132128

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

139+
/**
140+
* @internal
141+
*/
142+
get connectionId(): string | undefined {
143+
return this.client.connection.id;
144+
}
145+
143146
private presenceUpdate = ({ data, extras }: SpacePresenceData) => {
144147
if (!extras) {
145148
return this.channel.presence.update(data);

0 commit comments

Comments
 (0)