diff --git a/chuan-next/src/app/layout.tsx b/chuan-next/src/app/layout.tsx index 6aacd9d..6df4d0d 100644 --- a/chuan-next/src/app/layout.tsx +++ b/chuan-next/src/app/layout.tsx @@ -25,6 +25,9 @@ export default function RootLayout({ }>) { return ( + + + diff --git a/chuan-next/src/components/WebRTCSettings.tsx b/chuan-next/src/components/WebRTCSettings.tsx index 82e07e9..cd6c543 100644 --- a/chuan-next/src/components/WebRTCSettings.tsx +++ b/chuan-next/src/components/WebRTCSettings.tsx @@ -251,8 +251,6 @@ interface ServerItemProps { } function ServerItem({ server, onRemove, canRemove }: ServerItemProps) { - const isDefault = server.id.startsWith('google-') || server.id.startsWith('twilio-'); - return (
@@ -261,8 +259,8 @@ function ServerItem({ server, onRemove, canRemove }: ServerItemProps) { {server.type?.toUpperCase() || 'STUN'} - {isDefault && ( - + {server.isDefault && ( + 默认 )} @@ -341,7 +339,8 @@ export default function WebRTCSettings() { removeIceServer(serverToDelete); showToast('ICE服务器删除成功', 'success'); } catch (error) { - showToast('至少需要保留一个ICE服务器', 'error'); + const errorMessage = error instanceof Error ? error.message : '删除失败'; + showToast(errorMessage, 'error'); } finally { setServerToDelete(null); setShowDeleteDialog(false); @@ -518,6 +517,13 @@ export default function WebRTCSettings() { 格式:turn:服务器地址:端口

+ +
+

默认服务器:

+

+ 系统预置的可靠ICE服务器,建议保留以确保连接稳定性。可以根据需要删除或添加自定义服务器。 +

+
@@ -537,7 +543,19 @@ export default function WebRTCSettings() { onClose={cancelDeleteServer} onConfirm={confirmDeleteServer} title="删除ICE服务器" - message={`确定要删除这个ICE服务器吗?删除后将无法恢复。${iceServers.length <= 1 ? '\n\n注意:这是最后一个服务器,删除后将无法建立WebRTC连接。' : ''}`} + message={(() => { + if (!serverToDelete) return "确定要删除这个ICE服务器吗?"; + + const serverToDeleteInfo = iceServers.find(s => s.id === serverToDelete); + + if (iceServers.length <= 1) { + return "这是最后一个ICE服务器,删除后将无法建立WebRTC连接。确定要删除吗?"; + } else if (serverToDeleteInfo?.isDefault) { + return "这是一个默认ICE服务器,删除后可能需要手动添加其他服务器。确定要删除吗?"; + } else { + return "确定要删除这个ICE服务器吗?删除后将无法恢复。"; + } + })()} confirmText="删除" cancelText="取消" type="danger" diff --git a/chuan-next/src/hooks/settings/useIceServersConfig.ts b/chuan-next/src/hooks/settings/useIceServersConfig.ts index ad14037..671c45a 100644 --- a/chuan-next/src/hooks/settings/useIceServersConfig.ts +++ b/chuan-next/src/hooks/settings/useIceServersConfig.ts @@ -7,36 +7,48 @@ export interface IceServerConfig { credential?: string; type: 'stun' | 'turn'; enabled: boolean; + isDefault?: boolean; // 标记是否为默认服务器 } const DEFAULT_ICE_SERVERS: IceServerConfig[] = [ + { + id: 'easyvoip-stun', + urls: 'stun:stun.easyvoip.com:3478', + type: 'stun', + enabled: true, + isDefault: true, + }, + { + id: 'miwifi-stun', + urls: 'stun:stun.miwifi.com:3478', + type: 'stun', + enabled: true, + isDefault: true, + }, { id: 'google-stun-1', urls: 'stun:stun.l.google.com:19302', type: 'stun', enabled: true, + isDefault: true, }, { id: 'google-stun-2', urls: 'stun:stun1.l.google.com:19302', type: 'stun', enabled: true, - }, - { - id: 'google-stun-3', - urls: 'stun:stun2.l.google.com:19302', - type: 'stun', - enabled: true, + isDefault: true, }, { id: 'twilio-stun', urls: 'stun:global.stun.twilio.com:3478', type: 'stun', enabled: true, - }, + isDefault: true, + } ]; -const STORAGE_KEY = 'webrtc-ice-servers-config'; +const STORAGE_KEY = 'webrtc-ice-servers-config-090901'; export function useIceServersConfig() { const [iceServers, setIceServers] = useState([]); @@ -48,7 +60,13 @@ export function useIceServersConfig() { const savedConfig = localStorage.getItem(STORAGE_KEY); if (savedConfig) { const parsed = JSON.parse(savedConfig); - setIceServers(parsed); + // 确保所有服务器都有isDefault属性 + const serversWithDefaults = parsed.map((server: any) => ({ + ...server, + isDefault: server.isDefault !== undefined ? server.isDefault : + DEFAULT_ICE_SERVERS.some(defaultServer => defaultServer.id === server.id) + })); + setIceServers(serversWithDefaults); } else { setIceServers(DEFAULT_ICE_SERVERS); } @@ -76,6 +94,7 @@ export function useIceServersConfig() { const newServer: IceServerConfig = { ...config, id: `custom-${Date.now()}`, + isDefault: false, // 用户添加的服务器不标记为默认 }; const updatedServers = [...iceServers, newServer]; saveConfig(updatedServers); @@ -95,6 +114,7 @@ export function useIceServersConfig() { if (iceServers.length <= 1) { throw new Error('至少需要保留一个ICE服务器'); } + const updatedServers = iceServers.filter(server => server.id !== id); saveConfig(updatedServers); }, [iceServers, saveConfig]);