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.21k stars 88 forks source link

Fix Firebase database URL behaviour #57

Closed matthewjumpsoffbuildings closed 10 months ago

matthewjumpsoffbuildings commented 10 months ago

I was struggling to get the Firebase database to work, and it turns out its due to the fact that the normalizeDbUrl() function does not conform to actual database URLs, and cannot generate them correctly simply from the Firebase project ID.

The issue is that database URLs that are not in the US region take the form

https://PROJECT_ID-default-rtdb{.SERVER_REGION}.firebasedatabase.app

While the US region database URLs take the form

https://PROJECT_ID-default-rtdb.firebaseio.com

In both cases the normalizeDbUrl() function does not generate a correct URL from just the project ID.

It seems the simplest solution is just add a databaseURL option to the config, and to just use that directly, which is what this pull request adds.

I kept the non-functional normalize function and the final 2 lines in init(), though they should not be used

matthewjumpsoffbuildings commented 10 months ago

fixes #56 fixes #43

dmotz commented 10 months ago

Thanks for discovering this! I decided to do a fix based on yours that doesn't change or add to the API surface: just pass the full Firebase databaseURL as appId, which keeps consistency with the other strategies. Released as 0.14.0.