mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
refactor(web): 前端代码规范化重构
- 集中化 HID 类型定义到 types/hid.ts,消除重复代码 - 统一 WebSocket 连接管理,提取共享工具到 types/websocket.ts - 拆分 ConsoleView.vue 关注点,创建 useVideoStream、useHidInput、useConsoleEvents composables - 添加 useConfigPopover 抽象配置弹窗公共逻辑 - 优化视频容器布局,支持动态比例自适应
This commit is contained in:
@@ -351,6 +351,15 @@ impl PeerConnection {
|
||||
|
||||
/// Close the connection
|
||||
pub async fn close(&self) -> Result<()> {
|
||||
// Reset HID state to release any held keys/buttons
|
||||
if let Some(ref hid) = self.hid_controller {
|
||||
if let Err(e) = hid.reset().await {
|
||||
tracing::warn!("Failed to reset HID on peer {} close: {}", self.session_id, e);
|
||||
} else {
|
||||
tracing::debug!("HID reset on peer {} close", self.session_id);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ref track) = self.video_track {
|
||||
track.stop();
|
||||
}
|
||||
|
||||
@@ -568,6 +568,32 @@ impl WebRtcStreamer {
|
||||
);
|
||||
}
|
||||
|
||||
/// Check if current encoder configuration uses hardware encoding
|
||||
///
|
||||
/// Returns true if:
|
||||
/// - A specific hardware backend is configured, OR
|
||||
/// - Auto mode is used and hardware encoders are available
|
||||
pub async fn is_hardware_encoding(&self) -> bool {
|
||||
let config = self.config.read().await;
|
||||
match config.encoder_backend {
|
||||
Some(backend) => backend.is_hardware(),
|
||||
None => {
|
||||
// Auto mode: check if hardware encoder is available for current codec
|
||||
use crate::video::encoder::registry::{EncoderRegistry, VideoEncoderType};
|
||||
let codec_type = match *self.video_codec.read().await {
|
||||
VideoCodecType::H264 => VideoEncoderType::H264,
|
||||
VideoCodecType::H265 => VideoEncoderType::H265,
|
||||
VideoCodecType::VP8 => VideoEncoderType::VP8,
|
||||
VideoCodecType::VP9 => VideoEncoderType::VP9,
|
||||
};
|
||||
EncoderRegistry::global()
|
||||
.best_encoder(codec_type, false)
|
||||
.map(|e| e.is_hardware)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Update ICE configuration (STUN/TURN servers)
|
||||
///
|
||||
/// Note: Changes take effect for new sessions only.
|
||||
|
||||
Reference in New Issue
Block a user