Skip to content

Commit 93d2676

Browse files
Merge branch 'master' of github.com:GetStream/stream-chat-js into rc
2 parents e2d9b15 + ffcf1d5 commit 93d2676

File tree

6 files changed

+74
-7
lines changed

6 files changed

+74
-7
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ property in the formatted message output
3737

3838
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
3939

40+
### [8.57.5](https://github.com/GetStream/stream-chat-js/compare/v8.57.4...v8.57.5) (2025-03-01)
41+
42+
43+
### Bug Fixes
44+
45+
* properly encode user agent on WS connection ([#1482](https://github.com/GetStream/stream-chat-js/issues/1482)) ([58b538b](https://github.com/GetStream/stream-chat-js/commit/58b538b5380000cfcf2abeb369b5ef6a0acf3913))
46+
47+
### [8.57.4](https://github.com/GetStream/stream-chat-js/compare/v8.57.3...v8.57.4) (2025-02-28)
48+
49+
50+
### Bug Fixes
51+
52+
* add missing env variable in rollup config ([#1480](https://github.com/GetStream/stream-chat-js/issues/1480)) ([a935e9e](https://github.com/GetStream/stream-chat-js/commit/a935e9e79232da0df9d951119f48891da59d6281))
53+
54+
### [8.57.3](https://github.com/GetStream/stream-chat-js/compare/v8.57.2...v8.57.3) (2025-02-28)
55+
56+
57+
### Bug Fixes
58+
59+
* add extra user agent fields resolvable by react native ([#1477](https://github.com/GetStream/stream-chat-js/issues/1477)) ([4232150](https://github.com/GetStream/stream-chat-js/commit/42321500096491252211b57e3d238cfe920a0777))
60+
4061
### [8.57.2](https://github.com/GetStream/stream-chat-js/compare/v8.57.1...v8.57.2) (2025-02-27)
4162

4263

src/client.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
DeleteCommandResponse,
7979
DeleteUserOptions,
8080
Device,
81+
DeviceIdentifier,
8182
EndpointName,
8283
ErrorFromResponse,
8384
Event,
@@ -274,6 +275,7 @@ export class StreamChat {
274275
defaultWSTimeoutWithFallback: number;
275276
defaultWSTimeout: number;
276277
sdkIdentifier?: SdkIdentifier;
278+
deviceIdentifier?: DeviceIdentifier;
277279
private nextRequestAbortController: AbortController | null = null;
278280

279281
/**
@@ -2870,12 +2872,20 @@ export class StreamChat {
28702872
userAgentString = `stream-chat-js-v${version}-${this.node ? 'node' : 'browser'}`;
28712873
}
28722874

2873-
const additionalOptions = ([
2875+
const { os, model } = this.deviceIdentifier ?? {};
2876+
2877+
return ([
2878+
// reports the device OS, if provided
2879+
['os', os],
2880+
// reports the device model, if provided
2881+
['device_model', model],
28742882
// reports which bundle is being picked from the exports
28752883
['client_bundle', clientBundle],
2876-
] as const).map(([key, value]) => `${key}=${value ?? ''}`);
2877-
2878-
return [userAgentString, ...additionalOptions].join('|');
2884+
] as const).reduce(
2885+
(withArguments, [key, value]) =>
2886+
value && value.length > 0 ? withArguments.concat(`|${key}=${value}`) : withArguments,
2887+
userAgentString,
2888+
);
28792889
}
28802890

28812891
/**

src/connection.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ export class StableWSConnection {
194194

195195
return `${this.client.wsBaseURL}/connect?json=${qs}&api_key=${
196196
this.client.key
197-
}&authorization=${token}&stream-auth-type=${this.client.getAuthType()}&X-Stream-Client=${this.client.getUserAgent()}`;
197+
}&authorization=${token}&stream-auth-type=${this.client.getAuthType()}&X-Stream-Client=${encodeURIComponent(
198+
this.client.getUserAgent(),
199+
)}`;
198200
};
199201

200202
/**

src/types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3691,4 +3691,14 @@ export type PromoteChannelParams = {
36913691
channelToMoveIndexWithinChannels?: number;
36923692
};
36933693

3694-
export type SdkIdentifier = { name: 'react' | 'react-native' | 'angular'; version: string };
3694+
/**
3695+
* An identifier containing information about the downstream SDK using stream-chat. It
3696+
* is used to resolve the user agent.
3697+
*/
3698+
export type SdkIdentifier = { name: 'react' | 'react-native' | 'expo' | 'angular'; version: string };
3699+
3700+
/**
3701+
* An identifier containing information about the downstream device using stream-chat, if
3702+
* available. Is used by the react-native SDKs to enrich the user agent further.
3703+
*/
3704+
export type DeviceIdentifier = { os: string; model?: string };

test/unit/client.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,13 +664,29 @@ describe('X-Stream-Client header', () => {
664664
expect(userAgent).to.be.equal('stream-chat-js-v1.2.3-browser|client_bundle=browser-esm');
665665
});
666666

667-
it('SDK integration', () => {
667+
it('SDK integration without deviceIdentifier', () => {
668668
client.sdkIdentifier = { name: 'react', version: '2.3.4' };
669669
const userAgent = client.getUserAgent();
670670

671671
expect(userAgent).to.be.equal('stream-chat-react-v2.3.4-llc-v1.2.3|client_bundle=browser-esm');
672672
});
673673

674+
it('SDK integration with deviceIdentifier', () => {
675+
client.sdkIdentifier = { name: 'react-native', version: '2.3.4' };
676+
client.deviceIdentifier = { os: 'iOS 15.0', model: 'iPhone17,4' };
677+
const userAgent = client.getUserAgent();
678+
679+
expect(userAgent).to.be.equal('stream-chat-react-native-v2.3.4-llc-v1.2.3|os=iOS 15.0|device_model=iPhone17,4');
680+
});
681+
682+
it('SDK integration with process.env.CLIENT_BUNDLE', () => {
683+
process.env.CLIENT_BUNDLE = 'browser';
684+
client.sdkIdentifier = { name: 'react', version: '2.3.4' };
685+
const userAgent = client.getUserAgent();
686+
687+
expect(userAgent).to.be.equal('stream-chat-react-v2.3.4-llc-v1.2.3|client_bundle=browser');
688+
});
689+
674690
it('setUserAgent is now deprecated', () => {
675691
client.setUserAgent('deprecated');
676692
const userAgent = client.getUserAgent();

test/unit/connection.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ describe('connection', function () {
7777
expect(data.device).to.deep.equal(device);
7878
});
7979

80+
it('should properly encode X-Stream-Client', () => {
81+
const userAgent = 'agent|val=foo bar';
82+
client.userAgent = userAgent;
83+
const url = ws._buildUrl();
84+
85+
expect(url).to.contain(encodeURIComponent(userAgent));
86+
});
87+
8088
it('should not include device if not there', function () {
8189
ws.client.options.device = undefined;
8290
const { query } = url.parse(ws._buildUrl(), true);

0 commit comments

Comments
 (0)