[B4X] Supabase - The Open Source Firebase alternative
Supabase is an open source Firebase alternative. It provides all the backend services you need to build a product. Supabase uses Postgres database with real-time capabilities. Basically, supabase provides an interface to manage postgres database that you can use to create table and insert, edit...
www.b4x.com
Share state between users with Realtime Presence.
Setup
[B4X] Supabase - Realtime
https://www.b4x.com/android/forum/threads/b4x-supabase-the-open-source-firebase-alternative.149855/ This is a very simple tutorial on how to use the Realtime module. A more detailed tutorial is coming soon. Step 1 Click in your project on "Project -> Build configurations -> Conditional...
www.b4x.com
Sync and track state
Listen to the sync, join, and leave events triggered whenever any client joins or leaves the channel or changes their slice of state:
B4X:
Realtime _
.Channel("Room1","","") _
.On(Realtime.SubscribeType_Presence) _
.Event(Realtime.Event_Sync) _
.On(Realtime.SubscribeType_Presence) _
.Event(Realtime.Event_Join) _
.On(Realtime.SubscribeType_Presence) _
.Event(Realtime.Event_Leave) _
.Subscribe
You can send state to all subscribers using track:
B4X:
Channel1.Track(CreateMap("user":"user-1","online_at":DateUtils.TicksToString(DateTime.Now)))
You can stop tracking presence using the untrack() method. This will trigger the sync and leave event handlers.
B4X:
Channel1.Untrack
B4X:
Private Sub Realtime_PresenceDataReceived(PresenceData As SupabaseRealtime_PresenceData)
Log("Presence data:")
Dim json As JSONGenerator
json.Initialize(PresenceData.Joins)
Log("Joins: " & json.ToString)
json.Initialize(PresenceData.Leaves)
Log("Leaves: " & json.ToString)
End Sub