Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import {
DeleteCommandResponse,
DeleteUserOptions,
Device,
DeviceIdentifier,
EndpointName,
ErrorFromResponse,
Event,
Expand Down Expand Up @@ -277,6 +278,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
defaultWSTimeoutWithFallback: number;
defaultWSTimeout: number;
sdkIdentifier?: SdkIdentifier;
deviceIdentifier?: DeviceIdentifier;
private nextRequestAbortController: AbortController | null = null;

/**
Expand Down Expand Up @@ -2924,7 +2926,12 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
}
const version = process.env.PKG_VERSION;
if (this.sdkIdentifier) {
return `stream-chat-${this.sdkIdentifier.name}-v${this.sdkIdentifier.version}-llc-v${version}`;
const { os, model } = this.deviceIdentifier ?? {};
return `stream-chat-${this.sdkIdentifier.name}-v${this.sdkIdentifier.version}-llc-v${version}${
os ? `|os=${os}` : ''
}${
model ? `|device_model=${model}` : ''
}`;
} else {
return `stream-chat-js-v${version}-${this.node ? 'node' : 'browser'}`;
}
Expand Down
12 changes: 11 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3816,4 +3816,14 @@ export type PromoteChannelParams<SCG extends ExtendableGenerics = DefaultGeneric
channelToMoveIndexWithinChannels?: number;
};

export type SdkIdentifier = { name: 'react' | 'react-native' | 'angular'; version: string };
/**
* An identifier containing information about the downstream SDK using stream-chat. It
* is used to resolve the user agent.
*/
export type SdkIdentifier = { name: 'react' | 'react-native' | 'expo' | 'angular'; version: string };

/**
* An identifier containing information about the downstream device using stream-chat, if
* available. Is used by the react-native SDKs to enrich the user agent further.
*/
export type DeviceIdentifier = { os: string; model?: string }
12 changes: 10 additions & 2 deletions test/unit/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ describe('StreamChat.queryChannels', async () => {
});
});

describe('X-Stream-Client header', () => {
describe.only('X-Stream-Client header', () => {
process.env.PKG_VERSION = '1.2.3';
let client;

Expand All @@ -663,13 +663,21 @@ describe('X-Stream-Client header', () => {
expect(userAgent).to.be.equal('stream-chat-js-v1.2.3-browser');
});

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

expect(userAgent).to.be.equal('stream-chat-react-v2.3.4-llc-v1.2.3');
});

it('SDK integration with deviceIdentifier', () => {
client.sdkIdentifier = { name: 'react-native', version: '2.3.4' };
client.deviceIdentifier = { os: 'iOS 15.0', model: 'iPhone17,4' };
const userAgent = client.getUserAgent();

expect(userAgent).to.be.equal('stream-chat-react-native-v2.3.4-llc-v1.2.3|os=iOS 15.0|device_model=iPhone17,4');
})

it('setUserAgent is now deprecated', () => {
client.setUserAgent('deprecated');
const userAgent = client.getUserAgent();
Expand Down
Loading