refactor: extract sharing views and repair player ownership

This commit is contained in:
illusia committed 2026-10-01 19:11:29 +08:00
1 parent 8b6c998c43
commit 6ed8abfb15
11 files changed
+355 -222

No files matched your search

+12 -88
View File
@@ -91,28 +91,7 @@
<header class="workspace-header" data-ws-part="voice.header">
<div class="breadcrumbs" data-ws-part="voice.breadcrumbs"><span class="mobile-brand">TeamSpeak <em>Web</em></span><span class="crumb-muted">{{ t('serverBreadcrumb') }}</span><Icon name="chevron-right" :size="14" /><strong>{{ currentChannelName }}</strong></div>
<div class="workspace-actions" data-ws-part="voice.header-actions">
<div class="network-performance" data-ws-part="voice.performance">
<button type="button" class="performance-trigger" :title="t('voiceStatus')" :aria-label="t('voiceStatus')" :aria-expanded="performancePanelOpen" @click.stop="togglePerformancePanel"><Icon name="activity" :size="16" /><span class="performance-trigger-label">{{ t('voiceStatus') }}</span><small v-if="performanceStats.ready">{{ voiceTransportLabel }}</small><Icon name="chevron-down" :size="13" /></button>
<section v-if="performancePanelOpen" class="performance-panel" data-ws-part="voice.performance.panel" role="dialog" :aria-label="t('voiceStatus')" @click.stop>
<header><div><strong>{{ t('voiceStatus') }}</strong><small>{{ t('voiceStatusHint') }}</small></div><button type="button" class="performance-refresh" :title="t('measureNow')" :disabled="performanceRunning" @click="refreshPerformanceProbe"><Icon name="refresh" :size="15" /></button></header>
<div class="voice-status-summary" :data-health="performanceStats.health" data-ws-part="voice.performance.route"><i></i><div><strong>{{ voiceHealthLabel }}</strong><small>{{ voiceTransportLabel }}<template v-if="performanceStats.connectionState"> · {{ performanceStats.connectionState }}</template></small></div></div>
<div class="performance-metrics voice-audio-metrics" data-ws-part="voice.performance.metrics">
<article><small>{{ t('voiceUplink') }}</small><strong>{{ performanceStats.uplinkFramesPerSecond == null ? '—' : `${performanceStats.uplinkFramesPerSecond} ${t('audioFramesPerSecondUnit')}` }}</strong><span>{{ t('audioBitrate') }} {{ performanceStats.uplinkBitrateKbps == null ? '—' : `${performanceStats.uplinkBitrateKbps} kbps` }}</span><span v-if="performanceStats.transport === 'webrtc'">{{ t('voicePacketLoss') }} {{ performanceStats.uplinkLossPercent == null ? '—' : `${performanceStats.uplinkLossPercent.toFixed(2)}%` }} · {{ t('voiceRtt') }} {{ performanceStats.uplinkRttMs == null ? '—' : `${Math.round(performanceStats.uplinkRttMs)} ms` }}</span><span v-else>{{ t('voiceFallbackMetricHint') }}</span></article>
<article><small>{{ t('voiceDownlink') }}</small><strong>{{ performanceStats.downlinkFramesPerSecond == null ? '—' : `${performanceStats.downlinkFramesPerSecond} ${t('audioFramesPerSecondUnit')}` }}</strong><span>{{ t('audioBitrate') }} {{ performanceStats.downlinkBitrateKbps == null ? '—' : `${performanceStats.downlinkBitrateKbps} kbps` }}</span><span v-if="performanceStats.transport === 'webrtc'">{{ t('voicePacketLoss') }} {{ performanceStats.downlinkLossPercent == null ? '—' : `${performanceStats.downlinkLossPercent.toFixed(2)}%` }} · {{ t('voiceJitter') }} {{ performanceStats.downlinkJitterMs == null ? '—' : `${Math.round(performanceStats.downlinkJitterMs)} ms` }}</span><span v-else>{{ t('voiceFallbackMetricHint') }}</span></article>
</div>
<div class="voice-audio-details"><span>{{ t('microphone') }} · {{ voiceMicrophoneLabel }}</span><span>{{ t('voicePlayback') }} · {{ voicePlaybackLabel }}</span><span>{{ t('voiceSendErrors') }} {{ performanceStats.sendErrors == null ? '—' : performanceStats.sendErrors }} · {{ t('voiceDroppedFrames') }} {{ performanceStats.droppedFrames == null ? '—' : performanceStats.droppedFrames }}</span><span v-if="performanceStats.transport === 'webrtc'">{{ t('voiceQueueUnderruns') }} {{ performanceStats.queueUnderruns == null ? '—' : performanceStats.queueUnderruns }}</span></div>
<p class="performance-status" data-ws-part="voice.performance.status">{{ performanceRunning ? t('voiceStatusSampling') : performanceStats.ready ? t('voiceStatusLiveHint') : t('voiceStatusWaiting') }}</p>
<section v-if="screenShareWebRtcStats.peers.length" class="webrtc-stats" data-ws-part="voice.performance.webrtc-stats" aria-live="polite">
<header><div><strong>{{ t('webrtcStats') }}</strong><small>{{ t('webrtcStatsHint') }}</small></div></header>
<div v-if="screenShareWebRtcStats.capture" class="webrtc-stats-capture"><span>{{ t('screenShareCapture') }}</span><strong>{{ screenShareWebRtcStats.capture.width ?? '—' }} × {{ screenShareWebRtcStats.capture.height ?? '—' }}</strong><small>{{ screenShareWebRtcStats.capture.frameRate == null ? '—' : `${screenShareWebRtcStats.capture.frameRate.toFixed(1)} FPS` }}</small></div>
<div v-for="peer in screenShareWebRtcStats.peers" :key="peer.peerId" class="webrtc-stats-peer">
<div class="webrtc-stats-peer-heading"><strong>{{ peer.direction === 'outbound' ? t('screenShareSending') : t('screenShareReceiving') }}</strong><small>{{ peer.connectionState }} · {{ peer.candidateType ?? '—' }}</small></div>
<div class="webrtc-stats-values"><span>{{ peer.frameRate == null ? '—' : `${peer.frameRate.toFixed(1)} FPS` }}</span><span>{{ peer.bitrateKbps == null ? '—' : `${Math.round(peer.bitrateKbps)} kbps` }}</span><span>{{ peer.lossPercent == null ? '—' : `${peer.lossPercent.toFixed(2)}%` }} {{ t('packetLoss') }}</span><span>{{ peer.framesDropped == null ? '—' : peer.framesDropped }} {{ t('screenShareDroppedFrames') }}</span><span>{{ peer.jitterMs == null ? '—' : `${Math.round(peer.jitterMs)} ms` }} {{ t('screenShareJitter') }}</span><span>{{ peer.roundTripTimeMs == null ? '—' : `${Math.round(peer.roundTripTimeMs)} ms` }} {{ t('screenShareRtt') }}</span></div>
<small v-if="peer.codec || peer.qualityLimitationReason" class="webrtc-stats-detail">{{ peer.codec ?? '—' }}<template v-if="peer.qualityLimitationReason"> · {{ peer.qualityLimitationReason }}</template></small>
</div>
</section>
</section>
</div>
<VoicePerformancePanel :model="performance" :screen-share-web-rtc-stats="screenShareWebRtcStats" :t="t" />
<button class="header-action" :title="t('copyInvite')" @click="doShare"><Icon name="share" :size="18" /></button>
<button v-if="isMobileViewport" class="header-action microphone-header-toggle" :class="{ muted: microphoneMuted }" :title="microphoneMuted ? t('unmuteMic') : t('muteMic')" :aria-label="microphoneMuted ? t('microphoneMuted') : t('microphoneActive')" :aria-pressed="!microphoneMuted" @click="toggleMicrophone"><Icon :name="microphoneMuted ? 'mic-off' : 'mic'" :size="18" /></button>
<button v-if="isMobileViewport" class="header-action" :title="t('audioSettings')" :aria-label="t('audioSettings')" @click="settingsOpen = true"><Icon name="settings" :size="18" /></button>
@@ -122,18 +101,7 @@
</div>
</header>
<div v-if="screenShareSettingsOpen" class="modal-backdrop screen-share-settings-backdrop" @click.self="screenShareSettingsOpen = false">
<section class="screen-share-settings-modal" data-ws-part="voice.screen-share-settings" role="dialog" aria-modal="true" aria-labelledby="screen-share-settings-title" @click.stop>
<button type="button" class="screen-share-settings-close" :aria-label="t('close')" :title="t('close')" @click="screenShareSettingsOpen = false"><Icon name="close" :size="17" /></button>
<div class="screen-share-settings-heading" data-ws-part="voice.screen-share-settings.heading"><span class="card-kicker">{{ t('screenShare') }}</span><h2 id="screen-share-settings-title">{{ t('screenShareSettings') }}</h2><p>{{ t('screenShareSettingsHint') }}</p></div>
<div class="screen-share-settings-fields" data-ws-part="voice.screen-share-settings.fields">
<label><span>{{ t('screenShareResolution') }}</span><select v-model="screenShareResolutionPreset" :aria-label="t('screenShareResolution')"><option v-for="option in screenShareResolutionOptions" :key="option.value" :value="option.value">{{ t(option.label) }}</option></select></label>
<label><span>{{ t('screenShareFrameRate') }}</span><select v-model.number="screenShareFrameRate" :aria-label="t('screenShareFrameRate')"><option v-for="fps in screenShareFrameRateOptions" :key="fps" :value="fps">{{ fps }} FPS</option></select></label>
</div>
<p class="screen-share-settings-note" data-ws-part="voice.screen-share-settings.note">{{ t('screenShareSettingsNote') }}</p>
<footer class="screen-share-settings-footer" data-ws-part="voice.screen-share-settings.actions"><button type="button" class="text-button" @click="screenShareSettingsOpen = false">{{ t('cancel') }}</button><button type="button" class="primary-button screen-share-settings-start" @click="startScreenShareWithSettings"><Icon name="monitor" :size="14" /> {{ t('startScreenShare') }}</button></footer>
</section>
</div>
<ScreenShareSettingsDialog v-if="screenShareSettingsOpen" :model="screenShareControls" :t="t" @close="screenShareSettingsOpen = false" />
<div v-if="voiceState.reconnecting || voiceState.reconnectFailed" :class="['reconnect-banner', { failed: voiceState.reconnectFailed }]" data-ws-part="voice.connection-status" role="status">
<div class="reconnect-copy"><strong>{{ voiceState.reconnectFailed ? t('reconnectFailed') : t('connectionInterrupted') }}</strong><span v-if="voiceState.reconnecting">{{ t('reconnectingAttempt', { attempt: voiceState.reconnectAttempt }) }}</span><span v-else>{{ localizedMessage(voiceState.error) }}</span></div>
@@ -148,23 +116,9 @@
<div class="voice-activity-artwork" data-ws-part="voice.activity.artwork" aria-hidden="true"></div>
<div class="section-heading" data-ws-part="voice.activity-heading"><div><span class="section-kicker">{{ t('voiceActivity') }}</span><h2>{{ t('speakingNow') }}</h2></div><span class="section-counter">{{ t('onlineShort', { count: currentMembers.length }) }}</span></div>
<div v-if="screenShareError" class="screen-share-inline-error" data-ws-part="voice.screen-share-error" role="status"><Icon name="info" :size="15" /> <span>{{ screenShareErrorText }}</span></div>
<section v-if="screenShareViewing" ref="screenSharePlayerEl" class="screen-share-player" data-ws-part="voice.screen-player" role="region" :aria-label="t('screenShare')">
<div class="screen-share-player-stage" data-ws-part="voice.screen-player.stage">
<video v-if="screenShareRemoteStream" :ref="setScreenVideoElement" class="screen-share-player-video" data-ws-part="voice.screen-player.video" autoplay playsinline :muted="screenShareRemoteVolume === 0"></video>
<div v-else class="screen-share-player-placeholder" data-ws-part="voice.screen-player.placeholder"><span class="screen-share-player-placeholder-icon"><Icon name="monitor" :size="28" /></span><strong>{{ t('screenShareConnecting') }}</strong><span>{{ screenShareError ? screenShareErrorText : t('directP2POnly') }}</span></div>
<button type="button" class="screen-share-player-exit" data-ws-part="voice.screen-player.exit" :aria-label="t('screenShareExit')" :title="t('screenShareExit')" @click="leaveScreenShare"><Icon name="close" :size="22" /></button>
<div class="screen-share-player-viewers" data-ws-part="voice.screen-player.viewers" :aria-label="t('screenShareViewers')">
<span class="screen-share-player-viewer-label"><Icon name="users" :size="14" /> {{ screenSharePlayerViewerCount }}</span>
<span class="screen-share-player-viewer-avatars"><span v-for="viewer in screenSharePlayerViewers" :key="viewer.peerId" class="screen-share-player-viewer-avatar" data-ws-part="voice.screen-player.viewer-avatar" :style="screenShareViewerStyle(viewer)" :title="viewer.nickname">{{ viewer.avatar ? '' : avatarInitial(viewer.nickname) }}</span></span>
</div>
<span class="screen-share-player-live" data-ws-part="voice.screen-player.live"><i></i>{{ t('watchingScreenShare') }}</span>
<span class="screen-share-player-source" data-ws-part="voice.screen-player.source">{{ screenSharePlayerOwnerName }}</span>
<div class="screen-share-player-controls" data-ws-part="voice.screen-player.controls">
<label data-ws-part="voice.screen-player.volume" :title="t('screenShareVolume')"><Icon :name="screenShareRemoteVolume === 0 ? 'volume-off' : 'volume'" :size="18" /><input type="range" min="0" max="100" :value="screenShareRemoteVolume * 100" :aria-label="t('screenShareVolume')" @input="onScreenShareVolume" /></label>
<button type="button" data-ws-part="voice.screen-player.fullscreen" :aria-label="screenShareFullscreen ? t('screenShareExitFullscreen') : t('screenShareFullscreen')" :title="screenShareFullscreen ? t('screenShareExitFullscreen') : t('screenShareFullscreen')" @click="toggleScreenShareFullscreen"><Icon :name="screenShareFullscreen ? 'fullscreen-exit' : 'fullscreen'" :size="19" /></button>
</div>
</div>
</section>
<ScreenSharePlayer v-if="screenShareViewing" :model="screenShareControls"
:screen-share-remote-stream="screenShareRemoteStream" :screen-share-remote-volume="screenShareRemoteVolume"
:screen-share-error="screenShareError" :leave-screen-share="leaveScreenShare" :avatar-initial="avatarInitial" :t="t" />
<div v-if="currentMembers.length" class="voice-grid" data-ws-part="voice.members">
<article v-for="member in currentMembers" :key="member.id" :class="['voice-card', { speaking: isSpeaking(member), self: member.isSelf }]" data-ws-part="voice.member" :data-ws-state="member.isSelf ? 'self' : isSpeaking(member) ? 'speaking' : 'connected'" :data-ws-member-id="member.id" :data-ws-speaking="isSpeaking(member) ? 'true' : 'false'" :data-ws-self="member.isSelf ? 'true' : 'false'">
<button v-if="isMobileViewport && !member.isSelf" type="button" class="voice-member-action" :aria-label="t('moreMemberOptions')" @click.stop="openMemberActions(member)"><Icon name="more" :size="17" /></button>
@@ -256,6 +210,9 @@
<script setup lang="ts">
import { computed, onMounted, onUnmounted, reactive, ref, shallowRef, watch } from "vue";
import Icon from "../components/Icon.vue";
import VoicePerformancePanel from "../components/web-client/VoicePerformancePanel.vue";
import ScreenShareSettingsDialog from "../components/web-client/ScreenShareSettingsDialog.vue";
import ScreenSharePlayer from "../components/web-client/ScreenSharePlayer.vue";
import AudioDock from "../components/web-client/AudioDock.vue";
import WhisperControls from "../components/web-client/WhisperControls.vue";
import AudioSettingsDialog from "../components/web-client/AudioSettingsDialog.vue";
@@ -370,23 +327,8 @@ const {
clearError,
measureVoiceAudioStatus,
} = useVoiceWebSocket();
const {
panelOpen: performancePanelOpen,
running: performanceRunning,
stats: performanceStats,
togglePanel: togglePerformancePanel,
refresh: refreshPerformanceProbe,
} = useWebClientPerformance(computed(() => voiceState.connected), measureVoiceAudioStatus);
const voiceHealthLabel = computed(() => t(({ disconnected: "voiceHealthDisconnected", sampling: "voiceHealthSampling", connecting: "voiceHealthConnecting", warning: "voiceHealthWarning", active: "voiceHealthActive", quiet: "voiceHealthQuiet" } as const)[performanceStats.value.health]));
const voiceTransportLabel = computed(() => t(({ webrtc: "voiceTransportWebRTC", websocket: "voiceTransportWebSocket", negotiating: "voiceTransportNegotiating", disconnected: "voiceTransportDisconnected" } as const)[performanceStats.value.transport]));
const voicePlaybackLabel = computed(() => t(({ playing: "voicePlaybackReady", paused: "voicePlaybackPaused", unavailable: "voicePlaybackUnavailable" } as const)[performanceStats.value.playbackState ?? "unavailable"]));
const voiceMicrophoneLabel = computed(() => performanceStats.value.microphoneMuted
? t("voiceMicMuted")
: performanceStats.value.microphoneReady
? t("voiceMicOpen")
: performanceStats.value.microphonePermission === "denied" || performanceStats.value.microphonePermission === "granted"
? t("voiceMicUnavailable")
: t("voiceMicWaiting"));
const performance = useWebClientPerformance(computed(() => voiceState.connected), measureVoiceAudioStatus);
const { panelOpen: performancePanelOpen } = performance;
const query = new URLSearchParams(location.search);
const initialChannel = query.get("channel") ?? "";
@@ -563,26 +505,7 @@ function persistLanguage() {
}
const screenShareIndicatorBars = [5, 10, 7, 12, 8, 10];
const {
playerElement: screenSharePlayerEl,
fullscreen: screenShareFullscreen,
resolutionOptions: screenShareResolutionOptions,
frameRateOptions: screenShareFrameRateOptions,
resolutionPreset: screenShareResolutionPreset,
frameRate: screenShareFrameRate,
settingsOpen: screenShareSettingsOpen,
viewers: screenSharePlayerViewers,
viewerCount: screenSharePlayerViewerCount,
ownerName: screenSharePlayerOwnerName,
errorText: screenShareErrorText,
setVideoElement: setScreenVideoElement,
streamForMember: screenShareStreamForMember,
toggleForMember: toggleScreenShareForMember,
viewerStyle: screenShareViewerStyle,
setVolume: onScreenShareVolume,
toggleFullscreen: toggleScreenShareFullscreen,
startWithSettings: startScreenShareWithSettings,
} = useWebClientScreenShare({
const screenShareControls = useWebClientScreenShare({
streams: screenShareStreams,
viewing: screenShareViewing,
viewingStreamId: screenShareViewingStreamId,
@@ -597,6 +520,7 @@ const {
avatarStyle,
t,
});
const { settingsOpen: screenShareSettingsOpen, errorText: screenShareErrorText, streamForMember: screenShareStreamForMember, toggleForMember: toggleScreenShareForMember, startWithSettings: startScreenShareWithSettings } = screenShareControls;
const {
channelTree,
currentChannel,