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

feat: add connection details in stats for nerds #3305

Merged
merged 15 commits into from
Oct 8, 2024
3 changes: 3 additions & 0 deletions packages/hms-video-store/src/IHMSActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
TokenRequestOptions,
} from './internal';
import {
DebugInfo,
HMSChangeMultiTrackStateParams,
HMSGenericTypes,
HMSMessageID,
Expand Down Expand Up @@ -581,4 +582,6 @@ export interface IHMSActions<T extends HMSGenericTypes = { sessionStore: Record<
setPlaylistSettings(settings: HMSPlaylistSettings): void;

initDiagnostics(): HMSDiagnosticsInterface;

getDebugInfo(): DebugInfo;
}
4 changes: 4 additions & 0 deletions packages/hms-video-store/src/reactive-store/HMSSDKActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,10 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st
}, reason);
}

getDebugInfo() {
return this.sdk.getDebugInfo();
}

private async sdkJoinWithListeners(config: sdkTypes.HMSConfig) {
await this.sdk.join(config, {
onJoin: this.onJoin.bind(this),
Expand Down
6 changes: 6 additions & 0 deletions packages/hms-video-store/src/schema/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ export interface HMSMediaSettings {
audioOutputDeviceId?: string;
audioMode?: HMSAudioMode;
}

export interface DebugInfo {
websocketURL?: string;
enabledFlags?: string[];
initEndpoint?: string;
}
12 changes: 12 additions & 0 deletions packages/hms-video-store/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
} from '../notification-manager';
import { createRemotePeer } from '../notification-manager/managers/utils';
import { NotificationManager } from '../notification-manager/NotificationManager';
import { DebugInfo } from '../schema';
import { SessionStore } from '../session-store';
import { InteractivityCenter } from '../session-store/interactivity-center';
import { InitConfig, InitFlags } from '../signal/init/models';
Expand Down Expand Up @@ -279,6 +280,17 @@ export class HMSSdk implements HMSInterface {
return this.transport?.getWebrtcInternals();
}

getDebugInfo(): DebugInfo {
const websocketURL = this.transport.getWebsocketEndpoint();
const enabledFlags = Object.values(InitFlags).filter(flag => this.transport.isFlagEnabled(flag));
const initEndpoint = this.store.getConfig()?.initEndpoint;
return {
websocketURL,
enabledFlags,
initEndpoint,
};
}

getSessionStore() {
return this.sessionStore;
}
Expand Down
35 changes: 32 additions & 3 deletions packages/roomkit-react/src/Prebuilt/components/StatsForNerds.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import {
selectLocalPeerID,
selectPeersMap,
selectTracksMap,
useHMSActions,
useHMSStatsStore,
useHMSStore,
} from '@100mslive/react-sdk';
import { Accordion } from '../../Accordion';
import { HorizontalDivider } from '../../Divider';
import { Dropdown } from '../../Dropdown';
import { Label } from '../../Label';
Expand All @@ -27,6 +29,8 @@ export const StatsForNerds = ({ onOpenChange }) => {
() => [{ id: 'local-peer', label: 'Local Peer Stats' }, ...tracksWithLabels],
[tracksWithLabels],
);
const hmsActions = useHMSActions();
const details = hmsActions.getDebugInfo();
const [selectedStat, setSelectedStat] = useState(statsOptions[0]);
const [showStatsOnTiles, setShowStatsOnTiles] = useSetUiSettings(UI_SETTINGS.showStatsOnTiles);
const [open, setOpen] = useState(false);
Expand All @@ -46,7 +50,7 @@ export const StatsForNerds = ({ onOpenChange }) => {
<Dialog.Content
css={{
width: 'min(500px, 95%)',
maxHeight: '100%',
height: 'min(656px, 90%)',
KaustubhKumar05 marked this conversation as resolved.
Show resolved Hide resolved
overflowY: 'auto',
}}
>
Expand All @@ -70,6 +74,7 @@ export const StatsForNerds = ({ onOpenChange }) => {
</Text>
</Flex>
{/* Select */}

<Flex
direction="column"
css={{
Expand Down Expand Up @@ -119,6 +124,9 @@ export const StatsForNerds = ({ onOpenChange }) => {
) : (
<TrackStats trackID={selectedStat.id} layer={selectedStat.layer} local={selectedStat.local} />
)}
<Flex justify="start" gap={4} css={{ m: '$10 0', w: '100%' }}>
<DebugInfo details={details} />
</Flex>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
Expand Down Expand Up @@ -229,8 +237,29 @@ const TrackStats = ({ trackID, layer, local }) => {
);
};

const StatsRow = React.memo(({ label, value }) => (
<Box css={{ bg: '$surface_bright', w: 'calc(50% - $6)', p: '$8', r: '$3' }}>
const DebugInfo = ({ details }) => {
return (
<Accordion.Root type="single" collapsible css={{ w: '100%' }}>
<Accordion.Item value="Debug Info">
<Accordion.Header>
<Label variant="body2" css={{ c: '$on_surface_high' }}>
hdz-666 marked this conversation as resolved.
Show resolved Hide resolved
Debug Info
</Label>
</Accordion.Header>
<Accordion.Content>
<Flex css={{ flexWrap: 'wrap', mt: '$10', gap: '$10' }}>
<StatsRow css={{ w: 'calc(100%)' }} label="Websocket URL" value={details?.websocketURL} />
hdz-666 marked this conversation as resolved.
Show resolved Hide resolved
<StatsRow css={{ w: 'calc(100%)' }} label="Init Endpoint" value={details?.initEndpoint} />
<StatsRow css={{ w: 'calc(100%)' }} label="Enabled flags" value={details?.enabledFlags?.join(', ')} />
</Flex>
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>
);
};

const StatsRow = React.memo(({ label, value, css }) => (
<Box css={{ bg: '$surface_bright', w: 'calc(50% - $6)', p: '$8', r: '$3', ...css }}>
<Text
variant="overline"
css={{
Expand Down
Loading