Listen for updates in Firebase Realtime Database with REST in Unity WebGL

Viewed 20

I have a WebGL app and since Firebase does not have plugin for Unity WebGL I am using REST and the basic GET call looks like this ( using Unity RestClient )

RestClient.Get($"https://rtdb.firebaseio.com/Users/{localUser_dbId}/partyID/.json").Then(response => { })

How can I implement listening to value changes in the database? Something like new message was added to chat etc.

1 Answers

To get realtime updates through the REST API, you'll have to implement its REST streaming protocol which is based on EventSource / Server-Sent Events.

To start this protocol, set the request's Accept header to text/event-stream, which tells the server you want to receive SSE events instead of a regular REST response.

You'll then get all updates over a single connection/request, and send all write operations over separate connection.

Related