initChannels function

dynamic initChannels(
  1. bool _connected,
  2. PhoenixSocket _socket,
  3. PhoenixChannel? _channel,
  4. Props 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,
  Props 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;
        }
      },
    );
  }
}