Skip to content
Open
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
12 changes: 9 additions & 3 deletions packages/mobile-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import React from 'react';
import {
FishjamProvider as ReactClientFishjamProvider,
type FishjamProviderProps as ReactClientFishjamProviderProps,
useMicrophone as useMicrophoneReactClient
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 @@ -41,7 +42,10 @@ export {
Variant,
} from '@fishjam-cloud/react-client';

export const useMicrophone = useMicrophoneReactClient as () => Omit< ReturnType<typeof useMicrophoneReactClient>, 'toggleMicrophoneMute' >
export const useMicrophone = useMicrophoneReactClient as () => Omit<
ReturnType<typeof useMicrophoneReactClient>,
'toggleMicrophoneMute'
>;

export type {
UseInitializeDevicesParams,
Expand Down Expand Up @@ -83,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,
});
}
6 changes: 3 additions & 3 deletions packages/mobile-client/src/useForegroundService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useForegroundService as externalUseForegroundService } from '@fishjam-c

/**
* Configuration options for foreground service permissions.
*
*
* A type representing the configuration for foreground service permissions.
*/
export type ForegroundServiceConfig = {
Expand Down Expand Up @@ -38,10 +38,10 @@ export type ForegroundServiceConfig = {

/**
* Hook for managing a foreground service on Android.
*
*
* A hook for managing a foreground service on Android. Does nothing on other platforms.
* You can use this hook to keep your app running in the background. You're also required to run a foreground service when screen sharing.
*
*
* @param config - Configuration options for the foreground service.
*/
export const useForegroundService = externalUseForegroundService;
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