diff --git a/packages/mobile-client/src/index.ts b/packages/mobile-client/src/index.ts index a1ccf729..2a801ddc 100644 --- a/packages/mobile-client/src/index.ts +++ b/packages/mobile-client/src/index.ts @@ -10,6 +10,7 @@ import { type FishjamProviderProps as ReactClientFishjamProviderProps, useMicrophone as useMicrophoneReactClient, } from '@fishjam-cloud/react-client'; +import { FishjamClient } from '@fishjam-cloud/ts-client'; export { RTCView, RTCPIPView, type RTCVideoViewProps, type RTCPIPViewProps } from './overrides/RTCView'; export { @@ -86,10 +87,12 @@ export type { } from '@fishjam-cloud/react-client'; // persistLastDevice is not supported on mobile -export type FishjamProviderProps = Omit; +export type FishjamProviderProps = Omit; export function FishjamProvider(props: FishjamProviderProps) { + const fishjamClient = new FishjamClient({ reconnect: props.reconnect, debug: props.debug, clientType: 'mobile' }); return React.createElement(ReactClientFishjamProvider, { ...props, persistLastDevice: false, + fishjamClient, }); } diff --git a/packages/react-client/src/FishjamProvider.tsx b/packages/react-client/src/FishjamProvider.tsx index a4120afa..33416b42 100644 --- a/packages/react-client/src/FishjamProvider.tsx +++ b/packages/react-client/src/FishjamProvider.tsx @@ -61,6 +61,10 @@ export interface FishjamProviderProps extends PropsWithChildren { * Enables Fishjam SDK's debug logs in the console. */ debug?: boolean; + /** + * Allows to provide your own FishjamClient instance from ts-client. + */ + fishjamClient?: FishjamClient; } /** @@ -68,7 +72,9 @@ export interface FishjamProviderProps extends PropsWithChildren { * @category Components */ export function FishjamProvider(props: FishjamProviderProps) { - const fishjamClientRef = useRef(new FishjamClient({ reconnect: props.reconnect, debug: props.debug })); + const fishjamClientRef = useRef( + props.fishjamClient ?? new FishjamClient({ reconnect: props.reconnect, debug: props.debug }), + ); const persistHandlers = useMemo(() => { if (props.persistLastDevice === false) return undefined; diff --git a/packages/ts-client/src/FishjamClient.ts b/packages/ts-client/src/FishjamClient.ts index 89106508..0b0f66b5 100644 --- a/packages/ts-client/src/FishjamClient.ts +++ b/packages/ts-client/src/FishjamClient.ts @@ -24,6 +24,7 @@ import { isComponent, isJoinError, isPeer } from './guards'; import { MessageQueue } from './messageQueue'; import { ReconnectManager } from './reconnection'; import type { + ClientType, Component, ConnectConfig, CreateConfig, @@ -81,6 +82,7 @@ export class FishjamClient void) | null = null; private debug: boolean; private logger: ReturnType; + private clientType: ClientType; public status: 'new' | 'initialized' = 'new'; @@ -97,6 +99,7 @@ export class FishjamClient( this, @@ -172,7 +175,7 @@ export class FishjamClient { this.emit('socketOpen', event); - const sdkVersion = `web-${packageVersion}`; + const sdkVersion = `${this.clientType}-${packageVersion}`; const message = PeerMessage.encode({ authRequest: { token, sdkVersion } }).finish(); this.websocket?.send(message); }; diff --git a/packages/ts-client/src/index.ts b/packages/ts-client/src/index.ts index 6afb3f98..8a3d053b 100644 --- a/packages/ts-client/src/index.ts +++ b/packages/ts-client/src/index.ts @@ -12,6 +12,7 @@ export { } from './livestream'; export type { ReconnectConfig, ReconnectionStatus } from './reconnection'; export type { + ClientType, Component, ConnectConfig, CreateConfig, diff --git a/packages/ts-client/src/types.ts b/packages/ts-client/src/types.ts index 8d480553..51062ce2 100644 --- a/packages/ts-client/src/types.ts +++ b/packages/ts-client/src/types.ts @@ -226,6 +226,11 @@ export type MessageEvents = { */ dataChannelsError: (error: Error) => void; }; +/** + * Represents the type of client used. + * @category Connection + */ +export type ClientType = 'web' | 'mobile'; /** Configuration object for the client */ export interface ConnectConfig { @@ -245,4 +250,7 @@ export type CreateConfig = { * Enables Fishjam SDK's debug logs in the console. */ debug?: boolean; + + /** Type of client used */ + clientType?: ClientType; };