MqttGlobalReader constructor

MqttGlobalReader({
  1. required ClientHandler clientHandler,
})

Implementation

MqttGlobalReader({
  required this.clientHandler,
}) {
  clientHandler.allMessagesStream().listen((payloadWithTopic) {
    String payload = payloadWithTopic.payload;
    String topic = payloadWithTopic.topic;

    if (topic.isChattingTopic) {
      ChatMessage chatMessage = ChatMessage.fromString(payload);
      _chatController.add(chatMessage);
    } else if (topic.isPresenceTopic) {
      PresenceMessage pMsg = PresenceMessage.fromString(payload);
      _presenceController.add(pMsg);
    } else if (topic.isRoomEventsTopic) {
      BaseMessage baseMsg = BaseMessage.fromString(payload);
      //handle rooms events
      //String roomId = topic.toLowerCase().split("/")[1];
      if (baseMsg.isChatMarkerEvent()) {
        ChatMarkerMessage cmMsg = ChatMarkerMessage.fromString(payload);
        _chatMarkerController.add(cmMsg);
      } else if (baseMsg.isTypingEvent()) {
        TypingIndicatorMessage tMsg =
            TypingIndicatorMessage.fromString(payload);
        _typingController.add(tMsg);
      }
    }
  });
}