GodotNuts / GodotFirebase

Implementations of Firebase for Godot using GDScript
MIT License
532 stars 76 forks source link

[FEATURE REQUEST] Add ability to set firebase base URLs so that official emulator can be used #154

Closed creikey closed 2 years ago

creikey commented 3 years ago

Is your feature request related to a problem? Please describe. Developing a game with the production firebase servers is not good practice, and the firebase emulator has more tools based around development (quickly generate fake google users as an example)

Describe the solution you'd like A way to set the firebase root, auth, and store base URLs so that localhost can be used instead.

Describe alternatives you've considered There is no alternative

Additional context https://firebase.google.com/docs/emulator-suite

WolfgangSenff commented 3 years ago

We can and should support this. I actually didn't realize it worked with the REST API. We'll get this into the next release.

nate-trojian commented 3 years ago

I needed this feature for a project I am currently working on so I went and implemented it in my own fork of the project. While actually connecting to the emulators was easy enough, I discovered an issue in the Firebase emulators themselves that prevents SSE streaming from working.

When the HTTPSSEClient makes the request to the Realtime Database Emulator, it will never enter the STATUS_BODY state. Screenshot showing underlying HTTPClient Status and the StreamPeer Connection Available Bytes.

SSE_Never_Reads_Body

It can be seen here that the StreamPeer does have the data, but because we never go to STATUS_BODY, we are not allowed to actually read it, so it remains in available bytes.

Similar screenshot showing successful production Realtime Database Streaming connection

SSE_Production_Success

HTTPClient Status mappings: 3 = Connecting 5 = Connected 6 = Requesting 7 = Body

This is due to the Realtime Database emulator not returning the proper Response Headers like production Realtime Database does for SSE streaming. Namely, it is missing a Connection: close header. I have made an issue in the Firebase Emulator repo detailing this.

As described in the issue above, the Emulator is missing any of three headers that inform the client as to when the transmission could be considered complete. The Godot HTTPClient explicitly checks for these headers here: https://github.com/godotengine/godot/blob/3.3/core/io/http_client.cpp#L492-L503.

One of these need to be present in order to have the conditions met to transition to the STATUS_BODY state, as seen here: https://github.com/godotengine/godot/blob/3.3/core/io/http_client.cpp#L521-L531.

Because none of them are met, it always goes back to STATUS_CONNECTED, preventing the underlying data from being read.

WolfgangSenff commented 3 years ago

Care to open a PR to merge your changes, @nate-trojian? 😁

WolfgangSenff commented 2 years ago

Closed by #240. See https://github.com/GodotNuts/GodotFirebase/pull/240 for more details.