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

Improve devtools more #661

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function CommunicationChannelStatisticsView({
<StyledDevtoolsHeaderCell
content={t(
'boardBar.developerToolsDialog.communicationChannelStatistics.localSessionId',
'Local Session Id',
'Local Session ID',
)}
/>
<StyledDevtoolsHeaderCell
Expand All @@ -56,10 +56,10 @@ export function CommunicationChannelStatisticsView({
</TableHead>
<TableBody>
<TableRow>
<StyledDevtoolsTableCell align="right">
<StyledDevtoolsTableCell align="center" monospace={true}>
{communicationChannel.localSessionId}
</StyledDevtoolsTableCell>
<StyledDevtoolsTableCell align="right">
<StyledDevtoolsTableCell align="center">
{Object.keys(communicationChannel.peerConnections).length}
</StyledDevtoolsTableCell>
</TableRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
Typography,
} from '@mui/material';
import { unstable_useId as useId } from '@mui/utils';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useActiveWhiteboardInstanceStatistics } from '../../state';
import { CommunicationChannelStatisticsView } from './CommunicationChannelStatisticsView';
Expand All @@ -47,6 +48,27 @@ export function DeveloperToolsDialog({
const { document, communicationChannel } =
useActiveWhiteboardInstanceStatistics();

const sessions = useMemo(
() =>
communicationChannel.sessions
?.filter(
(s) =>
s.sessionId !== communicationChannel.localSessionId &&
s.expiresTs - Date.now() > 0,
)
.map((s) => ({
...s,
status: Object.values(communicationChannel.peerConnections).find(
(p) => p.remoteSessionId === s.sessionId,
)?.connectionState,
})),
[
communicationChannel.sessions,
communicationChannel.localSessionId,
communicationChannel.peerConnections,
],
);

const dialogTitleId = useId();
const dialogDescriptionId = useId();

Expand Down Expand Up @@ -132,13 +154,7 @@ export function DeveloperToolsDialog({
</Typography>
</AccordionSummary>
<AccordionDetails>
<WhiteboardSessionsTable
sessions={communicationChannel.sessions?.filter(
(s) =>
s.sessionId !== communicationChannel.localSessionId &&
s.expiresTs - Date.now() > 0,
)}
/>
<WhiteboardSessionsTable sessions={sessions} />
</AccordionDetails>
</Accordion>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function DocumentSyncStatisticsView({
<StyledDevtoolsHeaderCell
content={t(
'boardBar.developerToolsDialog.documentSyncStatistics.binaryJsonSize',
'Binary / JSON Size (bytes)',
'Binary Size / JSON Size',
)}
/>
<StyledDevtoolsHeaderCell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ export function PeerConnectionDetail({
<StyledDevtoolsTableCell>
{t(
'boardBar.developerToolsDialog.communicationChannelStatistics.remoteSessionId',
'Remote Session Id',
'Remote Session ID',
)}
</StyledDevtoolsTableCell>
<StyledDevtoolsTableCell>
<StyledDevtoolsTableCell monospace={true}>
{peerConnection.remoteSessionId}
</StyledDevtoolsTableCell>
</TableRow>
<TableRow>
<StyledDevtoolsTableCell>
{t(
'boardBar.developerToolsDialog.communicationChannelStatistics.userId',
'User Id',
'User ID',
)}
</StyledDevtoolsTableCell>
<StyledDevtoolsTableCell>
<StyledDevtoolsTableCell monospace={true}>
{peerConnection.remoteUserId}
</StyledDevtoolsTableCell>
</TableRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ const StyledTable = styled(Table)({
borderCollapse: 'collapse',
});

const StyledTableCell = styled(TableCell)(({ theme }) => ({
fontSize: '0.875rem',
padding: '8px 16px',
borderBottom: `1px solid ${theme.palette.divider}`,
'&:not(:last-child)': {
borderRight: `1px solid ${theme.palette.divider}`,
},
}));
interface StyledTableCellProps {
monospace?: boolean;
}

const StyledTableCell = styled(TableCell)<StyledTableCellProps>(
({ monospace, theme }) => ({
fontSize: '0.875rem',
padding: '8px 16px',
borderBottom: `1px solid ${theme.palette.divider}`,
'&:not(:last-child)': {
borderRight: `1px solid ${theme.palette.divider}`,
},
...(monospace ? { fontFamily: 'monospace' } : undefined),
}),
);

const HeaderCell = styled(StyledTableCell)(({ theme }) => ({
fontWeight: 'bold',
Expand All @@ -54,12 +61,14 @@ export function StyledDevtoolsTableCell({
children,
colSpan,
align,
monospace,
}: PropsWithChildren<{
colSpan?: number;
align?: 'inherit' | 'left' | 'center' | 'right' | 'justify';
monospace?: boolean;
}>) {
return (
<StyledTableCell colSpan={colSpan} align={align}>
<StyledTableCell colSpan={colSpan} align={align} monospace={monospace}>
{children}
</StyledTableCell>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/

import { TableBody, TableHead, TableRow } from '@mui/material';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useInterval } from 'react-use';
import { SessionState } from '../../state/communication/discovery/sessionManagerImpl';
import {
StyledDevtoolsHeaderCell,
Expand All @@ -26,9 +28,13 @@ import {
export function WhiteboardSessionsTable({
sessions,
}: {
sessions: SessionState[] | undefined;
sessions: (SessionState & { status?: string })[] | undefined;
}) {
const { t } = useTranslation('neoboard');
const [now, setNow] = useState(Date.now());
useInterval(() => {
setNow(Date.now());
}, 1000);

return (
<StyledDevtoolsTable
Expand All @@ -53,29 +59,38 @@ export function WhiteboardSessionsTable({
/>
<StyledDevtoolsHeaderCell
content={t(
'boardBar.developerToolsDialog.communicationChannelStatistics.whiteboardSessionsTable.expiresState',
'boardBar.developerToolsDialog.communicationChannelStatistics.whiteboardSessionsTable.state',
'State',
)}
/>
<StyledDevtoolsHeaderCell
content={t(
'boardBar.developerToolsDialog.communicationChannelStatistics.whiteboardSessionsTable.lifetime',
'Remaining',
)}
/>
</TableRow>
</TableHead>
<TableBody>
{sessions && sessions.length > 0 ? (
sessions
.sort((a, b) => a.userId.localeCompare(b.userId))
.map((session) => (
<TableRow key={session.userId}>
<StyledDevtoolsTableCell align="left">
<TableRow key={session.userId + session.sessionId}>
<StyledDevtoolsTableCell align="left" monospace={true}>
{session.userId}
</StyledDevtoolsTableCell>
<StyledDevtoolsTableCell align="left">
<StyledDevtoolsTableCell align="left" monospace={true}>
{session.sessionId}
</StyledDevtoolsTableCell>
<StyledDevtoolsTableCell align="right">
<StyledDevtoolsTableCell align="left">
{session.status}
</StyledDevtoolsTableCell>
<StyledDevtoolsTableCell align="left" monospace={true}>
{t(
'boardBar.developerToolsDialog.communicationChannelStatistics.whiteboardSessionsTable.expire',
'Session will expire in {{expire}}.',
{ expire: formatTime(session.expiresTs - Date.now()) },
'{{minutes}}:{{seconds}}',
formatTime(Math.max(0, session.expiresTs - now)),
)}
</StyledDevtoolsTableCell>
</TableRow>
Expand All @@ -95,9 +110,15 @@ export function WhiteboardSessionsTable({
);
}

function formatTime(milliseconds: number): string {
const minutes = Math.floor(milliseconds / 60000);
const seconds = Math.floor((milliseconds % 60000) / 1000);

return `${minutes}m ${seconds}s`;
function formatTime(milliseconds: number): {
minutes: string;
seconds: string;
} {
const minutes = Math.floor(milliseconds / 60000)
.toString()
.padStart(2, '0');
const seconds = Math.floor((milliseconds % 60000) / 1000)
.toString()
.padStart(2, '0');
return { minutes, seconds };
}
11 changes: 6 additions & 5 deletions packages/react-sdk/src/locales/de/neoboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@
"true": "wahr",
"userId": "Benutzer-ID",
"whiteboardSessionsTable": {
"expire": "Die Sitzung läuft in {{expire}} ab.",
"expiresState": "Status",
"expire": "{{minutes}}:{{seconds}}",
"lifetime": "Läuft ab in",
"noData": "Keine Whiteboard-Sitzungen verfügbar",
"sessionId": "Sitzungs",
"sessionId": "Sitzungs-ID",
"state": "Status",
"tableAriaLabel": "Whiteboard-Sitzungen",
"userId": "Benutzer-ID"
}
},
"communicationChannelStatisticsTitle": "Statistiken der Kommunikationskanäle (WRTC)",
"documentSyncStatistics": {
"binaryJsonSize": "Binär / JSON-Größe (Bytes)",
"binaryJsonSize": "Binär-Größe / JSON-Größe",
"false": "falsch",
"noData": "Keine Daten verfügbar",
"outstanding": "Ausstehend",
Expand All @@ -44,7 +45,7 @@
"true": "wahr"
},
"documentSyncStatisticsTitle": "Statistiken der Dokumentensynchronisation (Snapshots)",
"sessions": "Sitzungs-ID",
"sessions": "Sitzungen",
"title": "Entwicklerwerkzeuge"
},
"exportWhiteboardDialog": {
Expand Down
13 changes: 7 additions & 6 deletions packages/react-sdk/src/locales/en/neoboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@
"dataChannel": "Data Channel",
"dataTransfer": "Data Transfer",
"impolite": "Impolite",
"localSessionId": "Local Session Id",
"localSessionId": "Local Session ID",
"messagesReceived": "Messages Received",
"peers": "Peers",
"received": "Received",
"remoteSessionId": "Remote Session Id",
"remoteSessionId": "Remote Session ID",
"signaling": "Signaling",
"tableAriaLabel": "Communication Channel Statistics",
"true": "true",
"userId": "User Id",
"userId": "User ID",
"whiteboardSessionsTable": {
"expire": "Session will expire in {{expire}}.",
"expiresState": "State",
"expire": "{{minutes}}:{{seconds}}",
"lifetime": "Remaining",
"noData": "No whiteboard sessions available",
"sessionId": "Session ID",
"state": "State",
"tableAriaLabel": "Whiteboard Sessions",
"userId": "User ID"
}
},
"communicationChannelStatisticsTitle": "Communication Channel Statistics (WRTC)",
"documentSyncStatistics": {
"binaryJsonSize": "Binary / JSON Size (bytes)",
"binaryJsonSize": "Binary Size / JSON Size",
"false": "false",
"noData": "No data available",
"outstanding": "Outstanding",
Expand Down
Loading