firebase-admin-go
firebase-admin-go copied to clipboard
Initial commit - FR: realtime event listener for RTDB (#229)
Here's a pull request against dev
see cmd/listen/main.go for working simple test client app
To run the test app, edit main.go for credential json file location "edit 1." and db url "edit 2."
then from command line terminal, cd to cmd/listen
go run . init - creates snapshot user1/path1/key1:"init" for listener testing
go run . - starts listening
start a new command line terminal, cd to cmd/listen
go run . hey - this will trigger an event and should show up from other cmd line listener
Here's the gist of the code:
iter, err := ref.Listen(ctx)
defer iter.Stop()
go func() {
for {
event, err := iter.Next()
if err != nil {
break
}
}
}()
FR https://github.com/firebase/firebase-admin-go/issues/229
Thanks @johndelavega. The general shape of things look good. However the SSE sessions will die after an hour, when the underlying credential becomes invalid. You will need a way to reconnect when this happens. Also try to use the APIs in the json package as much as possible to parse SSE data.
Thanks for the feedback. Will work on the fix to reconnect. Will use json package for the SSE data parsing as that should make the code more resilient. Actually had plan to do that, so it was great seeing that feedback :)
Here's a fix for the timeout reconnection.
The code is tested and continued running for over 2 days.
The tested use case is similar to if we have a client-go SDK used for an IoT device or installed app using "authorized_user" JSON credential file,
like this: refresh_token.json
The JSON file is created from Google APIs Credential OAuth 2.0 Client IDs using Type: Other
This tool create-refresh-token can be used to create the JSON file.
This admin SDK can also be used as a client SDK, similar to Node.js SDK
Updated to use json package APIs for parsing SSE data.
This firebase-admin-go SDK can be used as firebase-client-go SDK using refresh_token "authorized_user" credential JSON file.
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.
ℹ️ Googlers: Go here for more info.
Any update on this?
Any updates on this ? Got the Event Listeners working thanks to @johndelavega github repo. Only issue I find is that the event is only triggered when I do manual changes from the firebase console. However the event is NOT triggered when I change data from another app (flutter), nor is it triggered when I update data via the Firebase Database REST API.
I think they are not going to work on this, sad.