Browse Source

rt subscribe

Fares 10 months ago
parent
commit
513d149fd0
1 changed files with 30 additions and 15 deletions
  1. 30 15
      lib/handlers/upload_handler.dart

+ 30 - 15
lib/handlers/upload_handler.dart

@@ -84,22 +84,37 @@ Future<Response> handleFileUpload(Request request) async {
                 ),
               );
 
-          // No need to subscribe to channel
-          final supabaseRT = SupabaseClient(
-            // 'http://baas.fares.cyou:8000',
-            supabaseurl,
-            token,
-          );
-          final channel = supabaseRT.channel('csvhichstorage');
-          final res = await channel.sendBroadcastMessage(
-            event: "upload",
-            payload: {
-              "filename": filename,
-              "updated_at": now,
-            },
+          final myChannel = supabase.channel(
+            'csvhichstorage',
+            opts: const RealtimeChannelConfig(
+              ack: true,
+            ),
           );
-          supabaseRT.dispose();
-          print("   realtime response: $res");
+
+          myChannel.subscribe((status, error) async {
+            if (status != RealtimeSubscribeStatus.subscribed) return;
+
+            final serverResponse = await myChannel.sendBroadcastMessage(
+              event: "upload",
+              payload: {
+                "filename": filename,
+                "updated_at": now,
+              },
+            );
+
+            print('serverResponse: $serverResponse');
+          });
+
+          // No need to subscribe to channel
+          // final channel = supabase.channel('csvhichstorage');
+          // final res = await channel.sendBroadcastMessage(
+          //   event: "upload",
+          //   payload: {
+          //     "filename": filename,
+          //     "updated_at": now,
+          //   },
+          // );
+          // print("   realtime response: $res");
 
           await processCsvData(tempFile, supabase);