Skip to content

Calling Unsubscribe from a channel is still receiving update messages #125

Open
@GrimLothar

Description

@GrimLothar

I have these 2 methods:

    public async void SubscribeToTournamentChanges(int tournament_id, TournamentChangedHandler handler)
    {
        var channelName = "tournaments:" + tournament_id;
        channels.TryGetValue(channelName, out RealtimeChannel channel);
        if (channel == null)
        {
            channel = _supabase.Realtime.Channel(channelName);
            channels.Add(channelName, channel);
            channel.Register(new PostgresChangesOptions("public", "aw-tournaments", ListenType.Updates, "id=eq." + tournament_id ));
            channel.AddPostgresChangeHandler(ListenType.Updates, (_, change) =>
            {
                if (change.Payload?.Data?.Table == "aw-tournaments")
                {
                    //Tournament data changed
                    var model = change.Model<Tournament>();
                    if (model != null)
                    {
                        _mainThreadContext.Post(_ => handler.Invoke(model), null);
                    }
                }
            });
        }
        await channel.Subscribe();
    }
    public void UnsubscribeToTournamentChanges(int tournament_id)
    {
        var channelName = "tournaments:" + tournament_id;
        channels.TryGetValue(channelName, out RealtimeChannel channel);
        if (channel != null)
        {
            channel.Unsubscribe();
        }
    }

When I call channel.Unsubscribe(); i see in the logs that something gets changed:

Socket Push [topic: realtime:tournaments:5, event: phx_leave, ref: 5505e55a-d2d9-484d-8d98-34fc9d3c3d9d]:
	null
UnityEngine.Debug:Log (object)
SupabaseManager/<>c:<Start>b__9_0 (object,string,System.Exception) (at Assets/TcgEngine/SupabaseManager.cs:60)
Supabase.Realtime.Debugger:Log (object,string,System.Exception)
Supabase.Realtime.RealtimeSocket:Push (Supabase.Realtime.Socket.SocketRequest)
Supabase.Realtime.Channel.Push:Send ()
Supabase.Realtime.RealtimeChannel:Unsubscribe ()
SupabaseManager:UnsubscribeToTournamentChanges (int) (at Assets/TcgEngine/SupabaseManager.cs:222)
TcgEngine.UI.TournamentDetailsPanel:OnBack () (at Assets/TcgEngine/Scripts/UI/TournamentDetailsPanel.cs:149)
UnityEngine.Events.UnityEvent:Invoke ()
TcgEngine.UI.AWButtonNew:OnClick () (at Assets/TcgEngine/Scripts/UI/AWButtonNew.cs:34)
UnityEngine.EventSystems.EventSystem:Update () (at ./Library/PackageCache/[email protected]/Runtime/EventSystem/EventSystem.cs:530)

But when I change my tournaments table in the DB, I still get the message. I would expect Unsubscribe to stop getting these (thus saving bandwith)

What is Unsubscribe meant to do if not this?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions