Skip to content

Commit

Permalink
fix: improve channel options reattachment logic
Browse files Browse the repository at this point in the history
This internal change makes the client more selective about which options
provided to `channels.get` will be interpreted as requiring
reattachment. More precisely, the channel params and modes will now be
shallow compared to existing params and modes, and only if they differ
will the call the `chnanels.get` throw an error (, provided of course
that the channel is already attached or attaching).
  • Loading branch information
owenpearson committed Oct 5, 2023
1 parent 65ff5d7 commit 5f14a5c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/common/lib/client/realtimechannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,20 @@ class RealtimeChannel extends Channel {
}

_shouldReattachToSetOptions(options?: API.Types.ChannelOptions) {
return (this.state === 'attached' || this.state === 'attaching') && (options?.params || options?.modes);
if (!(this.state === 'attached' || this.state === 'attaching')) {
return false;
}
if (options?.params) {
if (!this.params || !Utils.shallowEquals(this.params, options.params)) {
return true;
}
}
if (options?.modes) {
if (!this.modes || !Utils.arrEquals(options.modes, this.modes)) {
return true;
}
}
return false;
}

publish(...args: any[]): void | Promise<void> {
Expand Down

0 comments on commit 5f14a5c

Please sign in to comment.