Skip to content

Commit

Permalink
Merge pull request #12186 from daily-co/pre-1301
Browse files Browse the repository at this point in the history
  • Loading branch information
Regaddi authored Nov 12, 2024
2 parents 60610da + 5178364 commit a98b38f
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/DailyDevices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, { useCallback } from 'react';
import { DailyDevicesContext } from './DailyDevicesContext';
import { useDaily } from './hooks/useDaily';
import { useDailyEvent } from './hooks/useDailyEvent';
import { jotaiDebugLabel } from './lib/jotai-custom';

type GeneralState =
| 'idle'
Expand All @@ -31,12 +32,18 @@ export interface StatefulDevice {
}

export const generalCameraState = atom<GeneralState>('idle');
generalCameraState.debugLabel = jotaiDebugLabel('camera-state');
export const generalMicrophoneState = atom<GeneralState>('idle');
generalMicrophoneState.debugLabel = jotaiDebugLabel('microphone-state');
export const cameraDevicesState = atom<StatefulDevice[]>([]);
cameraDevicesState.debugLabel = jotaiDebugLabel('camera-devices');
export const microphoneDevicesState = atom<StatefulDevice[]>([]);
microphoneDevicesState.debugLabel = jotaiDebugLabel('microphone-devices');
export const speakerDevicesState = atom<StatefulDevice[]>([]);
speakerDevicesState.debugLabel = jotaiDebugLabel('speaker-devices');
export const lastCameraErrorState =
atom<DailyCameraErrorObject<DailyCameraErrorType> | null>(null);
lastCameraErrorState.debugLabel = jotaiDebugLabel('last-camera-error');

export const DailyDevices: React.FC<React.PropsWithChildren<unknown>> = ({
children,
Expand Down
2 changes: 2 additions & 0 deletions src/DailyLiveStreaming.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useAtomCallback } from 'jotai/utils';
import React, { useCallback } from 'react';

import { useDailyEvent } from './hooks/useDailyEvent';
import { jotaiDebugLabel } from './lib/jotai-custom';

interface LiveStreamingState {
errorMsg?: string;
Expand All @@ -16,6 +17,7 @@ export const liveStreamingState = atom<LiveStreamingState>({
isLiveStreaming: false,
layout: undefined,
});
liveStreamingState.debugLabel = jotaiDebugLabel('live-streaming');

export const DailyLiveStreaming: React.FC<React.PropsWithChildren<unknown>> = ({
children,
Expand Down
5 changes: 5 additions & 0 deletions src/DailyMeeting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ import React, { useCallback } from 'react';

import { useDaily } from './hooks/useDaily';
import { useDailyEvent } from './hooks/useDailyEvent';
import { jotaiDebugLabel } from './lib/jotai-custom';

export const meetingStateState = atom<DailyMeetingState>('new');
meetingStateState.debugLabel = jotaiDebugLabel('meeting-state');

export const meetingErrorState = atom<DailyEventObjectFatalError | null>(null);
meetingErrorState.debugLabel = jotaiDebugLabel('meeting-error');

export const nonFatalErrorState = atom<DailyEventObjectNonFatalError | null>(
null
);
nonFatalErrorState.debugLabel = jotaiDebugLabel('non-fatal-error');

export const meetingSessionDataState = atom<DailyMeetingSessionState>({
data: undefined,
topology: 'none',
});
meetingSessionDataState.debugLabel = jotaiDebugLabel('meeting-session-data');

export const DailyMeeting: React.FC<React.PropsWithChildren<{}>> = ({
children,
Expand Down
4 changes: 4 additions & 0 deletions src/DailyNetwork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import React, { useCallback, useEffect } from 'react';

import { useDaily } from './hooks/useDaily';
import { useDailyEvent } from './hooks/useDailyEvent';
import { jotaiDebugLabel } from './lib/jotai-custom';

export const topologyState = atom<DailyNetworkTopology | 'none'>('none');
topologyState.debugLabel = jotaiDebugLabel('topology');
export const networkQualityState = atom<DailyNetworkStats['quality']>(100);
networkQualityState.debugLabel = jotaiDebugLabel('network-quality');
export const networkThresholdState =
atom<DailyNetworkStats['threshold']>('good');
networkThresholdState.debugLabel = jotaiDebugLabel('network-threshold');

export const DailyNetwork: React.FC<React.PropsWithChildren<{}>> = ({
children,
Expand Down
28 changes: 19 additions & 9 deletions src/DailyParticipants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from './hooks/useParticipantProperty';
import { useThrottledDailyEvent } from './hooks/useThrottledDailyEvent';
import { arraysDeepEqual, customDeepEqual } from './lib/customDeepEqual';
import { equalAtomFamily } from './lib/jotai-custom';
import { equalAtomFamily, jotaiDebugLabel } from './lib/jotai-custom';
import { getParticipantPaths } from './utils/getParticipantPaths';
import { resolveParticipantPaths } from './utils/resolveParticipantPaths';

Expand All @@ -37,28 +37,38 @@ export interface ExtendedDailyParticipant
* Stores the most recent peerId as reported from [active-speaker-change](https://docs.daily.co/reference/daily-js/events/meeting-events#active-speaker-change) event.
*/
export const activeIdState = atom<string | null>(null);
activeIdState.debugLabel = jotaiDebugLabel('active-id');

export const localIdState = atom<string>('');
localIdState.debugLabel = jotaiDebugLabel('local-id');

export const localJoinDateState = atom<Date | null>(null);
localJoinDateState.debugLabel = jotaiDebugLabel('local-join-date');

export const participantIdsState = atom<string[]>([]);
participantIdsState.debugLabel = jotaiDebugLabel('participant-ids');

export const participantState = atomFamily((_id: string) =>
atom<ExtendedDailyParticipant | null>(null)
);

export const participantState = atomFamily((id: string) => {
const participantAtom = atom<ExtendedDailyParticipant | null>(null);
participantAtom.debugLabel = jotaiDebugLabel(`participant-${id}`);
return participantAtom;
});
export const waitingParticipantsState = atom<string[]>([]);
waitingParticipantsState.debugLabel = jotaiDebugLabel('waiting-participants');

export const waitingParticipantState = atomFamily((id: string) =>
atom<DailyWaitingParticipant>({
export const waitingParticipantState = atomFamily((id: string) => {
const waitingParticipantAtom = atom<DailyWaitingParticipant>({
awaitingAccess: {
level: 'full',
},
id,
name: '',
})
);
});
waitingParticipantAtom.debugLabel = jotaiDebugLabel(
`waiting-participant-${id}`
);
return waitingParticipantAtom;
});

export const allWaitingParticipantsSelector = equalAtomFamily<
any[],
Expand Down
2 changes: 2 additions & 0 deletions src/DailyRecordings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useDailyEvent } from './hooks/useDailyEvent';
import { useLocalSessionId } from './hooks/useLocalSessionId';
import { useParticipantIds } from './hooks/useParticipantIds';
import { customDeepEqual } from './lib/customDeepEqual';
import { jotaiDebugLabel } from './lib/jotai-custom';

interface RecordingState {
/**
Expand Down Expand Up @@ -54,6 +55,7 @@ export const recordingState = atom<RecordingState>({
isLocalParticipantRecorded: false,
isRecording: false,
});
recordingState.debugLabel = jotaiDebugLabel('recording-state');

export const DailyRecordings: React.FC<React.PropsWithChildren<unknown>> = ({
children,
Expand Down
2 changes: 2 additions & 0 deletions src/DailyRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import React, { useCallback } from 'react';
import { useDaily } from './hooks/useDaily';
import { useDailyEvent } from './hooks/useDailyEvent';
import { useMeetingState } from './hooks/useMeetingState';
import { jotaiDebugLabel } from './lib/jotai-custom';

export const roomState = atom<DailyRoomInfo | null>(null);
roomState.debugLabel = jotaiDebugLabel('room-state');

export const DailyRoom: React.FC<React.PropsWithChildren<{}>> = ({
children,
Expand Down
2 changes: 2 additions & 0 deletions src/DailyTranscriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useAtomCallback } from 'jotai/utils';
import React, { useCallback } from 'react';

import { useDailyEvent } from './hooks/useDailyEvent';
import { jotaiDebugLabel } from './lib/jotai-custom';

export interface Transcription {
session_id: string;
Expand Down Expand Up @@ -51,6 +52,7 @@ export const transcriptionState = atom<TranscriptionState>({
language: 'en',
transcriptions: [],
});
transcriptionState.debugLabel = jotaiDebugLabel('transcription-state');

export const DailyTranscriptions: React.FC<React.PropsWithChildren<{}>> = ({
children,
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useCPULoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { atom, useAtomValue } from 'jotai';
import { useAtomCallback } from 'jotai/utils';
import { useCallback, useDebugValue, useEffect } from 'react';

import { jotaiDebugLabel } from '../lib/jotai-custom';
import { useDaily } from './useDaily';
import { useDailyEvent } from './useDailyEvent';
import { useMeetingState } from './useMeetingState';
Expand All @@ -17,6 +18,7 @@ const CPULoadState = atom<CPULoad>({
state: 'low',
reason: 'none',
});
CPULoadState.debugLabel = jotaiDebugLabel('cpu-load');

interface Props {
onCPULoadChange?(ev: DailyEventObject<'cpu-load-change'>): void;
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useInputSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { atom, useAtomValue } from 'jotai';
import { useAtomCallback } from 'jotai/utils';
import { useCallback, useDebugValue, useEffect } from 'react';

import { jotaiDebugLabel } from '../lib/jotai-custom';
import { Reconstruct } from '../types/Reconstruct';
import { useDaily } from './useDaily';
import { useDailyError } from './useDailyError';
Expand All @@ -25,6 +26,7 @@ interface UseInputSettingsArgs {
}

const inputSettingsState = atom<DailyInputSettings | null>(null);
inputSettingsState.debugLabel = jotaiDebugLabel('input-settings');

export const useInputSettings = ({
onError,
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useParticipantCounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { atom, useAtomValue } from 'jotai';
import { useAtomCallback } from 'jotai/utils';
import { useCallback, useDebugValue, useEffect } from 'react';

import { jotaiDebugLabel } from '../lib/jotai-custom';
import { useDaily } from './useDaily';
import { useDailyEvent } from './useDailyEvent';

const participantCountsState = atom<DailyParticipantCounts>({
hidden: 0,
present: 0,
});
participantCountsState.debugLabel = jotaiDebugLabel('participant-counts');

interface Props {
onParticipantCountsUpdated?(
Expand Down
24 changes: 17 additions & 7 deletions src/hooks/useParticipantProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useDebugValue } from 'react';

import { ExtendedDailyParticipant } from '../DailyParticipants';
import { arraysDeepEqual } from '../lib/customDeepEqual';
import { equalAtomFamily } from '../lib/jotai-custom';
import { equalAtomFamily, jotaiDebugLabel } from '../lib/jotai-custom';
import type { NumericKeys } from '../types/NumericKeys';
import type { Paths } from '../types/paths';
import type { PathValue } from '../types/pathValue';
Expand All @@ -28,16 +28,26 @@ export const getParticipantPropertyAtom = (
/**
* Stores all property paths for a given participant.
*/
export const participantPropertyPathsState = atomFamily((_id: string) =>
atom<Paths<ExtendedDailyParticipant>[]>([])
);
export const participantPropertyPathsState = atomFamily((id: string) => {
const participantPropertyPathsAtom = atom<Paths<ExtendedDailyParticipant>[]>(
[]
);
participantPropertyPathsAtom.debugLabel = jotaiDebugLabel(
`participant-property-paths-${id}`
);
return participantPropertyPathsAtom;
});

/**
* Stores resolved values for each participant and property path.
*/
export const participantPropertyState = atomFamily((_param: string) =>
atom<any>(null)
);
export const participantPropertyState = atomFamily((param: string) => {
const participantPropertyAtom = atom<any>(null);
participantPropertyAtom.debugLabel = jotaiDebugLabel(
`participant-property-${param}`
);
return participantPropertyAtom;
});

/**
* Stores resolved values for each participant and property path.
Expand Down
7 changes: 6 additions & 1 deletion src/hooks/useReceiveSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useAtomCallback } from 'jotai/utils';
import { atomFamily } from 'jotai/utils';
import { useCallback, useDebugValue, useEffect } from 'react';

import { jotaiDebugLabel } from '../lib/jotai-custom';
import { useDaily } from './useDaily';
import { useDailyEvent } from './useDailyEvent';
import { useMeetingState } from './useMeetingState';
Expand All @@ -21,13 +22,17 @@ const participantReceiveSettingsState = atomFamily<
void
>
>((id) => {
return atom<
const participantReceiveSettingsAtom = atom<
DailySingleParticipantReceiveSettings,
[DailySingleParticipantReceiveSettings],
void
>({}, (_get, set, newValue) => {
set(participantReceiveSettingsState(id), newValue);
});
participantReceiveSettingsAtom.debugLabel = jotaiDebugLabel(
`participant-receive-settings-${id}`
);
return participantReceiveSettingsAtom;
});

interface UseReceiveSettingsArgs {
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useSendSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
import { atom, useAtom } from 'jotai';
import { useCallback, useDebugValue, useEffect } from 'react';

import { jotaiDebugLabel } from '../lib/jotai-custom';
import { useDaily } from './useDaily';
import { useDailyEvent } from './useDailyEvent';

const sendSettingsState = atom<DailySendSettings | null>(null);
sendSettingsState.debugLabel = jotaiDebugLabel('send-settings');

interface Props {
onSendSettingsUpdated?(ev: DailyEventObject<'send-settings-updated'>): void;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/jotai-custom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { atom, Getter, WritableAtom } from 'jotai';

export function jotaiDebugLabel(label: string) {
return 'daily-react-' + label;
}

interface EqualAtomOptions<T> {
key?: string;
get: () => T;
Expand Down

0 comments on commit a98b38f

Please sign in to comment.