0

I am using appwrite for my backend project. and for the getx state manager. So far, everything is fine with me except for realtime. Please explain how the real-time application recording mechanism works. I have seen many video tutorials and read many articles. How can I get it through the stream? I repeated everything exactly as in the video, but it does not work. How to know if the callback fired or not. In the console it only says that the subscription has been created and that's it. there is nothing more. How to get data from this stream.

//

I have a subscription but I can't get a response//

subscription: ws://195.49.210.221/v1/realtime?project=jetservice_server&channels%5B%5D=collection.77079959596.documents

get_realtime_chat_list() async {
    var realtime_chat = await serverProvider.realtime.subscribe([
      'collection.' +
          userdata.userDataStorage.value.read(my_phone) +
          '.documents'
    ]);
    realtime_chat.stream.listen((data) {
      try {
        if (data.payload.isNotEmpty) {
          switch (data.events) {
            case ['collection.document.create']:
              print(data.payload);
              break;
            case ['collection.document.delete']:
              print("document_deleted");
          }
        }
        print(realtime_chat);
      } on AppwriteException catch (e) {
        print(e.message);
      }
    });
  }

1 Answers1

0

I don't think the channel you subscribed to is correct. As stated in the docs, it should be databases.[ID].collections.[ID].documents.

Also, it seems like the switch statement isn't quite right. I would suggest grabbing the 1st event from the events array and checking that. You might want to check if the event ends with .create or .delete.

Finally, Appwrite's realtime sends messages when they're triggered. Did you create a new document after subscribing? Also, did you ensure the user has access to the documents?

Steven Nguyen
  • 452
  • 4
  • 4