Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/wrapper-sdk-client-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Add internal `setWrapperSdkInfo` so SDKs built on top of livekit-client (e.g. Unity WebGL) report their own SDK and version in `ClientInfo`, with livekit-client's version in `other_sdks`
68 changes: 66 additions & 2 deletions src/api/SignalClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ClientInfo_Capability,
ClientInfo_SDK,
DisconnectReason,
JoinRequest,
JoinResponse,
Expand All @@ -10,11 +11,12 @@ import {
WrappedJoinRequest,
WrappedJoinRequest_Compression,
} from '@livekit/protocol';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type { Mutex } from '@livekit/mutex';
import { ConnectionError, ConnectionErrorReason } from '../room/errors';
import CriticalTimers from '../room/timers';
import { Future } from '../room/utils';
import { Future, setWrapperSdkInfo } from '../room/utils';
import { version } from '../version';
import { SignalClient, SignalConnectionState } from './SignalClient';
import type { WebSocketCloseInfo, WebSocketConnection } from './WebSocketStream';
import { WebSocketStream } from './WebSocketStream';
Expand Down Expand Up @@ -526,6 +528,68 @@ describe('SignalClient.connect', () => {
expect(new URL(capturedUrl).searchParams.get('subscriber_allow_pause')).toBe(expected);
},
);

describe('sdk identity', () => {
afterEach(() => {
setWrapperSdkInfo(undefined);
vi.unstubAllGlobals();
});

async function joinAndCaptureUrl(useV0Path: boolean): Promise<string> {
const signalResponse = createSignalResponse('join', createJoinResponse());
const mockConnection = createMockConnection(createMockReadableStream([signalResponse]));
let capturedUrl = '';
mockWebSocketStream({
connection: mockConnection,
onUrl: (url) => {
capturedUrl = url;
},
});
await signalClient.join(
'wss://test.livekit.io',
'test-token',
defaultOptions,
undefined,
useV0Path,
);
return capturedUrl;
}

it.each([
['js', undefined],
['reactnative', 'react-native'],
['unityweb', 'unity-web'],
] as const)('sends sdk=%s on the v0 path (%s)', async (expected, scenario) => {
if (scenario === 'react-native') {
vi.stubGlobal('navigator', { userAgent: '', product: 'ReactNative' });
}
if (scenario === 'unity-web') {
setWrapperSdkInfo({ sdk: 'UNITY_WEB', version: '2.0.1' });
}

const url = await joinAndCaptureUrl(true);

expect(new URL(url).searchParams.get('sdk')).toBe(expected);
});

it('sends the wrapper version on the v0 path', async () => {
setWrapperSdkInfo({ sdk: 'UNITY_WEB', version: '2.0.1' });

const url = await joinAndCaptureUrl(true);

expect(new URL(url).searchParams.get('version')).toBe('2.0.1');
});

it('reports the wrapper sdk in the v1 join request', async () => {
setWrapperSdkInfo({ sdk: 'UNITY_WEB', version: '2.0.1' });

const joinRequest = await decodeJoinRequestFromUrl(await joinAndCaptureUrl(false));

expect(joinRequest.clientInfo?.sdk).toBe(ClientInfo_SDK.UNITY_WEB);
expect(joinRequest.clientInfo?.version).toBe('2.0.1');
expect(joinRequest.clientInfo?.otherSdks).toBe(`js:${version}`);
});
});
});

describe('Happy Path - Reconnect', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/api/SignalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AudioTrackFeature,
ClientInfo,
ClientInfo_Capability,
ClientInfo_SDK,
ConnectionQualityUpdate,
ConnectionSettings,
DataTrackSubscriberHandles,
Expand Down Expand Up @@ -60,7 +61,7 @@ import type { DataTrackSid } from '../room/data-track/types';
import { ConnectionError, ConnectionErrorReason } from '../room/errors';
import CriticalTimers from '../room/timers';
import type { LoggerOptions } from '../room/types';
import { getClientInfo, isCompressionStreamSupported, isReactNative, sleep } from '../room/utils';
import { getClientInfo, isCompressionStreamSupported, sleep } from '../room/utils';
import type { NonSharedUint8Array } from '../type-polyfills/non-shared-typed-arrays';
import { AsyncQueue } from '../utils/AsyncQueue';
import { abortSignalTimeout } from '../utils/abort-signal-polyfill';
Expand Down Expand Up @@ -1426,7 +1427,8 @@ function createConnectionParams(
params.set('auto_subscribe', opts.autoSubscribe ? '1' : '0');

// ClientInfo
params.set('sdk', isReactNative() ? 'reactnative' : 'js');
// the server expects the enum name lowercased without underscores, e.g. 'js', 'reactnative', 'unityweb'
params.set('sdk', ClientInfo_SDK[info.sdk!].toLowerCase().replace(/_/g, ''));

@MaxHeimbrock MaxHeimbrock Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.replace(/_/g, '') removes every underscore, giving unityweb and reactnative

Comment thread
MaxHeimbrock marked this conversation as resolved.
Resolved
params.set('version', info.version!);
params.set('protocol', info.protocol!.toString());
params.set('client_protocol', info.clientProtocol!.toString());
Expand Down
6 changes: 5 additions & 1 deletion src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import type { ElementInfo } from './room/track/RemoteVideoTrack';
import RemoteVideoTrack from './room/track/RemoteVideoTrack';
import { type PublicationEventCallbacks, TrackPublication } from './room/track/TrackPublication';
import type { LiveKitReactNativeInfo, TextStreamInfo } from './room/types';
import type { AudioAnalyserOptions } from './room/utils';
import type { AudioAnalyserOptions, WrapperSdkInfo } from './room/utils';
import {
compareVersions,
createAudioAnalyser,
Expand All @@ -61,6 +61,7 @@ import {
isVideoCodec,
isVideoTrack,
releaseEmptyAudioStreamTrack,
setWrapperSdkInfo,
supportsAV1,
supportsAdaptiveStream,
supportsAudioOutputSelection,
Expand Down Expand Up @@ -142,6 +143,8 @@ export {
isBrowserSupported,
setLogExtension,
setLogLevel,
/** @internal */
setWrapperSdkInfo,
supportsAV1,
supportsAdaptiveStream,
supportsAudioOutputSelection,
Expand All @@ -163,6 +166,7 @@ export {
};
export type {
AudioAnalyserOptions,
WrapperSdkInfo,
ElementInfo,
LiveKitReactNativeInfo,
TextStreamInfo,
Expand Down
29 changes: 27 additions & 2 deletions src/room/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,38 @@ export interface ObservableMediaElement extends HTMLMediaElement {
handleVisibilityChanged: (entry: IntersectionObserverEntry) => void;
}

export type WrapperSdkInfo = {
/** The `ClientInfo.SDK` enum name of the wrapping SDK, e.g. `'UNITY_WEB'` */
sdk: keyof typeof ClientInfo_SDK;
/** The wrapping SDK's own version */
version: string;
};

let wrapperSdkInfo: WrapperSdkInfo | undefined;

/**
* For LiveKit SDKs built on top of livekit-client (e.g. Unity WebGL).
* Reports the wrapper as the client SDK to the server, and moves livekit-client's
* own version to `ClientInfo.other_sdks`. Pass `undefined` to reset.
* Meant for wrapper SDKs, not for apps.
* @experimental
*/
export function setWrapperSdkInfo(info: WrapperSdkInfo | undefined) {
wrapperSdkInfo = info;
}

export function getClientInfo(capabilities?: ClientInfo_Capability[]): ClientInfo {
let sdk = isReactNative() ? ClientInfo_SDK.REACT_NATIVE : ClientInfo_SDK.JS;

@MaxHeimbrock MaxHeimbrock Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old react native path is still used here, so this does not force an update in the React SDK.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: I think this makes sense, but I do wonder if it would be preferable longer term if react native were to also use setWrapperSdkInfo? Or if there were a way to introduce a isUnityWeb function? I think ideally it would be good if this worked the same across platforms.

Also, I'm guessing this isn't a thing today, but in the future if we needed to gate some functionality to only happen on unity web then a isUnityWeb would be important to have as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as in Slack:

"The current react native way is a bit more hacky in my opinion, so the next step in unifying would be to move react native over to use the function instead of setting the property."

if (wrapperSdkInfo) {
sdk = ClientInfo_SDK[wrapperSdkInfo.sdk];
}
const info = new ClientInfo({
capabilities,
sdk: isReactNative() ? ClientInfo_SDK.REACT_NATIVE : ClientInfo_SDK.JS,
sdk,
protocol: protocolVersion,
clientProtocol,
version,
version: wrapperSdkInfo?.version ?? version,
otherSdks: wrapperSdkInfo ? `js:${version}` : undefined,
});

if (isReactNative()) {
Expand Down
Loading