From 3fc566ea7d0c65acbcef6781b52079e519248d62 Mon Sep 17 00:00:00 2001 From: Kamal Bennani Date: Wed, 29 Nov 2023 23:00:12 +0100 Subject: [PATCH] fix: persist previous options --- spec/javascripts/unit/core/pusher_spec.js | 17 +++++++++++++++++ src/core/pusher.ts | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/javascripts/unit/core/pusher_spec.js b/spec/javascripts/unit/core/pusher_spec.js index 28cfd73f..6993243a 100644 --- a/spec/javascripts/unit/core/pusher_spec.js +++ b/spec/javascripts/unit/core/pusher_spec.js @@ -346,6 +346,23 @@ describe("Pusher", function() { "channel" ); }); + + it('should keep the persist the previous options', () => { + var authorizeSpy = jasmine.createSpy("authorizeSpy"); + const options = { + cluster: "mt1", + enableStats: true, + channelAuthorization: { + customHandler: authorizeSpy + } + }; + + var pusher = new Pusher("foo", options); + pusher.connect(); + pusher.switchCluster({ appKey: 'bar', cluster: 'us3' }); + + expect(pusher.options).toEqual({ ...options, cluster: 'us3' }); + }) }) describe("#unsubscribe", function() { diff --git a/src/core/pusher.ts b/src/core/pusher.ts index b1ffc8ed..19d48ef9 100644 --- a/src/core/pusher.ts +++ b/src/core/pusher.ts @@ -63,7 +63,8 @@ export default class Pusher { checkAppKey(app_key); validateOptions(options); this.key = app_key; - this.config = getConfig(options, this); + this.options = options; + this.config = getConfig(this.options, this); this.channels = Factory.createChannels(); this.global_emitter = new EventsDispatcher();