supabase-swift icon indicating copy to clipboard operation
supabase-swift copied to clipboard

Assertion failed: You can only track your presence after subscribing to the channel. Did you forget to call `channel.subscribe()`?

Open arbyruns opened this issue 1 year ago • 2 comments

Bug report

  • [X] I confirm this is a bug with Supabase, not with my own application.
  • [X] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I've noticed that an increase of assert crash Assertion failed: You can only track your presence after subscribing to the channel. Did you forget to call channel.subscribe()? even though I'm calling subscribe()

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Launch app
  2. Ensure presence is configured for when the user launches the app

Expected behavior

Crash does not occur

Screenshots

image

System information

SupabaseSDK 2.20.5

Additional context

My function

    func setUserPresence() async {
        var isTracked = false

        let deviceId = UIDevice.current.identifierForVendor?.uuidString ?? "unknown-user"

        let realtime = supaBaseClient.realtimeV2
        let userPresence = supaBaseClient.channel("user_presence")
        let presenceStream = userPresence.presenceChange()
        await userPresence.subscribe()

        for await presence in presenceStream {
            // Handle joins
            if !presence.joins.isEmpty && !isTracked {
                await userPresence.track(
                    state: [
                        "user": .string(deviceId),
                        "onlineAt": .double(Date().timeIntervalSince1970)
                    ]
                )
                isTracked = true // Update the state
            }

            // Handle leaves
            if !presence.leaves.isEmpty && isTracked {
                await userPresence.untrack()
                isTracked = false // Update the state
            }
        }
    }

arbyruns avatar Dec 06 '24 18:12 arbyruns

Hi @arbyruns,

Did you notice this assertion increases after an update? Which version were you before if that is the case? Also, please make sure nothing has changed in your code that could lead to this increase.

Thanks

grdsdev avatar Dec 10 '24 14:12 grdsdev

Did you notice this assertion increases after an update?

I can't say for sure since this is a new implementation. I was also hitting this with the Android SDK. I've since removed the code from my app because it was chewing through my monthly allotment.

arbyruns avatar Dec 12 '24 18:12 arbyruns