Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presence diff do not get updated because of inPendingSyncState is false #101

Open
jaybe78 opened this issue Dec 10, 2024 · 0 comments
Open

Comments

@jaybe78
Copy link

jaybe78 commented Dec 10, 2024

Hello,

I'm not sure whether this is a bug or not but this line https://github.com/braverhealth/phoenix-socket-dart/blob/master/lib/src/presence.dart#L123

only sets channelRef for "presence_state" events

Presence.dart

  void _onMessage(Message message) {
    if (message.event.value == stateEventName) {
      _joinRef = channel.joinRef;

Consequently, the diff events do not always get sent to the onSync callback, which is a problem because I end up having inconsistent list of users when I test...

For example backend side:

def handle_info(%Phoenix.Socket.Broadcast{topic: topic, event: "presence_diff", payload: payload}, socket) do
   push(socket, "presence_diff", payload)
    {:noreply, socket}
  end
 if (inPendingSyncState) {
        pendingDiffs.add(diff);
      }

I don't really understand what that test if for but what I tried is to move the lift up the setting of the channelRef

void _onMessage(Message message) {
   _joinRef = channel.joinRef;
    // Processing of 'state' events.
    if (message.event.value == stateEventName) {
     
      final newState = _decodeStateFromPayload(message.payload!);
      state = _syncState(state, newState);
      for (final diff in pendingDiffs) {
        state = _syncDiff(state, diff);
      }
      pendingDiffs = [];
      onSync();

      // Processing of 'diff' events.
    } else if (message.event.value == diffEventName) {
       // added line
      _joinRef = channel.joinRef;
      final diff = _decodeDiffFromPayload(message.payload!);
      if (inPendingSyncState) {
        pendingDiffs.add(diff);
      } else {
        state = _syncDiff(state, diff);
        onSync();
      }
    }
  }

Doing so I get all diff updates correctly sent to presence.onMessage callback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant