GodotNuts / GodotFirebase

Implementations of Firebase for Godot using GDScript
MIT License
554 stars 79 forks source link

[FEATURE REQUEST] Support real-time listening via `onSnapshot` method #218

Closed lokimckay closed 3 years ago

lokimckay commented 3 years ago

Is your feature request related to a problem? Please describe. I need some way for my Godot application to be notified when a document or collection changes in Firebase

Describe the solution you'd like Support the onSnapshot() method

Describe alternatives you've considered Polling the database at intervals - undesired workaround

https://firebase.google.com/docs/firestore/query-data/listen

WolfgangSenff commented 3 years ago

Unfortunately, we cannot support this at this time, as it is only supported in Firestore through gRPC. This is a different protocol from what's implemented in Godot, and while I implemented an entirely new protocol in the Realtime Database, it is a much simpler one than gRPC, which is a huge, convoluted library that I have no intention of implementing. Sorry! I'll be closing this. Be aware we've gotten this request before and simply cannot support it at the moment - there's a chance with the new JavaScript improvements that we might be able to, but it will be a completely separate thing if we even want to try that at all. Thank you for submitting it though!

WolfgangSenff commented 3 years ago

Oh, as quick note, you can do listening for the realtime database, so it's possible to work around this by storing your data there. But unfortunately that's the best we can do at this time (it's a very small team).

lokimckay commented 3 years ago

@WolfgangSenff No worries, thank you for the info

The Wiki page for Realtime Database doesn't give much of a hint on how to achieve this. Are there any examples you know of that I could look at?

var db_ref = Firebase.Database.get_database_reference("path_to_position_in_database", {})

Does db_ref here contain data? or just a reference

WolfgangSenff commented 3 years ago

The reason it looks like that is because that's more or less how the Firebase Android library looks, so yes, it would have the data. You do have to connect to the listeners for it, but you can do that with db_ref.connect(), and there should be more info in the wiki about it. If you need to filter, that's what the dictionary in the second variable is for, and there should be data about that (and should help reduce the amount of data you're pulling back if that's going to be a concern).

WolfgangSenff commented 3 years ago

https://github.com/GodotNuts/GodotFirebase/wiki/Realtime-Database#firebasedatabasereference

So these are mostly the signals you want to use. The data won't exist until they have fired (the new_data_update signal will contain all the initial data that is in the path you set, and patch_data_update will contain anything that is changed with an update command - this does not include, it's important to notice, stuff that's updated in the Firebase console; at the moment, there is a bug that doesn't allow the Firebase console updates to be propagated correctly, unfortunately).