/** * 检查是否使用 HTTPS 协议 * WebRTC 功能(视频通话、音频通话)需要 HTTPS 才能正常工作 */ export function checkHttpsProtocol(): boolean { if (typeof window === 'undefined') { return true } const isHttps = window.location.protocol === 'https:' const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' return isHttps || isLocalhost } /** * 显示 HTTPS 警告提示 */ export function showHttpsWarning(): void { if (!checkHttpsProtocol()) { console.warn( '%c[WebRTC 警告] 当前使用 HTTP 协议访问', 'color: #ff6b6b; font-size: 14px; font-weight: bold;' ) console.warn( '%c视频通话、音频通话等功能需要 HTTPS 协议才能正常工作。\n' + '请使用 HTTPS 访问或在 localhost 环境下测试。', 'color: #ff6b6b; font-size: 12px;' ) } }