|
3 | 3 | import React, { useEffect, useState } from 'react'; |
4 | 4 | import { useSearchParams } from 'next/navigation'; |
5 | 5 | import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; |
6 | | -import { Upload, MessageSquare, Monitor, TestTube } from 'lucide-react'; |
| 6 | +import { Upload, MessageSquare, Monitor, Users } from 'lucide-react'; |
7 | 7 | import Hero from '@/components/Hero'; |
8 | 8 | import { WebRTCFileTransfer } from '@/components/WebRTCFileTransfer'; |
9 | 9 | import { WebRTCTextImageTransfer } from '@/components/WebRTCTextImageTransfer'; |
10 | 10 | import DesktopShare from '@/components/DesktopShare'; |
| 11 | +import WeChatGroup from '@/components/WeChatGroup'; |
| 12 | +import { WebRTCUnsupportedModal } from '@/components/WebRTCUnsupportedModal'; |
| 13 | +import { useWebRTCSupport } from '@/hooks/useWebRTCSupport'; |
11 | 14 |
|
12 | 15 | export default function HomePage() { |
13 | 16 | const searchParams = useSearchParams(); |
14 | 17 | const [activeTab, setActiveTab] = useState('webrtc'); |
15 | 18 | const [hasInitialized, setHasInitialized] = useState(false); |
16 | 19 |
|
| 20 | + // WebRTC 支持检测 |
| 21 | + const { |
| 22 | + webrtcSupport, |
| 23 | + isSupported, |
| 24 | + isChecked, |
| 25 | + showUnsupportedModal, |
| 26 | + closeUnsupportedModal, |
| 27 | + showUnsupportedModalManually, |
| 28 | + } = useWebRTCSupport(); |
| 29 | + |
17 | 30 | // 根据URL参数设置初始标签(仅首次加载时) |
18 | 31 | useEffect(() => { |
19 | 32 | if (!hasInitialized) { |
@@ -50,56 +63,123 @@ export default function HomePage() { |
50 | 63 | <Hero /> |
51 | 64 | </div> |
52 | 65 |
|
53 | | - {/* Main Content */} |
54 | | - <div className="max-w-4xl mx-auto"> |
55 | | - <Tabs value={activeTab} onValueChange={setActiveTab} className="w-full"> |
56 | | - {/* Tabs Navigation - 横向布局 */} |
57 | | - <div className="mb-6"> |
58 | | - <TabsList className="grid w-full grid-cols-3 max-w-xl mx-auto h-auto bg-white/90 backdrop-blur-sm shadow-lg rounded-xl p-2 border border-slate-200"> |
59 | | - <TabsTrigger |
60 | | - value="webrtc" |
61 | | - className="flex items-center justify-center space-x-2 px-3 py-3 text-sm font-medium rounded-lg transition-all duration-200 hover:bg-slate-50 data-[state=active]:bg-blue-500 data-[state=active]:text-white data-[state=active]:shadow-md data-[state=active]:hover:bg-blue-600" |
62 | | - > |
63 | | - <Upload className="w-4 h-4" /> |
64 | | - <span className="hidden sm:inline">文件传输</span> |
65 | | - <span className="sm:hidden">文件</span> |
66 | | - </TabsTrigger> |
67 | | - <TabsTrigger |
68 | | - value="message" |
69 | | - className="flex items-center justify-center space-x-2 px-3 py-3 text-sm font-medium rounded-lg transition-all duration-200 hover:bg-slate-50 data-[state=active]:bg-emerald-500 data-[state=active]:text-white data-[state=active]:shadow-md data-[state=active]:hover:bg-emerald-600" |
70 | | - > |
71 | | - <MessageSquare className="w-4 h-4" /> |
72 | | - <span className="hidden sm:inline">文本消息</span> |
73 | | - <span className="sm:hidden">消息</span> |
74 | | - </TabsTrigger> |
75 | | - <TabsTrigger |
76 | | - value="desktop" |
77 | | - className="flex items-center justify-center space-x-2 px-3 py-3 text-sm font-medium rounded-lg transition-all duration-200 hover:bg-slate-50 data-[state=active]:bg-purple-500 data-[state=active]:text-white data-[state=active]:shadow-md data-[state=active]:hover:bg-purple-600" |
78 | | - > |
79 | | - <Monitor className="w-4 h-4" /> |
80 | | - <span className="hidden sm:inline">共享桌面</span> |
81 | | - <span className="sm:hidden">桌面</span> |
82 | | - </TabsTrigger> |
83 | | - </TabsList> |
| 66 | + {/* WebRTC 支持检测加载状态 */} |
| 67 | + {!isChecked && ( |
| 68 | + <div className="max-w-4xl mx-auto text-center py-8"> |
| 69 | + <div className="animate-pulse"> |
| 70 | + <div className="h-4 bg-gray-200 rounded w-48 mx-auto mb-2"></div> |
| 71 | + <div className="h-4 bg-gray-200 rounded w-32 mx-auto"></div> |
84 | 72 | </div> |
| 73 | + <p className="mt-4 text-gray-600">正在检测浏览器支持...</p> |
| 74 | + </div> |
| 75 | + )} |
85 | 76 |
|
86 | | - {/* Tab Content */} |
87 | | - <div> |
88 | | - <TabsContent value="webrtc" className="mt-0 animate-fade-in-up"> |
89 | | - <WebRTCFileTransfer /> |
90 | | - </TabsContent> |
| 77 | + {/* 主要内容 - 只有在检测完成后才显示 */} |
| 78 | + {isChecked && ( |
| 79 | + <div className="max-w-4xl mx-auto"> |
| 80 | + {/* WebRTC 不支持时的警告横幅 */} |
| 81 | + {!isSupported && ( |
| 82 | + <div className="mb-6 p-4 bg-red-50 border border-red-200 rounded-lg"> |
| 83 | + <div className="flex items-center justify-between"> |
| 84 | + <div className="flex items-center gap-2"> |
| 85 | + <div className="w-2 h-2 bg-red-500 rounded-full animate-pulse"></div> |
| 86 | + <span className="text-red-700 font-medium"> |
| 87 | + 当前浏览器不支持 WebRTC,功能可能无法正常使用 |
| 88 | + </span> |
| 89 | + </div> |
| 90 | + <button |
| 91 | + onClick={showUnsupportedModalManually} |
| 92 | + className="text-red-600 hover:text-red-800 text-sm underline" |
| 93 | + > |
| 94 | + 查看详情 |
| 95 | + </button> |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + )} |
91 | 99 |
|
92 | | - <TabsContent value="message" className="mt-0 animate-fade-in-up"> |
93 | | - <WebRTCTextImageTransfer /> |
94 | | - </TabsContent> |
| 100 | + <Tabs value={activeTab} onValueChange={setActiveTab} className="w-full"> |
| 101 | + {/* Tabs Navigation - 横向布局 */} |
| 102 | + <div className="mb-6"> |
| 103 | + <TabsList className="grid w-full grid-cols-4 max-w-2xl mx-auto h-auto bg-white/90 backdrop-blur-sm shadow-lg rounded-xl p-2 border border-slate-200"> |
| 104 | + <TabsTrigger |
| 105 | + value="webrtc" |
| 106 | + className="flex items-center justify-center space-x-2 px-3 py-3 text-sm font-medium rounded-lg transition-all duration-200 hover:bg-slate-50 data-[state=active]:bg-blue-500 data-[state=active]:text-white data-[state=active]:shadow-md data-[state=active]:hover:bg-blue-600" |
| 107 | + disabled={!isSupported} |
| 108 | + > |
| 109 | + <Upload className="w-4 h-4" /> |
| 110 | + <span className="hidden sm:inline">文件传输</span> |
| 111 | + <span className="sm:hidden">文件</span> |
| 112 | + {!isSupported && <span className="text-xs opacity-60">*</span>} |
| 113 | + </TabsTrigger> |
| 114 | + <TabsTrigger |
| 115 | + value="message" |
| 116 | + className="flex items-center justify-center space-x-2 px-3 py-3 text-sm font-medium rounded-lg transition-all duration-200 hover:bg-slate-50 data-[state=active]:bg-emerald-500 data-[state=active]:text-white data-[state=active]:shadow-md data-[state=active]:hover:bg-emerald-600" |
| 117 | + disabled={!isSupported} |
| 118 | + > |
| 119 | + <MessageSquare className="w-4 h-4" /> |
| 120 | + <span className="hidden sm:inline">文本消息</span> |
| 121 | + <span className="sm:hidden">消息</span> |
| 122 | + {!isSupported && <span className="text-xs opacity-60">*</span>} |
| 123 | + </TabsTrigger> |
| 124 | + <TabsTrigger |
| 125 | + value="desktop" |
| 126 | + className="flex items-center justify-center space-x-2 px-3 py-3 text-sm font-medium rounded-lg transition-all duration-200 hover:bg-slate-50 data-[state=active]:bg-purple-500 data-[state=active]:text-white data-[state=active]:shadow-md data-[state=active]:hover:bg-purple-600" |
| 127 | + disabled={!isSupported} |
| 128 | + > |
| 129 | + <Monitor className="w-4 h-4" /> |
| 130 | + <span className="hidden sm:inline">共享桌面</span> |
| 131 | + <span className="sm:hidden">桌面</span> |
| 132 | + {!isSupported && <span className="text-xs opacity-60">*</span>} |
| 133 | + </TabsTrigger> |
| 134 | + <TabsTrigger |
| 135 | + value="wechat" |
| 136 | + className="flex items-center justify-center space-x-2 px-3 py-3 text-sm font-medium rounded-lg transition-all duration-200 hover:bg-slate-50 data-[state=active]:bg-green-500 data-[state=active]:text-white data-[state=active]:shadow-md data-[state=active]:hover:bg-green-600" |
| 137 | + > |
| 138 | + <Users className="w-4 h-4" /> |
| 139 | + <span className="hidden sm:inline">微信群</span> |
| 140 | + <span className="sm:hidden">微信</span> |
| 141 | + </TabsTrigger> |
| 142 | + </TabsList> |
| 143 | + |
| 144 | + {/* WebRTC 不支持时的提示 */} |
| 145 | + {!isSupported && ( |
| 146 | + <p className="text-center text-xs text-gray-500 mt-2"> |
| 147 | + * 需要 WebRTC 支持才能使用 |
| 148 | + </p> |
| 149 | + )} |
| 150 | + </div> |
95 | 151 |
|
96 | | - <TabsContent value="desktop" className="mt-0 animate-fade-in-up"> |
97 | | - <DesktopShare /> |
98 | | - </TabsContent> |
99 | | - </div> |
100 | | - </Tabs> |
101 | | - </div> |
| 152 | + {/* Tab Content */} |
| 153 | + <div> |
| 154 | + <TabsContent value="webrtc" className="mt-0 animate-fade-in-up"> |
| 155 | + <WebRTCFileTransfer /> |
| 156 | + </TabsContent> |
| 157 | + |
| 158 | + <TabsContent value="message" className="mt-0 animate-fade-in-up"> |
| 159 | + <WebRTCTextImageTransfer /> |
| 160 | + </TabsContent> |
| 161 | + |
| 162 | + <TabsContent value="desktop" className="mt-0 animate-fade-in-up"> |
| 163 | + <DesktopShare /> |
| 164 | + </TabsContent> |
| 165 | + |
| 166 | + <TabsContent value="wechat" className="mt-0 animate-fade-in-up"> |
| 167 | + <WeChatGroup /> |
| 168 | + </TabsContent> |
| 169 | + </div> |
| 170 | + </Tabs> |
| 171 | + </div> |
| 172 | + )} |
102 | 173 | </div> |
| 174 | + |
| 175 | + {/* WebRTC 不支持提示模态框 */} |
| 176 | + {webrtcSupport && ( |
| 177 | + <WebRTCUnsupportedModal |
| 178 | + isOpen={showUnsupportedModal} |
| 179 | + onClose={closeUnsupportedModal} |
| 180 | + webrtcSupport={webrtcSupport} |
| 181 | + /> |
| 182 | + )} |
103 | 183 | </div> |
104 | 184 | ); |
105 | 185 | } |
0 commit comments