dmotz / trystero

✨🤝✨ Build instant multiplayer webapps, no server required — Magic WebRTC matchmaking over BitTorrent, Nostr, MQTT, IPFS, Supabase, and Firebase
https://oxism.com/trystero
MIT License
1.33k stars 92 forks source link

Error: undefined 'digest' . (when accessing by ip address) #80

Closed chopin closed 4 months ago

chopin commented 4 months ago

Hi again,

I integrated Trystero for the first time. I saw that joinRoom() and room.onPeerJoin() worked fine when accessing by localhost.

But Trystero fail when I access by ip address not localhost. Following is the error message:

trystero-torrent.min.js:1 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'digest')
    at C (trystero-torrent.min.js:1:516)
    at rr.init (trystero-torrent.min.js:1:47935)

I found the corresponding line at debugger around at line 23 in trystero-torrent.min.js:

const t = Array.from(new Uint8Array(await crypto.subtle.digest("SHA-1", p(e)))).map((e=>e.toString(36))).join("");

I really appreciate your help. Thanks in advance.

jeremyckahn commented 4 months ago

Trystero uses the Web Crypto API, which requires a secure context. What that means is that it will only work under localhost or https URLs. If you're on an IP URL, it's probably http and not https. So, you'll need to update your project to be served from a https URL.

chopin commented 4 months ago

Thanks for your response. I found a related issue posted before. It explains how to get SSL certificate in local device: https://github.com/dmotz/trystero/issues/20#issuecomment-1204001712