Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React-native client info #629

Merged
merged 6 commits into from
Mar 27, 2023
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/lovely-boats-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Identify react-native apps when connecting to server
4 changes: 2 additions & 2 deletions src/api/SignalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from '../proto/livekit_rtc';
import { ConnectionError, ConnectionErrorReason } from '../room/errors';
import CriticalTimers from '../room/timers';
import { getClientInfo, Mutex, sleep } from '../room/utils';
import { getClientInfo, isReactNative, Mutex, sleep } from '../room/utils';

// internal options
interface ConnectOpts {
Expand Down Expand Up @@ -706,7 +706,7 @@ function createConnectionParams(token: string, info: ClientInfo, opts: ConnectOp
params.set('auto_subscribe', opts.autoSubscribe ? '1' : '0');

// ClientInfo
params.set('sdk', 'js');
params.set('sdk', isReactNative() ? 'reactnative' : 'js');
params.set('version', info.version!);
params.set('protocol', info.protocol!.toString());
if (info.deviceModel) {
Expand Down
24 changes: 24 additions & 0 deletions src/room/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ export function isWeb(): boolean {
return typeof document !== 'undefined';
}

export function isReactNative(): boolean {
// navigator.product is deprecated on browsers, but will be set appropriately for react-native.
return navigator.product == 'ReactNative';
}

export function getReactNativeOs(): string | undefined {
if (!isReactNative()) {
return undefined;
}

// global defined only for ReactNative.
// @ts-ignore
if (global && global.LiveKitReactNativeGlobal) {
// @ts-ignore
return global.LiveKitReactNativeGlobal.platform;
}

return undefined;
}

export function compareVersions(v1: string, v2: string): number {
const parts1 = v1.split('.');
const parts2 = v2.split('.');
Expand Down Expand Up @@ -174,6 +194,10 @@ export function getClientInfo(): ClientInfo {
protocol: protocolVersion,
version,
});

if (isReactNative()) {
info.os = getReactNativeOs() ?? '';
}
return info;
}

Expand Down