fix(presenter): replace crypto.subtle with simple hash for HTTP compatibility

crypto.subtle requires HTTPS context. Use simple string hash instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-03-20 12:42:53 +01:00
parent aece5f7414
commit eb263ce7a4

View File

@@ -31,14 +31,17 @@ interface UsePresenterModeReturn {
setTtsEnabled: (enabled: boolean) => void
}
// Client-side audio cache: text hash → blob URL
// Client-side audio cache: text key → blob URL
const audioCache = new Map<string, string>()
async function hashText(text: string): Promise<string> {
const encoder = new TextEncoder()
const data = encoder.encode(text)
const hash = await crypto.subtle.digest('SHA-256', data)
return Array.from(new Uint8Array(hash)).slice(0, 8).map(b => b.toString(16).padStart(2, '0')).join('')
function cacheKey(text: string, lang: string): string {
// Simple string hash — no crypto.subtle needed (works on HTTP too)
let hash = 0
const str = text + '|' + lang
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) - hash + str.charCodeAt(i)) | 0
}
return 'tts_' + (hash >>> 0).toString(36)
}
export function usePresenterMode({
@@ -162,7 +165,7 @@ export function usePresenterMode({
const playAudio = async () => {
try {
const key = await hashText(text + language)
const key = cacheKey(text, language)
let blobUrl = audioCache.get(key)
if (!blobUrl) {