Open GrimLothar opened 1 year ago
Okay! Late to the party. But if this is still an issue, I'd wonder if the socket is failing because of an expired token. Ideally the supabase client would handle your authentication and token renewal. So in your startup code, you'd just log in the user using the Supabase.Auth
(gotrue) client.
So adjust your Start()
method to something like the following:
async void Start()
{
Debug.Log("SupabaseManager start");
string url = SupabaseURL;
string key = SupabasePublicKey;
string userAccessToken = ApiClient.Get().AccessToken
string userRefreshToken = ApiClient.Get().RefreshToken // <---- This is important
_supabase = new Client(url, key);
await _supabase.InitializeAsync();
// Set session and start token refresh loop
await _supabase.Auth.SetSession(userAccessToken, userRefreshToken);
_supabase.Realtime.AddDebugHandler((sender, message, exception) => Debug.Log(message));
_supabase.Realtime.AddStateChangedHandler(SocketEventHandler);
var realtimeClient = await _supabase.Realtime.ConnectAsync();
Debug.Log("Is connected? " + realtimeClient.Socket?.IsConnected);
}
Actually, please try again on 0.13.3 and see if that fixes it for you!
I think you're looking for the wiki entry here! Unfortunately, I don't have write access to that repo, so I'm not much help there.
FYI updated the template to latest as of 9/27/2023. Added @acupofjose as a contributor to the template in case I'm, I dunno, retire off to some beach with no Internet or something. ;)
FYI updated the template to latest as of 9/27/2023. Added @acupofjose as a contributor to the template in case I'm, I dunno, retire off to some beach with no Internet or something. ;)
Hey, thanks for the quick turnaround! Any chance you can give a quick rundown of HOW you update the template to newer versions? So I don't have to wait/bug you in future updates
Thanks!
Right now I use the command line nuget to fetch the entire dependency graph that's in the wiki page on Unity. Then I manually remove a bunch of libraries (eg a bunch of the System and Newtonsoft Json) by hand that cause conflicts with Unity specific versions.
It's a giant PITA TBH but I haven't needed to do it enough yet to do the Right Thing(tm) and make a GitHub Action to create a Unity package manager friendly version... yet. ;)
Bug report
Describe the bug
For some unknown reason that I'm still trying to debug, my client is losing the connection to the socket. But besides that, once it reconnects, the SocketStateEventHandler is not being called.
Here is the Manager i'm using:
See code
```c# using System.Collections.Generic; using System.Threading.Tasks; using Newtonsoft.Json; using UnityEngine; using Supabase; using Supabase.Models; using Supabase.Realtime; using Supabase.Realtime.Interfaces; using Supabase.Realtime.Models; using Supabase.Realtime.PostgresChanges; using static Supabase.Realtime.PostgresChanges.PostgresChangesOptions; using static Supabase.Realtime.Constants.ChannelEventName; using TcgEngine; using UnityEngine.Events; using Client = Supabase.Client; public class SupabaseManager : MonoBehaviour { public UnityActionAnd you can see in my logs where the socket gets disconnected (I left the stacktraces for those in case it gives some hints) but after each of the
Socket State Change
I was expecting to see theSocket is $state and username is $username and user_id is $user_id
line and that never happenedLogs
``` SupabaseManager start Socket Reconnection: Initial Socket Connected to: wss://redacted4&vsn=1.0.0 Socket State Change: Open Socket is $Open and username is $Lothar and user_id is $1 Socket Push [topic: phoenix, event: heartbeat, ref: ec68999f-f9d4-41bc-aa55-849efc1f97c0]: {} Socket Push [topic: realtime:users:Lothar, event: phx_join, ref: 0245d09f-3b51-4d9a-93df-0a6d87b9f3e8]: { "config": { "broadcast": { "self": false, "ack": true }, "presence": { "key": "" }, "postgres_changes": [] } } Is connected? True Socket Message Received: {"event":"phx_reply","payload":{"response":{},"status":"ok"},"ref":"ec68999f-f9d4-41bc-aa55-849efc1f97c0","topic":"phoenix"} Socket Message Received: {"event":"phx_reply","payload":{"response":{"postgres_changes":[]},"status":"ok"},"ref":"0245d09f-3b51-4d9a-93df-0a6d87b9f3e8","topic":"realtime:users:Lothar"} Socket Push [topic: realtime:users:Lothar, event: access_token, ref: 71b840bc-4f6d-4d89-aba2-f45d0b7c6926]: { "access_token": "" } Socket Push [topic: realtime:public:users, event: phx_join, ref: df8a4e15-4830-4e91-9675-5b58a70482e6]: { "config": { "broadcast": { "self": false, "ack": false }, "presence": { "key": "" }, "postgres_changes": [ { "schema": "public", "table": "users", "filter": "id=eq.1", "event": "UPDATE" } ] } } Socket Message Received: {"event":"presence_state","payload":{},"ref":null,"topic":"realtime:users:Lothar"} Socket Message Received: {"event":"phx_reply","payload":{"response":{"postgres_changes":[{"id":98019032,"event":"UPDATE","filter":"id=eq.1","schema":"public","table":"users"}]},"status":"ok"},"ref":"df8a4e15-4830-4e91-9675-5b58a70482e6","topic":"realtime:public:users"} Socket Push [topic: realtime:public:users, event: access_token, ref: f779ebe6-fa13-4698-8be9-b9ad676e64be]: { "access_token": "" } Socket Message Received: {"event":"presence_state","payload":{},"ref":null,"topic":"realtime:public:users"} Socket Message Received: {"event":"system","payload":{"channel":"public:users","extension":"postgres_changes","message":"Subscribed to PostgreSQL","status":"ok"},"ref":null,"topic":"realtime:public:users"} Socket Push [topic: realtime:users:grimlothar, event: phx_join, ref: 70d64e2c-0f1e-43ed-a385-7d71651ce676]: { "config": { "broadcast": { "self": false, "ack": true }, "presence": { "key": "" }, "postgres_changes": [] } } Socket Message Received: {"event":"phx_reply","payload":{"response":{"postgres_changes":[]},"status":"ok"},"ref":"70d64e2c-0f1e-43ed-a385-7d71651ce676","topic":"realtime:users:grimlothar"} Socket Push [topic: realtime:users:grimlothar, event: access_token, ref: eb9393a6-dbf7-4553-85fc-267830438a55]: { "access_token": "" } Socket Message Received: {"event":"presence_state","payload":{},"ref":null,"topic":"realtime:users:grimlothar"} Socket Push [topic: realtime:users:grimlothar, event: broadcast, ref: 5862759f-cd8a-4760-bf15-1cde89390464]: { "payload": { "matchRequestFrom": "Lothar", "matchRequestKey": "Lothar-grimlothar" }, "event": "matchRequest" } Socket Message Received: {"event":"phx_reply","payload":{"response":{},"status":"ok"},"ref":"5862759f-cd8a-4760-bf15-1cde89390464","topic":"realtime:users:grimlothar"} Socket Push [topic: phoenix, event: heartbeat, ref: e54140ef-7b04-44a7-9025-4995aefa1cfc]: {} Socket Message Received: {"event":"phx_reply","payload":{"response":{},"status":"ok"},"ref":"e54140ef-7b04-44a7-9025-4995aefa1cfc","topic":"phoenix"} Socket Push [topic: realtime:users:Lothar, event: access_token, ref: 840bcfa0-60f2-4e8d-9e00-5132461bd0c2]: { "access_token": "" } Socket Push [topic: realtime:public:users, event: access_token, ref: 486e0d33-3c4f-4c43-99ef-0d77f774ab24]: { "access_token": "" } Socket Push [topic: realtime:users:grimlothar, event: access_token, ref: 4c4d4632-2f4f-46cf-9040-5a943495d754]: { "access_token": "" } Socket Message Received: {"event":"broadcast","payload":{"event":"matchRequest","payload":{"matchRequestFrom":"grimlothar","matchRequestKey":"Lothar-grimlothar"}},"ref":null,"topic":"realtime:users:Lothar"} Socket Disconnection: Lost UnityEngine.Debug:Log (object) SupabaseManager/<>c: