connect method

void connect(
  1. Supervisor supervisor, {
  2. OnSecureChannelFailed? onSecureChannelFailed,
})

The supervisor will ensure connection to the topic auth

Implementation

void connect(Supervisor supervisor,
    {OnSecureChannelFailed? onSecureChannelFailed}) {
  supervisor.listen(getTopic(), (phoenixChannel) {
    this.phoenixChannel = phoenixChannel;
    phoenixChannel.messages.listen((event) async {
      if (event.isReply == true && event.payload != null) {
        if (event.payload!.containsKey('response')) {
          dynamic response = event.payload!['response'];
          if (response.runtimeType == List) {
            // Topic List Answer
            List<dynamic> data = event.payload!['response'];
            for (int i = 0; i < data.length; i++) {
              _processMessage(data[i]);
            }
          } else {
            if (response.containsKey('error')) {
              print("IT IS A error WITH RESPONSE ${response['error']}");
            }
          }
        }
      } else {
        _processMessage(event.payload!);
      }
    });
    for (int i = 0; i < waitingTopicAuths.length; i++) {
      WaitingTopicAuth waitingTopicAuth = waitingTopicAuths[i];
      secureChannel(
          channel: waitingTopicAuth.channel,
          secret: waitingTopicAuth.secret,
          metadata: waitingTopicAuth.metadata);
    }
  }, messagingTopic: false);
}