firebase-admin-go icon indicating copy to clipboard operation
firebase-admin-go copied to clipboard

Initial commit - FR: realtime event listener for RTDB (#229)

Open johndelavega opened this issue 6 years ago • 9 comments
trafficstars

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

johndelavega avatar May 25 '19 00:05 johndelavega

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.

hiranya911 avatar May 29 '19 18:05 hiranya911

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 :)

johndelavega avatar May 30 '19 16:05 johndelavega

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

johndelavega avatar Jun 17 '19 08:06 johndelavega

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.

johndelavega avatar Jun 21 '19 03:06 johndelavega

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.

googlebot avatar Aug 20 '19 00:08 googlebot

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

googlebot avatar Sep 03 '19 18:09 googlebot

Any update on this?

smoya avatar Oct 06 '19 18:10 smoya

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.

joseph-grabinger avatar Sep 06 '21 13:09 joseph-grabinger

I think they are not going to work on this, sad.

iamkhalidbashir avatar Sep 26 '23 12:09 iamkhalidbashir