Skip to content

Commit d14d0ff

Browse files
authored
fix: provide a way for a suffix to be added to wsUrl (#1497)
## CLA - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required). - [ ] Code changes are tested ## Description of the changes, What, Why and How? ## Changelog -
1 parent 73a748d commit d14d0ff

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
330330
warmUp: false,
331331
recoverStateOnReconnect: true,
332332
disableCache: false,
333+
wsUrlSuffix: '',
333334
...inputOptions,
334335
};
335336

src/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class StableWSConnection<StreamChatGenerics extends ExtendableGenerics =
191191
this.client.key
192192
}&authorization=${token}&stream-auth-type=${this.client.getAuthType()}&X-Stream-Client=${encodeURIComponent(
193193
this.client.getUserAgent(),
194-
)}`;
194+
)}${this.client.options.wsUrlSuffix}`;
195195
};
196196

197197
/**

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,11 @@ export type StreamChatOptions = AxiosRequestConfig & {
12411241
* not be used in production apps.
12421242
*/
12431243
wsConnection?: StableWSConnection;
1244+
/**
1245+
* Sets a suffix to the wsUrl when it is being built in `wsConnection`. Is meant to be
1246+
* used purely in testing suites and should not be used in production apps.
1247+
*/
1248+
wsUrlSuffix?: string;
12441249
};
12451250

12461251
export type SyncOptions = {

test/unit/connection.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ describe('connection', function () {
9191
const data = JSON.parse(query.json);
9292
expect(data.device).to.deep.undefined;
9393
});
94+
95+
it('should include extra params when building url if provided', function () {
96+
const { query: prevQuery } = url.parse(ws._buildUrl(), true);
97+
ws.client.options.wsUrlSuffix = '&foo=1&bar=2';
98+
const { query } = url.parse(ws._buildUrl(), true);
99+
100+
// all of the previous query params should remain intact
101+
Object.keys(prevQuery).forEach((key) => {
102+
expect(prevQuery[key]).to.deep.equal(query[key]);
103+
});
104+
// only the updated query should contain the new ones
105+
expect(query.foo).to.equal('1');
106+
expect(query.bar).to.equal('2');
107+
});
94108
});
95109

96110
describe('isResolved flag', () => {

0 commit comments

Comments
 (0)