Skip to content

Commit

Permalink
feat: add livekit member panel
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Nov 18, 2023
1 parent c937178 commit 19a1e5d
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 62 deletions.
1 change: 1 addition & 0 deletions client/web/src/plugin/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export { ErrorBoundary } from '@/components/ErrorBoundary';
export { ErrorView } from '@/components/ErrorView';
export { UserAvatar } from '@/components/UserAvatar';
export { UserName } from '@/components/UserName';
export { UserListItem } from '@/components/UserListItem';
export { Markdown, MarkdownEditor } from '@/components/Markdown';
export { Webview, WebviewKeepAlive } from '@/components/Webview';
export { Card } from '@/components/Card';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import * as React from 'react';
import { Translate } from '../../translate';
import { cloneSingleChild } from '../../utils/common';
import { useObservableState } from '../../utils/useObservableState';
// import { useRoomContext } from '../context';
// import { useObservableState } from '../hooks/internal/useObservableState';
// import { cloneSingleChild } from '../utils';
// import type { MessageFormatter } from '../components/ChatEntry';
// import { ChatEntry } from '../components/ChatEntry';

export type { ChatMessage, ReceivedChatMessage };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as React from 'react';

import { supportsScreenSharing } from '@livekit/components-core';
import {
ChatToggle,
DisconnectButton,
MediaDeviceMenu,
StartAudio,
Expand All @@ -13,15 +12,15 @@ import {
} from '@livekit/components-react';
import { Translate } from '../../translate';
import { useMediaQuery } from '../../utils/useMediaQuery';
import { ChatIcon } from './icons/ChatIcon';
import { LeaveIcon } from './icons/LeaveIcon';
import { useMeetingContextState } from '../../context/MeetingContext';
import { Icon } from '@capital/component';

/** @public */
export type ControlBarControls = {
microphone?: boolean;
camera?: boolean;
chat?: boolean;
member?: boolean;
screenShare?: boolean;
leave?: boolean;
};
Expand Down Expand Up @@ -71,13 +70,15 @@ export function ControlBar({ variation, controls, ...props }: ControlBarProps) {
if (!localPermissions) {
visibleControls.camera = false;
visibleControls.chat = false;
visibleControls.member = false;
visibleControls.microphone = false;
visibleControls.screenShare = false;
} else {
visibleControls.camera ??= localPermissions.canPublish;
visibleControls.microphone ??= localPermissions.canPublish;
visibleControls.screenShare ??= localPermissions.canPublish;
visibleControls.chat ??= localPermissions.canPublishData && controls?.chat;
visibleControls.chat ??= localPermissions.canPublishData;
visibleControls.member ??= localPermissions.canSubscribe;
}

const showIcon = React.useMemo(
Expand Down Expand Up @@ -137,14 +138,21 @@ export function ControlBar({ variation, controls, ...props }: ControlBarProps) {

{visibleControls.chat && (
<button className="lk-button" onClick={() => setRightPanel('chat')}>
{showIcon && <ChatIcon />}
{showIcon && <Icon icon="mdi:message-reply-text-outline" />}
{showText && Translate.chat}
</button>
)}

{visibleControls.member && (
<button className="lk-button" onClick={() => setRightPanel('member')}>
{showIcon && <Icon icon="mdi:account-multiple" />}
{showText && Translate.member}
</button>
)}

{visibleControls.leave && (
<DisconnectButton>
{showIcon && <LeaveIcon />}
{showIcon && <Icon icon="mdi:logout-variant" />}
{showText && Translate.leave}
</DisconnectButton>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useParticipants } from '@livekit/components-react';
import * as React from 'react';
import styled from 'styled-components';
import { Icon, UserListItem } from '@capital/component';
import { useEvent } from '@capital/common';
import type { Participant } from 'livekit-client';
import { Translate } from '../../translate';

const MemberList = styled.div`
display: flex;
flex-direction: column;
align-items: stretch;
width: clamp(200px, 55ch, 60ch);
background-color: var(--lk-bg2);
border-left: 1px solid var(--lk-border-color);
padding: 8px;
`;

const IsSpeakingTip = styled.div`
font-size: 12px;
opacity: 0.6;
`;

export const Member: React.FC = React.memo(() => {
const participants = useParticipants();

const getAction = useEvent((participant: Participant) => {
return [
!participant.isSpeaking && (
<IsSpeakingTip>({Translate.isSpeaking})</IsSpeakingTip>
),
<div key="mic-state">
{participant.isMicrophoneEnabled ? (
<Icon icon="mdi:microphone" />
) : (
<Icon icon="mdi:microphone-off" />
)}
</div>,
];
});

return (
<MemberList>
{participants.map((member) => (
<UserListItem
key={member.sid}
userId={member.identity}
actions={getAction(member)}
/>
))}
</MemberList>
);
});
Member.displayName = 'Member';
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ControlBar } from './ControlBar';
import { Chat } from './Chat';
import { FocusLayout } from './FocusLayout';
import { useMeetingContextState } from '../../context/MeetingContext';
import { Member } from './Member';

/**
* @public
Expand Down Expand Up @@ -145,12 +146,14 @@ export const VideoConference: React.FC<VideoConferenceProps> = React.memo(
</div>
)}

<ControlBar controls={{ chat: true }} />
<ControlBar />
</div>

{rightPanel === 'chat' && (
<Chat messageFormatter={chatMessageFormatter} />
)}

{rightPanel === 'member' && <Member />}
</LayoutContextProvider>
)}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export const Translate = {
'zh-CN': '聊天',
'en-US': 'Chat',
}),
member: localTrans({
'zh-CN': '成员',
'en-US': 'Member',
}),
leave: localTrans({
'zh-CN': '离开',
'en-US': 'Leave',
Expand All @@ -53,6 +57,10 @@ export const Translate = {
'zh-CN': '输入消息...',
'en-US': 'Enter a message...',
}),
isSpeaking: localTrans({
'zh-CN': '正在发言',
'en-US': 'Is speaking',
}),
nobodyInMeeting: localTrans({
'zh-CN': '当前无人在会...',
'en-US': 'Nobody in Meeting...',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export function useObservableState<T>(
startWith: T
) {
const [state, setState] = React.useState<T>(startWith);

React.useEffect(() => {
// observable state doesn't run in SSR
if (typeof window === 'undefined' || !observable) return;
const subscription = observable.subscribe(setState);
return () => subscription.unsubscribe();
}, [observable]);

return state;
}

0 comments on commit 19a1e5d

Please sign in to comment.