2

I have tried the sample code provided by QB but event subscription is not working and the method body is never executed. I am attaching my code for reference

subscribeToEvent() async {

try {
  await QB.chat.subscribeMessageEvents( QBChatEvents.RECEIVED_NEW_MESSAGE, (data) {

    print("dbee inside event subscribeMessageEvents");
    Map<String, Object> map = new Map<String, dynamic>.from(data);
    String messageType = map["type"];
    String messageBody = "system message";
    if (messageType == QBChatEvents.RECEIVED_NEW_MESSAGE) {
      Map<String, Object> payload =
      new Map<String, dynamic>.from(map["payload"]);
      messageBody = payload["body"];
      String messageId = payload["id"];
      print("dbee $messageBody $messageId");
    }
  }, );
} on Exception catch (e) {
  print("Error in subscribing");
  print(e);
}

I can see the XMPP logs being printed on console when a new message comes but the subscriber is never invoked.

dbee
  • 21
  • 1

1 Answers1

0

Make sure you are using the latest version of QuickBlox Flutter SDK: 0.2.3-alpha .

Next, follow the below steps:

  • Settings => init credentials
  • Auth => login
  • Chat => connect
  • Chat => subscribe message events
  • Chat => send message

Please note that outgoing messages will also appear in the callback QBChatEvents.RECEIVED_NEW_MESSAGE.

QuickBlox
  • 233
  • 1
  • 11
  • Followed all the steps mentioned and upgraded to 0.2.4-alpha. It's still not working. The subscribeMessageEvents is still not being called. Please help. – dbee Apr 17 '20 at 14:14
  • 2
    It's now working with the latest release 0.2.5-alpha – dbee Apr 28 '20 at 18:17
  • It's not working with 3.3.0-alpha. I have followed all the steps but still not received anything in subscribe function. What I have miss?? – Thiyraash David Sep 16 '20 at 15:57