Skip to content
5 changes: 4 additions & 1 deletion packages/mobile-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -86,10 +87,12 @@ export type {
} from '@fishjam-cloud/react-client';

// persistLastDevice is not supported on mobile
export type FishjamProviderProps = Omit<ReactClientFishjamProviderProps, 'persistLastDevice'>;
export type FishjamProviderProps = Omit<ReactClientFishjamProviderProps, 'persistLastDevice' | 'fishjamClient'>;
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,
});
}
8 changes: 7 additions & 1 deletion packages/react-client/src/FishjamProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,20 @@ 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;
}

/**
* Provides the Fishjam Context
* @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;
Expand Down
5 changes: 4 additions & 1 deletion packages/ts-client/src/FishjamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { isComponent, isJoinError, isPeer } from './guards';
import { MessageQueue } from './messageQueue';
import { ReconnectManager } from './reconnection';
import type {
ClientType,
Component,
ConnectConfig,
CreateConfig,
Expand Down Expand Up @@ -81,6 +82,7 @@ export class FishjamClient<PeerMetadata = GenericMetadata, ServerMetadata = Gene
private removeEventListeners: (() => void) | null = null;
private debug: boolean;
private logger: ReturnType<typeof getLogger>;
private clientType: ClientType;

public status: 'new' | 'initialized' = 'new';

Expand All @@ -97,6 +99,7 @@ export class FishjamClient<PeerMetadata = GenericMetadata, ServerMetadata = Gene

this.debug = !!config?.debug;
this.logger = getLogger(this.debug);
this.clientType = config?.clientType ?? 'web';

this.reconnectManager = new ReconnectManager<PeerMetadata, ServerMetadata>(
this,
Expand Down Expand Up @@ -172,7 +175,7 @@ export class FishjamClient<PeerMetadata = GenericMetadata, ServerMetadata = Gene
const socketOpenHandler = (event: Event) => {
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);
};
Expand Down
1 change: 1 addition & 0 deletions packages/ts-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export {
} from './livestream';
export type { ReconnectConfig, ReconnectionStatus } from './reconnection';
export type {
ClientType,
Component,
ConnectConfig,
CreateConfig,
Expand Down
8 changes: 8 additions & 0 deletions packages/ts-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ export type MessageEvents<P, S> = {
*/
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<PeerMetadata> {
Expand All @@ -245,4 +250,7 @@ export type CreateConfig = {
* Enables Fishjam SDK's debug logs in the console.
*/
debug?: boolean;

/** Type of client used */
clientType?: ClientType;
};
Loading