initChannels function

dynamic initChannels(
  1. bool connected,
  2. PhoenixSocket socket,
  3. PhoenixChannel? channel,
  4. PapercupsProps props,
  5. bool canJoinConversation,
  6. Function setState,
)

This function creates the necessary channels, sockets and rooms for papercups to communicate.

Implementation

initChannels(
  bool connected,
  PhoenixSocket socket,
  PhoenixChannel? channel,
  PapercupsProps props,
  bool canJoinConversation,
  Function setState,
) {
  if (connected & socket.channels.isEmpty) {
    channel = socket.addChannel(
      topic: 'room:${props.accountId}',
    );
    channel.join().onReply(
      "ok",
      (res) {
        if (res.isOk && !canJoinConversation) {
          canJoinConversation = true;
        }
      },
    );
  }
}