refactor: migrate voice context menus to centralized store
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
import React, { useRef, useEffect, useState, useCallback } from 'react';
|
import React, { useRef, useEffect, useState, useCallback } from 'react';
|
||||||
import { Avatar } from '../ui/Avatar';
|
import { Avatar } from '../ui/Avatar';
|
||||||
import { useVoiceStore } from '../../stores/voiceStore';
|
import { useVoiceStore } from '../../stores/voiceStore';
|
||||||
|
import { useContextMenuStore, type ContextMenuItem } from '../../stores/contextMenuStore';
|
||||||
import { getActiveRoom, setStreamSubscription } from '../../hooks/useLiveKit';
|
import { getActiveRoom, setStreamSubscription } from '../../hooks/useLiveKit';
|
||||||
import { StreamContextMenu } from './StreamContextMenu';
|
import { stopScreenShare, changeScreenShare } from '../../utils/screenShare';
|
||||||
|
import { ScreenShareSettingsPopover } from './ScreenShareSettingsPopover';
|
||||||
import { useVoiceParticipantMeta } from '../../hooks/useVoiceParticipantMeta';
|
import { useVoiceParticipantMeta } from '../../hooks/useVoiceParticipantMeta';
|
||||||
import type { StreamTile as StreamTileType } from '../../hooks/useLiveKit';
|
import type { StreamTile as StreamTileType } from '../../hooks/useLiveKit';
|
||||||
|
|
||||||
@@ -11,6 +13,133 @@ interface StreamTileProps {
|
|||||||
large?: boolean;
|
large?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Wrapper component for stream quality settings — needs its own state + close guard. */
|
||||||
|
function StreamQualityItem() {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const btnRef = useRef<HTMLButtonElement>(null);
|
||||||
|
const setCloseGuard = useContextMenuStore((s) => s.setCloseGuard);
|
||||||
|
const screenShareConfig = useVoiceStore((s) => s.screenShareConfig);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-3">
|
||||||
|
<div className="text-xs text-txt-tertiary mb-2 font-medium uppercase tracking-wider">
|
||||||
|
Stream Quality
|
||||||
|
</div>
|
||||||
|
<div className="relative">
|
||||||
|
<button
|
||||||
|
ref={btnRef}
|
||||||
|
onClick={() => {
|
||||||
|
const n = !open;
|
||||||
|
setOpen(n);
|
||||||
|
setCloseGuard(n);
|
||||||
|
}}
|
||||||
|
className="w-full flex items-center justify-between px-2 py-1.5 text-sm text-txt-secondary hover:bg-interactive-hover rounded transition-colors"
|
||||||
|
>
|
||||||
|
<span>{screenShareConfig.height}p {screenShareConfig.fps}fps</span>
|
||||||
|
<svg width="12" height="12" viewBox="0 0 24 24" fill="currentColor">
|
||||||
|
<path d="M7 10l5 5 5-5z" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
{open && (
|
||||||
|
<ScreenShareSettingsPopover
|
||||||
|
open={open}
|
||||||
|
onClose={() => {
|
||||||
|
setOpen(false);
|
||||||
|
setCloseGuard(false);
|
||||||
|
}}
|
||||||
|
anchorRef={btnRef}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Wrapper component for stream volume slider — needs store subscription. */
|
||||||
|
function StreamVolumeItem({ userId }: { userId: string }) {
|
||||||
|
const streamVolume = useVoiceStore((s) => s.streamVolumes.get(userId) ?? 100);
|
||||||
|
const setStreamVolume = useVoiceStore((s) => s.setStreamVolume);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-3">
|
||||||
|
<div className="text-xs text-txt-tertiary mb-2 font-medium uppercase tracking-wider">
|
||||||
|
Stream Volume
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" className="text-txt-tertiary flex-shrink-0">
|
||||||
|
<path d="M3 9v6h4l5 5V4L7 9H3z" />
|
||||||
|
</svg>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min="0"
|
||||||
|
max="200"
|
||||||
|
value={streamVolume}
|
||||||
|
onChange={(e) => setStreamVolume(userId, parseInt(e.target.value))}
|
||||||
|
className="flex-1 accent-accent-primary h-1"
|
||||||
|
/>
|
||||||
|
<span className="text-xs text-txt-secondary min-w-[32px] text-right">
|
||||||
|
{streamVolume}%
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Wrapper component for stream attenuation controls — needs store subscription. */
|
||||||
|
function StreamAttenuationItem() {
|
||||||
|
const streamAttenuationEnabled = useVoiceStore((s) => s.streamAttenuationEnabled);
|
||||||
|
const streamAttenuationStrength = useVoiceStore((s) => s.streamAttenuationStrength);
|
||||||
|
const setAttenuationEnabled = useVoiceStore((s) => s.setStreamAttenuationEnabled);
|
||||||
|
const setAttenuationStrength = useVoiceStore((s) => s.setStreamAttenuationStrength);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="py-1.5">
|
||||||
|
<button
|
||||||
|
onClick={() => setAttenuationEnabled(!streamAttenuationEnabled)}
|
||||||
|
className="w-full text-left px-2 py-1.5 mx-1.5 text-sm rounded-sm flex items-center gap-2 text-txt-secondary hover:bg-accent-primary hover:text-white"
|
||||||
|
style={{ width: 'calc(100% - 12px)' }}
|
||||||
|
>
|
||||||
|
<span className="flex-1">Stream Attenuation</span>
|
||||||
|
<div
|
||||||
|
className={`w-4 h-4 rounded border flex items-center justify-center transition-colors ${
|
||||||
|
streamAttenuationEnabled
|
||||||
|
? 'bg-accent-primary border-accent-primary'
|
||||||
|
: 'border-txt-tertiary'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{streamAttenuationEnabled && (
|
||||||
|
<svg width="10" height="10" viewBox="0 0 24 24" fill="white">
|
||||||
|
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
|
||||||
|
</svg>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{streamAttenuationEnabled && (
|
||||||
|
<div className="p-3 pt-0">
|
||||||
|
<div className="text-xs text-txt-tertiary mb-2 font-medium uppercase tracking-wider">
|
||||||
|
Attenuation Strength
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min="0"
|
||||||
|
max="100"
|
||||||
|
value={streamAttenuationStrength}
|
||||||
|
onChange={(e) => setAttenuationStrength(parseInt(e.target.value))}
|
||||||
|
className="flex-1 accent-accent-primary h-1"
|
||||||
|
/>
|
||||||
|
<span className="text-xs text-txt-secondary min-w-[32px] text-right">
|
||||||
|
{streamAttenuationStrength}%
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function StreamTile({ tile, large }: StreamTileProps) {
|
export function StreamTile({ tile, large }: StreamTileProps) {
|
||||||
const videoRef = useRef<HTMLVideoElement>(null);
|
const videoRef = useRef<HTMLVideoElement>(null);
|
||||||
|
|
||||||
@@ -30,8 +159,7 @@ export function StreamTile({ tile, large }: StreamTileProps) {
|
|||||||
// Quality badge state
|
// Quality badge state
|
||||||
const [qualityBadge, setQualityBadge] = useState<string>('');
|
const [qualityBadge, setQualityBadge] = useState<string>('');
|
||||||
|
|
||||||
// Context menu state
|
const openContextMenu = useContextMenuStore((s) => s.open);
|
||||||
const [contextMenu, setContextMenu] = useState<{ x: number; y: number } | null>(null);
|
|
||||||
|
|
||||||
// --- VIDEO --- use LiveKit's track.attach() to register the element
|
// --- VIDEO --- use LiveKit's track.attach() to register the element
|
||||||
// with the adaptive stream observer (enables SFU layer switching by viewport size)
|
// with the adaptive stream observer (enables SFU layer switching by viewport size)
|
||||||
@@ -80,9 +208,114 @@ export function StreamTile({ tile, large }: StreamTileProps) {
|
|||||||
const handleContextMenu = useCallback(
|
const handleContextMenu = useCallback(
|
||||||
(e: React.MouseEvent) => {
|
(e: React.MouseEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setContextMenu({ x: e.clientX, y: e.clientY });
|
|
||||||
|
const items: ContextMenuItem[] = [];
|
||||||
|
|
||||||
|
if (isLocal) {
|
||||||
|
// Local stream: stop, change, quality
|
||||||
|
items.push({
|
||||||
|
key: 'stop-streaming',
|
||||||
|
type: 'action',
|
||||||
|
label: 'Stop Streaming',
|
||||||
|
danger: true,
|
||||||
|
icon: React.createElement('svg', { width: 14, height: 14, viewBox: '0 0 24 24', fill: 'currentColor', className: 'flex-shrink-0' },
|
||||||
|
React.createElement('path', { d: 'M21 3H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h7v2H8v2h8v-2h-2v-2h7c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 14H3V5h18v12z' }),
|
||||||
|
React.createElement('line', { x1: 4, y1: 4, x2: 20, y2: 20, stroke: 'currentColor', strokeWidth: 2 }),
|
||||||
|
),
|
||||||
|
onClick: async () => {
|
||||||
|
const room = getActiveRoom();
|
||||||
|
if (room) {
|
||||||
|
await stopScreenShare(room);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[],
|
});
|
||||||
|
items.push({
|
||||||
|
key: 'change-stream',
|
||||||
|
type: 'action',
|
||||||
|
label: 'Change Stream',
|
||||||
|
icon: React.createElement('svg', { width: 14, height: 14, viewBox: '0 0 24 24', fill: 'currentColor', className: 'flex-shrink-0' },
|
||||||
|
React.createElement('path', { d: 'M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z' }),
|
||||||
|
),
|
||||||
|
onClick: async () => {
|
||||||
|
const room = getActiveRoom();
|
||||||
|
if (room) {
|
||||||
|
await changeScreenShare(room);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
items.push({ key: 'quality-sep', type: 'separator' });
|
||||||
|
items.push({
|
||||||
|
key: 'stream-quality',
|
||||||
|
type: 'custom',
|
||||||
|
render: () => React.createElement(StreamQualityItem),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Remote stream: watch/unwatch, mute, volume, attenuation
|
||||||
|
const currentIsWatching = useVoiceStore.getState().watchingStreams.has(userId);
|
||||||
|
const identity = participant.identity;
|
||||||
|
|
||||||
|
if (currentIsWatching) {
|
||||||
|
items.push({
|
||||||
|
key: 'stop-watching',
|
||||||
|
type: 'action',
|
||||||
|
label: 'Stop Watching',
|
||||||
|
icon: React.createElement('svg', { width: 14, height: 14, viewBox: '0 0 24 24', fill: 'currentColor', className: 'flex-shrink-0' },
|
||||||
|
React.createElement('path', { d: 'M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z' }),
|
||||||
|
),
|
||||||
|
onClick: () => {
|
||||||
|
useVoiceStore.getState().unwatchStream(userId);
|
||||||
|
setStreamSubscription(getActiveRoom(), identity, false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
items.push({
|
||||||
|
key: 'watch-stream',
|
||||||
|
type: 'action',
|
||||||
|
label: 'Watch Stream',
|
||||||
|
icon: React.createElement('svg', { width: 14, height: 14, viewBox: '0 0 24 24', fill: 'currentColor', className: 'flex-shrink-0' },
|
||||||
|
React.createElement('path', { d: 'M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z' }),
|
||||||
|
),
|
||||||
|
onClick: () => {
|
||||||
|
useVoiceStore.getState().watchStream(userId);
|
||||||
|
setStreamSubscription(getActiveRoom(), identity, true);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
items.push({ key: 'watch-sep', type: 'separator' });
|
||||||
|
|
||||||
|
// Mute Stream checkbox
|
||||||
|
const isStreamMuted = useVoiceStore.getState().streamMutes.get(userId) ?? false;
|
||||||
|
items.push({
|
||||||
|
key: 'mute-stream',
|
||||||
|
type: 'checkbox',
|
||||||
|
label: 'Mute Stream',
|
||||||
|
checked: isStreamMuted,
|
||||||
|
onChange: (checked) => useVoiceStore.getState().setStreamMute(userId, checked),
|
||||||
|
});
|
||||||
|
|
||||||
|
items.push({ key: 'vol-sep', type: 'separator' });
|
||||||
|
|
||||||
|
// Stream volume slider
|
||||||
|
items.push({
|
||||||
|
key: 'stream-volume',
|
||||||
|
type: 'custom',
|
||||||
|
render: () => React.createElement(StreamVolumeItem, { userId }),
|
||||||
|
});
|
||||||
|
|
||||||
|
items.push({ key: 'attenuation-sep', type: 'separator' });
|
||||||
|
|
||||||
|
// Stream attenuation controls
|
||||||
|
items.push({
|
||||||
|
key: 'stream-attenuation',
|
||||||
|
type: 'custom',
|
||||||
|
render: () => React.createElement(StreamAttenuationItem),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
openContextMenu({ x: e.clientX, y: e.clientY }, items);
|
||||||
|
},
|
||||||
|
[isLocal, userId, participant.identity, openContextMenu],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleWatch = useCallback(() => {
|
const handleWatch = useCallback(() => {
|
||||||
@@ -163,17 +396,6 @@ export function StreamTile({ tile, large }: StreamTileProps) {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Context Menu */}
|
|
||||||
{contextMenu && (
|
|
||||||
<StreamContextMenu
|
|
||||||
userId={userId}
|
|
||||||
identity={participant.identity}
|
|
||||||
isLocal={isLocal}
|
|
||||||
position={contextMenu}
|
|
||||||
onClose={() => setContextMenu(null)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import { useVoiceStore } from '../../stores/voiceStore';
|
|||||||
import { useSpaceStore, getChannelOrigin } from '../../stores/spaceStore';
|
import { useSpaceStore, getChannelOrigin } from '../../stores/spaceStore';
|
||||||
import { useAuthStore } from '../../stores/authStore';
|
import { useAuthStore } from '../../stores/authStore';
|
||||||
import { Avatar } from '../ui/Avatar';
|
import { Avatar } from '../ui/Avatar';
|
||||||
import { VoiceUserContextMenu } from './VoiceUserContextMenu';
|
import { useContextMenuStore, type ContextMenuItem } from '../../stores/contextMenuStore';
|
||||||
|
import { buildVoiceModMenuItems } from './voiceMenuItems';
|
||||||
import { wsSend } from '../../hooks/useWebSocket';
|
import { wsSend } from '../../hooks/useWebSocket';
|
||||||
import { hasPermissionBit, PermissionBits } from '../../utils/permissions';
|
import { hasPermissionBit, PermissionBits } from '../../utils/permissions';
|
||||||
|
|
||||||
@@ -26,6 +27,36 @@ interface VoiceChannelProps {
|
|||||||
onDragEnd?: () => void;
|
onDragEnd?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Wrapper component for the volume slider so it can use hooks (useState). */
|
||||||
|
function VolumeSliderItem({ userId }: { userId: string }) {
|
||||||
|
const volume = useVoiceStore((s) => s.participantVolumes.get(userId) ?? 100);
|
||||||
|
const setParticipantVolume = useVoiceStore((s) => s.setParticipantVolume);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-3">
|
||||||
|
<div className="text-xs text-txt-tertiary mb-2 font-medium uppercase tracking-wider">
|
||||||
|
User Volume
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" className="text-txt-tertiary flex-shrink-0">
|
||||||
|
<path d="M3 9v6h4l5 5V4L7 9H3z" />
|
||||||
|
</svg>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min="0"
|
||||||
|
max="200"
|
||||||
|
value={volume}
|
||||||
|
onChange={(e) => setParticipantVolume(userId, parseInt(e.target.value))}
|
||||||
|
className="flex-1 accent-accent-primary h-1"
|
||||||
|
/>
|
||||||
|
<span className="text-xs text-txt-secondary min-w-[32px] text-right">
|
||||||
|
{volume}%
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function VoiceChannel({ channelId, channelName, onClick, locked, canManage, onSettingsClick, dragState, onDragStart, onDragEnd }: VoiceChannelProps) {
|
export function VoiceChannel({ channelId, channelName, onClick, locked, canManage, onSettingsClick, dragState, onDragStart, onDragEnd }: VoiceChannelProps) {
|
||||||
const serverVoiceUsers = useVoiceStore((s) => s.voiceUsers.get(channelId)) ?? EMPTY_VOICE_USERS;
|
const serverVoiceUsers = useVoiceStore((s) => s.voiceUsers.get(channelId)) ?? EMPTY_VOICE_USERS;
|
||||||
const currentVoiceChannel = useVoiceStore((s) => s.currentVoiceChannelId);
|
const currentVoiceChannel = useVoiceStore((s) => s.currentVoiceChannelId);
|
||||||
@@ -68,16 +99,45 @@ export function VoiceChannel({ channelId, channelName, onClick, locked, canManag
|
|||||||
const [isDragOver, setIsDragOver] = useState(false);
|
const [isDragOver, setIsDragOver] = useState(false);
|
||||||
const isValidDropTarget = dragState !== null && dragState !== undefined && dragState.fromChannelId !== channelId;
|
const isValidDropTarget = dragState !== null && dragState !== undefined && dragState.fromChannelId !== channelId;
|
||||||
|
|
||||||
// Context menu state
|
const openContextMenu = useContextMenuStore((s) => s.open);
|
||||||
const [contextMenu, setContextMenu] = useState<{ x: number; y: number; userId: string } | null>(null);
|
|
||||||
|
|
||||||
const handleContextMenu = useCallback(
|
const handleContextMenu = useCallback(
|
||||||
(e: React.MouseEvent, userId: string) => {
|
(e: React.MouseEvent, userId: string) => {
|
||||||
if (userId === myUser?.id) return;
|
if (userId === myUser?.id) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setContextMenu({ x: e.clientX, y: e.clientY, userId });
|
|
||||||
|
// Build moderation items
|
||||||
|
const modItems = buildVoiceModMenuItems(userId, channelId);
|
||||||
|
|
||||||
|
const items: ContextMenuItem[] = [...modItems];
|
||||||
|
|
||||||
|
// Separator after mod items
|
||||||
|
if (modItems.length > 0) {
|
||||||
|
items.push({ key: 'mod-end-sep', type: 'separator' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mute User checkbox
|
||||||
|
const isUserMuted = useVoiceStore.getState().participantMutes.get(userId) ?? false;
|
||||||
|
items.push({
|
||||||
|
key: 'mute-user',
|
||||||
|
type: 'checkbox',
|
||||||
|
label: 'Mute User',
|
||||||
|
checked: isUserMuted,
|
||||||
|
onChange: (checked) => useVoiceStore.getState().setParticipantMute(userId, checked),
|
||||||
|
});
|
||||||
|
|
||||||
|
items.push({ key: 'vol-sep', type: 'separator' });
|
||||||
|
|
||||||
|
// Volume slider
|
||||||
|
items.push({
|
||||||
|
key: 'volume',
|
||||||
|
type: 'custom',
|
||||||
|
render: () => React.createElement(VolumeSliderItem, { userId }),
|
||||||
|
});
|
||||||
|
|
||||||
|
openContextMenu({ x: e.clientX, y: e.clientY }, items);
|
||||||
},
|
},
|
||||||
[myUser?.id],
|
[myUser?.id, channelId, openContextMenu],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -266,17 +326,6 @@ export function VoiceChannel({ channelId, channelName, onClick, locked, canManag
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Voice moderation context menu (portalled to body) */}
|
|
||||||
{contextMenu && (
|
|
||||||
<VoiceUserContextMenu
|
|
||||||
targetUserId={contextMenu.userId}
|
|
||||||
channelId={channelId}
|
|
||||||
position={{ x: contextMenu.x, y: contextMenu.y }}
|
|
||||||
onClose={() => setContextMenu(null)}
|
|
||||||
isLocal={false}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import React, { useRef, useEffect, useState, useCallback } from 'react';
|
import React, { useRef, useEffect, useState, useCallback } from 'react';
|
||||||
import { Avatar } from '../ui/Avatar';
|
import { Avatar } from '../ui/Avatar';
|
||||||
import { useVoiceStore } from '../../stores/voiceStore';
|
import { useVoiceStore } from '../../stores/voiceStore';
|
||||||
import { VoiceUserContextMenu } from './VoiceUserContextMenu';
|
import { useContextMenuStore, type ContextMenuItem } from '../../stores/contextMenuStore';
|
||||||
|
import { buildVoiceModMenuItems } from './voiceMenuItems';
|
||||||
import { useSpaceStore } from '../../stores/spaceStore';
|
import { useSpaceStore } from '../../stores/spaceStore';
|
||||||
import { useVoiceParticipantMeta } from '../../hooks/useVoiceParticipantMeta';
|
import { useVoiceParticipantMeta } from '../../hooks/useVoiceParticipantMeta';
|
||||||
|
import { getActiveRoom, setCameraSubscription } from '../../hooks/useLiveKit';
|
||||||
import type { UserTile } from '../../hooks/useLiveKit';
|
import type { UserTile } from '../../hooks/useLiveKit';
|
||||||
|
|
||||||
interface VoiceUserProps {
|
interface VoiceUserProps {
|
||||||
@@ -11,6 +13,36 @@ interface VoiceUserProps {
|
|||||||
large?: boolean;
|
large?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Wrapper component for the volume slider so it can use hooks (useState). */
|
||||||
|
function VolumeSliderItem({ userId }: { userId: string }) {
|
||||||
|
const volume = useVoiceStore((s) => s.participantVolumes.get(userId) ?? 100);
|
||||||
|
const setParticipantVolume = useVoiceStore((s) => s.setParticipantVolume);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-3">
|
||||||
|
<div className="text-xs text-txt-tertiary mb-2 font-medium uppercase tracking-wider">
|
||||||
|
User Volume
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" className="text-txt-tertiary flex-shrink-0">
|
||||||
|
<path d="M3 9v6h4l5 5V4L7 9H3z" />
|
||||||
|
</svg>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min="0"
|
||||||
|
max="200"
|
||||||
|
value={volume}
|
||||||
|
onChange={(e) => setParticipantVolume(userId, parseInt(e.target.value))}
|
||||||
|
className="flex-1 accent-accent-primary h-1"
|
||||||
|
/>
|
||||||
|
<span className="text-xs text-txt-secondary min-w-[32px] text-right">
|
||||||
|
{volume}%
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function VoiceUser({ tile, large }: VoiceUserProps) {
|
export function VoiceUser({ tile, large }: VoiceUserProps) {
|
||||||
const videoRef = useRef<HTMLVideoElement>(null);
|
const videoRef = useRef<HTMLVideoElement>(null);
|
||||||
|
|
||||||
@@ -25,6 +57,8 @@ export function VoiceUser({ tile, large }: VoiceUserProps) {
|
|||||||
const participantMutes = useVoiceStore((s) => s.participantMutes);
|
const participantMutes = useVoiceStore((s) => s.participantMutes);
|
||||||
const spaceId = useSpaceStore((s) => currentVoiceChannelId ? s.channelToSpaceMap.get(currentVoiceChannelId) : null);
|
const spaceId = useSpaceStore((s) => currentVoiceChannelId ? s.channelToSpaceMap.get(currentVoiceChannelId) : null);
|
||||||
|
|
||||||
|
const openContextMenu = useContextMenuStore((s) => s.open);
|
||||||
|
|
||||||
const [, forceUpdate] = useState(0);
|
const [, forceUpdate] = useState(0);
|
||||||
|
|
||||||
const isLocal = participant.isLocal;
|
const isLocal = participant.isLocal;
|
||||||
@@ -59,18 +93,79 @@ export function VoiceUser({ tile, large }: VoiceUserProps) {
|
|||||||
}, [tile.lkVideoTrack]);
|
}, [tile.lkVideoTrack]);
|
||||||
|
|
||||||
// Context Menu
|
// Context Menu
|
||||||
const [volumeMenu, setVolumeMenu] = useState<{
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
} | null>(null);
|
|
||||||
|
|
||||||
const handleContextMenu = useCallback(
|
const handleContextMenu = useCallback(
|
||||||
(e: React.MouseEvent) => {
|
(e: React.MouseEvent) => {
|
||||||
if (isLocal) return;
|
if (isLocal || !currentVoiceChannelId) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setVolumeMenu({ x: e.clientX, y: e.clientY });
|
|
||||||
|
const targetUserId = participant.userId;
|
||||||
|
const channelId = currentVoiceChannelId;
|
||||||
|
|
||||||
|
// Build moderation items
|
||||||
|
const modItems = buildVoiceModMenuItems(targetUserId, channelId);
|
||||||
|
|
||||||
|
const items: ContextMenuItem[] = [...modItems];
|
||||||
|
|
||||||
|
// Separator after mod items
|
||||||
|
if (modItems.length > 0) {
|
||||||
|
items.push({ key: 'mod-end-sep', type: 'separator' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Camera watch/unwatch
|
||||||
|
const targetParticipant = useVoiceStore.getState().participants.find((p) => p.userId === targetUserId);
|
||||||
|
const targetHasCamera = targetParticipant?.isCameraOn ?? false;
|
||||||
|
const isCameraUnwatched = useVoiceStore.getState().unwatchedCameras.has(targetUserId);
|
||||||
|
|
||||||
|
if (targetHasCamera) {
|
||||||
|
items.push({
|
||||||
|
key: 'camera-toggle',
|
||||||
|
type: 'action',
|
||||||
|
label: isCameraUnwatched ? 'Watch Camera' : 'Stop Watching Camera',
|
||||||
|
icon: React.createElement('svg', { width: 14, height: 14, viewBox: '0 0 24 24', fill: 'currentColor', className: 'flex-shrink-0' },
|
||||||
|
...(isCameraUnwatched
|
||||||
|
? [React.createElement('path', { key: 'cam', d: 'M17 10.5V7c0-.55-.45-1-1-1H2c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h14c.55 0 1-.45 1-1v-3.5l4 4v-11l-4 4z' })]
|
||||||
|
: [
|
||||||
|
React.createElement('path', { key: 'cam', d: 'M17 10.5V7c0-.55-.45-1-1-1H2c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h14c.55 0 1-.45 1-1v-3.5l4 4v-11l-4 4z' }),
|
||||||
|
React.createElement('line', { key: 'slash', x1: 1, y1: 1, x2: 23, y2: 23, stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round' }),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
onClick: () => {
|
||||||
|
const room = getActiveRoom();
|
||||||
|
const identity = targetParticipant?.identity;
|
||||||
|
if (isCameraUnwatched) {
|
||||||
|
useVoiceStore.getState().rewatchCamera(targetUserId);
|
||||||
|
if (identity) setCameraSubscription(room, identity, true);
|
||||||
|
} else {
|
||||||
|
useVoiceStore.getState().unwatchCamera(targetUserId);
|
||||||
|
if (identity) setCameraSubscription(room, identity, false);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[isLocal],
|
});
|
||||||
|
items.push({ key: 'camera-sep', type: 'separator' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mute User checkbox
|
||||||
|
const isUserMuted = useVoiceStore.getState().participantMutes.get(targetUserId) ?? false;
|
||||||
|
items.push({
|
||||||
|
key: 'mute-user',
|
||||||
|
type: 'checkbox',
|
||||||
|
label: 'Mute User',
|
||||||
|
checked: isUserMuted,
|
||||||
|
onChange: (checked) => useVoiceStore.getState().setParticipantMute(targetUserId, checked),
|
||||||
|
});
|
||||||
|
|
||||||
|
items.push({ key: 'vol-sep', type: 'separator' });
|
||||||
|
|
||||||
|
// Volume slider (custom, needs store subscription via wrapper component)
|
||||||
|
items.push({
|
||||||
|
key: 'volume',
|
||||||
|
type: 'custom',
|
||||||
|
render: () => React.createElement(VolumeSliderItem, { userId: targetUserId }),
|
||||||
|
});
|
||||||
|
|
||||||
|
openContextMenu({ x: e.clientX, y: e.clientY }, items);
|
||||||
|
},
|
||||||
|
[isLocal, currentVoiceChannelId, participant.userId, openContextMenu],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -185,16 +280,6 @@ export function VoiceUser({ tile, large }: VoiceUserProps) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{volumeMenu && currentVoiceChannelId && (
|
|
||||||
<VoiceUserContextMenu
|
|
||||||
targetUserId={participant.userId}
|
|
||||||
channelId={currentVoiceChannelId}
|
|
||||||
position={volumeMenu}
|
|
||||||
onClose={() => setVolumeMenu(null)}
|
|
||||||
isLocal={isLocal}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import type { ContextMenuItem } from '../../stores/contextMenuStore';
|
||||||
|
import { useVoiceStore } from '../../stores/voiceStore';
|
||||||
|
import { useSpaceStore, getChannelOrigin } from '../../stores/spaceStore';
|
||||||
|
import { wsSend } from '../../hooks/useWebSocket';
|
||||||
|
import { hasPermissionBit, PermissionBits } from '../../utils/permissions';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build moderation context menu items for a voice user.
|
||||||
|
* Called imperatively at right-click time (not during render).
|
||||||
|
*/
|
||||||
|
export function buildVoiceModMenuItems(targetUserId: string, channelId: string): ContextMenuItem[] {
|
||||||
|
const { spacePermissions, currentSpaceId, channels, channelToSpaceMap } = useSpaceStore.getState();
|
||||||
|
const { spaceMutedUserIds, spaceDeafenedUserIds } = useVoiceStore.getState();
|
||||||
|
|
||||||
|
const myPerms = currentSpaceId ? spacePermissions.get(currentSpaceId) : undefined;
|
||||||
|
const canMuteMembers = hasPermissionBit(myPerms, PermissionBits.MUTE_MEMBERS);
|
||||||
|
const canDeafenMembers = hasPermissionBit(myPerms, PermissionBits.DEAFEN_MEMBERS);
|
||||||
|
const canMoveMembers = hasPermissionBit(myPerms, PermissionBits.MOVE_MEMBERS);
|
||||||
|
const canDisconnectMembers = hasPermissionBit(myPerms, PermissionBits.DISCONNECT_MEMBERS);
|
||||||
|
|
||||||
|
if (!canMuteMembers && !canDeafenMembers && !canMoveMembers && !canDisconnectMembers) return [];
|
||||||
|
|
||||||
|
const voiceOrigin = getChannelOrigin(channelId);
|
||||||
|
const spaceId = channelToSpaceMap.get(channelId);
|
||||||
|
const isSpaceMuted = spaceMutedUserIds.has(`${spaceId}:${targetUserId}`);
|
||||||
|
const isSpaceDeafened = spaceDeafenedUserIds.has(`${spaceId}:${targetUserId}`);
|
||||||
|
const otherVoiceChannels = channels.filter(c => c.type === 'voice' && c.id !== channelId);
|
||||||
|
|
||||||
|
const items: ContextMenuItem[] = [];
|
||||||
|
|
||||||
|
if (canMuteMembers) {
|
||||||
|
items.push({
|
||||||
|
key: 'space-mute',
|
||||||
|
type: 'action',
|
||||||
|
label: isSpaceMuted ? 'Space Unmute' : 'Space Mute',
|
||||||
|
icon: React.createElement('svg', { width: 14, height: 14, viewBox: '0 0 24 24', fill: 'currentColor', className: 'flex-shrink-0' },
|
||||||
|
React.createElement('path', { d: 'M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z' }),
|
||||||
|
React.createElement('path', { d: 'M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z' }),
|
||||||
|
...(isSpaceMuted
|
||||||
|
? [React.createElement('line', { key: 'slash', x1: 3, y1: 3, x2: 21, y2: 21, stroke: 'currentColor', strokeWidth: 2.5, strokeLinecap: 'round' })]
|
||||||
|
: []),
|
||||||
|
),
|
||||||
|
onClick: () => wsSend({ type: 'voice_space_mute', userId: targetUserId, muted: !isSpaceMuted }, voiceOrigin),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canDeafenMembers) {
|
||||||
|
items.push({
|
||||||
|
key: 'space-deafen',
|
||||||
|
type: 'action',
|
||||||
|
label: isSpaceDeafened ? 'Space Undeafen' : 'Space Deafen',
|
||||||
|
icon: React.createElement('svg', { width: 14, height: 14, viewBox: '0 0 24 24', fill: 'currentColor', className: 'flex-shrink-0' },
|
||||||
|
React.createElement('path', { d: 'M12 3c-4.97 0-9 4.03-9 9v7c0 1.1.9 2 2 2h2v-7H5v-2c0-3.87 3.13-7 7-7s7 3.13 7 7v2h-2v7h2c1.1 0 2-.9 2-2v-7c0-4.97-4.03-9-9-9z' }),
|
||||||
|
...(isSpaceDeafened
|
||||||
|
? [React.createElement('line', { key: 'slash', x1: 3, y1: 3, x2: 21, y2: 21, stroke: 'currentColor', strokeWidth: 2.5, strokeLinecap: 'round' })]
|
||||||
|
: []),
|
||||||
|
),
|
||||||
|
onClick: () => wsSend({ type: 'voice_space_deafen', userId: targetUserId, deafened: !isSpaceDeafened }, voiceOrigin),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canDisconnectMembers) {
|
||||||
|
items.push({ key: 'mod-sep', type: 'separator' });
|
||||||
|
items.push({
|
||||||
|
key: 'disconnect',
|
||||||
|
type: 'action',
|
||||||
|
label: 'Disconnect',
|
||||||
|
danger: true,
|
||||||
|
icon: React.createElement('svg', { width: 14, height: 14, viewBox: '0 0 24 24', fill: 'currentColor', className: 'flex-shrink-0' },
|
||||||
|
React.createElement('path', { d: 'M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 010-1.36C3.36 8.68 7.42 7 12 7s8.64 1.68 11.71 4.72c.18.18.29.44.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 00-2.67-1.85.996.996 0 01-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z' }),
|
||||||
|
),
|
||||||
|
onClick: () => wsSend({ type: 'voice_disconnect', userId: targetUserId }, voiceOrigin),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canMoveMembers && otherVoiceChannels.length > 0) {
|
||||||
|
items.push({ key: 'move-sep', type: 'separator' });
|
||||||
|
items.push({
|
||||||
|
key: 'move-to',
|
||||||
|
type: 'submenu',
|
||||||
|
label: 'Move to',
|
||||||
|
icon: React.createElement('svg', { width: 14, height: 14, viewBox: '0 0 24 24', fill: 'currentColor', className: 'flex-shrink-0' },
|
||||||
|
React.createElement('path', { d: 'M14 4l2.29 2.29-2.88 2.88 1.42 1.42 2.88-2.88L20 10V4h-6zM10 4H4v6l2.29-2.29 4.71 4.7V20h2v-8.41l-5.29-5.3L10 4z' }),
|
||||||
|
),
|
||||||
|
children: otherVoiceChannels.map(ch => ({
|
||||||
|
key: ch.id,
|
||||||
|
type: 'action' as const,
|
||||||
|
label: ch.name,
|
||||||
|
icon: React.createElement('svg', { width: 14, height: 14, viewBox: '0 0 24 24', fill: 'currentColor', className: 'flex-shrink-0 text-txt-tertiary' },
|
||||||
|
React.createElement('path', { d: 'M11 5L6 9H2V15H6L11 19V5ZM15.54 8.46C16.48 9.4 17 10.67 17 12S16.48 14.6 15.54 15.54L14.12 14.12C14.69 13.55 15 12.79 15 12S14.69 10.45 14.12 9.88L15.54 8.46Z' }),
|
||||||
|
),
|
||||||
|
onClick: () => wsSend({ type: 'voice_move', userId: targetUserId, targetChannelId: ch.id }, voiceOrigin),
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user