braverhealth / phoenix-socket-dart

Cross-platform and stream-based implementation of Phoenix Sockets
https://pub.dev/packages/phoenix_socket
BSD 3-Clause "New" or "Revised" License
73 stars 37 forks source link

Getting two socket replies instead of one #51

Closed vizakenjack closed 4 months ago

vizakenjack commented 1 year ago

My code:

_socket = PhoenixSocket(url, socketOptions: _socketOptions())..connect();
_socket.openStream.listen(_onStreamEvent);

void _onStreamEvent(PhoenixSocketOpenEvent event) {
    channel = _socket.addChannel(topic: 'user:${user.id}');
    channel?.join().future.then((response) async {
      if (response.isOk) {
        onChannelJoin?.call();
        await for (final message in channel!.messages) {
          onChannelMessage?.call(message);
        }
      }
    });

    onConnected?.call();
  }

When I receive a reply from socket, there are two messages - one is PhoenixChannelEvent(phx_reply) and another is PhoenixChannelEvent(chan_reply_2) (with ref id)

Is that intended behavior or I am doing something wrong? Both of them responds to event.isReply, so I had to add an additional condition to prevent my code running twice.

matehat commented 1 year ago

I've also started to see some unexpected behavior like this, I'm wondering if the exact implementation of Phoenix has changed the protocol a bit.

What version of Phoenix are you using?

vizakenjack commented 1 year ago

What version of Phoenix are you using?

I use 1.6.11 Phoenix and 2.1.1 PubSub

opsb commented 5 months ago

Took me a little digging around to figure out how to distinguish the two types of response

extension PhoenixChannelReplyIdentification on PhoenixChannelEvent {
  static const String __chanReplyEventName = 'chan_reply';
  static const String __replyEventName = 'phx_reply';
  bool get isChanReply => value.startsWith(__chanReplyEventName);
  bool get isPhxReply => value.startsWith(__replyEventName);
}
opsb commented 5 months ago

If I inspect the websocket messages I only see the phx_reply, there's no sign of the chan_reply messages which leads me to believe it's client side somehow.

matehat commented 4 months ago

Fix is in the 0.7.2 release