import React from 'react' import { useAppSelector } from '@/app/hooks' import type { TimelineMessage } from '@/types' import { Message } from './Message' const DATA_CHANNEL_COLORS: { [key: string]: string } = { signaling: '#ff00ff', notify: '#ffff00', push: '#98fb98', e2ee: '#00ffff', stats: '#ffc0cb', } const WebSocketLabel: React.FC = () => { return ( [websocket] ) } const PeerConnectionLabel: React.FC = () => { return ( [peerconnection] ) } const SoraLabel: React.FC = () => { return ( [sora] ) } const SoraDevtoolsLabel: React.FC = () => { return ( [sora-devtools] ) } type DataChannelLabelProps = { id?: number | null label?: string | null } const DataChannelLabel: React.FC = (props) => { const { label, id } = props const color = label && Object.keys(DATA_CHANNEL_COLORS).includes(label) ? DATA_CHANNEL_COLORS[label] : undefined return ( [datachannel]{label ? `[${label}]` : ''} {typeof id === 'number' ? `[${id}]` : ''} ) } const Collapse: React.FC = (props) => { const { timestamp, logType, dataChannelId, dataChannelLabel, type, data } = props const title = `${type}` let labelComponent if (logType === 'websocket') { labelComponent = } else if (logType === 'datachannel') { labelComponent = } else if (logType === 'peerconnection') { labelComponent = } else if (logType === 'sora') { labelComponent = } else if (logType === 'sora-devtools') { labelComponent = } return } const Log = React.memo((props: TimelineMessage) => { return }) export const TimelineMessages: React.FC = () => { const timelineMessages = useAppSelector((state) => state.timelineMessages) const debugFilterText = useAppSelector((state) => state.debugFilterText) const filteredMessages = timelineMessages.filter((message) => { return debugFilterText.split(' ').every((filterText) => { if (filterText === '') { return true } return 0 <= JSON.stringify(message).indexOf(filterText) }) }) return (
{filteredMessages.map((message) => { let key = `${message.timestamp}-${message.type}` // datachannel onopen が同時刻に発火することがあるため key に datachannel label を追加する if (message.dataChannelLabel) { key += `-${message.dataChannelLabel}` } return })}
) }